11 #include "gtest/gtest.h"
17 TEST(CoLa2ProtocolHandlerTest, OpenSession)
19 constexpr uint32_t SESSION_ID = 0x4e11ba11u;
24 EXPECT_TRUE(protocolHandler.openSession(50u));
26 EXPECT_TRUE(transport.
cmdHeader().has_value());
27 EXPECT_EQ(transport.
cmdHeader()->cmdMode,
"Ox");
28 EXPECT_EQ(protocolHandler.getSessionId(), SESSION_ID);
31 TEST(CoLa2ProtocolHandlerTest, ReadVariable)
34 const ByteBuffer results({0x01u, 0x02u, 0x03u, 0x04u});
41 auto response = protocolHandler.send(testCommand);
43 EXPECT_TRUE(transport.
cmdHeader().has_value());
44 EXPECT_EQ(transport.
cmdHeader()->cmdMode,
"RN");
46 EXPECT_EQ(CoLaError::OK,
response.getError());
51 TEST(CoLa2ProtocolHandlerTest, WriteVariable)
54 constexpr int32_t VAR_VALUE = -0x12345678;
61 auto response = protocolHandler.send(testCommand);
63 EXPECT_TRUE(transport.
cmdHeader().has_value());
64 EXPECT_EQ(transport.
cmdHeader()->cmdMode,
"WN");
66 const ByteBuffer expectedValue{
' ',
'v',
'n',
'a',
'm',
'e',
' ', 0xedu, 0xcbu, 0xa9u, 0x88u};
67 EXPECT_EQ(transport.
cmdpayload(), expectedValue);
70 EXPECT_EQ(CoLaError::OK,
response.getError());
73 TEST(CoLa2ProtocolHandlerTest, MethodInvocation)
76 constexpr uint16_t PAR_VALUE = 0xfeed;
77 const ByteBuffer results({0x01u, 0x02u, 0x03u, 0x04u});
85 auto response = protocolHandler.send(testCommand);
87 const ByteBuffer expectedValue({
' ',
'm',
't',
'd',
' ', 0xfeu, 0xedu});
88 EXPECT_EQ(transport.
cmdpayload(), expectedValue);
90 EXPECT_TRUE(transport.
cmdHeader().has_value());
91 EXPECT_EQ(transport.
cmdHeader()->cmdMode,
"MN");
94 EXPECT_EQ(CoLaError::OK,
response.getError());
99 TEST(CoLa2ProtocolHandlerTest, OpenSessionInvalidMagic)
104 EXPECT_FALSE(protocolHandler.openSession(50u));
107 TEST(CoLa2ProtocolHandlerTest, OpenSessionBrokenPacket)
109 MockTransport transport{0x02, 0x02, 0x02, 0x02, 0x0, 0x0, 0x0, 0x1, 0x1};
112 EXPECT_FALSE(protocolHandler.openSession(50u));
115 TEST(CoLa2ProtocolHandlerTest, OpenSessionEmptyPacket)
120 EXPECT_FALSE(protocolHandler.openSession(50u));
123 TEST(CoLa2ProtocolHandlerTest, InvalidMagicBytes)
130 auto response = protocolHandler.send(testCommand);
136 TEST(CoLa2ProtocolHandlerTest, tooFewMagicBytes)
142 auto response = protocolHandler.send(testCommand);
148 TEST(CoLa2ProtocolHandlerTest, EmptyAnswer)
154 auto response = protocolHandler.send(testCommand);
160 TEST(CoLa2ProtocolHandlerTest, EmptyPackage)
166 auto response = protocolHandler.send(testCommand);
172 TEST(CoLa2ProtocolHandlerTest, InvalidSessionId)
175 const ByteBuffer results({0x01u, 0x02u, 0x03u, 0x04u});
181 auto response = protocolHandler.send(testCommand);
187 TEST(CoLa2ProtocolHandlerTest, InvalidReqId)
190 constexpr int32_t VAR_VALUE = -0x12345678;
197 auto response = protocolHandler.send(testCommand);
203 TEST(CoLa2ProtocolHandlerTest, InvalidResponseCode)
211 auto response = protocolHandler.send(testCommand);
217 TEST(CoLa2ProtocolHandlerTest, ColaAnswerTooShort)
225 auto response = protocolHandler.send(testCommand);
231 TEST(CoLa2ProtocolHandlerTest, ColaErrorTooShort)
239 auto response = protocolHandler.send(testCommand);
245 TEST(CoLa2ProtocolHandlerTest, ColaErrorErrornoMissing)
253 auto response = protocolHandler.send(testCommand);
259 TEST(CoLa2ProtocolHandlerTest, ColaErrorErrorTooShort)
268 auto response = protocolHandler.send(testCommand);
274 TEST(CoLa2ProtocolHandlerTest, ColaErrorValid)
283 auto response = protocolHandler.send(testCommand);
289 TEST(CoLa2ProtocolHandlerTest, SendFailed)
298 auto response = protocolHandler.send(testCommand);