Skip to content
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

Added arrays and sequences of primitive types to test [#8959] #24

Draft
wants to merge 4 commits into
base: foxy
Choose a base branch
from
Draft
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ devel_isolated/
.project
.cproject

# VSCode stuff
.vscode

# qcreator stuff
CMakeLists.txt.user

Expand Down
632 changes: 627 additions & 5 deletions test/c/src/test_typesupport.cpp

Large diffs are not rendered by default.

265 changes: 265 additions & 0 deletions test/cpp/src/test_typesupport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
// Specific defined types used during testing
#include "rosidl_typesupport_microxrcedds_test_msg/msg/primitive.hpp"
#include "rosidl_typesupport_microxrcedds_test_msg/msg/sequence.hpp"
#include "rosidl_typesupport_microxrcedds_test_msg/msg/array.hpp"

/*
* @brief TestTypeSupport class, used to automate typesupport testing for a specific type.
Expand Down Expand Up @@ -81,6 +82,17 @@ class TestTypeSupport : public ::testing::Test
ROSIDL_TYPESUPPORT_MICROXRCEDDS_CPP__IDENTIFIER_VALUE), 0);
}

/*
* @brief Compares sequences and arrays member by member.
*/
void memberwise_comparison(int size, )
{
for (size_t i = 0; i < A.sequence_bool_test.size(); ++i)
{
EXPECT_EQ(A.sequence_bool_test[i].compare(B.sequence_bool_test[i]), 0);
}
}

/*
* @brief Tests serialization and deserialization of a T type message,
* and compares the original instance and the deserialized one
Expand Down Expand Up @@ -159,6 +171,7 @@ TYPED_TEST(PrimitivesTestTypeSupport, serialize_primitive_types)
EXPECT_EQ(A.uint32_test, B.uint32_test);
EXPECT_EQ(A.int64_test, B.int64_test);
EXPECT_EQ(A.uint64_test, B.uint64_test);
EXPECT_EQ(A.string_test, B.string_test);

EXPECT_EQ(A.nested_test.unbounded_string1.compare(B.nested_test.unbounded_string1), 0);
EXPECT_EQ(A.nested_test.unbounded_string2.compare(B.nested_test.unbounded_string2), 0);
Expand All @@ -181,6 +194,7 @@ TYPED_TEST(PrimitivesTestTypeSupport, serialize_primitive_types)
init_primitive.uint32_test = 0x01010101;
init_primitive.int64_test = 0x0101010101010101;
init_primitive.uint64_test = 0x0101010101010101;
init_primitive.string_test = "Hello";
init_primitive.nested_test.unbounded_string1 = "ABCDEF";
init_primitive.nested_test.unbounded_string2 = "TGHIJKLMNO";
init_primitive.nested_test.unbounded_string3 = "PQRSTVWX";
Expand All @@ -207,15 +221,137 @@ TYPED_TEST(SequencesTestTypeSupport, serialize_sequence_types)
const rosidl_typesupport_microxrcedds_test_msg::msg::Sequence & A,
const rosidl_typesupport_microxrcedds_test_msg::msg::Sequence & B) -> void
{
EXPECT_EQ(A.sequence_bool_test.size(), B.sequence_bool_test.size());
EXPECT_EQ(A.sequence_byte_test.size(), B.sequence_byte_test.size());
EXPECT_EQ(A.sequence_char_test.size(), B.sequence_char_test.size());
EXPECT_EQ(A.sequence_float32_test.size(), B.sequence_float32_test.size());
EXPECT_EQ(A.sequence_double_test.size(), B.sequence_double_test.size());
EXPECT_EQ(A.sequence_int8_test.size(), B.sequence_int8_test.size());
EXPECT_EQ(A.sequence_uint8_test.size(), B.sequence_uint8_test.size());
EXPECT_EQ(A.sequence_int16_test.size(), B.sequence_int16_test.size());
EXPECT_EQ(A.sequence_uint16_test.size(), B.sequence_uint16_test.size());
EXPECT_EQ(A.sequence_int32_test.size(), B.sequence_int32_test.size());
EXPECT_EQ(A.sequence_uint32_test.size(), B.sequence_uint32_test.size());
EXPECT_EQ(A.sequence_int64_test.size(), B.sequence_int64_test.size());
EXPECT_EQ(A.sequence_uint64_test.size(), B.sequence_uint64_test.size());
EXPECT_EQ(A.sequence_string_test.size(), B.sequence_string_test.size());

for (size_t i = 0; i < A.sequence_bool_test.size(); ++i)
{
EXPECT_EQ(A.sequence_bool_test[i].compare(B.sequence_bool_test[i]), 0);
}
for (size_t i = 0; i < A.sequence_byte_test.size(); ++i)
{
EXPECT_EQ(A.sequence_byte_test[i].compare(B.sequence_byte_test[i]), 0);
}
for (size_t i = 0; i < A.sequence_char_test.size(); ++i)
{
EXPECT_EQ(A.sequence_char_test[i].compare(B.sequence_char_test[i]), 0);
}
for (size_t i = 0; i < A.sequence_float32_test.size(); ++i)
{
EXPECT_EQ(A.sequence_float32_test[i].compare(B.sequence_float32_test[i]), 0);
}
for (size_t i = 0; i < A.sequence_double_test.size(); ++i)
{
EXPECT_EQ(A.sequence_double_test[i].compare(B.sequence_double_test[i]), 0);
}
for (size_t i = 0; i < A.sequence_int8_test.size(); ++i)
{
EXPECT_EQ(A.sequence_int8_test[i].compare(B.sequence_int8_test[i]), 0);
}
for (size_t i = 0; i < A.sequence_uint8_test.size(); ++i)
{
EXPECT_EQ(A.sequence_uint8_test[i].compare(B.sequence_uint8_test[i]), 0);
}
for (size_t i = 0; i < A.sequence_int16_test.size(); ++i)
{
EXPECT_EQ(A.sequence_int16_test[i].compare(B.sequence_int16_test[i]), 0);
}
for (size_t i = 0; i < A.sequence_uint16_test.size(); ++i)
{
EXPECT_EQ(A.sequence_uint16_test[i].compare(B.sequence_uint16_test[i]), 0);
}
for (size_t i = 0; i < A.sequence_int32_test.size(); ++i)
{
EXPECT_EQ(A.sequence_int32_test[i].compare(B.sequence_int32_test[i]), 0);
}
for (size_t i = 0; i < A.sequence_uint32_test.size(); ++i)
{
EXPECT_EQ(A.sequence_uint32_test[i].compare(B.sequence_uint32_test[i]), 0);
}
for (size_t i = 0; i < A.sequence_int64_test.size(); ++i)
{
EXPECT_EQ(A.sequence_int64_test[i].compare(B.sequence_int64_test[i]), 0);
}
for (size_t i = 0; i < A.sequence_uint64_test.size(); ++i)
{
EXPECT_EQ(A.sequence_uint64_test[i].compare(B.sequence_uint64_test[i]), 0);
}
for (size_t i = 0; i < A.sequence_string_test.size(); ++i)
{
EXPECT_EQ(A.sequence_string_test[i].compare(B.sequence_string_test[i]), 0);
}
});

// Initialize data to be serialized and deserialized

rosidl_typesupport_microxrcedds_test_msg::msg::Sequence init_sequence;

init_sequence.sequence_bool_test.emplace_back(true);
init_sequence.sequence_bool_test.emplace_back(true);
init_sequence.sequence_bool_test.emplace_back(false);

init_sequence.sequence_byte_test.emplace_back(0);
init_sequence.sequence_byte_test.emplace_back(1);

init_sequence.sequence_char_test.emplace_back('z');
init_sequence.sequence_char_test.emplace_back('y');
init_sequence.sequence_char_test.emplace_back('x');
init_sequence.sequence_char_test.emplace_back('w');
init_sequence.sequence_char_test.emplace_back('v');

init_sequence.sequence_float32_test.emplace_back(1.23);
init_sequence.sequence_float32_test.emplace_back(45.6);
init_sequence.sequence_float32_test.emplace_back(-222.0);
init_sequence.sequence_float32_test.emplace_back(1287.9);

init_sequence.sequence_double_test.emplace_back(5287483999.3);
init_sequence.sequence_double_test.emplace_back(-46.5);

init_sequence.sequence_int8_test.emplace_back(1);
init_sequence.sequence_int8_test.emplace_back(2);
init_sequence.sequence_int8_test.emplace_back(-124);

init_sequence.sequence_uint8_test.emplace_back(11);
init_sequence.sequence_uint8_test.emplace_back(12);
init_sequence.sequence_uint8_test.emplace_back(13);
init_sequence.sequence_uint8_test.emplace_back(250);

init_sequence.sequence_int16_test.emplace_back(-360);
init_sequence.sequence_int16_test.emplace_back(1);

init_sequence.sequence_uint16_test.emplace_back(360);
init_sequence.sequence_uint16_test.emplace_back(800);
init_sequence.sequence_uint16_test.emplace_back(13);

init_sequence.sequence_int32_test.emplace_back(1000);
init_sequence.sequence_int32_test.emplace_back(16843009);

init_sequence.sequence_uint32_test.emplace_back(1000);
init_sequence.sequence_uint32_test.emplace_back(16843009);
init_sequence.sequence_uint32_test.emplace_back(3000);
init_sequence.sequence_uint32_test.emplace_back(2);

init_sequence.sequence_int64_test.emplace_back(72340172838076673L);
init_sequence.sequence_int64_test.emplace_back(16843009);
init_sequence.sequence_int64_test.emplace_back(-3000);
init_sequence.sequence_int64_test.emplace_back(2);
init_sequence.sequence_int64_test.emplace_back(16);

init_sequence.sequence_uint64_test.emplace_back(21);
init_sequence.sequence_uint64_test.emplace_back(72340172838076673L);

init_sequence.sequence_string_test.emplace_back("This");
init_sequence.sequence_string_test.emplace_back("is");
init_sequence.sequence_string_test.emplace_back("a");
Expand All @@ -225,3 +361,132 @@ TYPED_TEST(SequencesTestTypeSupport, serialize_sequence_types)
this->check_identifier();
this->test_serialize_deserialize();
}

/*
* @brief Array ROS 2 types serialization and deserialization tests.
*/

template <typename T>
class ArraysTestTypeSupport : public TestTypeSupport<T> {};

TYPED_TEST_CASE(ArraysTestTypeSupport,
testing::Types<rosidl_typesupport_microxrcedds_test_msg::msg::Array>);
TYPED_TEST(ArraysTestTypeSupport, serialize_array_types)
{
std::function<void (
const rosidl_typesupport_microxrcedds_test_msg::msg::Array &,
const rosidl_typesupport_microxrcedds_test_msg::msg::Array &)> compare_arrays ([](
const rosidl_typesupport_microxrcedds_test_msg::msg::Array & A,
const rosidl_typesupport_microxrcedds_test_msg::msg::Array & B) -> void
{

EXPECT_EQ(A.array_bool_test.size(), 3);
EXPECT_EQ(A.array_byte_test.size(), 3);
EXPECT_EQ(A.array_char_test.size(), 3);
EXPECT_EQ(A.array_float32_test.size(), 3);
EXPECT_EQ(A.array_double_test.size(), 3);
EXPECT_EQ(A.array_int8_test.size(), 3);
EXPECT_EQ(A.array_uint8_test.size(), 3);
EXPECT_EQ(A.array_int16_test.size(), 3);
EXPECT_EQ(A.array_uint16_test.size(), 3);
EXPECT_EQ(A.array_int32_test.size(), 3);
EXPECT_EQ(A.array_uint32_test.size(), 3);
EXPECT_EQ(A.array_int64_test.size(), 3);
EXPECT_EQ(A.array_uint64_test.size(), 3);
EXPECT_EQ(A.array_string_test.size(), 3);

EXPECT_EQ(A.array_bool_test.size(), B.array_bool_test.size());
EXPECT_EQ(A.array_byte_test.size(), B.array_byte_test.size());
EXPECT_EQ(A.array_char_test.size(), B.array_char_test.size());
EXPECT_EQ(A.array_float32_test.size(), B.array_float32_test.size());
EXPECT_EQ(A.array_double_test.size(), B.array_double_test.size());
EXPECT_EQ(A.array_int8_test.size(), B.array_int8_test.size());
EXPECT_EQ(A.array_uint8_test.size(), B.array_uint8_test.size());
EXPECT_EQ(A.array_int16_test.size(), B.array_int16_test.size());
EXPECT_EQ(A.array_uint16_test.size(), B.array_uint16_test.size());
EXPECT_EQ(A.array_int32_test.size(), B.array_int32_test.size());
EXPECT_EQ(A.array_uint32_test.size(), B.array_uint32_test.size());
EXPECT_EQ(A.array_int64_test.size(), B.array_int64_test.size());
EXPECT_EQ(A.array_uint64_test.size(), B.array_uint64_test.size());
EXPECT_EQ(A.array_string_test.size(), B.array_string_test.size());

for (size_t i = 0; i < A.array_bool_test.size(); ++i)
{
EXPECT_EQ(A.array_bool_test[i].compare(B.array_bool_test[i]), 0);
}
for (size_t i = 0; i < A.array_byte_test.size(); ++i)
{
EXPECT_EQ(A.array_byte_test[i].compare(B.array_byte_test[i]), 0);
}
for (size_t i = 0; i < A.array_char_test.size(); ++i)
{
EXPECT_EQ(A.array_char_test[i].compare(B.array_char_test[i]), 0);
}
for (size_t i = 0; i < A.array_float32_test.size(); ++i)
{
EXPECT_EQ(A.array_float32_test[i].compare(B.array_float32_test[i]), 0);
}
for (size_t i = 0; i < A.array_double_test.size(); ++i)
{
EXPECT_EQ(A.array_double_test[i].compare(B.array_double_test[i]), 0);
}
for (size_t i = 0; i < A.array_int8_test.size(); ++i)
{
EXPECT_EQ(A.array_int8_test[i].compare(B.array_int8_test[i]), 0);
}
for (size_t i = 0; i < A.array_uint8_test.size(); ++i)
{
EXPECT_EQ(A.array_uint8_test[i].compare(B.array_uint8_test[i]), 0);
}
for (size_t i = 0; i < A.array_int16_test.size(); ++i)
{
EXPECT_EQ(A.array_int16_test[i].compare(B.array_int16_test[i]), 0);
}
for (size_t i = 0; i < A.array_uint16_test.size(); ++i)
{
EXPECT_EQ(A.array_uint16_test[i].compare(B.array_uint16_test[i]), 0);
}
for (size_t i = 0; i < A.array_int32_test.size(); ++i)
{
EXPECT_EQ(A.array_int32_test[i].compare(B.array_int32_test[i]), 0);
}
for (size_t i = 0; i < A.array_uint32_test.size(); ++i)
{
EXPECT_EQ(A.array_uint32_test[i].compare(B.array_uint32_test[i]), 0);
}
for (size_t i = 0; i < A.array_int64_test.size(); ++i)
{
EXPECT_EQ(A.array_int64_test[i].compare(B.array_int64_test[i]), 0);
}
for (size_t i = 0; i < A.array_uint64_test.size(); ++i)
{
EXPECT_EQ(A.array_uint64_test[i].compare(B.array_uint64_test[i]), 0);
}
for (size_t i = 0; i < A.array_string_test.size(); ++i)
{
EXPECT_EQ(A.array_string_test[i].compare(B.array_string_test[i]), 0);
}
});

// Initialize data to be serialized and deserialized

rosidl_typesupport_microxrcedds_test_msg::msg::Array init_array;
init_array.array_bool_test = {true, true, false};
init_array.array_byte_test = {0, 1, 1};
init_array.array_char_test = {'y', 'x', 'w'};
init_array.array_float32_test = {1.23, 45.6, -222.0);
init_array.array_double_test = {5287483999.3, -46.5, 2.};
init_array.array_int8_test = {1, 2, -124};
init_array.array_uint8_test = {11, 12, 13};
init_array.array_int16_test = {-360, 1, 1};
init_array.array_uint16_test = {360, 800, 13};
init_array.array_int32_test = {1000, 16843009, - 244};
init_array.array_uint32_test = {1000, 3000, 2};
init_array.array_int64_test = {72340172838076673L, -3000, 16};
init_array.array_uint64_test = {21, 72340172838076673L, 14};
init_array.array_string_test = {"This", "is", "it"};

this->setup(std::move(init_array), compare_arrays);
this->check_identifier();
this->test_serialize_deserialize();
}
1 change: 1 addition & 0 deletions test/msg/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ if(BUILD_TESTING)
"msg/UnboundedString.msg"
"msg/Primitive.msg"
"msg/Sequence.msg"
"msg/Array.msg"
)

