@@ -227,61 +227,71 @@ TEST_F(TestLocalTransceiver, parseInMsgValid)
227227 EXPECT_EQ (parsed_test.waypoints [1 ].longitude , holder);
228228}
229229
230- // std::mutex port_mutex;
231-
232- // TEST_F(TestLocalTransceiver, testMailboxBlackbox)
233- // {
234- // std::lock_guard<std::mutex> lock(port_mutex); // because same port is being used
235-
236- // std::string holder = "curl -X POST -F \"test=1234\" http://localhost:8080";
237- // std::string holder2 = "printf \"at+sbdix\r\" > $LOCAL_TRANSCEIVER_TEST_PORT";
238-
239- // system(holder.c_str()); //NOLINT
240- // system(holder2.c_str()); //NOLINT
241-
242- // std::optional<std::string> response = lcl_trns_->readRsp();
243- // std::cout << *response << std::endl;
244- // }
245-
246- // TEST_F(TestLocalTransceiver, parseReceiveMessageBlackbox)
247- // {
248- // std::lock_guard<std::mutex> lock(port_mutex);
249-
250- // constexpr float holder = 14.3;
251- // Polaris::GlobalPath sample_data;
252-
253- // Polaris::Waypoint * waypoint_a = sample_data.add_waypoints();
254- // waypoint_a->set_latitude(holder);
255- // waypoint_a->set_longitude(holder);
256- // Polaris::Waypoint * waypoint_b = sample_data.add_waypoints();
257- // waypoint_b->set_latitude(holder);
258- // waypoint_b->set_longitude(holder);
259-
260- // std::string serialized_data;
261- // ASSERT_TRUE(sample_data.SerializeToString(&serialized_data));
262-
263- // std::ofstream outfile("/tmp/serialized_data.bin", std::ios::binary);
264- // outfile.write(serialized_data.data(), static_cast<std::streamsize>(serialized_data.size()));
265- // outfile.close();
266-
267- // std::string holder2 = "curl -X POST -F \"data=@/tmp/serialized_data.bin\" http://localhost:8080";
268- // std::system(holder2.c_str()); //NOLINT
269-
270- // custom_interfaces::msg::Path received_data = lcl_trns_->receive();
271-
272- // Polaris::GlobalPath global_path;
273- // for (const auto & waypoint : received_data.waypoints) {
274- // Polaris::Waypoint * new_waypoint = global_path.add_waypoints();
275- // new_waypoint->set_latitude(waypoint.latitude);
276- // new_waypoint->set_longitude(waypoint.longitude);
277- // }
278-
279- // if (global_path.waypoints_size() > 0) {
280- // ASSERT_EQ(global_path.waypoints_size(), sample_data.waypoints_size())
281- // << "Mismatch in number of waypoints received.";
282- // ASSERT_EQ(global_path.waypoints(0).latitude(), holder);
283- // ASSERT_EQ(global_path.waypoints(0).longitude(), holder);
284- // } else {
285- // std::cout << "No waypoints received." << std::endl;
286- // }
287- // }
230+ std::mutex port_mutex;
231+
232+ TEST_F (TestLocalTransceiver, testMailboxBlackbox)
233+ {
234+ std::lock_guard<std::mutex> lock (port_mutex); // because same port is being used
235+
236+ std::string holder = " curl -X POST -F \" test=1234\" http://localhost:8080" ;
237+ std::string holder2 = " printf \" at+sbdix\r\" > $LOCAL_TRANSCEIVER_TEST_PORT" ;
238+
239+ system (holder.c_str ()); // NOLINT
240+ system (holder2.c_str ()); // NOLINT
241+
242+ std::optional<std::string> response = lcl_trns_->readRsp ();
243+ std::cout << *response << std::endl;
244+ }
245+
246+ TEST_F (TestLocalTransceiver, parseReceiveMessageBlackbox)
247+ {
248+ std::lock_guard<std::mutex> lock (port_mutex);
249+
250+ constexpr float holder = 10.3 ;
251+ Polaris::GlobalPath sample_data;
252+
253+ Polaris::Waypoint * waypoint_a = sample_data.add_waypoints ();
254+ waypoint_a->set_latitude (holder);
255+ waypoint_a->set_longitude (holder);
256+ Polaris::Waypoint * waypoint_b = sample_data.add_waypoints ();
257+ waypoint_b->set_latitude (holder);
258+ waypoint_b->set_longitude (holder);
259+
260+ std::string serialized_data;
261+ ASSERT_TRUE (sample_data.SerializeToString (&serialized_data));
262+
263+ uint16_t message_size = static_cast <uint16_t >(serialized_data.size ());
264+ uint16_t message_size_be = htons (message_size); // Convert to big-endian
265+
266+ std::string size_prefix (reinterpret_cast <const char *>(&message_size_be), sizeof (message_size_be));
267+
268+ std::ofstream outfile (" /tmp/serialized_data.bin" , std::ios::binary);
269+ outfile.write (size_prefix.data (), size_prefix.size ()); // NOLINT
270+ outfile.write (serialized_data.data (), static_cast <std::streamsize>(serialized_data.size ()));
271+ outfile.close ();
272+
273+ outfile.close (); // Close the file after writing
274+
275+ std::string holder2 = " curl -X POST --data-binary @/tmp/serialized_data.bin http://localhost:8080" ;
276+ std::system (holder2.c_str ()); // NOLINT
277+ std::string test_cmd = " hexdump -C /tmp/serialized_data.bin" ;
278+ std::system (test_cmd.c_str ()); // NOLINT
279+
280+ custom_interfaces::msg::Path received_data = lcl_trns_->receive ();
281+
282+ Polaris::GlobalPath global_path;
283+ for (const auto & waypoint : received_data.waypoints ) {
284+ Polaris::Waypoint * new_waypoint = global_path.add_waypoints ();
285+ new_waypoint->set_latitude (waypoint.latitude );
286+ new_waypoint->set_longitude (waypoint.longitude );
287+ }
288+
289+ if (global_path.waypoints_size () > 0 ) {
290+ ASSERT_EQ (global_path.waypoints_size (), sample_data.waypoints_size ())
291+ << " Mismatch in number of waypoints received." ;
292+ ASSERT_EQ (global_path.waypoints (0 ).latitude (), holder);
293+ ASSERT_EQ (global_path.waypoints (0 ).longitude (), holder);
294+ } else {
295+ std::cout << " No waypoints received." << std::endl;
296+ }
297+ }
0 commit comments