Skip to content

Commit

Permalink
Refs #1977. Fixing warnings.
Browse files Browse the repository at this point in the history
  • Loading branch information
richiware committed Mar 28, 2017
1 parent a946730 commit 2b545fc
Show file tree
Hide file tree
Showing 10 changed files with 94 additions and 56 deletions.
6 changes: 5 additions & 1 deletion cmake/dev/compile_example.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,14 @@ macro(compile_example example example_directory)
# Separate CMAKE_PREFIX_PATH
string(REPLACE ";" "|" CMAKE_PREFIX_PATH_ "${CMAKE_PREFIX_PATH}")
set(${example}_CMAKE_ARGS
"-DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE}"
"-DCMAKE_INSTALL_PREFIX:PATH=${CMAKE_INSTALL_PREFIX}"
"-DCMAKE_PREFIX_PATH:PATH=${CMAKE_CURRENT_BINARY_DIR}/config|${CMAKE_PREFIX_PATH_}"
"-DBIN_INSTALL_DIR:PATH=${BIN_INSTALL_DIR}")
if(UNIX)
list(APPEND ${example}_CMAKE_ARGS
"-DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE}"
)
endif()
list(APPEND ${example}_CMAKE_ARGS LIST_SEPARATOR "|")

include(ExternalProject)
Expand Down
6 changes: 3 additions & 3 deletions examples/C++/SecureHelloWorldExample/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,6 @@ install(TARGETS SecureHelloWorldExample
RUNTIME DESTINATION examples/C++/SecureHelloWorldExample/${BIN_INSTALL_DIR})

