Removed W->A from DEFWND_ImmIsUIMessageW.
[wine] / dlls / gdi / tests / gdiobj.c
1 /*
2  * Unit test suite for GDI objects
3  *
4  * Copyright 2002 Mike McCormack
5  * Copyright 2004 Dmitry Timoshkov
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20  */
21
22 #include <stdarg.h>
23 #include <assert.h>
24
25 #include "windef.h"
26 #include "winbase.h"
27 #include "wingdi.h"
28 #include "winuser.h"
29
30 #include "wine/test.h"
31
32 static void test_logfont(void)
33 {
34     LOGFONTA lf, lfout;
35     HFONT hfont;
36
37     memset(&lf, 0, sizeof lf);
38
39     lf.lfCharSet = ANSI_CHARSET;
40     lf.lfClipPrecision = CLIP_DEFAULT_PRECIS;
41     lf.lfWeight = FW_DONTCARE;
42     lf.lfHeight = 16;
43     lf.lfWidth = 16;
44     lf.lfQuality = DEFAULT_QUALITY;
45     lstrcpyA(lf.lfFaceName, "Arial");
46
47     hfont = CreateFontIndirectA(&lf);
48     ok(hfont != 0, "CreateFontIndirect failed\n");
49
50     ok(GetObjectA(hfont, sizeof(lfout), &lfout) == sizeof(lfout),
51        "GetObject returned wrong size\n");
52
53     ok(!memcmp(&lfout, &lf, FIELD_OFFSET(LOGFONTA, lfFaceName)), "fonts don't match\n");
54     ok(!lstrcmpA(lfout.lfFaceName, lf.lfFaceName),
55        "font names don't match: %s != %s\n", lfout.lfFaceName, lf.lfFaceName);
56
57     DeleteObject(hfont);
58
59     memset(&lf, 'A', sizeof(lf));
60     hfont = CreateFontIndirectA(&lf);
61     ok(hfont != 0, "CreateFontIndirectA with strange LOGFONT failed\n");
62
63     ok(GetObjectA(hfont, sizeof(lfout), NULL) == sizeof(lfout),
64        "GetObjectA with NULL failed\n");
65
66     ok(GetObjectA(hfont, sizeof(lfout), &lfout) == sizeof(lfout),
67        "GetObjectA failed\n");
68     ok(!memcmp(&lfout, &lf, FIELD_OFFSET(LOGFONTA, lfFaceName)), "fonts don't match\n");
69     lf.lfFaceName[LF_FACESIZE - 1] = 0;
70     ok(!lstrcmpA(lfout.lfFaceName, lf.lfFaceName),
71        "font names don't match: %s != %s\n", lfout.lfFaceName, lf.lfFaceName);
72
73     DeleteObject(hfont);
74 }
75
76 static INT CALLBACK font_enum_proc(const LOGFONT *elf, const TEXTMETRIC *ntm, DWORD type, LPARAM lParam)
77 {
78     if (type & RASTER_FONTTYPE)
79     {
80         LOGFONT *lf = (LOGFONT *)lParam;
81         *lf = *elf;
82         return 0; /* stop enumeration */
83     }
84
85     return 1; /* continue enumeration */
86 }
87
88 static void test_font_metrics(HDC hdc, HFONT hfont, const char *test_str,
89                               INT test_str_len, const TEXTMETRICA *tm_orig,
90                               const SIZE *size_orig, INT width_orig,
91                               INT scale_x, INT scale_y)
92 {
93     HFONT old_hfont;
94     TEXTMETRICA tm;
95     SIZE size;
96     INT width;
97
98     old_hfont = SelectObject(hdc, hfont);
99
100     GetTextMetricsA(hdc, &tm);
101
102     ok(tm.tmHeight == tm_orig->tmHeight * scale_y, "%ld != %ld\n", tm.tmHeight, tm_orig->tmHeight * scale_y);
103     ok(tm.tmAscent == tm_orig->tmAscent * scale_y, "%ld != %ld\n", tm.tmAscent, tm_orig->tmAscent * scale_y);
104     ok(tm.tmDescent == tm_orig->tmDescent * scale_y, "%ld != %ld\n", tm.tmDescent, tm_orig->tmDescent * scale_y);
105     ok(tm.tmAveCharWidth == tm_orig->tmAveCharWidth * scale_x, "%ld != %ld\n", tm.tmAveCharWidth, tm_orig->tmAveCharWidth * scale_x);
106
107     GetTextExtentPoint32A(hdc, test_str, test_str_len, &size);
108
109     ok(size.cx == size_orig->cx * scale_x, "%ld != %ld\n", size.cx, size_orig->cx * scale_x);
110     ok(size.cy == size_orig->cy * scale_y, "%ld != %ld\n", size.cy, size_orig->cy * scale_y);
111
112     GetCharWidthA(hdc, 'A', 'A', &width);
113
114     ok(width == width_orig * scale_x, "%d != %d\n", width, width_orig * scale_x);
115
116     SelectObject(hdc, old_hfont);
117 }
118
119 /* see whether GDI scales bitmap font metrics */
120 static void test_bitmap_font(void)
121 {
122     static const char test_str[11] = "Test String";
123     HDC hdc;
124     LOGFONTA bitmap_lf, lf;
125     HFONT hfont, old_hfont;
126     TEXTMETRICA tm_orig;
127     SIZE size_orig;
128     INT ret, i, width_orig, height_orig;
129
130     hdc = GetDC(0);
131
132     /* "System" has only 1 pixel size defined, otherwise the test breaks */
133     ret = EnumFontFamiliesA(hdc, "System", font_enum_proc, (LPARAM)&bitmap_lf);
134     if (ret)
135     {
136         ReleaseDC(0, hdc);
137         trace("no bitmap fonts were found, skipping the test\n");
138         return;
139     }
140
141     trace("found bitmap font %s, height %ld\n", bitmap_lf.lfFaceName, bitmap_lf.lfHeight);
142
143     height_orig = bitmap_lf.lfHeight;
144     hfont = CreateFontIndirectA(&bitmap_lf);
145     assert(hfont);
146
147     old_hfont = SelectObject(hdc, hfont);
148     ok(GetTextMetricsA(hdc, &tm_orig), "GetTextMetricsA failed\n");
149     ok(GetTextExtentPoint32A(hdc, test_str, sizeof(test_str), &size_orig), "GetTextExtentPoint32A failed\n");
150     ok(GetCharWidthA(hdc, 'A', 'A', &width_orig), "GetCharWidthA failed\n");
151     SelectObject(hdc, old_hfont);
152     DeleteObject(hfont);
153
154     /* test fractional scaling */
155     for (i = 1; i < height_orig; i++)
156     {
157         bitmap_lf.lfHeight = i;
158         hfont = CreateFontIndirectA(&bitmap_lf);
159         assert(hfont);
160
161         ret = GetObject(hfont, sizeof(lf), &lf);
162         ok(ret == sizeof(lf), "GetObject failed: %d\n", ret);
163         ok(!memcmp(&bitmap_lf, &lf, FIELD_OFFSET(LOGFONTA, lfFaceName)), "fonts don't match\n");
164         ok(!lstrcmpA(bitmap_lf.lfFaceName, lf.lfFaceName),
165            "font names don't match: %s != %s\n", bitmap_lf.lfFaceName, lf.lfFaceName);
166
167         test_font_metrics(hdc, hfont, test_str, sizeof(test_str), &tm_orig, &size_orig, width_orig, 1, 1);
168         DeleteObject(hfont);
169     }
170
171     /* test integer scaling 3x2 */
172     bitmap_lf.lfHeight = height_orig * 2;
173     bitmap_lf.lfWidth *= 3;
174     hfont = CreateFontIndirectA(&bitmap_lf);
175     assert(hfont);
176
177     ret = GetObject(hfont, sizeof(lf), &lf);
178     ok(ret == sizeof(lf), "GetObject failed: %d\n", ret);
179     ok(!memcmp(&bitmap_lf, &lf, FIELD_OFFSET(LOGFONTA, lfFaceName)), "fonts don't match\n");
180     ok(!lstrcmpA(bitmap_lf.lfFaceName, lf.lfFaceName),
181        "font names don't match: %s != %s\n", bitmap_lf.lfFaceName, lf.lfFaceName);
182 todo_wine
183 {
184     test_font_metrics(hdc, hfont, test_str, sizeof(test_str), &tm_orig, &size_orig, width_orig, 3, 2);
185 }
186     DeleteObject(hfont);
187
188     /* test integer scaling 3x3 */
189     bitmap_lf.lfHeight = height_orig * 3;
190     bitmap_lf.lfWidth = 0;
191     hfont = CreateFontIndirectA(&bitmap_lf);
192     assert(hfont);
193
194     ret = GetObject(hfont, sizeof(lf), &lf);
195     ok(ret == sizeof(lf), "GetObject failed: %d\n", ret);
196     ok(!memcmp(&bitmap_lf, &lf, FIELD_OFFSET(LOGFONTA, lfFaceName)), "fonts don't match\n");
197     ok(!lstrcmpA(bitmap_lf.lfFaceName, lf.lfFaceName),
198        "font names don't match: %s != %s\n", bitmap_lf.lfFaceName, lf.lfFaceName);
199 todo_wine
200 {
201     test_font_metrics(hdc, hfont, test_str, sizeof(test_str), &tm_orig, &size_orig, width_orig, 3, 3);
202 }
203     DeleteObject(hfont);
204
205     ReleaseDC(0, hdc);
206 }
207
208 START_TEST(gdiobj)
209 {
210     test_logfont();
211     test_bitmap_font();
212 }