forked from pocoproject/poco
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDNSTest.cpp
More file actions
115 lines (91 loc) · 2.26 KB
/
Copy pathDNSTest.cpp
File metadata and controls
115 lines (91 loc) · 2.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
//
// DNSTest.cpp
//
// $Id: //poco/1.4/Net/testsuite/src/DNSTest.cpp#4 $
//
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0
//
#include "DNSTest.h"
#include "CppUnit/TestCaller.h"
#include "CppUnit/TestSuite.h"
#include "Poco/Net/DNS.h"
#include "Poco/Net/HostEntry.h"
#include "Poco/Net/NetException.h"
using Poco::Net::DNS;
using Poco::Net::IPAddress;
using Poco::Net::HostEntry;
using Poco::Net::InvalidAddressException;
using Poco::Net::HostNotFoundException;
using Poco::Net::ServiceNotFoundException;
using Poco::Net::NoAddressFoundException;
DNSTest::DNSTest(const std::string& name): CppUnit::TestCase(name)
{
}
DNSTest::~DNSTest()
{
}
void DNSTest::testHostByName()
{
HostEntry he1 = DNS::hostByName("aliastest.appinf.com");
// different systems report different canonical names, unfortunately.
assert (he1.name() == "dnstest.appinf.com" || he1.name() == "aliastest.appinf.com");
#if !defined(POCO_HAVE_ADDRINFO)
// getaddrinfo() does not report any aliases
assert (!he1.aliases().empty());
assert (he1.aliases()[0] == "aliastest.appinf.com");
#endif
assert (he1.addresses().size() >= 1);
assert (he1.addresses()[0].toString() == "1.2.3.4");
try
{
HostEntry he1 = DNS::hostByName("nohost.appinf.com");
fail("host not found - must throw");
}
catch (HostNotFoundException&)
{
}
catch (NoAddressFoundException&)
{
}
}
void DNSTest::testHostByAddress()
{
IPAddress ip1("80.122.195.86");
HostEntry he1 = DNS::hostByAddress(ip1);
assert (he1.name() == "mailhost.appinf.com");
assert (he1.aliases().empty());
assert (he1.addresses().size() >= 1);
assert (he1.addresses()[0].toString() == "80.122.195.86");
IPAddress ip2("10.0.244.253");
try
{
HostEntry he2 = DNS::hostByAddress(ip2);
fail("host not found - must throw");
}
catch (HostNotFoundException&)
{
}
catch (NoAddressFoundException&)
{
}
}
void DNSTest::testResolve()
{
}
void DNSTest::setUp()
{
}
void DNSTest::tearDown()
{
}
CppUnit::Test* DNSTest::suite()
{
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("DNSTest");
CppUnit_addTest(pSuite, DNSTest, testHostByName);
CppUnit_addTest(pSuite, DNSTest, testHostByAddress);
CppUnit_addTest(pSuite, DNSTest, testResolve);
return pSuite;
}