windowscodecs: Implement IWICComponentInfo::GetVendorGUID.
[wine] / dlls / windowscodecs / tests / palette.c
1 /*
2  * Copyright 2009 Vincent Povirk for CodeWeavers
3  *
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.
8  *
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.
13  *
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
17  */
18
19 #include <stdarg.h>
20
21 #define COBJMACROS
22
23 #include "windef.h"
24 #include "objbase.h"
25 #include "wincodec.h"
26 #include "wine/test.h"
27
28 static void test_custom_palette(void)
29 {
30     IWICImagingFactory *factory;
31     IWICPalette *palette;
32     HRESULT hr;
33     WICBitmapPaletteType type=0xffffffff;
34     UINT count=1;
35     const WICColor initcolors[4]={0xff000000,0xff0000ff,0xffffff00,0xffffffff};
36     WICColor colors[4];
37     BOOL boolresult;
38
39     hr = CoCreateInstance(&CLSID_WICImagingFactory, NULL, CLSCTX_INPROC_SERVER,
40         &IID_IWICImagingFactory, (void**)&factory);
41     ok(SUCCEEDED(hr), "CoCreateInstance failed, hr=%x\n", hr);
42     if (FAILED(hr)) return;
43
44     hr = IWICImagingFactory_CreatePalette(factory, &palette);
45     ok(SUCCEEDED(hr), "CreatePalette failed, hr=%x\n", hr);
46     if (SUCCEEDED(hr))
47     {
48         hr = IWICPalette_GetType(palette, &type);
49         ok(SUCCEEDED(hr), "GetType failed, hr=%x\n", hr);
50         ok(type == WICBitmapPaletteTypeCustom, "expected WICBitmapPaletteTypeCustom, got %x\n", type);
51
52         hr = IWICPalette_GetColorCount(palette, &count);
53         ok(SUCCEEDED(hr), "GetColorCount failed, hr=%x\n", hr);
54         ok(count == 0, "expected 0, got %u\n", count);
55
56         hr = IWICPalette_GetColors(palette, 0, colors, &count);
57         ok(SUCCEEDED(hr), "GetColors failed, hr=%x\n", hr);
58         ok(count == 0, "expected 0, got %u\n", count);
59
60         hr = IWICPalette_GetColors(palette, 4, colors, &count);
61         ok(SUCCEEDED(hr), "GetColors failed, hr=%x\n", hr);
62         ok(count == 0, "expected 0, got %u\n", count);
63
64         memcpy(colors, initcolors, sizeof(initcolors));
65         hr = IWICPalette_InitializeCustom(palette, colors, 4);
66         ok(SUCCEEDED(hr), "InitializeCustom failed, hr=%x\n", hr);
67
68         hr = IWICPalette_GetType(palette, &type);
69         ok(SUCCEEDED(hr), "GetType failed, hr=%x\n", hr);
70         ok(type == WICBitmapPaletteTypeCustom, "expected WICBitmapPaletteTypeCustom, got %x\n", type);
71
72         hr = IWICPalette_GetColorCount(palette, &count);
73         ok(SUCCEEDED(hr), "GetColorCount failed, hr=%x\n", hr);
74         ok(count == 4, "expected 4, got %u\n", count);
75
76         memset(colors, 0, sizeof(colors));
77         count = 0;
78         hr = IWICPalette_GetColors(palette, 4, colors, &count);
79         ok(SUCCEEDED(hr), "GetColors failed, hr=%x\n", hr);
80         ok(count == 4, "expected 4, got %u\n", count);
81         ok(!memcmp(colors, initcolors, sizeof(colors)), "got unexpected palette data\n");
82
83         memset(colors, 0, sizeof(colors));
84         count = 0;
85         hr = IWICPalette_GetColors(palette, 2, colors, &count);
86         ok(SUCCEEDED(hr), "GetColors failed, hr=%x\n", hr);
87         ok(count == 2, "expected 2, got %u\n", count);
88         ok(!memcmp(colors, initcolors, sizeof(WICColor)*2), "got unexpected palette data\n");
89
90         count = 0;
91         hr = IWICPalette_GetColors(palette, 6, colors, &count);
92         ok(SUCCEEDED(hr), "GetColors failed, hr=%x\n", hr);
93         ok(count == 4, "expected 4, got %u\n", count);
94
95         hr = IWICPalette_HasAlpha(palette, &boolresult);
96         ok(SUCCEEDED(hr), "HasAlpha failed, hr=%x\n", hr);
97         ok(!boolresult, "expected FALSE, got TRUE\n");
98
99         hr = IWICPalette_IsBlackWhite(palette, &boolresult);
100         ok(SUCCEEDED(hr), "IsBlackWhite failed, hr=%x\n", hr);
101         ok(!boolresult, "expected FALSE, got TRUE\n");
102
103         hr = IWICPalette_IsGrayscale(palette, &boolresult);
104         ok(SUCCEEDED(hr), "IsGrayscale failed, hr=%x\n", hr);
105         ok(!boolresult, "expected FALSE, got TRUE\n");
106
107         /* try a palette with some alpha in it */
108         colors[2] = 0x80ffffff;
109         hr = IWICPalette_InitializeCustom(palette, colors, 4);
110         ok(SUCCEEDED(hr), "InitializeCustom failed, hr=%x\n", hr);
111
112         hr = IWICPalette_HasAlpha(palette, &boolresult);
113         ok(SUCCEEDED(hr), "HasAlpha failed, hr=%x\n", hr);
114         ok(boolresult, "expected TRUE, got FALSE\n");
115
116         /* setting to a 0-color palette is acceptable */
117         hr = IWICPalette_InitializeCustom(palette, NULL, 0);
118         ok(SUCCEEDED(hr), "InitializeCustom failed, hr=%x\n", hr);
119
120         /* IWICPalette is paranoid about NULL pointers */
121         hr = IWICPalette_GetType(palette, NULL);
122         ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got %x\n", hr);
123
124         hr = IWICPalette_GetColorCount(palette, NULL);
125         ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got %x\n", hr);
126
127         hr = IWICPalette_InitializeCustom(palette, NULL, 4);
128         ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got %x\n", hr);
129
130         hr = IWICPalette_GetColors(palette, 4, NULL, &count);
131         ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got %x\n", hr);
132
133         hr = IWICPalette_GetColors(palette, 4, colors, NULL);
134         ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got %x\n", hr);
135
136         hr = IWICPalette_HasAlpha(palette, NULL);
137         ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got %x\n", hr);
138
139         hr = IWICPalette_IsBlackWhite(palette, NULL);
140         ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got %x\n", hr);
141
142         hr = IWICPalette_IsGrayscale(palette, NULL);
143         ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got %x\n", hr);
144
145         IWICPalette_Release(palette);
146     }
147
148     IWICImagingFactory_Release(factory);
149 }
150
151 START_TEST(palette)
152 {
153     CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
154
155     test_custom_palette();
156
157     CoUninitialize();
158 }