2 * Copyright 2009 Tony Wasserka
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 #include "wine/test.h"
24 static void test_StreamOnMemory(void)
26 IWICImagingFactory
*pFactory
;
27 IWICStream
*pStream
, *pBufStream
;
28 const BYTE CmpMem
[] = {
29 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
30 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
31 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
32 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
34 BYTE Memory
[64], MemBuf
[64];
35 LARGE_INTEGER LargeNull
, LargeInt
;
36 ULARGE_INTEGER uLargeNull
, uNewPos
;
37 ULONG uBytesRead
, uBytesWritten
;
41 LargeNull
.QuadPart
= 0;
42 uLargeNull
.QuadPart
= 0;
44 memcpy(Memory
, CmpMem
, sizeof(CmpMem
));
48 hr
= CoCreateInstance(&CLSID_WICImagingFactory
, NULL
, CLSCTX_INPROC_SERVER
, &IID_IWICImagingFactory
, (void**)&pFactory
);
50 skip("CoCreateInstance returned with %#x, expected %#x\n", hr
, S_OK
);
54 hr
= IWICImagingFactory_CreateStream(pFactory
, &pStream
);
55 ok(hr
== S_OK
, "CreateStream returned with %#x, expected %#x\n", hr
, S_OK
);
57 skip("Failed to create stream\n");
61 /* InitializeFromMemory */
62 hr
= IWICStream_InitializeFromMemory(pStream
, NULL
, sizeof(Memory
)); /* memory = NULL */
63 ok(hr
== E_INVALIDARG
, "InitializeFromMemory returned with %#x, expected %#x\n", hr
, E_INVALIDARG
);
65 hr
= IWICStream_InitializeFromMemory(pStream
, Memory
, 0); /* size = 0 */
66 ok(hr
== S_OK
, "InitializeFromMemory returned with %#x, expected %#x\n", hr
, S_OK
);
68 hr
= IWICStream_InitializeFromMemory(pStream
, Memory
, sizeof(Memory
)); /* stream already initialized */
69 ok(hr
== WINCODEC_ERR_WRONGSTATE
, "InitializeFromMemory returned with %#x, expected %#x\n", hr
, WINCODEC_ERR_WRONGSTATE
);
72 IWICStream_Release(pStream
);
73 hr
= IWICImagingFactory_CreateStream(pFactory
, &pStream
);
74 ok(hr
== S_OK
, "CreateStream failed with %#x\n", hr
);
76 hr
= IWICStream_InitializeFromMemory(pStream
, Memory
, sizeof(Memory
));
77 ok(hr
== S_OK
, "InitializeFromMemory returned with %#x, expected %#x\n", hr
, S_OK
);
81 hr
= IWICStream_Seek(pStream
, LargeNull
, STREAM_SEEK_SET
, &uNewPos
);
82 ok(hr
== S_OK
, "Seek returned with %#x, expected %#x\n", hr
, S_OK
);
83 ok(uNewPos
.u
.HighPart
== 0 && uNewPos
.u
.LowPart
== 0, "Seek cursor moved to position (%u;%u), expected (%u;%u)\n", uNewPos
.u
.HighPart
, uNewPos
.u
.LowPart
, 0, 0);
85 hr
= IWICStream_Seek(pStream
, LargeNull
, STREAM_SEEK_SET
, NULL
);
86 ok(hr
== S_OK
, "Seek returned with %#x, expected %#x\n", hr
, S_OK
);
88 LargeInt
.u
.HighPart
= 1;
89 LargeInt
.u
.LowPart
= 0;
90 hr
= IWICStream_Seek(pStream
, LargeInt
, STREAM_SEEK_SET
, &uNewPos
);
91 ok(hr
== HRESULT_FROM_WIN32(ERROR_ARITHMETIC_OVERFLOW
), "Seek returned with %#x, expected %#x\n", hr
, HRESULT_FROM_WIN32(ERROR_ARITHMETIC_OVERFLOW
));
92 ok(uNewPos
.u
.HighPart
== 0 && uNewPos
.u
.LowPart
== 0, "Seek cursor moved to position (%u;%u), expected (%u;%u)\n", uNewPos
.u
.HighPart
, uNewPos
.u
.LowPart
, 0, 0);
94 LargeInt
.QuadPart
= sizeof(Memory
) + 10;
95 hr
= IWICStream_Seek(pStream
, LargeInt
, STREAM_SEEK_SET
, &uNewPos
);
96 ok(hr
== E_INVALIDARG
, "Seek returned with %#x, expected %#x\n", hr
, E_INVALIDARG
);
97 ok(uNewPos
.u
.HighPart
== 0 && uNewPos
.u
.LowPart
== 0, "Seek cursor moved to position (%u;%u), expected (%u;%u)\n", uNewPos
.u
.HighPart
, uNewPos
.u
.LowPart
, 0, 0);
99 LargeInt
.QuadPart
= 1;
100 hr
= IWICStream_Seek(pStream
, LargeInt
, STREAM_SEEK_END
, &uNewPos
);
101 ok(hr
== E_INVALIDARG
, "Seek returned with %#x, expected %#x\n", hr
, E_INVALIDARG
);
102 ok(uNewPos
.u
.HighPart
== 0 && uNewPos
.u
.LowPart
== 0, "Seek cursor moved to position (%u;%u), expected (%u;%u)\n", uNewPos
.u
.HighPart
, uNewPos
.u
.LowPart
, 0, 0);
104 LargeInt
.QuadPart
= -1;
105 hr
= IWICStream_Seek(pStream
, LargeInt
, STREAM_SEEK_END
, &uNewPos
);
106 ok(hr
== S_OK
, "Seek returned with %#x, expected %#x\n", hr
, S_OK
);
107 ok(uNewPos
.u
.HighPart
== 0 && uNewPos
.u
.LowPart
== sizeof(Memory
) - 1, "bSeek cursor moved to position (%u;%u), expected (%u;%u)\n", uNewPos
.u
.HighPart
, uNewPos
.u
.LowPart
, 0, sizeof(Memory
) - 1);
109 IWICStream_Seek(pStream
, LargeNull
, STREAM_SEEK_SET
, &uNewPos
); /* reset seek pointer */
110 LargeInt
.QuadPart
= -sizeof(Memory
) - 5;
111 hr
= IWICStream_Seek(pStream
, LargeInt
, STREAM_SEEK_END
, &uNewPos
);
112 ok(hr
== E_INVALIDARG
, "Seek returned with %#x, expected %#x\n", hr
, E_INVALIDARG
);
113 ok(uNewPos
.u
.HighPart
== 0 && uNewPos
.u
.LowPart
== 0, "bSeek cursor moved to position (%u;%u), expected (%u;%u)\n", uNewPos
.u
.HighPart
, uNewPos
.u
.LowPart
, 0, 0); /* remains unchanged */
114 IWICStream_Seek(pStream
, LargeNull
, STREAM_SEEK_SET
, NULL
);
118 hr
= IWICStream_Read(pStream
, MemBuf
, 12, &uBytesRead
);
119 ok(hr
== S_OK
, "Read returned with %#x, expected %#x\n", hr
, S_OK
);
121 ok(uBytesRead
== 12, "Read %u bytes, expected %u\n", uBytesRead
, 3);
122 ok(memcmp(MemBuf
, CmpMem
, 12) == 0, "Read returned invalid data!\n");
124 /* check whether the seek pointer has moved correctly */
125 IWICStream_Seek(pStream
, LargeNull
, STREAM_SEEK_CUR
, &uNewPos
);
126 ok(uNewPos
.u
.HighPart
== 0 && uNewPos
.u
.LowPart
== uBytesRead
, "Seek cursor moved to position (%u;%u), expected (%u;%u)\n", uNewPos
.u
.HighPart
, uNewPos
.u
.LowPart
, 0, uBytesRead
);
129 IWICStream_Seek(pStream
, LargeNull
, STREAM_SEEK_SET
, NULL
);
131 hr
= IWICStream_Read(pStream
, Memory
, 10, &uBytesRead
); /* source = dest */
132 ok(hr
== S_OK
, "Read returned with %#x, expected %#x\n", hr
, S_OK
);
134 ok(uBytesRead
== 10, "Read %u bytes, expected %u\n", uBytesRead
, 10);
135 ok(memcmp(Memory
, CmpMem
, uBytesRead
) == 0, "Read returned invalid data!\n");
138 IWICStream_Seek(pStream
, LargeNull
, STREAM_SEEK_SET
, NULL
);
140 hr
= IWICStream_Read(pStream
, Memory
, sizeof(Memory
) + 10, &uBytesRead
); /* request too many bytes */
141 ok(hr
== S_OK
, "Read returned with %#x, expected %#x\n", hr
, S_OK
);
143 ok(uBytesRead
== sizeof(Memory
), "Read %u bytes, expected %u\n", uBytesRead
, sizeof(Memory
));
144 ok(memcmp(Memory
, CmpMem
, uBytesRead
) == 0, "Read returned invalid data!\n");
147 hr
= IWICStream_Read(pStream
, NULL
, 1, &uBytesRead
); /* destination buffer = NULL */
148 ok(hr
== E_INVALIDARG
, "Read returned with %#x, expected %#x\n", hr
, E_INVALIDARG
);
150 hr
= IWICStream_Read(pStream
, MemBuf
, 0, &uBytesRead
); /* read 0 bytes */
151 ok(hr
== S_OK
, "Read returned with %#x, expected %#x\n", hr
, S_OK
);
153 hr
= IWICStream_Read(pStream
, NULL
, 0, &uBytesRead
);
154 ok(hr
== E_INVALIDARG
, "Read returned with %#x, expected %#x\n", hr
, E_INVALIDARG
);
156 hr
= IWICStream_Read(pStream
, NULL
, 0, NULL
);
157 ok(hr
== E_INVALIDARG
, "Read returned with %#x, expected %#x\n", hr
, E_INVALIDARG
);
159 hr
= IWICStream_Read(pStream
, MemBuf
, 1, NULL
);
160 ok(hr
== S_OK
, "Read returned with %#x, expected %#x\n", hr
, S_OK
);
162 IWICStream_Seek(pStream
, LargeNull
, STREAM_SEEK_SET
, NULL
);
163 ZeroMemory(MemBuf
, sizeof(MemBuf
));
164 hr
= IWICStream_Read(pStream
, MemBuf
, sizeof(Memory
) + 10, &uBytesRead
);
165 ok(hr
== S_OK
, "Read returned with %#x, expected %#x\n", hr
, S_OK
);
167 ok(uBytesRead
== sizeof(Memory
), "Read %u bytes, expected %u\n", uBytesRead
, sizeof(Memory
));
168 ok(memcmp(Memory
, CmpMem
, 64) == 0, "Read returned invalid data!\n");
170 IWICStream_Seek(pStream
, LargeNull
, STREAM_SEEK_SET
, NULL
);
174 MemBuf
[0] = CmpMem
[0] + 1;
175 MemBuf
[1] = CmpMem
[1] + 1;
176 MemBuf
[2] = CmpMem
[2] + 1;
177 hr
= IWICStream_Write(pStream
, MemBuf
, 3, &uBytesWritten
);
178 ok(hr
== S_OK
, "Write returned with %#x, expected %#x\n", hr
, S_OK
);
180 ok(uBytesWritten
== 3, "Wrote %u bytes, expected %u\n", uBytesWritten
, 3);
181 ok(memcmp(MemBuf
, Memory
, 3) == 0, "Wrote returned invalid data!\n"); /* make sure we're writing directly */
183 /* check whether the seek pointer has moved correctly */
184 IWICStream_Seek(pStream
, LargeNull
, STREAM_SEEK_CUR
, &uNewPos
);
185 ok(uNewPos
.u
.HighPart
== 0 && uNewPos
.u
.LowPart
== uBytesWritten
, "Seek cursor moved to position (%u;%u), expected (%u;%u)\n", uNewPos
.u
.HighPart
, uNewPos
.u
.LowPart
, 0, uBytesWritten
);
187 IWICStream_Seek(pStream
, LargeNull
, STREAM_SEEK_SET
, NULL
);
189 hr
= IWICStream_Write(pStream
, MemBuf
, 0, &uBytesWritten
);
190 ok(hr
== S_OK
, "Read returned with %#x, expected %#x\n", hr
, S_OK
);
192 hr
= IWICStream_Write(pStream
, NULL
, 3, &uBytesWritten
);
193 ok(hr
== E_INVALIDARG
, "Write returned with %#x, expected %#x\n", hr
, E_INVALIDARG
);
194 ok(uBytesWritten
== 0, "Wrote %u bytes, expected %u\n", uBytesWritten
, 0);
195 IWICStream_Seek(pStream
, LargeNull
, STREAM_SEEK_CUR
, &uNewPos
);
196 ok(uNewPos
.u
.HighPart
== 0 && uNewPos
.u
.LowPart
== 0, "Seek cursor moved to position (%u;%u), expected (%u;%u)\n", uNewPos
.u
.HighPart
, uNewPos
.u
.LowPart
, 0, 0);
198 hr
= IWICStream_Write(pStream
, NULL
, 0, &uBytesWritten
);
199 ok(hr
== E_INVALIDARG
, "Write returned with %#x, expected %#x\n", hr
, E_INVALIDARG
);
200 ok(uBytesWritten
== 0, "Wrote %u bytes, expected %u\n", uBytesWritten
, 0);
201 IWICStream_Seek(pStream
, LargeNull
, STREAM_SEEK_CUR
, &uNewPos
);
202 ok(uNewPos
.u
.HighPart
== 0 && uNewPos
.u
.LowPart
== 0, "Seek cursor moved to position (%u;%u), expected (%u;%u)\n", uNewPos
.u
.HighPart
, uNewPos
.u
.LowPart
, 0, 0);
204 hr
= IWICStream_Write(pStream
, CmpMem
, sizeof(Memory
) + 10, &uBytesWritten
);
205 ok(hr
== STG_E_MEDIUMFULL
, "Write returned with %#x, expected %#x\n", hr
, STG_E_MEDIUMFULL
);
206 ok(uBytesWritten
== 0, "Wrote %u bytes, expected %u\n", uBytesWritten
, 0);
207 IWICStream_Seek(pStream
, LargeNull
, STREAM_SEEK_CUR
, &uNewPos
);
208 ok(uNewPos
.u
.HighPart
== 0 && uNewPos
.u
.LowPart
== uBytesWritten
, "Seek cursor moved to position (%u;%u), expected (%u;%u)\n", uNewPos
.u
.HighPart
, uNewPos
.u
.LowPart
, 0, uBytesWritten
);
209 IWICStream_Seek(pStream
, LargeNull
, STREAM_SEEK_SET
, NULL
);
213 uNewPos
.u
.HighPart
= 0;
214 uNewPos
.u
.LowPart
= sizeof(Memory
) + 10;
215 hr
= IWICStream_SetSize(pStream
, uNewPos
);
216 ok(hr
== E_NOTIMPL
, "SetSize returned %#x, expected %#x\n", hr
, E_NOTIMPL
);
218 uNewPos
.u
.HighPart
= 0;
219 uNewPos
.u
.LowPart
= sizeof(Memory
);
220 hr
= IWICStream_SetSize(pStream
, uNewPos
);
221 ok(hr
== E_NOTIMPL
, "SetSize returned %#x, expected %#x\n", hr
, E_NOTIMPL
);
223 uNewPos
.u
.HighPart
= 0;
224 uNewPos
.u
.LowPart
= sizeof(Memory
) - 10;
225 hr
= IWICStream_SetSize(pStream
, uNewPos
);
226 ok(hr
== E_NOTIMPL
, "SetSize returned %#x, expected %#x\n", hr
, E_NOTIMPL
);
228 uNewPos
.u
.HighPart
= 0;
229 uNewPos
.u
.LowPart
= 0;
230 hr
= IWICStream_SetSize(pStream
, uNewPos
);
231 ok(hr
== E_NOTIMPL
, "SetSize returned %#x, expected %#x\n", hr
, E_NOTIMPL
);
233 uNewPos
.QuadPart
= -10;
234 hr
= IWICStream_SetSize(pStream
, uNewPos
);
235 ok(hr
== E_NOTIMPL
, "SetSize returned %#x, expected %#x\n", hr
, E_NOTIMPL
);
239 uNewPos
.u
.HighPart
= 0;
240 uNewPos
.u
.LowPart
= 5;
241 hr
= IWICStream_CopyTo(pStream
, NULL
, uNewPos
, NULL
, NULL
);
242 ok(hr
== E_NOTIMPL
, "CopyTo returned %#x, expected %#x\n", hr
, E_NOTIMPL
);
244 hr
= IWICImagingFactory_CreateStream(pFactory
, &pBufStream
);
245 ok(hr
== S_OK
, "CreateStream failed with %#x\n", hr
);
247 hr
= IWICStream_InitializeFromMemory(pBufStream
, Memory
, sizeof(Memory
));
248 ok(hr
== S_OK
, "InitializeFromMemory returned with %#x, expected %#x\n", hr
, S_OK
);
250 hr
= IWICStream_CopyTo(pStream
, (IStream
*)pBufStream
, uNewPos
, NULL
, NULL
);
251 ok(hr
== E_NOTIMPL
, "CopyTo returned %#x, expected %#x\n", hr
, E_NOTIMPL
);
252 IWICStream_Release(pBufStream
);
256 hr
= IWICStream_Commit(pStream
, STGC_DEFAULT
);
257 ok(hr
== E_NOTIMPL
, "Commit returned %#x, expected %#x\n", hr
, E_NOTIMPL
);
259 hr
= IWICStream_Commit(pStream
, STGC_OVERWRITE
);
260 ok(hr
== E_NOTIMPL
, "Commit returned %#x, expected %#x\n", hr
, E_NOTIMPL
);
262 hr
= IWICStream_Commit(pStream
, STGC_ONLYIFCURRENT
);
263 ok(hr
== E_NOTIMPL
, "Commit returned %#x, expected %#x\n", hr
, E_NOTIMPL
);
265 hr
= IWICStream_Commit(pStream
, STGC_DANGEROUSLYCOMMITMERELYTODISKCACHE
);
266 ok(hr
== E_NOTIMPL
, "Commit returned %#x, expected %#x\n", hr
, E_NOTIMPL
);
268 hr
= IWICStream_Commit(pStream
, STGC_CONSOLIDATE
);
269 ok(hr
== E_NOTIMPL
, "Commit returned %#x, expected %#x\n", hr
, E_NOTIMPL
);
273 IWICStream_Write(pStream
, &MemBuf
[5], 6, NULL
);
274 hr
= IWICStream_Revert(pStream
);
275 ok(hr
== E_NOTIMPL
, "Revert returned %#x, expected %#x\n", hr
, E_NOTIMPL
);
276 memcpy(Memory
, CmpMem
, sizeof(Memory
));
279 /* LockRegion/UnlockRegion */
280 hr
= IWICStream_LockRegion(pStream
, uLargeNull
, uLargeNull
, 0);
281 ok(hr
== E_NOTIMPL
, "LockRegion returned %#x, expected %#x\n", hr
, E_NOTIMPL
);
283 hr
= IWICStream_UnlockRegion(pStream
, uLargeNull
, uLargeNull
, 0);
284 ok(hr
== E_NOTIMPL
, "UnlockRegion returned %#x, expected %#x\n", hr
, E_NOTIMPL
);
288 hr
= IWICStream_Stat(pStream
, NULL
, 0);
289 ok(hr
== E_INVALIDARG
, "Stat returned %#x, expected %#x\n", hr
, E_INVALIDARG
);
291 hr
= IWICStream_Stat(pStream
, &Stats
, 0);
292 ok(hr
== S_OK
, "Stat returned %#x, expected %#x\n", hr
, S_OK
);
293 ok(Stats
.pwcsName
== NULL
, "Stat returned name %p, expected %p\n", Stats
.pwcsName
, NULL
);
294 ok(Stats
.type
== STGTY_STREAM
, "Stat returned type %d, expected %d\n", Stats
.type
, STGTY_STREAM
);
295 ok(Stats
.cbSize
.u
.HighPart
== 0 && Stats
.cbSize
.u
.LowPart
== sizeof(Memory
), "Stat returned size (%u;%u), expected (%u;%u)\n", Stats
.cbSize
.u
.HighPart
, Stats
.cbSize
.u
.LowPart
, 0, sizeof(Memory
));
296 ok(Stats
.mtime
.dwHighDateTime
== 0 && Stats
.mtime
.dwLowDateTime
== 0, "Stat returned mtime (%u;%u), expected (%u;%u)\n", Stats
.mtime
.dwHighDateTime
, Stats
.mtime
.dwLowDateTime
, 0, 0);
297 ok(Stats
.ctime
.dwHighDateTime
== 0 && Stats
.ctime
.dwLowDateTime
== 0, "Stat returned ctime (%u;%u), expected (%u;%u)\n", Stats
.ctime
.dwHighDateTime
, Stats
.ctime
.dwLowDateTime
, 0, 0);
298 ok(Stats
.atime
.dwHighDateTime
== 0 && Stats
.atime
.dwLowDateTime
== 0, "Stat returned atime (%u;%u), expected (%u;%u)\n", Stats
.atime
.dwHighDateTime
, Stats
.atime
.dwLowDateTime
, 0, 0);
299 ok(Stats
.grfMode
== 0, "Stat returned access mode %d, expected %d\n", Stats
.grfMode
, 0);
300 ok(Stats
.grfLocksSupported
== 0, "Stat returned supported locks %#x, expected %#x\n", Stats
.grfLocksSupported
, 0);
301 ok(Stats
.grfStateBits
== 0, "Stat returned state bits %#x, expected %#x\n", Stats
.grfStateBits
, 0);
305 hr
= IWICStream_Clone(pStream
, (IStream
**)&pBufStream
);
306 ok(hr
== E_NOTIMPL
, "UnlockRegion returned %#x, expected %#x\n", hr
, E_NOTIMPL
);
309 IWICStream_Release(pStream
);
310 IWICStream_Release(pFactory
);
316 test_StreamOnMemory();