rosidl_generate_interfaces(${PROJECT_NAME}
Expand Down
14 changes: 14 additions & 0 deletions test/msg/msg/Array.msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
bool[3] array_bool_test
byte[3] array_byte_test
char[3] array_char_test
float32[3] array_float32_test
float64[3] array_double_test
int8[3] array_int8_test
uint8[3] array_uint8_test
int16[3] array_int16_test
uint16[3] array_uint16_test
int32[3] array_int32_test
uint32[3] array_uint32_test
int64[3] array_int64_test
uint64[3] array_uint64_test
string[3] array_string_test
14 changes: 1 addition & 13 deletions test/msg/msg/Primitive.msg
Original file line number Diff line number Diff line change
@@ -1,27 +1,15 @@
bool bool_test
bool[11] bool_array_test
byte byte_test
byte[11] byte_array_test
char char_test
char[11] char_array_test
float32 float32_test
float32[11] float32_array_test
float64 double_test
float64[11] float64_array_test
int8 int8_test
int8[11] int8_array_test
uint8 uint8_test
uint8[11] uint8_array_test
int16 int16_test
int16[11] int16_array_test
uint16 uint16_test
uint16[11] uint16_array_test
int32 int32_test
int32[11] int32_array_test
uint32 uint32_test
uint32[11] uint32_array_test
int64 int64_test
int64[11] int64_array_test
uint64 uint64_test
uint64[11] uint64_array_test
string string_test
UnboundedString nested_test
13 changes: 13 additions & 0 deletions test/msg/msg/Sequence.msg
Original file line number Diff line number Diff line change
@@ -1 +1,14 @@
bool[] sequence_bool_test
byte[] sequence_byte_test
char[] sequence_char_test
float32[] sequence_float32_test
float64[] sequence_double_test
int8[] sequence_int8_test
uint8[] sequence_uint8_test
int16[] sequence_int16_test
uint16[] sequence_uint16_test
int32[] sequence_int32_test
uint32[] sequence_uint32_test
int64[] sequence_int64_test
uint64[] sequence_uint64_test
string[] sequence_string_test