1 /* Unit test suite for SHLWAPI ShCreateStreamOnFile functions.
3 * Copyright 2008 Reece H. Dunn
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
25 #include "wine/test.h"
32 /* Function pointers for the SHCreateStreamOnFile functions */
33 static HMODULE hShlwapi
;
34 static HRESULT (WINAPI
*pSHCreateStreamOnFileA
)(LPCSTR file
, DWORD mode
, IStream
**stream
);
35 static HRESULT (WINAPI
*pSHCreateStreamOnFileW
)(LPCWSTR file
, DWORD mode
, IStream
**stream
);
36 static HRESULT (WINAPI
*pSHCreateStreamOnFileEx
)(LPCWSTR file
, DWORD mode
, DWORD attributes
, BOOL create
, IStream
*template, IStream
**stream
);
39 static void test_IStream_invalid_operations(IStream
* stream
, DWORD mode
)
50 U(uzero
).HighPart
= 0;
59 /* IStream_Read from the COBJMACROS is undefined by shlwapi.h, replaced by the IStream_Read helper function. */
61 ret
= stream
->lpVtbl
->Read(stream
, NULL
, 0, &count
);
62 ok(ret
== S_OK
, "expected S_OK, got 0x%08x\n", ret
);
64 ret
= stream
->lpVtbl
->Read(stream
, data
, 5, NULL
);
65 ok(ret
== S_FALSE
|| ret
== S_OK
, "expected S_FALSE or S_OK, got 0x%08x\n", ret
);
67 ret
= stream
->lpVtbl
->Read(stream
, data
, 0, NULL
);
68 ok(ret
== S_OK
, "expected S_OK, got 0x%08x\n", ret
);
70 ret
= stream
->lpVtbl
->Read(stream
, data
, 3, &count
);
71 ok(ret
== S_FALSE
|| ret
== S_OK
, "expected S_FALSE or S_OK, got 0x%08x\n", ret
);
75 /* IStream_Write from the COBJMACROS is undefined by shlwapi.h, replaced by the IStream_Write helper function. */
77 ret
= stream
->lpVtbl
->Write(stream
, NULL
, 0, &count
);
78 if (mode
== STGM_READ
)
79 ok(ret
== STG_E_ACCESSDENIED
/* XP */ || ret
== S_OK
/* 2000 */,
80 "expected STG_E_ACCESSDENIED or S_OK, got 0x%08x\n", ret
);
82 ok(ret
== S_OK
, "expected S_OK, got 0x%08x\n", ret
);
84 strcpy(data
, "Hello");
85 ret
= stream
->lpVtbl
->Write(stream
, data
, 5, NULL
);
86 if (mode
== STGM_READ
)
87 ok(ret
== STG_E_ACCESSDENIED
/* XP */ || ret
== S_OK
/* 2000 */,
88 "expected STG_E_ACCESSDENIED or S_OK, got 0x%08x\n", ret
);
90 ok(ret
== S_OK
, "expected S_OK, got 0x%08x\n", ret
);
92 strcpy(data
, "Hello");
93 ret
= stream
->lpVtbl
->Write(stream
, data
, 0, NULL
);
94 if (mode
== STGM_READ
)
95 ok(ret
== STG_E_ACCESSDENIED
/* XP */ || ret
== S_OK
/* 2000 */,
96 "expected STG_E_ACCESSDENIED or S_OK, got 0x%08x\n", ret
);
98 ok(ret
== S_OK
, "expected S_OK, got 0x%08x\n", ret
);
100 strcpy(data
, "Hello");
101 ret
= stream
->lpVtbl
->Write(stream
, data
, 0, &count
);
102 if (mode
== STGM_READ
)
103 ok(ret
== STG_E_ACCESSDENIED
/* XP */ || ret
== S_OK
/* 2000 */,
104 "expected STG_E_ACCESSDENIED or S_OK, got 0x%08x\n", ret
);
106 ok(ret
== S_OK
, "expected S_OK, got 0x%08x\n", ret
);
108 strcpy(data
, "Hello");
109 ret
= stream
->lpVtbl
->Write(stream
, data
, 3, &count
);
110 if (mode
== STGM_READ
)
111 ok(ret
== STG_E_ACCESSDENIED
/* XP */ || ret
== S_OK
/* 2000 */,
112 "expected STG_E_ACCESSDENIED or S_OK, got 0x%08x\n", ret
);
114 ok(ret
== S_OK
, "expected S_OK, got 0x%08x\n", ret
);
118 ret
= IStream_Seek(stream
, zero
, STREAM_SEEK_SET
, NULL
);
119 ok(ret
== S_OK
, "expected S_OK, got 0x%08x\n", ret
);
121 ret
= IStream_Seek(stream
, zero
, 20, NULL
);
122 ok(ret
== E_INVALIDARG
/* XP */ || ret
== S_OK
/* 2000 */,
123 "expected E_INVALIDARG or S_OK, got 0x%08x\n", ret
);
125 /* IStream::CopyTo */
127 ret
= IStream_CopyTo(stream
, NULL
, uzero
, &uret
, &uret
);
128 ok(ret
== S_OK
, "expected S_OK, got 0x%08x\n", ret
);
131 ret
= IStream_CopyTo(stream
, clone
, uzero
, &uret
, &uret
);
132 ok(ret
== S_OK
, "expected S_OK, got 0x%08x\n", ret
);
134 ret
= IStream_CopyTo(stream
, stream
, uzero
, &uret
, &uret
);
135 ok(ret
== S_OK
, "expected S_OK, got 0x%08x\n", ret
);
137 ret
= IStream_CopyTo(stream
, stream
, uzero
, &uret
, NULL
);
138 ok(ret
== S_OK
, "expected S_OK, got 0x%08x\n", ret
);
140 ret
= IStream_CopyTo(stream
, stream
, uzero
, NULL
, &uret
);
141 ok(ret
== S_OK
, "expected S_OK, got 0x%08x\n", ret
);
143 /* IStream::Commit */
145 ret
= IStream_Commit(stream
, STGC_DEFAULT
);
146 ok(ret
== S_OK
, "expected S_OK, got 0x%08x\n", ret
);
148 /* IStream::Revert */
150 ret
= IStream_Revert(stream
);
151 ok(ret
== E_NOTIMPL
, "expected E_NOTIMPL, got 0x%08x\n", ret
);
153 /* IStream::LockRegion */
155 ret
= IStream_LockRegion(stream
, uzero
, uzero
, 0);
156 ok(ret
== E_NOTIMPL
/* XP */ || ret
== S_OK
/* Vista */,
157 "expected E_NOTIMPL or S_OK, got 0x%08x\n", ret
);
159 /* IStream::UnlockRegion */
161 if (ret
== E_NOTIMPL
) /* XP */ {
162 ret
= IStream_UnlockRegion(stream
, uzero
, uzero
, 0);
163 ok(ret
== E_NOTIMPL
, "expected E_NOTIMPL, got 0x%08x\n", ret
);
165 ret
= IStream_UnlockRegion(stream
, uzero
, uzero
, 0);
166 ok(ret
== S_OK
, "expected S_OK, got 0x%08x\n", ret
);
168 ret
= IStream_UnlockRegion(stream
, uzero
, uzero
, 0);
169 ok(ret
== STG_E_LOCKVIOLATION
, "expected STG_E_LOCKVIOLATION, got 0x%08x\n", ret
);
174 ret
= IStream_Stat(stream
, NULL
, 0);
175 ok(ret
== STG_E_INVALIDPOINTER
/* XP */ || ret
== E_NOTIMPL
/* 2000 */,
176 "expected STG_E_INVALIDPOINTER or E_NOTIMPL, got 0x%08x\n", ret
);
180 /* Passing a NULL pointer for the second IStream::Clone param crashes on Win7 */
183 ret
= IStream_Clone(stream
, &clone
);
184 ok(ret
== E_NOTIMPL
, "expected E_NOTIMPL, got 0x%08x\n", ret
);
185 ok(clone
== NULL
, "expected a NULL IStream object, got %p\n", stream
);
188 refcount
= IStream_Release(clone
);
189 ok(refcount
== 0, "expected 0, got %d\n", refcount
);
194 static void test_SHCreateStreamOnFileA(DWORD mode
, DWORD stgm
)
199 char test_file
[MAX_PATH
];
200 static const CHAR testA_txt
[] = "\\testA.txt";
202 trace("SHCreateStreamOnFileA: testing mode %d, STGM flags %08x\n", mode
, stgm
);
204 /* Don't used a fixed path for the testA.txt file */
205 GetTempPathA(MAX_PATH
, test_file
);
206 lstrcatA(test_file
, testA_txt
);
208 /* invalid arguments */
211 /* NT: ERROR_PATH_NOT_FOUND, 9x: ERROR_BAD_PATHNAME */
212 ret
= (*pSHCreateStreamOnFileA
)(NULL
, mode
| stgm
, &stream
);
213 ok(ret
== HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND
) ||
214 ret
== HRESULT_FROM_WIN32(ERROR_BAD_PATHNAME
),
215 "SHCreateStreamOnFileA: expected HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND)"
216 "or HRESULT_FROM_WIN32(ERROR_BAD_PATHNAME), got 0x%08x\n", ret
);
217 ok(stream
== NULL
, "SHCreateStreamOnFileA: expected a NULL IStream object, got %p\n", stream
);
219 #if 0 /* This test crashes on WinXP SP2 */
220 ret
= (*pSHCreateStreamOnFileA
)(test_file
, mode
| stgm
, NULL
);
221 ok(ret
== E_INVALIDARG
, "SHCreateStreamOnFileA: expected E_INVALIDARG, got 0x%08x\n", ret
);
225 ret
= (*pSHCreateStreamOnFileA
)(test_file
, mode
| STGM_CONVERT
| stgm
, &stream
);
226 ok(ret
== E_INVALIDARG
, "SHCreateStreamOnFileA: expected E_INVALIDARG, got 0x%08x\n", ret
);
227 ok(stream
== NULL
, "SHCreateStreamOnFileA: expected a NULL IStream object, got %p\n", stream
);
230 ret
= (*pSHCreateStreamOnFileA
)(test_file
, mode
| STGM_DELETEONRELEASE
| stgm
, &stream
);
231 ok(ret
== E_INVALIDARG
, "SHCreateStreamOnFileA: expected E_INVALIDARG, got 0x%08x\n", ret
);
232 ok(stream
== NULL
, "SHCreateStreamOnFileA: expected a NULL IStream object, got %p\n", stream
);
235 ret
= (*pSHCreateStreamOnFileA
)(test_file
, mode
| STGM_TRANSACTED
| stgm
, &stream
);
236 ok(ret
== E_INVALIDARG
, "SHCreateStreamOnFileA: expected E_INVALIDARG, got 0x%08x\n", ret
);
237 ok(stream
== NULL
, "SHCreateStreamOnFileA: expected a NULL IStream object, got %p\n", stream
);
239 /* file does not exist */
242 ret
= (*pSHCreateStreamOnFileA
)(test_file
, mode
| STGM_FAILIFTHERE
| stgm
, &stream
);
243 ok(ret
== HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND
), "SHCreateStreamOnFileA: expected HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), got 0x%08x\n", ret
);
244 ok(stream
== NULL
, "SHCreateStreamOnFileA: expected a NULL IStream object, got %p\n", stream
);
247 ret
= (*pSHCreateStreamOnFileA
)(test_file
, mode
| STGM_CREATE
| stgm
, &stream
);
248 ok(ret
== S_OK
, "SHCreateStreamOnFileA: expected S_OK, got 0x%08x\n", ret
);
249 ok(stream
!= NULL
, "SHCreateStreamOnFileA: expected a valid IStream object, got NULL\n");
252 test_IStream_invalid_operations(stream
, mode
);
254 refcount
= IStream_Release(stream
);
255 ok(refcount
== 0, "SHCreateStreamOnFileA: expected 0, got %d\n", refcount
);
258 /* NOTE: don't delete the file, as it will be used for the file exists tests. */
263 ret
= (*pSHCreateStreamOnFileA
)(test_file
, mode
| STGM_FAILIFTHERE
| stgm
, &stream
);
264 ok(ret
== S_OK
, "SHCreateStreamOnFileA: expected S_OK, got 0x%08x\n", ret
);
265 ok(stream
!= NULL
, "SHCreateStreamOnFileA: expected a valid IStream object, got NULL\n");
268 test_IStream_invalid_operations(stream
, mode
);
270 refcount
= IStream_Release(stream
);
271 ok(refcount
== 0, "SHCreateStreamOnFileA: expected 0, got %d\n", refcount
);
275 ret
= (*pSHCreateStreamOnFileA
)(test_file
, mode
| STGM_CREATE
| stgm
, &stream
);
276 ok(ret
== S_OK
, "SHCreateStreamOnFileA: expected S_OK, got 0x%08x\n", ret
);
277 ok(stream
!= NULL
, "SHCreateStreamOnFileA: expected a valid IStream object, got NULL\n");
280 test_IStream_invalid_operations(stream
, mode
);
282 refcount
= IStream_Release(stream
);
283 ok(refcount
== 0, "SHCreateStreamOnFileA: expected 0, got %d\n", refcount
);
285 ok(DeleteFileA(test_file
), "SHCreateStreamOnFileA: could not delete file '%s', got error %d\n", test_file
, GetLastError());
290 static void test_SHCreateStreamOnFileW(DWORD mode
, DWORD stgm
)
295 WCHAR test_file
[MAX_PATH
];
296 CHAR test_fileA
[MAX_PATH
];
297 static const CHAR testW_txt
[] = "\\testW.txt";
299 trace("SHCreateStreamOnFileW: testing mode %d, STGM flags %08x\n", mode
, stgm
);
301 /* Don't used a fixed path for the testW.txt file */
302 GetTempPathA(MAX_PATH
, test_fileA
);
303 lstrcatA(test_fileA
, testW_txt
);
304 MultiByteToWideChar(CP_ACP
, 0, test_fileA
, -1, test_file
, MAX_PATH
);
306 /* invalid arguments */
312 ret
= (*pSHCreateStreamOnFileW
)(NULL
, mode
| stgm
, &stream
);
313 ok(ret
== HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND
) || /* XP */
314 ret
== E_INVALIDARG
/* Vista */,
315 "SHCreateStreamOnFileW: expected HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND) or E_INVALIDARG, got 0x%08x\n", ret
);
316 ok(stream
== NULL
, "SHCreateStreamOnFileW: expected a NULL IStream object, got %p\n", stream
);
321 /* This test crashes on WinXP SP2 */
322 ret
= (*pSHCreateStreamOnFileW
)(test_file
, mode
| stgm
, NULL
);
323 ok(ret
== E_INVALIDARG
, "SHCreateStreamOnFileW: expected E_INVALIDARG, got 0x%08x\n", ret
);
327 ret
= (*pSHCreateStreamOnFileW
)(test_file
, mode
| STGM_CONVERT
| stgm
, &stream
);
328 ok(ret
== E_INVALIDARG
, "SHCreateStreamOnFileW: expected E_INVALIDARG, got 0x%08x\n", ret
);
329 ok(stream
== NULL
, "SHCreateStreamOnFileW: expected a NULL IStream object, got %p\n", stream
);
332 ret
= (*pSHCreateStreamOnFileW
)(test_file
, mode
| STGM_DELETEONRELEASE
| stgm
, &stream
);
333 ok(ret
== E_INVALIDARG
, "SHCreateStreamOnFileW: expected E_INVALIDARG, got 0x%08x\n", ret
);
334 ok(stream
== NULL
, "SHCreateStreamOnFileW: expected a NULL IStream object, got %p\n", stream
);
337 ret
= (*pSHCreateStreamOnFileW
)(test_file
, mode
| STGM_TRANSACTED
| stgm
, &stream
);
338 ok(ret
== E_INVALIDARG
, "SHCreateStreamOnFileW: expected E_INVALIDARG, got 0x%08x\n", ret
);
339 ok(stream
== NULL
, "SHCreateStreamOnFileW: expected a NULL IStream object, got %p\n", stream
);
341 /* file does not exist */
344 ret
= (*pSHCreateStreamOnFileW
)(test_file
, mode
| STGM_FAILIFTHERE
| stgm
, &stream
);
345 ok(ret
== HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND
), "SHCreateStreamOnFileW: expected HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), got 0x%08x\n", ret
);
346 ok(stream
== NULL
, "SHCreateStreamOnFileW: expected a NULL IStream object, got %p\n", stream
);
349 ret
= (*pSHCreateStreamOnFileW
)(test_file
, mode
| STGM_CREATE
| stgm
, &stream
);
350 ok(ret
== S_OK
, "SHCreateStreamOnFileW: expected S_OK, got 0x%08x\n", ret
);
351 ok(stream
!= NULL
, "SHCreateStreamOnFileW: expected a valid IStream object, got NULL\n");
354 test_IStream_invalid_operations(stream
, mode
);
356 refcount
= IStream_Release(stream
);
357 ok(refcount
== 0, "SHCreateStreamOnFileW: expected 0, got %d\n", refcount
);
360 /* NOTE: don't delete the file, as it will be used for the file exists tests. */
365 ret
= (*pSHCreateStreamOnFileW
)(test_file
, mode
| STGM_FAILIFTHERE
| stgm
, &stream
);
366 ok(ret
== S_OK
, "SHCreateStreamOnFileW: expected S_OK, got 0x%08x\n", ret
);
367 ok(stream
!= NULL
, "SHCreateStreamOnFileW: expected a valid IStream object, got NULL\n");
370 test_IStream_invalid_operations(stream
, mode
);
372 refcount
= IStream_Release(stream
);
373 ok(refcount
== 0, "SHCreateStreamOnFileW: expected 0, got %d\n", refcount
);
377 ret
= (*pSHCreateStreamOnFileW
)(test_file
, mode
| STGM_CREATE
| stgm
, &stream
);
378 ok(ret
== S_OK
, "SHCreateStreamOnFileW: expected S_OK, got 0x%08x\n", ret
);
379 ok(stream
!= NULL
, "SHCreateStreamOnFileW: expected a valid IStream object, got NULL\n");
382 test_IStream_invalid_operations(stream
, mode
);
384 refcount
= IStream_Release(stream
);
385 ok(refcount
== 0, "SHCreateStreamOnFileW: expected 0, got %d\n", refcount
);
387 ok(DeleteFileA(test_fileA
),
388 "SHCreateStreamOnFileW: could not delete the test file, got error %d\n",
394 static void test_SHCreateStreamOnFileEx(DWORD mode
, DWORD stgm
)
397 IStream
* template = NULL
;
400 WCHAR test_file
[MAX_PATH
];
401 CHAR test_fileA
[MAX_PATH
];
402 static const CHAR testEx_txt
[] = "\\testEx.txt";
404 trace("SHCreateStreamOnFileEx: testing mode %d, STGM flags %08x\n", mode
, stgm
);
406 /* Don't used a fixed path for the testEx.txt file */
407 GetTempPathA(MAX_PATH
, test_fileA
);
408 lstrcatA(test_fileA
, testEx_txt
);
409 MultiByteToWideChar(CP_ACP
, 0, test_fileA
, -1, test_file
, MAX_PATH
);
411 /* invalid arguments */
417 ret
= (*pSHCreateStreamOnFileEx
)(NULL
, mode
, 0, FALSE
, NULL
, &stream
);
418 ok(ret
== HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND
) || /* XP */
419 ret
== E_INVALIDARG
/* Vista */,
420 "SHCreateStreamOnFileEx: expected HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND) or E_INVALIDARG, got 0x%08x\n", ret
);
421 ok(stream
== NULL
, "SHCreateStreamOnFileEx: expected a NULL IStream object, got %p\n", stream
);
425 ret
= (*pSHCreateStreamOnFileEx
)(test_file
, mode
, 0, FALSE
, template, &stream
);
426 ok( ret
== HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND
) ||
427 ret
== HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER
),
428 "SHCreateStreamOnFileEx: expected HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND) or "
429 "HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER), got 0x%08x\n", ret
);
431 ok(stream
== NULL
, "SHCreateStreamOnFileEx: expected a NULL IStream object, got %p\n", stream
);
435 /* This test crashes on WinXP SP2 */
436 ret
= (*pSHCreateStreamOnFileEx
)(test_file
, mode
, 0, FALSE
, NULL
, NULL
);
437 ok(ret
== E_INVALIDARG
, "SHCreateStreamOnFileEx: expected E_INVALIDARG, got 0x%08x\n", ret
);
440 /* file does not exist */
443 ret
= (*pSHCreateStreamOnFileEx
)(test_file
, mode
| STGM_FAILIFTHERE
| stgm
, 0, FALSE
, NULL
, &stream
);
444 if ((stgm
& STGM_TRANSACTED
) == STGM_TRANSACTED
&& mode
== STGM_READ
) {
445 ok(ret
== HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND
) /* XP */ || ret
== E_INVALIDARG
/* Vista */,
446 "SHCreateStreamOnFileEx: expected E_INVALIDARG or HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), got 0x%08x\n", ret
);
448 if (ret
== E_INVALIDARG
) {
449 skip("SHCreateStreamOnFileEx: STGM_TRANSACTED not supported in this configuration.\n");
453 ok( ret
== HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND
) ||
454 ret
== HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER
),
455 "SHCreateStreamOnFileEx: expected HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND) or "
456 "HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER), got 0x%08x\n", ret
);
458 ok(stream
== NULL
, "SHCreateStreamOnFileEx: expected a NULL IStream object, got %p\n", stream
);
461 ret
= (*pSHCreateStreamOnFileEx
)(test_file
, mode
| STGM_FAILIFTHERE
| stgm
, 0, TRUE
, NULL
, &stream
);
462 /* not supported on win9x */
463 if (broken(ret
== HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER
) && stream
== NULL
)) {
464 skip("Not supported\n");
465 DeleteFileA(test_fileA
);
469 ok(ret
== S_OK
, "SHCreateStreamOnFileEx: expected S_OK, got 0x%08x\n", ret
);
470 ok(stream
!= NULL
, "SHCreateStreamOnFileEx: expected a valid IStream object, got NULL\n");
473 test_IStream_invalid_operations(stream
, mode
);
475 refcount
= IStream_Release(stream
);
476 ok(refcount
== 0, "SHCreateStreamOnFileEx: expected 0, got %d\n", refcount
);
478 ok(DeleteFileA(test_fileA
),
479 "SHCreateStreamOnFileEx: could not delete the test file, got error %d\n",
484 ret
= (*pSHCreateStreamOnFileEx
)(test_file
, mode
| STGM_CREATE
| stgm
, 0, FALSE
, NULL
, &stream
);
485 ok(ret
== S_OK
, "SHCreateStreamOnFileEx: expected S_OK, got 0x%08x\n", ret
);
486 ok(stream
!= NULL
, "SHCreateStreamOnFileEx: expected a valid IStream object, got NULL\n");
489 test_IStream_invalid_operations(stream
, mode
);
491 refcount
= IStream_Release(stream
);
492 ok(refcount
== 0, "SHCreateStreamOnFileEx: expected 0, got %d\n", refcount
);
494 ok(DeleteFileA(test_fileA
),
495 "SHCreateStreamOnFileEx: could not delete the test file, got error %d\n",
500 ret
= (*pSHCreateStreamOnFileEx
)(test_file
, mode
| STGM_CREATE
| stgm
, 0, TRUE
, NULL
, &stream
);
501 ok(ret
== S_OK
, "SHCreateStreamOnFileEx: expected S_OK, got 0x%08x\n", ret
);
502 ok(stream
!= NULL
, "SHCreateStreamOnFileEx: expected a valid IStream object, got NULL\n");
505 test_IStream_invalid_operations(stream
, mode
);
507 refcount
= IStream_Release(stream
);
508 ok(refcount
== 0, "SHCreateStreamOnFileEx: expected 0, got %d\n", refcount
);
511 /* NOTE: don't delete the file, as it will be used for the file exists tests. */
516 ret
= (*pSHCreateStreamOnFileEx
)(test_file
, mode
| STGM_FAILIFTHERE
| stgm
, 0, FALSE
, NULL
, &stream
);
517 ok(ret
== S_OK
, "SHCreateStreamOnFileEx: expected S_OK, got 0x%08x\n", ret
);
518 ok(stream
!= NULL
, "SHCreateStreamOnFileEx: expected a valid IStream object, got NULL\n");
521 test_IStream_invalid_operations(stream
, mode
);
523 refcount
= IStream_Release(stream
);
524 ok(refcount
== 0, "SHCreateStreamOnFileEx: expected 0, got %d\n", refcount
);
528 ret
= (*pSHCreateStreamOnFileEx
)(test_file
, mode
| STGM_FAILIFTHERE
| stgm
, 0, TRUE
, NULL
, &stream
);
529 ok(ret
== HRESULT_FROM_WIN32(ERROR_FILE_EXISTS
), "SHCreateStreamOnFileEx: expected HRESULT_FROM_WIN32(ERROR_FILE_EXISTS), got 0x%08x\n", ret
);
530 ok(stream
== NULL
, "SHCreateStreamOnFileEx: expected a NULL IStream object, got %p\n", stream
);
533 ret
= (*pSHCreateStreamOnFileEx
)(test_file
, mode
| STGM_CREATE
| stgm
, 0, FALSE
, NULL
, &stream
);
534 ok(ret
== S_OK
, "SHCreateStreamOnFileEx: expected S_OK, got 0x%08x\n", ret
);
535 ok(stream
!= NULL
, "SHCreateStreamOnFileEx: expected a valid IStream object, got NULL\n");
538 test_IStream_invalid_operations(stream
, mode
);
540 refcount
= IStream_Release(stream
);
541 ok(refcount
== 0, "SHCreateStreamOnFileEx: expected 0, got %d\n", refcount
);
545 ret
= (*pSHCreateStreamOnFileEx
)(test_file
, mode
| STGM_CREATE
| stgm
, 0, TRUE
, NULL
, &stream
);
546 ok(ret
== S_OK
, "SHCreateStreamOnFileEx: expected S_OK, got 0x%08x\n", ret
);
547 ok(stream
!= NULL
, "SHCreateStreamOnFileEx: expected a valid IStream object, got NULL\n");
550 test_IStream_invalid_operations(stream
, mode
);
552 refcount
= IStream_Release(stream
);
553 ok(refcount
== 0, "SHCreateStreamOnFileEx: expected 0, got %d\n", refcount
);
556 ok(DeleteFileA(test_fileA
),
557 "SHCreateStreamOnFileEx: could not delete the test file, got error %d\n",
564 static const DWORD stgm_access
[] = {
570 static const DWORD stgm_sharing
[] = {
572 STGM_SHARE_DENY_NONE
,
573 STGM_SHARE_DENY_READ
,
574 STGM_SHARE_DENY_WRITE
,
578 static const DWORD stgm_flags
[] = {
581 STGM_DELETEONRELEASE
,
582 STGM_CONVERT
| STGM_DELETEONRELEASE
,
583 STGM_TRANSACTED
| STGM_CONVERT
,
584 STGM_TRANSACTED
| STGM_DELETEONRELEASE
,
585 STGM_TRANSACTED
| STGM_CONVERT
| STGM_DELETEONRELEASE
590 hShlwapi
= GetModuleHandleA("shlwapi.dll");
592 pSHCreateStreamOnFileA
= (void*)GetProcAddress(hShlwapi
, "SHCreateStreamOnFileA");
593 pSHCreateStreamOnFileW
= (void*)GetProcAddress(hShlwapi
, "SHCreateStreamOnFileW");
594 pSHCreateStreamOnFileEx
= (void*)GetProcAddress(hShlwapi
, "SHCreateStreamOnFileEx");
596 if (!pSHCreateStreamOnFileA
)
597 skip("SHCreateStreamOnFileA not found.\n");
599 if (!pSHCreateStreamOnFileW
)
600 skip("SHCreateStreamOnFileW not found.\n");
602 if (!pSHCreateStreamOnFileEx
)
603 skip("SHCreateStreamOnFileEx not found.\n");
605 for (i
= 0; i
!= sizeof(stgm_access
)/sizeof(stgm_access
[0]); i
++) {
606 for (j
= 0; j
!= sizeof(stgm_sharing
)/sizeof(stgm_sharing
[0]); j
++) {
607 if (pSHCreateStreamOnFileA
)
608 test_SHCreateStreamOnFileA(stgm_access
[i
], stgm_sharing
[j
]);
610 if (pSHCreateStreamOnFileW
)
611 test_SHCreateStreamOnFileW(stgm_access
[i
], stgm_sharing
[j
]);
613 if (pSHCreateStreamOnFileEx
) {
614 for (k
= 0; k
!= sizeof(stgm_flags
)/sizeof(stgm_flags
[0]); k
++)
615 test_SHCreateStreamOnFileEx(stgm_access
[i
], stgm_sharing
[j
] | stgm_flags
[k
]);