Fixed warnings with gcc option "-Wwrite-strings".
[wine/multimedia.git] / dlls / shlwapi / tests / path.c
blob33082e95fb0c3123797637833c94811c6c1122f5
1 /* Unit test suite for Path functions
3 * Copyright 2002 Matthew Mastracci
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.
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.
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
20 #include <assert.h>
21 #include <stdlib.h>
22 #include <stdarg.h>
23 #include <stdio.h>
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"
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";
37 static LPWSTR GetWideString(const char* szString)
39 LPWSTR wszString = (LPWSTR) HeapAlloc(GetProcessHeap(), 0,
40 (2*INTERNET_MAX_URL_LENGTH) * sizeof(WCHAR));
42 MultiByteToWideChar(0, 0, szString, -1, wszString, INTERNET_MAX_URL_LENGTH);
44 return wszString;
47 static void FreeWideString(LPWSTR wszString)
49 HeapFree(GetProcessHeap(), 0, wszString);
52 static void hash_url(const char* szUrl)
54 LPCSTR szTestUrl = szUrl;
55 LPWSTR wszTestUrl = GetWideString(szTestUrl);
57 DWORD cbSize = sizeof(DWORD);
58 DWORD dwHash1, dwHash2;
59 ok(UrlHashA(szTestUrl, (LPBYTE)&dwHash1, cbSize) == S_OK, "UrlHashA didn't return S_OK");
60 ok(UrlHashW(wszTestUrl, (LPBYTE)&dwHash2, cbSize) == S_OK, "UrlHashW didn't return S_OK");
62 FreeWideString(wszTestUrl);
64 ok(dwHash1 == dwHash2, "Hashes didn't compare");
67 static void test_UrlHash(void)
69 hash_url(TEST_URL_1);
70 hash_url(TEST_URL_2);
71 hash_url(TEST_URL_3);
74 static void test_url_part(const char* szUrl, DWORD dwPart, DWORD dwFlags, const char* szExpected)
76 CHAR szPart[INTERNET_MAX_URL_LENGTH];
77 WCHAR wszPart[INTERNET_MAX_URL_LENGTH];
78 LPWSTR wszUrl = GetWideString(szUrl);
79 LPWSTR wszConvertedPart;
81 DWORD dwSize;
83 dwSize = INTERNET_MAX_URL_LENGTH;
84 ok( UrlGetPartA(szUrl, szPart, &dwSize, dwPart, dwFlags) == S_OK, "UrlGetPartA didn't return S_OK" );
85 dwSize = INTERNET_MAX_URL_LENGTH;
86 ok( UrlGetPartW(wszUrl, wszPart, &dwSize, dwPart, dwFlags) == S_OK, "UrlGetPartW didn't return S_OK" );
88 wszConvertedPart = GetWideString(szPart);
90 ok(strcmpW(wszPart,wszConvertedPart)==0, "Strings didn't match between ascii and unicode UrlGetPart!");
92 FreeWideString(wszUrl);
93 FreeWideString(wszConvertedPart);
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", szExpected, szPart);
101 static void test_UrlGetPart(void)
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");
111 START_TEST(path)
113 test_UrlHash();
114 test_UrlGetPart();