ReactOS 0.4.16-dev-1946-g52006dd
istream.c
Go to the documentation of this file.
1/* Unit test suite for SHLWAPI ShCreateStreamOnFile functions.
2 *
3 * Copyright 2008 Reece H. Dunn
4 *
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.
9 *
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.
14 *
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
18 */
19
20#define COBJMACROS
21
22#include <stdarg.h>
23#include <stdio.h>
24
25#include "wine/test.h"
26#include "windef.h"
27#include "winbase.h"
28#include "objbase.h"
29#include "shlwapi.h"
30
32{
34 IStream * clone;
35 ULONG refcount;
36 ULARGE_INTEGER uzero;
37 ULARGE_INTEGER uret;
40 char data[256];
41
42 uzero.HighPart = 0;
43 uzero.LowPart = 0;
44 uret.HighPart = 0;
45 uret.LowPart = 0;
46 zero.HighPart = 0;
47 zero.LowPart = 0;
48
49 /* IStream::Read */
50
51 /* IStream_Read from the COBJMACROS is undefined by shlwapi.h, replaced by the IStream_Read helper function. */
52
53 ret = stream->lpVtbl->Read(stream, NULL, 0, &count);
54 ok(ret == S_OK, "expected S_OK, got 0x%08lx\n", ret);
55
56 ret = stream->lpVtbl->Read(stream, data, 5, NULL);
57 ok(ret == S_FALSE || ret == S_OK, "expected S_FALSE or S_OK, got 0x%08lx\n", ret);
58
59 ret = stream->lpVtbl->Read(stream, data, 0, NULL);
60 ok(ret == S_OK, "expected S_OK, got 0x%08lx\n", ret);
61
62 ret = stream->lpVtbl->Read(stream, data, 3, &count);
63 ok(ret == S_FALSE || ret == S_OK, "expected S_FALSE or S_OK, got 0x%08lx\n", ret);
64
65 /* IStream::Write */
66
67 /* IStream_Write from the COBJMACROS is undefined by shlwapi.h, replaced by the IStream_Write helper function. */
68
69 ret = stream->lpVtbl->Write(stream, NULL, 0, &count);
70 if (mode == STGM_READ)
71 {
72 ok(ret == STG_E_ACCESSDENIED /* XP */ || broken(ret == S_OK) /* Win2000 + IE5 */,
73 "expected STG_E_ACCESSDENIED, got 0x%08lx\n", ret);
74 }
75 else
76 ok(ret == S_OK, "expected S_OK, got 0x%08lx\n", ret);
77
78 strcpy(data, "Hello");
79 ret = stream->lpVtbl->Write(stream, data, 5, NULL);
80 if (mode == STGM_READ)
82 "expected STG_E_ACCESSDENIED, got 0x%08lx\n", ret);
83 else
84 ok(ret == S_OK, "expected S_OK, got 0x%08lx\n", ret);
85
86 strcpy(data, "Hello");
87 ret = stream->lpVtbl->Write(stream, data, 0, NULL);
88 if (mode == STGM_READ)
90 "expected STG_E_ACCESSDENIED, got 0x%08lx\n", ret);
91 else
92 ok(ret == S_OK, "expected S_OK, got 0x%08lx\n", ret);
93
94 strcpy(data, "Hello");
95 ret = stream->lpVtbl->Write(stream, data, 0, &count);
96 if (mode == STGM_READ)
98 "expected STG_E_ACCESSDENIED, got 0x%08lx\n", ret);
99 else
100 ok(ret == S_OK, "expected S_OK, got 0x%08lx\n", ret);
101
102 strcpy(data, "Hello");
103 ret = stream->lpVtbl->Write(stream, data, 3, &count);
104 if (mode == STGM_READ)
106 "expected STG_E_ACCESSDENIED, got 0x%08lx\n", ret);
107 else
108 ok(ret == S_OK, "expected S_OK, got 0x%08lx\n", ret);
109
110 /* IStream::Seek */
111
112 ret = IStream_Seek(stream, zero, STREAM_SEEK_SET, NULL);
113 ok(ret == S_OK, "expected S_OK, got 0x%08lx\n", ret);
114
115 ret = IStream_Seek(stream, zero, 20, NULL);
117 "expected E_INVALIDARG, got 0x%08lx\n", ret);
118
119 /* IStream::CopyTo */
120
121 ret = IStream_CopyTo(stream, NULL, uzero, &uret, &uret);
122 ok(ret == S_OK, "expected S_OK, got 0x%08lx\n", ret);
123
124 clone = NULL;
125 ret = IStream_CopyTo(stream, clone, uzero, &uret, &uret);
126 ok(ret == S_OK, "expected S_OK, got 0x%08lx\n", ret);
127
128 ret = IStream_CopyTo(stream, stream, uzero, &uret, &uret);
129 ok(ret == S_OK, "expected S_OK, got 0x%08lx\n", ret);
130
131 ret = IStream_CopyTo(stream, stream, uzero, &uret, NULL);
132 ok(ret == S_OK, "expected S_OK, got 0x%08lx\n", ret);
133
134 ret = IStream_CopyTo(stream, stream, uzero, NULL, &uret);
135 ok(ret == S_OK, "expected S_OK, got 0x%08lx\n", ret);
136
137 /* IStream::Commit */
138
139 ret = IStream_Commit(stream, STGC_DEFAULT);
140 ok(ret == S_OK, "expected S_OK, got 0x%08lx\n", ret);
141
142 /* IStream::Revert */
143
144 ret = IStream_Revert(stream);
145 ok(ret == E_NOTIMPL, "expected E_NOTIMPL, got 0x%08lx\n", ret);
146
147 /* IStream::LockRegion */
148
149 ret = IStream_LockRegion(stream, uzero, uzero, 0);
150 ok(ret == E_NOTIMPL /* XP */ || ret == S_OK /* Vista */,
151 "expected E_NOTIMPL or S_OK, got 0x%08lx\n", ret);
152
153 /* IStream::UnlockRegion */
154
155 if (ret == E_NOTIMPL) /* XP */ {
156 ret = IStream_UnlockRegion(stream, uzero, uzero, 0);
157 ok(ret == E_NOTIMPL, "expected E_NOTIMPL, got 0x%08lx\n", ret);
158 } else /* Vista */ {
159 ret = IStream_UnlockRegion(stream, uzero, uzero, 0);
160 ok(ret == S_OK, "expected S_OK, got 0x%08lx\n", ret);
161
162 ret = IStream_UnlockRegion(stream, uzero, uzero, 0);
163 ok(ret == STG_E_LOCKVIOLATION, "expected STG_E_LOCKVIOLATION, got 0x%08lx\n", ret);
164 }
165
166 /* IStream::Stat */
167
168 ret = IStream_Stat(stream, NULL, 0);
170 "expected STG_E_INVALIDPOINTER or E_NOTIMPL, got 0x%08lx\n", ret);
171
172 /* IStream::Clone */
173
174 /* Passing a NULL pointer for the second IStream::Clone param crashes on Win7 */
175
176 clone = NULL;
177 ret = IStream_Clone(stream, &clone);
178 ok(ret == E_NOTIMPL, "expected E_NOTIMPL, got 0x%08lx\n", ret);
179 ok(clone == NULL, "expected a NULL IStream object, got %p\n", stream);
180
181 if (clone) {
182 refcount = IStream_Release(clone);
183 ok(refcount == 0, "expected 0, got %ld\n", refcount);
184 }
185}
186
187
189{
190 static const LARGE_INTEGER start;
191 HRESULT ret;
192 unsigned char buf[16];
193 DWORD written, count;
194 STATSTG statstg;
195
196 /* IStream_Read/Write from the COBJMACROS is undefined by shlwapi.h */
197
198 written = 0xdeadbeaf;
199 ret = stream->lpVtbl->Write(stream, "\x5e\xa7", 2, &written);
200 if (mode == STGM_WRITE || mode == STGM_READWRITE)
201 {
202 ok(ret == S_OK, "IStream_Write error %#lx (access %#lx)\n", ret, mode);
203 ok(written == 2, "expected 2, got %lu\n", written);
204 }
205 else
206 {
207 ok(ret == STG_E_ACCESSDENIED || broken(ret == S_OK) /* win2000 */, "expected STG_E_ACCESSDENIED, got %#lx (access %#lx)\n", ret, mode);
208 ok(written == 0xdeadbeaf || broken(written == 2) /* win2000 */, "expected 0xdeadbeaf, got %#lx\n", written);
209 written = 0;
210 if (ret == S_OK) return; /* no point in further testing */
211 }
212
213 ret = stream->lpVtbl->Seek(stream, start, STREAM_SEEK_SET, NULL);
214 ok(ret == S_OK, "Seek error %#lx\n", ret);
215
216 count = 0xdeadbeaf;
217 ret = stream->lpVtbl->Read(stream, buf, 2, &count);
218 if (written != 0)
219 {
220 ok(ret == S_OK || broken(ret == S_FALSE) /* win2000 */, "IStream_Read error %#lx (access %#lx, written %lu)\n", ret, mode, written);
221 if (ret == S_OK && (mode == STGM_WRITE || mode == STGM_READWRITE))
222 {
223 ok(count == 2, "expected 2, got %lu\n", count);
224 ok(buf[0] == 0x5e && buf[1] == 0xa7, "expected 5ea7, got %02x%02x\n", buf[0], buf[1]);
225 }
226 else
227 ok(count == 0, "expected 0, got %lu\n", count);
228 }
229 else
230 {
231 ok(ret == S_FALSE, "expected S_FALSE, got %#lx (access %#lx, written %lu)\n", ret, mode, written);
232 ok(count == 0, "expected 0, got %lu\n", count);
233 }
234
235 ret = stream->lpVtbl->Seek(stream, start, STREAM_SEEK_SET, NULL);
236 ok(ret == S_OK, "Seek error %#lx\n", ret);
237
238 count = 0xdeadbeaf;
239 ret = stream->lpVtbl->Read(stream, buf, 0, &count);
240 ok(ret == S_OK, "IStream_Read error %#lx (access %#lx, written %lu)\n", ret, mode, written);
241 ok(count == 0, "expected 0, got %lu\n", count);
242
243 count = 0xdeadbeaf;
244 ret = stream->lpVtbl->Read(stream, buf, sizeof(buf), &count);
245 ok(ret == S_FALSE, "expected S_FALSE, got %#lx (access %#lx, written %lu)\n", ret, mode, written);
246 ok(count == written, "expected %lu, got %lu\n", written, count);
247 if (count)
248 ok(buf[0] == 0x5e && buf[1] == 0xa7, "expected 5ea7, got %02x%02x\n", buf[0], buf[1]);
249
250 memset(&statstg, 0xff, sizeof(statstg));
251 ret = IStream_Stat(stream, &statstg, 0);
252 ok(ret == S_OK, "Stat failed, hr %#lx.\n", ret);
253 ok(statstg.pwcsName != NULL, "Unexpected name %s.\n", wine_dbgstr_w(statstg.pwcsName));
254 CoTaskMemFree(statstg.pwcsName);
255
256 memset(&statstg, 0xff, sizeof(statstg));
257 ret = IStream_Stat(stream, &statstg, STATFLAG_NONAME);
258 ok(ret == S_OK, "Stat failed, hr %#lx.\n", ret);
259 ok(statstg.pwcsName == NULL, "Unexpected name %s.\n", wine_dbgstr_w(statstg.pwcsName));
260}
261
263{
264 IUnknown *unk;
265 HRESULT hr;
266
267 hr = IStream_QueryInterface(stream, &IID_IStream, (void **)&unk);
268 ok(SUCCEEDED(hr), "Failed to get IStream interface, hr %#lx.\n", hr);
269 IUnknown_Release(unk);
270
271 unk = NULL;
272 hr = IStream_QueryInterface(stream, &IID_ISequentialStream, (void **)&unk);
273 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* XP */, "Failed to get ISequentialStream interface, hr %#lx.\n", hr);
274 if (unk)
275 IUnknown_Release(unk);
276
277 hr = IStream_QueryInterface(stream, &IID_IUnknown, (void **)&unk);
278 ok(SUCCEEDED(hr), "Failed to get IUnknown interface, hr %#lx.\n", hr);
279 IUnknown_Release(unk);
280}
281
283{
284 IStream * stream;
285 HRESULT ret;
286 ULONG refcount;
287 char test_file[MAX_PATH];
288 static const CHAR testA_txt[] = "\\testA.txt";
289
290 trace("SHCreateStreamOnFileA: testing mode %ld, STGM flags %08lx\n", mode, stgm);
291
292 /* Don't used a fixed path for the testA.txt file */
294 lstrcatA(test_file, testA_txt);
295
296 /* invalid arguments */
297
298 stream = NULL;
300 if (ret == E_INVALIDARG) /* Win98 SE */ {
301 win_skip("Not supported\n");
302 return;
303 }
304
307 "SHCreateStreamOnFileA: expected HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND) "
308 "or HRESULT_FROM_WIN32(ERROR_BAD_PATHNAME), got 0x%08lx\n", ret);
309 ok(stream == NULL, "SHCreateStreamOnFileA: expected a NULL IStream object, got %p\n", stream);
310
311if (0) /* This test crashes on WinXP SP2 */
312{
314 ok(ret == E_INVALIDARG, "SHCreateStreamOnFileA: expected E_INVALIDARG, got 0x%08lx\n", ret);
315}
316
317 stream = NULL;
319 ok(ret == E_INVALIDARG, "SHCreateStreamOnFileA: expected E_INVALIDARG, got 0x%08lx\n", ret);
320 ok(stream == NULL, "SHCreateStreamOnFileA: expected a NULL IStream object, got %p\n", stream);
321
322 stream = NULL;
324 ok(ret == E_INVALIDARG, "SHCreateStreamOnFileA: expected E_INVALIDARG, got 0x%08lx\n", ret);
325 ok(stream == NULL, "SHCreateStreamOnFileA: expected a NULL IStream object, got %p\n", stream);
326
327 stream = NULL;
329 ok(ret == E_INVALIDARG, "SHCreateStreamOnFileA: expected E_INVALIDARG, got 0x%08lx\n", ret);
330 ok(stream == NULL, "SHCreateStreamOnFileA: expected a NULL IStream object, got %p\n", stream);
331
332 /* file does not exist */
333
334 stream = NULL;
336 ok(ret == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), "SHCreateStreamOnFileA: expected HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), got 0x%08lx\n", ret);
337 ok(stream == NULL, "SHCreateStreamOnFileA: expected a NULL IStream object, got %p\n", stream);
338
339 stream = NULL;
341 ok(ret == S_OK, "SHCreateStreamOnFileA: expected S_OK, got 0x%08lx\n", ret);
342 ok(stream != NULL, "SHCreateStreamOnFileA: expected a valid IStream object, got NULL\n");
343
344 if (stream) {
347
348 refcount = IStream_Release(stream);
349 ok(refcount == 0, "SHCreateStreamOnFileA: expected 0, got %ld\n", refcount);
350 }
351
352 /* NOTE: don't delete the file, as it will be used for the file exists tests. */
353
354 /* file exists */
355
356 stream = NULL;
358 ok(ret == S_OK, "SHCreateStreamOnFileA: expected S_OK, got 0x%08lx\n", ret);
359 ok(stream != NULL, "SHCreateStreamOnFileA: expected a valid IStream object, got NULL\n");
360
361 if (stream) {
363
364 refcount = IStream_Release(stream);
365 ok(refcount == 0, "SHCreateStreamOnFileA: expected 0, got %ld\n", refcount);
366 }
367
368 stream = NULL;
370 ok(ret == S_OK, "SHCreateStreamOnFileA: expected S_OK, got 0x%08lx\n", ret);
371 ok(stream != NULL, "SHCreateStreamOnFileA: expected a valid IStream object, got NULL\n");
372
373 if (stream) {
374 BOOL delret;
375
378
379 refcount = IStream_Release(stream);
380 ok(refcount == 0, "SHCreateStreamOnFileA: expected 0, got %ld\n", refcount);
381
382 delret = DeleteFileA(test_file);
383 ok(delret, "SHCreateStreamOnFileA: could not delete file '%s', got error %ld\n",
385 }
386}
387
388
390{
391 IStream * stream;
392 HRESULT ret;
393 ULONG refcount;
395 CHAR test_fileA[MAX_PATH];
396 static const CHAR testW_txt[] = "\\testW.txt";
397
398 trace("SHCreateStreamOnFileW: testing mode %ld, STGM flags %08lx\n", mode, stgm);
399
400 /* Don't used a fixed path for the testW.txt file */
401 GetTempPathA(MAX_PATH, test_fileA);
402 lstrcatA(test_fileA, testW_txt);
403 MultiByteToWideChar(CP_ACP, 0, test_fileA, -1, test_file, MAX_PATH);
404
405 /* invalid arguments */
406
407 if (0)
408 {
409 /* Crashes on NT4 */
410 stream = NULL;
413 ret == E_INVALIDARG /* Vista */,
414 "SHCreateStreamOnFileW: expected HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND) or E_INVALIDARG, got 0x%08lx\n", ret);
415 ok(stream == NULL, "SHCreateStreamOnFileW: expected a NULL IStream object, got %p\n", stream);
416 }
417
418 if (0)
419 {
420 /* This test crashes on WinXP SP2 */
422 ok(ret == E_INVALIDARG, "SHCreateStreamOnFileW: expected E_INVALIDARG, got 0x%08lx\n", ret);
423 }
424
425 stream = NULL;
427 ok(ret == E_INVALIDARG, "SHCreateStreamOnFileW: expected E_INVALIDARG, got 0x%08lx\n", ret);
428 ok(stream == NULL, "SHCreateStreamOnFileW: expected a NULL IStream object, got %p\n", stream);
429
430 stream = NULL;
432 ok(ret == E_INVALIDARG, "SHCreateStreamOnFileW: expected E_INVALIDARG, got 0x%08lx\n", ret);
433 ok(stream == NULL, "SHCreateStreamOnFileW: expected a NULL IStream object, got %p\n", stream);
434
435 stream = NULL;
437 ok(ret == E_INVALIDARG, "SHCreateStreamOnFileW: expected E_INVALIDARG, got 0x%08lx\n", ret);
438 ok(stream == NULL, "SHCreateStreamOnFileW: expected a NULL IStream object, got %p\n", stream);
439
440 /* file does not exist */
441
442 stream = NULL;
444 if (ret == E_INVALIDARG) /* Win98 SE */ {
445 win_skip("Not supported\n");
446 return;
447 }
448
449 ok(ret == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), "SHCreateStreamOnFileW: expected HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), got 0x%08lx\n", ret);
450 ok(stream == NULL, "SHCreateStreamOnFileW: expected a NULL IStream object, got %p\n", stream);
451
452 stream = NULL;
454 ok(ret == S_OK, "SHCreateStreamOnFileW: expected S_OK, got 0x%08lx\n", ret);
455 ok(stream != NULL, "SHCreateStreamOnFileW: expected a valid IStream object, got NULL\n");
456
457 if (stream) {
460
461 refcount = IStream_Release(stream);
462 ok(refcount == 0, "SHCreateStreamOnFileW: expected 0, got %ld\n", refcount);
463 }
464
465 /* NOTE: don't delete the file, as it will be used for the file exists tests. */
466
467 /* file exists */
468
469 stream = NULL;
471 ok(ret == S_OK, "SHCreateStreamOnFileW: expected S_OK, got 0x%08lx\n", ret);
472 ok(stream != NULL, "SHCreateStreamOnFileW: expected a valid IStream object, got NULL\n");
473
474 if (stream) {
476
477 refcount = IStream_Release(stream);
478 ok(refcount == 0, "SHCreateStreamOnFileW: expected 0, got %ld\n", refcount);
479 }
480
481 stream = NULL;
483 ok(ret == S_OK, "SHCreateStreamOnFileW: expected S_OK, got 0x%08lx\n", ret);
484 ok(stream != NULL, "SHCreateStreamOnFileW: expected a valid IStream object, got NULL\n");
485
486 if (stream) {
487 BOOL delret;
488
491
492 refcount = IStream_Release(stream);
493 ok(refcount == 0, "SHCreateStreamOnFileW: expected 0, got %ld\n", refcount);
494
495 delret = DeleteFileA(test_fileA);
496 ok(delret, "SHCreateStreamOnFileW: could not delete the test file, got error %ld\n",
497 GetLastError());
498 }
499}
500
501
503{
504 IStream * stream;
505 IStream * template = NULL;
506 HRESULT ret;
507 ULONG refcount;
509 CHAR test_fileA[MAX_PATH];
510 static const CHAR testEx_txt[] = "\\testEx.txt";
511 BOOL delret;
512
513 if (winetest_debug > 1)
514 trace("SHCreateStreamOnFileEx: testing mode %ld, STGM flags %08lx\n", mode, stgm);
515
516 /* Don't used a fixed path for the testEx.txt file */
517 GetTempPathA(MAX_PATH, test_fileA);
518 lstrcatA(test_fileA, testEx_txt);
519 MultiByteToWideChar(CP_ACP, 0, test_fileA, -1, test_file, MAX_PATH);
520
521 /* invalid arguments */
522
523 if (0)
524 {
525 /* Crashes on NT4 */
526 stream = NULL;
529 ret == E_INVALIDARG /* Vista */,
530 "SHCreateStreamOnFileEx: expected HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND) or E_INVALIDARG, got 0x%08lx\n", ret);
531 ok(stream == NULL, "SHCreateStreamOnFileEx: expected a NULL IStream object, got %p\n", stream);
532 }
533
534 stream = NULL;
537 win_skip("File probably locked by Anti-Virus/Spam software, trying again\n");
538 Sleep(1000);
540 }
543 "SHCreateStreamOnFileEx: expected HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND) or "
544 "HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER), got 0x%08lx\n", ret);
545
546 ok(stream == NULL, "SHCreateStreamOnFileEx: expected a NULL IStream object, got %p\n", stream);
547
548 if (0)
549 {
550 /* This test crashes on WinXP SP2 */
552 ok(ret == E_INVALIDARG, "SHCreateStreamOnFileEx: expected E_INVALIDARG, got 0x%08lx\n", ret);
553 }
554
555 /* file does not exist */
556
557 stream = NULL;
559 if ((stgm & STGM_TRANSACTED) == STGM_TRANSACTED && mode == STGM_READ) {
560 ok(ret == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND) /* XP */ || ret == E_INVALIDARG /* Vista */,
561 "SHCreateStreamOnFileEx: expected E_INVALIDARG or HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), got 0x%08lx\n", ret);
562
563 if (ret == E_INVALIDARG) {
564 skip("SHCreateStreamOnFileEx: STGM_TRANSACTED not supported in this configuration.\n");
565 return;
566 }
567 } else {
570 "SHCreateStreamOnFileEx: expected HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND) or "
571 "HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER), got 0x%08lx\n", ret);
572 }
573 ok(stream == NULL, "SHCreateStreamOnFileEx: expected a NULL IStream object, got %p\n", stream);
574
575 stream = NULL;
577 /* not supported on win9x */
579 skip("Not supported\n");
580 DeleteFileA(test_fileA);
581 return;
582 }
583
584 ok(ret == S_OK, "SHCreateStreamOnFileEx: expected S_OK, got 0x%08lx\n", ret);
585 ok(stream != NULL, "SHCreateStreamOnFileEx: expected a valid IStream object, got NULL\n");
586
587 if (stream) {
590
591 refcount = IStream_Release(stream);
592 ok(refcount == 0, "SHCreateStreamOnFileEx: expected 0, got %ld\n", refcount);
593
594 delret = DeleteFileA(test_fileA);
595 ok(delret, "SHCreateStreamOnFileEx: could not delete the test file, got error %ld\n",
596 GetLastError());
597 }
598
599 stream = NULL;
602 win_skip("File probably locked by Anti-Virus/Spam software, trying again\n");
603 Sleep(1000);
605 }
606 ok(ret == S_OK, "SHCreateStreamOnFileEx: expected S_OK, got 0x%08lx\n", ret);
607 ok(stream != NULL, "SHCreateStreamOnFileEx: expected a valid IStream object, got NULL\n");
608
609 if (stream) {
611
612 refcount = IStream_Release(stream);
613 ok(refcount == 0, "SHCreateStreamOnFileEx: expected 0, got %ld\n", refcount);
614
615 delret = DeleteFileA(test_fileA);
616 ok(delret, "SHCreateStreamOnFileEx: could not delete the test file, got error %ld\n",
617 GetLastError());
618 }
619
620 stream = NULL;
623 win_skip("File probably locked by Anti-Virus/Spam software, trying again\n");
624 Sleep(1000);
626 }
627 ok(ret == S_OK, "SHCreateStreamOnFileEx: expected S_OK, got 0x%08lx\n", ret);
628 ok(stream != NULL, "SHCreateStreamOnFileEx: expected a valid IStream object, got NULL\n");
629
630 if (stream) {
632
633 refcount = IStream_Release(stream);
634 ok(refcount == 0, "SHCreateStreamOnFileEx: expected 0, got %ld\n", refcount);
635 }
636
637 /* NOTE: don't delete the file, as it will be used for the file exists tests. */
638
639 /* file exists */
640
641 stream = NULL;
643 ok(ret == S_OK, "SHCreateStreamOnFileEx: expected S_OK, got 0x%08lx\n", ret);
644 ok(stream != NULL, "SHCreateStreamOnFileEx: expected a valid IStream object, got NULL\n");
645
646 if (stream) {
648
649 refcount = IStream_Release(stream);
650 ok(refcount == 0, "SHCreateStreamOnFileEx: expected 0, got %ld\n", refcount);
651 }
652
653 stream = NULL;
655 ok(ret == HRESULT_FROM_WIN32(ERROR_FILE_EXISTS), "SHCreateStreamOnFileEx: expected HRESULT_FROM_WIN32(ERROR_FILE_EXISTS), got 0x%08lx\n", ret);
656 ok(stream == NULL, "SHCreateStreamOnFileEx: expected a NULL IStream object, got %p\n", stream);
657
658 stream = NULL;
660 ok(ret == S_OK, "SHCreateStreamOnFileEx: expected S_OK, got 0x%08lx\n", ret);
661 ok(stream != NULL, "SHCreateStreamOnFileEx: expected a valid IStream object, got NULL\n");
662
663 if (stream) {
665
666 refcount = IStream_Release(stream);
667 ok(refcount == 0, "SHCreateStreamOnFileEx: expected 0, got %ld\n", refcount);
668 }
669
670 stream = NULL;
672 ok(ret == S_OK, "SHCreateStreamOnFileEx: expected S_OK, got 0x%08lx\n", ret);
673 ok(stream != NULL, "SHCreateStreamOnFileEx: expected a valid IStream object, got NULL\n");
674
675 if (stream) {
677
678 refcount = IStream_Release(stream);
679 ok(refcount == 0, "SHCreateStreamOnFileEx: expected 0, got %ld\n", refcount);
680 }
681
682 delret = DeleteFileA(test_fileA);
683 ok(delret, "SHCreateStreamOnFileEx: could not delete the test file, got error %ld\n",
684 GetLastError());
685}
686
687
689{
690 HRESULT ret;
691 IStream *src, *dst;
692 WCHAR tmpPath[MAX_PATH];
693 WCHAR srcFileName[MAX_PATH];
694 WCHAR dstFileName[MAX_PATH];
695 ULARGE_INTEGER count, read, written;
697 static const char srcContents[1];
698 static const WCHAR prefix[] = { 'T', 'S', 'T', 0 };
699
700 GetTempPathW(MAX_PATH, tmpPath);
701 ret = GetTempFileNameW(tmpPath, prefix, 0, srcFileName);
702 ok(ret != 0, "GetTempFileName failed, got error %ld\n", GetLastError());
703 ret = GetTempFileNameW(tmpPath, prefix, 0, dstFileName);
704 ok(ret != 0, "GetTempFileName failed, got error %ld\n", GetLastError());
705
707 ok(SUCCEEDED(ret), "SHCreateStreamOnFileEx failed with ret=0x%08lx\n", ret);
708
709 written.QuadPart = 0;
710 ret = IStream_Write(src, srcContents, sizeof(srcContents), &written.LowPart);
711 ok(SUCCEEDED(ret), "ISequentialStream_Write failed with ret=0x%08lx\n", ret);
712
713 distance.QuadPart = 0;
714 ret = IStream_Seek(src, distance, STREAM_SEEK_SET, &written);
715 ok(SUCCEEDED(ret), "ISequentialStream_Seek failed with ret=0x%08lx\n", ret);
716
718 ok(SUCCEEDED(ret), "SHCreateStreamOnFileEx failed with ret=0x%08lx\n", ret);
719
720 /* Test using a count larger than the source file, so that the Read operation will fall short */
721 count.QuadPart = 2;
722
723 ret = IStream_CopyTo(src, dst, count, &read, &written);
724 ok(SUCCEEDED(ret), "CopyTo failed with ret=0x%08lx\n", ret);
725
726 ok(read.QuadPart == 1, "read does not match size: %ld != 1\n", read.LowPart);
727 ok(written.QuadPart == 1, "written does not match size: %ld != 1\n", written.LowPart);
728
729 IStream_Release(dst);
730 IStream_Release(src);
731 DeleteFileW( srcFileName );
732 DeleteFileW( dstFileName );
733}
734
735static void test_SHCreateMemStream(void)
736{
737 static const BYTE initial[10];
738 IStream *stream, *stream2;
739 LARGE_INTEGER off;
740 IUnknown *unk;
741 char buff[10];
742 ULONG i, num;
743 HRESULT hr;
744
745 stream = SHCreateMemStream(initial, 0);
746 ok(stream != NULL, "Failed to create a stream.\n");
747 IStream_Release(stream);
748
750 ok(stream != NULL, "Failed to create a stream.\n");
751 IStream_Release(stream);
752
754 ok(stream != NULL, "Failed to create a stream.\n");
755
756 hr = IStream_QueryInterface(stream, &IID_ISequentialStream, (void **)&unk);
757 ok(hr == S_OK || broken(hr == E_NOINTERFACE) /* WinXP */, "Failed to QI, hr %#lx.\n", hr);
758 if (unk)
759 IUnknown_Release(unk);
760
761 num = ~0;
762 hr = IStream_Read(stream, buff, sizeof(buff), &num);
763#ifdef __REACTOS__
764 ok(hr == S_FALSE || broken(hr == S_OK) /* WS03 */, "Unexpected hr %#lx.\n", hr);
765#else
766 ok(hr == S_FALSE, "Unexpected hr %#lx.\n", hr);
767#endif
768 ok(num == 0, "expected 0, got 0x%08lx\n", num);
769
770 num = ~0;
771 memset(buff, 0x55, sizeof(buff));
772 hr = IStream_Write(stream, buff, sizeof(buff), &num);
773 ok(hr == S_OK, "Failed to write, hr %#lx.\n", hr);
774 ok(num == sizeof(buff), "expected %Iu, got %lu\n", sizeof(buff), num);
775
776 off.QuadPart = 0;
777 hr = IStream_Seek(stream, off, STREAM_SEEK_SET, NULL);
778 ok(hr == S_OK, "Failed to seek, hr %#lx.\n", hr);
779
780 num = ~0;
781 memset(buff, 0, sizeof(buff));
782 hr = IStream_Read(stream, buff, sizeof(buff), &num);
783 ok(hr == S_OK, "Failed to read, hr %#lx.\n", hr);
784 ok(num == sizeof(buff), "expected %Iu, got %lu\n", sizeof(buff), num);
785 for (i = 0; i < ARRAY_SIZE(buff); i++)
786 ok(buff[i] == 0x55, "expected 0x55, got 0x%02x at %lu\n", buff[i], i);
787
788 num = ~0;
789 hr = IStream_Read(stream, buff, sizeof(buff), &num);
790#ifdef __REACTOS__
791 ok(hr == S_FALSE || broken(hr == S_OK) /* WS03 */, "Unexpected hr %#lx.\n", hr);
792#else
793 ok(hr == S_FALSE, "Unexpected hr %#lx.\n", hr);
794#endif
795 ok(num == 0, "expected 0, got 0x%08lx\n", num);
796
797 num = ~0;
798 memset(buff, 0x11, sizeof(buff));
799 hr = IStream_Write(stream, buff, sizeof(buff), &num);
800 ok(hr == S_OK, "Failed to write, hr %#lx.\n", hr);
801 ok(num == sizeof(buff), "expected %Iu, got %lu\n", sizeof(buff), num);
802
803 off.QuadPart = -sizeof(buff);
804 hr = IStream_Seek(stream, off, STREAM_SEEK_CUR, NULL);
805 ok(hr == S_OK, "Failed to seek, hr %#lx.\n", hr);
806
807 num = ~0;
808 memset(buff, 0, sizeof(buff));
809 hr = IStream_Read(stream, buff, sizeof(buff), &num);
810 ok(hr == S_OK, "Failed to read, hr %#lx.\n", hr);
811 ok(num == sizeof(buff), "expected %Iu, got %lu\n", sizeof(buff), num);
812 for (i = 0; i < ARRAY_SIZE(buff); i++)
813 ok(buff[i] == 0x11, "expected 0x11, got 0x%02x at %lu\n", buff[i], i);
814
815 num = ~0;
816 hr = IStream_Read(stream, buff, sizeof(buff), &num);
817#ifdef __REACTOS__
818 ok(hr == S_FALSE || broken(hr == S_OK) /* WS03 */, "Unexpected hr %#lx.\n", hr);
819#else
820 ok(hr == S_FALSE, "Unexpected hr %#lx.\n", hr);
821#endif
822 ok(num == 0, "expected 0, got 0x%08lx\n", num);
823
824 hr = IStream_Clone(stream, &stream2);
826 ok(hr == S_OK || broken(hr == E_NOTIMPL) /* < Win8 */, "Failed to clone a stream, hr %#lx.\n", hr);
827 if (hr == S_OK)
828 IStream_Release(stream2);
829
830 IStream_Release(stream);
831}
832
834{
835 static const DWORD stgm_access[] = {
836 STGM_READ,
839 };
840
841 static const DWORD stgm_sharing[] = {
842 0,
847 };
848
849 static const DWORD stgm_flags[] = {
850 0,
857 };
858
859 int i, j, k;
860
861 for (i = 0; i != ARRAY_SIZE(stgm_access); i++) {
862 for (j = 0; j != ARRAY_SIZE(stgm_sharing); j ++) {
863 test_SHCreateStreamOnFileA(stgm_access[i], stgm_sharing[j]);
864 test_SHCreateStreamOnFileW(stgm_access[i], stgm_sharing[j]);
865
866 for (k = 0; k != ARRAY_SIZE(stgm_flags); k++)
867 test_SHCreateStreamOnFileEx(stgm_access[i], stgm_sharing[j] | stgm_flags[k]);
868 }
869 }
870
873}
#define read
Definition: acwin.h:96
#define trace
Definition: atltest.h:70
#define ok(value,...)
Definition: atltest.h:57
#define skip(...)
Definition: atltest.h:64
#define broken(x)
Definition: atltest.h:178
#define START_TEST(x)
Definition: atltest.h:75
#define ARRAY_SIZE(A)
Definition: main.h:20
const GUID IID_IUnknown
#define E_INVALIDARG
Definition: ddrawi.h:101
#define E_NOTIMPL
Definition: ddrawi.h:99
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
#define CP_ACP
Definition: compat.h:109
#define MAX_PATH
Definition: compat.h:34
#define MultiByteToWideChar
Definition: compat.h:110
#define ERROR_ACCESS_DENIED
Definition: compat.h:97
BOOL WINAPI DeleteFileA(IN LPCSTR lpFileName)
Definition: delete.c:24
BOOL WINAPI DeleteFileW(IN LPCWSTR lpFileName)
Definition: delete.c:39
DWORD WINAPI GetTempPathW(IN DWORD count, OUT LPWSTR path)
Definition: path.c:2080
DWORD WINAPI GetTempPathA(IN DWORD nBufferLength, OUT LPSTR lpBuffer)
Definition: path.c:2054
HRESULT WINAPI SHCreateStreamOnFileA(LPCSTR lpszPath, DWORD dwMode, IStream **lppStream)
Definition: istream.c:512
HRESULT WINAPI SHCreateStreamOnFileEx(LPCWSTR lpszPath, DWORD dwMode, DWORD dwAttributes, BOOL bCreate, IStream *lpTemplate, IStream **lppStream)
Definition: istream.c:401
HRESULT WINAPI SHCreateStreamOnFileW(LPCWSTR lpszPath, DWORD dwMode, IStream **lppStream)
Definition: istream.c:484
return ret
Definition: mutex.c:146
static unsigned char buff[32768]
Definition: fatten.c:17
UINT WINAPI GetTempFileNameW(IN LPCWSTR lpPathName, IN LPCWSTR lpPrefixString, IN UINT uUnique, OUT LPWSTR lpTempFileName)
Definition: filename.c:84
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
GLuint start
Definition: gl.h:1545
GLuint GLuint GLsizei count
Definition: gl.h:1545
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
GLenum src
Definition: glext.h:6340
GLsizei GLsizei GLfloat distance
Definition: glext.h:11755
GLenum mode
Definition: glext.h:6217
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
GLenum GLenum dst
Definition: glext.h:6340
GLuint GLuint num
Definition: glext.h:9618
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint GLint GLint j
Definition: glfuncs.h:250
VOID WINAPI CoTaskMemFree(LPVOID ptr)
Definition: ifs.c:442
#define S_OK
Definition: intsafe.h:52
#define SUCCEEDED(hr)
Definition: intsafe.h:50
#define wine_dbgstr_w
Definition: kernel32.h:34
LPSTR WINAPI lstrcatA(LPSTR lpString1, LPCSTR lpString2)
Definition: lstring.c:123
int winetest_debug
#define win_skip
Definition: minitest.h:67
#define todo_wine
Definition: minitest.h:80
#define ERROR_FILE_NOT_FOUND
Definition: disk.h:79
static IBackgroundCopyFile * test_file
Definition: file.c:39
static void test_stream_qi(IStream *stream)
Definition: istream.c:262
static void test_SHCreateStreamOnFileEx_CopyTo(void)
Definition: istream.c:688
static void test_stream_read_write(IStream *stream, DWORD mode)
Definition: istream.c:188
static void test_SHCreateStreamOnFileW(DWORD mode, DWORD stgm)
Definition: istream.c:389
static void test_SHCreateStreamOnFileEx(DWORD mode, DWORD stgm)
Definition: istream.c:502
static void test_IStream_invalid_operations(IStream *stream, DWORD mode)
Definition: istream.c:31
static void test_SHCreateMemStream(void)
Definition: istream.c:735
static void test_SHCreateStreamOnFileA(DWORD mode, DWORD stgm)
Definition: istream.c:282
int k
Definition: mpi.c:3369
#define FILE_ATTRIBUTE_TEMPORARY
Definition: nt_native.h:708
#define STGM_CREATE
Definition: objbase.h:926
#define STGM_SHARE_DENY_NONE
Definition: objbase.h:920
#define STGM_CONVERT
Definition: objbase.h:927
#define STGM_READWRITE
Definition: objbase.h:919
#define STGM_TRANSACTED
Definition: objbase.h:915
#define STGM_SHARE_EXCLUSIVE
Definition: objbase.h:923
#define STGM_FAILIFTHERE
Definition: objbase.h:928
#define STGM_DELETEONRELEASE
Definition: objbase.h:925
#define STGM_SHARE_DENY_WRITE
Definition: objbase.h:922
#define STGM_WRITE
Definition: objbase.h:918
#define STGM_READ
Definition: objbase.h:917
#define STGM_SHARE_DENY_READ
Definition: objbase.h:921
IStream *WINAPI SHCreateMemStream(const BYTE *lpbData, UINT dwDataLen)
Definition: regstream.c:652
strcpy
Definition: string.h:131
#define memset(x, y, z)
Definition: compat.h:39
int zero
Definition: sehframes.cpp:29
HRESULT hr
Definition: shlfolder.c:183
$ULONG LowPart
Definition: ntbasedef.h:581
ULONGLONG QuadPart
Definition: ms-dtyp.idl:185
$ULONG HighPart
Definition: ntbasedef.h:582
Definition: parse.h:23
VOID WINAPI DECLSPEC_HOTPATCH Sleep(IN DWORD dwMilliseconds)
Definition: synch.c:790
Character const *const prefix
Definition: tempnam.cpp:195
uint32_t ULONG
Definition: typedefs.h:59
LONGLONG QuadPart
Definition: typedefs.h:114
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define STG_E_INVALIDPOINTER
Definition: winerror.h:3666
#define S_FALSE
Definition: winerror.h:3451
static HRESULT HRESULT_FROM_WIN32(unsigned int x)
Definition: winerror.h:210
#define STG_E_LOCKVIOLATION
Definition: winerror.h:3673
#define E_NOINTERFACE
Definition: winerror.h:3479
#define ERROR_PATH_NOT_FOUND
Definition: winerror.h:228
#define ERROR_BAD_PATHNAME
Definition: winerror.h:355
#define ERROR_FILE_EXISTS
Definition: winerror.h:287
#define STG_E_ACCESSDENIED
Definition: winerror.h:3663
__wchar_t WCHAR
Definition: xmlstorage.h:180
char CHAR
Definition: xmlstorage.h:175
unsigned char BYTE
Definition: xxhash.c:193