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