Skip to content

Commit

Permalink
keep NULL for the valid case and adapt tests
Browse files Browse the repository at this point in the history
Signed-off-by: Ethan Gao <ethan.gao@linux.intel.com>
  • Loading branch information
gaoethan committed Dec 19, 2017
1 parent 976a72d commit c49b6f7
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 72 deletions.
2 changes: 1 addition & 1 deletion rmw/src/validate_full_topic_name.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ rmw_full_topic_name_validation_result_string(int validation_result)
{
switch (validation_result) {
case RMW_TOPIC_VALID:
return "valid topic name";
return NULL;
case RMW_TOPIC_INVALID_IS_EMPTY_STRING:
return "topic name must not be empty";
case RMW_TOPIC_INVALID_NOT_ABSOLUTE:
Expand Down
2 changes: 1 addition & 1 deletion rmw/src/validate_namespace.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ rmw_namespace_validation_result_string(int validation_result)
{
switch (validation_result) {
case RMW_NAMESPACE_VALID:
return "valid namespace";
return NULL;
case RMW_NAMESPACE_INVALID_IS_EMPTY_STRING:
return "namespace must not be empty";
case RMW_NAMESPACE_INVALID_NOT_ABSOLUTE:
Expand Down
2 changes: 1 addition & 1 deletion rmw/src/validate_node_name.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ rmw_node_name_validation_result_string(int validation_result)
{
switch (validation_result) {
case RMW_NODE_NAME_VALID:
return "valid node name";
return NULL;
case RMW_NODE_NAME_INVALID_IS_EMPTY_STRING:
return "node name must not be empty";
case RMW_NODE_NAME_INVALID_CONTAINS_UNALLOWED_CHARACTERS:
Expand Down
34 changes: 8 additions & 26 deletions rmw/test/test_validate_full_topic_name.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ TEST(test_validate_topic_name, valid_topic) {
ASSERT_EQ(RMW_RET_OK, ret);
ASSERT_EQ(RMW_TOPIC_VALID, validation_result);

ret = strcmp("valid topic name", rmw_full_topic_name_validation_result_string(validation_result));
ASSERT_EQ(0, ret);
ASSERT_EQ((char *)nullptr, rmw_full_topic_name_validation_result_string(validation_result));
}

TEST(test_validate_topic_name, empty_topic_name) {
Expand All @@ -67,10 +66,7 @@ TEST(test_validate_topic_name, empty_topic_name) {
ASSERT_EQ(RMW_TOPIC_INVALID_IS_EMPTY_STRING, validation_result);
ASSERT_EQ(0ul, invalid_index);

ret =
strcmp("topic name must not be empty", rmw_full_topic_name_validation_result_string(
validation_result));
ASSERT_EQ(0, ret);
ASSERT_NE((char *)nullptr, rmw_full_topic_name_validation_result_string(validation_result));
}

TEST(test_validate_topic_name, not_absolute) {
Expand All @@ -94,9 +90,7 @@ TEST(test_validate_topic_name, not_absolute) {
ASSERT_EQ(RMW_TOPIC_INVALID_NOT_ABSOLUTE, validation_result);
ASSERT_EQ(0ul, invalid_index);

ret = strcmp("topic name must be absolute, it must lead with a '/'",
rmw_full_topic_name_validation_result_string(validation_result));
ASSERT_EQ(0, ret);
ASSERT_NE((char *)nullptr, rmw_full_topic_name_validation_result_string(validation_result));
}

TEST(test_validate_topic_name, ends_with_forward_slash) {
Expand All @@ -120,10 +114,7 @@ TEST(test_validate_topic_name, ends_with_forward_slash) {
ASSERT_EQ(RMW_TOPIC_INVALID_ENDS_WITH_FORWARD_SLASH, validation_result);
ASSERT_EQ(0ul, invalid_index);

ret =
strcmp("topic name must not end with a '/'", rmw_full_topic_name_validation_result_string(
validation_result));
ASSERT_EQ(0, ret);
ASSERT_NE((char *)nullptr, rmw_full_topic_name_validation_result_string(validation_result));
}

TEST(test_validate_topic_name, unallowed_characters) {
Expand Down Expand Up @@ -157,9 +148,7 @@ TEST(test_validate_topic_name, unallowed_characters) {
ASSERT_EQ(RMW_TOPIC_INVALID_CONTAINS_UNALLOWED_CHARACTERS, validation_result);
ASSERT_EQ(5ul, invalid_index);

ret = strcmp("topic name must not contain characters other than alphanumerics, '_', or '/'",
rmw_full_topic_name_validation_result_string(validation_result));
ASSERT_EQ(0, ret);
ASSERT_NE((char *)nullptr, rmw_full_topic_name_validation_result_string(validation_result));
}

TEST(test_validate_topic_name, repeated_forward_slashes) {
Expand All @@ -178,9 +167,7 @@ TEST(test_validate_topic_name, repeated_forward_slashes) {
ASSERT_EQ(RMW_TOPIC_INVALID_CONTAINS_REPEATED_FORWARD_SLASH, validation_result);
ASSERT_EQ(10ul, invalid_index);

ret = strcmp("topic name must not contain repeated '/'",
rmw_full_topic_name_validation_result_string(validation_result));
ASSERT_EQ(0, ret);
ASSERT_NE((char *)nullptr, rmw_full_topic_name_validation_result_string(validation_result));
}

TEST(test_validate_topic_name, starts_with_number) {
Expand All @@ -204,9 +191,7 @@ TEST(test_validate_topic_name, starts_with_number) {
ASSERT_EQ(RMW_TOPIC_INVALID_NAME_TOKEN_STARTS_WITH_NUMBER, validation_result);
ASSERT_EQ(8ul, invalid_index);

ret = strcmp("topic name must not have a token that starts with a number",
rmw_full_topic_name_validation_result_string(validation_result));
ASSERT_EQ(0, ret);
ASSERT_NE((char *)nullptr, rmw_full_topic_name_validation_result_string(validation_result));
}

TEST(test_validate_topic_name, topic_too_long) {
Expand Down Expand Up @@ -243,8 +228,5 @@ TEST(test_validate_topic_name, topic_too_long) {
EXPECT_EQ(RMW_TOPIC_INVALID_TOO_LONG, validation_result);
EXPECT_EQ(RMW_TOPIC_MAX_NAME_LENGTH - 1, invalid_index);

const char * result_string = "topic length should not exceed '" RMW_STRINGIFY(
RMW_TOPIC_MAX_NAME_LENGTH) "'";
ret = strcmp(result_string, rmw_full_topic_name_validation_result_string(validation_result));
ASSERT_EQ(0, ret);
ASSERT_NE((char *)nullptr, rmw_full_topic_name_validation_result_string(validation_result));
}
34 changes: 8 additions & 26 deletions rmw/test/test_validate_namespace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ TEST(test_validate_namespace, valid_namespace) {
ASSERT_EQ(RMW_RET_OK, ret);
ASSERT_EQ(RMW_NAMESPACE_VALID, validation_result);

ret = strcmp("valid namespace", rmw_namespace_validation_result_string(validation_result));
ASSERT_EQ(0, ret);
ASSERT_EQ((char *)nullptr, rmw_namespace_validation_result_string(validation_result));
}

TEST(test_validate_namespace, empty_namespace) {
Expand All @@ -72,10 +71,7 @@ TEST(test_validate_namespace, empty_namespace) {
ASSERT_EQ(RMW_NAMESPACE_INVALID_IS_EMPTY_STRING, validation_result);
ASSERT_EQ(0ul, invalid_index);

ret =
strcmp("namespace must not be empty",
rmw_namespace_validation_result_string(validation_result));
ASSERT_EQ(0, ret);
ASSERT_NE((char *)nullptr, rmw_namespace_validation_result_string(validation_result));
}

TEST(test_validate_namespace, not_absolute) {
Expand All @@ -99,9 +95,7 @@ TEST(test_validate_namespace, not_absolute) {
ASSERT_EQ(RMW_NAMESPACE_INVALID_NOT_ABSOLUTE, validation_result);
ASSERT_EQ(0ul, invalid_index);

ret = strcmp("namespace must be absolute, it must lead with a '/'",
rmw_namespace_validation_result_string(validation_result));
ASSERT_EQ(0, ret);
ASSERT_NE((char *)nullptr, rmw_namespace_validation_result_string(validation_result));
}

TEST(test_validate_namespace, ends_with_forward_slash) {
Expand All @@ -120,9 +114,7 @@ TEST(test_validate_namespace, ends_with_forward_slash) {
ASSERT_EQ(RMW_NAMESPACE_INVALID_ENDS_WITH_FORWARD_SLASH, validation_result);
ASSERT_EQ(10ul, invalid_index);

ret = strcmp("namespace must not end with a '/', unless only a '/'",
rmw_namespace_validation_result_string(validation_result));
ASSERT_EQ(0, ret);
ASSERT_NE((char *)nullptr, rmw_namespace_validation_result_string(validation_result));
}

TEST(test_validate_namespace, unallowed_characters) {
Expand Down Expand Up @@ -156,9 +148,7 @@ TEST(test_validate_namespace, unallowed_characters) {
ASSERT_EQ(RMW_NAMESPACE_INVALID_CONTAINS_UNALLOWED_CHARACTERS, validation_result);
ASSERT_EQ(5ul, invalid_index);

ret = strcmp("namespace must not contain characters other than alphanumerics, '_', or '/'",
rmw_namespace_validation_result_string(validation_result));
ASSERT_EQ(0, ret);
ASSERT_NE((char *)nullptr, rmw_namespace_validation_result_string(validation_result));
}

TEST(test_validate_namespace, repeated_forward_slashes) {
Expand All @@ -177,10 +167,7 @@ TEST(test_validate_namespace, repeated_forward_slashes) {
ASSERT_EQ(RMW_NAMESPACE_INVALID_CONTAINS_REPEATED_FORWARD_SLASH, validation_result);
ASSERT_EQ(10ul, invalid_index);

ret =
strcmp("namespace must not contain repeated '/'", rmw_namespace_validation_result_string(
validation_result));
ASSERT_EQ(0, ret);
ASSERT_NE((char *)nullptr, rmw_namespace_validation_result_string(validation_result));
}

TEST(test_validate_namespace, starts_with_number) {
Expand All @@ -204,9 +191,7 @@ TEST(test_validate_namespace, starts_with_number) {
ASSERT_EQ(RMW_NAMESPACE_INVALID_NAME_TOKEN_STARTS_WITH_NUMBER, validation_result);
ASSERT_EQ(8ul, invalid_index);

ret = strcmp("namespace must not have a token that starts with a number",
rmw_namespace_validation_result_string(validation_result));
ASSERT_EQ(0, ret);
ASSERT_NE((char *)nullptr, rmw_namespace_validation_result_string(validation_result));
}

TEST(test_validate_namespace, topic_too_long) {
Expand Down Expand Up @@ -243,8 +228,5 @@ TEST(test_validate_namespace, topic_too_long) {
EXPECT_EQ(RMW_NAMESPACE_INVALID_TOO_LONG, validation_result);
EXPECT_EQ(RMW_NAMESPACE_MAX_LENGTH - 1, invalid_index);

const char * result_string = "namespace should not exceed '" RMW_STRINGIFY(
RMW_NAMESPACE_MAX_NAME_LENGTH) "'";
ret = strcmp(result_string, rmw_namespace_validation_result_string(validation_result));
ASSERT_EQ(0, ret);
ASSERT_NE((char *)nullptr, rmw_namespace_validation_result_string(validation_result));
}
22 changes: 5 additions & 17 deletions rmw/test/test_validate_node_name.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ TEST(test_validate_node_name, valid_node_name) {
ASSERT_EQ(RMW_RET_OK, ret);
ASSERT_EQ(RMW_NODE_NAME_VALID, validation_result);

ret = strcmp("valid node name", rmw_node_name_validation_result_string(validation_result));
ASSERT_EQ(0, ret);
ASSERT_EQ((char *)nullptr, rmw_node_name_validation_result_string(validation_result));
}

TEST(test_validate_node_name, empty_node_name) {
Expand All @@ -67,10 +66,7 @@ TEST(test_validate_node_name, empty_node_name) {
ASSERT_EQ(RMW_NODE_NAME_INVALID_IS_EMPTY_STRING, validation_result);
ASSERT_EQ(0ul, invalid_index);

ret =
strcmp("node name must not be empty",
rmw_node_name_validation_result_string(validation_result));
ASSERT_EQ(0, ret);
ASSERT_NE((char *)nullptr, rmw_node_name_validation_result_string(validation_result));
}

TEST(test_validate_node_name, unallowed_characters) {
Expand Down Expand Up @@ -109,9 +105,7 @@ TEST(test_validate_node_name, unallowed_characters) {
ASSERT_EQ(RMW_NODE_NAME_INVALID_CONTAINS_UNALLOWED_CHARACTERS, validation_result);
ASSERT_EQ(4ul, invalid_index);

ret = strcmp("node name must not contain characters other than alphanumerics or '_'",
rmw_node_name_validation_result_string(validation_result));
ASSERT_EQ(0, ret);
ASSERT_NE((char *)nullptr, rmw_node_name_validation_result_string(validation_result));
}

TEST(test_validate_node_name, starts_with_number) {
Expand All @@ -130,10 +124,7 @@ TEST(test_validate_node_name, starts_with_number) {
ASSERT_EQ(RMW_NODE_NAME_INVALID_STARTS_WITH_NUMBER, validation_result);
ASSERT_EQ(0ul, invalid_index);

ret =
strcmp("node name must not start with a number", rmw_node_name_validation_result_string(
validation_result));
ASSERT_EQ(0, ret);
ASSERT_NE((char *)nullptr, rmw_node_name_validation_result_string(validation_result));
}

TEST(test_validate_node_name, node_name_too_long) {
Expand Down Expand Up @@ -171,8 +162,5 @@ TEST(test_validate_node_name, node_name_too_long) {
EXPECT_EQ(RMW_NODE_NAME_INVALID_TOO_LONG, validation_result);
EXPECT_EQ(RMW_NODE_NAME_MAX_NAME_LENGTH - 1U, invalid_index);

const char * result_string = "node name length should not exceed '" RMW_STRINGIFY(
RMW_NODE_NAME_MAX_NAME_LENGTH) "'";
ret = strcmp(result_string, rmw_node_name_validation_result_string(validation_result));
ASSERT_EQ(0, ret);
ASSERT_NE((char *)nullptr, rmw_node_name_validation_result_string(validation_result));
}

0 comments on commit c49b6f7

Please sign in to comment.