msi: Handle remote calls to MsiProcessMessage.
[wine] / dlls / user32 / tests / combo.c
1 /* Unit test suite for combo boxes.
2  *
3  * Copyright 2007 Mikolaj Zalewski
4  *
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.
9  *
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.
14  *
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
18  */
19
20 #include <assert.h>
21 #include <stdarg.h>
22 #include <stdio.h>
23
24 #define WIN32_LEAN_AND_MEAN
25 #include <windows.h>
26
27 #include "wine/test.h"
28
29 HWND hMainWnd;
30
31 #define expect_eq(expr, value, type, fmt); { type val = expr; ok(val == (value), #expr " expected " #fmt " got " #fmt "\n", (value), val); }
32 #define expect_rect(r, _left, _top, _right, _bottom) ok(r.left == _left && r.top == _top && \
33     r.bottom == _bottom && r.right == _right, "Invalid rect (%d,%d) (%d,%d) vs (%d,%d) (%d,%d)\n", \
34     r.left, r.top, r.right, r.bottom, _left, _top, _right, _bottom);
35
36 static HWND build_combo(DWORD style)
37 {
38     return CreateWindow("ComboBox", "Combo", WS_VISIBLE|WS_CHILD|style, 5, 5, 100, 100, hMainWnd, NULL, NULL, 0);
39 }
40
41 static int font_height(HFONT hFont)
42 {
43     TEXTMETRIC tm;
44     HFONT hFontOld;
45     HDC hDC;
46
47     hDC = CreateCompatibleDC(NULL);
48     hFontOld = SelectObject(hDC, hFont);
49     GetTextMetrics(hDC, &tm);
50     SelectObject(hDC, hFontOld);
51     DeleteDC(hDC);
52
53     return tm.tmHeight;
54 }
55
56 static INT CALLBACK is_font_installed_proc(const LOGFONT *elf, const TEXTMETRIC *tm, DWORD type, LPARAM lParam)
57 {
58     return 0;
59 }
60
61 static int is_font_installed(const char *name)
62 {
63     HDC hdc = GetDC(NULL);
64     BOOL ret = !EnumFontFamilies(hdc, name, is_font_installed_proc, 0);
65     ReleaseDC(NULL, hdc);
66     return ret;
67 }
68
69 static void test_setfont(DWORD style)
70 {
71     HWND hCombo = build_combo(style);
72     HFONT hFont1 = CreateFont(10, 0, 0, 0, FW_DONTCARE, FALSE, FALSE, FALSE, ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH|FF_DONTCARE, "Marlett");
73     HFONT hFont2 = CreateFont(8, 0, 0, 0, FW_DONTCARE, FALSE, FALSE, FALSE, ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH|FF_DONTCARE, "Marlett");
74     RECT r;
75     int i;
76
77     trace("Style %x\n", style);
78     GetClientRect(hCombo, &r);
79     expect_rect(r, 0, 0, 100, 24);
80     SendMessageA(hCombo, CB_GETDROPPEDCONTROLRECT, 0, (LPARAM)&r);
81     MapWindowPoints(HWND_DESKTOP, hMainWnd, (LPPOINT)&r, 2);
82     todo_wine expect_rect(r, 5, 5, 105, 105);
83
84     if (!is_font_installed("Marlett"))
85     {
86         skip("Marlett font not available\n");
87         return;
88     }
89
90     if (font_height(hFont1) == 10 && font_height(hFont2) == 8)
91     {
92         SendMessage(hCombo, WM_SETFONT, (WPARAM)hFont1, FALSE);
93         GetClientRect(hCombo, &r);
94         expect_rect(r, 0, 0, 100, 18);
95         SendMessageA(hCombo, CB_GETDROPPEDCONTROLRECT, 0, (LPARAM)&r);
96         MapWindowPoints(HWND_DESKTOP, hMainWnd, (LPPOINT)&r, 2);
97         todo_wine expect_rect(r, 5, 5, 105, 99);
98
99         SendMessage(hCombo, WM_SETFONT, (WPARAM)hFont2, FALSE);
100         GetClientRect(hCombo, &r);
101         expect_rect(r, 0, 0, 100, 16);
102         SendMessageA(hCombo, CB_GETDROPPEDCONTROLRECT, 0, (LPARAM)&r);
103         MapWindowPoints(HWND_DESKTOP, hMainWnd, (LPPOINT)&r, 2);
104         todo_wine expect_rect(r, 5, 5, 105, 97);
105
106         SendMessage(hCombo, WM_SETFONT, (WPARAM)hFont1, FALSE);
107         GetClientRect(hCombo, &r);
108         expect_rect(r, 0, 0, 100, 18);
109         SendMessageA(hCombo, CB_GETDROPPEDCONTROLRECT, 0, (LPARAM)&r);
110         MapWindowPoints(HWND_DESKTOP, hMainWnd, (LPPOINT)&r, 2);
111         todo_wine expect_rect(r, 5, 5, 105, 99);
112     }
113     else
114         skip("Invalid Marlett font heights\n");
115
116     for (i = 1; i < 30; i++)
117     {
118         HFONT hFont = CreateFont(i, 0, 0, 0, FW_DONTCARE, FALSE, FALSE, FALSE, ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH|FF_DONTCARE, "Marlett");
119         int height = font_height(hFont);
120
121         SendMessage(hCombo, WM_SETFONT, (WPARAM)hFont, FALSE);
122         GetClientRect(hCombo, &r);
123         expect_eq(r.bottom - r.top, height + 8, int, "%d");
124         SendMessage(hCombo, WM_SETFONT, 0, FALSE);
125         DeleteObject(hFont);
126     }
127
128     DestroyWindow(hCombo);
129     DeleteObject(hFont1);
130     DeleteObject(hFont2);
131 }
132
133 START_TEST(combo)
134 {
135     hMainWnd = CreateWindow("static", "Test", WS_OVERLAPPEDWINDOW, 10, 10, 300, 300, NULL, NULL, NULL, 0);
136     ShowWindow(hMainWnd, SW_SHOW);
137
138     test_setfont(CBS_DROPDOWN);
139     test_setfont(CBS_DROPDOWNLIST);
140     DestroyWindow(hMainWnd);
141 }