32#define ok_ole_success(hr, func) ok(hr == S_OK, func " failed with error %#08lx\n", hr)
36#define CHECK_EXPECTED_METHOD(method_name) \
38 ok(*expected_method_list != NULL, "Extra method %s called\n", method_name); \
39 if (*expected_method_list) \
41 ok(!strcmp(*expected_method_list, method_name), "Expected %s to be called instead of %s\n", \
42 *expected_method_list, method_name); \
43 expected_method_list++; \
49 const char data[] =
"Test String";
59 ok(
hr ==
S_OK,
"Failed to create a stream, hr %#lx.\n",
hr);
62 hr = IStream_SetSize(pStream, ull);
69 ll.QuadPart =
sizeof(
data) + 16;
70 hr = IStream_Seek(pStream,
ll, STREAM_SEEK_SET,
NULL);
75 ok(
read == 0,
"IStream_Read returned read %ld\n",
read);
77 ull.
u.HighPart = 0xCAFECAFE;
78 ull.
u.LowPart = 0xCAFECAFE;
81 hr = IStream_Seek(pStream,
ll, STREAM_SEEK_CUR, &ull);
83 ok(ull.
u.LowPart ==
sizeof(
data) + 16,
"LowPart set to %ld\n", ull.
u.LowPart);
84 ok(ull.
u.HighPart == 0,
"should have set HighPart to 0 instead of %ld\n", ull.
u.HighPart);
88 hr = IStream_Seek(pStream,
ll, STREAM_SEEK_SET,
NULL);
94 ok(
read ==
sizeof(
data),
"IStream_Read returned read %ld\n",
read);
99 hr = IStream_SetSize(pStream, ull);
105 hr = IStream_Seek(pStream,
ll, STREAM_SEEK_CUR,
NULL);
109 ull.
u.HighPart = 0xCAFECAFE;
110 ull.
u.LowPart = 0xCAFECAFE;
113 hr = IStream_Seek(pStream,
ll, STREAM_SEEK_CUR, &ull);
115 ok(ull.
u.LowPart ==
sizeof(
data),
"LowPart set to %ld\n", ull.
u.LowPart);
116 ok(ull.
u.HighPart == 0,
"should have set HighPart to 0 instead of %ld\n", ull.
u.HighPart);
119 ull.
u.HighPart = 0xCAFECAFE;
120 ull.
u.LowPart = 0xCAFECAFE;
123 hr = IStream_Seek(pStream,
ll, STREAM_SEEK_END+1, &ull);
124 ok(
hr ==
STG_E_SEEKERROR,
"IStream_Seek should have returned STG_E_SEEKERROR instead of 0x%08lx\n",
hr);
125 ok(ull.
u.LowPart ==
sizeof(
data),
"LowPart set to %ld\n", ull.
u.LowPart);
126 ok(ull.
u.HighPart == 0,
"should not have changed HighPart, got %ld\n", ull.
u.HighPart);
129 ull.
u.HighPart = 0xCAFECAFE;
130 ull.
u.LowPart = 0xCAFECAFE;
133 hr = IStream_Seek(pStream,
ll, STREAM_SEEK_SET, &ull);
135 ok(ull.
u.LowPart == 0,
"should have set LowPart to 0 instead of %ld\n", ull.
u.LowPart);
136 ok(ull.
u.HighPart == 0,
"should have set HighPart to 0 instead of %ld\n", ull.
u.HighPart);
139 ull.
u.HighPart = 0xCAFECAFE;
140 ull.
u.LowPart = 0xCAFECAFE;
143 hr = IStream_Seek(pStream,
ll, STREAM_SEEK_END, &ull);
145 ok(ull.
u.LowPart == 0,
"should have set LowPart to 0 instead of %ld\n", ull.
u.LowPart);
146 ok(ull.
u.HighPart == 0,
"should have set HighPart to 0 instead of %ld\n", ull.
u.HighPart);
150 ll.u.LowPart =
sizeof(
data);
151 hr = IStream_Seek(pStream,
ll, STREAM_SEEK_SET, &ull);
154 ull.
u.HighPart = 0xCAFECAFE;
155 ull.
u.LowPart = 0xCAFECAFE;
158 hr = IStream_Seek(pStream,
ll, STREAM_SEEK_CUR, &ull);
160 ok(ull.
u.LowPart ==
sizeof(
data),
"LowPart set to %ld\n", ull.
u.LowPart);
161 ok(ull.
u.HighPart == 0,
"should have set HighPart to 0 instead of %ld\n", ull.
u.HighPart);
165 ll.u.LowPart =
sizeof(
data);
166 hr = IStream_Seek(pStream,
ll, STREAM_SEEK_SET, &ull);
169 ull.
u.HighPart = 0xCAFECAFE;
170 ull.
u.LowPart = 0xCAFECAFE;
173 hr = IStream_Seek(pStream,
ll, STREAM_SEEK_SET, &ull);
175 ok(ull.
u.LowPart == 0,
"should have set LowPart to 0 instead of %ld\n", ull.
u.LowPart);
176 ok(ull.
u.HighPart == 0,
"should have set HighPart to 0 instead of %ld\n", ull.
u.HighPart);
180 ll.u.LowPart =
sizeof(
data);
181 hr = IStream_Seek(pStream,
ll, STREAM_SEEK_SET, &ull);
184 ull.
u.HighPart = 0xCAFECAFE;
185 ull.
u.LowPart = 0xCAFECAFE;
187 ll.u.LowPart = 0x80000000;
188 hr = IStream_Seek(pStream,
ll, STREAM_SEEK_CUR, &ull);
189 ok(
hr ==
STG_E_SEEKERROR,
"IStream_Seek should have returned STG_E_SEEKERROR instead of 0x%08lx\n",
hr);
190 ok(ull.
u.LowPart ==
sizeof(
data),
"LowPart set to %ld\n", ull.
u.LowPart);
191 ok(ull.
u.HighPart == 0,
"should have set HighPart to 0 instead of %ld\n", ull.
u.HighPart);
195 ll.u.LowPart =
sizeof(
data);
196 hr = IStream_Seek(pStream,
ll, STREAM_SEEK_SET, &ull);
199 ull.
u.HighPart = 0xCAFECAFE;
200 ull.
u.LowPart = 0xCAFECAFE;
203 hr = IStream_Seek(pStream,
ll, STREAM_SEEK_CUR, &ull);
205 ok(ull.
u.LowPart == 0,
"LowPart set to %ld\n", ull.
u.LowPart);
206 ok(ull.
u.HighPart == 0,
"should have set HighPart to 0 instead of %ld\n", ull.
u.HighPart);
210 ll.u.LowPart =
sizeof(
data);
211 hr = IStream_Seek(pStream,
ll, STREAM_SEEK_SET, &ull);
214 ull.
u.HighPart = 0xCAFECAFE;
215 ull.
u.LowPart = 0xCAFECAFE;
218 hr = IStream_Seek(pStream,
ll, STREAM_SEEK_CUR, &ull);
219 ok(
hr ==
STG_E_SEEKERROR,
"IStream_Seek should have returned STG_E_SEEKERROR instead of 0x%08lx\n",
hr);
220 ok(ull.
u.LowPart ==
sizeof(
data),
"LowPart set to %ld\n", ull.
u.LowPart);
221 ok(ull.
u.HighPart == 0,
"should have set HighPart to 0 instead of %ld\n", ull.
u.HighPart);
225 ll.u.LowPart =
sizeof(
data);
226 hr = IStream_Seek(pStream,
ll, STREAM_SEEK_SET, &ull);
229 ull.
u.HighPart = 0xCAFECAFE;
230 ull.
u.LowPart = 0xCAFECAFE;
232 ll.u.LowPart = 0x80000000 -
sizeof(
data);
233 hr = IStream_Seek(pStream,
ll, STREAM_SEEK_CUR, &ull);
235 ok(ull.
u.LowPart == 0x80000000,
"LowPart set to %ld\n", ull.
u.LowPart);
236 ok(ull.
u.HighPart == 0,
"should have set HighPart to 0 instead of %ld\n", ull.
u.HighPart);
240 ll.u.LowPart =
sizeof(
data);
241 hr = IStream_Seek(pStream,
ll, STREAM_SEEK_SET, &ull);
244 ull.
u.HighPart = 0xCAFECAFE;
245 ull.
u.LowPart = 0xCAFECAFE;
247 ll.u.LowPart = 0x80000000;
248 hr = IStream_Seek(pStream,
ll, STREAM_SEEK_SET, &ull);
249 ok(
hr ==
STG_E_SEEKERROR,
"IStream_Seek should have returned STG_E_SEEKERROR instead of 0x%08lx\n",
hr);
250 ok(ull.
u.LowPart ==
sizeof(
data),
"LowPart set to %ld\n", ull.
u.LowPart);
251 ok(ull.
u.HighPart == 0,
"should have set HighPart to 0 instead of %ld\n", ull.
u.HighPart);
254 ull.
u.HighPart = 0xCAFECAFE;
255 ull.
u.LowPart = 0xCAFECAFE;
257 ll.u.LowPart = 0x7FFFFFFF;
258 hr = IStream_Seek(pStream,
ll, STREAM_SEEK_SET, &ull);
260 ok(ull.
u.LowPart == 0x7FFFFFFF,
"should have set LowPart to 0x7FFFFFFF instead of %08lx\n", ull.
u.LowPart);
261 ok(ull.
u.HighPart == 0,
"should have set HighPart to 0 instead of %ld\n", ull.
u.HighPart);
266 hr = IStream_Seek(pStream,
ll, STREAM_SEEK_SET, &ull);
269 ull.
u.HighPart = 0xCAFECAFE;
270 ull.
u.LowPart = 0xCAFECAFE;
272 ll.u.LowPart = 0x7FFFFFFF;
273 hr = IStream_Seek(pStream,
ll, STREAM_SEEK_CUR, &ull);
275 ok(ull.
u.LowPart == 0x7FFFFFFF,
"should have set LowPart to 0x7FFFFFFF instead of %08lx\n", ull.
u.LowPart);
276 ok(ull.
u.HighPart == 0,
"should have set HighPart to 0 instead of %ld\n", ull.
u.HighPart);
279 ull.
u.HighPart = 0xCAFECAFE;
280 ull.
u.LowPart = 0xCAFECAFE;
283 hr = IStream_Seek(pStream,
ll, STREAM_SEEK_CUR, &ull);
285 ok(ull.
u.LowPart == 0x80000008,
"should have set LowPart to 0x80000008 instead of %08lx\n", ull.
u.LowPart);
286 ok(ull.
u.HighPart == 0,
"should have set HighPart to 0 instead of %ld\n", ull.
u.HighPart);
289 ull.
u.HighPart = 0xCAFECAFE;
290 ull.
u.LowPart = 0xCAFECAFE;
292 ll.u.LowPart = 0x7FFFFFFF;
293 hr = IStream_Seek(pStream,
ll, STREAM_SEEK_CUR, &ull);
296 ok(ull.
u.LowPart == 0x00000007,
"should have set LowPart to 0x00000007 instead of %08lx\n", ull.
u.LowPart);
298 ok(ull.
u.LowPart == 0x80000008,
"should have set LowPart to 0x80000008 instead of %08lx\n", ull.
u.LowPart);
299 ok(ull.
u.HighPart == 0,
"should have set HighPart to 0 instead of %ld\n", ull.
u.HighPart);
301 hr = IStream_Commit(pStream, STGC_DEFAULT);
304 hr = IStream_Revert(pStream);
307 hr = IStream_LockRegion(pStream, ull, ull, LOCK_WRITE);
310 hr = IStream_Stat(pStream, &statstg, STATFLAG_DEFAULT);
312 ok(statstg.type == STGTY_STREAM,
"statstg.type should have been STGTY_STREAM instead of %ld\n", statstg.type);
317 hr = IStream_SetSize(pStream, ull);
318 ok(
hr ==
S_OK,
"IStream_SetSize with large size should have returned S_OK instead of 0x%08lx\n",
hr);
320 IStream_Release(pStream);
330 IStream_AddRef(iface);
438 static const char szHello[] =
"Hello";
440 static const char *methods_copyto[] =
456 hr = IStream_Write(pStream, szHello,
sizeof(szHello), &written);
458 ok(written ==
sizeof(szHello),
"only %ld bytes written\n", written);
460 hr = IStream_Seek(pStream,
llZero, STREAM_SEEK_SET,
NULL);
463 cb.QuadPart =
sizeof(szHello);
471 hr = IStream_Clone(pStream, &pStream2);
474 hr = IStream_Seek(pStream2,
llZero, STREAM_SEEK_CUR, &libNewPosition);
476 ok(libNewPosition.
QuadPart ==
sizeof(szHello),
"libNewPosition wasn't set correctly for the cloned stream\n");
478 hr = IStream_Seek(pStream2,
llZero, STREAM_SEEK_SET,
NULL);
483 ok(!
strcmp(
buffer, szHello),
"read data \"%s\" didn't match originally written data\n",
buffer);
485 IStream_Release(pStream2);
486 IStream_Release(pStream);
491 static const char teststring[] =
"this is a test string";
496 char buffer[
sizeof(teststring) + 8];
512 ok(
read ==
sizeof(teststring) ||
513 broken(
read == ((
sizeof(teststring) + 3) & ~3)),
514 "read should be sizeof(teststring) instead of %ld\n",
read);
522 ok(
buffer[0] == 0,
"buffer data should be untouched\n");
523 ok(
read == 0,
"read should be 0 instead of %ld\n",
read);
525 ull.QuadPart =
sizeof(
buffer);
526 hr = IStream_SetSize(pStream, ull);
527 ok(
hr ==
E_OUTOFMEMORY,
"IStream_SetSize with invalid HGLOBAL should return E_OUTOFMEMORY instead of 0x%08lx\n",
hr);
530 ok(
hr ==
E_OUTOFMEMORY,
"IStream_Write with invalid HGLOBAL should return E_OUTOFMEMORY instead of 0x%08lx\n",
hr);
531 ok(written == 0,
"written should be 0 instead of %ld\n", written);
533 IStream_Release(pStream);
552 ok(
stat.type == STGTY_STREAM,
"unexpected %#lx\n",
stat.type);
553 ok(!
stat.pwcsName,
"unexpected %p\n",
stat.pwcsName);
555 ok(!
stat.cbSize.HighPart,
"unexpected %#lx\n",
stat.cbSize.HighPart);
567 static const char hello[] =
"Hello World!";
571 HGLOBAL orig_hmem, hmem, hmem_clone;
578 ok(orig_hmem != 0,
"unexpected %p\n", orig_hmem);
589 ok(hmem == orig_hmem,
"handles should match\n");
591 ok(
pos == 0,
"unexpected %d\n",
pos);
600 ok(hmem == orig_hmem,
"handles should match\n");
602 ok(
pos == 13,
"unexpected %d\n",
pos);
605 ok(hmem_clone == hmem,
"handles should match\n");
607 ok(
pos == 0,
"unexpected %d\n",
pos);
615 hr = IStream_SetSize(
stream, newsize);
619 ok(hmem == orig_hmem,
"handles should match\n");
621 ok(
pos == 13,
"unexpected %d\n",
pos);
624 ok(hmem_clone == hmem,
"handles should match\n");
626 ok(
pos == 13,
"unexpected %d\n",
pos);
628 IStream_Release(clone);
633 ok(orig_hmem != 0,
"unexpected %p\n", orig_hmem);
641 ok(hmem == orig_hmem,
"handles should match\n");
643 ok(
pos == 0,
"unexpected %d\n",
pos);
646 ok(hmem_clone == hmem,
"handles should match\n");
648 ok(
pos == 0,
"unexpected %d\n",
pos);
651 hr = IStream_SetSize(
stream, newsize);
655 ok(hmem != 0,
"unexpected %p\n", hmem);
656 ok(hmem != orig_hmem,
"unexpected %p\n", hmem);
658 ok(
pos == 0,
"unexpected %d\n",
pos);
661 ok(hmem_clone == hmem,
"handles should match\n");
663 ok(
pos == 0,
"unexpected %d\n",
pos);
666 IStream_Release(clone);
676 ok(hmem != 0,
"unexpected %p\n", hmem);
678 ok(
pos == 0,
"unexpected %d\n",
pos);
681 ok(hmem_clone == hmem,
"handles should match\n");
683 ok(
pos == 0,
"unexpected %d\n",
pos);
686 ok(
ret == 0,
"unexpected %d\n",
ret);
689 hr = IStream_SetSize(clone, newsize);
693 ok(hmem_clone == hmem,
"handles should match\n");
695 ok(
pos == 0,
"unexpected %d\n",
pos);
701 ok(hmem_clone == hmem,
"handles should match\n");
703 ok(
pos == 13,
"unexpected %d\n",
pos);
706 hr = IStream_Seek(clone,
offset, STREAM_SEEK_SET,
NULL);
715 ok(hmem_clone == hmem,
"handles should match\n");
717 ok(
pos == 32,
"unexpected %d\n",
pos);
719 ret = IStream_Release(clone);
720 ok(
ret == 0,
"unexpected %d\n",
ret);
HRESULT WINAPI GetHGlobalFromStream(IStream *stream, HGLOBAL *phglobal)
HRESULT WINAPI CreateStreamOnHGlobal(HGLOBAL hGlobal, BOOL delete_on_release, IStream **stream)
_ACRTIMP size_t __cdecl strlen(const char *)
_ACRTIMP int __cdecl strcmp(const char *, const char *)
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
GLenum GLuint GLenum GLsizei const GLchar * buf
HGLOBAL NTAPI GlobalFree(HGLOBAL hMem)
BOOL NTAPI GlobalUnlock(HGLOBAL hMem)
HGLOBAL NTAPI GlobalAlloc(UINT uFlags, SIZE_T dwBytes)
static ERESOURCE GlobalLock
static HRESULT WINAPI TestStream_Read(IStream *iface, void *pv, ULONG cb, ULONG *pcbRead)
static HRESULT WINAPI TestStream_Seek(IStream *iface, LARGE_INTEGER dlibMove, DWORD dwOrigin, ULARGE_INTEGER *plibNewPosition)
static HRESULT WINAPI TestStream_Stat(IStream *iface, STATSTG *pstatstg, DWORD grfStatFlag)
static void test_IStream_Clone(void)
static HRESULT WINAPI TestStream_LockRegion(IStream *iface, ULARGE_INTEGER libOffset, ULARGE_INTEGER cb, DWORD dwLockType)
static void test_copyto(void)
static HRESULT WINAPI TestStream_CopyTo(IStream *iface, IStream *pStream, ULARGE_INTEGER cb, ULARGE_INTEGER *pcbRead, ULARGE_INTEGER *pcbWritten)
static HRESULT WINAPI TestStream_SetSize(IStream *iface, ULARGE_INTEGER libNewSize)
#define ok_ole_success(hr, func)
static HRESULT WINAPI TestStream_Revert(IStream *iface)
static char const *const * expected_method_list
static IStreamVtbl StreamVtbl
#define CHECK_EXPECTED_METHOD(method_name)
static HRESULT WINAPI TestStream_Write(IStream *iface, const void *pv, ULONG cb, ULONG *pcbWritten)
static HRESULT WINAPI TestStream_Commit(IStream *iface, DWORD grfCommitFlags)
static void test_streamonhglobal(void)
static HRESULT WINAPI TestStream_QueryInterface(IStream *iface, REFIID riid, void **ppv)
static void stream_info(IStream *stream, HGLOBAL *hmem, int *size, int *pos)
static ULONG WINAPI TestStream_Release(IStream *iface)
static HRESULT WINAPI TestStream_UnlockRegion(IStream *iface, ULARGE_INTEGER libOffset, ULARGE_INTEGER cb, DWORD dwLockType)
static HRESULT WINAPI TestStream_Clone(IStream *iface, IStream **pStream)
static ULONG WINAPI TestStream_AddRef(IStream *iface)
static void test_freed_hglobal(void)
static IStream Test_Stream
static const LARGE_INTEGER llZero
#define IsEqualIID(riid1, riid2)
static __inline const char * wine_dbgstr_guid(const GUID *id)
struct _ULARGE_INTEGER::@4458 u
DWORD WINAPI GetLastError(void)
#define STG_E_INVALIDFUNCTION