From a23b39d61abdef184cc922087eac2b273194b59b Mon Sep 17 00:00:00 2001 From: Vadim Kurland Date: Sat, 24 Apr 2010 00:29:25 +0000 Subject: [PATCH] added unit test for #1418 - test actually compiles a firewall, then tries to open instDialog again and makes sure the "compile" checkbox is now off --- .../instDialogObjectListTest.cpp | 133 ++++++++++++++++++ .../instDialogObjectListTest.h | 3 +- 2 files changed, 135 insertions(+), 1 deletion(-) diff --git a/src/gui/unit_tests/instDialogObjectListTest/instDialogObjectListTest.cpp b/src/gui/unit_tests/instDialogObjectListTest/instDialogObjectListTest.cpp index 04ccafe84..b76135e7e 100644 --- a/src/gui/unit_tests/instDialogObjectListTest/instDialogObjectListTest.cpp +++ b/src/gui/unit_tests/instDialogObjectListTest/instDialogObjectListTest.cpp @@ -168,6 +168,48 @@ void instDialogObjectListTest::verifyCompileCheckboxes(QTreeWidget *table, } } +/* + * This function checks the state of checkboxes after firewall test1 has been compiled + */ +void instDialogObjectListTest::verifyCompileCheckboxes_2(QTreeWidget *table) +{ + QTreeWidgetItemIterator it(table, QTreeWidgetItemIterator::Enabled); + while (*it) + { + if ((*it)->text(0) == "cluster1") + { + QVERIFY(((*it)->flags() & Qt::ItemIsUserCheckable) != 0); + QVERIFY((*it)->checkState(COMPILE_CHECKBOX_COLUMN) == Qt::Checked); + } + + if ((*it)->text(0) == "test1") + { + QVERIFY(((*it)->flags() & Qt::ItemIsUserCheckable) != 0); + QVERIFY((*it)->checkState(COMPILE_CHECKBOX_COLUMN) == Qt::Unchecked); + } + + if ((*it)->text(0) == "test2") + { + QVERIFY(((*it)->flags() & Qt::ItemIsUserCheckable) != 0); + QVERIFY((*it)->checkState(COMPILE_CHECKBOX_COLUMN) == Qt::Unchecked); + } + + if ((*it)->text(0) == "test3") + { + QVERIFY(((*it)->flags() & Qt::ItemIsUserCheckable) != 0); + QVERIFY((*it)->checkState(COMPILE_CHECKBOX_COLUMN) == Qt::Unchecked); + } + + if ((*it)->text(0) == "test4") + { + QVERIFY(((*it)->flags() & Qt::ItemIsUserCheckable) != 0); + QVERIFY((*it)->checkState(COMPILE_CHECKBOX_COLUMN) == Qt::Unchecked); + } + + it++; + } +} + void instDialogObjectListTest::verifyInstallCheckboxes(QTreeWidget *table, int items) { @@ -501,6 +543,7 @@ void instDialogObjectListTest::test_compile_7() QTest::qWait(100); } + /* * all previous tests tested "Compile" function. This test should test * first step of the "Install" function. @@ -527,3 +570,93 @@ void instDialogObjectListTest::test_install_1() QTest::qWait(100); } + + +/* + * Select two firewalls in the tree (test1 and test2), open context + * menu and click "Compile". Should get a list with both firewalls, + * with checkbox "Compile" selected for test2 and not selected for + * test1. Then click "Next" to compile, wait until done, then click + * "Finish". Select the same firewalls in the tree and open instDialog + * again, now both checkboxes should be turned off. + * + * This test changes "last_compiled" timestamp of the firewall object + * test2 so it should run after all tests above because it changes the + * state of the "compile" checkbox next to this firewall in the list. + */ +void instDialogObjectListTest::test_actually_compile_1() +{ + if (QFileInfo("test1.fw").exists()) + QVERIFY(QFile("test1.fw").remove()); + + ObjectTreeView *tree = mw->getCurrentObjectTree(); + tree->expandAll(); + ObjectTreeViewItem *test1 = + dynamic_cast(tree->findItems("test1", Qt::MatchExactly | Qt::MatchRecursive, 0).first()); + ObjectTreeViewItem *test2 = + dynamic_cast(tree->findItems("test2", Qt::MatchExactly | Qt::MatchRecursive, 0).first()); + + tree->scrollToItem(test1); + tree->selectionModel()->select( + tree->indexAt(findItemPos(test1, tree)), QItemSelectionModel::Clear | QItemSelectionModel::SelectCurrent); + tree->setCurrentItem(test1); + tree->selectionModel()->select( + tree->indexAt(findItemPos(test2, tree)), QItemSelectionModel::Select); + + ObjectManipulator *om = mw->findChild("om"); + openContextMenu(om, test2, tree, "Compile"); + instDialog *dlg = NULL; + foreach (QWidget *w, app->allWidgets()) + if (dynamic_cast(w) != NULL) + dlg = dynamic_cast(w); + + QTreeWidget *table = dlg->findChild("selectTable"); + QVERIFY(table != NULL); + QVERIFY(table->isColumnHidden(COMPILE_CHECKBOX_COLUMN) == false); + QVERIFY(table->isColumnHidden(INSTALL_CHECKBOX_COLUMN) == true); + verifyCompileCheckboxes(table, 2); + + QTest::qWait(100); + dlg->findChild("nextButton")->click(); + + QPushButton *finish = dlg->findChild("finishButton"); + QVERIFY(finish != NULL); + + int timeout_counter = 0; + while (!finish->isEnabled()) + { + timeout_counter++; + QVERIFY2(timeout_counter < 600, + "Compile takes too long (over 1 min) or button \"Finish\" " + "is not enabled properly when compile is done"); + QTest::qWait(100); + } + + finish->click(); + + // Now select the same firewalls and open compile/install dialog again + tree->scrollToItem(test1); + tree->selectionModel()->select( + tree->indexAt(findItemPos(test1, tree)), QItemSelectionModel::Clear | QItemSelectionModel::SelectCurrent); + tree->setCurrentItem(test1); + tree->selectionModel()->select( + tree->indexAt(findItemPos(test2, tree)), QItemSelectionModel::Select); + + openContextMenu(om, test2, tree, "Compile"); + foreach (QWidget *w, app->allWidgets()) + if (dynamic_cast(w) != NULL) + dlg = dynamic_cast(w); + + table = dlg->findChild("selectTable"); + QVERIFY(table != NULL); + QVERIFY(table->isColumnHidden(COMPILE_CHECKBOX_COLUMN) == false); + QVERIFY(table->isColumnHidden(INSTALL_CHECKBOX_COLUMN) == true); + verifyCompileCheckboxes_2(table); + + dlg->findChild("cancelButton")->click(); + QTest::qWait(100); + + QVERIFY(QFileInfo("test1.fw").exists() && QFileInfo("test1.fw").size()); + QFile::remove("test1.fw"); +} + diff --git a/src/gui/unit_tests/instDialogObjectListTest/instDialogObjectListTest.h b/src/gui/unit_tests/instDialogObjectListTest/instDialogObjectListTest.h index 1906c3a88..7fcfadb04 100644 --- a/src/gui/unit_tests/instDialogObjectListTest/instDialogObjectListTest.h +++ b/src/gui/unit_tests/instDialogObjectListTest/instDialogObjectListTest.h @@ -49,6 +49,7 @@ class instDialogObjectListTest : public QObject void openPolicy(QString fw); void verifyCompileCheckboxes(QTreeWidget *table, int items = -1); + void verifyCompileCheckboxes_2(QTreeWidget *table); void verifyInstallCheckboxes(QTreeWidget *table, int items = -1); void openContextMenu(ObjectManipulator *om, ObjectTreeViewItem *item, ObjectTreeView *tree, const QString &actionText); @@ -63,8 +64,8 @@ private slots: void test_compile_5(); void test_compile_6(); void test_compile_7(); - void test_install_1(); + void test_actually_compile_1(); public slots: void closeContextMenu();