@@ -63,6 +63,9 @@ class CLASSNAME (TestGraphFixture, RMW_IMPLEMENTATION) : public ::testing::Test
6363 rcl_wait_set_t * wait_set_ptr;
6464 const char * test_graph_node_name = " test_graph_node" ;
6565
66+ rmw_topic_info_array_t * topic_info_array;
67+ const char * topic_name = " valid_topic_name" ;
68+
6669 void SetUp ()
6770 {
6871 rcl_ret_t ret;
@@ -101,6 +104,12 @@ class CLASSNAME (TestGraphFixture, RMW_IMPLEMENTATION) : public ::testing::Test
101104 ret = rcl_wait_set_init (
102105 this ->wait_set_ptr , 0 , 1 , 0 , 0 , 0 , 0 , this ->context_ptr , rcl_get_default_allocator ());
103106 ASSERT_EQ (RCL_RET_OK, ret) << rcl_get_error_string ().str ;
107+
108+ rmw_topic_info_array_t valid_topic_info_array = {
109+ 0 , /* count*/
110+ nullptr /* info_array*/
111+ };
112+ this ->topic_info_array = &valid_topic_info_array;
104113 }
105114
106115 void TearDown ()
@@ -1321,3 +1330,172 @@ TEST_F(CLASSNAME(TestGraphFixture, RMW_IMPLEMENTATION), test_rcl_service_server_
13211330 wait_for_service_state_to_change (false , is_available);
13221331 ASSERT_FALSE (is_available);
13231332}
1333+
1334+
1335+ /*
1336+ * This does not test content of the response.
1337+ * It only tests if the return code is the one expected.
1338+ */
1339+ TEST_F (CLASSNAME(TestGraphFixture, RMW_IMPLEMENTATION),
1340+ test_rcl_get_publishers_info_by_topic_null_node)
1341+ {
1342+ rcl_allocator_t allocator = rcl_get_default_allocator ();
1343+ auto ret = rcl_get_publishers_info_by_topic (nullptr ,
1344+ &allocator, this ->topic_name , false , this ->topic_info_array );
1345+ EXPECT_EQ (RCL_RET_NODE_INVALID, ret);
1346+ }
1347+
1348+ /*
1349+ * This does not test content of the response.
1350+ * It only tests if the return code is the one expected.
1351+ */
1352+ TEST_F (CLASSNAME(TestGraphFixture, RMW_IMPLEMENTATION),
1353+ test_rcl_get_subscriptions_info_by_topic_null_node)
1354+ {
1355+ rcl_allocator_t allocator = rcl_get_default_allocator ();
1356+ auto ret = rcl_get_subscriptions_info_by_topic (nullptr ,
1357+ &allocator, this ->topic_name , false , this ->topic_info_array );
1358+ EXPECT_EQ (RCL_RET_NODE_INVALID, ret);
1359+ }
1360+
1361+ /*
1362+ * This does not test content of the response.
1363+ * It only tests if the return code is the one expected.
1364+ */
1365+ TEST_F (CLASSNAME(TestGraphFixture, RMW_IMPLEMENTATION),
1366+ test_rcl_get_publishers_info_by_topic_invalid_node)
1367+ {
1368+ // this->old_node_ptr is a pointer to an invalid node.
1369+ rcl_allocator_t allocator = rcl_get_default_allocator ();
1370+ auto ret = rcl_get_publishers_info_by_topic (this ->old_node_ptr ,
1371+ &allocator, this ->topic_name , false , this ->topic_info_array );
1372+ EXPECT_EQ (RCL_RET_NODE_INVALID, ret);
1373+ }
1374+
1375+ /*
1376+ * This does not test content of the response.
1377+ * It only tests if the return code is the one expected.
1378+ */
1379+ TEST_F (CLASSNAME(TestGraphFixture, RMW_IMPLEMENTATION),
1380+ test_rcl_get_subscriptions_info_by_topic_invalid_node)
1381+ {
1382+ // this->old_node_ptr is a pointer to an invalid node.
1383+ rcl_allocator_t allocator = rcl_get_default_allocator ();
1384+ auto ret = rcl_get_subscriptions_info_by_topic (this ->old_node_ptr ,
1385+ &allocator, this ->topic_name , false , this ->topic_info_array );
1386+ EXPECT_EQ (RCL_RET_NODE_INVALID, ret);
1387+ }
1388+
1389+ /*
1390+ * This does not test content of the response.
1391+ * It only tests if the return code is the one expected.
1392+ */
1393+ TEST_F (CLASSNAME(TestGraphFixture, RMW_IMPLEMENTATION),
1394+ test_rcl_get_publishers_info_by_topic_null_allocator)
1395+ {
1396+ auto ret = rcl_get_publishers_info_by_topic (this ->node_ptr , nullptr , this ->topic_name , false ,
1397+ this ->topic_info_array );
1398+ EXPECT_EQ (RCL_RET_INVALID_ARGUMENT, ret);
1399+ }
1400+
1401+ /*
1402+ * This does not test content of the response.
1403+ * It only tests if the return code is the one expected.
1404+ */
1405+ TEST_F (CLASSNAME(TestGraphFixture, RMW_IMPLEMENTATION),
1406+ test_rcl_get_subscriptions_info_by_topic_null_allocator)
1407+ {
1408+ auto ret = rcl_get_subscriptions_info_by_topic (this ->node_ptr , nullptr , this ->topic_name , false ,
1409+ this ->topic_info_array );
1410+ EXPECT_EQ (RCL_RET_INVALID_ARGUMENT, ret);
1411+ }
1412+
1413+ /*
1414+ * This does not test content of the response.
1415+ * It only tests if the return code is the one expected.
1416+ */
1417+ TEST_F (CLASSNAME(TestGraphFixture, RMW_IMPLEMENTATION),
1418+ test_rcl_get_publishers_info_by_topic_null_topic)
1419+ {
1420+ rcl_allocator_t allocator = rcl_get_default_allocator ();
1421+ auto ret = rcl_get_publishers_info_by_topic (this ->node_ptr ,
1422+ &allocator, nullptr , false , this ->topic_info_array );
1423+ EXPECT_EQ (RCL_RET_INVALID_ARGUMENT, ret);
1424+ }
1425+
1426+ /*
1427+ * This does not test content of the response.
1428+ * It only tests if the return code is the one expected.
1429+ */
1430+ TEST_F (CLASSNAME(TestGraphFixture, RMW_IMPLEMENTATION),
1431+ test_rcl_get_subscriptions_info_by_topic_null_topic)
1432+ {
1433+ rcl_allocator_t allocator = rcl_get_default_allocator ();
1434+ auto ret = rcl_get_subscriptions_info_by_topic (this ->node_ptr ,
1435+ &allocator, nullptr , false , this ->topic_info_array );
1436+ EXPECT_EQ (RCL_RET_INVALID_ARGUMENT, ret);
1437+ }
1438+
1439+ /*
1440+ * This does not test content of the response.
1441+ * It only tests if the return code is the one expected.
1442+ */
1443+ TEST_F (CLASSNAME(TestGraphFixture, RMW_IMPLEMENTATION),
1444+ test_rcl_get_publishers_info_by_topic_null_participants)
1445+ {
1446+ rcl_allocator_t allocator = rcl_get_default_allocator ();
1447+ auto ret = rcl_get_publishers_info_by_topic (this ->node_ptr ,
1448+ &allocator, this ->topic_name , false , nullptr );
1449+ EXPECT_EQ (RCL_RET_INVALID_ARGUMENT, ret);
1450+ }
1451+
1452+ /*
1453+ * This does not test content of the response.
1454+ * It only tests if the return code is the one expected.
1455+ */
1456+ TEST_F (CLASSNAME(TestGraphFixture, RMW_IMPLEMENTATION),
1457+ test_rcl_get_subscriptions_info_by_topic_null_participants)
1458+ {
1459+ rcl_allocator_t allocator = rcl_get_default_allocator ();
1460+ auto ret = rcl_get_subscriptions_info_by_topic (this ->node_ptr ,
1461+ &allocator, this ->topic_name , false , nullptr );
1462+ EXPECT_EQ (RCL_RET_INVALID_ARGUMENT, ret);
1463+ }
1464+
1465+ /*
1466+ * This does not test content of the response.
1467+ * It only tests if the return code is the one expected.
1468+ */
1469+ TEST_F (CLASSNAME(TestGraphFixture, RMW_IMPLEMENTATION),
1470+ test_rcl_get_publishers_info_by_topic_invalid_participants)
1471+ {
1472+ // this participant is invalid as the pointer "participants" inside is expected to be null.
1473+ this ->topic_info_array ->info_array =
1474+ reinterpret_cast <rmw_topic_info_t *>(malloc (sizeof (rmw_topic_info_t *)));
1475+ OSRF_TESTING_TOOLS_CPP_SCOPE_EXIT ({
1476+ free (this ->topic_info_array ->info_array );
1477+ });
1478+ rcl_allocator_t allocator = rcl_get_default_allocator ();
1479+ auto ret = rcl_get_publishers_info_by_topic (this ->node_ptr ,
1480+ &allocator, this ->topic_name , false , this ->topic_info_array );
1481+ EXPECT_EQ (RCL_RET_INVALID_ARGUMENT, ret);
1482+ }
1483+
1484+ /*
1485+ * This does not test content of the response.
1486+ * It only tests if the return code is the one expected.
1487+ */
1488+ TEST_F (CLASSNAME(TestGraphFixture, RMW_IMPLEMENTATION),
1489+ test_rcl_get_subscriptions_info_by_topic_invalid_participants)
1490+ {
1491+ // this participant is invalid as the pointer "participants" inside is expected to be null.
1492+ this ->topic_info_array ->info_array =
1493+ reinterpret_cast <rmw_topic_info_t *>(malloc (sizeof (rmw_topic_info_t *)));
1494+ OSRF_TESTING_TOOLS_CPP_SCOPE_EXIT ({
1495+ free (this ->topic_info_array ->info_array );
1496+ });
1497+ rcl_allocator_t allocator = rcl_get_default_allocator ();
1498+ auto ret = rcl_get_subscriptions_info_by_topic (this ->node_ptr ,
1499+ &allocator, this ->topic_name , false , this ->topic_info_array );
1500+ EXPECT_EQ (RCL_RET_INVALID_ARGUMENT, ret);
1501+ }
0 commit comments