1 /* Unit test suite for SHLWAPI Compact List and IStream ordinal functions
3 * Copyright 2002 Jon Griffiths
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 #include "wine/test.h"
24 typedef struct tagSHLWAPI_CLIST
28 } SHLWAPI_CLIST, *LPSHLWAPI_CLIST;
30 typedef const SHLWAPI_CLIST* LPCSHLWAPI_CLIST;
33 static const SHLWAPI_CLIST SHLWAPI_CLIST_items[] =
49 /* Dummy IStream object for testing calls */
65 LPCSHLWAPI_CLIST item;
70 HRESULT WINAPI QueryInterface(_IDummyStream *This,REFIID riid, LPVOID *ppvObj)
75 static ULONG WINAPI AddRef(_IDummyStream *This)
80 static ULONG WINAPI Release(_IDummyStream *This)
85 static HRESULT WINAPI Read(_IDummyStream* This, LPVOID lpMem, ULONG ulSize,
91 if (This->failreadcall)
93 return STG_E_ACCESSDENIED;
95 else if (This->failreadsize)
100 else if (This->readreturnlarge)
102 *((ULONG*)lpMem) = 0xffff01;
104 This->readreturnlarge = FALSE;
107 if (ulSize == sizeof(ULONG))
109 /* Read size of item */
110 *((ULONG*)lpMem) = This->item->ulSize ? This->item->ulSize + sizeof(SHLWAPI_CLIST) : 0;
116 char* buff = (char*)lpMem;
119 if (!This->item->ulSize)
121 This->readbeyondend = TRUE;
123 return E_FAIL; /* Should never happen */
125 *((ULONG*)lpMem) = This->item->ulId;
128 for (i = 0; i < This->item->ulSize; i++)
136 static HRESULT WINAPI Write(_IDummyStream* This, LPVOID lpMem, ULONG ulSize,
142 if (This->failwritecall)
144 return STG_E_ACCESSDENIED;
146 else if (This->failwritesize)
155 static HRESULT WINAPI Seek(_IDummyStream* This, LARGE_INTEGER dlibMove,
156 DWORD dwOrigin, ULARGE_INTEGER* plibNewPosition)
159 This->pos.QuadPart = dlibMove.QuadPart;
161 plibNewPosition->QuadPart = dlibMove.QuadPart;
165 static HRESULT WINAPI Stat(_IDummyStream* This, STATSTG* pstatstg,
169 if (This->failstatcall)
172 pstatstg->cbSize.QuadPart = This->pos.QuadPart;
177 static void* iclvt[] =
189 NULL, /* LockRegion */
190 NULL, /* UnlockRegion */
195 /* Function ptrs for ordinal calls */
196 static HMODULE SHLWAPI_hshlwapi = 0;
198 static VOID (WINAPI *pSHLWAPI_19)(LPSHLWAPI_CLIST);
199 static HRESULT (WINAPI *pSHLWAPI_20)(LPSHLWAPI_CLIST*,LPCSHLWAPI_CLIST);
200 static BOOL (WINAPI *pSHLWAPI_21)(LPSHLWAPI_CLIST*,ULONG);
201 static LPSHLWAPI_CLIST (WINAPI *pSHLWAPI_22)(LPSHLWAPI_CLIST,ULONG);
202 static HRESULT (WINAPI *pSHLWAPI_17)(_IDummyStream*,LPSHLWAPI_CLIST);
203 static HRESULT (WINAPI *pSHLWAPI_18)(_IDummyStream*,LPSHLWAPI_CLIST*);
205 static BOOL (WINAPI *pSHLWAPI_166)(_IDummyStream*);
206 static HRESULT (WINAPI *pSHLWAPI_184)(_IDummyStream*,LPVOID,ULONG);
207 static HRESULT (WINAPI *pSHLWAPI_212)(_IDummyStream*,LPCVOID,ULONG);
208 static HRESULT (WINAPI *pSHLWAPI_213)(_IDummyStream*);
209 static HRESULT (WINAPI *pSHLWAPI_214)(_IDummyStream*,ULARGE_INTEGER*);
212 static void InitFunctionPtrs()
214 SHLWAPI_hshlwapi = LoadLibraryA("shlwapi.dll");
215 ok(SHLWAPI_hshlwapi != 0, "LoadLibrary failed");
216 if (SHLWAPI_hshlwapi)
218 pSHLWAPI_17 = (void *)GetProcAddress( SHLWAPI_hshlwapi, (LPSTR)17);
219 ok(pSHLWAPI_17 != 0, "No Ordinal 17");
220 pSHLWAPI_18 = (void *)GetProcAddress( SHLWAPI_hshlwapi, (LPSTR)18);
221 ok(pSHLWAPI_18 != 0, "No Ordinal 18");
222 pSHLWAPI_19 = (void *)GetProcAddress( SHLWAPI_hshlwapi, (LPSTR)19);
223 ok(pSHLWAPI_19 != 0, "No Ordinal 19");
224 pSHLWAPI_20 = (void *)GetProcAddress( SHLWAPI_hshlwapi, (LPSTR)20);
225 ok(pSHLWAPI_20 != 0, "No Ordinal 20");
226 pSHLWAPI_21 = (void *)GetProcAddress( SHLWAPI_hshlwapi, (LPSTR)21);
227 ok(pSHLWAPI_21 != 0, "No Ordinal 21");
228 pSHLWAPI_22 = (void *)GetProcAddress( SHLWAPI_hshlwapi, (LPSTR)22);
229 ok(pSHLWAPI_22 != 0, "No Ordinal 22");
230 pSHLWAPI_166 = (void *)GetProcAddress( SHLWAPI_hshlwapi, (LPSTR)166);
231 ok(pSHLWAPI_166 != 0, "No Ordinal 166");
232 pSHLWAPI_184 = (void *)GetProcAddress( SHLWAPI_hshlwapi, (LPSTR)184);
233 ok(pSHLWAPI_184 != 0, "No Ordinal 184");
234 pSHLWAPI_212 = (void *)GetProcAddress( SHLWAPI_hshlwapi, (LPSTR)212);
235 ok(pSHLWAPI_212 != 0, "No Ordinal 212");
236 pSHLWAPI_213 = (void *)GetProcAddress( SHLWAPI_hshlwapi, (LPSTR)213);
237 ok(pSHLWAPI_213 != 0, "No Ordinal 213");
238 pSHLWAPI_214 = (void *)GetProcAddress( SHLWAPI_hshlwapi, (LPSTR)214);
239 ok(pSHLWAPI_214 != 0, "No Ordinal 214");
243 static void InitDummyStream(_IDummyStream* iface)
245 iface->lpVtbl = (void*)iclvt;
247 iface->readcalls = 0;
248 iface->failreadcall = FALSE;
249 iface->failreadsize = FALSE;
250 iface->readbeyondend = FALSE;
251 iface->readreturnlarge = FALSE;
252 iface->writecalls = 0;
253 iface->failwritecall = FALSE;
254 iface->failwritesize = FALSE;
255 iface->seekcalls = 0;
256 iface->statcalls = 0;
257 iface->failstatcall = FALSE;
258 iface->item = SHLWAPI_CLIST_items;
259 iface->pos.QuadPart = 0;
263 static void test_CList(void)
265 _IDummyStream streamobj;
266 LPSHLWAPI_CLIST list = NULL;
267 LPCSHLWAPI_CLIST item = SHLWAPI_CLIST_items;
269 LPSHLWAPI_CLIST inserted;
273 if (!pSHLWAPI_17 || !pSHLWAPI_18 || !pSHLWAPI_19 || !pSHLWAPI_20 ||
274 !pSHLWAPI_21 || !pSHLWAPI_22)
277 /* Populate a list and test the items are added correctly */
280 /* Create item and fill with data */
281 inserted = (LPSHLWAPI_CLIST)buff;
282 inserted->ulSize = item->ulSize + sizeof(SHLWAPI_CLIST);
283 inserted->ulId = item->ulId;
284 for (i = 0; i < item->ulSize; i++)
285 buff[sizeof(SHLWAPI_CLIST)+i] = i*2;
288 hRet = pSHLWAPI_20(&list, inserted);
289 ok(hRet > S_OK, "failed list add");
293 ok(list && list->ulSize, "item not added");
296 inserted = pSHLWAPI_22(list, item->ulId);
297 ok(inserted != NULL, "lost after adding");
299 ok(!inserted || inserted->ulId != -1, "find returned a container");
302 if (inserted && inserted->ulSize & 0x3)
305 ok(inserted[-1].ulId == -1, "invalid size is not countained");
306 ok(inserted[-1].ulSize > inserted->ulSize+sizeof(SHLWAPI_CLIST),
307 "container too small");
311 ok(inserted->ulSize==item->ulSize+sizeof(SHLWAPI_CLIST),
312 "id %ld size wrong (%ld!=%ld)", inserted->ulId, inserted->ulSize,
313 item->ulSize+sizeof(SHLWAPI_CLIST));
318 LPBYTE bufftest = (LPBYTE)inserted;
320 for (i = 0; i < inserted->ulSize - sizeof(SHLWAPI_CLIST); i++)
321 if (bufftest[sizeof(SHLWAPI_CLIST)+i] != i*2)
324 ok(bDataOK == TRUE, "data corrupted on insert");
326 ok(!inserted || inserted->ulId==item->ulId, "find got wrong item");
332 InitDummyStream(&streamobj);
334 hRet = pSHLWAPI_17(&streamobj, list);
335 ok(hRet == S_OK, "write failed");
338 /* 1 call for each element, + 1 for OK (use our null element for this) */
339 ok(streamobj.writecalls == sizeof(SHLWAPI_CLIST_items)/sizeof(SHLWAPI_CLIST),
341 ok(streamobj.readcalls == 0,"called Read() in write");
342 ok(streamobj.seekcalls == 0,"called Seek() in write");
345 /* Failure cases for writing */
346 InitDummyStream(&streamobj);
347 streamobj.failwritecall = TRUE;
348 hRet = pSHLWAPI_17(&streamobj, list);
349 ok(hRet == STG_E_ACCESSDENIED, "changed object failure return");
350 ok(streamobj.writecalls == 1, "called object after failure");
351 ok(streamobj.readcalls == 0,"called Read() after failure");
352 ok(streamobj.seekcalls == 0,"called Seek() after failure");
354 InitDummyStream(&streamobj);
355 streamobj.failwritesize = TRUE;
356 hRet = pSHLWAPI_17(&streamobj, list);
357 ok(hRet == STG_E_MEDIUMFULL, "changed size failure return");
358 ok(streamobj.writecalls == 1, "called object after size failure");
359 ok(streamobj.readcalls == 0,"called Read() after failure");
360 ok(streamobj.seekcalls == 0,"called Seek() after failure");
362 /* Invalid inputs for adding */
363 inserted = (LPSHLWAPI_CLIST)buff;
364 inserted->ulSize = sizeof(SHLWAPI_CLIST) -1;
366 hRet = pSHLWAPI_20(&list, inserted);
367 /* The call succeeds but the item is not inserted */
368 ok(hRet == S_OK, "failed bad element size");
369 inserted = pSHLWAPI_22(list, 33);
370 ok(inserted == NULL, "inserted bad element size");
372 inserted = (LPSHLWAPI_CLIST)buff;
373 inserted->ulSize = 44;
375 hRet = pSHLWAPI_20(&list, inserted);
376 /* The call succeeds but the item is not inserted */
377 ok(hRet == S_OK, "failed adding a container");
379 item = SHLWAPI_CLIST_items;
381 /* Look for non-existing item in populated list */
382 inserted = pSHLWAPI_22(list, 99999999);
383 ok(inserted == NULL, "found a non-existing item");
388 BOOL bRet = pSHLWAPI_21(&list, item->ulId);
389 ok(bRet == TRUE, "couldn't find item to delete");
393 /* Look for non-existing item in empty list */
394 inserted = pSHLWAPI_22(list, 99999999);
395 ok(inserted == NULL, "found an item in empty list");
397 /* Create a list by reading in data */
398 InitDummyStream(&streamobj);
400 hRet = pSHLWAPI_18(&streamobj, &list);
401 ok(hRet == S_OK, "failed create from Read()");
404 ok(streamobj.readbeyondend == FALSE, "read beyond end");
405 /* 2 calls per item, but only 1 for the terminator */
406 ok(streamobj.readcalls == sizeof(SHLWAPI_CLIST_items)/sizeof(SHLWAPI_CLIST)*2-1,
408 ok(streamobj.writecalls == 0, "called Write() from create");
409 ok(streamobj.seekcalls == 0,"called Seek() from create");
411 item = SHLWAPI_CLIST_items;
413 /* Check the items were added correctly */
416 inserted = pSHLWAPI_22(list, item->ulId);
417 ok(inserted != NULL, "lost after adding");
419 ok(!inserted || inserted->ulId != -1, "find returned a container");
422 if (inserted && inserted->ulSize & 0x3)
425 ok(inserted[-1].ulId == -1, "invalid size is not countained");
426 ok(inserted[-1].ulSize > inserted->ulSize+sizeof(SHLWAPI_CLIST),
427 "container too small");
431 ok(inserted->ulSize==item->ulSize+sizeof(SHLWAPI_CLIST),
432 "id %ld size wrong (%ld!=%ld)", inserted->ulId, inserted->ulSize,
433 item->ulSize+sizeof(SHLWAPI_CLIST));
435 ok(!inserted || inserted->ulId==item->ulId, "find got wrong item");
439 LPBYTE bufftest = (LPBYTE)inserted;
441 for (i = 0; i < inserted->ulSize - sizeof(SHLWAPI_CLIST); i++)
442 if (bufftest[sizeof(SHLWAPI_CLIST)+i] != i*2)
445 ok(bDataOK == TRUE, "data corrupted on insert");
451 /* Failure cases for reading */
452 InitDummyStream(&streamobj);
453 streamobj.failreadcall = TRUE;
454 hRet = pSHLWAPI_18(&streamobj, &list);
455 ok(hRet == STG_E_ACCESSDENIED, "changed object failure return");
456 ok(streamobj.readbeyondend == FALSE, "read beyond end");
457 ok(streamobj.readcalls == 1, "called object after read failure");
458 ok(streamobj.writecalls == 0,"called Write() after read failure");
459 ok(streamobj.seekcalls == 0,"called Seek() after read failure");
461 /* Read returns large object */
462 InitDummyStream(&streamobj);
463 streamobj.readreturnlarge = TRUE;
464 hRet = pSHLWAPI_18(&streamobj, &list);
465 ok(hRet == S_OK, "failed create from Read() with large item");
466 ok(streamobj.readbeyondend == FALSE, "read beyond end");
467 ok(streamobj.readcalls == 1,"wrong call count");
468 ok(streamobj.writecalls == 0,"called Write() after read failure");
469 ok(streamobj.seekcalls == 2,"wrong Seek() call count (%d)", streamobj.seekcalls);
474 static void test_SHLWAPI_166(void)
476 _IDummyStream streamobj;
482 InitDummyStream(&streamobj);
483 bRet = pSHLWAPI_166(&streamobj);
485 ok(bRet == TRUE, "failed before seek adjusted");
486 ok(streamobj.readcalls == 0, "called Read()");
487 ok(streamobj.writecalls == 0, "called Write()");
488 ok(streamobj.seekcalls == 0, "called Seek()");
489 ok(streamobj.statcalls == 1, "wrong call count");
491 streamobj.statcalls = 0;
492 streamobj.pos.QuadPart = 50001;
494 bRet = pSHLWAPI_166(&streamobj);
496 ok(bRet == FALSE, "failed after seek adjusted");
497 ok(streamobj.readcalls == 0, "called Read()");
498 ok(streamobj.writecalls == 0, "called Write()");
499 ok(streamobj.seekcalls == 0, "called Seek()");
500 ok(streamobj.statcalls == 1, "wrong call count");
503 InitDummyStream(&streamobj);
504 streamobj.pos.QuadPart = 50001;
505 streamobj.failstatcall = TRUE; /* 1: Stat() Bad, Read() OK */
506 bRet = pSHLWAPI_166(&streamobj);
507 ok(bRet == FALSE, "should be FALSE after read is OK");
508 ok(streamobj.readcalls == 1, "wrong call count");
509 ok(streamobj.writecalls == 0, "called Write()");
510 ok(streamobj.seekcalls == 1, "wrong call count");
511 ok(streamobj.statcalls == 1, "wrong call count");
512 ok(streamobj.pos.QuadPart == 0, "Didn't seek to start");
514 InitDummyStream(&streamobj);
515 streamobj.pos.QuadPart = 50001;
516 streamobj.failstatcall = TRUE;
517 streamobj.failreadcall = TRUE; /* 2: Stat() Bad, Read() Bad Also */
518 bRet = pSHLWAPI_166(&streamobj);
519 ok(bRet == TRUE, "Should be true after read fails");
520 ok(streamobj.readcalls == 1, "wrong call count");
521 ok(streamobj.writecalls == 0, "called Write()");
522 ok(streamobj.seekcalls == 0, "Called Seek()");
523 ok(streamobj.statcalls == 1, "wrong call count");
524 ok(streamobj.pos.QuadPart == 50001, "called Seek() after read failed");
527 static void test_SHLWAPI_184(void)
529 _IDummyStream streamobj;
536 InitDummyStream(&streamobj);
537 hRet = pSHLWAPI_184(&streamobj, buff, sizeof(buff));
539 ok(hRet == S_OK, "failed Read()");
540 ok(streamobj.readcalls == 1, "wrong call count");
541 ok(streamobj.writecalls == 0, "called Write()");
542 ok(streamobj.seekcalls == 0, "called Seek()");
545 static void test_SHLWAPI_212(void)
547 _IDummyStream streamobj;
554 InitDummyStream(&streamobj);
555 hRet = pSHLWAPI_212(&streamobj, buff, sizeof(buff));
557 ok(hRet == S_OK, "failed Write()");
558 ok(streamobj.readcalls == 0, "called Read()");
559 ok(streamobj.writecalls == 1, "wrong call count");
560 ok(streamobj.seekcalls == 0, "called Seek()");
563 static void test_SHLWAPI_213(void)
565 _IDummyStream streamobj;
570 if (!pSHLWAPI_213 || !pSHLWAPI_214)
573 InitDummyStream(&streamobj);
575 Seek(&streamobj, ll, 0, NULL); /* Seek to 5000l */
577 streamobj.seekcalls = 0;
578 pSHLWAPI_213(&streamobj); /* Should rewind */
579 ok(streamobj.statcalls == 0, "called Stat()");
580 ok(streamobj.readcalls == 0, "called Read()");
581 ok(streamobj.writecalls == 0, "called Write()");
582 ok(streamobj.seekcalls == 1, "wrong call count");
585 hRet = pSHLWAPI_214(&streamobj, &ul);
586 ok(hRet == S_OK, "failed Stat()");
587 ok(ul.QuadPart == 0, "213 didn't rewind stream");
590 static void test_SHLWAPI_214(void)
592 _IDummyStream streamobj;
600 InitDummyStream(&streamobj);
602 Seek(&streamobj, ll, 0, NULL);
604 streamobj.seekcalls = 0;
605 hRet = pSHLWAPI_214(&streamobj, &ul);
607 ok(hRet == S_OK, "failed Stat()");
608 ok(streamobj.statcalls == 1, "wrong call count");
609 ok(streamobj.readcalls == 0, "called Read()");
610 ok(streamobj.writecalls == 0, "called Write()");
611 ok(streamobj.seekcalls == 0, "called Seek()");
612 ok(ul.QuadPart == 5000l, "Stat gave wrong size");
627 if (SHLWAPI_hshlwapi)
628 FreeLibrary(SHLWAPI_hshlwapi);