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 25, 2019
1 parent cada35a commit cfb3afb
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/cpp/transport/UDPv4Transport.cpp
Expand Up @@ -281,7 +281,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 @@ -297,7 +297,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
41 changes: 31 additions & 10 deletions test/unittest/transport/UDPv4Tests.cpp
Expand Up @@ -302,7 +302,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 Down Expand Up @@ -525,17 +536,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 cfb3afb

Please sign in to comment.