ReactOS 0.4.16-dev-1946-g52006dd
assoc.c File Reference
#include <stdarg.h>
#include "wine/test.h"
#include "shlwapi.h"
#include "shlguid.h"
Include dependency graph for assoc.c:

Go to the source code of this file.

Macros

#define expect(expected, got)   ok ( expected == got, "Expected %ld, got %ld\n", expected, got)
 
#define expect_hr(expected, got)   ok ( expected == got, "Expected %08lx, got %08lx\n", expected, got)
 

Functions

static HRESULT (WINAPI *pAssocQueryStringA)(ASSOCF
 
static void **static void test_getstring_bad (void)
 
static void test_getstring_basic (void)
 
static void test_getstring_no_extra (void)
 
static void test_assoc_create (void)
 
 START_TEST (assoc)
 

Variables

static ASSOCSTR
 
static LPCSTR
 
static LPSTR
 
static LPDWORD = NULL
 
static LPCWSTR
 
static LPWSTR
 
static REFIID
 

Macro Definition Documentation

◆ expect

#define expect (   expected,
  got 
)    ok ( expected == got, "Expected %ld, got %ld\n", expected, got)

Definition at line 26 of file assoc.c.

◆ expect_hr

#define expect_hr (   expected,
  got 
)    ok ( expected == got, "Expected %08lx, got %08lx\n", expected, got)

Definition at line 27 of file assoc.c.

Function Documentation

◆ HRESULT()

static HRESULT ( WINAPI pAssocQueryStringA)
static

◆ START_TEST()

START_TEST ( assoc  )

Definition at line 304 of file assoc.c.

305{
307 hshlwapi = GetModuleHandleA("shlwapi.dll");
308 pAssocQueryStringA = (void*)GetProcAddress(hshlwapi, "AssocQueryStringA");
309 pAssocQueryStringW = (void*)GetProcAddress(hshlwapi, "AssocQueryStringW");
310 pAssocCreate = (void*)GetProcAddress(hshlwapi, "AssocCreate");
311
316}
#define GetProcAddress(x, y)
Definition: compat.h:753
HMODULE WINAPI DECLSPEC_HOTPATCH GetModuleHandleA(LPCSTR lpModuleName)
Definition: loader.c:812
static void **static void test_getstring_bad(void)
Definition: assoc.c:35
static void test_getstring_basic(void)
Definition: assoc.c:120
static void test_assoc_create(void)
Definition: assoc.c:265
static void test_getstring_no_extra(void)
Definition: assoc.c:191
static HMODULE hshlwapi
Definition: shreg.c:35

◆ test_assoc_create()

static void test_assoc_create ( void  )
static

Definition at line 265 of file assoc.c.

266{
267 HRESULT hr;
268 IQueryAssociations *pqa;
269
270 if (!pAssocCreate)
271 {
272 win_skip("AssocCreate() is missing\n");
273 return;
274 }
275
276 hr = pAssocCreate(IID_NULL, &IID_NULL, NULL);
277 ok(hr == E_INVALIDARG, "Unexpected result : %08lx\n", hr);
278
279 hr = pAssocCreate(CLSID_QueryAssociations, &IID_NULL, (LPVOID*)&pqa);
281 , "Unexpected result : %08lx\n", hr);
282
283 hr = pAssocCreate(IID_NULL, &IID_IQueryAssociations, (LPVOID*)&pqa);
285 , "Unexpected result : %08lx\n", hr);
286
287 hr = pAssocCreate(CLSID_QueryAssociations, &IID_IQueryAssociations, (LPVOID*)&pqa);
288 ok(hr == S_OK || hr == E_NOTIMPL /* win98 */
289 , "Unexpected result : %08lx\n", hr);
290 if(hr == S_OK)
291 {
293 }
294
295 hr = pAssocCreate(CLSID_QueryAssociations, &IID_IUnknown, (LPVOID*)&pqa);
296 ok(hr == S_OK || hr == E_NOTIMPL /* win98 */
297 , "Unexpected result : %08lx\n", hr);
298 if(hr == S_OK)
299 {
301 }
302}
#define ok(value,...)
Definition: atltest.h:57
const GUID IID_IUnknown
#define E_INVALIDARG
Definition: ddrawi.h:101
#define E_NOTIMPL
Definition: ddrawi.h:99
#define NULL
Definition: types.h:112
#define S_OK
Definition: intsafe.h:52
#define win_skip
Definition: minitest.h:67
#define IID_NULL
Definition: guiddef.h:98
#define IQueryAssociations_Release(p)
Definition: shlwapi.h:987
HRESULT hr
Definition: shlfolder.c:183
#define E_NOINTERFACE
Definition: winerror.h:3479
#define CLASS_E_CLASSNOTAVAILABLE
Definition: winerror.h:3772

