From 802d5ae0399d19a34340e88dda5576460b6c146e Mon Sep 17 00:00:00 2001
From: Fabian Maurer <dark.shadow4@web.de>
Date: Sun, 8 Aug 2021 06:14:22 +0200
Subject: [PATCH] comctl32/tests/static: Add test for icons

Signed-off-by: Fabian Maurer <dark.shadow4@web.de>
---
 dlls/comctl32/static.c                 |   8 ++++-
 dlls/comctl32/tests/ico16x16_1bpp.ico  | Bin 0 -> 198 bytes
 dlls/comctl32/tests/ico16x16_24bpp.ico | Bin 0 -> 1150 bytes
 dlls/comctl32/tests/ico17x17_1bpp.ico  | Bin 0 -> 206 bytes
 dlls/comctl32/tests/ico17x17_24bpp.ico | Bin 0 -> 1286 bytes
 dlls/comctl32/tests/ico32x32_1bpp.ico  | Bin 0 -> 326 bytes
 dlls/comctl32/tests/ico32x32_24bpp.ico | Bin 0 -> 4286 bytes
 dlls/comctl32/tests/ico64x64_1bpp.ico  | Bin 0 -> 1094 bytes
 dlls/comctl32/tests/ico64x64_24bpp.ico | Bin 0 -> 16958 bytes
 dlls/comctl32/tests/ico8x8_1bpp.ico    | Bin 0 -> 134 bytes
 dlls/comctl32/tests/ico8x8_24bpp.ico   | Bin 0 -> 350 bytes
 dlls/comctl32/tests/resources.h        |  11 ++++++
 dlls/comctl32/tests/rsrc.rc            |  30 +++++++++++++++++
 dlls/comctl32/tests/static.c           |  45 +++++++++++++++++++++++++
 14 files changed, 93 insertions(+), 1 deletion(-)
 create mode 100644 dlls/comctl32/tests/ico16x16_1bpp.ico
 create mode 100644 dlls/comctl32/tests/ico16x16_24bpp.ico
 create mode 100644 dlls/comctl32/tests/ico17x17_1bpp.ico
 create mode 100644 dlls/comctl32/tests/ico17x17_24bpp.ico
 create mode 100644 dlls/comctl32/tests/ico32x32_1bpp.ico
 create mode 100644 dlls/comctl32/tests/ico32x32_24bpp.ico
 create mode 100644 dlls/comctl32/tests/ico64x64_1bpp.ico
 create mode 100644 dlls/comctl32/tests/ico64x64_24bpp.ico
 create mode 100644 dlls/comctl32/tests/ico8x8_1bpp.ico
 create mode 100644 dlls/comctl32/tests/ico8x8_24bpp.ico

diff --git a/dlls/comctl32/static.c b/dlls/comctl32/static.c
index 2bd2b22bc20..45a262c051b 100644
--- a/dlls/comctl32/static.c
+++ b/dlls/comctl32/static.c
@@ -109,11 +109,17 @@ static BOOL get_icon_size( HICON handle, SIZE *size )
     if (!GetIconInfo(handle, &info))
         return FALSE;
 
-    ret = GetObjectW(info.hbmColor, sizeof(bmp), &bmp);
+    ret = GetObjectW(info.hbmMask, sizeof(bmp), &bmp);
     if (ret)
     {
         size->cx = bmp.bmWidth;
         size->cy = bmp.bmHeight;
+        /* For black and white icons, the bitmask contains the AND bitmask (upper half) and the XOR bitmask (lower half) */
+        if (!info.hbmColor)
+        {
+            size->cx = 32;
+            size->cy = 32;
+        }
     }
 
     DeleteObject(info.hbmMask);
