Add unit tests specific for #12208. Pass depends on network.

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.
This commit is contained in:
Fredrik Holmqvist
2015-07-28 22:13:23 +02:00
parent 9b7802354f
commit 0cd38980a3
3 changed files with 41 additions and 1 deletions
+1 -1
View File
@@ -6,5 +6,5 @@ UnitTestLib libnetapitest.so :
NetworkAddressTest.cpp NetworkAddressTest.cpp
NetworkInterfaceTest.cpp NetworkInterfaceTest.cpp
: bnetapi network [ TargetLibstdc++ ] [ TargetLibsupc++ ] : be bnetapi network [ TargetLibstdc++ ] [ TargetLibsupc++ ]
; ;
@@ -6,6 +6,7 @@
#include "NetworkAddressTest.h" #include "NetworkAddressTest.h"
#include <arpa/inet.h>
#include <netinet6/in6.h> #include <netinet6/in6.h>
#include <NetworkAddress.h> #include <NetworkAddress.h>
@@ -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 void
NetworkAddressTest::TestIsLocal() NetworkAddressTest::TestIsLocal()
{ {
@@ -131,6 +164,11 @@ NetworkAddressTest::AddTests(BTestSuite& parent)
"NetworkAddressTest::TestSetTo", &NetworkAddressTest::TestSetTo)); "NetworkAddressTest::TestSetTo", &NetworkAddressTest::TestSetTo));
suite.addTest(new CppUnit::TestCaller<NetworkAddressTest>( suite.addTest(new CppUnit::TestCaller<NetworkAddressTest>(
"NetworkAddressTest::TestWildcard", &NetworkAddressTest::TestWildcard)); "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>( suite.addTest(new CppUnit::TestCaller<NetworkAddressTest>(
"NetworkAddressTest::TestIsLocal", &NetworkAddressTest::TestIsLocal)); "NetworkAddressTest::TestIsLocal", &NetworkAddressTest::TestIsLocal));
suite.addTest(new CppUnit::TestCaller<NetworkAddressTest>( suite.addTest(new CppUnit::TestCaller<NetworkAddressTest>(
@@ -18,6 +18,8 @@ public:
void TestUnset(); void TestUnset();
void TestSetTo(); void TestSetTo();
void TestWildcard(); void TestWildcard();
void TestNullAddr();
void TestSetAddressFromFamilyPort();
void TestIsLocal(); void TestIsLocal();
void TestFlatten(); void TestFlatten();