random ai stuff

This commit is contained in:
matst80
2025-11-21 18:12:55 +01:00
commit 60f5783a26
187 changed files with 25197 additions and 0 deletions

View File

@@ -0,0 +1,51 @@
SET(ENABLE_TESTING FALSE CACHE BOOL "Enable unit tests")
#We have disabled some of the default tests in the google style guidelines
# whitespace/tab
# We are using tabs for indentation, not spaces, in our code
#
# whitespace/parens
# We believe grouping of parameters with spaces in some functions could ease the readability
#
# whitespace/line_length
# Although you should try to keep the lines short it should not be a requirement (at least for now)
#
# whitespace/labels
# Since we use tabs instead of spaces for indentation, this test makes no sense
#
# runtime/rtti
# We are using dynamic_cast for the events. We use this to be able to send arbitrary data
# trought the events.
#
SET(cpplint_filters
+whitespace/use_tab_for_indentation,-whitespace/tab,-whitespace/parens,-whitespace/line_length,-whitespace/labels,-runtime/rtti
)
FUNCTION(ADD_SOURCES TARGET PATH)
GET_TARGET_PROPERTY(SOURCES ${TARGET} SOURCES)
FOREACH(SOURCE ${SOURCES})
LIST(APPEND L ${PATH}/${SOURCE})
ENDFOREACH()
ADD_TEST(StyleGuidelines-${TARGET} ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/cpplint.py --filter=${cpplint_filters} ${L})
ENDFUNCTION()
IF(ENABLE_TESTING)
INCLUDE(FindPythonInterp)
FIND_LIBRARY(CPPUNIT cppunit)
ADD_SUBDIRECTORY(common)
ADD_SUBDIRECTORY(service)
ADD_EXECUTABLE(TestRunner cppunit.cpp)
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)
ADD_SOURCES(${telldus-service_TARGET} ${CMAKE_SOURCE_DIR}/service)
ADD_TEST(cppunit ${CMAKE_CURRENT_BINARY_DIR}/TestRunner)
IF (UNIX)
ADD_TEST(cppcheck cppcheck --quiet --error-exitcode=2 ${CMAKE_SOURCE_DIR})
ENDIF()
ENDIF()

View File

@@ -0,0 +1,9 @@
FILE(GLOB SRCS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "*Test.cpp" )
INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/common)
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

@@ -0,0 +1,16 @@
#include "StringsTest.h"
#include "Strings.h"
void StringsTest :: setUp (void)
{
}
void StringsTest :: tearDown (void)
{
}
void StringsTest :: formatfTest (void) {
CPPUNIT_ASSERT_EQUAL(std::string("42"), TelldusCore::formatf("%u", 42));
CPPUNIT_ASSERT_EQUAL(std::string("2A"), TelldusCore::formatf("%X", 42));
CPPUNIT_ASSERT_EQUAL(std::string("42"), TelldusCore::formatf("%s", "42"));
}

View File

@@ -0,0 +1,21 @@
#ifndef STRINGSTEST_H
#define STRINGSTEST_H
#include <cppunit/TestFixture.h>
#include <cppunit/extensions/HelperMacros.h>
class StringsTest : public CPPUNIT_NS :: TestFixture
{
CPPUNIT_TEST_SUITE (StringsTest);
CPPUNIT_TEST (formatfTest);
CPPUNIT_TEST_SUITE_END ();
public:
void setUp (void);
void tearDown (void);
protected:
void formatfTest(void);
};
#endif //STRINGSTEST_H

