[PATCH 7/7] windowscodecs: Add tests for memory streams in IWICStream

Tony Wasserka tony.wasserka at freenet.de
Tue Aug 18 04:20:55 CDT 2009


---
 dlls/windowscodecs/tests/Makefile.in |    3 +-
 dlls/windowscodecs/tests/stream.c    |  316 ++++++++++++++++++++++++++++++++++
 2 files changed, 318 insertions(+), 1 deletions(-)
 create mode 100644 dlls/windowscodecs/tests/stream.c

diff --git a/dlls/windowscodecs/tests/Makefile.in b/dlls/windowscodecs/tests/Makefile.in
index 2bb8c01..ef707ab 100644
--- a/dlls/windowscodecs/tests/Makefile.in
+++ b/dlls/windowscodecs/tests/Makefile.in
@@ -7,7 +7,8 @@ IMPORTS   = kernel32 ole32
 
 CTESTS = \
        bmpformat.c \
-       palette.c
+       palette.c \
+       stream.c
 
 @MAKE_TEST_RULES@
 
diff --git a/dlls/windowscodecs/tests/stream.c b/dlls/windowscodecs/tests/stream.c
new file mode 100644
index 0000000..84fbf2e
--- /dev/null
+++ b/dlls/windowscodecs/tests/stream.c
@@ -0,0 +1,316 @@
+/*
+ * Copyright 2009 Tony Wasserka
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#include "wine/test.h"
+#include "wincodec.h"
+
+static void test_StreamOnMemory()
+{
+    IWICImagingFactory *pFactory;
+    IWICStream *pStream, *pBufStream;
+    HRESULT hr;
+    const BYTE CmpMem[] = {
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
+        0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
+        0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
+        0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
+    };
+    BYTE Memory[64];
+    BYTE MemBuf[64];
+    ULONG uBytesRead, uBytesWritten;
+    LARGE_INTEGER LargeInt;
+    ULARGE_INTEGER uNewPos;
+    ULARGE_INTEGER uLargeNull;
+    LARGE_INTEGER LargeNull;
+    STATSTG Stats;
+
+    uLargeNull.QuadPart = 0;
+    LargeNull.QuadPart = 0;
+
+    memcpy(Memory, CmpMem, sizeof(CmpMem));
+
+    CoInitialize(NULL);
+
+    hr = CoCreateInstance(&CLSID_WICImagingFactory, NULL, CLSCTX_INPROC_SERVER, &IID_IWICImagingFactory, (void**)&pFactory);
+    if(FAILED(hr)) {
+        skip("CoCreateInstance returned with %#x, expected %#x\n", hr, S_OK);
+        return;
+    }
+
+    hr = pFactory->lpVtbl->CreateStream(pFactory, &pStream);
+    ok(hr == S_OK, "CreateStream returned with %#x, expected %#x\n", hr, S_OK);
+    if(FAILED(hr)) {
+        skip("Failed to create stream\n");
+        return;
+    }
+
+    /* InitializeFromMemory */
+    hr = pStream->lpVtbl->InitializeFromMemory(pStream, NULL, sizeof(Memory));   /* memory = NULL */
+    ok(hr == E_INVALIDARG, "InitializeFromMemory returned with %#x, expected %#x\n", hr, E_INVALIDARG);
+
+    hr = pStream->lpVtbl->InitializeFromMemory(pStream, Memory, 0);   /* size = 0 */
+    ok(hr == S_OK, "InitializeFromMemory returned with %#x, expected %#x\n", hr, S_OK);
+
+    hr = pStream->lpVtbl->InitializeFromMemory(pStream, Memory, sizeof(Memory));   /* stream already initialized */
+    ok(hr == WINCODEC_ERR_WRONGSTATE, "InitializeFromMemory returned with %#x, expected %#x\n", hr, WINCODEC_ERR_WRONGSTATE);
+
+    /* recreate stream */
+    pStream->lpVtbl->Release(pStream);
+    hr = pFactory->lpVtbl->CreateStream(pFactory, &pStream);
+    ok(hr == S_OK, "CreateStream failed with %#x\n", hr);
+
+    hr = pStream->lpVtbl->InitializeFromMemory(pStream, Memory, sizeof(Memory));
+    ok(hr == S_OK, "InitializeFromMemory returned with %#x, expected %#x\n", hr, S_OK);
+
+    /* Seek */
+    hr = pStream->lpVtbl->Seek(pStream, LargeNull, STREAM_SEEK_SET, &uNewPos);
+    ok(hr == S_OK, "Seek returned with %#x, expected %#x\n", hr, S_OK);
+    ok(uNewPos.HighPart == 0 && uNewPos.LowPart == 0, "Seek cursor moved to position (%u;%u), expected (%u;%u)\n", uNewPos.HighPart, uNewPos.LowPart, 0, 0);
+
+    hr = pStream->lpVtbl->Seek(pStream, LargeNull, STREAM_SEEK_SET, NULL);
+    ok(hr == S_OK, "Seek returned with %#x, expected %#x\n", hr, S_OK);
+
+    LargeInt.HighPart = 1;
+    LargeInt.LowPart = 0;
+    hr = pStream->lpVtbl->Seek(pStream, LargeInt, STREAM_SEEK_SET, &uNewPos);
+    ok(hr == HRESULT_FROM_WIN32(ERROR_ARITHMETIC_OVERFLOW), "Seek returned with %#x, expected %#x\n", hr, HRESULT_FROM_WIN32(ERROR_ARITHMETIC_OVERFLOW));
+    ok(uNewPos.HighPart == 0 && uNewPos.LowPart == 0, "Seek cursor moved to position (%u;%u), expected (%u;%u)\n", uNewPos.HighPart, uNewPos.LowPart, 0, 0);
+
+    LargeInt.QuadPart = sizeof(Memory) + 10;
+    hr = pStream->lpVtbl->Seek(pStream, LargeInt, STREAM_SEEK_SET, &uNewPos);
+    ok(hr == E_INVALIDARG, "Seek returned with %#x, expected %#x\n", hr, E_INVALIDARG);
+    ok(uNewPos.HighPart == 0 && uNewPos.LowPart == 0, "Seek cursor moved to position (%u;%u), expected (%u;%u)\n", uNewPos.HighPart, uNewPos.LowPart, 0, 0);
+
+    LargeInt.QuadPart = 1;
+    hr = pStream->lpVtbl->Seek(pStream, LargeInt, STREAM_SEEK_END, &uNewPos);
+    ok(hr == E_INVALIDARG, "Seek returned with %#x, expected %#x\n", hr, E_INVALIDARG);
+    ok(uNewPos.HighPart == 0 && uNewPos.LowPart == 0, "Seek cursor moved to position (%u;%u), expected (%u;%u)\n", uNewPos.HighPart, uNewPos.LowPart, 0, 0);
+
+    LargeInt.QuadPart = -1;
+    hr = pStream->lpVtbl->Seek(pStream, LargeInt, STREAM_SEEK_END, &uNewPos);
+    ok(hr == S_OK, "Seek returned with %#x, expected %#x\n", hr, S_OK);
+    ok(uNewPos.HighPart == 0 && uNewPos.LowPart == sizeof(Memory) - 1, "bSeek cursor moved to position (%u;%u), expected (%u;%u)\n", uNewPos.HighPart, uNewPos.LowPart, 0, sizeof(Memory) - 1);
+
+    pStream->lpVtbl->Seek(pStream, LargeNull, STREAM_SEEK_SET, &uNewPos); /* reset seek pointer */
+    LargeInt.QuadPart = -sizeof(Memory) - 5;
+    hr = pStream->lpVtbl->Seek(pStream, LargeInt, STREAM_SEEK_END, &uNewPos);
+    ok(hr == E_INVALIDARG, "Seek returned with %#x, expected %#x\n", hr, E_INVALIDARG);
+    ok(uNewPos.HighPart == 0 && uNewPos.LowPart == 0, "bSeek cursor moved to position (%u;%u), expected (%u;%u)\n", uNewPos.HighPart, uNewPos.LowPart, 0, 0); /* remains unchanged */
+
+    pStream->lpVtbl->Seek(pStream, LargeNull, STREAM_SEEK_SET, NULL);
+
+    /* Read */
+    hr = pStream->lpVtbl->Read(pStream, MemBuf, 12, &uBytesRead);
+    ok(hr == S_OK, "Read returned with %#x, expected %#x\n", hr, S_OK);
+    if(SUCCEEDED(hr)) {
+        ok(uBytesRead == 12, "Read %u bytes, expected %u\n", uBytesRead, 3);
+        ok(memcmp(MemBuf, CmpMem, 12) == 0, "Read returned invalid data!\n");
+
+        /* check whether the seek pointer has moved correctly */
+        pStream->lpVtbl->Seek(pStream, LargeNull, STREAM_SEEK_CUR, &uNewPos);
+        ok(uNewPos.HighPart == 0 && uNewPos.LowPart == uBytesRead, "Seek cursor moved to position (%u;%u), expected (%u;%u)\n", uNewPos.HighPart, uNewPos.LowPart, 0, uBytesRead);
+    }
+
+    pStream->lpVtbl->Seek(pStream, LargeNull, STREAM_SEEK_SET, NULL);
+
+    hr = pStream->lpVtbl->Read(pStream, Memory, 10, &uBytesRead);   /* source = dest */
+    ok(hr == S_OK, "Read returned with %#x, expected %#x\n", hr, S_OK);
+    if(SUCCEEDED(hr)) {
+        ok(uBytesRead == 10, "Read %u bytes, expected %u\n", uBytesRead, 10);
+        ok(memcmp(Memory, CmpMem, uBytesRead) == 0, "Read returned invalid data!\n");
+    }
+
+    pStream->lpVtbl->Seek(pStream, LargeNull, STREAM_SEEK_SET, NULL);
+
+    hr = pStream->lpVtbl->Read(pStream, Memory, sizeof(Memory) + 10, &uBytesRead);   /* request too many bytes */
+    ok(hr == S_OK, "Read returned with %#x, expected %#x\n", hr, S_OK);
+    if(SUCCEEDED(hr)) {
+        ok(uBytesRead == sizeof(Memory), "Read %u bytes, expected %u\n", uBytesRead, sizeof(Memory));
+        ok(memcmp(Memory, CmpMem, uBytesRead) == 0, "Read returned invalid data!\n");
+    }
+
+    hr = pStream->lpVtbl->Read(pStream, NULL, 1, &uBytesRead);    /* destination buffer = NULL */
+    ok(hr == E_INVALIDARG, "Read returned with %#x, expected %#x\n", hr, E_INVALIDARG);
+
+    hr = pStream->lpVtbl->Read(pStream, MemBuf, 0, &uBytesRead);    /* read 0 bytes */
+    ok(hr == S_OK, "Read returned with %#x, expected %#x\n", hr, S_OK);
+
+    hr = pStream->lpVtbl->Read(pStream, NULL, 0, &uBytesRead);
+    ok(hr == E_INVALIDARG, "Read returned with %#x, expected %#x\n", hr, E_INVALIDARG);
+
+    hr = pStream->lpVtbl->Read(pStream, NULL, 0, NULL);
+    ok(hr == E_INVALIDARG, "Read returned with %#x, expected %#x\n", hr, E_INVALIDARG);
+
+    hr = pStream->lpVtbl->Read(pStream, MemBuf, 1, NULL);
+    ok(hr == S_OK, "Read returned with %#x, expected %#x\n", hr, S_OK);
+
+    pStream->lpVtbl->Seek(pStream, LargeNull, STREAM_SEEK_SET, NULL);
+    ZeroMemory(MemBuf, sizeof(MemBuf));
+    hr = pStream->lpVtbl->Read(pStream, MemBuf, sizeof(Memory) + 10, &uBytesRead);
+    ok(hr == S_OK, "Read returned with %#x, expected %#x\n", hr, S_OK);
+    if(SUCCEEDED(hr)) {
+        ok(uBytesRead == sizeof(Memory), "Read %u bytes, expected %u\n", uBytesRead, sizeof(Memory));
+        ok(memcmp(Memory, CmpMem, 64) == 0, "Read returned invalid data!\n");
+    }
+    pStream->lpVtbl->Seek(pStream, LargeNull, STREAM_SEEK_SET, NULL);
+
+    /* Write */
+    MemBuf[0] = CmpMem[0] + 1;
+    MemBuf[1] = CmpMem[1] + 1;
+    MemBuf[2] = CmpMem[2] + 1;
+    hr = pStream->lpVtbl->Write(pStream, MemBuf, 3, &uBytesWritten);
+    ok(hr == S_OK, "Write returned with %#x, expected %#x\n", hr, S_OK);
+    if(SUCCEEDED(hr)) {
+        ok(uBytesWritten == 3, "Wrote %u bytes, expected %u\n", uBytesWritten, 3);
+        ok(memcmp(MemBuf, Memory, 3) == 0, "Wrote returned invalid data!\n"); /* make sure we're writing directly */
+
+        /* check whether the seek pointer has moved correctly */
+        pStream->lpVtbl->Seek(pStream, LargeNull, STREAM_SEEK_CUR, &uNewPos);
+        ok(uNewPos.HighPart == 0 && uNewPos.LowPart == uBytesWritten, "Seek cursor moved to position (%u;%u), expected (%u;%u)\n", uNewPos.HighPart, uNewPos.LowPart, 0, uBytesWritten);
+    }
+    pStream->lpVtbl->Seek(pStream, LargeNull, STREAM_SEEK_SET, NULL);
+
+    hr = pStream->lpVtbl->Write(pStream, MemBuf, 0, &uBytesWritten);
+    ok(hr == S_OK, "Read returned with %#x, expected %#x\n", hr, S_OK);
+
+    hr = pStream->lpVtbl->Write(pStream, NULL, 3, &uBytesWritten);
+    ok(hr == E_INVALIDARG, "Write returned with %#x, expected %#x\n", hr, E_INVALIDARG);
+    ok(uBytesWritten == 0, "Wrote %u bytes, expected %u\n", uBytesWritten, 0);
+    pStream->lpVtbl->Seek(pStream, LargeNull, STREAM_SEEK_CUR, &uNewPos);
+    ok(uNewPos.HighPart == 0 && uNewPos.LowPart == 0, "Seek cursor moved to position (%u;%u), expected (%u;%u)\n", uNewPos.HighPart, uNewPos.LowPart, 0, 0);
+
+    hr = pStream->lpVtbl->Write(pStream, NULL, 0, &uBytesWritten);
+    ok(hr == E_INVALIDARG, "Write returned with %#x, expected %#x\n", hr, E_INVALIDARG);
+    ok(uBytesWritten == 0, "Wrote %u bytes, expected %u\n", uBytesWritten, 0);
+    pStream->lpVtbl->Seek(pStream, LargeNull, STREAM_SEEK_CUR, &uNewPos);
+    ok(uNewPos.HighPart == 0 && uNewPos.LowPart == 0, "Seek cursor moved to position (%u;%u), expected (%u;%u)\n", uNewPos.HighPart, uNewPos.LowPart, 0, 0);
+
+    hr = pStream->lpVtbl->Write(pStream, CmpMem, sizeof(Memory) + 10, &uBytesWritten);
+    ok(hr == STG_E_MEDIUMFULL, "Write returned with %#x, expected %#x\n", hr, STG_E_MEDIUMFULL);
+    ok(uBytesWritten == 0, "Wrote %u bytes, expected %u\n", uBytesWritten, 0);
+    pStream->lpVtbl->Seek(pStream, LargeNull, STREAM_SEEK_CUR, &uNewPos);
+    ok(uNewPos.HighPart == 0 && uNewPos.LowPart == uBytesWritten, "Seek cursor moved to position (%u;%u), expected (%u;%u)\n", uNewPos.HighPart, uNewPos.LowPart, 0, uBytesWritten);
+    pStream->lpVtbl->Seek(pStream, LargeNull, STREAM_SEEK_SET, NULL);
+
+
+    /* SetSize */
+    uNewPos.HighPart = 0;
+    uNewPos.LowPart = sizeof(Memory) + 10;
+    hr = pStream->lpVtbl->SetSize(pStream, uNewPos);
+    ok(hr == E_NOTIMPL, "SetSize returned %#x, expected %#x\n", hr, E_NOTIMPL);
+
+    uNewPos.HighPart = 0;
+    uNewPos.LowPart = sizeof(Memory);
+    hr = pStream->lpVtbl->SetSize(pStream, uNewPos);
+    ok(hr == E_NOTIMPL, "SetSize returned %#x, expected %#x\n", hr, E_NOTIMPL);
+
+    uNewPos.HighPart = 0;
+    uNewPos.LowPart = sizeof(Memory) - 10;
+    hr = pStream->lpVtbl->SetSize(pStream, uNewPos);
+    ok(hr == E_NOTIMPL, "SetSize returned %#x, expected %#x\n", hr, E_NOTIMPL);
+
+    uNewPos.HighPart = 0;
+    uNewPos.LowPart = 0;
+    hr = pStream->lpVtbl->SetSize(pStream, uNewPos);
+    ok(hr == E_NOTIMPL, "SetSize returned %#x, expected %#x\n", hr, E_NOTIMPL);
+
+    uNewPos.QuadPart = -10;
+    hr = pStream->lpVtbl->SetSize(pStream, uNewPos);
+    ok(hr == E_NOTIMPL, "SetSize returned %#x, expected %#x\n", hr, E_NOTIMPL);
+
+
+    /* CopyTo */
+    uNewPos.HighPart = 0;
+    uNewPos.LowPart = 5;
+    hr = pStream->lpVtbl->CopyTo(pStream, NULL, uNewPos, NULL, NULL);
+    ok(hr == E_NOTIMPL, "CopyTo returned %#x, expected %#x\n", hr, E_NOTIMPL);
+
+    hr = pFactory->lpVtbl->CreateStream(pFactory, &pBufStream);
+    ok(hr == S_OK, "CreateStream failed with %#x\n", hr);
+
+    hr = pBufStream->lpVtbl->InitializeFromMemory(pBufStream, Memory, sizeof(Memory));
+    ok(hr == S_OK, "InitializeFromMemory returned with %#x, expected %#x\n", hr, S_OK);
+
+    hr = pStream->lpVtbl->CopyTo(pStream, (IStream*)pBufStream, uNewPos, NULL, NULL);
+    ok(hr == E_NOTIMPL, "CopyTo returned %#x, expected %#x\n", hr, E_NOTIMPL);
+    pBufStream->lpVtbl->Release(pBufStream);
+
+
+    /* Commit */
+    hr = pStream->lpVtbl->Commit(pStream, STGC_DEFAULT);
+    ok(hr == E_NOTIMPL, "Commit returned %#x, expected %#x\n", hr, E_NOTIMPL);
+
+    hr = pStream->lpVtbl->Commit(pStream, STGC_OVERWRITE);
+    ok(hr == E_NOTIMPL, "Commit returned %#x, expected %#x\n", hr, E_NOTIMPL);
+
+    hr = pStream->lpVtbl->Commit(pStream, STGC_ONLYIFCURRENT);
+    ok(hr == E_NOTIMPL, "Commit returned %#x, expected %#x\n", hr, E_NOTIMPL);
+
+    hr = pStream->lpVtbl->Commit(pStream, STGC_DANGEROUSLYCOMMITMERELYTODISKCACHE);
+    ok(hr == E_NOTIMPL, "Commit returned %#x, expected %#x\n", hr, E_NOTIMPL);
+
+    hr = pStream->lpVtbl->Commit(pStream, STGC_CONSOLIDATE);
+    ok(hr == E_NOTIMPL, "Commit returned %#x, expected %#x\n", hr, E_NOTIMPL);
+
+
+    /* Revert */
+    pStream->lpVtbl->Write(pStream, &MemBuf[5], 6, NULL);
+    hr = pStream->lpVtbl->Revert(pStream);
+    ok(hr == E_NOTIMPL, "Revert returned %#x, expected %#x\n", hr, E_NOTIMPL);
+    memcpy(Memory, CmpMem, sizeof(Memory));
+
+
+    /* LockRegion/UnlockRegion */
+    hr = pStream->lpVtbl->LockRegion(pStream, uLargeNull, uLargeNull, 0);
+    ok(hr == E_NOTIMPL, "LockRegion returned %#x, expected %#x\n", hr, E_NOTIMPL);
+
+    hr = pStream->lpVtbl->UnlockRegion(pStream, uLargeNull, uLargeNull, 0);
+    ok(hr == E_NOTIMPL, "UnlockRegion returned %#x, expected %#x\n", hr, E_NOTIMPL);
+
+
+    /* Stat */
+    hr = pStream->lpVtbl->Stat(pStream, NULL, 0);
+    ok(hr == E_INVALIDARG, "Stat returned %#x, expected %#x\n", hr, E_INVALIDARG);
+
+    hr = pStream->lpVtbl->Stat(pStream, &Stats, 0);
+    ok(hr == S_OK, "Stat returned %#x, expected %#x\n", hr, S_OK);
+    ok(Stats.pwcsName == NULL, "Stat returned name %p, expected %p\n", Stats.pwcsName, NULL);
+    ok(Stats.type == STGTY_STREAM, "Stat returned type %d, expected %d\n", Stats.type, STGTY_STREAM);
+    ok(Stats.cbSize.HighPart == 0 && Stats.cbSize.LowPart == sizeof(Memory), "Stat returned size (%u;%u), expected (%u;%u)\n", Stats.cbSize.HighPart, Stats.cbSize.LowPart, 0, sizeof(Memory));
+    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);
+    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);
+    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);
+    ok(Stats.grfMode == 0, "Stat returned access mode %d, expected %d\n", Stats.grfMode, 0);
+    ok(Stats.grfLocksSupported == 0, "Stat returned supported locks %#x, expected %#x\n", Stats.grfLocksSupported, 0);
+    ok(Stats.grfStateBits == 0, "Stat returned state bits %#x, expected %#x\n", Stats.grfStateBits, 0);
+
+
+    /* Clone */
+    hr = pStream->lpVtbl->Clone(pStream, (IStream**)&pBufStream);
+    ok(hr == E_NOTIMPL, "UnlockRegion returned %#x, expected %#x\n", hr, E_NOTIMPL);
+
+
+    pStream->lpVtbl->Release(pStream);
+    pFactory->lpVtbl->Release(pFactory);
+    CoUninitialize();
+}
+
+START_TEST(stream)
+{
+    test_StreamOnMemory();
+}
-- 
1.6.3.3


--------------010609050603000302050706--



More information about the wine-patches mailing list