Test Adding and Removing a TCP Callback.
115{
116
118 []()
119 {
120
122
123
124
125 for (int i = 0; i < 3; ++i)
126 {
127 if (RoveCommTCPNode.
Init(
"127.0.0.1", 12002))
128 {
129 break;
130 }
131 else
132 {
133 std::this_thread::sleep_for(std::chrono::seconds(1));
134 }
135 }
136
137
138 bool bCallbackInvoked = false;
139
140 std::vector<int32_t> vExpectedData = {-100, -1, 5555};
141
142
143 RoveCommTCPNode.
On<int32_t>(1100,
145 {
146
147 bCallbackInvoked = true;
148
149
150 EXPECT_EQ(packet.unDataId, 1100);
151 EXPECT_EQ(packet.GetDataCount(), 3);
153
154 for (size_t i = 0; i < packet.vData.size(); i++)
155 {
156 EXPECT_EQ(packet.vData[i], vExpectedData[i]);
157 }
158 });
159
160
161
163
164 for (int32_t nData : vExpectedData)
165 {
166 stPacket.vData.push_back(nData);
167 }
168
169
171
172
174
175
176 EXPECT_TRUE(bCallbackInvoked);
177
178
179 RoveCommTCPNode.
Close();
180 },
181 3,
182 30000);
183}
The RoveCommTCP class is used to send and receive data over a TCP connection.
Definition RoveCommTCP.h:52
void Close()
Closes the TCP socket.
Definition RoveCommTCP.cpp:459
void ProcessPacket(std::span< const uint8_t > stData)
Processes a received packet and invokes the appropriate callback function from the vector of TCP call...
Definition RoveCommTCP.cpp:329
CallbackHandle On(const uint16_t unDataId, std::function< void(const RoveCommPacket< T > &)> fnCallback)
Register a callback for TCP packets with the given data ID. The callback belongs to this node: packet...
Definition RoveCommTCP.cpp:227
bool Init(const manifest::AddressEntry &stIPAddress={0, 0, 0, 0}, int nPort=manifest::General::ETHERNET_TCP_PORT)
Initializes a TCP socket and binds it to the specified IP address and port. And then starts the threa...
Definition RoveCommTCP.cpp:76
@ INT32_T
Definition RoveCommManifest.h:39
std::vector< uint8_t > PackPacket(const RoveCommPacket< T > &stPacket)
Create a RoveCommData structure from a RoveCommPacket structure.
Definition RoveCommPacket.cpp:44
void RunTimedTest(const std::function< void()> &fnTestCode, int nMaxRetries, int nTimeoutMS)
Run a test with a timeout and retries.
Definition TestUtils.cc:31
The RoveCommPacket struct is used to store data in a packet format for transmission over a network....
Definition RoveCommPacket.h:75