forked from pocoproject/poco
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSocketAddressTest.cpp
More file actions
161 lines (126 loc) · 3.15 KB
/
SocketAddressTest.cpp
File metadata and controls
161 lines (126 loc) · 3.15 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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
//
// SocketAddressTest.cpp
//
// $Id: //poco/1.4/Net/testsuite/src/SocketAddressTest.cpp#2 $
//
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0
//
#include "SocketAddressTest.h"
#include "CppUnit/TestCaller.h"
#include "CppUnit/TestSuite.h"
#include "Poco/Net/SocketAddress.h"
#include "Poco/Net/NetException.h"
using Poco::Net::SocketAddress;
using Poco::Net::IPAddress;
using Poco::Net::InvalidAddressException;
using Poco::Net::HostNotFoundException;
using Poco::Net::ServiceNotFoundException;
using Poco::Net::NoAddressFoundException;
using Poco::InvalidArgumentException;
SocketAddressTest::SocketAddressTest(const std::string& name): CppUnit::TestCase(name)
{
}
SocketAddressTest::~SocketAddressTest()
{
}
void SocketAddressTest::testSocketAddress()
{
SocketAddress wild;
assert (wild.host().isWildcard());
assert (wild.port() == 0);
SocketAddress sa1("192.168.1.100", 100);
assert (sa1.host().toString() == "192.168.1.100");
assert (sa1.port() == 100);
SocketAddress sa2("192.168.1.100", "100");
assert (sa2.host().toString() == "192.168.1.100");
assert (sa2.port() == 100);
#if !defined(_WIN32_WCE)
SocketAddress sa3("192.168.1.100", "ftp");
assert (sa3.host().toString() == "192.168.1.100");
assert (sa3.port() == 21);
#endif
try
{
SocketAddress sa3("192.168.1.100", "f00bar");
fail("bad service name - must throw");
}
catch (ServiceNotFoundException&)
{
}
SocketAddress sa4("www.appinf.com", 80);
assert (sa4.host().toString() == "50.57.108.29");
assert (sa4.port() == 80);
try
{
SocketAddress sa5("192.168.2.260", 80);
fail("invalid address - must throw");
}
catch (HostNotFoundException&)
{
}
catch (NoAddressFoundException&)
{
}
try
{
SocketAddress sa6("192.168.2.120", "80000");
fail("invalid port - must throw");
}
catch (ServiceNotFoundException&)
{
}
SocketAddress sa7("192.168.2.120:88");
assert (sa7.host().toString() == "192.168.2.120");
assert (sa7.port() == 88);
SocketAddress sa8("[192.168.2.120]:88");
assert (sa8.host().toString() == "192.168.2.120");
assert (sa8.port() == 88);
try
{
SocketAddress sa9("[192.168.2.260]");
fail("invalid address - must throw");
}
catch (InvalidArgumentException&)
{
}
try
{
SocketAddress sa9("[192.168.2.260:88");
fail("invalid address - must throw");
}
catch (InvalidArgumentException&)
{
}
}
void SocketAddressTest::testSocketRelationals()
{
SocketAddress sa1("192.168.1.100", 100);
SocketAddress sa2("192.168.1.100:100");
assert (sa1 == sa2);
SocketAddress sa3("192.168.1.101", "99");
assert (sa2 < sa3);
SocketAddress sa4("192.168.1.101", "102");
assert (sa3 < sa4);
}
void SocketAddressTest::testSocketAddress6()
{
#ifdef POCO_HAVE_IPv6
#endif
}
void SocketAddressTest::setUp()
{
}
void SocketAddressTest::tearDown()
{
}
CppUnit::Test* SocketAddressTest::suite()
{
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("SocketAddressTest");
CppUnit_addTest(pSuite, SocketAddressTest, testSocketAddress);
CppUnit_addTest(pSuite, SocketAddressTest, testSocketRelationals);
CppUnit_addTest(pSuite, SocketAddressTest, testSocketAddress6);
return pSuite;
}