diff --git a/dlls/comctl32/tests/ico16x16_1bpp.ico b/dlls/comctl32/tests/ico16x16_1bpp.ico
new file mode 100644
index 0000000000000000000000000000000000000000..bc3b2a096ef5ba8326413715b0e0981934554fb5
GIT binary patch
diff --git a/dlls/comctl32/tests/ico16x16_24bpp.ico b/dlls/comctl32/tests/ico16x16_24bpp.ico
new file mode 100644
index 0000000000000000000000000000000000000000..d671dae8c46cea1af95ba0c3b58038c711051548
GIT binary patch
diff --git a/dlls/comctl32/tests/ico17x17_1bpp.ico b/dlls/comctl32/tests/ico17x17_1bpp.ico
new file mode 100644
index 0000000000000000000000000000000000000000..b3f9348324729bba8e444acbdf898643e0030899
GIT binary patch
diff --git a/dlls/comctl32/tests/ico17x17_24bpp.ico b/dlls/comctl32/tests/ico17x17_24bpp.ico
new file mode 100644
index 0000000000000000000000000000000000000000..3e5856fff4ba093e29c46590c3936e8cb16f006f
GIT binary patch
diff --git a/dlls/comctl32/tests/ico32x32_1bpp.ico b/dlls/comctl32/tests/ico32x32_1bpp.ico
new file mode 100644
index 0000000000000000000000000000000000000000..9f26bbd9c5cd47e1e8429e24a57703e2e36023c2
GIT binary patch
diff --git a/dlls/comctl32/tests/ico32x32_24bpp.ico b/dlls/comctl32/tests/ico32x32_24bpp.ico
new file mode 100644
index 0000000000000000000000000000000000000000..a472f21488a548d6297a8a52d364db680de12de8
GIT binary patch
diff --git a/dlls/comctl32/tests/ico64x64_1bpp.ico b/dlls/comctl32/tests/ico64x64_1bpp.ico
new file mode 100644
index 0000000000000000000000000000000000000000..7c76236be35bddaa83886c5c6f960ae05cc05686
GIT binary patch
diff --git a/dlls/comctl32/tests/ico64x64_24bpp.ico b/dlls/comctl32/tests/ico64x64_24bpp.ico
new file mode 100644
index 0000000000000000000000000000000000000000..d134a0ca683ac8b5555c78d0bf2157c445eef63d
GIT binary patch
diff --git a/dlls/comctl32/tests/ico8x8_1bpp.ico b/dlls/comctl32/tests/ico8x8_1bpp.ico
new file mode 100644
index 0000000000000000000000000000000000000000..bc27625fa18c0d6f9f755a855432fd7add9885b2
GIT binary patch
diff --git a/dlls/comctl32/tests/ico8x8_24bpp.ico b/dlls/comctl32/tests/ico8x8_24bpp.ico
new file mode 100644
index 0000000000000000000000000000000000000000..ea993c571dd0a42488f66cf36ebcc7483aa9e685
GIT binary patch
diff --git a/dlls/comctl32/tests/resources.h b/dlls/comctl32/tests/resources.h
index c4692654aed..dc917ce58e0 100644
--- a/dlls/comctl32/tests/resources.h
+++ b/dlls/comctl32/tests/resources.h
@@ -42,6 +42,17 @@
 #define IDD_PROP_PAGE_ERROR 36
 #define IDD_PROP_PAGE_BAD_CONTROL 37
 
+#define IDB_ICON_8x8_1BPP       100
+#define IDB_ICON_8x8_24BPP      101
+#define IDB_ICON_16x16_1BPP     102
+#define IDB_ICON_16x16_24BPP    103
+#define IDB_ICON_17x17_1BPP     104
+#define IDB_ICON_17x17_24BPP    105
+#define IDB_ICON_32x32_1BPP     106
+#define IDB_ICON_32x32_24BPP    107
+#define IDB_ICON_64x64_1BPP     108
+#define IDB_ICON_64x64_24BPP    109
+
 #define IDC_PS_EDIT1 1000
 #define IDC_PS_EDIT2 1001
 #define IDC_PS_RADIO1 1010
diff --git a/dlls/comctl32/tests/rsrc.rc b/dlls/comctl32/tests/rsrc.rc
index df22053d4cc..9ba66cee8a0 100644
--- a/dlls/comctl32/tests/rsrc.rc
+++ b/dlls/comctl32/tests/rsrc.rc
@@ -104,6 +104,36 @@ IDB_BITMAP_80x15 BITMAP bmp80x15.bmp
 /* @makedep: bmp1x1_32bpp.bmp */
 IDB_BITMAP_1x1_32BPP BITMAP bmp1x1_32bpp.bmp
 
