From 5fb4f327592be73c15c24fbcfdbb1f5518963689 Mon Sep 17 00:00:00 2001
From: Ilya Shpigor <shpigor@etersoft.ru>
Date: Fri, 2 Oct 2009 12:09:07 +0400
Subject: [PATCH] user32/tests: Add tests for STM_SETIMAGE and STM_SETICON message processing

---
 dlls/user32/tests/msg.c |  116 +++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 116 insertions(+), 0 deletions(-)

diff --git a/dlls/user32/tests/msg.c b/dlls/user32/tests/msg.c
index 9208c9d..fa91cba 100644
--- a/dlls/user32/tests/msg.c
+++ b/dlls/user32/tests/msg.c
@@ -5454,6 +5454,38 @@ static const struct message WmSetFontStaticSeq[] =
     { 0 }
 };
 
+static const struct message WmSetImageOkStaticSeq[] =
+{
+    { STM_SETIMAGE, sent },
+    { WM_WINDOWPOSCHANGING, sent|defwinproc },
+    { WM_PAINT, sent|defwinproc|optional },
+    { WM_ERASEBKGND, sent|defwinproc|optional },
+    { WM_CTLCOLORSTATIC, sent|defwinproc|optional },
+    { 0 }
+};
+
+static const struct message WmSetIconOkStaticSeq[] =
+{
+    { STM_SETICON, sent },
+    { WM_WINDOWPOSCHANGING, sent|defwinproc },
+    { WM_PAINT, sent|defwinproc|optional },
+    { WM_ERASEBKGND, sent|defwinproc|optional },
+    { WM_CTLCOLORSTATIC, sent|defwinproc|optional },
+    { 0 }
+};
+
+static const struct message WmSetImageErrStaticSeq[] =
+{
+    { STM_SETIMAGE, sent },
+    { 0 }
+};
+
+static const struct message WmSetIconErrStaticSeq[] =
+{
+    { STM_SETICON, sent },
+    { 0 }
+};
+
 static WNDPROC old_static_proc;
 
 static LRESULT CALLBACK static_hook_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
@@ -5510,6 +5542,14 @@ static void test_static_messages(void)
     unsigned int i;
     HWND hwnd;
     DWORD dlg_code;
+    HBITMAP hbm;
+    HICON hicon;
+    HENHMETAFILE hemf;
+    int depth;
+    int planes;
+    HDC hdc;
+    LRESULT res;
+    DWORD style;
 
     subclass_static();
 
@@ -5533,6 +5573,82 @@ static void test_static_messages(void)
 
 	DestroyWindow(hwnd);
     }
+
+    hwnd = CreateWindowExA(0, "my_static_class", "test", SS_LEFT | WS_POPUP | WS_VISIBLE,
+                           0, 0, 50, 14, 0, 0, 0, NULL);
+    ok(hwnd != 0, "Failed to create static window\n");
+
+    hdc = GetDC(hwnd);
+    depth = GetDeviceCaps(hdc, BITSPIXEL);
+    planes = GetDeviceCaps(hdc, PLANES);
+    ReleaseDC(hwnd, hdc);
+    hbm = CreateBitmap(16, 16, planes, depth, NULL);
+    hicon = CreateIcon(GetModuleHandle(NULL), 16, 16, planes, depth, NULL, NULL);
+    hdc = CreateEnhMetaFileA(NULL, NULL, NULL, NULL);
+    hemf = CloseEnhMetaFile(hdc);
+
+    /* Set the initial image to differ the errors */
+    style = GetWindowLongA(hwnd, GWL_STYLE);
+    SetWindowLongA(hwnd, GWL_STYLE, style | SS_BITMAP);
+    SendMessageA(hwnd, STM_SETIMAGE, (WPARAM)IMAGE_BITMAP, (LPARAM)hbm);
+
+    /* Check the initial image */
+    res = SendMessageA(hwnd, STM_SETIMAGE, (WPARAM)IMAGE_BITMAP, (LPARAM)hbm);
+    ok(res == (LRESULT)hbm, "expected %p got 0x%lx\n", hbm, res);
+
+    SetWindowLongA(hwnd, GWL_STYLE, style);
+
+    flush_sequence();
+    res = SendMessageA(hwnd, STM_SETIMAGE, (WPARAM)IMAGE_BITMAP, (LPARAM)hbm);
+    ok(!res, "expected NULL got 0x%lx\n", res);
+    todo_wine ok_sequence(WmSetImageErrStaticSeq, "STM_SETIMAGE on a static", FALSE);
+
+    flush_sequence();
+    res = SendMessageA(hwnd, STM_SETIMAGE, (WPARAM)IMAGE_ICON, (LPARAM)hicon);
+    ok(!res, "expected NULL got 0x%lx\n", res);
+    todo_wine ok_sequence(WmSetImageErrStaticSeq, "STM_SETIMAGE on a static", FALSE);
+
+    flush_sequence();
+    res = SendMessageA(hwnd, STM_SETICON, (WPARAM)hicon, 0);
+    ok(!res, "expected NULL got 0x%lx\n", res);
+    todo_wine ok_sequence(WmSetIconErrStaticSeq, "STM_SETICON on a static", FALSE);
+
+    flush_sequence();    style = GetWindowLongA(hwnd, GWL_STYLE);
+    res = SendMessageA(hwnd, STM_SETIMAGE, (WPARAM)IMAGE_ENHMETAFILE, (LPARAM)hemf);
+    ok(!res, "expected NULL got 0x%lx\n", res);
+    todo_wine ok_sequence(WmSetImageErrStaticSeq, "STM_SETIMAGE on a static", FALSE);
+
+    SetWindowLongA(hwnd, GWL_STYLE, style | SS_BITMAP);
+
+    flush_sequence();
+    res = SendMessageA(hwnd, STM_SETIMAGE, (WPARAM)IMAGE_BITMAP, (LPARAM)hbm);
+    ok(res, "expected not NULL got NULL\n");
+    todo_wine ok_sequence(WmSetImageOkStaticSeq, "STM_SETIMAGE on a static", FALSE);
+
+    SetWindowLongA(hwnd, GWL_STYLE, style | SS_ICON);
+
+    flush_sequence();
+    res = SendMessageA(hwnd, STM_SETIMAGE, (WPARAM)IMAGE_ICON, (LPARAM)hicon);
+    ok(res, "expected not NULL got NULL\n");
+    todo_wine ok_sequence(WmSetImageOkStaticSeq, "STM_SETIMAGE on a static", FALSE);
+
+    flush_sequence();
+    res = SendMessageA(hwnd, STM_SETICON, (WPARAM)hicon, 0);
+    ok(res, "expected not NULL got NULL\n");
+    ok_sequence(WmSetIconOkStaticSeq, "STM_SETICON on a static", FALSE);
+
+    SetWindowLongA(hwnd, GWL_STYLE, style | SS_ENHMETAFILE);
+
+    flush_sequence();
+    res = SendMessageA(hwnd, STM_SETIMAGE, (WPARAM)IMAGE_ENHMETAFILE, (LPARAM)hemf);
+    ok(res, "expected not NULL got NULL\n");
+    todo_wine ok_sequence(WmSetImageOkStaticSeq, "STM_SETIMAGE on a static", FALSE);
+
+    DeleteEnhMetaFile(hemf);
+    DeleteObject(hicon);
+    DeleteObject(hbm);
+    DeleteDC(hdc);
+    DestroyWindow(hwnd);
 }
 
 /****************** ComboBox message test *************************/
-- 
1.6.4.2


