1 #include "../../src/plugin_router/binary_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/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_;
32 ASSISTED(udp::endpoint) target_socket,
33 ASSISTED(std::shared_ptr<std::function<
void(std::vector<uint8_t>)>>)
38 std::vector<uint8_t> vec{0, 1};
48 virtual void SendData(std::vector<uint8_t> data)
override {
49 for (
int i = 0; i < data.size(); i++) {
50 ASSERT_EQ(data[i], i);
60 Component<Annotated<BinaryAnnotation, PluginRouterFactory>>
62 return createComponent()
69 TEST(TestSuite, binary_plugin_try_start_with_invalid_xml) {
70 std::shared_ptr<rapidjson::Document> config(
new rapidjson::Document);
74 Injector<Annotated<BinaryAnnotation, PluginRouterFactory>> injector(
77 injector.get<Annotated<BinaryAnnotation, PluginRouterFactory>>();
79 auto source = pluginRouterFactory(config, udp::endpoint(udp::v4(), 0));
80 auto result = source->TryStart();
82 ASSERT_FALSE(result.is_success);
83 ASSERT_STREQ(result.error_message,
"invalid config parameters");
87 TEST(TestSuite, binary_plugin_try_start_not_found_plugin) {
88 std::shared_ptr<rapidjson::Document> config(
new rapidjson::Document);
90 "[{\"plugin_name\":\"binary_loopback::BinaryLoopback\",\"param\":"
92 "\"plugin_name\":\"not_found_plugin::NotFoundPlugin\"}]");
93 ROS_INFO(
"This test produces a ROS_ERROR message because of a loading error in the plugin, but the behavior is as expected.");
96 Injector<Annotated<BinaryAnnotation, PluginRouterFactory>> injector(
99 injector.get<Annotated<BinaryAnnotation, PluginRouterFactory>>();
101 auto source = pluginRouterFactory(config, udp::endpoint(udp::v4(), 0));
102 auto result = source->TryStart();
104 ASSERT_FALSE(result.is_success);
105 std::string error_message = result.error_message;
106 ASSERT_EQ(error_message.rfind(
"Failed to load"), 0);
110 TEST(TestSuite, binary_plugin_try_start_with_loopback_plugin) {
111 std::shared_ptr<rapidjson::Document> config(
new rapidjson::Document);
113 "[{\"plugin_name\":\"binary_loopback::BinaryLoopback\",\"param\":"
117 Injector<Annotated<BinaryAnnotation, PluginRouterFactory>> injector(
120 injector.get<Annotated<BinaryAnnotation, PluginRouterFactory>>();
122 auto source = pluginRouterFactory(config, udp::endpoint(udp::v4(), 0));
123 auto result = source->TryStart();
126 ASSERT_TRUE(result.is_success);