Remove sscanf() from ProtocolSartano and add a unittest for ProtocolSartano::decodeData()
This commit is contained in:
parent
ddfb87f45d
commit
9eac84fb4a
3 changed files with 55 additions and 5 deletions
|
@ -42,16 +42,14 @@ std::string ProtocolSartano::getStringForCode(const std::wstring &strCode, int m
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string ProtocolSartano::decodeData(const ControllerMessage &dataMsg) {
|
std::string ProtocolSartano::decodeData(const ControllerMessage &dataMsg) {
|
||||||
std::string data = dataMsg.getParameter("data");
|
uint64_t allDataIn;
|
||||||
signed int allDataIn;
|
uint16_t allData = 0;
|
||||||
signed int allData = 0;
|
|
||||||
unsigned int code = 0;
|
unsigned int code = 0;
|
||||||
unsigned int method1 = 0;
|
unsigned int method1 = 0;
|
||||||
unsigned int method2 = 0;
|
unsigned int method2 = 0;
|
||||||
unsigned int method = 0;
|
unsigned int method = 0;
|
||||||
|
|
||||||
// TODO(micke): Convert sscanf. This is slow and can overflow buffers!
|
allDataIn = dataMsg.getInt64Parameter("data");
|
||||||
sscanf(data.c_str(), "%X", &allDataIn); // NOLINT(runtime/printf)
|
|
||||||
|
|
||||||
uint16_t mask = (1<<11);
|
uint16_t mask = (1<<11);
|
||||||
for(int i = 0; i < 12; ++i) {
|
for(int i = 0; i < 12; ++i) {
|
||||||
|
|
27
telldus-core/tests/service/ProtocolSartanoTest.cpp
Normal file
27
telldus-core/tests/service/ProtocolSartanoTest.cpp
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
#include "ProtocolSartanoTest.h"
|
||||||
|
#include "service/ProtocolSartano.h"
|
||||||
|
|
||||||
|
CPPUNIT_TEST_SUITE_REGISTRATION (ProtocolSartanoTest);
|
||||||
|
|
||||||
|
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;"))
|
||||||
|
);
|
||||||
|
}
|
25
telldus-core/tests/service/ProtocolSartanoTest.h
Normal file
25
telldus-core/tests/service/ProtocolSartanoTest.h
Normal 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
|
Loading…
Add table
Add a link
Reference in a new issue