From 264b92889ac950801a0d7a87632e55671ccf3451 Mon Sep 17 00:00:00 2001 From: Micke Prag Date: Wed, 20 Jun 2012 12:20:23 +0200 Subject: [PATCH] Add unittest for ProtocolNexa::decodeData() --- telldus-core/tests/CMakeLists.txt | 5 ++- telldus-core/tests/service/CMakeLists.txt | 9 ++++ .../tests/service/ProtocolNexaTest.cpp | 42 +++++++++++++++++++ telldus-core/tests/service/ProtocolNexaTest.h | 25 +++++++++++ 4 files changed, 79 insertions(+), 2 deletions(-) create mode 100644 telldus-core/tests/service/CMakeLists.txt create mode 100644 telldus-core/tests/service/ProtocolNexaTest.cpp create mode 100644 telldus-core/tests/service/ProtocolNexaTest.h diff --git a/telldus-core/tests/CMakeLists.txt b/telldus-core/tests/CMakeLists.txt index edc1e976..c1c8fa9e 100644 --- a/telldus-core/tests/CMakeLists.txt +++ b/telldus-core/tests/CMakeLists.txt @@ -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) diff --git a/telldus-core/tests/service/CMakeLists.txt b/telldus-core/tests/service/CMakeLists.txt new file mode 100644 index 00000000..0e795cd8 --- /dev/null +++ b/telldus-core/tests/service/CMakeLists.txt @@ -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} ) + diff --git a/telldus-core/tests/service/ProtocolNexaTest.cpp b/telldus-core/tests/service/ProtocolNexaTest.cpp new file mode 100644 index 00000000..f65c0381 --- /dev/null +++ b/telldus-core/tests/service/ProtocolNexaTest.cpp @@ -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;")) + ); +} diff --git a/telldus-core/tests/service/ProtocolNexaTest.h b/telldus-core/tests/service/ProtocolNexaTest.h new file mode 100644 index 00000000..74c0377b --- /dev/null +++ b/telldus-core/tests/service/ProtocolNexaTest.h @@ -0,0 +1,25 @@ +#ifndef PROTOCOLNEXATEST_H +#define PROTOCOLNEXATEST_H + +#include +#include + +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