diff options
author | Jacek Antonelli | 2008-08-15 23:45:02 -0500 |
---|---|---|
committer | Jacek Antonelli | 2008-08-15 23:45:02 -0500 |
commit | d644fc64407dcd14ffcee6a0e9fbe28ee3a4e9bd (patch) | |
tree | 7ed0c2c27d717801238a2e6b5749cd5bf88c3059 /linden/indra/test/llhost_tut.cpp | |
parent | Second Life viewer sources 1.17.3.0 (diff) | |
download | meta-impy-d644fc64407dcd14ffcee6a0e9fbe28ee3a4e9bd.zip meta-impy-d644fc64407dcd14ffcee6a0e9fbe28ee3a4e9bd.tar.gz meta-impy-d644fc64407dcd14ffcee6a0e9fbe28ee3a4e9bd.tar.bz2 meta-impy-d644fc64407dcd14ffcee6a0e9fbe28ee3a4e9bd.tar.xz |
Second Life viewer sources 1.18.0.6
Diffstat (limited to '')
-rw-r--r-- | linden/indra/test/llhost_tut.cpp | 237 |
1 files changed, 237 insertions, 0 deletions
diff --git a/linden/indra/test/llhost_tut.cpp b/linden/indra/test/llhost_tut.cpp new file mode 100644 index 0000000..01f3079 --- /dev/null +++ b/linden/indra/test/llhost_tut.cpp | |||
@@ -0,0 +1,237 @@ | |||
1 | /** | ||
2 | * @file llhost_tut.cpp | ||
3 | * @author Adroit | ||
4 | * @date 2007-02 | ||
5 | * @brief llhost test cases. | ||
6 | * | ||
7 | * Copyright (c) 2007-2007, Linden Research, Inc. | ||
8 | * | ||
9 | * Second Life Viewer Source Code | ||
10 | * The source code in this file ("Source Code") is provided by Linden Lab | ||
11 | * to you under the terms of the GNU General Public License, version 2.0 | ||
12 | * ("GPL"), unless you have obtained a separate licensing agreement | ||
13 | * ("Other License"), formally executed by you and Linden Lab. Terms of | ||
14 | * the GPL can be found in doc/GPL-license.txt in this distribution, or | ||
15 | * online at http://secondlife.com/developers/opensource/gplv2 | ||
16 | * | ||
17 | * There are special exceptions to the terms and conditions of the GPL as | ||
18 | * it is applied to this Source Code. View the full text of the exception | ||
19 | * in the file doc/FLOSS-exception.txt in this software distribution, or | ||
20 | * online at http://secondlife.com/developers/opensource/flossexception | ||
21 | * | ||
22 | * By copying, modifying or distributing this software, you acknowledge | ||
23 | * that you have read and understood your obligations described above, | ||
24 | * and agree to abide by those obligations. | ||
25 | * | ||
26 | * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO | ||
27 | * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, | ||
28 | * COMPLETENESS OR PERFORMANCE. | ||
29 | */ | ||
30 | |||
31 | #include <tut/tut.h> | ||
32 | #include "lltut.h" | ||
33 | #include "linden_common.h" | ||
34 | #include "llhost.h" | ||
35 | |||
36 | namespace tut | ||
37 | { | ||
38 | struct host_data | ||
39 | { | ||
40 | }; | ||
41 | typedef test_group<host_data> host_test; | ||
42 | typedef host_test::object host_object; | ||
43 | tut::host_test host_testcase("llhost"); | ||
44 | |||
45 | |||
46 | template<> template<> | ||
47 | void host_object::test<1>() | ||
48 | { | ||
49 | LLHost host; | ||
50 | ensure("IP address is not NULL", (0 == host.getAddress()) && (0 == host.getPort()) && !host.isOk()); | ||
51 | } | ||
52 | template<> template<> | ||
53 | void host_object::test<2>() | ||
54 | { | ||
55 | U32 ip_addr = 0xc098017d; | ||
56 | U32 port = 8080; | ||
57 | LLHost host(ip_addr, port); | ||
58 | ensure("IP address is invalid", ip_addr == host.getAddress()); | ||
59 | ensure("Port Number is invalid", port == host.getPort()); | ||
60 | ensure("IP address and port number both should be ok", host.isOk()); | ||
61 | } | ||
62 | |||
63 | template<> template<> | ||
64 | void host_object::test<3>() | ||
65 | { | ||
66 | const char* str = "192.168.1.1"; | ||
67 | U32 port = 8080; | ||
68 | LLHost host(str, port); | ||
69 | ensure("IP address could not be processed", (host.getAddress() == ip_string_to_u32(str))); | ||
70 | ensure("Port Number is invalid", (port == host.getPort())); | ||
71 | } | ||
72 | |||
73 | template<> template<> | ||
74 | void host_object::test<4>() | ||
75 | { | ||
76 | U32 ip = ip_string_to_u32("192.168.1.1"); | ||
77 | U32 port = 22; | ||
78 | U64 ip_port = (((U64) ip) << 32) | port; | ||
79 | LLHost host(ip_port); | ||
80 | ensure("IP address is invalid", ip == host.getAddress()); | ||
81 | ensure("Port Number is invalid", port == host.getPort()); | ||
82 | } | ||
83 | |||
84 | template<> template<> | ||
85 | void host_object::test<5>() | ||
86 | { | ||
87 | std::string ip_port_string = "192.168.1.1:8080"; | ||
88 | U32 ip = ip_string_to_u32("192.168.1.1"); | ||
89 | U32 port = 8080; | ||
90 | |||
91 | LLHost host(ip_port_string.c_str()); | ||
92 | ensure("IP address from IP:port is invalid", ip == host.getAddress()); | ||
93 | ensure("Port Number from from IP:port is invalid", port == host.getPort()); | ||
94 | } | ||
95 | |||
96 | template<> template<> | ||
97 | void host_object::test<6>() | ||
98 | { | ||
99 | U32 ip = 0xc098017d, port = 8080; | ||
100 | LLHost host; | ||
101 | host.set(ip,port); | ||
102 | ensure("IP address is invalid", (ip == host.getAddress())); | ||
103 | ensure("Port Number is invalid", (port == host.getPort())); | ||
104 | } | ||
105 | |||
106 | template<> template<> | ||
107 | void host_object::test<7>() | ||
108 | { | ||
109 | const char* str = "192.168.1.1"; | ||
110 | U32 port = 8080, ip; | ||
111 | LLHost host; | ||
112 | host.set(str,port); | ||
113 | ip = ip_string_to_u32(str); | ||
114 | ensure("IP address is invalid", (ip == host.getAddress())); | ||
115 | ensure("Port Number is invalid", (port == host.getPort())); | ||
116 | |||
117 | str = "64.233.187.99"; | ||
118 | ip = ip_string_to_u32(str); | ||
119 | host.setAddress(str); | ||
120 | ensure("IP address is invalid", (ip == host.getAddress())); | ||
121 | |||
122 | ip = 0xc098017b; | ||
123 | host.setAddress(ip); | ||
124 | ensure("IP address is invalid", (ip == host.getAddress())); | ||
125 | // should still use the old port | ||
126 | ensure("Port Number is invalid", (port == host.getPort())); | ||
127 | |||
128 | port = 8084; | ||
129 | host.setPort(port); | ||
130 | ensure("Port Number is invalid", (port == host.getPort())); | ||
131 | // should still use the old address | ||
132 | ensure("IP address is invalid", (ip == host.getAddress())); | ||
133 | } | ||
134 | |||
135 | template<> template<> | ||
136 | void host_object::test<8>() | ||
137 | { | ||
138 | char buffer[50]; | ||
139 | char buffer1[50]; | ||
140 | const char* str = "192.168.1.1"; | ||
141 | U32 port = 8080; | ||
142 | LLHost host; | ||
143 | host.set(str,port); | ||
144 | host.getString(buffer, 50); | ||
145 | ensure("Function Failed", (0 == strcmp("192.168.1.1:8080", buffer))); | ||
146 | |||
147 | host.getIPString(buffer1, 50); | ||
148 | ensure("Function Failed", (0 == strcmp(str, buffer1))); | ||
149 | |||
150 | std::string ip_string = host.getIPString(); | ||
151 | ensure("Function Failed", (0 == strcmp(str, buffer1))); | ||
152 | |||
153 | std::string ip_string_port = host.getIPandPort(); | ||
154 | ensure("Function Failed", (0 == strcmp("192.168.1.1:8080", buffer))); | ||
155 | } | ||
156 | |||
157 | |||
158 | // getHostName() and setHostByName | ||
159 | template<> template<> | ||
160 | void host_object::test<9>() | ||
161 | { | ||
162 | std::string hostStr = "google.com"; | ||
163 | char buffer[50] = {0}; | ||
164 | LLHost host; | ||
165 | host.setHostByName(hostStr.c_str()); | ||
166 | host.getHostName(buffer, 50); | ||
167 | // reverse DNS will likely result in appending of some | ||
168 | // sub-domain to the main hostname. so look for | ||
169 | // the main domain name and not do the exact compare | ||
170 | ensure("getHostName failed", (NULL != strstr(buffer, hostStr.c_str()))); | ||
171 | |||
172 | LLString hostname = host.getHostName(); | ||
173 | ensure("getHostName failed", (NULL != strstr(hostname.c_str(), hostStr.c_str()))); | ||
174 | } | ||
175 | |||
176 | // setHostByName for dotted IP | ||
177 | template<> template<> | ||
178 | void host_object::test<10>() | ||
179 | { | ||
180 | std::string hostStr = "64.233.167.99"; | ||
181 | LLHost host; | ||
182 | host.setHostByName(hostStr.c_str()); | ||
183 | ensure("SetHostByName for dotted IP Address failed", host.getAddress() == ip_string_to_u32(hostStr.c_str())); | ||
184 | } | ||
185 | |||
186 | template<> template<> | ||
187 | void host_object::test<11>() | ||
188 | { | ||
189 | LLHost host1(0xc098017d, 8080); | ||
190 | LLHost host2 = host1; | ||
191 | ensure("Both IP addresses are not same", (host1.getAddress() == host2.getAddress())); | ||
192 | ensure("Both port numbers are not same", (host1.getPort() == host2.getPort())); | ||
193 | } | ||
194 | |||
195 | template<> template<> | ||
196 | void host_object::test<12>() | ||
197 | { | ||
198 | LLHost host1("192.168.1.1", 8080); | ||
199 | std::string str1 = "192.168.1.1:8080"; | ||
200 | std::ostringstream stream; | ||
201 | stream << host1; | ||
202 | ensure("Operator << failed", ( stream.str()== str1)); | ||
203 | |||
204 | // There is no istream >> llhost operator. | ||
205 | //std::istringstream is(stream.str()); | ||
206 | //LLHost host2; | ||
207 | //is >> host2; | ||
208 | //ensure("Operator >> failed. Not compatible with <<", host1 == host2); | ||
209 | } | ||
210 | |||
211 | // operators ==, !=, < | ||
212 | template<> template<> | ||
213 | void host_object::test<13>() | ||
214 | { | ||
215 | U32 ip_addr = 0xc098017d; | ||
216 | U32 port = 8080; | ||
217 | LLHost host1(ip_addr, port); | ||
218 | LLHost host2(ip_addr, port); | ||
219 | ensure("operator== failed", host1 == host2); | ||
220 | |||
221 | // change port | ||
222 | host2.setPort(7070); | ||
223 | ensure("operator!= failed", host1 != host2); | ||
224 | |||
225 | // set port back to 8080 and change IP address now | ||
226 | host2.setPort(8080); | ||
227 | host2.setAddress(ip_addr+10); | ||
228 | ensure("operator!= failed", host1 != host2); | ||
229 | |||
230 | ensure("operator< failed", host1 < host2); | ||
231 | |||
232 | // set IP address back to same value and change port | ||
233 | host2.setAddress(ip_addr); | ||
234 | host2.setPort(host1.getPort() + 10); | ||
235 | ensure("operator< failed", host1 < host2); | ||
236 | } | ||
237 | } | ||