shell32: Added support for ASSOCF_NOTRUNCATE flag in GetString().
[wine.git] / dlls / shell32 / tests / assoc.c
blobabfe6d4b556a506d1533282e34350b4ecc75cd3d
1 /* Unit test suite for various shell Association objects
3 * Copyright 2012 Detlef Riekenberg
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 #define COBJMACROS
22 #include <stdarg.h>
24 #include "shlwapi.h"
25 #include "shlguid.h"
26 #include "shobjidl.h"
28 #include "wine/test.h"
31 static void test_IQueryAssociations_QueryInterface(void)
33 IQueryAssociations *qa;
34 IQueryAssociations *qa2;
35 IUnknown *unk;
36 HRESULT hr;
38 hr = CoCreateInstance(&CLSID_QueryAssociations, NULL, CLSCTX_INPROC_SERVER, &IID_IQueryAssociations, (void*)&qa);
39 ok(hr == S_OK, "got 0x%08x\n", hr);
41 hr = IQueryAssociations_QueryInterface(qa, &IID_IQueryAssociations, (void**)&qa2);
42 ok(hr == S_OK, "QueryInterface (IQueryAssociations) returned 0x%x\n", hr);
43 if (SUCCEEDED(hr)) {
44 IQueryAssociations_Release(qa2);
47 hr = IQueryAssociations_QueryInterface(qa, &IID_IUnknown, (void**)&unk);
48 ok(hr == S_OK, "QueryInterface (IUnknown) returned 0x%x\n", hr);
49 if (SUCCEEDED(hr)) {
50 IUnknown_Release(unk);
53 hr = IQueryAssociations_QueryInterface(qa, &IID_IUnknown, NULL);
54 ok(hr == E_POINTER, "got 0x%x (expected E_POINTER)\n", hr);
56 IQueryAssociations_Release(qa);
60 static void test_IApplicationAssociationRegistration_QueryInterface(void)
62 IApplicationAssociationRegistration *appreg;
63 IApplicationAssociationRegistration *appreg2;
64 IUnknown *unk;
65 HRESULT hr;
67 /* this works since Vista */
68 hr = CoCreateInstance(&CLSID_ApplicationAssociationRegistration, NULL, CLSCTX_INPROC_SERVER,
69 &IID_IApplicationAssociationRegistration, (LPVOID*)&appreg);
71 if (FAILED(hr)) {
72 skip("IApplicationAssociationRegistration not created: 0x%x\n", hr);
73 return;
76 hr = IApplicationAssociationRegistration_QueryInterface(appreg, &IID_IApplicationAssociationRegistration,
77 (void**)&appreg2);
78 ok(hr == S_OK, "QueryInterface (IApplicationAssociationRegistration) returned 0x%x\n", hr);
79 if (SUCCEEDED(hr)) {
80 IApplicationAssociationRegistration_Release(appreg2);
83 hr = IApplicationAssociationRegistration_QueryInterface(appreg, &IID_IUnknown, (void**)&unk);
84 ok(hr == S_OK, "QueryInterface (IUnknown) returned 0x%x\n", hr);
85 if (SUCCEEDED(hr)) {
86 IUnknown_Release(unk);
89 hr = IApplicationAssociationRegistration_QueryInterface(appreg, &IID_IUnknown, NULL);
90 ok(hr == E_POINTER, "got 0x%x (expected E_POINTER)\n", hr);
92 IApplicationAssociationRegistration_Release(appreg);
95 struct assoc_getstring_test
97 const WCHAR *key;
98 ASSOCF flags;
99 ASSOCSTR str;
100 DWORD len;
101 HRESULT hr;
102 HRESULT brokenhr;
105 static const WCHAR httpW[] = {'h','t','t','p',0};
107 static struct assoc_getstring_test getstring_tests[] =
109 { httpW, 0, ASSOCSTR_EXECUTABLE, 2, 0x8007007a /* E_NOT_SUFFICIENT_BUFFER */, S_OK },
110 { httpW, ASSOCF_NOTRUNCATE, ASSOCSTR_EXECUTABLE, 2, E_POINTER },
111 { NULL }
114 static void test_IQueryAssociations_GetString(void)
116 struct assoc_getstring_test *ptr = getstring_tests;
117 IQueryAssociations *assoc;
118 HRESULT hr;
119 DWORD len;
120 int i = 0;
122 hr = CoCreateInstance(&CLSID_QueryAssociations, NULL, CLSCTX_INPROC_SERVER, &IID_IQueryAssociations, (void*)&assoc);
123 ok(hr == S_OK, "failed to create object, 0x%x\n", hr);
125 hr = IQueryAssociations_Init(assoc, 0, httpW, NULL, NULL);
126 ok(hr == S_OK, "Init failed, 0x%x\n", hr);
128 len = 0;
129 hr = IQueryAssociations_GetString(assoc, 0, ASSOCSTR_EXECUTABLE, NULL, NULL, &len);
130 ok(hr == S_FALSE, "got 0x%08x\n", hr);
131 ok(len > 0, "got wrong needed length, %d\n", len);
133 while (ptr->key)
135 WCHAR buffW[MAX_PATH];
136 DWORD len;
138 hr = IQueryAssociations_Init(assoc, 0, ptr->key, NULL, NULL);
139 ok(hr == S_OK, "%d: Init failed, 0x%x\n", i, hr);
141 len = ptr->len;
142 buffW[0] = ptr->flags & ASSOCF_NOTRUNCATE ? 0x1 : 0;
143 hr = IQueryAssociations_GetString(assoc, ptr->flags, ptr->str, NULL, buffW, &len);
144 if (hr != ptr->hr)
145 ok(broken(hr == ptr->brokenhr), "%d: GetString failed, 0x%08x\n", i, hr);
146 else
148 ok(hr == ptr->hr, "%d: GetString failed, 0x%08x\n", i, hr);
149 ok(len > ptr->len, "%d: got needed length %d\n", i, len);
152 /* even with ASSOCF_NOTRUNCATE it's null terminated */
153 if ((ptr->flags & ASSOCF_NOTRUNCATE) && (ptr->len > 0))
154 ok(buffW[0] == 0 || broken(buffW[0] == 0x1) /* pre win7 */, "%d: got %x\n", i, buffW[0]);
156 if (!(ptr->flags & ASSOCF_NOTRUNCATE) && ptr->len && FAILED(ptr->hr))
157 ok(buffW[0] != 0, "%d: got %x\n", i, buffW[0]);
159 i++;
160 ptr++;
163 IQueryAssociations_Release(assoc);
166 START_TEST(assoc)
168 IQueryAssociations *qa;
169 HRESULT hr;
171 CoInitialize(NULL);
173 /* this works since XP */
174 hr = CoCreateInstance(&CLSID_QueryAssociations, NULL, CLSCTX_INPROC_SERVER, &IID_IQueryAssociations, (void*)&qa);
175 if (hr == S_OK)
177 test_IQueryAssociations_QueryInterface();
178 test_IQueryAssociations_GetString();
180 IQueryAssociations_Release(qa);
182 else
183 win_skip("IQueryAssociations not supported, 0x%x\n", hr);
185 test_IApplicationAssociationRegistration_QueryInterface();
187 CoUninitialize();