Referenced by START_TEST().

◆ test_getstring_bad()

static void **static void test_getstring_bad ( void  )
static

Definition at line 35 of file assoc.c.

36{
37 static const WCHAR openwith[] = {'O','p','e','n','W','i','t','h','.','e','x','e',0};
39 HRESULT hr;
40 DWORD len;
41
42 if (!pAssocQueryStringW)
43 {
44 win_skip("AssocQueryStringW() is missing\n");
45 return;
46 }
47
48 len = 0xdeadbeef;
49 hr = pAssocQueryStringW(0, ASSOCSTR_EXECUTABLE, NULL, L"open", NULL, &len);
51 ok(len == 0xdeadbeef, "got %lu\n", len);
52
53 len = 0xdeadbeef;
54 hr = pAssocQueryStringW(0, ASSOCSTR_EXECUTABLE, L"badbad", L"open", NULL, &len);
55 ok(hr == E_FAIL ||
56 hr == HRESULT_FROM_WIN32(ERROR_NO_ASSOCIATION), /* Win9x/WinMe/NT4/W2K/Vista/W2K8 */
57 "Unexpected result : %08lx\n", hr);
58 ok(len == 0xdeadbeef, "got %lu\n", len);
59
61 hr = pAssocQueryStringW(0, ASSOCSTR_EXECUTABLE, L".bad", L"open", buf, &len);
62 ok(hr == E_FAIL ||
63 hr == HRESULT_FROM_WIN32(ERROR_NO_ASSOCIATION) /* Win9x/WinMe/NT4/W2K/Vista/W2K8 */ ||
64 hr == S_OK /* Win8 */,
65 "Unexpected result : %08lx\n", hr);
66 if (hr == S_OK)
67 {
68 ok(len < ARRAY_SIZE(buf), "got %lu\n", len);
69 ok(!lstrcmpiW(buf + len - ARRAY_SIZE(openwith), openwith), "wrong data\n");
70 }
71
72 len = 0xdeadbeef;
73 hr = pAssocQueryStringW(0, ASSOCSTR_EXECUTABLE, L".html", L"invalid", NULL, &len);
75 hr == HRESULT_FROM_WIN32(ERROR_NO_ASSOCIATION), /* Win9x/WinMe/NT4/W2K/Vista/W2K8 */
76 "Unexpected result : %08lx\n", hr);
77 ok(len == 0xdeadbeef, "got %lu\n", len);
78
79 hr = pAssocQueryStringW(0, ASSOCSTR_EXECUTABLE, L".html", L"open", NULL, NULL);
80 ok(hr == E_UNEXPECTED ||
81 hr == E_INVALIDARG, /* Win9x/WinMe/NT4/W2K/Vista/W2K8 */
82 "Unexpected result : %08lx\n", hr);
83
84 len = 0xdeadbeef;
85 hr = pAssocQueryStringW(0, ASSOCSTR_FRIENDLYAPPNAME, NULL, L"open", NULL, &len);
87 ok(len == 0xdeadbeef, "got %lu\n", len);
88
89 len = 0xdeadbeef;
90 hr = pAssocQueryStringW(0, ASSOCSTR_FRIENDLYAPPNAME, L"badbad", L"open", NULL, &len);
91 ok(hr == E_FAIL ||
92 hr == HRESULT_FROM_WIN32(ERROR_NO_ASSOCIATION), /* Win9x/WinMe/NT4/W2K/Vista/W2K8 */
93 "Unexpected result : %08lx\n", hr);
94 ok(len == 0xdeadbeef, "got %lu\n", len);
95
96 len = 0xdeadbeef;
97 hr = pAssocQueryStringW(0, ASSOCSTR_FRIENDLYAPPNAME, L".bad", L"open", NULL, &len);
98 ok(hr == E_FAIL ||
99 hr == HRESULT_FROM_WIN32(ERROR_NO_ASSOCIATION) /* Win9x/WinMe/NT4/W2K/Vista/W2K8 */ ||
100 hr == HRESULT_FROM_WIN32(ERROR_NOT_FOUND) /* Win8 */ ||
101 hr == S_FALSE, /* Win10 */
102 "Unexpected result : %08lx\n", hr);
103 ok((hr == S_FALSE && len < ARRAY_SIZE(buf)) || len == 0xdeadbeef,
104 "got hr=%08lx and len=%lu\n", hr, len);
105
106 len = 0xdeadbeef;
107 hr = pAssocQueryStringW(0, ASSOCSTR_FRIENDLYAPPNAME, L".html", L"invalid", NULL, &len);
109 hr == HRESULT_FROM_WIN32(ERROR_NO_ASSOCIATION) || /* W2K/Vista/W2K8 */
110 hr == E_FAIL, /* Win9x/WinMe/NT4 */
111 "Unexpected result : %08lx\n", hr);
112 ok(len == 0xdeadbeef, "got %lu\n", len);
113
114 hr = pAssocQueryStringW(0, ASSOCSTR_FRIENDLYAPPNAME, L".html", L"open", NULL, NULL);
115 ok(hr == E_UNEXPECTED ||
116 hr == E_INVALIDARG, /* Win9x/WinMe/NT4/W2K/Vista/W2K8 */
117 "Unexpected result : %08lx\n", hr);
118}
#define ARRAY_SIZE(A)
Definition: main.h:20
#define E_FAIL
Definition: ddrawi.h:102
#define MAX_PATH
Definition: compat.h:34
int WINAPI lstrcmpiW(LPCWSTR str1, LPCWSTR str2)
Definition: locale.c:4265
#define L(x)
Definition: resources.c:13
unsigned long DWORD
Definition: ntddk_ex.h:95
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
GLenum GLsizei len
Definition: glext.h:6722
#define ERROR_FILE_NOT_FOUND
Definition: disk.h:79
#define expect_hr(expected, got)
Definition: assoc.c:27
@ ASSOCSTR_FRIENDLYAPPNAME
Definition: shlwapi.h:889
@ ASSOCSTR_EXECUTABLE
Definition: shlwapi.h:887
#define S_FALSE
Definition: winerror.h:3451
static HRESULT HRESULT_FROM_WIN32(unsigned int x)
Definition: winerror.h:210
#define ERROR_NO_ASSOCIATION
Definition: winerror.h:1001
#define E_UNEXPECTED
Definition: winerror.h:3528
#define ERROR_NOT_FOUND
Definition: winerror.h:1014
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by START_TEST().

