1 /* Unit test suite for cursors and icons.
3 * Copyright 2006 Michael Kaufmann
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
25 #include "wine/test.h"
32 static void test_CopyImage_Check(HBITMAP bitmap, UINT flags, INT copyWidth, INT copyHeight,
33 INT expectedWidth, INT expectedHeight, WORD expectedDepth, BOOL dibExpected)
41 copy = (HBITMAP) CopyImage(bitmap, IMAGE_BITMAP, copyWidth, copyHeight, flags);
42 ok(copy != NULL, "CopyImage() failed\n");
45 GetObject(bitmap, sizeof(origBitmap), &origBitmap);
46 GetObject(copy, sizeof(copyBitmap), ©Bitmap);
47 orig_is_dib = (origBitmap.bmBits != NULL);
48 copy_is_dib = (copyBitmap.bmBits != NULL);
50 if (copy_is_dib && dibExpected
51 && copyBitmap.bmBitsPixel == 24
52 && (expectedDepth == 16 || expectedDepth == 32))
54 /* Windows 95 doesn't create DIBs with a depth of 16 or 32 bit */
55 if (GetVersion() & 0x80000000)
61 if (copy_is_dib && !dibExpected && !(flags & LR_CREATEDIBSECTION))
63 /* It's not forbidden to create a DIB section if the flag
64 LR_CREATEDIBSECTION is absent.
65 Windows 9x does this if the bitmap has a depth that doesn't
66 match the screen depth, Windows NT doesn't */
68 expectedDepth = origBitmap.bmBitsPixel;
71 ok((!(dibExpected ^ copy_is_dib)
72 && (copyBitmap.bmWidth == expectedWidth)
73 && (copyBitmap.bmHeight == expectedHeight)
74 && (copyBitmap.bmBitsPixel == expectedDepth)),
75 "CopyImage ((%s, %dx%d, %u bpp), %d, %d, %#x): Expected (%s, %dx%d, %u bpp), got (%s, %dx%d, %u bpp)\n",
76 orig_is_dib ? "DIB" : "DDB", origBitmap.bmWidth, origBitmap.bmHeight, origBitmap.bmBitsPixel,
77 copyWidth, copyHeight, flags,
78 dibExpected ? "DIB" : "DDB", expectedWidth, expectedHeight, expectedDepth,
79 copy_is_dib ? "DIB" : "DDB", copyBitmap.bmWidth, copyBitmap.bmHeight, copyBitmap.bmBitsPixel);
85 static void test_CopyImage_Bitmap(int depth)
94 /* Create a device-independent bitmap (DIB) */
95 info = (BITMAPINFO *) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD));
96 info->bmiHeader.biSize = sizeof(info->bmiHeader);
97 info->bmiHeader.biWidth = 2;
98 info->bmiHeader.biHeight = 2;
99 info->bmiHeader.biPlanes = 1;
100 info->bmiHeader.biBitCount = depth;
101 info->bmiHeader.biCompression = BI_RGB;
103 for (i=0; i < 256; i++)
105 info->bmiColors[i].rgbRed = i;
106 info->bmiColors[i].rgbGreen = i;
107 info->bmiColors[i].rgbBlue = 255 - i;
108 info->bmiColors[i].rgbReserved = 0;
111 dib = CreateDIBSection(NULL, info, DIB_RGB_COLORS, &bits, NULL, 0);
113 /* Create a device-dependent bitmap (DDB) */
114 screenDC = GetDC(NULL);
115 screen_depth = GetDeviceCaps(screenDC, BITSPIXEL);
116 if (depth == 1 || depth == screen_depth)
118 ddb = CreateBitmap(2, 2, 1, depth, NULL);
124 ReleaseDC(NULL, screenDC);
128 test_CopyImage_Check(ddb, 0, 0, 0, 2, 2, depth == 1 ? 1 : screen_depth, FALSE);
129 test_CopyImage_Check(ddb, 0, 0, 5, 2, 5, depth == 1 ? 1 : screen_depth, FALSE);
130 test_CopyImage_Check(ddb, 0, 5, 0, 5, 2, depth == 1 ? 1 : screen_depth, FALSE);
131 test_CopyImage_Check(ddb, 0, 5, 5, 5, 5, depth == 1 ? 1 : screen_depth, FALSE);
133 test_CopyImage_Check(ddb, LR_MONOCHROME, 0, 0, 2, 2, 1, FALSE);
134 test_CopyImage_Check(ddb, LR_MONOCHROME, 5, 0, 5, 2, 1, FALSE);
135 test_CopyImage_Check(ddb, LR_MONOCHROME, 0, 5, 2, 5, 1, FALSE);
136 test_CopyImage_Check(ddb, LR_MONOCHROME, 5, 5, 5, 5, 1, FALSE);
138 test_CopyImage_Check(ddb, LR_CREATEDIBSECTION, 0, 0, 2, 2, depth, TRUE);
139 test_CopyImage_Check(ddb, LR_CREATEDIBSECTION, 5, 0, 5, 2, depth, TRUE);
140 test_CopyImage_Check(ddb, LR_CREATEDIBSECTION, 0, 5, 2, 5, depth, TRUE);
141 test_CopyImage_Check(ddb, LR_CREATEDIBSECTION, 5, 5, 5, 5, depth, TRUE);
143 /* LR_MONOCHROME is ignored if LR_CREATEDIBSECTION is present */
144 test_CopyImage_Check(ddb, LR_MONOCHROME | LR_CREATEDIBSECTION, 0, 0, 2, 2, depth, TRUE);
145 test_CopyImage_Check(ddb, LR_MONOCHROME | LR_CREATEDIBSECTION, 5, 0, 5, 2, depth, TRUE);
146 test_CopyImage_Check(ddb, LR_MONOCHROME | LR_CREATEDIBSECTION, 0, 5, 2, 5, depth, TRUE);
147 test_CopyImage_Check(ddb, LR_MONOCHROME | LR_CREATEDIBSECTION, 5, 5, 5, 5, depth, TRUE);
154 test_CopyImage_Check(dib, 0, 0, 0, 2, 2, screen_depth, FALSE);
155 test_CopyImage_Check(dib, 0, 5, 0, 5, 2, screen_depth, FALSE);
156 test_CopyImage_Check(dib, 0, 0, 5, 2, 5, screen_depth, FALSE);
157 test_CopyImage_Check(dib, 0, 5, 5, 5, 5, screen_depth, FALSE);
160 test_CopyImage_Check(dib, LR_MONOCHROME, 0, 0, 2, 2, 1, FALSE);
161 test_CopyImage_Check(dib, LR_MONOCHROME, 5, 0, 5, 2, 1, FALSE);
162 test_CopyImage_Check(dib, LR_MONOCHROME, 0, 5, 2, 5, 1, FALSE);
163 test_CopyImage_Check(dib, LR_MONOCHROME, 5, 5, 5, 5, 1, FALSE);
165 test_CopyImage_Check(dib, LR_CREATEDIBSECTION, 0, 0, 2, 2, depth, TRUE);
166 test_CopyImage_Check(dib, LR_CREATEDIBSECTION, 5, 0, 5, 2, depth, TRUE);
167 test_CopyImage_Check(dib, LR_CREATEDIBSECTION, 0, 5, 2, 5, depth, TRUE);
168 test_CopyImage_Check(dib, LR_CREATEDIBSECTION, 5, 5, 5, 5, depth, TRUE);
170 /* LR_MONOCHROME is ignored if LR_CREATEDIBSECTION is present */
171 test_CopyImage_Check(dib, LR_MONOCHROME | LR_CREATEDIBSECTION, 0, 0, 2, 2, depth, TRUE);
172 test_CopyImage_Check(dib, LR_MONOCHROME | LR_CREATEDIBSECTION, 5, 0, 5, 2, depth, TRUE);
173 test_CopyImage_Check(dib, LR_MONOCHROME | LR_CREATEDIBSECTION, 0, 5, 2, 5, depth, TRUE);
174 test_CopyImage_Check(dib, LR_MONOCHROME | LR_CREATEDIBSECTION, 5, 5, 5, 5, depth, TRUE);
180 /* Special case: A monochrome DIB is converted to a monochrome DDB if
181 the colors in the color table are black and white.
183 Skip this test on Windows 95, it always creates a monochrome DDB
186 if (!(GetVersion() & 0x80000000))
188 info->bmiHeader.biBitCount = 1;
189 info->bmiColors[0].rgbRed = 0xFF;
190 info->bmiColors[0].rgbGreen = 0;
191 info->bmiColors[0].rgbBlue = 0;
192 info->bmiColors[1].rgbRed = 0;
193 info->bmiColors[1].rgbGreen = 0xFF;
194 info->bmiColors[1].rgbBlue = 0;
196 dib = CreateDIBSection(NULL, info, DIB_RGB_COLORS, &bits, NULL, 0);
197 test_CopyImage_Check(dib, 0, 0, 0, 2, 2, screen_depth, FALSE);
198 test_CopyImage_Check(dib, 0, 5, 0, 5, 2, screen_depth, FALSE);
199 test_CopyImage_Check(dib, 0, 0, 5, 2, 5, screen_depth, FALSE);
200 test_CopyImage_Check(dib, 0, 5, 5, 5, 5, screen_depth, FALSE);
203 info->bmiHeader.biBitCount = 1;
204 info->bmiColors[0].rgbRed = 0;
205 info->bmiColors[0].rgbGreen = 0;
206 info->bmiColors[0].rgbBlue = 0;
207 info->bmiColors[1].rgbRed = 0xFF;
208 info->bmiColors[1].rgbGreen = 0xFF;
209 info->bmiColors[1].rgbBlue = 0xFF;
211 dib = CreateDIBSection(NULL, info, DIB_RGB_COLORS, &bits, NULL, 0);
212 test_CopyImage_Check(dib, 0, 0, 0, 2, 2, 1, FALSE);
213 test_CopyImage_Check(dib, 0, 5, 0, 5, 2, 1, FALSE);
214 test_CopyImage_Check(dib, 0, 0, 5, 2, 5, 1, FALSE);
215 test_CopyImage_Check(dib, 0, 5, 5, 5, 5, 1, FALSE);
218 info->bmiHeader.biBitCount = 1;
219 info->bmiColors[0].rgbRed = 0xFF;
220 info->bmiColors[0].rgbGreen = 0xFF;
221 info->bmiColors[0].rgbBlue = 0xFF;
222 info->bmiColors[1].rgbRed = 0;
223 info->bmiColors[1].rgbGreen = 0;
224 info->bmiColors[1].rgbBlue = 0;
226 dib = CreateDIBSection(NULL, info, DIB_RGB_COLORS, &bits, NULL, 0);
227 test_CopyImage_Check(dib, 0, 0, 0, 2, 2, 1, FALSE);
228 test_CopyImage_Check(dib, 0, 5, 0, 5, 2, 1, FALSE);
229 test_CopyImage_Check(dib, 0, 0, 5, 2, 5, 1, FALSE);
230 test_CopyImage_Check(dib, 0, 5, 5, 5, 5, 1, FALSE);
235 HeapFree(GetProcessHeap(), 0, info);
238 START_TEST(cursoricon)
240 test_CopyImage_Bitmap(1);
241 test_CopyImage_Bitmap(4);
242 test_CopyImage_Bitmap(8);
243 test_CopyImage_Bitmap(16);
244 test_CopyImage_Bitmap(24);
245 test_CopyImage_Bitmap(32);