dmsynth: Dump data passed to Download method.
[wine] / dlls / windowscodecs / tests / icoformat.c
1 /*
2  * Copyright 2010 Damjan Jovanovic
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 #include <math.h>
21
22 #define COBJMACROS
23
24 #include "windef.h"
25 #include "objbase.h"
26 #include "wincodec.h"
27 #include "wine/test.h"
28
29 static unsigned char testico_bad_icondirentry_size[] = {
30     /* ICONDIR */
31     0, 0, /* reserved */
32     1, 0, /* type */
33     1, 0, /* count */
34     /* ICONDIRENTRY */
35     2, /* width */
36     2, /* height */
37     2, /* colorCount */
38     0, /* reserved */
39     1,0, /* planes */
40     8,0, /* bitCount */
41     (40+2*4+16*16+16*4) & 0xFF,((40+2*4+16*16+16*4) >> 8) & 0xFF,0,0, /* bytesInRes */
42     22,0,0,0, /* imageOffset */
43     /* BITMAPINFOHEADER */
44     40,0,0,0, /* header size */
45     16,0,0,0, /* width */
46     2*16,0,0,0, /* height (XOR+AND rows) */
47     1,0, /* planes */
48     8,0, /* bit count */
49     0,0,0,0, /* compression */
50     0,0,0,0, /* sizeImage */
51     0,0,0,0, /* x pels per meter */
52     0,0,0,0, /* y pels per meter */
53     2,0,0,0, /* clrUsed */
54     0,0,0,0, /* clrImportant */
55     /* palette */
56     0,0,0,0,
57     0xFF,0xFF,0xFF,0,
58     /* XOR mask */
59     0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
60     0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
61     0,1,0,0,0,0,0,0,0,0,0,0,0,1,0,0,
62     0,1,0,0,0,0,0,0,0,0,0,0,0,1,0,0,
63     0,1,0,0,0,0,0,0,0,0,0,0,0,1,0,0,
64     0,0,1,0,0,0,0,0,0,0,0,0,1,0,0,0,
65     0,0,1,0,0,0,0,0,0,0,0,0,1,0,0,0,
66     0,0,1,0,0,0,0,0,0,0,0,0,1,0,0,0,
67     0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,
68     0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,
69     0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,0,
70     0,0,0,0,1,0,1,0,1,0,1,0,0,0,0,0,
71     0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,
72     0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
73     0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
74     0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
75     /* AND mask */
76     0,0,0,0,
77     0,0,0,0,
78     0,0,0,0,
79     0,0,0,0,
80     0,0,0,0,
81     0,0,0,0,
82     0,0,0,0,
83     0,0,0,0,
84     0,0,0,0,
85     0,0,0,0,
86     0,0,0,0,
87     0,0,0,0,
88     0,0,0,0,
89     0,0,0,0,
90     0,0,0,0,
91     0,0,0,0
92 };
93
94 static void test_bad_icondirentry_size(void)
95 {
96     IWICBitmapDecoder *decoder;
97     IWICImagingFactory *factory;
98     HRESULT hr;
99     IWICStream *icostream;
100     IWICBitmapFrameDecode *framedecode = NULL;
101
102     hr = CoCreateInstance(&CLSID_WICImagingFactory, NULL, CLSCTX_INPROC_SERVER,
103         &IID_IWICImagingFactory, (void**)&factory);
104     ok(hr == S_OK, "CoCreateInstance failed, hr=%x\n", hr);
105     if (FAILED(hr)) return;
106
107     hr = IWICImagingFactory_CreateStream(factory, &icostream);
108     ok(hr == S_OK, "CreateStream failed, hr=%x\n", hr);
109     if (SUCCEEDED(hr))
110     {
111         hr = IWICStream_InitializeFromMemory(icostream, testico_bad_icondirentry_size,
112             sizeof(testico_bad_icondirentry_size));
113         ok(hr == S_OK, "InitializeFromMemory failed, hr=%x\n", hr);
114
115         if (SUCCEEDED(hr))
116         {
117             hr = CoCreateInstance(&CLSID_WICIcoDecoder, NULL, CLSCTX_INPROC_SERVER,
118                 &IID_IWICBitmapDecoder, (void**)&decoder);
119             ok(hr == S_OK, "CoCreateInstance failed, hr=%x\n", hr);
120         }
121
122         if (SUCCEEDED(hr))
123         {
124             hr = IWICBitmapDecoder_Initialize(decoder, (IStream*)icostream,
125                 WICDecodeMetadataCacheOnDemand);
126             ok(hr == S_OK, "Initialize failed, hr=%x\n", hr);
127
128             if (SUCCEEDED(hr))
129             {
130                 hr = IWICBitmapDecoder_GetFrame(decoder, 0, &framedecode);
131                 ok(hr == S_OK, "GetFrame failed, hr=%x\n", hr);
132             }
133
134             if (SUCCEEDED(hr))
135             {
136                 UINT width = 0, height = 0;
137                 IWICBitmapSource *thumbnail = NULL;
138
139                 hr = IWICBitmapFrameDecode_GetSize(framedecode, &width, &height);
140                 ok(hr == S_OK, "GetFrameSize failed, hr=%x\n", hr);
141                 ok(width == 16 && height == 16, "framesize=%ux%u\n", width, height);
142
143                 hr = IWICBitmapFrameDecode_GetThumbnail(framedecode, &thumbnail);
144                 todo_wine ok(hr == S_OK, "GetThumbnail failed, hr=%x\n", hr);
145
146                 if (thumbnail) IWICBitmapSource_Release(thumbnail);
147                 IWICBitmapFrameDecode_Release(framedecode);
148             }
149
150             IWICBitmapDecoder_Release(decoder);
151         }
152
153         IWICStream_Release(icostream);
154     }
155
156     IWICImagingFactory_Release(factory);
157 }
158
159 START_TEST(icoformat)
160 {
161     CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
162
163     test_bad_icondirentry_size();
164
165     CoUninitialize();
166 }