lluri_tut.cpp

Go to the documentation of this file.
00001 
00033 #include "linden_common.h"
00034 #include "lltut.h"
00035 #include "llsd.h"
00036 #include "lluri.h"
00037 #include "llhost.h"
00038 
00039 namespace tut
00040 {
00041         struct URITestData {
00042                 void checkParts(const LLURI& u,
00043                                 const char* expectedScheme,
00044                                 const char* expectedOpaque,
00045                                 const char* expectedAuthority,
00046                                 const char* expectedPath,
00047                                 const char* expectedQuery = "")
00048                 {
00049                         ensure_equals("scheme",         u.scheme(),             expectedScheme);
00050                         ensure_equals("opaque",         u.opaque(),             expectedOpaque);
00051                         ensure_equals("authority",      u.authority(),  expectedAuthority);
00052                         ensure_equals("path",           u.path(),               expectedPath);
00053                         ensure_equals("query",          u.query(),              expectedQuery);
00054                 }
00055         };
00056         
00057         typedef test_group<URITestData> URITestGroup;
00058         typedef URITestGroup::object    URITestObject;
00059 
00060         URITestGroup uriTestGroup("LLURI");
00061         
00062         template<> template<>
00063         void URITestObject::test<1>()
00064         {
00065                 LLURI u("http://abc.com/def/ghi?x=37&y=hello");
00066 
00067                 ensure_equals("scheme",         u.scheme(),             "http");
00068                 ensure_equals("authority",      u.authority(),  "abc.com");
00069                 ensure_equals("path",           u.path(),               "/def/ghi");
00070                 ensure_equals("query",          u.query(),              "x=37&y=hello");
00071 
00072                 ensure_equals("host name", u.hostName(), "abc.com");
00073                 ensure_equals("host port", u.hostPort(), 80);
00074 
00075                 LLSD query = u.queryMap();
00076                 ensure_equals("query x", query["x"].asInteger(), 37);
00077                 ensure_equals("query y", query["y"].asString(), "hello");
00078 
00079                 query = LLURI::queryMap("x=22.23&y=https://lindenlab.com/");
00080                 ensure_equals("query x", query["x"].asReal(), 22.23);
00081                 ensure_equals("query y", query["y"].asURI().asString(), "https://lindenlab.com/");
00082         }
00083 
00084         template<> template<>
00085         void URITestObject::test<2>()
00086         {
00087                 // empty string
00088                 checkParts(LLURI(""), "", "", "", "");
00089         }
00090         
00091         template<> template<>
00092         void URITestObject::test<3>()
00093         {
00094                 // no scheme
00095                 checkParts(LLURI("foo"), "", "foo", "", "");
00096                 checkParts(LLURI("foo%3A"), "", "foo:", "", "");
00097         }
00098 
00099         template<> template<>
00100         void URITestObject::test<4>()
00101         {
00102                 // scheme w/o paths
00103                 checkParts(LLURI("mailto:zero@ll.com"),
00104                         "mailto", "zero@ll.com", "", "");
00105                 checkParts(LLURI("silly://abc/def?foo"),
00106                         "silly", "//abc/def?foo", "", "");
00107         }
00108 
00109         template<> template<>
00110         void URITestObject::test<5>()
00111         {
00112                 // authority section
00113                 checkParts(LLURI("http:///"),
00114                         "http", "///", "", "/");
00115                         
00116                 checkParts(LLURI("http://abc"),
00117                         "http", "//abc", "abc", "");
00118                         
00119                 checkParts(LLURI("http://a%2Fb/cd"),
00120                         "http", "//a/b/cd", "a/b", "/cd");
00121                         
00122                 checkParts(LLURI("http://host?"),
00123                         "http", "//host?", "host", "");
00124         }
00125 
00126         template<> template<>
00127         void URITestObject::test<6>()
00128         {               
00129                 // path section
00130                 checkParts(LLURI("http://host/a/b/"),
00131                                 "http", "//host/a/b/", "host", "/a/b/");
00132                                 
00133                 checkParts(LLURI("http://host/a%3Fb/"),
00134                                 "http", "//host/a?b/", "host", "/a?b/");
00135                                 
00136                 checkParts(LLURI("http://host/a:b/"),
00137                                 "http", "//host/a:b/", "host", "/a:b/");
00138         }
00139 
00140         template<> template<>
00141         void URITestObject::test<7>()
00142         {               
00143                 // query string
00144                 checkParts(LLURI("http://host/?"),
00145                                 "http", "//host/?", "host", "/", "");
00146                                 
00147                 checkParts(LLURI("http://host/?x"),
00148                                 "http", "//host/?x", "host", "/", "x");
00149                                 
00150                 checkParts(LLURI("http://host/??"),
00151                                 "http", "//host/??", "host", "/", "?");
00152                                 
00153                 checkParts(LLURI("http://host/?%3F"),
00154                                 "http", "//host/??", "host", "/", "?");
00155         }
00156 
00157         template<> template<>
00158         void URITestObject::test<8>()
00159         {
00160                 LLSD path;
00161                 path.append("x");
00162                 path.append("123");
00163                 checkParts(LLURI::buildHTTP("host", path),
00164                         "http", "//host/x/123", "host", "/x/123");
00165                 
00166                 LLSD query;
00167                 query["123"] = "12";
00168                 query["abcd"] = "abc";
00169                 checkParts(LLURI::buildHTTP("host", path, query),
00170                         "http", "//host/x/123?123=12&abcd=abc",
00171                         "host", "/x/123", "123=12&abcd=abc");
00172         }
00173 
00174         template<> template<>
00175         void URITestObject::test<9>()
00176         {
00177                 // test unescaped path components
00178                 LLSD path;
00179                 path.append("x@*//*$&^");
00180                 path.append("123");
00181                 checkParts(LLURI::buildHTTP("host", path),
00182                         "http", "//host/x@*//*$&^/123", "host", "/x@*//*$&^/123");
00183         }
00184 
00185         template<> template<>
00186         void URITestObject::test<10>()
00187         {
00188                 // test unescaped query components
00189                 LLSD path;
00190                 path.append("x");
00191                 path.append("123");
00192                 LLSD query;
00193                 query["123"] = "?&*#//";
00194                 query["**@&?//"] = "abc";
00195                 checkParts(LLURI::buildHTTP("host", path, query),
00196                         "http", "//host/x/123?**@&?//=abc&123=?&*#//",
00197                         "host", "/x/123", "**@&?//=abc&123=?&*#//");
00198         }
00199 
00200         template<> template<>
00201         void URITestObject::test<11>()
00202         {
00203                 // test unescaped host components
00204                 LLSD path;
00205                 path.append("x");
00206                 path.append("123");
00207                 LLSD query;
00208                 query["123"] = "12";
00209                 query["abcd"] = "abc";
00210                 checkParts(LLURI::buildHTTP("hi123*33--}{:portstuffs", path, query),
00211                         "http", "//hi123*33--}{:portstuffs/x/123?123=12&abcd=abc",
00212                         "hi123*33--}{:portstuffs", "/x/123", "123=12&abcd=abc");
00213         }
00214         
00215         template<> template<>
00216         void URITestObject::test<12>()
00217         {
00218                 // test funky host_port values that are actually prefixes
00219                 
00220                 checkParts(LLURI::buildHTTP("http://example.com:8080", LLSD()),
00221                         "http", "//example.com:8080",
00222                         "example.com:8080", "");
00223                         
00224                 checkParts(LLURI::buildHTTP("http://example.com:8080/", LLSD()),
00225                         "http", "//example.com:8080/",
00226                         "example.com:8080", "/");
00227 
00228                 checkParts(LLURI::buildHTTP("http://example.com:8080/a/b", LLSD()),
00229                         "http", "//example.com:8080/a/b",
00230                         "example.com:8080", "/a/b");
00231         }
00232 
00233         template<> template<>
00234         void URITestObject::test<13>()
00235         {
00236                 const std::string unreserved =   
00237                         "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
00238                         "0123456789"
00239                         "-._~";
00240                 // test escape
00241                 ensure_equals("escaping", LLURI::escape("abcdefg", "abcdef"), "abcdef%67");
00242                 ensure_equals("escaping", LLURI::escape("|/&\\+-_!@", ""), "%7C%2F%26%5C%2B%2D%5F%21%40");
00243                 ensure_equals("escaping as query variable", 
00244                                           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 + ":@!$'()*+,="), 
00245                                           "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");
00246         }
00247         
00248 
00249 #if LL_ENABLE_JANKY_DEPRECATED_WEB_SERVICE_CALLS
00250         template<> template<>
00251         void URITestObject::test<14>()
00252         {
00253                 // test various build utilities
00254                 
00255                 LLUUID id("11111111-2222-3333-4444-5566778899aa");
00256                 
00257                 
00258                 checkParts(LLURI::buildAgentSessionURI(id, NULL),
00259                         "http", "//localhost:12040/agent/11111111-2222-3333-4444-5566778899aa/session",
00260                         "localhost:12040", "/agent/11111111-2222-3333-4444-5566778899aa/session");
00261 
00262                 checkParts(LLURI::buildAgentLoginInfoURI(id, "datasever:12345"),
00263                         "http", "//datasever:12345/agent/11111111-2222-3333-4444-5566778899aa/logininfo",
00264                         "datasever:12345", "/agent/11111111-2222-3333-4444-5566778899aa/logininfo");
00265         }
00266 #endif // LL_ENABLE_JANKY_DEPRECATED_WEB_SERVICE_CALLS
00267 }
00268 

Generated on Thu Jul 1 06:09:24 2010 for Second Life Viewer by  doxygen 1.4.7