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 typedef struct tagSHLWAPI_CLIST
26 } SHLWAPI_CLIST
, *LPSHLWAPI_CLIST
;
28 typedef const SHLWAPI_CLIST
* LPCSHLWAPI_CLIST
;
31 static const SHLWAPI_CLIST SHLWAPI_CLIST_items
[] =
47 /* Dummy IStream object for testing calls */
50 IStream IStream_iface
;
63 LPCSHLWAPI_CLIST item
;
67 static inline struct dummystream
*impl_from_IStream(IStream
*iface
)
69 return CONTAINING_RECORD(iface
, struct dummystream
, IStream_iface
);
72 static HRESULT WINAPI
QueryInterface(IStream
*iface
, REFIID riid
, void **ret_iface
)
74 if (IsEqualGUID(&IID_IUnknown
, riid
) || IsEqualGUID(&IID_IStream
, riid
)) {
76 IStream_AddRef(iface
);
79 trace("Unexpected REFIID %s\n", wine_dbgstr_guid(riid
));
84 static ULONG WINAPI
AddRef(IStream
*iface
)
86 struct dummystream
*This
= impl_from_IStream(iface
);
88 return InterlockedIncrement(&This
->ref
);
91 static ULONG WINAPI
Release(IStream
*iface
)
93 struct dummystream
*This
= impl_from_IStream(iface
);
95 return InterlockedDecrement(&This
->ref
);
98 static HRESULT WINAPI
Read(IStream
*iface
, void *lpMem
, ULONG ulSize
, ULONG
*lpRead
)
100 struct dummystream
*This
= impl_from_IStream(iface
);
104 if (This
->failreadcall
)
106 return STG_E_ACCESSDENIED
;
108 else if (This
->failreadsize
)
110 *lpRead
= ulSize
+ 8;
113 else if (This
->readreturnlarge
)
115 *((ULONG
*)lpMem
) = 0xffff01;
117 This
->readreturnlarge
= FALSE
;
120 if (ulSize
== sizeof(ULONG
))
122 /* Read size of item */
123 *((ULONG
*)lpMem
) = This
->item
->ulSize
? This
->item
->ulSize
+ sizeof(SHLWAPI_CLIST
) : 0;
132 if (!This
->item
->ulSize
)
134 This
->readbeyondend
= TRUE
;
136 return E_FAIL
; /* Should never happen */
138 *((ULONG
*)lpMem
) = This
->item
->ulId
;
141 for (i
= 0; i
< This
->item
->ulSize
; i
++)
149 static HRESULT WINAPI
Write(IStream
*iface
, const void *lpMem
, ULONG ulSize
, ULONG
*lpWritten
)
151 struct dummystream
*This
= impl_from_IStream(iface
);
155 if (This
->failwritecall
)
157 return STG_E_ACCESSDENIED
;
159 else if (This
->failwritesize
)
168 static HRESULT WINAPI
Seek(IStream
*iface
, LARGE_INTEGER dlibMove
, DWORD dwOrigin
,
169 ULARGE_INTEGER
*plibNewPosition
)
171 struct dummystream
*This
= impl_from_IStream(iface
);
174 This
->pos
.QuadPart
= dlibMove
.QuadPart
;
176 plibNewPosition
->QuadPart
= dlibMove
.QuadPart
;
180 static HRESULT WINAPI
Stat(IStream
*iface
, STATSTG
*pstatstg
, DWORD grfStatFlag
)
182 struct dummystream
*This
= impl_from_IStream(iface
);
185 if (This
->failstatcall
)
188 pstatstg
->cbSize
.QuadPart
= This
->pos
.QuadPart
;
193 static IStreamVtbl iclvt
=
205 NULL
, /* LockRegion */
206 NULL
, /* UnlockRegion */
211 /* Function ptrs for ordinal calls */
212 static HMODULE SHLWAPI_hshlwapi
= 0;
214 static VOID (WINAPI
*pSHLWAPI_19
)(LPSHLWAPI_CLIST
);
215 static HRESULT (WINAPI
*pSHLWAPI_20
)(LPSHLWAPI_CLIST
*,LPCSHLWAPI_CLIST
);
216 static BOOL (WINAPI
*pSHLWAPI_21
)(LPSHLWAPI_CLIST
*,ULONG
);
217 static LPSHLWAPI_CLIST (WINAPI
*pSHLWAPI_22
)(LPSHLWAPI_CLIST
,ULONG
);
218 static HRESULT (WINAPI
*pSHLWAPI_17
)(IStream
*, SHLWAPI_CLIST
*);
219 static HRESULT (WINAPI
*pSHLWAPI_18
)(IStream
*, SHLWAPI_CLIST
**);
221 static BOOL (WINAPI
*pSHLWAPI_166
)(IStream
*);
222 static HRESULT (WINAPI
*pSHLWAPI_184
)(IStream
*, void*, ULONG
);
223 static HRESULT (WINAPI
*pSHLWAPI_212
)(IStream
*, const void*, ULONG
);
224 static HRESULT (WINAPI
*pSHLWAPI_213
)(IStream
*);
225 static HRESULT (WINAPI
*pSHLWAPI_214
)(IStream
*, ULARGE_INTEGER
*);
228 static BOOL
InitFunctionPtrs(void)
230 SHLWAPI_hshlwapi
= GetModuleHandleA("shlwapi.dll");
232 /* SHCreateStreamOnFileEx was introduced in shlwapi v6.0 */
233 if(!GetProcAddress(SHLWAPI_hshlwapi
, "SHCreateStreamOnFileEx")){
234 win_skip("Too old shlwapi version\n");
238 pSHLWAPI_17
= (void *)GetProcAddress( SHLWAPI_hshlwapi
, (LPSTR
)17);
239 ok(pSHLWAPI_17
!= 0, "No Ordinal 17\n");
240 pSHLWAPI_18
= (void *)GetProcAddress( SHLWAPI_hshlwapi
, (LPSTR
)18);
241 ok(pSHLWAPI_18
!= 0, "No Ordinal 18\n");
242 pSHLWAPI_19
= (void *)GetProcAddress( SHLWAPI_hshlwapi
, (LPSTR
)19);
243 ok(pSHLWAPI_19
!= 0, "No Ordinal 19\n");
244 pSHLWAPI_20
= (void *)GetProcAddress( SHLWAPI_hshlwapi
, (LPSTR
)20);
245 ok(pSHLWAPI_20
!= 0, "No Ordinal 20\n");
246 pSHLWAPI_21
= (void *)GetProcAddress( SHLWAPI_hshlwapi
, (LPSTR
)21);
247 ok(pSHLWAPI_21
!= 0, "No Ordinal 21\n");
248 pSHLWAPI_22
= (void *)GetProcAddress( SHLWAPI_hshlwapi
, (LPSTR
)22);
249 ok(pSHLWAPI_22
!= 0, "No Ordinal 22\n");
250 pSHLWAPI_166
= (void *)GetProcAddress( SHLWAPI_hshlwapi
, (LPSTR
)166);
251 ok(pSHLWAPI_166
!= 0, "No Ordinal 166\n");
252 pSHLWAPI_184
= (void *)GetProcAddress( SHLWAPI_hshlwapi
, (LPSTR
)184);
253 ok(pSHLWAPI_184
!= 0, "No Ordinal 184\n");
254 pSHLWAPI_212
= (void *)GetProcAddress( SHLWAPI_hshlwapi
, (LPSTR
)212);
255 ok(pSHLWAPI_212
!= 0, "No Ordinal 212\n");
256 pSHLWAPI_213
= (void *)GetProcAddress( SHLWAPI_hshlwapi
, (LPSTR
)213);
257 ok(pSHLWAPI_213
!= 0, "No Ordinal 213\n");
258 pSHLWAPI_214
= (void *)GetProcAddress( SHLWAPI_hshlwapi
, (LPSTR
)214);
259 ok(pSHLWAPI_214
!= 0, "No Ordinal 214\n");
264 static void InitDummyStream(struct dummystream
*obj
)
266 obj
->IStream_iface
.lpVtbl
= &iclvt
;
269 obj
->failreadcall
= FALSE
;
270 obj
->failreadsize
= FALSE
;
271 obj
->readbeyondend
= FALSE
;
272 obj
->readreturnlarge
= FALSE
;
274 obj
->failwritecall
= FALSE
;
275 obj
->failwritesize
= FALSE
;
278 obj
->failstatcall
= FALSE
;
279 obj
->item
= SHLWAPI_CLIST_items
;
280 obj
->pos
.QuadPart
= 0;
284 static void test_CList(void)
286 struct dummystream streamobj
;
287 LPSHLWAPI_CLIST list
= NULL
;
288 LPCSHLWAPI_CLIST item
= SHLWAPI_CLIST_items
;
290 LPSHLWAPI_CLIST inserted
;
294 if (!pSHLWAPI_17
|| !pSHLWAPI_18
|| !pSHLWAPI_19
|| !pSHLWAPI_20
||
295 !pSHLWAPI_21
|| !pSHLWAPI_22
)
298 /* Populate a list and test the items are added correctly */
301 /* Create item and fill with data */
302 inserted
= (LPSHLWAPI_CLIST
)buff
;
303 inserted
->ulSize
= item
->ulSize
+ sizeof(SHLWAPI_CLIST
);
304 inserted
->ulId
= item
->ulId
;
305 for (i
= 0; i
< item
->ulSize
; i
++)
306 buff
[sizeof(SHLWAPI_CLIST
)+i
] = i
*2;
309 hRet
= pSHLWAPI_20(&list
, inserted
);
310 ok(hRet
> S_OK
, "failed list add\n");
314 ok(list
&& list
->ulSize
, "item not added\n");
317 inserted
= pSHLWAPI_22(list
, item
->ulId
);
318 ok(inserted
!= NULL
, "lost after adding\n");
320 ok(!inserted
|| inserted
->ulId
!= ~0U, "find returned a container\n");
323 if (inserted
&& inserted
->ulSize
& 0x3)
326 ok(inserted
[-1].ulId
== ~0U, "invalid size is not countained\n");
327 ok(inserted
[-1].ulSize
> inserted
->ulSize
+sizeof(SHLWAPI_CLIST
),
328 "container too small\n");
332 ok(inserted
->ulSize
==item
->ulSize
+sizeof(SHLWAPI_CLIST
),
333 "id %d wrong size %d\n", inserted
->ulId
, inserted
->ulSize
);
338 LPBYTE bufftest
= (LPBYTE
)inserted
;
340 for (i
= 0; i
< inserted
->ulSize
- sizeof(SHLWAPI_CLIST
); i
++)
341 if (bufftest
[sizeof(SHLWAPI_CLIST
)+i
] != i
*2)
344 ok(bDataOK
== TRUE
, "data corrupted on insert\n");
346 ok(!inserted
|| inserted
->ulId
==item
->ulId
, "find got wrong item\n");
352 InitDummyStream(&streamobj
);
354 hRet
= pSHLWAPI_17(&streamobj
.IStream_iface
, list
);
355 ok(hRet
== S_OK
, "write failed\n");
358 /* 1 call for each element, + 1 for OK (use our null element for this) */
359 ok(streamobj
.writecalls
== sizeof(SHLWAPI_CLIST_items
)/sizeof(SHLWAPI_CLIST
),
360 "wrong call count\n");
361 ok(streamobj
.readcalls
== 0,"called Read() in write\n");
362 ok(streamobj
.seekcalls
== 0,"called Seek() in write\n");
365 /* Failure cases for writing */
366 InitDummyStream(&streamobj
);
367 streamobj
.failwritecall
= TRUE
;
368 hRet
= pSHLWAPI_17(&streamobj
.IStream_iface
, list
);
369 ok(hRet
== STG_E_ACCESSDENIED
, "changed object failure return\n");
370 ok(streamobj
.writecalls
== 1, "called object after failure\n");
371 ok(streamobj
.readcalls
== 0,"called Read() after failure\n");
372 ok(streamobj
.seekcalls
== 0,"called Seek() after failure\n");
374 InitDummyStream(&streamobj
);
375 streamobj
.failwritesize
= TRUE
;
376 hRet
= pSHLWAPI_17(&streamobj
.IStream_iface
, list
);
377 ok(hRet
== STG_E_MEDIUMFULL
|| broken(hRet
== E_FAIL
) /* Win7 */,
378 "changed size failure return\n");
379 ok(streamobj
.writecalls
== 1, "called object after size failure\n");
380 ok(streamobj
.readcalls
== 0,"called Read() after failure\n");
381 ok(streamobj
.seekcalls
== 0,"called Seek() after failure\n");
383 /* Invalid inputs for adding */
384 inserted
= (LPSHLWAPI_CLIST
)buff
;
385 inserted
->ulSize
= sizeof(SHLWAPI_CLIST
) -1;
388 /* The call succeeds but the item is not inserted, except on some early
389 * versions which return failure. Wine behaves like later versions.
391 pSHLWAPI_20(&list
, inserted
);
393 inserted
= pSHLWAPI_22(list
, 33);
394 ok(inserted
== NULL
, "inserted bad element size\n");
396 inserted
= (LPSHLWAPI_CLIST
)buff
;
397 inserted
->ulSize
= 44;
398 inserted
->ulId
= ~0U;
400 /* See comment above, some early versions fail this call */
401 pSHLWAPI_20(&list
, inserted
);
403 item
= SHLWAPI_CLIST_items
;
405 /* Look for nonexistent item in populated list */
406 inserted
= pSHLWAPI_22(list
, 99999999);
407 ok(inserted
== NULL
, "found a nonexistent item\n");
412 BOOL bRet
= pSHLWAPI_21(&list
, item
->ulId
);
413 ok(bRet
== TRUE
, "couldn't find item to delete\n");
417 /* Look for nonexistent item in empty list */
418 inserted
= pSHLWAPI_22(list
, 99999999);
419 ok(inserted
== NULL
, "found an item in empty list\n");
421 /* Create a list by reading in data */
422 InitDummyStream(&streamobj
);
424 hRet
= pSHLWAPI_18(&streamobj
.IStream_iface
, &list
);
425 ok(hRet
== S_OK
, "failed create from Read()\n");
428 ok(streamobj
.readbeyondend
== FALSE
, "read beyond end\n");
429 /* 2 calls per item, but only 1 for the terminator */
430 ok(streamobj
.readcalls
== sizeof(SHLWAPI_CLIST_items
)/sizeof(SHLWAPI_CLIST
)*2-1,
431 "wrong call count\n");
432 ok(streamobj
.writecalls
== 0, "called Write() from create\n");
433 ok(streamobj
.seekcalls
== 0,"called Seek() from create\n");
435 item
= SHLWAPI_CLIST_items
;
437 /* Check the items were added correctly */
440 inserted
= pSHLWAPI_22(list
, item
->ulId
);
441 ok(inserted
!= NULL
, "lost after adding\n");
443 ok(!inserted
|| inserted
->ulId
!= ~0U, "find returned a container\n");
446 if (inserted
&& inserted
->ulSize
& 0x3)
449 ok(inserted
[-1].ulId
== ~0U, "invalid size is not countained\n");
450 ok(inserted
[-1].ulSize
> inserted
->ulSize
+sizeof(SHLWAPI_CLIST
),
451 "container too small\n");
455 ok(inserted
->ulSize
==item
->ulSize
+sizeof(SHLWAPI_CLIST
),
456 "id %d wrong size %d\n", inserted
->ulId
, inserted
->ulSize
);
458 ok(!inserted
|| inserted
->ulId
==item
->ulId
, "find got wrong item\n");
462 LPBYTE bufftest
= (LPBYTE
)inserted
;
464 for (i
= 0; i
< inserted
->ulSize
- sizeof(SHLWAPI_CLIST
); i
++)
465 if (bufftest
[sizeof(SHLWAPI_CLIST
)+i
] != i
*2)
468 ok(bDataOK
== TRUE
, "data corrupted on insert\n");
474 /* Failure cases for reading */
475 InitDummyStream(&streamobj
);
476 streamobj
.failreadcall
= TRUE
;
477 hRet
= pSHLWAPI_18(&streamobj
.IStream_iface
, &list
);
478 ok(hRet
== STG_E_ACCESSDENIED
, "changed object failure return\n");
479 ok(streamobj
.readbeyondend
== FALSE
, "read beyond end\n");
480 ok(streamobj
.readcalls
== 1, "called object after read failure\n");
481 ok(streamobj
.writecalls
== 0,"called Write() after read failure\n");
482 ok(streamobj
.seekcalls
== 0,"called Seek() after read failure\n");
484 /* Read returns large object */
485 InitDummyStream(&streamobj
);
486 streamobj
.readreturnlarge
= TRUE
;
487 hRet
= pSHLWAPI_18(&streamobj
.IStream_iface
, &list
);
488 ok(hRet
== S_OK
, "failed create from Read() with large item\n");
489 ok(streamobj
.readbeyondend
== FALSE
, "read beyond end\n");
490 ok(streamobj
.readcalls
== 1,"wrong call count\n");
491 ok(streamobj
.writecalls
== 0,"called Write() after read failure\n");
492 ok(streamobj
.seekcalls
== 2,"wrong Seek() call count (%d)\n", streamobj
.seekcalls
);
497 static BOOL
test_SHLWAPI_166(void)
499 struct dummystream streamobj
;
505 InitDummyStream(&streamobj
);
506 bRet
= pSHLWAPI_166(&streamobj
.IStream_iface
);
509 return FALSE
; /* This version doesn't support stream ops on clists */
511 ok(streamobj
.readcalls
== 0, "called Read()\n");
512 ok(streamobj
.writecalls
== 0, "called Write()\n");
513 ok(streamobj
.seekcalls
== 0, "called Seek()\n");
514 ok(streamobj
.statcalls
== 1, "wrong call count\n");
516 streamobj
.statcalls
= 0;
517 streamobj
.pos
.QuadPart
= 50001;
519 bRet
= pSHLWAPI_166(&streamobj
.IStream_iface
);
521 ok(bRet
== FALSE
, "failed after seek adjusted\n");
522 ok(streamobj
.readcalls
== 0, "called Read()\n");
523 ok(streamobj
.writecalls
== 0, "called Write()\n");
524 ok(streamobj
.seekcalls
== 0, "called Seek()\n");
525 ok(streamobj
.statcalls
== 1, "wrong call count\n");
528 InitDummyStream(&streamobj
);
529 streamobj
.pos
.QuadPart
= 50001;
530 streamobj
.failstatcall
= TRUE
; /* 1: Stat() Bad, Read() OK */
531 bRet
= pSHLWAPI_166(&streamobj
.IStream_iface
);
532 ok(bRet
== FALSE
, "should be FALSE after read is OK\n");
533 ok(streamobj
.readcalls
== 1, "wrong call count\n");
534 ok(streamobj
.writecalls
== 0, "called Write()\n");
535 ok(streamobj
.seekcalls
== 1, "wrong call count\n");
536 ok(streamobj
.statcalls
== 1, "wrong call count\n");
537 ok(streamobj
.pos
.QuadPart
== 0, "Didn't seek to start\n");
539 InitDummyStream(&streamobj
);
540 streamobj
.pos
.QuadPart
= 50001;
541 streamobj
.failstatcall
= TRUE
;
542 streamobj
.failreadcall
= TRUE
; /* 2: Stat() Bad, Read() Bad Also */
543 bRet
= pSHLWAPI_166(&streamobj
.IStream_iface
);
544 ok(bRet
== TRUE
, "Should be true after read fails\n");
545 ok(streamobj
.readcalls
== 1, "wrong call count\n");
546 ok(streamobj
.writecalls
== 0, "called Write()\n");
547 ok(streamobj
.seekcalls
== 0, "Called Seek()\n");
548 ok(streamobj
.statcalls
== 1, "wrong call count\n");
549 ok(streamobj
.pos
.QuadPart
== 50001, "called Seek() after read failed\n");
553 static void test_SHLWAPI_184(void)
555 struct dummystream streamobj
;
562 InitDummyStream(&streamobj
);
563 hRet
= pSHLWAPI_184(&streamobj
.IStream_iface
, buff
, sizeof(buff
));
565 ok(hRet
== S_OK
, "failed Read()\n");
566 ok(streamobj
.readcalls
== 1, "wrong call count\n");
567 ok(streamobj
.writecalls
== 0, "called Write()\n");
568 ok(streamobj
.seekcalls
== 0, "called Seek()\n");
571 static void test_SHLWAPI_212(void)
573 struct dummystream streamobj
;
580 InitDummyStream(&streamobj
);
581 hRet
= pSHLWAPI_212(&streamobj
.IStream_iface
, buff
, sizeof(buff
));
583 ok(hRet
== S_OK
, "failed Write()\n");
584 ok(streamobj
.readcalls
== 0, "called Read()\n");
585 ok(streamobj
.writecalls
== 1, "wrong call count\n");
586 ok(streamobj
.seekcalls
== 0, "called Seek()\n");
589 static void test_SHLWAPI_213(void)
591 struct dummystream streamobj
;
596 if (!pSHLWAPI_213
|| !pSHLWAPI_214
)
599 InitDummyStream(&streamobj
);
601 Seek(&streamobj
.IStream_iface
, ll
, 0, NULL
); /* Seek to 5000l */
603 streamobj
.seekcalls
= 0;
604 pSHLWAPI_213(&streamobj
.IStream_iface
); /* Should rewind */
605 ok(streamobj
.statcalls
== 0, "called Stat()\n");
606 ok(streamobj
.readcalls
== 0, "called Read()\n");
607 ok(streamobj
.writecalls
== 0, "called Write()\n");
608 ok(streamobj
.seekcalls
== 1, "wrong call count\n");
611 hRet
= pSHLWAPI_214(&streamobj
.IStream_iface
, &ul
);
612 ok(hRet
== S_OK
, "failed Stat()\n");
613 ok(ul
.QuadPart
== 0, "213 didn't rewind stream\n");
616 static void test_SHLWAPI_214(void)
618 struct dummystream streamobj
;
626 InitDummyStream(&streamobj
);
628 Seek(&streamobj
.IStream_iface
, ll
, 0, NULL
);
630 streamobj
.seekcalls
= 0;
631 hRet
= pSHLWAPI_214(&streamobj
.IStream_iface
, &ul
);
633 ok(hRet
== S_OK
, "failed Stat()\n");
634 ok(streamobj
.statcalls
== 1, "wrong call count\n");
635 ok(streamobj
.readcalls
== 0, "called Read()\n");
636 ok(streamobj
.writecalls
== 0, "called Write()\n");
637 ok(streamobj
.seekcalls
== 0, "called Seek()\n");
638 ok(ul
.QuadPart
== 5000l, "Stat gave wrong size\n");
643 if(!InitFunctionPtrs())
648 /* Test streaming if this version supports it */
649 if (test_SHLWAPI_166())