Add unittest for ProtocolNexa::decodeData()

This commit is contained in:
Micke Prag 2012-06-20 12:20:23 +02:00
parent ae7b9b8c1a
commit 264b92889a
4 changed files with 79 additions and 2 deletions

View file

@ -31,10 +31,11 @@ ENDFUNCTION()
IF(ENABLE_TESTING)
ADD_SUBDIRECTORY(common)
ADD_SUBDIRECTORY(service)
ADD_EXECUTABLE(TestRunner cppunit.cpp)
TARGET_LINK_LIBRARIES(TestRunner cppunit TelldusCommonTests)
ADD_DEPENDENCIES(TestRunner TelldusCommonTests)
TARGET_LINK_LIBRARIES(TestRunner cppunit TelldusCommonTests TelldusServiceTests)
ADD_DEPENDENCIES(TestRunner TelldusCommonTests TelldusServiceTests)
ADD_SOURCES(TelldusCommon ${CMAKE_SOURCE_DIR}/common)
ADD_SOURCES(${telldus-core_TARGET} ${CMAKE_SOURCE_DIR}/client)

View file

@ -0,0 +1,9 @@
FILE(GLOB SRCS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "*Test.cpp" )
INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR})
ADD_LIBRARY(TelldusServiceTests SHARED ${SRCS} )
TARGET_LINK_LIBRARIES( TelldusServiceTests TelldusServiceStatic )
ADD_DEPENDENCIES( TelldusServiceTests ${telldus-service_TARGET} )

View file

@ -0,0 +1,42 @@
#include "ProtocolNexaTest.h"
#include "service/ProtocolNexa.h"
CPPUNIT_TEST_SUITE_REGISTRATION (ProtocolNexaTest);
class ProtocolNexaTest::PrivateData {
public:
ProtocolNexa *protocol;
};
void ProtocolNexaTest :: setUp (void) {
d = new PrivateData;
d->protocol = new ProtocolNexa();
}
void ProtocolNexaTest :: tearDown (void) {
delete d->protocol;
delete d;
}
void ProtocolNexaTest :: decodeDataTest (void) {
CPPUNIT_ASSERT_EQUAL_MESSAGE(
"Arctech Codeswitch A1 ON",
std::string("class:command;protocol:arctech;model:codeswitch;house:A;unit:1;method:turnon;"),
d->protocol->decodeData(ControllerMessage("protocol:arctech;model:codeswitch;data:0xE00;"))
);
CPPUNIT_ASSERT_EQUAL_MESSAGE(
"Arctech Codeswitch A1 OFF",
std::string("class:command;protocol:arctech;model:codeswitch;house:A;unit:1;method:turnoff;"),
d->protocol->decodeData(ControllerMessage("protocol:arctech;model:codeswitch;data:0x600;"))
);
CPPUNIT_ASSERT_EQUAL_MESSAGE(
"Arctech Selflearning 1329110 1 ON",
std::string("class:command;protocol:arctech;model:selflearning;house:1329110;unit:1;group:0;method:turnon;"),
d->protocol->decodeData(ControllerMessage("protocol:arctech;model:selflearning;data:0x511F590;"))
);
CPPUNIT_ASSERT_EQUAL_MESSAGE(
"Arctech Selflearning 1329110 1 OFF",
std::string("class:command;protocol:arctech;model:selflearning;house:1329110;unit:1;group:0;method:turnoff;"),
d->protocol->decodeData(ControllerMessage("protocol:arctech;model:selflearning;data:0x511F580;"))
);
}

View file

@ -0,0 +1,25 @@
#ifndef PROTOCOLNEXATEST_H
#define PROTOCOLNEXATEST_H
#include <cppunit/TestFixture.h>
#include <cppunit/extensions/HelperMacros.h>
class ProtocolNexaTest : public CPPUNIT_NS :: TestFixture
{
CPPUNIT_TEST_SUITE (ProtocolNexaTest);
CPPUNIT_TEST (decodeDataTest);
CPPUNIT_TEST_SUITE_END ();
public:
void setUp (void);
void tearDown (void);
protected:
void decodeDataTest(void);
private:
class PrivateData;
PrivateData *d;
};
#endif //PROTOCOLNEXATEST_H