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
28 #include "wine/test.h"
30 #define stop_on_error(exp) \
32 HRESULT res = (exp); \
35 ok(FALSE, #exp " failed: %x\n", res); \
42 HRESULT res = (exp); \
44 ok(FALSE, #exp " failed: %x\n", res); \
47 LPWSTR strdup_AtoW(LPCSTR str)
49 int size = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
50 LPWSTR wstr = (LPWSTR)CoTaskMemAlloc((size + 1)*sizeof(WCHAR));
51 MultiByteToWideChar(CP_ACP, 0, str, -1, wstr, size+1);
57 IEnumStringVtbl *vtbl;
67 extern IEnumStringVtbl TestACLVtbl;
68 extern IACListVtbl TestACL_ACListVtbl;
70 static TestACL *impl_from_IACList(IACList *iface)
72 return (TestACL *)((char *)iface - FIELD_OFFSET(TestACL, aclVtbl));
75 static TestACL *TestACL_Constructor(int limit, const char **strings)
77 TestACL *This = CoTaskMemAlloc(sizeof(TestACL));
78 ZeroMemory(This, sizeof(*This));
79 This->vtbl = &TestACLVtbl;
80 This->aclVtbl = &TestACL_ACListVtbl;
88 ULONG STDMETHODCALLTYPE TestACL_AddRef(IEnumString *iface)
90 TestACL *This = (TestACL *)iface;
91 trace("ACL(%p): addref (%d)\n", This, This->ref+1);
92 return InterlockedIncrement(&This->ref);
95 ULONG STDMETHODCALLTYPE TestACL_Release(IEnumString *iface)
97 TestACL *This = (TestACL *)iface;
100 res = InterlockedDecrement(&This->ref);
101 trace("ACL(%p): release (%d)\n", This, res);
105 HRESULT STDMETHODCALLTYPE TestACL_QueryInterface(IEnumString *iface, REFIID iid, LPVOID *ppvOut)
107 TestACL *This = (TestACL *)iface;
109 if (IsEqualGUID(iid, &IID_IUnknown) || IsEqualGUID(iid, &IID_IEnumString))
113 else if (IsEqualGUID(iid, &IID_IACList))
115 *ppvOut = &This->aclVtbl;
120 iface->lpVtbl->AddRef(iface);
124 #if 0 /* IID_IEnumACString not defined yet in wine */
125 if (!IsEqualGUID(iid, &IID_IEnumACString))
126 trace("unknown interface queried\n");
128 return E_NOINTERFACE;
131 HRESULT STDMETHODCALLTYPE TestACL_Next(IEnumString *iface, ULONG celt, LPOLESTR *rgelt, ULONG *pceltFetched)
133 TestACL *This = (TestACL *)iface;
136 trace("ACL(%p): read %d item(s)\n", This, celt);
137 for (i = 0; i < celt; i++)
139 if (This->pos >= This->limit)
141 rgelt[i] = strdup_AtoW(This->data[This->pos]);
152 HRESULT STDMETHODCALLTYPE TestACL_Skip(IEnumString *iface, ULONG celt)
154 ok(FALSE, "Unexpected call to TestACL_Skip\n");
158 HRESULT STDMETHODCALLTYPE TestACL_Clone(IEnumString *iface, IEnumString **out)
160 ok(FALSE, "Unexpected call to TestACL_Clone\n");
161 return E_OUTOFMEMORY;
164 HRESULT STDMETHODCALLTYPE TestACL_Reset(IEnumString *iface)
166 TestACL *This = (TestACL *)iface;
167 trace("ACL(%p): Reset\n", This);
172 HRESULT STDMETHODCALLTYPE TestACL_Expand(IACList *iface, LPCOLESTR str)
174 TestACL *This = impl_from_IACList(iface);
175 trace("ACL(%p): Expand\n", impl_from_IACList(iface));
180 IEnumStringVtbl TestACLVtbl =
182 TestACL_QueryInterface,
192 ULONG STDMETHODCALLTYPE TestACL_ACList_AddRef(IACList *iface)
194 return TestACL_AddRef((IEnumString *)impl_from_IACList(iface));
197 ULONG STDMETHODCALLTYPE TestACL_ACList_Release(IACList *iface)
199 return TestACL_Release((IEnumString *)impl_from_IACList(iface));
202 HRESULT STDMETHODCALLTYPE TestACL_ACList_QueryInterface(IACList *iface, REFIID iid, LPVOID *ppvout)
204 return TestACL_QueryInterface((IEnumString *)impl_from_IACList(iface), iid, ppvout);
207 IACListVtbl TestACL_ACListVtbl =
209 TestACL_ACList_QueryInterface,
210 TestACL_ACList_AddRef,
211 TestACL_ACList_Release,
216 #define expect_str(obj, str) \
218 ole_ok(obj->lpVtbl->Next(obj, 1, &wstr, &i)); \
219 ok(i == 1, "Expected i == 1, got %d\n", i); \
220 ok(str[0] == wstr[0], "String mismatch\n"); \
223 #define expect_end(obj) \
224 ok(obj->lpVtbl->Next(obj, 1, &wstr, &i) == S_FALSE, "Unexpected return from Next\n");
226 static void test_ACLMulti(void)
228 const char *strings1[] = {"a", "c", "e"};
229 const char *strings2[] = {"a", "b", "d"};
230 WCHAR exp[] = {'A','B','C',0};
232 TestACL *acl1, *acl2;
240 stop_on_error(CoCreateInstance(&CLSID_ACLMulti, NULL, CLSCTX_INPROC, &IID_IEnumString, (LPVOID *)&obj));
241 stop_on_error(obj->lpVtbl->QueryInterface(obj, &IID_IACList, (LPVOID *)&acl));
242 ok(obj->lpVtbl->QueryInterface(obj, &IID_IACList2, &tmp) == E_NOINTERFACE,
243 "Unexpected interface IACList2 in ACLMulti\n");
244 stop_on_error(obj->lpVtbl->QueryInterface(obj, &IID_IObjMgr, (LPVOID *)&mgr));
245 #if 0 /* IID_IEnumACString not defined yet in wine */
246 ole_ok(obj->lpVtbl->QueryInterface(obj, &IID_IEnumACString, &unk));
248 unk->lpVtbl->Release(unk);
251 ok(obj->lpVtbl->Next(obj, 1, (LPOLESTR *)&tmp, &i) == S_FALSE, "Unexpected return from Next\n");
252 ok(i == 0, "Unexpected fetched value %d\n", i);
253 ok(obj->lpVtbl->Next(obj, 44, (LPOLESTR *)&tmp, &i) == S_FALSE, "Unexpected return from Next\n");
254 ok(obj->lpVtbl->Skip(obj, 1) == E_NOTIMPL, "Unexpected return from Skip\n");
255 ok(obj->lpVtbl->Clone(obj, (IEnumString **)&tmp) == E_OUTOFMEMORY, "Unexpected return from Clone\n");
256 ole_ok(acl->lpVtbl->Expand(acl, exp));
258 acl1 = TestACL_Constructor(3, strings1);
259 acl2 = TestACL_Constructor(3, strings2);
260 stop_on_error(mgr->lpVtbl->Append(mgr, (IUnknown *)acl1));
261 stop_on_error(mgr->lpVtbl->Append(mgr, (IUnknown *)acl2));
262 ok(mgr->lpVtbl->Append(mgr, NULL) == E_FAIL, "Unexpected return from Append\n");
263 expect_str(obj, "a");
264 expect_str(obj, "c");
265 expect_str(obj, "e");
266 expect_str(obj, "a");
267 expect_str(obj, "b");
268 expect_str(obj, "d");
271 ole_ok(obj->lpVtbl->Reset(obj));
272 ok(acl1->pos == 0, "acl1 not reset\n");
273 ok(acl2->pos == 0, "acl2 not reset\n");
275 ole_ok(acl->lpVtbl->Expand(acl, exp));
276 ok(acl1->expcount == 1, "expcount - expected 1, got %d\n", acl1->expcount);
277 ok(acl2->expcount == 0 /* XP */ || acl2->expcount == 1 /* Vista */,
278 "expcount - expected 0 or 1, got %d\n", acl2->expcount);
280 ole_ok(obj->lpVtbl->Next(obj, 15, wstrtab, &i));
281 ok(i == 1, "Expected i == 1, got %d\n", i);
282 ole_ok(obj->lpVtbl->Next(obj, 15, wstrtab, &i));
283 ole_ok(obj->lpVtbl->Next(obj, 15, wstrtab, &i));
284 ole_ok(obj->lpVtbl->Next(obj, 15, wstrtab, &i));
285 ole_ok(acl->lpVtbl->Expand(acl, exp));
286 ok(acl1->expcount == 2, "expcount - expected 1, got %d\n", acl1->expcount);
287 ok(acl2->expcount == 0 /* XP */ || acl2->expcount == 2 /* Vista */,
288 "expcount - expected 0 or 2, got %d\n", acl2->expcount);
289 acl1->expret = S_FALSE;
290 ole_ok(acl->lpVtbl->Expand(acl, exp));
291 ok(acl1->expcount == 3, "expcount - expected 1, got %d\n", acl1->expcount);
292 ok(acl2->expcount == 1 /* XP */ || acl2->expcount == 3 /* Vista */,
293 "expcount - expected 0 or 3, got %d\n", acl2->expcount);
294 acl1->expret = E_NOTIMPL;
295 ole_ok(acl->lpVtbl->Expand(acl, exp));
296 ok(acl1->expcount == 4, "expcount - expected 1, got %d\n", acl1->expcount);
297 ok(acl2->expcount == 2 /* XP */ || acl2->expcount == 4 /* Vista */,
298 "expcount - expected 0 or 4, got %d\n", acl2->expcount);
299 acl2->expret = E_OUTOFMEMORY;
300 ok(acl->lpVtbl->Expand(acl, exp) == E_OUTOFMEMORY, "Unexpected Expand return\n");
301 acl2->expret = E_FAIL;
302 ok(acl->lpVtbl->Expand(acl, exp) == E_FAIL, "Unexpected Expand return\n");
304 stop_on_error(mgr->lpVtbl->Remove(mgr, (IUnknown *)acl1));
305 ok(acl1->ref == 1, "acl1 not released\n");
307 obj->lpVtbl->Reset(obj);
308 expect_str(obj, "a");
309 expect_str(obj, "b");
310 expect_str(obj, "d");
313 obj->lpVtbl->Release(obj);
314 acl->lpVtbl->Release(acl);
315 ok(mgr->lpVtbl->Release(mgr) == 0, "Unexpected references\n");
316 ok(acl1->ref == 1, "acl1 not released\n");
317 ok(acl2->ref == 1, "acl2 not released\n");
320 START_TEST(autocomplete)