Complete rcl enclave validation API coverage. (#751)
Signed-off-by: Michel Hidalgo <michel@ekumenlabs.com>
This commit is contained in:
parent
fe2d89d0e1
commit
7669ced71b
2 changed files with 60 additions and 1 deletions
|
@ -353,7 +353,7 @@ call_for_each_rmw_implementation(test_target)
|
||||||
rcl_add_custom_gtest(test_validate_enclave_name
|
rcl_add_custom_gtest(test_validate_enclave_name
|
||||||
SRCS rcl/test_validate_enclave_name.cpp
|
SRCS rcl/test_validate_enclave_name.cpp
|
||||||
APPEND_LIBRARY_DIRS ${extra_lib_dirs}
|
APPEND_LIBRARY_DIRS ${extra_lib_dirs}
|
||||||
LIBRARIES ${PROJECT_NAME}
|
LIBRARIES ${PROJECT_NAME} mimick
|
||||||
)
|
)
|
||||||
|
|
||||||
rcl_add_custom_gtest(test_domain_id
|
rcl_add_custom_gtest(test_domain_id
|
||||||
|
|
|
@ -17,11 +17,17 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
#include "rcutils/snprintf.h"
|
||||||
|
|
||||||
#include "rcl/rcl.h"
|
#include "rcl/rcl.h"
|
||||||
#include "rcl/validate_enclave_name.h"
|
#include "rcl/validate_enclave_name.h"
|
||||||
|
|
||||||
#include "rcl/error_handling.h"
|
#include "rcl/error_handling.h"
|
||||||
|
|
||||||
|
#include "rmw/validate_namespace.h"
|
||||||
|
|
||||||
|
#include "../mocking_utils/patch.hpp"
|
||||||
|
|
||||||
TEST(TestValidateEnclaveName, test_validate) {
|
TEST(TestValidateEnclaveName, test_validate) {
|
||||||
int validation_result;
|
int validation_result;
|
||||||
size_t invalid_index;
|
size_t invalid_index;
|
||||||
|
@ -47,6 +53,59 @@ TEST(TestValidateEnclaveName, test_validate) {
|
||||||
RCL_RET_OK,
|
RCL_RET_OK,
|
||||||
rcl_validate_enclave_name("/foo/bar", &validation_result, &invalid_index));
|
rcl_validate_enclave_name("/foo/bar", &validation_result, &invalid_index));
|
||||||
EXPECT_EQ(RCL_ENCLAVE_NAME_VALID, validation_result);
|
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) {
|
TEST(TestValidateEnclaveName, test_validation_string) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue