From 3d5205ef5f9d039ec56d8d4053fdb9d6b0be544f Mon Sep 17 00:00:00 2001 From: Kevin Koltzau Date: Mon, 3 May 2004 20:07:03 +0000 Subject: [PATCH] Handle context in CreateURLMoniker. --- dlls/urlmon/Makefile.in | 2 +- dlls/urlmon/tests/.cvsignore | 1 + dlls/urlmon/tests/Makefile.in | 3 +- dlls/urlmon/tests/url.c | 55 +++++++++++++++++++++++++++++++++++ dlls/urlmon/umon.c | 49 ++++++++++++++++++++++++------- 5 files changed, 98 insertions(+), 12 deletions(-) create mode 100644 dlls/urlmon/tests/url.c diff --git a/dlls/urlmon/Makefile.in b/dlls/urlmon/Makefile.in index 8765ae6bcfc..45ee964031f 100644 --- a/dlls/urlmon/Makefile.in +++ b/dlls/urlmon/Makefile.in @@ -3,7 +3,7 @@ TOPOBJDIR = ../.. SRCDIR = @srcdir@ VPATH = @srcdir@ MODULE = urlmon.dll -IMPORTS = cabinet ole32 wininet user32 advapi32 kernel32 ntdll +IMPORTS = cabinet ole32 shlwapi wininet user32 advapi32 kernel32 ntdll EXTRALIBS = -luuid C_SRCS = \ diff --git a/dlls/urlmon/tests/.cvsignore b/dlls/urlmon/tests/.cvsignore index 1b546053253..b15b9e4c149 100644 --- a/dlls/urlmon/tests/.cvsignore +++ b/dlls/urlmon/tests/.cvsignore @@ -1,3 +1,4 @@ Makefile generated.ok testlist.c +url.ok diff --git a/dlls/urlmon/tests/Makefile.in b/dlls/urlmon/tests/Makefile.in index 7dd65a373c1..03ab73a5480 100644 --- a/dlls/urlmon/tests/Makefile.in +++ b/dlls/urlmon/tests/Makefile.in @@ -6,7 +6,8 @@ TESTDLL = urlmon.dll IMPORTS = urlmon CTESTS = \ - generated.c + generated.c \ + url.c @MAKE_TEST_RULES@ diff --git a/dlls/urlmon/tests/url.c b/dlls/urlmon/tests/url.c new file mode 100644 index 00000000000..d9caaab828e --- /dev/null +++ b/dlls/urlmon/tests/url.c @@ -0,0 +1,55 @@ +/* + * UrlMon URL tests + * + * Copyright 2004 Kevin Koltzau + * + * 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 "windef.h" +#include "winbase.h" +#include "urlmon.h" + +#include "wine/test.h" + +const WCHAR TEST_URL_1[] = {'h','t','t','p',':','/','/','w','w','w','.','w','i','n','e','h','q','.','o','r','g','/','\0'}; +const WCHAR TEST_PART_URL_1[] = {'/','t','e','s','t','/','\0'}; + +static void test_CreateURLMoniker(LPCWSTR url1, LPCWSTR url2) +{ + HRESULT hr; + IMoniker *mon1 = NULL; + IMoniker *mon2 = NULL; + + hr = CreateURLMoniker(NULL, url1, &mon1); + ok(SUCCEEDED(hr), "failed to create moniker: 0x%08lx\n", hr); + if(SUCCEEDED(hr)) { + hr = CreateURLMoniker(mon1, url2, &mon2); + ok(SUCCEEDED(hr), "failed to create moniker: 0x%08lx\n", hr); + } + if(mon1) IMoniker_Release(mon1); + if(mon2) IMoniker_Release(mon2); +} + +static void test_create() +{ + test_CreateURLMoniker(TEST_URL_1, TEST_PART_URL_1); +} + +START_TEST(url) +{ + test_create(); +} diff --git a/dlls/urlmon/umon.c b/dlls/urlmon/umon.c index 1a5821d57cb..7556312d541 100644 --- a/dlls/urlmon/umon.c +++ b/dlls/urlmon/umon.c @@ -36,6 +36,7 @@ #include "ole2.h" #include "urlmon.h" #include "wininet.h" +#include "shlwapi.h" #include "urlmon_main.h" WINE_DEFAULT_DEBUG_CHANNEL(urlmon); @@ -106,7 +107,7 @@ static HRESULT WINAPI URLMonikerImpl_IBinding_GetPriority(IBinding* iface, LONG* static HRESULT WINAPI URLMonikerImpl_IBinding_GetBindResult(IBinding* iface, CLSID* pclsidProtocol, DWORD* pdwResult, LPOLESTR* pszResult, DWORD* pdwReserved); /* Local function used by urlmoniker implementation */ -static HRESULT URLMonikerImpl_Construct(URLMonikerImpl* iface, LPCOLESTR lpszURL); +static HRESULT URLMonikerImpl_Construct(URLMonikerImpl* iface, LPCOLESTR lpszLeftURL, LPCOLESTR lpszURL); static HRESULT URLMonikerImpl_Destroy(URLMonikerImpl* iface); /********************************************************************************/ @@ -337,11 +338,12 @@ static HRESULT WINAPI URLMonikerImpl_GetSizeMax(IMoniker* iface, /****************************************************************************** * URLMoniker_Construct (local function) *******************************************************************************/ -static HRESULT URLMonikerImpl_Construct(URLMonikerImpl* This, LPCOLESTR lpszURLName) +static HRESULT URLMonikerImpl_Construct(URLMonikerImpl* This, LPCOLESTR lpszLeftURLName, LPCOLESTR lpszURLName) { - int sizeStr = strlenW(lpszURLName); + HRESULT hres; + DWORD sizeStr; - TRACE("(%p,%s)\n",This,debugstr_w(lpszURLName)); + TRACE("(%p,%s,%s)\n",This,debugstr_w(lpszLeftURLName),debugstr_w(lpszURLName)); memset(This, 0, sizeof(*This)); /* Initialize the virtual function table. */ @@ -349,12 +351,30 @@ static HRESULT URLMonikerImpl_Construct(URLMonikerImpl* This, LPCOLESTR lpszURLN This->lpvtbl2 = &VTBinding_URLMonikerImpl; This->ref = 0; - This->URLName=HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR)*(sizeStr+1)); + if(lpszLeftURLName) { + hres = UrlCombineW(lpszLeftURLName, lpszURLName, NULL, &sizeStr, 0); + if(FAILED(hres)) { + return hres; + } + sizeStr++; + } + else + sizeStr = lstrlenW(lpszURLName)+1; + + This->URLName=HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR)*(sizeStr)); if (This->URLName==NULL) return E_OUTOFMEMORY; - strcpyW(This->URLName,lpszURLName); + if(lpszLeftURLName) { + hres = UrlCombineW(lpszLeftURLName, lpszURLName, This->URLName, &sizeStr, 0); + if(FAILED(hres)) { + HeapFree(GetProcessHeap(), 0, This->URLName); + return hres; + } + } + else + strcpyW(This->URLName,lpszURLName); return S_OK; } @@ -967,16 +987,25 @@ HRESULT WINAPI CreateURLMoniker(IMoniker *pmkContext, LPCWSTR szURL, IMoniker ** URLMonikerImpl *obj; HRESULT hres; IID iid = IID_IMoniker; + LPOLESTR lefturl = NULL; TRACE("(%p, %s, %p)\n", pmkContext, debugstr_w(szURL), ppmk); - if (NULL != pmkContext) - FIXME("Non-null pmkContext not implemented\n"); - if(!(obj = HeapAlloc(GetProcessHeap(), 0, sizeof(*obj)))) return E_OUTOFMEMORY; - hres = URLMonikerImpl_Construct(obj, szURL); + if(pmkContext) { + CLSID clsid; + IBindCtx* bind; + IMoniker_GetClassID(pmkContext, &clsid); + if(IsEqualCLSID(&clsid, &CLSID_StdURLMoniker) && SUCCEEDED(CreateBindCtx(0, &bind))) { + URLMonikerImpl_GetDisplayName(pmkContext, bind, NULL, &lefturl); + IBindCtx_Release(bind); + } + } + + hres = URLMonikerImpl_Construct(obj, lefturl, szURL); + CoTaskMemFree(lefturl); if(SUCCEEDED(hres)) hres = URLMonikerImpl_QueryInterface((IMoniker*)obj, &iid, (void**)ppmk); else