[OLE32_WINETEST]
[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, but not on win8 */
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(hr == S_OK || hr == STG_E_SEEKERROR /* win8 */, "IStream_Seek\n");
276 if (SUCCEEDED(hr))
277 ok(ull.u.LowPart == 0x00000007, "should have set LowPart to 0x00000007 instead of %08x\n", ull.u.LowPart);
278 else
279 ok(ull.u.LowPart == 0x80000008, "should have set LowPart to 0x80000008 instead of %08x\n", ull.u.LowPart);
280 ok(ull.u.HighPart == 0, "should have set HighPart to 0 instead of %d\n", ull.u.HighPart);
281
282 hr = IStream_Commit(pStream, STGC_DEFAULT);
283 ok_ole_success(hr, "IStream_Commit");
284
285 hr = IStream_Revert(pStream);
286 ok_ole_success(hr, "IStream_Revert");
287
288 hr = IStream_LockRegion(pStream, ull, ull, LOCK_WRITE);
289 ok(hr == STG_E_INVALIDFUNCTION, "IStream_LockRegion should have returned STG_E_INVALIDFUNCTION instead of 0x%08x\n", hr);
290
291 hr = IStream_Stat(pStream, &statstg, STATFLAG_DEFAULT);
292 ok_ole_success(hr, "IStream_Stat");
293 ok(statstg.type == STGTY_STREAM, "statstg.type should have been STGTY_STREAM instead of %d\n", statstg.type);
294
295 /* test OOM condition */
296 ull.u.HighPart = -1;
297 ull.u.LowPart = -1;
298 hr = IStream_SetSize(pStream, ull);
299 ok(hr == E_OUTOFMEMORY || broken(hr == S_OK), /* win9x */
300 "IStream_SetSize with large size should have returned E_OUTOFMEMORY instead of 0x%08x\n", hr);
301 }
302
303 static HRESULT WINAPI TestStream_QueryInterface(IStream *iface, REFIID riid, void **ppv)
304 {
305 if (IsEqualIID(riid, &IID_IUnknown) ||
306 IsEqualIID(riid, &IID_ISequentialStream) ||
307 IsEqualIID(riid, &IID_IStream))
308 {
309 *ppv = iface;
310 IStream_AddRef(iface);
311 return S_OK;
312 }
313 *ppv = NULL;
314 return E_NOINTERFACE;
315 }
316
317 static ULONG WINAPI TestStream_AddRef(IStream *iface)
318 {
319 return 2;
320 }
321
322 static ULONG WINAPI TestStream_Release(IStream *iface)
323 {
324 return 1;
325 }
326
327 static HRESULT WINAPI TestStream_Read(IStream *iface, void *pv, ULONG cb, ULONG *pcbRead)
328 {
329 CHECK_EXPECTED_METHOD("TestStream_Read");
330 return E_NOTIMPL;
331 }
332
333 static HRESULT WINAPI TestStream_Write(IStream *iface, const void *pv, ULONG cb, ULONG *pcbWritten)
334 {
335 CHECK_EXPECTED_METHOD("TestStream_Write");
336 *pcbWritten = 5;
337 return S_OK;
338 }
339
340 static HRESULT WINAPI TestStream_Seek(IStream *iface, LARGE_INTEGER dlibMove, DWORD dwOrigin, ULARGE_INTEGER *plibNewPosition)
341 {
342 CHECK_EXPECTED_METHOD("TestStream_Seek");
343 return E_NOTIMPL;
344 }
345
346 static HRESULT WINAPI TestStream_SetSize(IStream *iface, ULARGE_INTEGER libNewSize)
347 {
348 CHECK_EXPECTED_METHOD("TestStream_SetSize");
349 return E_NOTIMPL;
350 }
351
352 static HRESULT WINAPI TestStream_CopyTo(IStream *iface, IStream *pStream, ULARGE_INTEGER cb, ULARGE_INTEGER *pcbRead, ULARGE_INTEGER *pcbWritten)
353 {
354 CHECK_EXPECTED_METHOD("TestStream_CopyTo");
355 return E_NOTIMPL;
356 }
357
358 static HRESULT WINAPI TestStream_Commit(IStream *iface, DWORD grfCommitFlags)
359 {
360 CHECK_EXPECTED_METHOD("TestStream_Commit");
361 return E_NOTIMPL;
362 }
363
364 static HRESULT WINAPI TestStream_Revert(IStream *iface)
365 {
366 CHECK_EXPECTED_METHOD("TestStream_Revert");
367 return E_NOTIMPL;
368 }
369
370 static HRESULT WINAPI TestStream_LockRegion(IStream *iface, ULARGE_INTEGER libOffset, ULARGE_INTEGER cb, DWORD dwLockType)
371 {
372 CHECK_EXPECTED_METHOD("TestStream_LockRegion");
373 return E_NOTIMPL;
374 }
375
376 static HRESULT WINAPI TestStream_UnlockRegion(IStream *iface, ULARGE_INTEGER libOffset, ULARGE_INTEGER cb, DWORD dwLockType)
377 {
378 CHECK_EXPECTED_METHOD("TestStream_UnlockRegion");
379 return E_NOTIMPL;
380 }
381
382 static HRESULT WINAPI TestStream_Stat(IStream *iface, STATSTG *pstatstg, DWORD grfStatFlag)
383 {
384 CHECK_EXPECTED_METHOD("TestStream_Stat");
385 return E_NOTIMPL;
386 }
387
388 static HRESULT WINAPI TestStream_Clone(IStream *iface, IStream **pStream)
389 {
390 CHECK_EXPECTED_METHOD("TestStream_Clone");
391 return E_NOTIMPL;
392 }
393
394 static /*const*/ IStreamVtbl StreamVtbl =
395 {
396 TestStream_QueryInterface,
397 TestStream_AddRef,
398 TestStream_Release,
399 TestStream_Read,
400 TestStream_Write,
401 TestStream_Seek,
402 TestStream_SetSize,
403 TestStream_CopyTo,
404 TestStream_Commit,
405 TestStream_Revert,
406 TestStream_LockRegion,
407 TestStream_UnlockRegion,
408 TestStream_Stat,
409 TestStream_Clone
410 };
411
412 static IStream Test_Stream = { &StreamVtbl };
413
414 static void test_copyto(void)
415 {
416 IStream *pStream, *pStream2;
417 HRESULT hr = CreateStreamOnHGlobal(NULL, TRUE, &pStream);
418 static const char szHello[] = "Hello";
419 ULARGE_INTEGER cb;
420 static const char *methods_copyto[] =
421 {
422 "TestStream_Write",
423 NULL
424 };
425 ULONG written;
426 ULARGE_INTEGER ullRead;
427 ULARGE_INTEGER ullWritten;
428 ULARGE_INTEGER libNewPosition;
429 static const LARGE_INTEGER llZero;
430 char buffer[15];
431
432 ok_ole_success(hr, "CreateStreamOnHGlobal");
433
434 expected_method_list = methods_copyto;
435
436 hr = IStream_Write(pStream, szHello, sizeof(szHello), &written);
437 ok_ole_success(hr, "IStream_Write");
438 ok(written == sizeof(szHello), "only %d bytes written\n", written);
439
440 hr = IStream_Seek(pStream, llZero, STREAM_SEEK_SET, NULL);
441 ok_ole_success(hr, "IStream_Seek");
442
443 cb.QuadPart = sizeof(szHello);
444 hr = IStream_CopyTo(pStream, &Test_Stream, cb, &ullRead, &ullWritten);
445 ok(ullWritten.QuadPart == 5, "ullWritten was %d instead\n", (ULONG)ullWritten.QuadPart);
446 ok(ullRead.QuadPart == sizeof(szHello), "only %d bytes read\n", (ULONG)ullRead.QuadPart);
447 ok_ole_success(hr, "IStream_CopyTo");
448
449 ok(!*expected_method_list, "Method sequence starting from %s not called\n", *expected_method_list);
450
451 hr = IStream_Clone(pStream, &pStream2);
452 ok_ole_success(hr, "IStream_Clone");
453
454 hr = IStream_Seek(pStream2, llZero, STREAM_SEEK_CUR, &libNewPosition);
455 ok_ole_success(hr, "IStream_Seek");
456 ok(libNewPosition.QuadPart == sizeof(szHello), "libNewPosition wasn't set correctly for the cloned stream\n");
457
458 hr = IStream_Seek(pStream2, llZero, STREAM_SEEK_SET, NULL);
459 ok_ole_success(hr, "IStream_Seek");
460
461 hr = IStream_Read(pStream2, buffer, sizeof(buffer), NULL);
462 ok_ole_success(hr, "IStream_Read");
463 ok(!strcmp(buffer, szHello), "read data \"%s\" didn't match originally written data\n", buffer);
464
465 IStream_Release(pStream2);
466 IStream_Release(pStream);
467 }
468
469 static void test_freed_hglobal(void)
470 {
471 static const char teststring[] = "this is a test string";
472 HRESULT hr;
473 IStream *pStream;
474 HGLOBAL hglobal;
475 char *p;
476 char buffer[sizeof(teststring) + 8];
477 ULARGE_INTEGER ull;
478 ULONG read, written;
479
480 hglobal = GlobalAlloc(GMEM_DDESHARE|GMEM_NODISCARD|GMEM_MOVEABLE, strlen(teststring) + 1);
481 ok(hglobal != NULL, "GlobalAlloc failed with error %d\n", GetLastError());
482 p = GlobalLock(hglobal);
483 strcpy(p, teststring);
484 GlobalUnlock(hglobal);
485
486 hr = CreateStreamOnHGlobal(hglobal, FALSE, &pStream);
487 ok_ole_success(hr, "CreateStreamOnHGlobal");
488
489 hr = IStream_Read(pStream, buffer, sizeof(buffer), &read);
490 ok_ole_success(hr, "IStream_Read");
491 ok(!strcmp(buffer, teststring), "buffer data %s differs\n", buffer);
492 ok(read == sizeof(teststring) ||
493 broken(read == ((sizeof(teststring) + 3) & ~3)), /* win9x rounds the size */
494 "read should be sizeof(teststring) instead of %d\n", read);
495
496 GlobalFree(hglobal);
497
498 memset(buffer, 0, sizeof(buffer));
499 read = -1;
500 hr = IStream_Read(pStream, buffer, sizeof(buffer), &read);
501 ok_ole_success(hr, "IStream_Read");
502 ok(buffer[0] == 0, "buffer data should be untouched\n");
503 ok(read == 0, "read should be 0 instead of %d\n", read);
504
505 ull.QuadPart = sizeof(buffer);
506 hr = IStream_SetSize(pStream, ull);
507 ok(hr == E_OUTOFMEMORY, "IStream_SetSize with invalid HGLOBAL should return E_OUTOFMEMORY instead of 0x%08x\n", hr);
508
509 hr = IStream_Write(pStream, buffer, sizeof(buffer), &written);
510 ok(hr == E_OUTOFMEMORY, "IStream_Write with invalid HGLOBAL should return E_OUTOFMEMORY instead of 0x%08x\n", hr);
511 ok(written == 0, "written should be 0 instead of %d\n", written);
512
513 IStream_Release(pStream);
514 }
515
516 START_TEST(hglobalstream)
517 {
518 HRESULT hr;
519 IStream *pStream;
520
521 hr = CreateStreamOnHGlobal(NULL, TRUE, &pStream);
522 ok_ole_success(hr, "CreateStreamOnHGlobal");
523
524 test_streamonhglobal(pStream);
525 IStream_Release(pStream);
526 test_copyto();
527 test_freed_hglobal();
528 }