Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
wine-mirror
GitHub Repository: wine-mirror/wine
Path: blob/master/dlls/comdlg32/tests/fontdlg.c
4393 views
1
/*
2
* Unit test suite for comdlg32 API functions: font dialogs
3
*
4
* Copyright 2009 Vincent Povirk for CodeWeavers
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19
*
20
*/
21
22
#include <stdarg.h>
23
24
#include "windef.h"
25
#include "winbase.h"
26
#include "winerror.h"
27
#include "wingdi.h"
28
#include "winspool.h"
29
#include "winuser.h"
30
#include "objbase.h"
31
32
#include "commdlg.h"
33
34
#include "wine/test.h"
35
36
static int get_dpiy(void)
37
{
38
HDC hdc;
39
int result;
40
41
hdc = GetDC(0);
42
result = GetDeviceCaps(hdc, LOGPIXELSY);
43
ReleaseDC(0, hdc);
44
45
return result;
46
}
47
48
static HDC get_printer_ic(void)
49
{
50
PRINTER_INFO_2A *info;
51
DWORD info_size, num_printers=0;
52
BOOL ret;
53
HDC result=NULL;
54
55
EnumPrintersA(PRINTER_ENUM_LOCAL, NULL, 2, NULL, 0, &info_size, &num_printers);
56
57
if (info_size == 0)
58
return NULL;
59
60
info = malloc(info_size);
61
62
ret = EnumPrintersA(PRINTER_ENUM_LOCAL, NULL, 2, (LPBYTE)info, info_size, &info_size, &num_printers);
63
64
if (ret)
65
result = CreateICA(info->pDriverName, info->pPrinterName, NULL, NULL);
66
67
free(info);
68
69
return result;
70
}
71
72
static UINT_PTR CALLBACK CFHookProcOK(HWND hdlg, UINT msg, WPARAM wparam, LPARAM lparam)
73
{
74
switch (msg)
75
{
76
case WM_INITDIALOG:
77
PostMessageA(hdlg, WM_COMMAND, IDOK, FALSE);
78
return 0;
79
default:
80
return 0;
81
}
82
}
83
84
static void test_ChooseFontA(void)
85
{
86
LOGFONTA lfa;
87
CHOOSEFONTA cfa;
88
BOOL ret;
89
int dpiy = get_dpiy();
90
int expected_pointsize, expected_lfheight;
91
HDC printer_ic;
92
93
memset(&lfa, 0, sizeof(LOGFONTA));
94
lfa.lfHeight = -16;
95
lfa.lfWeight = FW_NORMAL;
96
strcpy(lfa.lfFaceName, "Symbol");
97
98
memset(&cfa, 0, sizeof(CHOOSEFONTA));
99
cfa.lStructSize = sizeof(cfa);
100
cfa.lpLogFont = &lfa;
101
cfa.Flags = CF_ENABLEHOOK|CF_INITTOLOGFONTSTRUCT|CF_SCREENFONTS;
102
cfa.lpfnHook = CFHookProcOK;
103
104
ret = ChooseFontA(&cfa);
105
106
expected_pointsize = MulDiv(16, 72, dpiy) * 10;
107
expected_lfheight = -MulDiv(expected_pointsize, dpiy, 720);
108
109
ok(ret == TRUE, "ChooseFontA returned FALSE\n");
110
ok(cfa.iPointSize == expected_pointsize, "Expected %i, got %i\n", expected_pointsize, cfa.iPointSize);
111
ok(lfa.lfHeight == expected_lfheight, "Expected %i, got %li\n", expected_lfheight, lfa.lfHeight);
112
ok(lfa.lfWeight == FW_NORMAL, "Expected FW_NORMAL, got %li\n", lfa.lfWeight);
113
ok(lfa.lfCharSet == SYMBOL_CHARSET, "Expected SYMBOL_CHARSET, got %i\n", lfa.lfCharSet);
114
ok(strcmp(lfa.lfFaceName, "Symbol") == 0, "Expected Symbol, got %s\n", lfa.lfFaceName);
115
116
cfa.Flags = CF_ENABLEHOOK|CF_INITTOLOGFONTSTRUCT|CF_SCREENFONTS|CF_NOSCRIPTSEL;
117
ret = ChooseFontA(&cfa);
118
ok(ret == TRUE, "ChooseFontA returned FALSE\n");
119
ok(lfa.lfCharSet == DEFAULT_CHARSET, "Expected DEFAULT_CHARSET, got %i\n", lfa.lfCharSet);
120
121
printer_ic = get_printer_ic();
122
if (!printer_ic)
123
skip("can't get a DC for a local printer\n");
124
else
125
{
126
memset(&lfa, 0, sizeof(LOGFONTA));
127
lfa.lfHeight = -16;
128
lfa.lfWeight = FW_NORMAL;
129
strcpy(lfa.lfFaceName, "Symbol");
130
131
memset(&cfa, 0, sizeof(CHOOSEFONTA));
132
cfa.lStructSize = sizeof(cfa);
133
cfa.lpLogFont = &lfa;
134
cfa.Flags = CF_ENABLEHOOK|CF_INITTOLOGFONTSTRUCT|CF_PRINTERFONTS;
135
cfa.hDC = printer_ic;
136
cfa.lpfnHook = CFHookProcOK;
137
138
ret = ChooseFontA(&cfa);
139
140
expected_pointsize = MulDiv(16, 72, dpiy) * 10;
141
expected_lfheight = -MulDiv(expected_pointsize, dpiy, 720);
142
143
ok(ret == TRUE, "ChooseFontA returned FALSE\n");
144
ok(cfa.iPointSize == expected_pointsize, "Expected %i, got %i\n", expected_pointsize, cfa.iPointSize);
145
ok(lfa.lfHeight == expected_lfheight, "Expected %i, got %li\n", expected_lfheight, lfa.lfHeight);
146
ok(lfa.lfWeight == FW_NORMAL, "Expected FW_NORMAL, got %li\n", lfa.lfWeight);
147
ok((strcmp(lfa.lfFaceName, "Symbol") == 0) ||
148
broken(*lfa.lfFaceName == 0), "Expected Symbol, got %s\n", lfa.lfFaceName);
149
150
DeleteDC(printer_ic);
151
}
152
}
153
154
START_TEST(fontdlg)
155
{
156
test_ChooseFontA();
157
}
158
159