2 * Copyright 2010 Damjan Jovanovic
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
27 #include "wine/test.h"
52 struct ICONHEADER header
;
53 struct ICONDIRENTRY direntry
;
55 unsigned char data
[512];
58 static const struct test_ico ico_1
=
74 40 + 2*4 + 16 * 16 + 16 * 4, /* data size */
77 /* BITMAPINFOHEADER */
79 sizeof(BITMAPINFOHEADER
), /* header size */
81 2*16, /* height (XOR+AND rows) */
86 0, /* x pels per meter */
87 0, /* y pels per meter */
96 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
97 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
98 0,1,0,0,0,0,0,0,0,0,0,0,0,1,0,0,
99 0,1,0,0,0,0,0,0,0,0,0,0,0,1,0,0,
100 0,1,0,0,0,0,0,0,0,0,0,0,0,1,0,0,
101 0,0,1,0,0,0,0,0,0,0,0,0,1,0,0,0,
102 0,0,1,0,0,0,0,0,0,0,0,0,1,0,0,0,
103 0,0,1,0,0,0,0,0,0,0,0,0,1,0,0,0,
104 0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,
105 0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,
106 0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,0,
107 0,0,0,0,1,0,1,0,1,0,1,0,0,0,0,0,
108 0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,
109 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
110 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
111 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
134 #define test_ico_data(a, b, c) test_ico_data_(a, b, c, 0, __LINE__)
135 #define test_ico_data_todo(a, b, c) test_ico_data_(a, b, c, 1, __LINE__)
136 static void test_ico_data_(void *data
, DWORD data_size
, HRESULT init_hr
, int todo
, unsigned int line
)
138 IWICBitmapDecoder
*decoder
;
139 IWICImagingFactory
*factory
;
141 IWICStream
*icostream
;
142 IWICBitmapFrameDecode
*framedecode
= NULL
;
144 hr
= CoCreateInstance(&CLSID_WICImagingFactory
, NULL
, CLSCTX_INPROC_SERVER
,
145 &IID_IWICImagingFactory
, (void**)&factory
);
146 ok(hr
== S_OK
, "CoCreateInstance failed, hr=%x\n", hr
);
147 if (FAILED(hr
)) return;
149 hr
= IWICImagingFactory_CreateStream(factory
, &icostream
);
150 ok(hr
== S_OK
, "CreateStream failed, hr=%x\n", hr
);
153 hr
= IWICStream_InitializeFromMemory(icostream
, data
, data_size
);
154 ok(hr
== S_OK
, "InitializeFromMemory failed, hr=%x\n", hr
);
158 hr
= CoCreateInstance(&CLSID_WICIcoDecoder
, NULL
, CLSCTX_INPROC_SERVER
,
159 &IID_IWICBitmapDecoder
, (void**)&decoder
);
160 ok(hr
== S_OK
, "CoCreateInstance failed, hr=%x\n", hr
);
165 hr
= IWICBitmapDecoder_Initialize(decoder
, (IStream
*)icostream
,
166 WICDecodeMetadataCacheOnDemand
);
168 ok_(__FILE__
, line
)(hr
== init_hr
, "Initialize failed, hr=%x\n", hr
);
172 hr
= IWICBitmapDecoder_GetFrame(decoder
, 0, &framedecode
);
173 ok(hr
== S_OK
, "GetFrame failed, hr=%x\n", hr
);
179 IWICBitmapSource
*thumbnail
;
182 hr
= IWICBitmapFrameDecode_GetSize(framedecode
, &width
, &height
);
183 ok(hr
== S_OK
, "GetFrameSize failed, hr=%x\n", hr
);
184 ok(width
== 16 && height
== 16, "framesize=%ux%u\n", width
, height
);
186 hr
= IWICBitmapFrameDecode_GetThumbnail(framedecode
, &thumbnail
);
187 ok(hr
== S_OK
, "GetThumbnail failed, hr=%x\n", hr
);
191 hr
= IWICBitmapSource_GetSize(thumbnail
, &width
, &height
);
192 ok(hr
== S_OK
, "GetFrameSize failed, hr=%x\n", hr
);
193 ok(width
== 16 && height
== 16, "framesize=%ux%u\n", width
, height
);
194 IWICBitmapSource_Release(thumbnail
);
196 IWICBitmapFrameDecode_Release(framedecode
);
199 IWICBitmapDecoder_Release(decoder
);
202 IWICStream_Release(icostream
);
205 IWICImagingFactory_Release(factory
);
208 static void test_decoder(void)
212 /* Icon size specified in ICONDIRENTRY does not match bitmap header. */
214 ico
.direntry
.bWidth
= 2;
215 ico
.direntry
.bHeight
= 2;
216 test_ico_data(&ico
, sizeof(ico
), S_OK
);
218 /* Invalid DIRENTRY data size/offset. */
220 ico
.direntry
.dwDIBOffset
= sizeof(ico
);
221 test_ico_data(&ico
, sizeof(ico
), WINCODEC_ERR_BADIMAGE
);
224 ico
.direntry
.dwDIBSize
= sizeof(ico
);
225 test_ico_data(&ico
, sizeof(ico
), WINCODEC_ERR_BADIMAGE
);
227 /* Header fields validation. */
229 ico
.header
.idReserved
= 1;
230 test_ico_data_todo(&ico
, sizeof(ico
), S_OK
);
231 ico
.header
.idReserved
= 0;
232 ico
.header
.idType
= 100;
233 test_ico_data_todo(&ico
, sizeof(ico
), S_OK
);
235 /* Premature end of data. */
237 test_ico_data(&ico
, sizeof(ico
.header
) - 1, WINCODEC_ERR_STREAMREAD
);
238 test_ico_data(&ico
, sizeof(ico
.header
) + sizeof(ico
.direntry
) - 1, WINCODEC_ERR_BADIMAGE
);
241 START_TEST(icoformat
)
243 CoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);