From 7a81507fa7bafae67bf5a0caedead4a039c62110 Mon Sep 17 00:00:00 2001 From: Tony Wasserka Date: Sun, 23 Aug 2009 11:44:32 +0200 Subject: [PATCH] windowscodecs: Add tests for IWICStream_Write with memory streams. --- dlls/windowscodecs/tests/stream.c | 41 ++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/dlls/windowscodecs/tests/stream.c b/dlls/windowscodecs/tests/stream.c index 6528b20903c..89a238bf48e 100644 --- a/dlls/windowscodecs/tests/stream.c +++ b/dlls/windowscodecs/tests/stream.c @@ -34,7 +34,7 @@ static void test_StreamOnMemory(void) BYTE Memory[64], MemBuf[64]; LARGE_INTEGER LargeNull, LargeInt; ULARGE_INTEGER uNewPos; - ULONG uBytesRead; + ULONG uBytesRead, uBytesWritten; HRESULT hr; LargeNull.QuadPart = 0; @@ -168,6 +168,45 @@ static void test_StreamOnMemory(void) IWICStream_Seek(pStream, LargeNull, STREAM_SEEK_SET, NULL); + /* Write */ + MemBuf[0] = CmpMem[0] + 1; + MemBuf[1] = CmpMem[1] + 1; + MemBuf[2] = CmpMem[2] + 1; + hr = IWICStream_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 */ + IWICStream_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); + } + IWICStream_Seek(pStream, LargeNull, STREAM_SEEK_SET, NULL); + + hr = IWICStream_Write(pStream, MemBuf, 0, &uBytesWritten); + ok(hr == S_OK, "Read returned with %#x, expected %#x\n", hr, S_OK); + + hr = IWICStream_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); + IWICStream_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 = IWICStream_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); + IWICStream_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 = IWICStream_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); + IWICStream_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); + IWICStream_Seek(pStream, LargeNull, STREAM_SEEK_SET, NULL); + + IWICStream_Release(pStream); IWICStream_Release(pFactory); CoUninitialize();