From b56823a6e79c2342af5dbd70f84f53ef0a2c09e7 Mon Sep 17 00:00:00 2001 From: Micke Prag Date: Fri, 17 May 2013 11:24:27 +0200 Subject: [PATCH] Some compilers seems to optimize away our tests. Compiling them statically and force initiating them seems to do the trick. --- telldus-core/tests/common/CMakeLists.txt | 2 +- telldus-core/tests/common/CommonTests.h | 11 +++++ telldus-core/tests/common/StringsTest.cpp | 2 - telldus-core/tests/cppunit.cpp | 47 +++++++++++-------- telldus-core/tests/service/CMakeLists.txt | 2 +- .../service/ProtocolEverflourishTest.cpp | 2 - .../tests/service/ProtocolNexaTest.cpp | 2 - .../tests/service/ProtocolOregonTest.cpp | 2 - .../tests/service/ProtocolSartanoTest.cpp | 2 - .../tests/service/ProtocolX10Test.cpp | 2 - telldus-core/tests/service/ServiceTests.h | 19 ++++++++ 11 files changed, 59 insertions(+), 34 deletions(-) create mode 100644 telldus-core/tests/common/CommonTests.h create mode 100644 telldus-core/tests/service/ServiceTests.h diff --git a/telldus-core/tests/common/CMakeLists.txt b/telldus-core/tests/common/CMakeLists.txt index ae52a231..eec397fb 100644 --- a/telldus-core/tests/common/CMakeLists.txt +++ b/telldus-core/tests/common/CMakeLists.txt @@ -2,7 +2,7 @@ FILE(GLOB SRCS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "*Test.cpp" ) INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/common) -ADD_LIBRARY(TelldusCommonTests SHARED ${SRCS} ) +ADD_LIBRARY(TelldusCommonTests STATIC ${SRCS} ) TARGET_LINK_LIBRARIES( TelldusCommonTests TelldusCommon ${CPPUNIT} ) ADD_DEPENDENCIES( TelldusCommonTests TelldusCommon ) diff --git a/telldus-core/tests/common/CommonTests.h b/telldus-core/tests/common/CommonTests.h new file mode 100644 index 00000000..805b51ee --- /dev/null +++ b/telldus-core/tests/common/CommonTests.h @@ -0,0 +1,11 @@ +#ifndef COMMONTESTS_H +#define COMMONTESTS_H + +#include "StringsTest.h" + +namespace CommonTests { + inline void setup() { + CPPUNIT_TEST_SUITE_REGISTRATION (StringsTest); + } +} +#endif // COMMONTESTS_H diff --git a/telldus-core/tests/common/StringsTest.cpp b/telldus-core/tests/common/StringsTest.cpp index 790368a1..251d4a39 100644 --- a/telldus-core/tests/common/StringsTest.cpp +++ b/telldus-core/tests/common/StringsTest.cpp @@ -1,8 +1,6 @@ #include "StringsTest.h" #include "Strings.h" -CPPUNIT_TEST_SUITE_REGISTRATION (StringsTest); - void StringsTest :: setUp (void) { } diff --git a/telldus-core/tests/cppunit.cpp b/telldus-core/tests/cppunit.cpp index 65f0739e..8a05906f 100644 --- a/telldus-core/tests/cppunit.cpp +++ b/telldus-core/tests/cppunit.cpp @@ -8,32 +8,39 @@ #include +#include "common/CommonTests.h" +#include "service/ServiceTests.h" + int main (int argc, char* argv[]) { - // informs test-listener about testresults - CPPUNIT_NS :: TestResult testresult; + // Setup our tests + CommonTests::setup(); + ServiceTests::setup(); - // register listener for collecting the test-results - CPPUNIT_NS :: TestResultCollector collectedresults; - testresult.addListener (&collectedresults); + // informs test-listener about testresults + CPPUNIT_NS :: TestResult testresult; - // register listener for per-test progress output - CPPUNIT_NS :: BriefTestProgressListener progress; - testresult.addListener (&progress); + // register listener for collecting the test-results + CPPUNIT_NS :: TestResultCollector collectedresults; + testresult.addListener (&collectedresults); - // insert test-suite at test-runner by registry - CPPUNIT_NS :: TestRunner testrunner; - testrunner.addTest (CPPUNIT_NS :: TestFactoryRegistry :: getRegistry ().makeTest ()); - testrunner.run (testresult); + // register listener for per-test progress output + CPPUNIT_NS :: BriefTestProgressListener progress; + testresult.addListener (&progress); - // output results in compiler-format - CPPUNIT_NS :: CompilerOutputter compileroutputter (&collectedresults, std::cerr); - compileroutputter.write (); + // insert test-suite at test-runner by registry + CPPUNIT_NS :: TestRunner testrunner; + testrunner.addTest (CPPUNIT_NS :: TestFactoryRegistry :: getRegistry ().makeTest ()); + testrunner.run (testresult); - std::ofstream xmlFileOut("cpptestresults.xml"); - CPPUNIT_NS :: XmlOutputter xmlOut(&collectedresults, xmlFileOut); - xmlOut.write(); + // output results in compiler-format + CPPUNIT_NS :: CompilerOutputter compileroutputter (&collectedresults, std::cerr); + compileroutputter.write (); - // return 0 if tests were successful - return collectedresults.wasSuccessful () ? 0 : 1; + std::ofstream xmlFileOut("cpptestresults.xml"); + CPPUNIT_NS :: XmlOutputter xmlOut(&collectedresults, xmlFileOut); + xmlOut.write(); + + // return 0 if tests were successful + return collectedresults.wasSuccessful () ? 0 : 1; } diff --git a/telldus-core/tests/service/CMakeLists.txt b/telldus-core/tests/service/CMakeLists.txt index d43357a0..057f609c 100644 --- a/telldus-core/tests/service/CMakeLists.txt +++ b/telldus-core/tests/service/CMakeLists.txt @@ -2,7 +2,7 @@ FILE(GLOB SRCS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "*Test.cpp" ) INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}) -ADD_LIBRARY(TelldusServiceTests SHARED ${SRCS} ) +ADD_LIBRARY(TelldusServiceTests STATIC ${SRCS} ) TARGET_LINK_LIBRARIES( TelldusServiceTests TelldusServiceStatic ${CPPUNIT} ) ADD_DEPENDENCIES( TelldusServiceTests ${telldus-service_TARGET} ) diff --git a/telldus-core/tests/service/ProtocolEverflourishTest.cpp b/telldus-core/tests/service/ProtocolEverflourishTest.cpp index cb9749d6..2d9ec66d 100644 --- a/telldus-core/tests/service/ProtocolEverflourishTest.cpp +++ b/telldus-core/tests/service/ProtocolEverflourishTest.cpp @@ -1,8 +1,6 @@ #include "ProtocolEverflourishTest.h" #include "service/ProtocolEverflourish.h" -CPPUNIT_TEST_SUITE_REGISTRATION (ProtocolEverflourishTest); - class ProtocolEverflourishTest::PrivateData { public: ProtocolEverflourish *protocol; diff --git a/telldus-core/tests/service/ProtocolNexaTest.cpp b/telldus-core/tests/service/ProtocolNexaTest.cpp index f65c0381..e2c9f8ec 100644 --- a/telldus-core/tests/service/ProtocolNexaTest.cpp +++ b/telldus-core/tests/service/ProtocolNexaTest.cpp @@ -1,8 +1,6 @@ #include "ProtocolNexaTest.h" #include "service/ProtocolNexa.h" -CPPUNIT_TEST_SUITE_REGISTRATION (ProtocolNexaTest); - class ProtocolNexaTest::PrivateData { public: ProtocolNexa *protocol; diff --git a/telldus-core/tests/service/ProtocolOregonTest.cpp b/telldus-core/tests/service/ProtocolOregonTest.cpp index a18d3d52..2d5fd0fb 100644 --- a/telldus-core/tests/service/ProtocolOregonTest.cpp +++ b/telldus-core/tests/service/ProtocolOregonTest.cpp @@ -1,8 +1,6 @@ #include "ProtocolOregonTest.h" #include "service/ProtocolOregon.h" -CPPUNIT_TEST_SUITE_REGISTRATION (ProtocolOregonTest); - class ProtocolOregonTest::PrivateData { public: }; diff --git a/telldus-core/tests/service/ProtocolSartanoTest.cpp b/telldus-core/tests/service/ProtocolSartanoTest.cpp index 24bef0b0..655dbb59 100644 --- a/telldus-core/tests/service/ProtocolSartanoTest.cpp +++ b/telldus-core/tests/service/ProtocolSartanoTest.cpp @@ -1,8 +1,6 @@ #include "ProtocolSartanoTest.h" #include "service/ProtocolSartano.h" -CPPUNIT_TEST_SUITE_REGISTRATION (ProtocolSartanoTest); - class ProtocolSartanoTest::PrivateData { public: ProtocolSartano *protocol; diff --git a/telldus-core/tests/service/ProtocolX10Test.cpp b/telldus-core/tests/service/ProtocolX10Test.cpp index 4e97b425..572608f6 100644 --- a/telldus-core/tests/service/ProtocolX10Test.cpp +++ b/telldus-core/tests/service/ProtocolX10Test.cpp @@ -1,8 +1,6 @@ #include "ProtocolX10Test.h" #include "service/ProtocolX10.h" -CPPUNIT_TEST_SUITE_REGISTRATION (ProtocolX10Test); - class ProtocolX10Test::PrivateData { public: ProtocolX10 *protocol; diff --git a/telldus-core/tests/service/ServiceTests.h b/telldus-core/tests/service/ServiceTests.h new file mode 100644 index 00000000..527f2d07 --- /dev/null +++ b/telldus-core/tests/service/ServiceTests.h @@ -0,0 +1,19 @@ +#ifndef SERVICETESTS_H +#define SERVICETESTS_H + +#include "ProtocolEverflourishTest.h" +#include "ProtocolNexaTest.h" +#include "ProtocolOregonTest.h" +#include "ProtocolSartanoTest.h" +#include "ProtocolX10Test.h" + +namespace ServiceTests { + inline void setup() { + CPPUNIT_TEST_SUITE_REGISTRATION (ProtocolEverflourishTest); + CPPUNIT_TEST_SUITE_REGISTRATION (ProtocolNexaTest); + CPPUNIT_TEST_SUITE_REGISTRATION (ProtocolOregonTest); + CPPUNIT_TEST_SUITE_REGISTRATION (ProtocolSartanoTest); + CPPUNIT_TEST_SUITE_REGISTRATION (ProtocolX10Test); + } +} +#endif // SERVICETESTS_H