Added version information.
[wine] / dlls / shlwapi / tests / path.c
1 /* Unit test suite for Path functions
2  *
3  * Copyright 2002 Matthew Mastracci
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18  */
19
20 #include <assert.h>
21 #include <stdlib.h>
22 #include <stdio.h>
23
24 #include "wine/test.h"
25 #include "winbase.h"
26 #include "wine/unicode.h"
27 #include "winreg.h"
28 #include "shlwapi.h"
29 #include "wininet.h"
30
31 const char* TEST_URL_1 = "http://www.winehq.org/tests?date=10/10/1923";
32 const char* TEST_URL_2 = "http://localhost:8080/tests%2e.html?date=Mon%2010/10/1923";
33 const char* TEST_URL_3 = "http://foo:bar@localhost:21/internal.php?query=x&return=y";
34
35 static LPWSTR GetWideString(const char* szString)
36 {
37   LPWSTR wszString = (LPWSTR) HeapAlloc(GetProcessHeap(), 0,
38                                          (2*INTERNET_MAX_URL_LENGTH) * sizeof(WCHAR));
39   
40   MultiByteToWideChar(0, 0, szString, -1, wszString, INTERNET_MAX_URL_LENGTH);
41
42   return wszString;
43 }
44
45 static void FreeWideString(LPWSTR wszString)
46 {
47    HeapFree(GetProcessHeap(), 0, wszString);
48 }
49
50 static void hash_url(const char* szUrl)
51 {
52   LPCSTR szTestUrl = szUrl;
53   LPWSTR wszTestUrl = GetWideString(szTestUrl);
54   
55   DWORD cbSize = sizeof(DWORD);
56   DWORD dwHash1, dwHash2;
57   ok(UrlHashA(szTestUrl, (LPBYTE)&dwHash1, cbSize) == S_OK, "UrlHashA didn't return S_OK");
58   ok(UrlHashW(wszTestUrl, (LPBYTE)&dwHash2, cbSize) == S_OK, "UrlHashW didn't return S_OK");
59
60   FreeWideString(wszTestUrl);
61
62   ok(dwHash1 == dwHash2, "Hashes didn't compare");
63 }
64
65 static void test_UrlHash(void)
66 {
67   hash_url(TEST_URL_1);
68   hash_url(TEST_URL_2);
69   hash_url(TEST_URL_3);
70 }
71
72 static void test_url_part(const char* szUrl, DWORD dwPart, DWORD dwFlags, char* szExpected)
73 {
74   CHAR szPart[INTERNET_MAX_URL_LENGTH];
75   WCHAR wszPart[INTERNET_MAX_URL_LENGTH];
76   LPWSTR wszUrl = GetWideString(szUrl);
77   LPWSTR wszConvertedPart;
78
79   DWORD dwSize;
80
81   dwSize = INTERNET_MAX_URL_LENGTH;
82   ok( UrlGetPartA(szUrl, szPart, &dwSize, dwPart, dwFlags) == S_OK, "UrlGetPartA didn't return S_OK" );
83   dwSize = INTERNET_MAX_URL_LENGTH;
84   ok( UrlGetPartW(wszUrl, wszPart, &dwSize, dwPart, dwFlags) == S_OK, "UrlGetPartW didn't return S_OK" );
85
86   wszConvertedPart = GetWideString(szPart);
87
88   ok(strcmpW(wszPart,wszConvertedPart)==0, "Strings didn't match between ascii and unicode UrlGetPart!");
89
90   FreeWideString(wszUrl);
91   FreeWideString(wszConvertedPart);
92
93   ok(strcmp(szPart,szExpected)==0, "Expected %s, but got %s", szExpected, szPart);
94 }
95
96 static void test_UrlGetPart(void)
97 {
98   test_url_part(TEST_URL_3, URL_PART_HOSTNAME, 0, "localhost");
99   test_url_part(TEST_URL_3, URL_PART_PORT, 0, "21");
100   test_url_part(TEST_URL_3, URL_PART_USERNAME, 0, "foo");
101   test_url_part(TEST_URL_3, URL_PART_PASSWORD, 0, "bar");
102   test_url_part(TEST_URL_3, URL_PART_SCHEME, 0, "http");
103   test_url_part(TEST_URL_3, URL_PART_QUERY, 0, "?query=x&return=y");
104 }
105
106 START_TEST(path)
107 {
108   test_UrlHash();
109   test_UrlGetPart();
110 }