static void test_IQueryAssociations_GetString(void) { struct assoc_getstring_test *ptr = getstring_tests; IQueryAssociations *assoc; HRESULT hr; DWORD len; int i = 0; hr = CoCreateInstance(&CLSID_QueryAssociations, NULL, CLSCTX_INPROC_SERVER, &IID_IQueryAssociations, (void*)&assoc); ok(hr == S_OK, "failed to create object, 0x%x\n", hr); hr = IQueryAssociations_Init(assoc, 0, httpW, NULL, NULL); ok(hr == S_OK, "Init failed, 0x%x\n", hr); len = 0; hr = IQueryAssociations_GetString(assoc, 0, ASSOCSTR_EXECUTABLE, NULL, NULL, &len); ok(hr == S_FALSE, "got 0x%08x\n", hr); ok(len > 0, "got wrong needed length, %d\n", len); while (ptr->key) { WCHAR buffW[MAX_PATH]; DWORD len; hr = IQueryAssociations_Init(assoc, 0, ptr->key, NULL, NULL); ok(hr == S_OK, "%d: Init failed, 0x%x\n", i, hr); len = ptr->len; buffW[0] = ptr->flags & ASSOCF_NOTRUNCATE ? 0x1 : 0; hr = IQueryAssociations_GetString(assoc, ptr->flags, ptr->str, NULL, buffW, &len); if (hr != ptr->hr) ok(broken(hr == ptr->brokenhr), "%d: GetString failed, 0x%08x\n", i, hr); else { ok(hr == ptr->hr, "%d: GetString failed, 0x%08x\n", i, hr); ok(len > ptr->len, "%d: got needed length %d\n", i, len); } /* even with ASSOCF_NOTRUNCATE it's null terminated */ if ((ptr->flags & ASSOCF_NOTRUNCATE) && (ptr->len > 0)) ok(buffW[0] == 0 || broken(buffW[0] == 0x1) /* pre win7 */, "%d: got %x\n", i, buffW[0]); if (!(ptr->flags & ASSOCF_NOTRUNCATE) && ptr->len && FAILED(ptr->hr)) ok(buffW[0] != 0, "%d: got %x\n", i, buffW[0]); i++; ptr++; } IQueryAssociations_Release(assoc); }
/************************************************************************* * AssocQueryStringByKeyW [SHLWAPI.@] * * See AssocQueryStringByKeyA. */ HRESULT WINAPI AssocQueryStringByKeyW(ASSOCF cfFlags, ASSOCSTR str, HKEY hkAssoc, LPCWSTR pszExtra, LPWSTR pszOut, DWORD *pcchOut) { HRESULT hRet; IQueryAssociations* lpAssoc; TRACE("(0x%8x,0x%8x,%p,%s,%p,%p)\n", cfFlags, str, hkAssoc, debugstr_w(pszExtra), pszOut, pcchOut); lpAssoc = IQueryAssociations_Constructor(); if (!lpAssoc) return E_OUTOFMEMORY; cfFlags &= SHLWAPI_DEF_ASSOCF; hRet = IQueryAssociations_Init(lpAssoc, cfFlags, 0, hkAssoc, NULL); if (SUCCEEDED(hRet)) hRet = IQueryAssociations_GetString(lpAssoc, cfFlags, str, pszExtra, pszOut, pcchOut); IQueryAssociations_Release(lpAssoc); return hRet; }
static void getstring_test(LPCWSTR assocName, HKEY progIdKey, ASSOCSTR str, LPCWSTR expected_string, int line) { IQueryAssociations *assoc; HRESULT hr; WCHAR *buffer = NULL; DWORD len; hr = CoCreateInstance(&CLSID_QueryAssociations, NULL, CLSCTX_INPROC_SERVER, &IID_IQueryAssociations, (void*)&assoc); ok_(__FILE__, line)(hr == S_OK, "failed to create IQueryAssociations, 0x%x\n", hr); hr = IQueryAssociations_Init(assoc, ASSOCF_NONE, assocName, progIdKey, NULL); ok_(__FILE__, line)(hr == S_OK, "IQueryAssociations::Init failed, 0x%x\n", hr); hr = IQueryAssociations_GetString(assoc, ASSOCF_NONE, str, NULL, NULL, &len); if (expected_string) { ok_(__FILE__, line)(hr == S_FALSE, "GetString returned 0x%x, expected S_FALSE\n", hr); if (hr != S_FALSE) { /* don't try to allocate memory using uninitialized len */ IQueryAssociations_Release(assoc); return; } buffer = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR)); ok_(__FILE__, line)(buffer != NULL, "out of memory\n"); hr = IQueryAssociations_GetString(assoc, 0, str, NULL, buffer, &len); ok_(__FILE__, line)(hr == S_OK, "GetString returned 0x%x, expected S_OK\n", hr); ok_(__FILE__, line)(lstrcmpW(buffer, expected_string) == 0, "GetString returned %s, expected %s\n", wine_dbgstr_w(buffer), wine_dbgstr_w(expected_string)); } else { ok_(__FILE__, line)(FAILED(hr), "GetString returned 0x%x, expected failure\n", hr); } IQueryAssociations_Release(assoc); HeapFree(GetProcessHeap(), 0, buffer); }
/************************************************************************* * AssocQueryStringW [SHLWAPI.@] * * See AssocQueryStringA. */ HRESULT WINAPI AssocQueryStringW(ASSOCF cfFlags, ASSOCSTR str, LPCWSTR pszAssoc, LPCWSTR pszExtra, LPWSTR pszOut, DWORD *pcchOut) { HRESULT hRet; IQueryAssociations* lpAssoc; TRACE("(0x%x,%d,%s,%s,%p,%p)\n", cfFlags, str, debugstr_w(pszAssoc), debugstr_w(pszExtra), pszOut, pcchOut); if (!pcchOut) return E_UNEXPECTED; hRet = AssocCreate( CLSID_QueryAssociations, &IID_IQueryAssociations, (void **)&lpAssoc ); if (FAILED(hRet)) return hRet; hRet = IQueryAssociations_Init(lpAssoc, cfFlags & SHLWAPI_DEF_ASSOCF, pszAssoc, NULL, NULL); if (SUCCEEDED(hRet)) hRet = IQueryAssociations_GetString(lpAssoc, cfFlags, str, pszExtra, pszOut, pcchOut); IQueryAssociations_Release(lpAssoc); return hRet; }
static void test_IQueryAssociations_Init(void) { IQueryAssociations *assoc; HRESULT hr; DWORD len; hr = CoCreateInstance(&CLSID_QueryAssociations, NULL, CLSCTX_INPROC_SERVER, &IID_IQueryAssociations, (void*)&assoc); ok(hr == S_OK, "failed to create object, 0x%x\n", hr); hr = IQueryAssociations_Init(assoc, ASSOCF_NONE, NULL, NULL, NULL); ok(hr == E_INVALIDARG, "Init failed, 0x%08x\n", hr); hr = IQueryAssociations_Init(assoc, ASSOCF_NONE, httpW, NULL, NULL); ok(hr == S_OK, "Init failed, 0x%08x\n", hr); hr = IQueryAssociations_Init(assoc, ASSOCF_NONE, badW, NULL, NULL); ok(hr == S_OK || broken(hr == S_FALSE) /* pre-vista */, "Init failed, 0x%08x\n", hr); len = 0; hr = IQueryAssociations_GetString(assoc, ASSOCF_NONE, ASSOCSTR_EXECUTABLE, NULL, NULL, &len); ok(hr == HRESULT_FROM_WIN32(ERROR_NO_ASSOCIATION) || broken(hr == E_FAIL) /* pre-vista */, "got 0x%08x\n", hr); IQueryAssociations_Release(assoc); }
/************************************************************************* * AssocQueryKeyW [SHLWAPI.@] * * See AssocQueryKeyA. */ HRESULT WINAPI AssocQueryKeyW(ASSOCF cfFlags, ASSOCKEY assockey, LPCWSTR pszAssoc, LPCWSTR pszExtra, HKEY *phkeyOut) { HRESULT hRet; IQueryAssociations* lpAssoc; TRACE("(0x%x,%d,%s,%s,%p)\n", cfFlags, assockey, debugstr_w(pszAssoc), debugstr_w(pszExtra), phkeyOut); hRet = AssocCreate( CLSID_QueryAssociations, &IID_IQueryAssociations, (void **)&lpAssoc ); if (FAILED(hRet)) return hRet; cfFlags &= SHLWAPI_DEF_ASSOCF; hRet = IQueryAssociations_Init(lpAssoc, cfFlags, pszAssoc, NULL, NULL); if (SUCCEEDED(hRet)) hRet = IQueryAssociations_GetKey(lpAssoc, cfFlags, assockey, pszExtra, phkeyOut); IQueryAssociations_Release(lpAssoc); return hRet; }
/************************************************************************* * AssocQueryKeyW [SHLWAPI.@] * * See AssocQueryKeyA. */ HRESULT WINAPI AssocQueryKeyW(ASSOCF cfFlags, ASSOCKEY assockey, LPCWSTR pszAssoc, LPCWSTR pszExtra, HKEY *phkeyOut) { HRESULT hRet; IQueryAssociations* lpAssoc; TRACE("(0x%8x,0x%8x,%s,%s,%p)\n", cfFlags, assockey, debugstr_w(pszAssoc), debugstr_w(pszExtra), phkeyOut); lpAssoc = IQueryAssociations_Constructor(); if (!lpAssoc) return E_OUTOFMEMORY; cfFlags &= SHLWAPI_DEF_ASSOCF; hRet = IQueryAssociations_Init(lpAssoc, cfFlags, pszAssoc, NULL, NULL); if (SUCCEEDED(hRet)) hRet = IQueryAssociations_GetKey(lpAssoc, cfFlags, assockey, pszExtra, phkeyOut); IQueryAssociations_Release(lpAssoc); return hRet; }
static void test_IQueryAssociations_GetString(void) { static WCHAR test_extensionW[] = {'.','t','e','s','t',0}; static WCHAR test_progidW[] = {'t','e','s','t','f','i','l','e',0}; static WCHAR DefaultIconW[] = {'D','e','f','a','u','l','t','I','c','o','n',0}; /* folder.ico, why not */ static WCHAR test_iconW[] = {'s','h','e','l','l','3','2','.','d','l','l',',','1',0}; HKEY test_extension_key; HKEY test_progid_key; HKEY test_defaulticon_key; LRESULT r; struct assoc_getstring_test *ptr = getstring_tests; IQueryAssociations *assoc; HRESULT hr; DWORD len; int i = 0; r = RegCreateKeyExW(HKEY_CLASSES_ROOT, test_extensionW, 0, NULL, 0, KEY_ALL_ACCESS, NULL, &test_extension_key, NULL); if (r == ERROR_ACCESS_DENIED) { win_skip("Not enough permissions to create a test key.\n"); return; } ok(r == ERROR_SUCCESS, "RegCreateKeyExW(HKCR, \".test\") failed: 0x%lx\n", r); r = RegSetValueExW(test_extension_key, NULL, 0, REG_SZ, (PBYTE)test_progidW, sizeof(test_progidW)); ok(r == ERROR_SUCCESS, "RegSetValueExW(HKCR\\.test, NULL, \"testfile\") failed: 0x%lx\n", r); /* adding progid key with no information should fail to return information */ r = RegCreateKeyExW(HKEY_CLASSES_ROOT, test_progidW, 0, NULL, 0, KEY_ALL_ACCESS, NULL, &test_progid_key, NULL); ok(r == ERROR_SUCCESS, "RegCreateKeyExW(HKCR, \"testfile\") failed: 0x%lx\n", r); getstring_test(test_extensionW, NULL, ASSOCSTR_DEFAULTICON, NULL, __LINE__); getstring_test(test_progidW, NULL, ASSOCSTR_DEFAULTICON, NULL, __LINE__); getstring_test(NULL, test_progid_key, ASSOCSTR_DEFAULTICON, NULL, __LINE__); /* adding information to the progid should return that information */ r = RegCreateKeyExW(test_progid_key, DefaultIconW, 0, NULL, 0, KEY_ALL_ACCESS, NULL, &test_defaulticon_key, NULL); ok(r == ERROR_SUCCESS, "RegCreateKeyExW(HKCR\\testfile\\DefaultIcon) failed: 0x%lx\n", r); r = RegSetValueExW(test_defaulticon_key, NULL, 0, REG_SZ, (PBYTE)test_iconW, sizeof(test_iconW)); ok(r == ERROR_SUCCESS, "RegSetValueExW(HKCR\\testfile\\DefaultIcon, NULL, \"folder.ico\") failed: 0x%lx\n", r); getstring_test(test_extensionW, NULL, ASSOCSTR_DEFAULTICON, test_iconW, __LINE__); getstring_test(test_progidW, NULL, ASSOCSTR_DEFAULTICON, test_iconW, __LINE__); getstring_test(NULL, test_progid_key, ASSOCSTR_DEFAULTICON, test_iconW, __LINE__); RegDeleteKeyW(test_progid_key, DefaultIconW); RegDeleteKeyW(HKEY_CLASSES_ROOT, test_progidW); RegDeleteKeyW(HKEY_CLASSES_ROOT, test_extensionW); hr = CoCreateInstance(&CLSID_QueryAssociations, NULL, CLSCTX_INPROC_SERVER, &IID_IQueryAssociations, (void*)&assoc); ok(hr == S_OK, "failed to create object, 0x%x\n", hr); hr = IQueryAssociations_Init(assoc, ASSOCF_NONE, httpW, NULL, NULL); ok(hr == S_OK, "Init failed, 0x%x\n", hr); len = 0; hr = IQueryAssociations_GetString(assoc, ASSOCF_NONE, ASSOCSTR_EXECUTABLE, NULL, NULL, &len); ok(hr == S_FALSE, "got 0x%08x\n", hr); ok(len > 0, "got wrong needed length, %d\n", len); while (ptr->key) { WCHAR buffW[MAX_PATH]; DWORD len; hr = IQueryAssociations_Init(assoc, ASSOCF_NONE, ptr->key, NULL, NULL); ok(hr == S_OK, "%d: Init failed, 0x%x\n", i, hr); len = ptr->len; buffW[0] = ptr->flags & ASSOCF_NOTRUNCATE ? 0x1 : 0; hr = IQueryAssociations_GetString(assoc, ptr->flags, ptr->str, NULL, buffW, &len); if (hr != ptr->hr) ok(broken(hr == ptr->brokenhr), "%d: GetString failed, 0x%08x\n", i, hr); else { ok(hr == ptr->hr, "%d: GetString failed, 0x%08x\n", i, hr); ok(len > ptr->len, "%d: got needed length %d\n", i, len); } /* even with ASSOCF_NOTRUNCATE it's null terminated */ if ((ptr->flags & ASSOCF_NOTRUNCATE) && (ptr->len > 0)) ok(buffW[0] == 0 || broken(buffW[0] == 0x1) /* pre win7 */, "%d: got %x\n", i, buffW[0]); if (!(ptr->flags & ASSOCF_NOTRUNCATE) && ptr->len && FAILED(ptr->hr)) ok(buffW[0] != 0, "%d: got %x\n", i, buffW[0]); i++; ptr++; } IQueryAssociations_Release(assoc); }