Some compilers seems to optimize away our tests. Compiling them

statically and force initiating them seems to do the trick.
This commit is contained in:
Micke Prag 2013-05-17 11:24:27 +02:00
parent a78773a8ed
commit b56823a6e7
11 changed files with 59 additions and 34 deletions

View file

@ -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 )

View file

@ -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

View file

@ -1,8 +1,6 @@
#include "StringsTest.h"
#include "Strings.h"
CPPUNIT_TEST_SUITE_REGISTRATION (StringsTest);
void StringsTest :: setUp (void)
{
}

View file

@ -8,32 +8,39 @@
#include <fstream>
#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;
}

View file

@ -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} )

View file

@ -1,8 +1,6 @@
#include "ProtocolEverflourishTest.h"
#include "service/ProtocolEverflourish.h"
CPPUNIT_TEST_SUITE_REGISTRATION (ProtocolEverflourishTest);
class ProtocolEverflourishTest::PrivateData {
public:
ProtocolEverflourish *protocol;

View file

@ -1,8 +1,6 @@
#include "ProtocolNexaTest.h"
#include "service/ProtocolNexa.h"
CPPUNIT_TEST_SUITE_REGISTRATION (ProtocolNexaTest);
class ProtocolNexaTest::PrivateData {
public:
ProtocolNexa *protocol;

View file

@ -1,8 +1,6 @@
#include "ProtocolOregonTest.h"
#include "service/ProtocolOregon.h"
CPPUNIT_TEST_SUITE_REGISTRATION (ProtocolOregonTest);
class ProtocolOregonTest::PrivateData {
public:
};

View file

@ -1,8 +1,6 @@
#include "ProtocolSartanoTest.h"
#include "service/ProtocolSartano.h"
CPPUNIT_TEST_SUITE_REGISTRATION (ProtocolSartanoTest);
class ProtocolSartanoTest::PrivateData {
public:
ProtocolSartano *protocol;

View file

@ -1,8 +1,6 @@
#include "ProtocolX10Test.h"
#include "service/ProtocolX10.h"
CPPUNIT_TEST_SUITE_REGISTRATION (ProtocolX10Test);
class ProtocolX10Test::PrivateData {
public:
ProtocolX10 *protocol;

View file

@ -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