Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion rcl/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ call_for_each_rmw_implementation(test_target)
rcl_add_custom_gtest(test_validate_enclave_name
SRCS rcl/test_validate_enclave_name.cpp
APPEND_LIBRARY_DIRS ${extra_lib_dirs}
LIBRARIES ${PROJECT_NAME}
LIBRARIES ${PROJECT_NAME} mimick
)

rcl_add_custom_gtest(test_domain_id
Expand Down
59 changes: 59 additions & 0 deletions rcl/test/rcl/test_validate_enclave_name.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,17 @@
#include <string>
#include <vector>

#include "rcutils/snprintf.h"

#include "rcl/rcl.h"
#include "rcl/validate_enclave_name.h"

#include "rcl/error_handling.h"

#include "rmw/validate_namespace.h"

#include "../mocking_utils/patch.hpp"

TEST(TestValidateEnclaveName, test_validate) {
int validation_result;
size_t invalid_index;
Expand All @@ -47,6 +53,59 @@ TEST(TestValidateEnclaveName, test_validate) {
RCL_RET_OK,
rcl_validate_enclave_name("/foo/bar", &validation_result, &invalid_index));
EXPECT_EQ(RCL_ENCLAVE_NAME_VALID, validation_result);

{
auto mock = mocking_utils::patch(
"lib:rcl", rmw_validate_namespace_with_size,
[&](auto, auto, int * result, size_t * index) {
if (index) {
*index = 0u;
}
*result = RMW_NAMESPACE_INVALID_TOO_LONG;
return RMW_RET_OK;
});

// When applying RMW namespace validation rules, an enclave name may be too
// long for an RMW namespace but not necessarily for an enclave name.
EXPECT_EQ(
RCL_RET_OK,
rcl_validate_enclave_name("/foo/baz", &validation_result, &invalid_index));
EXPECT_EQ(RCL_ENCLAVE_NAME_VALID, validation_result);
}
}

TEST(TestValidateEnclaveName, test_validate_on_internal_error) {
int validation_result;
size_t invalid_index;

{
auto mock = mocking_utils::patch_to_fail(
"lib:rcl", rmw_validate_namespace_with_size, "internal error", RMW_RET_ERROR);

EXPECT_EQ(
RCL_RET_ERROR,
rcl_validate_enclave_name("/foo", &validation_result, &invalid_index));
EXPECT_TRUE(rcl_error_is_set());
rcl_reset_error();
}

{
auto mock = mocking_utils::patch(
"lib:rcl", rmw_validate_namespace_with_size,
[&](auto, auto, int * result, size_t * index) {
if (index) {
*index = 0u;
}
*result = -1;
return RMW_RET_OK;
});

EXPECT_EQ(
RCL_RET_ERROR,
rcl_validate_enclave_name("/foo", &validation_result, &invalid_index));
EXPECT_TRUE(rcl_error_is_set());
rcl_reset_error();
}
}

TEST(TestValidateEnclaveName, test_validation_string) {
Expand Down