@@ -245,6 +245,39 @@ TEST(TestHandle, interface_description_bool_data_type)
245245 EXPECT_NO_THROW ({ std::ignore = handle.get_optional <double >(); });
246246}
247247
248+ TEST (TestHandle, interface_description_bool_data_type_copy)
249+ {
250+ const std::string collision_interface = " collision" ;
251+ const std::string itf_name = " joint1" ;
252+ InterfaceInfo info;
253+ info.name = collision_interface;
254+ info.data_type = " bool" ;
255+ InterfaceDescription interface_descr (itf_name, info);
256+ StateInterface handle{interface_descr};
257+
258+ auto handle_copy = handle; // Copy constructor
259+
260+ ASSERT_EQ (hardware_interface::HandleDataType::BOOL, interface_descr.get_data_type ());
261+ ASSERT_EQ (hardware_interface::HandleDataType::BOOL, handle_copy.get_data_type ());
262+ EXPECT_EQ (handle_copy.get_name (), itf_name + " /" + collision_interface);
263+ EXPECT_EQ (handle_copy.get_interface_name (), collision_interface);
264+ EXPECT_EQ (handle_copy.get_prefix_name (), itf_name);
265+ EXPECT_NO_THROW ({ std::ignore = handle_copy.get_optional <bool >(); });
266+ ASSERT_FALSE (handle_copy.get_optional <bool >().value ()) << " Default value should be false" ;
267+ ASSERT_TRUE (handle_copy.set_value (true ));
268+ ASSERT_TRUE (handle_copy.get_optional <bool >().value ());
269+ ASSERT_EQ (handle_copy.get_optional (), 1.0 );
270+ ASSERT_TRUE (handle_copy.set_value (false ));
271+ ASSERT_FALSE (handle_copy.get_optional <bool >().value ());
272+ ASSERT_EQ (handle_copy.get_optional (), 0.0 );
273+
274+ // Test the assertions
275+ ASSERT_THROW ({ std::ignore = handle.set_value (-1.0 ); }, std::runtime_error);
276+ ASSERT_THROW ({ std::ignore = handle.set_value (0.0 ); }, std::runtime_error);
277+
278+ EXPECT_NO_THROW ({ std::ignore = handle.get_optional <double >(); });
279+ }
280+
248281TEST (TestHandle, handle_constructor_double_data_type)
249282{
250283 const std::string POSITION_INTERFACE = " position" ;
0 commit comments