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
27 #include "wine/test.h"
29 #define stop_on_error(exp) \
31 HRESULT res = (exp); \
34 ok(FALSE, #exp " failed: %x\n", res); \
41 HRESULT res = (exp); \
43 ok(FALSE, #exp " failed: %x\n", res); \
46 LPWSTR strdup_AtoW(LPCSTR str)
48 int size = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
49 LPWSTR wstr = (LPWSTR)CoTaskMemAlloc((size + 1)*sizeof(WCHAR));
50 MultiByteToWideChar(CP_ACP, 0, str, -1, wstr, size+1);
56 IEnumStringVtbl *vtbl;
66 extern IEnumStringVtbl TestACLVtbl;
67 extern IACListVtbl TestACL_ACListVtbl;
69 static TestACL *impl_from_IACList(IACList *iface)
71 return (TestACL *)((char *)iface - FIELD_OFFSET(TestACL, aclVtbl));
74 static TestACL *TestACL_Constructor(int limit, const char **strings)
76 TestACL *This = CoTaskMemAlloc(sizeof(TestACL));
77 ZeroMemory(This, sizeof(*This));
78 This->vtbl = &TestACLVtbl;
79 This->aclVtbl = &TestACL_ACListVtbl;
87 ULONG STDMETHODCALLTYPE TestACL_AddRef(IEnumString *iface)
89 TestACL *This = (TestACL *)iface;
90 trace("ACL(%p): addref (%d)\n", This, This->ref+1);
91 return InterlockedIncrement(&This->ref);
94 ULONG STDMETHODCALLTYPE TestACL_Release(IEnumString *iface)
96 TestACL *This = (TestACL *)iface;
99 res = InterlockedDecrement(&This->ref);
100 trace("ACL(%p): release (%d)\n", This, res);
104 HRESULT STDMETHODCALLTYPE TestACL_QueryInterface(IEnumString *iface, REFIID iid, LPVOID *ppvOut)
106 TestACL *This = (TestACL *)iface;
108 if (IsEqualGUID(iid, &IID_IUnknown) || IsEqualGUID(iid, &IID_IEnumString))
112 else if (IsEqualGUID(iid, &IID_IACList))
114 *ppvOut = &This->aclVtbl;
119 iface->lpVtbl->AddRef(iface);
123 #if 0 /* IID_IEnumACString not defined yet in wine */
124 if (!IsEqualGUID(iid, &IID_IEnumACString))
125 trace("unknown interface queried\n");
127 return E_NOINTERFACE;
130 HRESULT STDMETHODCALLTYPE TestACL_Next(IEnumString *iface, ULONG celt, LPOLESTR *rgelt, ULONG *pceltFetched)
132 TestACL *This = (TestACL *)iface;
135 trace("ACL(%p): read %d item(s)\n", This, celt);
136 for (i = 0; i < celt; i++)
138 if (This->pos >= This->limit)
140 rgelt[i] = strdup_AtoW(This->data[This->pos]);
151 HRESULT STDMETHODCALLTYPE TestACL_Skip(IEnumString *iface, ULONG celt)
153 ok(FALSE, "Unexpected call to TestACL_Skip\n");
157 HRESULT STDMETHODCALLTYPE TestACL_Clone(IEnumString *iface, IEnumString **out)
159 ok(FALSE, "Unexpected call to TestACL_Clone\n");
160 return E_OUTOFMEMORY;
163 HRESULT STDMETHODCALLTYPE TestACL_Reset(IEnumString *iface)
165 TestACL *This = (TestACL *)iface;
166 trace("ACL(%p): Reset\n", This);
171 HRESULT STDMETHODCALLTYPE TestACL_Expand(IACList *iface, LPCOLESTR str)
173 TestACL *This = impl_from_IACList(iface);
174 trace("ACL(%p): Expand\n", impl_from_IACList(iface));
179 IEnumStringVtbl TestACLVtbl =
181 TestACL_QueryInterface,
191 ULONG STDMETHODCALLTYPE TestACL_ACList_AddRef(IACList *iface)
193 return TestACL_AddRef((IEnumString *)impl_from_IACList(iface));
196 ULONG STDMETHODCALLTYPE TestACL_ACList_Release(IACList *iface)
198 return TestACL_Release((IEnumString *)impl_from_IACList(iface));
201 HRESULT STDMETHODCALLTYPE TestACL_ACList_QueryInterface(IACList *iface, REFIID iid, LPVOID *ppvout)
203 return TestACL_QueryInterface((IEnumString *)impl_from_IACList(iface), iid, ppvout);
206 IACListVtbl TestACL_ACListVtbl =
208 TestACL_ACList_QueryInterface,
209 TestACL_ACList_AddRef,
210 TestACL_ACList_Release,
215 #define expect_str(obj, str) \
217 ole_ok(obj->lpVtbl->Next(obj, 1, &wstr, &i)); \
218 ok(i == 1, "Expected i == 1, got %d\n", i); \
219 ok(str[0] == wstr[0], "String mismatch\n"); \
222 #define expect_end(obj) \
223 ok(obj->lpVtbl->Next(obj, 1, &wstr, &i) == S_FALSE, "Unexpected return from Next\n");
225 static void test_ACLMulti(void)
227 const char *strings1[] = {"a", "c", "e"};
228 const char *strings2[] = {"a", "b", "d"};
229 WCHAR exp[] = {'A','B','C',0};
231 TestACL *acl1, *acl2;
239 stop_on_error(CoCreateInstance(&CLSID_ACLMulti, NULL, CLSCTX_INPROC, &IID_IEnumString, (LPVOID *)&obj));
240 stop_on_error(obj->lpVtbl->QueryInterface(obj, &IID_IACList, (LPVOID *)&acl));
241 ok(obj->lpVtbl->QueryInterface(obj, &IID_IACList2, &tmp) == E_NOINTERFACE,
242 "Unexpected interface IACList2 in ACLMulti\n");
243 stop_on_error(obj->lpVtbl->QueryInterface(obj, &IID_IObjMgr, (LPVOID *)&mgr));
244 #if 0 /* IID_IEnumACString not defined yet in wine */
245 ole_ok(obj->lpVtbl->QueryInterface(obj, &IID_IEnumACString, &unk));
247 unk->lpVtbl->Release(unk);
250 ok(obj->lpVtbl->Next(obj, 1, (LPOLESTR *)&tmp, &i) == S_FALSE, "Unexpected return from Next\n");
251 ok(i == 0, "Unexpected fetched value %d\n", i);
252 ok(obj->lpVtbl->Next(obj, 44, (LPOLESTR *)&tmp, &i) == S_FALSE, "Unexpected return from Next\n");
253 ok(obj->lpVtbl->Skip(obj, 1) == E_NOTIMPL, "Unexpected return from Skip\n");
254 ok(obj->lpVtbl->Clone(obj, (IEnumString **)&tmp) == E_OUTOFMEMORY, "Unexpected return from Clone\n");
255 ole_ok(acl->lpVtbl->Expand(acl, exp));
257 acl1 = TestACL_Constructor(3, strings1);
258 acl2 = TestACL_Constructor(3, strings2);
259 stop_on_error(mgr->lpVtbl->Append(mgr, (IUnknown *)acl1));
260 stop_on_error(mgr->lpVtbl->Append(mgr, (IUnknown *)acl2));
261 ok(mgr->lpVtbl->Append(mgr, NULL) == E_FAIL, "Unexpected return from Append\n");
262 expect_str(obj, "a");
263 expect_str(obj, "c");
264 expect_str(obj, "e");
265 expect_str(obj, "a");
266 expect_str(obj, "b");
267 expect_str(obj, "d");
270 ole_ok(obj->lpVtbl->Reset(obj));
271 ok(acl1->pos == 0, "acl1 not reset\n");
272 ok(acl2->pos == 0, "acl2 not reset\n");
274 ole_ok(acl->lpVtbl->Expand(acl, exp));
275 ok(acl1->expcount == 1, "expcount - expected 1, got %d\n", acl1->expcount);
276 ok(acl2->expcount == 0, "expcount - expected 0, got %d\n", acl2->expcount);
278 ole_ok(obj->lpVtbl->Next(obj, 15, wstrtab, &i));
279 ok(i == 1, "Expected i == 1, got %d\n", i);
280 ole_ok(obj->lpVtbl->Next(obj, 15, wstrtab, &i));
281 ole_ok(obj->lpVtbl->Next(obj, 15, wstrtab, &i));
282 ole_ok(obj->lpVtbl->Next(obj, 15, wstrtab, &i));
283 ole_ok(acl->lpVtbl->Expand(acl, exp));
284 ok(acl1->expcount == 2, "expcount - expected 1, got %d\n", acl1->expcount);
285 ok(acl2->expcount == 0, "expcount - expected 0, got %d\n", acl2->expcount);
286 acl1->expret = S_FALSE;
287 ole_ok(acl->lpVtbl->Expand(acl, exp));
288 ok(acl1->expcount == 3, "expcount - expected 1, got %d\n", acl1->expcount);
289 ok(acl2->expcount == 1, "expcount - expected 0, got %d\n", acl2->expcount);
290 acl1->expret = E_NOTIMPL;
291 ole_ok(acl->lpVtbl->Expand(acl, exp));
292 ok(acl1->expcount == 4, "expcount - expected 1, got %d\n", acl1->expcount);
293 ok(acl2->expcount == 2, "expcount - expected 0, got %d\n", acl2->expcount);
294 acl2->expret = E_OUTOFMEMORY;
295 ok(acl->lpVtbl->Expand(acl, exp) == E_OUTOFMEMORY, "Unexpected Expand return\n");
296 acl2->expret = E_FAIL;
297 ok(acl->lpVtbl->Expand(acl, exp) == E_FAIL, "Unexpected Expand return\n");
299 stop_on_error(mgr->lpVtbl->Remove(mgr, (IUnknown *)acl1));
300 ok(acl1->ref == 1, "acl1 not released\n");
302 obj->lpVtbl->Reset(obj);
303 expect_str(obj, "a");
304 expect_str(obj, "b");
305 expect_str(obj, "d");
308 obj->lpVtbl->Release(obj);
309 acl->lpVtbl->Release(acl);
310 ok(mgr->lpVtbl->Release(mgr) == 0, "Unexpected references\n");
311 ok(acl1->ref == 1, "acl1 not released\n");
312 ok(acl2->ref == 1, "acl2 not released\n");
315 START_TEST(autocomplete)