Output BEGIN/END_INTERFACE for C++ base classes too.
[wine/multimedia.git] / dlls / gdi / tests / metafile.c
blobb3dda3d132c3c7582ec9bdf0cafaec6769d8e394
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 INT *dx, *orig_dx = (INT *)param;
38 LOGFONTA device_lf;
40 trace("hdc %p, emr->iType %ld, emr->nSize %ld, param %p\n",
41 hdc, emr->iType, emr->nSize, (void *)param);
43 PlayEnhMetaFileRecord(hdc, handle_table, emr, n_objs);
45 switch (emr->iType)
47 case EMR_HEADER:
48 n_record = 0;
49 break;
51 case EMR_EXTTEXTOUTA:
53 EMREXTTEXTOUTA *emr_ExtTextOutA = (EMREXTTEXTOUTA *)emr;
54 dx = (INT *)((char *)emr + emr_ExtTextOutA->emrtext.offDx);
56 ok(GetObjectA(GetCurrentObject(hdc, OBJ_FONT), sizeof(device_lf), &device_lf) == sizeof(device_lf),
57 "GetObjectA error %ld\n", GetLastError());
59 /* compare up to lfOutPrecision, other values are not interesting,
60 * and in fact sometimes arbitrary adapted by Win9x.
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");
65 for(i = 0; i < emr_ExtTextOutA->emrtext.nChars; i++)
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]);
70 n_record++;
71 emr_processed = TRUE;
72 break;
75 case EMR_EXTTEXTOUTW:
77 EMREXTTEXTOUTW *emr_ExtTextOutW = (EMREXTTEXTOUTW *)emr;
78 dx = (INT *)((char *)emr + emr_ExtTextOutW->emrtext.offDx);
80 ok(GetObjectA(GetCurrentObject(hdc, OBJ_FONT), sizeof(device_lf), &device_lf) == sizeof(device_lf),
81 "GetObjectA error %ld\n", GetLastError());
83 /* compare up to lfOutPrecision, other values are not interesting,
84 * and in fact sometimes arbitrary adapted by Win9x.
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");
89 for(i = 0; i < emr_ExtTextOutW->emrtext.nChars; i++)
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]);
94 n_record++;
95 emr_processed = TRUE;
96 break;
99 default:
100 break;
103 return 1;
106 static void test_ExtTextOut(void)
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 };
116 assert(sizeof(dx)/sizeof(dx[0]) >= lstrlenA(text));
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());
123 hdcDisplay = GetDC(hwnd);
124 ok(hdcDisplay != 0, "GetDC error %ld\n", GetLastError());
126 trace("hdcDisplay %p\n", hdcDisplay);
128 SetMapMode(hdcDisplay, MM_TEXT);
130 memset(&orig_lf, 0, sizeof(orig_lf));
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());
141 hFont = SelectObject(hdcDisplay, hFont);
143 len = lstrlenA(text);
144 for (i = 0; i < len; i++)
146 ok(GetCharWidthA(hdcDisplay, text[i], text[i], &dx[i]),
147 "GetCharWidthA error %ld\n", GetLastError());
149 hFont = SelectObject(hdcDisplay, hFont);
151 hdcMetafile = CreateEnhMetaFileA(hdcDisplay, NULL, NULL, NULL);
152 ok(hdcMetafile != 0, "CreateEnhMetaFileA error %ld\n", GetLastError());
154 trace("hdcMetafile %p\n", hdcMetafile);
156 ok(GetDeviceCaps(hdcMetafile, TECHNOLOGY) == DT_RASDISPLAY,
157 "GetDeviceCaps(TECHNOLOGY) has to return DT_RASDISPLAY for a display based EMF\n");
159 hFont = SelectObject(hdcMetafile, hFont);
161 /* 1. pass NULL lpDx */
162 ok(ExtTextOutA(hdcMetafile, 0, 0, 0, &rc, text, lstrlenA(text), NULL),
163 "ExtTextOutA error %ld\n", GetLastError());
165 /* 2. pass custom lpDx */
166 ok(ExtTextOutA(hdcMetafile, 0, 20, 0, &rc, text, lstrlenA(text), dx),
167 "ExtTextOutA error %ld\n", GetLastError());
169 hFont = SelectObject(hdcMetafile, hFont);
170 ok(DeleteObject(hFont), "DeleteObject error %ld\n", GetLastError());
172 hMetafile = CloseEnhMetaFile(hdcMetafile);
173 ok(hMetafile != 0, "CloseEnhMetaFile error %ld\n", GetLastError());
175 ok(!GetObjectType(hdcMetafile), "CloseEnhMetaFile has to destroy metafile hdc\n");
177 ok(PlayEnhMetaFile(hdcDisplay, hMetafile, &rc), "PlayEnhMetaFile error %ld\n", GetLastError());
179 ok(EnumEnhMetaFile(hdcDisplay, hMetafile, emf_enum_proc, dx, &rc),
180 "EnumEnhMetaFile error %ld\n", GetLastError());
182 ok(emr_processed, "EnumEnhMetaFile couldn't find EMR_EXTTEXTOUTA or EMR_EXTTEXTOUTW record\n");
184 ok(!EnumEnhMetaFile(hdcDisplay, hMetafile, emf_enum_proc, dx, NULL),
185 "A valid hdc has to require a valid rc\n");
187 ok(DeleteEnhMetaFile(hMetafile), "DeleteEnhMetaFile error %ld\n", GetLastError());
188 ok(ReleaseDC(hwnd, hdcDisplay), "ReleaseDC error %ld\n", GetLastError());
191 START_TEST(metafile)
193 test_ExtTextOut();