Skip to content

Commit

Permalink
fix uncrustify issues
Browse files Browse the repository at this point in the history
Signed-off-by: Brian Wilcox <[email protected]>
  • Loading branch information
bpwilcox committed Mar 29, 2021
1 parent 70fca6e commit e12a2b3
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 44 deletions.
25 changes: 15 additions & 10 deletions rcl_yaml_param_parser/src/parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,8 @@ rcutils_ret_t parse_descriptor(
return RCUTILS_RET_ERROR;
}
// If parsing a yaml value, then current parameter namespace must be parameter name
allocator.deallocate(params_st->descriptors[node_idx].parameter_names[parameter_idx],
allocator.deallocate(
params_st->descriptors[node_idx].parameter_names[parameter_idx],
allocator.state);
params_st->descriptors[node_idx].parameter_names[parameter_idx] =
rcutils_strdup(ns_tracker->parameter_ns, allocator);
Expand All @@ -526,8 +527,9 @@ rcutils_ret_t parse_descriptor(
return RCUTILS_RET_ERROR;
}

if (0 == strncmp("additional_constraints", ns_tracker->descriptor_key_ns,
strlen("additional_constraints")))
if (0 == strncmp(
"additional_constraints", ns_tracker->descriptor_key_ns,
strlen("additional_constraints")))
{
if (val_type == DATA_TYPE_STRING) {
param_descriptor->additional_constraints = (char *)ret_val;
Expand Down Expand Up @@ -947,8 +949,9 @@ rcutils_ret_t parse_key(
ret = RCUTILS_RET_ERROR;
break;
}
ret = replace_ns(ns_tracker, parameter_ns, (ns_tracker->num_parameter_ns + 1U),
NS_TYPE_PARAM, allocator);
ret = replace_ns(
ns_tracker, parameter_ns, (ns_tracker->num_parameter_ns + 1U),
NS_TYPE_PARAM, allocator);
if (RCUTILS_RET_OK != ret) {
RCUTILS_SET_ERROR_MSG_WITH_FORMAT_STRING(
"Internal error replacing namespace at line %d", line_num);
Expand All @@ -972,9 +975,10 @@ rcutils_ret_t parse_key(
}

ret =
replace_ns(ns_tracker, rcutils_strdup(value, allocator),
(ns_tracker->num_descriptor_key_ns + 1U),
NS_TYPE_DESCRIPTOR, allocator);
replace_ns(
ns_tracker, rcutils_strdup(value, allocator),
(ns_tracker->num_descriptor_key_ns + 1U),
NS_TYPE_DESCRIPTOR, allocator);
if (RCUTILS_RET_OK != ret) {
RCUTILS_SET_ERROR_MSG_WITH_FORMAT_STRING(
"Internal error replacing namespace at line %d", line_num);
Expand Down Expand Up @@ -1091,8 +1095,9 @@ rcutils_ret_t parse_file_events(
if (map_level != 3U) {
ret = parse_value(event, is_seq, node_idx, parameter_idx, &seq_data_type, params_st);
} else {
ret = parse_descriptor(ns_tracker, event, is_seq, node_idx, parameter_idx,
params_st);
ret = parse_descriptor(
ns_tracker, event, is_seq, node_idx, parameter_idx,
params_st);
}
if (RCUTILS_RET_OK != ret) {
break;
Expand Down
10 changes: 6 additions & 4 deletions rcl_yaml_param_parser/test/test_node_params_descriptors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ TEST(TestNodeParamsDescriptors, init_fini) {
TEST(TestNodeParamsDescriptors, init_with_capacity_fini) {
rcutils_allocator_t allocator = rcutils_get_default_allocator();
rcl_node_params_descriptors_t node_descriptors = {NULL, NULL, 0u, 1024u};
EXPECT_EQ(RCUTILS_RET_OK, node_params_descriptors_init_with_capacity(
&node_descriptors, 1024, allocator));
EXPECT_EQ(
RCUTILS_RET_OK, node_params_descriptors_init_with_capacity(
&node_descriptors, 1024, allocator));
EXPECT_NE(nullptr, node_descriptors.parameter_names);
EXPECT_NE(nullptr, node_descriptors.parameter_descriptors);
EXPECT_EQ(0u, node_descriptors.num_params);
Expand All @@ -59,8 +60,9 @@ TEST(TestNodeParamsDescriptors, init_with_capacity_fini) {
TEST(TestNodeParamsDescriptors, reallocate_with_capacity_fini) {
rcutils_allocator_t allocator = rcutils_get_default_allocator();
rcl_node_params_descriptors_t node_descriptors = {NULL, NULL, 0u, 1024u};
EXPECT_EQ(RCUTILS_RET_OK, node_params_descriptors_init_with_capacity(
&node_descriptors, 1024, allocator));
EXPECT_EQ(
RCUTILS_RET_OK, node_params_descriptors_init_with_capacity(
&node_descriptors, 1024, allocator));
EXPECT_NE(nullptr, node_descriptors.parameter_names);
EXPECT_NE(nullptr, node_descriptors.parameter_descriptors);
EXPECT_EQ(0u, node_descriptors.num_params);
Expand Down
48 changes: 31 additions & 17 deletions rcl_yaml_param_parser/test/test_parse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,8 @@ TEST(TestParse, parse_descriptor) {
RCUTILS_RET_OK,
parse_descriptor(&ns_tracker, event, is_seq, node_idx, parameter_idx, params_st)) <<
rcutils_get_error_string().str;
ASSERT_NE(nullptr,
ASSERT_NE(
nullptr,
params_st->descriptors[node_idx].parameter_descriptors[parameter_idx].read_only);
EXPECT_TRUE(*params_st->descriptors[node_idx].parameter_descriptors[parameter_idx].read_only);
allocator.deallocate(
Expand All @@ -193,9 +194,11 @@ TEST(TestParse, parse_descriptor) {
RCUTILS_RET_OK,
parse_descriptor(&ns_tracker, event, is_seq, node_idx, parameter_idx, params_st)) <<
rcutils_get_error_string().str;
ASSERT_NE(nullptr,
ASSERT_NE(
nullptr,
params_st->descriptors[node_idx].parameter_descriptors[parameter_idx].min_value_int);
EXPECT_EQ(28,
EXPECT_EQ(
28,
*params_st->descriptors[node_idx].parameter_descriptors[parameter_idx].min_value_int);
allocator.deallocate(
params_st->descriptors[node_idx].parameter_descriptors[parameter_idx].min_value_int,
Expand All @@ -209,9 +212,11 @@ TEST(TestParse, parse_descriptor) {
RCUTILS_RET_OK,
parse_descriptor(&ns_tracker, event, is_seq, node_idx, parameter_idx, params_st)) <<
rcutils_get_error_string().str;
ASSERT_NE(nullptr,
ASSERT_NE(
nullptr,
params_st->descriptors[node_idx].parameter_descriptors[parameter_idx].min_value_double);
EXPECT_EQ(1.23456,
EXPECT_EQ(
1.23456,
*params_st->descriptors[node_idx].parameter_descriptors[parameter_idx].min_value_double);
allocator.deallocate(
params_st->descriptors[node_idx].parameter_descriptors[parameter_idx].min_value_double,
Expand All @@ -228,9 +233,11 @@ TEST(TestParse, parse_descriptor) {
RCUTILS_RET_OK,
parse_descriptor(&ns_tracker, event, is_seq, node_idx, parameter_idx, params_st)) <<
rcutils_get_error_string().str;
ASSERT_NE(nullptr,
ASSERT_NE(
nullptr,
params_st->descriptors[node_idx].parameter_descriptors[parameter_idx].max_value_int);
EXPECT_EQ(28,
EXPECT_EQ(
28,
*params_st->descriptors[node_idx].parameter_descriptors[parameter_idx].max_value_int);
allocator.deallocate(
params_st->descriptors[node_idx].parameter_descriptors[parameter_idx].max_value_int,
Expand All @@ -244,17 +251,19 @@ TEST(TestParse, parse_descriptor) {
RCUTILS_RET_OK,
parse_descriptor(&ns_tracker, event, is_seq, node_idx, parameter_idx, params_st)) <<
rcutils_get_error_string().str;
ASSERT_NE(nullptr,
ASSERT_NE(
nullptr,
params_st->descriptors[node_idx].parameter_descriptors[parameter_idx].max_value_double);
EXPECT_EQ(1.23456,
EXPECT_EQ(
1.23456,
*params_st->descriptors[node_idx].parameter_descriptors[parameter_idx].max_value_double);
allocator.deallocate(
params_st->descriptors[node_idx].parameter_descriptors[parameter_idx].max_value_double,
allocator.state);
allocator.deallocate(ns_tracker.descriptor_key_ns, allocator.state);
params_st->descriptors[node_idx].parameter_descriptors[parameter_idx].max_value_double = nullptr;

// step (int)
// step (int)
ns_tracker.descriptor_key_ns = rcutils_strdup("step", allocator);
ASSERT_STREQ("step", ns_tracker.descriptor_key_ns);
event.data.scalar.value = int_value;
Expand All @@ -263,7 +272,8 @@ TEST(TestParse, parse_descriptor) {
RCUTILS_RET_OK,
parse_descriptor(&ns_tracker, event, is_seq, node_idx, parameter_idx, params_st)) <<
rcutils_get_error_string().str;
ASSERT_NE(nullptr,
ASSERT_NE(
nullptr,
params_st->descriptors[node_idx].parameter_descriptors[parameter_idx].step_int);
EXPECT_EQ(28, *params_st->descriptors[node_idx].parameter_descriptors[parameter_idx].step_int);
allocator.deallocate(
Expand All @@ -278,9 +288,11 @@ TEST(TestParse, parse_descriptor) {
RCUTILS_RET_OK,
parse_descriptor(&ns_tracker, event, is_seq, node_idx, parameter_idx, params_st)) <<
rcutils_get_error_string().str;
ASSERT_NE(nullptr,
ASSERT_NE(
nullptr,
params_st->descriptors[node_idx].parameter_descriptors[parameter_idx].step_double);
EXPECT_EQ(1.23456,
EXPECT_EQ(
1.23456,
*params_st->descriptors[node_idx].parameter_descriptors[parameter_idx].step_double);
allocator.deallocate(
params_st->descriptors[node_idx].parameter_descriptors[parameter_idx].step_double,
Expand All @@ -297,7 +309,8 @@ TEST(TestParse, parse_descriptor) {
RCUTILS_RET_OK,
parse_descriptor(&ns_tracker, event, is_seq, node_idx, parameter_idx, params_st)) <<
rcutils_get_error_string().str;
ASSERT_NE(nullptr,
ASSERT_NE(
nullptr,
params_st->descriptors[node_idx].parameter_descriptors[parameter_idx].description);
EXPECT_STREQ(
"I am a string",
Expand All @@ -317,8 +330,9 @@ TEST(TestParse, parse_descriptor) {
RCUTILS_RET_OK,
parse_descriptor(&ns_tracker, event, is_seq, node_idx, parameter_idx, params_st)) <<
rcutils_get_error_string().str;
ASSERT_NE(nullptr,
params_st->descriptors[node_idx].parameter_descriptors[parameter_idx].additional_constraints);
ASSERT_NE(
nullptr,
params_st->descriptors[node_idx].parameter_descriptors[parameter_idx].additional_constraints);
EXPECT_STREQ(
"I am a string",
params_st->descriptors[node_idx].parameter_descriptors[parameter_idx].additional_constraints);
Expand Down Expand Up @@ -546,7 +560,7 @@ TEST(TestParse, parse_descriptor_bad_types) {
params_st->descriptors[node_idx].parameter_descriptors[parameter_idx].max_value_int = nullptr;
rcutils_reset_error();

// step (int)
// step (int)
ns_tracker.descriptor_key_ns = rcutils_strdup("step", allocator);
ASSERT_STREQ("step", ns_tracker.descriptor_key_ns);
// step: catch invalid value type
Expand Down
39 changes: 26 additions & 13 deletions rcl_yaml_param_parser/test/test_parse_yaml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -667,26 +667,30 @@ TEST(test_file_parser, correct_syntax_descriptors) {
rcutils_allocator_t allocator = rcutils_get_default_allocator();
char * test_path = rcutils_join_path(cur_dir, "test", allocator);
ASSERT_TRUE(NULL != test_path) << rcutils_get_error_string().str;
OSRF_TESTING_TOOLS_CPP_SCOPE_EXIT({
OSRF_TESTING_TOOLS_CPP_SCOPE_EXIT(
{
allocator.deallocate(test_path, allocator.state);
});
char * path = rcutils_join_path(test_path, "correct_param_descriptors.yaml", allocator);
ASSERT_TRUE(NULL != path) << rcutils_get_error_string().str;
OSRF_TESTING_TOOLS_CPP_SCOPE_EXIT({
OSRF_TESTING_TOOLS_CPP_SCOPE_EXIT(
{
allocator.deallocate(path, allocator.state);
});
ASSERT_TRUE(rcutils_exists(path)) << "No test YAML file found at " << path;
rcl_params_t * params_hdl = rcl_yaml_node_struct_init(allocator);
ASSERT_TRUE(NULL != params_hdl) << rcutils_get_error_string().str;
OSRF_TESTING_TOOLS_CPP_SCOPE_EXIT({
OSRF_TESTING_TOOLS_CPP_SCOPE_EXIT(
{
rcl_yaml_node_struct_fini(params_hdl);
});
bool res = rcl_parse_yaml_file(path, params_hdl);
ASSERT_TRUE(res) << rcutils_get_error_string().str;

char * another_path = rcutils_join_path(test_path, "overlay_descriptors.yaml", allocator);
ASSERT_TRUE(NULL != another_path) << rcutils_get_error_string().str;
OSRF_TESTING_TOOLS_CPP_SCOPE_EXIT({
OSRF_TESTING_TOOLS_CPP_SCOPE_EXIT(
{
allocator.deallocate(another_path, allocator.state);
});
ASSERT_TRUE(rcutils_exists(another_path)) << "No test YAML file found at " << another_path;
Expand All @@ -695,7 +699,8 @@ TEST(test_file_parser, correct_syntax_descriptors) {

rcl_params_t * copy_of_params_hdl = rcl_yaml_node_struct_copy(params_hdl);
ASSERT_TRUE(NULL != copy_of_params_hdl) << rcutils_get_error_string().str;
OSRF_TESTING_TOOLS_CPP_SCOPE_EXIT({
OSRF_TESTING_TOOLS_CPP_SCOPE_EXIT(
{
rcl_yaml_node_struct_fini(copy_of_params_hdl);
});

Expand Down Expand Up @@ -773,12 +778,14 @@ TEST(test_parser, param_assign_in_descriptors) {
rcutils_allocator_t allocator = rcutils_get_default_allocator();
char * test_path = rcutils_join_path(cur_dir, "test", allocator);
ASSERT_TRUE(NULL != test_path) << rcutils_get_error_string().str;
OSRF_TESTING_TOOLS_CPP_SCOPE_EXIT({
OSRF_TESTING_TOOLS_CPP_SCOPE_EXIT(
{
allocator.deallocate(test_path, allocator.state);
});
char * path = rcutils_join_path(test_path, "assign_param_in_descriptors.yaml", allocator);
ASSERT_TRUE(NULL != path) << rcutils_get_error_string().str;
OSRF_TESTING_TOOLS_CPP_SCOPE_EXIT({
OSRF_TESTING_TOOLS_CPP_SCOPE_EXIT(
{
allocator.deallocate(path, allocator.state);
});
ASSERT_TRUE(rcutils_exists(path)) << "No test YAML file found at " << path;
Expand All @@ -794,12 +801,14 @@ TEST(test_parser, invalid_param_descriptor_key) {
rcutils_allocator_t allocator = rcutils_get_default_allocator();
char * test_path = rcutils_join_path(cur_dir, "test", allocator);
ASSERT_TRUE(NULL != test_path) << rcutils_get_error_string().str;
OSRF_TESTING_TOOLS_CPP_SCOPE_EXIT({
OSRF_TESTING_TOOLS_CPP_SCOPE_EXIT(
{
allocator.deallocate(test_path, allocator.state);
});
char * path = rcutils_join_path(test_path, "invalid_param_descriptor_key.yaml", allocator);
ASSERT_TRUE(NULL != path) << rcutils_get_error_string().str;
OSRF_TESTING_TOOLS_CPP_SCOPE_EXIT({
OSRF_TESTING_TOOLS_CPP_SCOPE_EXIT(
{
allocator.deallocate(path, allocator.state);
});
ASSERT_TRUE(rcutils_exists(path)) << "No test YAML file found at " << path;
Expand All @@ -815,12 +824,14 @@ TEST(test_parser, invalid_param_descriptor_type) {
rcutils_allocator_t allocator = rcutils_get_default_allocator();
char * test_path = rcutils_join_path(cur_dir, "test", allocator);
ASSERT_TRUE(NULL != test_path) << rcutils_get_error_string().str;
OSRF_TESTING_TOOLS_CPP_SCOPE_EXIT({
OSRF_TESTING_TOOLS_CPP_SCOPE_EXIT(
{
allocator.deallocate(test_path, allocator.state);
});
char * path = rcutils_join_path(test_path, "invalid_param_descriptor_type.yaml", allocator);
ASSERT_TRUE(NULL != path) << rcutils_get_error_string().str;
OSRF_TESTING_TOOLS_CPP_SCOPE_EXIT({
OSRF_TESTING_TOOLS_CPP_SCOPE_EXIT(
{
allocator.deallocate(path, allocator.state);
});
ASSERT_TRUE(rcutils_exists(path)) << "No test YAML file found at " << path;
Expand All @@ -836,12 +847,14 @@ TEST(test_parser, no_value_descriptor) {
rcutils_allocator_t allocator = rcutils_get_default_allocator();
char * test_path = rcutils_join_path(cur_dir, "test", allocator);
ASSERT_TRUE(NULL != test_path) << rcutils_get_error_string().str;
OSRF_TESTING_TOOLS_CPP_SCOPE_EXIT({
OSRF_TESTING_TOOLS_CPP_SCOPE_EXIT(
{
allocator.deallocate(test_path, allocator.state);
});
char * path = rcutils_join_path(test_path, "no_value_descriptor.yaml", allocator);
ASSERT_TRUE(NULL != path) << rcutils_get_error_string().str;
OSRF_TESTING_TOOLS_CPP_SCOPE_EXIT({
OSRF_TESTING_TOOLS_CPP_SCOPE_EXIT(
{
allocator.deallocate(path, allocator.state);
});
ASSERT_TRUE(rcutils_exists(path)) << "No test YAML file found at " << path;
Expand Down

0 comments on commit e12a2b3

Please sign in to comment.