add_custom_command(TARGET SecureHelloWorldExample POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
${PROJECT_SOURCE_DIR}/certs/*.pem
${PROJECT_BINARY_DIR})
COMMAND ${CMAKE_COMMAND} -E copy_directory
${PROJECT_SOURCE_DIR}/certs
${PROJECT_BINARY_DIR}/certs)
6 changes: 3 additions & 3 deletions examples/C++/SecureHelloWorldExample/HelloWorldPublisher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ bool HelloWorldPublisher::init()
participant_property_policy.properties().emplace_back("dds.sec.auth.plugin",
"builtin.PKI-DH");
participant_property_policy.properties().emplace_back("dds.sec.auth.builtin.PKI-DH.identity_ca",
"file://maincacert.pem");
"file://certs/maincacert.pem");
participant_property_policy.properties().emplace_back("dds.sec.auth.builtin.PKI-DH.identity_certificate",
"file://mainpubcert.pem");
"file://certs/mainpubcert.pem");
participant_property_policy.properties().emplace_back("dds.sec.auth.builtin.PKI-DH.private_key",
"file://mainpubkey.pem");
"file://certs/mainpubkey.pem");
participant_property_policy.properties().emplace_back("dds.sec.crypto.plugin",
"builtin.AES-GCM-GMAC");
participant_property_policy.properties().emplace_back("rtps.participant.rtps_protection_kind", "ENCRYPT");
Expand Down
6 changes: 3 additions & 3 deletions examples/C++/SecureHelloWorldExample/HelloWorldSubscriber.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ bool HelloWorldSubscriber::init()
participant_property_policy.properties().emplace_back("dds.sec.auth.plugin",
"builtin.PKI-DH");
participant_property_policy.properties().emplace_back("dds.sec.auth.builtin.PKI-DH.identity_ca",
"file://maincacert.pem");
"file://certs/maincacert.pem");
participant_property_policy.properties().emplace_back("dds.sec.auth.builtin.PKI-DH.identity_certificate",
"file://mainsubcert.pem");
"file://certs/mainsubcert.pem");
participant_property_policy.properties().emplace_back("dds.sec.auth.builtin.PKI-DH.private_key",
"file://mainsubkey.pem");
"file://certs/mainsubkey.pem");
participant_property_policy.properties().emplace_back("dds.sec.crypto.plugin",
"builtin.AES-GCM-GMAC");
participant_property_policy.properties().emplace_back("rtps.participant.rtps_protection_kind", "ENCRYPT");
Expand Down
2 changes: 2 additions & 0 deletions src/cpp/rtps/messages/RTPSMessageGroup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ bool RTPSMessageGroup::insert_submessage(const std::vector<GUID_t>& remote_endpo

bool RTPSMessageGroup::add_info_dst_in_buffer(CDRMessage_t* buffer, const std::vector<GUID_t>& remote_endpoints)
{
(void)remote_endpoints;
bool added = false;

#if HAVE_SECURITY
Expand Down Expand Up @@ -310,6 +311,7 @@ bool RTPSMessageGroup::add_info_dst_in_buffer(CDRMessage_t* buffer, const std::v

bool RTPSMessageGroup::add_info_ts_in_buffer(const std::vector<GUID_t>& remote_readers)
{
(void)remote_readers;
logInfo(RTPS_WRITER, "Sending INFO_TS message");

#if HAVE_SECURITY
Expand Down
4 changes: 4 additions & 0 deletions src/cpp/rtps/participant/RTPSParticipantImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,7 @@ bool RTPSParticipantImpl::createWriter(RTPSWriter** WriterOut,
}

// Get properties.
#if HAVE_SECURITY
bool submessage_protection = false;
const std::string* property_value = PropertyPolicyHelper::find_property(param.endpoint.properties, "rtps.endpoint.submessage_protection_kind");

Expand All @@ -461,6 +462,7 @@ bool RTPSParticipantImpl::createWriter(RTPSWriter** WriterOut,

if(property_value != nullptr && property_value->compare("ENCRYPT") == 0)
payload_protection = true;
#endif

// Normalize unicast locators
if (!param.endpoint.unicastLocatorList.empty())
Expand Down Expand Up @@ -575,6 +577,7 @@ bool RTPSParticipantImpl::createReader(RTPSReader** ReaderOut,
}

// Get properties.
#if HAVE_SECURITY
bool submessage_protection = false;
const std::string* property_value = PropertyPolicyHelper::find_property(param.endpoint.properties, "rtps.endpoint.submessage_protection_kind");

Expand All @@ -586,6 +589,7 @@ bool RTPSParticipantImpl::createReader(RTPSReader** ReaderOut,

if(property_value != nullptr && property_value->compare("ENCRYPT") == 0)
payload_protection = true;
#endif

// Normalize unicast locators
if (!param.endpoint.unicastLocatorList.empty())
Expand Down
48 changes: 30 additions & 18 deletions test/unittest/transport/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,40 +53,52 @@ if(NOT ((MSVC OR MSVC_IDE) AND EPROSIMA_INSTALLER))

include_directories(mock/)

string(RANDOM LENGTH 4 ALPHABET 0123456789 PORT_RANDOM_NUMBER)
math(EXPR PORT_RANDOM_NUMBER "${PORT_RANDOM_NUMBER} + 0") # Remove extra leading 0s.
if(PORT_RANDOM_NUMBER LESS 1025)
math(EXPR PORT_RANDOM_NUMBER "${PORT_RANDOM_NUMBER} + 1024") # Remove extra leading 0s.
endif()

add_executable(UDPv4Tests ${UDPV4TESTS_SOURCE})
add_gtest(UDPv4Tests ${UDPV4TESTS_SOURCE})
add_gtest(UDPv4Tests ${UDPV4TESTS_SOURCE}
ENVIRONMENT "PORT_RANDOM_NUMBER=${PORT_RANDOM_NUMBER}"
)
target_compile_definitions(UDPv4Tests PRIVATE FASTRTPS_NO_LIB)
target_include_directories(UDPv4Tests PRIVATE ${GTEST_INCLUDE_DIRS}
${PROJECT_SOURCE_DIR}/include ${PROJECT_BINARY_DIR}/include/${PROJECT_NAME})
target_link_libraries(UDPv4Tests ${GTEST_LIBRARIES} ${MOCKS} )
if(MSVC OR MSVC_IDE)
target_link_libraries(UDPv4Tests ${PRIVACY}
iphlpapi Shlwapi
)
endif()
if(MSVC OR MSVC_IDE)
target_link_libraries(UDPv4Tests ${PRIVACY}
iphlpapi Shlwapi
)
endif()

add_executable(UDPv6Tests ${UDPV6TESTS_SOURCE})
add_gtest(UDPv6Tests ${UDPV6TESTS_SOURCE})
add_gtest(UDPv6Tests ${UDPV6TESTS_SOURCE}
ENVIRONMENT "PORT_RANDOM_NUMBER=${PORT_RANDOM_NUMBER}"
)
target_compile_definitions(UDPv6Tests PRIVATE FASTRTPS_NO_LIB)
target_include_directories(UDPv6Tests PRIVATE ${GTEST_INCLUDE_DIRS}
${PROJECT_SOURCE_DIR}/include ${PROJECT_BINARY_DIR}/include/${PROJECT_NAME})
target_link_libraries(UDPv6Tests ${GTEST_LIBRARIES} ${MOCKS} )
if(MSVC OR MSVC_IDE)
target_link_libraries(UDPv6Tests ${PRIVACY}
iphlpapi Shlwapi
)
endif()
if(MSVC OR MSVC_IDE)
target_link_libraries(UDPv6Tests ${PRIVACY}
iphlpapi Shlwapi
)
endif()

add_executable(test_UDPv4Tests ${TEST_UDPV4TESTS_SOURCE})
add_gtest(test_UDPv4Tests ${TEST_UDPV4TESTS_SOURCE})
add_gtest(test_UDPv4Tests ${TEST_UDPV4TESTS_SOURCE}
ENVIRONMENT "PORT_RANDOM_NUMBER=${PORT_RANDOM_NUMBER}"
)
target_compile_definitions(test_UDPv4Tests PRIVATE FASTRTPS_NO_LIB)
target_include_directories(test_UDPv4Tests PRIVATE ${GTEST_INCLUDE_DIRS}
${PROJECT_SOURCE_DIR}/include ${PROJECT_BINARY_DIR}/include/${PROJECT_NAME})
target_link_libraries(test_UDPv4Tests ${GTEST_LIBRARIES} ${MOCKS} )
if(MSVC OR MSVC_IDE)
target_link_libraries(test_UDPv4Tests ${PRIVACY}
iphlpapi Shlwapi
)
endif()
if(MSVC OR MSVC_IDE)
target_link_libraries(test_UDPv4Tests ${PRIVACY}
iphlpapi Shlwapi
)
endif()
endif()
endif()
32 changes: 19 additions & 13 deletions test/unittest/transport/UDPv4Tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ using namespace eprosima::fastrtps::rtps;
const uint32_t ReceiveBufferCapacity = 65536;
#endif

static uint32_t g_default_port = 7400;

class UDPv4Tests: public ::testing::Test
{
public:
Expand Down Expand Up @@ -72,7 +74,7 @@ TEST_F(UDPv4Tests, opening_and_closing_output_channel)

Locator_t genericOutputChannelLocator;
genericOutputChannelLocator.kind = LOCATOR_KIND_UDPv4;
genericOutputChannelLocator.port = 7400; // arbitrary
genericOutputChannelLocator.port = g_default_port; // arbitrary

// Then
ASSERT_FALSE (transportUnderTest.IsOutputChannelOpen(genericOutputChannelLocator));
Expand All @@ -91,7 +93,7 @@ TEST_F(UDPv4Tests, opening_and_closing_input_channel)

Locator_t multicastFilterLocator;
multicastFilterLocator.kind = LOCATOR_KIND_UDPv4;
multicastFilterLocator.port = 7410; // arbitrary
multicastFilterLocator.port = g_default_port; // arbitrary
multicastFilterLocator.set_IP4_address(239, 255, 0, 1);

// Then
Expand All @@ -110,12 +112,12 @@ TEST_F(UDPv4Tests, send_and_receive_between_ports)
transportUnderTest.init();

Locator_t multicastLocator;
multicastLocator.port = 7410;
multicastLocator.port = g_default_port;
multicastLocator.kind = LOCATOR_KIND_UDPv4;
multicastLocator.set_IP4_address(239, 255, 0, 1);

Locator_t outputChannelLocator;
outputChannelLocator.port = 7400;
outputChannelLocator.port = g_default_port + 1;
outputChannelLocator.kind = LOCATOR_KIND_UDPv4;
ASSERT_TRUE(transportUnderTest.OpenOutputChannel(outputChannelLocator)); // Includes loopback
ASSERT_TRUE(transportUnderTest.OpenInputChannel(multicastLocator));
Expand Down Expand Up @@ -148,12 +150,12 @@ TEST_F(UDPv4Tests, send_to_loopback)
transportUnderTest.init();

Locator_t multicastLocator;
multicastLocator.port = 7410;
multicastLocator.port = g_default_port;
multicastLocator.kind = LOCATOR_KIND_UDPv4;
multicastLocator.set_IP4_address(239, 255, 0, 1);

Locator_t outputChannelLocator;
outputChannelLocator.port = 7400;
outputChannelLocator.port = g_default_port + 1;
outputChannelLocator.kind = LOCATOR_KIND_UDPv4;
outputChannelLocator.set_IP4_address(127,0,0,1); // Loopback
ASSERT_TRUE(transportUnderTest.OpenOutputChannel(outputChannelLocator));
Expand All @@ -163,7 +165,7 @@ TEST_F(UDPv4Tests, send_to_loopback)
auto sendThreadFunction = [&]()
{
Locator_t destinationLocator;
destinationLocator.port = 7410;
destinationLocator.port = g_default_port;
destinationLocator.kind = LOCATOR_KIND_UDPv4;
EXPECT_TRUE(transportUnderTest.Send(message, 5, outputChannelLocator, multicastLocator));
};
Expand Down Expand Up @@ -193,12 +195,12 @@ TEST_F(UDPv4Tests, send_is_rejected_if_buffer_size_is_bigger_to_size_specified_i

Locator_t genericOutputChannelLocator;
genericOutputChannelLocator.kind = LOCATOR_KIND_UDPv4;
genericOutputChannelLocator.port = 7400;
genericOutputChannelLocator.port = g_default_port;
transportUnderTest.OpenOutputChannel(genericOutputChannelLocator);

Locator_t destinationLocator;
destinationLocator.kind = LOCATOR_KIND_UDPv4;
destinationLocator.port = 7410;
destinationLocator.port = g_default_port + 1;

// Then
std::vector<octet> receiveBufferWrongSize(descriptor.sendBufferSize + 1);
Expand All @@ -213,7 +215,7 @@ TEST_F(UDPv4Tests, Receive_is_rejected_if_buffer_size_is_smaller_than_size_speci

Locator_t genericInputChannelLocator;
genericInputChannelLocator.kind = LOCATOR_KIND_UDPv4;
genericInputChannelLocator.port = 7410;
genericInputChannelLocator.port = g_default_port;
transportUnderTest.OpenInputChannel(genericInputChannelLocator);

Locator_t originLocator;
Expand All @@ -231,7 +233,7 @@ TEST_F(UDPv4Tests, RemoteToMainLocal_simply_strips_out_address_leaving_IP_ANY)

Locator_t remoteLocator;
remoteLocator.kind = LOCATOR_KIND_UDPv4;
remoteLocator.port = 7410;
remoteLocator.port = g_default_port;
remoteLocator.set_IP4_address(222,222,222,222);

// When
Expand All @@ -250,7 +252,7 @@ TEST_F(UDPv4Tests, match_if_port_AND_address_matches)
transportUnderTest.init();

Locator_t locatorAlpha;
locatorAlpha.port = 50000;
locatorAlpha.port = g_default_port;
locatorAlpha.set_IP4_address(239, 255, 0, 1);
Locator_t locatorBeta = locatorAlpha;

Expand All @@ -268,7 +270,7 @@ TEST_F(UDPv4Tests, send_to_wrong_interface)
transportUnderTest.init();

Locator_t outputChannelLocator;
outputChannelLocator.port = 7400;
outputChannelLocator.port = g_default_port;
outputChannelLocator.kind = LOCATOR_KIND_UDPv4;
outputChannelLocator.set_IP4_address(127,0,0,1); // Loopback
ASSERT_TRUE(transportUnderTest.OpenOutputChannel(outputChannelLocator));
Expand All @@ -289,6 +291,10 @@ void UDPv4Tests::HELPER_SetDescriptorDefaults()
int main(int argc, char **argv)
{
Log::SetVerbosity(Log::Info);

if(const char* env_p = std::getenv("PORT_RANDOM_NUMBER"))
g_default_port = std::stoi(env_p);

testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
21 changes: 13 additions & 8 deletions test/unittest/transport/UDPv6Tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ using namespace eprosima::fastrtps;
const uint32_t ReceiveBufferCapacity = 65536;
#endif

static uint32_t g_default_port = 7400;

class UDPv6Tests: public ::testing::Test
{
public:
Expand Down Expand Up @@ -99,7 +101,7 @@ TEST_F(UDPv6Tests, opening_and_closing_output_channel)

Locator_t genericOutputChannelLocator;
genericOutputChannelLocator.kind = LOCATOR_KIND_UDPv6;
genericOutputChannelLocator.port = 7400; // arbitrary
genericOutputChannelLocator.port = g_default_port; // arbitrary

// Then
ASSERT_FALSE (transportUnderTest.IsOutputChannelOpen(genericOutputChannelLocator));
Expand All @@ -119,7 +121,7 @@ TEST_F(UDPv6Tests, opening_and_closing_input_channel)

Locator_t multicastFilterLocator;
multicastFilterLocator.kind = LOCATOR_KIND_UDPv6;
multicastFilterLocator.port = 7410; // arbitrary
multicastFilterLocator.port = g_default_port; // arbitrary
multicastFilterLocator.set_IP6_address(0xff31, 0, 0, 0, 0, 0, 0x8000, 0x1234);

// Then
Expand All @@ -137,12 +139,12 @@ TEST_F(UDPv6Tests, send_and_receive_between_ports)
transportUnderTest.init();

Locator_t multicastLocator;
multicastLocator.port = 7410;
multicastLocator.port = g_default_port;
multicastLocator.kind = LOCATOR_KIND_UDPv6;
multicastLocator.set_IP6_address(0xff31, 0, 0, 0, 0, 0, 0, 0);

Locator_t outputChannelLocator;
outputChannelLocator.port = 7400;
outputChannelLocator.port = g_default_port + 1;
outputChannelLocator.kind = LOCATOR_KIND_UDPv6;
ASSERT_TRUE(transportUnderTest.OpenOutputChannel(outputChannelLocator)); // Includes loopback
ASSERT_TRUE(transportUnderTest.OpenInputChannel(multicastLocator));
Expand All @@ -151,7 +153,7 @@ TEST_F(UDPv6Tests, send_and_receive_between_ports)
auto sendThreadFunction = [&]()
{
Locator_t destinationLocator;
destinationLocator.port = 7410;
destinationLocator.port = g_default_port;
destinationLocator.kind = LOCATOR_KIND_UDPv6;
EXPECT_TRUE(transportUnderTest.Send(message, 5, outputChannelLocator, multicastLocator));
};
Expand All @@ -178,12 +180,12 @@ TEST_F(UDPv6Tests, send_to_loopback)
transportUnderTest.init();
Locator_t multicastLocator;
multicastLocator.port = 7410;
multicastLocator.port = g_default_port;
multicastLocator.kind = LOCATOR_KIND_UDPv6;
multicastLocator.set_IP6_address(0xff31, 0, 0, 0, 0, 0, 0, 0);
Locator_t outputChannelLocator;
outputChannelLocator.port = 7400;
outputChannelLocator.port = g_default_port + 1;
outputChannelLocator.kind = LOCATOR_KIND_UDPv6;
outputChannelLocator.set_IP6_address(0,0,0,0,0,0,0,1); // Loopback
ASSERT_TRUE(transportUnderTest.OpenOutputChannel(outputChannelLocator));
Expand All @@ -193,7 +195,7 @@ TEST_F(UDPv6Tests, send_to_loopback)
auto sendThreadFunction = [&]()
{
Locator_t destinationLocator;
destinationLocator.port = 7410;
destinationLocator.port = g_default_port;
destinationLocator.kind = LOCATOR_KIND_UDPv6;
EXPECT_TRUE(transportUnderTest.Send(message, 5, outputChannelLocator, multicastLocator));
};
Expand Down Expand Up @@ -225,6 +227,9 @@ void UDPv6Tests::HELPER_SetDescriptorDefaults()

int main(int argc, char **argv)
{
if(const char* env_p = std::getenv("PORT_RANDOM_NUMBER"))
g_default_port = std::stoi(env_p);

testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
Loading

0 comments on commit 2b545fc

Please sign in to comment.