2 * Unit test suite for cursors and icons.
4 * Copyright 2006 Michael Kaufmann
5 * Copyright 2007 Dmitry Timoshkov
6 * Copyright 2007-2008 Andrew Riedi
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
28 #include "wine/test.h"
47 } CURSORICONFILEDIRENTRY;
54 CURSORICONFILEDIRENTRY idEntries[1];
59 static char **test_argv;
61 static HWND child = 0;
62 static HWND parent = 0;
63 static HANDLE child_process;
65 #define PROC_INIT (WM_USER+1)
67 static LRESULT CALLBACK callback_child(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
74 /* Destroy the cursor. */
76 SetLastError(0xdeadbeef);
77 ret = DestroyCursor((HCURSOR) lParam);
78 error = GetLastError();
80 ok(!ret, "DestroyCursor on the active cursor succeeded.\n");
81 ok(error == ERROR_DESTROY_OBJECT_OF_OTHER_THREAD,
82 "Last error: %u\n", error);
90 return DefWindowProc(hwnd, msg, wParam, lParam);
93 static LRESULT CALLBACK callback_parent(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
97 child = (HWND) wParam;
101 return DefWindowProc(hwnd, msg, wParam, lParam);
104 static void do_child(void)
110 /* Register a new class. */
111 class.style = CS_GLOBALCLASS;
112 class.lpfnWndProc = callback_child;
113 class.cbClsExtra = 0;
114 class.cbWndExtra = 0;
115 class.hInstance = GetModuleHandle(NULL);
117 class.hCursor = NULL;
118 class.hbrBackground = NULL;
119 class.lpszMenuName = NULL;
120 class.lpszClassName = "cursor_child";
122 SetLastError(0xdeadbeef);
123 ret = RegisterClass(&class);
124 ok(ret, "Failed to register window class. Error: %u\n", GetLastError());
126 /* Create a window. */
127 child = CreateWindowA("cursor_child", "cursor_child", WS_POPUP | WS_VISIBLE,
128 0, 0, 200, 200, 0, 0, 0, NULL);
129 ok(child != 0, "CreateWindowA failed. Error: %u\n", GetLastError());
131 /* Let the parent know our HWND. */
132 PostMessage(parent, PROC_INIT, (WPARAM) child, 0);
134 /* Receive messages. */
135 while ((ret = GetMessage(&msg, child, 0, 0)))
137 ok(ret != -1, "GetMessage failed. Error: %u\n", GetLastError());
138 TranslateMessage(&msg);
139 DispatchMessage(&msg);
143 static void do_parent(void)
145 char path_name[MAX_PATH];
146 PROCESS_INFORMATION info;
147 STARTUPINFOA startup;
152 /* Register a new class. */
153 class.style = CS_GLOBALCLASS;
154 class.lpfnWndProc = callback_parent;
155 class.cbClsExtra = 0;
156 class.cbWndExtra = 0;
157 class.hInstance = GetModuleHandle(NULL);
159 class.hCursor = NULL;
160 class.hbrBackground = NULL;
161 class.lpszMenuName = NULL;
162 class.lpszClassName = "cursor_parent";
164 SetLastError(0xdeadbeef);
165 ret = RegisterClass(&class);
166 ok(ret, "Failed to register window class. Error: %u\n", GetLastError());
168 /* Create a window. */
169 parent = CreateWindowA("cursor_parent", "cursor_parent", WS_POPUP | WS_VISIBLE,
170 0, 0, 200, 200, 0, 0, 0, NULL);
171 ok(parent != 0, "CreateWindowA failed. Error: %u\n", GetLastError());
173 /* Start child process. */
174 memset(&startup, 0, sizeof(startup));
175 startup.cb = sizeof(startup);
176 startup.dwFlags = STARTF_USESHOWWINDOW;
177 startup.wShowWindow = SW_SHOWNORMAL;
179 sprintf(path_name, "%s cursoricon %x", test_argv[0], (unsigned int) parent);
180 ok(CreateProcessA(NULL, path_name, NULL, NULL, FALSE, 0L, NULL, NULL, &startup, &info), "CreateProcess failed.\n");
181 child_process = info.hProcess;
183 /* Wait for child window handle. */
184 while ((child == 0) && (ret = GetMessage(&msg, parent, 0, 0)))
186 ok(ret != -1, "GetMessage failed. Error: %u\n", GetLastError());
187 TranslateMessage(&msg);
188 DispatchMessage(&msg);
192 static void finish_child_process(void)
194 SendMessage(child, WM_CLOSE, 0, 0);
195 winetest_wait_child_process( child_process );
196 CloseHandle(child_process);
199 static void test_child_process(void)
201 static const BYTE bmp_bits[4096];
207 /* Create and set a dummy cursor. */
209 display_bpp = GetDeviceCaps(hdc, BITSPIXEL);
212 cursorInfo.fIcon = FALSE;
213 cursorInfo.xHotspot = 0;
214 cursorInfo.yHotspot = 0;
215 cursorInfo.hbmMask = CreateBitmap(32, 32, 1, 1, bmp_bits);
216 cursorInfo.hbmColor = CreateBitmap(32, 32, 1, display_bpp, bmp_bits);
218 cursor = CreateIconIndirect(&cursorInfo);
219 ok(cursor != NULL, "CreateIconIndirect returned %p.\n", cursor);
223 /* Destroy the cursor. */
224 SendMessage(child, WM_USER+1, 0, (LPARAM) cursor);
227 static void test_CopyImage_Check(HBITMAP bitmap, UINT flags, INT copyWidth, INT copyHeight,
228 INT expectedWidth, INT expectedHeight, WORD expectedDepth, BOOL dibExpected)
236 copy = (HBITMAP) CopyImage(bitmap, IMAGE_BITMAP, copyWidth, copyHeight, flags);
237 ok(copy != NULL, "CopyImage() failed\n");
240 GetObject(bitmap, sizeof(origBitmap), &origBitmap);
241 GetObject(copy, sizeof(copyBitmap), ©Bitmap);
242 orig_is_dib = (origBitmap.bmBits != NULL);
243 copy_is_dib = (copyBitmap.bmBits != NULL);
245 if (copy_is_dib && dibExpected
246 && copyBitmap.bmBitsPixel == 24
247 && (expectedDepth == 16 || expectedDepth == 32))
249 /* Windows 95 doesn't create DIBs with a depth of 16 or 32 bit */
250 if (GetVersion() & 0x80000000)
256 if (copy_is_dib && !dibExpected && !(flags & LR_CREATEDIBSECTION))
258 /* It's not forbidden to create a DIB section if the flag
259 LR_CREATEDIBSECTION is absent.
260 Windows 9x does this if the bitmap has a depth that doesn't
261 match the screen depth, Windows NT doesn't */
263 expectedDepth = origBitmap.bmBitsPixel;
266 ok((!(dibExpected ^ copy_is_dib)
267 && (copyBitmap.bmWidth == expectedWidth)
268 && (copyBitmap.bmHeight == expectedHeight)
269 && (copyBitmap.bmBitsPixel == expectedDepth)),
270 "CopyImage ((%s, %dx%d, %u bpp), %d, %d, %#x): Expected (%s, %dx%d, %u bpp), got (%s, %dx%d, %u bpp)\n",
271 orig_is_dib ? "DIB" : "DDB", origBitmap.bmWidth, origBitmap.bmHeight, origBitmap.bmBitsPixel,
272 copyWidth, copyHeight, flags,
273 dibExpected ? "DIB" : "DDB", expectedWidth, expectedHeight, expectedDepth,
274 copy_is_dib ? "DIB" : "DDB", copyBitmap.bmWidth, copyBitmap.bmHeight, copyBitmap.bmBitsPixel);
280 static void test_CopyImage_Bitmap(int depth)
289 /* Create a device-independent bitmap (DIB) */
290 info = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD));
291 info->bmiHeader.biSize = sizeof(info->bmiHeader);
292 info->bmiHeader.biWidth = 2;
293 info->bmiHeader.biHeight = 2;
294 info->bmiHeader.biPlanes = 1;
295 info->bmiHeader.biBitCount = depth;
296 info->bmiHeader.biCompression = BI_RGB;
298 for (i=0; i < 256; i++)
300 info->bmiColors[i].rgbRed = i;
301 info->bmiColors[i].rgbGreen = i;
302 info->bmiColors[i].rgbBlue = 255 - i;
303 info->bmiColors[i].rgbReserved = 0;
306 dib = CreateDIBSection(NULL, info, DIB_RGB_COLORS, &bits, NULL, 0);
308 /* Create a device-dependent bitmap (DDB) */
309 screenDC = GetDC(NULL);
310 screen_depth = GetDeviceCaps(screenDC, BITSPIXEL);
311 if (depth == 1 || depth == screen_depth)
313 ddb = CreateBitmap(2, 2, 1, depth, NULL);
319 ReleaseDC(NULL, screenDC);
323 test_CopyImage_Check(ddb, 0, 0, 0, 2, 2, depth == 1 ? 1 : screen_depth, FALSE);
324 test_CopyImage_Check(ddb, 0, 0, 5, 2, 5, depth == 1 ? 1 : screen_depth, FALSE);
325 test_CopyImage_Check(ddb, 0, 5, 0, 5, 2, depth == 1 ? 1 : screen_depth, FALSE);
326 test_CopyImage_Check(ddb, 0, 5, 5, 5, 5, depth == 1 ? 1 : screen_depth, FALSE);
328 test_CopyImage_Check(ddb, LR_MONOCHROME, 0, 0, 2, 2, 1, FALSE);
329 test_CopyImage_Check(ddb, LR_MONOCHROME, 5, 0, 5, 2, 1, FALSE);
330 test_CopyImage_Check(ddb, LR_MONOCHROME, 0, 5, 2, 5, 1, FALSE);
331 test_CopyImage_Check(ddb, LR_MONOCHROME, 5, 5, 5, 5, 1, FALSE);
333 test_CopyImage_Check(ddb, LR_CREATEDIBSECTION, 0, 0, 2, 2, depth, TRUE);
334 test_CopyImage_Check(ddb, LR_CREATEDIBSECTION, 5, 0, 5, 2, depth, TRUE);
335 test_CopyImage_Check(ddb, LR_CREATEDIBSECTION, 0, 5, 2, 5, depth, TRUE);
336 test_CopyImage_Check(ddb, LR_CREATEDIBSECTION, 5, 5, 5, 5, depth, TRUE);
338 /* LR_MONOCHROME is ignored if LR_CREATEDIBSECTION is present */
339 test_CopyImage_Check(ddb, LR_MONOCHROME | LR_CREATEDIBSECTION, 0, 0, 2, 2, depth, TRUE);
340 test_CopyImage_Check(ddb, LR_MONOCHROME | LR_CREATEDIBSECTION, 5, 0, 5, 2, depth, TRUE);
341 test_CopyImage_Check(ddb, LR_MONOCHROME | LR_CREATEDIBSECTION, 0, 5, 2, 5, depth, TRUE);
342 test_CopyImage_Check(ddb, LR_MONOCHROME | LR_CREATEDIBSECTION, 5, 5, 5, 5, depth, TRUE);
349 test_CopyImage_Check(dib, 0, 0, 0, 2, 2, screen_depth, FALSE);
350 test_CopyImage_Check(dib, 0, 5, 0, 5, 2, screen_depth, FALSE);
351 test_CopyImage_Check(dib, 0, 0, 5, 2, 5, screen_depth, FALSE);
352 test_CopyImage_Check(dib, 0, 5, 5, 5, 5, screen_depth, FALSE);
355 test_CopyImage_Check(dib, LR_MONOCHROME, 0, 0, 2, 2, 1, FALSE);
356 test_CopyImage_Check(dib, LR_MONOCHROME, 5, 0, 5, 2, 1, FALSE);
357 test_CopyImage_Check(dib, LR_MONOCHROME, 0, 5, 2, 5, 1, FALSE);
358 test_CopyImage_Check(dib, LR_MONOCHROME, 5, 5, 5, 5, 1, FALSE);
360 test_CopyImage_Check(dib, LR_CREATEDIBSECTION, 0, 0, 2, 2, depth, TRUE);
361 test_CopyImage_Check(dib, LR_CREATEDIBSECTION, 5, 0, 5, 2, depth, TRUE);
362 test_CopyImage_Check(dib, LR_CREATEDIBSECTION, 0, 5, 2, 5, depth, TRUE);
363 test_CopyImage_Check(dib, LR_CREATEDIBSECTION, 5, 5, 5, 5, depth, TRUE);
365 /* LR_MONOCHROME is ignored if LR_CREATEDIBSECTION is present */
366 test_CopyImage_Check(dib, LR_MONOCHROME | LR_CREATEDIBSECTION, 0, 0, 2, 2, depth, TRUE);
367 test_CopyImage_Check(dib, LR_MONOCHROME | LR_CREATEDIBSECTION, 5, 0, 5, 2, depth, TRUE);
368 test_CopyImage_Check(dib, LR_MONOCHROME | LR_CREATEDIBSECTION, 0, 5, 2, 5, depth, TRUE);
369 test_CopyImage_Check(dib, LR_MONOCHROME | LR_CREATEDIBSECTION, 5, 5, 5, 5, depth, TRUE);
375 /* Special case: A monochrome DIB is converted to a monochrome DDB if
376 the colors in the color table are black and white.
378 Skip this test on Windows 95, it always creates a monochrome DDB
381 if (!(GetVersion() & 0x80000000))
383 info->bmiHeader.biBitCount = 1;
384 info->bmiColors[0].rgbRed = 0xFF;
385 info->bmiColors[0].rgbGreen = 0;
386 info->bmiColors[0].rgbBlue = 0;
387 info->bmiColors[1].rgbRed = 0;
388 info->bmiColors[1].rgbGreen = 0xFF;
389 info->bmiColors[1].rgbBlue = 0;
391 dib = CreateDIBSection(NULL, info, DIB_RGB_COLORS, &bits, NULL, 0);
392 test_CopyImage_Check(dib, 0, 0, 0, 2, 2, screen_depth, FALSE);
393 test_CopyImage_Check(dib, 0, 5, 0, 5, 2, screen_depth, FALSE);
394 test_CopyImage_Check(dib, 0, 0, 5, 2, 5, screen_depth, FALSE);
395 test_CopyImage_Check(dib, 0, 5, 5, 5, 5, screen_depth, FALSE);
398 info->bmiHeader.biBitCount = 1;
399 info->bmiColors[0].rgbRed = 0;
400 info->bmiColors[0].rgbGreen = 0;
401 info->bmiColors[0].rgbBlue = 0;
402 info->bmiColors[1].rgbRed = 0xFF;
403 info->bmiColors[1].rgbGreen = 0xFF;
404 info->bmiColors[1].rgbBlue = 0xFF;
406 dib = CreateDIBSection(NULL, info, DIB_RGB_COLORS, &bits, NULL, 0);
407 test_CopyImage_Check(dib, 0, 0, 0, 2, 2, 1, FALSE);
408 test_CopyImage_Check(dib, 0, 5, 0, 5, 2, 1, FALSE);
409 test_CopyImage_Check(dib, 0, 0, 5, 2, 5, 1, FALSE);
410 test_CopyImage_Check(dib, 0, 5, 5, 5, 5, 1, FALSE);
413 info->bmiHeader.biBitCount = 1;
414 info->bmiColors[0].rgbRed = 0xFF;
415 info->bmiColors[0].rgbGreen = 0xFF;
416 info->bmiColors[0].rgbBlue = 0xFF;
417 info->bmiColors[1].rgbRed = 0;
418 info->bmiColors[1].rgbGreen = 0;
419 info->bmiColors[1].rgbBlue = 0;
421 dib = CreateDIBSection(NULL, info, DIB_RGB_COLORS, &bits, NULL, 0);
422 test_CopyImage_Check(dib, 0, 0, 0, 2, 2, 1, FALSE);
423 test_CopyImage_Check(dib, 0, 5, 0, 5, 2, 1, FALSE);
424 test_CopyImage_Check(dib, 0, 0, 5, 2, 5, 1, FALSE);
425 test_CopyImage_Check(dib, 0, 5, 5, 5, 5, 1, FALSE);
430 HeapFree(GetProcessHeap(), 0, info);
433 static void test_initial_cursor(void)
435 HCURSOR cursor, cursor2;
438 cursor = GetCursor();
440 /* Check what handle GetCursor() returns if a cursor is not set yet. */
441 SetLastError(0xdeadbeef);
442 cursor2 = LoadCursor(NULL, IDC_WAIT);
444 ok(cursor == cursor2, "cursor (%p) is not IDC_WAIT (%p).\n", cursor, cursor2);
446 error = GetLastError();
447 ok(error == 0xdeadbeef, "Last error: 0x%08x\n", error);
450 static void test_icon_info_dbg(HICON hIcon, UINT exp_cx, UINT exp_cy, UINT exp_bpp, int line)
454 BITMAP bmMask, bmColor;
456 ret = GetIconInfo(hIcon, &info);
457 ok_(__FILE__, line)(ret, "GetIconInfo failed\n");
459 /* CreateIcon under XP causes info.fIcon to be 0 */
460 ok_(__FILE__, line)(info.xHotspot == exp_cx/2, "info.xHotspot = %u\n", info.xHotspot);
461 ok_(__FILE__, line)(info.yHotspot == exp_cy/2, "info.yHotspot = %u\n", info.yHotspot);
462 ok_(__FILE__, line)(info.hbmMask != 0, "info.hbmMask is NULL\n");
464 ret = GetObject(info.hbmMask, sizeof(bmMask), &bmMask);
465 ok_(__FILE__, line)(ret == sizeof(bmMask), "GetObject(info.hbmMask) failed, ret %u\n", ret);
468 ok_(__FILE__, line)(info.hbmColor == 0, "info.hbmColor should be NULL\n");
476 display_bpp = GetDeviceCaps(hdc, BITSPIXEL);
479 ret = GetObject(info.hbmColor, sizeof(bmColor), &bmColor);
480 ok_(__FILE__, line)(ret == sizeof(bmColor), "GetObject(info.hbmColor) failed, ret %u\n", ret);
482 ok_(__FILE__, line)(bmColor.bmBitsPixel == display_bpp /* XP */ ||
483 bmColor.bmBitsPixel == exp_bpp /* Win98 */,
484 "bmColor.bmBitsPixel = %d\n", bmColor.bmBitsPixel);
485 ok_(__FILE__, line)(bmColor.bmWidth == exp_cx, "bmColor.bmWidth = %d\n", bmColor.bmWidth);
486 ok_(__FILE__, line)(bmColor.bmHeight == exp_cy, "bmColor.bmHeight = %d\n", bmColor.bmHeight);
488 ok_(__FILE__, line)(bmMask.bmBitsPixel == 1, "bmMask.bmBitsPixel = %d\n", bmMask.bmBitsPixel);
489 ok_(__FILE__, line)(bmMask.bmWidth == exp_cx, "bmMask.bmWidth = %d\n", bmMask.bmWidth);
490 ok_(__FILE__, line)(bmMask.bmHeight == exp_cy, "bmMask.bmHeight = %d\n", bmMask.bmHeight);
494 ok_(__FILE__, line)(bmMask.bmBitsPixel == 1, "bmMask.bmBitsPixel = %d\n", bmMask.bmBitsPixel);
495 ok_(__FILE__, line)(bmMask.bmWidth == exp_cx, "bmMask.bmWidth = %d\n", bmMask.bmWidth);
496 ok_(__FILE__, line)(bmMask.bmHeight == exp_cy * 2, "bmMask.bmHeight = %d\n", bmMask.bmHeight);
500 #define test_icon_info(a,b,c,d) test_icon_info_dbg((a),(b),(c),(d),__LINE__)
502 static void test_CreateIcon(void)
504 static const BYTE bmp_bits[1024];
506 HBITMAP hbmMask, hbmColor;
512 display_bpp = GetDeviceCaps(hdc, BITSPIXEL);
515 /* these crash under XP
516 hIcon = CreateIcon(0, 16, 16, 1, 1, bmp_bits, NULL);
517 hIcon = CreateIcon(0, 16, 16, 1, 1, NULL, bmp_bits);
520 hIcon = CreateIcon(0, 16, 16, 1, 1, bmp_bits, bmp_bits);
521 ok(hIcon != 0, "CreateIcon failed\n");
522 test_icon_info(hIcon, 16, 16, 1);
525 hIcon = CreateIcon(0, 16, 16, 1, display_bpp, bmp_bits, bmp_bits);
526 ok(hIcon != 0, "CreateIcon failed\n");
527 test_icon_info(hIcon, 16, 16, display_bpp);
530 hbmMask = CreateBitmap(16, 16, 1, 1, bmp_bits);
531 ok(hbmMask != 0, "CreateBitmap failed\n");
532 hbmColor = CreateBitmap(16, 16, 1, display_bpp, bmp_bits);
533 ok(hbmColor != 0, "CreateBitmap failed\n");
540 SetLastError(0xdeadbeaf);
541 hIcon = CreateIconIndirect(&info);
542 ok(!hIcon, "CreateIconIndirect should fail\n");
543 ok(GetLastError() == 0xdeadbeaf, "wrong error %u\n", GetLastError());
549 info.hbmColor = hbmColor;
550 SetLastError(0xdeadbeaf);
551 hIcon = CreateIconIndirect(&info);
552 ok(!hIcon, "CreateIconIndirect should fail\n");
553 ok(GetLastError() == 0xdeadbeaf, "wrong error %u\n", GetLastError());
558 info.hbmMask = hbmMask;
559 info.hbmColor = hbmColor;
560 hIcon = CreateIconIndirect(&info);
561 ok(hIcon != 0, "CreateIconIndirect failed\n");
562 test_icon_info(hIcon, 16, 16, display_bpp);
565 DeleteObject(hbmMask);
566 DeleteObject(hbmColor);
568 hbmMask = CreateBitmap(16, 32, 1, 1, bmp_bits);
569 ok(hbmMask != 0, "CreateBitmap failed\n");
574 info.hbmMask = hbmMask;
576 SetLastError(0xdeadbeaf);
577 hIcon = CreateIconIndirect(&info);
578 ok(hIcon != 0, "CreateIconIndirect failed\n");
579 test_icon_info(hIcon, 16, 16, 1);
582 DeleteObject(hbmMask);
583 DeleteObject(hbmColor);
586 static void test_LoadImage(void)
590 DWORD error, bytes_written;
591 CURSORICONFILEDIR *icon_data;
592 CURSORICONFILEDIRENTRY *icon_entry;
593 BITMAPINFOHEADER *icon_header;
596 #define ICON_WIDTH 32
597 #define ICON_HEIGHT 32
598 #define ICON_AND_SIZE (ICON_WIDTH*ICON_HEIGHT/8)
601 (sizeof(CURSORICONFILEDIR) + sizeof(BITMAPINFOHEADER) \
602 + ICON_AND_SIZE + ICON_AND_SIZE*ICON_BPP)
605 icon_data = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, ICON_SIZE);
606 icon_data->idReserved = 0;
607 icon_data->idType = 1;
608 icon_data->idCount = 1;
610 icon_entry = icon_data->idEntries;
611 icon_entry->bWidth = ICON_WIDTH;
612 icon_entry->bHeight = ICON_HEIGHT;
613 icon_entry->bColorCount = 0;
614 icon_entry->bReserved = 0;
615 icon_entry->xHotspot = 1;
616 icon_entry->yHotspot = 1;
617 icon_entry->dwDIBSize = ICON_SIZE - sizeof(CURSORICONFILEDIR);
618 icon_entry->dwDIBOffset = sizeof(CURSORICONFILEDIR);
620 icon_header = (BITMAPINFOHEADER *) ((BYTE *) icon_data + icon_entry->dwDIBOffset);
621 icon_header->biSize = sizeof(BITMAPINFOHEADER);
622 icon_header->biWidth = ICON_WIDTH;
623 icon_header->biHeight = ICON_HEIGHT*2;
624 icon_header->biPlanes = 1;
625 icon_header->biBitCount = ICON_BPP;
626 icon_header->biSizeImage = 0; /* Uncompressed bitmap. */
628 /* Create the icon. */
629 handle = CreateFileA("icon.ico", GENERIC_READ|GENERIC_WRITE, 0, NULL, CREATE_NEW,
630 FILE_ATTRIBUTE_NORMAL, NULL);
631 ok(handle != INVALID_HANDLE_VALUE, "CreateFileA failed. %u\n", GetLastError());
632 ret = WriteFile(handle, icon_data, ICON_SIZE, &bytes_written, NULL);
633 ok(bytes_written == ICON_SIZE, "icon.ico created improperly.\n");
636 /* Test loading an icon as a cursor. */
637 SetLastError(0xdeadbeef);
638 handle = LoadImageA(NULL, "icon.ico", IMAGE_CURSOR, 0, 0, LR_LOADFROMFILE);
640 ok(handle != NULL, "LoadImage() failed.\n");
641 error = GetLastError();
642 ok(error == 0, "Last error: %u\n", error);
644 /* Test the icon information. */
645 SetLastError(0xdeadbeef);
646 ret = GetIconInfo(handle, &icon_info);
648 ok(ret, "GetIconInfo() failed.\n");
649 error = GetLastError();
650 ok(error == 0xdeadbeef, "Last error: %u\n", error);
653 ok(icon_info.fIcon == FALSE, "fIcon != FALSE.\n");
654 ok(icon_info.xHotspot == 1, "xHotspot is %u.\n", icon_info.xHotspot);
655 ok(icon_info.yHotspot == 1, "yHotspot is %u.\n", icon_info.yHotspot);
656 ok(icon_info.hbmColor != NULL, "No hbmColor!\n");
658 ok(icon_info.hbmMask != NULL, "No hbmMask!\n");
661 SetLastError(0xdeadbeef);
662 ret = DestroyCursor(handle);
664 ok(ret, "DestroyCursor() failed.\n");
665 error = GetLastError();
666 ok(error == 0xdeadbeef, "Last error: %u\n", error);
668 HeapFree(GetProcessHeap(), 0, icon_data);
669 DeleteFileA("icon.ico");
672 static void test_DestroyCursor(void)
674 static const BYTE bmp_bits[4096];
676 HCURSOR cursor, cursor2;
683 display_bpp = GetDeviceCaps(hdc, BITSPIXEL);
686 cursorInfo.fIcon = FALSE;
687 cursorInfo.xHotspot = 0;
688 cursorInfo.yHotspot = 0;
689 cursorInfo.hbmMask = CreateBitmap(32, 32, 1, 1, bmp_bits);
690 cursorInfo.hbmColor = CreateBitmap(32, 32, 1, display_bpp, bmp_bits);
692 cursor = CreateIconIndirect(&cursorInfo);
693 ok(cursor != NULL, "CreateIconIndirect returned %p\n", cursor);
699 SetLastError(0xdeadbeef);
700 ret = DestroyCursor(cursor);
701 ok(!ret, "DestroyCursor on the active cursor succeeded\n");
702 error = GetLastError();
703 ok(error == 0xdeadbeef, "Last error: %u\n", error);
705 cursor2 = GetCursor();
706 ok(cursor2 == cursor, "Active was set to %p when trying to destroy it\n", cursor2);
710 /* Trying to destroy the cursor properly fails now with
711 * ERROR_INVALID_CURSOR_HANDLE. This happens because we called
712 * DestroyCursor() 2+ times after calling SetCursor(). The calls to
713 * GetCursor() and SetCursor(NULL) in between make no difference. */
714 ret = DestroyCursor(cursor);
716 ok(!ret, "DestroyCursor succeeded.\n");
717 error = GetLastError();
718 ok(error == ERROR_INVALID_CURSOR_HANDLE, "Last error: 0x%08x\n", error);
721 DeleteObject(cursorInfo.hbmMask);
722 DeleteObject(cursorInfo.hbmColor);
724 /* Try testing DestroyCursor() now using LoadCursor() cursors. */
725 cursor = LoadCursor(NULL, IDC_ARROW);
727 SetLastError(0xdeadbeef);
728 ret = DestroyCursor(cursor);
729 ok(ret, "DestroyCursor on the active cursor failed.\n");
730 error = GetLastError();
731 ok(error == 0xdeadbeef, "Last error: 0x%08x\n", error);
733 /* Try setting the cursor to a destroyed OEM cursor. */
734 SetLastError(0xdeadbeef);
736 error = GetLastError();
738 ok(error == 0xdeadbeef, "Last error: 0x%08x\n", error);
741 /* Check if LoadCursor() returns the same handle with the same icon. */
742 cursor2 = LoadCursor(NULL, IDC_ARROW);
743 ok(cursor2 == cursor, "cursor == %p, cursor2 == %p\n", cursor, cursor2);
745 /* Check if LoadCursor() returns the same handle with a different icon. */
746 cursor2 = LoadCursor(NULL, IDC_WAIT);
747 ok(cursor2 != cursor, "cursor == %p, cursor2 == %p\n", cursor, cursor2);
750 START_TEST(cursoricon)
752 test_argc = winetest_get_mainargs(&test_argv);
757 sscanf (test_argv[2], "%x", (unsigned int *) &parent);
759 ok(parent != NULL, "Parent not found.\n");
767 test_CopyImage_Bitmap(1);
768 test_CopyImage_Bitmap(4);
769 test_CopyImage_Bitmap(8);
770 test_CopyImage_Bitmap(16);
771 test_CopyImage_Bitmap(24);
772 test_CopyImage_Bitmap(32);
773 test_initial_cursor();
776 test_DestroyCursor();
778 test_child_process();
779 finish_child_process();