Add test for getaddrinfo on empty host.
* This should fail immediately, but it timeouts after 22 seconds when the network interfaces are not configured properly.
This commit is contained in:
parent
5ee2151e2c
commit
bca1813626
@ -39,6 +39,7 @@ SubInclude HAIKU_TOP src tests kits net ipv6 ;
|
||||
HaikuSubInclude libnetapi ;
|
||||
SubInclude HAIKU_TOP src tests kits net multicast ;
|
||||
SubInclude HAIKU_TOP src tests kits net netperf ;
|
||||
SubInclude HAIKU_TOP src tests kits net posixnet ;
|
||||
SubInclude HAIKU_TOP src tests kits net service ;
|
||||
SubInclude HAIKU_TOP src tests kits net sock ;
|
||||
SubInclude HAIKU_TOP src tests kits net tcp_shell ;
|
||||
|
56
src/tests/kits/net/posixnet/GetAddrInfo.cpp
Normal file
56
src/tests/kits/net/posixnet/GetAddrInfo.cpp
Normal file
@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Copyright 2014, Haiku, inc.
|
||||
* Distributed under the terms of the MIT licence
|
||||
*/
|
||||
|
||||
|
||||
#include "GetAddrInfo.h"
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netdb.h>
|
||||
|
||||
#include <cppunit/TestCaller.h>
|
||||
#include <cppunit/TestSuite.h>
|
||||
|
||||
|
||||
GetAddrInfoTest::GetAddrInfoTest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
GetAddrInfoTest::~GetAddrInfoTest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
GetAddrInfoTest::EmptyTest()
|
||||
{
|
||||
struct addrinfo* info;
|
||||
addrinfo hint = {0};
|
||||
hint.ai_family = AF_INET;
|
||||
hint.ai_flags = AI_PASSIVE;
|
||||
|
||||
// Trying to resolve an empty host...
|
||||
int result = getaddrinfo("", NULL, &hint, &info);
|
||||
|
||||
if (info)
|
||||
freeaddrinfo(info);
|
||||
|
||||
// getaddrinfo shouldn't suggest that this may work better by trying again.
|
||||
CPPUNIT_ASSERT(result != EAI_EAGAIN);
|
||||
// TODO it should also not take 22 seconds before it says so!
|
||||
}
|
||||
|
||||
|
||||
/* static */ void
|
||||
GetAddrInfoTest::AddTests(BTestSuite& parent)
|
||||
{
|
||||
CppUnit::TestSuite& suite = *new CppUnit::TestSuite("GetAddrInfoTest");
|
||||
|
||||
suite.addTest(new CppUnit::TestCaller<GetAddrInfoTest>(
|
||||
"GetAddrInfoTest::EmptyTest", &GetAddrInfoTest::EmptyTest));
|
||||
|
||||
parent.addTest("GetAddrInfoTest", &suite);
|
||||
}
|
25
src/tests/kits/net/posixnet/GetAddrInfo.h
Normal file
25
src/tests/kits/net/posixnet/GetAddrInfo.h
Normal file
@ -0,0 +1,25 @@
|
||||
/*
|
||||
* Copyright 2014 Haiku, inc.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef GET_ADDR_INFO_TEST_H
|
||||
#define GET_ADDR_INFO_TEST_H
|
||||
|
||||
|
||||
#include <TestCase.h>
|
||||
#include <TestSuite.h>
|
||||
|
||||
|
||||
class GetAddrInfoTest: public BTestCase {
|
||||
public:
|
||||
GetAddrInfoTest();
|
||||
virtual ~GetAddrInfoTest();
|
||||
|
||||
void EmptyTest();
|
||||
|
||||
static void AddTests(BTestSuite& suite);
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
12
src/tests/kits/net/posixnet/Jamfile
Normal file
12
src/tests/kits/net/posixnet/Jamfile
Normal file
@ -0,0 +1,12 @@
|
||||
SubDir HAIKU_TOP src tests kits net posixnet ;
|
||||
|
||||
UsePrivateHeaders private shared ;
|
||||
|
||||
UnitTestLib posixnettest.so :
|
||||
PosixNetTestAddon.cpp
|
||||
|
||||
GetAddrInfo.cpp
|
||||
|
||||
: be $(TARGET_NETWORK_LIBS) [ TargetLibstdc++ ]
|
||||
;
|
||||
|
22
src/tests/kits/net/posixnet/PosixNetTestAddon.cpp
Normal file
22
src/tests/kits/net/posixnet/PosixNetTestAddon.cpp
Normal file
@ -0,0 +1,22 @@
|
||||
/*
|
||||
* Copyright 2014 Haiku, Inc.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
|
||||
|
||||
#include <TestSuite.h>
|
||||
#include <TestSuiteAddon.h>
|
||||
|
||||
#include "GetAddrInfo.h"
|
||||
|
||||
|
||||
BTestSuite*
|
||||
getTestSuite()
|
||||
{
|
||||
BTestSuite* suite = new BTestSuite("PosixNet");
|
||||
|
||||
GetAddrInfoTest::AddTests(*suite);
|
||||
|
||||
return suite;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user