Skip to content

Commit

Permalink
Add unit tests specific for #12208. Pass depends on network.
Browse files Browse the repository at this point in the history
NetworkAddressTest passes (most) tests when you have network.
When no network interface (ie -net none in QEMU) tests take forever and
more tests fail.
When network interface exists but is disabled in Haiku, tests are fast but
more tests fail.
  • Loading branch information
tqh committed Jul 28, 2015
1 parent 9b78023 commit 0cd3898
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/tests/kits/net/libnetapi/Jamfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ UnitTestLib libnetapitest.so :
NetworkAddressTest.cpp
NetworkInterfaceTest.cpp

: bnetapi network [ TargetLibstdc++ ] [ TargetLibsupc++ ]
: be bnetapi network [ TargetLibstdc++ ] [ TargetLibsupc++ ]
;
38 changes: 38 additions & 0 deletions src/tests/kits/net/libnetapi/NetworkAddressTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include "NetworkAddressTest.h"

#include <arpa/inet.h>
#include <netinet6/in6.h>

#include <NetworkAddress.h>
Expand Down Expand Up @@ -83,6 +84,38 @@ NetworkAddressTest::TestWildcard()
}


void
NetworkAddressTest::TestNullAddr()
{
BNetworkAddress nullAddr(AF_INET, NULL, 555);
CPPUNIT_ASSERT(nullAddr.InitCheck() == B_OK);

CPPUNIT_ASSERT(nullAddr.Family() == AF_INET);
CPPUNIT_ASSERT(nullAddr.Length() == sizeof(sockaddr_in));
CPPUNIT_ASSERT(nullAddr.Port() == 555);
CPPUNIT_ASSERT(!nullAddr.IsEmpty());
}


void
NetworkAddressTest::TestSetAddressFromFamilyPort()
{
BString addressStr = "192.168.1.1";
BNetworkAddress nullAddr(AF_INET, NULL, 555);
in_addr_t inetAddress = inet_addr(addressStr.String());
CPPUNIT_ASSERT(nullAddr.SetAddress(inetAddress) == B_OK);
CPPUNIT_ASSERT(nullAddr.InitCheck() == B_OK);

CPPUNIT_ASSERT(nullAddr.Family() == AF_INET);
CPPUNIT_ASSERT(nullAddr.Length() == sizeof(sockaddr_in));

sockaddr_in& sin = (sockaddr_in&)nullAddr.SockAddr();
CPPUNIT_ASSERT(addressStr == inet_ntoa(sin.sin_addr));
CPPUNIT_ASSERT(nullAddr.Port() == 555);
CPPUNIT_ASSERT(!nullAddr.IsEmpty());
}


void
NetworkAddressTest::TestIsLocal()
{
Expand Down Expand Up @@ -131,6 +164,11 @@ NetworkAddressTest::AddTests(BTestSuite& parent)
"NetworkAddressTest::TestSetTo", &NetworkAddressTest::TestSetTo));
suite.addTest(new CppUnit::TestCaller<NetworkAddressTest>(
"NetworkAddressTest::TestWildcard", &NetworkAddressTest::TestWildcard));
suite.addTest(new CppUnit::TestCaller<NetworkAddressTest>(
"NetworkAddressTest::TestNullAddr", &NetworkAddressTest::TestNullAddr));
suite.addTest(new CppUnit::TestCaller<NetworkAddressTest>(
"NetworkAddressTest::TestSetAddressFromFamilyPort",
&NetworkAddressTest::TestSetAddressFromFamilyPort));
suite.addTest(new CppUnit::TestCaller<NetworkAddressTest>(
"NetworkAddressTest::TestIsLocal", &NetworkAddressTest::TestIsLocal));
suite.addTest(new CppUnit::TestCaller<NetworkAddressTest>(
Expand Down
2 changes: 2 additions & 0 deletions src/tests/kits/net/libnetapi/NetworkAddressTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ class NetworkAddressTest : public CppUnit::TestCase {
void TestUnset();
void TestSetTo();
void TestWildcard();
void TestNullAddr();
void TestSetAddressFromFamilyPort();
void TestIsLocal();
void TestFlatten();

Expand Down

0 comments on commit 0cd3898

Please sign in to comment.