diff --git a/build_num b/build_num index 007e57ccb..fda7e7cb4 100644 --- a/build_num +++ b/build_num @@ -1 +1 @@ -#define BUILD_NUM 3120 +#define BUILD_NUM 3124 diff --git a/src/gui/InterfaceEditorWidget.cpp b/src/gui/InterfaceEditorWidget.cpp index fff77a664..488f38443 100644 --- a/src/gui/InterfaceEditorWidget.cpp +++ b/src/gui/InterfaceEditorWidget.cpp @@ -418,7 +418,6 @@ void InterfaceEditorWidget::resizeEvent ( QResizeEvent * ) void InterfaceEditorWidget::addressChanged(int row, int col) { - qDebug() << m_ui->addresses->rowCount(); if (m_ui->addresses->rowCount() >= 1) m_ui->addAddress->setText(tr("Add another address")); else diff --git a/src/gui/unit_tests/DiscoveryDruidTest/DiscoveryDruidTest.cpp b/src/gui/unit_tests/DiscoveryDruidTest/DiscoveryDruidTest.cpp new file mode 100644 index 000000000..391bcfdf5 --- /dev/null +++ b/src/gui/unit_tests/DiscoveryDruidTest/DiscoveryDruidTest.cpp @@ -0,0 +1,152 @@ +/* + + Firewall Builder + + Copyright (C) 2010 NetCitadel, LLC + + Author: Roman Bovsunivskiy a2k0001@gmail.com + + $Id: DiscoveryDruidTest.cpp 2786 2010-04-01 14:05:36Z a2k $ + + This program is free software which we release under the GNU General Public + License. You may redistribute and/or modify this program under the terms + of that license as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + To get a copy of the GNU General Public License, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +*/ + +#include "DiscoveryDruidTest.h" + +#include "unistd.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include "FWObjectClipboard.h" +#include "FWBApplication.h" +#include "DiscoveryDruid.h" + +using namespace std; +using namespace QTest; +using namespace libfwbuilder; + + +void DiscoveryDruidTest::initTestCase() +{ + mw = new FWWindow(); + mw->show(); + mw->startupLoad(); + new FWObjectClipboard(); +} + +void DiscoveryDruidTest::cleanupTestCase() +{ + if (QFileInfo("result.fwb").exists()) + QVERIFY(QFile::remove("result.fwb")); +} + +void DiscoveryDruidTest::compareFwbFiles(QString expected_result_file_name, + QString obtained_result_file_name) +{ + QStringList obtained_result; + + QFile rr(obtained_result_file_name); + rr.open(QFile::ReadOnly); + QString result_file = rr.readAll(); + rr.close(); + obtained_result = result_file.split("\n"); + + QFile er(expected_result_file_name); + er.open(QFile::ReadOnly); + result_file = er.readAll(); + er.close(); + QStringList expected_result = result_file.split("\n"); + + // find all lastModified attributes and replace them with identical values + // because they are always going to be different + Q_ASSERT_X(expected_result.size() == obtained_result.size(), "result comparison", + "Sizes of the generated .fwb and test files are different"); + + QRegExp last_mod_re("lastModified=\"\\d+\""); + QRegExp id_re("id=\"\\w+\""); + int max_idx = max(expected_result.size(), obtained_result.size()); + for (int i=0; i < max_idx; ++i) + { + QString os = obtained_result[i]; + obtained_result[i] = os.replace(last_mod_re, "lastModified=\"0000000000\"") + .remove(id_re); + + QString es = expected_result[i]; + expected_result[i] = es.replace(last_mod_re, "lastModified=\"0000000000\"") + .remove(id_re); + } + + for (int i=0; i < max_idx; ++i) + { + QString err = QString("Line %1:\nExpected: '%2'\nResult: '%3'\n") + .arg(i).arg(expected_result[i]).arg(obtained_result[i]); + Q_ASSERT_X(expected_result[i] == obtained_result[i], "result comparison", err.toUtf8().constData()); + } +} + +void DiscoveryDruidTest::testHostsImportDialog() +{ + DiscoveryDruid *dlg = dynamic_cast(app->activeModalWidget()); + QVERIFY(dlg!=NULL); + + QPushButton *next = dlg->findChild("nextButton"); + QPushButton *finish = dlg->findChild("finishButton"); + + // Selecting "Read file in hosts format" radio button + QTest::mouseClick(dlg->findChild("dm_fromfile"), Qt::LeftButton, 0, QPoint(5,5)); + QTest::mouseClick(next, Qt::LeftButton); + + dlg->findChild("filename")->setText("test.hosts"); + + QTest::mouseClick(next, Qt::LeftButton); + + // Waiting for parsing to wait. We are using small and simple hosts + // file, so it should not take more than 1 second + QTest::qWait(1000); + QVERIFY(next->isEnabled()); + QTest::mouseClick(next, Qt::LeftButton); + + QListWidget *unused = dlg->findChild("objectresultlist"); + QVERIFY(unused->count() == 3); + unused->selectAll(); + QTest::mouseClick(dlg->findChild("addObjButton"), Qt::LeftButton); + QVERIFY(dlg->findChild("objectlist")->count() == 3); + QTest::mouseClick(next, Qt::LeftButton); + QTest::mouseClick(next, Qt::LeftButton); // using default library ("User") + + QVERIFY(finish->isEnabled()); // it should be enabled if everything is ok + QTest::mouseClick(finish, Qt::LeftButton); + // hosts should be imported to "User" database now and dialog is closed +} + +void DiscoveryDruidTest::testHostsImport() +{ + // Dialog is modal, so we have to test it in another thread + QTimer::singleShot(100, this, SLOT(testHostsImportDialog())); + mw->findChild("DiscoveryDruidAction")->trigger(); + + // this is running after import dialog is closed + mw->activeProject()->setFileName("result.fwb"); + mw->activeProject()->save(); + + compareFwbFiles("output.fwb", "result.fwb"); +} + diff --git a/src/gui/unit_tests/DiscoveryDruidTest/DiscoveryDruidTest.h b/src/gui/unit_tests/DiscoveryDruidTest/DiscoveryDruidTest.h new file mode 100644 index 000000000..8b5fc64d5 --- /dev/null +++ b/src/gui/unit_tests/DiscoveryDruidTest/DiscoveryDruidTest.h @@ -0,0 +1,58 @@ +/* + + Firewall Builder + + Copyright (C) 2010 NetCitadel, LLC + + Author: Roman Bovsunivskiy a2k0001@gmail.com + + $Id: DiscoveryDruidTest.h 2786 2010-04-01 14:05:36Z a2k $ + + This program is free software which we release under the GNU General Public + License. You may redistribute and/or modify this program under the terms + of that license as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + To get a copy of the GNU General Public License, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +*/ + +#ifndef INSTDIALOGTEST_H +#define INSTDIALOGTEST_H + +#include + +#include "FWBTree.h" +#include "FWWindow.h" +#include "ObjectManipulator.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 DiscoveryDruidTest : public QObject +{ + Q_OBJECT; + void compareFwbFiles(QString expected_result_file_name, + QString obtained_result_file_name); +private slots: + void initTestCase(); + void cleanupTestCase(); + + void testHostsImport(); +public slots: + void testHostsImportDialog(); +}; + +#endif // INSTDIALOGTEST_H diff --git a/src/gui/unit_tests/DiscoveryDruidTest/DiscoveryDruidTest.pro b/src/gui/unit_tests/DiscoveryDruidTest/DiscoveryDruidTest.pro new file mode 100644 index 000000000..cd8c9879f --- /dev/null +++ b/src/gui/unit_tests/DiscoveryDruidTest/DiscoveryDruidTest.pro @@ -0,0 +1,105 @@ +# ------------------------------------------------- +# Project created by QtCreator 2009-12-29T12:59:35 +# ------------------------------------------------- + +include(../../../../qmake.inc) +INCLUDEPATH += ../.. + +QT += testlib network gui +TARGET = DiscoveryDruidTest +CONFIG += console +CONFIG -= app_bundle +TEMPLATE = app +SOURCES += main_DiscoveryDruidTest.cpp \ + DiscoveryDruidTest.cpp + +HEADERS += DiscoveryDruidTest.h + +RESOURCES += ../../MainRes.qrc +CONFIG -= release +CONFIG += debug +RESOURCES += ../../MainRes.qrc +LIBS += ../guilib/libguilib.a +LIBS += $$LIBS_FWCOMPILER $$LIBS_FWBUILDER $$CPPUNIT_LIBS +OBJECTS_DIR = ../../.obj +MOC_DIR = ../../.moc + +INCLUDEPATH += ../../.ui +INCLUDEPATH += ../../../compiler_lib +INCLUDEPATH += ../../../iptlib +INCLUDEPATH += ../../../.. \ +../../../cisco_lib \ +../../../pflib \ +../../.. + +DEPENDPATH = ../../../common + +!win32:LIBS += ../../../common/libcommon.a +!win32:PRE_TARGETDEPS = ../../../common/libcommon.a + +win32:CONFIG += console + +win32:LIBS += ../../../common/release/common.lib +win32:PRE_TARGETDEPS = ../../../common/release/common.lib + + + +run_tests.commands = echo "Running tests..."; \ + cp -f test.fwb test_work.fwb; \ + ./${TARGET}; \ + rm -f test_work.fwb +run_tests.depends = build_tests +build_tests.depends = all +clean_tests.depends = all +QMAKE_EXTRA_TARGETS += run_tests build_tests clean_tests + + +INCLUDEPATH += $$ANTLR_INCLUDEPATH +LIBS += ../../$$FWBPARSER_LIB $$ANTLR_LIBS +DEFINES += $$ANTLR_DEFINES + +LIBS += $$LIBS_FWCOMPILER + +# fwtransfer lib. Add this before adding -lQtDBus to LIBS below +LIBS += ../../$$FWTRANSFER_LIB +contains( HAVE_QTDBUS, 1 ):unix { + !macx:QT += network \ + dbus + macx:LIBS += -framework \ + QtDBus +} + +HEADERS += ../../transferDialog.h +SOURCES += ../../transferDialog.cpp + +# !macx:LIBS += -lQtDBus # workaround for QT += dbus not working with Qt < 4.4.0 +INCLUDEPATH += ../../../common \ + ../../../iptlib \ + ../../../pflib \ + ../../../cisco_lib/ \ + ../../../compiler_lib/ +DEPENDPATH = ../../../common \ + ../../../iptlib \ + ../../../pflib \ + ../../../cisco_lib/ \ + ../../../compiler_lib +win32:LIBS += ../../../common/release/common.lib \ + ../../../iptlib/release/iptlib.lib \ + ../../../pflib/release/fwbpf.lib \ + ../../../cisco_lib/release/fwbcisco.lib \ + ../../../compiler_lib/release/compilerdriver.lib +!win32:LIBS += ../../../common/libcommon.a \ + ../../../iptlib/libiptlib.a \ + ../../../pflib/libfwbpf.a \ + ../../../cisco_lib/libfwbcisco.a \ + ../../../compiler_lib/libcompilerdriver.a +win32:PRE_TARGETDEPS = ../../../common/release/common.lib \ + ../../../iptlib/release/iptlib.lib \ + ../../../pflib/release/fwbpf.lib \ + ../../../cisco_lib/release/fwbcisco.lib \ + ../../../compiler_lib/release/compilerdriver.lib +!win32:PRE_TARGETDEPS = ../../../common/libcommon.a \ + ../../../iptlib/libiptlib.a \ + ../../../pflib/libfwbpf.a \ + ../../../cisco_lib/libfwbcisco.a \ + ../../../compiler_lib/libcompilerdriver.a diff --git a/src/gui/unit_tests/DiscoveryDruidTest/main_DiscoveryDruidTest.cpp b/src/gui/unit_tests/DiscoveryDruidTest/main_DiscoveryDruidTest.cpp new file mode 100644 index 000000000..8737bbe7f --- /dev/null +++ b/src/gui/unit_tests/DiscoveryDruidTest/main_DiscoveryDruidTest.cpp @@ -0,0 +1,30 @@ +/* + + Firewall Builder + + Copyright (C) 2010 NetCitadel, LLC + + Author: Roman Bovsunivskiy a2k0001@gmail.com + + $Id: main_DiscoveryDruidTest.cpp 2707 2010-03-10 18:22:19Z a2k $ + + This program is free software which we release under the GNU General Public + License. You may redistribute and/or modify this program under the terms + of that license as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + To get a copy of the GNU General Public License, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +*/ + +#include "DiscoveryDruidTest.h" +#include "../main/main_macros.cpp" + + +RUN_TEST(new DiscoveryDruidTest()); diff --git a/src/gui/unit_tests/DiscoveryDruidTest/output.fwb b/src/gui/unit_tests/DiscoveryDruidTest/output.fwb new file mode 100644 index 000000000..76aa474bd --- /dev/null +++ b/src/gui/unit_tests/DiscoveryDruidTest/output.fwb @@ -0,0 +1,447 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + established + + established + -m state --state ESTABLISHED,RELATED + established + + + + established + + established + -m state --state ESTABLISHED,RELATED + established + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + -m record_rpc + + + + + + + + + + -m irc + + + + + + + + + + -m psd --psd-weight-threshold 5 --psd-delay-threshold 10000 + + + + + + + + + + -m string --string test_pattern + + + + + + + + + + -m talk + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/gui/unit_tests/DiscoveryDruidTest/test.hosts b/src/gui/unit_tests/DiscoveryDruidTest/test.hosts new file mode 100644 index 000000000..348c3d131 --- /dev/null +++ b/src/gui/unit_tests/DiscoveryDruidTest/test.hosts @@ -0,0 +1,5 @@ +192.168.1.1 host1 +192.168.1.2 host2 +# comment +192.168.1.3 host3 +