* Added basic test for BNetworkInterface - I did not run that one yet, though
(switching to Haiku now to change that). git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@40422 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
cf93c8c719
commit
ce9e476882
@ -4,6 +4,7 @@ UnitTestLib libnetapitest.so :
|
||||
NetAPITestAddon.cpp
|
||||
|
||||
NetworkAddressTest.cpp
|
||||
NetworkInterfaceTest.cpp
|
||||
|
||||
: bnetapi $(TARGET_LIBSTDC++) $(TARGET_LIBSUPC++)
|
||||
;
|
||||
|
134
src/tests/kits/net/libnetapi/NetworkInterfaceTest.cpp
Normal file
134
src/tests/kits/net/libnetapi/NetworkInterfaceTest.cpp
Normal file
@ -0,0 +1,134 @@
|
||||
/*
|
||||
* Copyright 2011, Axel Dörfler, axeld@pinc-software.de.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
|
||||
|
||||
#include "NetworkInterfaceTest.h"
|
||||
|
||||
#include <NetworkInterface.h>
|
||||
#include <NetworkRoster.h>
|
||||
|
||||
#include <cppunit/TestCaller.h>
|
||||
#include <cppunit/TestSuite.h>
|
||||
|
||||
|
||||
NetworkInterfaceTest::NetworkInterfaceTest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
NetworkInterfaceTest::~NetworkInterfaceTest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
NetworkInterfaceTest::TestUnset()
|
||||
{
|
||||
BNetworkInterface unset("test");
|
||||
unset.Unset();
|
||||
CPPUNIT_ASSERT(unset.Name() == NULL || unset.Name()[0] == '\0');
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
NetworkInterfaceTest::TestFindAddress()
|
||||
{
|
||||
BNetworkInterface interface("testInterface");
|
||||
CPPUNIT_ASSERT(BNetworkRoster::Default().AddInterface(interface) == B_OK);
|
||||
CPPUNIT_ASSERT(interface.CountAddresses() == 0);
|
||||
|
||||
// Add first
|
||||
|
||||
BNetworkInterfaceAddress first;
|
||||
first.SetAddress(BNetworkAddress(AF_INET, "8.8.8.8"));
|
||||
|
||||
CPPUNIT_ASSERT(interface.FindAddress(first.Address()) < 0);
|
||||
CPPUNIT_ASSERT(interface.AddAddress(first) == B_OK);
|
||||
CPPUNIT_ASSERT(interface.FindAddress(first.Address()) == 0);
|
||||
|
||||
// Add second
|
||||
|
||||
BNetworkInterfaceAddress second;
|
||||
second.SetAddress(BNetworkAddress(AF_INET6, "::1"));
|
||||
|
||||
CPPUNIT_ASSERT(interface.FindAddress(second.Address()) < 0);
|
||||
CPPUNIT_ASSERT(interface.AddAddress(second) == B_OK);
|
||||
CPPUNIT_ASSERT(interface.FindAddress(second.Address()) >= 0);
|
||||
|
||||
// Remove them again
|
||||
|
||||
CPPUNIT_ASSERT(interface.RemoveAddress(first) == B_OK);
|
||||
CPPUNIT_ASSERT(interface.FindAddress(first.Address()) < 0);
|
||||
CPPUNIT_ASSERT(interface.FindAddress(second.Address()) >= 0);
|
||||
|
||||
CPPUNIT_ASSERT(interface.RemoveAddress(second.Address()) == B_OK);
|
||||
CPPUNIT_ASSERT(interface.FindAddress(first.Address()) < 0);
|
||||
CPPUNIT_ASSERT(interface.FindAddress(second.Address()) < 0);
|
||||
|
||||
CPPUNIT_ASSERT(BNetworkRoster::Default().RemoveInterface(interface)
|
||||
== B_OK);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
NetworkInterfaceTest::TestFindFirstAddress()
|
||||
{
|
||||
BNetworkInterface interface("testInterface");
|
||||
CPPUNIT_ASSERT(BNetworkRoster::Default().AddInterface(interface) == B_OK);
|
||||
CPPUNIT_ASSERT(interface.CountAddresses() == 0);
|
||||
|
||||
// Add first
|
||||
|
||||
BNetworkInterfaceAddress first;
|
||||
first.SetAddress(BNetworkAddress(AF_INET, "8.8.8.8"));
|
||||
|
||||
CPPUNIT_ASSERT(interface.FindFirstAddress(AF_INET) < 0);
|
||||
CPPUNIT_ASSERT(interface.FindFirstAddress(AF_INET6) < 0);
|
||||
CPPUNIT_ASSERT(interface.AddAddress(first) == B_OK);
|
||||
CPPUNIT_ASSERT(interface.FindFirstAddress(AF_INET) == 0);
|
||||
CPPUNIT_ASSERT(interface.FindFirstAddress(AF_INET6) < 0);
|
||||
|
||||
// Add second
|
||||
|
||||
BNetworkInterfaceAddress second;
|
||||
second.SetAddress(BNetworkAddress(AF_INET6, "::1"));
|
||||
|
||||
CPPUNIT_ASSERT(interface.AddAddress(second) == B_OK);
|
||||
CPPUNIT_ASSERT(interface.FindFirstAddress(AF_INET) >= 0);
|
||||
CPPUNIT_ASSERT(interface.FindFirstAddress(AF_INET6) >= 0);
|
||||
CPPUNIT_ASSERT(interface.FindFirstAddress(AF_INET)
|
||||
!= interface.FindFirstAddress(AF_INET6));
|
||||
|
||||
// Remove them again
|
||||
|
||||
CPPUNIT_ASSERT(interface.RemoveAddress(first) == B_OK);
|
||||
CPPUNIT_ASSERT(interface.FindFirstAddress(AF_INET) < 0);
|
||||
CPPUNIT_ASSERT(interface.FindFirstAddress(AF_INET6) >= 0);
|
||||
|
||||
CPPUNIT_ASSERT(interface.RemoveAddress(second.Address()) == B_OK);
|
||||
CPPUNIT_ASSERT(interface.FindFirstAddress(AF_INET) < 0);
|
||||
CPPUNIT_ASSERT(interface.FindFirstAddress(AF_INET6) < 0);
|
||||
|
||||
CPPUNIT_ASSERT(BNetworkRoster::Default().RemoveInterface(interface)
|
||||
== B_OK);
|
||||
}
|
||||
|
||||
|
||||
/*static*/ void
|
||||
NetworkInterfaceTest::AddTests(BTestSuite& parent)
|
||||
{
|
||||
CppUnit::TestSuite& suite = *new CppUnit::TestSuite("NetworkInterfaceTest");
|
||||
|
||||
suite.addTest(new CppUnit::TestCaller<NetworkInterfaceTest>(
|
||||
"NetworkInterfaceTest::TestUnset", &NetworkInterfaceTest::TestUnset));
|
||||
suite.addTest(new CppUnit::TestCaller<NetworkInterfaceTest>(
|
||||
"NetworkInterfaceTest::TestFindAddress",
|
||||
&NetworkInterfaceTest::TestFindAddress));
|
||||
suite.addTest(new CppUnit::TestCaller<NetworkInterfaceTest>(
|
||||
"NetworkInterfaceTest::TestFindFirstAddress",
|
||||
&NetworkInterfaceTest::TestFindFirstAddress));
|
||||
|
||||
parent.addTest("NetworkInterfaceTest", &suite);
|
||||
}
|
26
src/tests/kits/net/libnetapi/NetworkInterfaceTest.h
Normal file
26
src/tests/kits/net/libnetapi/NetworkInterfaceTest.h
Normal file
@ -0,0 +1,26 @@
|
||||
/*
|
||||
* Copyright 2011, Axel Dörfler, axeld@pinc-software.de.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef NETWORK_INTERFACE_TEST_H
|
||||
#define NETWORK_INTERFACE_TEST_H
|
||||
|
||||
|
||||
#include <TestCase.h>
|
||||
#include <TestSuite.h>
|
||||
|
||||
|
||||
class NetworkInterfaceTest : public CppUnit::TestCase {
|
||||
public:
|
||||
NetworkInterfaceTest();
|
||||
virtual ~NetworkInterfaceTest();
|
||||
|
||||
void TestUnset();
|
||||
void TestFindAddress();
|
||||
void TestFindFirstAddress();
|
||||
|
||||
static void AddTests(BTestSuite& suite);
|
||||
};
|
||||
|
||||
|
||||
#endif // NETWORK_INTERFACE_TEST_H
|
Loading…
Reference in New Issue
Block a user