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

[18721] Typelookup service tests #3597

Closed
wants to merge 14 commits into from
Closed
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
12 changes: 12 additions & 0 deletions include/fastdds/dds/builtin/typelookup/TypeLookupManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,21 @@ class TypeLookupManager
#endif
*/

/**
* @brief Send a request for the dependencies of the given TypeIdentifiers.
*
* @param in Sequence of TypeIdentifiers for which the participant wants to get the dependencies.
* @return fastrtps::rtps::SampleIdentity of the sent request.
*/
fastrtps::rtps::SampleIdentity get_type_dependencies(
const fastrtps::types::TypeIdentifierSeq& in) const;

/**
* @brief Send a request for the TypeObjects of the given TypeIdentifiers.
*
* @param in Sequence of TypeIdentifiers for which the participant wants to get the related TypeObjects.
* @return fastrtps::rtps::SampleIdentity of the sent request.
*/
fastrtps::rtps::SampleIdentity get_types(
const fastrtps::types::TypeIdentifierSeq& in) const;

Expand Down
14 changes: 11 additions & 3 deletions include/fastdds/dds/domain/DomainParticipant.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -833,18 +833,26 @@ class DomainParticipant : public Entity
* PublicationBuiltinTopicData or SubscriptionBuiltinTopicData, it may request the additional type
* dependencies by invoking the getTypeDependencies operation.
*
* This method sends a request through the TypeLookup Service with the sequence of TypeIdentifiers for which the
* DomainParticipant wants to get the dependencies, returning the SampleIdentity of the sent request.
* It does not wait to receive the reply with the related TypeObjects.
*
* @param in TypeIdentifier sequence
* @return SampleIdentity
* @return SampleIdentity of the sent request.
*/
RTPS_DllAPI fastrtps::rtps::SampleIdentity get_type_dependencies(
const fastrtps::types::TypeIdentifierSeq& in) const;

/**
* A DomainParticipant may invoke the operation getTypes to retrieve the TypeObjects associated with a
* list of TypeIdentifiers.
* list of TypeIdentifiers: XTYPES v1.3 clause 7.6.3.3.4.2
*
* This method sends a request through the TypeLookup Service with the TypeIdentifiers returning the SampleIdentity
* of the sent request.
* It does not wait to receive the reply with the related TypeObjects.
*
* @param in TypeIdentifier sequence
* @return SampleIdentity
* @return SampleIdentity of the sent request
*/
RTPS_DllAPI fastrtps::rtps::SampleIdentity get_types(
const fastrtps::types::TypeIdentifierSeq& in) const;
Expand Down
5,568 changes: 5,568 additions & 0 deletions tatus

Large diffs are not rendered by default.

127 changes: 86 additions & 41 deletions test/unittest/dds/participant/ParticipantTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include <dds/topic/Topic.hpp>
#include <fastdds/dds/builtin/topic/ParticipantBuiltinTopicData.hpp>
#include <fastdds/dds/builtin/topic/TopicBuiltinTopicData.hpp>
#include <fastdds/dds/builtin/typelookup/TypeLookupManager.hpp>
#include <fastdds/dds/domain/DomainParticipantFactory.hpp>
#include <fastdds/dds/domain/DomainParticipantListener.hpp>
#include <fastdds/dds/domain/qos/DomainParticipantQos.hpp>
Expand Down Expand Up @@ -3140,20 +3141,13 @@ TEST(ParticipantTests, RegisterDynamicTypeToFactoriesNotTypeIdentifier)
ASSERT_EQ(DomainParticipantFactory::get_instance()->delete_participant(participant), ReturnCode_t::RETCODE_OK);
}

/*
* This test create a sequence of TypeIdentifiers to call the get_types() DomainParticipant function. It should return
* the TypeObjects associated with the TypeIdentifiers. Finally, the test checks that the writer guid prefix given by
* the TypeObject is the same as the DomainPartipant guid prefix.
/**
* Auxiliary method registering a dynamic data string into the participant
*/
TEST(ParticipantTests, GetTypes)
void register_dynamic_data_string(
DomainParticipant* participant,
fastrtps::types::TypeIdentifierSeq& types)
{
// Create the participant
DomainParticipantQos pqos;
pqos.wire_protocol().builtin.typelookup_config.use_client = true;
DomainParticipant* participant =
DomainParticipantFactory::get_instance()->create_participant(
(uint32_t)GET_PID() % 230, pqos);

// Create the dynamic type builder
DynamicTypeBuilder_ptr builder_string = DynamicTypeBuilderFactory::get_instance()->create_string_builder(100);
// Create the dynamic type
Expand All @@ -3169,61 +3163,112 @@ TEST(ParticipantTests, GetTypes)
type_string.register_type(participant);

// Create the sequence of TypeIdentifiers
const fastrtps::types::TypeIdentifier* indentifier_string =
const fastrtps::types::TypeIdentifier* identifier_string =
fastrtps::types::TypeObjectFactory::get_instance()->get_type_identifier_trying_complete(
type_string.get_type_name());

types.push_back(*identifier_string);
}

