1 #include "../../src/plugin_router/string_plugin_router.h" 3 #include <fruit/fruit.h> 4 #include <gtest/gtest.h> 7 #include <boost/array.hpp> 8 #include <boost/asio.hpp> 13 #include <unordered_map> 15 #include "../../src/socket/udp_socket.h" 16 #include "std_msgs/UInt8MultiArray.h" 18 using boost::asio::ip::udp;
19 using fruit::Annotated;
20 using fruit::Component;
21 using fruit::createComponent;
22 using fruit::Injector;
26 std::shared_ptr<std::function<void(std::vector<uint8_t>)>>
callback_;
33 ASSISTED(udp::endpoint) target_socket,
34 ASSISTED(std::shared_ptr<std::function<
void(std::vector<uint8_t>)>>)
39 std::string first_message =
"first message";
40 std::vector<uint8_t> first_data(first_message.begin(), first_message.end());
41 (*callback_)(first_data);
44 virtual void SendData(std::vector<uint8_t> data)
override {
45 std::string message(data.begin(), data.end());
50 ASSERT_STREQ(message.c_str(),
"first message");
53 ASSERT_STREQ(message.c_str(),
"second message");
56 ASSERT_STREQ(message.c_str(),
"third message");
67 Component<Annotated<StringAnnotation, PluginRouterFactory>>
69 return createComponent()
76 TEST(TestSuite, string_plugin_try_start_with_invalid_xml) {
77 std::shared_ptr<rapidjson::Document> config(
new rapidjson::Document);
81 Injector<Annotated<StringAnnotation, PluginRouterFactory>> injector(
84 injector.get<fruit::Annotated<StringAnnotation, PluginRouterFactory>>();
86 auto source = pluginRouterFactory(config, udp::endpoint(udp::v4(), 0));
87 auto result = source->TryStart();
89 ASSERT_FALSE(result.is_success);
90 ASSERT_STREQ(result.error_message,
"invalid config parameters");
94 TEST(TestSuite, string_plugin_try_start_not_found_plugin) {
95 std::shared_ptr<rapidjson::Document> config(
new rapidjson::Document);
97 "[{\"plugin_name\":\"string_loopback::StringLoopback\",\"param\":" 99 "\"plugin_name\":\"not_found_plugin::NotFoundPlugin\"}]");
100 ROS_INFO(
"This test produces a ROS_ERROR message because of a loading error in the plugin, but the behavior is as expected.");
103 Injector<Annotated<StringAnnotation, PluginRouterFactory>> injector(
106 injector.get<fruit::Annotated<StringAnnotation, PluginRouterFactory>>();
108 auto source = pluginRouterFactory(config, udp::endpoint(udp::v4(), 0));
109 auto result = source->TryStart();
111 ASSERT_FALSE(result.is_success);
112 std::string error_message = result.error_message;
113 ASSERT_EQ(error_message.rfind(
"Failed to load"), 0);
117 TEST(TestSuite, string_plugin_try_start_with_loopback_plugin) {
118 std::shared_ptr<rapidjson::Document> config(
new rapidjson::Document);
120 "[{\"plugin_name\":\"string_loopback::StringLoopback\",\"param\":" 124 Injector<Annotated<StringAnnotation, PluginRouterFactory>> injector(
127 injector.get<fruit::Annotated<StringAnnotation, PluginRouterFactory>>();
129 auto source = pluginRouterFactory(config, udp::endpoint(udp::v4(), 0));
130 auto result = source->TryStart();
133 ASSERT_TRUE(result.is_success);
virtual void Start() override
Component< fruit::Annotated< StringAnnotation, PluginRouterFactory > > getStringPluginRouterComponent()
virtual void SendData(std::vector< uint8_t > data) override
std::shared_ptr< std::function< void(std::vector< uint8_t >)> > callback_
INJECT(MockStringSocket(ASSISTED(udp::endpoint) target_socket, callback))
Component< Annotated< StringAnnotation, PluginRouterFactory > > getMockStringPluginRouterComponent()
TEST(TestSuite, string_plugin_try_start_with_invalid_xml)
Component< SocketFactory > getUdpSocketComponent()
MockStringSocket()=delete
std::function< std::unique_ptr< PluginRouter >(std::shared_ptr< rapidjson::Document >, udp::endpoint)> PluginRouterFactory
Component< SocketFactory > getMockStringUdpSourceComponent()