@@ -234,6 +234,36 @@ TEST(TestHandle, interface_description_bool_data_type)
234234 ASSERT_THROW ({ std::ignore = handle.get_optional <double >(); }, std::runtime_error);
235235}
236236
237+ TEST (TestHandle, interface_description_bool_data_type_copy)
238+ {
239+ const std::string collision_interface = " collision" ;
240+ const std::string itf_name = " joint1" ;
241+ InterfaceInfo info;
242+ info.name = collision_interface;
243+ info.data_type = " bool" ;
244+ InterfaceDescription interface_descr (itf_name, info);
245+ StateInterface handle{interface_descr};
246+
247+ auto handle_copy = handle; // Copy constructor
248+
249+ ASSERT_EQ (hardware_interface::HandleDataType::BOOL, interface_descr.get_data_type ());
250+ ASSERT_EQ (hardware_interface::HandleDataType::BOOL, handle_copy.get_data_type ());
251+ EXPECT_EQ (handle_copy.get_name (), itf_name + " /" + collision_interface);
252+ EXPECT_EQ (handle_copy.get_interface_name (), collision_interface);
253+ EXPECT_EQ (handle_copy.get_prefix_name (), itf_name);
254+ EXPECT_NO_THROW ({ std::ignore = handle_copy.get_optional <bool >(); });
255+ ASSERT_FALSE (handle_copy.get_optional <bool >().value ()) << " Default value should be false" ;
256+ ASSERT_TRUE (handle_copy.set_value (true ));
257+ ASSERT_TRUE (handle_copy.get_optional <bool >().value ());
258+ ASSERT_TRUE (handle_copy.set_value (false ));
259+ ASSERT_FALSE (handle_copy.get_optional <bool >().value ());
260+
261+ // Test the assertions
262+ ASSERT_THROW ({ std::ignore = handle.set_value (-1.0 ); }, std::runtime_error);
263+ ASSERT_THROW ({ std::ignore = handle.set_value (0.0 ); }, std::runtime_error);
264+ EXPECT_THROW ({ std::ignore = handle.get_optional <double >(); }, std::runtime_error);
265+ }
266+
237267TEST (TestHandle, handle_constructor_double_data_type)
238268{
239269 const std::string POSITION_INTERFACE = " position" ;
0 commit comments