◆ test_getstring_basic()

static void test_getstring_basic ( void  )
static

Definition at line 120 of file assoc.c.

121{
122 HRESULT hr;
123 WCHAR * friendlyName;
124 WCHAR * executableName;
125 DWORD len, len2, slen;
126
127 if (!pAssocQueryStringW)
128 {
129 win_skip("AssocQueryStringW() is missing\n");
130 return;
131 }
132
133 hr = pAssocQueryStringW(0, ASSOCSTR_EXECUTABLE, L".html", L"open", NULL, &len);
135 if (hr != S_FALSE)
136 {
137 skip("failed to get initial len\n");
138 return;
139 }
140
141 executableName = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
142 len * sizeof(WCHAR));
143 if (!executableName)
144 {
145 skip("failed to allocate memory\n");
146 return;
147 }
148
149 len2 = len;
150 hr = pAssocQueryStringW(0, ASSOCSTR_EXECUTABLE, L".html", L"open",
151 executableName, &len2);
152 expect_hr(S_OK, hr);
153 slen = lstrlenW(executableName) + 1;
154 expect(len, len2);
155 expect(len, slen);
156
157 hr = pAssocQueryStringW(0, ASSOCSTR_FRIENDLYAPPNAME, L".html", L"open", NULL,
158 &len);
159 ok(hr == S_FALSE ||
160 hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND) /* Win9x/NT4 */ ||
162 "Unexpected result : %08lx\n", hr);
163 if (hr != S_FALSE)
164 {
165 HeapFree(GetProcessHeap(), 0, executableName);
166 skip("failed to get initial len\n");
167 return;
168 }
169
170 friendlyName = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
171 len * sizeof(WCHAR));
172 if (!friendlyName)
173 {
174 HeapFree(GetProcessHeap(), 0, executableName);
175 skip("failed to allocate memory\n");
176 return;
177 }
178
179 len2 = len;
180 hr = pAssocQueryStringW(0, ASSOCSTR_FRIENDLYAPPNAME, L".html", L"open",
181 friendlyName, &len2);
182 expect_hr(S_OK, hr);
183 slen = lstrlenW(friendlyName) + 1;
184 expect(len, len2);
185 expect(len, slen);
186
187 HeapFree(GetProcessHeap(), 0, executableName);
188 HeapFree(GetProcessHeap(), 0, friendlyName);
189}
#define skip(...)
Definition: atltest.h:64
#define GetProcessHeap()
Definition: compat.h:736
#define HeapAlloc
Definition: compat.h:733
#define HeapFree(x, y, z)
Definition: compat.h:735
#define HEAP_ZERO_MEMORY
Definition: compat.h:134
#define lstrlenW
Definition: compat.h:750
#define expect(expected, got)
Definition: assoc.c:26

