From d9a33f3c17218a393959534ce656f4abbe3cbf28 Mon Sep 17 00:00:00 2001 From: Detlef Riekenberg Date: Fri, 12 Oct 2007 09:46:19 +0200 Subject: [PATCH] shlwapi/tests: Move URL testing functions from path.c to url.c. --- dlls/shlwapi/tests/Makefile.in | 3 +- dlls/shlwapi/tests/path.c | 588 +--------------------------- dlls/shlwapi/tests/url.c | 686 +++++++++++++++++++++++++++++++++ 3 files changed, 695 insertions(+), 582 deletions(-) create mode 100644 dlls/shlwapi/tests/url.c diff --git a/dlls/shlwapi/tests/Makefile.in b/dlls/shlwapi/tests/Makefile.in index 8d48932ab7d..42382761e4e 100644 --- a/dlls/shlwapi/tests/Makefile.in +++ b/dlls/shlwapi/tests/Makefile.in @@ -13,7 +13,8 @@ CTESTS = \ ordinal.c \ path.c \ shreg.c \ - string.c + string.c \ + url.c @MAKE_TEST_RULES@ diff --git a/dlls/shlwapi/tests/path.c b/dlls/shlwapi/tests/path.c index 7eb02b2c42f..5fb490d0fad 100644 --- a/dlls/shlwapi/tests/path.c +++ b/dlls/shlwapi/tests/path.c @@ -33,203 +33,7 @@ static HRESULT (WINAPI *pPathIsValidCharA)(char,DWORD); static HRESULT (WINAPI *pPathIsValidCharW)(WCHAR,DWORD); static LPWSTR (WINAPI *pPathCombineW)(LPWSTR, LPCWSTR, LPCWSTR); -const char* TEST_URL_1 = "http://www.winehq.org/tests?date=10/10/1923"; -const char* TEST_URL_2 = "http://localhost:8080/tests%2e.html?date=Mon%2010/10/1923"; -const char* TEST_URL_3 = "http://foo:bar@localhost:21/internal.php?query=x&return=y"; - -typedef struct _TEST_URL_CANONICALIZE { - const char *url; - DWORD flags; - HRESULT expectret; - const char *expecturl; -} TEST_URL_CANONICALIZE; - -const TEST_URL_CANONICALIZE TEST_CANONICALIZE[] = { - /*FIXME {"http://www.winehq.org/tests/../tests/../..", 0, S_OK, "http://www.winehq.org/"},*/ - {"http://www.winehq.org/tests/../tests", 0, S_OK, "http://www.winehq.org/tests"}, - {"http://www.winehq.org/tests\n", URL_WININET_COMPATIBILITY|URL_ESCAPE_SPACES_ONLY|URL_ESCAPE_UNSAFE, S_OK, "http://www.winehq.org/tests"}, - {"http://www.winehq.org/tests\r", URL_WININET_COMPATIBILITY|URL_ESCAPE_SPACES_ONLY|URL_ESCAPE_UNSAFE, S_OK, "http://www.winehq.org/tests"}, - {"http://www.winehq.org/tests\r", 0, S_OK, "http://www.winehq.org/tests"}, - {"http://www.winehq.org/tests\r", URL_DONT_SIMPLIFY, S_OK, "http://www.winehq.org/tests"}, - {"http://www.winehq.org/tests/../tests/", 0, S_OK, "http://www.winehq.org/tests/"}, - {"http://www.winehq.org/tests/../tests/..", 0, S_OK, "http://www.winehq.org/"}, - {"http://www.winehq.org/tests/../tests/../", 0, S_OK, "http://www.winehq.org/"}, - {"http://www.winehq.org/tests/..", 0, S_OK, "http://www.winehq.org/"}, - {"http://www.winehq.org/tests/../", 0, S_OK, "http://www.winehq.org/"}, - {"http://www.winehq.org/tests/..?query=x&return=y", 0, S_OK, "http://www.winehq.org/?query=x&return=y"}, - {"http://www.winehq.org/tests/../?query=x&return=y", 0, S_OK, "http://www.winehq.org/?query=x&return=y"}, - {"http://www.winehq.org/tests/..#example", 0, S_OK, "http://www.winehq.org/#example"}, - {"http://www.winehq.org/tests/../#example", 0, S_OK, "http://www.winehq.org/#example"}, - {"http://www.winehq.org/tests\\../#example", 0, S_OK, "http://www.winehq.org/#example"}, - {"http://www.winehq.org/tests/..\\#example", 0, S_OK, "http://www.winehq.org/#example"}, - {"http://www.winehq.org\\tests/../#example", 0, S_OK, "http://www.winehq.org/#example"}, - {"http://www.winehq.org/tests/../#example", URL_DONT_SIMPLIFY, S_OK, "http://www.winehq.org/tests/../#example"}, - {"http://www.winehq.org/tests/foo bar", URL_ESCAPE_SPACES_ONLY| URL_DONT_ESCAPE_EXTRA_INFO , S_OK, "http://www.winehq.org/tests/foo%20bar"}, - {"http://www.winehq.org/tests/foo%20bar", URL_UNESCAPE , S_OK, "http://www.winehq.org/tests/foo bar"}, - {"file:///c:/tests/foo%20bar", URL_UNESCAPE , S_OK, "file:///c:/tests/foo bar"}, - {"file:///c:/tests\\foo%20bar", URL_UNESCAPE , S_OK, "file:///c:/tests/foo bar"}, - {"file:///c:/tests/foo%20bar", 0, S_OK, "file:///c:/tests/foo%20bar"}, - {"file:///c:/tests/foo%20bar", URL_FILE_USE_PATHURL, S_OK, "file://c:\\tests\\foo bar"}, - {"file://c:/tests/../tests/foo%20bar", URL_FILE_USE_PATHURL, S_OK, "file://c:\\tests\\foo bar"}, - {"file://c:/tests\\../tests/foo%20bar", URL_FILE_USE_PATHURL, S_OK, "file://c:\\tests\\foo bar"}, - {"file://c:/tests/foo%20bar", URL_FILE_USE_PATHURL, S_OK, "file://c:\\tests\\foo bar"}, - {"file:///c://tests/foo%20bar", URL_FILE_USE_PATHURL, S_OK, "file://c:\\\\tests\\foo bar"}, - {"file:///c:\\tests\\foo bar", 0, S_OK, "file:///c:/tests/foo bar"}, - {"file:///c:\\tests\\foo bar", URL_DONT_SIMPLIFY, S_OK, "file:///c:/tests/foo bar"}, - {"http://www.winehq.org/site/about", URL_FILE_USE_PATHURL, S_OK, "http://www.winehq.org/site/about"}, - {"file_://www.winehq.org/site/about", URL_FILE_USE_PATHURL, S_OK, "file_://www.winehq.org/site/about"}, - {"c:\\dir\\file", 0, S_OK, "file:///c:/dir/file"}, - {"file:///c:\\dir\\file", 0, S_OK, "file:///c:/dir/file"}, - {"c:dir\\file", 0, S_OK, "file:///c:dir/file"}, - {"c:\\tests\\foo bar", URL_FILE_USE_PATHURL, S_OK, "file://c:\\tests\\foo bar"}, - {"c:\\tests\\foo bar", 0, S_OK, "file:///c:/tests/foo%20bar"}, - {"A", 0, S_OK, "A"}, - {"", 0, S_OK, ""} -}; - -typedef struct _TEST_URL_ESCAPE { - const char *url; - DWORD flags; - DWORD expectescaped; - HRESULT expectret; - const char *expecturl; -} TEST_URL_ESCAPE; - -const TEST_URL_ESCAPE TEST_ESCAPE[] = { - {"http://www.winehq.org/tests0", 0, 0, S_OK, "http://www.winehq.org/tests0"}, - {"http://www.winehq.org/tests1\n", 0, 0, S_OK, "http://www.winehq.org/tests1%0A"}, - {"http://www.winehq.org/tests2\r", 0, 0, S_OK, "http://www.winehq.org/tests2%0D"}, - {"http://www.winehq.org/tests3\r", URL_ESCAPE_SPACES_ONLY|URL_ESCAPE_UNSAFE, 0, S_OK, "http://www.winehq.org/tests3\r"}, - {"http://www.winehq.org/tests4\r", URL_ESCAPE_SPACES_ONLY, 0, S_OK, "http://www.winehq.org/tests4\r"}, - {"http://www.winehq.org/tests5\r", URL_WININET_COMPATIBILITY|URL_ESCAPE_SPACES_ONLY, 0, S_OK, "http://www.winehq.org/tests5\r"}, - {"/direct/swhelp/series6/6.2i_latestservicepack.dat\r", URL_ESCAPE_SPACES_ONLY, 0, S_OK, "/direct/swhelp/series6/6.2i_latestservicepack.dat\r"}, - - {"file://////foo/bar\\baz", 0, 0, S_OK, "file://foo/bar/baz"}, - {"file://///foo/bar\\baz", 0, 0, S_OK, "file://foo/bar/baz"}, - {"file:////foo/bar\\baz", 0, 0, S_OK, "file://foo/bar/baz"}, - {"file:///localhost/foo/bar\\baz", 0, 0, S_OK, "file:///localhost/foo/bar/baz"}, - {"file:///foo/bar\\baz", 0, 0, S_OK, "file:///foo/bar/baz"}, - {"file://loCalHost/foo/bar\\baz", 0, 0, S_OK, "file:///foo/bar/baz"}, - {"file://foo/bar\\baz", 0, 0, S_OK, "file://foo/bar/baz"}, - {"file:/localhost/foo/bar\\baz", 0, 0, S_OK, "file:///localhost/foo/bar/baz"}, - {"file:/foo/bar\\baz", 0, 0, S_OK, "file:///foo/bar/baz"}, - {"file:foo/bar\\baz", 0, 0, S_OK, "file:foo/bar/baz"}, - {"file:\\foo/bar\\baz", 0, 0, S_OK, "file:///foo/bar/baz"}, - {"file:\\\\foo/bar\\baz", 0, 0, S_OK, "file://foo/bar/baz"}, - {"file:\\\\\\foo/bar\\baz", 0, 0, S_OK, "file:///foo/bar/baz"}, - {"file:\\\\localhost\\foo/bar\\baz", 0, 0, S_OK, "file:///foo/bar/baz"}, - {"file:///f oo/b?a r\\baz", 0, 0, S_OK, "file:///f%20oo/b?a r\\baz"}, - {"file:///foo/b#a r\\baz", 0, 0, S_OK, "file:///foo/b%23a%20r/baz"}, - {"file:///f o^&`{}|][\"<>\\%o/b#a r\\baz", 0, 0, S_OK, "file:///f%20o%5E%26%60%7B%7D%7C%5D%5B%22%3C%3E/%o/b%23a%20r/baz"}, - {"file:///f o%o/b?a r\\b%az", URL_ESCAPE_PERCENT, 0, S_OK, "file:///f%20o%25o/b?a r\\b%az"}, - {"file:/foo/bar\\baz", URL_ESCAPE_SEGMENT_ONLY, 0, S_OK, "file:%2Ffoo%2Fbar%5Cbaz"}, - - {"foo/b%ar\\ba?z\\", URL_ESCAPE_SEGMENT_ONLY, 0, S_OK, "foo%2Fb%ar%5Cba%3Fz%5C"}, - {"foo/b%ar\\ba?z\\", URL_ESCAPE_PERCENT | URL_ESCAPE_SEGMENT_ONLY, 0, S_OK, "foo%2Fb%25ar%5Cba%3Fz%5C"}, - {"foo/bar\\ba?z\\", 0, 0, S_OK, "foo/bar%5Cba?z\\"}, - {"/foo/bar\\ba?z\\", 0, 0, S_OK, "/foo/bar%5Cba?z\\"}, - {"/foo/bar\\ba#z\\", 0, 0, S_OK, "/foo/bar%5Cba#z\\"}, - {"/foo/%5C", 0, 0, S_OK, "/foo/%5C"}, - {"/foo/%5C", URL_ESCAPE_PERCENT, 0, S_OK, "/foo/%255C"}, - - {"http://////foo/bar\\baz", 0, 0, S_OK, "http://////foo/bar/baz"}, - {"http://///foo/bar\\baz", 0, 0, S_OK, "http://///foo/bar/baz"}, - {"http:////foo/bar\\baz", 0, 0, S_OK, "http:////foo/bar/baz"}, - {"http:///foo/bar\\baz", 0, 0, S_OK, "http:///foo/bar/baz"}, - {"http://localhost/foo/bar\\baz", 0, 0, S_OK, "http://localhost/foo/bar/baz"}, - {"http://foo/bar\\baz", 0, 0, S_OK, "http://foo/bar/baz"}, - {"http:/foo/bar\\baz", 0, 0, S_OK, "http:/foo/bar/baz"}, - {"http:foo/bar\\ba?z\\", 0, 0, S_OK, "http:foo%2Fbar%2Fba?z\\"}, - {"http:foo/bar\\ba#z\\", 0, 0, S_OK, "http:foo%2Fbar%2Fba#z\\"}, - {"http:\\foo/bar\\baz", 0, 0, S_OK, "http:/foo/bar/baz"}, - {"http:\\\\foo/bar\\baz", 0, 0, S_OK, "http://foo/bar/baz"}, - {"http:\\\\\\foo/bar\\baz", 0, 0, S_OK, "http:///foo/bar/baz"}, - {"http:\\\\\\\\foo/bar\\baz", 0, 0, S_OK, "http:////foo/bar/baz"}, - {"http:/fo ?o/b ar\\baz", 0, 0, S_OK, "http:/fo%20?o/b ar\\baz"}, - {"http:fo ?o/b ar\\baz", 0, 0, S_OK, "http:fo%20?o/b ar\\baz"}, - {"http:/foo/bar\\baz", URL_ESCAPE_SEGMENT_ONLY, 0, S_OK, "http:%2Ffoo%2Fbar%5Cbaz"}, - - {"https://foo/bar\\baz", 0, 0, S_OK, "https://foo/bar/baz"}, - {"https:/foo/bar\\baz", 0, 0, S_OK, "https:/foo/bar/baz"}, - {"https:\\foo/bar\\baz", 0, 0, S_OK, "https:/foo/bar/baz"}, - - {"foo:////foo/bar\\baz", 0, 0, S_OK, "foo:////foo/bar%5Cbaz"}, - {"foo:///foo/bar\\baz", 0, 0, S_OK, "foo:///foo/bar%5Cbaz"}, - {"foo://localhost/foo/bar\\baz", 0, 0, S_OK, "foo://localhost/foo/bar%5Cbaz"}, - {"foo://foo/bar\\baz", 0, 0, S_OK, "foo://foo/bar%5Cbaz"}, - {"foo:/foo/bar\\baz", 0, 0, S_OK, "foo:/foo/bar%5Cbaz"}, - {"foo:foo/bar\\baz", 0, 0, S_OK, "foo:foo%2Fbar%5Cbaz"}, - {"foo:\\foo/bar\\baz", 0, 0, S_OK, "foo:%5Cfoo%2Fbar%5Cbaz"}, - {"foo:/foo/bar\\ba?\\z", 0, 0, S_OK, "foo:/foo/bar%5Cba?\\z"}, - {"foo:/foo/bar\\ba#\\z", 0, 0, S_OK, "foo:/foo/bar%5Cba#\\z"}, - - {"mailto:/fo/o@b\\%a?\\r.b#\\az", 0, 0, S_OK, "mailto:%2Ffo%2Fo@b%5C%a%3F%5Cr.b%23%5Caz"}, - {"mailto:fo/o@b\\%a?\\r.b#\\az", 0, 0, S_OK, "mailto:fo%2Fo@b%5C%a%3F%5Cr.b%23%5Caz"}, - {"mailto:fo/o@b\\%a?\\r.b#\\az", URL_ESCAPE_PERCENT, 0, S_OK, "mailto:fo%2Fo@b%5C%25a%3F%5Cr.b%23%5Caz"}, - - {"ftp:fo/o@bar.baz/foo/bar", 0, 0, S_OK, "ftp:fo%2Fo@bar.baz%2Ffoo%2Fbar"}, - {"ftp:/fo/o@bar.baz/foo/bar", 0, 0, S_OK, "ftp:/fo/o@bar.baz/foo/bar"}, - {"ftp://fo/o@bar.baz/fo?o\\bar", 0, 0, S_OK, "ftp://fo/o@bar.baz/fo?o\\bar"}, - {"ftp://fo/o@bar.baz/fo#o\\bar", 0, 0, S_OK, "ftp://fo/o@bar.baz/fo#o\\bar"}, - {"ftp://localhost/o@bar.baz/fo#o\\bar", 0, 0, S_OK, "ftp://localhost/o@bar.baz/fo#o\\bar"}, - {"ftp:///fo/o@bar.baz/foo/bar", 0, 0, S_OK, "ftp:///fo/o@bar.baz/foo/bar"}, - {"ftp:////fo/o@bar.baz/foo/bar", 0, 0, S_OK, "ftp:////fo/o@bar.baz/foo/bar"} -}; - -typedef struct _TEST_URL_COMBINE { - const char *url1; - const char *url2; - DWORD flags; - HRESULT expectret; - const char *expecturl; -} TEST_URL_COMBINE; - -const TEST_URL_COMBINE TEST_COMBINE[] = { - {"http://www.winehq.org/tests", "tests1", 0, S_OK, "http://www.winehq.org/tests1"}, - {"http://www.%77inehq.org/tests", "tests1", 0, S_OK, "http://www.%77inehq.org/tests1"}, - /*FIXME {"http://www.winehq.org/tests", "../tests2", 0, S_OK, "http://www.winehq.org/tests2"},*/ - {"http://www.winehq.org/tests/", "../tests3", 0, S_OK, "http://www.winehq.org/tests3"}, - {"http://www.winehq.org/tests/test1", "test2", 0, S_OK, "http://www.winehq.org/tests/test2"}, - {"http://www.winehq.org/tests/../tests", "tests4", 0, S_OK, "http://www.winehq.org/tests4"}, - {"http://www.winehq.org/tests/../tests/", "tests5", 0, S_OK, "http://www.winehq.org/tests/tests5"}, - {"http://www.winehq.org/tests/../tests/", "/tests6/..", 0, S_OK, "http://www.winehq.org/"}, - {"http://www.winehq.org/tests/../tests/..", "tests7/..", 0, S_OK, "http://www.winehq.org/"}, - {"http://www.winehq.org/tests/?query=x&return=y", "tests8", 0, S_OK, "http://www.winehq.org/tests/tests8"}, - {"http://www.winehq.org/tests/#example", "tests9", 0, S_OK, "http://www.winehq.org/tests/tests9"}, - {"http://www.winehq.org/tests/../tests/", "/tests10/..", URL_DONT_SIMPLIFY, S_OK, "http://www.winehq.org/tests10/.."}, - {"http://www.winehq.org/tests/../", "tests11", URL_DONT_SIMPLIFY, S_OK, "http://www.winehq.org/tests/../tests11"}, - {"file:///C:\\dir\\file.txt", "test.txt", 0, S_OK, "file:///C:/dir/test.txt"}, - {"http://www.winehq.org/test/", "test%20file.txt", 0, S_OK, "http://www.winehq.org/test/test%20file.txt"}, - {"http://www.winehq.org/test/", "test%20file.txt", URL_FILE_USE_PATHURL, S_OK, "http://www.winehq.org/test/test%20file.txt"}, - {"http://www.winehq.org%2ftest/", "test%20file.txt", URL_FILE_USE_PATHURL, S_OK, "http://www.winehq.org%2ftest/test%20file.txt"}, - {"xxx:@MSITStore:file.chm/file.html", "dir/file", 0, S_OK, "xxx:dir/file"}, - {"mk:@MSITStore:file.chm::/file.html", "/dir/file", 0, S_OK, "mk:@MSITStore:file.chm::/dir/file"}, - {"mk:@MSITStore:file.chm::/file.html", "mk:@MSITStore:file.chm::/dir/file", 0, S_OK, "mk:@MSITStore:file.chm::/dir/file"}, - {"foo:today", "foo:calendar", 0, S_OK, "foo:calendar"}, - {"foo:today", "bar:calendar", 0, S_OK, "bar:calendar"}, - {"foo:/today", "foo:calendar", 0, S_OK, "foo:/calendar"}, - {"foo:/today/", "foo:calendar", 0, S_OK, "foo:/today/calendar"}, -}; - -struct { - const char *path; - const char *url; - DWORD ret; -} TEST_URLFROMPATH [] = { - {"foo", "file:foo", S_OK}, - {"foo\\bar", "file:foo/bar", S_OK}, - {"\\foo\\bar", "file:///foo/bar", S_OK}, - {"c:\\foo\\bar", "file:///c:/foo/bar", S_OK}, - {"c:foo\\bar", "file:///c:foo/bar", S_OK}, - {"c:\\foo/b a%r", "file:///c:/foo/b%20a%25r", S_OK}, - {"c:\\foo\\foo bar", "file:///c:/foo/foo%20bar", S_OK}, -#if 0 - /* The following test fails on native shlwapi as distributed with Win95/98. - * Wine matches the behaviour of later versions. - */ - {"xx:c:\\foo\\bar", "xx:c:\\foo\\bar", S_FALSE} -#endif -}; +/* ################ */ struct { const char *url; @@ -265,16 +69,8 @@ struct { }; -struct { - char url[30]; - const char *expect; -} TEST_URL_UNESCAPE[] = { - {"file://foo/bar", "file://foo/bar"}, - {"file://fo%20o%5Ca/bar", "file://fo o\\a/bar"} -}; - -struct { +static struct { const char *path; BOOL expect; } TEST_PATH_IS_URL[] = { @@ -287,38 +83,6 @@ struct { {"http:partial", TRUE} }; -struct { - const char *url; - BOOL expectOpaque; - BOOL expectFile; -} TEST_URLIS_ATTRIBS[] = { - { "ftp:", FALSE, FALSE }, - { "http:", FALSE, FALSE }, - { "gopher:", FALSE, FALSE }, - { "mailto:", TRUE, FALSE }, - { "news:", FALSE, FALSE }, - { "nntp:", FALSE, FALSE }, - { "telnet:", FALSE, FALSE }, - { "wais:", FALSE, FALSE }, - { "file:", FALSE, TRUE }, - { "mk:", FALSE, FALSE }, - { "https:", FALSE, FALSE }, - { "shell:", TRUE, FALSE }, - { "https:", FALSE, FALSE }, - { "snews:", FALSE, FALSE }, - { "local:", FALSE, FALSE }, - { "javascript:", TRUE, FALSE }, - { "vbscript:", TRUE, FALSE }, - { "about:", TRUE, FALSE }, - { "res:", FALSE, FALSE }, - { "bogusscheme:", FALSE, FALSE }, - { "file:\\\\e:\\b\\c", FALSE, TRUE }, - { "file://e:/b/c", FALSE, TRUE }, - { "http:partial", FALSE, FALSE }, - { "mailto://www.winehq.org/test.html", TRUE, FALSE }, - { "file:partial", FALSE, TRUE } -}; - struct { const char *path; const char *result; @@ -336,6 +100,8 @@ struct { { "\"", "" } }; +/* ################ */ + static LPWSTR GetWideString(const char* szString) { LPWSTR wszString = HeapAlloc(GetProcessHeap(), 0, (2*INTERNET_MAX_URL_LENGTH) * sizeof(WCHAR)); @@ -359,340 +125,7 @@ static LPSTR strdupA(LPCSTR p) return ret; } -static void hash_url(const char* szUrl) -{ - LPCSTR szTestUrl = szUrl; - LPWSTR wszTestUrl = GetWideString(szTestUrl); - - DWORD cbSize = sizeof(DWORD); - DWORD dwHash1, dwHash2; - ok(UrlHashA(szTestUrl, (LPBYTE)&dwHash1, cbSize) == S_OK, "UrlHashA didn't return S_OK\n"); - ok(UrlHashW(wszTestUrl, (LPBYTE)&dwHash2, cbSize) == S_OK, "UrlHashW didn't return S_OK\n"); - - FreeWideString(wszTestUrl); - - ok(dwHash1 == dwHash2, "Hashes didn't compare\n"); -} - -static void test_UrlHash(void) -{ - hash_url(TEST_URL_1); - hash_url(TEST_URL_2); - hash_url(TEST_URL_3); -} - -static void test_url_part(const char* szUrl, DWORD dwPart, DWORD dwFlags, const char* szExpected) -{ - CHAR szPart[INTERNET_MAX_URL_LENGTH]; - WCHAR wszPart[INTERNET_MAX_URL_LENGTH]; - LPWSTR wszUrl = GetWideString(szUrl); - LPWSTR wszConvertedPart; - - DWORD dwSize; - - dwSize = INTERNET_MAX_URL_LENGTH; - ok( UrlGetPartA(szUrl, szPart, &dwSize, dwPart, dwFlags) == S_OK, "UrlGetPartA for \"%s\" part 0x%08x didn't return S_OK but \"%s\"\n", szUrl, dwPart, szPart); - dwSize = INTERNET_MAX_URL_LENGTH; - ok( UrlGetPartW(wszUrl, wszPart, &dwSize, dwPart, dwFlags) == S_OK, "UrlGetPartW didn't return S_OK\n" ); - - wszConvertedPart = GetWideString(szPart); - - ok(lstrcmpW(wszPart,wszConvertedPart)==0, "Strings didn't match between ascii and unicode UrlGetPart!\n"); - - FreeWideString(wszUrl); - FreeWideString(wszConvertedPart); - - /* Note that v6.0 and later don't return '?' with the query */ - ok(strcmp(szPart,szExpected)==0 || - (*szExpected=='?' && !strcmp(szPart,szExpected+1)), - "Expected %s, but got %s\n", szExpected, szPart); -} - -static void test_UrlGetPart(void) -{ - CHAR szPart[INTERNET_MAX_URL_LENGTH]; - DWORD dwSize; - HRESULT res; - - dwSize = sizeof szPart; - szPart[0]='x'; szPart[1]=0; - res = UrlGetPartA("hi", szPart, &dwSize, URL_PART_SCHEME, 0); - todo_wine { - ok (res==S_FALSE, "UrlGetPartA(\"hi\") returned %08X\n", res); - ok(szPart[0]==0, "UrlGetPartA(\"hi\") return \"%s\" instead of \"\"\n", szPart); - } - dwSize = sizeof szPart; - szPart[0]='x'; szPart[1]=0; - res = UrlGetPartA("hi", szPart, &dwSize, URL_PART_QUERY, 0); - todo_wine { - ok (res==S_FALSE, "UrlGetPartA(\"hi\") returned %08X\n", res); - ok(szPart[0]==0, "UrlGetPartA(\"hi\") return \"%s\" instead of \"\"\n", szPart); - } - - test_url_part(TEST_URL_3, URL_PART_HOSTNAME, 0, "localhost"); - test_url_part(TEST_URL_3, URL_PART_PORT, 0, "21"); - test_url_part(TEST_URL_3, URL_PART_USERNAME, 0, "foo"); - test_url_part(TEST_URL_3, URL_PART_PASSWORD, 0, "bar"); - test_url_part(TEST_URL_3, URL_PART_SCHEME, 0, "http"); - test_url_part(TEST_URL_3, URL_PART_QUERY, 0, "?query=x&return=y"); -} - -static void test_url_escape(const char *szUrl, DWORD dwFlags, HRESULT dwExpectReturn, const char *szExpectUrl) -{ - CHAR szReturnUrl[INTERNET_MAX_URL_LENGTH]; - DWORD dwEscaped; - WCHAR ret_urlW[INTERNET_MAX_URL_LENGTH]; - WCHAR *urlW, *expected_urlW; - dwEscaped=INTERNET_MAX_URL_LENGTH; - - ok(UrlEscapeA(szUrl, szReturnUrl, &dwEscaped, dwFlags) == dwExpectReturn, "UrlEscapeA didn't return 0x%08x from \"%s\"\n", dwExpectReturn, szUrl); - ok(strcmp(szReturnUrl,szExpectUrl)==0, "Expected \"%s\", but got \"%s\" from \"%s\"\n", szExpectUrl, szReturnUrl, szUrl); - - dwEscaped = INTERNET_MAX_URL_LENGTH; - urlW = GetWideString(szUrl); - expected_urlW = GetWideString(szExpectUrl); - ok(UrlEscapeW(urlW, ret_urlW, &dwEscaped, dwFlags) == dwExpectReturn, "UrlEscapeW didn't return 0x%08x from \"%s\"\n", dwExpectReturn, szUrl); - WideCharToMultiByte(CP_ACP,0,ret_urlW,-1,szReturnUrl,INTERNET_MAX_URL_LENGTH,0,0); - ok(lstrcmpW(ret_urlW, expected_urlW)==0, "Expected \"%s\", but got \"%s\" from \"%s\" flags %08x\n", szExpectUrl, szReturnUrl, szUrl, dwFlags); - FreeWideString(urlW); - FreeWideString(expected_urlW); - -} - -static void test_url_canonicalize(const char *szUrl, DWORD dwFlags, HRESULT dwExpectReturn, const char *szExpectUrl) -{ - CHAR szReturnUrl[INTERNET_MAX_URL_LENGTH]; - WCHAR wszReturnUrl[INTERNET_MAX_URL_LENGTH]; - LPWSTR wszUrl = GetWideString(szUrl); - LPWSTR wszExpectUrl = GetWideString(szExpectUrl); - LPWSTR wszConvertedUrl; - - DWORD dwSize; - - dwSize = INTERNET_MAX_URL_LENGTH; - ok(UrlCanonicalizeA(szUrl, NULL, &dwSize, dwFlags) != dwExpectReturn, "Unexpected return for NULL buffer\n"); - ok(UrlCanonicalizeA(szUrl, szReturnUrl, &dwSize, dwFlags) == dwExpectReturn, "UrlCanonicalizeA didn't return 0x%08x\n", dwExpectReturn); - ok(strcmp(szReturnUrl,szExpectUrl)==0, "UrlCanonicalizeA dwFlags 0x%08x Expected \"%s\", but got \"%s\"\n", dwFlags, szExpectUrl, szReturnUrl); - - dwSize = INTERNET_MAX_URL_LENGTH; - ok(UrlCanonicalizeW(wszUrl, NULL, &dwSize, dwFlags) != dwExpectReturn, "Unexpected return for NULL buffer\n"); - ok(UrlCanonicalizeW(wszUrl, wszReturnUrl, &dwSize, dwFlags) == dwExpectReturn, "UrlCanonicalizeW didn't return 0x%08x\n", dwExpectReturn); - wszConvertedUrl = GetWideString(szReturnUrl); - ok(lstrcmpW(wszReturnUrl, wszConvertedUrl)==0, "Strings didn't match between ascii and unicode UrlCanonicalize!\n"); - FreeWideString(wszConvertedUrl); - - - FreeWideString(wszUrl); - FreeWideString(wszExpectUrl); -} - - -static void test_UrlEscape(void) -{ - DWORD size; - HRESULT ret; - unsigned int i; - - ret = UrlEscapeA("/woningplan/woonkamer basis.swf", NULL, &size, URL_ESCAPE_SPACES_ONLY); - ok(ret == E_INVALIDARG, "got %x, expected %x\n", ret, E_INVALIDARG); - - for(i=0; i +#include + +#include "wine/test.h" +#include "windef.h" +#include "winbase.h" +#include "winreg.h" +#include "shlwapi.h" +#include "wininet.h" + +/* ################ */ + +const char* TEST_URL_1 = "http://www.winehq.org/tests?date=10/10/1923"; +const char* TEST_URL_2 = "http://localhost:8080/tests%2e.html?date=Mon%2010/10/1923"; +const char* TEST_URL_3 = "http://foo:bar@localhost:21/internal.php?query=x&return=y"; + +/* ################ */ + +typedef struct _TEST_URL_CANONICALIZE { + const char *url; + DWORD flags; + HRESULT expectret; + const char *expecturl; +} TEST_URL_CANONICALIZE; + +const TEST_URL_CANONICALIZE TEST_CANONICALIZE[] = { + /*FIXME {"http://www.winehq.org/tests/../tests/../..", 0, S_OK, "http://www.winehq.org/"},*/ + {"http://www.winehq.org/tests/../tests", 0, S_OK, "http://www.winehq.org/tests"}, + {"http://www.winehq.org/tests\n", URL_WININET_COMPATIBILITY|URL_ESCAPE_SPACES_ONLY|URL_ESCAPE_UNSAFE, S_OK, "http://www.winehq.org/tests"}, + {"http://www.winehq.org/tests\r", URL_WININET_COMPATIBILITY|URL_ESCAPE_SPACES_ONLY|URL_ESCAPE_UNSAFE, S_OK, "http://www.winehq.org/tests"}, + {"http://www.winehq.org/tests\r", 0, S_OK, "http://www.winehq.org/tests"}, + {"http://www.winehq.org/tests\r", URL_DONT_SIMPLIFY, S_OK, "http://www.winehq.org/tests"}, + {"http://www.winehq.org/tests/../tests/", 0, S_OK, "http://www.winehq.org/tests/"}, + {"http://www.winehq.org/tests/../tests/..", 0, S_OK, "http://www.winehq.org/"}, + {"http://www.winehq.org/tests/../tests/../", 0, S_OK, "http://www.winehq.org/"}, + {"http://www.winehq.org/tests/..", 0, S_OK, "http://www.winehq.org/"}, + {"http://www.winehq.org/tests/../", 0, S_OK, "http://www.winehq.org/"}, + {"http://www.winehq.org/tests/..?query=x&return=y", 0, S_OK, "http://www.winehq.org/?query=x&return=y"}, + {"http://www.winehq.org/tests/../?query=x&return=y", 0, S_OK, "http://www.winehq.org/?query=x&return=y"}, + {"http://www.winehq.org/tests/..#example", 0, S_OK, "http://www.winehq.org/#example"}, + {"http://www.winehq.org/tests/../#example", 0, S_OK, "http://www.winehq.org/#example"}, + {"http://www.winehq.org/tests\\../#example", 0, S_OK, "http://www.winehq.org/#example"}, + {"http://www.winehq.org/tests/..\\#example", 0, S_OK, "http://www.winehq.org/#example"}, + {"http://www.winehq.org\\tests/../#example", 0, S_OK, "http://www.winehq.org/#example"}, + {"http://www.winehq.org/tests/../#example", URL_DONT_SIMPLIFY, S_OK, "http://www.winehq.org/tests/../#example"}, + {"http://www.winehq.org/tests/foo bar", URL_ESCAPE_SPACES_ONLY| URL_DONT_ESCAPE_EXTRA_INFO , S_OK, "http://www.winehq.org/tests/foo%20bar"}, + {"http://www.winehq.org/tests/foo%20bar", URL_UNESCAPE , S_OK, "http://www.winehq.org/tests/foo bar"}, + {"file:///c:/tests/foo%20bar", URL_UNESCAPE , S_OK, "file:///c:/tests/foo bar"}, + {"file:///c:/tests\\foo%20bar", URL_UNESCAPE , S_OK, "file:///c:/tests/foo bar"}, + {"file:///c:/tests/foo%20bar", 0, S_OK, "file:///c:/tests/foo%20bar"}, + {"file:///c:/tests/foo%20bar", URL_FILE_USE_PATHURL, S_OK, "file://c:\\tests\\foo bar"}, + {"file://c:/tests/../tests/foo%20bar", URL_FILE_USE_PATHURL, S_OK, "file://c:\\tests\\foo bar"}, + {"file://c:/tests\\../tests/foo%20bar", URL_FILE_USE_PATHURL, S_OK, "file://c:\\tests\\foo bar"}, + {"file://c:/tests/foo%20bar", URL_FILE_USE_PATHURL, S_OK, "file://c:\\tests\\foo bar"}, + {"file:///c://tests/foo%20bar", URL_FILE_USE_PATHURL, S_OK, "file://c:\\\\tests\\foo bar"}, + {"file:///c:\\tests\\foo bar", 0, S_OK, "file:///c:/tests/foo bar"}, + {"file:///c:\\tests\\foo bar", URL_DONT_SIMPLIFY, S_OK, "file:///c:/tests/foo bar"}, + {"http://www.winehq.org/site/about", URL_FILE_USE_PATHURL, S_OK, "http://www.winehq.org/site/about"}, + {"file_://www.winehq.org/site/about", URL_FILE_USE_PATHURL, S_OK, "file_://www.winehq.org/site/about"}, + {"c:\\dir\\file", 0, S_OK, "file:///c:/dir/file"}, + {"file:///c:\\dir\\file", 0, S_OK, "file:///c:/dir/file"}, + {"c:dir\\file", 0, S_OK, "file:///c:dir/file"}, + {"c:\\tests\\foo bar", URL_FILE_USE_PATHURL, S_OK, "file://c:\\tests\\foo bar"}, + {"c:\\tests\\foo bar", 0, S_OK, "file:///c:/tests/foo%20bar"}, + {"A", 0, S_OK, "A"}, + {"", 0, S_OK, ""} +}; + +/* ################ */ + +typedef struct _TEST_URL_ESCAPE { + const char *url; + DWORD flags; + DWORD expectescaped; + HRESULT expectret; + const char *expecturl; +} TEST_URL_ESCAPE; + +const TEST_URL_ESCAPE TEST_ESCAPE[] = { + {"http://www.winehq.org/tests0", 0, 0, S_OK, "http://www.winehq.org/tests0"}, + {"http://www.winehq.org/tests1\n", 0, 0, S_OK, "http://www.winehq.org/tests1%0A"}, + {"http://www.winehq.org/tests2\r", 0, 0, S_OK, "http://www.winehq.org/tests2%0D"}, + {"http://www.winehq.org/tests3\r", URL_ESCAPE_SPACES_ONLY|URL_ESCAPE_UNSAFE, 0, S_OK, "http://www.winehq.org/tests3\r"}, + {"http://www.winehq.org/tests4\r", URL_ESCAPE_SPACES_ONLY, 0, S_OK, "http://www.winehq.org/tests4\r"}, + {"http://www.winehq.org/tests5\r", URL_WININET_COMPATIBILITY|URL_ESCAPE_SPACES_ONLY, 0, S_OK, "http://www.winehq.org/tests5\r"}, + {"/direct/swhelp/series6/6.2i_latestservicepack.dat\r", URL_ESCAPE_SPACES_ONLY, 0, S_OK, "/direct/swhelp/series6/6.2i_latestservicepack.dat\r"}, + + {"file://////foo/bar\\baz", 0, 0, S_OK, "file://foo/bar/baz"}, + {"file://///foo/bar\\baz", 0, 0, S_OK, "file://foo/bar/baz"}, + {"file:////foo/bar\\baz", 0, 0, S_OK, "file://foo/bar/baz"}, + {"file:///localhost/foo/bar\\baz", 0, 0, S_OK, "file:///localhost/foo/bar/baz"}, + {"file:///foo/bar\\baz", 0, 0, S_OK, "file:///foo/bar/baz"}, + {"file://loCalHost/foo/bar\\baz", 0, 0, S_OK, "file:///foo/bar/baz"}, + {"file://foo/bar\\baz", 0, 0, S_OK, "file://foo/bar/baz"}, + {"file:/localhost/foo/bar\\baz", 0, 0, S_OK, "file:///localhost/foo/bar/baz"}, + {"file:/foo/bar\\baz", 0, 0, S_OK, "file:///foo/bar/baz"}, + {"file:foo/bar\\baz", 0, 0, S_OK, "file:foo/bar/baz"}, + {"file:\\foo/bar\\baz", 0, 0, S_OK, "file:///foo/bar/baz"}, + {"file:\\\\foo/bar\\baz", 0, 0, S_OK, "file://foo/bar/baz"}, + {"file:\\\\\\foo/bar\\baz", 0, 0, S_OK, "file:///foo/bar/baz"}, + {"file:\\\\localhost\\foo/bar\\baz", 0, 0, S_OK, "file:///foo/bar/baz"}, + {"file:///f oo/b?a r\\baz", 0, 0, S_OK, "file:///f%20oo/b?a r\\baz"}, + {"file:///foo/b#a r\\baz", 0, 0, S_OK, "file:///foo/b%23a%20r/baz"}, + {"file:///f o^&`{}|][\"<>\\%o/b#a r\\baz", 0, 0, S_OK, "file:///f%20o%5E%26%60%7B%7D%7C%5D%5B%22%3C%3E/%o/b%23a%20r/baz"}, + {"file:///f o%o/b?a r\\b%az", URL_ESCAPE_PERCENT, 0, S_OK, "file:///f%20o%25o/b?a r\\b%az"}, + {"file:/foo/bar\\baz", URL_ESCAPE_SEGMENT_ONLY, 0, S_OK, "file:%2Ffoo%2Fbar%5Cbaz"}, + + {"foo/b%ar\\ba?z\\", URL_ESCAPE_SEGMENT_ONLY, 0, S_OK, "foo%2Fb%ar%5Cba%3Fz%5C"}, + {"foo/b%ar\\ba?z\\", URL_ESCAPE_PERCENT | URL_ESCAPE_SEGMENT_ONLY, 0, S_OK, "foo%2Fb%25ar%5Cba%3Fz%5C"}, + {"foo/bar\\ba?z\\", 0, 0, S_OK, "foo/bar%5Cba?z\\"}, + {"/foo/bar\\ba?z\\", 0, 0, S_OK, "/foo/bar%5Cba?z\\"}, + {"/foo/bar\\ba#z\\", 0, 0, S_OK, "/foo/bar%5Cba#z\\"}, + {"/foo/%5C", 0, 0, S_OK, "/foo/%5C"}, + {"/foo/%5C", URL_ESCAPE_PERCENT, 0, S_OK, "/foo/%255C"}, + + {"http://////foo/bar\\baz", 0, 0, S_OK, "http://////foo/bar/baz"}, + {"http://///foo/bar\\baz", 0, 0, S_OK, "http://///foo/bar/baz"}, + {"http:////foo/bar\\baz", 0, 0, S_OK, "http:////foo/bar/baz"}, + {"http:///foo/bar\\baz", 0, 0, S_OK, "http:///foo/bar/baz"}, + {"http://localhost/foo/bar\\baz", 0, 0, S_OK, "http://localhost/foo/bar/baz"}, + {"http://foo/bar\\baz", 0, 0, S_OK, "http://foo/bar/baz"}, + {"http:/foo/bar\\baz", 0, 0, S_OK, "http:/foo/bar/baz"}, + {"http:foo/bar\\ba?z\\", 0, 0, S_OK, "http:foo%2Fbar%2Fba?z\\"}, + {"http:foo/bar\\ba#z\\", 0, 0, S_OK, "http:foo%2Fbar%2Fba#z\\"}, + {"http:\\foo/bar\\baz", 0, 0, S_OK, "http:/foo/bar/baz"}, + {"http:\\\\foo/bar\\baz", 0, 0, S_OK, "http://foo/bar/baz"}, + {"http:\\\\\\foo/bar\\baz", 0, 0, S_OK, "http:///foo/bar/baz"}, + {"http:\\\\\\\\foo/bar\\baz", 0, 0, S_OK, "http:////foo/bar/baz"}, + {"http:/fo ?o/b ar\\baz", 0, 0, S_OK, "http:/fo%20?o/b ar\\baz"}, + {"http:fo ?o/b ar\\baz", 0, 0, S_OK, "http:fo%20?o/b ar\\baz"}, + {"http:/foo/bar\\baz", URL_ESCAPE_SEGMENT_ONLY, 0, S_OK, "http:%2Ffoo%2Fbar%5Cbaz"}, + + {"https://foo/bar\\baz", 0, 0, S_OK, "https://foo/bar/baz"}, + {"https:/foo/bar\\baz", 0, 0, S_OK, "https:/foo/bar/baz"}, + {"https:\\foo/bar\\baz", 0, 0, S_OK, "https:/foo/bar/baz"}, + + {"foo:////foo/bar\\baz", 0, 0, S_OK, "foo:////foo/bar%5Cbaz"}, + {"foo:///foo/bar\\baz", 0, 0, S_OK, "foo:///foo/bar%5Cbaz"}, + {"foo://localhost/foo/bar\\baz", 0, 0, S_OK, "foo://localhost/foo/bar%5Cbaz"}, + {"foo://foo/bar\\baz", 0, 0, S_OK, "foo://foo/bar%5Cbaz"}, + {"foo:/foo/bar\\baz", 0, 0, S_OK, "foo:/foo/bar%5Cbaz"}, + {"foo:foo/bar\\baz", 0, 0, S_OK, "foo:foo%2Fbar%5Cbaz"}, + {"foo:\\foo/bar\\baz", 0, 0, S_OK, "foo:%5Cfoo%2Fbar%5Cbaz"}, + {"foo:/foo/bar\\ba?\\z", 0, 0, S_OK, "foo:/foo/bar%5Cba?\\z"}, + {"foo:/foo/bar\\ba#\\z", 0, 0, S_OK, "foo:/foo/bar%5Cba#\\z"}, + + {"mailto:/fo/o@b\\%a?\\r.b#\\az", 0, 0, S_OK, "mailto:%2Ffo%2Fo@b%5C%a%3F%5Cr.b%23%5Caz"}, + {"mailto:fo/o@b\\%a?\\r.b#\\az", 0, 0, S_OK, "mailto:fo%2Fo@b%5C%a%3F%5Cr.b%23%5Caz"}, + {"mailto:fo/o@b\\%a?\\r.b#\\az", URL_ESCAPE_PERCENT, 0, S_OK, "mailto:fo%2Fo@b%5C%25a%3F%5Cr.b%23%5Caz"}, + + {"ftp:fo/o@bar.baz/foo/bar", 0, 0, S_OK, "ftp:fo%2Fo@bar.baz%2Ffoo%2Fbar"}, + {"ftp:/fo/o@bar.baz/foo/bar", 0, 0, S_OK, "ftp:/fo/o@bar.baz/foo/bar"}, + {"ftp://fo/o@bar.baz/fo?o\\bar", 0, 0, S_OK, "ftp://fo/o@bar.baz/fo?o\\bar"}, + {"ftp://fo/o@bar.baz/fo#o\\bar", 0, 0, S_OK, "ftp://fo/o@bar.baz/fo#o\\bar"}, + {"ftp://localhost/o@bar.baz/fo#o\\bar", 0, 0, S_OK, "ftp://localhost/o@bar.baz/fo#o\\bar"}, + {"ftp:///fo/o@bar.baz/foo/bar", 0, 0, S_OK, "ftp:///fo/o@bar.baz/foo/bar"}, + {"ftp:////fo/o@bar.baz/foo/bar", 0, 0, S_OK, "ftp:////fo/o@bar.baz/foo/bar"} +}; + +/* ################ */ + +typedef struct _TEST_URL_COMBINE { + const char *url1; + const char *url2; + DWORD flags; + HRESULT expectret; + const char *expecturl; +} TEST_URL_COMBINE; + +const TEST_URL_COMBINE TEST_COMBINE[] = { + {"http://www.winehq.org/tests", "tests1", 0, S_OK, "http://www.winehq.org/tests1"}, + {"http://www.%77inehq.org/tests", "tests1", 0, S_OK, "http://www.%77inehq.org/tests1"}, + /*FIXME {"http://www.winehq.org/tests", "../tests2", 0, S_OK, "http://www.winehq.org/tests2"},*/ + {"http://www.winehq.org/tests/", "../tests3", 0, S_OK, "http://www.winehq.org/tests3"}, + {"http://www.winehq.org/tests/test1", "test2", 0, S_OK, "http://www.winehq.org/tests/test2"}, + {"http://www.winehq.org/tests/../tests", "tests4", 0, S_OK, "http://www.winehq.org/tests4"}, + {"http://www.winehq.org/tests/../tests/", "tests5", 0, S_OK, "http://www.winehq.org/tests/tests5"}, + {"http://www.winehq.org/tests/../tests/", "/tests6/..", 0, S_OK, "http://www.winehq.org/"}, + {"http://www.winehq.org/tests/../tests/..", "tests7/..", 0, S_OK, "http://www.winehq.org/"}, + {"http://www.winehq.org/tests/?query=x&return=y", "tests8", 0, S_OK, "http://www.winehq.org/tests/tests8"}, + {"http://www.winehq.org/tests/#example", "tests9", 0, S_OK, "http://www.winehq.org/tests/tests9"}, + {"http://www.winehq.org/tests/../tests/", "/tests10/..", URL_DONT_SIMPLIFY, S_OK, "http://www.winehq.org/tests10/.."}, + {"http://www.winehq.org/tests/../", "tests11", URL_DONT_SIMPLIFY, S_OK, "http://www.winehq.org/tests/../tests11"}, + {"file:///C:\\dir\\file.txt", "test.txt", 0, S_OK, "file:///C:/dir/test.txt"}, + {"http://www.winehq.org/test/", "test%20file.txt", 0, S_OK, "http://www.winehq.org/test/test%20file.txt"}, + {"http://www.winehq.org/test/", "test%20file.txt", URL_FILE_USE_PATHURL, S_OK, "http://www.winehq.org/test/test%20file.txt"}, + {"http://www.winehq.org%2ftest/", "test%20file.txt", URL_FILE_USE_PATHURL, S_OK, "http://www.winehq.org%2ftest/test%20file.txt"}, + {"xxx:@MSITStore:file.chm/file.html", "dir/file", 0, S_OK, "xxx:dir/file"}, + {"mk:@MSITStore:file.chm::/file.html", "/dir/file", 0, S_OK, "mk:@MSITStore:file.chm::/dir/file"}, + {"mk:@MSITStore:file.chm::/file.html", "mk:@MSITStore:file.chm::/dir/file", 0, S_OK, "mk:@MSITStore:file.chm::/dir/file"}, + {"foo:today", "foo:calendar", 0, S_OK, "foo:calendar"}, + {"foo:today", "bar:calendar", 0, S_OK, "bar:calendar"}, + {"foo:/today", "foo:calendar", 0, S_OK, "foo:/calendar"}, + {"foo:/today/", "foo:calendar", 0, S_OK, "foo:/today/calendar"}, +}; + +/* ################ */ + +struct { + const char *path; + const char *url; + DWORD ret; +} TEST_URLFROMPATH [] = { + {"foo", "file:foo", S_OK}, + {"foo\\bar", "file:foo/bar", S_OK}, + {"\\foo\\bar", "file:///foo/bar", S_OK}, + {"c:\\foo\\bar", "file:///c:/foo/bar", S_OK}, + {"c:foo\\bar", "file:///c:foo/bar", S_OK}, + {"c:\\foo/b a%r", "file:///c:/foo/b%20a%25r", S_OK}, + {"c:\\foo\\foo bar", "file:///c:/foo/foo%20bar", S_OK}, +#if 0 + /* The following test fails on native shlwapi as distributed with Win95/98. + * Wine matches the behaviour of later versions. + */ + {"xx:c:\\foo\\bar", "xx:c:\\foo\\bar", S_FALSE} +#endif +}; + +/* ################ */ + +struct { + char url[30]; + const char *expect; +} TEST_URL_UNESCAPE[] = { + {"file://foo/bar", "file://foo/bar"}, + {"file://fo%20o%5Ca/bar", "file://fo o\\a/bar"} +}; + +/* ################ */ + +static struct { + const char *path; + BOOL expect; +} TEST_PATH_IS_URL[] = { + {"http://foo/bar", TRUE}, + {"c:\\foo\\bar", FALSE}, + {"foo://foo/bar", TRUE}, + {"foo\\bar", FALSE}, + {"foo.bar", FALSE}, + {"bogusscheme:", TRUE}, + {"http:partial", TRUE} +}; + +/* ################ */ + +struct { + const char *url; + BOOL expectOpaque; + BOOL expectFile; +} TEST_URLIS_ATTRIBS[] = { + { "ftp:", FALSE, FALSE }, + { "http:", FALSE, FALSE }, + { "gopher:", FALSE, FALSE }, + { "mailto:", TRUE, FALSE }, + { "news:", FALSE, FALSE }, + { "nntp:", FALSE, FALSE }, + { "telnet:", FALSE, FALSE }, + { "wais:", FALSE, FALSE }, + { "file:", FALSE, TRUE }, + { "mk:", FALSE, FALSE }, + { "https:", FALSE, FALSE }, + { "shell:", TRUE, FALSE }, + { "https:", FALSE, FALSE }, + { "snews:", FALSE, FALSE }, + { "local:", FALSE, FALSE }, + { "javascript:", TRUE, FALSE }, + { "vbscript:", TRUE, FALSE }, + { "about:", TRUE, FALSE }, + { "res:", FALSE, FALSE }, + { "bogusscheme:", FALSE, FALSE }, + { "file:\\\\e:\\b\\c", FALSE, TRUE }, + { "file://e:/b/c", FALSE, TRUE }, + { "http:partial", FALSE, FALSE }, + { "mailto://www.winehq.org/test.html", TRUE, FALSE }, + { "file:partial", FALSE, TRUE } +}; + +/* ########################### */ + +static LPWSTR GetWideString(const char* szString) +{ + LPWSTR wszString = HeapAlloc(GetProcessHeap(), 0, (2*INTERNET_MAX_URL_LENGTH) * sizeof(WCHAR)); + + MultiByteToWideChar(0, 0, szString, -1, wszString, INTERNET_MAX_URL_LENGTH); + + return wszString; +} + + +static void FreeWideString(LPWSTR wszString) +{ + HeapFree(GetProcessHeap(), 0, wszString); +} + +/* ########################### */ + +static void hash_url(const char* szUrl) +{ + LPCSTR szTestUrl = szUrl; + LPWSTR wszTestUrl = GetWideString(szTestUrl); + + DWORD cbSize = sizeof(DWORD); + DWORD dwHash1, dwHash2; + ok(UrlHashA(szTestUrl, (LPBYTE)&dwHash1, cbSize) == S_OK, "UrlHashA didn't return S_OK\n"); + ok(UrlHashW(wszTestUrl, (LPBYTE)&dwHash2, cbSize) == S_OK, "UrlHashW didn't return S_OK\n"); + + FreeWideString(wszTestUrl); + + ok(dwHash1 == dwHash2, "Hashes didn't compare\n"); +} + +static void test_UrlHash(void) +{ + hash_url(TEST_URL_1); + hash_url(TEST_URL_2); + hash_url(TEST_URL_3); +} + +/* ########################### */ + +static void test_url_part(const char* szUrl, DWORD dwPart, DWORD dwFlags, const char* szExpected) +{ + CHAR szPart[INTERNET_MAX_URL_LENGTH]; + WCHAR wszPart[INTERNET_MAX_URL_LENGTH]; + LPWSTR wszUrl = GetWideString(szUrl); + LPWSTR wszConvertedPart; + + DWORD dwSize; + + dwSize = INTERNET_MAX_URL_LENGTH; + ok( UrlGetPartA(szUrl, szPart, &dwSize, dwPart, dwFlags) == S_OK, "UrlGetPartA for \"%s\" part 0x%08x didn't return S_OK but \"%s\"\n", szUrl, dwPart, szPart); + dwSize = INTERNET_MAX_URL_LENGTH; + ok( UrlGetPartW(wszUrl, wszPart, &dwSize, dwPart, dwFlags) == S_OK, "UrlGetPartW didn't return S_OK\n" ); + + wszConvertedPart = GetWideString(szPart); + + ok(lstrcmpW(wszPart,wszConvertedPart)==0, "Strings didn't match between ascii and unicode UrlGetPart!\n"); + + FreeWideString(wszUrl); + FreeWideString(wszConvertedPart); + + /* Note that v6.0 and later don't return '?' with the query */ + ok(strcmp(szPart,szExpected)==0 || + (*szExpected=='?' && !strcmp(szPart,szExpected+1)), + "Expected %s, but got %s\n", szExpected, szPart); +} + +/* ########################### */ + +static void test_UrlGetPart(void) +{ + CHAR szPart[INTERNET_MAX_URL_LENGTH]; + DWORD dwSize; + HRESULT res; + + dwSize = sizeof szPart; + szPart[0]='x'; szPart[1]=0; + res = UrlGetPartA("hi", szPart, &dwSize, URL_PART_SCHEME, 0); + todo_wine { + ok (res==S_FALSE, "UrlGetPartA(\"hi\") returned %08X\n", res); + ok(szPart[0]==0, "UrlGetPartA(\"hi\") return \"%s\" instead of \"\"\n", szPart); + } + dwSize = sizeof szPart; + szPart[0]='x'; szPart[1]=0; + res = UrlGetPartA("hi", szPart, &dwSize, URL_PART_QUERY, 0); + todo_wine { + ok (res==S_FALSE, "UrlGetPartA(\"hi\") returned %08X\n", res); + ok(szPart[0]==0, "UrlGetPartA(\"hi\") return \"%s\" instead of \"\"\n", szPart); + } + + test_url_part(TEST_URL_3, URL_PART_HOSTNAME, 0, "localhost"); + test_url_part(TEST_URL_3, URL_PART_PORT, 0, "21"); + test_url_part(TEST_URL_3, URL_PART_USERNAME, 0, "foo"); + test_url_part(TEST_URL_3, URL_PART_PASSWORD, 0, "bar"); + test_url_part(TEST_URL_3, URL_PART_SCHEME, 0, "http"); + test_url_part(TEST_URL_3, URL_PART_QUERY, 0, "?query=x&return=y"); +} + +/* ########################### */ + +static void test_url_escape(const char *szUrl, DWORD dwFlags, HRESULT dwExpectReturn, const char *szExpectUrl) +{ + CHAR szReturnUrl[INTERNET_MAX_URL_LENGTH]; + DWORD dwEscaped; + WCHAR ret_urlW[INTERNET_MAX_URL_LENGTH]; + WCHAR *urlW, *expected_urlW; + dwEscaped=INTERNET_MAX_URL_LENGTH; + + ok(UrlEscapeA(szUrl, szReturnUrl, &dwEscaped, dwFlags) == dwExpectReturn, "UrlEscapeA didn't return 0x%08x from \"%s\"\n", dwExpectReturn, szUrl); + ok(strcmp(szReturnUrl,szExpectUrl)==0, "Expected \"%s\", but got \"%s\" from \"%s\"\n", szExpectUrl, szReturnUrl, szUrl); + + dwEscaped = INTERNET_MAX_URL_LENGTH; + urlW = GetWideString(szUrl); + expected_urlW = GetWideString(szExpectUrl); + ok(UrlEscapeW(urlW, ret_urlW, &dwEscaped, dwFlags) == dwExpectReturn, "UrlEscapeW didn't return 0x%08x from \"%s\"\n", dwExpectReturn, szUrl); + WideCharToMultiByte(CP_ACP,0,ret_urlW,-1,szReturnUrl,INTERNET_MAX_URL_LENGTH,0,0); + ok(lstrcmpW(ret_urlW, expected_urlW)==0, "Expected \"%s\", but got \"%s\" from \"%s\" flags %08x\n", szExpectUrl, szReturnUrl, szUrl, dwFlags); + FreeWideString(urlW); + FreeWideString(expected_urlW); + +} + +static void test_url_canonicalize(const char *szUrl, DWORD dwFlags, HRESULT dwExpectReturn, const char *szExpectUrl) +{ + CHAR szReturnUrl[INTERNET_MAX_URL_LENGTH]; + WCHAR wszReturnUrl[INTERNET_MAX_URL_LENGTH]; + LPWSTR wszUrl = GetWideString(szUrl); + LPWSTR wszExpectUrl = GetWideString(szExpectUrl); + LPWSTR wszConvertedUrl; + + DWORD dwSize; + + dwSize = INTERNET_MAX_URL_LENGTH; + ok(UrlCanonicalizeA(szUrl, NULL, &dwSize, dwFlags) != dwExpectReturn, "Unexpected return for NULL buffer\n"); + ok(UrlCanonicalizeA(szUrl, szReturnUrl, &dwSize, dwFlags) == dwExpectReturn, "UrlCanonicalizeA didn't return 0x%08x\n", dwExpectReturn); + ok(strcmp(szReturnUrl,szExpectUrl)==0, "UrlCanonicalizeA dwFlags 0x%08x Expected \"%s\", but got \"%s\"\n", dwFlags, szExpectUrl, szReturnUrl); + + dwSize = INTERNET_MAX_URL_LENGTH; + ok(UrlCanonicalizeW(wszUrl, NULL, &dwSize, dwFlags) != dwExpectReturn, "Unexpected return for NULL buffer\n"); + ok(UrlCanonicalizeW(wszUrl, wszReturnUrl, &dwSize, dwFlags) == dwExpectReturn, "UrlCanonicalizeW didn't return 0x%08x\n", dwExpectReturn); + wszConvertedUrl = GetWideString(szReturnUrl); + ok(lstrcmpW(wszReturnUrl, wszConvertedUrl)==0, "Strings didn't match between ascii and unicode UrlCanonicalize!\n"); + FreeWideString(wszConvertedUrl); + + + FreeWideString(wszUrl); + FreeWideString(wszExpectUrl); +} + + +static void test_UrlEscape(void) +{ + DWORD size; + HRESULT ret; + unsigned int i; + + ret = UrlEscapeA("/woningplan/woonkamer basis.swf", NULL, &size, URL_ESCAPE_SPACES_ONLY); + ok(ret == E_INVALIDARG, "got %x, expected %x\n", ret, E_INVALIDARG); + + for(i=0; i