29 #include <can_msgs/Frame.h> 34 #include <gtest/gtest.h> 47 messages.push_back(f);
57 TEST(SocketCANToTopicTest, checkCorrectData)
66 to_topic_bridge.setup();
69 driver_->init(
"string_not_used",
true);
84 for (uint8_t i=0; i < f.
dlc; i++)
96 ASSERT_EQ(1, message_collector_.
messages.size());
100 can_msgs::Frame msg = message_collector_.
messages.back();
103 EXPECT_EQ(received.id, f.
id);
104 EXPECT_EQ(received.dlc, f.
dlc);
106 EXPECT_EQ(received.is_rtr, f.
is_rtr);
107 EXPECT_EQ(received.is_error, f.
is_error);
108 EXPECT_EQ(received.data, f.
data);
111 TEST(SocketCANToTopicTest, checkInvalidFrameHandling)
127 to_topic_bridge.setup();
146 EXPECT_EQ(message_collector_.
messages.size(), 0);
154 EXPECT_EQ(message_collector_.
messages.size(), 1);
157 TEST(SocketCANToTopicTest, checkCorrectCanIdFilter)
165 std::vector<unsigned int> pass_can_ids;
166 pass_can_ids.push_back(0x1337);
173 driver_->init(
"string_not_used",
true);
188 for (uint8_t i=0; i < f.
dlc; i++)
200 ASSERT_EQ(1, message_collector_.
messages.size());
204 can_msgs::Frame msg = message_collector_.
messages.back();
207 EXPECT_EQ(received.id, f.
id);
208 EXPECT_EQ(received.dlc, f.
dlc);
210 EXPECT_EQ(received.is_rtr, f.
is_rtr);
211 EXPECT_EQ(received.is_error, f.
is_error);
212 EXPECT_EQ(received.data, f.
data);
215 TEST(SocketCANToTopicTest, checkInvalidCanIdFilter)
223 std::vector<unsigned int> pass_can_ids;
224 pass_can_ids.push_back(0x300);
231 driver_->init(
"string_not_used",
true);
246 for (uint8_t i=0; i < f.
dlc; i++)
258 EXPECT_EQ(0, message_collector_.
messages.size());
261 TEST(SocketCANToTopicTest, checkMaskFilter)
274 to_topic_bridge.
setup(filters);
277 driver_->init(
"string_not_used",
true);
285 const std::string pass1(
"300#1234"), nopass1(
"302#9999"), pass2(
"301#5678");
297 ASSERT_EQ(2, message_collector_.
messages.size());
302 int main(
int argc,
char **argv)
307 testing::InitGoogleTest(&argc, argv);
308 return RUN_ALL_TESTS();
FilteredFrameListener::FilterVector tofilters(const T &v)
TEST(SocketCANToTopicTest, checkCorrectData)
std::string tostring(const Header &h, bool lc)
FrameFilterSharedPtr tofilter(const T &ct)
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
std::list< can_msgs::Frame > messages
boost::array< value_type, 8 > data
Frame toframe(const std::string &s)
void convertMessageToSocketCAN(const can_msgs::Frame &m, can::Frame &f)
std::vector< FrameFilterSharedPtr > FilterVector
void msgCallback(const can_msgs::Frame &f)
ROSCPP_DECL void spinOnce()
std::string convertMessageToString(const can_msgs::Frame &msg, bool lc=true)
int main(int argc, char **argv)