7 #include <gtest/gtest.h>
41 std::cout <<
"RX frame [flags=" << flags <<
"]: " <<
frame.toString() << std::endl;
74 ASSERT_TRUE(rx_listener.
rx_frames.empty());
87 typedef std::unique_ptr<TestListener> TestListenerPtr;
88 static const int MaxBufSize = 512;
89 static const int NumSubscribers = 6;
90 TestListenerPtr subscribers[NumSubscribers] =
100 static const std::string DATA[6] =
102 "Yes, man is mortal, but that would be only half the trouble. "
103 "The worst of it is that he's sometimes unexpectedly mortal - there's the trick!",
105 "In fact, I'm beginning to fear that this confusion will go on for a long time. "
106 "And all because he writes down what I said incorrectly.",
108 "I had the pleasure of meeting that young man at the Patriarch's Ponds. "
109 "He almost drove me mad myself, proving to me that I don't exist. But you do believe that it is really I?",
111 "He was a dreamer, a thinker, a speculative philosopher... or, as his wife would have it, an idiot.",
113 "The only way to get ideas for stories is to drink way too much coffee and buy a desk that doesn't "
114 "collapse when you beat your head against it",
119 for (
unsigned i = 0; i <
sizeof(DATA) /
sizeof(DATA[0]); i++)
121 std::cout <<
"Size of test data chunk " << i <<
": " << DATA[i].length() << std::endl;
140 for (
int i = 0; i < NumSubscribers; i++)
142 ASSERT_FALSE(dispatcher.
hasSubscriber(subscribers[i]->getDataTypeDescriptor().getID()));
143 ASSERT_FALSE(dispatcher.
hasPublisher(subscribers[i]->getDataTypeDescriptor().getID()));
144 ASSERT_FALSE(dispatcher.
hasServer(subscribers[i]->getDataTypeDescriptor().getID()));
154 for (
int i = 0; i < NumSubscribers; i++)
156 ASSERT_FALSE(dispatcher.
hasPublisher(subscribers[i]->getDataTypeDescriptor().getID()));
160 ASSERT_TRUE(dispatcher.
hasSubscriber(subscribers[0]->getDataTypeDescriptor().getID()));
161 ASSERT_TRUE(dispatcher.
hasSubscriber(subscribers[1]->getDataTypeDescriptor().getID()));
162 ASSERT_TRUE(dispatcher.
hasSubscriber(subscribers[2]->getDataTypeDescriptor().getID()));
165 ASSERT_TRUE(dispatcher.
hasServer(subscribers[3]->getDataTypeDescriptor().getID()));
178 for (
int i = 0; i < NumSubscribers; i++)
180 ASSERT_TRUE(subscribers[i]->isEmpty());
183 emulator.
send(transfers);
184 emulator.
send(transfers);
188 const int res = dispatcher.
spinOnce();
200 ASSERT_TRUE(subscribers[0]->matchAndPop(transfers[4]));
201 ASSERT_TRUE(subscribers[0]->matchAndPop(transfers[0]));
203 ASSERT_TRUE(subscribers[1]->matchAndPop(transfers[4]));
204 ASSERT_TRUE(subscribers[1]->matchAndPop(transfers[0]));
206 ASSERT_TRUE(subscribers[2]->matchAndPop(transfers[5]));
207 ASSERT_TRUE(subscribers[2]->matchAndPop(transfers[1]));
209 ASSERT_TRUE(subscribers[3]->matchAndPop(transfers[2]));
211 ASSERT_TRUE(subscribers[4]->matchAndPop(transfers[3]));
213 ASSERT_TRUE(subscribers[5]->matchAndPop(transfers[3]));
215 for (
int i = 0; i < NumSubscribers; i++)
217 ASSERT_TRUE(subscribers[i]->isEmpty());
244 std::cout <<
"Num received frames: " << rx_listener.
rx_frames.size() << std::endl;
245 ASSERT_EQ(292, rx_listener.
rx_frames.size());
274 frame.setPayload(
reinterpret_cast<const uint8_t*
>(
"123"), 3);
290 ASSERT_TRUE(
frame.compile(expected_can_frame));
292 ASSERT_TRUE(driver.
ifaces.at(0).matchAndPopTx(expected_can_frame, TX_DEADLINE));
293 ASSERT_TRUE(driver.
ifaces.at(1).matchAndPopTx(expected_can_frame, TX_DEADLINE));
295 ASSERT_TRUE(driver.
ifaces.at(0).tx.empty());
296 ASSERT_TRUE(driver.
ifaces.at(1).tx.empty());
308 ASSERT_TRUE(rx_listener.
rx_frames.empty());
328 ASSERT_EQ(0, dispatcher.
spinOnce());
350 std::cout <<
"DispatcherTestLoopbackFrameListener: " <<
frame.toString() << std::endl;
375 frame.setPayload(
reinterpret_cast<const uint8_t*
>(
"123"), 3);
387 ASSERT_EQ(2, listener.
count);