Skip to content

Commit

Permalink
Refs #5041. Fixed unit tests.
Browse files Browse the repository at this point in the history
Signed-off-by: Miguel Company <MiguelCompany@eprosima.com>
  • Loading branch information
MiguelCompany committed Apr 5, 2019
1 parent fd84e5a commit d28d629
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/cpp/transport/UDPv4Transport.cpp
Expand Up @@ -280,7 +280,7 @@ bool UDPv4Transport::OpenInputChannel(
uint32_t maxMsgSize)
{
std::unique_lock<std::recursive_mutex> scopedLock(mInputMapMutex);
if (!IsLocatorSupported(locator))
if (!is_locator_allowed(locator))
return false;

bool success = false;
Expand Down
2 changes: 1 addition & 1 deletion src/cpp/transport/UDPv6Transport.cpp
Expand Up @@ -296,7 +296,7 @@ bool UDPv6Transport::OpenInputChannel(
uint32_t maxMsgSize)
{
std::unique_lock<std::recursive_mutex> scopedLock(mInputMapMutex);
if (!IsLocatorSupported(locator))
if (!is_locator_allowed(locator))
return false;

bool success = false;
Expand Down
43 changes: 32 additions & 11 deletions test/unittest/transport/UDPv4Tests.cpp
Expand Up @@ -297,7 +297,18 @@ TEST_F(UDPv4Tests, send_to_wrong_interface)

TEST_F(UDPv4Tests, send_to_blocked_interface)
{
descriptor.interfaceWhiteList.emplace_back("111.111.111.111");
std::vector<IPFinder::info_IP> ip_list;
IPFinder::getIPs(&ip_list);

for (const IPFinder::info_IP& ip : ip_list)
{
if (IPFinder::IP4 == ip.type)
{
descriptor.interfaceWhiteList.emplace_back(ip.name);
break;
}
}

UDPv4Transport transportUnderTest(descriptor);
transportUnderTest.init();

Expand All @@ -311,7 +322,7 @@ TEST_F(UDPv4Tests, send_to_blocked_interface)
IPLocator::setIPv4(outputChannelLocator, 127, 0, 0, 1);
std::vector<octet> message = { 'H','e','l','l','o' };
ASSERT_FALSE(transportUnderTest.send(message.data(), (uint32_t)message.size(), outputChannelLocator, Locator_t()));
ASSERT_FALSE(transportUnderTest.CloseOutputChannel(outputChannelLocator));
ASSERT_TRUE(transportUnderTest.CloseOutputChannel(outputChannelLocator));
}

TEST_F(UDPv4Tests, send_to_allowed_interface)
Expand Down Expand Up @@ -519,17 +530,27 @@ TEST_F(UDPv4Tests, send_and_receive_between_allowed_sockets_using_unicast_to_mul

TEST_F(UDPv4Tests, open_a_blocked_socket)
{
descriptor.interfaceWhiteList.emplace_back("111.111.111.111");
UDPv4Transport transportUnderTest(descriptor);
transportUnderTest.init();
std::vector<IPFinder::info_IP> ip_list;
IPFinder::getIPs(&ip_list);

Locator_t multicastLocator;
multicastLocator.port = g_default_port;
multicastLocator.kind = LOCATOR_KIND_UDPv4;
IPLocator::setIPv4(multicastLocator, 239, 255, 0, 1);
for (const IPFinder::info_IP& ip : ip_list)
{
if (IPFinder::IP4 == ip.type)
{
descriptor.interfaceWhiteList.emplace_back("127.0.0.1");
UDPv4Transport transportUnderTest(descriptor);
transportUnderTest.init();

MockReceiverResource receiver(transportUnderTest, multicastLocator);
ASSERT_FALSE(transportUnderTest.IsInputChannelOpen(multicastLocator));
Locator_t multicastLocator;
multicastLocator.port = g_default_port;
multicastLocator.kind = LOCATOR_KIND_UDPv4;
IPLocator::setIPv4(multicastLocator, ip.name);

MockReceiverResource receiver(transportUnderTest, multicastLocator);
ASSERT_FALSE(transportUnderTest.IsInputChannelOpen(multicastLocator));
break;
}
}
}

TEST_F(UDPv4Tests, shrink_locator_lists)
Expand Down

0 comments on commit d28d629

Please sign in to comment.