mirror of
https://github.com/fwbuilder/fwbuilder
synced 2026-03-23 19:57:21 +01:00
* instDialog.cpp (instDialog::show): fixes #1429 "Finish" button
is activated during compile. Also added unit test for this.
This commit is contained in:
parent
64bbe7fdb9
commit
8fa068846c
@ -1,3 +1,8 @@
|
||||
2010-04-28 Vadim Kurland <vadim@vk.crocodile.org>
|
||||
|
||||
* instDialog.cpp (instDialog::show): fixes #1429 "Finish" button
|
||||
is activated during compile. Also added unit test for this.
|
||||
|
||||
2010-04-27 vadim <vadim@vk.crocodile.org>
|
||||
|
||||
* CompilerDriver_ipt.cpp (CompilerDriver_ipt::dumpScript): fixes #1425
|
||||
|
||||
@ -144,7 +144,7 @@ instDialog::instDialog(QWidget *p) : QDialog(p)
|
||||
|
||||
currentSaveButton = m_dialog->saveMCLogButton;
|
||||
currentSaveButton->setEnabled(true);
|
||||
currentStopButton = m_dialog->controlMCButton;
|
||||
currentStopButton = m_dialog->stopButton;
|
||||
currentProgressBar = m_dialog->compProgress;
|
||||
currentFirewallsBar = m_dialog->compFirewallProgress;
|
||||
currentLabel = m_dialog->infoMCLabel;
|
||||
@ -159,9 +159,6 @@ instDialog::instDialog(QWidget *p) : QDialog(p)
|
||||
proc.setProcessChannelMode(QProcess::MergedChannels);
|
||||
|
||||
m_dialog->fwWorkList->setSortingEnabled(true);
|
||||
|
||||
for (int page=0; page < pageCount(); page++)
|
||||
setFinishEnabled(page, false);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -197,6 +194,9 @@ void instDialog::show(ProjectPanel *proj,
|
||||
compile_fw_list.clear();
|
||||
install_fw_list.clear();
|
||||
|
||||
for (int page=0; page < pageCount(); page++)
|
||||
setFinishEnabled(page, false);
|
||||
|
||||
if (!onlySelected)
|
||||
{
|
||||
findFirewalls();
|
||||
|
||||
@ -60,7 +60,7 @@
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="currentIndex">
|
||||
<number>0</number>
|
||||
<number>1</number>
|
||||
</property>
|
||||
<widget class="QWidget" name="select_firewalls_page">
|
||||
<property name="sizePolicy">
|
||||
@ -272,7 +272,7 @@
|
||||
<number>11</number>
|
||||
</property>
|
||||
<item row="2" column="1">
|
||||
<widget class="QPushButton" name="controlMCButton">
|
||||
<widget class="QPushButton" name="stopButton">
|
||||
<property name="text">
|
||||
<string>Stop</string>
|
||||
</property>
|
||||
|
||||
@ -90,12 +90,22 @@ void instDialogCompileTest::testCompile()
|
||||
QTest::qWait(500);
|
||||
dlg->findChild<QPushButton*>("nextButton")->click();
|
||||
|
||||
QTreeWidget *list= dlg->findChild<QTreeWidget*>("fwWorkList");
|
||||
QTreeWidget *list = dlg->findChild<QTreeWidget*>("fwWorkList");
|
||||
QPushButton *back = dlg->findChild<QPushButton*>("backButton");
|
||||
QPushButton *next = dlg->findChild<QPushButton*>("nextButton");
|
||||
QPushButton *finish = dlg->findChild<QPushButton*>("finishButton");
|
||||
QPushButton *cancel = dlg->findChild<QPushButton*>("cancelButton");
|
||||
|
||||
int waited = 0;
|
||||
|
||||
while (!checkProgress(list))
|
||||
{
|
||||
// test state of the buttons
|
||||
QVERIFY(back->isEnabled() == false);
|
||||
QVERIFY(next->isEnabled() == false);
|
||||
QVERIFY(cancel->isEnabled() == true);
|
||||
QVERIFY(finish->isEnabled() == false);
|
||||
|
||||
QTest::qWait(500);
|
||||
waited += 500;
|
||||
QVERIFY(waited < 10000);
|
||||
@ -105,6 +115,13 @@ void instDialogCompileTest::testCompile()
|
||||
{
|
||||
QVERIFY(list->topLevelItem(i)->text(1) == "Success");
|
||||
}
|
||||
|
||||
// test state of the buttons
|
||||
QVERIFY(back->isEnabled() == false);
|
||||
QVERIFY(next->isEnabled() == false);
|
||||
QVERIFY(cancel->isEnabled() == true);
|
||||
QVERIFY(finish->isEnabled() == true);
|
||||
|
||||
dlg->reject();
|
||||
|
||||
QVERIFY(QFileInfo("test1.fw").exists() && QFileInfo("test1.fw").size());
|
||||
|
||||
@ -134,6 +134,18 @@ using namespace std;
|
||||
using namespace QTest;
|
||||
using namespace libfwbuilder;
|
||||
|
||||
|
||||
bool checkProgress(QTreeWidget *list)
|
||||
{
|
||||
for(int i=0; i<list->topLevelItemCount(); i++)
|
||||
{
|
||||
if ( (list->topLevelItem(i)->text(1).toStdString() == "Compiling ...") ||
|
||||
(list->topLevelItem(i)->text(1).toStdString() == "Installing ...") )
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void instDialogInstallTest::initTestCase()
|
||||
{
|
||||
mw = new FWWindow();
|
||||
@ -150,15 +162,63 @@ void instDialogInstallTest::cleanupTestCase()
|
||||
QFile::remove("test1.fw");
|
||||
}
|
||||
|
||||
bool checkProgress(QTreeWidget *list)
|
||||
void instDialogInstallTest::resetDialogs()
|
||||
{
|
||||
for(int i=0; i<list->topLevelItemCount(); i++)
|
||||
{
|
||||
if ( (list->topLevelItem(i)->text(1).toStdString() == "Compiling ...") ||
|
||||
(list->topLevelItem(i)->text(1).toStdString() == "Installing ...") )
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
instOptionsDialog *optdlg = mw->findChild<instOptionsDialog*>("instOptionsDialog_q");
|
||||
if (optdlg && optdlg->isVisible()) optdlg->reject();
|
||||
instDialog *dlg = mw->findChild<instDialog*>();
|
||||
if (dlg && dlg->isVisible()) dlg->reject();
|
||||
QTest::qWait(500);
|
||||
}
|
||||
|
||||
void instDialogInstallTest::fillInstOptionsDialog(const QString &user_name,
|
||||
const QString &passwd,
|
||||
const QString &alt_address,
|
||||
bool verbose_flag)
|
||||
{
|
||||
instOptionsDialog *optdlg = mw->findChild<instOptionsDialog*>("instOptionsDialog_q");
|
||||
QVERIFY(optdlg != NULL);
|
||||
QVERIFY(optdlg->isVisible() == true);
|
||||
|
||||
QLineEdit *uname = optdlg->findChild<QLineEdit*>("uname");
|
||||
QLineEdit *pwd = optdlg->findChild<QLineEdit*>("pwd");
|
||||
QLineEdit *altAddress = optdlg->findChild<QLineEdit*>("altAddress");
|
||||
QCheckBox *verbose = optdlg->findChild<QCheckBox*>("verbose");
|
||||
|
||||
if (!user_name.isEmpty()) uname->setText(user_name);
|
||||
if (!passwd.isEmpty()) pwd->setText(passwd);
|
||||
if (!alt_address.isEmpty()) altAddress->setText(alt_address);
|
||||
verbose->setChecked(verbose_flag);
|
||||
|
||||
optdlg->findChild<QPushButton*>("okButton")->click();
|
||||
}
|
||||
|
||||
void instDialogInstallTest::instOptionsForTest1()
|
||||
{
|
||||
// set verbose on to reveal scp and ssh command line
|
||||
fillInstOptionsDialog(QString("root"), QString(""), QString("127.0.0.1"), true);
|
||||
}
|
||||
|
||||
void instDialogInstallTest::instOptionsForTest2()
|
||||
{
|
||||
// set verbose on to reveal scp and ssh command line
|
||||
fillInstOptionsDialog(QString("root"), QString(""), QString("127.0.0.1"), true);
|
||||
}
|
||||
|
||||
void instDialogInstallTest::instOptionsForTest3()
|
||||
{
|
||||
// set verbose on to reveal scp and ssh command line
|
||||
fillInstOptionsDialog(QString("root"), QString(""), QString("192.168.254.254"), true);
|
||||
}
|
||||
|
||||
void instDialogInstallTest::instOptionsForTest4()
|
||||
{
|
||||
fillInstOptionsDialog(QString("root"), QString(""), QString("192.168.254.254"), false);
|
||||
}
|
||||
|
||||
void instDialogInstallTest::instOptionsForTest5()
|
||||
{
|
||||
fillInstOptionsDialog(QString("root"), QString(""), QString("192.168.254.254"), false);
|
||||
}
|
||||
|
||||
void instDialogInstallTest::removeFiles()
|
||||
@ -183,8 +243,17 @@ void instDialogInstallTest::removeFiles()
|
||||
QVERIFY(QDir().mkdir("test_install"));
|
||||
}
|
||||
|
||||
/*
|
||||
* compile and install object test1. After it is compiled, test
|
||||
* verifies that all buttons in the dialog are in the right state and
|
||||
* the file test1.fw has been produced. Then the file is replaced with
|
||||
* a dummy test script and test proceeds to the install phase by
|
||||
* clicking Next in the dialog.
|
||||
*/
|
||||
void instDialogInstallTest::testInstall1()
|
||||
{
|
||||
resetDialogs();
|
||||
|
||||
removeFiles();
|
||||
Firewall *test1 = NULL;
|
||||
foreach(FWObject *fw, mw->db()->getByTypeDeep(Firewall::TYPENAME))
|
||||
@ -196,8 +265,15 @@ void instDialogInstallTest::testInstall1()
|
||||
}
|
||||
}
|
||||
QVERIFY(test1 != NULL);
|
||||
|
||||
// reset additional args for scp and ssh
|
||||
FWOptions *fwoptions = test1->getOptionsObject();
|
||||
fwoptions->setStr("scpArgs", "");
|
||||
fwoptions->setStr("sshArgs", "");
|
||||
|
||||
fwoptions->setStr("firewall_dir", (QDir::currentPath()+"/test_install").toStdString());
|
||||
// add -v command line arg for ssh
|
||||
fwoptions->setStr("sshArgs", "-o ConnectTimeout=2");
|
||||
|
||||
mw->findChild<QAction*>("installAction")->trigger();
|
||||
QTest::qWait(500);
|
||||
@ -205,12 +281,17 @@ void instDialogInstallTest::testInstall1()
|
||||
instDialog *dlg = mw->findChild<instDialog*>();
|
||||
dlg->findChild<QPushButton*>("pushButton17")->click();
|
||||
|
||||
QPushButton *back = dlg->findChild<QPushButton*>("backButton");
|
||||
QPushButton *next = dlg->findChild<QPushButton*>("nextButton");
|
||||
QPushButton *finish = dlg->findChild<QPushButton*>("finishButton");
|
||||
QPushButton *cancel = dlg->findChild<QPushButton*>("cancelButton");
|
||||
|
||||
QTreeWidget *selectTable = dlg->findChild<QTreeWidget*>("selectTable");
|
||||
QTreeWidgetItem *test1item = selectTable->findItems("test1", Qt::MatchExactly | Qt::MatchRecursive, 0).first();
|
||||
test1item->setCheckState(1, Qt::Checked);
|
||||
test1item->setCheckState(2, Qt::Checked);
|
||||
QTest::qWait(500);
|
||||
dlg->findChild<QPushButton*>("nextButton")->click();
|
||||
next->click();
|
||||
|
||||
QTreeWidget *list= dlg->findChild<QTreeWidget*>("fwWorkList");
|
||||
QTextBrowser *processLogDisplay = dlg->findChild<QTextBrowser*>("procLogDisplay");
|
||||
@ -222,6 +303,11 @@ void instDialogInstallTest::testInstall1()
|
||||
|
||||
while (!checkProgress(list))
|
||||
{
|
||||
QVERIFY(back->isEnabled() == false);
|
||||
QVERIFY(next->isEnabled() == false);
|
||||
QVERIFY(cancel->isEnabled() == true);
|
||||
QVERIFY2(finish->isEnabled() == false, "Button Finish is enabled during operation");
|
||||
|
||||
QTest::qWait(500);
|
||||
waited += 500;
|
||||
QVERIFY(waited < 10000);
|
||||
@ -233,8 +319,13 @@ void instDialogInstallTest::testInstall1()
|
||||
}
|
||||
QTest::qWait(500);
|
||||
|
||||
QVERIFY(dlg->findChild<QPushButton*>("nextButton")->isEnabled());
|
||||
QVERIFY(!dlg->findChild<QPushButton*>("finishButton")->isEnabled());
|
||||
QVERIFY(back->isEnabled() == false);
|
||||
QVERIFY(next->isEnabled() == true);
|
||||
QVERIFY(cancel->isEnabled() == true);
|
||||
QVERIFY(finish->isEnabled() == false);
|
||||
|
||||
// Compile phase is done. Replace generated script test1.fw with a test script
|
||||
// and proceed to install phase
|
||||
|
||||
QVERIFY(QFile::exists("test1.fw"));
|
||||
QVERIFY(QFile::remove("test1.fw"));
|
||||
@ -244,43 +335,45 @@ void instDialogInstallTest::testInstall1()
|
||||
testfile.close();
|
||||
testfile.setPermissions(testfile.permissions() | QFile::ExeOwner);
|
||||
|
||||
QTimer::singleShot(200, this, SLOT(testInstall1_part2()));
|
||||
dlg->findChild<QPushButton*>("nextButton")->click();
|
||||
// now runs testInstall_part2 and fills install options dialog
|
||||
QTimer::singleShot(200, this, SLOT(instOptionsForTest1()));
|
||||
|
||||
next->click();
|
||||
QTest::qWait(500);
|
||||
|
||||
waited = 0;
|
||||
while (!checkProgress(list))
|
||||
{
|
||||
QVERIFY(back->isEnabled() == false);
|
||||
QVERIFY(next->isEnabled() == false);
|
||||
QVERIFY(cancel->isEnabled() == true);
|
||||
QVERIFY2(finish->isEnabled() == false, "Button Finish is enabled during operation");
|
||||
|
||||
QTest::qWait(500);
|
||||
waited += 500;
|
||||
QVERIFY(waited < 10000);
|
||||
}
|
||||
|
||||
QTest::qWait(3000);
|
||||
QTest::qWait(2000);
|
||||
|
||||
verifyInstallSuccess("instDialogInstallTest::testInstall1()");
|
||||
|
||||
QVERIFY(back->isEnabled() == false);
|
||||
QVERIFY(next->isEnabled() == false);
|
||||
QVERIFY(cancel->isEnabled() == true);
|
||||
QVERIFY(finish->isEnabled() == true);
|
||||
|
||||
QString text = processLogDisplay->toPlainText();
|
||||
|
||||
// check that additional ssh command line argument was indeed used
|
||||
QVERIFY(text.contains("-o ConnectTimeout=2"));
|
||||
|
||||
QVERIFY(text.contains("Testing policy activation script"));
|
||||
QVERIFY(!text.contains("*** Fatal error"));
|
||||
QVERIFY(!text.isEmpty());
|
||||
dlg->reject();
|
||||
QTest::qWait(1000);
|
||||
QTest::qWait(500);
|
||||
}
|
||||
|
||||
void instDialogInstallTest::testInstall1_part2() // sets install options in modal dialog
|
||||
{
|
||||
instOptionsDialog *optdlg = mw->findChild<instOptionsDialog*>("instOptionsDialog_q");
|
||||
QLineEdit *uname = optdlg->findChild<QLineEdit*>("uname");
|
||||
QLineEdit *pwd = optdlg->findChild<QLineEdit*>("pwd");
|
||||
QLineEdit *altAddress = optdlg->findChild<QLineEdit*>("altAddress");
|
||||
QCheckBox *verbose = optdlg->findChild<QCheckBox*>("verbose");
|
||||
uname->setText("root"); // getenv("USER"));
|
||||
altAddress->setText("127.0.0.1");
|
||||
verbose->setChecked(false); // turn verbose off even if it is on in settings
|
||||
optdlg->findChild<QPushButton*>("okButton")->click();
|
||||
}
|
||||
|
||||
|
||||
void instDialogInstallTest::verifyInstallSuccess(const QString &test_name)
|
||||
{
|
||||
instDialog *dlg = mw->findChild<instDialog*>();
|
||||
@ -299,8 +392,23 @@ void instDialogInstallTest::verifyInstallSuccess(const QString &test_name)
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
test for "authentication failed" error:
|
||||
|
||||
* before compiling and installing, set environment variable
|
||||
"SSH_AUTH_SOCK" to empty string. Save its value before destroying it
|
||||
and then restore when this test is done
|
||||
|
||||
* repeat the test1 with address 127.0.0.1. Since you have turned off
|
||||
ssh-agent and left password field empty, the program should not be
|
||||
able to authenticate and you should see "Permission denied" in the
|
||||
progress output
|
||||
|
||||
*/
|
||||
void instDialogInstallTest::testInstall2()
|
||||
{
|
||||
resetDialogs();
|
||||
|
||||
removeFiles();
|
||||
Firewall *test1 = NULL;
|
||||
foreach(FWObject *fw, mw->db()->getByTypeDeep(Firewall::TYPENAME))
|
||||
@ -312,9 +420,15 @@ void instDialogInstallTest::testInstall2()
|
||||
}
|
||||
}
|
||||
QVERIFY(test1 != NULL);
|
||||
|
||||
// reset additional args for scp and ssh
|
||||
FWOptions *fwoptions = test1->getOptionsObject();
|
||||
fwoptions->setStr("scpArgs", "");
|
||||
fwoptions->setStr("sshArgs", "");
|
||||
|
||||
fwoptions->setStr("firewall_dir", (QDir::currentPath()+"/test_install").toStdString());
|
||||
|
||||
|
||||
setenv("SSH_AUTH_SOCK", "nothinghere", 1);
|
||||
QTest::qWait(500);
|
||||
mw->findChild<QAction*>("installAction")->trigger();
|
||||
@ -323,12 +437,18 @@ void instDialogInstallTest::testInstall2()
|
||||
instDialog *dlg = mw->findChild<instDialog*>();
|
||||
dlg->findChild<QPushButton*>("pushButton17")->click();
|
||||
|
||||
|
||||
QPushButton *back = dlg->findChild<QPushButton*>("backButton");
|
||||
QPushButton *next = dlg->findChild<QPushButton*>("nextButton");
|
||||
QPushButton *finish = dlg->findChild<QPushButton*>("finishButton");
|
||||
QPushButton *cancel = dlg->findChild<QPushButton*>("cancelButton");
|
||||
|
||||
QTreeWidget *selectTable = dlg->findChild<QTreeWidget*>("selectTable");
|
||||
QTreeWidgetItem *test1item = selectTable->findItems("test1", Qt::MatchExactly | Qt::MatchRecursive, 0).first();
|
||||
test1item->setCheckState(1, Qt::Checked);
|
||||
test1item->setCheckState(2, Qt::Checked);
|
||||
QTest::qWait(500);
|
||||
dlg->findChild<QPushButton*>("nextButton")->click();
|
||||
next->click();
|
||||
|
||||
QTreeWidget *list= dlg->findChild<QTreeWidget*>("fwWorkList");
|
||||
|
||||
@ -336,16 +456,23 @@ void instDialogInstallTest::testInstall2()
|
||||
|
||||
while (!checkProgress(list))
|
||||
{
|
||||
QVERIFY(back->isEnabled() == false);
|
||||
QVERIFY(next->isEnabled() == false);
|
||||
QVERIFY(cancel->isEnabled() == true);
|
||||
QVERIFY2(finish->isEnabled() == false, "Button Finish is enabled during operation");
|
||||
|
||||
QTest::qWait(500);
|
||||
waited += 500;
|
||||
QVERIFY(waited < 10000);
|
||||
}
|
||||
|
||||
qDebug() << "Test 2 continues";
|
||||
|
||||
verifyInstallSuccess("instDialogInstallTest::testInstall2()");
|
||||
|
||||
QTest::qWait(1000);
|
||||
QTest::qWait(500);
|
||||
|
||||
QVERIFY(dlg->findChild<QPushButton*>("nextButton")->isEnabled());
|
||||
QVERIFY(next->isEnabled());
|
||||
QVERIFY(!dlg->findChild<QPushButton*>("finishButton")->isEnabled());
|
||||
|
||||
QVERIFY(QFile::exists("test1.fw"));
|
||||
@ -356,12 +483,19 @@ void instDialogInstallTest::testInstall2()
|
||||
testfile.close();
|
||||
testfile.setPermissions(testfile.permissions() | QFile::ExeOwner);
|
||||
|
||||
QTimer::singleShot(200, this, SLOT(testInstall1_part2()));
|
||||
dlg->findChild<QPushButton*>("nextButton")->click();
|
||||
// now runs testInstall_part2 and fills install options dialog
|
||||
QTimer::singleShot(200, this, SLOT(instOptionsForTest2()));
|
||||
|
||||
next->click();
|
||||
QTest::qWait(500);
|
||||
|
||||
waited = 0;
|
||||
while (!checkProgress(list))
|
||||
{
|
||||
QVERIFY(back->isEnabled() == false);
|
||||
QVERIFY(next->isEnabled() == false);
|
||||
QVERIFY(cancel->isEnabled() == true);
|
||||
QVERIFY2(finish->isEnabled() == false, "Button Finish is enabled during operation");
|
||||
|
||||
QTest::qWait(500);
|
||||
waited += 500;
|
||||
QVERIFY(waited < 10000);
|
||||
@ -375,16 +509,40 @@ void instDialogInstallTest::testInstall2()
|
||||
setenv("SSH_AUTH_SOCK", ssh_auth_sock, 1);
|
||||
QString text = dlg->findChild<QTextBrowser*>("procLogDisplay")->toPlainText();
|
||||
QVERIFY(!text.isEmpty());
|
||||
|
||||
// foreach(QString line, text.split("\n"))
|
||||
// qDebug() << line;
|
||||
|
||||
QVERIFY(text.contains("lost connection"));
|
||||
QVERIFY(text.contains("SSH session terminated, exit status: 1"));
|
||||
|
||||
dlg->reject();
|
||||
QTest::qWait(1000);
|
||||
QTest::qWait(500);
|
||||
|
||||
qDebug() << "Test 2 done";
|
||||
}
|
||||
|
||||
/*
|
||||
* Another kind of error is a timeout.
|
||||
|
||||
* To simulate timeout repeat the test with an ip address that does
|
||||
* not exist. Ssh should time out after some considerable time with
|
||||
* appropriate error message in the output. Check for this message
|
||||
* and make sure at that point button "Finish" is enabled and status
|
||||
* is "Failed" (or is it "Error" ? )
|
||||
|
||||
* this test also tests custom scp command line argument
|
||||
* addition. The argument is ConnectTimeout, we both test the code
|
||||
* path that adds custom arguments for scp and make the test run
|
||||
* faster by shirtening the timeout.
|
||||
|
||||
*/
|
||||
void instDialogInstallTest::testInstall3()
|
||||
{
|
||||
qDebug() << "Test 3 begins";
|
||||
|
||||
resetDialogs();
|
||||
|
||||
removeFiles();
|
||||
Firewall *test1 = NULL;
|
||||
foreach(FWObject *fw, mw->db()->getByTypeDeep(Firewall::TYPENAME))
|
||||
@ -396,21 +554,34 @@ void instDialogInstallTest::testInstall3()
|
||||
}
|
||||
}
|
||||
QVERIFY(test1 != NULL);
|
||||
|
||||
// reset additional args for scp and ssh
|
||||
FWOptions *fwoptions = test1->getOptionsObject();
|
||||
fwoptions->setStr("scpArgs", "");
|
||||
fwoptions->setStr("sshArgs", "");
|
||||
|
||||
fwoptions->setStr("firewall_dir", (QDir::currentPath()+"/test_install").toStdString());
|
||||
|
||||
// reduce timeout time to make test run faster
|
||||
fwoptions->setStr("scpArgs", "-o ConnectTimeout=2");
|
||||
|
||||
mw->findChild<QAction*>("installAction")->trigger();
|
||||
QTest::qWait(500);
|
||||
|
||||
instDialog *dlg = mw->findChild<instDialog*>();
|
||||
dlg->findChild<QPushButton*>("pushButton17")->click();
|
||||
|
||||
QPushButton *back = dlg->findChild<QPushButton*>("backButton");
|
||||
QPushButton *next = dlg->findChild<QPushButton*>("nextButton");
|
||||
QPushButton *finish = dlg->findChild<QPushButton*>("finishButton");
|
||||
QPushButton *cancel = dlg->findChild<QPushButton*>("cancelButton");
|
||||
|
||||
QTreeWidget *selectTable = dlg->findChild<QTreeWidget*>("selectTable");
|
||||
QTreeWidgetItem *test1item = selectTable->findItems("test1", Qt::MatchExactly | Qt::MatchRecursive, 0).first();
|
||||
test1item->setCheckState(1, Qt::Checked);
|
||||
test1item->setCheckState(2, Qt::Checked);
|
||||
QTest::qWait(500);
|
||||
dlg->findChild<QPushButton*>("nextButton")->click();
|
||||
next->click();
|
||||
|
||||
QTreeWidget *list= dlg->findChild<QTreeWidget*>("fwWorkList");
|
||||
|
||||
@ -418,6 +589,11 @@ void instDialogInstallTest::testInstall3()
|
||||
|
||||
while (!checkProgress(list))
|
||||
{
|
||||
QVERIFY(back->isEnabled() == false);
|
||||
QVERIFY(next->isEnabled() == false);
|
||||
QVERIFY(cancel->isEnabled() == true);
|
||||
QVERIFY2(finish->isEnabled() == false, "Button Finish is enabled during operation");
|
||||
|
||||
QTest::qWait(500);
|
||||
waited += 500;
|
||||
QVERIFY(waited < 10000);
|
||||
@ -427,8 +603,8 @@ void instDialogInstallTest::testInstall3()
|
||||
|
||||
QTest::qWait(500);
|
||||
|
||||
QVERIFY(dlg->findChild<QPushButton*>("nextButton")->isEnabled());
|
||||
QVERIFY(!dlg->findChild<QPushButton*>("finishButton")->isEnabled());
|
||||
QVERIFY(next->isEnabled());
|
||||
QVERIFY(!finish->isEnabled());
|
||||
|
||||
QVERIFY(QFile::exists("test1.fw"));
|
||||
QVERIFY(QFile::remove("test1.fw"));
|
||||
@ -438,12 +614,19 @@ void instDialogInstallTest::testInstall3()
|
||||
testfile.close();
|
||||
testfile.setPermissions(testfile.permissions() | QFile::ExeOwner);
|
||||
|
||||
QTimer::singleShot(200, this, SLOT(testInstall3_part2()));
|
||||
dlg->findChild<QPushButton*>("nextButton")->click();
|
||||
// now runs testInstall_part2 and fills install options dialog
|
||||
QTimer::singleShot(200, this, SLOT(instOptionsForTest3()));
|
||||
|
||||
next->click();
|
||||
QTest::qWait(500);
|
||||
|
||||
waited = 0;
|
||||
while (!checkProgress(list))
|
||||
{
|
||||
QVERIFY(back->isEnabled() == false);
|
||||
QVERIFY(next->isEnabled() == false);
|
||||
QVERIFY(cancel->isEnabled() == true);
|
||||
QVERIFY2(finish->isEnabled() == false, "Button Finish is enabled during operation");
|
||||
|
||||
QTest::qWait(500);
|
||||
waited += 500;
|
||||
QVERIFY(waited < 1000000);
|
||||
@ -455,27 +638,38 @@ void instDialogInstallTest::testInstall3()
|
||||
}
|
||||
|
||||
QString text = dlg->findChild<QTextBrowser*>("procLogDisplay")->toPlainText();
|
||||
// check that additional scp command line argument was indeed used
|
||||
QVERIFY(text.contains("-o ConnectTimeout=2"));
|
||||
// check that ssh timed out as expected
|
||||
QVERIFY(text.contains("lost connection"));
|
||||
QVERIFY(text.contains("SSH session terminated, exit status: 1"));
|
||||
QVERIFY(!text.isEmpty());
|
||||
dlg->reject();
|
||||
QTest::qWait(1000);
|
||||
QTest::qWait(500);
|
||||
}
|
||||
|
||||
void instDialogInstallTest::testInstall3_part2() // sets install options in modal dialog
|
||||
{
|
||||
instOptionsDialog *optdlg = mw->findChild<instOptionsDialog*>("instOptionsDialog_q");
|
||||
QLineEdit *uname = optdlg->findChild<QLineEdit*>("uname");
|
||||
QLineEdit *pwd = optdlg->findChild<QLineEdit*>("pwd");
|
||||
QLineEdit *altAddress = optdlg->findChild<QLineEdit*>("altAddress");
|
||||
uname->setText("root");
|
||||
//uname->setText(getenv("USER"));
|
||||
altAddress->setText("1.2.3.4");
|
||||
optdlg->findChild<QPushButton*>("okButton")->click();
|
||||
}
|
||||
|
||||
void instDialogInstallTest::testInstall4()
|
||||
/*
|
||||
* Test cancellation.
|
||||
*
|
||||
* This function does two tests: it runs install but hits Cancel or Stop
|
||||
* button (per @button_name argument) to interrupt the process and then
|
||||
* checks that the dialog is still open or not (per @dialog_should_stay_open
|
||||
* arg)
|
||||
*
|
||||
* Repeat the test using address that does not exist but click
|
||||
* "Cancel" 1 sec after you start installation (this is too short for
|
||||
* the ssh timeout to occur). Wait after that until the line "Stopping
|
||||
* background process" appears, then check that the installer dialog
|
||||
* closes.
|
||||
*
|
||||
*/
|
||||
|
||||
void instDialogInstallTest::executeCancelAndStopTests(const QString &button_name,
|
||||
bool dialog_should_stay_open)
|
||||
{
|
||||
resetDialogs();
|
||||
|
||||
removeFiles();
|
||||
Firewall *test1 = NULL;
|
||||
foreach(FWObject *fw, mw->db()->getByTypeDeep(Firewall::TYPENAME))
|
||||
@ -487,7 +681,12 @@ void instDialogInstallTest::testInstall4()
|
||||
}
|
||||
}
|
||||
QVERIFY(test1 != NULL);
|
||||
|
||||
// reset additional args for scp and ssh
|
||||
FWOptions *fwoptions = test1->getOptionsObject();
|
||||
fwoptions->setStr("scpArgs", "");
|
||||
fwoptions->setStr("sshArgs", "");
|
||||
|
||||
fwoptions->setStr("firewall_dir", (QDir::currentPath()+"/test_install").toStdString());
|
||||
|
||||
mw->findChild<QAction*>("installAction")->trigger();
|
||||
@ -496,12 +695,17 @@ void instDialogInstallTest::testInstall4()
|
||||
instDialog *dlg = mw->findChild<instDialog*>();
|
||||
dlg->findChild<QPushButton*>("pushButton17")->click();
|
||||
|
||||
QPushButton *back = dlg->findChild<QPushButton*>("backButton");
|
||||
QPushButton *next = dlg->findChild<QPushButton*>("nextButton");
|
||||
QPushButton *finish = dlg->findChild<QPushButton*>("finishButton");
|
||||
QPushButton *cancel = dlg->findChild<QPushButton*>("cancelButton");
|
||||
|
||||
QTreeWidget *selectTable = dlg->findChild<QTreeWidget*>("selectTable");
|
||||
QTreeWidgetItem *test1item = selectTable->findItems("test1", Qt::MatchExactly | Qt::MatchRecursive, 0).first();
|
||||
test1item->setCheckState(1, Qt::Checked);
|
||||
test1item->setCheckState(2, Qt::Checked);
|
||||
QTest::qWait(500);
|
||||
dlg->findChild<QPushButton*>("nextButton")->click();
|
||||
next->click();
|
||||
|
||||
QTreeWidget *list= dlg->findChild<QTreeWidget*>("fwWorkList");
|
||||
|
||||
@ -509,6 +713,11 @@ void instDialogInstallTest::testInstall4()
|
||||
|
||||
while (!checkProgress(list))
|
||||
{
|
||||
QVERIFY(back->isEnabled() == false);
|
||||
QVERIFY(next->isEnabled() == false);
|
||||
QVERIFY(cancel->isEnabled() == true);
|
||||
QVERIFY2(finish->isEnabled() == false, "Button Finish is enabled during operation");
|
||||
|
||||
QTest::qWait(500);
|
||||
waited += 500;
|
||||
QVERIFY(waited < 10000);
|
||||
@ -520,8 +729,8 @@ void instDialogInstallTest::testInstall4()
|
||||
}
|
||||
QTest::qWait(500);
|
||||
|
||||
QVERIFY(dlg->findChild<QPushButton*>("nextButton")->isEnabled());
|
||||
QVERIFY(!dlg->findChild<QPushButton*>("finishButton")->isEnabled());
|
||||
QVERIFY(next->isEnabled());
|
||||
QVERIFY(!finish->isEnabled());
|
||||
|
||||
QVERIFY(QFile::exists("test1.fw"));
|
||||
QVERIFY(QFile::remove("test1.fw"));
|
||||
@ -531,14 +740,34 @@ void instDialogInstallTest::testInstall4()
|
||||
testfile.close();
|
||||
testfile.setPermissions(testfile.permissions() | QFile::ExeOwner);
|
||||
|
||||
QTimer::singleShot(200, this, SLOT(testInstall3_part2()));
|
||||
dlg->findChild<QPushButton*>("nextButton")->click();
|
||||
// now runs testInstall_part2 and fills install options dialog
|
||||
QTimer::singleShot(200, this, SLOT(instOptionsForTest4()));
|
||||
|
||||
next->click();
|
||||
|
||||
QTest::qWait(1000);
|
||||
dlg->findChild<QPushButton*>("cancelButton")->click();
|
||||
// Now click button to interrupt the process
|
||||
dlg->findChild<QPushButton*>(button_name)->click();
|
||||
QTest::qWait(2000);
|
||||
|
||||
QString text = dlg->findChild<QTextBrowser*>("procLogDisplay")->toPlainText();
|
||||
QVERIFY(text.contains("Stopping background process"));
|
||||
QTest::qWait(3000);
|
||||
QVERIFY(mw->findChild<instDialog*>()->isVisible() == false); // check that dialog is closed
|
||||
QTest::qWait(1000);
|
||||
QTest::qWait(500);
|
||||
QVERIFY(mw->findChild<instDialog*>()->isVisible() == dialog_should_stay_open);
|
||||
QTest::qWait(500);
|
||||
}
|
||||
|
||||
|
||||
void instDialogInstallTest::testInstall4()
|
||||
{
|
||||
executeCancelAndStopTests("cancelButton", false);
|
||||
}
|
||||
|
||||
/*
|
||||
* Test "Stop" button. This is just like "Cancel", except the dialog
|
||||
* stays open.
|
||||
*
|
||||
*/
|
||||
void instDialogInstallTest::testInstall5()
|
||||
{
|
||||
executeCancelAndStopTests("stopButton", true);
|
||||
}
|
||||
|
||||
@ -27,25 +27,32 @@
|
||||
#define INSTDIALOGTEST_H
|
||||
|
||||
#include <QTest>
|
||||
#include "newClusterDialog.h"
|
||||
#include "upgradePredicate.h"
|
||||
|
||||
#include "FWBTree.h"
|
||||
#include "fwbuilder/Library.h"
|
||||
#include "instDialog.h"
|
||||
#include "FWWindow.h"
|
||||
#include "ObjectTreeView.h"
|
||||
#include "ObjectTreeViewItem.h"
|
||||
#include "events.h"
|
||||
#include "fwbuilder/Firewall.h"
|
||||
#include "fwbuilder/Library.h"
|
||||
#include "fwbuilder/Policy.h"
|
||||
#include "instDialog.h"
|
||||
#include "newClusterDialog.h"
|
||||
#include "upgradePredicate.h"
|
||||
|
||||
class instDialogInstallTest : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT;
|
||||
const char *ssh_auth_sock;
|
||||
void removeFiles();
|
||||
void verifyInstallSuccess(const QString &test_name);
|
||||
|
||||
void resetDialogs();
|
||||
void fillInstOptionsDialog(const QString &user_name,
|
||||
const QString &pwd,
|
||||
const QString &alt_address,
|
||||
bool verbose);
|
||||
void executeCancelAndStopTests(const QString &button_name,
|
||||
bool dialog_should_stay_open);
|
||||
|
||||
private slots:
|
||||
void initTestCase();
|
||||
@ -54,11 +61,15 @@ private slots:
|
||||
void testInstall2();
|
||||
void testInstall3();
|
||||
void testInstall4();
|
||||
void testInstall5();
|
||||
|
||||
public slots:
|
||||
void testInstall1_part2();
|
||||
void testInstall3_part2();
|
||||
|
||||
void instOptionsForTest1();
|
||||
void instOptionsForTest2();
|
||||
void instOptionsForTest3();
|
||||
void instOptionsForTest4();
|
||||
void instOptionsForTest5();
|
||||
|
||||
};
|
||||
|
||||
#endif // INSTDIALOGTEST_H
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user