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:
Adrien Destugues 2014-11-06 14:05:00 +01:00
parent 5ee2151e2c
commit bca1813626
5 changed files with 116 additions and 0 deletions

View File

@ -39,6 +39,7 @@ SubInclude HAIKU_TOP src tests kits net ipv6 ;
HaikuSubInclude libnetapi ; HaikuSubInclude libnetapi ;
SubInclude HAIKU_TOP src tests kits net multicast ; SubInclude HAIKU_TOP src tests kits net multicast ;
SubInclude HAIKU_TOP src tests kits net netperf ; 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 service ;
SubInclude HAIKU_TOP src tests kits net sock ; SubInclude HAIKU_TOP src tests kits net sock ;
SubInclude HAIKU_TOP src tests kits net tcp_shell ; SubInclude HAIKU_TOP src tests kits net tcp_shell ;

View 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);
}

View 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

View 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++ ]
;

View 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;
}