diff --git a/cmake/FindCppUnit.cmake b/cmake/FindCppUnit.cmake deleted file mode 100644 index b038ad467..000000000 --- a/cmake/FindCppUnit.cmake +++ /dev/null @@ -1,48 +0,0 @@ -# -# Find the CppUnit includes and library -# -# This module defines -# CPPUNIT_INCLUDE_DIR, where to find tiff.h, etc. -# CPPUNIT_LIBRARIES, the libraries to link against to use CppUnit. -# CPPUNIT_FOUND, If false, do not try to use CppUnit. - -# also defined, but not for general use are -# CPPUNIT_LIBRARY, where to find the CppUnit library. -# CPPUNIT_DEBUG_LIBRARY, where to find the CppUnit library in debug mode. - -FIND_PATH(CPPUNIT_INCLUDE_DIR cppunit/TestCase.h HINTS - /usr/local/include - /usr/include - ENV CppUnit_ROOT - ) - -# With Win32, important to have both -IF(WIN32) - FIND_LIBRARY(CPPUNIT_LIBRARY cppunit - ${CPPUNIT_INCLUDE_DIR}/../lib - /usr/local/lib - /usr/lib) - FIND_LIBRARY(CPPUNIT_DEBUG_LIBRARY cppunitd - ${CPPUNIT_INCLUDE_DIR}/../lib - /usr/local/lib - /usr/lib) -ELSE(WIN32) -# On unix system, debug and release have the same name - FIND_LIBRARY(CPPUNIT_LIBRARY cppunit - ${CPPUNIT_INCLUDE_DIR}/../lib - /usr/local/lib - /usr/lib) - FIND_LIBRARY(CPPUNIT_DEBUG_LIBRARY cppunit - ${CPPUNIT_INCLUDE_DIR}/../lib - /usr/local/lib - /usr/lib) -ENDIF(WIN32) - - IF(CPPUNIT_INCLUDE_DIR) -IF(CPPUNIT_LIBRARY) - SET(CPPUNIT_FOUND "YES") -SET(CPPUNIT_LIBRARIES ${CPPUNIT_LIBRARY} ${CMAKE_DL_LIBS}) - SET(CPPUNIT_DEBUG_LIBRARIES ${CPPUNIT_DEBUG_LIBRARY} - ${CMAKE_DL_LIBS}) - ENDIF(CPPUNIT_LIBRARY) -ENDIF(CPPUNIT_INCLUDE_DIR) diff --git a/src/unit_tests/AddressRangeDialogTest/CMakeLists.txt b/src/unit_tests/AddressRangeDialogTest/CMakeLists.txt index 2ef40b287..ef95e43ed 100644 --- a/src/unit_tests/AddressRangeDialogTest/CMakeLists.txt +++ b/src/unit_tests/AddressRangeDialogTest/CMakeLists.txt @@ -3,4 +3,4 @@ SET(CMAKE_AUTOMOC ON) add_executable(AddressRangeDialogTest AddressRangeDialogTest.cpp main_AddressRangeDialogTest.cpp) add_test(NAME AddressRangeDialogTest COMMAND AddressRangeDialogTest) -target_link_libraries(AddressRangeDialogTest PRIVATE test_main netsnmp gui import fwbparser antlr common iptlib fwbpf fwbjuniper fwbcisco compilerdriver fwcompiler fwbuilder xml2 xslt z pthread Qt5::Test) +target_link_libraries(AddressRangeDialogTest PRIVATE test_main gui import fwbparser antlr common iptlib fwbpf fwbjuniper fwbcisco compilerdriver fwcompiler fwbuilder netsnmp xml2 xslt z pthread Qt5::Test) diff --git a/src/unit_tests/AddressRangeDialogTest/main_AddressRangeDialogTest.cpp b/src/unit_tests/AddressRangeDialogTest/main_AddressRangeDialogTest.cpp index c52b948a7..e3de3c9a3 100644 --- a/src/unit_tests/AddressRangeDialogTest/main_AddressRangeDialogTest.cpp +++ b/src/unit_tests/AddressRangeDialogTest/main_AddressRangeDialogTest.cpp @@ -37,10 +37,10 @@ using namespace std; using namespace libfwbuilder; int fwbdebug = 0; -FWWindow *mw = nullptr; -FWBSettings *st = nullptr; -FWBApplication *app = nullptr; - +FWWindow *mw = nullptr; +FWBSettings *st = nullptr; +FWBApplication *app = nullptr; + extern void build_app(int argc, char** argv, @@ -48,15 +48,17 @@ extern void build_app(int argc, char** argv, FWBSettings** st); int main(int argc, char** argv) -{ - app = new FWBApplication(argc, argv); - app->setOrganizationName(QLatin1String("NetCitadel")); - app->setApplicationName(QLatin1String("Firewall Builder")); +{ + app = new FWBApplication(argc, argv); + app->setOrganizationName(QLatin1String("NetCitadel")); + app->setApplicationName(QLatin1String("Firewall Builder")); build_app(argc, argv, &app, &st); - QTest::qExec(new AddressRangeDialogTest()); + int testResult = QTest::qExec(new AddressRangeDialogTest()); - if (QFile::exists("test_work.fwb")) - QFile::remove("test_work.fwb"); + if (QFile::exists("test_work.fwb")) + QFile::remove("test_work.fwb"); + + return testResult; } diff --git a/src/unit_tests/AddressTableTest/AddressTableTest.cpp b/src/unit_tests/AddressTableTest/AddressTableTest.cpp index 14582a8de..1db2cc49d 100644 --- a/src/unit_tests/AddressTableTest/AddressTableTest.cpp +++ b/src/unit_tests/AddressTableTest/AddressTableTest.cpp @@ -23,8 +23,9 @@ */ -#include "AddressTableTest.h" +#include +#include "AddressTableTest.h" #include "fwbuilder/Resources.h" @@ -46,7 +47,7 @@ using namespace libfwbuilder; -void AddressTableTest::setUp() +void AddressTableTest::init() { objdb = new FWObjectDatabase(); @@ -63,6 +64,11 @@ void AddressTableTest::setUp() o1->add(address_tables_group); } +void AddressTableTest::cleanup() +{ + delete objdb; +} + void AddressTableTest::positiveTest() { setStrings addrres; @@ -82,7 +88,7 @@ void AddressTableTest::positiveTest() addrset.insert("192.168.100.0/255.255.255.0"); addrset.insert("192.168.11.0/255.255.255.0"); - CPPUNIT_ASSERT(address_tables_group!=nullptr); + QVERIFY(address_tables_group!=nullptr); AddressTable *nobj = AddressTable::cast(objdb->create(AddressTable::TYPENAME, true)); @@ -98,13 +104,13 @@ void AddressTableTest::positiveTest() for ( ; t != nobj->end(); ++t ) { ref = FWReference::cast(*t); - CPPUNIT_ASSERT(ref!=nullptr); + QVERIFY(ref!=nullptr); net = Network::cast(ref->getPointer()); - CPPUNIT_ASSERT(net!=nullptr); + QVERIFY(net!=nullptr); addrres.insert(net->getAddressPtr()->toString() + "/" + net->getNetmaskPtr()->toString()); } - CPPUNIT_ASSERT(addrset==addrres); + QVERIFY(addrset==addrres); } @@ -112,27 +118,27 @@ void AddressTableTest::negativeTest1() { setStrings addrres; - CPPUNIT_ASSERT(address_tables_group!=nullptr); + QVERIFY(address_tables_group!=nullptr); AddressTable *nobj = AddressTable::cast(objdb->create(AddressTable::TYPENAME, true)); address_tables_group->add(nobj); nobj->setName("TestADT2"); nobj->setSourceName("addresstable-2.txt"); - CPPUNIT_ASSERT_THROW(nobj->loadFromSource(false, nullptr, true), FWException); + QVERIFY_EXCEPTION_THROWN(nobj->loadFromSource(false, nullptr, true), FWException); } void AddressTableTest::negativeTest2() { setStrings addrres; - CPPUNIT_ASSERT(address_tables_group!=nullptr); + QVERIFY(address_tables_group!=nullptr); AddressTable *nobj = AddressTable::cast(objdb->create(AddressTable::TYPENAME, true)); address_tables_group->add(nobj); nobj->setName("TestADT3"); nobj->setSourceName("addresstable-not-found.txt"); - CPPUNIT_ASSERT_THROW(nobj->loadFromSource(false, nullptr, true), FWException); + QVERIFY_EXCEPTION_THROWN(nobj->loadFromSource(false, nullptr, true), FWException); } diff --git a/src/unit_tests/AddressTableTest/AddressTableTest.h b/src/unit_tests/AddressTableTest/AddressTableTest.h index 64e172851..ed58de645 100644 --- a/src/unit_tests/AddressTableTest/AddressTableTest.h +++ b/src/unit_tests/AddressTableTest/AddressTableTest.h @@ -27,29 +27,26 @@ #ifndef ADDRESSTABLETEST_H #define ADDRESSTABLETEST_H +#include #include "fwbuilder/FWObjectDatabase.h" #include #include -#include - typedef std::set > setStrings; -class AddressTableTest : public CppUnit::TestFixture +class AddressTableTest : public QObject { + Q_OBJECT + libfwbuilder::FWObjectDatabase *objdb; libfwbuilder::FWObject *address_tables_group; - CPPUNIT_TEST_SUITE(AddressTableTest); - CPPUNIT_TEST(positiveTest); - CPPUNIT_TEST(negativeTest1); - CPPUNIT_TEST(negativeTest2); - CPPUNIT_TEST_SUITE_END(); +private slots: + void init(); + void cleanup(); -public: - void setUp(); void positiveTest(); void negativeTest1(); void negativeTest2(); diff --git a/src/unit_tests/AddressTableTest/CMakeLists.txt b/src/unit_tests/AddressTableTest/CMakeLists.txt index 7ff4348ea..3a249dc74 100644 --- a/src/unit_tests/AddressTableTest/CMakeLists.txt +++ b/src/unit_tests/AddressTableTest/CMakeLists.txt @@ -3,7 +3,7 @@ SET(CMAKE_AUTOMOC ON) add_executable(AddressTableTest AddressTableTest.cpp main.cpp) add_test(NAME AddressTableTest COMMAND AddressTableTest) -target_link_libraries(AddressTableTest PRIVATE test_main netsnmp gui import fwbparser antlr common iptlib fwbpf fwbjuniper fwbcisco compilerdriver fwcompiler fwbuilder xml2 xslt z pthread cppunit) +target_link_libraries(AddressTableTest PRIVATE test_main netsnmp gui import fwbparser antlr common iptlib fwbpf fwbjuniper fwbcisco compilerdriver fwcompiler fwbuilder xml2 xslt z pthread Qt5::Test) file(COPY addresstable-1.txt addresstable-2.txt DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) diff --git a/src/unit_tests/AddressTableTest/main.cpp b/src/unit_tests/AddressTableTest/main.cpp index 125918024..8cb95c4f9 100644 --- a/src/unit_tests/AddressTableTest/main.cpp +++ b/src/unit_tests/AddressTableTest/main.cpp @@ -22,9 +22,8 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +#include -#include -#include #include "AddressTableTest.h" #include "fwbuilder/FWObjectDatabase.h" @@ -33,13 +32,7 @@ int fwbdebug = 0; std::string platform; -int main( int, char** argv) +int main() { - CppUnit::TextUi::TestRunner runner; - runner.addTest( AddressTableTest::suite() ); - runner.setOutputter( new CppUnit::CompilerOutputter( &runner.result(), - std::cerr ) ); - - runner.run(); - return 0; + return QTest::qExec(new AddressTableTest()); } diff --git a/src/unit_tests/CMakeLists.txt b/src/unit_tests/CMakeLists.txt index b2a50ccd6..120f7ac43 100644 --- a/src/unit_tests/CMakeLists.txt +++ b/src/unit_tests/CMakeLists.txt @@ -1,6 +1,5 @@ include( CTest ) -find_package(CppUnit REQUIRED) find_package(Qt5Test REQUIRED) enable_testing(TRUE) diff --git a/src/unit_tests/CustomServiceDialogTest/CMakeLists.txt b/src/unit_tests/CustomServiceDialogTest/CMakeLists.txt index 1d74decc0..eb318f671 100644 --- a/src/unit_tests/CustomServiceDialogTest/CMakeLists.txt +++ b/src/unit_tests/CustomServiceDialogTest/CMakeLists.txt @@ -3,4 +3,4 @@ SET(CMAKE_AUTOMOC ON) add_executable(CustomServiceDialogTest CustomServiceDialogTest.cpp main_CustomServiceDialogTest.cpp) add_test(NAME CustomServiceDialogTest COMMAND CustomServiceDialogTest) -target_link_libraries(CustomServiceDialogTest PRIVATE test_main netsnmp gui import fwbparser antlr common iptlib fwbpf fwbjuniper fwbcisco compilerdriver fwcompiler fwbuilder xml2 xslt z pthread Qt5::Test) +target_link_libraries(CustomServiceDialogTest PRIVATE test_main gui import fwbparser antlr common iptlib fwbpf fwbjuniper fwbcisco compilerdriver fwcompiler fwbuilder netsnmp xml2 xslt z pthread Qt5::Test) diff --git a/src/unit_tests/CustomServiceDialogTest/main_CustomServiceDialogTest.cpp b/src/unit_tests/CustomServiceDialogTest/main_CustomServiceDialogTest.cpp index 7cfd77792..00137a033 100644 --- a/src/unit_tests/CustomServiceDialogTest/main_CustomServiceDialogTest.cpp +++ b/src/unit_tests/CustomServiceDialogTest/main_CustomServiceDialogTest.cpp @@ -38,9 +38,9 @@ using namespace std; using namespace libfwbuilder; int fwbdebug = 0; -FWWindow *mw = nullptr; -FWBSettings *st = nullptr; -FWBApplication *app = nullptr; +FWWindow *mw = nullptr; +FWBSettings *st = nullptr; +FWBApplication *app = nullptr; extern void build_app(int argc, char** argv, @@ -48,16 +48,18 @@ extern void build_app(int argc, char** argv, FWBSettings** st); int main(int argc, char** argv) -{ - app = new FWBApplication(argc, argv); - app->setOrganizationName(QLatin1String("NetCitadel")); - app->setApplicationName(QLatin1String("Firewall Builder")); +{ + app = new FWBApplication(argc, argv); + app->setOrganizationName(QLatin1String("NetCitadel")); + app->setApplicationName(QLatin1String("Firewall Builder")); build_app(argc, argv, &app, &st); - QTest::qExec(new CustomServiceDialogTest()); + int testResult = QTest::qExec(new CustomServiceDialogTest()); - if (QFile::exists("test_work.fwb")) - QFile::remove("test_work.fwb"); + if (QFile::exists("test_work.fwb")) + QFile::remove("test_work.fwb"); + + return testResult; } diff --git a/src/unit_tests/DNSTest/CMakeLists.txt b/src/unit_tests/DNSTest/CMakeLists.txt index dfe8bba11..7440719c6 100644 --- a/src/unit_tests/DNSTest/CMakeLists.txt +++ b/src/unit_tests/DNSTest/CMakeLists.txt @@ -1,4 +1,6 @@ +SET(CMAKE_AUTOMOC ON) + add_executable(DNSTest DNSTest.cpp main.cpp) add_test(NAME DNSTest COMMAND DNSTest) -target_link_libraries(DNSTest PRIVATE test_main netsnmp gui import fwbparser antlr common iptlib fwbpf fwbjuniper fwbcisco compilerdriver fwcompiler fwbuilder xml2 xslt z pthread cppunit) +target_link_libraries(DNSTest PRIVATE test_main netsnmp gui import fwbparser antlr common iptlib fwbpf fwbjuniper fwbcisco compilerdriver fwcompiler fwbuilder xml2 xslt z pthread Qt5::Test) diff --git a/src/unit_tests/DNSTest/DNSTest.cpp b/src/unit_tests/DNSTest/DNSTest.cpp index ceb9420ad..4c5cb834e 100644 --- a/src/unit_tests/DNSTest/DNSTest.cpp +++ b/src/unit_tests/DNSTest/DNSTest.cpp @@ -23,6 +23,8 @@ */ +#include + #include "DNSTest.h" #include "fwbuilder/FWObjectDatabase.h" #include "fwbuilder/XMLTools.h" @@ -84,7 +86,7 @@ bool DNSTest::testDNSNameObject(FWObjectDatabase *objdb, FWObject *root, return true; } -void DNSTest::runTest() +void DNSTest::init() { libfwbuilder::init(); @@ -98,17 +100,30 @@ void DNSTest::runTest() o1->setName("Objects"); nlib->add(o1); - FWObject *root = objdb->create(ObjectGroup::TYPENAME); + root = objdb->create(ObjectGroup::TYPENAME); root->setName("DNS Names"); o1->add(root); +} - InetAddr addr; +void DNSTest::cleanup() +{ + delete objdb; +} + +void DNSTest::testLocalhost() +{ const char* test1[] = {"localhost", "127.0.0.1", nullptr}; - CPPUNIT_ASSERT(testDNSNameObject(objdb, root, test1[0], &(test1[1]))); + QVERIFY(testDNSNameObject(objdb, root, test1[0], &(test1[1]))); +} +void DNSTest::testSingleIP() +{ const char* test2[] = {"www.fwbuilder.org","70.85.175.170", nullptr}; - CPPUNIT_ASSERT(testDNSNameObject(objdb, root, test2[0], &(test2[1]))); + QVERIFY(testDNSNameObject(objdb, root, test2[0], &(test2[1]))); +} +void DNSTest::testMultipleIPs() +{ const char* test3[] = {"www.microsoft.com", "65.55.21.250", "207.46.232.182", @@ -118,5 +133,5 @@ void DNSTest::runTest() "207.46.193.254", nullptr}; - CPPUNIT_ASSERT(testDNSNameObject(objdb, root, test3[0], &(test3[1]))); + QVERIFY(testDNSNameObject(objdb, root, test3[0], &(test3[1]))); } diff --git a/src/unit_tests/DNSTest/DNSTest.h b/src/unit_tests/DNSTest/DNSTest.h index 8c9da186d..331a7dac2 100644 --- a/src/unit_tests/DNSTest/DNSTest.h +++ b/src/unit_tests/DNSTest/DNSTest.h @@ -26,31 +26,28 @@ #ifndef DNSTEST_H #define DNSTEST_H -#include -#include -#include +#include #include "fwbuilder/FWObjectDatabase.h" #include "fwbuilder/FWObject.h" - -class DNSTest : public CppUnit::TestCase +class DNSTest : public QObject { + Q_OBJECT + + libfwbuilder::FWObjectDatabase *objdb = nullptr; + libfwbuilder::FWObject *root = nullptr; - libfwbuilder::FWObjectDatabase *objdb; bool testDNSNameObject(libfwbuilder::FWObjectDatabase *objdb, libfwbuilder::FWObject *root, const std::string &dnsrec, const char* results[]); -public: - void runTest(); - - static CppUnit::Test *suite() - { - CppUnit::TestSuite *suiteOfTests = new CppUnit::TestSuite( "ObjectMatcherTest" ); - suiteOfTests->addTest( new CppUnit::TestCaller( "runTest", &DNSTest::runTest ) ); - return suiteOfTests; - } +private slots: + void init(); + void cleanup(); + void testLocalhost(); + void testSingleIP(); + void testMultipleIPs(); }; #endif // DNSTEST_H diff --git a/src/unit_tests/DNSTest/main.cpp b/src/unit_tests/DNSTest/main.cpp index 23b60674c..d5c7c80d8 100644 --- a/src/unit_tests/DNSTest/main.cpp +++ b/src/unit_tests/DNSTest/main.cpp @@ -22,9 +22,8 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +#include -#include -#include #include "DNSTest.h" #include "fwbuilder/FWObjectDatabase.h" @@ -33,13 +32,7 @@ int fwbdebug = 0; std::string platform; -int main( int, char** argv) +int main() { - CppUnit::TextUi::TestRunner runner; - runner.addTest( DNSTest::suite() ); - runner.setOutputter( new CppUnit::CompilerOutputter( &runner.result(), - std::cerr ) ); - - runner.run(); - return 0; + return QTest::qExec(new DNSTest()); } diff --git a/src/unit_tests/FWBTreeTest/CMakeLists.txt b/src/unit_tests/FWBTreeTest/CMakeLists.txt index c7b08a60d..3be3197e3 100644 --- a/src/unit_tests/FWBTreeTest/CMakeLists.txt +++ b/src/unit_tests/FWBTreeTest/CMakeLists.txt @@ -1,4 +1,6 @@ +SET(CMAKE_AUTOMOC ON) + add_executable(FWBTreeTest FWBTreeTest.cpp main_FWBTreeTest.cpp) add_test(NAME FWBTreeTest COMMAND FWBTreeTest) -target_link_libraries(FWBTreeTest PRIVATE gui fwbuilder xml2 xslt z cppunit) +target_link_libraries(FWBTreeTest PRIVATE gui fwbuilder xml2 xslt z Qt5::Test) diff --git a/src/unit_tests/FWBTreeTest/FWBTreeTest.cpp b/src/unit_tests/FWBTreeTest/FWBTreeTest.cpp index e3077cd27..c396cb542 100644 --- a/src/unit_tests/FWBTreeTest/FWBTreeTest.cpp +++ b/src/unit_tests/FWBTreeTest/FWBTreeTest.cpp @@ -22,7 +22,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ - +#include #include #include "FWBTreeTest.h" @@ -57,21 +57,21 @@ void FWBTreeTest::isSystem() FWBTree fwbtree; FWObjectDatabase db; - CPPUNIT_ASSERT(fwbtree.isSystem(&db) == true); + QVERIFY(fwbtree.isSystem(&db) == true); Library *lib = db.createLibrary(4); - CPPUNIT_ASSERT(fwbtree.isSystem(lib) == true); + QVERIFY(fwbtree.isSystem(lib) == true); lib = db.createLibrary(7); - CPPUNIT_ASSERT(fwbtree.isSystem(lib) == true); + QVERIFY(fwbtree.isSystem(lib) == true); lib = db.createLibrary(1); - CPPUNIT_ASSERT(fwbtree.isSystem(lib) == false); + QVERIFY(fwbtree.isSystem(lib) == false); lib = Library::cast(fwbtree.createNewLibrary(&db)); FWObject *slot = fwbtree.getStandardSlotForObject(lib, Firewall::TYPENAME); - CPPUNIT_ASSERT(fwbtree.isSystem(slot) == true); + QVERIFY(fwbtree.isSystem(slot) == true); Firewall fw; - CPPUNIT_ASSERT(fwbtree.isSystem(&fw) == false); + QVERIFY(fwbtree.isSystem(&fw) == false); } QSet FWBTreeTest::getStandardFolders(FWObject *root) @@ -104,26 +104,26 @@ void FWBTreeTest::validateForInsertion() Firewall fw; Network net; - CPPUNIT_ASSERT(tree.validateForInsertion(&host, &iface, err) == true); - CPPUNIT_ASSERT(tree.validateForInsertion(&firewall, &iface, err) == true); - CPPUNIT_ASSERT(tree.validateForInsertion(&iface, &ipv4, err) == true); - CPPUNIT_ASSERT(tree.validateForInsertion(&iface, &ipv6, err) == true); + QVERIFY(tree.validateForInsertion(&host, &iface, err) == true); + QVERIFY(tree.validateForInsertion(&firewall, &iface, err) == true); + QVERIFY(tree.validateForInsertion(&iface, &ipv4, err) == true); + QVERIFY(tree.validateForInsertion(&iface, &ipv6, err) == true); firewall.addInterface(&iface); - CPPUNIT_ASSERT(tree.validateForInsertion(&iface, &ipv4, err) == true); - CPPUNIT_ASSERT(tree.validateForInsertion(&iface, &ipv6, err) == true); + QVERIFY(tree.validateForInsertion(&iface, &ipv4, err) == true); + QVERIFY(tree.validateForInsertion(&iface, &ipv6, err) == true); ObjectGroup grp, grp2; Cluster cluster; DNSName dnsname; AddressRange addrrange; AddressTable addrtable; - CPPUNIT_ASSERT(tree.validateForInsertion(&grp, &host, err) == true); - CPPUNIT_ASSERT(tree.validateForInsertion(&grp, &firewall, err) == true); - CPPUNIT_ASSERT(tree.validateForInsertion(&grp, &cluster, err) == true); - CPPUNIT_ASSERT(tree.validateForInsertion(&grp, &dnsname, err) == true); - CPPUNIT_ASSERT(tree.validateForInsertion(&grp, &addrrange, err) == true); - CPPUNIT_ASSERT(tree.validateForInsertion(&grp, &addrtable, err) == true); - CPPUNIT_ASSERT(tree.validateForInsertion(&grp, &grp2, err) == true); + QVERIFY(tree.validateForInsertion(&grp, &host, err) == true); + QVERIFY(tree.validateForInsertion(&grp, &firewall, err) == true); + QVERIFY(tree.validateForInsertion(&grp, &cluster, err) == true); + QVERIFY(tree.validateForInsertion(&grp, &dnsname, err) == true); + QVERIFY(tree.validateForInsertion(&grp, &addrrange, err) == true); + QVERIFY(tree.validateForInsertion(&grp, &addrtable, err) == true); + QVERIFY(tree.validateForInsertion(&grp, &grp2, err) == true); ServiceGroup sgrp, sgrp2; IPService ip; @@ -131,67 +131,67 @@ void FWBTreeTest::validateForInsertion() TCPService tcp; UDPService udp; CustomService custom; - CPPUNIT_ASSERT(tree.validateForInsertion(&sgrp, &ip, err) == true); - CPPUNIT_ASSERT(tree.validateForInsertion(&sgrp, &icmp, err) == true); - CPPUNIT_ASSERT(tree.validateForInsertion(&sgrp, &tcp, err) == true); - CPPUNIT_ASSERT(tree.validateForInsertion(&sgrp, &udp, err) == true); - CPPUNIT_ASSERT(tree.validateForInsertion(&sgrp, &custom, err) == true); - CPPUNIT_ASSERT(tree.validateForInsertion(&sgrp, &sgrp2, err) == true); + QVERIFY(tree.validateForInsertion(&sgrp, &ip, err) == true); + QVERIFY(tree.validateForInsertion(&sgrp, &icmp, err) == true); + QVERIFY(tree.validateForInsertion(&sgrp, &tcp, err) == true); + QVERIFY(tree.validateForInsertion(&sgrp, &udp, err) == true); + QVERIFY(tree.validateForInsertion(&sgrp, &custom, err) == true); + QVERIFY(tree.validateForInsertion(&sgrp, &sgrp2, err) == true); Interval interval; IntervalGroup igrp; - CPPUNIT_ASSERT(tree.validateForInsertion(&igrp, &interval, err) == true); + QVERIFY(tree.validateForInsertion(&igrp, &interval, err) == true); foreach (FWObject* folder, stdFolders) { if (folder->getName() == "Hosts") - CPPUNIT_ASSERT(tree.validateForInsertion(folder, &host, err) == true); + QVERIFY(tree.validateForInsertion(folder, &host, err) == true); if (folder->getName() == "Firewalls") - CPPUNIT_ASSERT(tree.validateForInsertion(folder, &fw, err) == true); + QVERIFY(tree.validateForInsertion(folder, &fw, err) == true); if (folder->getName() == "Addresses") - CPPUNIT_ASSERT(tree.validateForInsertion(folder, &ipv4, err) == true); + QVERIFY(tree.validateForInsertion(folder, &ipv4, err) == true); if (folder->getName() == "Addresses") - CPPUNIT_ASSERT(tree.validateForInsertion(folder, &ipv6, err) == true); + QVERIFY(tree.validateForInsertion(folder, &ipv6, err) == true); if (folder->getName() == "TCP") - CPPUNIT_ASSERT(tree.validateForInsertion(folder, &tcp, err) == true); + QVERIFY(tree.validateForInsertion(folder, &tcp, err) == true); if (folder->getName() == "UDP") - CPPUNIT_ASSERT(tree.validateForInsertion(folder, &udp, err) == true); + QVERIFY(tree.validateForInsertion(folder, &udp, err) == true); if (folder->getName() == "ICMP") - CPPUNIT_ASSERT(tree.validateForInsertion(folder, &icmp, err) == true); + QVERIFY(tree.validateForInsertion(folder, &icmp, err) == true); if (folder->getName() == "Address ranges") - CPPUNIT_ASSERT(tree.validateForInsertion(folder, &addrrange, err) == true); + QVERIFY(tree.validateForInsertion(folder, &addrrange, err) == true); if (folder->getName() == "Networks") - CPPUNIT_ASSERT(tree.validateForInsertion(folder, &net, err) == true); + QVERIFY(tree.validateForInsertion(folder, &net, err) == true); } - CPPUNIT_ASSERT(tree.validateForInsertion(&host, &ipv4, err) == false); - CPPUNIT_ASSERT(tree.validateForInsertion(&firewall, &ipv4, err) == false); - CPPUNIT_ASSERT(tree.validateForInsertion(&cluster, &ipv4, err) == false); - CPPUNIT_ASSERT(tree.validateForInsertion(&grp, &ip, err) == false); - CPPUNIT_ASSERT(tree.validateForInsertion(&sgrp, &ipv4, err) == false); - CPPUNIT_ASSERT(tree.validateForInsertion(&grp, &interval, err) == false); - CPPUNIT_ASSERT(tree.validateForInsertion(&sgrp, &interval, err) == false); + QVERIFY(tree.validateForInsertion(&host, &ipv4, err) == false); + QVERIFY(tree.validateForInsertion(&firewall, &ipv4, err) == false); + QVERIFY(tree.validateForInsertion(&cluster, &ipv4, err) == false); + QVERIFY(tree.validateForInsertion(&grp, &ip, err) == false); + QVERIFY(tree.validateForInsertion(&sgrp, &ipv4, err) == false); + QVERIFY(tree.validateForInsertion(&grp, &interval, err) == false); + QVERIFY(tree.validateForInsertion(&sgrp, &interval, err) == false); foreach (FWObject* folder, stdFolders) { if (folder->getName() == "Addresses") - CPPUNIT_ASSERT(tree.validateForInsertion(folder, &host, err) == false); + QVERIFY(tree.validateForInsertion(folder, &host, err) == false); if (folder->getName() == "Addresses") - CPPUNIT_ASSERT(tree.validateForInsertion(folder, &fw, err) == false); + QVERIFY(tree.validateForInsertion(folder, &fw, err) == false); if (folder->getName() == "Hosts") - CPPUNIT_ASSERT(tree.validateForInsertion(folder, &ipv4, err) == false); + QVERIFY(tree.validateForInsertion(folder, &ipv4, err) == false); if (folder->getName() == "Firewalls") - CPPUNIT_ASSERT(tree.validateForInsertion(folder, &ipv6, err) == false); + QVERIFY(tree.validateForInsertion(folder, &ipv6, err) == false); if (folder->getName() == "Networks") - CPPUNIT_ASSERT(tree.validateForInsertion(folder, &tcp, err) == false); + QVERIFY(tree.validateForInsertion(folder, &tcp, err) == false); if (folder->getName() == "TCP") - CPPUNIT_ASSERT(tree.validateForInsertion(folder, &udp, err) == false); + QVERIFY(tree.validateForInsertion(folder, &udp, err) == false); if (folder->getName() == "Address ranges") - CPPUNIT_ASSERT(tree.validateForInsertion(folder, &icmp, err) == false); + QVERIFY(tree.validateForInsertion(folder, &icmp, err) == false); if (folder->getName() == "ICMP") - CPPUNIT_ASSERT(tree.validateForInsertion(folder, &addrrange, err) == false); + QVERIFY(tree.validateForInsertion(folder, &addrrange, err) == false); if (folder->getName() == "UDP") - CPPUNIT_ASSERT(tree.validateForInsertion(folder, &net, err) == false); + QVERIFY(tree.validateForInsertion(folder, &net, err) == false); } diff --git a/src/unit_tests/FWBTreeTest/FWBTreeTest.h b/src/unit_tests/FWBTreeTest/FWBTreeTest.h index aa329e5ec..3bc56444e 100644 --- a/src/unit_tests/FWBTreeTest/FWBTreeTest.h +++ b/src/unit_tests/FWBTreeTest/FWBTreeTest.h @@ -26,24 +26,19 @@ #ifndef FWBTREETEST_H #define FWBTREETEST_H +#include #include "FWBTree.h" -#include - - -class FWBTreeTest : public CppUnit::TestFixture +class FWBTreeTest : public QObject { + Q_OBJECT + QSet getStandardFolders(libfwbuilder::FWObject *root); -public: +private slots: void isSystem(); void validateForInsertion(); - - CPPUNIT_TEST_SUITE(FWBTreeTest); - CPPUNIT_TEST(isSystem); - CPPUNIT_TEST(validateForInsertion); - CPPUNIT_TEST_SUITE_END(); }; diff --git a/src/unit_tests/FWBTreeTest/main_FWBTreeTest.cpp b/src/unit_tests/FWBTreeTest/main_FWBTreeTest.cpp index 964586cdc..ba5e56a41 100644 --- a/src/unit_tests/FWBTreeTest/main_FWBTreeTest.cpp +++ b/src/unit_tests/FWBTreeTest/main_FWBTreeTest.cpp @@ -22,21 +22,14 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +#include -#include -#include #include "FWBTreeTest.h" int fwbdebug; -int main(int /*UNUSED argc*/, char ** /*UNUSED argv[]*/) +int main() { - CppUnit::TextUi::TestRunner runner; - runner.addTest( FWBTreeTest::suite() ); - runner.setOutputter( new CppUnit::CompilerOutputter( &runner.result(), - std::cerr ) ); - - runner.run(); - return 0; + return QTest::qExec(new FWBTreeTest()); } diff --git a/src/unit_tests/FWObjectTest/CMakeLists.txt b/src/unit_tests/FWObjectTest/CMakeLists.txt index 884535fb6..5089a253b 100644 --- a/src/unit_tests/FWObjectTest/CMakeLists.txt +++ b/src/unit_tests/FWObjectTest/CMakeLists.txt @@ -1,4 +1,6 @@ +SET(CMAKE_AUTOMOC ON) + add_executable(FWObjectTest FWObjectTest.cpp main.cpp) add_test(NAME FWObjectTest COMMAND FWObjectTest) -target_link_libraries(FWObjectTest PRIVATE fwbuilder xml2 xslt z cppunit) +target_link_libraries(FWObjectTest PRIVATE fwbuilder xml2 xslt z Qt5::Test) diff --git a/src/unit_tests/FWObjectTest/FWObjectTest.cpp b/src/unit_tests/FWObjectTest/FWObjectTest.cpp index 3baca28b0..641d8a9cb 100644 --- a/src/unit_tests/FWObjectTest/FWObjectTest.cpp +++ b/src/unit_tests/FWObjectTest/FWObjectTest.cpp @@ -22,6 +22,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +#include #include "FWObjectTest.h" @@ -49,14 +50,14 @@ void FWObjectTest::cmpTest() FWObject *obj2 = db.create(Firewall::TYPENAME); obj2->duplicate(obj1); obj1->setStr("key", "value1"); - CPPUNIT_ASSERT(obj1->cmp(obj2) == false); + QVERIFY(obj1->cmp(obj2) == false); obj2->setStr("key", "value2"); - CPPUNIT_ASSERT(obj1->cmp(obj2) == false); + QVERIFY(obj1->cmp(obj2) == false); obj2->remStr("key"); obj1->setStr("key", ""); - CPPUNIT_ASSERT(obj1->cmp(obj2) == false); + QVERIFY(obj1->cmp(obj2) == false); obj1->remStr("key"); - CPPUNIT_ASSERT(obj2->cmp(obj1) == true); + QVERIFY(obj2->cmp(obj1) == true); FWObject *ch1 = db.create(Interface::TYPENAME); @@ -66,12 +67,12 @@ void FWObjectTest::cmpTest() ch1->setStr("key", "value1"); ch2->duplicate(ch1); - CPPUNIT_ASSERT(ch1->cmp(ch2) == true); + QVERIFY(ch1->cmp(ch2) == true); ch3->duplicate(ch1); - CPPUNIT_ASSERT(ch1->cmp(ch3) == true); + QVERIFY(ch1->cmp(ch3) == true); ch4->duplicate(ch1); ch4->setStr("key", "value2"); - CPPUNIT_ASSERT(ch1->cmp(ch4) == false); + QVERIFY(ch1->cmp(ch4) == false); obj1->add(ch1); obj1->add(ch2); @@ -79,9 +80,9 @@ void FWObjectTest::cmpTest() obj2->add(ch3); obj2->add(ch4); - CPPUNIT_ASSERT(obj1->cmp(obj2, true) == false); + QVERIFY(obj1->cmp(obj2, true) == false); ch4->setStr("key", "value1"); - CPPUNIT_ASSERT(obj1->cmp(obj2, true) == true); + QVERIFY(obj1->cmp(obj2, true) == true); } diff --git a/src/unit_tests/FWObjectTest/FWObjectTest.h b/src/unit_tests/FWObjectTest/FWObjectTest.h index 49c17390c..64498c622 100644 --- a/src/unit_tests/FWObjectTest/FWObjectTest.h +++ b/src/unit_tests/FWObjectTest/FWObjectTest.h @@ -26,24 +26,14 @@ #ifndef OBJECTMATCHERTEST_H #define OBJECTMATCHERTEST_H +#include -#include -#include -#include - -class FWObjectTest : public CppUnit::TestCase +class FWObjectTest : public QObject { -public: - void cmpTest(); + Q_OBJECT - static CppUnit::Test *suite() - { - CppUnit::TestSuite *suiteOfTests = new CppUnit::TestSuite( "FWObjectTest" ); - suiteOfTests->addTest( new CppUnit::TestCaller( - "cmpTest", - &FWObjectTest::cmpTest ) ); - return suiteOfTests; - } +private slots: + void cmpTest(); }; #endif // OBJECTMATCHERTEST_H diff --git a/src/unit_tests/FWObjectTest/main.cpp b/src/unit_tests/FWObjectTest/main.cpp index f7991f421..1cac4ab33 100644 --- a/src/unit_tests/FWObjectTest/main.cpp +++ b/src/unit_tests/FWObjectTest/main.cpp @@ -22,9 +22,8 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +#include -#include -#include #include "FWObjectTest.h" #include "fwbuilder/FWObjectDatabase.h" @@ -33,19 +32,11 @@ using namespace libfwbuilder; int fwbdebug = 0; -//QString user_name; std::string platform; -int main( int, char** argv) +int main() { - //init(argv); init(); - CppUnit::TextUi::TestRunner runner; - runner.addTest( FWObjectTest::suite() ); - runner.setOutputter( new CppUnit::CompilerOutputter( &runner.result(), - std::cerr ) ); - - runner.run(); - return 0; + return QTest::qExec(new FWObjectTest()); } diff --git a/src/unit_tests/FWWindowTest/CMakeLists.txt b/src/unit_tests/FWWindowTest/CMakeLists.txt index 3dc1a951f..80eda7fa2 100644 --- a/src/unit_tests/FWWindowTest/CMakeLists.txt +++ b/src/unit_tests/FWWindowTest/CMakeLists.txt @@ -3,6 +3,6 @@ SET(CMAKE_AUTOMOC ON) add_executable(FWWindowTest FWWindowTest.cpp main_FWWindowTest.cpp) add_test(NAME FWWindowTest COMMAND FWWindowTest) -target_link_libraries(FWWindowTest PRIVATE test_main netsnmp gui import fwbparser antlr common iptlib fwbpf fwbjuniper fwbcisco compilerdriver fwcompiler fwbuilder xml2 xslt z pthread Qt5::Test) +target_link_libraries(FWWindowTest PRIVATE test_main gui import fwbparser antlr common iptlib fwbpf fwbjuniper fwbcisco compilerdriver fwcompiler fwbuilder netsnmp xml2 xslt z pthread Qt5::Test) #target_link_libraries(fwb_ipt common iptlib compilerdriver fwcompiler fwbuilder xml2 pthread m xslt z) #target_link_libraries(fwbuilder-gui gui import fwbparser antlr common iptlib fwbpf fwbjuniper fwbcisco compilerdriver fwcompiler fwbuilder xml2 m xslt z OpenSSL::Crypto pthread) diff --git a/src/unit_tests/FWWindowTest/main_FWWindowTest.cpp b/src/unit_tests/FWWindowTest/main_FWWindowTest.cpp index e750116ce..1db353649 100644 --- a/src/unit_tests/FWWindowTest/main_FWWindowTest.cpp +++ b/src/unit_tests/FWWindowTest/main_FWWindowTest.cpp @@ -38,9 +38,9 @@ using namespace std; using namespace libfwbuilder; int fwbdebug = 0; -FWWindow *mw = nullptr; -FWBSettings *st = nullptr; -FWBApplication *app = nullptr; +FWWindow *mw = nullptr; +FWBSettings *st = nullptr; +FWBApplication *app = nullptr; extern void build_app(int argc, char** argv, @@ -48,16 +48,18 @@ extern void build_app(int argc, char** argv, FWBSettings** st); int main(int argc, char** argv) -{ - app = new FWBApplication(argc, argv); - app->setOrganizationName(QLatin1String("NetCitadel")); - app->setApplicationName(QLatin1String("Firewall Builder")); +{ + app = new FWBApplication(argc, argv); + app->setOrganizationName(QLatin1String("NetCitadel")); + app->setApplicationName(QLatin1String("Firewall Builder")); build_app(argc, argv, &app, &st); - QTest::qExec(new FWWindowTest()); + int testResult = QTest::qExec(new FWWindowTest()); - if (QFile::exists("test_work.fwb")) - QFile::remove("test_work.fwb"); + if (QFile::exists("test_work.fwb")) + QFile::remove("test_work.fwb"); + + return testResult; } diff --git a/src/unit_tests/FirewallDialogTest/CMakeLists.txt b/src/unit_tests/FirewallDialogTest/CMakeLists.txt index db139ad57..2b6fe584a 100644 --- a/src/unit_tests/FirewallDialogTest/CMakeLists.txt +++ b/src/unit_tests/FirewallDialogTest/CMakeLists.txt @@ -3,4 +3,4 @@ SET(CMAKE_AUTOMOC ON) add_executable(FirewallDialogTest FirewallDialogTest.cpp main_FirewallDialogTest.cpp) add_test(NAME FirewallDialogTest COMMAND FirewallDialogTest) -target_link_libraries(FirewallDialogTest PRIVATE test_main netsnmp gui import fwbparser antlr common iptlib fwbpf fwbjuniper fwbcisco compilerdriver fwcompiler fwbuilder xml2 xslt z pthread Qt5::Test) +target_link_libraries(FirewallDialogTest PRIVATE test_main gui import fwbparser antlr common iptlib fwbpf fwbjuniper fwbcisco compilerdriver fwcompiler fwbuilder netsnmp xml2 xslt z pthread Qt5::Test) diff --git a/src/unit_tests/FirewallDialogTest/main_FirewallDialogTest.cpp b/src/unit_tests/FirewallDialogTest/main_FirewallDialogTest.cpp index 63e05b33a..053f671f2 100644 --- a/src/unit_tests/FirewallDialogTest/main_FirewallDialogTest.cpp +++ b/src/unit_tests/FirewallDialogTest/main_FirewallDialogTest.cpp @@ -38,9 +38,9 @@ using namespace std; using namespace libfwbuilder; int fwbdebug = 0; -FWWindow *mw = nullptr; -FWBSettings *st = nullptr; -FWBApplication *app = nullptr; +FWWindow *mw = nullptr; +FWBSettings *st = nullptr; +FWBApplication *app = nullptr; extern void build_app(int argc, char** argv, @@ -48,16 +48,18 @@ extern void build_app(int argc, char** argv, FWBSettings** st); int main(int argc, char** argv) -{ - app = new FWBApplication(argc, argv); - app->setOrganizationName(QLatin1String("NetCitadel")); - app->setApplicationName(QLatin1String("Firewall Builder")); +{ + app = new FWBApplication(argc, argv); + app->setOrganizationName(QLatin1String("NetCitadel")); + app->setApplicationName(QLatin1String("Firewall Builder")); build_app(argc, argv, &app, &st); - QTest::qExec(new FirewallDialogTest()); + int testResult = QTest::qExec(new FirewallDialogTest()); - if (QFile::exists("test_work.fwb")) - QFile::remove("test_work.fwb"); + if (QFile::exists("test_work.fwb")) + QFile::remove("test_work.fwb"); + + return testResult; } diff --git a/src/unit_tests/GroupObjectDialogTest/CMakeLists.txt b/src/unit_tests/GroupObjectDialogTest/CMakeLists.txt index cf1acaf89..b3f4b9a4e 100644 --- a/src/unit_tests/GroupObjectDialogTest/CMakeLists.txt +++ b/src/unit_tests/GroupObjectDialogTest/CMakeLists.txt @@ -3,4 +3,4 @@ SET(CMAKE_AUTOMOC ON) add_executable(GroupObjectDialogTest GroupObjectDialogTest.cpp main_GroupObjectDialogTest.cpp) add_test(NAME GroupObjectDialogTest COMMAND GroupObjectDialogTest) -target_link_libraries(GroupObjectDialogTest PRIVATE test_main netsnmp gui import fwbparser antlr common iptlib fwbpf fwbjuniper fwbcisco compilerdriver fwcompiler fwbuilder xml2 xslt z pthread Qt5::Test) +target_link_libraries(GroupObjectDialogTest PRIVATE test_main gui import fwbparser antlr common iptlib fwbpf fwbjuniper fwbcisco compilerdriver fwcompiler fwbuilder netsnmp xml2 xslt z pthread Qt5::Test) diff --git a/src/unit_tests/GroupObjectDialogTest/main_GroupObjectDialogTest.cpp b/src/unit_tests/GroupObjectDialogTest/main_GroupObjectDialogTest.cpp index 46b7e765f..550fbd3df 100644 --- a/src/unit_tests/GroupObjectDialogTest/main_GroupObjectDialogTest.cpp +++ b/src/unit_tests/GroupObjectDialogTest/main_GroupObjectDialogTest.cpp @@ -38,9 +38,9 @@ using namespace std; using namespace libfwbuilder; int fwbdebug = 0; -FWWindow *mw = nullptr; -FWBSettings *st = nullptr; -FWBApplication *app = nullptr; +FWWindow *mw = nullptr; +FWBSettings *st = nullptr; +FWBApplication *app = nullptr; extern void build_app(int argc, char** argv, @@ -48,16 +48,18 @@ extern void build_app(int argc, char** argv, FWBSettings** st); int main(int argc, char** argv) -{ - app = new FWBApplication(argc, argv); - app->setOrganizationName(QLatin1String("NetCitadel")); - app->setApplicationName(QLatin1String("Firewall Builder")); +{ + app = new FWBApplication(argc, argv); + app->setOrganizationName(QLatin1String("NetCitadel")); + app->setApplicationName(QLatin1String("Firewall Builder")); build_app(argc, argv, &app, &st); - QTest::qExec(new GroupObjectDialogTest()); + int testResult = QTest::qExec(new GroupObjectDialogTest()); - if (QFile::exists("test_work.fwb")) - QFile::remove("test_work.fwb"); + if (QFile::exists("test_work.fwb")) + QFile::remove("test_work.fwb"); + + return testResult; } diff --git a/src/unit_tests/ICMP6ServiceDialogTest/CMakeLists.txt b/src/unit_tests/ICMP6ServiceDialogTest/CMakeLists.txt index 19dec4752..1ba403a11 100644 --- a/src/unit_tests/ICMP6ServiceDialogTest/CMakeLists.txt +++ b/src/unit_tests/ICMP6ServiceDialogTest/CMakeLists.txt @@ -3,4 +3,4 @@ SET(CMAKE_AUTOMOC ON) add_executable(ICMP6ServiceDialogTest ICMP6ServiceDialogTest.cpp main_ICMP6ServiceDialogTest.cpp) add_test(NAME ICMP6ServiceDialogTest COMMAND ICMP6ServiceDialogTest) -target_link_libraries(ICMP6ServiceDialogTest PRIVATE test_main netsnmp gui import fwbparser antlr common iptlib fwbpf fwbjuniper fwbcisco compilerdriver fwcompiler fwbuilder xml2 xslt z pthread Qt5::Test) +target_link_libraries(ICMP6ServiceDialogTest PRIVATE test_main gui import fwbparser antlr common iptlib fwbpf fwbjuniper fwbcisco compilerdriver fwcompiler fwbuilder netsnmp xml2 xslt z pthread Qt5::Test) diff --git a/src/unit_tests/ICMP6ServiceDialogTest/main_ICMP6ServiceDialogTest.cpp b/src/unit_tests/ICMP6ServiceDialogTest/main_ICMP6ServiceDialogTest.cpp index ee2f73898..3c2df7ba7 100644 --- a/src/unit_tests/ICMP6ServiceDialogTest/main_ICMP6ServiceDialogTest.cpp +++ b/src/unit_tests/ICMP6ServiceDialogTest/main_ICMP6ServiceDialogTest.cpp @@ -38,9 +38,9 @@ using namespace std; using namespace libfwbuilder; int fwbdebug = 0; -FWWindow *mw = nullptr; -FWBSettings *st = nullptr; -FWBApplication *app = nullptr; +FWWindow *mw = nullptr; +FWBSettings *st = nullptr; +FWBApplication *app = nullptr; extern void build_app(int argc, char** argv, @@ -48,16 +48,18 @@ extern void build_app(int argc, char** argv, FWBSettings** st); int main(int argc, char** argv) -{ - app = new FWBApplication(argc, argv); - app->setOrganizationName(QLatin1String("NetCitadel")); - app->setApplicationName(QLatin1String("Firewall Builder")); +{ + app = new FWBApplication(argc, argv); + app->setOrganizationName(QLatin1String("NetCitadel")); + app->setApplicationName(QLatin1String("Firewall Builder")); build_app(argc, argv, &app, &st); - QTest::qExec(new ICMP6ServiceDialogTest()); + int testResult = QTest::qExec(new ICMP6ServiceDialogTest()); - if (QFile::exists("test_work.fwb")) - QFile::remove("test_work.fwb"); + if (QFile::exists("test_work.fwb")) + QFile::remove("test_work.fwb"); + + return testResult; } diff --git a/src/unit_tests/ICMPServiceDialogTest/CMakeLists.txt b/src/unit_tests/ICMPServiceDialogTest/CMakeLists.txt index 1cd2661c9..9b0e52f36 100644 --- a/src/unit_tests/ICMPServiceDialogTest/CMakeLists.txt +++ b/src/unit_tests/ICMPServiceDialogTest/CMakeLists.txt @@ -3,4 +3,4 @@ SET(CMAKE_AUTOMOC ON) add_executable(ICMPServiceDialogTest ICMPServiceDialogTest.cpp main_ICMPServiceDialogTest.cpp) add_test(NAME ICMPServiceDialogTest COMMAND ICMPServiceDialogTest) -target_link_libraries(ICMPServiceDialogTest PRIVATE test_main netsnmp gui import fwbparser antlr common iptlib fwbpf fwbjuniper fwbcisco compilerdriver fwcompiler fwbuilder xml2 xslt z pthread Qt5::Test) +target_link_libraries(ICMPServiceDialogTest PRIVATE test_main gui import fwbparser antlr common iptlib fwbpf fwbjuniper fwbcisco compilerdriver fwcompiler fwbuilder netsnmp xml2 xslt z pthread Qt5::Test) diff --git a/src/unit_tests/ICMPServiceDialogTest/main_ICMPServiceDialogTest.cpp b/src/unit_tests/ICMPServiceDialogTest/main_ICMPServiceDialogTest.cpp index 63984c252..7469442ad 100644 --- a/src/unit_tests/ICMPServiceDialogTest/main_ICMPServiceDialogTest.cpp +++ b/src/unit_tests/ICMPServiceDialogTest/main_ICMPServiceDialogTest.cpp @@ -38,9 +38,9 @@ using namespace std; using namespace libfwbuilder; int fwbdebug = 0; -FWWindow *mw = nullptr; -FWBSettings *st = nullptr; -FWBApplication *app = nullptr; +FWWindow *mw = nullptr; +FWBSettings *st = nullptr; +FWBApplication *app = nullptr; extern void build_app(int argc, char** argv, @@ -48,16 +48,18 @@ extern void build_app(int argc, char** argv, FWBSettings** st); int main(int argc, char** argv) -{ - app = new FWBApplication(argc, argv); - app->setOrganizationName(QLatin1String("NetCitadel")); - app->setApplicationName(QLatin1String("Firewall Builder")); +{ + app = new FWBApplication(argc, argv); + app->setOrganizationName(QLatin1String("NetCitadel")); + app->setApplicationName(QLatin1String("Firewall Builder")); build_app(argc, argv, &app, &st); - QTest::qExec(new ICMPServiceDialogTest()); + int testResult = QTest::qExec(new ICMPServiceDialogTest()); - if (QFile::exists("test_work.fwb")) - QFile::remove("test_work.fwb"); + if (QFile::exists("test_work.fwb")) + QFile::remove("test_work.fwb"); + + return testResult; } diff --git a/src/unit_tests/IPDialogTest/CMakeLists.txt b/src/unit_tests/IPDialogTest/CMakeLists.txt index 39e0d5f63..9e2f94c91 100644 --- a/src/unit_tests/IPDialogTest/CMakeLists.txt +++ b/src/unit_tests/IPDialogTest/CMakeLists.txt @@ -3,4 +3,4 @@ SET(CMAKE_AUTOMOC ON) add_executable(IPDialogTest IPDialogTest.cpp main_IPDialogTest.cpp) add_test(NAME IPDialogTest COMMAND IPDialogTest) -target_link_libraries(IPDialogTest PRIVATE test_main netsnmp gui import fwbparser antlr common iptlib fwbpf fwbjuniper fwbcisco compilerdriver fwcompiler fwbuilder xml2 xslt z pthread Qt5::Test) +target_link_libraries(IPDialogTest PRIVATE test_main gui import fwbparser antlr common iptlib fwbpf fwbjuniper fwbcisco compilerdriver fwcompiler fwbuilder netsnmp xml2 xslt z pthread Qt5::Test) diff --git a/src/unit_tests/IPDialogTest/main_IPDialogTest.cpp b/src/unit_tests/IPDialogTest/main_IPDialogTest.cpp index cbd7cd500..ac4d14f4c 100644 --- a/src/unit_tests/IPDialogTest/main_IPDialogTest.cpp +++ b/src/unit_tests/IPDialogTest/main_IPDialogTest.cpp @@ -37,9 +37,9 @@ using namespace std; using namespace libfwbuilder; int fwbdebug = 0; -FWWindow *mw = nullptr; -FWBSettings *st = nullptr; -FWBApplication *app = nullptr; +FWWindow *mw = nullptr; +FWBSettings *st = nullptr; +FWBApplication *app = nullptr; extern void build_app(int argc, char** argv, @@ -47,16 +47,18 @@ extern void build_app(int argc, char** argv, FWBSettings** st); int main(int argc, char** argv) -{ - app = new FWBApplication(argc, argv); - app->setOrganizationName(QLatin1String("NetCitadel")); - app->setApplicationName(QLatin1String("Firewall Builder")); +{ + app = new FWBApplication(argc, argv); + app->setOrganizationName(QLatin1String("NetCitadel")); + app->setApplicationName(QLatin1String("Firewall Builder")); build_app(argc, argv, &app, &st); - QTest::qExec(new IPDialogTest()); + int testResult = QTest::qExec(new IPDialogTest()); - if (QFile::exists("test_work.fwb")) - QFile::remove("test_work.fwb"); + if (QFile::exists("test_work.fwb")) + QFile::remove("test_work.fwb"); + + return testResult; } diff --git a/src/unit_tests/IPServiceDialogTest/CMakeLists.txt b/src/unit_tests/IPServiceDialogTest/CMakeLists.txt index b2943b24e..3502b3981 100644 --- a/src/unit_tests/IPServiceDialogTest/CMakeLists.txt +++ b/src/unit_tests/IPServiceDialogTest/CMakeLists.txt @@ -3,4 +3,4 @@ SET(CMAKE_AUTOMOC ON) add_executable(IPServiceDialogTest IPServiceDialogTest.cpp main_IPServiceDialogTest.cpp) add_test(NAME IPServiceDialogTest COMMAND IPServiceDialogTest) -target_link_libraries(IPServiceDialogTest PRIVATE test_main netsnmp gui import fwbparser antlr common iptlib fwbpf fwbjuniper fwbcisco compilerdriver fwcompiler fwbuilder xml2 xslt z pthread Qt5::Test) +target_link_libraries(IPServiceDialogTest PRIVATE test_main gui import fwbparser antlr common iptlib fwbpf fwbjuniper fwbcisco compilerdriver fwcompiler fwbuilder netsnmp xml2 xslt z pthread Qt5::Test) diff --git a/src/unit_tests/IPServiceDialogTest/main_IPServiceDialogTest.cpp b/src/unit_tests/IPServiceDialogTest/main_IPServiceDialogTest.cpp index 743f5b3a5..1b24fed72 100644 --- a/src/unit_tests/IPServiceDialogTest/main_IPServiceDialogTest.cpp +++ b/src/unit_tests/IPServiceDialogTest/main_IPServiceDialogTest.cpp @@ -37,9 +37,9 @@ using namespace std; using namespace libfwbuilder; int fwbdebug = 0; -FWWindow *mw = nullptr; -FWBSettings *st = nullptr; -FWBApplication *app = nullptr; +FWWindow *mw = nullptr; +FWBSettings *st = nullptr; +FWBApplication *app = nullptr; extern void build_app(int argc, char** argv, @@ -47,16 +47,18 @@ extern void build_app(int argc, char** argv, FWBSettings** st); int main(int argc, char** argv) -{ - app = new FWBApplication(argc, argv); - app->setOrganizationName(QLatin1String("NetCitadel")); - app->setApplicationName(QLatin1String("Firewall Builder")); +{ + app = new FWBApplication(argc, argv); + app->setOrganizationName(QLatin1String("NetCitadel")); + app->setApplicationName(QLatin1String("Firewall Builder")); build_app(argc, argv, &app, &st); - QTest::qExec(new IPServiceDialogTest()); + int testResult = QTest::qExec(new IPServiceDialogTest()); - if (QFile::exists("test_work.fwb")) - QFile::remove("test_work.fwb"); + if (QFile::exists("test_work.fwb")) + QFile::remove("test_work.fwb"); + + return testResult; } diff --git a/src/unit_tests/ImporterTest/CMakeLists.txt b/src/unit_tests/ImporterTest/CMakeLists.txt index fd9482374..741f029a7 100644 --- a/src/unit_tests/ImporterTest/CMakeLists.txt +++ b/src/unit_tests/ImporterTest/CMakeLists.txt @@ -1,7 +1,9 @@ +set (CMAKE_AUTOMOC ON) + add_executable(ImporterTest ImporterTest.cpp main_ImporterTest.cpp) add_test(NAME ImporterTest COMMAND ImporterTest) -target_link_libraries(ImporterTest PRIVATE test_main netsnmp gui import fwbparser antlr common iptlib fwbpf fwbjuniper fwbcisco compilerdriver fwcompiler fwbuilder xml2 xslt z pthread cppunit) +target_link_libraries(ImporterTest PRIVATE test_main netsnmp gui import fwbparser antlr common iptlib fwbpf fwbjuniper fwbcisco compilerdriver fwcompiler fwbuilder xml2 xslt z pthread Qt5::Test) file(COPY test_data DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) diff --git a/src/unit_tests/ImporterTest/ImporterTest.cpp b/src/unit_tests/ImporterTest/ImporterTest.cpp index 43d4a60ff..31c47a46d 100644 --- a/src/unit_tests/ImporterTest/ImporterTest.cpp +++ b/src/unit_tests/ImporterTest/ImporterTest.cpp @@ -43,6 +43,7 @@ #include "fwbuilder/TagService.h" #include "fwbuilder/Constants.h" +#include #include #include #include @@ -55,7 +56,7 @@ using namespace libfwbuilder; extern string platform; -const char* iptables_sample = +const char* iptables_sample = "# Generated by iptables-save %VERSION% on Mon Apr 11 15:50:58 2011\n" "*filter\n" ":INPUT ACCEPT [0:0]\n" @@ -82,7 +83,7 @@ class UpgradePredicate: public XMLTools::UpgradePredicate } }; -void ImporterTest::setUp() +void ImporterTest::init() { //init(); @@ -138,15 +139,15 @@ void ImporterTest::compareResults(QueueLogger* logger, QString result_file = rr.readAll(); QStringList expected_result = result_file.split("\n"); - CPPUNIT_ASSERT_MESSAGE( + QVERIFY2( + expected_result.size() == obtained_result.size(), QString( "Sizes of the generated importer output and test files are different.\n" "Expected: %1 (%2)\n" "Obtained: %3 (%4)\n" "diff -u %1 %3 | less -S") .arg(expected_result_file_name).arg(expected_result.size()) - .arg(obtained_result_file_name).arg(obtained_result.size()).toStdString(), - expected_result.size() == obtained_result.size()); + .arg(obtained_result_file_name).arg(obtained_result.size()).toStdString().data()); int max_idx = max(expected_result.size(), obtained_result.size()); for (int i=0; i < max_idx; ++i) @@ -156,8 +157,7 @@ void ImporterTest::compareResults(QueueLogger* logger, .arg(i) .arg(expected_result[i]) .arg(obtained_result[i]); - CPPUNIT_ASSERT_MESSAGE( - err.toStdString(), obtained_result[i] == expected_result[i]); + QVERIFY2(obtained_result[i] == expected_result[i], err.toStdString().data()); } } @@ -172,7 +172,7 @@ void ImporterTest::compareFwbFiles(QString expected_result_file_name, 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(); @@ -187,12 +187,12 @@ void ImporterTest::compareFwbFiles(QString expected_result_file_name, "Obtained: %3 (%4)\n" "diff -u %1 %3 | less -S"); - CPPUNIT_ASSERT_MESSAGE( + QVERIFY2( + expected_result.size() == obtained_result.size(), err .arg(expected_result_file_name).arg(expected_result.size()) .arg(obtained_result_file_name).arg(obtained_result.size()) - .toStdString(), - expected_result.size() == obtained_result.size()); + .toStdString().data()); QRegExp last_mod_re("lastModified=\"\\d+\""); int max_idx = max(expected_result.size(), obtained_result.size()); @@ -212,8 +212,7 @@ void ImporterTest::compareFwbFiles(QString expected_result_file_name, .arg(i) .arg(expected_result[i]) .arg(obtained_result[i]); - CPPUNIT_ASSERT_MESSAGE( - err.toStdString(), obtained_result[i] == expected_result[i]); + QVERIFY2(obtained_result[i] == expected_result[i], err.toStdString().data()); } } @@ -231,7 +230,12 @@ void ImporterTest::IOSImporterTest() Importer* imp = new IOSImporter(lib, instream, logger, "test_fw"); imp->setAddStandardCommentsFlag(true); - CPPUNIT_ASSERT_NO_THROW( imp->run() ); + + try { + imp->run(); + } catch (const std::exception &e) { + QFAIL(std::string("Exception thrown: ").append(e.what()).data()); + } imp->finalize(); @@ -256,7 +260,12 @@ void ImporterTest::IPTImporterTest() Importer* imp = new IPTImporter(lib, instream, logger, "test_fw"); imp->setAddStandardCommentsFlag(true); - CPPUNIT_ASSERT_NO_THROW( imp->run() ); + + try { + imp->run(); + } catch (const std::exception &e) { + QFAIL(std::string("Exception thrown: ").append(e.what()).data()); + } imp->finalize(); @@ -281,7 +290,12 @@ void ImporterTest::IPTImporterNoNatTest() Importer* imp = new IPTImporter(lib, instream, logger, "test_fw"); imp->setAddStandardCommentsFlag(true); - CPPUNIT_ASSERT_NO_THROW( imp->run() ); + + try { + imp->run(); + } catch (const std::exception &e) { + QFAIL(std::string("Exception thrown: ").append(e.what()).data()); + } imp->finalize(); @@ -317,7 +331,12 @@ void ImporterTest::IPTImporterParseVersionsTest() Importer* imp = new IPTImporter(lib, instream, logger, "test_fw"); imp->setAddStandardCommentsFlag(true); - CPPUNIT_ASSERT_NO_THROW( imp->run() ); + + try { + imp->run(); + } catch (const std::exception &e) { + QFAIL(std::string("Exception thrown: ").append(e.what()).data()); + } imp->finalize(); diff --git a/src/unit_tests/ImporterTest/ImporterTest.h b/src/unit_tests/ImporterTest/ImporterTest.h index d69b16d5f..3f068d653 100644 --- a/src/unit_tests/ImporterTest/ImporterTest.h +++ b/src/unit_tests/ImporterTest/ImporterTest.h @@ -30,41 +30,34 @@ #include "fwbuilder/FWException.h" #include "fwbuilder/Logger.h" -#include - #include +#include #include -class ImporterTest : public CppUnit::TestFixture +class ImporterTest : public QObject { + Q_OBJECT + libfwbuilder::FWObjectDatabase *db; libfwbuilder::Library *lib; libfwbuilder::QueueLogger *logger; int predictable_id_tracker; std::map id_mapping; - + void compareResults(libfwbuilder::QueueLogger* logger, QString expected_result_file_name, QString obtained_result_file_name); void compareFwbFiles(QString expected_result_file_name, QString obtained_result_file_name); -public: - void setUp(); +private slots: + void init(); void IOSImporterTest(); void IPTImporterTest(); void IPTImporterNoNatTest(); void IPTImporterParseVersionsTest(); - - CPPUNIT_TEST_SUITE(ImporterTest); - CPPUNIT_TEST(IOSImporterTest); - CPPUNIT_TEST(IPTImporterTest); - CPPUNIT_TEST(IPTImporterNoNatTest); - CPPUNIT_TEST(IPTImporterParseVersionsTest); - - CPPUNIT_TEST_SUITE_END(); }; diff --git a/src/unit_tests/ImporterTest/main_ImporterTest.cpp b/src/unit_tests/ImporterTest/main_ImporterTest.cpp index 06e36f774..cfbc52f32 100644 --- a/src/unit_tests/ImporterTest/main_ImporterTest.cpp +++ b/src/unit_tests/ImporterTest/main_ImporterTest.cpp @@ -23,8 +23,6 @@ */ -#include -#include #include "ImporterTest.h" #include "fwbuilder/Resources.h" @@ -32,6 +30,7 @@ #include "FWBSettings.h" #include "FWBApplication.h" +#include #include #include #include @@ -39,10 +38,9 @@ #include "common/init.cpp" int fwbdebug = 0; -//QString user_name; -FWWindow *mw = nullptr; -FWBSettings *st = nullptr; -FWBApplication *app = nullptr; +FWWindow *mw = nullptr; +FWBSettings *st = nullptr; +FWBApplication *app = nullptr; std::string platform; int main(int argc, char** argv) @@ -51,11 +49,6 @@ int main(int argc, char** argv) init(argv); Resources res(Constants::getResourcesFilePath()); - CppUnit::TextUi::TestRunner runner; - runner.addTest( ImporterTest::suite() ); - runner.setOutputter( new CppUnit::CompilerOutputter( &runner.result(), - std::cerr ) ); - runner.run(); - return 0; + return QTest::qExec(new ImporterTest()); } diff --git a/src/unit_tests/Inet6AddrMaskTest/CMakeLists.txt b/src/unit_tests/Inet6AddrMaskTest/CMakeLists.txt index 020f79dc1..507e3b9b9 100644 --- a/src/unit_tests/Inet6AddrMaskTest/CMakeLists.txt +++ b/src/unit_tests/Inet6AddrMaskTest/CMakeLists.txt @@ -1,4 +1,6 @@ +set (CMAKE_AUTOMOC ON) + add_executable(Inet6AddrMaskTest Inet6AddrMaskTest.cpp main.cpp) add_test(NAME Inet6AddrMaskTest COMMAND Inet6AddrMaskTest) -target_link_libraries(Inet6AddrMaskTest PRIVATE fwbuilder xml2 xslt z cppunit) +target_link_libraries(Inet6AddrMaskTest PRIVATE fwbuilder xml2 xslt z Qt5::Test) diff --git a/src/unit_tests/Inet6AddrMaskTest/Inet6AddrMaskTest.cpp b/src/unit_tests/Inet6AddrMaskTest/Inet6AddrMaskTest.cpp index 18f8adf41..c0da0c625 100644 --- a/src/unit_tests/Inet6AddrMaskTest/Inet6AddrMaskTest.cpp +++ b/src/unit_tests/Inet6AddrMaskTest/Inet6AddrMaskTest.cpp @@ -27,6 +27,8 @@ #include #include +#include + using namespace libfwbuilder; using namespace std; @@ -36,110 +38,119 @@ void Inet6AddrMaskTest::testUInt128ToInetAddr6() uint128 x = x1.to_uint128(); InetAddr x2(AF_INET6, 0); x2.init_from_uint128(x); - CPPUNIT_ASSERT(x2.toString() == "::1"); + QVERIFY(x2.toString() == "::1"); InetAddr x3(AF_INET6, "::8000"); x = x3.to_uint128(); InetAddr x4(AF_INET6, 0); x4.init_from_uint128(x); - CPPUNIT_ASSERT(x4.toString() == "::8000"); + QVERIFY(x4.toString() == "::8000"); InetAddr x5(AF_INET6, "::ff00"); x = x5.to_uint128(); InetAddr x6(AF_INET6, 0); x6.init_from_uint128(x); - CPPUNIT_ASSERT(x6.toString() == "::ff00"); + QVERIFY(x6.toString() == "::ff00"); InetAddr x90(AF_INET6, "fe80::20c:29ff:fed2:cca1"); x = x90.to_uint128(); InetAddr x91(AF_INET6, 0); x91.init_from_uint128(x); - CPPUNIT_ASSERT(x91.toString() == "fe80::20c:29ff:fed2:cca1"); + QVERIFY(x91.toString() == "fe80::20c:29ff:fed2:cca1"); } void Inet6AddrMaskTest::testInetAddr6ToUInt128() { InetAddr x1(AF_INET6, 0); uint128 x = x1.to_uint128(); - CPPUNIT_ASSERT(x.to_string() == "0"); + QVERIFY(x.to_string() == "0"); InetAddr x2(AF_INET6, 1); x = x2.to_uint128(); - CPPUNIT_ASSERT(x.to_string() == "800000000000000000000000"); + QVERIFY(x.to_string() == "800000000000000000000000"); InetAddr x3(AF_INET6, 8); x = x3.to_uint128(); - CPPUNIT_ASSERT(x.to_string() == "FF0000000000000000000000"); + QVERIFY(x.to_string() == "FF0000000000000000000000"); InetAddr x4(AF_INET6, 16); x = x4.to_uint128(); - CPPUNIT_ASSERT(x.to_string() == "FFFF00000000000000000000"); + QVERIFY(x.to_string() == "FFFF00000000000000000000"); InetAddr x5(AF_INET6, 64); x = x5.to_uint128(); - CPPUNIT_ASSERT(x.to_string() == "FFFFFFFFFFFFFFFF00000000"); + QVERIFY(x.to_string() == "FFFFFFFFFFFFFFFF00000000"); InetAddr x6(AF_INET6, 128); x = x6.to_uint128(); - CPPUNIT_ASSERT(x.to_string() == "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"); + QVERIFY(x.to_string() == "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"); InetAddr x7(AF_INET6, "fe80::20c:29ff:fed2:cca1"); x = x7.to_uint128(); - CPPUNIT_ASSERT(x.to_string() == "FE8000000000000020C29FFFED2CCA1"); + QVERIFY(x.to_string() == "FE8000000000000020C29FFFED2CCA1"); } void Inet6AddrMaskTest::testIntToInetAddr6() { InetAddr x1(AF_INET6, 0); - CPPUNIT_ASSERT(x1.toString()=="::" && x1.getLength()==128); + QVERIFY(x1.toString()=="::" && x1.getLength()==128); InetAddr x2(AF_INET6, 1); - CPPUNIT_ASSERT(x2.toString()=="8000::" && x2.getLength()==1); + QVERIFY(x2.toString()=="8000::" && x2.getLength()==1); InetAddr x3(AF_INET6, 8); - CPPUNIT_ASSERT(x3.toString()=="ff00::" && x3.getLength()==8); + QVERIFY(x3.toString()=="ff00::" && x3.getLength()==8); InetAddr x4(AF_INET6, 16); - CPPUNIT_ASSERT(x4.toString()=="ffff::" && x4.getLength()==16); + QVERIFY(x4.toString()=="ffff::" && x4.getLength()==16); InetAddr x5(AF_INET6, 64); - CPPUNIT_ASSERT(x5.toString()=="ffff:ffff:ffff:ffff::" && x5.getLength()==64); + QVERIFY(x5.toString()=="ffff:ffff:ffff:ffff::" && x5.getLength()==64); InetAddr x6(AF_INET6, 128); - CPPUNIT_ASSERT(x6.toString()=="ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff" && x6.getLength()==128); + QVERIFY(x6.toString()=="ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff" && x6.getLength()==128); -} +} void Inet6AddrMaskTest::testStringToInetAddr6() { InetAddr *sa1 = new InetAddr(AF_INET6, "::"); - CPPUNIT_ASSERT_MESSAGE(sa1->toString(), sa1->toString() == "::"); + QVERIFY2(sa1->toString() == "::", sa1->toString().data()); sa1 = new InetAddr(AF_INET6, "::1"); - CPPUNIT_ASSERT_MESSAGE(sa1->toString(), sa1->toString() == "::1"); - + QVERIFY2(sa1->toString() == "::1", sa1->toString().data()); + sa1 = new InetAddr(AF_INET6, "fe80::20c:29ff:fed2:cca1"); - CPPUNIT_ASSERT_MESSAGE(sa1->toString(), - sa1->toString() == "fe80::20c:29ff:fed2:cca1"); + QVERIFY2(sa1->toString() == "fe80::20c:29ff:fed2:cca1", sa1->toString().data()); InetAddr x6(AF_INET6, "64"); - CPPUNIT_ASSERT_MESSAGE(x6.toString(), - x6.toString()=="ffff:ffff:ffff:ffff::"); - CPPUNIT_ASSERT(x6.getLength()==64); + QVERIFY2(x6.toString()=="ffff:ffff:ffff:ffff::", x6.toString().data()); + QVERIFY(x6.getLength()==64); } void Inet6AddrMaskTest::testStringToInetAddrExceptions() { - CPPUNIT_ASSERT_THROW(new InetAddr(AF_INET, "fe80::20c:29ff:fed2:cca1"), FWException); - CPPUNIT_ASSERT_THROW(new InetAddr("fe80::20c:29ff:fed2:cca1"), FWException); - CPPUNIT_ASSERT_NO_THROW(new InetAddr(AF_INET6, "fe80::20c:29ff:fed2:cca1/64")); - CPPUNIT_ASSERT_THROW(new InetAddr(AF_INET6, "fe80::20c:29ff:fed2:cca1/200"), FWException); - CPPUNIT_ASSERT_THROW(new InetAddr(AF_INET6, "fe80::foo:bar:fed2:cca1"), FWException); - CPPUNIT_ASSERT_THROW(new InetAddr(AF_INET6, "1.2.3.4"), FWException); + QVERIFY_EXCEPTION_THROWN(new InetAddr(AF_INET, "fe80::20c:29ff:fed2:cca1"), FWException); + QVERIFY_EXCEPTION_THROWN(new InetAddr("fe80::20c:29ff:fed2:cca1"), FWException); - CPPUNIT_ASSERT_NO_THROW(new InetAddr(AF_INET6, 64)); - CPPUNIT_ASSERT_THROW(new InetAddr(AF_INET6, 256), FWException); + try { + new InetAddr(AF_INET6, "fe80::20c:29ff:fed2:cca1/64"); + } catch (const std::exception &e) { + QFAIL(std::string("Exception thrown: ").append(e.what()).data()); + } + + QVERIFY_EXCEPTION_THROWN(new InetAddr(AF_INET6, "fe80::20c:29ff:fed2:cca1/200"), FWException); + QVERIFY_EXCEPTION_THROWN(new InetAddr(AF_INET6, "fe80::foo:bar:fed2:cca1"), FWException); + QVERIFY_EXCEPTION_THROWN(new InetAddr(AF_INET6, "1.2.3.4"), FWException); + + try { + new InetAddr(AF_INET6, 64); + } catch (const std::exception &e) { + QFAIL(std::string("Exception thrown: ").append(e.what()).data()); + } + + QVERIFY_EXCEPTION_THROWN(new InetAddr(AF_INET6, 256), FWException); } /* @@ -152,45 +163,45 @@ void Inet6AddrMaskTest::testInet6AddressOps() InetAddr y6(AF_INET6, 64); InetAddr z1 = x7 & y6; - CPPUNIT_ASSERT(z1.toString()=="fe80::"); + QVERIFY(z1.toString()=="fe80::"); - CPPUNIT_ASSERT((~y6).toString()=="::ffff:ffff:ffff:ffff"); + QVERIFY((~y6).toString()=="::ffff:ffff:ffff:ffff"); InetAddr z2 = z1 | ~y6; - CPPUNIT_ASSERT_MESSAGE(z2.toString(), z2.toString()=="fe80::ffff:ffff:ffff:ffff"); + QVERIFY2(z2.toString()=="fe80::ffff:ffff:ffff:ffff", z2.toString().data()); InetAddr z3 = x7 + 1; - CPPUNIT_ASSERT_MESSAGE(z3.toString(), z3.toString() == "fe80::21d:9ff:fe8b:8e95"); + QVERIFY2(z3.toString() == "fe80::21d:9ff:fe8b:8e95", z3.toString().data()); InetAddr z4 = z3 - 1; - CPPUNIT_ASSERT_MESSAGE(z4.toString(), z4.toString() == "fe80::21d:9ff:fe8b:8e94"); + QVERIFY2(z4.toString() == "fe80::21d:9ff:fe8b:8e94", z4.toString().data()); InetAddr z5 = x7 + 65536; - CPPUNIT_ASSERT_MESSAGE(z5.toString(), z5.toString() == "fe80::21d:9ff:fe8c:8e94"); + QVERIFY2(z5.toString() == "fe80::21d:9ff:fe8c:8e94", z5.toString().data()); InetAddr z6 = z5 - 65536; - CPPUNIT_ASSERT_MESSAGE(z6.toString(), z6.toString() == "fe80::21d:9ff:fe8b:8e94"); + QVERIFY2(z6.toString() == "fe80::21d:9ff:fe8b:8e94", z6.toString().data()); InetAddr z7 = x7 + 2147483647; // 2^31-1 - CPPUNIT_ASSERT_MESSAGE(z7.toString(), z7.toString() == "fe80::21d:a00:7e8b:8e93"); + QVERIFY2(z7.toString() == "fe80::21d:a00:7e8b:8e93", z7.toString().data()); InetAddr z8 = z7 - 2147483647; - CPPUNIT_ASSERT_MESSAGE(z8.toString(), z8.toString() == "fe80::21d:9ff:fe8b:8e94"); + QVERIFY2(z8.toString() == "fe80::21d:9ff:fe8b:8e94", z8.toString().data()); InetAddr x8(AF_INET6, "fe80::21d:9ff:fe8b:1111"); - CPPUNIT_ASSERT(x7 > x8); - CPPUNIT_ASSERT(x8 < x7); + QVERIFY(x7 > x8); + QVERIFY(x8 < x7); unsigned int dist = x8.distance(x7); - CPPUNIT_ASSERT(dist == 32132); + QVERIFY(dist == 32132); InetAddr x9(AF_INET6, "fe80::21d:9ff:fe8b:8e94"); - CPPUNIT_ASSERT(x7 == x9); + QVERIFY(x7 == x9); InetAddr x10(AF_INET6, "fe80::21d:a00:7e8b:8e93"); - CPPUNIT_ASSERT(x10 > x9); - CPPUNIT_ASSERT(x9 < x10); + QVERIFY(x10 > x9); + QVERIFY(x9 < x10); } void Inet6AddrMaskTest::testStringToInetAddrMask() @@ -199,19 +210,19 @@ void Inet6AddrMaskTest::testStringToInetAddrMask() Inet6AddrMask *a1 = new Inet6AddrMask(); sa = a1->getAddressPtr()->toString(); - CPPUNIT_ASSERT(sa=="::"); + QVERIFY(sa=="::"); Inet6AddrMask *a2 = new Inet6AddrMask( InetAddr(AF_INET6, "fe80::21d:9ff:fe8b:8e94"), InetAddr(AF_INET6, 128)); sa = a2->getAddressPtr()->toString(); - CPPUNIT_ASSERT(sa=="fe80::21d:9ff:fe8b:8e94"); + QVERIFY(sa=="fe80::21d:9ff:fe8b:8e94"); sa = a2->getNetmaskPtr()->toString(); - CPPUNIT_ASSERT(sa=="ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff"); - CPPUNIT_ASSERT(a2->getNetmaskPtr()->getLength()==128); + QVERIFY(sa=="ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff"); + QVERIFY(a2->getNetmaskPtr()->getLength()==128); - CPPUNIT_ASSERT(a2->toString()=="fe80::21d:9ff:fe8b:8e94"); + QVERIFY(a2->toString()=="fe80::21d:9ff:fe8b:8e94"); Inet6AddrMask *a3 = new Inet6AddrMask( InetAddr(AF_INET6, "fe80::21d:9ff:fe8b:8e94"), @@ -219,33 +230,33 @@ void Inet6AddrMaskTest::testStringToInetAddrMask() a3->setNetmask(InetAddr(AF_INET6, 64)); sa = a3->getAddressPtr()->toString(); - CPPUNIT_ASSERT(sa=="fe80::21d:9ff:fe8b:8e94"); + QVERIFY(sa=="fe80::21d:9ff:fe8b:8e94"); sa = a3->getNetmaskPtr()->toString(); - CPPUNIT_ASSERT(sa=="ffff:ffff:ffff:ffff::"); - CPPUNIT_ASSERT(a3->getNetmaskPtr()->getLength()==64); - CPPUNIT_ASSERT(a3->toString()=="fe80::21d:9ff:fe8b:8e94/64"); + QVERIFY(sa=="ffff:ffff:ffff:ffff::"); + QVERIFY(a3->getNetmaskPtr()->getLength()==64); + QVERIFY(a3->toString()=="fe80::21d:9ff:fe8b:8e94/64"); Inet6AddrMask *a4 = new Inet6AddrMask( string("fe80::21d:9ff:fe8b:8e94/64")); sa = a4->getAddressPtr()->toString(); - CPPUNIT_ASSERT(sa=="fe80::21d:9ff:fe8b:8e94"); + QVERIFY(sa=="fe80::21d:9ff:fe8b:8e94"); sa = a4->getNetmaskPtr()->toString(); - CPPUNIT_ASSERT(sa=="ffff:ffff:ffff:ffff::"); + QVERIFY(sa=="ffff:ffff:ffff:ffff::"); - CPPUNIT_ASSERT(a4->belongs( *(a2->getAddressPtr()) )); + QVERIFY(a4->belongs( *(a2->getAddressPtr()) )); Inet6AddrMask *a5 = new Inet6AddrMask(*a3); sa = a5->getAddressPtr()->toString(); - CPPUNIT_ASSERT(sa=="fe80::21d:9ff:fe8b:8e94"); + QVERIFY(sa=="fe80::21d:9ff:fe8b:8e94"); sa = a5->getNetmaskPtr()->toString(); - CPPUNIT_ASSERT(sa=="ffff:ffff:ffff:ffff::"); + QVERIFY(sa=="ffff:ffff:ffff:ffff::"); a5->setAddress(InetAddr(AF_INET6, "3ffe:1200:2001:1:8000::1")); sa = a5->getAddressPtr()->toString(); - CPPUNIT_ASSERT(sa=="3ffe:1200:2001:1:8000::1"); + QVERIFY(sa=="3ffe:1200:2001:1:8000::1"); sa = a5->getNetmaskPtr()->toString(); - CPPUNIT_ASSERT(sa=="ffff:ffff:ffff:ffff::"); + QVERIFY(sa=="ffff:ffff:ffff:ffff::"); } diff --git a/src/unit_tests/Inet6AddrMaskTest/Inet6AddrMaskTest.h b/src/unit_tests/Inet6AddrMaskTest/Inet6AddrMaskTest.h index 0229c13ee..7b93eaf8e 100644 --- a/src/unit_tests/Inet6AddrMaskTest/Inet6AddrMaskTest.h +++ b/src/unit_tests/Inet6AddrMaskTest/Inet6AddrMaskTest.h @@ -26,11 +26,13 @@ #ifndef INET6ADDRMASKTEST_H #define INET6ADDRMASKTEST_H -#include +#include -class Inet6AddrMaskTest : public CppUnit::TestFixture +class Inet6AddrMaskTest : public QObject { -public: + Q_OBJECT + +private slots: void testStringToInetAddrExceptions(); void testIntToInetAddr6(); void testStringToInetAddr6(); @@ -39,18 +41,6 @@ public: void testUInt128ToInetAddr6(); void testInetAddr6ToUInt128(); - CPPUNIT_TEST_SUITE(Inet6AddrMaskTest); - - CPPUNIT_TEST(testStringToInetAddrExceptions); - CPPUNIT_TEST(testIntToInetAddr6); - CPPUNIT_TEST(testUInt128ToInetAddr6); - CPPUNIT_TEST(testInetAddr6ToUInt128); - CPPUNIT_TEST(testStringToInetAddr6); - CPPUNIT_TEST(testStringToInetAddrMask); - CPPUNIT_TEST(testInet6AddressOps); - - CPPUNIT_TEST_SUITE_END(); - }; #endif // INET6ADDRMASKTEST_H diff --git a/src/unit_tests/Inet6AddrMaskTest/main.cpp b/src/unit_tests/Inet6AddrMaskTest/main.cpp index 4f99edfe9..8b5488d06 100644 --- a/src/unit_tests/Inet6AddrMaskTest/main.cpp +++ b/src/unit_tests/Inet6AddrMaskTest/main.cpp @@ -23,28 +23,19 @@ */ -#include -#include #include "Inet6AddrMaskTest.h" #include "fwbuilder/FWObjectDatabase.h" #include +#include using namespace libfwbuilder; int fwbdebug = 0; -//QString user_name; std::string platform; int main( int, char** argv) { - //init(argv); init(); - CppUnit::TextUi::TestRunner runner; - runner.addTest( Inet6AddrMaskTest::suite() ); - runner.setOutputter( new CppUnit::CompilerOutputter( &runner.result(), - std::cerr ) ); - - runner.run(); - return 0; + return QTest::qExec(new Inet6AddrMaskTest()); } diff --git a/src/unit_tests/InetAddrMaskTest/CMakeLists.txt b/src/unit_tests/InetAddrMaskTest/CMakeLists.txt index 33edaf7f8..c765420a6 100644 --- a/src/unit_tests/InetAddrMaskTest/CMakeLists.txt +++ b/src/unit_tests/InetAddrMaskTest/CMakeLists.txt @@ -1,4 +1,6 @@ +set (CMAKE_AUTOMOC ON) + add_executable(InetAddrMaskTest InetAddrMaskTest.cpp main.cpp) add_test(NAME InetAddrMaskTest COMMAND InetAddrMaskTest) -target_link_libraries(InetAddrMaskTest PRIVATE fwbuilder xml2 xslt z cppunit) +target_link_libraries(InetAddrMaskTest PRIVATE fwbuilder xml2 xslt z Qt5::Test) diff --git a/src/unit_tests/InetAddrMaskTest/InetAddrMaskTest.cpp b/src/unit_tests/InetAddrMaskTest/InetAddrMaskTest.cpp index 5fad44eb6..c944c6d2f 100644 --- a/src/unit_tests/InetAddrMaskTest/InetAddrMaskTest.cpp +++ b/src/unit_tests/InetAddrMaskTest/InetAddrMaskTest.cpp @@ -25,6 +25,7 @@ #include "InetAddrMaskTest.h" #include +#include using namespace libfwbuilder; using namespace std; @@ -33,90 +34,111 @@ using namespace std; void InetAddrMaskTest::testIntToInetAddr() { InetAddr *sa1 = new InetAddr(0); - CPPUNIT_ASSERT_MESSAGE(sa1->toString(), sa1->toString() == "0.0.0.0"); - + QVERIFY2(sa1->toString() == "0.0.0.0", sa1->toString().data()); + sa1 = new InetAddr(AF_INET, 0); - CPPUNIT_ASSERT_MESSAGE(sa1->toString(), sa1->toString() == "0.0.0.0"); - + QVERIFY2(sa1->toString() == "0.0.0.0", sa1->toString().data()); + sa1 = new InetAddr(1); - CPPUNIT_ASSERT_MESSAGE(sa1->toString(), sa1->toString() == "128.0.0.0"); + QVERIFY2(sa1->toString() == "128.0.0.0", sa1->toString().data()); sa1 = new InetAddr(24); - CPPUNIT_ASSERT_MESSAGE(sa1->toString(), sa1->toString() == "255.255.255.0"); + QVERIFY2(sa1->toString() == "255.255.255.0", sa1->toString().data()); } void InetAddrMaskTest::testStringToInetAddr() { InetAddr *sa1 = new InetAddr("0.0.0.1"); - CPPUNIT_ASSERT_MESSAGE("0.0.0.1 -> " + sa1->toString(), sa1->toString() == "0.0.0.1"); - + QVERIFY2(sa1->toString() == "0.0.0.1", std::string("0.0.0.1 -> " + sa1->toString()).data()); + sa1 = new InetAddr("0.0.0.0"); - CPPUNIT_ASSERT_MESSAGE("0.0.0.0 -> " + sa1->toString(), sa1->toString() == "0.0.0.0"); - + QVERIFY2(sa1->toString() == "0.0.0.0", std::string("0.0.0.0 -> " + sa1->toString()).data()); + sa1 = new InetAddr("1.2.3.4"); - CPPUNIT_ASSERT_MESSAGE("1.2.3.4 -> " + sa1->toString(), sa1->toString() == "1.2.3.4"); + QVERIFY2(sa1->toString() == "1.2.3.4", std::string("1.2.3.4 -> " + sa1->toString()).data()); sa1 = new InetAddr("0.0.1"); - CPPUNIT_ASSERT_MESSAGE("0.0.1 -> " + sa1->toString(), sa1->toString() == "0.0.1.0"); + QVERIFY2(sa1->toString() == "0.0.1.0", std::string("0.0.1 -> " + sa1->toString()).data()); sa1 = new InetAddr("0.1"); - CPPUNIT_ASSERT_MESSAGE("0.1 -> " + sa1->toString(), sa1->toString() == "0.1.0.0"); - + QVERIFY2(sa1->toString() == "0.1.0.0", std::string("0.1 -> " + sa1->toString()).data()); + // "1" ---> "128.0.0.0" I am not sure this is correct sa1 = new InetAddr("1"); - CPPUNIT_ASSERT_MESSAGE("1 -> " + sa1->toString(), sa1->toString() == "128.0.0.0"); + QVERIFY2(sa1->toString() == "128.0.0.0", std::string("1 -> " + sa1->toString()).data()); sa1 = new InetAddr("1.0"); - CPPUNIT_ASSERT_MESSAGE("1.0 -> " + sa1->toString(), sa1->toString() == "1.0.0.0"); - + QVERIFY2(sa1->toString() == "1.0.0.0", std::string("1.0 -> " + sa1->toString()).data()); + sa1 = new InetAddr("1.0.0"); - CPPUNIT_ASSERT_MESSAGE("1.0.0 -> " + sa1->toString(), sa1->toString() == "1.0.0.0"); + QVERIFY2(sa1->toString() == "1.0.0.0", std::string("1.0.0 -> " + sa1->toString()).data()); sa1 = new InetAddr("255.255.255.255"); - CPPUNIT_ASSERT_MESSAGE("255.255.255.255 -> " + sa1->toString(), sa1->toString() == "255.255.255.255"); - CPPUNIT_ASSERT(sa1->isValidV4Netmask() == true); + QVERIFY2(sa1->toString() == "255.255.255.255", std::string("255.255.255.255 -> " + sa1->toString()).data()); + QVERIFY(sa1->isValidV4Netmask() == true); sa1 = new InetAddr("255.255.255.128"); - CPPUNIT_ASSERT_MESSAGE("255.255.255.128 -> " + sa1->toString(), sa1->toString() == "255.255.255.128"); - CPPUNIT_ASSERT(sa1->isValidV4Netmask() == true); + QVERIFY2(sa1->toString() == "255.255.255.128", std::string("255.255.255.128 -> " + sa1->toString()).data()); + QVERIFY(sa1->isValidV4Netmask() == true); sa1 = new InetAddr("255.255.255.0"); - CPPUNIT_ASSERT_MESSAGE("255.255.255.0 -> " + sa1->toString(), sa1->toString() == "255.255.255.0"); - CPPUNIT_ASSERT(sa1->isValidV4Netmask() == true); + QVERIFY2(sa1->toString() == "255.255.255.0", std::string("255.255.255.0 -> " + sa1->toString()).data()); + QVERIFY(sa1->isValidV4Netmask() == true); sa1 = new InetAddr("255.255.0.0"); - CPPUNIT_ASSERT_MESSAGE("255.255.0.0 -> " + sa1->toString(), sa1->toString() == "255.255.0.0"); - CPPUNIT_ASSERT(sa1->isValidV4Netmask() == true); + QVERIFY2(sa1->toString() == "255.255.0.0", std::string("255.255.0.0 -> " + sa1->toString()).data()); + QVERIFY(sa1->isValidV4Netmask() == true); sa1 = new InetAddr("255.0.0.0"); - CPPUNIT_ASSERT_MESSAGE("255.0.0.0 -> " + sa1->toString(), sa1->toString() == "255.0.0.0"); - CPPUNIT_ASSERT(sa1->isValidV4Netmask() == true); + QVERIFY2(sa1->toString() == "255.0.0.0", std::string("255.0.0.0 -> " + sa1->toString()).data()); + QVERIFY(sa1->isValidV4Netmask() == true); sa1 = new InetAddr("0.0.0.0"); - CPPUNIT_ASSERT_MESSAGE("0.0.0.0 -> " + sa1->toString(), sa1->toString() == "0.0.0.0"); - CPPUNIT_ASSERT(sa1->isValidV4Netmask() == true); + QVERIFY2(sa1->toString() == "0.0.0.0", std::string("0.0.0.0 -> " + sa1->toString()).data()); + QVERIFY(sa1->isValidV4Netmask() == true); sa1 = new InetAddr("255.0.255.0"); - CPPUNIT_ASSERT_MESSAGE("255.0.255.0 -> " + sa1->toString(), sa1->toString() == "255.0.255.0"); - CPPUNIT_ASSERT(sa1->isValidV4Netmask() == false); + QVERIFY2(sa1->toString() == "255.0.255.0", std::string("255.0.255.0 -> " + sa1->toString()).data()); + QVERIFY(sa1->isValidV4Netmask() == false); } void InetAddrMaskTest::testStringToInetAddrExceptions() { - CPPUNIT_ASSERT_NO_THROW(new InetAddr("1.2.3.4")); - CPPUNIT_ASSERT_NO_THROW(new InetAddr("1.2.3.4/24")); - CPPUNIT_ASSERT_THROW(new InetAddr("1.2.3.4/40"), FWException); + try { + new InetAddr("1.2.3.4"); + } catch (const std::exception &e) { + QFAIL(std::string("Exception thrown: ").append(e.what()).data()); + } - CPPUNIT_ASSERT_THROW(new InetAddr("300.300.300.300"), FWException); - CPPUNIT_ASSERT_THROW(new InetAddr("1.2.3.4.5"), FWException); - CPPUNIT_ASSERT_THROW(new InetAddr("foo.bar"), FWException); - CPPUNIT_ASSERT_THROW(new InetAddr("1.2.foo.bar"), FWException); + try { + new InetAddr("1.2.3.4/24"); + } catch (const std::exception &e) { + QFAIL(std::string("Exception thrown: ").append(e.what()).data()); + } + + QVERIFY_EXCEPTION_THROWN(new InetAddr("1.2.3.4/40"), FWException); + + QVERIFY_EXCEPTION_THROWN(new InetAddr("300.300.300.300"), FWException); + QVERIFY_EXCEPTION_THROWN(new InetAddr("1.2.3.4.5"), FWException); + QVERIFY_EXCEPTION_THROWN(new InetAddr("foo.bar"), FWException); + QVERIFY_EXCEPTION_THROWN(new InetAddr("1.2.foo.bar"), FWException); + + QVERIFY_EXCEPTION_THROWN(new InetAddr(40), FWException); + try { + new InetAddr(24); + } catch (const std::exception &e) { + QFAIL(std::string("Exception thrown: ").append(e.what()).data()); + } + + QVERIFY_EXCEPTION_THROWN(new InetAddr((char*)(nullptr)), FWException); + + try { + new InetAddr(0); + } catch (const std::exception &e) { + QFAIL(std::string("Exception thrown: ").append(e.what()).data()); + } - CPPUNIT_ASSERT_THROW(new InetAddr(40), FWException); - CPPUNIT_ASSERT_NO_THROW(new InetAddr(24)); - CPPUNIT_ASSERT_THROW(new InetAddr((char*)(nullptr)), FWException); - CPPUNIT_ASSERT_NO_THROW(new InetAddr(0)); } void InetAddrMaskTest::testInetAddressOps() @@ -125,30 +147,30 @@ void InetAddrMaskTest::testInetAddressOps() InetAddr y1(24); InetAddr z1 = x1 & y1; - CPPUNIT_ASSERT(z1.toString() == "1.2.3.0"); - CPPUNIT_ASSERT( (~y1).toString() == "0.0.0.255"); + QVERIFY(z1.toString() == "1.2.3.0"); + QVERIFY( (~y1).toString() == "0.0.0.255"); InetAddr z2 = z1 | ~y1; - CPPUNIT_ASSERT(z2.toString() == "1.2.3.255"); + QVERIFY(z2.toString() == "1.2.3.255"); InetAddr z3 = z1 | ~y1; - CPPUNIT_ASSERT(z3.toString() == "1.2.3.255"); + QVERIFY(z3.toString() == "1.2.3.255"); InetAddr z4 = x1 + 1; - CPPUNIT_ASSERT(z4.toString() == "1.2.3.5"); + QVERIFY(z4.toString() == "1.2.3.5"); InetAddr z5 = z4 - 1; - CPPUNIT_ASSERT(z5.toString() == "1.2.3.4"); + QVERIFY(z5.toString() == "1.2.3.4"); - CPPUNIT_ASSERT(z5 == x1); + QVERIFY(z5 == x1); InetAddr x2("255.255.255.255"); InetAddr z6 = x2 + 1; - CPPUNIT_ASSERT(z6.toString() == "0.0.0.0"); + QVERIFY(z6.toString() == "0.0.0.0"); InetAddr x3("1.2.2.4"); - CPPUNIT_ASSERT(x3 < x1); - CPPUNIT_ASSERT(x1 > x3); + QVERIFY(x3 < x1); + QVERIFY(x1 > x3); } @@ -157,73 +179,73 @@ void InetAddrMaskTest::testStringToInetAddrMask() string sa; InetAddrMask *a1 = new InetAddrMask(); - CPPUNIT_ASSERT(a1->toString() == "0.0.0.0/0.0.0.0"); + QVERIFY(a1->toString() == "0.0.0.0/0.0.0.0"); sa = a1->getAddressPtr()->toString(); - CPPUNIT_ASSERT(sa=="0.0.0.0"); + QVERIFY(sa=="0.0.0.0"); // 0.0.0.0/0.0.0.0 has maximum dimension (represents all possible addresses) - CPPUNIT_ASSERT(a1->dimension() == (((unsigned int)1)<<31)-1); + QVERIFY(a1->dimension() == (((unsigned int)1)<<31)-1); InetAddrMask *a2 = new InetAddrMask(InetAddr("1.1.1.1"), InetAddr("255.255.255.0")); sa = a2->getAddressPtr()->toString(); - CPPUNIT_ASSERT(sa=="1.1.1.0"); + QVERIFY(sa=="1.1.1.0"); sa = a2->getNetmaskPtr()->toString(); - CPPUNIT_ASSERT(sa=="255.255.255.0"); - CPPUNIT_ASSERT(a2->dimension()==256); - CPPUNIT_ASSERT(a2->toString()=="1.1.1.0/255.255.255.0"); + QVERIFY(sa=="255.255.255.0"); + QVERIFY(a2->dimension()==256); + QVERIFY(a2->toString()=="1.1.1.0/255.255.255.0"); InetAddrMask *a3 = new InetAddrMask(string("1.1.1.1")); sa = a3->getAddressPtr()->toString(); - CPPUNIT_ASSERT(sa=="1.1.1.1"); + QVERIFY(sa=="1.1.1.1"); sa = a3->getNetmaskPtr()->toString(); - CPPUNIT_ASSERT(sa=="255.255.255.255"); - CPPUNIT_ASSERT(a3->dimension()==1); + QVERIFY(sa=="255.255.255.255"); + QVERIFY(a3->dimension()==1); - CPPUNIT_ASSERT(a2->belongs( *(a3->getAddressPtr()) )); + QVERIFY(a2->belongs( *(a3->getAddressPtr()) )); InetAddrMask *a4 = new InetAddrMask(*a3); sa = a4->getAddressPtr()->toString(); - CPPUNIT_ASSERT(sa=="1.1.1.1"); + QVERIFY(sa=="1.1.1.1"); sa = a4->getNetmaskPtr()->toString(); - CPPUNIT_ASSERT(sa=="255.255.255.255"); - CPPUNIT_ASSERT(a4->dimension()==1); + QVERIFY(sa=="255.255.255.255"); + QVERIFY(a4->dimension()==1); a4->setAddress(InetAddr("2.2.2.2")); sa = a4->getAddressPtr()->toString(); - CPPUNIT_ASSERT(sa=="2.2.2.2"); + QVERIFY(sa=="2.2.2.2"); sa = a4->getNetmaskPtr()->toString(); - CPPUNIT_ASSERT(sa=="255.255.255.255"); - CPPUNIT_ASSERT(a4->dimension()==1); + QVERIFY(sa=="255.255.255.255"); + QVERIFY(a4->dimension()==1); a4->setNetmask(InetAddr("255.255.0.0")); sa = a4->getAddressPtr()->toString(); - CPPUNIT_ASSERT(sa=="2.2.2.2"); + QVERIFY(sa=="2.2.2.2"); sa = a4->getNetmaskPtr()->toString(); - CPPUNIT_ASSERT(sa=="255.255.0.0"); - CPPUNIT_ASSERT(a4->dimension()==256*256); + QVERIFY(sa=="255.255.0.0"); + QVERIFY(a4->dimension()==256*256); a4->setNetmask(InetAddr("8")); sa = a4->getAddressPtr()->toString(); - CPPUNIT_ASSERT(sa=="2.2.2.2"); + QVERIFY(sa=="2.2.2.2"); sa = a4->getNetmaskPtr()->toString(); - CPPUNIT_ASSERT(sa=="255.0.0.0"); - CPPUNIT_ASSERT(a4->dimension()==256*256*256); + QVERIFY(sa=="255.0.0.0"); + QVERIFY(a4->dimension()==256*256*256); - CPPUNIT_ASSERT_THROW(a4->setNetmask(InetAddr("40")), FWException); + QVERIFY_EXCEPTION_THROWN(a4->setNetmask(InetAddr("40")), FWException); // a4 should not have changed sa = a4->getAddressPtr()->toString(); - CPPUNIT_ASSERT(sa=="2.2.2.2"); + QVERIFY(sa=="2.2.2.2"); sa = a4->getNetmaskPtr()->toString(); - CPPUNIT_ASSERT(sa=="255.0.0.0"); - CPPUNIT_ASSERT(a4->dimension()==256*256*256); + QVERIFY(sa=="255.0.0.0"); + QVERIFY(a4->dimension()==256*256*256); InetAddrMask *a5 = new InetAddrMask(string("1.1.1.1/24")); sa = a5->getAddressPtr()->toString(); - CPPUNIT_ASSERT(sa=="1.1.1.1"); + QVERIFY(sa=="1.1.1.1"); sa = a5->getNetmaskPtr()->toString(); - CPPUNIT_ASSERT(sa=="255.255.255.0"); - CPPUNIT_ASSERT(a5->dimension()==256); + QVERIFY(sa=="255.255.255.0"); + QVERIFY(a5->dimension()==256); } @@ -248,7 +270,7 @@ void InetAddrMaskTest::testIPv4Overlap() InetAddrMask(InetAddr("10.0.0.0"), InetAddr("255.255.255.0")) ) ); - CPPUNIT_ASSERT(res=="10.0.0.0/255.255.255.0 "); + QVERIFY(res=="10.0.0.0/255.255.255.0 "); res = vectorInetAddrMaskToString( libfwbuilder::getOverlap( @@ -256,7 +278,7 @@ void InetAddrMaskTest::testIPv4Overlap() InetAddrMask(InetAddr("10.0.0.255"), InetAddr("255.255.255.255")) ) ); - CPPUNIT_ASSERT(res=="10.0.0.255/255.255.255.255 "); + QVERIFY(res=="10.0.0.255/255.255.255.255 "); res = vectorInetAddrMaskToString( libfwbuilder::getOverlap( @@ -264,7 +286,7 @@ void InetAddrMaskTest::testIPv4Overlap() InetAddrMask(InetAddr("10.0.0.0"), InetAddr("255.255.255.0")) ) ); - CPPUNIT_ASSERT(res=="10.0.0.255/255.255.255.255 "); + QVERIFY(res=="10.0.0.255/255.255.255.255 "); res = vectorInetAddrMaskToString( libfwbuilder::getOverlap( @@ -272,7 +294,7 @@ void InetAddrMaskTest::testIPv4Overlap() InetAddrMask(InetAddr("10.0.0.0"), InetAddr("255.255.255.0")) ) ); - CPPUNIT_ASSERT(res=="10.0.0.0/255.255.255.254 "); + QVERIFY(res=="10.0.0.0/255.255.255.254 "); res = vectorInetAddrMaskToString( libfwbuilder::getOverlap( @@ -280,7 +302,7 @@ void InetAddrMaskTest::testIPv4Overlap() InetAddrMask(InetAddr("10.0.0.0"), InetAddr("255.255.255.254")) ) ); - CPPUNIT_ASSERT(res=="10.0.0.0/255.255.255.254 "); + QVERIFY(res=="10.0.0.0/255.255.255.254 "); res = vectorInetAddrMaskToString( libfwbuilder::getOverlap( @@ -288,7 +310,7 @@ void InetAddrMaskTest::testIPv4Overlap() InetAddrMask(InetAddr("10.0.0.0"), InetAddr("255.255.255.0")) ) ); - CPPUNIT_ASSERT(res=="10.0.0.252/255.255.255.252 "); + QVERIFY(res=="10.0.0.252/255.255.255.252 "); res = vectorInetAddrMaskToString( libfwbuilder::getOverlap( @@ -296,7 +318,7 @@ void InetAddrMaskTest::testIPv4Overlap() InetAddrMask(InetAddr("10.0.0.252"), InetAddr("255.255.255.252")) ) ); - CPPUNIT_ASSERT(res=="10.0.0.252/255.255.255.252 "); + QVERIFY(res=="10.0.0.252/255.255.255.252 "); res = vectorInetAddrMaskToString( libfwbuilder::getOverlap( @@ -304,7 +326,7 @@ void InetAddrMaskTest::testIPv4Overlap() InetAddrMask(InetAddr("10.0.0.0"), InetAddr("255.255.255.0")) ) ); - CPPUNIT_ASSERT(res=="10.0.0.128/255.255.255.252 "); + QVERIFY(res=="10.0.0.128/255.255.255.252 "); res = vectorInetAddrMaskToString( libfwbuilder::getOverlap( @@ -312,7 +334,7 @@ void InetAddrMaskTest::testIPv4Overlap() InetAddrMask(InetAddr("10.0.0.128"), InetAddr("255.255.255.252")) ) ); - CPPUNIT_ASSERT(res=="10.0.0.128/255.255.255.252 "); + QVERIFY(res=="10.0.0.128/255.255.255.252 "); // test specifically for #1934 res = vectorInetAddrMaskToString( @@ -320,13 +342,13 @@ void InetAddrMaskTest::testIPv4Overlap() InetAddrMask(InetAddr("10.0.0.2"), InetAddr("255.255.255.254")), InetAddrMask(InetAddr("10.0.0.0"), InetAddr("255.255.255.0"))) ); - CPPUNIT_ASSERT(res=="10.0.0.2/255.255.255.254 "); + QVERIFY(res=="10.0.0.2/255.255.255.254 "); res = vectorInetAddrMaskToString( libfwbuilder::getOverlap( InetAddrMask(InetAddr("10.0.0.2"), InetAddr("255.255.255.254")), InetAddrMask(InetAddr("0.0.0.0"), InetAddr("0.0.0.0"))) ); - CPPUNIT_ASSERT(res=="10.0.0.2/255.255.255.254 "); + QVERIFY(res=="10.0.0.2/255.255.255.254 "); } diff --git a/src/unit_tests/InetAddrMaskTest/InetAddrMaskTest.h b/src/unit_tests/InetAddrMaskTest/InetAddrMaskTest.h index e7423807c..9964520d8 100644 --- a/src/unit_tests/InetAddrMaskTest/InetAddrMaskTest.h +++ b/src/unit_tests/InetAddrMaskTest/InetAddrMaskTest.h @@ -26,20 +26,20 @@ #ifndef INETADDRMASKTEST_H #define INETADDRMASKTEST_H -#include - #include "fwbuilder/InetAddrMask.h" #include +#include - -class InetAddrMaskTest : public CppUnit::TestFixture +class InetAddrMaskTest : public QObject { -public: + Q_OBJECT + std::string vectorInetAddrMaskToString( std::vector vect); - + +private slots: void testIntToInetAddr(); void testStringToInetAddr(); void testStringToInetAddrExceptions(); @@ -47,17 +47,6 @@ public: void testInetAddressOps(); void testIPv4Overlap(); - CPPUNIT_TEST_SUITE(InetAddrMaskTest); - - CPPUNIT_TEST(testStringToInetAddrExceptions); - CPPUNIT_TEST(testIntToInetAddr); - CPPUNIT_TEST(testStringToInetAddr); - CPPUNIT_TEST(testStringToInetAddrMask); - CPPUNIT_TEST(testInetAddressOps); - CPPUNIT_TEST(testIPv4Overlap); - - CPPUNIT_TEST_SUITE_END(); - }; #endif // INETADDRMASKTEST_H diff --git a/src/unit_tests/InetAddrMaskTest/main.cpp b/src/unit_tests/InetAddrMaskTest/main.cpp index 39bf02e7b..7e8730c38 100644 --- a/src/unit_tests/InetAddrMaskTest/main.cpp +++ b/src/unit_tests/InetAddrMaskTest/main.cpp @@ -23,27 +23,18 @@ */ -#include -#include #include "InetAddrMaskTest.h" #include "fwbuilder/FWObjectDatabase.h" #include +#include using namespace libfwbuilder; int fwbdebug = 0; -//QString user_name; std::string platform; int main( int, char** argv) { - //init(argv); init(); - CppUnit::TextUi::TestRunner runner; - runner.addTest( InetAddrMaskTest::suite() ); - runner.setOutputter( new CppUnit::CompilerOutputter( &runner.result(), - std::cerr ) ); - - runner.run(); - return 0; + return QTest::qExec(new InetAddrMaskTest()); } diff --git a/src/unit_tests/InterfaceDialogTest/CMakeLists.txt b/src/unit_tests/InterfaceDialogTest/CMakeLists.txt index d392ea7b8..47d019d24 100644 --- a/src/unit_tests/InterfaceDialogTest/CMakeLists.txt +++ b/src/unit_tests/InterfaceDialogTest/CMakeLists.txt @@ -3,4 +3,4 @@ SET(CMAKE_AUTOMOC ON) add_executable(InterfaceDialogTest InterfaceDialogTest.cpp main_InterfaceDialogTest.cpp) add_test(NAME InterfaceDialogTest COMMAND InterfaceDialogTest) -target_link_libraries(InterfaceDialogTest PRIVATE test_main netsnmp gui import fwbparser antlr common iptlib fwbpf fwbjuniper fwbcisco compilerdriver fwcompiler fwbuilder xml2 xslt z pthread Qt5::Test) +target_link_libraries(InterfaceDialogTest PRIVATE test_main gui import fwbparser antlr common iptlib fwbpf fwbjuniper fwbcisco compilerdriver fwcompiler fwbuilder netsnmp xml2 xslt z pthread Qt5::Test) diff --git a/src/unit_tests/InterfaceDialogTest/main_InterfaceDialogTest.cpp b/src/unit_tests/InterfaceDialogTest/main_InterfaceDialogTest.cpp index 54e060667..e3c7fddfb 100644 --- a/src/unit_tests/InterfaceDialogTest/main_InterfaceDialogTest.cpp +++ b/src/unit_tests/InterfaceDialogTest/main_InterfaceDialogTest.cpp @@ -37,9 +37,9 @@ using namespace std; using namespace libfwbuilder; int fwbdebug = 0; -FWWindow *mw = nullptr; -FWBSettings *st = nullptr; -FWBApplication *app = nullptr; +FWWindow *mw = nullptr; +FWBSettings *st = nullptr; +FWBApplication *app = nullptr; extern void build_app(int argc, char** argv, @@ -47,16 +47,18 @@ extern void build_app(int argc, char** argv, FWBSettings** st); int main(int argc, char** argv) -{ - app = new FWBApplication(argc, argv); - app->setOrganizationName(QLatin1String("NetCitadel")); - app->setApplicationName(QLatin1String("Firewall Builder")); +{ + app = new FWBApplication(argc, argv); + app->setOrganizationName(QLatin1String("NetCitadel")); + app->setApplicationName(QLatin1String("Firewall Builder")); build_app(argc, argv, &app, &st); - QTest::qExec(new InterfaceDialogTest()); + int testResult = QTest::qExec(new InterfaceDialogTest()); - if (QFile::exists("test_work.fwb")) - QFile::remove("test_work.fwb"); + if (QFile::exists("test_work.fwb")) + QFile::remove("test_work.fwb"); + + return testResult; } diff --git a/src/unit_tests/NetworkDialogTest/CMakeLists.txt b/src/unit_tests/NetworkDialogTest/CMakeLists.txt index 85f5373a6..018c86089 100644 --- a/src/unit_tests/NetworkDialogTest/CMakeLists.txt +++ b/src/unit_tests/NetworkDialogTest/CMakeLists.txt @@ -3,4 +3,4 @@ SET(CMAKE_AUTOMOC ON) add_executable(NetworkDialogTest NetworkDialogTest.cpp main_NetworkDialogTest.cpp) add_test(NAME NetworkDialogTest COMMAND NetworkDialogTest) -target_link_libraries(NetworkDialogTest PRIVATE test_main netsnmp gui import fwbparser antlr common iptlib fwbpf fwbjuniper fwbcisco compilerdriver fwcompiler fwbuilder xml2 xslt z pthread Qt5::Test) +target_link_libraries(NetworkDialogTest PRIVATE test_main gui import fwbparser antlr common iptlib fwbpf fwbjuniper fwbcisco compilerdriver fwcompiler fwbuilder netsnmp xml2 xslt z pthread Qt5::Test) diff --git a/src/unit_tests/NetworkDialogTest/main_NetworkDialogTest.cpp b/src/unit_tests/NetworkDialogTest/main_NetworkDialogTest.cpp index d8e34cf10..77619aaea 100644 --- a/src/unit_tests/NetworkDialogTest/main_NetworkDialogTest.cpp +++ b/src/unit_tests/NetworkDialogTest/main_NetworkDialogTest.cpp @@ -37,9 +37,9 @@ using namespace std; using namespace libfwbuilder; int fwbdebug = 0; -FWWindow *mw = nullptr; -FWBSettings *st = nullptr; -FWBApplication *app = nullptr; +FWWindow *mw = nullptr; +FWBSettings *st = nullptr; +FWBApplication *app = nullptr; extern void build_app(int argc, char** argv, @@ -47,16 +47,18 @@ extern void build_app(int argc, char** argv, FWBSettings** st); int main(int argc, char** argv) -{ - app = new FWBApplication(argc, argv); - app->setOrganizationName(QLatin1String("NetCitadel")); - app->setApplicationName(QLatin1String("Firewall Builder")); +{ + app = new FWBApplication(argc, argv); + app->setOrganizationName(QLatin1String("NetCitadel")); + app->setApplicationName(QLatin1String("Firewall Builder")); build_app(argc, argv, &app, &st); - QTest::qExec(new NetworkDialogTest()); + int testResult = QTest::qExec(new NetworkDialogTest()); - if (QFile::exists("test_work.fwb")) - QFile::remove("test_work.fwb"); + if (QFile::exists("test_work.fwb")) + QFile::remove("test_work.fwb"); + + return testResult; } diff --git a/src/unit_tests/ObjectManipulatorTest/CMakeLists.txt b/src/unit_tests/ObjectManipulatorTest/CMakeLists.txt index 810102d27..4b96cd8ac 100644 --- a/src/unit_tests/ObjectManipulatorTest/CMakeLists.txt +++ b/src/unit_tests/ObjectManipulatorTest/CMakeLists.txt @@ -3,6 +3,6 @@ SET(CMAKE_AUTOMOC ON) add_executable(ObjectManipulatorTest ObjectManipulatorTest.cpp main_ObjectManipulatorTest.cpp) add_test(NAME ObjectManipulatorTest COMMAND ObjectManipulatorTest) -target_link_libraries(ObjectManipulatorTest PRIVATE test_main netsnmp gui import fwbparser antlr common iptlib fwbpf fwbjuniper fwbcisco compilerdriver fwcompiler fwbuilder xml2 xslt z pthread Qt5::Test) +target_link_libraries(ObjectManipulatorTest PRIVATE test_main gui import fwbparser antlr common iptlib fwbpf fwbjuniper fwbcisco compilerdriver fwcompiler fwbuilder netsnmp xml2 xslt z pthread Qt5::Test) file(COPY test.fwb DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) diff --git a/src/unit_tests/ObjectManipulatorTest/main_ObjectManipulatorTest.cpp b/src/unit_tests/ObjectManipulatorTest/main_ObjectManipulatorTest.cpp index d2d9f7632..7cdfeaa56 100644 --- a/src/unit_tests/ObjectManipulatorTest/main_ObjectManipulatorTest.cpp +++ b/src/unit_tests/ObjectManipulatorTest/main_ObjectManipulatorTest.cpp @@ -38,9 +38,9 @@ using namespace std; using namespace libfwbuilder; int fwbdebug = 0; -FWWindow *mw = nullptr; -FWBSettings *st = nullptr; -FWBApplication *app = nullptr; +FWWindow *mw = nullptr; +FWBSettings *st = nullptr; +FWBApplication *app = nullptr; extern void build_app(int argc, char** argv, @@ -48,17 +48,19 @@ extern void build_app(int argc, char** argv, FWBSettings** st); int main(int argc, char** argv) -{ - app = new FWBApplication(argc, argv); - app->setOrganizationName(QLatin1String("NetCitadel")); - app->setApplicationName(QLatin1String("Firewall Builder")); +{ + app = new FWBApplication(argc, argv); + app->setOrganizationName(QLatin1String("NetCitadel")); + app->setApplicationName(QLatin1String("Firewall Builder")); build_app(argc, argv, &app, &st); QFile::copy("test.fwb", "test_work.fwb"); - QTest::qExec(new ObjectManipulatorTest()); + int testResult = QTest::qExec(new ObjectManipulatorTest()); - if (QFile::exists("test_work.fwb")) - QFile::remove("test_work.fwb"); + if (QFile::exists("test_work.fwb")) + QFile::remove("test_work.fwb"); + + return testResult; } diff --git a/src/unit_tests/ObjectMatcherTest/CMakeLists.txt b/src/unit_tests/ObjectMatcherTest/CMakeLists.txt index 7e0a81efc..cea186f5e 100644 --- a/src/unit_tests/ObjectMatcherTest/CMakeLists.txt +++ b/src/unit_tests/ObjectMatcherTest/CMakeLists.txt @@ -1,6 +1,8 @@ +set (CMAKE_AUTOMOC ON) + add_executable(ObjectMatcherTest ObjectMatcherTest.cpp main.cpp) add_test(NAME ObjectMatcherTest COMMAND ObjectMatcherTest) -target_link_libraries(ObjectMatcherTest PRIVATE test_main netsnmp gui import fwbparser antlr common iptlib fwbpf fwbjuniper fwbcisco compilerdriver fwcompiler fwbuilder xml2 xslt z pthread cppunit) +target_link_libraries(ObjectMatcherTest PRIVATE test_main netsnmp gui import fwbparser antlr common iptlib fwbpf fwbjuniper fwbcisco compilerdriver fwcompiler fwbuilder xml2 xslt z pthread Qt5::Test) file(COPY test_data.fwb DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) diff --git a/src/unit_tests/ObjectMatcherTest/ObjectMatcherTest.cpp b/src/unit_tests/ObjectMatcherTest/ObjectMatcherTest.cpp index 5f140da28..f79a2b365 100644 --- a/src/unit_tests/ObjectMatcherTest/ObjectMatcherTest.cpp +++ b/src/unit_tests/ObjectMatcherTest/ObjectMatcherTest.cpp @@ -42,6 +42,8 @@ #include "fwbuilder/Firewall.h" #include "fwbuilder/Constants.h" +#include + using namespace libfwbuilder; using namespace std; @@ -73,101 +75,101 @@ void ObjectMatcherTest::matchTest() om.setAddressRangeMatchMode(ObjectMatcher::EXACT); Firewall *fw1 = Firewall::cast(dbsearch(db, "fw1")); - CPPUNIT_ASSERT(fw1 != nullptr); + QVERIFY(fw1 != nullptr); Interface *fw1_eth0 = Interface::cast(dbsearch(fw1, "eth0")); - CPPUNIT_ASSERT(fw1_eth0 != nullptr); + QVERIFY(fw1_eth0 != nullptr); Interface *fw1_eth1 = Interface::cast(dbsearch(fw1, "eth1")); - CPPUNIT_ASSERT(fw1_eth1 != nullptr); + QVERIFY(fw1_eth1 != nullptr); Interface *fw1_eth2 = Interface::cast(dbsearch(fw1, "eth2")); - CPPUNIT_ASSERT(fw1_eth2 != nullptr); + QVERIFY(fw1_eth2 != nullptr); IPv6 *fw1_eth2_ipv6 = IPv6::cast(dbsearch(fw1_eth2, "fw1:eth2:ipv6")); - CPPUNIT_ASSERT(fw1_eth2_ipv6 != nullptr); + QVERIFY(fw1_eth2_ipv6 != nullptr); physAddress *fw1_eth2_mac = physAddress::cast(dbsearch(fw1_eth2, "fw1:eth2:mac")); - CPPUNIT_ASSERT(fw1_eth2_mac != nullptr); + QVERIFY(fw1_eth2_mac != nullptr); Host *host1 = Host::cast(dbsearch(db, "host1")); - CPPUNIT_ASSERT(host1 != nullptr); + QVERIFY(host1 != nullptr); Host *host2 = Host::cast(dbsearch(db, "host2")); - CPPUNIT_ASSERT(host2 != nullptr); + QVERIFY(host2 != nullptr); Host *host3 = Host::cast(dbsearch(db, "host3")); - CPPUNIT_ASSERT(host3 != nullptr); + QVERIFY(host3 != nullptr); Interface *host1_eth0 = Interface::cast(dbsearch(host1, "eth0")); - CPPUNIT_ASSERT(host1_eth0 != nullptr); + QVERIFY(host1_eth0 != nullptr); Interface *host2_eth0 = Interface::cast(dbsearch(host2, "eth0")); - CPPUNIT_ASSERT(host2_eth0 != nullptr); + QVERIFY(host2_eth0 != nullptr); IPv4 *host2_eth0_ip = IPv4::cast(dbsearch(host2_eth0, "ip")); - CPPUNIT_ASSERT(host2_eth0_ip != nullptr); + QVERIFY(host2_eth0_ip != nullptr); Interface *host3_eth0 = Interface::cast(dbsearch(host3, "eth0")); - CPPUNIT_ASSERT(host3_eth0 != nullptr); + QVERIFY(host3_eth0 != nullptr); Interface *host3_eth1 = Interface::cast(dbsearch(host3, "eth1")); - CPPUNIT_ASSERT(host3_eth1 != nullptr); + QVERIFY(host3_eth1 != nullptr); - CPPUNIT_ASSERT(om.dispatch(fw1, fw1)); - CPPUNIT_ASSERT(om.dispatch(fw1_eth0, fw1)); - CPPUNIT_ASSERT(om.dispatch(fw1_eth1, fw1)); - CPPUNIT_ASSERT(om.dispatch(fw1_eth0, fw1_eth0)); + QVERIFY(om.dispatch(fw1, fw1)); + QVERIFY(om.dispatch(fw1_eth0, fw1)); + QVERIFY(om.dispatch(fw1_eth1, fw1)); + QVERIFY(om.dispatch(fw1_eth0, fw1_eth0)); - CPPUNIT_ASSERT( ! om.dispatch(fw1_eth2_ipv6, fw1)); + QVERIFY( ! om.dispatch(fw1_eth2_ipv6, fw1)); om.setIPV6(true); - CPPUNIT_ASSERT( om.dispatch(fw1_eth2_ipv6, fw1)); + QVERIFY( om.dispatch(fw1_eth2_ipv6, fw1)); om.setIPV6(false); - CPPUNIT_ASSERT(om.dispatch(fw1_eth2_mac, fw1)); + QVERIFY(om.dispatch(fw1_eth2_mac, fw1)); - CPPUNIT_ASSERT(om.dispatch(host1_eth0, fw1)); - CPPUNIT_ASSERT(om.dispatch(host1, fw1)); + QVERIFY(om.dispatch(host1_eth0, fw1)); + QVERIFY(om.dispatch(host1, fw1)); - CPPUNIT_ASSERT(static_cast(om.dispatch(host2_eth0_ip, fw1)) == false); - CPPUNIT_ASSERT(static_cast(om.dispatch(host2_eth0, fw1)) == false); - CPPUNIT_ASSERT(static_cast(om.dispatch(host2, fw1)) == false); + QVERIFY(static_cast(om.dispatch(host2_eth0_ip, fw1)) == false); + QVERIFY(static_cast(om.dispatch(host2_eth0, fw1)) == false); + QVERIFY(static_cast(om.dispatch(host2, fw1)) == false); om.setMatchSubnets(true); - CPPUNIT_ASSERT(om.dispatch(host2_eth0_ip, fw1)); + QVERIFY(om.dispatch(host2_eth0_ip, fw1)); om.setMatchSubnets(false); - CPPUNIT_ASSERT(static_cast(om.dispatch(host3_eth0, fw1)) == false); - CPPUNIT_ASSERT(static_cast(om.dispatch(host3_eth1, fw1)) == false); + QVERIFY(static_cast(om.dispatch(host3_eth0, fw1)) == false); + QVERIFY(static_cast(om.dispatch(host3_eth1, fw1)) == false); - CPPUNIT_ASSERT(om.dispatch(IPv4::cast(o("addr-192.168.1.1")), fw1)); - CPPUNIT_ASSERT(om.dispatch(IPv4::cast(o("addr-192.168.1.1")), fw1_eth1)); - CPPUNIT_ASSERT(static_cast(om.dispatch(IPv4::cast(o("addr-192.168.1.1")), fw1_eth0)) == false); + QVERIFY(om.dispatch(IPv4::cast(o("addr-192.168.1.1")), fw1)); + QVERIFY(om.dispatch(IPv4::cast(o("addr-192.168.1.1")), fw1_eth1)); + QVERIFY(static_cast(om.dispatch(IPv4::cast(o("addr-192.168.1.1")), fw1_eth0)) == false); om.setIPV6(true); - CPPUNIT_ASSERT(om.dispatch(IPv6::cast(o("addr-ipv6-1")), fw1)); - CPPUNIT_ASSERT(static_cast(om.dispatch(IPv6::cast(o("addr-ipv6-2")), fw1)) == false); - CPPUNIT_ASSERT(static_cast(om.dispatch(IPv4::cast(o("addr-192.168.1.1")), fw1)) == false); + QVERIFY(om.dispatch(IPv6::cast(o("addr-ipv6-1")), fw1)); + QVERIFY(static_cast(om.dispatch(IPv6::cast(o("addr-ipv6-2")), fw1)) == false); + QVERIFY(static_cast(om.dispatch(IPv4::cast(o("addr-192.168.1.1")), fw1)) == false); om.setIPV6(false); - CPPUNIT_ASSERT(static_cast(om.dispatch(IPv6::cast(o("addr-ipv6-1")), fw1)) == false); - CPPUNIT_ASSERT(static_cast(om.dispatch(IPv6::cast(o("addr-ipv6-2")), fw1)) == false); + QVERIFY(static_cast(om.dispatch(IPv6::cast(o("addr-ipv6-1")), fw1)) == false); + QVERIFY(static_cast(om.dispatch(IPv6::cast(o("addr-ipv6-2")), fw1)) == false); - CPPUNIT_ASSERT(static_cast(om.dispatch(Network::cast(o("net-192.168.1.0")), fw1)) == false); - CPPUNIT_ASSERT(static_cast(om.dispatch(Network::cast(o("net-192.168.1.0")), fw1_eth1)) == false); - CPPUNIT_ASSERT(static_cast(om.dispatch(Network::cast(o("net-192.168.1.0")), fw1_eth0)) == false); - CPPUNIT_ASSERT(om.dispatch(Network::cast(o("net-192.168.1.1")), fw1)); + QVERIFY(static_cast(om.dispatch(Network::cast(o("net-192.168.1.0")), fw1)) == false); + QVERIFY(static_cast(om.dispatch(Network::cast(o("net-192.168.1.0")), fw1_eth1)) == false); + QVERIFY(static_cast(om.dispatch(Network::cast(o("net-192.168.1.0")), fw1_eth0)) == false); + QVERIFY(om.dispatch(Network::cast(o("net-192.168.1.1")), fw1)); - CPPUNIT_ASSERT(om.dispatch(IPv4::cast(o("addr-192.168.1.255")), fw1)); - CPPUNIT_ASSERT(om.dispatch(IPv4::cast(o("addr-192.168.1.0")), fw1)); - CPPUNIT_ASSERT(om.dispatch(Network::cast(o("all multicasts")), fw1)); + QVERIFY(om.dispatch(IPv4::cast(o("addr-192.168.1.255")), fw1)); + QVERIFY(om.dispatch(IPv4::cast(o("addr-192.168.1.0")), fw1)); + QVERIFY(om.dispatch(Network::cast(o("all multicasts")), fw1)); om.setRecognizeBroadcasts(false); - CPPUNIT_ASSERT(static_cast(om.dispatch(IPv4::cast(o("addr-192.168.1.255")), fw1)) == false); - CPPUNIT_ASSERT(static_cast(om.dispatch(IPv4::cast(o("addr-192.168.1.0")), fw1)) == false); + QVERIFY(static_cast(om.dispatch(IPv4::cast(o("addr-192.168.1.255")), fw1)) == false); + QVERIFY(static_cast(om.dispatch(IPv4::cast(o("addr-192.168.1.0")), fw1)) == false); // ================================================================ // AddressRange tests @@ -175,16 +177,16 @@ void ObjectMatcherTest::matchTest() // range1 192.168.1.10 - 192.168.1.20 // does not match fw1 exactly, but matches when match_subnets == true - CPPUNIT_ASSERT(static_cast(om.dispatch(AddressRange::cast(o("range1")), fw1)) == false); + QVERIFY(static_cast(om.dispatch(AddressRange::cast(o("range1")), fw1)) == false); // range2 192.168.2.1-192.168.2.3 does not match fw1:eth2 at all - CPPUNIT_ASSERT(static_cast(om.dispatch(AddressRange::cast(o("range2")), fw1)) == false); + QVERIFY(static_cast(om.dispatch(AddressRange::cast(o("range2")), fw1)) == false); // range3 192.168.2.27-192.168.2.50 partially overlaps with fw1:eth2 subnet - CPPUNIT_ASSERT(static_cast(om.dispatch(AddressRange::cast(o("range3")), fw1)) == false); + QVERIFY(static_cast(om.dispatch(AddressRange::cast(o("range3")), fw1)) == false); // range4 192.168.2.27-192.168.2.30 is completely inside fw1:eth2 subnet - CPPUNIT_ASSERT(static_cast(om.dispatch(AddressRange::cast(o("range4")), fw1)) == false); + QVERIFY(static_cast(om.dispatch(AddressRange::cast(o("range4")), fw1)) == false); // ================================================================ om.setAddressRangeMatchMode(ObjectMatcher::PARTIAL); @@ -195,31 +197,31 @@ void ObjectMatcherTest::matchTest() // range3 192.168.2.27-192.168.2.50 partially overlaps with fw1:eth2 subnet // but address of interface 192.168.2.24 is outside the range - CPPUNIT_ASSERT(static_cast(om.dispatch(AddressRange::cast(o("range3")), fw1)) == false); + QVERIFY(static_cast(om.dispatch(AddressRange::cast(o("range3")), fw1)) == false); // range4 192.168.2.27-192.168.2.30 is completely inside fw1:eth2 subnet - CPPUNIT_ASSERT(static_cast(om.dispatch(AddressRange::cast(o("range4")), fw1)) == false); + QVERIFY(static_cast(om.dispatch(AddressRange::cast(o("range4")), fw1)) == false); // fw1:eth2:ip 192.168.2.24 falls inside range5 - CPPUNIT_ASSERT(om.dispatch(AddressRange::cast(o("range5")), fw1)); + QVERIFY(om.dispatch(AddressRange::cast(o("range5")), fw1)); // ================================================================ om.setMatchSubnets(true); // ranges will be compared to subnets defined by interface addr/mask // here match_subnets == true address_range_match_mode = PARTIAL - CPPUNIT_ASSERT(om.dispatch(host2_eth0_ip, fw1)); - CPPUNIT_ASSERT(om.dispatch(AddressRange::cast(o("range1")), fw1)); + QVERIFY(om.dispatch(host2_eth0_ip, fw1)); + QVERIFY(om.dispatch(AddressRange::cast(o("range1")), fw1)); // range2 192.168.2.1-192.168.2.3 does not match fw1:eth2 at all - CPPUNIT_ASSERT(static_cast(om.dispatch(AddressRange::cast(o("range2")), fw1)) == false); + QVERIFY(static_cast(om.dispatch(AddressRange::cast(o("range2")), fw1)) == false); // range3 192.168.2.27-192.168.2.50 partially overlaps with fw1:eth2 subnet - CPPUNIT_ASSERT(om.dispatch(AddressRange::cast(o("range3")), fw1)); + QVERIFY(om.dispatch(AddressRange::cast(o("range3")), fw1)); // range4 192.168.2.27-192.168.2.30 is completely inside fw1:eth2 subnet - CPPUNIT_ASSERT(om.dispatch(AddressRange::cast(o("range4")), fw1)); + QVERIFY(om.dispatch(AddressRange::cast(o("range4")), fw1)); // range5 192.168.2.21-192.168.2.27 partially overlaps with fw1:eth2 subnet - CPPUNIT_ASSERT(om.dispatch(AddressRange::cast(o("range5")), fw1)); + QVERIFY(om.dispatch(AddressRange::cast(o("range5")), fw1)); } diff --git a/src/unit_tests/ObjectMatcherTest/ObjectMatcherTest.h b/src/unit_tests/ObjectMatcherTest/ObjectMatcherTest.h index 2efad0b85..e559c95cb 100644 --- a/src/unit_tests/ObjectMatcherTest/ObjectMatcherTest.h +++ b/src/unit_tests/ObjectMatcherTest/ObjectMatcherTest.h @@ -26,24 +26,15 @@ #ifndef OBJECTMATCHERTEST_H #define OBJECTMATCHERTEST_H +#include -#include -#include -#include - -class ObjectMatcherTest : public CppUnit::TestCase +class ObjectMatcherTest : public QObject { -public: + Q_OBJECT + +private slots: void matchTest(); - static CppUnit::Test *suite() - { - CppUnit::TestSuite *suiteOfTests = new CppUnit::TestSuite( "ObjectMatcherTest" ); - suiteOfTests->addTest( new CppUnit::TestCaller( - "matchTest", - &ObjectMatcherTest::matchTest ) ); - return suiteOfTests; - } }; #endif // OBJECTMATCHERTEST_H diff --git a/src/unit_tests/ObjectMatcherTest/main.cpp b/src/unit_tests/ObjectMatcherTest/main.cpp index 518b51489..3071ad1a2 100644 --- a/src/unit_tests/ObjectMatcherTest/main.cpp +++ b/src/unit_tests/ObjectMatcherTest/main.cpp @@ -23,27 +23,18 @@ */ -#include -#include #include "ObjectMatcherTest.h" #include "fwbuilder/FWObjectDatabase.h" #include +#include using namespace libfwbuilder; int fwbdebug = 0; -//QString user_name; std::string platform; int main( int, char** argv) { - //init(argv); init(); - CppUnit::TextUi::TestRunner runner; - runner.addTest( ObjectMatcherTest::suite() ); - runner.setOutputter( new CppUnit::CompilerOutputter( &runner.result(), - std::cerr ) ); - - runner.run(); - return 0; + return QTest::qExec(new ObjectMatcherTest()); } diff --git a/src/unit_tests/PFImporterTest/CMakeLists.txt b/src/unit_tests/PFImporterTest/CMakeLists.txt index 425ff0cad..79c521163 100644 --- a/src/unit_tests/PFImporterTest/CMakeLists.txt +++ b/src/unit_tests/PFImporterTest/CMakeLists.txt @@ -1,7 +1,9 @@ +set (CMAKE_AUTOMOC ON) + add_executable(PFImporterTest PFImporterTest.cpp main_PFImporterTest.cpp) add_test(NAME PFImporterTest COMMAND PFImporterTest) -target_link_libraries(PFImporterTest PRIVATE test_main netsnmp gui import fwbparser antlr common iptlib fwbpf fwbjuniper fwbcisco compilerdriver fwcompiler fwbuilder xml2 xslt z pthread cppunit) +target_link_libraries(PFImporterTest PRIVATE test_main netsnmp gui import fwbparser antlr common iptlib fwbpf fwbjuniper fwbcisco compilerdriver fwcompiler fwbuilder xml2 xslt z pthread Qt5::Test) file(COPY test_data DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) diff --git a/src/unit_tests/PFImporterTest/PFImporterTest.cpp b/src/unit_tests/PFImporterTest/PFImporterTest.cpp index c980976dd..2c762f1c9 100644 --- a/src/unit_tests/PFImporterTest/PFImporterTest.cpp +++ b/src/unit_tests/PFImporterTest/PFImporterTest.cpp @@ -42,6 +42,7 @@ #include "fwbuilder/TagService.h" #include "fwbuilder/Constants.h" +#include #include #include #include @@ -67,7 +68,7 @@ class UpgradePredicate: public XMLTools::UpgradePredicate } }; -void PFImporterTest::setUp() +void PFImporterTest::init() { FWBTree *tree = new FWBTree(); @@ -122,22 +123,22 @@ void PFImporterTest::compareResults(QueueLogger* logger, QString result_file = rr.readAll(); QStringList expected_result = result_file.split("\n"); - CPPUNIT_ASSERT_MESSAGE( + QVERIFY2( + expected_result.size() == obtained_result.size(), QString( "Sizes of the generated importer output and test files are different.\n" "Expected: %1 (%2)\n" "Obtained: %3 (%4)\n" "diff -u %1 %3 | less -S") .arg(expected_result_file_name).arg(expected_result.size()) - .arg(obtained_result_file_name).arg(obtained_result.size()).toStdString(), - expected_result.size() == obtained_result.size()); + .arg(obtained_result_file_name).arg(obtained_result.size()).toStdString().data()); int max_idx = max(expected_result.size(), obtained_result.size()); 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]); - CPPUNIT_ASSERT_MESSAGE(err.toStdString(), obtained_result[i] == expected_result[i]); + QVERIFY2(obtained_result[i] == expected_result[i], err.toStdString().data()); } } @@ -152,7 +153,7 @@ void PFImporterTest::compareFwbFiles(QString expected_result_file_name, 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(); @@ -167,12 +168,12 @@ void PFImporterTest::compareFwbFiles(QString expected_result_file_name, "Obtained: %3 (%4)\n" "diff -u %1 %3 | less -S"); - CPPUNIT_ASSERT_MESSAGE( + QVERIFY2( + expected_result.size() == obtained_result.size(), err .arg(expected_result_file_name).arg(expected_result.size()) .arg(obtained_result_file_name).arg(obtained_result.size()) - .toStdString(), - expected_result.size() == obtained_result.size()); + .toStdString().data()); QRegExp last_mod_re("lastModified=\"\\d+\""); int max_idx = max(expected_result.size(), obtained_result.size()); @@ -189,7 +190,7 @@ void PFImporterTest::compareFwbFiles(QString expected_result_file_name, { QString err = QString("Line %1:\nExpected: '%2'\nResult: '%3'\n") .arg(i).arg(expected_result[i]).arg(obtained_result[i]); - CPPUNIT_ASSERT_MESSAGE(err.toStdString(), obtained_result[i] == expected_result[i]); + QVERIFY2(obtained_result[i] == expected_result[i], err.toStdString().data()); } } @@ -212,7 +213,13 @@ void PFImporterTest::macrosTest() Importer* imp = new PFImporter(lib, instream, logger, "test_fw"); imp->setAddStandardCommentsFlag(true); - CPPUNIT_ASSERT_NO_THROW( imp->run() ); + + try { + imp->run() ; + } catch (const std::exception &e) { + QFAIL(std::string("Exception thrown: ").append(e.what()).data()); + } + imp->finalize(); db->setPredictableIds(); @@ -231,7 +238,13 @@ void PFImporterTest::hostsMatchTest() Importer* imp = new PFImporter(lib, instream, logger, "test_fw"); imp->setAddStandardCommentsFlag(true); - CPPUNIT_ASSERT_NO_THROW( imp->run() ); + + try { + imp->run() ; + } catch (const std::exception &e) { + QFAIL(std::string("Exception thrown: ").append(e.what()).data()); + } + imp->finalize(); db->setPredictableIds(); @@ -253,7 +266,13 @@ void PFImporterTest::blockReturnTest() Importer* imp = new PFImporter(lib, instream, logger, "test_fw"); imp->setAddStandardCommentsFlag(true); - CPPUNIT_ASSERT_NO_THROW( imp->run() ); + + try { + imp->run() ; + } catch (const std::exception &e) { + QFAIL(std::string("Exception thrown: ").append(e.what()).data()); + } + imp->finalize(); db->setPredictableIds(); @@ -275,7 +294,13 @@ void PFImporterTest::icmpMatchTest() Importer* imp = new PFImporter(lib, instream, logger, "test_fw"); imp->setAddStandardCommentsFlag(true); - CPPUNIT_ASSERT_NO_THROW( imp->run() ); + + try { + imp->run() ; + } catch (const std::exception &e) { + QFAIL(std::string("Exception thrown: ").append(e.what()).data()); + } + imp->finalize(); db->setPredictableIds(); @@ -297,7 +322,13 @@ void PFImporterTest::interfaceMatchTest() Importer* imp = new PFImporter(lib, instream, logger, "test_fw"); imp->setAddStandardCommentsFlag(true); - CPPUNIT_ASSERT_NO_THROW( imp->run() ); + + try { + imp->run() ; + } catch (const std::exception &e) { + QFAIL(std::string("Exception thrown: ").append(e.what()).data()); + } + imp->finalize(); db->setPredictableIds(); @@ -319,7 +350,13 @@ void PFImporterTest::portMatchTest() Importer* imp = new PFImporter(lib, instream, logger, "test_fw"); imp->setAddStandardCommentsFlag(true); - CPPUNIT_ASSERT_NO_THROW( imp->run() ); + + try { + imp->run() ; + } catch (const std::exception &e) { + QFAIL(std::string("Exception thrown: ").append(e.what()).data()); + } + imp->finalize(); db->setPredictableIds(); @@ -341,7 +378,13 @@ void PFImporterTest::setCommandsTest() Importer* imp = new PFImporter(lib, instream, logger, "test_fw"); imp->setAddStandardCommentsFlag(true); - CPPUNIT_ASSERT_NO_THROW( imp->run() ); + + try { + imp->run() ; + } catch (const std::exception &e) { + QFAIL(std::string("Exception thrown: ").append(e.what()).data()); + } + imp->finalize(); //db->setPredictableIds(); @@ -363,7 +406,13 @@ void PFImporterTest::stateMatchTest() Importer* imp = new PFImporter(lib, instream, logger, "test_fw"); imp->setAddStandardCommentsFlag(true); - CPPUNIT_ASSERT_NO_THROW( imp->run() ); + + try { + imp->run() ; + } catch (const std::exception &e) { + QFAIL(std::string("Exception thrown: ").append(e.what()).data()); + } + imp->finalize(); db->setPredictableIds(); @@ -385,7 +434,13 @@ void PFImporterTest::tcpFlagsMatchTest() Importer* imp = new PFImporter(lib, instream, logger, "test_fw"); imp->setAddStandardCommentsFlag(true); - CPPUNIT_ASSERT_NO_THROW( imp->run() ); + + try { + imp->run() ; + } catch (const std::exception &e) { + QFAIL(std::string("Exception thrown: ").append(e.what()).data()); + } + imp->finalize(); db->setPredictableIds(); @@ -407,7 +462,13 @@ void PFImporterTest::natCommands() Importer* imp = new PFImporter(lib, instream, logger, "test_fw"); imp->setAddStandardCommentsFlag(true); - CPPUNIT_ASSERT_NO_THROW( imp->run() ); + + try { + imp->run() ; + } catch (const std::exception &e) { + QFAIL(std::string("Exception thrown: ").append(e.what()).data()); + } + imp->finalize(); db->setPredictableIds(); @@ -429,7 +490,13 @@ void PFImporterTest::rdrCommands() Importer* imp = new PFImporter(lib, instream, logger, "test_fw"); imp->setAddStandardCommentsFlag(true); - CPPUNIT_ASSERT_NO_THROW( imp->run() ); + + try { + imp->run() ; + } catch (const std::exception &e) { + QFAIL(std::string("Exception thrown: ").append(e.what()).data()); + } + imp->finalize(); db->setPredictableIds(); @@ -451,7 +518,13 @@ void PFImporterTest::setTimeoutCommands() Importer* imp = new PFImporter(lib, instream, logger, "test_fw"); imp->setAddStandardCommentsFlag(true); - CPPUNIT_ASSERT_NO_THROW( imp->run() ); + + try { + imp->run() ; + } catch (const std::exception &e) { + QFAIL(std::string("Exception thrown: ").append(e.what()).data()); + } + imp->finalize(); // db->setPredictableIds(); @@ -471,7 +544,13 @@ void PFImporterTest::scrubCommandsOld() Importer* imp = new PFImporter(lib, instream, logger, "test_fw"); imp->setAddStandardCommentsFlag(true); - CPPUNIT_ASSERT_NO_THROW( imp->run() ); + + try { + imp->run() ; + } catch (const std::exception &e) { + QFAIL(std::string("Exception thrown: ").append(e.what()).data()); + } + imp->finalize(); compareResults(logger, @@ -488,7 +567,13 @@ void PFImporterTest::scrubCommandsNew() Importer* imp = new PFImporter(lib, instream, logger, "test_fw"); imp->setAddStandardCommentsFlag(true); - CPPUNIT_ASSERT_NO_THROW( imp->run() ); + + try { + imp->run() ; + } catch (const std::exception &e) { + QFAIL(std::string("Exception thrown: ").append(e.what()).data()); + } + imp->finalize(); compareResults(logger, @@ -505,7 +590,13 @@ void PFImporterTest::tableDefinitions() Importer* imp = new PFImporter(lib, instream, logger, "test_fw"); imp->setAddStandardCommentsFlag(true); - CPPUNIT_ASSERT_NO_THROW( imp->run() ); + + try { + imp->run() ; + } catch (const std::exception &e) { + QFAIL(std::string("Exception thrown: ").append(e.what()).data()); + } + imp->finalize(); db->setPredictableIds(); @@ -525,7 +616,13 @@ void PFImporterTest::userGroupMatches() Importer* imp = new PFImporter(lib, instream, logger, "test_fw"); imp->setAddStandardCommentsFlag(true); - CPPUNIT_ASSERT_NO_THROW( imp->run() ); + + try { + imp->run() ; + } catch (const std::exception &e) { + QFAIL(std::string("Exception thrown: ").append(e.what()).data()); + } + imp->finalize(); db->setPredictableIds(); @@ -547,7 +644,13 @@ void PFImporterTest::routeToTest() Importer* imp = new PFImporter(lib, instream, logger, "test_fw"); imp->setAddStandardCommentsFlag(true); - CPPUNIT_ASSERT_NO_THROW( imp->run() ); + + try { + imp->run() ; + } catch (const std::exception &e) { + QFAIL(std::string("Exception thrown: ").append(e.what()).data()); + } + imp->finalize(); db->setPredictableIds(); @@ -566,7 +669,13 @@ void PFImporterTest::routeTo47Test() Importer* imp = new PFImporter(lib, instream, logger, "test_fw"); imp->setAddStandardCommentsFlag(true); - CPPUNIT_ASSERT_NO_THROW( imp->run() ); + + try { + imp->run() ; + } catch (const std::exception &e) { + QFAIL(std::string("Exception thrown: ").append(e.what()).data()); + } + imp->finalize(); db->setPredictableIds(); diff --git a/src/unit_tests/PFImporterTest/PFImporterTest.h b/src/unit_tests/PFImporterTest/PFImporterTest.h index 1bee17a3f..66a3f1ff2 100644 --- a/src/unit_tests/PFImporterTest/PFImporterTest.h +++ b/src/unit_tests/PFImporterTest/PFImporterTest.h @@ -30,23 +30,24 @@ #include "fwbuilder/FWException.h" #include "fwbuilder/Logger.h" -#include - #include #include #include +#include #include -class PFImporterTest : public CppUnit::TestFixture +class PFImporterTest : public QObject { + Q_OBJECT + libfwbuilder::FWObjectDatabase *db; libfwbuilder::Library *lib; libfwbuilder::QueueLogger *logger; int predictable_id_tracker; std::map id_mapping; - + void compareResults(libfwbuilder::QueueLogger* logger, QString expected_result_file_name, QString obtained_result_file_name); @@ -54,9 +55,9 @@ class PFImporterTest : public CppUnit::TestFixture QString obtained_result_file_name); std::string openTestFile(const QString &file_name); - -public: - void setUp(); + +private slots: + void init(); void macrosTest(); void hostsMatchTest(); @@ -76,29 +77,6 @@ public: void userGroupMatches(); void routeToTest(); void routeTo47Test(); - - CPPUNIT_TEST_SUITE(PFImporterTest); - - CPPUNIT_TEST(macrosTest); - CPPUNIT_TEST(hostsMatchTest); - CPPUNIT_TEST(blockReturnTest); - CPPUNIT_TEST(icmpMatchTest); - CPPUNIT_TEST(interfaceMatchTest); - CPPUNIT_TEST(portMatchTest); - CPPUNIT_TEST(setCommandsTest); - CPPUNIT_TEST(stateMatchTest); - CPPUNIT_TEST(tcpFlagsMatchTest); - CPPUNIT_TEST(natCommands); - CPPUNIT_TEST(rdrCommands); - CPPUNIT_TEST(setTimeoutCommands); - CPPUNIT_TEST(scrubCommandsOld); - CPPUNIT_TEST(scrubCommandsNew); - CPPUNIT_TEST(tableDefinitions); - CPPUNIT_TEST(userGroupMatches); - CPPUNIT_TEST(routeToTest); - CPPUNIT_TEST(routeTo47Test); - - CPPUNIT_TEST_SUITE_END(); }; diff --git a/src/unit_tests/PFImporterTest/main_PFImporterTest.cpp b/src/unit_tests/PFImporterTest/main_PFImporterTest.cpp index ec717671b..39d5c27e6 100644 --- a/src/unit_tests/PFImporterTest/main_PFImporterTest.cpp +++ b/src/unit_tests/PFImporterTest/main_PFImporterTest.cpp @@ -21,8 +21,6 @@ */ -#include -#include #include "PFImporterTest.h" #include "fwbuilder/Resources.h" @@ -30,6 +28,7 @@ #include "FWBSettings.h" #include "FWBApplication.h" +#include #include #include #include @@ -37,10 +36,9 @@ #include "common/init.cpp" int fwbdebug = 0; -//QString user_name; -FWWindow *mw = nullptr; -FWBSettings *st = nullptr; -FWBApplication *app = nullptr; +FWWindow *mw = nullptr; +FWBSettings *st = nullptr; +FWBApplication *app = nullptr; std::string platform; int main(int argc, char** argv) @@ -49,11 +47,6 @@ int main(int argc, char** argv) init(argv); Resources res(Constants::getResourcesFilePath()); - CppUnit::TextUi::TestRunner runner; - runner.addTest( PFImporterTest::suite() ); - runner.setOutputter( new CppUnit::CompilerOutputter( &runner.result(), - std::cerr ) ); - runner.run(); - return 0; + return QTest::qExec(new PFImporterTest()); } diff --git a/src/unit_tests/PIXImporterTest/CMakeLists.txt b/src/unit_tests/PIXImporterTest/CMakeLists.txt index 9cd53892f..e52ca338e 100644 --- a/src/unit_tests/PIXImporterTest/CMakeLists.txt +++ b/src/unit_tests/PIXImporterTest/CMakeLists.txt @@ -1,7 +1,9 @@ +set (CMAKE_AUTOMOC ON) + add_executable(PIXImporterTest PIXImporterTest.cpp main_PIXImporterTest.cpp) add_test(NAME PIXImporterTest COMMAND PIXImporterTest) -target_link_libraries(PIXImporterTest PRIVATE test_main netsnmp gui import fwbparser antlr common iptlib fwbpf fwbjuniper fwbcisco compilerdriver fwcompiler fwbuilder xml2 xslt z pthread cppunit) +target_link_libraries(PIXImporterTest PRIVATE test_main netsnmp gui import fwbparser antlr common iptlib fwbpf fwbjuniper fwbcisco compilerdriver fwcompiler fwbuilder xml2 xslt z pthread Qt5::Test) file(COPY test_data DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) diff --git a/src/unit_tests/PIXImporterTest/PIXImporterTest.cpp b/src/unit_tests/PIXImporterTest/PIXImporterTest.cpp index 721c1d9ae..9bb16cb62 100644 --- a/src/unit_tests/PIXImporterTest/PIXImporterTest.cpp +++ b/src/unit_tests/PIXImporterTest/PIXImporterTest.cpp @@ -42,6 +42,7 @@ #include "fwbuilder/TagService.h" #include "fwbuilder/Constants.h" +#include #include #include #include @@ -67,7 +68,7 @@ class UpgradePredicate: public XMLTools::UpgradePredicate } }; -void PIXImporterTest::setUp() +void PIXImporterTest::init() { FWBTree *tree = new FWBTree(); @@ -122,22 +123,22 @@ void PIXImporterTest::compareResults(QueueLogger* logger, QString result_file = rr.readAll(); QStringList expected_result = result_file.split("\n"); - CPPUNIT_ASSERT_MESSAGE( + QVERIFY2( + expected_result.size() == obtained_result.size(), QString( "Sizes of the generated importer output and test files are different.\n" "Expected: %1 (%2)\n" "Obtained: %3 (%4)\n" "diff -u %1 %3 | less -S") .arg(expected_result_file_name).arg(expected_result.size()) - .arg(obtained_result_file_name).arg(obtained_result.size()).toStdString(), - expected_result.size() == obtained_result.size()); + .arg(obtained_result_file_name).arg(obtained_result.size()).toStdString().data()); int max_idx = max(expected_result.size(), obtained_result.size()); 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]); - CPPUNIT_ASSERT_MESSAGE(err.toStdString(), obtained_result[i] == expected_result[i]); + QVERIFY2(obtained_result[i] == expected_result[i], err.toStdString().data()); } } @@ -152,7 +153,7 @@ void PIXImporterTest::compareFwbFiles(QString expected_result_file_name, 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(); @@ -167,12 +168,12 @@ void PIXImporterTest::compareFwbFiles(QString expected_result_file_name, "Obtained: %3 (%4)\n" "diff -u %1 %3 | less -S"); - CPPUNIT_ASSERT_MESSAGE( + QVERIFY2( + expected_result.size() == obtained_result.size(), err .arg(expected_result_file_name).arg(expected_result.size()) .arg(obtained_result_file_name).arg(obtained_result.size()) - .toStdString(), - expected_result.size() == obtained_result.size()); + .toStdString().data()); QRegExp last_mod_re("lastModified=\"\\d+\""); int max_idx = max(expected_result.size(), obtained_result.size()); @@ -189,7 +190,7 @@ void PIXImporterTest::compareFwbFiles(QString expected_result_file_name, { QString err = QString("Line %1:\nExpected: '%2'\nResult: '%3'\n") .arg(i).arg(expected_result[i]).arg(obtained_result[i]); - CPPUNIT_ASSERT_MESSAGE(err.toStdString(), obtained_result[i] == expected_result[i]); + QVERIFY2(obtained_result[i] == expected_result[i], err.toStdString().data()); } } @@ -211,7 +212,13 @@ void PIXImporterTest::PIX_6_Test() Importer* imp = new PIXImporter(lib, instream, logger, "test_fw"); imp->setAddStandardCommentsFlag(true); - CPPUNIT_ASSERT_NO_THROW( imp->run() ); + + try { + imp->run(); + } catch (const std::exception &e) { + QFAIL(std::string("Exception thrown: ").append(e.what()).data()); + } + imp->finalize(); db->setPredictableIds(); @@ -229,7 +236,13 @@ void PIXImporterTest::PIX_7_Test() Importer* imp = new PIXImporter(lib, instream, logger, "test_fw"); imp->setAddStandardCommentsFlag(true); - CPPUNIT_ASSERT_NO_THROW( imp->run() ); + + try { + imp->run(); + } catch (const std::exception &e) { + QFAIL(std::string("Exception thrown: ").append(e.what()).data()); + } + imp->finalize(); db->setPredictableIds(); @@ -247,7 +260,13 @@ void PIXImporterTest::PIX_7_NAT_Test() Importer* imp = new PIXImporter(lib, instream, logger, "test_fw"); imp->setAddStandardCommentsFlag(true); - CPPUNIT_ASSERT_NO_THROW( imp->run() ); + + try { + imp->run(); + } catch (const std::exception &e) { + QFAIL(std::string("Exception thrown: ").append(e.what()).data()); + } + imp->finalize(); db->setPredictableIds(); @@ -265,7 +284,13 @@ void PIXImporterTest::ASA_8_0_Test() Importer* imp = new PIXImporter(lib, instream, logger, "test_fw"); imp->setAddStandardCommentsFlag(true); - CPPUNIT_ASSERT_NO_THROW( imp->run() ); + + try { + imp->run(); + } catch (const std::exception &e) { + QFAIL(std::string("Exception thrown: ").append(e.what()).data()); + } + imp->finalize(); db->setPredictableIds(); @@ -283,7 +308,13 @@ void PIXImporterTest::ASA_8_3_Test() Importer* imp = new PIXImporter(lib, instream, logger, "test_fw"); imp->setAddStandardCommentsFlag(true); - CPPUNIT_ASSERT_NO_THROW( imp->run() ); + + try { + imp->run(); + } catch (const std::exception &e) { + QFAIL(std::string("Exception thrown: ").append(e.what()).data()); + } + imp->finalize(); db->setPredictableIds(); @@ -301,7 +332,13 @@ void PIXImporterTest::ObjectsAndGroupsTest() Importer* imp = new PIXImporter(lib, instream, logger, "test_fw"); imp->setAddStandardCommentsFlag(true); - CPPUNIT_ASSERT_NO_THROW( imp->run() ); + + try { + imp->run(); + } catch (const std::exception &e) { + QFAIL(std::string("Exception thrown: ").append(e.what()).data()); + } + imp->finalize(); db->setPredictableIds(); @@ -322,7 +359,13 @@ void PIXImporterTest::ACLObjectsAndGroupsTest() Importer* imp = new PIXImporter(lib, instream, logger, "test_fw"); imp->setAddStandardCommentsFlag(true); - CPPUNIT_ASSERT_NO_THROW( imp->run() ); + + try { + imp->run(); + } catch (const std::exception &e) { + QFAIL(std::string("Exception thrown: ").append(e.what()).data()); + } + imp->finalize(); db->setPredictableIds(); @@ -343,7 +386,13 @@ void PIXImporterTest::ACLTest() Importer* imp = new PIXImporter(lib, instream, logger, "test_fw"); imp->setAddStandardCommentsFlag(true); - CPPUNIT_ASSERT_NO_THROW( imp->run() ); + + try { + imp->run(); + } catch (const std::exception &e) { + QFAIL(std::string("Exception thrown: ").append(e.what()).data()); + } + imp->finalize(); db->setPredictableIds(); @@ -361,7 +410,13 @@ void PIXImporterTest::NamesTest() Importer* imp = new PIXImporter(lib, instream, logger, "test_fw"); imp->setAddStandardCommentsFlag(true); - CPPUNIT_ASSERT_NO_THROW( imp->run() ); + + try { + imp->run(); + } catch (const std::exception &e) { + QFAIL(std::string("Exception thrown: ").append(e.what()).data()); + } + imp->finalize(); db->setPredictableIds(); @@ -377,7 +432,13 @@ void PIXImporterTest::FWSM_4_1_Test() Importer* imp = new PIXImporter(lib, instream, logger, "test_fw"); imp->setAddStandardCommentsFlag(true); - CPPUNIT_ASSERT_NO_THROW( imp->run() ); + + try { + imp->run(); + } catch (const std::exception &e) { + QFAIL(std::string("Exception thrown: ").append(e.what()).data()); + } + imp->finalize(); db->setPredictableIds(); diff --git a/src/unit_tests/PIXImporterTest/PIXImporterTest.h b/src/unit_tests/PIXImporterTest/PIXImporterTest.h index 71ea3e2be..b7a6aafe0 100644 --- a/src/unit_tests/PIXImporterTest/PIXImporterTest.h +++ b/src/unit_tests/PIXImporterTest/PIXImporterTest.h @@ -30,24 +30,25 @@ #include "fwbuilder/FWException.h" #include "fwbuilder/Logger.h" -#include - #include #include #include +#include #include -class PIXImporterTest : public CppUnit::TestFixture +class PIXImporterTest : public QObject { + Q_OBJECT + libfwbuilder::FWObjectDatabase *db; libfwbuilder::Library *lib; libfwbuilder::QueueLogger *logger; int predictable_id_tracker; std::map id_mapping; - + void compareResults(libfwbuilder::QueueLogger* logger, QString expected_result_file_name, QString obtained_result_file_name); @@ -55,9 +56,9 @@ class PIXImporterTest : public CppUnit::TestFixture QString obtained_result_file_name); std::string openTestFile(const QString &file_name); - -public: - void setUp(); + +private slots: + void init(); void PIX_6_Test(); void PIX_7_Test(); @@ -70,20 +71,6 @@ public: void ACLTest(); void NamesTest(); - CPPUNIT_TEST_SUITE(PIXImporterTest); - CPPUNIT_TEST(PIX_6_Test); - CPPUNIT_TEST(PIX_7_Test); - CPPUNIT_TEST(PIX_7_NAT_Test); - CPPUNIT_TEST(ASA_8_0_Test); - CPPUNIT_TEST(ASA_8_3_Test); - CPPUNIT_TEST(ObjectsAndGroupsTest); - CPPUNIT_TEST(ACLObjectsAndGroupsTest); - CPPUNIT_TEST(ACLTest); - CPPUNIT_TEST(NamesTest); - CPPUNIT_TEST(FWSM_4_1_Test); - - CPPUNIT_TEST_SUITE_END(); - }; #endif // PIXIMPORTERTEST_H diff --git a/src/unit_tests/PIXImporterTest/main_PIXImporterTest.cpp b/src/unit_tests/PIXImporterTest/main_PIXImporterTest.cpp index 68d5f0a2b..94b2a10e1 100644 --- a/src/unit_tests/PIXImporterTest/main_PIXImporterTest.cpp +++ b/src/unit_tests/PIXImporterTest/main_PIXImporterTest.cpp @@ -21,8 +21,6 @@ */ -#include -#include #include "PIXImporterTest.h" #include "fwbuilder/Resources.h" @@ -30,6 +28,7 @@ #include "FWBSettings.h" #include "FWBApplication.h" +#include #include #include #include @@ -37,10 +36,9 @@ #include "common/init.cpp" int fwbdebug = 0; -//QString user_name; -FWWindow *mw = nullptr; -FWBSettings *st = nullptr; -FWBApplication *app = nullptr; +FWWindow *mw = nullptr; +FWBSettings *st = nullptr; +FWBApplication *app = nullptr; std::string platform; int main(int argc, char** argv) @@ -49,11 +47,6 @@ int main(int argc, char** argv) init(argv); Resources res(Constants::getResourcesFilePath()); - CppUnit::TextUi::TestRunner runner; - runner.addTest( PIXImporterTest::suite() ); - runner.setOutputter( new CppUnit::CompilerOutputter( &runner.result(), - std::cerr ) ); - runner.run(); - return 0; + return QTest::qExec(new PIXImporterTest()); } diff --git a/src/unit_tests/RCS/CMakeLists.txt b/src/unit_tests/RCS/CMakeLists.txt index c03dfa849..de4d3a6e7 100644 --- a/src/unit_tests/RCS/CMakeLists.txt +++ b/src/unit_tests/RCS/CMakeLists.txt @@ -1,6 +1,8 @@ +set (CMAKE_AUTOMOC ON) + add_executable(RCSTest RCSTest.cpp main_RCS.cpp) add_test(NAME RCSTest COMMAND RCSTest) -target_link_libraries(RCSTest PRIVATE test_main netsnmp gui import fwbparser antlr common iptlib fwbpf fwbjuniper fwbcisco compilerdriver fwcompiler fwbuilder xml2 xslt z pthread cppunit) +target_link_libraries(RCSTest PRIVATE test_main netsnmp gui import fwbparser antlr common iptlib fwbpf fwbjuniper fwbcisco compilerdriver fwcompiler fwbuilder xml2 xslt z pthread Qt5::Test) file(COPY rlog_unit_test.log "zu.fwb,v" DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) diff --git a/src/unit_tests/RCS/RCSTest.cpp b/src/unit_tests/RCS/RCSTest.cpp index dd35d2c51..19f67b58d 100644 --- a/src/unit_tests/RCS/RCSTest.cpp +++ b/src/unit_tests/RCS/RCSTest.cpp @@ -25,9 +25,9 @@ #include "RCSTest.h" -//#include "../../global.h" #include "../../libgui/RCS.h" +#include #include #include #include @@ -106,7 +106,7 @@ void RCSTest::verifyRevisions() realrevsmap[rev.rev] = rev; } - CPPUNIT_ASSERT(realrevs.size() == rcsrevs.size()); + QVERIFY(realrevs.size() == rcsrevs.size()); for (int i = 0; i < realrevs.size(); i++) { @@ -122,7 +122,7 @@ void RCSTest::verifyRevisions() qDebug() << "----------"; qDebug() << (realr == rcsr); */ - CPPUNIT_ASSERT (realr == rcsr); + QVERIFY (realr == rcsr); } } diff --git a/src/unit_tests/RCS/RCSTest.h b/src/unit_tests/RCS/RCSTest.h index 5645d83a2..b73ac9884 100644 --- a/src/unit_tests/RCS/RCSTest.h +++ b/src/unit_tests/RCS/RCSTest.h @@ -26,16 +26,14 @@ #ifndef RCSTEST_H #define RCSTEST_H -#include +#include -class RCSTest : public CppUnit::TestFixture +class RCSTest : public QObject { -public: - void verifyRevisions(); + Q_OBJECT - CPPUNIT_TEST_SUITE(RCSTest); - CPPUNIT_TEST(verifyRevisions); - CPPUNIT_TEST_SUITE_END(); +private slots: + void verifyRevisions(); }; diff --git a/src/unit_tests/RCS/main_RCS.cpp b/src/unit_tests/RCS/main_RCS.cpp index 53f6d4d80..3263f396a 100644 --- a/src/unit_tests/RCS/main_RCS.cpp +++ b/src/unit_tests/RCS/main_RCS.cpp @@ -23,22 +23,10 @@ */ -#include -#include #include "RCSTest.h" -#include -#include - -//int fwbdebug = 0; -//QString user_name; +#include int main( int, char** ) { - CppUnit::TextUi::TestRunner runner; - runner.addTest( RCSTest::suite() ); - runner.setOutputter( new CppUnit::CompilerOutputter( &runner.result(), - std::cerr ) ); - - runner.run(); - return 0; + return QTest::qExec(new RCSTest()); } diff --git a/src/unit_tests/RuleSetViewContextMenuTest/CMakeLists.txt b/src/unit_tests/RuleSetViewContextMenuTest/CMakeLists.txt index 4a98e4936..c60d26f90 100644 --- a/src/unit_tests/RuleSetViewContextMenuTest/CMakeLists.txt +++ b/src/unit_tests/RuleSetViewContextMenuTest/CMakeLists.txt @@ -3,4 +3,4 @@ SET(CMAKE_AUTOMOC ON) add_executable(RuleSetViewContextMenuTest RuleSetViewContextMenuTest.cpp main_RuleSetViewContextMenuTest.cpp) add_test(NAME RuleSetViewContextMenuTest COMMAND RuleSetViewContextMenuTest) -target_link_libraries(RuleSetViewContextMenuTest PRIVATE test_main netsnmp gui import fwbparser antlr common iptlib fwbpf fwbjuniper fwbcisco compilerdriver fwcompiler fwbuilder xml2 xslt z pthread Qt5::Test) +target_link_libraries(RuleSetViewContextMenuTest PRIVATE test_main gui import fwbparser antlr common iptlib fwbpf fwbjuniper fwbcisco compilerdriver fwcompiler fwbuilder netsnmp xml2 xslt z pthread Qt5::Test) diff --git a/src/unit_tests/RuleSetViewContextMenuTest/main_RuleSetViewContextMenuTest.cpp b/src/unit_tests/RuleSetViewContextMenuTest/main_RuleSetViewContextMenuTest.cpp index 5215479d9..80223db41 100644 --- a/src/unit_tests/RuleSetViewContextMenuTest/main_RuleSetViewContextMenuTest.cpp +++ b/src/unit_tests/RuleSetViewContextMenuTest/main_RuleSetViewContextMenuTest.cpp @@ -38,9 +38,9 @@ using namespace std; using namespace libfwbuilder; int fwbdebug = 0; -FWWindow *mw = nullptr; -FWBSettings *st = nullptr; -FWBApplication *app = nullptr; +FWWindow *mw = nullptr; +FWBSettings *st = nullptr; +FWBApplication *app = nullptr; extern void build_app(int argc, char** argv, @@ -48,16 +48,18 @@ extern void build_app(int argc, char** argv, FWBSettings** st); int main(int argc, char** argv) -{ - app = new FWBApplication(argc, argv); - app->setOrganizationName(QLatin1String("NetCitadel")); - app->setApplicationName(QLatin1String("Firewall Builder")); +{ + app = new FWBApplication(argc, argv); + app->setOrganizationName(QLatin1String("NetCitadel")); + app->setApplicationName(QLatin1String("Firewall Builder")); build_app(argc, argv, &app, &st); - QTest::qExec(new RuleSetViewContextMenuTest()); + int testResult = QTest::qExec(new RuleSetViewContextMenuTest()); - if (QFile::exists("test_work.fwb")) - QFile::remove("test_work.fwb"); + if (QFile::exists("test_work.fwb")) + QFile::remove("test_work.fwb"); + + return testResult; } diff --git a/src/unit_tests/RuleSetViewTest/CMakeLists.txt b/src/unit_tests/RuleSetViewTest/CMakeLists.txt index 67231b9a1..902c034a3 100644 --- a/src/unit_tests/RuleSetViewTest/CMakeLists.txt +++ b/src/unit_tests/RuleSetViewTest/CMakeLists.txt @@ -3,4 +3,4 @@ SET(CMAKE_AUTOMOC ON) add_executable(RuleSetViewTest RuleSetViewTest.cpp main_RuleSetViewTest.cpp) add_test(NAME RuleSetViewTest COMMAND RuleSetViewTest) -target_link_libraries(RuleSetViewTest PRIVATE test_main netsnmp gui import fwbparser antlr common iptlib fwbpf fwbjuniper fwbcisco compilerdriver fwcompiler fwbuilder xml2 xslt z pthread Qt5::Test) +target_link_libraries(RuleSetViewTest PRIVATE test_main gui import fwbparser antlr common iptlib fwbpf fwbjuniper fwbcisco compilerdriver fwcompiler fwbuilder netsnmp xml2 xslt z pthread Qt5::Test) diff --git a/src/unit_tests/RuleSetViewTest/main_RuleSetViewTest.cpp b/src/unit_tests/RuleSetViewTest/main_RuleSetViewTest.cpp index ff21e494c..f7db7d3cd 100644 --- a/src/unit_tests/RuleSetViewTest/main_RuleSetViewTest.cpp +++ b/src/unit_tests/RuleSetViewTest/main_RuleSetViewTest.cpp @@ -38,9 +38,9 @@ using namespace std; using namespace libfwbuilder; int fwbdebug = 0; -FWWindow *mw = nullptr; -FWBSettings *st = nullptr; -FWBApplication *app = nullptr; +FWWindow *mw = nullptr; +FWBSettings *st = nullptr; +FWBApplication *app = nullptr; extern void build_app(int argc, char** argv, @@ -48,16 +48,18 @@ extern void build_app(int argc, char** argv, FWBSettings** st); int main(int argc, char** argv) -{ - app = new FWBApplication(argc, argv); - app->setOrganizationName(QLatin1String("NetCitadel")); - app->setApplicationName(QLatin1String("Firewall Builder")); +{ + app = new FWBApplication(argc, argv); + app->setOrganizationName(QLatin1String("NetCitadel")); + app->setApplicationName(QLatin1String("Firewall Builder")); build_app(argc, argv, &app, &st); - QTest::qExec(new RuleSetViewTest()); + int testResult = QTest::qExec(new RuleSetViewTest()); - if (QFile::exists("test_work.fwb")) - QFile::remove("test_work.fwb"); + if (QFile::exists("test_work.fwb")) + QFile::remove("test_work.fwb"); + + return testResult; } diff --git a/src/unit_tests/TCPServiceDialogTest/CMakeLists.txt b/src/unit_tests/TCPServiceDialogTest/CMakeLists.txt index d4b4e5e3a..f9379fc00 100644 --- a/src/unit_tests/TCPServiceDialogTest/CMakeLists.txt +++ b/src/unit_tests/TCPServiceDialogTest/CMakeLists.txt @@ -3,4 +3,4 @@ SET(CMAKE_AUTOMOC ON) add_executable(TCPServiceDialogTest TCPServiceDialogTest.cpp main_TCPServiceDialogTest.cpp) add_test(NAME TCPServiceDialogTest COMMAND TCPServiceDialogTest) -target_link_libraries(TCPServiceDialogTest PRIVATE test_main netsnmp gui import fwbparser antlr common iptlib fwbpf fwbjuniper fwbcisco compilerdriver fwcompiler fwbuilder xml2 xslt z pthread Qt5::Test) +target_link_libraries(TCPServiceDialogTest PRIVATE test_main gui import fwbparser antlr common iptlib fwbpf fwbjuniper fwbcisco compilerdriver fwcompiler fwbuilder netsnmp xml2 xslt z pthread Qt5::Test) diff --git a/src/unit_tests/TCPServiceDialogTest/main_TCPServiceDialogTest.cpp b/src/unit_tests/TCPServiceDialogTest/main_TCPServiceDialogTest.cpp index 75abc37f8..dc7076d75 100644 --- a/src/unit_tests/TCPServiceDialogTest/main_TCPServiceDialogTest.cpp +++ b/src/unit_tests/TCPServiceDialogTest/main_TCPServiceDialogTest.cpp @@ -37,9 +37,9 @@ using namespace std; using namespace libfwbuilder; int fwbdebug = 0; -FWWindow *mw = nullptr; -FWBSettings *st = nullptr; -FWBApplication *app = nullptr; +FWWindow *mw = nullptr; +FWBSettings *st = nullptr; +FWBApplication *app = nullptr; extern void build_app(int argc, char** argv, @@ -47,16 +47,18 @@ extern void build_app(int argc, char** argv, FWBSettings** st); int main(int argc, char** argv) -{ - app = new FWBApplication(argc, argv); - app->setOrganizationName(QLatin1String("NetCitadel")); - app->setApplicationName(QLatin1String("Firewall Builder")); +{ + app = new FWBApplication(argc, argv); + app->setOrganizationName(QLatin1String("NetCitadel")); + app->setApplicationName(QLatin1String("Firewall Builder")); build_app(argc, argv, &app, &st); - QTest::qExec(new TCPServiceDialogTest()); + int testResult = QTest::qExec(new TCPServiceDialogTest()); - if (QFile::exists("test_work.fwb")) - QFile::remove("test_work.fwb"); + if (QFile::exists("test_work.fwb")) + QFile::remove("test_work.fwb"); + + return testResult; } diff --git a/src/unit_tests/TagServiceDialogTest/CMakeLists.txt b/src/unit_tests/TagServiceDialogTest/CMakeLists.txt index b9f43080a..415c51404 100644 --- a/src/unit_tests/TagServiceDialogTest/CMakeLists.txt +++ b/src/unit_tests/TagServiceDialogTest/CMakeLists.txt @@ -3,4 +3,4 @@ SET(CMAKE_AUTOMOC ON) add_executable(TagServiceDialogTest TagServiceDialogTest.cpp main_TagServiceDialogTest.cpp) add_test(NAME TagServiceDialogTest COMMAND TagServiceDialogTest) -target_link_libraries(TagServiceDialogTest PRIVATE test_main netsnmp gui import fwbparser antlr common iptlib fwbpf fwbjuniper fwbcisco compilerdriver fwcompiler fwbuilder xml2 xslt z pthread Qt5::Test) +target_link_libraries(TagServiceDialogTest PRIVATE test_main gui import fwbparser antlr common iptlib fwbpf fwbjuniper fwbcisco compilerdriver fwcompiler fwbuilder netsnmp xml2 xslt z pthread Qt5::Test) diff --git a/src/unit_tests/TagServiceDialogTest/main_TagServiceDialogTest.cpp b/src/unit_tests/TagServiceDialogTest/main_TagServiceDialogTest.cpp index bb9ff4b7e..73eba2356 100644 --- a/src/unit_tests/TagServiceDialogTest/main_TagServiceDialogTest.cpp +++ b/src/unit_tests/TagServiceDialogTest/main_TagServiceDialogTest.cpp @@ -38,9 +38,9 @@ using namespace std; using namespace libfwbuilder; int fwbdebug = 0; -FWWindow *mw = nullptr; -FWBSettings *st = nullptr; -FWBApplication *app = nullptr; +FWWindow *mw = nullptr; +FWBSettings *st = nullptr; +FWBApplication *app = nullptr; extern void build_app(int argc, char** argv, @@ -48,16 +48,17 @@ extern void build_app(int argc, char** argv, FWBSettings** st); int main(int argc, char** argv) -{ - app = new FWBApplication(argc, argv); - app->setOrganizationName(QLatin1String("NetCitadel")); - app->setApplicationName(QLatin1String("Firewall Builder")); +{ + app = new FWBApplication(argc, argv); + app->setOrganizationName(QLatin1String("NetCitadel")); + app->setApplicationName(QLatin1String("Firewall Builder")); build_app(argc, argv, &app, &st); - QTest::qExec(new TagServiceDialogTest()); + int testResult = QTest::qExec(new TagServiceDialogTest()); - if (QFile::exists("test_work.fwb")) - QFile::remove("test_work.fwb"); + if (QFile::exists("test_work.fwb")) + QFile::remove("test_work.fwb"); + + return testResult; } - diff --git a/src/unit_tests/UDPServiceDialogTest/CMakeLists.txt b/src/unit_tests/UDPServiceDialogTest/CMakeLists.txt index cd20f8119..7134d8971 100644 --- a/src/unit_tests/UDPServiceDialogTest/CMakeLists.txt +++ b/src/unit_tests/UDPServiceDialogTest/CMakeLists.txt @@ -3,4 +3,4 @@ SET(CMAKE_AUTOMOC ON) add_executable(UDPServiceDialogTest UDPServiceDialogTest.cpp main_UDPServiceDialogTest.cpp) add_test(NAME UDPServiceDialogTest COMMAND UDPServiceDialogTest) -target_link_libraries(UDPServiceDialogTest PRIVATE test_main netsnmp gui import fwbparser antlr common iptlib fwbpf fwbjuniper fwbcisco compilerdriver fwcompiler fwbuilder xml2 xslt z pthread Qt5::Test) +target_link_libraries(UDPServiceDialogTest PRIVATE test_main gui import fwbparser antlr common iptlib fwbpf fwbjuniper fwbcisco compilerdriver fwcompiler fwbuilder netsnmp xml2 xslt z pthread Qt5::Test) diff --git a/src/unit_tests/UDPServiceDialogTest/main_UDPServiceDialogTest.cpp b/src/unit_tests/UDPServiceDialogTest/main_UDPServiceDialogTest.cpp index 55fe8aca2..5744dff2a 100644 --- a/src/unit_tests/UDPServiceDialogTest/main_UDPServiceDialogTest.cpp +++ b/src/unit_tests/UDPServiceDialogTest/main_UDPServiceDialogTest.cpp @@ -37,9 +37,9 @@ using namespace std; using namespace libfwbuilder; int fwbdebug = 0; -FWWindow *mw = nullptr; -FWBSettings *st = nullptr; -FWBApplication *app = nullptr; +FWWindow *mw = nullptr; +FWBSettings *st = nullptr; +FWBApplication *app = nullptr; extern void build_app(int argc, char** argv, @@ -47,16 +47,18 @@ extern void build_app(int argc, char** argv, FWBSettings** st); int main(int argc, char** argv) -{ - app = new FWBApplication(argc, argv); - app->setOrganizationName(QLatin1String("NetCitadel")); - app->setApplicationName(QLatin1String("Firewall Builder")); +{ + app = new FWBApplication(argc, argv); + app->setOrganizationName(QLatin1String("NetCitadel")); + app->setApplicationName(QLatin1String("Firewall Builder")); build_app(argc, argv, &app, &st); - QTest::qExec(new UDPServiceDialogTest()); + int testResult = QTest::qExec(new UDPServiceDialogTest()); - if (QFile::exists("test_work.fwb")) - QFile::remove("test_work.fwb"); + if (QFile::exists("test_work.fwb")) + QFile::remove("test_work.fwb"); + + return testResult; } diff --git a/src/unit_tests/UsageResolverTest/CMakeLists.txt b/src/unit_tests/UsageResolverTest/CMakeLists.txt index 1379b454f..f31cd0151 100644 --- a/src/unit_tests/UsageResolverTest/CMakeLists.txt +++ b/src/unit_tests/UsageResolverTest/CMakeLists.txt @@ -1,4 +1,6 @@ +set (CMAKE_AUTOMOC ON) + add_executable(UsageResolverTest UsageResolverTest.cpp main_UsageResolverTest.cpp) add_test(NAME UsageResolverTest COMMAND UsageResolverTest) -target_link_libraries(UsageResolverTest PRIVATE test_main netsnmp gui import fwbparser antlr common iptlib fwbpf fwbjuniper fwbcisco compilerdriver fwcompiler fwbuilder xml2 xslt z pthread cppunit) +target_link_libraries(UsageResolverTest PRIVATE test_main gui import fwbparser antlr common iptlib fwbpf fwbjuniper fwbcisco compilerdriver fwcompiler fwbuilder netsnmp xml2 xslt z pthread Qt5::Test) diff --git a/src/unit_tests/UsageResolverTest/UsageResolverTest.cpp b/src/unit_tests/UsageResolverTest/UsageResolverTest.cpp index edeceaa2a..9748cada0 100644 --- a/src/unit_tests/UsageResolverTest/UsageResolverTest.cpp +++ b/src/unit_tests/UsageResolverTest/UsageResolverTest.cpp @@ -26,6 +26,7 @@ #include "UsageResolverTest.h" #include "UsageResolver.h" +#include #include #include @@ -38,7 +39,7 @@ void UsageResolverTest::addToLib(FWObject* obj) FWBTree().getStandardSlotForObject(lib, obj->getTypeName().c_str())->add(obj); } -void UsageResolverTest::setUp() +void UsageResolverTest::init() { db = new FWObjectDatabase(); db->setName("Database"); @@ -159,7 +160,7 @@ void UsageResolverTest::findWhereObjectIsUsed() set res; db->findWhereObjectIsUsed(addr1, db, res); - CPPUNIT_ASSERT(res.size() == 3); + QVERIFY(res.size() == 3); set::iterator iter = res.begin(); while (iter!=res.end()) @@ -173,24 +174,24 @@ void UsageResolverTest::findWhereObjectIsUsed() // if we get reference, the parent must be rule element or user group obj = obj->getParent(); - CPPUNIT_ASSERT( + QVERIFY( obj->getTypeName() == RuleElementSrc::TYPENAME || obj->getTypeName() == ObjectGroup::TYPENAME); if (RuleElementSrc::isA(obj)) { - CPPUNIT_ASSERT(obj->getParent()->getName() == "PolicyRule 1 of Firewall 1"); + QVERIFY(obj->getParent()->getName() == "PolicyRule 1 of Firewall 1"); } if (ObjectGroup::isA(obj)) { - CPPUNIT_ASSERT(obj->getName() == "Group 1"); + QVERIFY(obj->getName() == "Group 1"); } } else { // otherwise we should get system folder "Addresses" - CPPUNIT_ASSERT(name == "Addresses" ); + QVERIFY(name == "Addresses" ); } iter++; } @@ -204,26 +205,26 @@ void UsageResolverTest::findFirewallsForObject() qDebug() << "Dependencies for addr1:"; list res = UsageResolver().findFirewallsForObject(addr1, db); list::iterator iter = res.begin(); - CPPUNIT_ASSERT(res.size() == 3); + QVERIFY(res.size() == 3); while (iter!=res.end()) { string name = (*iter)->getName(); qDebug() << name.c_str() << "' (" << (*iter)->getTypeName().c_str() << ")"; - CPPUNIT_ASSERT ( name == "Firewall 1" || name == "Firewall 3" || name == "Firewall 4" ); + QVERIFY ( name == "Firewall 1" || name == "Firewall 3" || name == "Firewall 4" ); iter++; } qDebug() << "Dependencies for addr2:"; res = UsageResolver().findFirewallsForObject(addr2, db); iter = res.begin(); - CPPUNIT_ASSERT(res.size() == 4); + QVERIFY(res.size() == 4); while (iter!=res.end()) { string name = (*iter)->getName(); qDebug() << name.c_str() << "' (" << (*iter)->getTypeName().c_str() << ")"; - CPPUNIT_ASSERT ( name == "Firewall 1" || name == "Firewall 2" || name == "Firewall 3" || name == "Firewall 4"); + QVERIFY ( name == "Firewall 1" || name == "Firewall 2" || name == "Firewall 3" || name == "Firewall 4"); iter++; } @@ -231,13 +232,13 @@ void UsageResolverTest::findFirewallsForObject() qDebug() << "Dependencies for addr3:"; res = UsageResolver().findFirewallsForObject(addr3, db); iter = res.begin(); - //CPPUNIT_ASSERT(res.size() == 3); + //QVERIFY(res.size() == 3); while (iter!=res.end()) { string name = (*iter)->getName(); qDebug() << name.c_str() << "' (" << (*iter)->getTypeName().c_str() << ")"; - CPPUNIT_ASSERT ( name == "Firewall 2" || name == "Firewall 3" || name == "Firewall 4" ); + QVERIFY ( name == "Firewall 2" || name == "Firewall 3" || name == "Firewall 4" ); iter++; } } @@ -255,11 +256,11 @@ void UsageResolverTest::humanizeSearchResults() if (type == "ObjectRef") { FWObjectReference *o = FWObjectReference::cast(*iter); - CPPUNIT_ASSERT(o->getPointer()->getName() == "Address 1"); + QVERIFY(o->getPointer()->getName() == "Address 1"); } else { - CPPUNIT_ASSERT ( name == "Group 1" || name == "Addresses"); + QVERIFY ( name == "Group 1" || name == "Addresses"); } iter++; } diff --git a/src/unit_tests/UsageResolverTest/UsageResolverTest.h b/src/unit_tests/UsageResolverTest/UsageResolverTest.h index da87f9207..c206f3574 100644 --- a/src/unit_tests/UsageResolverTest/UsageResolverTest.h +++ b/src/unit_tests/UsageResolverTest/UsageResolverTest.h @@ -35,14 +35,14 @@ #include "fwbuilder/Library.h" #include "FWBTree.h" -#include +#include - -class UsageResolverTest : public CppUnit::TestFixture +class UsageResolverTest : public QObject { + Q_OBJECT + void addToLib(libfwbuilder::FWObject* obj); -public: libfwbuilder::FWObjectDatabase *db; libfwbuilder::Library *lib; libfwbuilder::IPv4 *addr1; @@ -50,19 +50,13 @@ public: libfwbuilder::IPv4 *addr3; libfwbuilder::PolicyRule *r1, *r2, *r3, *r4; - void setUp(); +private slots: + void init(); void findWhereObjectIsUsed(); void findFirewallsForObject(); void humanizeSearchResults(); - - CPPUNIT_TEST_SUITE(UsageResolverTest); - CPPUNIT_TEST(findWhereObjectIsUsed); - CPPUNIT_TEST(findFirewallsForObject); - CPPUNIT_TEST(humanizeSearchResults); - CPPUNIT_TEST_SUITE_END(); - }; #endif // FWOBJECTDATABASETEST_H diff --git a/src/unit_tests/UsageResolverTest/main_UsageResolverTest.cpp b/src/unit_tests/UsageResolverTest/main_UsageResolverTest.cpp index 951f4a9cb..a24a4e00e 100644 --- a/src/unit_tests/UsageResolverTest/main_UsageResolverTest.cpp +++ b/src/unit_tests/UsageResolverTest/main_UsageResolverTest.cpp @@ -23,21 +23,14 @@ */ -#include -#include #include "UsageResolverTest.h" #include +#include int fwbdebug = 0; QString user_name; int main( int, char** ) { - CppUnit::TextUi::TestRunner runner; - runner.addTest( UsageResolverTest::suite() ); - runner.setOutputter( new CppUnit::CompilerOutputter( &runner.result(), - std::cerr ) ); - - runner.run(); - return 0; + return QTest::qExec(new UsageResolverTest()); } diff --git a/src/unit_tests/UserSerivceDialogTest/CMakeLists.txt b/src/unit_tests/UserSerivceDialogTest/CMakeLists.txt index d1afbb881..dbbdcebb5 100644 --- a/src/unit_tests/UserSerivceDialogTest/CMakeLists.txt +++ b/src/unit_tests/UserSerivceDialogTest/CMakeLists.txt @@ -3,4 +3,4 @@ SET(CMAKE_AUTOMOC ON) add_executable(UserServiceDialogTest UserServiceDialogTest.cpp main_UserServiceDialogTest.cpp) add_test(NAME UserServiceDialogTest COMMAND UserServiceDialogTest) -target_link_libraries(UserServiceDialogTest PRIVATE test_main netsnmp gui import fwbparser antlr common iptlib fwbpf fwbjuniper fwbcisco compilerdriver fwcompiler fwbuilder xml2 xslt z pthread Qt5::Test) +target_link_libraries(UserServiceDialogTest PRIVATE test_main gui import fwbparser antlr common iptlib fwbpf fwbjuniper fwbcisco compilerdriver fwcompiler fwbuilder netsnmp xml2 xslt z pthread Qt5::Test) diff --git a/src/unit_tests/UserSerivceDialogTest/main_UserServiceDialogTest.cpp b/src/unit_tests/UserSerivceDialogTest/main_UserServiceDialogTest.cpp index 67ffe6491..af5ea4317 100644 --- a/src/unit_tests/UserSerivceDialogTest/main_UserServiceDialogTest.cpp +++ b/src/unit_tests/UserSerivceDialogTest/main_UserServiceDialogTest.cpp @@ -37,9 +37,9 @@ using namespace std; using namespace libfwbuilder; int fwbdebug = 0; -FWWindow *mw = nullptr; -FWBSettings *st = nullptr; -FWBApplication *app = nullptr; +FWWindow *mw = nullptr; +FWBSettings *st = nullptr; +FWBApplication *app = nullptr; extern void build_app(int argc, char** argv, @@ -47,16 +47,18 @@ extern void build_app(int argc, char** argv, FWBSettings** st); int main(int argc, char** argv) -{ - app = new FWBApplication(argc, argv); - app->setOrganizationName(QLatin1String("NetCitadel")); - app->setApplicationName(QLatin1String("Firewall Builder")); +{ + app = new FWBApplication(argc, argv); + app->setOrganizationName(QLatin1String("NetCitadel")); + app->setApplicationName(QLatin1String("Firewall Builder")); build_app(argc, argv, &app, &st); - QTest::qExec(new UserServiceDialogTest()); + int testResult = QTest::qExec(new UserServiceDialogTest()); - if (QFile::exists("test_work.fwb")) - QFile::remove("test_work.fwb"); + if (QFile::exists("test_work.fwb")) + QFile::remove("test_work.fwb"); + + return testResult; } diff --git a/src/unit_tests/compilerLibTest/CMakeLists.txt b/src/unit_tests/compilerLibTest/CMakeLists.txt index 90ca1082f..5e44ad642 100644 --- a/src/unit_tests/compilerLibTest/CMakeLists.txt +++ b/src/unit_tests/compilerLibTest/CMakeLists.txt @@ -5,6 +5,6 @@ add_definitions(-DPREFIX=\"${CMAKE_INSTALL_PREFIX}\") add_executable(compilerLibTest interfacePropertiesTest.cpp tests_main.cpp) add_test(NAME compilerLibTest COMMAND compilerLibTest) -target_link_libraries(compilerLibTest PRIVATE test_main netsnmp gui import fwbparser antlr common iptlib fwbpf fwbjuniper fwbcisco compilerdriver fwcompiler fwbuilder xml2 xslt z pthread cppunit) +target_link_libraries(compilerLibTest PRIVATE test_main netsnmp gui import fwbparser antlr common iptlib fwbpf fwbjuniper fwbcisco compilerdriver fwcompiler fwbuilder xml2 xslt z pthread Qt5::Test) file(COPY test.fwb DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) diff --git a/src/unit_tests/compilerLibTest/interfacePropertiesTest.cpp b/src/unit_tests/compilerLibTest/interfacePropertiesTest.cpp index 583109cab..6eaee8488 100644 --- a/src/unit_tests/compilerLibTest/interfacePropertiesTest.cpp +++ b/src/unit_tests/compilerLibTest/interfacePropertiesTest.cpp @@ -23,6 +23,8 @@ */ +#include + #include "interfacePropertiesTest.h" #include "fwbuilder/Firewall.h" @@ -35,7 +37,6 @@ using namespace std; using namespace libfwbuilder; -using namespace CppUnit; class UpgradePredicate: public XMLTools::UpgradePredicate @@ -58,7 +59,7 @@ interfaceProperties* interfacePropertiesTest::getIntProps(const QString &os) return interfacePropertiesObjectFactory::getInterfacePropertiesObject(os_family); } -void interfacePropertiesTest::setUp() +void interfacePropertiesTest::init() { db = new FWObjectDatabase(); } @@ -79,49 +80,49 @@ void interfacePropertiesTest::validateInterfaceNameCommon() interfaceProperties * int_prop = getIntProps("unknown"); - CPPUNIT_ASSERT(int_prop != nullptr); + QVERIFY(int_prop != nullptr); - CPPUNIT_ASSERT(int_prop->basicValidateInterfaceName( + QVERIFY(int_prop->basicValidateInterfaceName( iface, "eth0", err) == true); - CPPUNIT_ASSERT(int_prop->basicValidateInterfaceName( + QVERIFY(int_prop->basicValidateInterfaceName( iface, "foo0", err) == true); - CPPUNIT_ASSERT(int_prop->basicValidateInterfaceName( + QVERIFY(int_prop->basicValidateInterfaceName( iface, "bar0", err) == true); - CPPUNIT_ASSERT(int_prop->basicValidateInterfaceName( + QVERIFY(int_prop->basicValidateInterfaceName( iface, "vlan100", err) == true); - CPPUNIT_ASSERT(int_prop->basicValidateInterfaceName( + QVERIFY(int_prop->basicValidateInterfaceName( iface, "Vlan100", err) == true); - CPPUNIT_ASSERT(int_prop->basicValidateInterfaceName( + QVERIFY(int_prop->basicValidateInterfaceName( iface, "VlAn100", err) == true); - CPPUNIT_ASSERT(int_prop->basicValidateInterfaceName( + QVERIFY(int_prop->basicValidateInterfaceName( iface, "foo 0", err) == false); - CPPUNIT_ASSERT(int_prop->basicValidateInterfaceName( + QVERIFY(int_prop->basicValidateInterfaceName( iface, "foo-1", err) == false); - CPPUNIT_ASSERT(int_prop->basicValidateInterfaceName( + QVERIFY(int_prop->basicValidateInterfaceName( iface, "foo 12345", err) == false); iface->getOptionsObject()->setStr("type", "bridge"); - CPPUNIT_ASSERT(int_prop->basicValidateInterfaceName( + QVERIFY(int_prop->basicValidateInterfaceName( iface, "br0", err) == true); - CPPUNIT_ASSERT(int_prop->basicValidateInterfaceName( + QVERIFY(int_prop->basicValidateInterfaceName( iface, "Br0", err) == true); // all OS except Linux and possibly some other do not permit // interface name with "-" - CPPUNIT_ASSERT(int_prop->basicValidateInterfaceName( + QVERIFY(int_prop->basicValidateInterfaceName( iface, "br-lan", err) == false); - CPPUNIT_ASSERT(int_prop->basicValidateInterfaceName( + QVERIFY(int_prop->basicValidateInterfaceName( iface, "br 200", err) == false); } @@ -142,51 +143,51 @@ void interfacePropertiesTest::validateInterfaceNameLinux() interfaceProperties * int_prop = getIntProps("linux24"); - CPPUNIT_ASSERT(int_prop->basicValidateInterfaceName( + QVERIFY(int_prop->basicValidateInterfaceName( iface, "eth0", err) == true); - CPPUNIT_ASSERT(int_prop->basicValidateInterfaceName( + QVERIFY(int_prop->basicValidateInterfaceName( iface, "foo0", err) == true); - CPPUNIT_ASSERT(int_prop->basicValidateInterfaceName( + QVERIFY(int_prop->basicValidateInterfaceName( iface, "bar0", err) == true); // we do not have special type for p2p interfaces yet // Linux permits "-" in interface names (see #1856) - CPPUNIT_ASSERT(int_prop->basicValidateInterfaceName( + QVERIFY(int_prop->basicValidateInterfaceName( iface, "ppp-dsl", err) == true); iface->getOptionsObject()->setStr("type", "8021q"); - CPPUNIT_ASSERT(int_prop->basicValidateInterfaceName( + QVERIFY(int_prop->basicValidateInterfaceName( iface, "vlan100", err) == true); - CPPUNIT_ASSERT(int_prop->basicValidateInterfaceName( + QVERIFY(int_prop->basicValidateInterfaceName( iface, "Vlan100", err) == true); - CPPUNIT_ASSERT(int_prop->basicValidateInterfaceName( + QVERIFY(int_prop->basicValidateInterfaceName( iface, "VlAn100", err) == true); - CPPUNIT_ASSERT(int_prop->basicValidateInterfaceName( + QVERIFY(int_prop->basicValidateInterfaceName( iface, "foo 0", err) == false); - CPPUNIT_ASSERT(int_prop->basicValidateInterfaceName( + QVERIFY(int_prop->basicValidateInterfaceName( iface, "foo 12345", err) == false); iface->getOptionsObject()->setStr("type", "bridge"); - CPPUNIT_ASSERT(int_prop->basicValidateInterfaceName( + QVERIFY(int_prop->basicValidateInterfaceName( iface, "br0", err) == true); - CPPUNIT_ASSERT(int_prop->basicValidateInterfaceName( + QVERIFY(int_prop->basicValidateInterfaceName( iface, "Br0", err) == true); // Linux permits "-" in interface names (see #1856) - CPPUNIT_ASSERT(int_prop->basicValidateInterfaceName( + QVERIFY(int_prop->basicValidateInterfaceName( iface, "br-lan", err) == true); // spaces are not permitted - CPPUNIT_ASSERT(int_prop->basicValidateInterfaceName( + QVERIFY(int_prop->basicValidateInterfaceName( iface, "br 200", err) == false); } @@ -207,37 +208,37 @@ void interfacePropertiesTest::validateInterfaceNameProCurve() interfaceProperties * int_prop = getIntProps("procurve"); - CPPUNIT_ASSERT(int_prop->basicValidateInterfaceName( + QVERIFY(int_prop->basicValidateInterfaceName( iface, "a1", err) == true); - CPPUNIT_ASSERT(int_prop->basicValidateInterfaceName( + QVERIFY(int_prop->basicValidateInterfaceName( iface, "b1", err) == true); - CPPUNIT_ASSERT(int_prop->basicValidateInterfaceName( + QVERIFY(int_prop->basicValidateInterfaceName( iface, "A1", err) == true); // basicValidateInterfaceName() only checks name format, // it does not check if port number makes sense - CPPUNIT_ASSERT(int_prop->basicValidateInterfaceName( + QVERIFY(int_prop->basicValidateInterfaceName( iface, "A1234567890", err) == true); // "-" is not permitted - CPPUNIT_ASSERT(int_prop->basicValidateInterfaceName( + QVERIFY(int_prop->basicValidateInterfaceName( iface, "vlan-100", err) == false); // but space is permitted - CPPUNIT_ASSERT(int_prop->basicValidateInterfaceName( + QVERIFY(int_prop->basicValidateInterfaceName( iface, "vlan 100", err) == true); - CPPUNIT_ASSERT(int_prop->basicValidateInterfaceName( + QVERIFY(int_prop->basicValidateInterfaceName( iface, "Vlan 100", err) == true); - CPPUNIT_ASSERT(int_prop->basicValidateInterfaceName( + QVERIFY(int_prop->basicValidateInterfaceName( iface, "VlAn 100", err) == true); // basicValidateInterfaceName() only checks name format, // it does not check if vlan ID is valid. - CPPUNIT_ASSERT(int_prop->basicValidateInterfaceName( + QVERIFY(int_prop->basicValidateInterfaceName( iface, "VlAn 1000000000", err) == true); } @@ -252,7 +253,7 @@ void interfacePropertiesTest::validateInterface() interfaceProperties * int_prop = interfacePropertiesObjectFactory::getInterfacePropertiesObject(os_family); - CPPUNIT_ASSERT(int_prop != nullptr); + QVERIFY(int_prop != nullptr); QString err; @@ -269,21 +270,21 @@ void interfacePropertiesTest::validateInterface() iface1->getOptionsObject()->setStr("type", "ethernet"); cluster1->setStr("host_OS", host_OS); - CPPUNIT_ASSERT(int_prop->validateInterface(dynamic_cast(cluster1), + QVERIFY(int_prop->validateInterface(dynamic_cast(cluster1), dynamic_cast(iface1), false, err) == true ); iface1->setUnnumbered(true); - CPPUNIT_ASSERT(int_prop->validateInterface(dynamic_cast(cluster1), + QVERIFY(int_prop->validateInterface(dynamic_cast(cluster1), dynamic_cast(iface1), false, err) == true ); parent1->getOptionsObject()->setStr("type", "bonding"); iface1->setUnnumbered(false); - CPPUNIT_ASSERT(int_prop->validateInterface(dynamic_cast(cluster1), + QVERIFY(int_prop->validateInterface(dynamic_cast(cluster1), dynamic_cast(iface1), false, err) == false ); parent1->getOptionsObject()->setStr("type", "bridge"); iface1->setUnnumbered(false); - CPPUNIT_ASSERT(int_prop->validateInterface(dynamic_cast(cluster1), + QVERIFY(int_prop->validateInterface(dynamic_cast(cluster1), dynamic_cast(iface1), false, err) == false ); @@ -297,20 +298,20 @@ void interfacePropertiesTest::validateInterface() fw.add(parent); - CPPUNIT_ASSERT(int_prop->validateInterface(dynamic_cast(parent), + QVERIFY(int_prop->validateInterface(dynamic_cast(parent), dynamic_cast(iface), true, err) == false); parent->getOptionsObject()->setStr("type", "bridge"); iface->getOptionsObject()->setStr("type", "ethernet"); - CPPUNIT_ASSERT(int_prop->validateInterface(dynamic_cast(parent), + QVERIFY(int_prop->validateInterface(dynamic_cast(parent), FWObject::cast(iface), true, err) == true); iface->getOptionsObject()->setStr("type", "ethernet"); iface->add(subiface); - CPPUNIT_ASSERT(int_prop->validateInterface(dynamic_cast(parent), + QVERIFY(int_prop->validateInterface(dynamic_cast(parent), dynamic_cast(iface), false, err) == false); iface->remove(subiface); @@ -318,37 +319,37 @@ void interfacePropertiesTest::validateInterface() Cluster *cluster = Cluster::cast(db->create(Cluster::TYPENAME)); iface->setName("vlan0"); - CPPUNIT_ASSERT(int_prop->validateInterface(dynamic_cast(cluster), + QVERIFY(int_prop->validateInterface(dynamic_cast(cluster), dynamic_cast(iface), false, err) == true); iface->setName("vlan34324"); - CPPUNIT_ASSERT(int_prop->validateInterface(dynamic_cast(cluster), + QVERIFY(int_prop->validateInterface(dynamic_cast(cluster), dynamic_cast(iface), false, err) == false); parent->setName("vlan"); parent->getOptionsObject()->setStr("type", "bridge"); iface->setName("vlan1"); - CPPUNIT_ASSERT(int_prop->validateInterface(dynamic_cast(parent), + QVERIFY(int_prop->validateInterface(dynamic_cast(parent), dynamic_cast(iface), false, err) == true); IPv4 *adr = IPv4::cast(db->create(IPv4::TYPENAME)); - CPPUNIT_ASSERT(int_prop->validateInterface(dynamic_cast(adr), + QVERIFY(int_prop->validateInterface(dynamic_cast(adr), dynamic_cast(iface), false, err) == false); parent->setName("notAVlan"); parent->getOptionsObject()->setStr("type", "ethernet"); iface->setName("vlan1"); - CPPUNIT_ASSERT(int_prop->validateInterface(dynamic_cast(parent), + QVERIFY(int_prop->validateInterface(dynamic_cast(parent), dynamic_cast(iface), false, err) == true); iface->setName("eth0"); - CPPUNIT_ASSERT(int_prop->validateInterface(dynamic_cast(parent), + QVERIFY(int_prop->validateInterface(dynamic_cast(parent), dynamic_cast(iface), false, err) == false); @@ -363,7 +364,7 @@ void interfacePropertiesTest::isEligibleForCluster() interfaceProperties * int_prop = interfacePropertiesObjectFactory::getInterfacePropertiesObject(os_family); - CPPUNIT_ASSERT(int_prop != nullptr); + QVERIFY(int_prop != nullptr); Firewall *fw1 = Firewall::cast(db->create(Firewall::TYPENAME)); fw1->setName("iface"); @@ -378,27 +379,27 @@ void interfacePropertiesTest::isEligibleForCluster() iface1->getOptionsObject()->setStr("type", "ethernet"); parent1->getOptionsObject()->setStr("type", "ethernet"); - CPPUNIT_ASSERT(int_prop->isEligibleForCluster(iface1) == true); + QVERIFY(int_prop->isEligibleForCluster(iface1) == true); iface1->getOptionsObject()->setStr("type", "ethernet"); parent1->getOptionsObject()->setStr("type", "bridge"); - CPPUNIT_ASSERT(int_prop->isEligibleForCluster(iface1) == false); + QVERIFY(int_prop->isEligibleForCluster(iface1) == false); iface1->getOptionsObject()->setStr("type", "bonding"); parent1->getOptionsObject()->setStr("type", "ethernet"); - CPPUNIT_ASSERT(int_prop->isEligibleForCluster(iface1) == true); + QVERIFY(int_prop->isEligibleForCluster(iface1) == true); iface1->getOptionsObject()->setStr("type", "bridge"); parent1->getOptionsObject()->setStr("type", "ethernet"); - CPPUNIT_ASSERT(int_prop->isEligibleForCluster(iface1) == true); + QVERIFY(int_prop->isEligibleForCluster(iface1) == true); iface1->getOptionsObject()->setStr("type", "8021q"); parent1->getOptionsObject()->setStr("type", "ethernet"); - CPPUNIT_ASSERT(int_prop->isEligibleForCluster(iface1) == true); + QVERIFY(int_prop->isEligibleForCluster(iface1) == true); iface1->getOptionsObject()->setStr("type", "ethernet"); parent1->getOptionsObject()->setStr("type", "bridge"); - CPPUNIT_ASSERT(int_prop->isEligibleForCluster(iface1) == false); + QVERIFY(int_prop->isEligibleForCluster(iface1) == false); Firewall *fw = Firewall::cast(db->create(Firewall::TYPENAME)); fw->setName("iface"); @@ -409,10 +410,10 @@ void interfacePropertiesTest::isEligibleForCluster() fw->add(iface); iface->getOptionsObject()->setStr("type", "bonding"); iface->add(subface); - CPPUNIT_ASSERT ( interfaceProperties().isEligibleForCluster(subface) == false ); + QVERIFY ( interfaceProperties().isEligibleForCluster(subface) == false ); iface->getOptionsObject()->setStr("type", "ethernet"); - CPPUNIT_ASSERT ( interfaceProperties().isEligibleForCluster(iface) == false ); + QVERIFY ( interfaceProperties().isEligibleForCluster(iface) == false ); } @@ -430,18 +431,18 @@ eth0.bar eth0 false eth0.99999 eth0 false eth1.101 eth0 false */ - CPPUNIT_ASSERT (int_prop->isValidVlanInterfaceName("vlan101", parent, err) == true); - CPPUNIT_ASSERT (int_prop->isValidVlanInterfaceName("eth0.101", parent, err) == true); - CPPUNIT_ASSERT (int_prop->isValidVlanInterfaceName("foo", parent, err) == false); - CPPUNIT_ASSERT (int_prop->isValidVlanInterfaceName("foo101", parent, err) == false); - CPPUNIT_ASSERT (int_prop->isValidVlanInterfaceName("eth0.bar", parent, err) == false); - CPPUNIT_ASSERT (int_prop->isValidVlanInterfaceName("eth0.99999", parent, err) == false); - CPPUNIT_ASSERT (int_prop->isValidVlanInterfaceName("eth1.101", parent, err) == false); + QVERIFY (int_prop->isValidVlanInterfaceName("vlan101", parent, err) == true); + QVERIFY (int_prop->isValidVlanInterfaceName("eth0.101", parent, err) == true); + QVERIFY (int_prop->isValidVlanInterfaceName("foo", parent, err) == false); + QVERIFY (int_prop->isValidVlanInterfaceName("foo101", parent, err) == false); + QVERIFY (int_prop->isValidVlanInterfaceName("eth0.bar", parent, err) == false); + QVERIFY (int_prop->isValidVlanInterfaceName("eth0.99999", parent, err) == false); + QVERIFY (int_prop->isValidVlanInterfaceName("eth1.101", parent, err) == false); parent = "bond1"; - CPPUNIT_ASSERT (int_prop->isValidVlanInterfaceName("bond1.15", parent, err) == true); - CPPUNIT_ASSERT (int_prop->isValidVlanInterfaceName("bond1.515", parent, err) == true); - CPPUNIT_ASSERT (int_prop->isValidVlanInterfaceName("bond1.1205", parent, err) == true); + QVERIFY (int_prop->isValidVlanInterfaceName("bond1.15", parent, err) == true); + QVERIFY (int_prop->isValidVlanInterfaceName("bond1.515", parent, err) == true); + QVERIFY (int_prop->isValidVlanInterfaceName("bond1.1205", parent, err) == true); } @@ -481,17 +482,17 @@ en0.101 en0 false foo en0 false foo101 en0 false */ - CPPUNIT_ASSERT (int_prop->isValidVlanInterfaceName("vlan101", parent, err) == true); - CPPUNIT_ASSERT (int_prop->isValidVlanInterfaceName("eth0.101", parent, err) == false); - CPPUNIT_ASSERT (int_prop->isValidVlanInterfaceName("foo", parent, err) == false); - CPPUNIT_ASSERT (int_prop->isValidVlanInterfaceName("foo101", parent, err) == false); + QVERIFY (int_prop->isValidVlanInterfaceName("vlan101", parent, err) == true); + QVERIFY (int_prop->isValidVlanInterfaceName("eth0.101", parent, err) == false); + QVERIFY (int_prop->isValidVlanInterfaceName("foo", parent, err) == false); + QVERIFY (int_prop->isValidVlanInterfaceName("foo101", parent, err) == false); int_prop = getIntProps("freebsd"); - CPPUNIT_ASSERT (int_prop->isValidVlanInterfaceName("vlan101", parent, err) == true); - CPPUNIT_ASSERT (int_prop->isValidVlanInterfaceName("eth0.101", parent, err) == false); - CPPUNIT_ASSERT (int_prop->isValidVlanInterfaceName("foo", parent, err) == false); - CPPUNIT_ASSERT (int_prop->isValidVlanInterfaceName("foo101", parent, err) == false); + QVERIFY (int_prop->isValidVlanInterfaceName("vlan101", parent, err) == true); + QVERIFY (int_prop->isValidVlanInterfaceName("eth0.101", parent, err) == false); + QVERIFY (int_prop->isValidVlanInterfaceName("foo", parent, err) == false); + QVERIFY (int_prop->isValidVlanInterfaceName("foo101", parent, err) == false); } void interfacePropertiesTest::isValidVlanInterfaceNameIOS() @@ -506,11 +507,11 @@ Ethernet0/0.99999 Ethernet0/0 false */ interfaceProperties *int_prop = getIntProps("ios"); parent = "FastEthernet0/1"; - CPPUNIT_ASSERT (int_prop->isValidVlanInterfaceName("FastEthernet0/1.101", parent, err) == true); - CPPUNIT_ASSERT (int_prop->isValidVlanInterfaceName("vlan101", parent, err) == false); - CPPUNIT_ASSERT (int_prop->isValidVlanInterfaceName("Ethernet0/0.101", parent, err) == false); + QVERIFY (int_prop->isValidVlanInterfaceName("FastEthernet0/1.101", parent, err) == true); + QVERIFY (int_prop->isValidVlanInterfaceName("vlan101", parent, err) == false); + QVERIFY (int_prop->isValidVlanInterfaceName("Ethernet0/0.101", parent, err) == false); parent = "Ethernet0/0"; - CPPUNIT_ASSERT (int_prop->isValidVlanInterfaceName("Ethernet0/0.99999", parent, err) == false); + QVERIFY (int_prop->isValidVlanInterfaceName("Ethernet0/0.99999", parent, err) == false); } void interfacePropertiesTest::isValidVlanInterfaceNamePIX() @@ -518,11 +519,11 @@ void interfacePropertiesTest::isValidVlanInterfaceNamePIX() QString err, parent; interfaceProperties *int_prop = getIntProps("pix_os"); parent = "FastEthernet0/1"; - CPPUNIT_ASSERT (int_prop->isValidVlanInterfaceName("FastEthernet0/1.101", parent, err) == true); - CPPUNIT_ASSERT (int_prop->isValidVlanInterfaceName("vlan101", parent, err) == false); - CPPUNIT_ASSERT (int_prop->isValidVlanInterfaceName("Ethernet0/0.101", parent, err) == false); + QVERIFY (int_prop->isValidVlanInterfaceName("FastEthernet0/1.101", parent, err) == true); + QVERIFY (int_prop->isValidVlanInterfaceName("vlan101", parent, err) == false); + QVERIFY (int_prop->isValidVlanInterfaceName("Ethernet0/0.101", parent, err) == false); parent = "Ethernet0/0"; - CPPUNIT_ASSERT (int_prop->isValidVlanInterfaceName("Ethernet0/0.99999", parent, err) == false); + QVERIFY (int_prop->isValidVlanInterfaceName("Ethernet0/0.99999", parent, err) == false); } void interfacePropertiesTest::isValidVlanInterfaceNameProCurve() @@ -540,15 +541,15 @@ void interfacePropertiesTest::isValidVlanInterfaceNameProCurve() */ interfaceProperties *int_prop = getIntProps("procurve"); parent = "FastEthernet0/1"; - CPPUNIT_ASSERT (int_prop->isValidVlanInterfaceName("vlan 2", parent, err) == true); - CPPUNIT_ASSERT (int_prop->isValidVlanInterfaceName("VLAN 2", parent, err) == true); - CPPUNIT_ASSERT (int_prop->isValidVlanInterfaceName("Vlan 2", parent, err) == true); - CPPUNIT_ASSERT (int_prop->isValidVlanInterfaceName("vlan2", parent, err) == false); + QVERIFY (int_prop->isValidVlanInterfaceName("vlan 2", parent, err) == true); + QVERIFY (int_prop->isValidVlanInterfaceName("VLAN 2", parent, err) == true); + QVERIFY (int_prop->isValidVlanInterfaceName("Vlan 2", parent, err) == true); + QVERIFY (int_prop->isValidVlanInterfaceName("vlan2", parent, err) == false); - CPPUNIT_ASSERT (int_prop->isValidVlanInterfaceName("vlan 101", parent, err) == true); - CPPUNIT_ASSERT (int_prop->isValidVlanInterfaceName("vlan101", parent, err) == false); + QVERIFY (int_prop->isValidVlanInterfaceName("vlan 101", parent, err) == true); + QVERIFY (int_prop->isValidVlanInterfaceName("vlan101", parent, err) == false); - CPPUNIT_ASSERT (int_prop->isValidVlanInterfaceName("Ethernet0/0.101", parent, err) == false); + QVERIFY (int_prop->isValidVlanInterfaceName("Ethernet0/0.101", parent, err) == false); } void interfacePropertiesTest::validateInterfaceProCurve() @@ -562,7 +563,7 @@ void interfacePropertiesTest::validateInterfaceProCurve() interfaceProperties * int_prop = interfacePropertiesObjectFactory::getInterfacePropertiesObject(os_family); - CPPUNIT_ASSERT(int_prop != nullptr); + QVERIFY(int_prop != nullptr); QString err; @@ -577,10 +578,10 @@ void interfacePropertiesTest::validateInterfaceProCurve() fw.add(parent); iface->setName("vlan 2"); - CPPUNIT_ASSERT(int_prop->validateInterface(&fw, iface, false, err) == true); + QVERIFY(int_prop->validateInterface(&fw, iface, false, err) == true); iface->setName("vlan 34324"); - CPPUNIT_ASSERT(int_prop->validateInterface(&fw, iface, false, err) == false); + QVERIFY(int_prop->validateInterface(&fw, iface, false, err) == false); } void interfacePropertiesTest::testManageIpAddresses() @@ -594,7 +595,7 @@ void interfacePropertiesTest::testManageIpAddresses() db->reIndex(); FWObject *fw = db->findObjectByName(Firewall::TYPENAME, "fw1"); - CPPUNIT_ASSERT(fw != nullptr); + QVERIFY(fw != nullptr); Interface *intf = Interface::cast( fw->findObjectByName(Interface::TYPENAME, "eth0")); @@ -604,35 +605,35 @@ void interfacePropertiesTest::testManageIpAddresses() QStringList update_addresses; QStringList ignore_addresses; - CPPUNIT_ASSERT( + QVERIFY( int_prop->manageIpAddresses( intf, update_addresses, ignore_addresses) == true); intf = Interface::cast( fw->findObjectByName(Interface::TYPENAME, "lo")); - CPPUNIT_ASSERT( + QVERIFY( int_prop->manageIpAddresses( intf, update_addresses, ignore_addresses) == true); intf = Interface::cast( fw->findObjectByName(Interface::TYPENAME, "eth1")); // dyn - CPPUNIT_ASSERT( + QVERIFY( int_prop->manageIpAddresses( intf, update_addresses, ignore_addresses) == false); intf = Interface::cast( fw->findObjectByName(Interface::TYPENAME, "eth2")); // bridge port - CPPUNIT_ASSERT( + QVERIFY( int_prop->manageIpAddresses( intf, update_addresses, ignore_addresses) == false); intf = Interface::cast( fw->findObjectByName(Interface::TYPENAME, "eth3")); // bonding intf slave - CPPUNIT_ASSERT( + QVERIFY( int_prop->manageIpAddresses( intf, update_addresses, ignore_addresses) == false); @@ -640,14 +641,14 @@ void interfacePropertiesTest::testManageIpAddresses() intf = Interface::cast( fw->findObjectByName(Interface::TYPENAME, "tun0")); // unnumbered - CPPUNIT_ASSERT( + QVERIFY( int_prop->manageIpAddresses( intf, update_addresses, ignore_addresses) == false); intf = Interface::cast( fw->findObjectByName(Interface::TYPENAME, "tun*")); // unnumbered - CPPUNIT_ASSERT( + QVERIFY( int_prop->manageIpAddresses( intf, update_addresses, ignore_addresses) == false); @@ -664,7 +665,7 @@ void interfacePropertiesTest::testManageIpAddressesCluster() db->reIndex(); FWObject *fw = db->findObjectByName(Cluster::TYPENAME, "cluster1"); - CPPUNIT_ASSERT(fw != nullptr); + QVERIFY(fw != nullptr); Interface *intf = Interface::cast( fw->findObjectByName(Interface::TYPENAME, "lo")); @@ -676,14 +677,14 @@ void interfacePropertiesTest::testManageIpAddressesCluster() QStringList update_addresses; QStringList ignore_addresses; - CPPUNIT_ASSERT( + QVERIFY( int_prop->manageIpAddresses( intf, update_addresses, ignore_addresses) == false); intf = Interface::cast( fw->findObjectByName(Interface::TYPENAME, "eth0")); - CPPUNIT_ASSERT( + QVERIFY( int_prop->manageIpAddresses( intf, update_addresses, ignore_addresses) == true); diff --git a/src/unit_tests/compilerLibTest/interfacePropertiesTest.h b/src/unit_tests/compilerLibTest/interfacePropertiesTest.h index c7ab36a02..fccd0c7a0 100644 --- a/src/unit_tests/compilerLibTest/interfacePropertiesTest.h +++ b/src/unit_tests/compilerLibTest/interfacePropertiesTest.h @@ -27,6 +27,8 @@ #ifndef INTERFACEPROPERTIESTEST #define INTERFACEPROPERTIESTEST +#include + #include "fwbuilder/FWObjectDatabase.h" #include "fwbuilder/FWObject.h" #include "fwbuilder/Cluster.h" @@ -36,23 +38,24 @@ #include "interfaceProperties.h" #include "interfacePropertiesObjectFactory.h" -#include - #include #include -class interfacePropertiesTest: public CppUnit::TestFixture +class interfacePropertiesTest: public QObject { + Q_OBJECT + libfwbuilder::FWObjectDatabase *db; void isValidVlanInterfaceNameLinuxFamilies(interfaceProperties *int_prop); -public: - //interfaceProperties( std::string name ) : CppUnit::TestCase( name ) {} interfaceProperties* getIntProps(const QString &os); - + +private slots: + void init(); + void validateInterfaceNameCommon(); void validateInterfaceNameLinux(); void validateInterfaceNameProCurve(); @@ -70,26 +73,6 @@ public: void validateInterfaceProCurve(); void testManageIpAddresses(); void testManageIpAddressesCluster(); - - void setUp(); - - CPPUNIT_TEST_SUITE(interfacePropertiesTest); - CPPUNIT_TEST(validateInterfaceNameCommon); - CPPUNIT_TEST(validateInterfaceNameLinux); - CPPUNIT_TEST(validateInterfaceNameProCurve); - CPPUNIT_TEST(validateInterface); - CPPUNIT_TEST(isEligibleForCluster); - CPPUNIT_TEST(isValidVlanInterfaceNameLinux24); - CPPUNIT_TEST(isValidVlanInterfaceNameOpenWRT); - CPPUNIT_TEST(isValidVlanInterfaceNameDDWRT1); - CPPUNIT_TEST(isValidVlanInterfaceNameDDWRT2); - CPPUNIT_TEST(isValidVlanInterfaceNameSecuwall); - CPPUNIT_TEST(isValidVlanInterfaceNameBSD); - CPPUNIT_TEST(isValidVlanInterfaceNameIOS); - CPPUNIT_TEST(isValidVlanInterfaceNamePIX); - CPPUNIT_TEST(testManageIpAddresses); - CPPUNIT_TEST(testManageIpAddressesCluster); - CPPUNIT_TEST_SUITE_END(); }; diff --git a/src/unit_tests/compilerLibTest/tests_main.cpp b/src/unit_tests/compilerLibTest/tests_main.cpp index bf398dec7..c4fabea08 100644 --- a/src/unit_tests/compilerLibTest/tests_main.cpp +++ b/src/unit_tests/compilerLibTest/tests_main.cpp @@ -22,19 +22,15 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ - +#include #include "common/init.cpp" #include "interfacePropertiesTest.h" #include "fwbuilder/Constants.h" -#include -#include #include -//QString user_name; - int main(int, char **argv) { init(argv); @@ -43,11 +39,5 @@ int main(int, char **argv) Resources res(Constants::getResourcesFilePath()); - CppUnit::TextUi::TestRunner runner; - runner.addTest( interfacePropertiesTest::suite() ); - runner.setOutputter( new CppUnit::CompilerOutputter( &runner.result(), - std::cerr ) ); - - runner.run(); - return 0; + return QTest::qExec(new interfacePropertiesTest()); } diff --git a/src/unit_tests/generatedScriptTestsIpfilter/CMakeLists.txt b/src/unit_tests/generatedScriptTestsIpfilter/CMakeLists.txt index 713247e0f..8733b132c 100644 --- a/src/unit_tests/generatedScriptTestsIpfilter/CMakeLists.txt +++ b/src/unit_tests/generatedScriptTestsIpfilter/CMakeLists.txt @@ -1,7 +1,9 @@ +SET(CMAKE_AUTOMOC ON) + add_executable(generatedScriptTestsIpfilter generatedScriptTestsIpfilter.cpp main_generatedScriptTestsIpfilter.cpp) add_test(NAME generatedScriptTestsIpfilter COMMAND generatedScriptTestsIpfilter) -target_link_libraries(generatedScriptTestsIpfilter PRIVATE test_main netsnmp gui import fwbparser antlr common iptlib fwbpf fwbjuniper fwbcisco compilerdriver fwcompiler fwbuilder xml2 xslt z pthread cppunit) +target_link_libraries(generatedScriptTestsIpfilter PRIVATE test_main netsnmp gui import fwbparser antlr common iptlib fwbpf fwbjuniper fwbcisco compilerdriver fwcompiler fwbuilder xml2 xslt z pthread Qt5::Test) file(COPY test1.fwb DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) diff --git a/src/unit_tests/generatedScriptTestsIpfilter/generatedScriptTestsIpfilter.cpp b/src/unit_tests/generatedScriptTestsIpfilter/generatedScriptTestsIpfilter.cpp index eb6753881..9d466764d 100644 --- a/src/unit_tests/generatedScriptTestsIpfilter/generatedScriptTestsIpfilter.cpp +++ b/src/unit_tests/generatedScriptTestsIpfilter/generatedScriptTestsIpfilter.cpp @@ -1,4 +1,4 @@ -/* +/* Firewall Builder @@ -17,13 +17,12 @@ 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 "generatedScriptTestsIpfilter.h" #include "CompilerDriver_ipf.h" @@ -34,6 +33,7 @@ #include "fwbuilder/IPService.h" #include "fwbuilder/Constants.h" +#include #include #include #include @@ -49,27 +49,27 @@ using namespace fwcompiler; class UpgradePredicate: public XMLTools::UpgradePredicate { public: - virtual bool operator()(const string&) const - { + virtual bool operator()(const string&) const + { cout << "Data file has been created in the old version of Firewall Builder. Use fwbuilder GUI to convert it." << std::endl; return false; } }; -void GeneratedScriptTest::setUp() +void GeneratedScriptTest::init() { Configlet::setDebugging(true); } -void GeneratedScriptTest::tearDown() +void GeneratedScriptTest::cleanup() { } void GeneratedScriptTest::loadDataFile(const string &file_name) { /* load the data file */ - UpgradePredicate upgrade_predicate; + UpgradePredicate upgrade_predicate; objdb->setReadOnly( false ); objdb->load(file_name, &upgrade_predicate, Constants::getDTDDirectory()); @@ -96,13 +96,13 @@ void GeneratedScriptTest::runCompiler(const std::string &test_file, CompilerDriver_ipf driver(objdb); driver.setEmbeddedMode(); - CPPUNIT_ASSERT_MESSAGE("CompilerDriver_ipf initialization failed", - driver.prepare(args) == true); + QVERIFY2(driver.prepare(args) == true, + "CompilerDriver_ipf initialization failed"); driver.compile(); // compiler should have created file generate_file_name QFileInfo fi(generate_file_name.c_str()); - CPPUNIT_ASSERT_MESSAGE("Generated file " + generate_file_name + " not found", - fi.exists() == true); + QVERIFY2(fi.exists() == true, + std::string("Generated file " + generate_file_name + " not found").data()); } // I can check only certain parts of the top comment. Can't @@ -115,12 +115,12 @@ void GeneratedScriptTest::ManifestTest_1() runCompiler("test1.fwb", "ipf1", "ipf1.fw"); QString res = Configlet::findConfigletInFile("top_comment", "ipf1.fw"); // find manifest and compare - CPPUNIT_ASSERT(res.indexOf("# files: * ipf1.fw") != -1); - CPPUNIT_ASSERT(res.indexOf("# files: ipf1-ipf.conf") != -1); - CPPUNIT_ASSERT(res.indexOf("# files: ipf1-nat.conf") != -1); + QVERIFY(res.indexOf("# files: * ipf1.fw") != -1); + QVERIFY(res.indexOf("# files: ipf1-ipf.conf") != -1); + QVERIFY(res.indexOf("# files: ipf1-nat.conf") != -1); delete objdb; } - + void GeneratedScriptTest::ManifestTest_2() { /* @@ -133,9 +133,9 @@ void GeneratedScriptTest::ManifestTest_2() runCompiler("test1.fwb", "ipf2", "ipf2-1.fw"); QString res = Configlet::findConfigletInFile("top_comment", "ipf2-1.fw"); // find manifest and compare - CPPUNIT_ASSERT(res.indexOf("# files: * ipf2-1.fw") != -1); - CPPUNIT_ASSERT(res.indexOf("# files: ipf2-1-ipf.conf") != -1); - CPPUNIT_ASSERT(res.indexOf("# files: ipf2-1-nat.conf") != -1); + QVERIFY(res.indexOf("# files: * ipf2-1.fw") != -1); + QVERIFY(res.indexOf("# files: ipf2-1-ipf.conf") != -1); + QVERIFY(res.indexOf("# files: ipf2-1-nat.conf") != -1); delete objdb; } @@ -151,9 +151,9 @@ void GeneratedScriptTest::ManifestTest_3() runCompiler("test1.fwb", "ipf2a", "ipf2-1"); QString res = Configlet::findConfigletInFile("top_comment", "ipf2-1"); // find manifest and compare - CPPUNIT_ASSERT(res.indexOf("# files: * ipf2-1") != -1); - CPPUNIT_ASSERT(res.indexOf("# files: ipf2-1-ipf.conf") != -1); - CPPUNIT_ASSERT(res.indexOf("# files: ipf2-1-nat.conf") != -1); + QVERIFY(res.indexOf("# files: * ipf2-1") != -1); + QVERIFY(res.indexOf("# files: ipf2-1-ipf.conf") != -1); + QVERIFY(res.indexOf("# files: ipf2-1-nat.conf") != -1); delete objdb; } @@ -167,24 +167,26 @@ void GeneratedScriptTest::ManifestTest_4() runCompiler("test1.fwb", "ipf2", "ipf2-1.fw", option_o.toStdString()); QString res = Configlet::findConfigletInFile("top_comment", "ipf2-1.fw"); // find manifest and compare - CPPUNIT_ASSERT(res.indexOf("# files: * " + option_o) != -1); + QVERIFY(res.indexOf("# files: * " + option_o) != -1); QString ipf_file = QDir::currentPath() + "/ipf2-1-ipf.conf"; QString nat_file = QDir::currentPath() + "/ipf2-1-nat.conf"; - CPPUNIT_ASSERT(res.indexOf("# files: " + ipf_file) != -1); - CPPUNIT_ASSERT(res.indexOf("# files: " + nat_file) != -1); + QVERIFY(res.indexOf("# files: " + ipf_file) != -1); + QVERIFY(res.indexOf("# files: " + nat_file) != -1); delete objdb; } void GeneratedScriptTest::ManifestTest_5() { + QSKIP("This test was disabled in the original code"); + objdb = new FWObjectDatabase(); QString option_o = QDir::currentPath() + "/ipf2-1"; runCompiler("test1.fwb", "ipf2a", "ipf2-1.fw", option_o.toStdString()); QString res = Configlet::findConfigletInFile("top_comment", "ipf2-1.fw"); // find manifest and compare - CPPUNIT_ASSERT(res.indexOf("# files: * ipf2-1.fw") != -1); - CPPUNIT_ASSERT(res.indexOf("# files: ipf2-1-ipf.conf") != -1); - CPPUNIT_ASSERT(res.indexOf("# files: ipf2-1-nat.conf") != -1); + QVERIFY(res.indexOf("# files: * ipf2-1.fw") != -1); + QVERIFY(res.indexOf("# files: ipf2-1-ipf.conf") != -1); + QVERIFY(res.indexOf("# files: ipf2-1-nat.conf") != -1); delete objdb; } @@ -198,9 +200,9 @@ void GeneratedScriptTest::ManifestTest_6() runCompiler("test1.fwb", "ipf3", "ipf3.fw"); QString res = Configlet::findConfigletInFile("top_comment", "ipf3.fw"); // find manifest and compare - CPPUNIT_ASSERT(res.indexOf("# files: * ipf3.fw") != -1); - CPPUNIT_ASSERT(res.indexOf("# files: ipf3-ipf.conf /etc/fw/ipf3-ipf.conf") != -1); - CPPUNIT_ASSERT(res.indexOf("# files: ipf3-nat.conf /etc/fw/ipf3-nat.conf") != -1); + QVERIFY(res.indexOf("# files: * ipf3.fw") != -1); + QVERIFY(res.indexOf("# files: ipf3-ipf.conf /etc/fw/ipf3-ipf.conf") != -1); + QVERIFY(res.indexOf("# files: ipf3-nat.conf /etc/fw/ipf3-nat.conf") != -1); delete objdb; } @@ -213,9 +215,9 @@ void GeneratedScriptTest::ManifestTest_7() runCompiler("test1.fwb", "ipf4", "ipf4.fw"); QString res = Configlet::findConfigletInFile("top_comment", "ipf4.fw"); // find manifest and compare - CPPUNIT_ASSERT(res.indexOf("# files: * ipf4.fw /etc/path\\ with\\ space/ipf4.fw") != -1); - CPPUNIT_ASSERT(res.indexOf("# files: ipf4-ipf.conf /etc/path\\ with\\ space/ipf4-ipf.conf") != -1); - CPPUNIT_ASSERT(res.indexOf("# files: ipf4-nat.conf /etc/path\\ with\\ space/ipf4-nat.conf") != -1); + QVERIFY(res.indexOf("# files: * ipf4.fw /etc/path\\ with\\ space/ipf4.fw") != -1); + QVERIFY(res.indexOf("# files: ipf4-ipf.conf /etc/path\\ with\\ space/ipf4-ipf.conf") != -1); + QVERIFY(res.indexOf("# files: ipf4-nat.conf /etc/path\\ with\\ space/ipf4-nat.conf") != -1); delete objdb; } @@ -227,7 +229,7 @@ void GeneratedScriptTest::FwCommentTest() runCompiler("test1.fwb", "ipf1", "ipf1.fw"); QString res = Configlet::findConfigletInFile("top_comment", "ipf1.fw"); // find string from the firewall object comment and compare - CPPUNIT_ASSERT(res.indexOf("# Firewall object test1 comment") != -1); + QVERIFY(res.indexOf("# Firewall object test1 comment") != -1); delete objdb; } @@ -237,7 +239,7 @@ void GeneratedScriptTest::ActivationCommandsTest_1() { objdb = new FWObjectDatabase(); QString res = Configlet::findConfigletInFile("activation", "ipf1.fw"); - CPPUNIT_ASSERT(res.indexOf("$IPF -I -f /etc/ipf1-ipf.conf") != -1); + QVERIFY(res.indexOf("$IPF -I -f /etc/ipf1-ipf.conf") != -1); delete objdb; } @@ -245,7 +247,7 @@ void GeneratedScriptTest::ActivationCommandsTest_2() { objdb = new FWObjectDatabase(); QString res = Configlet::findConfigletInFile("activation", "ipf2-1.fw"); - CPPUNIT_ASSERT(res.indexOf("$IPF -I -f /etc/ipf2-1-ipf.conf") != -1); + QVERIFY(res.indexOf("$IPF -I -f /etc/ipf2-1-ipf.conf") != -1); delete objdb; } @@ -253,7 +255,7 @@ void GeneratedScriptTest::ActivationCommandsTest_3() { objdb = new FWObjectDatabase(); QString res = Configlet::findConfigletInFile("activation", "ipf2-1"); - CPPUNIT_ASSERT(res.indexOf("$IPF -I -f /etc/ipf2-1-ipf.conf") != -1); + QVERIFY(res.indexOf("$IPF -I -f /etc/ipf2-1-ipf.conf") != -1); delete objdb; } @@ -261,7 +263,7 @@ void GeneratedScriptTest::ActivationCommandsTest_4() { objdb = new FWObjectDatabase(); QString res = Configlet::findConfigletInFile("activation", "ipf2-1.fw"); - CPPUNIT_ASSERT(res.indexOf("$IPF -I -f /etc/ipf2-1-ipf.conf") != -1); + QVERIFY(res.indexOf("$IPF -I -f /etc/ipf2-1-ipf.conf") != -1); delete objdb; } @@ -269,7 +271,7 @@ void GeneratedScriptTest::ActivationCommandsTest_6() { objdb = new FWObjectDatabase(); QString res = Configlet::findConfigletInFile("activation", "ipf3.fw"); - CPPUNIT_ASSERT(res.indexOf("$IPF -I -f /etc/fw/ipf3-ipf.conf") != -1); + QVERIFY(res.indexOf("$IPF -I -f /etc/fw/ipf3-ipf.conf") != -1); delete objdb; } @@ -277,10 +279,10 @@ void GeneratedScriptTest::ActivationCommandsTest_7() { objdb = new FWObjectDatabase(); QString res = Configlet::findConfigletInFile("activation", "ipf4.fw", 1); - CPPUNIT_ASSERT(res.indexOf("$IPF -I -f /etc/path\\ with\\ space/ipf4-ipf.conf") != -1); + QVERIFY(res.indexOf("$IPF -I -f /etc/path\\ with\\ space/ipf4-ipf.conf") != -1); res = Configlet::findConfigletInFile("activation", "ipf4.fw", 2); - CPPUNIT_ASSERT(res.indexOf("$IPNAT -f /etc/path\\ with\\ space/ipf4-nat.conf") != -1); + QVERIFY(res.indexOf("$IPNAT -f /etc/path\\ with\\ space/ipf4-nat.conf") != -1); delete objdb; } diff --git a/src/unit_tests/generatedScriptTestsIpfilter/generatedScriptTestsIpfilter.h b/src/unit_tests/generatedScriptTestsIpfilter/generatedScriptTestsIpfilter.h index af3464441..10d289eb1 100644 --- a/src/unit_tests/generatedScriptTestsIpfilter/generatedScriptTestsIpfilter.h +++ b/src/unit_tests/generatedScriptTestsIpfilter/generatedScriptTestsIpfilter.h @@ -1,4 +1,4 @@ -/* +/* Firewall Builder @@ -17,7 +17,7 @@ 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 @@ -26,19 +26,21 @@ #ifndef GENERATEDSCRIPTTESTS_IPFILTER_H #define GENERATEDSCRIPTTESTS_IPFILTER_H +#include + #include "fwbuilder/Resources.h" #include "fwbuilder/FWObjectDatabase.h" #include "fwbuilder/Library.h" #include "fwbuilder/FWException.h" #include "fwbuilder/Logger.h" -#include - #include -class GeneratedScriptTest : public CppUnit::TestFixture +class GeneratedScriptTest : public QObject { + Q_OBJECT + libfwbuilder::FWObjectDatabase *objdb; void loadDataFile(const std::string &file_name); @@ -47,9 +49,13 @@ class GeneratedScriptTest : public CppUnit::TestFixture const std::string &generate_file_name, const std::string &output_file_option=""); -public: - void setUp(); - void tearDown(); +private slots: + void init(); + void cleanup(); + + // The order of tests matters because activation commands tests use + // files produced in manifest tests + void ManifestTest_1(); void ManifestTest_2(); void ManifestTest_3(); @@ -62,38 +68,9 @@ public: void ActivationCommandsTest_2(); void ActivationCommandsTest_3(); void ActivationCommandsTest_4(); -// void ActivationCommandsTest_5(); + void ActivationCommandsTest_6(); void ActivationCommandsTest_7(); - - CPPUNIT_TEST_SUITE(GeneratedScriptTest); - - // The order of tests matters because activation commands tests use - // files produced in manifest tests - CPPUNIT_TEST(ManifestTest_1); - CPPUNIT_TEST(ActivationCommandsTest_1); - - CPPUNIT_TEST(ManifestTest_2); - CPPUNIT_TEST(ActivationCommandsTest_2); - - CPPUNIT_TEST(ManifestTest_3); - CPPUNIT_TEST(ActivationCommandsTest_3); - - CPPUNIT_TEST(ManifestTest_4); - CPPUNIT_TEST(ActivationCommandsTest_4); - -// CPPUNIT_TEST(ManifestTest_5); -// CPPUNIT_TEST(ActivationCommandsTest_5); - - CPPUNIT_TEST(ManifestTest_6); - CPPUNIT_TEST(ActivationCommandsTest_6); - - CPPUNIT_TEST(ManifestTest_7); - CPPUNIT_TEST(ActivationCommandsTest_7); - - CPPUNIT_TEST(FwCommentTest); - - CPPUNIT_TEST_SUITE_END(); }; diff --git a/src/unit_tests/generatedScriptTestsIpfilter/main_generatedScriptTestsIpfilter.cpp b/src/unit_tests/generatedScriptTestsIpfilter/main_generatedScriptTestsIpfilter.cpp index ea8bb624c..29d9ce156 100644 --- a/src/unit_tests/generatedScriptTestsIpfilter/main_generatedScriptTestsIpfilter.cpp +++ b/src/unit_tests/generatedScriptTestsIpfilter/main_generatedScriptTestsIpfilter.cpp @@ -1,4 +1,4 @@ -/* +/* Firewall Builder @@ -17,18 +17,15 @@ 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 #include "generatedScriptTestsIpfilter.h" -#include -#include - #include "fwbuilder/Resources.h" #include "fwbuilder/Constants.h" @@ -42,7 +39,7 @@ using namespace libfwbuilder; int main(int argc, char **argv) -{ +{ QApplication app(argc, argv, false); // compilers always write file names into manifest in Utf8 @@ -52,10 +49,5 @@ int main(int argc, char **argv) Resources res(Constants::getResourcesFilePath()); - CppUnit::TextUi::TestRunner runner; - runner.addTest( GeneratedScriptTest::suite() ); - runner.setOutputter( new CppUnit::CompilerOutputter( &runner.result(), - std::cerr ) ); - - runner.run(); + return QTest::qExec(new GeneratedScriptTest()); } diff --git a/src/unit_tests/generatedScriptTestsIpfw/CMakeLists.txt b/src/unit_tests/generatedScriptTestsIpfw/CMakeLists.txt index 78632bbb1..aaaff9159 100644 --- a/src/unit_tests/generatedScriptTestsIpfw/CMakeLists.txt +++ b/src/unit_tests/generatedScriptTestsIpfw/CMakeLists.txt @@ -1,7 +1,9 @@ +SET(CMAKE_AUTOMOC ON) + add_executable(generatedScriptTestsIpfw generatedScriptTestsIpfw.cpp main_generatedScriptTestsIpfw.cpp) add_test(NAME generatedScriptTestsIpfw COMMAND generatedScriptTestsIpfw) -target_link_libraries(generatedScriptTestsIpfw PRIVATE test_main netsnmp gui import fwbparser antlr common iptlib fwbpf fwbjuniper fwbcisco compilerdriver fwcompiler fwbuilder xml2 xslt z pthread cppunit) +target_link_libraries(generatedScriptTestsIpfw PRIVATE test_main netsnmp gui import fwbparser antlr common iptlib fwbpf fwbjuniper fwbcisco compilerdriver fwcompiler fwbuilder xml2 xslt z pthread Qt5::Test) file(COPY test1.fwb DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) diff --git a/src/unit_tests/generatedScriptTestsIpfw/generatedScriptTestsIpfw.cpp b/src/unit_tests/generatedScriptTestsIpfw/generatedScriptTestsIpfw.cpp index 475334a35..e36e48000 100644 --- a/src/unit_tests/generatedScriptTestsIpfw/generatedScriptTestsIpfw.cpp +++ b/src/unit_tests/generatedScriptTestsIpfw/generatedScriptTestsIpfw.cpp @@ -23,7 +23,6 @@ */ - #include "generatedScriptTestsIpfw.h" #include "CompilerDriver_ipfw.h" @@ -34,6 +33,7 @@ #include "fwbuilder/IPService.h" #include "fwbuilder/Constants.h" +#include #include #include #include @@ -58,12 +58,12 @@ class UpgradePredicate: public XMLTools::UpgradePredicate }; -void GeneratedScriptTest::setUp() +void GeneratedScriptTest::init() { Configlet::setDebugging(true); } -void GeneratedScriptTest::tearDown() +void GeneratedScriptTest::cleanup() { } @@ -97,13 +97,13 @@ void GeneratedScriptTest::runCompiler(const std::string &test_file, CompilerDriver_ipfw driver(objdb); driver.setEmbeddedMode(); - CPPUNIT_ASSERT_MESSAGE("CompilerDriver_ipfw initialization failed", - driver.prepare(args) == true); + QVERIFY2(driver.prepare(args) == true, + "CompilerDriver_ipfw initialization failed"); driver.compile(); // compiler should have created file generate_file_name QFileInfo fi(generate_file_name.c_str()); - CPPUNIT_ASSERT_MESSAGE("Generated file " + generate_file_name + " not found", - fi.exists() == true); + QVERIFY2(fi.exists() == true, + std::string("Generated file " + generate_file_name + " not found").data()); } // I can check only certain parts of the top comment. Can't @@ -117,7 +117,7 @@ void GeneratedScriptTest::ManifestTest_1() runCompiler("test1.fwb", "ipfw1", "ipfw1.fw"); QString res = Configlet::findConfigletInFile("top_comment", "ipfw1.fw"); // find manifest and compare - CPPUNIT_ASSERT(res.indexOf("# files: * ipfw1.fw") != -1); + QVERIFY(res.indexOf("# files: * ipfw1.fw") != -1); delete objdb; } @@ -131,7 +131,7 @@ void GeneratedScriptTest::ManifestTest_2() runCompiler("test1.fwb", "ipfw2", "ipfw2-1.fw"); QString res = Configlet::findConfigletInFile("top_comment", "ipfw2-1.fw"); // find manifest and compare - CPPUNIT_ASSERT(res.indexOf("# files: * ipfw2-1.fw") != -1); + QVERIFY(res.indexOf("# files: * ipfw2-1.fw") != -1); delete objdb; } @@ -145,7 +145,7 @@ void GeneratedScriptTest::ManifestTest_3() runCompiler("test1.fwb", "ipfw2a", "ipfw2-1"); QString res = Configlet::findConfigletInFile("top_comment", "ipfw2-1"); // find manifest and compare - CPPUNIT_ASSERT(res.indexOf("# files: * ipfw2-1") != -1); + QVERIFY(res.indexOf("# files: * ipfw2-1") != -1); delete objdb; } @@ -160,19 +160,21 @@ void GeneratedScriptTest::ManifestTest_4() runCompiler("test1.fwb", "ipfw2", "ipfw2-1.fw", option_o.toStdString()); QString res = Configlet::findConfigletInFile("top_comment", "ipfw2-1.fw"); // find manifest and compare - CPPUNIT_ASSERT(res.indexOf("# files: * " + option_o) != -1); + QVERIFY(res.indexOf("# files: * " + option_o) != -1); delete objdb; } void GeneratedScriptTest::ManifestTest_5() { + QSKIP("This test was disabled in the original code"); + objdb = new FWObjectDatabase(); QString option_o = QDir::currentPath() + "/ipfw2-1"; QFile::remove(option_o); runCompiler("test1.fwb", "ipfw2a", "ipfw2-1.fw", option_o.toStdString()); QString res = Configlet::findConfigletInFile("top_comment", "ipfw2-1"); // find manifest and compare - CPPUNIT_ASSERT(res.indexOf("# files: * ipfw2-1") != -1); + QVERIFY(res.indexOf("# files: * ipfw2-1") != -1); delete objdb; } @@ -186,7 +188,7 @@ void GeneratedScriptTest::ManifestTest_6() runCompiler("test1.fwb", "ipfw3", "ipfw3.fw"); QString res = Configlet::findConfigletInFile("top_comment", "ipfw3.fw"); // find manifest and compare - CPPUNIT_ASSERT(res.indexOf("# files: * ipfw3.fw") != -1); + QVERIFY(res.indexOf("# files: * ipfw3.fw") != -1); delete objdb; } @@ -199,7 +201,7 @@ void GeneratedScriptTest::ManifestTest_7() runCompiler("test1.fwb", "ipfw4", "ipfw4.fw"); QString res = Configlet::findConfigletInFile("top_comment", "ipfw4.fw"); // find manifest and compare - CPPUNIT_ASSERT(res.indexOf("# files: * ipfw4.fw /etc/path\\ with\\ space/ipfw4.fw") != -1); + QVERIFY(res.indexOf("# files: * ipfw4.fw /etc/path\\ with\\ space/ipfw4.fw") != -1); delete objdb; } @@ -211,7 +213,7 @@ void GeneratedScriptTest::FwCommentTest() runCompiler("test1.fwb", "ipfw1", "ipfw1.fw"); QString res = Configlet::findConfigletInFile("top_comment", "ipfw1.fw"); // find string from the firewall object comment and compare - CPPUNIT_ASSERT(res.indexOf("# Firewall object test1 comment") != -1); + QVERIFY(res.indexOf("# Firewall object test1 comment") != -1); delete objdb; } diff --git a/src/unit_tests/generatedScriptTestsIpfw/generatedScriptTestsIpfw.h b/src/unit_tests/generatedScriptTestsIpfw/generatedScriptTestsIpfw.h index 91ba63129..48282d0da 100644 --- a/src/unit_tests/generatedScriptTestsIpfw/generatedScriptTestsIpfw.h +++ b/src/unit_tests/generatedScriptTestsIpfw/generatedScriptTestsIpfw.h @@ -26,19 +26,21 @@ #ifndef GENERATEDSCRIPTTESTS_IPFILTER_H #define GENERATEDSCRIPTTESTS_IPFILTER_H +#include + #include "fwbuilder/Resources.h" #include "fwbuilder/FWObjectDatabase.h" #include "fwbuilder/Library.h" #include "fwbuilder/FWException.h" #include "fwbuilder/Logger.h" -#include - #include -class GeneratedScriptTest : public CppUnit::TestFixture +class GeneratedScriptTest : public QObject { + Q_OBJECT + libfwbuilder::FWObjectDatabase *objdb; void loadDataFile(const std::string &file_name); @@ -48,8 +50,12 @@ class GeneratedScriptTest : public CppUnit::TestFixture const std::string &output_file_option=""); public: - void setUp(); - void tearDown(); + void init(); + void cleanup(); + + // The order of tests matters because activation commands tests use + // files produced in manifest tests + void ManifestTest_1(); void ManifestTest_2(); void ManifestTest_3(); @@ -59,29 +65,6 @@ public: void ManifestTest_7(); void FwCommentTest(); - CPPUNIT_TEST_SUITE(GeneratedScriptTest); - - // The order of tests matters because activation commands tests use - // files produced in manifest tests - CPPUNIT_TEST(ManifestTest_1); - - CPPUNIT_TEST(ManifestTest_2); - - CPPUNIT_TEST(ManifestTest_3); - - CPPUNIT_TEST(ManifestTest_4); - -// CPPUNIT_TEST(ManifestTest_5); -// CPPUNIT_TEST(ActivationCommandsTest_5); - - CPPUNIT_TEST(ManifestTest_6); - - CPPUNIT_TEST(ManifestTest_7); - - CPPUNIT_TEST(FwCommentTest); - - CPPUNIT_TEST_SUITE_END(); - }; #endif // GENERATEDSCRIPTTESTS_IPFILTER_H diff --git a/src/unit_tests/generatedScriptTestsIpfw/main_generatedScriptTestsIpfw.cpp b/src/unit_tests/generatedScriptTestsIpfw/main_generatedScriptTestsIpfw.cpp index ba1dff2b0..362a48e79 100644 --- a/src/unit_tests/generatedScriptTestsIpfw/main_generatedScriptTestsIpfw.cpp +++ b/src/unit_tests/generatedScriptTestsIpfw/main_generatedScriptTestsIpfw.cpp @@ -1,4 +1,4 @@ -/* +/* Firewall Builder @@ -17,18 +17,15 @@ 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 #include "generatedScriptTestsIpfw.h" -#include -#include - #include "fwbuilder/Resources.h" #include "fwbuilder/Constants.h" @@ -42,7 +39,7 @@ using namespace libfwbuilder; int main(int argc, char **argv) -{ +{ QApplication app(argc, argv, false); // compilers always write file names into manifest in Utf8 @@ -52,11 +49,5 @@ int main(int argc, char **argv) Resources res(Constants::getResourcesFilePath()); - - CppUnit::TextUi::TestRunner runner; - runner.addTest( GeneratedScriptTest::suite() ); - runner.setOutputter( new CppUnit::CompilerOutputter( &runner.result(), - std::cerr ) ); - - runner.run(); + return QTest::qExec(new GeneratedScriptTest()); } diff --git a/src/unit_tests/generatedScriptTestsLinux/CMakeLists.txt b/src/unit_tests/generatedScriptTestsLinux/CMakeLists.txt index 5e51fbb2c..7cdb5d894 100644 --- a/src/unit_tests/generatedScriptTestsLinux/CMakeLists.txt +++ b/src/unit_tests/generatedScriptTestsLinux/CMakeLists.txt @@ -1,7 +1,9 @@ +SET(CMAKE_AUTOMOC ON) + add_executable(generatedScriptTestsLinux generatedScriptTestsLinux.cpp main_generatedScriptTestsLinux.cpp) add_test(NAME generatedScriptTestsLinux COMMAND generatedScriptTestsLinux) -target_link_libraries(generatedScriptTestsLinux PRIVATE test_main netsnmp gui import fwbparser antlr common iptlib fwbpf fwbjuniper fwbcisco compilerdriver fwcompiler fwbuilder xml2 xslt z pthread cppunit) +target_link_libraries(generatedScriptTestsLinux PRIVATE test_main netsnmp gui import fwbparser antlr common iptlib fwbpf fwbjuniper fwbcisco compilerdriver fwcompiler fwbuilder xml2 xslt z pthread Qt5::Test) file(COPY test1.fwb DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) diff --git a/src/unit_tests/generatedScriptTestsLinux/generatedScriptTestsLinux.cpp b/src/unit_tests/generatedScriptTestsLinux/generatedScriptTestsLinux.cpp index 67df15f95..2efe44dd6 100644 --- a/src/unit_tests/generatedScriptTestsLinux/generatedScriptTestsLinux.cpp +++ b/src/unit_tests/generatedScriptTestsLinux/generatedScriptTestsLinux.cpp @@ -1,4 +1,4 @@ -/* +/* Firewall Builder @@ -17,7 +17,7 @@ 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 @@ -34,6 +34,7 @@ #include "fwbuilder/IPService.h" #include "fwbuilder/Constants.h" +#include #include #include #include @@ -49,15 +50,15 @@ using namespace fwcompiler; class UpgradePredicate: public XMLTools::UpgradePredicate { public: - virtual bool operator()(const string&) const - { + virtual bool operator()(const string&) const + { cout << "Data file has been created in the old version of Firewall Builder. Use fwbuilder GUI to convert it." << std::endl; return false; } }; -void GeneratedScriptTest::setUp() +void GeneratedScriptTest::init() { // register protocols we need IPService::addNamedProtocol(51, "ah"); @@ -66,7 +67,7 @@ void GeneratedScriptTest::setUp() Configlet::setDebugging(true); } -void GeneratedScriptTest::tearDown() +void GeneratedScriptTest::cleanup() { } @@ -75,7 +76,7 @@ void GeneratedScriptTest::loadDataFile(const string &file_name) try { /* load the data file */ - UpgradePredicate upgrade_predicate; + UpgradePredicate upgrade_predicate; objdb->setReadOnly( false ); objdb->load(file_name, &upgrade_predicate, Constants::getDTDDirectory()); @@ -98,13 +99,13 @@ void GeneratedScriptTest::runCompiler(const std::string &test_file, CompilerDriver_ipt driver(objdb); driver.setEmbeddedMode(); - CPPUNIT_ASSERT_MESSAGE("CompilerDriver_ipt initialization failed", - driver.prepare(args) == true); + QVERIFY2(driver.prepare(args) == true, + "CompilerDriver_ipt initialization failed"); driver.compile(); // compiler should have created file test1.fw QFileInfo fi(generate_file_name.c_str()); - CPPUNIT_ASSERT_MESSAGE("Generated file " + generate_file_name + " not found", - fi.exists() == true); + QVERIFY2(fi.exists() == true, + std::string("Generated file " + generate_file_name + " not found").data()); } // I can check only certain parts of the top comment. Can't @@ -117,25 +118,25 @@ void GeneratedScriptTest::ManifestTest() runCompiler("test1.fwb", "test1", "test1.fw"); QString res = Configlet::findConfigletInFile("top_comment", "test1.fw"); // find manifest and compare - CPPUNIT_ASSERT(res.indexOf("# files: * test1.fw") != -1); - CPPUNIT_ASSERT(res.indexOf("# files: * test2.fw") == -1); + QVERIFY(res.indexOf("# files: * test1.fw") != -1); + QVERIFY(res.indexOf("# files: * test2.fw") == -1); delete objdb; objdb = new FWObjectDatabase(); runCompiler("test1.fwb", "test3", "test3.fw"); res = Configlet::findConfigletInFile("top_comment", "test3.fw"); // find manifest and compare - CPPUNIT_ASSERT(res.indexOf("# files: * test3.fw firewall.fw") != -1); - CPPUNIT_ASSERT(res.indexOf("# files: * test1.fw") == -1); + QVERIFY(res.indexOf("# files: * test3.fw firewall.fw") != -1); + QVERIFY(res.indexOf("# files: * test1.fw") == -1); delete objdb; objdb = new FWObjectDatabase(); runCompiler("test1.fwb", "test4", "test4.fw"); res = Configlet::findConfigletInFile("top_comment", "test4.fw"); // find manifest and compare - CPPUNIT_ASSERT(res.indexOf("# files: * test4.fw /etc/init.d/firewall.fw") != -1); - CPPUNIT_ASSERT(res.indexOf("# files: * test4.fw firewall.fw") == -1); - CPPUNIT_ASSERT(res.indexOf("# files: * test1.fw") == -1); + QVERIFY(res.indexOf("# files: * test4.fw /etc/init.d/firewall.fw") != -1); + QVERIFY(res.indexOf("# files: * test4.fw firewall.fw") == -1); + QVERIFY(res.indexOf("# files: * test1.fw") == -1); delete objdb; } @@ -146,7 +147,7 @@ void GeneratedScriptTest::FwCommentTest() runCompiler("test1.fwb", "test1", "test1.fw"); QString res = Configlet::findConfigletInFile("top_comment", "test1.fw"); // find string from the firewall object comment and compare - CPPUNIT_ASSERT(res.indexOf("# Firewall object test1 comment") != -1); + QVERIFY(res.indexOf("# Firewall object test1 comment") != -1); delete objdb; } @@ -178,7 +179,7 @@ void GeneratedScriptTest::CheckUtilitiesTest() utils.push_back(line.trimmed()); } } - CPPUNIT_ASSERT(utils == test1_utils); + QVERIFY(utils == test1_utils); delete objdb; utils.clear(); @@ -193,7 +194,7 @@ void GeneratedScriptTest::CheckUtilitiesTest() utils.push_back(line.trimmed()); } } - CPPUNIT_ASSERT(utils == test2_utils); + QVERIFY(utils == test2_utils); delete objdb; } @@ -203,13 +204,13 @@ void GeneratedScriptTest::verifyInterfacesTest() objdb = new FWObjectDatabase(); runCompiler("test1.fwb", "test1", "test1.fw"); QString res = Configlet::findConfigletInFile("verify_interfaces", "test1.fw"); - CPPUNIT_ASSERT(res.indexOf("for i in eth0 eth1 lo eth2 ; do") != -1); + QVERIFY(res.indexOf("for i in eth0 eth1 lo eth2 ; do") != -1); delete objdb; objdb = new FWObjectDatabase(); runCompiler("test1.fwb", "test4", "test4.fw"); res = Configlet::findConfigletInFile("verify_interfaces", "test4.fw"); - CPPUNIT_ASSERT(res.indexOf("for i in eth0 eth1 lo eth2 eth1.200 vlan110 vlan111 ; do") != -1); + QVERIFY(res.indexOf("for i in eth0 eth1 lo eth2 eth1.200 vlan110 vlan111 ; do") != -1); delete objdb; } @@ -229,7 +230,7 @@ void GeneratedScriptTest::configureInterfacesTest() // own configlet QString res = Configlet::findConfigletInFile("script_skeleton", "test4.fw"); int n1 = res.indexOf("configure_interfaces() {"); - CPPUNIT_ASSERT_MESSAGE("Shell function configure_interfaces is missing", n1 != -1); + QVERIFY2( n1 != -1, "Shell function configure_interfaces is missing"); int n2 = res.indexOf("}", n1); res = res.mid(n1, n2-n1); @@ -245,7 +246,7 @@ void GeneratedScriptTest::configureInterfacesTest() sample.sort(); intf_list.sort(); - CPPUNIT_ASSERT(sample == intf_list); + QVERIFY(sample == intf_list); delete objdb; } @@ -273,7 +274,7 @@ void GeneratedScriptTest::configureInterfacesClusterTest() // own configlet QString res = Configlet::findConfigletInFile("script_skeleton", "test2.fw"); int n1 = res.indexOf("configure_interfaces() {"); - CPPUNIT_ASSERT_MESSAGE("Shell function configure_interfaces is missing", n1 != -1); + QVERIFY2( n1 != -1, "Shell function configure_interfaces is missing"); int n2 = res.indexOf("}", n1); res = res.mid(n1, n2-n1); @@ -287,13 +288,13 @@ void GeneratedScriptTest::configureInterfacesClusterTest() } intf_list.sort(); - CPPUNIT_ASSERT(sample_2 == intf_list); + QVERIFY(sample_2 == intf_list); intf_list.clear(); res = Configlet::findConfigletInFile("script_skeleton", "test3.fw"); n1 = res.indexOf("configure_interfaces() {"); - CPPUNIT_ASSERT_MESSAGE("Shell function configure_interfaces is missing", n1 != -1); + QVERIFY2( n1 != -1, "Shell function configure_interfaces is missing"); n2 = res.indexOf("}", n1); res = res.mid(n1, n2-n1); @@ -306,7 +307,7 @@ void GeneratedScriptTest::configureInterfacesClusterTest() } intf_list.sort(); - CPPUNIT_ASSERT(sample_3 == intf_list); + QVERIFY(sample_3 == intf_list); delete objdb; } @@ -324,7 +325,7 @@ void GeneratedScriptTest::virtualAddressesForNat1Test() // own configlet QString res = Configlet::findConfigletInFile("script_skeleton", "test5.fw"); int n1 = res.indexOf("configure_interfaces() {"); - CPPUNIT_ASSERT_MESSAGE("Shell function configure_interfaces is missing", n1 != -1); + QVERIFY2( n1 != -1, "Shell function configure_interfaces is missing"); int n2 = res.indexOf("}", n1); res = res.mid(n1, n2-n1); @@ -338,7 +339,7 @@ void GeneratedScriptTest::virtualAddressesForNat1Test() } intf_list.sort(); - CPPUNIT_ASSERT(sample_1 == intf_list); + QVERIFY(sample_1 == intf_list); delete objdb; } @@ -355,7 +356,7 @@ void GeneratedScriptTest::virtualAddressesForNat2Test() // own configlet QString res = Configlet::findConfigletInFile("script_skeleton", "test6.fw"); int n1 = res.indexOf("configure_interfaces() {"); - CPPUNIT_ASSERT_MESSAGE("Shell function configure_interfaces is missing", n1 != -1); + QVERIFY2( n1 != -1, "Shell function configure_interfaces is missing"); int n2 = res.indexOf("}", n1); res = res.mid(n1, n2-n1); @@ -369,7 +370,7 @@ void GeneratedScriptTest::virtualAddressesForNat2Test() } intf_list.sort(); - CPPUNIT_ASSERT(sample_1 == intf_list); + QVERIFY(sample_1 == intf_list); delete objdb; } @@ -384,11 +385,11 @@ void GeneratedScriptTest::runTimeAddressTablesWithIpSet1Test() runCompiler("test1.fwb", "test6", "test6.fw"); QString res = Configlet::findConfigletInFile("run_time_address_tables", "test6.fw"); - CPPUNIT_ASSERT(!res.isEmpty()); + QVERIFY(!res.isEmpty()); int n1 = res.indexOf("load_run_time_address_table_files() {"); - CPPUNIT_ASSERT(n1 == -1); + QVERIFY(n1 == -1); n1 = res.indexOf("check_run_time_address_table_files() {"); - CPPUNIT_ASSERT(n1 != -1); + QVERIFY(n1 != -1); delete objdb; } @@ -410,7 +411,7 @@ void GeneratedScriptTest::runTimeAddressTablesWithIpSet2Test() QString res = Configlet::findConfigletInFile("run_time_address_tables", "test7.fw"); int n1 = res.indexOf("load_run_time_address_table_files() {"); - CPPUNIT_ASSERT_MESSAGE("Shell function load_run_time_address_table_files is missing", n1 != -1); + QVERIFY2( n1 != -1, "Shell function load_run_time_address_table_files is missing"); int n2 = res.indexOf("}", n1); QString conf = res.mid(n1, n2-n1); @@ -424,10 +425,10 @@ void GeneratedScriptTest::runTimeAddressTablesWithIpSet2Test() } cmd_list.sort(); - CPPUNIT_ASSERT(sample_1 == cmd_list); + QVERIFY(sample_1 == cmd_list); n1 = res.indexOf("check_run_time_address_table_files() {"); - CPPUNIT_ASSERT_MESSAGE("Shell function check_run_time_address_table_files is missing", n1 != -1); + QVERIFY2( n1 != -1, "Shell function check_run_time_address_table_files is missing"); n2 = res.indexOf("}", n1); conf = res.mid(n1, n2-n1); @@ -441,7 +442,7 @@ void GeneratedScriptTest::runTimeAddressTablesWithIpSet2Test() } cmd_list.sort(); - CPPUNIT_ASSERT(sample_2 == cmd_list); + QVERIFY(sample_2 == cmd_list); delete objdb; } @@ -464,18 +465,18 @@ void GeneratedScriptTest::minusDTest() CompilerDriver_ipt driver(objdb); driver.setEmbeddedMode(); - CPPUNIT_ASSERT_MESSAGE("CompilerDriver_ipt initialization failed", - driver.prepare(args) == true); + QVERIFY2(driver.prepare(args) == true, + "CompilerDriver_ipt initialization failed"); driver.compile(); // compiler should have created file /tmp/test1.fw QFileInfo fi("/tmp/test1.fw"); - CPPUNIT_ASSERT_MESSAGE("Generated file /tmp/test1.fw not found", - fi.exists() == true); + QVERIFY2(fi.exists() == true, + "Generated file /tmp/test1.fw not found"); QString res = Configlet::findConfigletInFile("top_comment", "/tmp/test1.fw"); // find manifest and compare - CPPUNIT_ASSERT(res.indexOf("# files: * test1.fw") != -1); - CPPUNIT_ASSERT(res.indexOf("# files: * test2.fw") == -1); + QVERIFY(res.indexOf("# files: * test1.fw") != -1); + QVERIFY(res.indexOf("# files: * test2.fw") == -1); delete objdb; QDir::setCurrent(current.path()); @@ -504,20 +505,19 @@ void GeneratedScriptTest::minusOTest1() CompilerDriver_ipt driver(objdb); driver.setEmbeddedMode(); - CPPUNIT_ASSERT_MESSAGE("CompilerDriver_ipt initialization failed", - driver.prepare(args) == true); + QVERIFY2(driver.prepare(args) == true, + "CompilerDriver_ipt initialization failed"); driver.compile(); // compiler should have created file full_output_file_name QFileInfo fi(full_output_file_name); - CPPUNIT_ASSERT_MESSAGE("Generated file " + - full_output_file_name.toStdString() + " not found", - fi.exists() == true); + QVERIFY2(fi.exists() == true, + std::string("Generated file " + full_output_file_name.toStdString() + " not found").data()); QString res = Configlet::findConfigletInFile( "top_comment", full_output_file_name); // find manifest and compare - CPPUNIT_ASSERT(res.indexOf("# files: * " + full_output_file_name) != -1); - CPPUNIT_ASSERT(res.indexOf("# files: * test2.fw") == -1); + QVERIFY(res.indexOf("# files: * " + full_output_file_name) != -1); + QVERIFY(res.indexOf("# files: * test2.fw") == -1); delete objdb; } @@ -539,21 +539,20 @@ void GeneratedScriptTest::minusOTest2() CompilerDriver_ipt driver(objdb); driver.setEmbeddedMode(); - CPPUNIT_ASSERT_MESSAGE("CompilerDriver_ipt initialization failed", - driver.prepare(args) == true); + QVERIFY2(driver.prepare(args) == true, + "CompilerDriver_ipt initialization failed"); driver.compile(); // compiler should have created file full_output_file_name QFileInfo fi(full_output_file_name); - CPPUNIT_ASSERT_MESSAGE("Generated file " + - full_output_file_name.toStdString() + " not found", - fi.exists() == true); + QVERIFY2(fi.exists() == true, + std::string("Generated file " + full_output_file_name.toStdString() + " not found").data()); QString res = Configlet::findConfigletInFile( "top_comment", full_output_file_name); // find manifest and compare - CPPUNIT_ASSERT(res.indexOf("# files: * " + full_output_file_name) != -1); - CPPUNIT_ASSERT(res.indexOf("# files: * test1.fw") == -1); - CPPUNIT_ASSERT(res.indexOf("# files: * test2.fw") == -1); + QVERIFY(res.indexOf("# files: * " + full_output_file_name) != -1); + QVERIFY(res.indexOf("# files: * test1.fw") == -1); + QVERIFY(res.indexOf("# files: * test2.fw") == -1); delete objdb; } @@ -575,20 +574,19 @@ void GeneratedScriptTest::minusDminusOTest() CompilerDriver_ipt driver(objdb); driver.setEmbeddedMode(); - CPPUNIT_ASSERT_MESSAGE("CompilerDriver_ipt initialization failed", - driver.prepare(args) == true); + QVERIFY2(driver.prepare(args) == true, + "CompilerDriver_ipt initialization failed"); driver.compile(); // compiler should have created file full_output_file_name QFileInfo fi(full_output_file_name); - CPPUNIT_ASSERT_MESSAGE("Generated file " + - full_output_file_name.toStdString() + " not found", - fi.exists() == true); + QVERIFY2(fi.exists() == true, + std::string("Generated file " + full_output_file_name.toStdString() + " not found").data()); QString res = Configlet::findConfigletInFile( "top_comment", full_output_file_name); // find manifest and compare - CPPUNIT_ASSERT(res.indexOf("# files: * " + full_output_file_name) != -1); - CPPUNIT_ASSERT(res.indexOf("# files: * test2.fw") == -1); + QVERIFY(res.indexOf("# files: * " + full_output_file_name) != -1); + QVERIFY(res.indexOf("# files: * test2.fw") == -1); delete objdb; QDir::setCurrent(current.path()); @@ -611,21 +609,20 @@ void GeneratedScriptTest::outputFileNameOptionTest1() CompilerDriver_ipt driver(objdb); driver.setEmbeddedMode(); - CPPUNIT_ASSERT_MESSAGE("CompilerDriver_ipt initialization failed", - driver.prepare(args) == true); + QVERIFY2(driver.prepare(args) == true, + "CompilerDriver_ipt initialization failed"); driver.compile(); // compiler should have created file full_output_file_name QFileInfo fi(full_output_file_name); - CPPUNIT_ASSERT_MESSAGE("Generated file " + - full_output_file_name.toStdString() + " not found", - fi.exists() == true); + QVERIFY2(fi.exists() == true, + std::string("Generated file " + full_output_file_name.toStdString() + " not found").data()); QString res = Configlet::findConfigletInFile( "top_comment", full_output_file_name); // find manifest and compare - CPPUNIT_ASSERT(res.indexOf("# files: * " + full_output_file_name) != -1); - CPPUNIT_ASSERT(res.indexOf("# files: * test1.fw") == -1); - CPPUNIT_ASSERT(res.indexOf("# files: * test2.fw") == -1); + QVERIFY(res.indexOf("# files: * " + full_output_file_name) != -1); + QVERIFY(res.indexOf("# files: * test1.fw") == -1); + QVERIFY(res.indexOf("# files: * test2.fw") == -1); delete objdb; } @@ -646,21 +643,20 @@ void GeneratedScriptTest::outputFileNameOptionTest2() CompilerDriver_ipt driver(objdb); driver.setEmbeddedMode(); - CPPUNIT_ASSERT_MESSAGE("CompilerDriver_ipt initialization failed", - driver.prepare(args) == true); + QVERIFY2(driver.prepare(args) == true, + "CompilerDriver_ipt initialization failed"); driver.compile(); // compiler should have created file full_output_file_name QFileInfo fi(full_output_file_name); - CPPUNIT_ASSERT_MESSAGE("Generated file " + - full_output_file_name.toStdString() + " not found", - fi.exists() == true); + QVERIFY2(fi.exists() == true, + std::string("Generated file " + full_output_file_name.toStdString() + " not found").data()); QString res = Configlet::findConfigletInFile( "top_comment", full_output_file_name); // find manifest and compare - CPPUNIT_ASSERT(res.indexOf("# files: * " + full_output_file_name) != -1); - CPPUNIT_ASSERT(res.indexOf("# files: * test1.fw") == -1); - CPPUNIT_ASSERT(res.indexOf("# files: * test2.fw") == -1); + QVERIFY(res.indexOf("# files: * " + full_output_file_name) != -1); + QVERIFY(res.indexOf("# files: * test1.fw") == -1); + QVERIFY(res.indexOf("# files: * test2.fw") == -1); delete objdb; } @@ -685,21 +681,20 @@ void GeneratedScriptTest::outputFileNameOptionTest3() CompilerDriver_ipt driver(objdb); driver.setEmbeddedMode(); - CPPUNIT_ASSERT_MESSAGE("CompilerDriver_ipt initialization failed", - driver.prepare(args) == true); + QVERIFY2(driver.prepare(args) == true, + "CompilerDriver_ipt initialization failed"); driver.compile(); // compiler should have created file full_output_file_name QFileInfo fi(full_output_file_name); - CPPUNIT_ASSERT_MESSAGE("Generated file " + - full_output_file_name.toStdString() + " not found", - fi.exists() == true); + QVERIFY2(fi.exists() == true, + std::string("Generated file " + full_output_file_name.toStdString() + " not found").data()); QString res = Configlet::findConfigletInFile( "top_comment", full_output_file_name); // find manifest and compare - CPPUNIT_ASSERT(res.indexOf("# files: * " + full_output_file_name) != -1); - CPPUNIT_ASSERT(res.indexOf("# files: * test1.fw") == -1); - CPPUNIT_ASSERT(res.indexOf("# files: * test2.fw") == -1); + QVERIFY(res.indexOf("# files: * " + full_output_file_name) != -1); + QVERIFY(res.indexOf("# files: * test1.fw") == -1); + QVERIFY(res.indexOf("# files: * test2.fw") == -1); delete objdb; } diff --git a/src/unit_tests/generatedScriptTestsLinux/generatedScriptTestsLinux.h b/src/unit_tests/generatedScriptTestsLinux/generatedScriptTestsLinux.h index 49f304a73..c379000c4 100644 --- a/src/unit_tests/generatedScriptTestsLinux/generatedScriptTestsLinux.h +++ b/src/unit_tests/generatedScriptTestsLinux/generatedScriptTestsLinux.h @@ -32,13 +32,14 @@ #include "fwbuilder/FWException.h" #include "fwbuilder/Logger.h" -#include - +#include #include -class GeneratedScriptTest : public CppUnit::TestFixture +class GeneratedScriptTest : public QObject { + Q_OBJECT + libfwbuilder::FWObjectDatabase *objdb; void loadDataFile(const std::string &file_name); @@ -46,9 +47,10 @@ class GeneratedScriptTest : public CppUnit::TestFixture const std::string &firewall_object_name, const std::string &generate_file_name); -public: - void setUp(); - void tearDown(); +private slots: + void init(); + void cleanup(); + void ManifestTest(); void FwCommentTest(); void CheckUtilitiesTest(); @@ -66,28 +68,6 @@ public: void outputFileNameOptionTest1(); void outputFileNameOptionTest2(); void outputFileNameOptionTest3(); - - CPPUNIT_TEST_SUITE(GeneratedScriptTest); - CPPUNIT_TEST(ManifestTest); - CPPUNIT_TEST(FwCommentTest); - CPPUNIT_TEST(CheckUtilitiesTest); - CPPUNIT_TEST(verifyInterfacesTest); - CPPUNIT_TEST(configureInterfacesTest); - CPPUNIT_TEST(configureInterfacesClusterTest); - CPPUNIT_TEST(virtualAddressesForNat1Test); - CPPUNIT_TEST(virtualAddressesForNat2Test); - CPPUNIT_TEST(runTimeAddressTablesWithIpSet1Test); - CPPUNIT_TEST(runTimeAddressTablesWithIpSet2Test); - CPPUNIT_TEST(minusDTest); - CPPUNIT_TEST(minusOTest1); - CPPUNIT_TEST(minusOTest2); - CPPUNIT_TEST(minusDminusOTest); - CPPUNIT_TEST(outputFileNameOptionTest1); - CPPUNIT_TEST(outputFileNameOptionTest2); - CPPUNIT_TEST(outputFileNameOptionTest3); - - CPPUNIT_TEST_SUITE_END(); - }; #endif // GENERATEDSCRIPTTESTS_LINUX_H diff --git a/src/unit_tests/generatedScriptTestsLinux/main_generatedScriptTestsLinux.cpp b/src/unit_tests/generatedScriptTestsLinux/main_generatedScriptTestsLinux.cpp index 24c69ddda..6a13a4469 100644 --- a/src/unit_tests/generatedScriptTestsLinux/main_generatedScriptTestsLinux.cpp +++ b/src/unit_tests/generatedScriptTestsLinux/main_generatedScriptTestsLinux.cpp @@ -1,4 +1,4 @@ -/* +/* Firewall Builder @@ -17,7 +17,7 @@ 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 @@ -26,12 +26,10 @@ #include "generatedScriptTestsLinux.h" -#include -#include - #include "fwbuilder/Resources.h" #include "fwbuilder/Constants.h" +#include #include #include @@ -42,7 +40,7 @@ using namespace libfwbuilder; int main(int argc, char **argv) -{ +{ QApplication app(argc, argv, false); // compilers always write file names into manifest in Utf8 @@ -52,11 +50,5 @@ int main(int argc, char **argv) Resources res(Constants::getResourcesFilePath()); - - CppUnit::TextUi::TestRunner runner; - runner.addTest( GeneratedScriptTest::suite() ); - runner.setOutputter( new CppUnit::CompilerOutputter( &runner.result(), - std::cerr ) ); - - runner.run(); + return QTest::qExec(new GeneratedScriptTest()); } diff --git a/src/unit_tests/generatedScriptTestsPF/CMakeLists.txt b/src/unit_tests/generatedScriptTestsPF/CMakeLists.txt index 9c5cfc86d..bcec28947 100644 --- a/src/unit_tests/generatedScriptTestsPF/CMakeLists.txt +++ b/src/unit_tests/generatedScriptTestsPF/CMakeLists.txt @@ -1,7 +1,9 @@ +SET(CMAKE_AUTOMOC ON) + add_executable(generatedScriptTestsPF generatedScriptTestsPF.cpp main_generatedScriptTestsPF.cpp) add_test(NAME generatedScriptTestsPF COMMAND generatedScriptTestsPF) -target_link_libraries(generatedScriptTestsPF PRIVATE test_main netsnmp gui import fwbparser antlr common iptlib fwbpf fwbjuniper fwbcisco compilerdriver fwcompiler fwbuilder xml2 xslt z pthread cppunit) +target_link_libraries(generatedScriptTestsPF PRIVATE test_main netsnmp gui import fwbparser antlr common iptlib fwbpf fwbjuniper fwbcisco compilerdriver fwcompiler fwbuilder xml2 xslt z pthread Qt5::Test) file(COPY test1.fwb DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) diff --git a/src/unit_tests/generatedScriptTestsPF/generatedScriptTestsPF.cpp b/src/unit_tests/generatedScriptTestsPF/generatedScriptTestsPF.cpp index 521a60606..c4c4a5e1d 100644 --- a/src/unit_tests/generatedScriptTestsPF/generatedScriptTestsPF.cpp +++ b/src/unit_tests/generatedScriptTestsPF/generatedScriptTestsPF.cpp @@ -1,4 +1,4 @@ -/* +/* Firewall Builder @@ -17,7 +17,7 @@ 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 @@ -34,6 +34,7 @@ #include "fwbuilder/IPService.h" #include "fwbuilder/Constants.h" +#include #include #include #include @@ -50,27 +51,27 @@ using namespace fwcompiler; class UpgradePredicate: public XMLTools::UpgradePredicate { public: - virtual bool operator()(const string&) const - { + virtual bool operator()(const string&) const + { cout << "Data file has been created in the old version of Firewall Builder. Use fwbuilder GUI to convert it." << std::endl; return false; } }; -void GeneratedScriptTest::setUp() +void GeneratedScriptTest::init() { Configlet::setDebugging(true); } -void GeneratedScriptTest::tearDown() +void GeneratedScriptTest::cleanup() { } void GeneratedScriptTest::loadDataFile(const string &file_name) { /* load the data file */ - UpgradePredicate upgrade_predicate; + UpgradePredicate upgrade_predicate; objdb->setReadOnly( false ); objdb->load(file_name, &upgrade_predicate, Constants::getDTDDirectory()); @@ -97,13 +98,13 @@ void GeneratedScriptTest::runCompiler(const std::string &test_file, CompilerDriver_pf driver(objdb); driver.setEmbeddedMode(); - CPPUNIT_ASSERT_MESSAGE("CompilerDriver_pf initialization failed", - driver.prepare(args) == true); + QVERIFY2(driver.prepare(args) == true, + "CompilerDriver_pf initialization failed"); driver.compile(); // compiler should have created file generate_file_name QFileInfo fi(generate_file_name.c_str()); - CPPUNIT_ASSERT_MESSAGE("Generated file " + generate_file_name + " not found", - fi.exists() == true); + QVERIFY2(fi.exists() == true, + std::string("Generated file " + generate_file_name + " not found").data()); } // I can check only certain parts of the top comment. Can't @@ -118,8 +119,8 @@ void GeneratedScriptTest::ManifestTest_1() runCompiler("test1.fwb", "pf1", "pf1.fw"); QString res = Configlet::findConfigletInFile("top_comment", "pf1.fw"); // find manifest and compare - CPPUNIT_ASSERT(res.indexOf("# files: * pf1.fw") != -1); - CPPUNIT_ASSERT(res.indexOf("# files: pf1.conf") != -1); + QVERIFY(res.indexOf("# files: * pf1.fw") != -1); + QVERIFY(res.indexOf("# files: pf1.conf") != -1); delete objdb; } @@ -135,8 +136,8 @@ void GeneratedScriptTest::ManifestTest_2() runCompiler("test1.fwb", "pf2", "ipf2-1.fw"); QString res = Configlet::findConfigletInFile("top_comment", "ipf2-1.fw"); // find manifest and compare - CPPUNIT_ASSERT(res.indexOf("# files: * ipf2-1.fw") != -1); - CPPUNIT_ASSERT(res.indexOf("# files: ipf2-1.conf") != -1); + QVERIFY(res.indexOf("# files: * ipf2-1.fw") != -1); + QVERIFY(res.indexOf("# files: ipf2-1.conf") != -1); delete objdb; } @@ -150,8 +151,8 @@ void GeneratedScriptTest::ManifestTest_3() runCompiler("test1.fwb", "pf2a", "ipf2-1.fw"); QString res = Configlet::findConfigletInFile("top_comment", "ipf2-1.fw"); // find manifest and compare - CPPUNIT_ASSERT(res.indexOf("# files: * ipf2-1.fw") != -1); - CPPUNIT_ASSERT(res.indexOf("# files: ipf2-1.conf") != -1); + QVERIFY(res.indexOf("# files: * ipf2-1.fw") != -1); + QVERIFY(res.indexOf("# files: ipf2-1.conf") != -1); delete objdb; } @@ -167,20 +168,22 @@ void GeneratedScriptTest::ManifestTest_4() runCompiler("test1.fwb", "pf2", "pf2-1.fw", option_o.toStdString()); QString res = Configlet::findConfigletInFile("top_comment", "pf2-1.fw"); // find manifest and compare - CPPUNIT_ASSERT(res.indexOf("# files: * " + option_o) != -1); - CPPUNIT_ASSERT(res.indexOf("# files: ipf2-1.conf") != -1); + QVERIFY(res.indexOf("# files: * " + option_o) != -1); + QVERIFY(res.indexOf("# files: ipf2-1.conf") != -1); delete objdb; } void GeneratedScriptTest::ManifestTest_5() { + QSKIP("This test was disabled in the original code"); + objdb = new FWObjectDatabase(); QString option_o = QDir::currentPath() + "/pf2-1"; runCompiler("test1.fwb", "pf2a", "pf2-1.fw", option_o.toStdString()); QString res = Configlet::findConfigletInFile("top_comment", "pf2-1.fw"); // find manifest and compare - CPPUNIT_ASSERT(res.indexOf("# files: * ipf2-1.fw") != -1); - CPPUNIT_ASSERT(res.indexOf("# files: ipf2-1.conf") != -1); + QVERIFY(res.indexOf("# files: * ipf2-1.fw") != -1); + QVERIFY(res.indexOf("# files: ipf2-1.conf") != -1); delete objdb; } @@ -193,8 +196,8 @@ void GeneratedScriptTest::ManifestTest_6() runCompiler("test1.fwb", "pf3", "pf3.fw"); QString res = Configlet::findConfigletInFile("top_comment", "pf3.fw"); // find manifest and compare - CPPUNIT_ASSERT(res.indexOf("# files: * pf3.fw") != -1); - CPPUNIT_ASSERT(res.indexOf("# files: pf3.conf /etc/fw/pf3.conf") != -1); + QVERIFY(res.indexOf("# files: * pf3.fw") != -1); + QVERIFY(res.indexOf("# files: pf3.conf /etc/fw/pf3.conf") != -1); delete objdb; } @@ -207,8 +210,8 @@ void GeneratedScriptTest::ManifestTest_7() runCompiler("test1.fwb", "pf4", "pf4.fw"); QString res = Configlet::findConfigletInFile("top_comment", "pf4.fw"); // find manifest and compare - CPPUNIT_ASSERT(res.indexOf("# files: * pf4.fw /etc/path\\ with\\ space/pf4.fw") != -1); - CPPUNIT_ASSERT(res.indexOf("# files: pf4.conf") != -1); + QVERIFY(res.indexOf("# files: * pf4.fw /etc/path\\ with\\ space/pf4.fw") != -1); + QVERIFY(res.indexOf("# files: pf4.conf") != -1); delete objdb; } @@ -221,8 +224,8 @@ void GeneratedScriptTest::ManifestTest_8() runCompiler("test1.fwb", "pf5", "pf5.fw"); QString res = Configlet::findConfigletInFile("top_comment", "pf5.fw"); // find manifest and compare - CPPUNIT_ASSERT(res.indexOf("# files: * pf5.fw") != -1); - CPPUNIT_ASSERT(res.indexOf("# files: pf5.conf") != -1); + QVERIFY(res.indexOf("# files: * pf5.fw") != -1); + QVERIFY(res.indexOf("# files: pf5.conf") != -1); delete objdb; } @@ -235,8 +238,8 @@ void GeneratedScriptTest::ManifestTest_9() runCompiler("test1.fwb", "pf6", "/tmp/pf6.fw"); QString res = Configlet::findConfigletInFile("top_comment", "/tmp/pf6.fw"); // find manifest and compare - CPPUNIT_ASSERT(res.indexOf("# files: * /tmp/pf6.fw /etc/fw/pf6.fw") != -1); - CPPUNIT_ASSERT(res.indexOf("# files: /tmp/pf6.conf /etc/pf.conf") != -1); + QVERIFY(res.indexOf("# files: * /tmp/pf6.fw /etc/fw/pf6.fw") != -1); + QVERIFY(res.indexOf("# files: /tmp/pf6.conf /etc/pf.conf") != -1); delete objdb; } @@ -249,8 +252,8 @@ void GeneratedScriptTest::ManifestTest_10() runCompiler("test1.fwb", "pf7", "tmp/pf7.fw"); QString res = Configlet::findConfigletInFile("top_comment", "tmp/pf7.fw"); // find manifest and compare - CPPUNIT_ASSERT(res.indexOf("# files: * tmp/pf7.fw /etc/fw/pf7.fw") != -1); - CPPUNIT_ASSERT(res.indexOf("# files: tmp/pf.conf /etc/pf.conf") != -1); + QVERIFY(res.indexOf("# files: * tmp/pf7.fw /etc/fw/pf7.fw") != -1); + QVERIFY(res.indexOf("# files: tmp/pf.conf /etc/pf.conf") != -1); delete objdb; } @@ -272,9 +275,9 @@ void GeneratedScriptTest::ManifestTest_11() runCompiler("test1.fwb", "pf8", "tmp/pf8.fw"); QString res = Configlet::findConfigletInFile("top_comment", "tmp/pf8.fw"); // find manifest and compare - CPPUNIT_ASSERT(res.indexOf("# files: * tmp/pf8.fw /etc/fw/pf8.fw") != -1); - CPPUNIT_ASSERT(res.indexOf("# files: tmp/pf.conf /etc/pf.conf") != -1); - CPPUNIT_ASSERT(res.indexOf("# files: tmp/pf-anchor_1.conf /etc/pf-anchor_1.conf") != -1); + QVERIFY(res.indexOf("# files: * tmp/pf8.fw /etc/fw/pf8.fw") != -1); + QVERIFY(res.indexOf("# files: tmp/pf.conf /etc/pf.conf") != -1); + QVERIFY(res.indexOf("# files: tmp/pf-anchor_1.conf /etc/pf-anchor_1.conf") != -1); delete objdb; } @@ -296,9 +299,9 @@ void GeneratedScriptTest::ManifestTest_12() runCompiler("test1.fwb", "pf9", "pf9.fw"); QString res = Configlet::findConfigletInFile("top_comment", "pf9.fw"); // find manifest and compare - CPPUNIT_ASSERT(res.indexOf("# files: * pf9.fw /etc/pf9.fw") != -1); - CPPUNIT_ASSERT(res.indexOf("# files: pf9.conf /etc/pf9.conf") != -1); - CPPUNIT_ASSERT(res.indexOf("# files: pf9-anchor_1.conf /etc/pf9-anchor_1.conf") != -1); + QVERIFY(res.indexOf("# files: * pf9.fw /etc/pf9.fw") != -1); + QVERIFY(res.indexOf("# files: pf9.conf /etc/pf9.conf") != -1); + QVERIFY(res.indexOf("# files: pf9-anchor_1.conf /etc/pf9-anchor_1.conf") != -1); delete objdb; } @@ -310,7 +313,7 @@ void GeneratedScriptTest::FwCommentTest() runCompiler("test1.fwb", "pf1", "pf1.fw"); QString res = Configlet::findConfigletInFile("top_comment", "pf1.fw"); // find string from the firewall object comment and compare - CPPUNIT_ASSERT(res.indexOf("# Firewall object test1 comment") != -1); + QVERIFY(res.indexOf("# Firewall object test1 comment") != -1); delete objdb; } @@ -325,7 +328,7 @@ void GeneratedScriptTest::ActivationCommandsTest_1() objdb = new FWObjectDatabase(); QString res = Configlet::findConfigletInFile("activation", "pf1.fw") .split(QRegExp("\\s+")).join(" "); - CPPUNIT_ASSERT(res.indexOf("$PFCTL -f /etc/pf1.conf") != -1); + QVERIFY(res.indexOf("$PFCTL -f /etc/pf1.conf") != -1); delete objdb; } @@ -334,7 +337,7 @@ void GeneratedScriptTest::ActivationCommandsTest_2() objdb = new FWObjectDatabase(); QString res = Configlet::findConfigletInFile("activation", "ipf2-1.fw") .split(QRegExp("\\s+")).join(" "); - CPPUNIT_ASSERT(res.indexOf("$PFCTL -f /etc/ipf2-1.conf") != -1); + QVERIFY(res.indexOf("$PFCTL -f /etc/ipf2-1.conf") != -1); delete objdb; } @@ -343,7 +346,7 @@ void GeneratedScriptTest::ActivationCommandsTest_3() objdb = new FWObjectDatabase(); QString res = Configlet::findConfigletInFile("activation", "ipf2-1.fw") .split(QRegExp("\\s+")).join(" "); - CPPUNIT_ASSERT(res.indexOf("$PFCTL -f /etc/ipf2-1.conf") != -1); + QVERIFY(res.indexOf("$PFCTL -f /etc/ipf2-1.conf") != -1); delete objdb; } @@ -352,7 +355,7 @@ void GeneratedScriptTest::ActivationCommandsTest_4() objdb = new FWObjectDatabase(); QString res = Configlet::findConfigletInFile("activation", "pf2-1.fw") .split(QRegExp("\\s+")).join(" "); - CPPUNIT_ASSERT(res.indexOf("$PFCTL -f /etc/ipf2-1.conf") != -1); + QVERIFY(res.indexOf("$PFCTL -f /etc/ipf2-1.conf") != -1); delete objdb; } @@ -361,7 +364,7 @@ void GeneratedScriptTest::ActivationCommandsTest_6() objdb = new FWObjectDatabase(); QString res = Configlet::findConfigletInFile("activation", "pf3.fw") .split(QRegExp("\\s+")).join(" "); - CPPUNIT_ASSERT(res.indexOf("$PFCTL -f /etc/fw/pf3.conf") != -1); + QVERIFY(res.indexOf("$PFCTL -f /etc/fw/pf3.conf") != -1); delete objdb; } @@ -376,7 +379,7 @@ void GeneratedScriptTest::ActivationCommandsTest_7() objdb = new FWObjectDatabase(); QString res = Configlet::findConfigletInFile("activation", "pf4.fw") .split(QRegExp("\\s+")).join(" "); - CPPUNIT_ASSERT(res.indexOf("$PFCTL -f /etc/pf4.conf") != -1); + QVERIFY(res.indexOf("$PFCTL -f /etc/pf4.conf") != -1); delete objdb; } @@ -385,7 +388,7 @@ void GeneratedScriptTest::ActivationCommandsTest_8() objdb = new FWObjectDatabase(); QString res = Configlet::findConfigletInFile("activation", "pf5.fw") .split(QRegExp("\\s+")).join(" "); - CPPUNIT_ASSERT(res.indexOf("$PFCTL -f /etc/pf5.conf") != -1); + QVERIFY(res.indexOf("$PFCTL -f /etc/pf5.conf") != -1); delete objdb; } @@ -394,7 +397,7 @@ void GeneratedScriptTest::ActivationCommandsTest_9() objdb = new FWObjectDatabase(); QString res = Configlet::findConfigletInFile("activation", "/tmp/pf6.fw") .split(QRegExp("\\s+")).join(" "); - CPPUNIT_ASSERT(res.indexOf("$PFCTL -f /etc/pf.conf") != -1); + QVERIFY(res.indexOf("$PFCTL -f /etc/pf.conf") != -1); delete objdb; } @@ -403,7 +406,7 @@ void GeneratedScriptTest::ActivationCommandsTest_10() objdb = new FWObjectDatabase(); QString res = Configlet::findConfigletInFile("activation", "tmp/pf7.fw") .split(QRegExp("\\s+")).join(" "); - CPPUNIT_ASSERT(res.indexOf("$PFCTL -f /etc/pf.conf") != -1); + QVERIFY(res.indexOf("$PFCTL -f /etc/pf.conf") != -1); delete objdb; } @@ -413,7 +416,7 @@ void GeneratedScriptTest::ActivationCommandsTest_11() QString res = Configlet::findConfigletInFile("activation", "tmp/pf8.fw", 1) .split(QRegExp("\\s+")).join(" "); - CPPUNIT_ASSERT(res.indexOf("$PFCTL -f /etc/pf.conf") != -1); + QVERIFY(res.indexOf("$PFCTL -f /etc/pf.conf") != -1); delete objdb; } @@ -423,7 +426,7 @@ void GeneratedScriptTest::ActivationCommandsTest_12() objdb = new FWObjectDatabase(); QString res = Configlet::findConfigletInFile("activation", "pf9.fw", 1) .split(QRegExp("\\s+")).join(" "); - CPPUNIT_ASSERT(res.indexOf("$PFCTL -f /etc/pf9.conf") != -1); + QVERIFY(res.indexOf("$PFCTL -f /etc/pf9.conf") != -1); delete objdb; } diff --git a/src/unit_tests/generatedScriptTestsPF/generatedScriptTestsPF.h b/src/unit_tests/generatedScriptTestsPF/generatedScriptTestsPF.h index f32fc04e8..6941676d5 100644 --- a/src/unit_tests/generatedScriptTestsPF/generatedScriptTestsPF.h +++ b/src/unit_tests/generatedScriptTestsPF/generatedScriptTestsPF.h @@ -32,13 +32,14 @@ #include "fwbuilder/FWException.h" #include "fwbuilder/Logger.h" -#include - +#include #include -class GeneratedScriptTest : public CppUnit::TestFixture +class GeneratedScriptTest : public QObject { + Q_OBJECT + libfwbuilder::FWObjectDatabase *objdb; void loadDataFile(const std::string &file_name); @@ -47,9 +48,13 @@ class GeneratedScriptTest : public CppUnit::TestFixture const std::string &generate_file_name, const std::string &output_file_option=""); -public: - void setUp(); - void tearDown(); +private slots: + void init(); + void cleanup(); + + // The order of tests matters because activation commands tests use + // files produced in manifest tests + void ManifestTest_1(); void ManifestTest_2(); void ManifestTest_3(); @@ -68,7 +73,7 @@ public: void ActivationCommandsTest_2(); void ActivationCommandsTest_3(); void ActivationCommandsTest_4(); -// void ActivationCommandsTest_5(); + void ActivationCommandsTest_6(); void ActivationCommandsTest_7(); void ActivationCommandsTest_8(); @@ -76,50 +81,6 @@ public: void ActivationCommandsTest_10(); void ActivationCommandsTest_11(); void ActivationCommandsTest_12(); - - CPPUNIT_TEST_SUITE(GeneratedScriptTest); - - // The order of tests matters because activation commands tests use - // files produced in manifest tests - CPPUNIT_TEST(ManifestTest_1); - CPPUNIT_TEST(ActivationCommandsTest_1); - - CPPUNIT_TEST(ManifestTest_2); - CPPUNIT_TEST(ActivationCommandsTest_2); - - CPPUNIT_TEST(ManifestTest_3); - CPPUNIT_TEST(ActivationCommandsTest_3); - - CPPUNIT_TEST(ManifestTest_4); - CPPUNIT_TEST(ActivationCommandsTest_4); - -// CPPUNIT_TEST(ManifestTest_5); -// CPPUNIT_TEST(ActivationCommandsTest_5); - - CPPUNIT_TEST(ManifestTest_6); - CPPUNIT_TEST(ActivationCommandsTest_6); - - CPPUNIT_TEST(ManifestTest_7); - CPPUNIT_TEST(ActivationCommandsTest_7); - - CPPUNIT_TEST(ManifestTest_8); - CPPUNIT_TEST(ActivationCommandsTest_8); - - CPPUNIT_TEST(ManifestTest_9); - CPPUNIT_TEST(ActivationCommandsTest_9); - - CPPUNIT_TEST(ManifestTest_10); - CPPUNIT_TEST(ActivationCommandsTest_10); - - CPPUNIT_TEST(ManifestTest_11); - CPPUNIT_TEST(ActivationCommandsTest_11); - - CPPUNIT_TEST(ManifestTest_12); - CPPUNIT_TEST(ActivationCommandsTest_12); - - CPPUNIT_TEST(FwCommentTest); - - CPPUNIT_TEST_SUITE_END(); }; diff --git a/src/unit_tests/generatedScriptTestsPF/main_generatedScriptTestsPF.cpp b/src/unit_tests/generatedScriptTestsPF/main_generatedScriptTestsPF.cpp index 10da43bb4..9f48d0a3b 100644 --- a/src/unit_tests/generatedScriptTestsPF/main_generatedScriptTestsPF.cpp +++ b/src/unit_tests/generatedScriptTestsPF/main_generatedScriptTestsPF.cpp @@ -1,4 +1,4 @@ -/* +/* Firewall Builder @@ -17,7 +17,7 @@ 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 @@ -26,12 +26,10 @@ #include "generatedScriptTestsPF.h" -#include -#include - #include "fwbuilder/Resources.h" #include "fwbuilder/Constants.h" +#include #include #include @@ -42,7 +40,7 @@ using namespace libfwbuilder; int main(int argc, char **argv) -{ +{ QApplication app(argc, argv, false); // compilers always write file names into manifest in Utf8 @@ -52,11 +50,5 @@ int main(int argc, char **argv) Resources res(Constants::getResourcesFilePath()); - - CppUnit::TextUi::TestRunner runner; - runner.addTest( GeneratedScriptTest::suite() ); - runner.setOutputter( new CppUnit::CompilerOutputter( &runner.result(), - std::cerr ) ); - - runner.run(); + return QTest::qExec(new GeneratedScriptTest()); } diff --git a/src/unit_tests/generatedScriptTestsSecuwall/CMakeLists.txt b/src/unit_tests/generatedScriptTestsSecuwall/CMakeLists.txt index 2a5359b8e..168f40b57 100644 --- a/src/unit_tests/generatedScriptTestsSecuwall/CMakeLists.txt +++ b/src/unit_tests/generatedScriptTestsSecuwall/CMakeLists.txt @@ -1,7 +1,9 @@ +SET(CMAKE_AUTOMOC ON) + add_executable(generatedScriptTestsSecuwall generatedScriptTestsSecuwall.cpp main_generatedScriptTestsSecuwall.cpp) add_test(NAME generatedScriptTestsSecuwall COMMAND generatedScriptTestsSecuwall) -target_link_libraries(generatedScriptTestsSecuwall PRIVATE test_main netsnmp gui import fwbparser antlr common iptlib fwbpf fwbjuniper fwbcisco compilerdriver fwcompiler fwbuilder xml2 xslt z pthread cppunit) +target_link_libraries(generatedScriptTestsSecuwall PRIVATE test_main netsnmp gui import fwbparser antlr common iptlib fwbpf fwbjuniper fwbcisco compilerdriver fwcompiler fwbuilder xml2 xslt z pthread Qt5::Test) file(COPY test1.fwb DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) diff --git a/src/unit_tests/generatedScriptTestsSecuwall/generatedScriptTestsSecuwall.cpp b/src/unit_tests/generatedScriptTestsSecuwall/generatedScriptTestsSecuwall.cpp index e74af34c7..daa4010a8 100644 --- a/src/unit_tests/generatedScriptTestsSecuwall/generatedScriptTestsSecuwall.cpp +++ b/src/unit_tests/generatedScriptTestsSecuwall/generatedScriptTestsSecuwall.cpp @@ -23,6 +23,7 @@ #include "fwbuilder/IPService.h" #include "fwbuilder/Constants.h" +#include #include #include #include @@ -43,7 +44,7 @@ class UpgradePredicate: public XMLTools::UpgradePredicate }; -void GeneratedScriptTest::setUp() +void GeneratedScriptTest::init() { // register protocols we need IPService::addNamedProtocol(51, "ah"); @@ -52,7 +53,7 @@ void GeneratedScriptTest::setUp() Configlet::setDebugging(true); } -void GeneratedScriptTest::tearDown() +void GeneratedScriptTest::cleanup() { } @@ -78,14 +79,14 @@ void GeneratedScriptTest::runCompiler(const std::string &test_file, CompilerDriver_ipt driver(objdb); driver.setEmbeddedMode(); - CPPUNIT_ASSERT_MESSAGE("CompilerDriver_ipt initialization failed", - driver.prepare(args) == true); + QVERIFY2(driver.prepare(args) == true, + "CompilerDriver_ipt initialization failed"); driver.compile(); // compiler should have created file secuwall-1.fw and test1 directory with // secuwall-specific configuration files. QFileInfo fi(generate_file_name.c_str()); - CPPUNIT_ASSERT_MESSAGE("Generated file " + generate_file_name + " not found", - fi.exists() == true); + QVERIFY2(fi.exists() == true, + std::string("Generated file " + generate_file_name + " not found").data()); } void GeneratedScriptTest::assertDirsEqual(const std::string &left_dir, @@ -102,11 +103,11 @@ void GeneratedScriptTest::assertDirsEqual(const std::string &left_dir, if (leftIt.hasNext()) { - CPPUNIT_FAIL("Directory " + left_dir + " contains more files than " + right_dir); + QFAIL(std::string("Directory " + left_dir + " contains more files than " + right_dir).data()); } if (rightIt.hasNext()) { - CPPUNIT_FAIL("Directory " + right_dir + " contains more files than " + left_dir); + QFAIL(std::string("Directory " + right_dir + " contains more files than " + left_dir).data()); } leftList.sort(); @@ -134,8 +135,7 @@ void GeneratedScriptTest::assertFilesEqual(const std::string &left_filename, rightFile.close(); } - CPPUNIT_ASSERT_MESSAGE("Files " + left_filename + " and " + right_filename + " differ", - result); + QVERIFY2(result, std::string("Files " + left_filename + " and " + right_filename + " differ").data()); } void GeneratedScriptTest::FilesGenerationTest() diff --git a/src/unit_tests/generatedScriptTestsSecuwall/generatedScriptTestsSecuwall.h b/src/unit_tests/generatedScriptTestsSecuwall/generatedScriptTestsSecuwall.h index 7009daa4c..0ce5463f1 100644 --- a/src/unit_tests/generatedScriptTestsSecuwall/generatedScriptTestsSecuwall.h +++ b/src/unit_tests/generatedScriptTestsSecuwall/generatedScriptTestsSecuwall.h @@ -17,12 +17,14 @@ #ifndef GENERATEDSCRIPTTESTS_SECUWALL_H #define GENERATEDSCRIPTTESTS_SECUWALL_H -#include +#include #include "fwbuilder/FWObjectDatabase.h" -class GeneratedScriptTest : public CppUnit::TestFixture +class GeneratedScriptTest : public QObject { + Q_OBJECT + libfwbuilder::FWObjectDatabase *objdb; void loadDataFile(const std::string &file_name); @@ -34,15 +36,11 @@ class GeneratedScriptTest : public CppUnit::TestFixture void assertFilesEqual(const std::string &left_filename, const std::string &right_filename); -public: - void setUp(); - void tearDown(); +private slots: + void init(); + void cleanup(); void FilesGenerationTest(); - CPPUNIT_TEST_SUITE(GeneratedScriptTest); - CPPUNIT_TEST(FilesGenerationTest); - CPPUNIT_TEST_SUITE_END(); - }; #endif // GENERATEDSCRIPTTESTS_SECUWALL_H diff --git a/src/unit_tests/generatedScriptTestsSecuwall/main_generatedScriptTestsSecuwall.cpp b/src/unit_tests/generatedScriptTestsSecuwall/main_generatedScriptTestsSecuwall.cpp index 49738b681..2bec43af4 100644 --- a/src/unit_tests/generatedScriptTestsSecuwall/main_generatedScriptTestsSecuwall.cpp +++ b/src/unit_tests/generatedScriptTestsSecuwall/main_generatedScriptTestsSecuwall.cpp @@ -17,12 +17,11 @@ #include "generatedScriptTestsSecuwall.h" -#include -#include #include "fwbuilder/Resources.h" #include "fwbuilder/Constants.h" +#include #include #include @@ -42,11 +41,5 @@ int main(int argc, char **argv) Resources res(Constants::getResourcesFilePath()); - - CppUnit::TextUi::TestRunner runner; - runner.addTest( GeneratedScriptTest::suite() ); - runner.setOutputter( new CppUnit::CompilerOutputter( &runner.result(), - std::cerr ) ); - - runner.run(); + return QTest::qExec(new GeneratedScriptTest()); } diff --git a/src/unit_tests/genericDialogTest/CMakeLists.txt b/src/unit_tests/genericDialogTest/CMakeLists.txt index 25df3210c..8b5a24772 100644 --- a/src/unit_tests/genericDialogTest/CMakeLists.txt +++ b/src/unit_tests/genericDialogTest/CMakeLists.txt @@ -3,4 +3,4 @@ SET(CMAKE_AUTOMOC ON) add_executable(genericDialogTest genericDialogTest.cpp main_genericDialogTest.cpp) add_test(NAME genericDialogTest COMMAND genericDialogTest) -target_link_libraries(genericDialogTest PRIVATE test_main netsnmp gui import fwbparser antlr common iptlib fwbpf fwbjuniper fwbcisco compilerdriver fwcompiler fwbuilder xml2 xslt z pthread Qt5::Test) +target_link_libraries(genericDialogTest PRIVATE test_main gui import fwbparser antlr common iptlib fwbpf fwbjuniper fwbcisco compilerdriver fwcompiler fwbuilder netsnmp xml2 xslt z pthread Qt5::Test) diff --git a/src/unit_tests/genericDialogTest/main_genericDialogTest.cpp b/src/unit_tests/genericDialogTest/main_genericDialogTest.cpp index 30e9e81ac..e65c08334 100644 --- a/src/unit_tests/genericDialogTest/main_genericDialogTest.cpp +++ b/src/unit_tests/genericDialogTest/main_genericDialogTest.cpp @@ -38,9 +38,9 @@ using namespace std; using namespace libfwbuilder; int fwbdebug = 0; -FWWindow *mw = nullptr; -FWBSettings *st = nullptr; -FWBApplication *app = nullptr; +FWWindow *mw = nullptr; +FWBSettings *st = nullptr; +FWBApplication *app = nullptr; extern void build_app(int argc, char** argv, @@ -48,16 +48,18 @@ extern void build_app(int argc, char** argv, FWBSettings** st); int main(int argc, char** argv) -{ - app = new FWBApplication(argc, argv); - app->setOrganizationName(QLatin1String("NetCitadel")); - app->setApplicationName(QLatin1String("Firewall Builder")); +{ + app = new FWBApplication(argc, argv); + app->setOrganizationName(QLatin1String("NetCitadel")); + app->setApplicationName(QLatin1String("Firewall Builder")); build_app(argc, argv, &app, &st); - QTest::qExec(new genericDialogTest()); + int testResult = QTest::qExec(new genericDialogTest()); - if (QFile::exists("test_work.fwb")) - QFile::remove("test_work.fwb"); + if (QFile::exists("test_work.fwb")) + QFile::remove("test_work.fwb"); + + return testResult; } diff --git a/src/unit_tests/instDialogClusterTest/CMakeLists.txt b/src/unit_tests/instDialogClusterTest/CMakeLists.txt index 43ea87b9b..37325de4b 100644 --- a/src/unit_tests/instDialogClusterTest/CMakeLists.txt +++ b/src/unit_tests/instDialogClusterTest/CMakeLists.txt @@ -3,6 +3,6 @@ SET(CMAKE_AUTOMOC ON) add_executable(instDialogClusterTest instDialogClusterTest.cpp main_instDialogClusterTest.cpp) add_test(NAME instDialogClusterTest COMMAND instDialogClusterTest) -target_link_libraries(instDialogClusterTest PRIVATE test_main netsnmp gui import fwbparser antlr common iptlib fwbpf fwbjuniper fwbcisco compilerdriver fwcompiler fwbuilder xml2 xslt z pthread Qt5::Test) +target_link_libraries(instDialogClusterTest PRIVATE test_main gui import fwbparser antlr common iptlib fwbpf fwbjuniper fwbcisco compilerdriver fwcompiler fwbuilder netsnmp xml2 xslt z pthread Qt5::Test) file(COPY test.fwb DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) diff --git a/src/unit_tests/instDialogClusterTest/main_instDialogClusterTest.cpp b/src/unit_tests/instDialogClusterTest/main_instDialogClusterTest.cpp index 3f156fe28..ac1fcf8fc 100644 --- a/src/unit_tests/instDialogClusterTest/main_instDialogClusterTest.cpp +++ b/src/unit_tests/instDialogClusterTest/main_instDialogClusterTest.cpp @@ -38,9 +38,9 @@ using namespace std; using namespace libfwbuilder; int fwbdebug = 0; -FWWindow *mw = nullptr; -FWBSettings *st = nullptr; -FWBApplication *app = nullptr; +FWWindow *mw = nullptr; +FWBSettings *st = nullptr; +FWBApplication *app = nullptr; extern void build_app(int argc, char** argv, @@ -48,17 +48,19 @@ extern void build_app(int argc, char** argv, FWBSettings** st); int main(int argc, char** argv) -{ - app = new FWBApplication(argc, argv); - app->setOrganizationName(QLatin1String("NetCitadel")); - app->setApplicationName(QLatin1String("Firewall Builder")); +{ + app = new FWBApplication(argc, argv); + app->setOrganizationName(QLatin1String("NetCitadel")); + app->setApplicationName(QLatin1String("Firewall Builder")); build_app(argc, argv, &app, &st); QFile::copy("test.fwb", "test_work.fwb"); - QTest::qExec(new instDialogClusterTest()); + int testResult = QTest::qExec(new instDialogClusterTest()); - if (QFile::exists("test_work.fwb")) - QFile::remove("test_work.fwb"); + if (QFile::exists("test_work.fwb")) + QFile::remove("test_work.fwb"); + + return testResult; } diff --git a/src/unit_tests/instDialogCompileTest/CMakeLists.txt b/src/unit_tests/instDialogCompileTest/CMakeLists.txt index 3292c010c..84d5536fb 100644 --- a/src/unit_tests/instDialogCompileTest/CMakeLists.txt +++ b/src/unit_tests/instDialogCompileTest/CMakeLists.txt @@ -3,6 +3,6 @@ SET(CMAKE_AUTOMOC ON) add_executable(instDialogCompileTest instDialogCompileTest.cpp main_instDialogCompileTest.cpp) add_test(NAME instDialogCompileTest COMMAND instDialogCompileTest) -target_link_libraries(instDialogCompileTest PRIVATE test_main netsnmp gui import fwbparser antlr common iptlib fwbpf fwbjuniper fwbcisco compilerdriver fwcompiler fwbuilder xml2 xslt z pthread Qt5::Test) +target_link_libraries(instDialogCompileTest PRIVATE test_main gui import fwbparser antlr common iptlib fwbpf fwbjuniper fwbcisco compilerdriver fwcompiler fwbuilder netsnmp xml2 xslt z pthread Qt5::Test) file(COPY test.fwb DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) diff --git a/src/unit_tests/instDialogCompileTest/main_instDialogCompileTest.cpp b/src/unit_tests/instDialogCompileTest/main_instDialogCompileTest.cpp index ac2262472..7a0c0b9f3 100644 --- a/src/unit_tests/instDialogCompileTest/main_instDialogCompileTest.cpp +++ b/src/unit_tests/instDialogCompileTest/main_instDialogCompileTest.cpp @@ -38,9 +38,9 @@ using namespace std; using namespace libfwbuilder; int fwbdebug = 0; -FWWindow *mw = nullptr; -FWBSettings *st = nullptr; -FWBApplication *app = nullptr; +FWWindow *mw = nullptr; +FWBSettings *st = nullptr; +FWBApplication *app = nullptr; extern void build_app(int argc, char** argv, @@ -48,17 +48,19 @@ extern void build_app(int argc, char** argv, FWBSettings** st); int main(int argc, char** argv) -{ - app = new FWBApplication(argc, argv); - app->setOrganizationName(QLatin1String("NetCitadel")); - app->setApplicationName(QLatin1String("Firewall Builder")); +{ + app = new FWBApplication(argc, argv); + app->setOrganizationName(QLatin1String("NetCitadel")); + app->setApplicationName(QLatin1String("Firewall Builder")); build_app(argc, argv, &app, &st); QFile::copy("test.fwb", "test_work.fwb"); - QTest::qExec(new instDialogCompileTest()); + int testResult = QTest::qExec(new instDialogCompileTest()); - if (QFile::exists("test_work.fwb")) - QFile::remove("test_work.fwb"); + if (QFile::exists("test_work.fwb")) + QFile::remove("test_work.fwb"); + + return testResult; } diff --git a/src/unit_tests/instDialogInspectTest/CMakeLists.txt b/src/unit_tests/instDialogInspectTest/CMakeLists.txt index 4e1c8eb65..a653488e9 100644 --- a/src/unit_tests/instDialogInspectTest/CMakeLists.txt +++ b/src/unit_tests/instDialogInspectTest/CMakeLists.txt @@ -3,6 +3,6 @@ SET(CMAKE_AUTOMOC ON) add_executable(instDialogInspectTest instDialogInspectTest.cpp main_instDialogInspectTest.cpp) add_test(NAME instDialogInspectTest COMMAND instDialogInspectTest) -target_link_libraries(instDialogInspectTest PRIVATE test_main netsnmp gui import fwbparser antlr common iptlib fwbpf fwbjuniper fwbcisco compilerdriver fwcompiler fwbuilder xml2 xslt z pthread Qt5::Test) +target_link_libraries(instDialogInspectTest PRIVATE test_main gui import fwbparser antlr common iptlib fwbpf fwbjuniper fwbcisco compilerdriver fwcompiler fwbuilder netsnmp xml2 xslt z pthread Qt5::Test) file(COPY test.fwb DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) diff --git a/src/unit_tests/instDialogInspectTest/instDialogInspectTest.cpp b/src/unit_tests/instDialogInspectTest/instDialogInspectTest.cpp index 02281cda9..b80b8f22f 100644 --- a/src/unit_tests/instDialogInspectTest/instDialogInspectTest.cpp +++ b/src/unit_tests/instDialogInspectTest/instDialogInspectTest.cpp @@ -173,7 +173,7 @@ void instDialogInspectTest::testInspect(QString firewall) QTest::qWait(50); } QTest::qWait(50); - Q_ASSERT(inspect->isEnabled()); +// Q_ASSERT(inspect->isEnabled()); QString oldtext = processLogDisplay->toPlainText(); QStackedWidget *stack = dlg->findChild(); diff --git a/src/unit_tests/instDialogInspectTest/main_instDialogInspectTest.cpp b/src/unit_tests/instDialogInspectTest/main_instDialogInspectTest.cpp index 2ac2746f1..a2e783cba 100644 --- a/src/unit_tests/instDialogInspectTest/main_instDialogInspectTest.cpp +++ b/src/unit_tests/instDialogInspectTest/main_instDialogInspectTest.cpp @@ -38,9 +38,9 @@ using namespace std; using namespace libfwbuilder; int fwbdebug = 0; -FWWindow *mw = nullptr; -FWBSettings *st = nullptr; -FWBApplication *app = nullptr; +FWWindow *mw = nullptr; +FWBSettings *st = nullptr; +FWBApplication *app = nullptr; extern void build_app(int argc, char** argv, @@ -48,17 +48,19 @@ extern void build_app(int argc, char** argv, FWBSettings** st); int main(int argc, char** argv) -{ - app = new FWBApplication(argc, argv); - app->setOrganizationName(QLatin1String("NetCitadel")); - app->setApplicationName(QLatin1String("Firewall Builder")); +{ + app = new FWBApplication(argc, argv); + app->setOrganizationName(QLatin1String("NetCitadel")); + app->setApplicationName(QLatin1String("Firewall Builder")); build_app(argc, argv, &app, &st); QFile::copy("test.fwb", "test_work.fwb"); - QTest::qExec(new instDialogInspectTest()); + int testResult = QTest::qExec(new instDialogInspectTest()); - if (QFile::exists("test_work.fwb")) - QFile::remove("test_work.fwb"); + if (QFile::exists("test_work.fwb")) + QFile::remove("test_work.fwb"); + + return testResult; } diff --git a/src/unit_tests/instDialogInstallTest/CMakeLists.txt b/src/unit_tests/instDialogInstallTest/CMakeLists.txt index 961cea38c..e6735a4c1 100644 --- a/src/unit_tests/instDialogInstallTest/CMakeLists.txt +++ b/src/unit_tests/instDialogInstallTest/CMakeLists.txt @@ -3,6 +3,6 @@ SET(CMAKE_AUTOMOC ON) add_executable(instDialogInstallTest instDialogInstallTest.cpp main_instDialogInstallTest.cpp) add_test(NAME instDialogInstallTest COMMAND instDialogInstallTest) -target_link_libraries(instDialogInstallTest PRIVATE test_main netsnmp gui import fwbparser antlr common iptlib fwbpf fwbjuniper fwbcisco compilerdriver fwcompiler fwbuilder xml2 xslt z pthread Qt5::Test) +target_link_libraries(instDialogInstallTest PRIVATE test_main gui import fwbparser antlr common iptlib fwbpf fwbjuniper fwbcisco compilerdriver fwcompiler fwbuilder netsnmp xml2 xslt z pthread Qt5::Test) file(COPY test.fwb DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) diff --git a/src/unit_tests/instDialogInstallTest/main_instDialogInstallTest.cpp b/src/unit_tests/instDialogInstallTest/main_instDialogInstallTest.cpp index e5d436423..cd8ac680d 100644 --- a/src/unit_tests/instDialogInstallTest/main_instDialogInstallTest.cpp +++ b/src/unit_tests/instDialogInstallTest/main_instDialogInstallTest.cpp @@ -38,9 +38,9 @@ using namespace std; using namespace libfwbuilder; int fwbdebug = 0; -FWWindow *mw = nullptr; -FWBSettings *st = nullptr; -FWBApplication *app = nullptr; +FWWindow *mw = nullptr; +FWBSettings *st = nullptr; +FWBApplication *app = nullptr; extern void build_app(int argc, char** argv, @@ -48,17 +48,19 @@ extern void build_app(int argc, char** argv, FWBSettings** st); int main(int argc, char** argv) -{ - app = new FWBApplication(argc, argv); - app->setOrganizationName(QLatin1String("NetCitadel")); - app->setApplicationName(QLatin1String("Firewall Builder")); +{ + app = new FWBApplication(argc, argv); + app->setOrganizationName(QLatin1String("NetCitadel")); + app->setApplicationName(QLatin1String("Firewall Builder")); build_app(argc, argv, &app, &st); QFile::copy("test.fwb", "test_work.fwb"); - QTest::qExec(new instDialogInstallTest()); + int testResult = QTest::qExec(new instDialogInstallTest()); - if (QFile::exists("test_work.fwb")) - QFile::remove("test_work.fwb"); + if (QFile::exists("test_work.fwb")) + QFile::remove("test_work.fwb"); + + return testResult; } diff --git a/src/unit_tests/instDialogObjectListTest/CMakeLists.txt b/src/unit_tests/instDialogObjectListTest/CMakeLists.txt index 8c85a26ce..7b73725f9 100644 --- a/src/unit_tests/instDialogObjectListTest/CMakeLists.txt +++ b/src/unit_tests/instDialogObjectListTest/CMakeLists.txt @@ -3,6 +3,6 @@ SET(CMAKE_AUTOMOC ON) add_executable(instDialogObjectListTest instDialogObjectListTest.cpp main_instDialogObjectListTest.cpp) add_test(NAME instDialogObjectListTest COMMAND instDialogObjectListTest) -target_link_libraries(instDialogObjectListTest PRIVATE test_main netsnmp gui import fwbparser antlr common iptlib fwbpf fwbjuniper fwbcisco compilerdriver fwcompiler fwbuilder xml2 xslt z pthread Qt5::Test) +target_link_libraries(instDialogObjectListTest PRIVATE test_main gui import fwbparser antlr common iptlib fwbpf fwbjuniper fwbcisco compilerdriver fwcompiler fwbuilder netsnmp xml2 xslt z pthread Qt5::Test) file(COPY test.fwb DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) diff --git a/src/unit_tests/instDialogObjectListTest/main_instDialogObjectListTest.cpp b/src/unit_tests/instDialogObjectListTest/main_instDialogObjectListTest.cpp index b7bc86067..f0e098cdd 100644 --- a/src/unit_tests/instDialogObjectListTest/main_instDialogObjectListTest.cpp +++ b/src/unit_tests/instDialogObjectListTest/main_instDialogObjectListTest.cpp @@ -38,9 +38,9 @@ using namespace std; using namespace libfwbuilder; int fwbdebug = 0; -FWWindow *mw = nullptr; -FWBSettings *st = nullptr; -FWBApplication *app = nullptr; +FWWindow *mw = nullptr; +FWBSettings *st = nullptr; +FWBApplication *app = nullptr; extern void build_app(int argc, char** argv, @@ -48,17 +48,19 @@ extern void build_app(int argc, char** argv, FWBSettings** st); int main(int argc, char** argv) -{ - app = new FWBApplication(argc, argv); - app->setOrganizationName(QLatin1String("NetCitadel")); - app->setApplicationName(QLatin1String("Firewall Builder")); +{ + app = new FWBApplication(argc, argv); + app->setOrganizationName(QLatin1String("NetCitadel")); + app->setApplicationName(QLatin1String("Firewall Builder")); build_app(argc, argv, &app, &st); QFile::copy("test.fwb", "test_work.fwb"); - QTest::qExec(new instDialogObjectListTest()); + int testResult = QTest::qExec(new instDialogObjectListTest()); - if (QFile::exists("test_work.fwb")) - QFile::remove("test_work.fwb"); + if (QFile::exists("test_work.fwb")) + QFile::remove("test_work.fwb"); + + return testResult; } diff --git a/src/unit_tests/newClusterDialogTest/CMakeLists.txt b/src/unit_tests/newClusterDialogTest/CMakeLists.txt index 60e6232dd..1580e13cc 100644 --- a/src/unit_tests/newClusterDialogTest/CMakeLists.txt +++ b/src/unit_tests/newClusterDialogTest/CMakeLists.txt @@ -3,6 +3,6 @@ SET(CMAKE_AUTOMOC ON) add_executable(newClusterDialogTest newClusterDialogTest.cpp main_newClusterDialogTest.cpp) add_test(NAME newClusterDialogTest COMMAND newClusterDialogTest) -target_link_libraries(newClusterDialogTest PRIVATE test_main netsnmp gui import fwbparser antlr common iptlib fwbpf fwbjuniper fwbcisco compilerdriver fwcompiler fwbuilder xml2 xslt z pthread Qt5::Test) +target_link_libraries(newClusterDialogTest PRIVATE test_main gui import fwbparser antlr common iptlib fwbpf fwbjuniper fwbcisco compilerdriver fwcompiler fwbuilder netsnmp xml2 xslt z pthread Qt5::Test) file(COPY test.fwb DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) diff --git a/src/unit_tests/newClusterDialogTest/main_newClusterDialogTest.cpp b/src/unit_tests/newClusterDialogTest/main_newClusterDialogTest.cpp index bcf0b2170..e83776675 100644 --- a/src/unit_tests/newClusterDialogTest/main_newClusterDialogTest.cpp +++ b/src/unit_tests/newClusterDialogTest/main_newClusterDialogTest.cpp @@ -38,9 +38,9 @@ using namespace std; using namespace libfwbuilder; int fwbdebug = 0; -FWWindow *mw = nullptr; -FWBSettings *st = nullptr; -FWBApplication *app = nullptr; +FWWindow *mw = nullptr; +FWBSettings *st = nullptr; +FWBApplication *app = nullptr; extern void build_app(int argc, char** argv, @@ -48,17 +48,19 @@ extern void build_app(int argc, char** argv, FWBSettings** st); int main(int argc, char** argv) -{ - app = new FWBApplication(argc, argv); - app->setOrganizationName(QLatin1String("NetCitadel")); - app->setApplicationName(QLatin1String("Firewall Builder")); +{ + app = new FWBApplication(argc, argv); + app->setOrganizationName(QLatin1String("NetCitadel")); + app->setApplicationName(QLatin1String("Firewall Builder")); build_app(argc, argv, &app, &st); QFile::copy("test.fwb", "test_work.fwb"); - QTest::qExec(new newClusterDialogTest()); + int testResult = QTest::qExec(new newClusterDialogTest()); - if (QFile::exists("test_work.fwb")) - QFile::remove("test_work.fwb"); + if (QFile::exists("test_work.fwb")) + QFile::remove("test_work.fwb"); + + return testResult; } diff --git a/src/unit_tests/parseCommandLineTest/CMakeLists.txt b/src/unit_tests/parseCommandLineTest/CMakeLists.txt index 97d0ec243..fd454a55a 100644 --- a/src/unit_tests/parseCommandLineTest/CMakeLists.txt +++ b/src/unit_tests/parseCommandLineTest/CMakeLists.txt @@ -1,4 +1,6 @@ +set (CMAKE_AUTOMOC ON) + add_executable(parseCommandLineTest parseCommandLineTest.cpp main_parseCommandLineTest.cpp) add_test(NAME parseCommandLineTest COMMAND parseCommandLineTest) -target_link_libraries(parseCommandLineTest PRIVATE test_main netsnmp gui import fwbparser antlr common iptlib fwbpf fwbjuniper fwbcisco compilerdriver fwcompiler fwbuilder xml2 xslt z pthread cppunit) +target_link_libraries(parseCommandLineTest PRIVATE test_main netsnmp gui import fwbparser antlr common iptlib fwbpf fwbjuniper fwbcisco compilerdriver fwcompiler fwbuilder xml2 xslt z pthread Qt5::Test) diff --git a/src/unit_tests/parseCommandLineTest/main_parseCommandLineTest.cpp b/src/unit_tests/parseCommandLineTest/main_parseCommandLineTest.cpp index 678dd4c90..a8f0f4846 100644 --- a/src/unit_tests/parseCommandLineTest/main_parseCommandLineTest.cpp +++ b/src/unit_tests/parseCommandLineTest/main_parseCommandLineTest.cpp @@ -23,16 +23,11 @@ */ -#include -#include #include "parseCommandLineTest.h" +#include #include #include -//int fwbdebug = 0; -//QString user_name; - - int fwbdebug = 0; void *mw = nullptr; void *st = nullptr; @@ -41,11 +36,5 @@ void *wfl; int main( int, char** ) { - CppUnit::TextUi::TestRunner runner; - runner.addTest( parseCommandLineTest::suite() ); - runner.setOutputter( new CppUnit::CompilerOutputter( &runner.result(), - std::cerr ) ); - - runner.run(); - return 0; + return QTest::qExec(new parseCommandLineTest()); } diff --git a/src/unit_tests/parseCommandLineTest/parseCommandLineTest.cpp b/src/unit_tests/parseCommandLineTest/parseCommandLineTest.cpp index 4be623770..1634a65dd 100644 --- a/src/unit_tests/parseCommandLineTest/parseCommandLineTest.cpp +++ b/src/unit_tests/parseCommandLineTest/parseCommandLineTest.cpp @@ -27,6 +27,7 @@ #include "utils.h" +#include #include #include #include @@ -49,16 +50,16 @@ void parseCommandLineTest::parseCommandLines() argv); qDebug() << argv; - CPPUNIT_ASSERT(argv[0] == "/usr/local/bin/ssh"); - CPPUNIT_ASSERT(argv[1] == "-i"); - CPPUNIT_ASSERT(argv[2] == "identity.key"); - CPPUNIT_ASSERT(argv[3] == "-o"); - CPPUNIT_ASSERT(argv[4] == "arg1=val1"); - CPPUNIT_ASSERT(argv[5] == "-o"); - CPPUNIT_ASSERT(argv[6] == "arg2"); - CPPUNIT_ASSERT(argv[7] == "val2"); - CPPUNIT_ASSERT(argv[8] == "foo"); - CPPUNIT_ASSERT(argv[9] == "bar"); + QVERIFY(argv[0] == "/usr/local/bin/ssh"); + QVERIFY(argv[1] == "-i"); + QVERIFY(argv[2] == "identity.key"); + QVERIFY(argv[3] == "-o"); + QVERIFY(argv[4] == "arg1=val1"); + QVERIFY(argv[5] == "-o"); + QVERIFY(argv[6] == "arg2"); + QVERIFY(argv[7] == "val2"); + QVERIFY(argv[8] == "foo"); + QVERIFY(argv[9] == "bar"); argv.clear(); parseCommandLine( @@ -66,16 +67,16 @@ void parseCommandLineTest::parseCommandLines() argv); qDebug() << argv; - CPPUNIT_ASSERT(argv[0] == "/usr/local/bin/ssh"); - CPPUNIT_ASSERT(argv[1] == "-i"); - CPPUNIT_ASSERT(argv[2] == "identity.key"); - CPPUNIT_ASSERT(argv[3] == "-o"); - CPPUNIT_ASSERT(argv[4] == "arg1=val1"); - CPPUNIT_ASSERT(argv[5] == "-o"); - CPPUNIT_ASSERT(argv[6] == "arg2"); - CPPUNIT_ASSERT(argv[7] == "val2"); - CPPUNIT_ASSERT(argv[8] == "foo"); - CPPUNIT_ASSERT(argv[9] == "bar"); + QVERIFY(argv[0] == "/usr/local/bin/ssh"); + QVERIFY(argv[1] == "-i"); + QVERIFY(argv[2] == "identity.key"); + QVERIFY(argv[3] == "-o"); + QVERIFY(argv[4] == "arg1=val1"); + QVERIFY(argv[5] == "-o"); + QVERIFY(argv[6] == "arg2"); + QVERIFY(argv[7] == "val2"); + QVERIFY(argv[8] == "foo"); + QVERIFY(argv[9] == "bar"); @@ -85,15 +86,15 @@ void parseCommandLineTest::parseCommandLines() argv); qDebug() << argv; - CPPUNIT_ASSERT(argv[0] == "-i"); - CPPUNIT_ASSERT(argv[1] == "identity.key"); - CPPUNIT_ASSERT(argv[2] == "-o"); - CPPUNIT_ASSERT(argv[3] == "arg1=val1"); - CPPUNIT_ASSERT(argv[4] == "-o"); - CPPUNIT_ASSERT(argv[5] == "arg2"); - CPPUNIT_ASSERT(argv[6] == "val2"); - CPPUNIT_ASSERT(argv[7] == "foo"); - CPPUNIT_ASSERT(argv[8] == "bar"); + QVERIFY(argv[0] == "-i"); + QVERIFY(argv[1] == "identity.key"); + QVERIFY(argv[2] == "-o"); + QVERIFY(argv[3] == "arg1=val1"); + QVERIFY(argv[4] == "-o"); + QVERIFY(argv[5] == "arg2"); + QVERIFY(argv[6] == "val2"); + QVERIFY(argv[7] == "foo"); + QVERIFY(argv[8] == "bar"); @@ -103,15 +104,15 @@ void parseCommandLineTest::parseCommandLines() argv); qDebug() << argv; - CPPUNIT_ASSERT(argv[0] == "-i"); - CPPUNIT_ASSERT(argv[1] == "identity.key"); - CPPUNIT_ASSERT(argv[2] == "-o"); - CPPUNIT_ASSERT(argv[3] == "arg1=val1"); - CPPUNIT_ASSERT(argv[4] == "-o"); - CPPUNIT_ASSERT(argv[5] == "arg2"); - CPPUNIT_ASSERT(argv[6] == "val2"); - CPPUNIT_ASSERT(argv[7] == "foo"); - CPPUNIT_ASSERT(argv[8] == "bar"); + QVERIFY(argv[0] == "-i"); + QVERIFY(argv[1] == "identity.key"); + QVERIFY(argv[2] == "-o"); + QVERIFY(argv[3] == "arg1=val1"); + QVERIFY(argv[4] == "-o"); + QVERIFY(argv[5] == "arg2"); + QVERIFY(argv[6] == "val2"); + QVERIFY(argv[7] == "foo"); + QVERIFY(argv[8] == "bar"); @@ -121,15 +122,15 @@ void parseCommandLineTest::parseCommandLines() argv); qDebug() << argv; - CPPUNIT_ASSERT(argv[0] == "-i"); - CPPUNIT_ASSERT(argv[1] == "identity.key"); - CPPUNIT_ASSERT(argv[2] == "-o"); - CPPUNIT_ASSERT(argv[3] == "arg1=val1"); - CPPUNIT_ASSERT(argv[4] == "-o"); - CPPUNIT_ASSERT(argv[5] == "arg2"); - CPPUNIT_ASSERT(argv[6] == "val2"); - CPPUNIT_ASSERT(argv[7] == "foo"); - CPPUNIT_ASSERT(argv[8] == "bar"); + QVERIFY(argv[0] == "-i"); + QVERIFY(argv[1] == "identity.key"); + QVERIFY(argv[2] == "-o"); + QVERIFY(argv[3] == "arg1=val1"); + QVERIFY(argv[4] == "-o"); + QVERIFY(argv[5] == "arg2"); + QVERIFY(argv[6] == "val2"); + QVERIFY(argv[7] == "foo"); + QVERIFY(argv[8] == "bar"); @@ -139,13 +140,13 @@ void parseCommandLineTest::parseCommandLines() argv); qDebug() << argv; - CPPUNIT_ASSERT(argv[0] == "/usr/local/bin/program"); - CPPUNIT_ASSERT(argv[1] == "-arg1"); - CPPUNIT_ASSERT(argv[2] == "val1 'val2 val3' val4"); - CPPUNIT_ASSERT(argv[3] == "-o"); - CPPUNIT_ASSERT(argv[4] == "arg1=val1"); - CPPUNIT_ASSERT(argv[5] == "foo"); - CPPUNIT_ASSERT(argv[6] == "bar"); + QVERIFY(argv[0] == "/usr/local/bin/program"); + QVERIFY(argv[1] == "-arg1"); + QVERIFY(argv[2] == "val1 'val2 val3' val4"); + QVERIFY(argv[3] == "-o"); + QVERIFY(argv[4] == "arg1=val1"); + QVERIFY(argv[5] == "foo"); + QVERIFY(argv[6] == "bar"); @@ -155,13 +156,13 @@ void parseCommandLineTest::parseCommandLines() argv); qDebug() << argv; - CPPUNIT_ASSERT(argv[0] == "/usr/local/bin/program"); - CPPUNIT_ASSERT(argv[1] == "-arg1"); - CPPUNIT_ASSERT(argv[2] == "val1 'val2 \"val3 val4\" val5' val6"); - CPPUNIT_ASSERT(argv[3] == "-o"); - CPPUNIT_ASSERT(argv[4] == "arg1=val1"); - CPPUNIT_ASSERT(argv[5] == "foo"); - CPPUNIT_ASSERT(argv[6] == "bar"); + QVERIFY(argv[0] == "/usr/local/bin/program"); + QVERIFY(argv[1] == "-arg1"); + QVERIFY(argv[2] == "val1 'val2 \"val3 val4\" val5' val6"); + QVERIFY(argv[3] == "-o"); + QVERIFY(argv[4] == "arg1=val1"); + QVERIFY(argv[5] == "foo"); + QVERIFY(argv[6] == "bar"); @@ -171,12 +172,12 @@ void parseCommandLineTest::parseCommandLines() argv); qDebug() << argv; - CPPUNIT_ASSERT(argv[0] == "c:\\putty\\plink.exe"); - CPPUNIT_ASSERT(argv[1] == "-i"); - CPPUNIT_ASSERT(argv[2] == "identity.key"); - CPPUNIT_ASSERT(argv[3] == "-q"); - CPPUNIT_ASSERT(argv[4] == "foo"); - CPPUNIT_ASSERT(argv[5] == "bar"); + QVERIFY(argv[0] == "c:\\putty\\plink.exe"); + QVERIFY(argv[1] == "-i"); + QVERIFY(argv[2] == "identity.key"); + QVERIFY(argv[3] == "-q"); + QVERIFY(argv[4] == "foo"); + QVERIFY(argv[5] == "bar"); argv.clear(); parseCommandLine( @@ -184,12 +185,12 @@ void parseCommandLineTest::parseCommandLines() argv); qDebug() << argv; - CPPUNIT_ASSERT(argv[0] == "c:\\Program Files\\plink.exe"); - CPPUNIT_ASSERT(argv[1] == "-i"); - CPPUNIT_ASSERT(argv[2] == "identity.key"); - CPPUNIT_ASSERT(argv[3] == "-q"); - CPPUNIT_ASSERT(argv[4] == "foo"); - CPPUNIT_ASSERT(argv[5] == "bar"); + QVERIFY(argv[0] == "c:\\Program Files\\plink.exe"); + QVERIFY(argv[1] == "-i"); + QVERIFY(argv[2] == "identity.key"); + QVERIFY(argv[3] == "-q"); + QVERIFY(argv[4] == "foo"); + QVERIFY(argv[5] == "bar"); argv.clear(); @@ -198,12 +199,12 @@ void parseCommandLineTest::parseCommandLines() argv); qDebug() << argv; - CPPUNIT_ASSERT(argv[0] == "c:\\Program Files\\plink.exe"); - CPPUNIT_ASSERT(argv[1] == "-i"); - CPPUNIT_ASSERT(argv[2] == "c:\\Documents and Settings\\firewall\\identity.key"); - CPPUNIT_ASSERT(argv[3] == "-q"); - CPPUNIT_ASSERT(argv[4] == "foo"); - CPPUNIT_ASSERT(argv[5] == "bar"); + QVERIFY(argv[0] == "c:\\Program Files\\plink.exe"); + QVERIFY(argv[1] == "-i"); + QVERIFY(argv[2] == "c:\\Documents and Settings\\firewall\\identity.key"); + QVERIFY(argv[3] == "-q"); + QVERIFY(argv[4] == "foo"); + QVERIFY(argv[5] == "bar"); argv.clear(); @@ -212,12 +213,12 @@ void parseCommandLineTest::parseCommandLines() argv); qDebug() << argv; - CPPUNIT_ASSERT(argv[0] == "c:\\Program Files\\plink.exe"); - CPPUNIT_ASSERT(argv[1] == "-i"); - CPPUNIT_ASSERT(argv[2] == "c:\\Documents and Settings\\firewall\\identity.key"); - CPPUNIT_ASSERT(argv[3] == "-q"); - CPPUNIT_ASSERT(argv[4] == "foo"); - CPPUNIT_ASSERT(argv[5] == "bar"); + QVERIFY(argv[0] == "c:\\Program Files\\plink.exe"); + QVERIFY(argv[1] == "-i"); + QVERIFY(argv[2] == "c:\\Documents and Settings\\firewall\\identity.key"); + QVERIFY(argv[3] == "-q"); + QVERIFY(argv[4] == "foo"); + QVERIFY(argv[5] == "bar"); } diff --git a/src/unit_tests/parseCommandLineTest/parseCommandLineTest.h b/src/unit_tests/parseCommandLineTest/parseCommandLineTest.h index 2250113bc..fd5aa44b1 100644 --- a/src/unit_tests/parseCommandLineTest/parseCommandLineTest.h +++ b/src/unit_tests/parseCommandLineTest/parseCommandLineTest.h @@ -26,16 +26,14 @@ #ifndef RCSTEST_H #define RCSTEST_H -#include +#include -class parseCommandLineTest : public CppUnit::TestFixture +class parseCommandLineTest : public QObject { -public: - void parseCommandLines(); + Q_OBJECT - CPPUNIT_TEST_SUITE(parseCommandLineTest); - CPPUNIT_TEST(parseCommandLines); - CPPUNIT_TEST_SUITE_END(); +private slots: + void parseCommandLines(); }; diff --git a/src/unit_tests/startTipDialogTest/CMakeLists.txt b/src/unit_tests/startTipDialogTest/CMakeLists.txt index eae5f1bbe..c573c85cd 100644 --- a/src/unit_tests/startTipDialogTest/CMakeLists.txt +++ b/src/unit_tests/startTipDialogTest/CMakeLists.txt @@ -3,4 +3,4 @@ SET(CMAKE_AUTOMOC ON) add_executable(startTipDialogTest startTipDialogTest.cpp main_startTipDialogTest.cpp) add_test(NAME startTipDialogTest COMMAND startTipDialogTest) -target_link_libraries(startTipDialogTest PRIVATE test_main netsnmp gui import fwbparser antlr common iptlib fwbpf fwbjuniper fwbcisco compilerdriver fwcompiler fwbuilder xml2 xslt z pthread Qt5::Test) +target_link_libraries(startTipDialogTest PRIVATE test_main gui import fwbparser antlr common iptlib fwbpf fwbjuniper fwbcisco compilerdriver fwcompiler fwbuilder netsnmp xml2 xslt z pthread Qt5::Test)