diff --git a/CMakeLists.txt b/CMakeLists.txt index b4cc506d6..597d49324 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -200,7 +200,6 @@ option(POCO_UNBUNDLED "Set to OFF|ON (default is OFF) to control linking dependencies as external" OFF) if(ENABLE_TESTS) - option(ENABLE_LONG_RUNNING_TESTS "Enable long running test" ON) include(CTest) enable_testing() message(STATUS "Building with unittests & samples") diff --git a/CppUnit/include/CppUnit/Test.h b/CppUnit/include/CppUnit/Test.h index 2b5ab0d0e..1c69ab122 100644 --- a/CppUnit/include/CppUnit/Test.h +++ b/CppUnit/include/CppUnit/Test.h @@ -25,11 +25,19 @@ class TestResult; */ class CppUnit_API Test { +public: + enum Type { + Suite, // Only set on CppUnit::TestSuite + Normal, // Default TestCase always run + Long // Such TestCase will only be run if the `-long` command line argument is set + }; + public: virtual ~Test() = 0; virtual void run(TestResult* result) = 0; - virtual int countTestCases() = 0; - virtual std::string toString() = 0; + virtual int countTestCases() const = 0; + virtual std::string toString() const = 0; + virtual Test::Type getType() const = 0; void addSetup(const std::vector& setup); const std::vector& setup() const; @@ -51,19 +59,26 @@ inline void Test::run(TestResult *result) // Counts the number of test cases that will be run by this test. -inline int Test::countTestCases() +inline int Test::countTestCases() const { return 0; } // Returns the name of the test instance. -inline std::string Test::toString() +inline std::string Test::toString() const { return ""; } +// Returns the type of the test, see Test::Type +inline Test::Type Test::getType() const +{ + return Test::Normal; +} + + inline void Test::addSetup(const std::vector& setup) { _setup = setup; diff --git a/CppUnit/include/CppUnit/TestCaller.h b/CppUnit/include/CppUnit/TestCaller.h index 3d9c732cf..5b8001dec 100644 --- a/CppUnit/include/CppUnit/TestCaller.h +++ b/CppUnit/include/CppUnit/TestCaller.h @@ -54,8 +54,8 @@ class TestCaller: public TestCase typedef void (Fixture::*TestMethod)(); public: - TestCaller(const std::string& name, TestMethod test): - TestCase(name), + TestCaller(const std::string& name, TestMethod test, Test::Type testType = Test::Type::Normal): + TestCase(name, testType), _test(test), _fixture(new Fixture(name)) { @@ -95,7 +95,13 @@ private: #define CppUnit_addTest(suite, cls, mth) \ suite->addTest(new CppUnit::TestCaller(#mth, &cls::mth)) +#define CppUnit_addLongTest(suite, cls, mth) \ + suite->addTest(new CppUnit::TestCaller(#mth, &cls::mth, CppUnit::Test::Long)) + #define CppUnit_addQualifiedTest(suite, cls, mth) \ suite->addTest(new CppUnit::TestCaller(#cls"::"#mth, &cls::mth)) +#define CppUnit_addLongQualifiedTest(suite, cls, mth) \ + suite->addTest(new CppUnit::TestCaller(#cls"::"#mth, &cls::mth, CppUnit::Test::Long)) + #endif // CppUnit_TestCaller_INCLUDED diff --git a/CppUnit/include/CppUnit/TestCase.h b/CppUnit/include/CppUnit/TestCase.h index d01cadb5b..6b7930392 100644 --- a/CppUnit/include/CppUnit/TestCase.h +++ b/CppUnit/include/CppUnit/TestCase.h @@ -87,14 +87,16 @@ class CppUnit_API TestCase: public Test REFERENCEOBJECT (TestCase) public: - TestCase(const std::string& Name); + TestCase(const std::string& Name, Test::Type testType = Test::Normal); ~TestCase(); virtual void run(TestResult* result); virtual TestResult* run(); - virtual int countTestCases(); + virtual int countTestCases() const; + virtual std::string toString() const; + virtual Test::Type getType() const; + void setType(Test::Type testType); const std::string& name() const; - std::string toString(); virtual void setUp(); virtual void setUp(const std::vector& setup); @@ -169,12 +171,15 @@ protected: private: const std::string _name; + Test::Type _type; }; // Constructs a test case -inline TestCase::TestCase(const std::string& name): _name (name) +inline TestCase::TestCase(const std::string& name, Test::Type testType) + : _name (name) { + setType(testType); } @@ -185,7 +190,7 @@ inline TestCase::~TestCase() // Returns a count of all the tests executed -inline int TestCase::countTestCases() +inline int TestCase::countTestCases() const { return 1; } @@ -217,12 +222,23 @@ inline void TestCase::tearDown() // Returns the name of the test case instance -inline std::string TestCase::toString() +inline std::string TestCase::toString() const { const std::type_info& thisClass = typeid(*this); return std::string(thisClass.name()) + "." + name(); } +// Returns the type of the test, see Test::Type +inline Test::Type TestCase::getType() const +{ + return _type; +} + +// Set the type of the test, see Test::Type +inline void TestCase::setType(Test::Type testType) +{ + _type = testType; +} // A set of macros which allow us to get the line number // and file name at the point of an error. diff --git a/CppUnit/include/CppUnit/TestRunner.h b/CppUnit/include/CppUnit/TestRunner.h index 5bf50ee48..20131ba77 100644 --- a/CppUnit/include/CppUnit/TestRunner.h +++ b/CppUnit/include/CppUnit/TestRunner.h @@ -33,7 +33,7 @@ class Test; * * Here is the synopsis: * - * TestRunner [-all] [-print] [-wait] ExampleTestCase + * TestRunner [-all] [-long] [-print] [-wait] ExampleTestCase * */ class CppUnit_API TestRunner @@ -54,6 +54,7 @@ protected: void printBanner(); void print(const std::string& name, Test* pTest, int indent); Test* find(const std::string& name, Test* pTest, const std::string& testName); + int collectAllTestCases(Test* pTest, std::vector& tests); private: std::ostream& _ostr; diff --git a/CppUnit/include/CppUnit/TestSuite.h b/CppUnit/include/CppUnit/TestSuite.h index 65bc2a3a9..7d3da3d61 100644 --- a/CppUnit/include/CppUnit/TestSuite.h +++ b/CppUnit/include/CppUnit/TestSuite.h @@ -42,9 +42,10 @@ public: ~TestSuite(); void run(TestResult* result); - int countTestCases(); + int countTestCases() const; void addTest(Test* test); - std::string toString(); + std::string toString() const; + Test::Type getType() const; virtual void deleteContents(); @@ -77,11 +78,16 @@ inline void TestSuite::addTest(Test* test) // Returns a std::string representation of the test suite. -inline std::string TestSuite::toString() +inline std::string TestSuite::toString() const { return "suite " + _name; } +// Returns the type of the test, see Test::Type +inline Test::Type TestSuite::getType() const +{ + return Test::Suite; +} // Returns all tests inline const std::vector TestSuite::tests() const diff --git a/CppUnit/src/TestRunner.cpp b/CppUnit/src/TestRunner.cpp index 8605dad7d..368f2065d 100644 --- a/CppUnit/src/TestRunner.cpp +++ b/CppUnit/src/TestRunner.cpp @@ -35,7 +35,7 @@ TestRunner::~TestRunner() void TestRunner::printBanner() { _ostr - << "Usage: driver [-all] [-print] [-wait] [name] ..." << std::endl + << "Usage: driver [-all] [-long] [-print] [-wait] [name] ..." << std::endl << " where name is the name of a test case class" << std::endl; } @@ -48,8 +48,11 @@ bool TestRunner::run(const std::vector& args) bool all = false; bool wait = false; bool printed = false; + bool long_running = false; + std::vector setup; + std::vector tests; for (int i = 1; i < args.size(); i++) { const std::string& arg = args[i]; @@ -63,6 +66,11 @@ bool TestRunner::run(const std::vector& args) all = true; continue; } + else if (arg == "-long") + { + long_running = true; + continue; + } else if (arg == "-print") { for (Mappings::iterator it = _mappings.begin(); it != _mappings.end(); ++it) @@ -96,11 +104,8 @@ bool TestRunner::run(const std::vector& args) } if (testToRun) { - if (setup.size() > 0) - testToRun->addSetup(setup); - if (!run(testToRun)) success = false; + collectAllTestCases(testToRun, tests); } - numberOfTests++; if (!testToRun) { @@ -112,15 +117,24 @@ bool TestRunner::run(const std::vector& args) if (all) { + tests.clear(); for (Mappings::iterator it = _mappings.begin(); it != _mappings.end(); ++it) { - if (setup.size() > 0) - it->second->addSetup(setup); - if (!run(it->second)) success = false; - numberOfTests++; + collectAllTestCases(it->second, tests); } } + for (std::vector::const_iterator it = tests.begin(); it != tests.end(); ++it) + { + Test* testToRun = *it; + if(testToRun->getType() == Test::Long && !long_running) + continue; + if (setup.size() > 0) + testToRun->addSetup(setup); + if (!run(testToRun)) success = false; + numberOfTests++; + } + if (numberOfTests == 0 && !printed) { printBanner(); @@ -194,4 +208,29 @@ Test* TestRunner::find(const std::string& name, Test* pTest, const std::string& } +int TestRunner::collectAllTestCases(Test* pTest, std::vector& testcases) +{ + int added = 0; + if (pTest->getType() == Test::Suite) + { + TestSuite* pSuite = dynamic_cast(pTest); + + if (pSuite) + { + const std::vector& tests = pSuite->tests(); + for (std::vector::const_iterator it = tests.begin(); it != tests.end(); ++it) + { + added += collectAllTestCases(*it, testcases); + } + } + } + else + { + testcases.push_back(pTest); + added = 1; + } + return added; +} + + } // namespace CppUnit diff --git a/CppUnit/src/TestSuite.cpp b/CppUnit/src/TestSuite.cpp index 3284f06ee..b89c47b4b 100644 --- a/CppUnit/src/TestSuite.cpp +++ b/CppUnit/src/TestSuite.cpp @@ -35,11 +35,11 @@ void TestSuite::run(TestResult *result) // Counts the number of test cases that will be run by this test. -int TestSuite::countTestCases() +int TestSuite::countTestCases() const { int count = 0; - for (std::vector::iterator it = _tests.begin (); it != _tests.end (); ++it) + for (std::vector::const_iterator it = _tests.begin (); it != _tests.end (); ++it) count += (*it)->countTestCases(); return count; diff --git a/Foundation/samples/StringTokenizer/CMakeLists.txt b/Foundation/samples/StringTokenizer/CMakeLists.txt index f0905ecf5..e66c23e4b 100644 --- a/Foundation/samples/StringTokenizer/CMakeLists.txt +++ b/Foundation/samples/StringTokenizer/CMakeLists.txt @@ -1,2 +1,2 @@ add_executable(StringTokenizer src/StringTokenizer.cpp) -target_link_libraries(StringTokenizer PUBLIC Poco::JSON Poco::XML Poco::Foundation) +target_link_libraries(StringTokenizer PUBLIC Poco::Foundation) diff --git a/Foundation/samples/URI/CMakeLists.txt b/Foundation/samples/URI/CMakeLists.txt index 05aef6df4..e31d42ff0 100644 --- a/Foundation/samples/URI/CMakeLists.txt +++ b/Foundation/samples/URI/CMakeLists.txt @@ -1,2 +1,2 @@ add_executable(URI src/URI.cpp) -target_link_libraries(URI PUBLIC Poco::JSON Poco::XML Poco::Foundation ) +target_link_libraries(URI PUBLIC Poco::Foundation ) diff --git a/Foundation/testsuite/CMakeLists.txt b/Foundation/testsuite/CMakeLists.txt index c7c56ac25..368ea82d6 100644 --- a/Foundation/testsuite/CMakeLists.txt +++ b/Foundation/testsuite/CMakeLists.txt @@ -41,10 +41,6 @@ if(UNIX AND NOT ANDROID) target_link_libraries(Foundation-testrunner PUBLIC pthread) endif(UNIX AND NOT ANDROID) -if(ENABLE_LONG_RUNNING_TESTS) - target_compile_definitions(Foundation-testrunner PRIVATE ENABLE_LONG_RUNNING_TESTS) -endif(ENABLE_LONG_RUNNING_TESTS) - # TestApp if(WINCE) add_executable( TestApp src/TestApp_WINCE.cpp ) diff --git a/Foundation/testsuite/src/PBKDF2EngineTest.cpp b/Foundation/testsuite/src/PBKDF2EngineTest.cpp index f05529b62..12848ec73 100644 --- a/Foundation/testsuite/src/PBKDF2EngineTest.cpp +++ b/Foundation/testsuite/src/PBKDF2EngineTest.cpp @@ -74,14 +74,12 @@ void PBKDF2EngineTest::testPBKDF2c() void PBKDF2EngineTest::testPBKDF2d() { // test vector 4 from RFC 6070 -#if defined(ENABLE_LONG_RUNNING_TESTS) std::string p("password"); std::string s("salt"); PBKDF2Engine > pbkdf2(s, 16777216, 20); pbkdf2.update(p); std::string dk = DigestEngine::digestToHex(pbkdf2.digest()); assertTrue (dk == "eefe3d61cd4da4e4e9945b3d6ba2158c2634e984"); -#endif // defined(ENABLE_LONG_RUNNING_TESTS) } @@ -128,7 +126,7 @@ CppUnit::Test* PBKDF2EngineTest::suite() CppUnit_addTest(pSuite, PBKDF2EngineTest, testPBKDF2a); CppUnit_addTest(pSuite, PBKDF2EngineTest, testPBKDF2b); CppUnit_addTest(pSuite, PBKDF2EngineTest, testPBKDF2c); - CppUnit_addTest(pSuite, PBKDF2EngineTest, testPBKDF2d); + CppUnit_addLongTest(pSuite, PBKDF2EngineTest, testPBKDF2d); CppUnit_addTest(pSuite, PBKDF2EngineTest, testPBKDF2e); CppUnit_addTest(pSuite, PBKDF2EngineTest, testPBKDF2f); diff --git a/Foundation/testsuite/src/RWLockTest.cpp b/Foundation/testsuite/src/RWLockTest.cpp index 9efe26317..d492473d6 100644 --- a/Foundation/testsuite/src/RWLockTest.cpp +++ b/Foundation/testsuite/src/RWLockTest.cpp @@ -131,7 +131,6 @@ RWLockTest::~RWLockTest() void RWLockTest::testLock() { -#if defined(ENABLE_LONG_RUNNING_TESTS) RWLock lock; int counter = 0; RWLockRunnable r1(lock, counter); @@ -160,13 +159,11 @@ void RWLockTest::testLock() assertTrue (r3.ok()); assertTrue (r4.ok()); assertTrue (r5.ok()); -#endif // defined(ENABLE_LONG_RUNNING_TESTS) } void RWLockTest::testTryLock() { -#if defined(ENABLE_LONG_RUNNING_TESTS) RWLock lock; int counter = 0; RWTryLockRunnable r1(lock, counter); @@ -195,7 +192,6 @@ void RWLockTest::testTryLock() assertTrue (r3.ok()); assertTrue (r4.ok()); assertTrue (r5.ok()); -#endif // defined(ENABLE_LONG_RUNNING_TESTS) } @@ -213,8 +209,8 @@ CppUnit::Test* RWLockTest::suite() { CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("RWLockTest"); - CppUnit_addTest(pSuite, RWLockTest, testLock); - CppUnit_addTest(pSuite, RWLockTest, testTryLock); + CppUnit_addLongTest(pSuite, RWLockTest, testLock); + CppUnit_addLongTest(pSuite, RWLockTest, testTryLock); return pSuite; }