Add trailing '\n's to ok() calls.
[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 <stdarg.h>
23 #include <stdio.h>
24
25 #include "wine/test.h"
26 #include "windef.h"
27 #include "winbase.h"
28 #include "wine/unicode.h"
29 #include "winreg.h"
30 #include "shlwapi.h"
31 #include "wininet.h"
32
33 const char* TEST_URL_1 = "http://www.winehq.org/tests?date=10/10/1923";
34 const char* TEST_URL_2 = "http://localhost:8080/tests%2e.html?date=Mon%2010/10/1923";
35 const char* TEST_URL_3 = "http://foo:bar@localhost:21/internal.php?query=x&return=y";
36
37 static LPWSTR GetWideString(const char* szString)
38 {
39   LPWSTR wszString = (LPWSTR) HeapAlloc(GetProcessHeap(), 0,
40                                          (2*INTERNET_MAX_URL_LENGTH) * sizeof(WCHAR));
41   
42   MultiByteToWideChar(0, 0, szString, -1, wszString, INTERNET_MAX_URL_LENGTH);
43
44   return wszString;
45 }
46
47 static void FreeWideString(LPWSTR wszString)
48 {
49    HeapFree(GetProcessHeap(), 0, wszString);
50 }
51
52 static void hash_url(const char* szUrl)
53 {
54   LPCSTR szTestUrl = szUrl;
55   LPWSTR wszTestUrl = GetWideString(szTestUrl);
56   
57   DWORD cbSize = sizeof(DWORD);
58   DWORD dwHash1, dwHash2;
59   ok(UrlHashA(szTestUrl, (LPBYTE)&dwHash1, cbSize) == S_OK, "UrlHashA didn't return S_OK\n");
60   ok(UrlHashW(wszTestUrl, (LPBYTE)&dwHash2, cbSize) == S_OK, "UrlHashW didn't return S_OK\n");
61
62   FreeWideString(wszTestUrl);
63
64   ok(dwHash1 == dwHash2, "Hashes didn't compare\n");
65 }
66
67 static void test_UrlHash(void)
68 {
69   hash_url(TEST_URL_1);
70   hash_url(TEST_URL_2);
71   hash_url(TEST_URL_3);
72 }
73
74 static void test_url_part(const char* szUrl, DWORD dwPart, DWORD dwFlags, const char* szExpected)
75 {
76   CHAR szPart[INTERNET_MAX_URL_LENGTH];
77   WCHAR wszPart[INTERNET_MAX_URL_LENGTH];
78   LPWSTR wszUrl = GetWideString(szUrl);
79   LPWSTR wszConvertedPart;
80
81   DWORD dwSize;
82
83   dwSize = INTERNET_MAX_URL_LENGTH;
84   ok( UrlGetPartA(szUrl, szPart, &dwSize, dwPart, dwFlags) == S_OK, "UrlGetPartA didn't return S_OK\n" );
85   dwSize = INTERNET_MAX_URL_LENGTH;
86   ok( UrlGetPartW(wszUrl, wszPart, &dwSize, dwPart, dwFlags) == S_OK, "UrlGetPartW didn't return S_OK\n" );
87
88   wszConvertedPart = GetWideString(szPart);
89
90   ok(strcmpW(wszPart,wszConvertedPart)==0, "Strings didn't match between ascii and unicode UrlGetPart!\n");
91
92   FreeWideString(wszUrl);
93   FreeWideString(wszConvertedPart);
94
95   /* Note that v6.0 and later don't return '?' with the query */
96   ok(strcmp(szPart,szExpected)==0 ||
97      (*szExpected=='?' && !strcmp(szPart,szExpected+1)),
98          "Expected %s, but got %s\n", szExpected, szPart);
99 }
100
101 static void test_UrlGetPart(void)
102 {
103   test_url_part(TEST_URL_3, URL_PART_HOSTNAME, 0, "localhost");
104   test_url_part(TEST_URL_3, URL_PART_PORT, 0, "21");
105   test_url_part(TEST_URL_3, URL_PART_USERNAME, 0, "foo");
106   test_url_part(TEST_URL_3, URL_PART_PASSWORD, 0, "bar");
107   test_url_part(TEST_URL_3, URL_PART_SCHEME, 0, "http");
108   test_url_part(TEST_URL_3, URL_PART_QUERY, 0, "?query=x&return=y");
109 }
110
111 START_TEST(path)
112 {
113   test_UrlHash();
114   test_UrlGetPart();
115 }