-
Notifications
You must be signed in to change notification settings - Fork 181
Add cov tests 95% #744
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Add cov tests 95% #744
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
f391200
Add mocking tools
Blast545 e60f44f
Add mocked tests fail init/fini
Blast545 4d11ecf
Reformat tests with helper macro
Blast545 226f21a
Fix returned value expected
Blast545 310b9f5
Add nullptr/invalid tests
Blast545 4d63f1c
Add domain_id mocked tests
Blast545 7171d71
Add mimick support for test_log_level
Blast545 85f95a0
Add fini/ini tests log_level
Blast545 8fd4d0e
Add fini nullptr test
Blast545 34c3ce8
Add mocked tests rmw_impl_id_check
Blast545 34d140e
Add tests log_level
Blast545 98cdcfc
Add bad_alloc test
Blast545 a6f8e99
Add ini/fini for size 0
Blast545 19a3842
Add tests add_logger_setting
Blast545 ffd0890
Add tests logger_settings
Blast545 19952df
Fix indentation
Blast545 6ad074c
Remove extra deallocation
Blast545 efb7585
Remove test
Blast545 bbe6241
Add comment on dummy operators added
Blast545 ecedb50
Change allocator call
Blast545 402b106
Change mock to inject on return
Blast545 4a7573a
Remove extra fini
Blast545 c4c9fb9
Replace allocation with captured rcutils_strdup
Blast545 0df49b9
Fix alpha order header
Blast545 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,6 +25,7 @@ | |
| #include "rcutils/snprintf.h" | ||
|
|
||
| #include "./allocator_testing_utils.h" | ||
| #include "../mocking_utils/patch.hpp" | ||
| #include "../src/rcl/init_options_impl.h" | ||
|
|
||
| #ifdef RMW_IMPLEMENTATION | ||
|
|
@@ -104,16 +105,34 @@ struct FakeTestArgv | |
| */ | ||
| TEST_F(CLASSNAME(TestRCLFixture, RMW_IMPLEMENTATION), test_rcl_init_options_init) { | ||
| rcl_init_options_t init_options = rcl_get_zero_initialized_init_options(); | ||
| rcl_ret_t ret = rcl_init_options_init(&init_options, rcl_get_default_allocator()); | ||
|
|
||
| // fini a not empty options | ||
| rcl_ret_t ret = rcl_init_options_fini(&init_options); | ||
| EXPECT_EQ(RCL_RET_INVALID_ARGUMENT, ret) << rcl_get_error_string().str; | ||
| rcl_reset_error(); | ||
|
|
||
| // Expected usage | ||
| ret = rcl_init_options_init(&init_options, rcl_get_default_allocator()); | ||
| ASSERT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str; | ||
| OSRF_TESTING_TOOLS_CPP_SCOPE_EXIT( | ||
| { | ||
| EXPECT_EQ(RCL_RET_OK, rcl_init_options_fini(&init_options)) << rcl_get_error_string().str; | ||
| }); | ||
|
|
||
| // Already init | ||
| ret = rcl_init_options_init(&init_options, rcl_get_default_allocator()); | ||
| EXPECT_EQ(RCL_RET_ALREADY_INIT, ret) << rcl_get_error_string().str; | ||
| rcl_reset_error(); | ||
|
|
||
| // nullptr | ||
| ret = rcl_init_options_init(nullptr, rcl_get_default_allocator()); | ||
| EXPECT_EQ(RCL_RET_INVALID_ARGUMENT, ret) << rcl_get_error_string().str; | ||
| rcl_reset_error(); | ||
|
|
||
| // nullptr | ||
| ret = rcl_init_options_fini(nullptr); | ||
| EXPECT_EQ(RCL_RET_INVALID_ARGUMENT, ret) << rcl_get_error_string().str; | ||
| rcl_reset_error(); | ||
| } | ||
|
|
||
| /* Tests calling rcl_init() with invalid arguments fails. | ||
|
|
@@ -364,6 +383,7 @@ TEST_F(CLASSNAME(TestRCLFixture, RMW_IMPLEMENTATION), test_rcl_get_instance_id) | |
|
|
||
| TEST_F(CLASSNAME(TestRCLFixture, RMW_IMPLEMENTATION), test_rcl_init_options_access) { | ||
| rcl_init_options_t init_options = rcl_get_zero_initialized_init_options(); | ||
| rcl_init_options_t not_ini_init_options = rcl_get_zero_initialized_init_options(); | ||
| rcl_ret_t ret = rcl_init_options_init(&init_options, rcl_get_default_allocator()); | ||
| ASSERT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str; | ||
| OSRF_TESTING_TOOLS_CPP_SCOPE_EXIT( | ||
|
|
@@ -375,14 +395,21 @@ TEST_F(CLASSNAME(TestRCLFixture, RMW_IMPLEMENTATION), test_rcl_init_options_acce | |
| ASSERT_NE(nullptr, options); | ||
| EXPECT_EQ(0u, options->instance_id); | ||
| EXPECT_EQ(nullptr, options->impl); | ||
| EXPECT_EQ(NULL, rcl_init_options_get_rmw_init_options(nullptr)); | ||
| EXPECT_EQ(NULL, rcl_init_options_get_rmw_init_options(¬_ini_init_options)); | ||
|
|
||
| const rcl_allocator_t * options_allocator = rcl_init_options_get_allocator(&init_options); | ||
| EXPECT_TRUE(rcutils_allocator_is_valid(options_allocator)); | ||
| EXPECT_EQ(NULL, rcl_init_options_get_allocator(nullptr)); | ||
| EXPECT_EQ(NULL, rcl_init_options_get_allocator(¬_ini_init_options)); | ||
|
|
||
| size_t domain_id; | ||
| ret = rcl_init_options_get_domain_id(NULL, &domain_id); | ||
| ASSERT_EQ(RCL_RET_INVALID_ARGUMENT, ret) << rcl_get_error_string().str; | ||
| rcl_reset_error(); | ||
| ret = rcl_init_options_get_domain_id(¬_ini_init_options, &domain_id); | ||
| EXPECT_EQ(RCL_RET_INVALID_ARGUMENT, ret) << rcl_get_error_string().str; | ||
| rcl_reset_error(); | ||
| ret = rcl_init_options_get_domain_id(&init_options, NULL); | ||
| ASSERT_EQ(RCL_RET_INVALID_ARGUMENT, ret) << rcl_get_error_string().str; | ||
| rcl_reset_error(); | ||
|
|
@@ -392,6 +419,9 @@ TEST_F(CLASSNAME(TestRCLFixture, RMW_IMPLEMENTATION), test_rcl_init_options_acce | |
| ret = rcl_init_options_set_domain_id(NULL, domain_id); | ||
| ASSERT_EQ(RCL_RET_INVALID_ARGUMENT, ret) << rcl_get_error_string().str; | ||
| rcl_reset_error(); | ||
| ret = rcl_init_options_set_domain_id(¬_ini_init_options, domain_id); | ||
| EXPECT_EQ(RCL_RET_INVALID_ARGUMENT, ret) << rcl_get_error_string().str; | ||
| rcl_reset_error(); | ||
|
|
||
| ret = rcl_init_options_get_domain_id(&init_options, &domain_id); | ||
| ASSERT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str; | ||
|
|
@@ -403,10 +433,82 @@ TEST_F(CLASSNAME(TestRCLFixture, RMW_IMPLEMENTATION), test_rcl_init_options_acce | |
| EXPECT_EQ(0U, domain_id); | ||
|
|
||
| rcl_init_options_t init_options_dst = rcl_get_zero_initialized_init_options(); | ||
|
|
||
| // nullptr copy cases | ||
| EXPECT_EQ( | ||
| RCL_RET_INVALID_ARGUMENT, rcl_init_options_copy(nullptr, &init_options_dst)); | ||
| EXPECT_EQ( | ||
| RCL_RET_INVALID_ARGUMENT, rcl_init_options_copy(&init_options, nullptr)); | ||
|
|
||
| // Expected usage copy | ||
| ASSERT_EQ(RCL_RET_OK, rcl_init_options_copy(&init_options, &init_options_dst)); | ||
| ret = rcl_init_options_get_domain_id(&init_options_dst, &domain_id); | ||
| ASSERT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str; | ||
| EXPECT_EQ(0U, domain_id); | ||
| EXPECT_EQ(RCL_RET_ALREADY_INIT, rcl_init_options_copy(&init_options, &init_options_dst)); | ||
| EXPECT_EQ(RCL_RET_OK, rcl_init_options_fini(&init_options_dst)); | ||
| } | ||
|
|
||
| // Define dummy comparison operators for rcutils_allocator_t type for use with the Mimick Library | ||
| MOCKING_UTILS_BOOL_OPERATOR_RETURNS_FALSE(rcutils_allocator_t, ==) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Blast545 nit: same as below and other PRs, an explanatory comment is nice. |
||
| MOCKING_UTILS_BOOL_OPERATOR_RETURNS_FALSE(rcutils_allocator_t, <) | ||
| MOCKING_UTILS_BOOL_OPERATOR_RETURNS_FALSE(rcutils_allocator_t, >) | ||
| MOCKING_UTILS_BOOL_OPERATOR_RETURNS_FALSE(rcutils_allocator_t, !=) | ||
|
|
||
| // Tests rcl_init_options_init() mocked to fail | ||
| TEST_F(CLASSNAME(TestRCLFixture, RMW_IMPLEMENTATION), test_mocked_rcl_init_options_ini) { | ||
| rcl_init_options_t init_options = rcl_get_zero_initialized_init_options(); | ||
| auto mock = mocking_utils::patch_and_return("lib:rcl", rmw_init_options_init, RMW_RET_ERROR); | ||
| EXPECT_EQ(RCL_RET_ERROR, rcl_init_options_init(&init_options, rcl_get_default_allocator())); | ||
| rcl_reset_error(); | ||
| } | ||
|
|
||
| // Tests rcl_init_options_fini() mocked to fail | ||
| TEST_F(CLASSNAME(TestRCLFixture, RMW_IMPLEMENTATION), test_mocked_rcl_init_options_fini) { | ||
| rcl_init_options_t init_options = rcl_get_zero_initialized_init_options(); | ||
| rcl_ret_t ret = rcl_init_options_init(&init_options, rcl_get_default_allocator()); | ||
| ASSERT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str; | ||
| auto mock = mocking_utils::inject_on_return("lib:rcl", rmw_init_options_fini, RMW_RET_ERROR); | ||
| EXPECT_EQ(RCL_RET_ERROR, rcl_init_options_fini(&init_options)); | ||
| rcl_reset_error(); | ||
| } | ||
|
|
||
| // Mock rcl_init_options_copy to fail | ||
| TEST_F(CLASSNAME(TestRCLFixture, RMW_IMPLEMENTATION), test_rcl_init_copy_mocked_fail_fini) { | ||
| rcl_init_options_t init_options = rcl_get_zero_initialized_init_options(); | ||
| rcl_ret_t ret = rcl_init_options_init(&init_options, rcl_get_default_allocator()); | ||
| ASSERT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str; | ||
| OSRF_TESTING_TOOLS_CPP_SCOPE_EXIT( | ||
| { | ||
| EXPECT_EQ(RCL_RET_OK, rcl_init_options_fini(&init_options)) << rcl_get_error_string().str; | ||
| }); | ||
| rcl_init_options_t init_options_dst = rcl_get_zero_initialized_init_options(); | ||
| auto mock = mocking_utils::inject_on_return("lib:rcl", rmw_init_options_fini, RMW_RET_ERROR); | ||
| EXPECT_EQ(RCL_RET_ERROR, rcl_init_options_copy(&init_options, &init_options_dst)); | ||
| rcl_reset_error(); | ||
| } | ||
|
|
||
| // Mock rcl_init_options_copy to fail | ||
| TEST_F(CLASSNAME(TestRCLFixture, RMW_IMPLEMENTATION), test_rcl_init_options_copy_fail_rmw_copy) { | ||
| rcl_init_options_t init_options = rcl_get_zero_initialized_init_options(); | ||
| rcl_ret_t ret = rcl_init_options_init(&init_options, rcl_get_default_allocator()); | ||
| ASSERT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str; | ||
| OSRF_TESTING_TOOLS_CPP_SCOPE_EXIT( | ||
| { | ||
| EXPECT_EQ(RCL_RET_OK, rcl_init_options_fini(&init_options)) << rcl_get_error_string().str; | ||
| }); | ||
| rcl_init_options_t init_options_dst = rcl_get_zero_initialized_init_options(); | ||
| OSRF_TESTING_TOOLS_CPP_SCOPE_EXIT( | ||
| { | ||
| // dst is in a invalid state after failed copy | ||
| EXPECT_EQ( | ||
| RCL_RET_INVALID_ARGUMENT, | ||
| rcl_init_options_fini(&init_options_dst)) << rcl_get_error_string().str; | ||
| rcl_reset_error(); | ||
| }); | ||
|
|
||
| // rmw_init_options_copy error is logged | ||
| auto mock = mocking_utils::patch_and_return("lib:rcl", rmw_init_options_copy, RMW_RET_ERROR); | ||
| EXPECT_EQ(RCL_RET_INVALID_ARGUMENT, rcl_init_options_copy(&init_options, &init_options_dst)); | ||
| rcl_reset_error(); | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.