/*
* This test creates a sequence of TypeIdentifiers to call the get_types() DomainParticipant function.
* The DomainParticipant is configured to enable the client endpoints of the TypeLookup Service.
* The method returns the SampleIdentity of the sent request which guid prefix should be the same as the
* DomainParticipant one.
*/
TEST(ParticipantTests, GetTypes_typelookup_config_client)
{
// Create the participant
DomainParticipantQos pqos;
pqos.wire_protocol().builtin.typelookup_config.use_client = true;
DomainParticipant* participant =
DomainParticipantFactory::get_instance()->create_participant(
(uint32_t)GET_PID() % 230, pqos);
ASSERT_NE(nullptr, participant);

fastrtps::types::TypeIdentifierSeq types;
types.push_back(*indentifier_string);
register_dynamic_data_string(participant, types);

// Checks that the writer guid prefix given by the TypeObject is the same as the DomainPartipant guid prefix
ASSERT_EQ(participant->guid().guidPrefix, participant->get_types(types).writer_guid().guidPrefix);
EXPECT_EQ(participant->guid().guidPrefix, participant->get_types(types).writer_guid().guidPrefix);

// Remove the participant
ASSERT_EQ(DomainParticipantFactory::get_instance()->delete_participant(participant), ReturnCode_t::RETCODE_OK);
EXPECT_EQ(DomainParticipantFactory::get_instance()->delete_participant(participant), ReturnCode_t::RETCODE_OK);
}

/*
* This test creates a sequence of TypeIdentifiers to call the get_types() DomainParticipant function.
* The DomainParticipant is configured to enable the server endpoints of the TypeLookup Service.
* The method returns the SampleIdentity of the sent request which guid prefix should be the same as the
* DomainParticipant one.
*/
TEST(ParticipantTests, GetTypes_typelookup_config_server)
{
// Create the participant
DomainParticipantQos pqos;
pqos.wire_protocol().builtin.typelookup_config.use_server = true;
DomainParticipant* participant =
DomainParticipantFactory::get_instance()->create_participant((uint32_t)GET_PID() % 230, pqos);
ASSERT_NE(nullptr, participant);

fastrtps::types::TypeIdentifierSeq types;
register_dynamic_data_string(participant, types);

// Checks that the writer guid prefix given by the TypeObject is the same as the DomainPartipant guid prefix
EXPECT_EQ(builtin::INVALID_SAMPLE_IDENTITY, participant->get_types(types));

// Remove the participant
EXPECT_EQ(DomainParticipantFactory::get_instance()->delete_participant(participant), ReturnCode_t::RETCODE_OK);
}

/*
* This test create a sequence of TypeIdentifiers to call the get_type_dependencies() DomainParticipant function.
* Finally, the test checks that the writer guid prefix given by the TypeObject is the same as the DomainPartipant
* guid prefix.
* This test creates a sequence of TypeIdentifiers to call the get_type_dependencies() DomainParticipant function.
* The DomainParticipant is configured to enable the client endpoints of the TypeLookup Service.
* The method returns the SampleIdentity of the sent request which guid prefix should be the same as the
* DomainParticipant one.
*/
TEST(ParticipantTests, GetTypeDependencies)
TEST(ParticipantTests, GetTypeDependencies_typelookup_config_client)
{
// Create the participant
DomainParticipantQos pqos;
pqos.wire_protocol().builtin.typelookup_config.use_client = true;
DomainParticipant* participant =
DomainParticipantFactory::get_instance()->create_participant(
(uint32_t)GET_PID() % 230, pqos);
DomainParticipantFactory::get_instance()->create_participant((uint32_t)GET_PID() % 230, pqos);
ASSERT_NE(nullptr, participant);

// Create the dynamic type builder
DynamicTypeBuilder_ptr builder_string = DynamicTypeBuilderFactory::get_instance()->create_string_builder(100);
// Create the dynamic type
DynamicType_ptr dyn_type_string = builder_string->build();
TypeSupport type_string(new eprosima::fastrtps::types::DynamicPubSubType(dyn_type_string));
// Create the data instance
DynamicData_ptr data_string(DynamicDataFactory::get_instance()->create_data(dyn_type_string));
data_string->set_string_value("Dynamic String");
fastrtps::types::TypeIdentifierSeq types;
register_dynamic_data_string(participant, types);

// Register the type
type_string->auto_fill_type_information(true);
type_string->auto_fill_type_object(true);
type_string.register_type(participant);
// Checks that the writer guid prefix given by the TypeObject is the same as the DomainPartipant guid prefix
EXPECT_EQ(participant->guid().guidPrefix, participant->get_type_dependencies(types).writer_guid().guidPrefix);

// Create the sequence of TypeIdentifiers
const fastrtps::types::TypeIdentifier* indentifier_string =
fastrtps::types::TypeObjectFactory::get_instance()->get_type_identifier_trying_complete(
type_string.get_type_name());
// Remove the participant
EXPECT_EQ(DomainParticipantFactory::get_instance()->delete_participant(participant), ReturnCode_t::RETCODE_OK);
}

