From b2fa99851c9d739d7f94eff1b5c54fe3b779087a Mon Sep 17 00:00:00 2001 From: Vincent Povirk Date: Tue, 15 Nov 2011 15:09:31 -0600 Subject: [PATCH] windowscodecs: Add tests for IWICMetadataReader. --- dlls/windowscodecs/tests/Makefile.in | 1 + dlls/windowscodecs/tests/bmpformat.c | 1 + dlls/windowscodecs/tests/metadata.c | 192 +++++++++++++++++++++++++++ include/wincodecsdk.idl | 8 ++ 4 files changed, 202 insertions(+) create mode 100644 dlls/windowscodecs/tests/metadata.c diff --git a/dlls/windowscodecs/tests/Makefile.in b/dlls/windowscodecs/tests/Makefile.in index 51b54d4ac0e..048fc294a12 100644 --- a/dlls/windowscodecs/tests/Makefile.in +++ b/dlls/windowscodecs/tests/Makefile.in @@ -6,6 +6,7 @@ C_SRCS = \ converter.c \ icoformat.c \ info.c \ + metadata.c \ palette.c \ stream.c diff --git a/dlls/windowscodecs/tests/bmpformat.c b/dlls/windowscodecs/tests/bmpformat.c index 378c375692e..f26453316b3 100644 --- a/dlls/windowscodecs/tests/bmpformat.c +++ b/dlls/windowscodecs/tests/bmpformat.c @@ -25,6 +25,7 @@ #include "initguid.h" #include "objbase.h" #include "wincodec.h" +#include "wincodecsdk.h" #include "wine/test.h" static const char testbmp_24bpp[] = { diff --git a/dlls/windowscodecs/tests/metadata.c b/dlls/windowscodecs/tests/metadata.c new file mode 100644 index 00000000000..d9008a469df --- /dev/null +++ b/dlls/windowscodecs/tests/metadata.c @@ -0,0 +1,192 @@ +/* + * Copyright 2011 Vincent Povirk for CodeWeavers + * + * 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 +#include + +#define COBJMACROS + +#include "windef.h" +#include "objbase.h" +#include "wincodec.h" +#include "wincodecsdk.h" +#include "wine/test.h" + +#define expect_blob(propvar, data, length) do { \ + ok((propvar).vt == VT_BLOB, "unexpected vt: %i\n", (propvar).vt); \ + if ((propvar).vt == VT_BLOB) { \ + ok((propvar).blob.cbSize == (length), "expected size %i, got %i\n", (length), (propvar).blob.cbSize); \ + if ((propvar).blob.cbSize == (length)) { \ + ok(!memcmp((propvar).blob.pBlobData, (data), (length)), "unexpected data\n"); \ + } \ + } \ +} while (0) + +static const char metadata_unknown[] = "lalala"; + +static const char metadata_tEXt[] = { + 0,0,0,14, /* chunk length */ + 't','E','X','t', /* chunk type */ + 'w','i','n','e','t','e','s','t',0, /* keyword */ + 'v','a','l','u','e', /* text */ + 0x3f,0x64,0x19,0xf3 /* chunk CRC */ +}; + +static void load_stream(IUnknown *reader, const char *data, int data_size) +{ + HRESULT hr; + IWICPersistStream *persist; + IStream *stream; + HGLOBAL hdata; + void *locked_data; + + hdata = GlobalAlloc(GMEM_MOVEABLE, data_size); + ok(hdata != 0, "GlobalAlloc failed\n"); + if (!hdata) return; + + locked_data = GlobalLock(hdata); + memcpy(locked_data, data, data_size); + GlobalUnlock(hdata); + + hr = CreateStreamOnHGlobal(hdata, TRUE, &stream); + ok(hr == S_OK, "CreateStreamOnHGlobal failed, hr=%x\n", hr); + if (FAILED(hr)) return; + + hr = IUnknown_QueryInterface(reader, &IID_IWICPersistStream, (void**)&persist); + ok(hr == S_OK, "QueryInterface failed, hr=%x\n", hr); + + if (SUCCEEDED(hr)) + { + hr = IWICPersistStream_LoadEx(persist, stream, NULL, WICPersistOptionsDefault); + ok(hr == S_OK, "LoadEx failed, hr=%x\n", hr); + + IWICPersistStream_Release(persist); + } + + IStream_Release(stream); +} + +static void test_metadata_unknown(void) +{ + HRESULT hr; + IWICMetadataReader *reader; + IWICEnumMetadataItem *enumerator; + PROPVARIANT schema, id, value; + ULONG items_returned; + + hr = CoCreateInstance(&CLSID_WICUnknownMetadataReader, NULL, CLSCTX_INPROC_SERVER, + &IID_IWICMetadataReader, (void**)&reader); + todo_wine ok(hr == S_OK, "CoCreateInstance failed, hr=%x\n", hr); + if (FAILED(hr)) return; + + load_stream((IUnknown*)reader, metadata_unknown, sizeof(metadata_unknown)); + + hr = IWICMetadataReader_GetEnumerator(reader, &enumerator); + ok(hr == S_OK, "GetEnumerator failed, hr=%x\n", hr); + + if (SUCCEEDED(hr)) + { + PropVariantInit(&schema); + PropVariantInit(&id); + PropVariantInit(&value); + + hr = IWICEnumMetadataItem_Next(enumerator, 1, &schema, &id, &value, &items_returned); + ok(hr == S_OK, "Next failed, hr=%x\n", hr); + ok(items_returned == 1, "unexpected item count %i\n", items_returned); + + if (hr == S_OK && items_returned == 1) + { + ok(schema.vt == VT_EMPTY, "unexpected vt: %i\n", schema.vt); + ok(id.vt == VT_EMPTY, "unexpected vt: %i\n", id.vt); + expect_blob(value, metadata_unknown, sizeof(metadata_unknown)); + + PropVariantClear(&schema); + PropVariantClear(&id); + PropVariantClear(&value); + } + + hr = IWICEnumMetadataItem_Next(enumerator, 1, &schema, &id, &value, &items_returned); + ok(hr == S_FALSE, "Next failed, hr=%x\n", hr); + ok(items_returned == 0, "unexpected item count %i\n", items_returned); + + IWICEnumMetadataItem_Release(enumerator); + } + + IWICMetadataReader_Release(reader); +} + +static void test_metadata_tEXt(void) +{ + HRESULT hr; + IWICMetadataReader *reader; + IWICEnumMetadataItem *enumerator; + PROPVARIANT schema, id, value; + ULONG items_returned; + + hr = CoCreateInstance(&CLSID_WICPngTextMetadataReader, NULL, CLSCTX_INPROC_SERVER, + &IID_IWICMetadataReader, (void**)&reader); + todo_wine ok(hr == S_OK, "CoCreateInstance failed, hr=%x\n", hr); + if (FAILED(hr)) return; + + load_stream((IUnknown*)reader, metadata_tEXt, sizeof(metadata_tEXt)); + + hr = IWICMetadataReader_GetEnumerator(reader, &enumerator); + ok(hr == S_OK, "GetEnumerator failed, hr=%x\n", hr); + + if (SUCCEEDED(hr)) + { + PropVariantInit(&schema); + PropVariantInit(&id); + PropVariantInit(&value); + + hr = IWICEnumMetadataItem_Next(enumerator, 1, &schema, &id, &value, &items_returned); + ok(hr == S_OK, "Next failed, hr=%x\n", hr); + ok(items_returned == 1, "unexpected item count %i\n", items_returned); + + if (hr == S_OK && items_returned == 1) + { + ok(schema.vt == VT_EMPTY, "unexpected vt: %i\n", schema.vt); + ok(id.vt == VT_LPSTR, "unexpected vt: %i\n", id.vt); + ok(!strcmp(id.pszVal, "winetest"), "unexpected id: %s\n", id.pszVal); + ok(value.vt == VT_LPSTR, "unexpected vt: %i\n", id.vt); + ok(!strcmp(value.pszVal, "value"), "unexpected value: %s\n", id.pszVal); + + PropVariantClear(&schema); + PropVariantClear(&id); + PropVariantClear(&value); + } + + hr = IWICEnumMetadataItem_Next(enumerator, 1, &schema, &id, &value, &items_returned); + ok(hr == S_FALSE, "Next failed, hr=%x\n", hr); + ok(items_returned == 0, "unexpected item count %i\n", items_returned); + + IWICEnumMetadataItem_Release(enumerator); + } + + IWICMetadataReader_Release(reader); +} + +START_TEST(metadata) +{ + CoInitializeEx(NULL, COINIT_APARTMENTTHREADED); + + test_metadata_unknown(); + test_metadata_tEXt(); + + CoUninitialize(); +} diff --git a/include/wincodecsdk.idl b/include/wincodecsdk.idl index ed00cfbf2d9..e32971cf5f4 100644 --- a/include/wincodecsdk.idl +++ b/include/wincodecsdk.idl @@ -34,6 +34,14 @@ typedef enum WICMetadataCreationOptions { WICMetadataCreationMask = 0xFFFF0000 } WICMetadataCreationOptions; +cpp_quote("DEFINE_GUID(GUID_MetadataFormatUnknown, 0xa45e592f,0x9078,0x4a7c,0xad,0xb5,0x4e,0xdc,0x4f,0xd6,0x1b,0x1f);") +cpp_quote("DEFINE_GUID(GUID_MetadataFormatChunktEXt, 0x568d8936,0xc0a9,0x4923,0x90,0x5d,0xdf,0x2b,0x38,0x23,0x8f,0xbc);") + +cpp_quote("DEFINE_GUID(CLSID_WICUnknownMetadataReader, 0x699745c2,0x5066,0x4b82,0xa8,0xe3,0xd4,0x04,0x78,0xdb,0xec,0x8c);") +cpp_quote("DEFINE_GUID(CLSID_WICUnknownMetadataWriter, 0xa09cca86,0x27ba,0x4f39,0x90,0x53,0x12,0x1f,0xa4,0xdc,0x08,0xfc);") +cpp_quote("DEFINE_GUID(CLSID_WICPngTextMetadataReader, 0x4b59afcc,0xb8c3,0x408a,0xb6,0x70,0x89,0xe5,0xfa,0xb6,0xfd,0xa7);") +cpp_quote("DEFINE_GUID(CLSID_WICPngTextMetadataWriter, 0xb5ebafb9,0x253e,0x4a72,0xa7,0x44,0x07,0x62,0xd2,0x68,0x56,0x83);") + [ object, uuid(aba958bf-c672-44d1-8d61-ce6df2e682c2)