[COMDLG32_WINETEST] Add a PCH.
[reactos.git] / modules / rostests / winetests / comdlg32 / fontdlg.c
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 "precomp.h"
23
24 #include <winspool.h>
25
26 static int get_dpiy(void)
27 {
28 HDC hdc;
29 int result;
30
31 hdc = GetDC(0);
32 result = GetDeviceCaps(hdc, LOGPIXELSY);
33 ReleaseDC(0, hdc);
34
35 return result;
36 }
37
38 static HDC get_printer_ic(void)
39 {
40 PRINTER_INFO_2A *info;
41 DWORD info_size, num_printers=0;
42 BOOL ret;
43 HDC result=NULL;
44
45 EnumPrintersA(PRINTER_ENUM_LOCAL, NULL, 2, NULL, 0, &info_size, &num_printers);
46
47 if (info_size == 0)
48 return NULL;
49
50 info = HeapAlloc(GetProcessHeap(), 0, info_size);
51
52 ret = EnumPrintersA(PRINTER_ENUM_LOCAL, NULL, 2, (LPBYTE)info, info_size, &info_size, &num_printers);
53
54 if (ret)
55 result = CreateICA(info->pDriverName, info->pPrinterName, NULL, NULL);
56
57 HeapFree(GetProcessHeap(), 0, info);
58
59 return result;
60 }
61
62 static UINT_PTR CALLBACK CFHookProcOK(HWND hdlg, UINT msg, WPARAM wparam, LPARAM lparam)
63 {
64 switch (msg)
65 {
66 case WM_INITDIALOG:
67 PostMessageA(hdlg, WM_COMMAND, IDOK, FALSE);
68 return 0;
69 default:
70 return 0;
71 }
72 }
73
74 static void test_ChooseFontA(void)
75 {
76 LOGFONTA lfa;
77 CHOOSEFONTA cfa;
78 BOOL ret;
79 int dpiy = get_dpiy();
80 int expected_pointsize, expected_lfheight;
81 HDC printer_ic;
82
83 memset(&lfa, 0, sizeof(LOGFONTA));
84 lfa.lfHeight = -16;
85 lfa.lfWeight = FW_NORMAL;
86 strcpy(lfa.lfFaceName, "Symbol");
87
88 memset(&cfa, 0, sizeof(CHOOSEFONTA));
89 cfa.lStructSize = sizeof(cfa);
90 cfa.lpLogFont = &lfa;
91 cfa.Flags = CF_ENABLEHOOK|CF_INITTOLOGFONTSTRUCT|CF_SCREENFONTS;
92 cfa.lpfnHook = CFHookProcOK;
93
94 ret = ChooseFontA(&cfa);
95
96 expected_pointsize = MulDiv(16, 72, dpiy) * 10;
97 expected_lfheight = -MulDiv(expected_pointsize, dpiy, 720);
98
99 ok(ret == TRUE, "ChooseFontA returned FALSE\n");
100 ok(cfa.iPointSize == expected_pointsize, "Expected %i, got %i\n", expected_pointsize, cfa.iPointSize);
101 ok(lfa.lfHeight == expected_lfheight, "Expected %i, got %i\n", expected_lfheight, lfa.lfHeight);
102 ok(lfa.lfWeight == FW_NORMAL, "Expected FW_NORMAL, got %i\n", lfa.lfWeight);
103 ok(strcmp(lfa.lfFaceName, "Symbol") == 0, "Expected Symbol, got %s\n", lfa.lfFaceName);
104
105 printer_ic = get_printer_ic();
106 if (!printer_ic)
107 skip("can't get a DC for a local printer\n");
108 else
109 {
110 memset(&lfa, 0, sizeof(LOGFONTA));
111 lfa.lfHeight = -16;
112 lfa.lfWeight = FW_NORMAL;
113 strcpy(lfa.lfFaceName, "Symbol");
114
115 memset(&cfa, 0, sizeof(CHOOSEFONTA));
116 cfa.lStructSize = sizeof(cfa);
117 cfa.lpLogFont = &lfa;
118 cfa.Flags = CF_ENABLEHOOK|CF_INITTOLOGFONTSTRUCT|CF_PRINTERFONTS;
119 cfa.hDC = printer_ic;
120 cfa.lpfnHook = CFHookProcOK;
121
122 ret = ChooseFontA(&cfa);
123
124 expected_pointsize = MulDiv(16, 72, dpiy) * 10;
125 expected_lfheight = -MulDiv(expected_pointsize, dpiy, 720);
126
127 ok(ret == TRUE, "ChooseFontA returned FALSE\n");
128 ok(cfa.iPointSize == expected_pointsize, "Expected %i, got %i\n", expected_pointsize, cfa.iPointSize);
129 ok(lfa.lfHeight == expected_lfheight, "Expected %i, got %i\n", expected_lfheight, lfa.lfHeight);
130 ok(lfa.lfWeight == FW_NORMAL, "Expected FW_NORMAL, got %i\n", lfa.lfWeight);
131 ok((strcmp(lfa.lfFaceName, "Symbol") == 0) ||
132 broken(*lfa.lfFaceName == 0), "Expected Symbol, got %s\n", lfa.lfFaceName);
133
134 DeleteDC(printer_ic);
135 }
136 }
137
138 START_TEST(fontdlg)
139 {
140 test_ChooseFontA();
141 }