Commit 6f09d8e8 authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

improve autotest

parent 6d3d2608
......@@ -24,6 +24,7 @@
#include <QCheckBox>
#include <QDialogButtonBox>
#include <QPushButton>
#include <qtestmouse.h>
#include <QTest>
#include <gui/widgets/selectiontypetreewidget.h>
......@@ -92,4 +93,31 @@ void SelectionTypeDialogTest::shouldHideButtons()
QVERIFY(mUseTemplateByDefault->isHidden());
}
void checkState(SelectionTypeTreeWidget *mSelectionTreeWidget, bool checked)
{
for (int i = 0; i < mSelectionTreeWidget->topLevelItemCount(); i++) {
QTreeWidgetItem *item = mSelectionTreeWidget->topLevelItem(i);
bool isChecked = item->checkState(0);
QCOMPARE(isChecked, checked);
for (int j = 0; j < item->childCount(); j++) {
bool childIsChecked = item->child(j)->checkState(0);
QCOMPARE(childIsChecked, checked);
}
}
}
void SelectionTypeDialogTest::shouldSelectAllItems()
{
SelectionTypeDialog dlg;
SelectionTypeTreeWidget *mSelectionTreeWidget = dlg.findChild<SelectionTypeTreeWidget *>(QStringLiteral("mSelectionTreeWidget"));
QPushButton *selectAll = dlg.findChild<QPushButton *>(QStringLiteral("selectAll"));
QTest::mouseClick(selectAll, Qt::LeftButton);
checkState(mSelectionTreeWidget, true);
QPushButton *unselectAll = dlg.findChild<QPushButton *>(QStringLiteral("unselectAll"));
QTest::mouseClick(unselectAll, Qt::LeftButton);
checkState(mSelectionTreeWidget, false);
}
QTEST_MAIN(SelectionTypeDialogTest)
......@@ -31,6 +31,8 @@ public:
private Q_SLOTS:
void shouldHaveDefaultValue();
void shouldHideButtons();
void shouldSelectAllItems();
};
#endif // SELECTIONTYPEDIALOGTEST_H
......@@ -49,6 +49,18 @@ void SelectionTypeTreeWidgetTest::shouldLoadTemplate_data()
QTest::newRow("selectedtypemodel2.xml") << QStringLiteral("selectedtypemodel2.xml") << 1;
}
void checkState(SelectionTypeTreeWidget *mSelectionTreeWidget, bool checked)
{
for (int i = 0; i < mSelectionTreeWidget->topLevelItemCount(); i++) {
QTreeWidgetItem *item = mSelectionTreeWidget->topLevelItem(i);
bool isChecked = item->checkState(0);
QCOMPARE(isChecked, checked);
for (int j = 0; j < item->childCount(); j++) {
bool childIsChecked = item->child(j)->checkState(0);
QCOMPARE(childIsChecked, checked);
}
}
}
void SelectionTypeTreeWidgetTest::shouldLoadTemplate()
{
QFETCH(QString, filename);
......@@ -66,6 +78,7 @@ void SelectionTypeTreeWidgetTest::shouldLoadTemplate()
w.show();
QTest::qWait(5000);
#endif
checkState(&w, true);
QCOMPARE(w.topLevelItemCount(), topLevelItems);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment