Skip to content

Commit

Permalink
Move tests to xtypes tests
Browse files Browse the repository at this point in the history
Signed-off-by: Lucia Echevarria <luciaechevarria@eprosima.com>
  • Loading branch information
LuciaEchevarria99 committed Jun 7, 2024
1 parent 8ba8f97 commit 5c344f6
Show file tree
Hide file tree
Showing 28 changed files with 23,106 additions and 24,773 deletions.
1 change: 1 addition & 0 deletions test/unittest/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ add_subdirectory(dds/status)
add_subdirectory(dds/subscriber)
add_subdirectory(dds/topic)
add_subdirectory(dds/topic/DDSSQLFilter)
add_subdirectory(dds/xtypes/dyndata_idl)
add_subdirectory(dds/xtypes/type_representation)
add_subdirectory(logging)
add_subdirectory(rtps/attributes)
Expand Down
48 changes: 48 additions & 0 deletions test/unittest/dds/xtypes/dyndata_idl/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Copyright 2024 Proyectos y Sistemas de Mantenimiento SL (eProsima).
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

set(RESOURCEIDLTOJSONTESTS_SOURCE
idl_to_json_Tests.cpp
${PROJECT_SOURCE_DIR}/test/unittest/dds/xtypes/dyndata_idl/types/types.cpp
${PROJECT_SOURCE_DIR}/src/cpp/fastdds/xtypes/utils.cpp)

file(GLOB DATATYPEBASE_SOURCES_CPP "types/*.cpp")
file(GLOB DATATYPE_SOURCES_CPP "types/**/**/*.cpp")
file(GLOB DATATYPE_SOURCES_CXX "types/**/**/*.cxx")

set(
EXAMPLE_SOURCES
${IMPLEMENTATION_SOURCES_CPP}
${DATATYPEBASE_SOURCES_CPP}
${DATATYPE_SOURCES_CPP}
${DATATYPE_SOURCES_CXX}
)

if(WIN32)
add_definitions(-D_WIN32_WINNT=0x0601)
endif()

add_executable(idl_to_json_Tests ${RESOURCEIDLTOJSONTESTS_SOURCE} ${EXAMPLE_SOURCES})
target_compile_definitions(idl_to_json_Tests PRIVATE
$<$<AND:$<NOT:$<BOOL:${WIN32}>>,$<STREQUAL:"${CMAKE_BUILD_TYPE}","Debug">>:__DEBUG>
$<$<BOOL:${INTERNAL_DEBUG}>:__INTERNALDEBUG> # Internal debug activated.
)
target_include_directories(idl_to_json_Tests PRIVATE
${PROJECT_SOURCE_DIR}/include ${PROJECT_BINARY_DIR}/include)
target_link_libraries(idl_to_json_Tests
fastdds
fastcdr
GTest::gtest
)
gtest_discover_tests(idl_to_json_Tests)
Original file line number Diff line number Diff line change
Expand Up @@ -398,8 +398,6 @@ std::string expected_json_complete = R"({
}
})";



TEST(idl_to_json_Tests, DataTest)
{
// std::string topic_name = "TypeIntrospectionTopic";
Expand Down Expand Up @@ -435,42 +433,6 @@ TEST(idl_to_json_Tests, DataTest)

}

TEST(idl_to_json_Tests, HelloWorld)
{
// std::string topic_name = "TypeIntrospectionTopic";
DataTypeKind data_type_hw = DataTypeKind::HELLO_WORLD;

auto data_type_hw_ = data_type_factory(data_type_hw);

eprosima::fastdds::dds::DynamicType::_ref_type dynamic_type_hw = data_type_hw_->generate_type_support_and_get_dyn_type();

// Get dynamic data depending on data_type_hw
auto dyn_data_hw = eprosima::fastdds::dds::DynamicDataFactory::get_instance()->create_data(dynamic_type_hw);

dyn_data_hw->set_uint32_value(dyn_data_hw->get_member_id_by_name("index"), 2);
dyn_data_hw->set_string_value(dyn_data_hw->get_member_id_by_name("message"), "Hello Test");

std::stringstream generated_json_hw;
generated_json_hw << std::setw(4);
if (eprosima::fastdds::dds::RETCODE_OK ==
eprosima::fastdds::dds::json_serialize(
dyn_data_hw,
generated_json_hw,
eprosima::fastdds::dds::DynamicDataJsonFormat::EPROSIMA))
{
std::cout << "---------------" << std::endl;
std::cout << generated_json_hw.str() << std::endl;
std::cout << "---------------" << std::endl;

ASSERT_EQ(generated_json_hw.str(), expected_json_complete);
}
else
{
std::cout << "FAILED" << std::endl;
}

}


int main(
int argc,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
struct PrimitivesStruct_TypeIntrospectionExample
struct PrimitivesStruct
{
boolean my_bool;
octet my_octet;
Expand Down Expand Up @@ -35,15 +35,15 @@ bitmask MyBitMask
};

// TODO: test aliasing struct
typedef PrimitivesStruct_TypeIntrospectionExample MyAliasedStruct;
typedef PrimitivesStruct MyAliasedStruct;
typedef MyEnum MyAliasedEnum;
typedef string<100> MyAliasedBoundedString;
typedef MyAliasedEnum MyRecursiveAlias;

union InnerUnion switch (short)
{
case 0:
@id(0x10) PrimitivesStruct_TypeIntrospectionExample first;
@id(0x10) PrimitivesStruct first;
case 1:
default:
long long second;
Expand All @@ -68,7 +68,7 @@ bitset MyBitSet
bitfield<12, short> d;
};

struct AllStruct_TypeIntrospectionExample : PrimitivesStruct_TypeIntrospectionExample
struct AllStruct : PrimitivesStruct
{
// strings
string my_string;
Expand Down Expand Up @@ -109,19 +109,19 @@ struct AllStruct_TypeIntrospectionExample : PrimitivesStruct_TypeIntrospectionEx
MyBitSet my_bitset;
};

struct DataTest_TypeIntrospectionExample
struct DataTest
{
unsigned long index;

// inner struct
AllStruct_TypeIntrospectionExample inner_struct;
AllStruct inner_struct;

// complex sequence
sequence<AllStruct_TypeIntrospectionExample> complex_sequence;
sequence<AllStruct> complex_sequence;

// complex array
AllStruct_TypeIntrospectionExample complex_array[2];
AllStruct complex_array[2];

// complex map
map<short, AllStruct_TypeIntrospectionExample> complex_map;
map<short, AllStruct> complex_map;
};
Loading

0 comments on commit 5c344f6

Please sign in to comment.