3369
telldus-core/tests/cpplint.py vendored Executable file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,46 @@
#include <cppunit/CompilerOutputter.h>
#include <cppunit/XmlOutputter.h>
#include <cppunit/extensions/TestFactoryRegistry.h>
#include <cppunit/TestResult.h>
#include <cppunit/TestResultCollector.h>
#include <cppunit/TestRunner.h>
#include <cppunit/BriefTestProgressListener.h>
#include <fstream>
#include "common/CommonTests.h"
#include "service/ServiceTests.h"
int main (int argc, char* argv[])
{
// Setup our tests
CommonTests::setup();
ServiceTests::setup();
// informs test-listener about testresults
CPPUNIT_NS :: TestResult testresult;
// register listener for collecting the test-results
CPPUNIT_NS :: TestResultCollector collectedresults;
testresult.addListener (&collectedresults);
// register listener for per-test progress output
CPPUNIT_NS :: BriefTestProgressListener progress;
testresult.addListener (&progress);
// insert test-suite at test-runner by registry
CPPUNIT_NS :: TestRunner testrunner;
testrunner.addTest (CPPUNIT_NS :: TestFactoryRegistry :: getRegistry ().makeTest ());
testrunner.run (testresult);
// output results in compiler-format
CPPUNIT_NS :: CompilerOutputter compileroutputter (&collectedresults, std::cerr);
compileroutputter.write ();
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

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

View File

@@ -0,0 +1,30 @@
#include "ProtocolEverflourishTest.h"
#include "service/ProtocolEverflourish.h"
class ProtocolEverflourishTest::PrivateData {
public:
ProtocolEverflourish *protocol;
};
void ProtocolEverflourishTest :: setUp (void) {
d = new PrivateData;
d->protocol = new ProtocolEverflourish();
}
void ProtocolEverflourishTest :: tearDown (void) {
delete d->protocol;
delete d;
}
void ProtocolEverflourishTest :: decodeDataTest (void) {
CPPUNIT_ASSERT_EQUAL_MESSAGE(
"Everflourish 4242:3 ON",
std::string("class:command;protocol:everflourish;model:selflearning;house:4242;unit:3;method:turnon;"),
d->protocol->decodeData(ControllerMessage("protocol:everflourish;data:0x424A6F;"))
);
CPPUNIT_ASSERT_EQUAL_MESSAGE(
"Everflourish 5353:4 OFF",
std::string("class:command;protocol:everflourish;model:selflearning;house:5353;unit:4;method:turnoff;"),
d->protocol->decodeData(ControllerMessage("protocol:everflourish;data:0x53A7E0;"))
);
}

View File

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

View File

@@ -0,0 +1,40 @@
#include "ProtocolHastaTest.h"
#include "service/ProtocolHasta.h"
class ProtocolHastaTest::PrivateData {
public:
ProtocolHasta *protocol;
};
void ProtocolHastaTest :: setUp (void) {
d = new PrivateData;
d->protocol = new ProtocolHasta();
}
void ProtocolHastaTest :: tearDown (void) {
delete d->protocol;
delete d;
}
void ProtocolHastaTest :: decodeDataTest (void) {
CPPUNIT_ASSERT_EQUAL_MESSAGE(
"Hasta Version 1 26380 1 DOWN",
std::string("class:command;protocol:hasta;model:selflearning;house:26380;unit:1;method:down;"),
d->protocol->decodeData(ControllerMessage("protocol:hasta;model:selflearning;data:0xC671100;"))
);
CPPUNIT_ASSERT_EQUAL_MESSAGE(
"Hasta Version 1 26380 1 UP",
std::string("class:command;protocol:hasta;model:selflearning;house:26380;unit:1;method:up;"),
d->protocol->decodeData(ControllerMessage("protocol:arctech;model:selflearning;data:0xC670100;"))
);
CPPUNIT_ASSERT_EQUAL_MESSAGE(
"Hasta Version 2 19337 15 DOWN",
std::string("class:command;protocol:hasta;model:selflearningv2;house:19337;unit:15;method:down;"),
d->protocol->decodeData(ControllerMessage("protocol:hasta;model:selflearningv2;data:0x4B891F01;"))
);
CPPUNIT_ASSERT_EQUAL_MESSAGE(
"Hasta Version 2 19337 15 UP",
std::string("class:command;protocol:hasta;model:selflearningv2;house:19337;unit:15;method:up;"),
d->protocol->decodeData(ControllerMessage("protocol:hasta;model:selflearningv2;data:0x4B89CF01;"))
);
}

View File

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

View File

@@ -0,0 +1,40 @@
#include "ProtocolNexaTest.h"
#include "service/ProtocolNexa.h"
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

View File

@@ -0,0 +1,67 @@
#include "ProtocolOregonTest.h"
#include "service/ProtocolOregon.h"
class ProtocolOregonTest::PrivateData {
public:
};
void ProtocolOregonTest :: setUp (void) {
d = new PrivateData;
}
void ProtocolOregonTest :: tearDown (void) {
delete d;
}
void ProtocolOregonTest :: decodeDataTest (void) {
CPPUNIT_ASSERT_EQUAL_MESSAGE(
"Oregon, id: 119, temp: 77.3",
std::string("class:sensor;protocol:oregon;model:EA4C;id:119;temp:77.3;"),
ProtocolOregon::decodeData(ControllerMessage("class:sensor;protocol:oregon;model:0xEA4C;data:2177307700E4;"))
);
CPPUNIT_ASSERT_EQUAL_MESSAGE(
"Oregon, id: 119, temp: 74.7",
std::string("class:sensor;protocol:oregon;model:EA4C;id:119;temp:74.7;"),
ProtocolOregon::decodeData(ControllerMessage("class:sensor;protocol:oregon;model:0xEA4C;data:2177707410A4;"))
);
CPPUNIT_ASSERT_EQUAL_MESSAGE(
"Oregon, id: 119, temp: 77.7",
std::string("class:sensor;protocol:oregon;model:EA4C;id:119;temp:77.7;"),
ProtocolOregon::decodeData(ControllerMessage("class:sensor;protocol:oregon;model:0xEA4C;data:217770774054;"))
);
CPPUNIT_ASSERT_EQUAL_MESSAGE(
"Oregon, id: 119, temp: 66.5",
std::string("class:sensor;protocol:oregon;model:EA4C;id:119;temp:66.5;"),
ProtocolOregon::decodeData(ControllerMessage("class:sensor;protocol:oregon;model:0xEA4C;data:2177506600E4;"))
);
CPPUNIT_ASSERT_EQUAL_MESSAGE(
"Oregon, id: 119, temp: 122.5",
std::string("class:sensor;protocol:oregon;model:EA4C;id:119;temp:122.5;"),
ProtocolOregon::decodeData(ControllerMessage("class:sensor;protocol:oregon;model:0xEA4C;data:2177502291A3;"))
);
CPPUNIT_ASSERT_EQUAL_MESSAGE(
"Oregon, id: 119, temp: 120.1",
std::string("class:sensor;protocol:oregon;model:EA4C;id:119;temp:120.1;"),
ProtocolOregon::decodeData(ControllerMessage("class:sensor;protocol:oregon;model:0xEA4C;data:2177102031B3;"))
);
CPPUNIT_ASSERT_EQUAL_MESSAGE(
"Oregon, id: 119, temp: 120.6",
std::string("class:sensor;protocol:oregon;model:EA4C;id:119;temp:120.6;"),
ProtocolOregon::decodeData(ControllerMessage("class:sensor;protocol:oregon;model:0xEA4C;data:217760208193;"))
);
CPPUNIT_ASSERT_EQUAL_MESSAGE(
"Oregon, id: 23, temp: 202.7",
std::string("class:sensor;protocol:oregon;model:EA4C;id:23;temp:202.7;"),
ProtocolOregon::decodeData(ControllerMessage("class:sensor;protocol:oregon;model:0xEA4C;data:2177702A2D3;"))
);
CPPUNIT_ASSERT_EQUAL_MESSAGE(
"Oregon, id: 119, temp: 202.7",
std::string("class:sensor;protocol:oregon;model:EA4C;id:119;temp:202.7;"),
ProtocolOregon::decodeData(ControllerMessage("class:sensor;protocol:oregon;model:0xEA4C;data:21777002A2D3;"))
);
CPPUNIT_ASSERT_EQUAL_MESSAGE(
"Oregon, id: 119, temp: -23.1",
std::string("class:sensor;protocol:oregon;model:EA4C;id:119;temp:-23.1;"),
ProtocolOregon::decodeData(ControllerMessage("class:sensor;protocol:oregon;model:0xEA4C;data:21771023D8B3;"))
);
}

View File

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

View File

@@ -0,0 +1,25 @@
#include "ProtocolSartanoTest.h"
#include "service/ProtocolSartano.h"
class ProtocolSartanoTest::PrivateData {
public:
ProtocolSartano *protocol;
};
void ProtocolSartanoTest :: setUp (void) {
d = new PrivateData;
d->protocol = new ProtocolSartano();
}
void ProtocolSartanoTest :: tearDown (void) {
delete d->protocol;
delete d;
}
void ProtocolSartanoTest :: decodeDataTest (void) {
CPPUNIT_ASSERT_EQUAL_MESSAGE(
"Sartano 0101010101 ON",
std::string("class:command;protocol:sartano;model:codeswitch;code:0101010101;method:turnon;"),
d->protocol->decodeData(ControllerMessage("protocol:arctech;model:codeswitch;data:0x955;"))
);
}

View File

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

View File

@@ -0,0 +1,30 @@
#include "ProtocolX10Test.h"
#include "service/ProtocolX10.h"
class ProtocolX10Test::PrivateData {
public:
ProtocolX10 *protocol;
};
void ProtocolX10Test :: setUp (void) {
d = new PrivateData;
d->protocol = new ProtocolX10();
}
void ProtocolX10Test :: tearDown (void) {
delete d->protocol;
delete d;
}
void ProtocolX10Test :: decodeDataTest (void) {
CPPUNIT_ASSERT_EQUAL_MESSAGE(
"X10 A1 ON",
std::string("class:command;protocol:x10;model:codeswitch;house:A;unit:1;method:turnon;"),
d->protocol->decodeData(ControllerMessage("protocol:x10;data:0x609F00FF;"))
);
CPPUNIT_ASSERT_EQUAL_MESSAGE(
"X10 E11 OFF",
std::string("class:command;protocol:x10;model:codeswitch;house:E;unit:11;method:turnoff;"),
d->protocol->decodeData(ControllerMessage("protocol:x10;data:0x847B28D7;"))
);
}

View File

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

View File

@@ -0,0 +1,21 @@
#ifndef SERVICETESTS_H
#define SERVICETESTS_H
#include "ProtocolEverflourishTest.h"
#include "ProtocolHastaTest.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 (ProtocolHastaTest);
CPPUNIT_TEST_SUITE_REGISTRATION (ProtocolNexaTest);
CPPUNIT_TEST_SUITE_REGISTRATION (ProtocolOregonTest);
CPPUNIT_TEST_SUITE_REGISTRATION (ProtocolSartanoTest);
CPPUNIT_TEST_SUITE_REGISTRATION (ProtocolX10Test);
}
}
#endif // SERVICETESTS_H