Removed W->A from DEFWND_ImmIsUIMessageW.
[wine] / dlls / gdi / tests / metafile.c
1 /*
2  * Unit tests for metafile functions
3  *
4  * Copyright (c) 2002 Dmitry Timoshkov
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  */
20
21 #include <assert.h>
22
23 #include "wine/test.h"
24 #include "winbase.h"
25 #include "wingdi.h"
26 #include "winuser.h"
27 #include "winerror.h"
28
29 static LOGFONTA orig_lf;
30 static BOOL emr_processed = FALSE;
31
32 static int CALLBACK emf_enum_proc(HDC hdc, HANDLETABLE *handle_table,
33     const ENHMETARECORD *emr, int n_objs, LPARAM param)
34 {
35     static int n_record;
36     DWORD i;
37     INT *dx, *orig_dx = (INT *)param;
38     LOGFONTA device_lf;
39
40     trace("hdc %p, emr->iType %ld, emr->nSize %ld, param %p\n",
41            hdc, emr->iType, emr->nSize, (void *)param);
42
43     PlayEnhMetaFileRecord(hdc, handle_table, emr, n_objs);
44
45     switch (emr->iType)
46     {
47     case EMR_HEADER:
48         n_record = 0;
49         break;
50
51     case EMR_EXTTEXTOUTA:
52     {
53         EMREXTTEXTOUTA *emr_ExtTextOutA = (EMREXTTEXTOUTA *)emr;
54         dx = (INT *)((char *)emr + emr_ExtTextOutA->emrtext.offDx);
55
56         ok(GetObjectA(GetCurrentObject(hdc, OBJ_FONT), sizeof(device_lf), &device_lf) == sizeof(device_lf),
57            "GetObjectA error %ld\n", GetLastError());
58
59         /* compare up to lfOutPrecision, other values are not interesting,
60          * and in fact sometimes arbitrary adapted by Win9x.
61          */
62         ok(!memcmp(&orig_lf, &device_lf, FIELD_OFFSET(LOGFONTA, lfOutPrecision)), "fonts don't match\n");
63         ok(!lstrcmpA(orig_lf.lfFaceName, device_lf.lfFaceName), "font names don't match\n");
64
65         for(i = 0; i < emr_ExtTextOutA->emrtext.nChars; i++)
66         {
67             ok(orig_dx[i] == dx[i], "pass %d: dx[%ld] (%d) didn't match %d\n",
68                                      n_record, i, dx[i], orig_dx[i]);
69         }
70         n_record++;
71         emr_processed = TRUE;
72         break;
73     }
74
75     case EMR_EXTTEXTOUTW:
76     {
77         EMREXTTEXTOUTW *emr_ExtTextOutW = (EMREXTTEXTOUTW *)emr;
78         dx = (INT *)((char *)emr + emr_ExtTextOutW->emrtext.offDx);
79
80         ok(GetObjectA(GetCurrentObject(hdc, OBJ_FONT), sizeof(device_lf), &device_lf) == sizeof(device_lf),
81            "GetObjectA error %ld\n", GetLastError());
82
83         /* compare up to lfOutPrecision, other values are not interesting,
84          * and in fact sometimes arbitrary adapted by Win9x.
85          */
86         ok(!memcmp(&orig_lf, &device_lf, FIELD_OFFSET(LOGFONTA, lfOutPrecision)), "fonts don't match\n");
87         ok(!lstrcmpA(orig_lf.lfFaceName, device_lf.lfFaceName), "font names don't match\n");
88
89         for(i = 0; i < emr_ExtTextOutW->emrtext.nChars; i++)
90         {
91             ok(orig_dx[i] == dx[i], "pass %d: dx[%ld] (%d) didn't match %d\n",
92                                      n_record, i, dx[i], orig_dx[i]);
93         }
94         n_record++;
95         emr_processed = TRUE;
96         break;
97     }
98
99     default:
100         break;
101     }
102
103     return 1;
104 }
105
106 static void test_ExtTextOut(void)
107 {
108     HWND hwnd;
109     HDC hdcDisplay, hdcMetafile;
110     HENHMETAFILE hMetafile;
111     HFONT hFont;
112     static const char text[] = "Simple text to test ExtTextOut on metafiles";
113     INT i, len, dx[256];
114     static const RECT rc = { 0, 0, 100, 100 };
115
116     assert(sizeof(dx)/sizeof(dx[0]) >= lstrlenA(text));
117
118     /* Win9x doesn't play EMFs on invisible windows */
119     hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP | WS_VISIBLE,
120                            0, 0, 200, 200, 0, 0, 0, NULL);
121     ok(hwnd != 0, "CreateWindowExA error %ld\n", GetLastError());
122
123     hdcDisplay = GetDC(hwnd);
124     ok(hdcDisplay != 0, "GetDC error %ld\n", GetLastError());
125
126     trace("hdcDisplay %p\n", hdcDisplay);
127
128     SetMapMode(hdcDisplay, MM_TEXT);
129
130     memset(&orig_lf, 0, sizeof(orig_lf));
131
132     orig_lf.lfCharSet = ANSI_CHARSET;
133     orig_lf.lfClipPrecision = CLIP_DEFAULT_PRECIS;
134     orig_lf.lfWeight = FW_DONTCARE;
135     orig_lf.lfHeight = 7;
136     orig_lf.lfQuality = DEFAULT_QUALITY;
137     lstrcpyA(orig_lf.lfFaceName, "Arial");
138     hFont = CreateFontIndirectA(&orig_lf);
139     ok(hFont != 0, "CreateFontIndirectA error %ld\n", GetLastError());
140
141     hFont = SelectObject(hdcDisplay, hFont);
142
143     len = lstrlenA(text);
144     for (i = 0; i < len; i++)
145     {
146         ok(GetCharWidthA(hdcDisplay, text[i], text[i], &dx[i]),
147            "GetCharWidthA error %ld\n", GetLastError());
148     }
149     hFont = SelectObject(hdcDisplay, hFont);
150
151     hdcMetafile = CreateEnhMetaFileA(hdcDisplay, NULL, NULL, NULL);
152     ok(hdcMetafile != 0, "CreateEnhMetaFileA error %ld\n", GetLastError());
153
154     trace("hdcMetafile %p\n", hdcMetafile);
155
156     ok(GetDeviceCaps(hdcMetafile, TECHNOLOGY) == DT_RASDISPLAY,
157        "GetDeviceCaps(TECHNOLOGY) has to return DT_RASDISPLAY for a display based EMF\n");
158
159     hFont = SelectObject(hdcMetafile, hFont);
160
161     /* 1. pass NULL lpDx */
162     ok(ExtTextOutA(hdcMetafile, 0, 0, 0, &rc, text, lstrlenA(text), NULL),
163        "ExtTextOutA error %ld\n", GetLastError());
164
165     /* 2. pass custom lpDx */
166     ok(ExtTextOutA(hdcMetafile, 0, 20, 0, &rc, text, lstrlenA(text), dx),
167        "ExtTextOutA error %ld\n", GetLastError());
168
169     hFont = SelectObject(hdcMetafile, hFont);
170     ok(DeleteObject(hFont), "DeleteObject error %ld\n", GetLastError());
171
172     hMetafile = CloseEnhMetaFile(hdcMetafile);
173     ok(hMetafile != 0, "CloseEnhMetaFile error %ld\n", GetLastError());
174
175     ok(!GetObjectType(hdcMetafile), "CloseEnhMetaFile has to destroy metafile hdc\n");
176
177     ok(PlayEnhMetaFile(hdcDisplay, hMetafile, &rc), "PlayEnhMetaFile error %ld\n", GetLastError());
178
179     ok(EnumEnhMetaFile(hdcDisplay, hMetafile, emf_enum_proc, dx, &rc),
180        "EnumEnhMetaFile error %ld\n", GetLastError());
181
182     ok(emr_processed, "EnumEnhMetaFile couldn't find EMR_EXTTEXTOUTA or EMR_EXTTEXTOUTW record\n");
183
184     ok(!EnumEnhMetaFile(hdcDisplay, hMetafile, emf_enum_proc, dx, NULL),
185        "A valid hdc has to require a valid rc\n");
186
187     ok(DeleteEnhMetaFile(hMetafile), "DeleteEnhMetaFile error %ld\n", GetLastError());
188     ok(ReleaseDC(hwnd, hdcDisplay), "ReleaseDC error %ld\n", GetLastError());
189 }
190
191 START_TEST(metafile)
192 {
193     test_ExtTextOut();
194 }