From 4caf4bf8770cd9e6e649fe62a6d134f0cdfab787 Mon Sep 17 00:00:00 2001 From: Matthew Mastracci Date: Thu, 9 Jan 2003 00:50:17 +0000 Subject: [PATCH] Add implementation for PathCreateFromUrlW and add the start for some URL unit tests. --- dlls/shlwapi/path.c | 33 +++++++++- dlls/shlwapi/tests/.cvsignore | 1 + dlls/shlwapi/tests/Makefile.in | 1 + dlls/shlwapi/tests/path.c | 109 +++++++++++++++++++++++++++++++++ 4 files changed, 142 insertions(+), 2 deletions(-) create mode 100644 dlls/shlwapi/tests/path.c diff --git a/dlls/shlwapi/path.c b/dlls/shlwapi/path.c index 62971ee2b7a..6f607a1eaff 100644 --- a/dlls/shlwapi/path.c +++ b/dlls/shlwapi/path.c @@ -3154,12 +3154,41 @@ HRESULT WINAPI PathCreateFromUrlA(LPCSTR lpszUrl, LPSTR lpszPath, HRESULT WINAPI PathCreateFromUrlW(LPCWSTR lpszUrl, LPWSTR lpszPath, LPDWORD pcchPath, DWORD dwFlags) { - FIXME("(%s,%p,%p,0x%08lx)-stub\n", debugstr_w(lpszUrl), lpszPath, pcchPath, dwFlags); + static const WCHAR stemp[] = { 'f','i','l','e',':','/','/',0 }; + LPWSTR pwszPathPart; + HRESULT hr; + + TRACE("(%s,%p,%p,0x%08lx)\n", debugstr_w(lpszUrl), lpszPath, pcchPath, dwFlags); if (!lpszUrl || !lpszPath || !pcchPath || !*pcchPath) return E_INVALIDARG; - return S_OK; + /* Path of the form file://... */ + if (!strncmpW(lpszUrl, stemp, 7)) + { + lpszUrl += 7; + } + /* Path of the form file:... */ + else if (!strncmpW(lpszUrl, stemp, 5)) + { + lpszUrl += 5; + } + + /* Ensure that path is of the form c:... or c|... */ + if (lpszUrl[1] != ':' && lpszUrl[1] != '|' && isalphaW(*lpszUrl)) + return E_INVALIDARG; + + hr = UrlUnescapeW(lpszUrl, lpszPath, pcchPath, dwFlags); + if (lpszPath[1] == '|') + lpszPath[1] = ':'; + + for (pwszPathPart = lpszPath; *pwszPathPart; pwszPathPart++) + if (*pwszPathPart == '/') + *pwszPathPart = '\\'; + + TRACE("Returning %s\n",debugstr_w(lpszPath)); + + return hr; } /************************************************************************* diff --git a/dlls/shlwapi/tests/.cvsignore b/dlls/shlwapi/tests/.cvsignore index b313cbeba96..2e61eaebc30 100644 --- a/dlls/shlwapi/tests/.cvsignore +++ b/dlls/shlwapi/tests/.cvsignore @@ -1,6 +1,7 @@ Makefile clist.ok generated.ok +path.ok shlwapi_test.exe.spec.c shreg.ok testlist.c diff --git a/dlls/shlwapi/tests/Makefile.in b/dlls/shlwapi/tests/Makefile.in index 6888b0ec7bb..9c08581d91d 100644 --- a/dlls/shlwapi/tests/Makefile.in +++ b/dlls/shlwapi/tests/Makefile.in @@ -8,6 +8,7 @@ IMPORTS = shlwapi advapi32 CTESTS = \ clist.c \ generated.c \ + path.c \ shreg.c @MAKE_TEST_RULES@ diff --git a/dlls/shlwapi/tests/path.c b/dlls/shlwapi/tests/path.c new file mode 100644 index 00000000000..efc252f7857 --- /dev/null +++ b/dlls/shlwapi/tests/path.c @@ -0,0 +1,109 @@ +/* Unit test suite for Path functions + * + * Copyright 2002 Matthew Mastracci + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include +#include +#include + +#include "wine/test.h" +#include "wine/unicode.h" +#include "winbase.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"; + +static LPWSTR GetWideString(const char* szString) +{ + LPWSTR wszString = (LPWSTR) 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"); + ok(UrlHashW(wszTestUrl, (LPBYTE)&dwHash2, cbSize) == S_OK, "UrlHashW didn't return S_OK"); + + FreeWideString(wszTestUrl); + + ok(dwHash1 == dwHash2, "Hashes didn't compare"); +} + +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, 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 didn't return S_OK" ); + dwSize = INTERNET_MAX_URL_LENGTH; + ok( UrlGetPartW(wszUrl, wszPart, &dwSize, dwPart, dwFlags) == S_OK, "UrlGetPartW didn't return S_OK" ); + + wszConvertedPart = GetWideString(szPart); + + ok(strcmpW(wszPart,wszConvertedPart)==0, "Strings didn't match between ascii and unicode UrlGetPart!"); + + FreeWideString(wszUrl); + FreeWideString(wszConvertedPart); + + ok(strcmp(szPart,szExpected)==0, "Expected %s, but got %s", szExpected, szPart); +} + +static void test_UrlGetPart(void) +{ + 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"); +} + +START_TEST(path) +{ + test_UrlHash(); + test_UrlGetPart(); +}