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