1f38d4d45SAdrien Destugues /*
2f38d4d45SAdrien Destugues * Copyright 2010, Christophe Huriaux
3f38d4d45SAdrien Destugues * Copyright 2014, Haiku, inc.
4f38d4d45SAdrien Destugues * Distributed under the terms of the MIT licence
5f38d4d45SAdrien Destugues */
6f38d4d45SAdrien Destugues
7f38d4d45SAdrien Destugues
8f38d4d45SAdrien Destugues #include "UrlTest.h"
9f38d4d45SAdrien Destugues
10f38d4d45SAdrien Destugues
11f38d4d45SAdrien Destugues #include <cstdlib>
12f38d4d45SAdrien Destugues #include <cstring>
13f38d4d45SAdrien Destugues #include <cstdio>
14f38d4d45SAdrien Destugues
15f38d4d45SAdrien Destugues #include <NetworkKit.h>
16f38d4d45SAdrien Destugues
17f38d4d45SAdrien Destugues #include <cppunit/TestCaller.h>
18f38d4d45SAdrien Destugues #include <cppunit/TestSuite.h>
19f38d4d45SAdrien Destugues
20f38d4d45SAdrien Destugues
UrlTest()21f38d4d45SAdrien Destugues UrlTest::UrlTest()
22f38d4d45SAdrien Destugues {
23f38d4d45SAdrien Destugues }
24f38d4d45SAdrien Destugues
25f38d4d45SAdrien Destugues
~UrlTest()26f38d4d45SAdrien Destugues UrlTest::~UrlTest()
27f38d4d45SAdrien Destugues {
28f38d4d45SAdrien Destugues }
29f38d4d45SAdrien Destugues
30f38d4d45SAdrien Destugues
31f38d4d45SAdrien Destugues // Test that parsing a valid URL and converting back to string doesn't alter it
ParseTest()32f38d4d45SAdrien Destugues void UrlTest::ParseTest()
33f38d4d45SAdrien Destugues {
34f38d4d45SAdrien Destugues uint8 testIndex;
35f38d4d45SAdrien Destugues BUrl testUrl;
36f38d4d45SAdrien Destugues
37f38d4d45SAdrien Destugues const char* kTestLength[] =
38f38d4d45SAdrien Destugues {
39f38d4d45SAdrien Destugues "http://user:pass@www.foo.com:80/path?query#fragment",
40f38d4d45SAdrien Destugues "http://user:pass@www.foo.com:80/path?query#",
41f38d4d45SAdrien Destugues "http://user:pass@www.foo.com:80/path?query",
42f38d4d45SAdrien Destugues "http://user:pass@www.foo.com:80/path?",
43f38d4d45SAdrien Destugues "http://user:pass@www.foo.com:80/path",
44f38d4d45SAdrien Destugues "http://user:pass@www.foo.com:80/",
45f38d4d45SAdrien Destugues "http://user:pass@www.foo.com",
46f38d4d45SAdrien Destugues "http://user:pass@",
47f38d4d45SAdrien Destugues "http://www.foo.com",
48f38d4d45SAdrien Destugues "http://",
49f38d4d45SAdrien Destugues "http:"
50f38d4d45SAdrien Destugues };
51f38d4d45SAdrien Destugues
52f38d4d45SAdrien Destugues for (testIndex = 0; testIndex < sizeof(kTestLength) / sizeof(const char*);
53f38d4d45SAdrien Destugues testIndex++)
54f38d4d45SAdrien Destugues {
55f38d4d45SAdrien Destugues NextSubTest();
56f38d4d45SAdrien Destugues
57f38d4d45SAdrien Destugues testUrl.SetUrlString(kTestLength[testIndex]);
58f38d4d45SAdrien Destugues CPPUNIT_ASSERT_EQUAL(BString(kTestLength[testIndex]),
59f38d4d45SAdrien Destugues testUrl.UrlString());
60f38d4d45SAdrien Destugues }
61f38d4d45SAdrien Destugues }
62f38d4d45SAdrien Destugues
63f38d4d45SAdrien Destugues
TestIsValid()64f38d4d45SAdrien Destugues void UrlTest::TestIsValid()
65f38d4d45SAdrien Destugues {
66f38d4d45SAdrien Destugues BUrl url("http:");
67f38d4d45SAdrien Destugues CPPUNIT_ASSERT_MESSAGE("Created with a scheme but no hierarchical segment.",
68f38d4d45SAdrien Destugues !url.IsValid());
69f38d4d45SAdrien Destugues
70f38d4d45SAdrien Destugues url.SetHost("<invalid>");
71f4db7fdcSAdrien Destugues CPPUNIT_ASSERT_MESSAGE("Set to an invalid host", !url.IsValid());
72f38d4d45SAdrien Destugues
73f38d4d45SAdrien Destugues url.SetUrlString("");
74f38d4d45SAdrien Destugues url.SetProtocol("\t \n");
75f38d4d45SAdrien Destugues CPPUNIT_ASSERT_MESSAGE("Set a protocol with whitespace", !url.IsValid());
76f38d4d45SAdrien Destugues url.SetProtocol("123");
77f38d4d45SAdrien Destugues CPPUNIT_ASSERT_MESSAGE("Set an all-digits protocol", !url.IsValid());
78f38d4d45SAdrien Destugues
79f38d4d45SAdrien Destugues url.SetUserName("user");
80f38d4d45SAdrien Destugues CPPUNIT_ASSERT_MESSAGE("Retain invalid state on user change",
81f38d4d45SAdrien Destugues !url.IsValid());
82f38d4d45SAdrien Destugues url.SetPassword("pass");
83f38d4d45SAdrien Destugues CPPUNIT_ASSERT_MESSAGE("Retain invalid state on password change",
84f38d4d45SAdrien Destugues !url.IsValid());
85f38d4d45SAdrien Destugues
86f38d4d45SAdrien Destugues url.SetProtocol("http");
87f38d4d45SAdrien Destugues url.SetFragment("fragment");
88f38d4d45SAdrien Destugues CPPUNIT_ASSERT_MESSAGE("Only protocol and fragment are set",
89f38d4d45SAdrien Destugues !url.IsValid());
90f38d4d45SAdrien Destugues url.SetFragment("fragment");
91f38d4d45SAdrien Destugues url.SetProtocol("http");
92f38d4d45SAdrien Destugues CPPUNIT_ASSERT_MESSAGE("Only protocol and fragment are set",
93f38d4d45SAdrien Destugues !url.IsValid());
94f38d4d45SAdrien Destugues }
95f38d4d45SAdrien Destugues
96f38d4d45SAdrien Destugues
TestGettersSetters()97f38d4d45SAdrien Destugues void UrlTest::TestGettersSetters()
98f38d4d45SAdrien Destugues {
99f38d4d45SAdrien Destugues BUrl url;
100f38d4d45SAdrien Destugues url.SetProtocol("http");
101f38d4d45SAdrien Destugues url.SetUserName("user");
102f38d4d45SAdrien Destugues url.SetPassword("password");
103f38d4d45SAdrien Destugues url.SetHost("example.com");
104f38d4d45SAdrien Destugues url.SetPort(8080);
105f38d4d45SAdrien Destugues url.SetPath("/path");
106f38d4d45SAdrien Destugues url.SetRequest("query=value");
107f38d4d45SAdrien Destugues url.SetFragment("fragment");
108f38d4d45SAdrien Destugues
109f38d4d45SAdrien Destugues CPPUNIT_ASSERT_EQUAL(BString("http"), url.Protocol());
110f38d4d45SAdrien Destugues CPPUNIT_ASSERT_EQUAL(BString("user"), url.UserName());
111f38d4d45SAdrien Destugues CPPUNIT_ASSERT_EQUAL(BString("password"), url.Password());
112f38d4d45SAdrien Destugues CPPUNIT_ASSERT_EQUAL(BString("user:password"), url.UserInfo());
113f38d4d45SAdrien Destugues CPPUNIT_ASSERT_EQUAL(BString("example.com"), url.Host());
114f38d4d45SAdrien Destugues CPPUNIT_ASSERT_EQUAL(BString("user:password@example.com:8080"),
115f38d4d45SAdrien Destugues url.Authority());
116f38d4d45SAdrien Destugues CPPUNIT_ASSERT_EQUAL(8080, url.Port());
117f38d4d45SAdrien Destugues CPPUNIT_ASSERT_EQUAL(BString("/path"), url.Path());
118f38d4d45SAdrien Destugues CPPUNIT_ASSERT_EQUAL(BString("query=value"), url.Request());
119f38d4d45SAdrien Destugues CPPUNIT_ASSERT_EQUAL(BString("fragment"), url.Fragment());
120f38d4d45SAdrien Destugues CPPUNIT_ASSERT_EQUAL(BString(
121f38d4d45SAdrien Destugues "http://user:password@example.com:8080/path?query=value#fragment"),
122f38d4d45SAdrien Destugues url.UrlString());
123f38d4d45SAdrien Destugues }
124f38d4d45SAdrien Destugues
125f38d4d45SAdrien Destugues
TestNullity()126f38d4d45SAdrien Destugues void UrlTest::TestNullity()
127f38d4d45SAdrien Destugues {
128f38d4d45SAdrien Destugues BUrl url;
129f38d4d45SAdrien Destugues url.SetProtocol("http");
130f38d4d45SAdrien Destugues url.SetHost("example.com");
131f38d4d45SAdrien Destugues
132f38d4d45SAdrien Destugues CPPUNIT_ASSERT(url.HasAuthority());
133f38d4d45SAdrien Destugues CPPUNIT_ASSERT(url.HasHost());
134f38d4d45SAdrien Destugues
135f38d4d45SAdrien Destugues CPPUNIT_ASSERT(!url.HasUserName());
136f38d4d45SAdrien Destugues CPPUNIT_ASSERT(!url.HasPassword());
137f38d4d45SAdrien Destugues CPPUNIT_ASSERT(!url.HasUserInfo());
138f38d4d45SAdrien Destugues CPPUNIT_ASSERT(!url.HasPort());
139f38d4d45SAdrien Destugues CPPUNIT_ASSERT(!url.HasPath());
140f38d4d45SAdrien Destugues CPPUNIT_ASSERT(!url.HasRequest());
141f38d4d45SAdrien Destugues CPPUNIT_ASSERT(!url.HasFragment());
142f38d4d45SAdrien Destugues }
143f38d4d45SAdrien Destugues
144f38d4d45SAdrien Destugues
TestCopy()145f38d4d45SAdrien Destugues void UrlTest::TestCopy()
146f38d4d45SAdrien Destugues {
147f38d4d45SAdrien Destugues BUrl url1("http://example.com");
148f38d4d45SAdrien Destugues BUrl url2(url1);
149f38d4d45SAdrien Destugues
150f38d4d45SAdrien Destugues url2.SetHost("www.example.com");
151f38d4d45SAdrien Destugues
152f38d4d45SAdrien Destugues CPPUNIT_ASSERT_EQUAL(BString("www.example.com"), url2.Host());
153f38d4d45SAdrien Destugues CPPUNIT_ASSERT_EQUAL(BString("http://www.example.com"), url2.UrlString());
154f38d4d45SAdrien Destugues CPPUNIT_ASSERT_EQUAL(BString("example.com"), url1.Host());
155f38d4d45SAdrien Destugues CPPUNIT_ASSERT_EQUAL(BString("http://example.com"), url1.UrlString());
156f38d4d45SAdrien Destugues }
157f38d4d45SAdrien Destugues
158f38d4d45SAdrien Destugues
159f38d4d45SAdrien Destugues typedef struct
160f38d4d45SAdrien Destugues {
161f38d4d45SAdrien Destugues const char* url;
162f38d4d45SAdrien Destugues
163f38d4d45SAdrien Destugues struct
164f38d4d45SAdrien Destugues {
165f38d4d45SAdrien Destugues const char* protocol;
166f38d4d45SAdrien Destugues const char* userName;
167f38d4d45SAdrien Destugues const char* password;
168f38d4d45SAdrien Destugues const char* host;
169f38d4d45SAdrien Destugues int16 port;
170f38d4d45SAdrien Destugues const char* path;
171f38d4d45SAdrien Destugues const char* request;
172f38d4d45SAdrien Destugues const char* fragment;
173f38d4d45SAdrien Destugues } expected;
174f38d4d45SAdrien Destugues } ExplodeTest;
175f38d4d45SAdrien Destugues
176f38d4d45SAdrien Destugues
177f38d4d45SAdrien Destugues const ExplodeTest kTestExplode[] =
178f38d4d45SAdrien Destugues // Url
179f38d4d45SAdrien Destugues // Protocol User Password Hostname Port Path Request Fragment
180f38d4d45SAdrien Destugues // -------- --------- --------- --------- ---- ---------- ---------- ------------
181f38d4d45SAdrien Destugues {
182f38d4d45SAdrien Destugues { "http://user:pass@host:80/path?query#fragment",
183f38d4d45SAdrien Destugues { "http", "user", "pass", "host", 80, "/path", "query", "fragment" } },
184f38d4d45SAdrien Destugues { "http://www.host.tld/path?query#fragment",
185f38d4d45SAdrien Destugues { "http", "", "", "www.host.tld",0, "/path", "query", "fragment" } },
186f38d4d45SAdrien Destugues { "",
187f38d4d45SAdrien Destugues { "", "", "", "", 0, "", "", ""} },
188f38d4d45SAdrien Destugues { "mailto:John.Doe@example.com",
189f38d4d45SAdrien Destugues { "mailto", "", "", "", 0, "John.Doe@example.com", "", "" } },
190f38d4d45SAdrien Destugues { "mailto:?to=addr1@an.example,addr2@an.example",
191f38d4d45SAdrien Destugues { "mailto", "", "", "", 0, "", "to=addr1@an.example,addr2@an.example", "" } },
192f38d4d45SAdrien Destugues { "urn:oasis:names:specification:docbook:dtd:xml:4.1.2",
193043178a0SAdrien Destugues { "urn", "", "", "", 0, "oasis:names:specification:docbook:dtd:xml:4.1.2", "", "" } },
194043178a0SAdrien Destugues { "http://www.goodsearch.com/login?return_path=/",
195043178a0SAdrien Destugues { "http", "", "", "www.goodsearch.com", 0, "/login", "return_path=/", "" } },
196f4db7fdcSAdrien Destugues { "ldap://[2001:db8::7]:389/c=GB?objectClass?one",
197043178a0SAdrien Destugues { "ldap", "", "", "[2001:db8::7]",389,"/c=GB", "objectClass?one", "" } },
198f4db7fdcSAdrien Destugues { "ldap://[2001:db8::7]/c=GB?objectClass?one",
199f4db7fdcSAdrien Destugues { "ldap", "", "", "[2001:db8::7]",0, "/c=GB", "objectClass?one", "" } },
200043178a0SAdrien Destugues { "HTTP://example.com.:80/%70a%74%68?a=%31#1%323",
201f4db7fdcSAdrien Destugues { "HTTP", "", "", "example.com.",80, "/%70a%74%68","a=%31","1%323"} },
202f4db7fdcSAdrien Destugues { "/boot/home/Desktop/index.html",
203f4db7fdcSAdrien Destugues { "", "", "", "", 0, "/boot/home/Desktop/index.html","",""} },
204f4db7fdcSAdrien Destugues { "//remote.host/boot/home/Desktop",
205*aa272ca3SAdrien Destugues { "", "", "", "remote.host", 0, "/boot/home/Desktop","",""} },
206*aa272ca3SAdrien Destugues { "tag:haiku-os.org,2020:repositories/haiku/r1beta2/x86_gcc2",
207*aa272ca3SAdrien Destugues { "tag", "", "", "", 0, "haiku-os.org,2020:repositories/haiku/r1beta2/x86_gcc2" } }
208f38d4d45SAdrien Destugues };
209f38d4d45SAdrien Destugues
ExplodeImplodeTest()210f38d4d45SAdrien Destugues void UrlTest::ExplodeImplodeTest()
211f38d4d45SAdrien Destugues {
212f38d4d45SAdrien Destugues uint8 testIndex;
213f38d4d45SAdrien Destugues BUrl testUrl;
214f38d4d45SAdrien Destugues
215f38d4d45SAdrien Destugues for (testIndex = 0; testIndex < (sizeof(kTestExplode) / sizeof(ExplodeTest)); testIndex++)
216f38d4d45SAdrien Destugues {
217f38d4d45SAdrien Destugues NextSubTest();
218f38d4d45SAdrien Destugues testUrl.SetUrlString(kTestExplode[testIndex].url);
219f38d4d45SAdrien Destugues
220f38d4d45SAdrien Destugues CPPUNIT_ASSERT_EQUAL(BString(kTestExplode[testIndex].url),
221f38d4d45SAdrien Destugues BString(testUrl.UrlString()));
222f38d4d45SAdrien Destugues CPPUNIT_ASSERT_EQUAL(BString(kTestExplode[testIndex].expected.protocol),
223f38d4d45SAdrien Destugues BString(testUrl.Protocol()));
224f38d4d45SAdrien Destugues CPPUNIT_ASSERT_EQUAL(BString(kTestExplode[testIndex].expected.userName),
225f38d4d45SAdrien Destugues BString(testUrl.UserName()));
226f38d4d45SAdrien Destugues CPPUNIT_ASSERT_EQUAL(BString(kTestExplode[testIndex].expected.password),
227f38d4d45SAdrien Destugues BString(testUrl.Password()));
228f38d4d45SAdrien Destugues CPPUNIT_ASSERT_EQUAL(BString(kTestExplode[testIndex].expected.host),
229f38d4d45SAdrien Destugues BString(testUrl.Host()));
230f38d4d45SAdrien Destugues CPPUNIT_ASSERT_EQUAL(kTestExplode[testIndex].expected.port,
231f38d4d45SAdrien Destugues testUrl.Port());
232f38d4d45SAdrien Destugues CPPUNIT_ASSERT_EQUAL(BString(kTestExplode[testIndex].expected.path),
233f38d4d45SAdrien Destugues BString(testUrl.Path()));
234f38d4d45SAdrien Destugues CPPUNIT_ASSERT_EQUAL(BString(kTestExplode[testIndex].expected.request),
235f38d4d45SAdrien Destugues BString(testUrl.Request()));
236f38d4d45SAdrien Destugues CPPUNIT_ASSERT_EQUAL(BString(kTestExplode[testIndex].expected.fragment),
237f38d4d45SAdrien Destugues BString(testUrl.Fragment()));
238f38d4d45SAdrien Destugues }
239f38d4d45SAdrien Destugues }
240f38d4d45SAdrien Destugues
241f38d4d45SAdrien Destugues
242f38d4d45SAdrien Destugues void
PathOnly()243f38d4d45SAdrien Destugues UrlTest::PathOnly()
244f38d4d45SAdrien Destugues {
245f38d4d45SAdrien Destugues BUrl test = "lol";
246f38d4d45SAdrien Destugues CPPUNIT_ASSERT(test.HasPath());
247f38d4d45SAdrien Destugues CPPUNIT_ASSERT_EQUAL(BString("lol"), test.Path());
248f38d4d45SAdrien Destugues CPPUNIT_ASSERT_EQUAL(BString("lol"), test.UrlString());
249f38d4d45SAdrien Destugues }
250f38d4d45SAdrien Destugues
251f38d4d45SAdrien Destugues
252f38d4d45SAdrien Destugues void
RelativeUriTest()253f38d4d45SAdrien Destugues UrlTest::RelativeUriTest()
254f38d4d45SAdrien Destugues {
255f38d4d45SAdrien Destugues // http://skew.org/uri/uri%5Ftests.html
256f38d4d45SAdrien Destugues struct RelativeUrl {
257f38d4d45SAdrien Destugues const char* base;
258f38d4d45SAdrien Destugues const char* relative;
259f38d4d45SAdrien Destugues const char* absolute;
260f38d4d45SAdrien Destugues };
261f38d4d45SAdrien Destugues
262f38d4d45SAdrien Destugues const RelativeUrl tests[] = {
2634359643eSAdrien Destugues // The port must be preserved
2644359643eSAdrien Destugues {"http://host:81/", "/path", "http://host:81/path"},
2654359643eSAdrien Destugues
2664359643eSAdrien Destugues // Tests from http://skew.org/uri/uri_tests.html
267f38d4d45SAdrien Destugues {"http://example.com/path?query#frag", "",
268f38d4d45SAdrien Destugues "http://example.com/path?query"},
2694359643eSAdrien Destugues // The fragment must be dropped when changing the path, but the
2704359643eSAdrien Destugues // query must be preserved
271f38d4d45SAdrien Destugues {"foo:a/b", "../c", "foo:/c"},
272f38d4d45SAdrien Destugues // foo:c would be more intuitive, and is what skew.org tests.
273f38d4d45SAdrien Destugues // However, foo:/c is what the RFC says we should get.
274f38d4d45SAdrien Destugues {"foo:a", "foo:.", "foo:"},
275f38d4d45SAdrien Destugues {"zz:abc", "/foo/../../../bar", "zz:/bar"},
276f38d4d45SAdrien Destugues {"zz:abc", "/foo/../bar", "zz:/bar"},
277f38d4d45SAdrien Destugues {"zz:abc", "foo/../../../bar", "zz:/bar"},
278f38d4d45SAdrien Destugues // zz:bar would be more intuitive, ...
279f38d4d45SAdrien Destugues {"zz:abc", "zz:.", "zz:"},
280f38d4d45SAdrien Destugues {"http://a/b/c/d;p?q", "/.", "http://a/"},
281f38d4d45SAdrien Destugues {"http://a/b/c/d;p?q", "/.foo", "http://a/.foo"},
282f38d4d45SAdrien Destugues {"http://a/b/c/d;p?q", ".foo", "http://a/b/c/.foo"},
283f38d4d45SAdrien Destugues {"http://a/b/c/d;p?q", "g:h", "g:h"},
284f38d4d45SAdrien Destugues
285f38d4d45SAdrien Destugues {"http://a/b/c/d;p?q", "g:h", "g:h"},
286f38d4d45SAdrien Destugues {"http://a/b/c/d;p?q", "g", "http://a/b/c/g"},
287f38d4d45SAdrien Destugues {"http://a/b/c/d;p?q", "./g", "http://a/b/c/g"},
288f38d4d45SAdrien Destugues {"http://a/b/c/d;p?q", "g/", "http://a/b/c/g/"},
289f38d4d45SAdrien Destugues {"http://a/b/c/d;p?q", "/g", "http://a/g"},
290f38d4d45SAdrien Destugues {"http://a/b/c/d;p?q", "//g", "http://g"},
291f38d4d45SAdrien Destugues {"http://a/b/c/d;p?q", "?y", "http://a/b/c/d;p?y"},
292f38d4d45SAdrien Destugues {"http://a/b/c/d;p?q", "g?y", "http://a/b/c/g?y"},
293f38d4d45SAdrien Destugues {"http://a/b/c/d;p?q", "#s", "http://a/b/c/d;p?q#s"},
294f38d4d45SAdrien Destugues {"http://a/b/c/d;p?q", "g#s", "http://a/b/c/g#s"},
295f38d4d45SAdrien Destugues {"http://a/b/c/d;p?q", "g?y#s", "http://a/b/c/g?y#s"},
296f38d4d45SAdrien Destugues {"http://a/b/c/d;p?q", ";x", "http://a/b/c/;x"},
297f38d4d45SAdrien Destugues {"http://a/b/c/d;p?q", "g;x", "http://a/b/c/g;x"},
298f38d4d45SAdrien Destugues {"http://a/b/c/d;p?q", "g;x?y#s", "http://a/b/c/g;x?y#s"},
299f38d4d45SAdrien Destugues {"http://a/b/c/d;p?q", "", "http://a/b/c/d;p?q"},
300f38d4d45SAdrien Destugues {"http://a/b/c/d;p?q", ".", "http://a/b/c/"},
301f38d4d45SAdrien Destugues {"http://a/b/c/d;p?q", "./", "http://a/b/c/"},
302f38d4d45SAdrien Destugues {"http://a/b/c/d;p?q", "..", "http://a/b/"},
303f38d4d45SAdrien Destugues {"http://a/b/c/d;p?q", "../", "http://a/b/"},
304f38d4d45SAdrien Destugues {"http://a/b/c/d;p?q", "../g", "http://a/b/g"},
305f38d4d45SAdrien Destugues {"http://a/b/c/d;p?q", "../..", "http://a/"},
306f38d4d45SAdrien Destugues {"http://a/b/c/d;p?q", "../../", "http://a/"},
307f38d4d45SAdrien Destugues {"http://a/b/c/d;p?q", "../../g", "http://a/g"},
308f38d4d45SAdrien Destugues
309f38d4d45SAdrien Destugues // Parsers must be careful in handling cases where there are more
310f38d4d45SAdrien Destugues // relative path ".." segments than there are hierarchical levels in the
311f38d4d45SAdrien Destugues // base URI's path. Note that the ".." syntax cannot be used to change
312f38d4d45SAdrien Destugues // the authority component of a URI.
313f38d4d45SAdrien Destugues {"http://a/b/c/d;p?q", "../../../g", "http://a/g"},
314f38d4d45SAdrien Destugues {"http://a/b/c/d;p?q", "../../../../g", "http://a/g"},
315f38d4d45SAdrien Destugues
316f38d4d45SAdrien Destugues // Similarly, parsers must remove the dot-segments "." and ".." when
317f38d4d45SAdrien Destugues // they are complete components of a path, but not when they are only
318f38d4d45SAdrien Destugues // part of a segment.
319f38d4d45SAdrien Destugues {"http://a/b/c/d;p?q", "/./g", "http://a/g"},
320f38d4d45SAdrien Destugues {"http://a/b/c/d;p?q", "/../g", "http://a/g"},
321f38d4d45SAdrien Destugues {"http://a/b/c/d;p?q", "g.", "http://a/b/c/g."},
322f38d4d45SAdrien Destugues {"http://a/b/c/d;p?q", ".g", "http://a/b/c/.g"},
323f38d4d45SAdrien Destugues {"http://a/b/c/d;p?q", "g..", "http://a/b/c/g.."},
324f38d4d45SAdrien Destugues {"http://a/b/c/d;p?q", "..g", "http://a/b/c/..g"},
325f38d4d45SAdrien Destugues
326f38d4d45SAdrien Destugues // Less likely are cases where the relative URI reference uses
327f38d4d45SAdrien Destugues // unnecessary or nonsensical forms of the "." and ".." complete path
328f38d4d45SAdrien Destugues // segments.
329f38d4d45SAdrien Destugues {"http://a/b/c/d;p?q", "./../g", "http://a/b/g"},
330f38d4d45SAdrien Destugues {"http://a/b/c/d;p?q", "./g/.", "http://a/b/c/g/"},
331f38d4d45SAdrien Destugues {"http://a/b/c/d;p?q", "g/./h", "http://a/b/c/g/h"},
332f38d4d45SAdrien Destugues {"http://a/b/c/d;p?q", "g/../h", "http://a/b/c/h"},
333f38d4d45SAdrien Destugues {"http://a/b/c/d;p?q", "g;x=1/./y", "http://a/b/c/g;x=1/y"},
334f38d4d45SAdrien Destugues {"http://a/b/c/d;p?q", "g;x=1/../y", "http://a/b/c/y"},
335f38d4d45SAdrien Destugues
336f38d4d45SAdrien Destugues // Some applications fail to separate the reference's query and/or
337f38d4d45SAdrien Destugues // fragment components from a relative path before merging it with the
338f38d4d45SAdrien Destugues // base path and removing dot-segments. This error is rarely noticed,
339f38d4d45SAdrien Destugues // since typical usage of a fragment never includes the hierarchy ("/")
340f38d4d45SAdrien Destugues // character, and the query component is not normally used within
341f38d4d45SAdrien Destugues // relative references.
342f38d4d45SAdrien Destugues {"http://a/b/c/d;p?q", "g?y/./x", "http://a/b/c/g?y/./x"},
343f38d4d45SAdrien Destugues {"http://a/b/c/d;p?q", "g?y/../x", "http://a/b/c/g?y/../x"},
344f38d4d45SAdrien Destugues {"http://a/b/c/d;p?q", "g#s/./x", "http://a/b/c/g#s/./x"},
345f38d4d45SAdrien Destugues {"http://a/b/c/d;p?q", "g#s/../x", "http://a/b/c/g#s/../x"},
346f38d4d45SAdrien Destugues
347f38d4d45SAdrien Destugues // Some parsers allow the scheme name to be present in a relative URI
348f38d4d45SAdrien Destugues // reference if it is the same as the base URI scheme. This is
349f38d4d45SAdrien Destugues // considered to be a loophole in prior specifications of partial URI
350f38d4d45SAdrien Destugues // [RFC1630]. Its use should be avoided, but is allowed for backward
351f38d4d45SAdrien Destugues // compatibility.
352f38d4d45SAdrien Destugues {"http://a/b/c/d;p?q", "http:g", "http:g"},
353f38d4d45SAdrien Destugues {"http://a/b/c/d;p?q", "http:", "http:"},
354f38d4d45SAdrien Destugues
355f38d4d45SAdrien Destugues {"http://a/b/c/d;p?q", "./g:h", "http://a/b/c/g:h"},
356f38d4d45SAdrien Destugues {"http://a/b/c/d;p?q", "/a/b/c/./../../g", "http://a/a/g"},
357f38d4d45SAdrien Destugues
358f38d4d45SAdrien Destugues {"http://a/b/c/d;p?q=1/2", "g", "http://a/b/c/g"},
359f38d4d45SAdrien Destugues {"http://a/b/c/d;p?q=1/2", "./g", "http://a/b/c/g"},
360f38d4d45SAdrien Destugues {"http://a/b/c/d;p?q=1/2", "g/", "http://a/b/c/g/"},
361f38d4d45SAdrien Destugues {"http://a/b/c/d;p?q=1/2", "/g", "http://a/g"},
362f38d4d45SAdrien Destugues {"http://a/b/c/d;p?q=1/2", "//g", "http://g"},
363f38d4d45SAdrien Destugues {"http://a/b/c/d;p?q=1/2", "?y", "http://a/b/c/d;p?y"},
364f38d4d45SAdrien Destugues {"http://a/b/c/d;p?q=1/2", "g?y", "http://a/b/c/g?y"},
365f38d4d45SAdrien Destugues {"http://a/b/c/d;p?q=1/2", "g?y/./x", "http://a/b/c/g?y/./x"},
366f38d4d45SAdrien Destugues {"http://a/b/c/d;p?q=1/2", "g?y/../x", "http://a/b/c/g?y/../x"},
367f38d4d45SAdrien Destugues {"http://a/b/c/d;p?q=1/2", "g#s", "http://a/b/c/g#s"},
368f38d4d45SAdrien Destugues {"http://a/b/c/d;p?q=1/2", "g#s/./x", "http://a/b/c/g#s/./x"},
369f38d4d45SAdrien Destugues {"http://a/b/c/d;p?q=1/2", "g#s/../x", "http://a/b/c/g#s/../x"},
370f38d4d45SAdrien Destugues {"http://a/b/c/d;p?q=1/2", "./", "http://a/b/c/"},
371f38d4d45SAdrien Destugues {"http://a/b/c/d;p?q=1/2", "../", "http://a/b/"},
372f38d4d45SAdrien Destugues {"http://a/b/c/d;p?q=1/2", "../g", "http://a/b/g"},
373f38d4d45SAdrien Destugues {"http://a/b/c/d;p?q=1/2", "../../", "http://a/"},
374f38d4d45SAdrien Destugues {"http://a/b/c/d;p?q=1/2", "../../g", "http://a/g"},
375f38d4d45SAdrien Destugues
376f38d4d45SAdrien Destugues {"http://a/b/c/d;p=1/2?q", "g", "http://a/b/c/d;p=1/g"},
377f38d4d45SAdrien Destugues {"http://a/b/c/d;p=1/2?q", "./g", "http://a/b/c/d;p=1/g"},
378f38d4d45SAdrien Destugues {"http://a/b/c/d;p=1/2?q", "g/", "http://a/b/c/d;p=1/g/"},
379f38d4d45SAdrien Destugues {"http://a/b/c/d;p=1/2?q", "g?y", "http://a/b/c/d;p=1/g?y"},
380f38d4d45SAdrien Destugues {"http://a/b/c/d;p=1/2?q", ";x", "http://a/b/c/d;p=1/;x"},
381f38d4d45SAdrien Destugues {"http://a/b/c/d;p=1/2?q", "g;x", "http://a/b/c/d;p=1/g;x"},
382f38d4d45SAdrien Destugues {"http://a/b/c/d;p=1/2?q", "g;x=1/./y", "http://a/b/c/d;p=1/g;x=1/y"},
383f38d4d45SAdrien Destugues {"http://a/b/c/d;p=1/2?q", "g;x=1/../y", "http://a/b/c/d;p=1/y"},
384f38d4d45SAdrien Destugues {"http://a/b/c/d;p=1/2?q", "./", "http://a/b/c/d;p=1/"},
385f38d4d45SAdrien Destugues {"http://a/b/c/d;p=1/2?q", "../", "http://a/b/c/"},
386f38d4d45SAdrien Destugues {"http://a/b/c/d;p=1/2?q", "../g", "http://a/b/c/g"},
387f38d4d45SAdrien Destugues {"http://a/b/c/d;p=1/2?q", "../../", "http://a/b/"},
388f38d4d45SAdrien Destugues {"http://a/b/c/d;p=1/2?q", "../../g", "http://a/b/g"},
389f38d4d45SAdrien Destugues
390f38d4d45SAdrien Destugues // Empty host and directory
391f38d4d45SAdrien Destugues {"fred:///s//a/b/c", "g:h", "g:h"},
392f38d4d45SAdrien Destugues {"fred:///s//a/b/c", "g", "fred:///s//a/b/g"},
393f38d4d45SAdrien Destugues {"fred:///s//a/b/c", "./g", "fred:///s//a/b/g"},
394f38d4d45SAdrien Destugues {"fred:///s//a/b/c", "g/", "fred:///s//a/b/g/"},
395f38d4d45SAdrien Destugues {"fred:///s//a/b/c", "/g", "fred:///g"},
396f38d4d45SAdrien Destugues {"fred:///s//a/b/c", "//g", "fred://g"},
397f38d4d45SAdrien Destugues {"fred:///s//a/b/c", "//g/x", "fred://g/x"},
398f38d4d45SAdrien Destugues {"fred:///s//a/b/c", "///g", "fred:///g"},
399f38d4d45SAdrien Destugues {"fred:///s//a/b/c", "./", "fred:///s//a/b/"},
400f38d4d45SAdrien Destugues {"fred:///s//a/b/c", "../", "fred:///s//a/"},
401f38d4d45SAdrien Destugues {"fred:///s//a/b/c", "../g", "fred:///s//a/g"},
402f38d4d45SAdrien Destugues {"fred:///s//a/b/c", "../..", "fred:///s//"},
403f38d4d45SAdrien Destugues {"fred:///s//a/b/c", "../../g", "fred:///s//g"},
404f38d4d45SAdrien Destugues {"fred:///s//a/b/c", "../../../g", "fred:///s/g"},
405f38d4d45SAdrien Destugues {"fred:///s//a/b/c", "../../../g", "fred:///s/g"},
406f38d4d45SAdrien Destugues
407f38d4d45SAdrien Destugues {"http:///s//a/b/c", "g:h", "g:h"},
408f38d4d45SAdrien Destugues {"http:///s//a/b/c", "g", "http:///s//a/b/g"},
409f38d4d45SAdrien Destugues {"http:///s//a/b/c", "./g", "http:///s//a/b/g"},
410f38d4d45SAdrien Destugues {"http:///s//a/b/c", "g/", "http:///s//a/b/g/"},
411f38d4d45SAdrien Destugues {"http:///s//a/b/c", "/g", "http:///g"},
412f38d4d45SAdrien Destugues {"http:///s//a/b/c", "//g", "http://g"},
413f38d4d45SAdrien Destugues {"http:///s//a/b/c", "//g/x", "http://g/x"},
414f38d4d45SAdrien Destugues {"http:///s//a/b/c", "///g", "http:///g"},
415f38d4d45SAdrien Destugues {"http:///s//a/b/c", "./", "http:///s//a/b/"},
416f38d4d45SAdrien Destugues {"http:///s//a/b/c", "../", "http:///s//a/"},
417f38d4d45SAdrien Destugues {"http:///s//a/b/c", "../g", "http:///s//a/g"},
418f38d4d45SAdrien Destugues {"http:///s//a/b/c", "../..", "http:///s//"},
419f38d4d45SAdrien Destugues {"http:///s//a/b/c", "../../g", "http:///s//g"},
420f38d4d45SAdrien Destugues {"http:///s//a/b/c", "../../../g", "http:///s/g"},
421f38d4d45SAdrien Destugues {"http:///s//a/b/c", "../../../g", "http:///s/g"},
422f38d4d45SAdrien Destugues
423f38d4d45SAdrien Destugues {"foo:xyz", "bar:abc", "bar:abc"},
424f38d4d45SAdrien Destugues {"http://example/x/y/z","../abc", "http://example/x/abc"},
425f38d4d45SAdrien Destugues {"http://example2/x/y/z","http://example/x/abc","http://example/x/abc"},
426f38d4d45SAdrien Destugues {"http://ex/x/y/z", "../r", "http://ex/x/r"},
427f38d4d45SAdrien Destugues {"http://ex/x/y", "q/r", "http://ex/x/q/r"},
428f38d4d45SAdrien Destugues {"http://ex/x/y", "q/r#s", "http://ex/x/q/r#s"},
429f38d4d45SAdrien Destugues {"http://ex/x/y", "q/r#s/t", "http://ex/x/q/r#s/t"},
430f38d4d45SAdrien Destugues {"http://ex/x/y", "ftp://ex/x/q/r", "ftp://ex/x/q/r"},
431f38d4d45SAdrien Destugues {"http://ex/x/y", "", "http://ex/x/y"},
432f38d4d45SAdrien Destugues {"http://ex/x/y/", "", "http://ex/x/y/"},
433f38d4d45SAdrien Destugues {"http://ex/x/y/pdq", "", "http://ex/x/y/pdq"},
434f38d4d45SAdrien Destugues {"http://ex/x/y/", "z/", "http://ex/x/y/z/"},
435f38d4d45SAdrien Destugues
436f38d4d45SAdrien Destugues {"file:/swap/test/animal.rdf", "#Animal",
437f38d4d45SAdrien Destugues "file:/swap/test/animal.rdf#Animal"},
438f38d4d45SAdrien Destugues {"file:/e/x/y/z", "../abc", "file:/e/x/abc"},
439f38d4d45SAdrien Destugues {"file:/example2/x/y/z","/example/x/abc", "file:/example/x/abc"},
440f38d4d45SAdrien Destugues {"file:/e/x/y/z", "../r", "file:/e/x/r"},
441f38d4d45SAdrien Destugues {"file:/e/x/y/z", "/r", "file:/r"},
442f38d4d45SAdrien Destugues {"file:/e/x/y", "q/r", "file:/e/x/q/r"},
443f38d4d45SAdrien Destugues {"file:/e/x/y", "q/r#s", "file:/e/x/q/r#s"},
444f38d4d45SAdrien Destugues {"file:/e/x/y", "q/r#", "file:/e/x/q/r#"},
445f38d4d45SAdrien Destugues {"file:/e/x/y", "q/r#s/t", "file:/e/x/q/r#s/t"},
446f38d4d45SAdrien Destugues {"file:/e/x/y", "ftp://ex/x/q/r", "ftp://ex/x/q/r"},
447f38d4d45SAdrien Destugues {"file:/e/x/y", "", "file:/e/x/y"},
448f38d4d45SAdrien Destugues {"file:/e/x/y/", "", "file:/e/x/y/"},
449f38d4d45SAdrien Destugues {"file:/e/x/y/pdq", "", "file:/e/x/y/pdq"},
450f38d4d45SAdrien Destugues {"file:/e/x/y/", "z/", "file:/e/x/y/z/"},
451f38d4d45SAdrien Destugues {"file:/devel/WWW/2000/10/swap/test/reluri-1.n3",
452f38d4d45SAdrien Destugues "file://meetings.example.com/cal#m1",
453f38d4d45SAdrien Destugues "file://meetings.example.com/cal#m1"},
454f38d4d45SAdrien Destugues {"file:/home/connolly/w3ccvs/WWW/2000/10/swap/test/reluri-1.n3",
455f38d4d45SAdrien Destugues "file://meetings.example.com/cal#m1",
456f38d4d45SAdrien Destugues "file://meetings.example.com/cal#m1"},
457f38d4d45SAdrien Destugues {"file:/some/dir/foo", "./#blort", "file:/some/dir/#blort"},
458f38d4d45SAdrien Destugues {"file:/some/dir/foo", "./#", "file:/some/dir/#"},
459f38d4d45SAdrien Destugues
460f38d4d45SAdrien Destugues {"http://example/x/abc.efg", "./", "http://example/x/"},
461f38d4d45SAdrien Destugues {"http://example2/x/y/z", "//example/x/abc","http://example/x/abc"},
462f38d4d45SAdrien Destugues {"http://ex/x/y/z", "/r", "http://ex/r"},
463f38d4d45SAdrien Destugues {"http://ex/x/y", "./q:r", "http://ex/x/q:r"},
464f38d4d45SAdrien Destugues {"http://ex/x/y", "./p=q:r", "http://ex/x/p=q:r"},
465f38d4d45SAdrien Destugues {"http://ex/x/y?pp/qq", "?pp/rr", "http://ex/x/y?pp/rr"},
466f38d4d45SAdrien Destugues {"http://ex/x/y?pp/qq", "y/z", "http://ex/x/y/z"},
467f38d4d45SAdrien Destugues
468f38d4d45SAdrien Destugues {"mailto:local", "local/qual@domain.org#frag",
469f38d4d45SAdrien Destugues "mailto:local/qual@domain.org#frag"},
470f38d4d45SAdrien Destugues {"mailto:local/qual1@domain1.org", "more/qual2@domain2.org#frag",
471f38d4d45SAdrien Destugues "mailto:local/more/qual2@domain2.org#frag"},
472f38d4d45SAdrien Destugues
473f38d4d45SAdrien Destugues {"http://ex/x/y?q", "y?q", "http://ex/x/y?q"},
474f38d4d45SAdrien Destugues {"http://ex?p", "x/y?q", "http://ex/x/y?q"},
475f38d4d45SAdrien Destugues {"foo:a/b", "c/d", "foo:a/c/d"},
476f38d4d45SAdrien Destugues {"foo:a/b", "/c/d", "foo:/c/d"},
477f38d4d45SAdrien Destugues {"foo:a/b?c#d", "", "foo:a/b?c"},
478f38d4d45SAdrien Destugues {"foo:a", "b/c", "foo:b/c"},
479f38d4d45SAdrien Destugues {"foo:/a/y/z", "../b/c", "foo:/a/b/c"},
480f38d4d45SAdrien Destugues {"foo:a", "./b/c", "foo:b/c"},
481f38d4d45SAdrien Destugues {"foo:a", "/./b/c", "foo:/b/c"},
482f38d4d45SAdrien Destugues {"foo://a//b/c", "../../d", "foo://a/d"},
483f38d4d45SAdrien Destugues {"foo:a", ".", "foo:"},
484f38d4d45SAdrien Destugues {"foo:a", "..", "foo:"},
485f38d4d45SAdrien Destugues
486f38d4d45SAdrien Destugues {"http://example/x/y%2Fz", "abc", "http://example/x/abc"},
487f38d4d45SAdrien Destugues {"http://example/a/x/y/z", "../../x%2Fabc", "http://example/a/x%2Fabc"},
488f38d4d45SAdrien Destugues {"http://example/a/x/y%2Fz", "../x%2Fabc", "http://example/a/x%2Fabc"},
489f38d4d45SAdrien Destugues {"http://example/x%2Fy/z", "abc", "http://example/x%2Fy/abc"},
490f38d4d45SAdrien Destugues {"http://ex/x/y", "q%3Ar", "http://ex/x/q%3Ar"},
491f38d4d45SAdrien Destugues {"http://example/x/y%2Fz", "/x%2Fabc", "http://example/x%2Fabc"},
492f38d4d45SAdrien Destugues {"http://example/x/y/z", "/x%2Fabc", "http://example/x%2Fabc"},
493f38d4d45SAdrien Destugues
494f38d4d45SAdrien Destugues {"mailto:local1@domain1?query1", "local2@domain2",
495f38d4d45SAdrien Destugues "mailto:local2@domain2"},
496f38d4d45SAdrien Destugues {"mailto:local1@domain1", "local2@domain2?query2",
497f38d4d45SAdrien Destugues "mailto:local2@domain2?query2"},
498f38d4d45SAdrien Destugues {"mailto:local1@domain1?query1", "local2@domain2?query2",
499f38d4d45SAdrien Destugues "mailto:local2@domain2?query2"},
500f38d4d45SAdrien Destugues {"mailto:local@domain?query1", "?query2",
501f38d4d45SAdrien Destugues "mailto:local@domain?query2"},
502f38d4d45SAdrien Destugues {"mailto:?query1", "local2@domain2?query2",
503f38d4d45SAdrien Destugues "mailto:local2@domain2?query2"},
504f38d4d45SAdrien Destugues {"mailto:local1@domain1?query1", "?query2",
505f38d4d45SAdrien Destugues "mailto:local1@domain1?query2"},
506f38d4d45SAdrien Destugues
507f38d4d45SAdrien Destugues {"foo:bar", "http://example/a/b?c/../d", "http://example/a/b?c/../d"},
508f38d4d45SAdrien Destugues {"foo:bar", "http://example/a/b#c/../d", "http://example/a/b#c/../d"},
509f38d4d45SAdrien Destugues {"http://example.org/base/uri", "http:this", "http:this"},
510f38d4d45SAdrien Destugues {"http:base", "http:this", "http:this"},
511f38d4d45SAdrien Destugues {"f:/a", ".//g", "f://g"},
512f38d4d45SAdrien Destugues {"f://example.org/base/a", "b/c//d/e", "f://example.org/base/b/c//d/e"},
513f38d4d45SAdrien Destugues {"mid:m@example.ord/c@example.org", "m2@example.ord/c2@example.org",
514f38d4d45SAdrien Destugues "mid:m@example.ord/m2@example.ord/c2@example.org"},
515f38d4d45SAdrien Destugues {"file:///C:/DEV/Haskell/lib/HXmlToolbox-3.01/examples/", "mini1.xml",
516f38d4d45SAdrien Destugues "file:///C:/DEV/Haskell/lib/HXmlToolbox-3.01/examples/mini1.xml"},
517f38d4d45SAdrien Destugues {"foo:a/y/z", "../b/c", "foo:a/b/c"},
518f38d4d45SAdrien Destugues {"foo:", "b", "foo:b"},
519f38d4d45SAdrien Destugues {"foo://a", "b", "foo://a/b"},
520f38d4d45SAdrien Destugues {"foo://a?q", "b", "foo://a/b"},
521f38d4d45SAdrien Destugues {"foo://a", "b?q", "foo://a/b?q"},
522f38d4d45SAdrien Destugues {"foo://a?r", "b?q", "foo://a/b?q"},
523f38d4d45SAdrien Destugues };
524f38d4d45SAdrien Destugues
525f38d4d45SAdrien Destugues BString message(" Base: ");
526f38d4d45SAdrien Destugues for (unsigned int index = 0; index < sizeof(tests) / sizeof(RelativeUrl);
527f38d4d45SAdrien Destugues index++)
528f38d4d45SAdrien Destugues {
529f38d4d45SAdrien Destugues NextSubTest();
530f38d4d45SAdrien Destugues
531f38d4d45SAdrien Destugues BUrl baseUrl(tests[index].base);
532f38d4d45SAdrien Destugues
533f38d4d45SAdrien Destugues message.Truncate(7, true);
534f38d4d45SAdrien Destugues message << tests[index].base;
535f38d4d45SAdrien Destugues message << " Relative: ";
536f38d4d45SAdrien Destugues message << tests[index].relative;
537f38d4d45SAdrien Destugues
538f38d4d45SAdrien Destugues CPPUNIT_ASSERT_EQUAL_MESSAGE(message.String(),
539f38d4d45SAdrien Destugues BString(tests[index].absolute),
540f38d4d45SAdrien Destugues BUrl(baseUrl, tests[index].relative).UrlString());
541f38d4d45SAdrien Destugues }
542f38d4d45SAdrien Destugues }
543f38d4d45SAdrien Destugues
544f38d4d45SAdrien Destugues
545f38d4d45SAdrien Destugues void
IDNTest()546f38d4d45SAdrien Destugues UrlTest::IDNTest()
547f38d4d45SAdrien Destugues {
548f38d4d45SAdrien Destugues // http://www.w3.org/2004/04/uri-rel-test.html
5496da9451eSAdrien Destugues // TODO We need to decide wether to store them as UTF-8 or IDNA/punycode.
5506da9451eSAdrien Destugues
5516da9451eSAdrien Destugues struct Test {
5526da9451eSAdrien Destugues const char* escaped;
5536da9451eSAdrien Destugues const char* decoded;
5546da9451eSAdrien Destugues };
5556da9451eSAdrien Destugues
5566da9451eSAdrien Destugues Test tests[] = {
5576da9451eSAdrien Destugues { "http://www.w%33.org", "http://www.w3.org" },
5586da9451eSAdrien Destugues { "http://r%C3%A4ksm%C3%B6rg%C3%A5s.josefsson.org",
5596da9451eSAdrien Destugues "http://xn--rksmrgs-5wao1o.josefsson.org" },
5606da9451eSAdrien Destugues { "http://%E7%B4%8D%E8%B1%86.w3.mag.keio.ac.jp",
5616da9451eSAdrien Destugues "http://xn--99zt52a.w3.mag.keio.ac.jp" },
5626da9451eSAdrien Destugues { "http://www.%E3%81%BB%E3%82%93%E3%81%A8%E3%81%86%E3%81%AB%E3%81%AA"
563f38d4d45SAdrien Destugues "%E3%81%8C%E3%81%84%E3%82%8F%E3%81%91%E3%81%AE%E3%82%8F%E3%81%8B%E3"
564f38d4d45SAdrien Destugues "%82%89%E3%81%AA%E3%81%84%E3%81%A9%E3%82%81%E3%81%84%E3%82%93%E3%82"
565f38d4d45SAdrien Destugues "%81%E3%81%84%E3%81%AE%E3%82%89%E3%81%B9%E3%82%8B%E3%81%BE%E3%81%A0"
566f38d4d45SAdrien Destugues "%E3%81%AA%E3%81%8C%E3%81%8F%E3%81%97%E3%81%AA%E3%81%84%E3%81%A8%E3"
5676da9451eSAdrien Destugues "%81%9F%E3%82%8A%E3%81%AA%E3%81%84.w3.mag.keio.ac.jp/",
5686da9451eSAdrien Destugues "http://www.xn--n8jaaaaai5bhf7as8fsfk3jnknefdde3fg11amb5gzdb4wi9b"
5696da9451eSAdrien Destugues "ya3kc6lra.w3.mag.keio.ac.jp/" },
5706da9451eSAdrien Destugues
5716da9451eSAdrien Destugues { "http://%E3%81%BB%E3%82%93%E3%81%A8%E3%81%86%E3%81%AB%E3%81%AA%E3"
572f38d4d45SAdrien Destugues "%81%8C%E3%81%84%E3%82%8F%E3%81%91%E3%81%AE%E3%82%8F%E3%81%8B%E3%82"
573f38d4d45SAdrien Destugues "%89%E3%81%AA%E3%81%84%E3%81%A9%E3%82%81%E3%81%84%E3%82%93%E3%82%81"
574f38d4d45SAdrien Destugues "%E3%81%84%E3%81%AE%E3%82%89%E3%81%B9%E3%82%8B%E3%81%BE%E3%81%A0%E3"
575f38d4d45SAdrien Destugues "%81%AA%E3%81%8C%E3%81%8F%E3%81%97%E3%81%AA%E3%81%84%E3%81%A8%E3%81"
576f38d4d45SAdrien Destugues "%9F%E3%82%8A%E3%81%AA%E3%81%84.%E3%81%BB%E3%82%93%E3%81%A8%E3%81"
577f38d4d45SAdrien Destugues "%86%E3%81%AB%E3%81%AA%E3%81%8C%E3%81%84%E3%82%8F%E3%81%91%E3%81%AE"
578f38d4d45SAdrien Destugues "%E3%82%8F%E3%81%8B%E3%82%89%E3%81%AA%E3%81%84%E3%81%A9%E3%82%81%E3"
579f38d4d45SAdrien Destugues "%81%84%E3%82%93%E3%82%81%E3%81%84%E3%81%AE%E3%82%89%E3%81%B9%E3%82"
580f38d4d45SAdrien Destugues "%8B%E3%81%BE%E3%81%A0%E3%81%AA%E3%81%8C%E3%81%8F%E3%81%97%E3%81%AA"
581f38d4d45SAdrien Destugues "%E3%81%84%E3%81%A8%E3%81%9F%E3%82%8A%E3%81%AA%E3%81%84.%E3%81%BB"
582f38d4d45SAdrien Destugues "%E3%82%93%E3%81%A8%E3%81%86%E3%81%AB%E3%81%AA%E3%81%8C%E3%81%84%E3"
583f38d4d45SAdrien Destugues "%82%8F%E3%81%91%E3%81%AE%E3%82%8F%E3%81%8B%E3%82%89%E3%81%AA%E3%81"
584f38d4d45SAdrien Destugues "%84%E3%81%A9%E3%82%81%E3%81%84%E3%82%93%E3%82%81%E3%81%84%E3%81%AE"
585f38d4d45SAdrien Destugues "%E3%82%89%E3%81%B9%E3%82%8B%E3%81%BE%E3%81%A0%E3%81%AA%E3%81%8C%E3"
586f38d4d45SAdrien Destugues "%81%8F%E3%81%97%E3%81%AA%E3%81%84%E3%81%A8%E3%81%9F%E3%82%8A%E3%81"
5876da9451eSAdrien Destugues "%AA%E3%81%84.w3.mag.keio.ac.jp/",
5886da9451eSAdrien Destugues "http://xn--n8jaaaaai5bhf7as8fsfk3jnknefdde3fg11amb5gzdb4wi9bya3k"
5896da9451eSAdrien Destugues "c6lra.xn--n8jaaaaai5bhf7as8fsfk3jnknefdde3fg11amb5gzdb4wi9bya3kc6"
5906da9451eSAdrien Destugues "lra.xn--n8jaaaaai5bhf7as8fsfk3jnknefdde3fg11amb5gzdb4wi9bya3kc6lr"
5916da9451eSAdrien Destugues "a.w3.mag.keio.ac.jp/" },
5926da9451eSAdrien Destugues { NULL, NULL }
5936da9451eSAdrien Destugues };
5946da9451eSAdrien Destugues
5956da9451eSAdrien Destugues for (int i = 0; tests[i].escaped != NULL; i++)
5966da9451eSAdrien Destugues {
5976da9451eSAdrien Destugues NextSubTest();
5989bf4e994SAdrien Destugues
5996da9451eSAdrien Destugues BUrl url(tests[i].escaped);
6006da9451eSAdrien Destugues url.UrlDecode();
6019bf4e994SAdrien Destugues
6029bf4e994SAdrien Destugues BUrl idn(tests[i].decoded);
6039bf4e994SAdrien Destugues status_t success = idn.IDNAToUnicode();
6049bf4e994SAdrien Destugues
6059bf4e994SAdrien Destugues CPPUNIT_ASSERT_EQUAL(B_OK, success);
6069bf4e994SAdrien Destugues CPPUNIT_ASSERT_EQUAL(url.UrlString(), idn.UrlString());
6076da9451eSAdrien Destugues }
608f38d4d45SAdrien Destugues }
609f38d4d45SAdrien Destugues
610f38d4d45SAdrien Destugues
611f38d4d45SAdrien Destugues /* static */ void
AddTests(BTestSuite & parent)612f38d4d45SAdrien Destugues UrlTest::AddTests(BTestSuite& parent)
613f38d4d45SAdrien Destugues {
614f38d4d45SAdrien Destugues CppUnit::TestSuite& suite = *new CppUnit::TestSuite("UrlTest");
615f38d4d45SAdrien Destugues
616f38d4d45SAdrien Destugues suite.addTest(new CppUnit::TestCaller<UrlTest>("UrlTest::ParseTest",
617f38d4d45SAdrien Destugues &UrlTest::ParseTest));
618f38d4d45SAdrien Destugues suite.addTest(new CppUnit::TestCaller<UrlTest>("UrlTest::TestIsValid",
619f38d4d45SAdrien Destugues &UrlTest::TestIsValid));
620f38d4d45SAdrien Destugues suite.addTest(new CppUnit::TestCaller<UrlTest>(
621f38d4d45SAdrien Destugues "UrlTest::TestGettersSetters", &UrlTest::TestGettersSetters));
622f38d4d45SAdrien Destugues suite.addTest(new CppUnit::TestCaller<UrlTest>("UrlTest::TestNullity",
623f38d4d45SAdrien Destugues &UrlTest::TestNullity));
624f38d4d45SAdrien Destugues suite.addTest(new CppUnit::TestCaller<UrlTest>("UrlTest::TestCopy",
625f38d4d45SAdrien Destugues &UrlTest::TestCopy));
626f38d4d45SAdrien Destugues suite.addTest(new CppUnit::TestCaller<UrlTest>(
627f38d4d45SAdrien Destugues "UrlTest::ExplodeImplodeTest", &UrlTest::ExplodeImplodeTest));
628f38d4d45SAdrien Destugues suite.addTest(new CppUnit::TestCaller<UrlTest>("UrlTest::PathOnly",
629f38d4d45SAdrien Destugues &UrlTest::PathOnly));
630f38d4d45SAdrien Destugues suite.addTest(new CppUnit::TestCaller<UrlTest>("UrlTest::RelativeUriTest",
631f38d4d45SAdrien Destugues &UrlTest::RelativeUriTest));
632f38d4d45SAdrien Destugues suite.addTest(new CppUnit::TestCaller<UrlTest>("UrlTest::IDNTest",
633f38d4d45SAdrien Destugues &UrlTest::IDNTest));
634f38d4d45SAdrien Destugues
635f38d4d45SAdrien Destugues parent.addTest("UrlTest", &suite);
636f38d4d45SAdrien Destugues }
637