Const correctness fixes.
[wine/multimedia.git] / dlls / gdi / tests / metafile.c
blobefc6aa7ed09f64def7b1605f05e6661e2d42a18d
1 /*
2 * Unit tests for metafile functions
4 * Copyright (c) 2002 Dmitry Timoshkov
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.
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.
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
21 #include <assert.h>
23 #include "wine/test.h"
24 #include "winbase.h"
25 #include "wingdi.h"
26 #include "winuser.h"
27 #include "winerror.h"
29 static LOGFONTA orig_lf;
30 static BOOL emr_processed = FALSE;
32 static int CALLBACK emf_enum_proc(HDC hdc, HANDLETABLE *handle_table,
33 const ENHMETARECORD *emr, int n_objs, LPARAM param)
35 static int n_record;
36 DWORD i;
37 const INT *dx;
38 INT *orig_dx = (INT *)param;
39 LOGFONTA device_lf;
41 trace("hdc %p, emr->iType %ld, emr->nSize %ld, param %p\n",
42 hdc, emr->iType, emr->nSize, (void *)param);
44 PlayEnhMetaFileRecord(hdc, handle_table, emr, n_objs);
46 switch (emr->iType)
48 case EMR_HEADER:
49 n_record = 0;
50 break;
52 case EMR_EXTTEXTOUTA:
54 const EMREXTTEXTOUTA *emr_ExtTextOutA = (const EMREXTTEXTOUTA *)emr;
55 dx = (const INT *)((const char *)emr + emr_ExtTextOutA->emrtext.offDx);
57 ok(GetObjectA(GetCurrentObject(hdc, OBJ_FONT), sizeof(device_lf), &device_lf) == sizeof(device_lf),
58 "GetObjectA error %ld\n", GetLastError());
60 /* compare up to lfOutPrecision, other values are not interesting,
61 * and in fact sometimes arbitrary adapted by Win9x.
63 ok(!memcmp(&orig_lf, &device_lf, FIELD_OFFSET(LOGFONTA, lfOutPrecision)), "fonts don't match\n");
64 ok(!lstrcmpA(orig_lf.lfFaceName, device_lf.lfFaceName), "font names don't match\n");
66 for(i = 0; i < emr_ExtTextOutA->emrtext.nChars; i++)
68 ok(orig_dx[i] == dx[i], "pass %d: dx[%ld] (%d) didn't match %d\n",
69 n_record, i, dx[i], orig_dx[i]);
71 n_record++;
72 emr_processed = TRUE;
73 break;
76 case EMR_EXTTEXTOUTW:
78 const EMREXTTEXTOUTW *emr_ExtTextOutW = (const EMREXTTEXTOUTW *)emr;
79 dx = (const INT *)((const char *)emr + emr_ExtTextOutW->emrtext.offDx);
81 ok(GetObjectA(GetCurrentObject(hdc, OBJ_FONT), sizeof(device_lf), &device_lf) == sizeof(device_lf),
82 "GetObjectA error %ld\n", GetLastError());
84 /* compare up to lfOutPrecision, other values are not interesting,
85 * and in fact sometimes arbitrary adapted by Win9x.
87 ok(!memcmp(&orig_lf, &device_lf, FIELD_OFFSET(LOGFONTA, lfOutPrecision)), "fonts don't match\n");
88 ok(!lstrcmpA(orig_lf.lfFaceName, device_lf.lfFaceName), "font names don't match\n");
90 for(i = 0; i < emr_ExtTextOutW->emrtext.nChars; i++)
92 ok(orig_dx[i] == dx[i], "pass %d: dx[%ld] (%d) didn't match %d\n",
93 n_record, i, dx[i], orig_dx[i]);
95 n_record++;
96 emr_processed = TRUE;
97 break;
100 default:
101 break;
104 return 1;
107 static void test_ExtTextOut(void)
109 HWND hwnd;
110 HDC hdcDisplay, hdcMetafile;
111 HENHMETAFILE hMetafile;
112 HFONT hFont;
113 static const char text[] = "Simple text to test ExtTextOut on metafiles";
114 INT i, len, dx[256];
115 static const RECT rc = { 0, 0, 100, 100 };
117 assert(sizeof(dx)/sizeof(dx[0]) >= lstrlenA(text));
119 /* Win9x doesn't play EMFs on invisible windows */
120 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP | WS_VISIBLE,
121 0, 0, 200, 200, 0, 0, 0, NULL);
122 ok(hwnd != 0, "CreateWindowExA error %ld\n", GetLastError());
124 hdcDisplay = GetDC(hwnd);
125 ok(hdcDisplay != 0, "GetDC error %ld\n", GetLastError());
127 trace("hdcDisplay %p\n", hdcDisplay);
129 SetMapMode(hdcDisplay, MM_TEXT);
131 memset(&orig_lf, 0, sizeof(orig_lf));
133 orig_lf.lfCharSet = ANSI_CHARSET;
134 orig_lf.lfClipPrecision = CLIP_DEFAULT_PRECIS;
135 orig_lf.lfWeight = FW_DONTCARE;
136 orig_lf.lfHeight = 7;
137 orig_lf.lfQuality = DEFAULT_QUALITY;
138 lstrcpyA(orig_lf.lfFaceName, "Arial");
139 hFont = CreateFontIndirectA(&orig_lf);
140 ok(hFont != 0, "CreateFontIndirectA error %ld\n", GetLastError());
142 hFont = SelectObject(hdcDisplay, hFont);
144 len = lstrlenA(text);
145 for (i = 0; i < len; i++)
147 ok(GetCharWidthA(hdcDisplay, text[i], text[i], &dx[i]),
148 "GetCharWidthA error %ld\n", GetLastError());
150 hFont = SelectObject(hdcDisplay, hFont);
152 hdcMetafile = CreateEnhMetaFileA(hdcDisplay, NULL, NULL, NULL);
153 ok(hdcMetafile != 0, "CreateEnhMetaFileA error %ld\n", GetLastError());
155 trace("hdcMetafile %p\n", hdcMetafile);
157 ok(GetDeviceCaps(hdcMetafile, TECHNOLOGY) == DT_RASDISPLAY,
158 "GetDeviceCaps(TECHNOLOGY) has to return DT_RASDISPLAY for a display based EMF\n");
160 hFont = SelectObject(hdcMetafile, hFont);
162 /* 1. pass NULL lpDx */
163 ok(ExtTextOutA(hdcMetafile, 0, 0, 0, &rc, text, lstrlenA(text), NULL),
164 "ExtTextOutA error %ld\n", GetLastError());
166 /* 2. pass custom lpDx */
167 ok(ExtTextOutA(hdcMetafile, 0, 20, 0, &rc, text, lstrlenA(text), dx),
168 "ExtTextOutA error %ld\n", GetLastError());
170 hFont = SelectObject(hdcMetafile, hFont);
171 ok(DeleteObject(hFont), "DeleteObject error %ld\n", GetLastError());
173 hMetafile = CloseEnhMetaFile(hdcMetafile);
174 ok(hMetafile != 0, "CloseEnhMetaFile error %ld\n", GetLastError());
176 ok(!GetObjectType(hdcMetafile), "CloseEnhMetaFile has to destroy metafile hdc\n");
178 ok(PlayEnhMetaFile(hdcDisplay, hMetafile, &rc), "PlayEnhMetaFile error %ld\n", GetLastError());
180 ok(EnumEnhMetaFile(hdcDisplay, hMetafile, emf_enum_proc, dx, &rc),
181 "EnumEnhMetaFile error %ld\n", GetLastError());
183 ok(emr_processed, "EnumEnhMetaFile couldn't find EMR_EXTTEXTOUTA or EMR_EXTTEXTOUTW record\n");
185 ok(!EnumEnhMetaFile(hdcDisplay, hMetafile, emf_enum_proc, dx, NULL),
186 "A valid hdc has to require a valid rc\n");
188 ok(DeleteEnhMetaFile(hMetafile), "DeleteEnhMetaFile error %ld\n", GetLastError());
189 ok(ReleaseDC(hwnd, hdcDisplay), "ReleaseDC error %ld\n", GetLastError());
192 START_TEST(metafile)
194 test_ExtTextOut();