aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/test/lluri_tut.cpp
diff options
context:
space:
mode:
authorJacek Antonelli2008-08-15 23:44:46 -0500
committerJacek Antonelli2008-08-15 23:44:46 -0500
commit38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4 (patch)
treeadca584755d22ca041a2dbfc35d4eca01f70b32c /linden/indra/test/lluri_tut.cpp
parentREADME.txt (diff)
downloadmeta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.zip
meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.gz
meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.bz2
meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.xz
Second Life viewer sources 1.13.2.12
Diffstat (limited to 'linden/indra/test/lluri_tut.cpp')
-rw-r--r--linden/indra/test/lluri_tut.cpp221
1 files changed, 221 insertions, 0 deletions
diff --git a/linden/indra/test/lluri_tut.cpp b/linden/indra/test/lluri_tut.cpp
new file mode 100644
index 0000000..acd67cf
--- /dev/null
+++ b/linden/indra/test/lluri_tut.cpp
@@ -0,0 +1,221 @@
1/**
2 * @file lluri_tut.cpp
3 * @brief LLURI unit tests
4 * @date September 2006
5 *
6 * Copyright (c) 2006-2007, Linden Research, Inc.
7 *
8 * The source code in this file ("Source Code") is provided by Linden Lab
9 * to you under the terms of the GNU General Public License, version 2.0
10 * ("GPL"), unless you have obtained a separate licensing agreement
11 * ("Other License"), formally executed by you and Linden Lab. Terms of
12 * the GPL can be found in doc/GPL-license.txt in this distribution, or
13 * online at http://secondlife.com/developers/opensource/gplv2
14 *
15 * There are special exceptions to the terms and conditions of the GPL as
16 * it is applied to this Source Code. View the full text of the exception
17 * in the file doc/FLOSS-exception.txt in this software distribution, or
18 * online at http://secondlife.com/developers/opensource/flossexception
19 *
20 * By copying, modifying or distributing this software, you acknowledge
21 * that you have read and understood your obligations described above,
22 * and agree to abide by those obligations.
23 *
24 * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
25 * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
26 * COMPLETENESS OR PERFORMANCE.
27 */
28
29#include <tut/tut.h>
30#include "lltut.h"
31
32#include "llsd.h"
33#include "lluri.h"
34#include "llhost.h"
35
36namespace tut
37{
38 struct URITestData {
39 void checkParts(const std::string& uriString,
40 const char* expectedScheme,
41 const char* expectedOpaque,
42 const char* expectedAuthority,
43 const char* expectedPath,
44 const char* expectedQuery)
45 {
46 LLURI u(uriString);
47
48 ensure_equals("scheme", u.scheme(), expectedScheme);
49 ensure_equals("opaque", u.opaque(), expectedOpaque);
50 ensure_equals("authority", u.authority(), expectedAuthority);
51 ensure_equals("path", u.path(), expectedPath);
52 ensure_equals("query", u.query(), expectedQuery);
53 }
54
55 void checkPartsHTTP(const char* host_and_port,
56 const LLSD& path,
57 const char* expectedOpaque,
58 const char* expectedAuthority,
59 const char* expectedPath)
60 {
61 LLURI u = LLURI::buildHTTP(host_and_port, path);
62 ensure_equals("scheme", u.scheme(), "HTTP");
63 ensure_equals("opaque", u.opaque(), expectedOpaque);
64 ensure_equals("authority", u.authority(), expectedAuthority);
65 ensure_equals("path", u.path(), expectedPath);
66 ensure_equals("query", u.query(), "");
67 }
68
69 void checkPartsHTTP(const char* host_and_port,
70 const LLSD& path,
71 const LLSD& args,
72 const char* expectedOpaque,
73 const char* expectedAuthority,
74 const char* expectedPath,
75 const char* expectedQuery)
76 {
77 LLURI u = LLURI::buildHTTP(host_and_port, path, args);
78 ensure_equals("scheme", u.scheme(), "HTTP");
79 ensure_equals("opaque", u.opaque(), expectedOpaque);
80 ensure_equals("authority", u.authority(), expectedAuthority);
81 ensure_equals("path", u.path(), expectedPath);
82 ensure_equals("query", u.query(), expectedQuery);
83 }
84 };
85
86 typedef test_group<URITestData> URITestGroup;
87 typedef URITestGroup::object URITestObject;
88
89 URITestGroup uriTestGroup("LLURI");
90
91 template<> template<>
92 void URITestObject::test<1>()
93 {
94 LLURI u("http://abc.com/def/ghi?x=37&y=hello");
95
96 ensure_equals("scheme", u.scheme(), "http");
97 ensure_equals("authority", u.authority(), "abc.com");
98 ensure_equals("path", u.path(), "/def/ghi");
99 ensure_equals("query", u.query(), "x=37&y=hello");
100
101 ensure_equals("host name", u.hostName(), "abc.com");
102 ensure_equals("host port", u.hostPort(), 80);
103
104 LLSD query = u.queryMap();
105 ensure_equals("query x", query["x"].asInteger(), 37);
106 ensure_equals("query y", query["y"].asString(), "hello");
107
108 query = LLURI::queryMap("x=22.23&y=https://lindenlab.com/");
109 ensure_equals("query x", query["x"].asReal(), 22.23);
110 ensure_equals("query y", query["y"].asURI().asString(), "https://lindenlab.com/");
111 }
112
113 template<> template<>
114 void URITestObject::test<2>()
115 {
116 // empty string
117 checkParts("", "", "", "", "", "");
118 }
119
120 template<> template<>
121 void URITestObject::test<3>()
122 {
123 // no scheme
124 checkParts("foo", "", "foo", "", "", "");
125 checkParts("foo%3A", "", "foo:", "", "", "");
126 }
127
128 template<> template<>
129 void URITestObject::test<4>()
130 {
131 // scheme w/o paths
132 checkParts("mailto:zero@ll.com", "mailto", "zero@ll.com", "", "", "");
133 checkParts("silly://abc/def?foo", "silly", "//abc/def?foo", "", "", "");
134 }
135
136 template<> template<>
137 void URITestObject::test<5>()
138 {
139 // authority section
140 checkParts("http:///", "http", "///", "", "/", "");
141 checkParts("http://abc", "http", "//abc", "abc", "", "");
142 checkParts("http://a%2Fb/cd", "http", "//a/b/cd", "a/b", "/cd", "");
143 checkParts("http://host?", "http", "//host?", "host", "", "");
144 }
145
146 template<> template<>
147 void URITestObject::test<6>()
148 {
149 // path section
150 checkParts("http://host/a/b/", "http", "//host/a/b/",
151 "host", "/a/b/", "");
152 checkParts("http://host/a%3Fb/", "http", "//host/a?b/",
153 "host", "/a?b/", "");
154 checkParts("http://host/a:b/", "http", "//host/a:b/",
155 "host", "/a:b/", "");
156 }
157
158 template<> template<>
159 void URITestObject::test<7>()
160 {
161 // query string
162 checkParts("http://host/?", "http", "//host/?",
163 "host", "/", "");
164 checkParts("http://host/?x", "http", "//host/?x",
165 "host", "/", "x");
166 checkParts("http://host/??", "http", "//host/??",
167 "host", "/", "?");
168 checkParts("http://host/?%3F", "http", "//host/??",
169 "host", "/", "?");
170 }
171
172 template<> template<>
173 void URITestObject::test<8>()
174 {
175 LLSD path;
176 path.append("x");
177 path.append("123");
178 checkPartsHTTP("host", path, "//host/x/123", "//host", "/x/123");
179 LLSD query;
180 query["123"] = "12";
181 query["abcd"] = "abc";
182 checkPartsHTTP("host", path, query, "//host/x/123?123=12&abcd=abc&", "//host", "/x/123", "123=12&abcd=abc&");
183 }
184
185 template<> template<>
186 void URITestObject::test<9>()
187 {
188 // test unescaped path components
189 LLSD path;
190 path.append("x@*//*$&^");
191 path.append("123");
192 checkPartsHTTP("host", path, "//host/x@*//*$&^/123", "//host", "/x@*//*$&^/123");
193 }
194
195 template<> template<>
196 void URITestObject::test<10>()
197 {
198 // test unescaped query components
199 LLSD path;
200 path.append("x");
201 path.append("123");
202 LLSD query;
203 query["123"] = "?&*#//";
204 query["**@&?//"] = "abc";
205 checkPartsHTTP("host", path, query, "//host/x/123?**@&?//=abc&123=?&*#//&", "//host", "/x/123", "**@&?//=abc&123=?&*#//&");
206 }
207
208 template<> template<>
209 void URITestObject::test<11>()
210 {
211 // test unescaped host components
212 LLSD path;
213 path.append("x");
214 path.append("123");
215 LLSD query;
216 query["123"] = "12";
217 query["abcd"] = "abc";
218 checkPartsHTTP("hi123*33--}{:portstuffs", path, query, "//hi123*33--}{:portstuffs/x/123?123=12&abcd=abc&", "//hi123*33--}{:portstuffs", "/x/123", "123=12&abcd=abc&");
219 }
220}
221