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
22 #include "wine/test.h"
27 typedef struct tagSHLWAPI_CLIST
31 } SHLWAPI_CLIST
, *LPSHLWAPI_CLIST
;
33 typedef const SHLWAPI_CLIST
* LPCSHLWAPI_CLIST
;
36 static const SHLWAPI_CLIST SHLWAPI_CLIST_items
[] =
52 /* Dummy IStream object for testing calls */
68 LPCSHLWAPI_CLIST item
;
73 HRESULT WINAPI
QueryInterface(_IDummyStream
*This
,REFIID riid
, LPVOID
*ppvObj
)
78 static ULONG WINAPI
AddRef(_IDummyStream
*This
)
83 static ULONG WINAPI
Release(_IDummyStream
*This
)
88 static HRESULT WINAPI
Read(_IDummyStream
* This
, LPVOID lpMem
, ULONG ulSize
,
94 if (This
->failreadcall
)
96 return STG_E_ACCESSDENIED
;
98 else if (This
->failreadsize
)
100 *lpRead
= ulSize
+ 8;
103 else if (This
->readreturnlarge
)
105 *((ULONG
*)lpMem
) = 0xffff01;
107 This
->readreturnlarge
= FALSE
;
110 if (ulSize
== sizeof(ULONG
))
112 /* Read size of item */
113 *((ULONG
*)lpMem
) = This
->item
->ulSize
? This
->item
->ulSize
+ sizeof(SHLWAPI_CLIST
) : 0;
119 char* buff
= (char*)lpMem
;
122 if (!This
->item
->ulSize
)
124 This
->readbeyondend
= TRUE
;
126 return E_FAIL
; /* Should never happen */
128 *((ULONG
*)lpMem
) = This
->item
->ulId
;
131 for (i
= 0; i
< This
->item
->ulSize
; i
++)
139 static HRESULT WINAPI
Write(_IDummyStream
* This
, LPVOID lpMem
, ULONG ulSize
,
145 if (This
->failwritecall
)
147 return STG_E_ACCESSDENIED
;
149 else if (This
->failwritesize
)
158 static HRESULT WINAPI
Seek(_IDummyStream
* This
, LARGE_INTEGER dlibMove
,
159 DWORD dwOrigin
, ULARGE_INTEGER
* plibNewPosition
)
162 This
->pos
.QuadPart
= dlibMove
.QuadPart
;
164 plibNewPosition
->QuadPart
= dlibMove
.QuadPart
;
168 static HRESULT WINAPI
Stat(_IDummyStream
* This
, STATSTG
* pstatstg
,
172 if (This
->failstatcall
)
175 pstatstg
->cbSize
.QuadPart
= This
->pos
.QuadPart
;
180 static void* iclvt
[] =
192 NULL
, /* LockRegion */
193 NULL
, /* UnlockRegion */
198 /* Function ptrs for ordinal calls */
199 static HMODULE SHLWAPI_hshlwapi
= 0;
201 static VOID (WINAPI
*pSHLWAPI_19
)(LPSHLWAPI_CLIST
);
202 static HRESULT (WINAPI
*pSHLWAPI_20
)(LPSHLWAPI_CLIST
*,LPCSHLWAPI_CLIST
);
203 static BOOL (WINAPI
*pSHLWAPI_21
)(LPSHLWAPI_CLIST
*,ULONG
);
204 static LPSHLWAPI_CLIST (WINAPI
*pSHLWAPI_22
)(LPSHLWAPI_CLIST
,ULONG
);
205 static HRESULT (WINAPI
*pSHLWAPI_17
)(_IDummyStream
*,LPSHLWAPI_CLIST
);
206 static HRESULT (WINAPI
*pSHLWAPI_18
)(_IDummyStream
*,LPSHLWAPI_CLIST
*);
208 static BOOL (WINAPI
*pSHLWAPI_166
)(_IDummyStream
*);
209 static HRESULT (WINAPI
*pSHLWAPI_184
)(_IDummyStream
*,LPVOID
,ULONG
);
210 static HRESULT (WINAPI
*pSHLWAPI_212
)(_IDummyStream
*,LPCVOID
,ULONG
);
211 static HRESULT (WINAPI
*pSHLWAPI_213
)(_IDummyStream
*);
212 static HRESULT (WINAPI
*pSHLWAPI_214
)(_IDummyStream
*,ULARGE_INTEGER
*);
215 static void InitFunctionPtrs()
217 SHLWAPI_hshlwapi
= LoadLibraryA("shlwapi.dll");
218 ok(SHLWAPI_hshlwapi
!= 0, "LoadLibrary failed");
219 if (SHLWAPI_hshlwapi
)
221 pSHLWAPI_17
= (void *)GetProcAddress( SHLWAPI_hshlwapi
, (LPSTR
)17);
222 ok(pSHLWAPI_17
!= 0, "No Ordinal 17");
223 pSHLWAPI_18
= (void *)GetProcAddress( SHLWAPI_hshlwapi
, (LPSTR
)18);
224 ok(pSHLWAPI_18
!= 0, "No Ordinal 18");
225 pSHLWAPI_19
= (void *)GetProcAddress( SHLWAPI_hshlwapi
, (LPSTR
)19);
226 ok(pSHLWAPI_19
!= 0, "No Ordinal 19");
227 pSHLWAPI_20
= (void *)GetProcAddress( SHLWAPI_hshlwapi
, (LPSTR
)20);
228 ok(pSHLWAPI_20
!= 0, "No Ordinal 20");
229 pSHLWAPI_21
= (void *)GetProcAddress( SHLWAPI_hshlwapi
, (LPSTR
)21);
230 ok(pSHLWAPI_21
!= 0, "No Ordinal 21");
231 pSHLWAPI_22
= (void *)GetProcAddress( SHLWAPI_hshlwapi
, (LPSTR
)22);
232 ok(pSHLWAPI_22
!= 0, "No Ordinal 22");
233 pSHLWAPI_166
= (void *)GetProcAddress( SHLWAPI_hshlwapi
, (LPSTR
)166);
234 ok(pSHLWAPI_166
!= 0, "No Ordinal 166");
235 pSHLWAPI_184
= (void *)GetProcAddress( SHLWAPI_hshlwapi
, (LPSTR
)184);
236 ok(pSHLWAPI_184
!= 0, "No Ordinal 184");
237 pSHLWAPI_212
= (void *)GetProcAddress( SHLWAPI_hshlwapi
, (LPSTR
)212);
238 ok(pSHLWAPI_212
!= 0, "No Ordinal 212");
239 pSHLWAPI_213
= (void *)GetProcAddress( SHLWAPI_hshlwapi
, (LPSTR
)213);
240 ok(pSHLWAPI_213
!= 0, "No Ordinal 213");
241 pSHLWAPI_214
= (void *)GetProcAddress( SHLWAPI_hshlwapi
, (LPSTR
)214);
242 ok(pSHLWAPI_214
!= 0, "No Ordinal 214");
246 static void InitDummyStream(_IDummyStream
* iface
)
248 iface
->lpVtbl
= (void*)iclvt
;
250 iface
->readcalls
= 0;
251 iface
->failreadcall
= FALSE
;
252 iface
->failreadsize
= FALSE
;
253 iface
->readbeyondend
= FALSE
;
254 iface
->readreturnlarge
= FALSE
;
255 iface
->writecalls
= 0;
256 iface
->failwritecall
= FALSE
;
257 iface
->failwritesize
= FALSE
;
258 iface
->seekcalls
= 0;
259 iface
->statcalls
= 0;
260 iface
->failstatcall
= FALSE
;
261 iface
->item
= SHLWAPI_CLIST_items
;
262 iface
->pos
.QuadPart
= 0;
266 static void test_CList(void)
268 _IDummyStream streamobj
;
269 LPSHLWAPI_CLIST list
= NULL
;
270 LPCSHLWAPI_CLIST item
= SHLWAPI_CLIST_items
;
272 LPSHLWAPI_CLIST inserted
;
276 if (!pSHLWAPI_17
|| !pSHLWAPI_18
|| !pSHLWAPI_19
|| !pSHLWAPI_20
||
277 !pSHLWAPI_21
|| !pSHLWAPI_22
)
280 /* Populate a list and test the items are added correctly */
283 /* Create item and fill with data */
284 inserted
= (LPSHLWAPI_CLIST
)buff
;
285 inserted
->ulSize
= item
->ulSize
+ sizeof(SHLWAPI_CLIST
);
286 inserted
->ulId
= item
->ulId
;
287 for (i
= 0; i
< item
->ulSize
; i
++)
288 buff
[sizeof(SHLWAPI_CLIST
)+i
] = i
*2;
291 hRet
= pSHLWAPI_20(&list
, inserted
);
292 ok(hRet
> S_OK
, "failed list add");
296 ok(list
&& list
->ulSize
, "item not added");
299 inserted
= pSHLWAPI_22(list
, item
->ulId
);
300 ok(inserted
!= NULL
, "lost after adding");
302 ok(!inserted
|| inserted
->ulId
!= -1, "find returned a container");
305 if (inserted
&& inserted
->ulSize
& 0x3)
308 ok(inserted
[-1].ulId
== -1, "invalid size is not countained");
309 ok(inserted
[-1].ulSize
> inserted
->ulSize
+sizeof(SHLWAPI_CLIST
),
310 "container too small");
314 ok(inserted
->ulSize
==item
->ulSize
+sizeof(SHLWAPI_CLIST
),
315 "id %ld size wrong (%ld!=%ld)", inserted
->ulId
, inserted
->ulSize
,
316 item
->ulSize
+sizeof(SHLWAPI_CLIST
));
321 LPBYTE bufftest
= (LPBYTE
)inserted
;
323 for (i
= 0; i
< inserted
->ulSize
- sizeof(SHLWAPI_CLIST
); i
++)
324 if (bufftest
[sizeof(SHLWAPI_CLIST
)+i
] != i
*2)
327 ok(bDataOK
== TRUE
, "data corrupted on insert");
329 ok(!inserted
|| inserted
->ulId
==item
->ulId
, "find got wrong item");
335 InitDummyStream(&streamobj
);
337 hRet
= pSHLWAPI_17(&streamobj
, list
);
338 ok(hRet
== S_OK
, "write failed");
341 /* 1 call for each element, + 1 for OK (use our null element for this) */
342 ok(streamobj
.writecalls
== sizeof(SHLWAPI_CLIST_items
)/sizeof(SHLWAPI_CLIST
),
344 ok(streamobj
.readcalls
== 0,"called Read() in write");
345 ok(streamobj
.seekcalls
== 0,"called Seek() in write");
348 /* Failure cases for writing */
349 InitDummyStream(&streamobj
);
350 streamobj
.failwritecall
= TRUE
;
351 hRet
= pSHLWAPI_17(&streamobj
, list
);
352 ok(hRet
== STG_E_ACCESSDENIED
, "changed object failure return");
353 ok(streamobj
.writecalls
== 1, "called object after failure");
354 ok(streamobj
.readcalls
== 0,"called Read() after failure");
355 ok(streamobj
.seekcalls
== 0,"called Seek() after failure");
357 InitDummyStream(&streamobj
);
358 streamobj
.failwritesize
= TRUE
;
359 hRet
= pSHLWAPI_17(&streamobj
, list
);
360 ok(hRet
== STG_E_MEDIUMFULL
, "changed size failure return");
361 ok(streamobj
.writecalls
== 1, "called object after size failure");
362 ok(streamobj
.readcalls
== 0,"called Read() after failure");
363 ok(streamobj
.seekcalls
== 0,"called Seek() after failure");
365 /* Invalid inputs for adding */
366 inserted
= (LPSHLWAPI_CLIST
)buff
;
367 inserted
->ulSize
= sizeof(SHLWAPI_CLIST
) -1;
369 hRet
= pSHLWAPI_20(&list
, inserted
);
370 /* The call succeeds but the item is not inserted */
371 ok(hRet
== S_OK
, "failed bad element size");
372 inserted
= pSHLWAPI_22(list
, 33);
373 ok(inserted
== NULL
, "inserted bad element size");
375 inserted
= (LPSHLWAPI_CLIST
)buff
;
376 inserted
->ulSize
= 44;
378 hRet
= pSHLWAPI_20(&list
, inserted
);
379 /* The call succeeds but the item is not inserted */
380 ok(hRet
== S_OK
, "failed adding a container");
382 item
= SHLWAPI_CLIST_items
;
384 /* Look for non-existing item in populated list */
385 inserted
= pSHLWAPI_22(list
, 99999999);
386 ok(inserted
== NULL
, "found a non-existing item");
391 BOOL bRet
= pSHLWAPI_21(&list
, item
->ulId
);
392 ok(bRet
== TRUE
, "couldn't find item to delete");
396 /* Look for non-existing item in empty list */
397 inserted
= pSHLWAPI_22(list
, 99999999);
398 ok(inserted
== NULL
, "found an item in empty list");
400 /* Create a list by reading in data */
401 InitDummyStream(&streamobj
);
403 hRet
= pSHLWAPI_18(&streamobj
, &list
);
404 ok(hRet
== S_OK
, "failed create from Read()");
407 ok(streamobj
.readbeyondend
== FALSE
, "read beyond end");
408 /* 2 calls per item, but only 1 for the terminator */
409 ok(streamobj
.readcalls
== sizeof(SHLWAPI_CLIST_items
)/sizeof(SHLWAPI_CLIST
)*2-1,
411 ok(streamobj
.writecalls
== 0, "called Write() from create");
412 ok(streamobj
.seekcalls
== 0,"called Seek() from create");
414 item
= SHLWAPI_CLIST_items
;
416 /* Check the items were added correctly */
419 inserted
= pSHLWAPI_22(list
, item
->ulId
);
420 ok(inserted
!= NULL
, "lost after adding");
422 ok(!inserted
|| inserted
->ulId
!= -1, "find returned a container");
425 if (inserted
&& inserted
->ulSize
& 0x3)
428 ok(inserted
[-1].ulId
== -1, "invalid size is not countained");
429 ok(inserted
[-1].ulSize
> inserted
->ulSize
+sizeof(SHLWAPI_CLIST
),
430 "container too small");
434 ok(inserted
->ulSize
==item
->ulSize
+sizeof(SHLWAPI_CLIST
),
435 "id %ld size wrong (%ld!=%ld)", inserted
->ulId
, inserted
->ulSize
,
436 item
->ulSize
+sizeof(SHLWAPI_CLIST
));
438 ok(!inserted
|| inserted
->ulId
==item
->ulId
, "find got wrong item");
442 LPBYTE bufftest
= (LPBYTE
)inserted
;
444 for (i
= 0; i
< inserted
->ulSize
- sizeof(SHLWAPI_CLIST
); i
++)
445 if (bufftest
[sizeof(SHLWAPI_CLIST
)+i
] != i
*2)
448 ok(bDataOK
== TRUE
, "data corrupted on insert");
454 /* Failure cases for reading */
455 InitDummyStream(&streamobj
);
456 streamobj
.failreadcall
= TRUE
;
457 hRet
= pSHLWAPI_18(&streamobj
, &list
);
458 ok(hRet
== STG_E_ACCESSDENIED
, "changed object failure return");
459 ok(streamobj
.readbeyondend
== FALSE
, "read beyond end");
460 ok(streamobj
.readcalls
== 1, "called object after read failure");
461 ok(streamobj
.writecalls
== 0,"called Write() after read failure");
462 ok(streamobj
.seekcalls
== 0,"called Seek() after read failure");
464 /* Read returns large object */
465 InitDummyStream(&streamobj
);
466 streamobj
.readreturnlarge
= TRUE
;
467 hRet
= pSHLWAPI_18(&streamobj
, &list
);
468 ok(hRet
== S_OK
, "failed create from Read() with large item");
469 ok(streamobj
.readbeyondend
== FALSE
, "read beyond end");
470 ok(streamobj
.readcalls
== 1,"wrong call count");
471 ok(streamobj
.writecalls
== 0,"called Write() after read failure");
472 ok(streamobj
.seekcalls
== 2,"wrong Seek() call count (%d)", streamobj
.seekcalls
);
477 static void test_SHLWAPI_166(void)
479 _IDummyStream streamobj
;
485 InitDummyStream(&streamobj
);
486 bRet
= pSHLWAPI_166(&streamobj
);
488 ok(bRet
== TRUE
, "failed before seek adjusted");
489 ok(streamobj
.readcalls
== 0, "called Read()");
490 ok(streamobj
.writecalls
== 0, "called Write()");
491 ok(streamobj
.seekcalls
== 0, "called Seek()");
492 ok(streamobj
.statcalls
== 1, "wrong call count");
494 streamobj
.statcalls
= 0;
495 streamobj
.pos
.QuadPart
= 50001;
497 bRet
= pSHLWAPI_166(&streamobj
);
499 ok(bRet
== FALSE
, "failed after seek adjusted");
500 ok(streamobj
.readcalls
== 0, "called Read()");
501 ok(streamobj
.writecalls
== 0, "called Write()");
502 ok(streamobj
.seekcalls
== 0, "called Seek()");
503 ok(streamobj
.statcalls
== 1, "wrong call count");
506 InitDummyStream(&streamobj
);
507 streamobj
.pos
.QuadPart
= 50001;
508 streamobj
.failstatcall
= TRUE
; /* 1: Stat() Bad, Read() OK */
509 bRet
= pSHLWAPI_166(&streamobj
);
510 ok(bRet
== FALSE
, "should be FALSE after read is OK");
511 ok(streamobj
.readcalls
== 1, "wrong call count");
512 ok(streamobj
.writecalls
== 0, "called Write()");
513 ok(streamobj
.seekcalls
== 1, "wrong call count");
514 ok(streamobj
.statcalls
== 1, "wrong call count");
515 ok(streamobj
.pos
.QuadPart
== 0, "Didn't seek to start");
517 InitDummyStream(&streamobj
);
518 streamobj
.pos
.QuadPart
= 50001;
519 streamobj
.failstatcall
= TRUE
;
520 streamobj
.failreadcall
= TRUE
; /* 2: Stat() Bad, Read() Bad Also */
521 bRet
= pSHLWAPI_166(&streamobj
);
522 ok(bRet
== TRUE
, "Should be true after read fails");
523 ok(streamobj
.readcalls
== 1, "wrong call count");
524 ok(streamobj
.writecalls
== 0, "called Write()");
525 ok(streamobj
.seekcalls
== 0, "Called Seek()");
526 ok(streamobj
.statcalls
== 1, "wrong call count");
527 ok(streamobj
.pos
.QuadPart
== 50001, "called Seek() after read failed");
530 static void test_SHLWAPI_184(void)
532 _IDummyStream streamobj
;
539 InitDummyStream(&streamobj
);
540 hRet
= pSHLWAPI_184(&streamobj
, buff
, sizeof(buff
));
542 ok(hRet
== S_OK
, "failed Read()");
543 ok(streamobj
.readcalls
== 1, "wrong call count");
544 ok(streamobj
.writecalls
== 0, "called Write()");
545 ok(streamobj
.seekcalls
== 0, "called Seek()");
548 static void test_SHLWAPI_212(void)
550 _IDummyStream streamobj
;
557 InitDummyStream(&streamobj
);
558 hRet
= pSHLWAPI_212(&streamobj
, buff
, sizeof(buff
));
560 ok(hRet
== S_OK
, "failed Write()");
561 ok(streamobj
.readcalls
== 0, "called Read()");
562 ok(streamobj
.writecalls
== 1, "wrong call count");
563 ok(streamobj
.seekcalls
== 0, "called Seek()");
566 static void test_SHLWAPI_213(void)
568 _IDummyStream streamobj
;
573 if (!pSHLWAPI_213
|| !pSHLWAPI_214
)
576 InitDummyStream(&streamobj
);
578 Seek(&streamobj
, ll
, 0, NULL
); /* Seek to 5000l */
580 streamobj
.seekcalls
= 0;
581 pSHLWAPI_213(&streamobj
); /* Should rewind */
582 ok(streamobj
.statcalls
== 0, "called Stat()");
583 ok(streamobj
.readcalls
== 0, "called Read()");
584 ok(streamobj
.writecalls
== 0, "called Write()");
585 ok(streamobj
.seekcalls
== 1, "wrong call count");
588 hRet
= pSHLWAPI_214(&streamobj
, &ul
);
589 ok(hRet
== S_OK
, "failed Stat()");
590 ok(ul
.QuadPart
== 0, "213 didn't rewind stream");
593 static void test_SHLWAPI_214(void)
595 _IDummyStream streamobj
;
603 InitDummyStream(&streamobj
);
605 Seek(&streamobj
, ll
, 0, NULL
);
607 streamobj
.seekcalls
= 0;
608 hRet
= pSHLWAPI_214(&streamobj
, &ul
);
610 ok(hRet
== S_OK
, "failed Stat()");
611 ok(streamobj
.statcalls
== 1, "wrong call count");
612 ok(streamobj
.readcalls
== 0, "called Read()");
613 ok(streamobj
.writecalls
== 0, "called Write()");
614 ok(streamobj
.seekcalls
== 0, "called Seek()");
615 ok(ul
.QuadPart
== 5000l, "Stat gave wrong size");
630 if (SHLWAPI_hshlwapi
)
631 FreeLibrary(SHLWAPI_hshlwapi
);