]>
git.saurik.com Git - wxWidgets.git/blob - tests/uris/uris.cpp
69a9128d9c29fe512174801aa56f1820918e9509
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: tests/uris/uris.cpp
3 // Purpose: wxURI unit test
7 // Copyright: (c) 2004 Ryan Norton
8 ///////////////////////////////////////////////////////////////////////////////
10 // ----------------------------------------------------------------------------
12 // ----------------------------------------------------------------------------
14 #include "wx/wxprec.h"
26 #include "wx/cppunit.h"
28 // ----------------------------------------------------------------------------
30 // ----------------------------------------------------------------------------
32 class URITestCase
: public CppUnit::TestCase
38 CPPUNIT_TEST_SUITE( URITestCase
);
41 CPPUNIT_TEST( Paths
);
42 CPPUNIT_TEST( NormalResolving
);
43 CPPUNIT_TEST( ComplexResolving
);
44 CPPUNIT_TEST( ReallyComplexResolving
);
45 CPPUNIT_TEST( QueryFragmentResolving
);
46 CPPUNIT_TEST( BackwardsResolving
);
47 CPPUNIT_TEST( Assignment
);
48 CPPUNIT_TEST( Comparison
);
49 CPPUNIT_TEST_SUITE_END();
54 void NormalResolving();
55 void ComplexResolving();
56 void ReallyComplexResolving();
57 void QueryFragmentResolving();
58 void BackwardsResolving();
62 DECLARE_NO_COPY_CLASS(URITestCase
)
65 // register in the unnamed registry so that these tests are run by default
66 CPPUNIT_TEST_SUITE_REGISTRATION( URITestCase
);
68 // also include in it's own registry so that these tests can be run alone
69 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( URITestCase
, "URITestCase" );
71 URITestCase::URITestCase()
76 #define URI_TEST(uristring, cond) \
77 uri = new wxURI(wxT(uristring));\
78 CPPUNIT_ASSERT(cond);\
81 #define URI_PRINT(uri)\
82 wxPrintf(wxT("SCHEME:%s\n"), uri.GetScheme());\
83 wxPrintf(wxT("USER:%s\n"), uri.GetUser());\
84 wxPrintf(wxT("SERVER:%s\n"), uri.GetServer());\
85 wxPrintf(wxT("PORT:%s\n"), uri.GetPort());\
86 wxPrintf(wxT("PATH:%s\n"), uri.GetPath());\
87 wxPrintf(wxT("QUERY:%s\n"), uri.GetQuery());\
88 wxPrintf(wxT("FRAGMENT:%s\n"), uri.GetFragment());
90 void URITestCase::IPv4()
95 URI_TEST("http://user:password@192.168.1.100:5050/path",
96 uri
->GetHostType() == wxURI_IPV4ADDRESS
);
98 URI_TEST("http://user:password@192.255.1.100:5050/path",
99 uri
->GetHostType() == wxURI_IPV4ADDRESS
);
102 URI_TEST("http://user:password@192.256.1.100:5050/path",
103 uri
->GetHostType() != wxURI_IPV4ADDRESS
);
106 void URITestCase::IPv6()
110 // IPv6address = 6( h16 ":" ) ls32
111 // / "::" 5( h16 ":" ) ls32
112 // / [ h16 ] "::" 4( h16 ":" ) ls32
113 // / [ *1( h16 ":" ) h16 ] "::" 3( h16 ":" ) ls32
114 // / [ *2( h16 ":" ) h16 ] "::" 2( h16 ":" ) ls32
115 // / [ *3( h16 ":" ) h16 ] "::" h16 ":" ls32
116 // / [ *4( h16 ":" ) h16 ] "::" ls32
117 // / [ *5( h16 ":" ) h16 ] "::" h16
118 // / [ *6( h16 ":" ) h16 ] "::"
119 // ls32 = ( h16 ":" h16 ) / IPv4address
121 URI_TEST("http://user:password@[aa:aa:aa:aa:aa:aa:192.168.1.100]:5050/path",
122 uri
->GetHostType() == wxURI_IPV6ADDRESS
);
124 URI_TEST("http://user:password@[aa:aa:aa:aa:aa:aa:aa:aa]:5050/path",
125 uri
->GetHostType() == wxURI_IPV6ADDRESS
);
127 URI_TEST("http://user:password@[aa:aa:aa:aa::192.168.1.100]:5050/path",
128 uri
->GetHostType() == wxURI_IPV6ADDRESS
);
130 URI_TEST("http://user:password@[aa:aa:aa:aa::aa:aa]:5050/path",
131 uri
->GetHostType() == wxURI_IPV6ADDRESS
);
134 void URITestCase::Paths()
139 URI_TEST("http://user:password@192.256.1.100:5050/../path",
140 uri
->GetPath() == wxT("/path"));
142 URI_TEST("http://user:password@192.256.1.100:5050/path/../",
143 uri
->GetPath() == wxT("/"));
145 URI_TEST("http://user:password@192.256.1.100:5050/path/.",
146 uri
->GetPath() == wxT("/path/"));
148 URI_TEST("http://user:password@192.256.1.100:5050/path/./",
149 uri
->GetPath() == wxT("/path/"));
151 URI_TEST("path/john/../../../joe",
152 uri
->Get() == wxT("../joe"));
156 #define URI_TEST_RESOLVE(string, eq, strict) \
157 uri = new wxURI(wxT(string));\
158 uri->Resolve(masteruri, strict);\
159 CPPUNIT_ASSERT(uri->Get() == wxT(eq));\
162 #define URI_TEST(string, eq) \
163 URI_TEST_RESOLVE(string, eq, true);
166 //examples taken from RFC 2396.bis
168 void URITestCase::NormalResolving()
170 wxURI
masteruri(wxT("http://a/b/c/d;p?q"));
173 URI_TEST("g:h" ,"g:h")
174 URI_TEST("g" ,"http://a/b/c/g")
175 URI_TEST("./g" ,"http://a/b/c/g")
176 URI_TEST("g/" ,"http://a/b/c/g/")
177 URI_TEST("/g" ,"http://a/g")
178 URI_TEST("//g" ,"http://g")
179 URI_TEST("?y" ,"http://a/b/c/d;p?y")
180 URI_TEST("g?y" ,"http://a/b/c/g?y")
181 URI_TEST("#s" ,"http://a/b/c/d;p?q#s")
182 URI_TEST("g#s" ,"http://a/b/c/g#s")
183 URI_TEST("g?y#s","http://a/b/c/g?y#s")
184 URI_TEST(";x" ,"http://a/b/c/;x")
185 URI_TEST("g;x" ,"http://a/b/c/g;x")
186 URI_TEST("g;x?y#s","http://a/b/c/g;x?y#s")
188 URI_TEST("" ,"http://a/b/c/d;p?q")
189 URI_TEST("." ,"http://a/b/c/")
190 URI_TEST("./" ,"http://a/b/c/")
191 URI_TEST(".." ,"http://a/b/")
192 URI_TEST("../" ,"http://a/b/")
193 URI_TEST("../g" ,"http://a/b/g")
194 URI_TEST("../..","http://a/")
195 URI_TEST("../../" , "http://a/")
196 URI_TEST("../../g" , "http://a/g")
199 void URITestCase::ComplexResolving()
201 wxURI
masteruri(wxT("http://a/b/c/d;p?q"));
205 URI_TEST("/./g" ,"http://a/g")
206 URI_TEST("/../g" ,"http://a/g")
207 URI_TEST("g." ,"http://a/b/c/g.")
208 URI_TEST(".g" ,"http://a/b/c/.g")
209 URI_TEST("g.." ,"http://a/b/c/g..")
210 URI_TEST("..g" ,"http://a/b/c/..g")
213 //"../../../g" = "http://a/g"
214 //"../../../../g" = "http://a/g"
216 void URITestCase::ReallyComplexResolving()
218 wxURI
masteruri(wxT("http://a/b/c/d;p?q"));
221 //even more odder path examples
222 URI_TEST("./../g" ,"http://a/b/g")
223 URI_TEST("./g/." ,"http://a/b/c/g/")
224 URI_TEST("g/./h" ,"http://a/b/c/g/h")
225 URI_TEST("g/../h" ,"http://a/b/c/h")
226 URI_TEST("g;x=1/./y" , "http://a/b/c/g;x=1/y")
227 URI_TEST("g;x=1/../y" , "http://a/b/c/y")
230 void URITestCase::QueryFragmentResolving()
232 wxURI
masteruri(wxT("http://a/b/c/d;p?q"));
235 //query/fragment ambigiousness
236 URI_TEST("g?y/./x","http://a/b/c/g?y/./x")
237 URI_TEST("g?y/../x" , "http://a/b/c/g?y/../x")
238 URI_TEST("g#s/./x","http://a/b/c/g#s/./x")
239 URI_TEST("g#s/../x" , "http://a/b/c/g#s/../x")
242 void URITestCase::BackwardsResolving()
244 wxURI
masteruri(wxT("http://a/b/c/d;p?q"));
248 URI_TEST("http:g" , "http:g") //strict
250 URI_TEST_RESOLVE("http:g", "http://a/b/c/g", false);
253 void URITestCase::Assignment()
255 wxURI
uri1(wxT("http://mysite.com")),
256 uri2(wxT("http://mysite2.com"));
260 CPPUNIT_ASSERT(uri1
.Get() == uri2
.Get());
263 void URITestCase::Comparison()
265 CPPUNIT_ASSERT(wxURI(wxT("http://mysite.com")) == wxURI(wxT("http://mysite.com")));