adapt to NULL removal from rmw result validation string (#193)

* adapt to NULL removal from rmw result valiation string

Signed-off-by: Ethan Gao <ethan.gao@linux.intel.com>

* adapt to rmw validation change and update rcl topic validation

Signed-off-by: Ethan Gao <ethan.gao@linux.intel.com>

* tweak the default error string returned

Signed-off-by: Ethan Gao <ethan.gao@linux.intel.com>

* tweak error output format

Signed-off-by: Ethan Gao <ethan.gao@linux.intel.com>

* fix build error

Signed-off-by: Ethan Gao <ethan.gao@linux.intel.com>
This commit is contained in:
Ethan Gao 2018-01-09 03:02:03 +08:00 committed by Mikael Arguedas
parent 0d6ec7728c
commit 34a4a728ab
3 changed files with 10 additions and 18 deletions

View file

@ -27,6 +27,7 @@ extern "C"
#include "rcl/error_handling.h"
#include "rcl/rcl.h"
#include "rcutils/filesystem.h"
#include "rcutils/format_string.h"
#include "rcutils/get_env.h"
#include "rcutils/logging_macros.h"
#include "rcutils/macros.h"
@ -128,9 +129,6 @@ rcl_node_init(
}
if (validation_result != RMW_NODE_NAME_VALID) {
const char * msg = rmw_node_name_validation_result_string(validation_result);
if (!msg) {
msg = "unknown validation_result, this should not happen";
}
RCL_SET_ERROR_MSG(msg, *allocator);
return RCL_RET_NODE_INVALID_NAME;
}
@ -169,15 +167,7 @@ rcl_node_init(
}
if (validation_result != RMW_NAMESPACE_VALID) {
const char * msg = rmw_namespace_validation_result_string(validation_result);
if (!msg) {
char fixed_msg[256];
rcutils_snprintf(
fixed_msg, sizeof(fixed_msg),
"unknown validation_result '%d', this should not happen", validation_result);
RCL_SET_ERROR_MSG(fixed_msg, *allocator);
} else {
RCL_SET_ERROR_MSG(msg, *allocator);
}
RCL_SET_ERROR_MSG_WITH_FORMAT_STRING((*allocator), "%s, result: %d", msg, validation_result);
if (should_free_local_namespace_) {
allocator->deallocate((char *)local_namespace_, allocator->state);

View file

@ -193,6 +193,8 @@ const char *
rcl_topic_name_validation_result_string(int validation_result)
{
switch (validation_result) {
case RCL_TOPIC_NAME_VALID:
return NULL;
case RCL_TOPIC_NAME_INVALID_IS_EMPTY_STRING:
return "topic name must not be empty string";
case RCL_TOPIC_NAME_INVALID_ENDS_WITH_FORWARD_SLASH:
@ -213,7 +215,7 @@ rcl_topic_name_validation_result_string(int validation_result)
case RCL_TOPIC_NAME_INVALID_SUBSTITUTION_STARTS_WITH_NUMBER:
return "substitution name must not start with a number";
default:
return NULL;
return "unknown result code for rcl topic name validation";
}
}

View file

@ -28,10 +28,10 @@ TEST(test_validate_topic_name, normal) {
// passing without invalid_index
{
int validation_result;
ret = rcl_validate_topic_name("topic", &validation_result, NULL);
ret = rcl_validate_topic_name("topic", &validation_result, nullptr);
EXPECT_EQ(RCL_RET_OK, ret) << rcl_get_error_string_safe();
EXPECT_EQ(RCL_TOPIC_NAME_VALID, validation_result);
EXPECT_EQ(NULL, rcl_topic_name_validation_result_string(validation_result));
EXPECT_EQ(nullptr, rcl_topic_name_validation_result_string(validation_result));
}
// passing with invalid_index
@ -42,7 +42,7 @@ TEST(test_validate_topic_name, normal) {
EXPECT_EQ(RCL_RET_OK, ret) << rcl_get_error_string_safe();
EXPECT_EQ(RCL_TOPIC_NAME_VALID, validation_result);
EXPECT_EQ(42u, invalid_index); // ensure invalid_index is not assigned on success
EXPECT_EQ(NULL, rcl_topic_name_validation_result_string(validation_result));
EXPECT_EQ(nullptr, rcl_topic_name_validation_result_string(validation_result));
}
// failing with invalid_index
@ -63,14 +63,14 @@ TEST(test_validate_topic_name, invalid_arguments) {
// pass null for topic string
{
int validation_result;
ret = rcl_validate_topic_name(NULL, &validation_result, NULL);
ret = rcl_validate_topic_name(nullptr, &validation_result, nullptr);
EXPECT_EQ(RCL_RET_INVALID_ARGUMENT, ret);
rcl_reset_error();
}
// pass null for validation_result
{
ret = rcl_validate_topic_name("topic", NULL, NULL);
ret = rcl_validate_topic_name("topic", nullptr, nullptr);
EXPECT_EQ(RCL_RET_INVALID_ARGUMENT, ret);
rcl_reset_error();
}