2 * Unit test suite for comdlg32 API functions: font dialogs
4 * Copyright 2009 Vincent Povirk for CodeWeavers
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
34 #include "wine/test.h"
36 static int get_dpiy(void)
42 result
= GetDeviceCaps(hdc
, LOGPIXELSY
);
48 static HDC
get_printer_ic(void)
50 PRINTER_INFO_2A
*info
;
51 DWORD info_size
, num_printers
=0;
55 EnumPrintersA(PRINTER_ENUM_LOCAL
, NULL
, 2, NULL
, 0, &info_size
, &num_printers
);
60 info
= HeapAlloc(GetProcessHeap(), 0, info_size
);
62 ret
= EnumPrintersA(PRINTER_ENUM_LOCAL
, NULL
, 2, (LPBYTE
)info
, info_size
, &info_size
, &num_printers
);
65 result
= CreateICA(info
->pDriverName
, info
->pPrinterName
, NULL
, NULL
);
67 HeapFree(GetProcessHeap(), 0, info
);
72 static UINT_PTR CALLBACK
CFHookProcOK(HWND hdlg
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
77 PostMessageA(hdlg
, WM_COMMAND
, IDOK
, FALSE
);
84 static void test_ChooseFontA(void)
89 int dpiy
= get_dpiy();
90 int expected_pointsize
, expected_lfheight
;
93 memset(&lfa
, 0, sizeof(LOGFONTA
));
95 lfa
.lfWeight
= FW_NORMAL
;
96 strcpy(lfa
.lfFaceName
, "Symbol");
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
;
104 ret
= ChooseFontA(&cfa
);
106 expected_pointsize
= MulDiv(16, 72, dpiy
) * 10;
107 expected_lfheight
= -MulDiv(expected_pointsize
, dpiy
, 720);
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 %i\n", expected_lfheight
, lfa
.lfHeight
);
112 ok(lfa
.lfWeight
== FW_NORMAL
, "Expected FW_NORMAL, got %i\n", lfa
.lfWeight
);
113 ok(strcmp(lfa
.lfFaceName
, "Symbol") == 0, "Expected Symbol, got %s\n", lfa
.lfFaceName
);
115 printer_ic
= get_printer_ic();
117 skip("can't get a DC for a local printer\n");
120 memset(&lfa
, 0, sizeof(LOGFONTA
));
122 lfa
.lfWeight
= FW_NORMAL
;
123 strcpy(lfa
.lfFaceName
, "Symbol");
125 memset(&cfa
, 0, sizeof(CHOOSEFONTA
));
126 cfa
.lStructSize
= sizeof(cfa
);
127 cfa
.lpLogFont
= &lfa
;
128 cfa
.Flags
= CF_ENABLEHOOK
|CF_INITTOLOGFONTSTRUCT
|CF_PRINTERFONTS
;
129 cfa
.hDC
= printer_ic
;
130 cfa
.lpfnHook
= CFHookProcOK
;
132 ret
= ChooseFontA(&cfa
);
134 expected_pointsize
= MulDiv(16, 72, dpiy
) * 10;
135 expected_lfheight
= -MulDiv(expected_pointsize
, dpiy
, 720);
137 ok(ret
== TRUE
, "ChooseFontA returned FALSE\n");
138 ok(cfa
.iPointSize
== expected_pointsize
, "Expected %i, got %i\n", expected_pointsize
, cfa
.iPointSize
);
139 ok(lfa
.lfHeight
== expected_lfheight
, "Expected %i, got %i\n", expected_lfheight
, lfa
.lfHeight
);
140 ok(lfa
.lfWeight
== FW_NORMAL
, "Expected FW_NORMAL, got %i\n", lfa
.lfWeight
);
141 ok((strcmp(lfa
.lfFaceName
, "Symbol") == 0) ||
142 broken(*lfa
.lfFaceName
== 0), "Expected Symbol, got %s\n", lfa
.lfFaceName
);
144 DeleteDC(printer_ic
);