2008-10-11 07:20:51 +02:00
|
|
|
/* Unit test suite for SHLWAPI IQueryAssociations functions
|
|
|
|
*
|
|
|
|
* Copyright 2008 Google (Lei Zhang)
|
|
|
|
*
|
|
|
|
* 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdarg.h>
|
|
|
|
|
|
|
|
#include "wine/test.h"
|
|
|
|
#include "shlwapi.h"
|
2009-07-30 03:30:22 +02:00
|
|
|
#include "shlguid.h"
|
2008-10-11 07:20:51 +02:00
|
|
|
|
|
|
|
#define expect(expected, got) ok ( expected == got, "Expected %d, got %d\n", expected, got)
|
|
|
|
#define expect_hr(expected, got) ok ( expected == got, "Expected %08x, got %08x\n", expected, got)
|
|
|
|
|
2008-11-02 23:58:06 +01:00
|
|
|
static HRESULT (WINAPI *pAssocQueryStringA)(ASSOCF,ASSOCSTR,LPCSTR,LPCSTR,LPSTR,LPDWORD) = NULL;
|
|
|
|
static HRESULT (WINAPI *pAssocQueryStringW)(ASSOCF,ASSOCSTR,LPCWSTR,LPCWSTR,LPWSTR,LPDWORD) = NULL;
|
2009-07-30 03:30:22 +02:00
|
|
|
static HRESULT (WINAPI *pAssocCreate)(CLSID, REFIID, void **) = NULL;
|
2008-11-02 23:58:06 +01:00
|
|
|
|
2008-10-11 07:20:51 +02:00
|
|
|
/* Every version of Windows with IE should have this association? */
|
|
|
|
static const WCHAR dotHtml[] = { '.','h','t','m','l',0 };
|
|
|
|
static const WCHAR badBad[] = { 'b','a','d','b','a','d',0 };
|
|
|
|
static const WCHAR dotBad[] = { '.','b','a','d',0 };
|
|
|
|
static const WCHAR open[] = { 'o','p','e','n',0 };
|
|
|
|
static const WCHAR invalid[] = { 'i','n','v','a','l','i','d',0 };
|
|
|
|
|
|
|
|
static void test_getstring_bad(void)
|
|
|
|
{
|
2014-03-11 13:24:42 +01:00
|
|
|
static const WCHAR openwith[] = {'O','p','e','n','W','i','t','h','.','e','x','e',0};
|
|
|
|
WCHAR buf[MAX_PATH];
|
2008-10-11 07:20:51 +02:00
|
|
|
HRESULT hr;
|
|
|
|
DWORD len;
|
|
|
|
|
2008-11-02 23:58:06 +01:00
|
|
|
if (!pAssocQueryStringW)
|
|
|
|
{
|
|
|
|
win_skip("AssocQueryStringW() is missing\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-03-11 13:24:42 +01:00
|
|
|
len = 0xdeadbeef;
|
2008-11-02 23:58:06 +01:00
|
|
|
hr = pAssocQueryStringW(0, ASSOCSTR_EXECUTABLE, NULL, open, NULL, &len);
|
2008-10-11 07:21:25 +02:00
|
|
|
expect_hr(E_INVALIDARG, hr);
|
2014-03-11 13:24:42 +01:00
|
|
|
ok(len == 0xdeadbeef, "got %u\n", len);
|
|
|
|
|
|
|
|
len = 0xdeadbeef;
|
2008-11-02 23:58:06 +01:00
|
|
|
hr = pAssocQueryStringW(0, ASSOCSTR_EXECUTABLE, badBad, open, NULL, &len);
|
2008-10-23 21:41:11 +02:00
|
|
|
ok(hr == E_FAIL ||
|
|
|
|
hr == HRESULT_FROM_WIN32(ERROR_NO_ASSOCIATION), /* Win9x/WinMe/NT4/W2K/Vista/W2K8 */
|
|
|
|
"Unexpected result : %08x\n", hr);
|
2014-03-11 13:24:42 +01:00
|
|
|
ok(len == 0xdeadbeef, "got %u\n", len);
|
|
|
|
|
|
|
|
len = sizeof(buf)/sizeof(buf[0]);
|
|
|
|
hr = pAssocQueryStringW(0, ASSOCSTR_EXECUTABLE, dotBad, open, buf, &len);
|
2008-10-23 21:41:11 +02:00
|
|
|
ok(hr == E_FAIL ||
|
2014-03-11 13:24:42 +01:00
|
|
|
hr == HRESULT_FROM_WIN32(ERROR_NO_ASSOCIATION) /* Win9x/WinMe/NT4/W2K/Vista/W2K8 */ ||
|
|
|
|
hr == S_OK /* Win8 */,
|
2008-10-23 21:41:11 +02:00
|
|
|
"Unexpected result : %08x\n", hr);
|
2014-03-11 13:24:42 +01:00
|
|
|
if (hr == S_OK)
|
|
|
|
{
|
|
|
|
ok(len < sizeof(buf)/sizeof(buf[0]), "got %u\n", len);
|
|
|
|
ok(!lstrcmpiW(buf + len - sizeof(openwith)/sizeof(openwith[0]), openwith), "wrong data\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
len = 0xdeadbeef;
|
|
|
|
hr = pAssocQueryStringW(0, ASSOCSTR_EXECUTABLE, dotHtml, invalid, NULL, &len);
|
2008-10-23 21:41:11 +02:00
|
|
|
ok(hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND) ||
|
|
|
|
hr == HRESULT_FROM_WIN32(ERROR_NO_ASSOCIATION), /* Win9x/WinMe/NT4/W2K/Vista/W2K8 */
|
|
|
|
"Unexpected result : %08x\n", hr);
|
2014-03-11 13:24:42 +01:00
|
|
|
ok(len == 0xdeadbeef, "got %u\n", len);
|
|
|
|
|
2008-11-02 23:58:06 +01:00
|
|
|
hr = pAssocQueryStringW(0, ASSOCSTR_EXECUTABLE, dotHtml, open, NULL, NULL);
|
2008-10-23 21:41:11 +02:00
|
|
|
ok(hr == E_UNEXPECTED ||
|
|
|
|
hr == E_INVALIDARG, /* Win9x/WinMe/NT4/W2K/Vista/W2K8 */
|
|
|
|
"Unexpected result : %08x\n", hr);
|
2008-10-11 07:20:51 +02:00
|
|
|
|
2014-03-11 13:24:42 +01:00
|
|
|
len = 0xdeadbeef;
|
2008-11-02 23:58:06 +01:00
|
|
|
hr = pAssocQueryStringW(0, ASSOCSTR_FRIENDLYAPPNAME, NULL, open, NULL, &len);
|
2008-10-11 07:21:25 +02:00
|
|
|
expect_hr(E_INVALIDARG, hr);
|
2014-03-11 13:24:42 +01:00
|
|
|
ok(len == 0xdeadbeef, "got %u\n", len);
|
|
|
|
|
|
|
|
len = 0xdeadbeef;
|
|
|
|
hr = pAssocQueryStringW(0, ASSOCSTR_FRIENDLYAPPNAME, badBad, open, NULL, &len);
|
2008-10-23 21:41:11 +02:00
|
|
|
ok(hr == E_FAIL ||
|
|
|
|
hr == HRESULT_FROM_WIN32(ERROR_NO_ASSOCIATION), /* Win9x/WinMe/NT4/W2K/Vista/W2K8 */
|
|
|
|
"Unexpected result : %08x\n", hr);
|
2014-03-11 13:24:42 +01:00
|
|
|
ok(len == 0xdeadbeef, "got %u\n", len);
|
|
|
|
|
|
|
|
len = 0xdeadbeef;
|
|
|
|
hr = pAssocQueryStringW(0, ASSOCSTR_FRIENDLYAPPNAME, dotBad, open, NULL, &len);
|
2008-10-23 21:41:11 +02:00
|
|
|
ok(hr == E_FAIL ||
|
2012-12-10 23:37:13 +01:00
|
|
|
hr == HRESULT_FROM_WIN32(ERROR_NO_ASSOCIATION) /* Win9x/WinMe/NT4/W2K/Vista/W2K8 */ ||
|
|
|
|
hr == HRESULT_FROM_WIN32(ERROR_NOT_FOUND), /* Win8 */
|
2008-10-23 21:41:11 +02:00
|
|
|
"Unexpected result : %08x\n", hr);
|
2014-03-11 13:24:42 +01:00
|
|
|
ok(len == 0xdeadbeef, "got %u\n", len);
|
|
|
|
|
|
|
|
len = 0xdeadbeef;
|
|
|
|
hr = pAssocQueryStringW(0, ASSOCSTR_FRIENDLYAPPNAME, dotHtml, invalid, NULL, &len);
|
2008-10-23 21:41:11 +02:00
|
|
|
ok(hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND) ||
|
|
|
|
hr == HRESULT_FROM_WIN32(ERROR_NO_ASSOCIATION) || /* W2K/Vista/W2K8 */
|
|
|
|
hr == E_FAIL, /* Win9x/WinMe/NT4 */
|
|
|
|
"Unexpected result : %08x\n", hr);
|
2014-03-11 13:24:42 +01:00
|
|
|
ok(len == 0xdeadbeef, "got %u\n", len);
|
|
|
|
|
|
|
|
hr = pAssocQueryStringW(0, ASSOCSTR_FRIENDLYAPPNAME, dotHtml, open, NULL, NULL);
|
2008-10-23 21:41:11 +02:00
|
|
|
ok(hr == E_UNEXPECTED ||
|
|
|
|
hr == E_INVALIDARG, /* Win9x/WinMe/NT4/W2K/Vista/W2K8 */
|
|
|
|
"Unexpected result : %08x\n", hr);
|
2008-10-11 07:20:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void test_getstring_basic(void)
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
WCHAR * friendlyName;
|
|
|
|
WCHAR * executableName;
|
|
|
|
DWORD len, len2, slen;
|
|
|
|
|
2008-11-02 23:58:06 +01:00
|
|
|
if (!pAssocQueryStringW)
|
|
|
|
{
|
|
|
|
win_skip("AssocQueryStringW() is missing\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
hr = pAssocQueryStringW(0, ASSOCSTR_EXECUTABLE, dotHtml, open, NULL, &len);
|
2008-10-11 08:34:04 +02:00
|
|
|
expect_hr(S_FALSE, hr);
|
2008-10-11 07:20:51 +02:00
|
|
|
if (hr != S_FALSE)
|
|
|
|
{
|
|
|
|
skip("failed to get initial len\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
executableName = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
|
|
|
|
len * sizeof(WCHAR));
|
|
|
|
if (!executableName)
|
|
|
|
{
|
|
|
|
skip("failed to allocate memory\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
len2 = len;
|
2008-11-02 23:58:06 +01:00
|
|
|
hr = pAssocQueryStringW(0, ASSOCSTR_EXECUTABLE, dotHtml, open,
|
2008-10-11 07:20:51 +02:00
|
|
|
executableName, &len2);
|
|
|
|
expect_hr(S_OK, hr);
|
|
|
|
slen = lstrlenW(executableName) + 1;
|
|
|
|
expect(len, len2);
|
|
|
|
expect(len, slen);
|
|
|
|
|
2008-11-02 23:58:06 +01:00
|
|
|
hr = pAssocQueryStringW(0, ASSOCSTR_FRIENDLYAPPNAME, dotHtml, open, NULL,
|
2008-10-11 07:20:51 +02:00
|
|
|
&len);
|
2008-11-04 19:21:50 +01:00
|
|
|
ok(hr == S_FALSE ||
|
2012-12-10 23:37:13 +01:00
|
|
|
hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND) /* Win9x/NT4 */ ||
|
|
|
|
hr == HRESULT_FROM_WIN32(ERROR_NOT_FOUND), /* Win8 */
|
2008-11-04 19:21:50 +01:00
|
|
|
"Unexpected result : %08x\n", hr);
|
2008-10-11 07:20:51 +02:00
|
|
|
if (hr != S_FALSE)
|
|
|
|
{
|
|
|
|
HeapFree(GetProcessHeap(), 0, executableName);
|
|
|
|
skip("failed to get initial len\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
friendlyName = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
|
|
|
|
len * sizeof(WCHAR));
|
|
|
|
if (!friendlyName)
|
|
|
|
{
|
|
|
|
HeapFree(GetProcessHeap(), 0, executableName);
|
|
|
|
skip("failed to allocate memory\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
len2 = len;
|
2008-11-02 23:58:06 +01:00
|
|
|
hr = pAssocQueryStringW(0, ASSOCSTR_FRIENDLYAPPNAME, dotHtml, open,
|
2008-10-11 07:20:51 +02:00
|
|
|
friendlyName, &len2);
|
|
|
|
expect_hr(S_OK, hr);
|
|
|
|
slen = lstrlenW(friendlyName) + 1;
|
|
|
|
expect(len, len2);
|
|
|
|
expect(len, slen);
|
|
|
|
|
|
|
|
HeapFree(GetProcessHeap(), 0, executableName);
|
|
|
|
HeapFree(GetProcessHeap(), 0, friendlyName);
|
|
|
|
}
|
|
|
|
|
2008-10-15 00:06:45 +02:00
|
|
|
static void test_getstring_no_extra(void)
|
|
|
|
{
|
|
|
|
LONG ret;
|
|
|
|
HKEY hkey;
|
|
|
|
HRESULT hr;
|
2008-10-17 16:38:55 +02:00
|
|
|
static const CHAR dotWinetest[] = {
|
2008-10-15 00:06:45 +02:00
|
|
|
'.','w','i','n','e','t','e','s','t',0
|
|
|
|
};
|
2008-10-17 16:38:55 +02:00
|
|
|
static const CHAR winetestfile[] = {
|
2008-10-15 00:06:45 +02:00
|
|
|
'w','i','n','e','t','e','s','t', 'f','i','l','e',0
|
|
|
|
};
|
2008-10-17 16:38:55 +02:00
|
|
|
static const CHAR winetestfileAction[] = {
|
2008-10-15 00:06:45 +02:00
|
|
|
'w','i','n','e','t','e','s','t','f','i','l','e',
|
|
|
|
'\\','s','h','e','l','l',
|
|
|
|
'\\','f','o','o',
|
|
|
|
'\\','c','o','m','m','a','n','d',0
|
|
|
|
};
|
2008-10-17 16:38:55 +02:00
|
|
|
static const CHAR action[] = {
|
2008-10-15 00:06:45 +02:00
|
|
|
'n','o','t','e','p','a','d','.','e','x','e',0
|
|
|
|
};
|
2008-10-17 16:38:55 +02:00
|
|
|
CHAR buf[MAX_PATH];
|
2008-10-15 00:06:45 +02:00
|
|
|
DWORD len = MAX_PATH;
|
|
|
|
|
2008-11-02 23:58:06 +01:00
|
|
|
if (!pAssocQueryStringA)
|
|
|
|
{
|
|
|
|
win_skip("AssocQueryStringA() is missing\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-10-17 16:38:55 +02:00
|
|
|
buf[0] = '\0';
|
|
|
|
ret = RegCreateKeyA(HKEY_CLASSES_ROOT, dotWinetest, &hkey);
|
|
|
|
if (ret != ERROR_SUCCESS) {
|
2008-10-15 00:06:45 +02:00
|
|
|
skip("failed to create dotWinetest key\n");
|
2008-10-17 16:38:55 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = RegSetValueA(hkey, NULL, REG_SZ, winetestfile, lstrlenA(winetestfile));
|
2008-10-15 00:06:45 +02:00
|
|
|
RegCloseKey(hkey);
|
|
|
|
if (ret != ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
skip("failed to set dotWinetest key\n");
|
2008-10-17 16:38:55 +02:00
|
|
|
goto cleanup;
|
2008-10-15 00:06:45 +02:00
|
|
|
}
|
|
|
|
|
2008-10-17 16:38:55 +02:00
|
|
|
ret = RegCreateKeyA(HKEY_CLASSES_ROOT, winetestfileAction, &hkey);
|
2008-10-15 00:06:45 +02:00
|
|
|
if (ret != ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
skip("failed to create winetestfileAction key\n");
|
2008-10-17 16:38:55 +02:00
|
|
|
goto cleanup;
|
2008-10-15 00:06:45 +02:00
|
|
|
}
|
2008-10-17 16:38:55 +02:00
|
|
|
|
|
|
|
ret = RegSetValueA(hkey, NULL, REG_SZ, action, lstrlenA(action));
|
2008-10-15 00:06:45 +02:00
|
|
|
RegCloseKey(hkey);
|
|
|
|
if (ret != ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
skip("failed to set winetestfileAction key\n");
|
2008-10-17 16:38:55 +02:00
|
|
|
goto cleanup;
|
2008-10-15 00:06:45 +02:00
|
|
|
}
|
|
|
|
|
2008-11-02 23:58:06 +01:00
|
|
|
hr = pAssocQueryStringA(0, ASSOCSTR_EXECUTABLE, dotWinetest, NULL, buf, &len);
|
2008-11-04 13:49:02 +01:00
|
|
|
ok(hr == S_OK ||
|
|
|
|
hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), /* XP and W2K3 */
|
|
|
|
"Unexpected result : %08x\n", hr);
|
|
|
|
hr = pAssocQueryStringA(0, ASSOCSTR_EXECUTABLE, dotWinetest, "foo", buf, &len);
|
2008-10-15 00:06:45 +02:00
|
|
|
expect_hr(S_OK, hr);
|
2008-10-17 16:38:55 +02:00
|
|
|
ok(strstr(buf, action) != NULL,
|
|
|
|
"got '%s' (Expected result to include 'notepad.exe')\n", buf);
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
SHDeleteKeyA(HKEY_CLASSES_ROOT, dotWinetest);
|
|
|
|
SHDeleteKeyA(HKEY_CLASSES_ROOT, winetestfile);
|
|
|
|
|
2008-10-15 00:06:45 +02:00
|
|
|
}
|
|
|
|
|
2009-07-30 03:30:22 +02:00
|
|
|
static void test_assoc_create(void)
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
IQueryAssociations *pqa;
|
|
|
|
|
|
|
|
if (!pAssocCreate)
|
|
|
|
{
|
|
|
|
win_skip("AssocCreate() is missing\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
hr = pAssocCreate(IID_NULL, &IID_NULL, NULL);
|
|
|
|
ok(hr == E_INVALIDARG, "Unexpected result : %08x\n", hr);
|
|
|
|
|
|
|
|
hr = pAssocCreate(CLSID_QueryAssociations, &IID_NULL, (LPVOID*)&pqa);
|
2009-08-05 06:19:38 +02:00
|
|
|
ok(hr == CLASS_E_CLASSNOTAVAILABLE || hr == E_NOTIMPL || hr == E_NOINTERFACE
|
2009-07-30 03:30:22 +02:00
|
|
|
, "Unexpected result : %08x\n", hr);
|
|
|
|
|
|
|
|
hr = pAssocCreate(IID_NULL, &IID_IQueryAssociations, (LPVOID*)&pqa);
|
2009-08-05 06:19:38 +02:00
|
|
|
ok(hr == CLASS_E_CLASSNOTAVAILABLE || hr == E_NOTIMPL || hr == E_INVALIDARG
|
2009-07-30 03:30:22 +02:00
|
|
|
, "Unexpected result : %08x\n", hr);
|
|
|
|
|
|
|
|
hr = pAssocCreate(CLSID_QueryAssociations, &IID_IQueryAssociations, (LPVOID*)&pqa);
|
|
|
|
ok(hr == S_OK || hr == E_NOTIMPL /* win98 */
|
|
|
|
, "Unexpected result : %08x\n", hr);
|
|
|
|
if(hr == S_OK)
|
|
|
|
{
|
|
|
|
IQueryAssociations_Release(pqa);
|
|
|
|
}
|
|
|
|
|
|
|
|
hr = pAssocCreate(CLSID_QueryAssociations, &IID_IUnknown, (LPVOID*)&pqa);
|
|
|
|
ok(hr == S_OK || hr == E_NOTIMPL /* win98 */
|
|
|
|
, "Unexpected result : %08x\n", hr);
|
|
|
|
if(hr == S_OK)
|
|
|
|
{
|
|
|
|
IQueryAssociations_Release(pqa);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-10-11 07:20:51 +02:00
|
|
|
START_TEST(assoc)
|
|
|
|
{
|
2008-11-02 23:58:06 +01:00
|
|
|
HMODULE hshlwapi;
|
|
|
|
hshlwapi = GetModuleHandleA("shlwapi.dll");
|
|
|
|
pAssocQueryStringA = (void*)GetProcAddress(hshlwapi, "AssocQueryStringA");
|
|
|
|
pAssocQueryStringW = (void*)GetProcAddress(hshlwapi, "AssocQueryStringW");
|
2009-07-30 03:30:22 +02:00
|
|
|
pAssocCreate = (void*)GetProcAddress(hshlwapi, "AssocCreate");
|
2008-11-02 23:58:06 +01:00
|
|
|
|
2008-10-11 07:20:51 +02:00
|
|
|
test_getstring_bad();
|
|
|
|
test_getstring_basic();
|
2008-10-15 00:06:45 +02:00
|
|
|
test_getstring_no_extra();
|
2009-07-30 03:30:22 +02:00
|
|
|
test_assoc_create();
|
2008-10-11 07:20:51 +02:00
|
|
|
}
|