[OLE32_WINETEST] Sync with Wine 3.0. CORE-14225
[reactos.git] / modules / rostests / winetests / ole32 / hglobalstream.c
1 /*
2 * Stream on HGLOBAL Tests
3 *
4 * Copyright 2006 Robert Shearman (for CodeWeavers)
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 */
20
21 #include "precomp.h"
22
23 #define ok_ole_success(hr, func) ok(hr == S_OK, func " failed with error 0x%08x\n", hr)
24
25 static char const * const *expected_method_list;
26
27 #define CHECK_EXPECTED_METHOD(method_name) \
28 do { \
29 ok(*expected_method_list != NULL, "Extra method %s called\n", method_name); \
30 if (*expected_method_list) \
31 { \
32 ok(!strcmp(*expected_method_list, method_name), "Expected %s to be called instead of %s\n", \
33 *expected_method_list, method_name); \
34 expected_method_list++; \
35 } \
36 } while(0)
37
38 static void test_streamonhglobal(IStream *pStream)
39 {
40 const char data[] = "Test String";
41 ULARGE_INTEGER ull;
42 LARGE_INTEGER ll;
43 char buffer[128];
44 ULONG read;
45 STATSTG statstg;
46 HRESULT hr;
47
48 ull.QuadPart = sizeof(data);
49 hr = IStream_SetSize(pStream, ull);
50 ok_ole_success(hr, "IStream_SetSize");
51
52 hr = IStream_Write(pStream, data, sizeof(data), NULL);
53 ok_ole_success(hr, "IStream_Write");
54
55 ll.QuadPart = 0;
56 hr = IStream_Seek(pStream, ll, STREAM_SEEK_SET, NULL);
57 ok_ole_success(hr, "IStream_Seek");
58
59 /* should return S_OK, not S_FALSE */
60 hr = IStream_Read(pStream, buffer, sizeof(buffer), &read);
61 ok_ole_success(hr, "IStream_Read");
62 ok(read == sizeof(data), "IStream_Read returned read %d\n", read);
63
64 /* ignores HighPart */
65 ull.u.HighPart = -1;
66 ull.u.LowPart = 0;
67 hr = IStream_SetSize(pStream, ull);
68 ok_ole_success(hr, "IStream_SetSize");
69
70 /* IStream_Seek -- NULL position argument */
71 ll.u.HighPart = 0;
72 ll.u.LowPart = 0;
73 hr = IStream_Seek(pStream, ll, STREAM_SEEK_CUR, NULL);
74 ok_ole_success(hr, "IStream_Seek");
75
76 /* IStream_Seek -- valid position argument (seek from current position) */
77 ull.u.HighPart = 0xCAFECAFE;
78 ull.u.LowPart = 0xCAFECAFE;
79 ll.u.HighPart = 0;
80 ll.u.LowPart = 0;
81 hr = IStream_Seek(pStream, ll, STREAM_SEEK_CUR, &ull);
82 ok_ole_success(hr, "IStream_Seek");
83 ok(ull.u.LowPart == sizeof(data), "LowPart set to %d\n", ull.u.LowPart);
84 ok(ull.u.HighPart == 0, "should have set HighPart to 0 instead of %d\n", ull.u.HighPart);
85
86 /* IStream_Seek -- invalid seek argument */
87 ull.u.HighPart = 0xCAFECAFE;
88 ull.u.LowPart = 0xCAFECAFE;
89 ll.u.HighPart = 0;
90 ll.u.LowPart = 123;
91 hr = IStream_Seek(pStream, ll, STREAM_SEEK_END+1, &ull);
92 ok(hr == STG_E_SEEKERROR, "IStream_Seek should have returned STG_E_SEEKERROR instead of 0x%08x\n", hr);
93 ok(ull.u.LowPart == sizeof(data), "LowPart set to %d\n", ull.u.LowPart);
94 ok(ull.u.HighPart == 0, "should not have changed HighPart, got %d\n", ull.u.HighPart);
95
96 /* IStream_Seek -- valid position argument (seek to beginning) */
97 ull.u.HighPart = 0xCAFECAFE;
98 ull.u.LowPart = 0xCAFECAFE;
99 ll.u.HighPart = 0;
100 ll.u.LowPart = 0;
101 hr = IStream_Seek(pStream, ll, STREAM_SEEK_SET, &ull);
102 ok_ole_success(hr, "IStream_Seek");
103 ok(ull.u.LowPart == 0, "should have set LowPart to 0 instead of %d\n", ull.u.LowPart);
104 ok(ull.u.HighPart == 0, "should have set HighPart to 0 instead of %d\n", ull.u.HighPart);
105
106 /* IStream_Seek -- valid position argument (seek to end) */
107 ull.u.HighPart = 0xCAFECAFE;
108 ull.u.LowPart = 0xCAFECAFE;
109 ll.u.HighPart = 0;
110 ll.u.LowPart = 0;
111 hr = IStream_Seek(pStream, ll, STREAM_SEEK_END, &ull);
112 ok_ole_success(hr, "IStream_Seek");
113 ok(ull.u.LowPart == 0, "should have set LowPart to 0 instead of %d\n", ull.u.LowPart);
114 ok(ull.u.HighPart == 0, "should have set HighPart to 0 instead of %d\n", ull.u.HighPart);
115
116 /* IStream_Seek -- ignore HighPart in the move value (seek from current position) */
117 ll.u.HighPart = 0;
118 ll.u.LowPart = sizeof(data);
119 hr = IStream_Seek(pStream, ll, STREAM_SEEK_SET, &ull);
120 ok_ole_success(hr, "IStream_Seek");
121
122 ull.u.HighPart = 0xCAFECAFE;
123 ull.u.LowPart = 0xCAFECAFE;
124 ll.u.HighPart = -1;
125 ll.u.LowPart = 0;
126 hr = IStream_Seek(pStream, ll, STREAM_SEEK_CUR, &ull);
127 ok_ole_success(hr, "IStream_Seek");
128 ok(ull.u.LowPart == sizeof(data), "LowPart set to %d\n", ull.u.LowPart);
129 ok(ull.u.HighPart == 0, "should have set HighPart to 0 instead of %d\n", ull.u.HighPart);
130
131 /* IStream_Seek -- ignore HighPart in the move value (seek to beginning) */
132 ll.u.HighPart = 0;
133 ll.u.LowPart = sizeof(data);
134 hr = IStream_Seek(pStream, ll, STREAM_SEEK_SET, &ull);
135 ok_ole_success(hr, "IStream_Seek");
136
137 ull.u.HighPart = 0xCAFECAFE;
138 ull.u.LowPart = 0xCAFECAFE;
139 ll.u.HighPart = -1;
140 ll.u.LowPart = 0;
141 hr = IStream_Seek(pStream, ll, STREAM_SEEK_SET, &ull);
142 ok_ole_success(hr, "IStream_Seek");
143 ok(ull.u.LowPart == 0, "should have set LowPart to 0 instead of %d\n", ull.u.LowPart);
144 ok(ull.u.HighPart == 0, "should have set HighPart to 0 instead of %d\n", ull.u.HighPart);
145
146 /* IStream_Seek -- invalid LowPart value (seek before start of stream) */
147 ll.u.HighPart = 0;
148 ll.u.LowPart = sizeof(data);
149 hr = IStream_Seek(pStream, ll, STREAM_SEEK_SET, &ull);
150 ok_ole_success(hr, "IStream_Seek");
151
152 ull.u.HighPart = 0xCAFECAFE;
153 ull.u.LowPart = 0xCAFECAFE;
154 ll.u.HighPart = 0;
155 ll.u.LowPart = 0x80000000;
156 hr = IStream_Seek(pStream, ll, STREAM_SEEK_CUR, &ull);
157 ok(hr == STG_E_SEEKERROR, "IStream_Seek should have returned STG_E_SEEKERROR instead of 0x%08x\n", hr);
158 ok(ull.u.LowPart == sizeof(data), "LowPart set to %d\n", ull.u.LowPart);
159 ok(ull.u.HighPart == 0, "should have set HighPart to 0 instead of %d\n", ull.u.HighPart);
160
161 /* IStream_Seek -- valid LowPart value (seek to start of stream) */
162 ll.u.HighPart = 0;
163 ll.u.LowPart = sizeof(data);
164 hr = IStream_Seek(pStream, ll, STREAM_SEEK_SET, &ull);
165 ok_ole_success(hr, "IStream_Seek");
166
167 ull.u.HighPart = 0xCAFECAFE;
168 ull.u.LowPart = 0xCAFECAFE;
169 ll.u.HighPart = 0;
170 ll.u.LowPart = -(DWORD)sizeof(data);
171 hr = IStream_Seek(pStream, ll, STREAM_SEEK_CUR, &ull);
172 ok_ole_success(hr, "IStream_Seek");
173 ok(ull.u.LowPart == 0, "LowPart set to %d\n", ull.u.LowPart);
174 ok(ull.u.HighPart == 0, "should have set HighPart to 0 instead of %d\n", ull.u.HighPart);
175
176 /* IStream_Seek -- invalid LowPart value (seek to start of stream-1) */
177 ll.u.HighPart = 0;
178 ll.u.LowPart = sizeof(data);
179 hr = IStream_Seek(pStream, ll, STREAM_SEEK_SET, &ull);
180 ok_ole_success(hr, "IStream_Seek");
181
182 ull.u.HighPart = 0xCAFECAFE;
183 ull.u.LowPart = 0xCAFECAFE;
184 ll.u.HighPart = 0;
185 ll.u.LowPart = -(DWORD)sizeof(data)-1;
186 hr = IStream_Seek(pStream, ll, STREAM_SEEK_CUR, &ull);
187 ok(hr == STG_E_SEEKERROR, "IStream_Seek should have returned STG_E_SEEKERROR instead of 0x%08x\n", hr);
188 ok(ull.u.LowPart == sizeof(data), "LowPart set to %d\n", ull.u.LowPart);
189 ok(ull.u.HighPart == 0, "should have set HighPart to 0 instead of %d\n", ull.u.HighPart);
190
191 /* IStream_Seek -- valid LowPart value (seek forward to 0x80000000) */
192 ll.u.HighPart = 0;
193 ll.u.LowPart = sizeof(data);
194 hr = IStream_Seek(pStream, ll, STREAM_SEEK_SET, &ull);
195 ok_ole_success(hr, "IStream_Seek");
196
197 ull.u.HighPart = 0xCAFECAFE;
198 ull.u.LowPart = 0xCAFECAFE;
199 ll.u.HighPart = 0;
200 ll.u.LowPart = 0x80000000 - sizeof(data);
201 hr = IStream_Seek(pStream, ll, STREAM_SEEK_CUR, &ull);
202 ok_ole_success(hr, "IStream_Seek");
203 ok(ull.u.LowPart == 0x80000000, "LowPart set to %d\n", ull.u.LowPart);
204 ok(ull.u.HighPart == 0, "should have set HighPart to 0 instead of %d\n", ull.u.HighPart);
205
206 /* IStream_Seek -- invalid LowPart value (seek to beginning) */
207 ll.u.HighPart = 0;
208 ll.u.LowPart = sizeof(data);
209 hr = IStream_Seek(pStream, ll, STREAM_SEEK_SET, &ull);
210 ok_ole_success(hr, "IStream_Seek");
211
212 ull.u.HighPart = 0xCAFECAFE;
213 ull.u.LowPart = 0xCAFECAFE;
214 ll.u.HighPart = 0;
215 ll.u.LowPart = 0x80000000;
216 hr = IStream_Seek(pStream, ll, STREAM_SEEK_SET, &ull);
217 ok(hr == STG_E_SEEKERROR, "IStream_Seek should have returned STG_E_SEEKERROR instead of 0x%08x\n", hr);
218 ok(ull.u.LowPart == sizeof(data), "LowPart set to %d\n", ull.u.LowPart);
219 ok(ull.u.HighPart == 0, "should have set HighPart to 0 instead of %d\n", ull.u.HighPart);
220
221 /* IStream_Seek -- valid LowPart value (seek to beginning) */
222 ull.u.HighPart = 0xCAFECAFE;
223 ull.u.LowPart = 0xCAFECAFE;
224 ll.u.HighPart = 0;
225 ll.u.LowPart = 0x7FFFFFFF;
226 hr = IStream_Seek(pStream, ll, STREAM_SEEK_SET, &ull);
227 ok_ole_success(hr, "IStream_Seek");
228 ok(ull.u.LowPart == 0x7FFFFFFF, "should have set LowPart to 0x7FFFFFFF instead of %08x\n", ull.u.LowPart);
229 ok(ull.u.HighPart == 0, "should have set HighPart to 0 instead of %d\n", ull.u.HighPart);
230
231 /* IStream_Seek -- valid LowPart value (seek from current position) */
232 ll.u.HighPart = 0;
233 ll.u.LowPart = 0;
234 hr = IStream_Seek(pStream, ll, STREAM_SEEK_SET, &ull);
235 ok_ole_success(hr, "IStream_Seek");
236
237 ull.u.HighPart = 0xCAFECAFE;
238 ull.u.LowPart = 0xCAFECAFE;
239 ll.u.HighPart = 0;
240 ll.u.LowPart = 0x7FFFFFFF;
241 hr = IStream_Seek(pStream, ll, STREAM_SEEK_CUR, &ull);
242 ok_ole_success(hr, "IStream_Seek");
243 ok(ull.u.LowPart == 0x7FFFFFFF, "should have set LowPart to 0x7FFFFFFF instead of %08x\n", ull.u.LowPart);
244 ok(ull.u.HighPart == 0, "should have set HighPart to 0 instead of %d\n", ull.u.HighPart);
245
246 /* IStream_Seek -- second seek allows you to go past 0x7FFFFFFF size */
247 ull.u.HighPart = 0xCAFECAFE;
248 ull.u.LowPart = 0xCAFECAFE;
249 ll.u.HighPart = 0;
250 ll.u.LowPart = 9;
251 hr = IStream_Seek(pStream, ll, STREAM_SEEK_CUR, &ull);
252 ok_ole_success(hr, "IStream_Seek");
253 ok(ull.u.LowPart == 0x80000008, "should have set LowPart to 0x80000008 instead of %08x\n", ull.u.LowPart);
254 ok(ull.u.HighPart == 0, "should have set HighPart to 0 instead of %d\n", ull.u.HighPart);
255
256 /* IStream_Seek -- seek wraps position/size on integer overflow, but not on win8 */
257 ull.u.HighPart = 0xCAFECAFE;
258 ull.u.LowPart = 0xCAFECAFE;
259 ll.u.HighPart = 0;
260 ll.u.LowPart = 0x7FFFFFFF;
261 hr = IStream_Seek(pStream, ll, STREAM_SEEK_CUR, &ull);
262 ok(hr == S_OK || hr == STG_E_SEEKERROR /* win8 */, "IStream_Seek\n");
263 if (SUCCEEDED(hr))
264 ok(ull.u.LowPart == 0x00000007, "should have set LowPart to 0x00000007 instead of %08x\n", ull.u.LowPart);
265 else
266 ok(ull.u.LowPart == 0x80000008, "should have set LowPart to 0x80000008 instead of %08x\n", ull.u.LowPart);
267 ok(ull.u.HighPart == 0, "should have set HighPart to 0 instead of %d\n", ull.u.HighPart);
268
269 hr = IStream_Commit(pStream, STGC_DEFAULT);
270 ok_ole_success(hr, "IStream_Commit");
271
272 hr = IStream_Revert(pStream);
273 ok_ole_success(hr, "IStream_Revert");
274
275 hr = IStream_LockRegion(pStream, ull, ull, LOCK_WRITE);
276 ok(hr == STG_E_INVALIDFUNCTION, "IStream_LockRegion should have returned STG_E_INVALIDFUNCTION instead of 0x%08x\n", hr);
277
278 hr = IStream_Stat(pStream, &statstg, STATFLAG_DEFAULT);
279 ok_ole_success(hr, "IStream_Stat");
280 ok(statstg.type == STGTY_STREAM, "statstg.type should have been STGTY_STREAM instead of %d\n", statstg.type);
281
282 /* test OOM condition */
283 ull.u.HighPart = -1;
284 ull.u.LowPart = -1;
285 hr = IStream_SetSize(pStream, ull);
286 ok(hr == E_OUTOFMEMORY || broken(hr == S_OK), /* win9x */
287 "IStream_SetSize with large size should have returned E_OUTOFMEMORY instead of 0x%08x\n", hr);
288 }
289
290 static HRESULT WINAPI TestStream_QueryInterface(IStream *iface, REFIID riid, void **ppv)
291 {
292 if (IsEqualIID(riid, &IID_IUnknown) ||
293 IsEqualIID(riid, &IID_ISequentialStream) ||
294 IsEqualIID(riid, &IID_IStream))
295 {
296 *ppv = iface;
297 IStream_AddRef(iface);
298 return S_OK;
299 }
300 *ppv = NULL;
301 return E_NOINTERFACE;
302 }
303
304 static ULONG WINAPI TestStream_AddRef(IStream *iface)
305 {
306 return 2;
307 }
308
309 static ULONG WINAPI TestStream_Release(IStream *iface)
310 {
311 return 1;
312 }
313
314 static HRESULT WINAPI TestStream_Read(IStream *iface, void *pv, ULONG cb, ULONG *pcbRead)
315 {
316 CHECK_EXPECTED_METHOD("TestStream_Read");
317 return E_NOTIMPL;
318 }
319
320 static HRESULT WINAPI TestStream_Write(IStream *iface, const void *pv, ULONG cb, ULONG *pcbWritten)
321 {
322 CHECK_EXPECTED_METHOD("TestStream_Write");
323 *pcbWritten = 5;
324 return S_OK;
325 }
326
327 static HRESULT WINAPI TestStream_Seek(IStream *iface, LARGE_INTEGER dlibMove, DWORD dwOrigin, ULARGE_INTEGER *plibNewPosition)
328 {
329 CHECK_EXPECTED_METHOD("TestStream_Seek");
330 return E_NOTIMPL;
331 }
332
333 static HRESULT WINAPI TestStream_SetSize(IStream *iface, ULARGE_INTEGER libNewSize)
334 {
335 CHECK_EXPECTED_METHOD("TestStream_SetSize");
336 return E_NOTIMPL;
337 }
338
339 static HRESULT WINAPI TestStream_CopyTo(IStream *iface, IStream *pStream, ULARGE_INTEGER cb, ULARGE_INTEGER *pcbRead, ULARGE_INTEGER *pcbWritten)
340 {
341 CHECK_EXPECTED_METHOD("TestStream_CopyTo");
342 return E_NOTIMPL;
343 }
344
345 static HRESULT WINAPI TestStream_Commit(IStream *iface, DWORD grfCommitFlags)
346 {
347 CHECK_EXPECTED_METHOD("TestStream_Commit");
348 return E_NOTIMPL;
349 }
350
351 static HRESULT WINAPI TestStream_Revert(IStream *iface)
352 {
353 CHECK_EXPECTED_METHOD("TestStream_Revert");
354 return E_NOTIMPL;
355 }
356
357 static HRESULT WINAPI TestStream_LockRegion(IStream *iface, ULARGE_INTEGER libOffset, ULARGE_INTEGER cb, DWORD dwLockType)
358 {
359 CHECK_EXPECTED_METHOD("TestStream_LockRegion");
360 return E_NOTIMPL;
361 }
362
363 static HRESULT WINAPI TestStream_UnlockRegion(IStream *iface, ULARGE_INTEGER libOffset, ULARGE_INTEGER cb, DWORD dwLockType)
364 {
365 CHECK_EXPECTED_METHOD("TestStream_UnlockRegion");
366 return E_NOTIMPL;
367 }
368
369 static HRESULT WINAPI TestStream_Stat(IStream *iface, STATSTG *pstatstg, DWORD grfStatFlag)
370 {
371 CHECK_EXPECTED_METHOD("TestStream_Stat");
372 return E_NOTIMPL;
373 }
374
375 static HRESULT WINAPI TestStream_Clone(IStream *iface, IStream **pStream)
376 {
377 CHECK_EXPECTED_METHOD("TestStream_Clone");
378 return E_NOTIMPL;
379 }
380
381 static /*const*/ IStreamVtbl StreamVtbl =
382 {
383 TestStream_QueryInterface,
384 TestStream_AddRef,
385 TestStream_Release,
386 TestStream_Read,
387 TestStream_Write,
388 TestStream_Seek,
389 TestStream_SetSize,
390 TestStream_CopyTo,
391 TestStream_Commit,
392 TestStream_Revert,
393 TestStream_LockRegion,
394 TestStream_UnlockRegion,
395 TestStream_Stat,
396 TestStream_Clone
397 };
398
399 static IStream Test_Stream = { &StreamVtbl };
400
401 static void test_copyto(void)
402 {
403 IStream *pStream, *pStream2;
404 HRESULT hr = CreateStreamOnHGlobal(NULL, TRUE, &pStream);
405 static const char szHello[] = "Hello";
406 ULARGE_INTEGER cb;
407 static const char *methods_copyto[] =
408 {
409 "TestStream_Write",
410 NULL
411 };
412 ULONG written;
413 ULARGE_INTEGER ullRead;
414 ULARGE_INTEGER ullWritten;
415 ULARGE_INTEGER libNewPosition;
416 static const LARGE_INTEGER llZero;
417 char buffer[15];
418
419 ok_ole_success(hr, "CreateStreamOnHGlobal");
420
421 expected_method_list = methods_copyto;
422
423 hr = IStream_Write(pStream, szHello, sizeof(szHello), &written);
424 ok_ole_success(hr, "IStream_Write");
425 ok(written == sizeof(szHello), "only %d bytes written\n", written);
426
427 hr = IStream_Seek(pStream, llZero, STREAM_SEEK_SET, NULL);
428 ok_ole_success(hr, "IStream_Seek");
429
430 cb.QuadPart = sizeof(szHello);
431 hr = IStream_CopyTo(pStream, &Test_Stream, cb, &ullRead, &ullWritten);
432 ok(ullWritten.QuadPart == 5, "ullWritten was %d instead\n", (ULONG)ullWritten.QuadPart);
433 ok(ullRead.QuadPart == sizeof(szHello), "only %d bytes read\n", (ULONG)ullRead.QuadPart);
434 ok_ole_success(hr, "IStream_CopyTo");
435
436 ok(!*expected_method_list, "Method sequence starting from %s not called\n", *expected_method_list);
437
438 hr = IStream_Clone(pStream, &pStream2);
439 ok_ole_success(hr, "IStream_Clone");
440
441 hr = IStream_Seek(pStream2, llZero, STREAM_SEEK_CUR, &libNewPosition);
442 ok_ole_success(hr, "IStream_Seek");
443 ok(libNewPosition.QuadPart == sizeof(szHello), "libNewPosition wasn't set correctly for the cloned stream\n");
444
445 hr = IStream_Seek(pStream2, llZero, STREAM_SEEK_SET, NULL);
446 ok_ole_success(hr, "IStream_Seek");
447
448 hr = IStream_Read(pStream2, buffer, sizeof(buffer), NULL);
449 ok_ole_success(hr, "IStream_Read");
450 ok(!strcmp(buffer, szHello), "read data \"%s\" didn't match originally written data\n", buffer);
451
452 IStream_Release(pStream2);
453 IStream_Release(pStream);
454 }
455
456 static void test_freed_hglobal(void)
457 {
458 static const char teststring[] = "this is a test string";
459 HRESULT hr;
460 IStream *pStream;
461 HGLOBAL hglobal;
462 char *p;
463 char buffer[sizeof(teststring) + 8];
464 ULARGE_INTEGER ull;
465 ULONG read, written;
466
467 hglobal = GlobalAlloc(GMEM_DDESHARE|GMEM_NODISCARD|GMEM_MOVEABLE, strlen(teststring) + 1);
468 ok(hglobal != NULL, "GlobalAlloc failed with error %d\n", GetLastError());
469 p = GlobalLock(hglobal);
470 strcpy(p, teststring);
471 GlobalUnlock(hglobal);
472
473 hr = CreateStreamOnHGlobal(hglobal, FALSE, &pStream);
474 ok_ole_success(hr, "CreateStreamOnHGlobal");
475
476 hr = IStream_Read(pStream, buffer, sizeof(buffer), &read);
477 ok_ole_success(hr, "IStream_Read");
478 ok(!strcmp(buffer, teststring), "buffer data %s differs\n", buffer);
479 ok(read == sizeof(teststring) ||
480 broken(read == ((sizeof(teststring) + 3) & ~3)), /* win9x rounds the size */
481 "read should be sizeof(teststring) instead of %d\n", read);
482
483 GlobalFree(hglobal);
484
485 memset(buffer, 0, sizeof(buffer));
486 read = -1;
487 hr = IStream_Read(pStream, buffer, sizeof(buffer), &read);
488 ok_ole_success(hr, "IStream_Read");
489 ok(buffer[0] == 0, "buffer data should be untouched\n");
490 ok(read == 0, "read should be 0 instead of %d\n", read);
491
492 ull.QuadPart = sizeof(buffer);
493 hr = IStream_SetSize(pStream, ull);
494 ok(hr == E_OUTOFMEMORY, "IStream_SetSize with invalid HGLOBAL should return E_OUTOFMEMORY instead of 0x%08x\n", hr);
495
496 hr = IStream_Write(pStream, buffer, sizeof(buffer), &written);
497 ok(hr == E_OUTOFMEMORY, "IStream_Write with invalid HGLOBAL should return E_OUTOFMEMORY instead of 0x%08x\n", hr);
498 ok(written == 0, "written should be 0 instead of %d\n", written);
499
500 IStream_Release(pStream);
501 }
502
503 START_TEST(hglobalstream)
504 {
505 HRESULT hr;
506 IStream *pStream;
507
508 hr = CreateStreamOnHGlobal(NULL, TRUE, &pStream);
509 ok_ole_success(hr, "CreateStreamOnHGlobal");
510
511 test_streamonhglobal(pStream);
512 IStream_Release(pStream);
513 test_copyto();
514 test_freed_hglobal();
515 }