aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/test/lluri_tut.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'linden/indra/test/lluri_tut.cpp')
-rw-r--r--linden/indra/test/lluri_tut.cpp173
1 files changed, 111 insertions, 62 deletions
diff --git a/linden/indra/test/lluri_tut.cpp b/linden/indra/test/lluri_tut.cpp
index acd67cf..31ea7d6 100644
--- a/linden/indra/test/lluri_tut.cpp
+++ b/linden/indra/test/lluri_tut.cpp
@@ -36,51 +36,19 @@
36namespace tut 36namespace tut
37{ 37{
38 struct URITestData { 38 struct URITestData {
39 void checkParts(const std::string& uriString, 39 void checkParts(const LLURI& u,
40 const char* expectedScheme, 40 const char* expectedScheme,
41 const char* expectedOpaque, 41 const char* expectedOpaque,
42 const char* expectedAuthority, 42 const char* expectedAuthority,
43 const char* expectedPath, 43 const char* expectedPath,
44 const char* expectedQuery) 44 const char* expectedQuery = "")
45 { 45 {
46 LLURI u(uriString);
47
48 ensure_equals("scheme", u.scheme(), expectedScheme); 46 ensure_equals("scheme", u.scheme(), expectedScheme);
49 ensure_equals("opaque", u.opaque(), expectedOpaque); 47 ensure_equals("opaque", u.opaque(), expectedOpaque);
50 ensure_equals("authority", u.authority(), expectedAuthority); 48 ensure_equals("authority", u.authority(), expectedAuthority);
51 ensure_equals("path", u.path(), expectedPath); 49 ensure_equals("path", u.path(), expectedPath);
52 ensure_equals("query", u.query(), expectedQuery); 50 ensure_equals("query", u.query(), expectedQuery);
53 } 51 }
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 }; 52 };
85 53
86 typedef test_group<URITestData> URITestGroup; 54 typedef test_group<URITestData> URITestGroup;
@@ -114,59 +82,73 @@ namespace tut
114 void URITestObject::test<2>() 82 void URITestObject::test<2>()
115 { 83 {
116 // empty string 84 // empty string
117 checkParts("", "", "", "", "", ""); 85 checkParts(LLURI(""), "", "", "", "");
118 } 86 }
119 87
120 template<> template<> 88 template<> template<>
121 void URITestObject::test<3>() 89 void URITestObject::test<3>()
122 { 90 {
123 // no scheme 91 // no scheme
124 checkParts("foo", "", "foo", "", "", ""); 92 checkParts(LLURI("foo"), "", "foo", "", "");
125 checkParts("foo%3A", "", "foo:", "", "", ""); 93 checkParts(LLURI("foo%3A"), "", "foo:", "", "");
126 } 94 }
127 95
128 template<> template<> 96 template<> template<>
129 void URITestObject::test<4>() 97 void URITestObject::test<4>()
130 { 98 {
131 // scheme w/o paths 99 // scheme w/o paths
132 checkParts("mailto:zero@ll.com", "mailto", "zero@ll.com", "", "", ""); 100 checkParts(LLURI("mailto:zero@ll.com"),
133 checkParts("silly://abc/def?foo", "silly", "//abc/def?foo", "", "", ""); 101 "mailto", "zero@ll.com", "", "");
102 checkParts(LLURI("silly://abc/def?foo"),
103 "silly", "//abc/def?foo", "", "");
134 } 104 }
135 105
136 template<> template<> 106 template<> template<>
137 void URITestObject::test<5>() 107 void URITestObject::test<5>()
138 { 108 {
139 // authority section 109 // authority section
140 checkParts("http:///", "http", "///", "", "/", ""); 110 checkParts(LLURI("http:///"),
141 checkParts("http://abc", "http", "//abc", "abc", "", ""); 111 "http", "///", "", "/");
142 checkParts("http://a%2Fb/cd", "http", "//a/b/cd", "a/b", "/cd", ""); 112
143 checkParts("http://host?", "http", "//host?", "host", "", ""); 113 checkParts(LLURI("http://abc"),
114 "http", "//abc", "abc", "");
115
116 checkParts(LLURI("http://a%2Fb/cd"),
117 "http", "//a/b/cd", "a/b", "/cd");
118
119 checkParts(LLURI("http://host?"),
120 "http", "//host?", "host", "");
144 } 121 }
145 122
146 template<> template<> 123 template<> template<>
147 void URITestObject::test<6>() 124 void URITestObject::test<6>()
148 { 125 {
149 // path section 126 // path section
150 checkParts("http://host/a/b/", "http", "//host/a/b/", 127 checkParts(LLURI("http://host/a/b/"),
151 "host", "/a/b/", ""); 128 "http", "//host/a/b/", "host", "/a/b/");
152 checkParts("http://host/a%3Fb/", "http", "//host/a?b/", 129
153 "host", "/a?b/", ""); 130 checkParts(LLURI("http://host/a%3Fb/"),
154 checkParts("http://host/a:b/", "http", "//host/a:b/", 131 "http", "//host/a?b/", "host", "/a?b/");
155 "host", "/a:b/", ""); 132
133 checkParts(LLURI("http://host/a:b/"),
134 "http", "//host/a:b/", "host", "/a:b/");
156 } 135 }
157 136
158 template<> template<> 137 template<> template<>
159 void URITestObject::test<7>() 138 void URITestObject::test<7>()
160 { 139 {
161 // query string 140 // query string
162 checkParts("http://host/?", "http", "//host/?", 141 checkParts(LLURI("http://host/?"),
163 "host", "/", ""); 142 "http", "//host/?", "host", "/", "");
164 checkParts("http://host/?x", "http", "//host/?x", 143
165 "host", "/", "x"); 144 checkParts(LLURI("http://host/?x"),
166 checkParts("http://host/??", "http", "//host/??", 145 "http", "//host/?x", "host", "/", "x");
167 "host", "/", "?"); 146
168 checkParts("http://host/?%3F", "http", "//host/??", 147 checkParts(LLURI("http://host/??"),
169 "host", "/", "?"); 148 "http", "//host/??", "host", "/", "?");
149
150 checkParts(LLURI("http://host/?%3F"),
151 "http", "//host/??", "host", "/", "?");
170 } 152 }
171 153
172 template<> template<> 154 template<> template<>
@@ -175,11 +157,15 @@ namespace tut
175 LLSD path; 157 LLSD path;
176 path.append("x"); 158 path.append("x");
177 path.append("123"); 159 path.append("123");
178 checkPartsHTTP("host", path, "//host/x/123", "//host", "/x/123"); 160 checkParts(LLURI::buildHTTP("host", path),
161 "http", "//host/x/123", "host", "/x/123");
162
179 LLSD query; 163 LLSD query;
180 query["123"] = "12"; 164 query["123"] = "12";
181 query["abcd"] = "abc"; 165 query["abcd"] = "abc";
182 checkPartsHTTP("host", path, query, "//host/x/123?123=12&abcd=abc&", "//host", "/x/123", "123=12&abcd=abc&"); 166 checkParts(LLURI::buildHTTP("host", path, query),
167 "http", "//host/x/123?123=12&abcd=abc&",
168 "host", "/x/123", "123=12&abcd=abc&");
183 } 169 }
184 170
185 template<> template<> 171 template<> template<>
@@ -189,7 +175,8 @@ namespace tut
189 LLSD path; 175 LLSD path;
190 path.append("x@*//*$&^"); 176 path.append("x@*//*$&^");
191 path.append("123"); 177 path.append("123");
192 checkPartsHTTP("host", path, "//host/x@*//*$&^/123", "//host", "/x@*//*$&^/123"); 178 checkParts(LLURI::buildHTTP("host", path),
179 "http", "//host/x@*//*$&^/123", "host", "/x@*//*$&^/123");
193 } 180 }
194 181
195 template<> template<> 182 template<> template<>
@@ -202,7 +189,9 @@ namespace tut
202 LLSD query; 189 LLSD query;
203 query["123"] = "?&*#//"; 190 query["123"] = "?&*#//";
204 query["**@&?//"] = "abc"; 191 query["**@&?//"] = "abc";
205 checkPartsHTTP("host", path, query, "//host/x/123?**@&?//=abc&123=?&*#//&", "//host", "/x/123", "**@&?//=abc&123=?&*#//&"); 192 checkParts(LLURI::buildHTTP("host", path, query),
193 "http", "//host/x/123?**@&?//=abc&123=?&*#//&",
194 "host", "/x/123", "**@&?//=abc&123=?&*#//&");
206 } 195 }
207 196
208 template<> template<> 197 template<> template<>
@@ -215,7 +204,67 @@ namespace tut
215 LLSD query; 204 LLSD query;
216 query["123"] = "12"; 205 query["123"] = "12";
217 query["abcd"] = "abc"; 206 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&"); 207 checkParts(LLURI::buildHTTP("hi123*33--}{:portstuffs", path, query),
208 "http", "//hi123*33--}{:portstuffs/x/123?123=12&abcd=abc&",
209 "hi123*33--}{:portstuffs", "/x/123", "123=12&abcd=abc&");
210 }
211
212 template<> template<>
213 void URITestObject::test<12>()
214 {
215 // test funky host_port values that are actually prefixes
216
217 checkParts(LLURI::buildHTTP("http://example.com:8080", LLSD()),
218 "http", "//example.com:8080",
219 "example.com:8080", "");
220
221 checkParts(LLURI::buildHTTP("http://example.com:8080/", LLSD()),
222 "http", "//example.com:8080/",
223 "example.com:8080", "/");
224
225 checkParts(LLURI::buildHTTP("http://example.com:8080/a/b", LLSD()),
226 "http", "//example.com:8080/a/b",
227 "example.com:8080", "/a/b");
228 }
229
230 template<> template<>
231 void URITestObject::test<13>()
232 {
233 const std::string unreserved =
234 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
235 "0123456789"
236 "-._~";
237 // test escape
238 ensure_equals("escaping", LLURI::escape("abcdefg", "abcdef"), "abcdef%67");
239 ensure_equals("escaping", LLURI::escape("|/&\\+-_!@", ""), "%7C%2F%26%5C%2B%2D%5F%21%40");
240 ensure_equals("escaping as query variable",
241 LLURI::escape("http://10.0.1.4:12032/agent/god/agent-id/map/layer/?resume=http://station3.ll.com:12032/agent/203ad6df-b522-491d-ba48-4e24eb57aeff/send-postcard", unreserved + ":@!$'()*+,="),
242 "http:%2F%2F10.0.1.4:12032%2Fagent%2Fgod%2Fagent-id%2Fmap%2Flayer%2F%3Fresume=http:%2F%2Fstation3.ll.com:12032%2Fagent%2F203ad6df-b522-491d-ba48-4e24eb57aeff%2Fsend-postcard");
243 }
244
245 template<> template<>
246 void URITestObject::test<14>()
247 {
248 // test various build utilities
249
250 LLUUID id("11111111-2222-3333-4444-5566778899aa");
251
252
253 checkParts(LLURI::buildAgentPresenceURI(id, NULL),
254 "http", "//localhost:12040/agent/11111111-2222-3333-4444-5566778899aa/presence",
255 "localhost:12040", "/agent/11111111-2222-3333-4444-5566778899aa/presence");
256
257 checkParts(LLURI::buildBulkAgentPresenceURI(NULL),
258 "http", "//localhost:12040/agent/presence",
259 "localhost:12040", "/agent/presence");
260
261 checkParts(LLURI::buildAgentSessionURI(id, NULL),
262 "http", "//localhost:12040/agent/11111111-2222-3333-4444-5566778899aa/session",
263 "localhost:12040", "/agent/11111111-2222-3333-4444-5566778899aa/session");
264
265 checkParts(LLURI::buildAgentLoginInfoURI(id, "datasever:12345"),
266 "http", "//datasever:12345/agent/11111111-2222-3333-4444-5566778899aa/logininfo",
267 "datasever:12345", "/agent/11111111-2222-3333-4444-5566778899aa/logininfo");
219 } 268 }
220} 269}
221 270