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
20 #define WIN32_NO_STATUS
22 #define COM_NO_WINDOWS_H
28 #include <wine/test.h>
30 //#include "winbase.h"
33 typedef struct tagSHLWAPI_CLIST
37 } SHLWAPI_CLIST
, *LPSHLWAPI_CLIST
;
39 typedef const SHLWAPI_CLIST
* LPCSHLWAPI_CLIST
;
42 static const SHLWAPI_CLIST SHLWAPI_CLIST_items
[] =
58 /* Dummy IStream object for testing calls */
61 IStream IStream_iface
;
74 LPCSHLWAPI_CLIST item
;
78 static inline struct dummystream
*impl_from_IStream(IStream
*iface
)
80 return CONTAINING_RECORD(iface
, struct dummystream
, IStream_iface
);
83 static HRESULT WINAPI
QueryInterface(IStream
*iface
, REFIID riid
, void **ret_iface
)
85 if (IsEqualGUID(&IID_IUnknown
, riid
) || IsEqualGUID(&IID_IStream
, riid
)) {
87 IStream_AddRef(iface
);
90 trace("Unexpected REFIID %s\n", wine_dbgstr_guid(riid
));
95 static ULONG WINAPI
AddRef(IStream
*iface
)
97 struct dummystream
*This
= impl_from_IStream(iface
);
99 return InterlockedIncrement(&This
->ref
);
102 static ULONG WINAPI
Release(IStream
*iface
)
104 struct dummystream
*This
= impl_from_IStream(iface
);
106 return InterlockedDecrement(&This
->ref
);
109 static HRESULT WINAPI
Read(IStream
*iface
, void *lpMem
, ULONG ulSize
, ULONG
*lpRead
)
111 struct dummystream
*This
= impl_from_IStream(iface
);
115 if (This
->failreadcall
)
117 return STG_E_ACCESSDENIED
;
119 else if (This
->failreadsize
)
121 *lpRead
= ulSize
+ 8;
124 else if (This
->readreturnlarge
)
126 *((ULONG
*)lpMem
) = 0xffff01;
128 This
->readreturnlarge
= FALSE
;
131 if (ulSize
== sizeof(ULONG
))
133 /* Read size of item */
134 *((ULONG
*)lpMem
) = This
->item
->ulSize
? This
->item
->ulSize
+ sizeof(SHLWAPI_CLIST
) : 0;
143 if (!This
->item
->ulSize
)
145 This
->readbeyondend
= TRUE
;
147 return E_FAIL
; /* Should never happen */
149 *((ULONG
*)lpMem
) = This
->item
->ulId
;
152 for (i
= 0; i
< This
->item
->ulSize
; i
++)
160 static HRESULT WINAPI
Write(IStream
*iface
, const void *lpMem
, ULONG ulSize
, ULONG
*lpWritten
)
162 struct dummystream
*This
= impl_from_IStream(iface
);
166 if (This
->failwritecall
)
168 return STG_E_ACCESSDENIED
;
170 else if (This
->failwritesize
)
179 static HRESULT WINAPI
Seek(IStream
*iface
, LARGE_INTEGER dlibMove
, DWORD dwOrigin
,
180 ULARGE_INTEGER
*plibNewPosition
)
182 struct dummystream
*This
= impl_from_IStream(iface
);
185 This
->pos
.QuadPart
= dlibMove
.QuadPart
;
187 plibNewPosition
->QuadPart
= dlibMove
.QuadPart
;
191 static HRESULT WINAPI
Stat(IStream
*iface
, STATSTG
*pstatstg
, DWORD grfStatFlag
)
193 struct dummystream
*This
= impl_from_IStream(iface
);
196 if (This
->failstatcall
)
199 pstatstg
->cbSize
.QuadPart
= This
->pos
.QuadPart
;
204 static IStreamVtbl iclvt
=
216 NULL
, /* LockRegion */
217 NULL
, /* UnlockRegion */
222 /* Function ptrs for ordinal calls */
223 static HMODULE SHLWAPI_hshlwapi
= 0;
225 static VOID (WINAPI
*pSHLWAPI_19
)(LPSHLWAPI_CLIST
);
226 static BOOL (WINAPI
*pSHLWAPI_20
)(LPSHLWAPI_CLIST
*,LPCSHLWAPI_CLIST
);
227 static BOOL (WINAPI
*pSHLWAPI_21
)(LPSHLWAPI_CLIST
*,ULONG
);
228 static LPSHLWAPI_CLIST (WINAPI
*pSHLWAPI_22
)(LPSHLWAPI_CLIST
,ULONG
);
229 static HRESULT (WINAPI
*pSHLWAPI_17
)(IStream
*, SHLWAPI_CLIST
*);
230 static HRESULT (WINAPI
*pSHLWAPI_18
)(IStream
*, SHLWAPI_CLIST
**);
232 static BOOL (WINAPI
*pSHLWAPI_166
)(IStream
*);
233 static HRESULT (WINAPI
*pSHLWAPI_184
)(IStream
*, void*, ULONG
);
234 static HRESULT (WINAPI
*pSHLWAPI_212
)(IStream
*, const void*, ULONG
);
235 static HRESULT (WINAPI
*pSHLWAPI_213
)(IStream
*);
236 static HRESULT (WINAPI
*pSHLWAPI_214
)(IStream
*, ULARGE_INTEGER
*);
239 static BOOL
InitFunctionPtrs(void)
241 SHLWAPI_hshlwapi
= GetModuleHandleA("shlwapi.dll");
243 /* SHCreateStreamOnFileEx was introduced in shlwapi v6.0 */
244 if(!GetProcAddress(SHLWAPI_hshlwapi
, "SHCreateStreamOnFileEx")){
245 win_skip("Too old shlwapi version\n");
249 pSHLWAPI_17
= (void *)GetProcAddress( SHLWAPI_hshlwapi
, (LPSTR
)17);
250 ok(pSHLWAPI_17
!= 0, "No Ordinal 17\n");
251 pSHLWAPI_18
= (void *)GetProcAddress( SHLWAPI_hshlwapi
, (LPSTR
)18);
252 ok(pSHLWAPI_18
!= 0, "No Ordinal 18\n");
253 pSHLWAPI_19
= (void *)GetProcAddress( SHLWAPI_hshlwapi
, (LPSTR
)19);
254 ok(pSHLWAPI_19
!= 0, "No Ordinal 19\n");
255 pSHLWAPI_20
= (void *)GetProcAddress( SHLWAPI_hshlwapi
, (LPSTR
)20);
256 ok(pSHLWAPI_20
!= 0, "No Ordinal 20\n");
257 pSHLWAPI_21
= (void *)GetProcAddress( SHLWAPI_hshlwapi
, (LPSTR
)21);
258 ok(pSHLWAPI_21
!= 0, "No Ordinal 21\n");
259 pSHLWAPI_22
= (void *)GetProcAddress( SHLWAPI_hshlwapi
, (LPSTR
)22);
260 ok(pSHLWAPI_22
!= 0, "No Ordinal 22\n");
261 pSHLWAPI_166
= (void *)GetProcAddress( SHLWAPI_hshlwapi
, (LPSTR
)166);
262 ok(pSHLWAPI_166
!= 0, "No Ordinal 166\n");
263 pSHLWAPI_184
= (void *)GetProcAddress( SHLWAPI_hshlwapi
, (LPSTR
)184);
264 ok(pSHLWAPI_184
!= 0, "No Ordinal 184\n");
265 pSHLWAPI_212
= (void *)GetProcAddress( SHLWAPI_hshlwapi
, (LPSTR
)212);
266 ok(pSHLWAPI_212
!= 0, "No Ordinal 212\n");
267 pSHLWAPI_213
= (void *)GetProcAddress( SHLWAPI_hshlwapi
, (LPSTR
)213);
268 ok(pSHLWAPI_213
!= 0, "No Ordinal 213\n");
269 pSHLWAPI_214
= (void *)GetProcAddress( SHLWAPI_hshlwapi
, (LPSTR
)214);
270 ok(pSHLWAPI_214
!= 0, "No Ordinal 214\n");
275 static void InitDummyStream(struct dummystream
*obj
)
277 obj
->IStream_iface
.lpVtbl
= &iclvt
;
280 obj
->failreadcall
= FALSE
;
281 obj
->failreadsize
= FALSE
;
282 obj
->readbeyondend
= FALSE
;
283 obj
->readreturnlarge
= FALSE
;
285 obj
->failwritecall
= FALSE
;
286 obj
->failwritesize
= FALSE
;
289 obj
->failstatcall
= FALSE
;
290 obj
->item
= SHLWAPI_CLIST_items
;
291 obj
->pos
.QuadPart
= 0;
295 static void test_CList(void)
297 struct dummystream streamobj
;
298 LPSHLWAPI_CLIST list
= NULL
;
299 LPCSHLWAPI_CLIST item
= SHLWAPI_CLIST_items
;
302 LPSHLWAPI_CLIST inserted
;
306 if (!pSHLWAPI_17
|| !pSHLWAPI_18
|| !pSHLWAPI_19
|| !pSHLWAPI_20
||
307 !pSHLWAPI_21
|| !pSHLWAPI_22
)
310 /* Populate a list and test the items are added correctly */
313 /* Create item and fill with data */
314 inserted
= (LPSHLWAPI_CLIST
)buff
;
315 inserted
->ulSize
= item
->ulSize
+ sizeof(SHLWAPI_CLIST
);
316 inserted
->ulId
= item
->ulId
;
317 for (i
= 0; i
< item
->ulSize
; i
++)
318 buff
[sizeof(SHLWAPI_CLIST
)+i
] = i
*2;
321 bRet
= pSHLWAPI_20(&list
, inserted
);
322 ok(bRet
== TRUE
, "failed list add\n");
326 ok(list
&& list
->ulSize
, "item not added\n");
329 inserted
= pSHLWAPI_22(list
, item
->ulId
);
330 ok(inserted
!= NULL
, "lost after adding\n");
332 ok(!inserted
|| inserted
->ulId
!= ~0U, "find returned a container\n");
335 if (inserted
&& inserted
->ulSize
& 0x3)
338 ok(inserted
[-1].ulId
== ~0U, "invalid size is not countained\n");
339 ok(inserted
[-1].ulSize
> inserted
->ulSize
+sizeof(SHLWAPI_CLIST
),
340 "container too small\n");
344 ok(inserted
->ulSize
==item
->ulSize
+sizeof(SHLWAPI_CLIST
),
345 "id %d wrong size %d\n", inserted
->ulId
, inserted
->ulSize
);
350 LPBYTE bufftest
= (LPBYTE
)inserted
;
352 for (i
= 0; i
< inserted
->ulSize
- sizeof(SHLWAPI_CLIST
); i
++)
353 if (bufftest
[sizeof(SHLWAPI_CLIST
)+i
] != i
*2)
356 ok(bDataOK
== TRUE
, "data corrupted on insert\n");
358 ok(!inserted
|| inserted
->ulId
==item
->ulId
, "find got wrong item\n");
364 InitDummyStream(&streamobj
);
366 hRet
= pSHLWAPI_17(&streamobj
.IStream_iface
, list
);
367 ok(hRet
== S_OK
, "write failed\n");
370 /* 1 call for each element, + 1 for OK (use our null element for this) */
371 ok(streamobj
.writecalls
== sizeof(SHLWAPI_CLIST_items
)/sizeof(SHLWAPI_CLIST
),
372 "wrong call count\n");
373 ok(streamobj
.readcalls
== 0,"called Read() in write\n");
374 ok(streamobj
.seekcalls
== 0,"called Seek() in write\n");
377 /* Failure cases for writing */
378 InitDummyStream(&streamobj
);
379 streamobj
.failwritecall
= TRUE
;
380 hRet
= pSHLWAPI_17(&streamobj
.IStream_iface
, list
);
381 ok(hRet
== STG_E_ACCESSDENIED
, "changed object failure return\n");
382 ok(streamobj
.writecalls
== 1, "called object after failure\n");
383 ok(streamobj
.readcalls
== 0,"called Read() after failure\n");
384 ok(streamobj
.seekcalls
== 0,"called Seek() after failure\n");
386 InitDummyStream(&streamobj
);
387 streamobj
.failwritesize
= TRUE
;
388 hRet
= pSHLWAPI_17(&streamobj
.IStream_iface
, list
);
389 ok(hRet
== STG_E_MEDIUMFULL
|| broken(hRet
== E_FAIL
) /* Win7 */,
390 "changed size failure return\n");
391 ok(streamobj
.writecalls
== 1, "called object after size failure\n");
392 ok(streamobj
.readcalls
== 0,"called Read() after failure\n");
393 ok(streamobj
.seekcalls
== 0,"called Seek() after failure\n");
395 /* Invalid inputs for adding */
396 inserted
= (LPSHLWAPI_CLIST
)buff
;
397 inserted
->ulSize
= sizeof(SHLWAPI_CLIST
) -1;
399 bRet
= pSHLWAPI_20(&list
, inserted
);
400 ok(bRet
== FALSE
, "Expected failure\n");
402 inserted
= pSHLWAPI_22(list
, 33);
403 ok(inserted
== NULL
, "inserted bad element size\n");
405 inserted
= (LPSHLWAPI_CLIST
)buff
;
406 inserted
->ulSize
= 44;
407 inserted
->ulId
= ~0U;
408 bRet
= pSHLWAPI_20(&list
, inserted
);
409 ok(bRet
== FALSE
, "Expected failure\n");
411 item
= SHLWAPI_CLIST_items
;
413 /* Look for nonexistent item in populated list */
414 inserted
= pSHLWAPI_22(list
, 99999999);
415 ok(inserted
== NULL
, "found a nonexistent item\n");
420 BOOL bRet
= pSHLWAPI_21(&list
, item
->ulId
);
421 ok(bRet
== TRUE
, "couldn't find item to delete\n");
425 /* Look for nonexistent item in empty list */
426 inserted
= pSHLWAPI_22(list
, 99999999);
427 ok(inserted
== NULL
, "found an item in empty list\n");
429 /* Create a list by reading in data */
430 InitDummyStream(&streamobj
);
432 hRet
= pSHLWAPI_18(&streamobj
.IStream_iface
, &list
);
433 ok(hRet
== S_OK
, "failed create from Read()\n");
436 ok(streamobj
.readbeyondend
== FALSE
, "read beyond end\n");
437 /* 2 calls per item, but only 1 for the terminator */
438 ok(streamobj
.readcalls
== sizeof(SHLWAPI_CLIST_items
)/sizeof(SHLWAPI_CLIST
)*2-1,
439 "wrong call count\n");
440 ok(streamobj
.writecalls
== 0, "called Write() from create\n");
441 ok(streamobj
.seekcalls
== 0,"called Seek() from create\n");
443 item
= SHLWAPI_CLIST_items
;
445 /* Check the items were added correctly */
448 inserted
= pSHLWAPI_22(list
, item
->ulId
);
449 ok(inserted
!= NULL
, "lost after adding\n");
451 ok(!inserted
|| inserted
->ulId
!= ~0U, "find returned a container\n");
454 if (inserted
&& inserted
->ulSize
& 0x3)
457 ok(inserted
[-1].ulId
== ~0U, "invalid size is not countained\n");
458 ok(inserted
[-1].ulSize
> inserted
->ulSize
+sizeof(SHLWAPI_CLIST
),
459 "container too small\n");
463 ok(inserted
->ulSize
==item
->ulSize
+sizeof(SHLWAPI_CLIST
),
464 "id %d wrong size %d\n", inserted
->ulId
, inserted
->ulSize
);
466 ok(!inserted
|| inserted
->ulId
==item
->ulId
, "find got wrong item\n");
470 LPBYTE bufftest
= (LPBYTE
)inserted
;
472 for (i
= 0; i
< inserted
->ulSize
- sizeof(SHLWAPI_CLIST
); i
++)
473 if (bufftest
[sizeof(SHLWAPI_CLIST
)+i
] != i
*2)
476 ok(bDataOK
== TRUE
, "data corrupted on insert\n");
482 /* Failure cases for reading */
483 InitDummyStream(&streamobj
);
484 streamobj
.failreadcall
= TRUE
;
485 hRet
= pSHLWAPI_18(&streamobj
.IStream_iface
, &list
);
486 ok(hRet
== STG_E_ACCESSDENIED
, "changed object failure return\n");
487 ok(streamobj
.readbeyondend
== FALSE
, "read beyond end\n");
488 ok(streamobj
.readcalls
== 1, "called object after read failure\n");
489 ok(streamobj
.writecalls
== 0,"called Write() after read failure\n");
490 ok(streamobj
.seekcalls
== 0,"called Seek() after read failure\n");
492 /* Read returns large object */
493 InitDummyStream(&streamobj
);
494 streamobj
.readreturnlarge
= TRUE
;
495 hRet
= pSHLWAPI_18(&streamobj
.IStream_iface
, &list
);
496 ok(hRet
== S_OK
, "failed create from Read() with large item\n");
497 ok(streamobj
.readbeyondend
== FALSE
, "read beyond end\n");
498 ok(streamobj
.readcalls
== 1,"wrong call count\n");
499 ok(streamobj
.writecalls
== 0,"called Write() after read failure\n");
500 ok(streamobj
.seekcalls
== 2,"wrong Seek() call count (%d)\n", streamobj
.seekcalls
);
505 static BOOL
test_SHLWAPI_166(void)
507 struct dummystream streamobj
;
513 InitDummyStream(&streamobj
);
514 bRet
= pSHLWAPI_166(&streamobj
.IStream_iface
);
517 return FALSE
; /* This version doesn't support stream ops on clists */
519 ok(streamobj
.readcalls
== 0, "called Read()\n");
520 ok(streamobj
.writecalls
== 0, "called Write()\n");
521 ok(streamobj
.seekcalls
== 0, "called Seek()\n");
522 ok(streamobj
.statcalls
== 1, "wrong call count\n");
524 streamobj
.statcalls
= 0;
525 streamobj
.pos
.QuadPart
= 50001;
527 bRet
= pSHLWAPI_166(&streamobj
.IStream_iface
);
529 ok(bRet
== FALSE
, "failed after seek adjusted\n");
530 ok(streamobj
.readcalls
== 0, "called Read()\n");
531 ok(streamobj
.writecalls
== 0, "called Write()\n");
532 ok(streamobj
.seekcalls
== 0, "called Seek()\n");
533 ok(streamobj
.statcalls
== 1, "wrong call count\n");
536 InitDummyStream(&streamobj
);
537 streamobj
.pos
.QuadPart
= 50001;
538 streamobj
.failstatcall
= TRUE
; /* 1: Stat() Bad, Read() OK */
539 bRet
= pSHLWAPI_166(&streamobj
.IStream_iface
);
540 ok(bRet
== FALSE
, "should be FALSE after read is OK\n");
541 ok(streamobj
.readcalls
== 1, "wrong call count\n");
542 ok(streamobj
.writecalls
== 0, "called Write()\n");
543 ok(streamobj
.seekcalls
== 1, "wrong call count\n");
544 ok(streamobj
.statcalls
== 1, "wrong call count\n");
545 ok(streamobj
.pos
.QuadPart
== 0, "Didn't seek to start\n");
547 InitDummyStream(&streamobj
);
548 streamobj
.pos
.QuadPart
= 50001;
549 streamobj
.failstatcall
= TRUE
;
550 streamobj
.failreadcall
= TRUE
; /* 2: Stat() Bad, Read() Bad Also */
551 bRet
= pSHLWAPI_166(&streamobj
.IStream_iface
);
552 ok(bRet
== TRUE
, "Should be true after read fails\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");
556 ok(streamobj
.statcalls
== 1, "wrong call count\n");
557 ok(streamobj
.pos
.QuadPart
== 50001, "called Seek() after read failed\n");
561 static void test_SHLWAPI_184(void)
563 struct dummystream streamobj
;
570 InitDummyStream(&streamobj
);
571 hRet
= pSHLWAPI_184(&streamobj
.IStream_iface
, buff
, sizeof(buff
));
573 ok(hRet
== S_OK
, "failed Read()\n");
574 ok(streamobj
.readcalls
== 1, "wrong call count\n");
575 ok(streamobj
.writecalls
== 0, "called Write()\n");
576 ok(streamobj
.seekcalls
== 0, "called Seek()\n");
579 static void test_SHLWAPI_212(void)
581 struct dummystream streamobj
;
588 InitDummyStream(&streamobj
);
589 hRet
= pSHLWAPI_212(&streamobj
.IStream_iface
, buff
, sizeof(buff
));
591 ok(hRet
== S_OK
, "failed Write()\n");
592 ok(streamobj
.readcalls
== 0, "called Read()\n");
593 ok(streamobj
.writecalls
== 1, "wrong call count\n");
594 ok(streamobj
.seekcalls
== 0, "called Seek()\n");
597 static void test_SHLWAPI_213(void)
599 struct dummystream streamobj
;
604 if (!pSHLWAPI_213
|| !pSHLWAPI_214
)
607 InitDummyStream(&streamobj
);
609 Seek(&streamobj
.IStream_iface
, ll
, 0, NULL
); /* Seek to 5000l */
611 streamobj
.seekcalls
= 0;
612 pSHLWAPI_213(&streamobj
.IStream_iface
); /* Should rewind */
613 ok(streamobj
.statcalls
== 0, "called Stat()\n");
614 ok(streamobj
.readcalls
== 0, "called Read()\n");
615 ok(streamobj
.writecalls
== 0, "called Write()\n");
616 ok(streamobj
.seekcalls
== 1, "wrong call count\n");
619 hRet
= pSHLWAPI_214(&streamobj
.IStream_iface
, &ul
);
620 ok(hRet
== S_OK
, "failed Stat()\n");
621 ok(ul
.QuadPart
== 0, "213 didn't rewind stream\n");
624 static void test_SHLWAPI_214(void)
626 struct dummystream streamobj
;
634 InitDummyStream(&streamobj
);
636 Seek(&streamobj
.IStream_iface
, ll
, 0, NULL
);
638 streamobj
.seekcalls
= 0;
639 hRet
= pSHLWAPI_214(&streamobj
.IStream_iface
, &ul
);
641 ok(hRet
== S_OK
, "failed Stat()\n");
642 ok(streamobj
.statcalls
== 1, "wrong call count\n");
643 ok(streamobj
.readcalls
== 0, "called Read()\n");
644 ok(streamobj
.writecalls
== 0, "called Write()\n");
645 ok(streamobj
.seekcalls
== 0, "called Seek()\n");
646 ok(ul
.QuadPart
== 5000l, "Stat gave wrong size\n");
651 if(!InitFunctionPtrs())
656 /* Test streaming if this version supports it */
657 if (test_SHLWAPI_166())