/*
* This test creates a sequence of TypeIdentifiers to call the get_type_dependencies() DomainParticipant function.
* The DomainParticipant is configured to enable the server endpoints of the TypeLookup Service.
* The method returns the SampleIdentity of the sent request which guid prefix should be the same as the
* DomainParticipant one.
*/
TEST(ParticipantTests, GetTypeDependencies_typelookup_config_server)
{
// Create the participant
DomainParticipantQos pqos;
pqos.wire_protocol().builtin.typelookup_config.use_server = true;
DomainParticipant* participant =
DomainParticipantFactory::get_instance()->create_participant((uint32_t)GET_PID() % 230, pqos);
ASSERT_NE(nullptr, participant);

fastrtps::types::TypeIdentifierSeq types;
types.push_back(*indentifier_string);
register_dynamic_data_string(participant, types);

// Checks that the writer guid prefix given by the TypeObject is the same as the DomainPartipant guid prefix
ASSERT_EQ(participant->guid().guidPrefix, participant->get_type_dependencies(types).writer_guid().guidPrefix);
EXPECT_EQ(builtin::INVALID_SAMPLE_IDENTITY, participant->get_type_dependencies(types));

// Remove the participant
ASSERT_EQ(DomainParticipantFactory::get_instance()->delete_participant(participant), ReturnCode_t::RETCODE_OK);
EXPECT_EQ(DomainParticipantFactory::get_instance()->delete_participant(participant), ReturnCode_t::RETCODE_OK);
}

/*
Expand Down
24 changes: 24 additions & 0 deletions test/unittest/xtypes/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,30 @@ if(WIN32)
)
endif()

set(TYPELOOKUP_SERVICE_TEST_SOURCE
TypeLookupServiceTests.cpp
idl/TypeLookupServiceTypes.cxx
idl/TypeLookupServiceTypesPubSubTypes.cxx
idl/TypeLookupServiceTypesTypeObject.cxx
${PROJECT_SOURCE_DIR}/src/cpp/utils/md5.cpp
)

add_executable(TypeLookupServiceTests ${TYPELOOKUP_SERVICE_TEST_SOURCE})
target_compile_definitions(TypeLookupServiceTests PRIVATE
$<$<AND:$<NOT:$<BOOL:${WIN32}>>,$<STREQUAL:"${CMAKE_BUILD_TYPE}","Debug">>:__DEBUG>
$<$<BOOL:${INTERNAL_DEBUG}>:__INTERNALDEBUG> # Internal debug activated.
)
target_include_directories(TypeLookupServiceTests PRIVATE
${PROJECT_SOURCE_DIR}/include ${PROJECT_BINARY_DIR}/include
${PROJECT_SOURCE_DIR}/src/cpp
)
target_link_libraries(TypeLookupServiceTests GTest::gtest
$<$<BOOL:${WIN32}>:iphlpapi$<SEMICOLON>Shlwapi>
$<$<BOOL:${WIN32}>:ws2_32>
fastrtps
)
add_gtest(TypeLookupServiceTests SOURCES ${TYPELOOKUP_SERVICE_TEST_SOURCE})

set(XTYPES_SOURCE
${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/AnnotationDescriptor.cpp
${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/DynamicData.cpp
Expand Down
Loading