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