Referenced by START_TEST().

◆ test_getstring_no_extra()

static void test_getstring_no_extra ( void  )
static

Definition at line 191 of file assoc.c.

192{
193 LONG ret;
194 HKEY hkey;
195 HRESULT hr;
196 static const CHAR dotWinetest[] = {
197 '.','w','i','n','e','t','e','s','t',0
198 };
199 static const CHAR winetestfile[] = {
200 'w','i','n','e','t','e','s','t', 'f','i','l','e',0
201 };
202 static const CHAR winetestfileAction[] = {
203 'w','i','n','e','t','e','s','t','f','i','l','e',
204 '\\','s','h','e','l','l',
205 '\\','f','o','o',
206 '\\','c','o','m','m','a','n','d',0
207 };
208 static const CHAR action[] = {
209 'n','o','t','e','p','a','d','.','e','x','e',0
210 };
213
214 if (!pAssocQueryStringA)
215 {
216 win_skip("AssocQueryStringA() is missing\n");
217 return;
218 }
219
220 buf[0] = '\0';
221 ret = RegCreateKeyA(HKEY_CLASSES_ROOT, dotWinetest, &hkey);
222 if (ret != ERROR_SUCCESS) {
223 skip("failed to create dotWinetest key\n");
224 return;
225 }
226
227 ret = RegSetValueA(hkey, NULL, REG_SZ, winetestfile, lstrlenA(winetestfile));
228 RegCloseKey(hkey);
229 if (ret != ERROR_SUCCESS)
230 {
231 skip("failed to set dotWinetest key\n");
232 goto cleanup;
233 }
234
235 ret = RegCreateKeyA(HKEY_CLASSES_ROOT, winetestfileAction, &hkey);
236 if (ret != ERROR_SUCCESS)
237 {
238 skip("failed to create winetestfileAction key\n");
239 goto cleanup;
240 }
241
243 RegCloseKey(hkey);
244 if (ret != ERROR_SUCCESS)
245 {
246 skip("failed to set winetestfileAction key\n");
247 goto cleanup;
248 }
249
250 hr = pAssocQueryStringA(0, ASSOCSTR_EXECUTABLE, dotWinetest, NULL, buf, &len);
251 ok(hr == S_OK ||
252 hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), /* XP and W2K3 */
253 "Unexpected result : %08lx\n", hr);
254 hr = pAssocQueryStringA(0, ASSOCSTR_EXECUTABLE, dotWinetest, "foo", buf, &len);
255 expect_hr(S_OK, hr);
256 ok(strstr(buf, action) != NULL,
257 "got '%s' (Expected result to include 'notepad.exe')\n", buf);
258
259cleanup:
260 SHDeleteKeyA(HKEY_CLASSES_ROOT, dotWinetest);
261 SHDeleteKeyA(HKEY_CLASSES_ROOT, winetestfile);
262
263}
char * strstr(char *String1, char *String2)
Definition: utclib.c:653
#define RegCloseKey(hKey)
Definition: registry.h:49
#define ERROR_SUCCESS
Definition: deptool.c:10
LONG WINAPI RegCreateKeyA(HKEY hKey, LPCSTR lpSubKey, PHKEY phkResult)
Definition: reg.c:1179
LONG WINAPI RegSetValueA(HKEY hKeyOriginal, LPCSTR lpSubKey, DWORD dwType, LPCSTR lpData, DWORD cbData)
Definition: reg.c:4954
static void cleanup(void)
Definition: main.c:1335
DWORD WINAPI SHDeleteKeyA(HKEY hKey, LPCSTR lpszSubKey)
Definition: reg.c:1533
return ret
Definition: mutex.c:146
action
Definition: namespace.c:707
#define REG_SZ
Definition: layer.c:22
int WINAPI lstrlenA(LPCSTR lpString)
Definition: lstring.c:145
long LONG
Definition: pedump.c:60
#define HKEY_CLASSES_ROOT
Definition: winreg.h:10
char CHAR
Definition: xmlstorage.h:175

Referenced by START_TEST().

Variable Documentation

◆ ASSOCSTR

Definition at line 29 of file assoc.c.

◆ LPCSTR

Definition at line 29 of file assoc.c.

◆ LPCWSTR

Definition at line 30 of file assoc.c.

◆ LPDWORD

Definition at line 29 of file assoc.c.

◆ LPSTR

Definition at line 29 of file assoc.c.

◆ LPWSTR

Definition at line 30 of file assoc.c.

◆ REFIID

REFIID

Definition at line 31 of file assoc.c.