push e2dd5002080a3a5df525dea14b261213385de3ae
[wine/hacks.git] / dlls / shlwapi / tests / assoc.c
blobbb1c4d6fc052ac39595ddf2156e318d9ecbccb3b
1 /* Unit test suite for SHLWAPI IQueryAssociations functions
3 * Copyright 2008 Google (Lei Zhang)
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 #include <stdarg.h>
22 #include "wine/test.h"
23 #include "shlwapi.h"
25 #define expect(expected, got) ok ( expected == got, "Expected %d, got %d\n", expected, got)
26 #define expect_hr(expected, got) ok ( expected == got, "Expected %08x, got %08x\n", expected, got)
28 /* Every version of Windows with IE should have this association? */
29 static const WCHAR dotHtml[] = { '.','h','t','m','l',0 };
30 static const WCHAR badBad[] = { 'b','a','d','b','a','d',0 };
31 static const WCHAR dotBad[] = { '.','b','a','d',0 };
32 static const WCHAR open[] = { 'o','p','e','n',0 };
33 static const WCHAR invalid[] = { 'i','n','v','a','l','i','d',0 };
35 static void test_getstring_bad(void)
37 HRESULT hr;
38 DWORD len;
40 hr = AssocQueryStringW(0, ASSOCSTR_EXECUTABLE, NULL, open, NULL, &len);
41 expect_hr(E_INVALIDARG, hr);
42 hr = AssocQueryStringW(0, ASSOCSTR_EXECUTABLE, badBad, open, NULL, &len);
43 expect_hr(E_FAIL, hr);
44 hr = AssocQueryStringW(0, ASSOCSTR_EXECUTABLE, dotBad, open, NULL, &len);
45 expect_hr(E_FAIL, hr);
46 hr = AssocQueryStringW(0, ASSOCSTR_EXECUTABLE, dotHtml, invalid, NULL,
47 &len);
48 expect_hr(0x80070002, hr); /* NOT FOUND */
49 hr = AssocQueryStringW(0, ASSOCSTR_EXECUTABLE, dotHtml, open, NULL, NULL);
50 expect_hr(E_UNEXPECTED, hr);
52 hr = AssocQueryStringW(0, ASSOCSTR_FRIENDLYAPPNAME, NULL, open, NULL, &len);
53 expect_hr(E_INVALIDARG, hr);
54 hr = AssocQueryStringW(0, ASSOCSTR_FRIENDLYAPPNAME, badBad, open, NULL,
55 &len);
56 expect_hr(E_FAIL, hr);
57 hr = AssocQueryStringW(0, ASSOCSTR_FRIENDLYAPPNAME, dotBad, open, NULL,
58 &len);
59 expect_hr(E_FAIL, hr);
60 hr = AssocQueryStringW(0, ASSOCSTR_FRIENDLYAPPNAME, dotHtml, invalid, NULL,
61 &len);
62 todo_wine expect_hr(0x80070002, hr); /* NOT FOUND */
63 hr = AssocQueryStringW(0, ASSOCSTR_FRIENDLYAPPNAME, dotHtml, open, NULL,
64 NULL);
65 expect_hr(E_UNEXPECTED, hr);
68 static void test_getstring_basic(void)
70 HRESULT hr;
71 WCHAR * friendlyName;
72 WCHAR * executableName;
73 DWORD len, len2, slen;
75 hr = AssocQueryStringW(0, ASSOCSTR_EXECUTABLE, dotHtml, open, NULL, &len);
76 expect_hr(S_FALSE, hr);
77 if (hr != S_FALSE)
79 skip("failed to get initial len\n");
80 return;
83 executableName = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
84 len * sizeof(WCHAR));
85 if (!executableName)
87 skip("failed to allocate memory\n");
88 return;
91 len2 = len;
92 hr = AssocQueryStringW(0, ASSOCSTR_EXECUTABLE, dotHtml, open,
93 executableName, &len2);
94 expect_hr(S_OK, hr);
95 slen = lstrlenW(executableName) + 1;
96 expect(len, len2);
97 expect(len, slen);
99 hr = AssocQueryStringW(0, ASSOCSTR_FRIENDLYAPPNAME, dotHtml, open, NULL,
100 &len);
101 todo_wine expect_hr(S_FALSE, hr);
102 if (hr != S_FALSE)
104 HeapFree(GetProcessHeap(), 0, executableName);
105 skip("failed to get initial len\n");
106 return;
109 friendlyName = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
110 len * sizeof(WCHAR));
111 if (!friendlyName)
113 HeapFree(GetProcessHeap(), 0, executableName);
114 skip("failed to allocate memory\n");
115 return;
118 len2 = len;
119 hr = AssocQueryStringW(0, ASSOCSTR_FRIENDLYAPPNAME, dotHtml, open,
120 friendlyName, &len2);
121 expect_hr(S_OK, hr);
122 slen = lstrlenW(friendlyName) + 1;
123 expect(len, len2);
124 expect(len, slen);
126 HeapFree(GetProcessHeap(), 0, executableName);
127 HeapFree(GetProcessHeap(), 0, friendlyName);
130 START_TEST(assoc)
132 test_getstring_bad();
133 test_getstring_basic();