1 /* Unit tests for autocomplete
3 * Copyright 2007 Mikolaj Zalewski
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
29 #include "wine/test.h"
31 #define stop_on_error(exp) \
33 HRESULT res = (exp); \
36 ok(FALSE, #exp " failed: %x\n", res); \
43 HRESULT res = (exp); \
45 ok(FALSE, #exp " failed: %x\n", res); \
48 static LPWSTR strdup_AtoW(LPCSTR str)
50 int size = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
51 LPWSTR wstr = CoTaskMemAlloc((size + 1)*sizeof(WCHAR));
52 MultiByteToWideChar(CP_ACP, 0, str, -1, wstr, size+1);
58 IEnumString IEnumString_iface;
59 IACList IACList_iface;
68 extern IEnumStringVtbl TestACLVtbl;
69 extern IACListVtbl TestACL_ACListVtbl;
71 static inline TestACL *impl_from_IEnumString(IEnumString *iface)
73 return CONTAINING_RECORD(iface, TestACL, IEnumString_iface);
76 static TestACL *impl_from_IACList(IACList *iface)
78 return CONTAINING_RECORD(iface, TestACL, IACList_iface);
81 static TestACL *TestACL_Constructor(int limit, const char **strings)
83 TestACL *This = CoTaskMemAlloc(sizeof(TestACL));
84 ZeroMemory(This, sizeof(*This));
85 This->IEnumString_iface.lpVtbl = &TestACLVtbl;
86 This->IACList_iface.lpVtbl = &TestACL_ACListVtbl;
94 static ULONG STDMETHODCALLTYPE TestACL_AddRef(IEnumString *iface)
96 TestACL *This = impl_from_IEnumString(iface);
97 trace("ACL(%p): addref (%d)\n", This, This->ref+1);
98 return InterlockedIncrement(&This->ref);
101 static ULONG STDMETHODCALLTYPE TestACL_Release(IEnumString *iface)
103 TestACL *This = impl_from_IEnumString(iface);
106 res = InterlockedDecrement(&This->ref);
107 trace("ACL(%p): release (%d)\n", This, res);
111 static HRESULT STDMETHODCALLTYPE TestACL_QueryInterface(IEnumString *iface, REFIID iid, LPVOID *ppvOut)
113 TestACL *This = impl_from_IEnumString(iface);
115 if (IsEqualGUID(iid, &IID_IUnknown) || IsEqualGUID(iid, &IID_IEnumString))
119 else if (IsEqualGUID(iid, &IID_IACList))
121 *ppvOut = &This->IACList_iface;
126 iface->lpVtbl->AddRef(iface);
130 #if 0 /* IID_IEnumACString not defined yet in wine */
131 if (!IsEqualGUID(iid, &IID_IEnumACString))
132 trace("unknown interface queried\n");
134 return E_NOINTERFACE;
137 static HRESULT STDMETHODCALLTYPE TestACL_Next(IEnumString *iface, ULONG celt, LPOLESTR *rgelt, ULONG *pceltFetched)
139 TestACL *This = impl_from_IEnumString(iface);
142 trace("ACL(%p): read %d item(s)\n", This, celt);
143 for (i = 0; i < celt; i++)
145 if (This->pos >= This->limit)
147 rgelt[i] = strdup_AtoW(This->data[This->pos]);
158 static HRESULT STDMETHODCALLTYPE TestACL_Skip(IEnumString *iface, ULONG celt)
160 ok(FALSE, "Unexpected call to TestACL_Skip\n");
164 static HRESULT STDMETHODCALLTYPE TestACL_Clone(IEnumString *iface, IEnumString **out)
166 ok(FALSE, "Unexpected call to TestACL_Clone\n");
167 return E_OUTOFMEMORY;
170 static HRESULT STDMETHODCALLTYPE TestACL_Reset(IEnumString *iface)
172 TestACL *This = impl_from_IEnumString(iface);
173 trace("ACL(%p): Reset\n", This);
178 static HRESULT STDMETHODCALLTYPE TestACL_Expand(IACList *iface, LPCOLESTR str)
180 TestACL *This = impl_from_IACList(iface);
181 trace("ACL(%p): Expand\n", This);
186 IEnumStringVtbl TestACLVtbl =
188 TestACL_QueryInterface,
198 static ULONG STDMETHODCALLTYPE TestACL_ACList_AddRef(IACList *iface)
200 TestACL *This = impl_from_IACList(iface);
201 return TestACL_AddRef(&This->IEnumString_iface);
204 static ULONG STDMETHODCALLTYPE TestACL_ACList_Release(IACList *iface)
206 TestACL *This = impl_from_IACList(iface);
207 return TestACL_Release(&This->IEnumString_iface);
210 static HRESULT STDMETHODCALLTYPE TestACL_ACList_QueryInterface(IACList *iface, REFIID iid, LPVOID *ppvout)
212 TestACL *This = impl_from_IACList(iface);
213 return TestACL_QueryInterface(&This->IEnumString_iface, iid, ppvout);
216 IACListVtbl TestACL_ACListVtbl =
218 TestACL_ACList_QueryInterface,
219 TestACL_ACList_AddRef,
220 TestACL_ACList_Release,
225 #define expect_str(obj, str) \
227 ole_ok(obj->lpVtbl->Next(obj, 1, &wstr, &i)); \
228 ok(i == 1, "Expected i == 1, got %d\n", i); \
229 ok(str[0] == wstr[0], "String mismatch\n"); \
230 CoTaskMemFree(wstr); \
233 #define expect_end(obj) \
234 ok(obj->lpVtbl->Next(obj, 1, &wstr, &i) == S_FALSE, "Unexpected return from Next\n");
236 static void test_ACLMulti(void)
238 const char *strings1[] = {"a", "c", "e"};
239 const char *strings2[] = {"a", "b", "d"};
240 WCHAR exp[] = {'A','B','C',0};
242 TestACL *acl1, *acl2;
250 stop_on_error(CoCreateInstance(&CLSID_ACLMulti, NULL, CLSCTX_INPROC, &IID_IEnumString, (LPVOID *)&obj));
251 stop_on_error(obj->lpVtbl->QueryInterface(obj, &IID_IACList, (LPVOID *)&acl));
252 ok(obj->lpVtbl->QueryInterface(obj, &IID_IACList2, &tmp) == E_NOINTERFACE,
253 "Unexpected interface IACList2 in ACLMulti\n");
254 stop_on_error(obj->lpVtbl->QueryInterface(obj, &IID_IObjMgr, (LPVOID *)&mgr));
255 #if 0 /* IID_IEnumACString not defined yet in wine */
256 ole_ok(obj->lpVtbl->QueryInterface(obj, &IID_IEnumACString, &unk));
258 unk->lpVtbl->Release(unk);
261 ok(obj->lpVtbl->Next(obj, 1, (LPOLESTR *)&tmp, &i) == S_FALSE, "Unexpected return from Next\n");
262 ok(i == 0, "Unexpected fetched value %d\n", i);
263 ok(obj->lpVtbl->Next(obj, 44, (LPOLESTR *)&tmp, &i) == S_FALSE, "Unexpected return from Next\n");
264 ok(obj->lpVtbl->Skip(obj, 1) == E_NOTIMPL, "Unexpected return from Skip\n");
265 ok(obj->lpVtbl->Clone(obj, (IEnumString **)&tmp) == E_OUTOFMEMORY, "Unexpected return from Clone\n");
266 ole_ok(acl->lpVtbl->Expand(acl, exp));
268 acl1 = TestACL_Constructor(3, strings1);
269 acl2 = TestACL_Constructor(3, strings2);
270 stop_on_error(mgr->lpVtbl->Append(mgr, (IUnknown *)&acl1->IACList_iface));
271 stop_on_error(mgr->lpVtbl->Append(mgr, (IUnknown *)&acl2->IACList_iface));
272 ok(mgr->lpVtbl->Append(mgr, NULL) == E_FAIL, "Unexpected return from Append\n");
273 expect_str(obj, "a");
274 expect_str(obj, "c");
275 expect_str(obj, "e");
276 expect_str(obj, "a");
277 expect_str(obj, "b");
278 expect_str(obj, "d");
281 ole_ok(obj->lpVtbl->Reset(obj));
282 ok(acl1->pos == 0, "acl1 not reset\n");
283 ok(acl2->pos == 0, "acl2 not reset\n");
285 ole_ok(acl->lpVtbl->Expand(acl, exp));
286 ok(acl1->expcount == 1, "expcount - expected 1, got %d\n", acl1->expcount);
287 ok(acl2->expcount == 0 /* XP */ || acl2->expcount == 1 /* Vista */,
288 "expcount - expected 0 or 1, got %d\n", acl2->expcount);
290 ole_ok(obj->lpVtbl->Next(obj, 15, wstrtab, &i));
291 ok(i == 1, "Expected i == 1, got %d\n", i);
292 CoTaskMemFree(wstrtab[0]);
293 ole_ok(obj->lpVtbl->Next(obj, 15, wstrtab, &i));
294 CoTaskMemFree(wstrtab[0]);
295 ole_ok(obj->lpVtbl->Next(obj, 15, wstrtab, &i));
296 CoTaskMemFree(wstrtab[0]);
297 ole_ok(obj->lpVtbl->Next(obj, 15, wstrtab, &i));
298 CoTaskMemFree(wstrtab[0]);
299 ole_ok(acl->lpVtbl->Expand(acl, exp));
300 ok(acl1->expcount == 2, "expcount - expected 1, got %d\n", acl1->expcount);
301 ok(acl2->expcount == 0 /* XP */ || acl2->expcount == 2 /* Vista */,
302 "expcount - expected 0 or 2, got %d\n", acl2->expcount);
303 acl1->expret = S_FALSE;
304 ole_ok(acl->lpVtbl->Expand(acl, exp));
305 ok(acl1->expcount == 3, "expcount - expected 1, got %d\n", acl1->expcount);
306 ok(acl2->expcount == 1 /* XP */ || acl2->expcount == 3 /* Vista */,
307 "expcount - expected 0 or 3, got %d\n", acl2->expcount);
308 acl1->expret = E_NOTIMPL;
309 ole_ok(acl->lpVtbl->Expand(acl, exp));
310 ok(acl1->expcount == 4, "expcount - expected 1, got %d\n", acl1->expcount);
311 ok(acl2->expcount == 2 /* XP */ || acl2->expcount == 4 /* Vista */,
312 "expcount - expected 0 or 4, got %d\n", acl2->expcount);
313 acl2->expret = E_OUTOFMEMORY;
314 ok(acl->lpVtbl->Expand(acl, exp) == E_OUTOFMEMORY, "Unexpected Expand return\n");
315 acl2->expret = E_FAIL;
316 ok(acl->lpVtbl->Expand(acl, exp) == E_FAIL, "Unexpected Expand return\n");
318 stop_on_error(mgr->lpVtbl->Remove(mgr, (IUnknown *)&acl1->IACList_iface));
319 ok(acl1->ref == 1, "acl1 not released\n");
321 obj->lpVtbl->Reset(obj);
322 expect_str(obj, "a");
323 expect_str(obj, "b");
324 expect_str(obj, "d");
327 obj->lpVtbl->Release(obj);
328 acl->lpVtbl->Release(acl);
329 ok(mgr->lpVtbl->Release(mgr) == 0, "Unexpected references\n");
330 ok(acl1->ref == 1, "acl1 not released\n");
331 ok(acl2->ref == 1, "acl2 not released\n");
337 START_TEST(autocomplete)