[haiku-commits] haiku: hrev49472 - src/tests/kits/net/libnetapi

  • From: fredrik.holmqvist@xxxxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Tue, 28 Jul 2015 22:13:05 +0200 (CEST)

hrev49472 adds 1 changeset to branch 'master'
old head: 9b7802354fa49caeff6dcc3b4eb630b5bde692e6
new head: 0cd38980a3c14b19926fdf28a808575a688470f4
overview:
http://cgit.haiku-os.org/haiku/log/?qt=range&q=0cd38980a3c1+%5E9b7802354fa4

----------------------------------------------------------------------------

0cd38980a3c1: 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.

[ Fredrik Holmqvist <fredrik.holmqvist@xxxxxxxxx> ]

----------------------------------------------------------------------------

Revision: hrev49472
Commit: 0cd38980a3c14b19926fdf28a808575a688470f4
URL: http://cgit.haiku-os.org/haiku/commit/?id=0cd38980a3c1
Author: Fredrik Holmqvist <fredrik.holmqvist@xxxxxxxxx>
Date: Tue Jul 28 20:08:31 2015 UTC

Ticket: https://dev.haiku-os.org/ticket/12208

----------------------------------------------------------------------------

3 files changed, 41 insertions(+), 1 deletion(-)
src/tests/kits/net/libnetapi/Jamfile | 2 +-
.../kits/net/libnetapi/NetworkAddressTest.cpp | 38 ++++++++++++++++++++
.../kits/net/libnetapi/NetworkAddressTest.h | 2 ++

----------------------------------------------------------------------------

diff --git a/src/tests/kits/net/libnetapi/Jamfile
b/src/tests/kits/net/libnetapi/Jamfile
index 1e7fca6..b2e34ce 100644
--- a/src/tests/kits/net/libnetapi/Jamfile
+++ b/src/tests/kits/net/libnetapi/Jamfile
@@ -6,5 +6,5 @@ UnitTestLib libnetapitest.so :
NetworkAddressTest.cpp
NetworkInterfaceTest.cpp

- : bnetapi network [ TargetLibstdc++ ] [ TargetLibsupc++ ]
+ : be bnetapi network [ TargetLibstdc++ ] [ TargetLibsupc++ ]
;
diff --git a/src/tests/kits/net/libnetapi/NetworkAddressTest.cpp
b/src/tests/kits/net/libnetapi/NetworkAddressTest.cpp
index 5c37134..12f9769 100644
--- a/src/tests/kits/net/libnetapi/NetworkAddressTest.cpp
+++ b/src/tests/kits/net/libnetapi/NetworkAddressTest.cpp
@@ -6,6 +6,7 @@

#include "NetworkAddressTest.h"

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

#include <NetworkAddress.h>
@@ -84,6 +85,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()
{
BNetworkAddress local(AF_INET, "localhost");
@@ -132,6 +165,11 @@ NetworkAddressTest::AddTests(BTestSuite& parent)
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>(
"NetworkAddressTest::TestFlatten",
&NetworkAddressTest::TestFlatten));
diff --git a/src/tests/kits/net/libnetapi/NetworkAddressTest.h
b/src/tests/kits/net/libnetapi/NetworkAddressTest.h
index c750d32..24c7a4b 100644
--- a/src/tests/kits/net/libnetapi/NetworkAddressTest.h
+++ b/src/tests/kits/net/libnetapi/NetworkAddressTest.h
@@ -18,6 +18,8 @@ public:
void TestUnset();
void TestSetTo();
void TestWildcard();
+ void TestNullAddr();
+ void
TestSetAddressFromFamilyPort();
void TestIsLocal();
void TestFlatten();



Other related posts:

  • » [haiku-commits] haiku: hrev49472 - src/tests/kits/net/libnetapi - fredrik . holmqvist