+/* @makedep: ico8x8_1bpp.ico */
+IDB_ICON_8x8_1BPP ICON ico8x8_1bpp.ico
+
+/* @makedep: ico8x8_24bpp.ico */
+IDB_ICON_8x8_24BPP ICON ico8x8_24bpp.ico
+
+/* @makedep: ico16x16_1bpp.ico */
+IDB_ICON_16x16_1BPP ICON ico16x16_1bpp.ico
+
+/* @makedep: ico16x16_24bpp.ico */
+IDB_ICON_16x16_24BPP ICON ico16x16_24bpp.ico
+
+/* @makedep: ico17x17_1bpp.ico */
+IDB_ICON_17x17_1BPP ICON ico17x17_1bpp.ico
+
+/* @makedep: ico17x17_24bpp.ico */
+IDB_ICON_17x17_24BPP ICON ico17x17_24bpp.ico
+
+/* @makedep: ico32x32_1bpp.ico */
+IDB_ICON_32x32_1BPP ICON ico32x32_1bpp.ico
+
+/* @makedep: ico32x32_24bpp.ico */
+IDB_ICON_32x32_24BPP ICON ico32x32_24bpp.ico
+
+/* @makedep: ico64x64_1bpp.ico */
+IDB_ICON_64x64_1BPP ICON ico64x64_1bpp.ico
+
+/* @makedep: ico64x64_24bpp.ico */
+IDB_ICON_64x64_24BPP ICON ico64x64_24bpp.ico
+
 IDD_PROP_PAGE_WITH_CUSTOM_DEFAULT_BUTTON DIALOG  5, 43, 227, 215
 STYLE WS_CHILD | WS_DISABLED
 FONT 8, "MS Shell Dlg"
diff --git a/dlls/comctl32/tests/static.c b/dlls/comctl32/tests/static.c
index 4efb7685790..15112e54a38 100644
--- a/dlls/comctl32/tests/static.c
+++ b/dlls/comctl32/tests/static.c
@@ -263,6 +263,50 @@ static void test_set_image(void)
     DeleteObject(image);
 }
 
+static void test_set_icon_step(int resource, int size, int line)
+{
+    HWND hwnd = create_static(SS_ICON);
+    HICON image, image2;
+    RECT rect;
+    int width, height;
+
+    image = LoadImageW(GetModuleHandleW(NULL), MAKEINTRESOURCEW(resource), IMAGE_ICON, 0, 0, 0);
+    ok_(__FILE__, line)(image != NULL, "LoadImage failed\n");
+
+    SendMessageW(hwnd, STM_SETIMAGE, IMAGE_ICON, (LPARAM)image);
+
+    image2 = (HICON)SendMessageW(hwnd, STM_GETIMAGE, IMAGE_ICON, 0);
+    //todo_wine
+    ok_(__FILE__, line)(image2 != NULL, "got NULL\n");
+    //todo_wine
+    ok_(__FILE__, line)(image2 == image, "image2 != image\n");
+
+    GetWindowRect(hwnd, &rect);
+    width = rect.right - rect.left;
+    height = rect.bottom - rect.top;
+    //todo_wine
+    ok_(__FILE__, line)(width == size, "Got %d\n", width);
+    //todo_wine
+    ok_(__FILE__, line)(height == size, "Got %d\n", height);
+
+    DeleteObject(image);
+    DestroyWindow(hwnd);
+}
+
+static void test_set_icon(void)
+{
+    test_set_icon_step(IDB_ICON_8x8_1BPP,    32, __LINE__);
+    test_set_icon_step(IDB_ICON_8x8_24BPP,   8, __LINE__);
+    test_set_icon_step(IDB_ICON_16x16_1BPP,  32, __LINE__);
+    test_set_icon_step(IDB_ICON_16x16_24BPP, 16, __LINE__);
+    test_set_icon_step(IDB_ICON_17x17_1BPP,  32, __LINE__);
+    test_set_icon_step(IDB_ICON_17x17_24BPP, 17, __LINE__);
+    test_set_icon_step(IDB_ICON_32x32_1BPP,  32, __LINE__);
+    test_set_icon_step(IDB_ICON_32x32_24BPP, 32, __LINE__);
+    test_set_icon_step(IDB_ICON_64x64_1BPP,  32, __LINE__);
+    test_set_icon_step(IDB_ICON_64x64_24BPP, 64, __LINE__);
+}
+
 START_TEST(static)
 {
     static const char classname[] = "testclass";
@@ -302,6 +346,7 @@ START_TEST(static)
     test_updates(SS_ETCHEDVERT, TODO_COUNT);
     test_set_text();
     test_set_image();
+    test_set_icon();
 
     DestroyWindow(hMainWnd);
 
-- 
2.32.0

