Skip to content

Commit

Permalink
Fix up test_network_flow_endpoints. (#912)
Browse files Browse the repository at this point in the history
It was using google test in a slightly strange way, and it
was also using unnecessary intermediate booleans.  Clean
that up here.

Signed-off-by: Chris Lalancette <clalancette@openrobotics.org>
  • Loading branch information
clalancette authored Apr 22, 2021
1 parent 6047547 commit 1aa50bc
Showing 1 changed file with 19 additions and 37 deletions.
56 changes: 19 additions & 37 deletions rcl/test/rcl/test_network_flow_endpoints.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,9 @@ class CLASSNAME (TestPublisherNetworkFlowEndpoints, RMW_IMPLEMENTATION)
ret = rcl_publisher_init(
&publisher_2, this->node_ptr, ts, topic_2,
&publisher_2_options);
ASSERT_EQ(
ret == RCL_RET_OK || ret == RCL_RET_UNSUPPORTED || ret == RCL_RET_ERROR,
true) << rcl_get_error_string().str;
ASSERT_TRUE(
ret == RCL_RET_OK || ret == RCL_RET_UNSUPPORTED ||
ret == RCL_RET_ERROR) << rcl_get_error_string().str;
rcl_reset_error();

publisher_3 = rcl_get_zero_initialized_publisher();
Expand Down Expand Up @@ -175,9 +175,9 @@ class CLASSNAME (TestSubscriptionNetworkFlowEndpoints, RMW_IMPLEMENTATION)
ret = rcl_subscription_init(
&subscription_2, this->node_ptr, ts, topic_2,
&subscription_2_options);
ASSERT_EQ(
ret == RCL_RET_OK || ret == RCL_RET_UNSUPPORTED || ret == RCL_RET_ERROR,
true) << rcl_get_error_string().str;
ASSERT_TRUE(
ret == RCL_RET_OK || ret == RCL_RET_UNSUPPORTED ||
ret == RCL_RET_ERROR) << rcl_get_error_string().str;
rcl_reset_error();

subscription_3 = rcl_get_zero_initialized_subscription();
Expand Down Expand Up @@ -218,33 +218,33 @@ TEST_F(
// Invalid publisher
ret = rcl_publisher_get_network_flow_endpoints(
nullptr, &allocator, &network_flow_endpoint_array);
EXPECT_EQ(ret == RCL_RET_INVALID_ARGUMENT || ret == RCL_RET_UNSUPPORTED, true);
EXPECT_TRUE(ret == RCL_RET_INVALID_ARGUMENT || ret == RCL_RET_UNSUPPORTED);
rcl_reset_error();

// Invalid allocator
ret = rcl_publisher_get_network_flow_endpoints(
&this->publisher_1, nullptr, &network_flow_endpoint_array);
EXPECT_EQ(ret == RCL_RET_INVALID_ARGUMENT || ret == RCL_RET_UNSUPPORTED, true);
EXPECT_TRUE(ret == RCL_RET_INVALID_ARGUMENT || ret == RCL_RET_UNSUPPORTED);
rcl_reset_error();

// Invalid network_flow_endpoint_array
ret = rcl_publisher_get_network_flow_endpoints(
&this->publisher_1, &allocator, nullptr);
EXPECT_EQ(ret == RCL_RET_INVALID_ARGUMENT || ret == RCL_RET_UNSUPPORTED, true);
EXPECT_TRUE(ret == RCL_RET_INVALID_ARGUMENT || ret == RCL_RET_UNSUPPORTED);
rcl_reset_error();

// Failing allocator
set_failing_allocator_is_failing(failing_allocator, true);
ret = rcl_publisher_get_network_flow_endpoints(
&this->publisher_1, &failing_allocator, &network_flow_endpoint_array);
EXPECT_EQ(ret == RCL_RET_BAD_ALLOC || ret == RCL_RET_UNSUPPORTED, true);
EXPECT_TRUE(ret == RCL_RET_BAD_ALLOC || ret == RCL_RET_UNSUPPORTED);
rcl_reset_error();

// Non-zero network_flow_endpoint_array
network_flow_endpoint_array.size = 1;
ret = rcl_publisher_get_network_flow_endpoints(
&this->publisher_1, &allocator, &network_flow_endpoint_array);
EXPECT_EQ(ret == RCL_RET_ERROR || ret == RCL_RET_UNSUPPORTED, true);
EXPECT_TRUE(ret == RCL_RET_ERROR || ret == RCL_RET_UNSUPPORTED);
rcl_reset_error();
}

Expand All @@ -254,19 +254,14 @@ TEST_F(
RMW_IMPLEMENTATION), test_publisher_get_network_flow_endpoints) {
rcl_ret_t ret_1;
rcl_ret_t ret_2;
bool flag = false;
rcl_allocator_t allocator = rcl_get_default_allocator();

// Get network flow endpoints of ordinary publisher
rcl_network_flow_endpoint_array_t network_flow_endpoint_array_1 =
rcl_get_zero_initialized_network_flow_endpoint_array();
ret_1 = rcl_publisher_get_network_flow_endpoints(
&this->publisher_1, &allocator, &network_flow_endpoint_array_1);
if (ret_1 == RCL_RET_OK || ret_1 == RCL_RET_UNSUPPORTED) {
flag = true;
}
EXPECT_EQ(true, flag);
flag = false;
EXPECT_TRUE(ret_1 == RCL_RET_OK || ret_1 == RCL_RET_UNSUPPORTED);

// Get network flow endpoints of publisher with unique network flow endpoints
rcl_network_flow_endpoint_array_t network_flow_endpoint_array_2 =
Expand All @@ -276,11 +271,7 @@ TEST_F(
rcl_get_zero_initialized_network_flow_endpoint_array();
ret_2 = rcl_publisher_get_network_flow_endpoints(
&this->publisher_2, &allocator, &network_flow_endpoint_array_2);
if (ret_2 == RCL_RET_OK || ret_2 == RCL_RET_UNSUPPORTED) {
flag = true;
}
EXPECT_EQ(true, flag);
flag = false;
EXPECT_TRUE(ret_2 == RCL_RET_OK || ret_2 == RCL_RET_UNSUPPORTED);
} else {
ret_2 = RCL_RET_ERROR;
}
Expand Down Expand Up @@ -336,27 +327,27 @@ TEST_F(
// Invalid allocator
ret = rcl_subscription_get_network_flow_endpoints(
&this->subscription_1, nullptr, &network_flow_endpoint_array);
EXPECT_EQ(ret == RCL_RET_INVALID_ARGUMENT || ret == RCL_RET_UNSUPPORTED, true);
EXPECT_TRUE(ret == RCL_RET_INVALID_ARGUMENT || ret == RCL_RET_UNSUPPORTED);
rcl_reset_error();

// Invalid network_flow_endpoint_array
ret = rcl_subscription_get_network_flow_endpoints(
&this->subscription_1, &allocator, nullptr);
EXPECT_EQ(ret == RCL_RET_INVALID_ARGUMENT || ret == RCL_RET_UNSUPPORTED, true);
EXPECT_TRUE(ret == RCL_RET_INVALID_ARGUMENT || ret == RCL_RET_UNSUPPORTED);
rcl_reset_error();

// Failing allocator
set_failing_allocator_is_failing(failing_allocator, true);
ret = rcl_subscription_get_network_flow_endpoints(
&this->subscription_1, &failing_allocator, &network_flow_endpoint_array);
EXPECT_EQ(ret == RCL_RET_BAD_ALLOC || ret == RCL_RET_UNSUPPORTED, true);
EXPECT_TRUE(ret == RCL_RET_BAD_ALLOC || ret == RCL_RET_UNSUPPORTED);
rcl_reset_error();

// Non-zero network_flow_endpoint_array
network_flow_endpoint_array.size = 1;
ret = rcl_subscription_get_network_flow_endpoints(
&this->subscription_1, &allocator, &network_flow_endpoint_array);
EXPECT_EQ(ret == RCL_RET_ERROR || ret == RCL_RET_UNSUPPORTED, true);
EXPECT_TRUE(ret == RCL_RET_ERROR || ret == RCL_RET_UNSUPPORTED);
rcl_reset_error();
}

Expand All @@ -366,19 +357,14 @@ TEST_F(
RMW_IMPLEMENTATION), test_subscription_get_network_flow_endpoints) {
rcl_ret_t ret_1;
rcl_ret_t ret_2;
bool flag = false;
rcl_allocator_t allocator = rcl_get_default_allocator();

// Get network flow endpoints of ordinary subscription
rcl_network_flow_endpoint_array_t network_flow_endpoint_array_1 =
rcl_get_zero_initialized_network_flow_endpoint_array();
ret_1 = rcl_subscription_get_network_flow_endpoints(
&this->subscription_1, &allocator, &network_flow_endpoint_array_1);
if (ret_1 == RCL_RET_OK || ret_1 == RCL_RET_UNSUPPORTED) {
flag = true;
}
EXPECT_EQ(true, flag);
flag = false;
EXPECT_TRUE(ret_1 == RCL_RET_OK || ret_1 == RCL_RET_UNSUPPORTED);

// Get network flow endpoints of subscription with unique network flow endpoints
rcl_network_flow_endpoint_array_t network_flow_endpoint_array_2 =
Expand All @@ -388,11 +374,7 @@ TEST_F(
rcl_get_zero_initialized_network_flow_endpoint_array();
ret_2 = rcl_subscription_get_network_flow_endpoints(
&this->subscription_2, &allocator, &network_flow_endpoint_array_2);
if (ret_2 == RCL_RET_OK || ret_2 == RCL_RET_UNSUPPORTED) {
flag = true;
}
EXPECT_EQ(true, flag);
flag = false;
EXPECT_TRUE(ret_2 == RCL_RET_OK || ret_2 == RCL_RET_UNSUPPORTED);
} else {
ret_2 = RCL_RET_ERROR;
}
Expand Down

0 comments on commit 1aa50bc

Please sign in to comment.