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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, 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
)
80 return InterlockedIncrement(&This
->ref
);
83 static ULONG WINAPI
Release(_IDummyStream
*This
)
85 return InterlockedDecrement(&This
->ref
);
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;
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 BOOL
InitFunctionPtrs(void)
217 SHLWAPI_hshlwapi
= GetModuleHandleA("shlwapi.dll");
219 /* SHCreateStreamOnFileEx was introduced in shlwapi v6.0 */
220 if(!GetProcAddress(SHLWAPI_hshlwapi
, "SHCreateStreamOnFileEx")){
221 win_skip("Too old shlwapi version\n");
225 pSHLWAPI_17
= (void *)GetProcAddress( SHLWAPI_hshlwapi
, (LPSTR
)17);
226 ok(pSHLWAPI_17
!= 0, "No Ordinal 17\n");
227 pSHLWAPI_18
= (void *)GetProcAddress( SHLWAPI_hshlwapi
, (LPSTR
)18);
228 ok(pSHLWAPI_18
!= 0, "No Ordinal 18\n");
229 pSHLWAPI_19
= (void *)GetProcAddress( SHLWAPI_hshlwapi
, (LPSTR
)19);
230 ok(pSHLWAPI_19
!= 0, "No Ordinal 19\n");
231 pSHLWAPI_20
= (void *)GetProcAddress( SHLWAPI_hshlwapi
, (LPSTR
)20);
232 ok(pSHLWAPI_20
!= 0, "No Ordinal 20\n");
233 pSHLWAPI_21
= (void *)GetProcAddress( SHLWAPI_hshlwapi
, (LPSTR
)21);
234 ok(pSHLWAPI_21
!= 0, "No Ordinal 21\n");
235 pSHLWAPI_22
= (void *)GetProcAddress( SHLWAPI_hshlwapi
, (LPSTR
)22);
236 ok(pSHLWAPI_22
!= 0, "No Ordinal 22\n");
237 pSHLWAPI_166
= (void *)GetProcAddress( SHLWAPI_hshlwapi
, (LPSTR
)166);
238 ok(pSHLWAPI_166
!= 0, "No Ordinal 166\n");
239 pSHLWAPI_184
= (void *)GetProcAddress( SHLWAPI_hshlwapi
, (LPSTR
)184);
240 ok(pSHLWAPI_184
!= 0, "No Ordinal 184\n");
241 pSHLWAPI_212
= (void *)GetProcAddress( SHLWAPI_hshlwapi
, (LPSTR
)212);
242 ok(pSHLWAPI_212
!= 0, "No Ordinal 212\n");
243 pSHLWAPI_213
= (void *)GetProcAddress( SHLWAPI_hshlwapi
, (LPSTR
)213);
244 ok(pSHLWAPI_213
!= 0, "No Ordinal 213\n");
245 pSHLWAPI_214
= (void *)GetProcAddress( SHLWAPI_hshlwapi
, (LPSTR
)214);
246 ok(pSHLWAPI_214
!= 0, "No Ordinal 214\n");
251 static void InitDummyStream(_IDummyStream
* iface
)
253 iface
->lpVtbl
= (void*)iclvt
;
255 iface
->readcalls
= 0;
256 iface
->failreadcall
= FALSE
;
257 iface
->failreadsize
= FALSE
;
258 iface
->readbeyondend
= FALSE
;
259 iface
->readreturnlarge
= FALSE
;
260 iface
->writecalls
= 0;
261 iface
->failwritecall
= FALSE
;
262 iface
->failwritesize
= FALSE
;
263 iface
->seekcalls
= 0;
264 iface
->statcalls
= 0;
265 iface
->failstatcall
= FALSE
;
266 iface
->item
= SHLWAPI_CLIST_items
;
267 iface
->pos
.QuadPart
= 0;
271 static void test_CList(void)
273 _IDummyStream streamobj
;
274 LPSHLWAPI_CLIST list
= NULL
;
275 LPCSHLWAPI_CLIST item
= SHLWAPI_CLIST_items
;
277 LPSHLWAPI_CLIST inserted
;
281 if (!pSHLWAPI_17
|| !pSHLWAPI_18
|| !pSHLWAPI_19
|| !pSHLWAPI_20
||
282 !pSHLWAPI_21
|| !pSHLWAPI_22
)
285 /* Populate a list and test the items are added correctly */
288 /* Create item and fill with data */
289 inserted
= (LPSHLWAPI_CLIST
)buff
;
290 inserted
->ulSize
= item
->ulSize
+ sizeof(SHLWAPI_CLIST
);
291 inserted
->ulId
= item
->ulId
;
292 for (i
= 0; i
< item
->ulSize
; i
++)
293 buff
[sizeof(SHLWAPI_CLIST
)+i
] = i
*2;
296 hRet
= pSHLWAPI_20(&list
, inserted
);
297 ok(hRet
> S_OK
, "failed list add\n");
301 ok(list
&& list
->ulSize
, "item not added\n");
304 inserted
= pSHLWAPI_22(list
, item
->ulId
);
305 ok(inserted
!= NULL
, "lost after adding\n");
307 ok(!inserted
|| inserted
->ulId
!= ~0U, "find returned a container\n");
310 if (inserted
&& inserted
->ulSize
& 0x3)
313 ok(inserted
[-1].ulId
== ~0U, "invalid size is not countained\n");
314 ok(inserted
[-1].ulSize
> inserted
->ulSize
+sizeof(SHLWAPI_CLIST
),
315 "container too small\n");
319 ok(inserted
->ulSize
==item
->ulSize
+sizeof(SHLWAPI_CLIST
),
320 "id %d wrong size %d\n", inserted
->ulId
, inserted
->ulSize
);
325 LPBYTE bufftest
= (LPBYTE
)inserted
;
327 for (i
= 0; i
< inserted
->ulSize
- sizeof(SHLWAPI_CLIST
); i
++)
328 if (bufftest
[sizeof(SHLWAPI_CLIST
)+i
] != i
*2)
331 ok(bDataOK
== TRUE
, "data corrupted on insert\n");
333 ok(!inserted
|| inserted
->ulId
==item
->ulId
, "find got wrong item\n");
339 InitDummyStream(&streamobj
);
341 hRet
= pSHLWAPI_17(&streamobj
, list
);
342 ok(hRet
== S_OK
, "write failed\n");
345 /* 1 call for each element, + 1 for OK (use our null element for this) */
346 ok(streamobj
.writecalls
== sizeof(SHLWAPI_CLIST_items
)/sizeof(SHLWAPI_CLIST
),
347 "wrong call count\n");
348 ok(streamobj
.readcalls
== 0,"called Read() in write\n");
349 ok(streamobj
.seekcalls
== 0,"called Seek() in write\n");
352 /* Failure cases for writing */
353 InitDummyStream(&streamobj
);
354 streamobj
.failwritecall
= TRUE
;
355 hRet
= pSHLWAPI_17(&streamobj
, list
);
356 ok(hRet
== STG_E_ACCESSDENIED
, "changed object failure return\n");
357 ok(streamobj
.writecalls
== 1, "called object after failure\n");
358 ok(streamobj
.readcalls
== 0,"called Read() after failure\n");
359 ok(streamobj
.seekcalls
== 0,"called Seek() after failure\n");
361 InitDummyStream(&streamobj
);
362 streamobj
.failwritesize
= TRUE
;
363 hRet
= pSHLWAPI_17(&streamobj
, list
);
364 ok(hRet
== STG_E_MEDIUMFULL
|| broken(hRet
== E_FAIL
) /* Win7 */,
365 "changed size failure return\n");
366 ok(streamobj
.writecalls
== 1, "called object after size failure\n");
367 ok(streamobj
.readcalls
== 0,"called Read() after failure\n");
368 ok(streamobj
.seekcalls
== 0,"called Seek() after failure\n");
370 /* Invalid inputs for adding */
371 inserted
= (LPSHLWAPI_CLIST
)buff
;
372 inserted
->ulSize
= sizeof(SHLWAPI_CLIST
) -1;
375 /* The call succeeds but the item is not inserted, except on some early
376 * versions which return failure. Wine behaves like later versions.
378 pSHLWAPI_20(&list
, inserted
);
380 inserted
= pSHLWAPI_22(list
, 33);
381 ok(inserted
== NULL
, "inserted bad element size\n");
383 inserted
= (LPSHLWAPI_CLIST
)buff
;
384 inserted
->ulSize
= 44;
385 inserted
->ulId
= ~0U;
387 /* See comment above, some early versions fail this call */
388 pSHLWAPI_20(&list
, inserted
);
390 item
= SHLWAPI_CLIST_items
;
392 /* Look for nonexistent item in populated list */
393 inserted
= pSHLWAPI_22(list
, 99999999);
394 ok(inserted
== NULL
, "found a nonexistent item\n");
399 BOOL bRet
= pSHLWAPI_21(&list
, item
->ulId
);
400 ok(bRet
== TRUE
, "couldn't find item to delete\n");
404 /* Look for nonexistent item in empty list */
405 inserted
= pSHLWAPI_22(list
, 99999999);
406 ok(inserted
== NULL
, "found an item in empty list\n");
408 /* Create a list by reading in data */
409 InitDummyStream(&streamobj
);
411 hRet
= pSHLWAPI_18(&streamobj
, &list
);
412 ok(hRet
== S_OK
, "failed create from Read()\n");
415 ok(streamobj
.readbeyondend
== FALSE
, "read beyond end\n");
416 /* 2 calls per item, but only 1 for the terminator */
417 ok(streamobj
.readcalls
== sizeof(SHLWAPI_CLIST_items
)/sizeof(SHLWAPI_CLIST
)*2-1,
418 "wrong call count\n");
419 ok(streamobj
.writecalls
== 0, "called Write() from create\n");
420 ok(streamobj
.seekcalls
== 0,"called Seek() from create\n");
422 item
= SHLWAPI_CLIST_items
;
424 /* Check the items were added correctly */
427 inserted
= pSHLWAPI_22(list
, item
->ulId
);
428 ok(inserted
!= NULL
, "lost after adding\n");
430 ok(!inserted
|| inserted
->ulId
!= ~0U, "find returned a container\n");
433 if (inserted
&& inserted
->ulSize
& 0x3)
436 ok(inserted
[-1].ulId
== ~0U, "invalid size is not countained\n");
437 ok(inserted
[-1].ulSize
> inserted
->ulSize
+sizeof(SHLWAPI_CLIST
),
438 "container too small\n");
442 ok(inserted
->ulSize
==item
->ulSize
+sizeof(SHLWAPI_CLIST
),
443 "id %d wrong size %d\n", inserted
->ulId
, inserted
->ulSize
);
445 ok(!inserted
|| inserted
->ulId
==item
->ulId
, "find got wrong item\n");
449 LPBYTE bufftest
= (LPBYTE
)inserted
;
451 for (i
= 0; i
< inserted
->ulSize
- sizeof(SHLWAPI_CLIST
); i
++)
452 if (bufftest
[sizeof(SHLWAPI_CLIST
)+i
] != i
*2)
455 ok(bDataOK
== TRUE
, "data corrupted on insert\n");
461 /* Failure cases for reading */
462 InitDummyStream(&streamobj
);
463 streamobj
.failreadcall
= TRUE
;
464 hRet
= pSHLWAPI_18(&streamobj
, &list
);
465 ok(hRet
== STG_E_ACCESSDENIED
, "changed object failure return\n");
466 ok(streamobj
.readbeyondend
== FALSE
, "read beyond end\n");
467 ok(streamobj
.readcalls
== 1, "called object after read failure\n");
468 ok(streamobj
.writecalls
== 0,"called Write() after read failure\n");
469 ok(streamobj
.seekcalls
== 0,"called Seek() after read failure\n");
471 /* Read returns large object */
472 InitDummyStream(&streamobj
);
473 streamobj
.readreturnlarge
= TRUE
;
474 hRet
= pSHLWAPI_18(&streamobj
, &list
);
475 ok(hRet
== S_OK
, "failed create from Read() with large item\n");
476 ok(streamobj
.readbeyondend
== FALSE
, "read beyond end\n");
477 ok(streamobj
.readcalls
== 1,"wrong call count\n");
478 ok(streamobj
.writecalls
== 0,"called Write() after read failure\n");
479 ok(streamobj
.seekcalls
== 2,"wrong Seek() call count (%d)\n", streamobj
.seekcalls
);
484 static BOOL
test_SHLWAPI_166(void)
486 _IDummyStream streamobj
;
492 InitDummyStream(&streamobj
);
493 bRet
= pSHLWAPI_166(&streamobj
);
496 return FALSE
; /* This version doesn't support stream ops on clists */
498 ok(streamobj
.readcalls
== 0, "called Read()\n");
499 ok(streamobj
.writecalls
== 0, "called Write()\n");
500 ok(streamobj
.seekcalls
== 0, "called Seek()\n");
501 ok(streamobj
.statcalls
== 1, "wrong call count\n");
503 streamobj
.statcalls
= 0;
504 streamobj
.pos
.QuadPart
= 50001;
506 bRet
= pSHLWAPI_166(&streamobj
);
508 ok(bRet
== FALSE
, "failed after seek adjusted\n");
509 ok(streamobj
.readcalls
== 0, "called Read()\n");
510 ok(streamobj
.writecalls
== 0, "called Write()\n");
511 ok(streamobj
.seekcalls
== 0, "called Seek()\n");
512 ok(streamobj
.statcalls
== 1, "wrong call count\n");
515 InitDummyStream(&streamobj
);
516 streamobj
.pos
.QuadPart
= 50001;
517 streamobj
.failstatcall
= TRUE
; /* 1: Stat() Bad, Read() OK */
518 bRet
= pSHLWAPI_166(&streamobj
);
519 ok(bRet
== FALSE
, "should be FALSE after read is OK\n");
520 ok(streamobj
.readcalls
== 1, "wrong call count\n");
521 ok(streamobj
.writecalls
== 0, "called Write()\n");
522 ok(streamobj
.seekcalls
== 1, "wrong call count\n");
523 ok(streamobj
.statcalls
== 1, "wrong call count\n");
524 ok(streamobj
.pos
.QuadPart
== 0, "Didn't seek to start\n");
526 InitDummyStream(&streamobj
);
527 streamobj
.pos
.QuadPart
= 50001;
528 streamobj
.failstatcall
= TRUE
;
529 streamobj
.failreadcall
= TRUE
; /* 2: Stat() Bad, Read() Bad Also */
530 bRet
= pSHLWAPI_166(&streamobj
);
531 ok(bRet
== TRUE
, "Should be true after read fails\n");
532 ok(streamobj
.readcalls
== 1, "wrong call count\n");
533 ok(streamobj
.writecalls
== 0, "called Write()\n");
534 ok(streamobj
.seekcalls
== 0, "Called Seek()\n");
535 ok(streamobj
.statcalls
== 1, "wrong call count\n");
536 ok(streamobj
.pos
.QuadPart
== 50001, "called Seek() after read failed\n");
540 static void test_SHLWAPI_184(void)
542 _IDummyStream streamobj
;
549 InitDummyStream(&streamobj
);
550 hRet
= pSHLWAPI_184(&streamobj
, buff
, sizeof(buff
));
552 ok(hRet
== S_OK
, "failed Read()\n");
553 ok(streamobj
.readcalls
== 1, "wrong call count\n");
554 ok(streamobj
.writecalls
== 0, "called Write()\n");
555 ok(streamobj
.seekcalls
== 0, "called Seek()\n");
558 static void test_SHLWAPI_212(void)
560 _IDummyStream streamobj
;
567 InitDummyStream(&streamobj
);
568 hRet
= pSHLWAPI_212(&streamobj
, buff
, sizeof(buff
));
570 ok(hRet
== S_OK
, "failed Write()\n");
571 ok(streamobj
.readcalls
== 0, "called Read()\n");
572 ok(streamobj
.writecalls
== 1, "wrong call count\n");
573 ok(streamobj
.seekcalls
== 0, "called Seek()\n");
576 static void test_SHLWAPI_213(void)
578 _IDummyStream streamobj
;
583 if (!pSHLWAPI_213
|| !pSHLWAPI_214
)
586 InitDummyStream(&streamobj
);
588 Seek(&streamobj
, ll
, 0, NULL
); /* Seek to 5000l */
590 streamobj
.seekcalls
= 0;
591 pSHLWAPI_213(&streamobj
); /* Should rewind */
592 ok(streamobj
.statcalls
== 0, "called Stat()\n");
593 ok(streamobj
.readcalls
== 0, "called Read()\n");
594 ok(streamobj
.writecalls
== 0, "called Write()\n");
595 ok(streamobj
.seekcalls
== 1, "wrong call count\n");
598 hRet
= pSHLWAPI_214(&streamobj
, &ul
);
599 ok(hRet
== S_OK
, "failed Stat()\n");
600 ok(ul
.QuadPart
== 0, "213 didn't rewind stream\n");
603 static void test_SHLWAPI_214(void)
605 _IDummyStream streamobj
;
613 InitDummyStream(&streamobj
);
615 Seek(&streamobj
, ll
, 0, NULL
);
617 streamobj
.seekcalls
= 0;
618 hRet
= pSHLWAPI_214(&streamobj
, &ul
);
620 ok(hRet
== S_OK
, "failed Stat()\n");
621 ok(streamobj
.statcalls
== 1, "wrong call count\n");
622 ok(streamobj
.readcalls
== 0, "called Read()\n");
623 ok(streamobj
.writecalls
== 0, "called Write()\n");
624 ok(streamobj
.seekcalls
== 0, "called Seek()\n");
625 ok(ul
.QuadPart
== 5000l, "Stat gave wrong size\n");
630 if(!InitFunctionPtrs())
635 /* Test streaming if this version supports it */
636 if (test_SHLWAPI_166())