fontdlg.c 4.36 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
/*
 * Unit test suite for comdlg32 API functions: font dialogs
 *
 * Copyright 2009 Vincent Povirk for CodeWeavers
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
 *
 */

#include <stdarg.h>

#include "windef.h"
#include "winbase.h"
#include "winerror.h"
#include "wingdi.h"
28
#include "winspool.h"
29 30 31 32 33 34 35
#include "winuser.h"
#include "objbase.h"

#include "commdlg.h"

#include "wine/test.h"

36 37 38 39 40 41 42 43 44 45 46 47
static int get_dpiy(void)
{
    HDC hdc;
    int result;

    hdc = GetDC(0);
    result = GetDeviceCaps(hdc, LOGPIXELSY);
    ReleaseDC(0, hdc);

    return result;
}

48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
static HDC get_printer_ic(void)
{
    PRINTER_INFO_2A *info;
    DWORD info_size, num_printers=0;
    BOOL ret;
    HDC result=NULL;

    EnumPrintersA(PRINTER_ENUM_LOCAL, NULL, 2, NULL, 0, &info_size, &num_printers);

    if (info_size == 0)
        return NULL;

    info = HeapAlloc(GetProcessHeap(), 0, info_size);

    ret = EnumPrintersA(PRINTER_ENUM_LOCAL, NULL, 2, (LPBYTE)info, info_size, &info_size, &num_printers);

    if (ret)
        result = CreateICA(info->pDriverName, info->pPrinterName, NULL, NULL);

    HeapFree(GetProcessHeap(), 0, info);

    return result;
}

72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
static UINT_PTR CALLBACK CFHookProcOK(HWND hdlg, UINT msg, WPARAM wparam, LPARAM lparam)
{
    switch (msg)
    {
    case WM_INITDIALOG:
        PostMessageA(hdlg, WM_COMMAND, IDOK, FALSE);
        return 0;
    default:
        return 0;
    }
}

static void test_ChooseFontA(void)
{
    LOGFONTA lfa;
    CHOOSEFONTA cfa;
    BOOL ret;
89 90
    int dpiy = get_dpiy();
    int expected_pointsize, expected_lfheight;
91
    HDC printer_ic;
92 93 94 95

    memset(&lfa, 0, sizeof(LOGFONTA));
    lfa.lfHeight = -16;
    lfa.lfWeight = FW_NORMAL;
96
    strcpy(lfa.lfFaceName, "Symbol");
97 98 99 100 101 102 103 104 105

    memset(&cfa, 0, sizeof(CHOOSEFONTA));
    cfa.lStructSize = sizeof(cfa);
    cfa.lpLogFont = &lfa;
    cfa.Flags = CF_ENABLEHOOK|CF_INITTOLOGFONTSTRUCT|CF_SCREENFONTS;
    cfa.lpfnHook = CFHookProcOK;

    ret = ChooseFontA(&cfa);

106 107 108
    expected_pointsize = MulDiv(16, 72, dpiy) * 10;
    expected_lfheight = -MulDiv(expected_pointsize, dpiy, 720);

109
    ok(ret == TRUE, "ChooseFontA returned FALSE\n");
110 111
    ok(cfa.iPointSize == expected_pointsize, "Expected %i, got %i\n", expected_pointsize, cfa.iPointSize);
    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);
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137

    printer_ic = get_printer_ic();
    if (!printer_ic)
        skip("can't get a DC for a local printer\n");
    else
    {
        memset(&lfa, 0, sizeof(LOGFONTA));
        lfa.lfHeight = -16;
        lfa.lfWeight = FW_NORMAL;
        strcpy(lfa.lfFaceName, "Symbol");

        memset(&cfa, 0, sizeof(CHOOSEFONTA));
        cfa.lStructSize = sizeof(cfa);
        cfa.lpLogFont = &lfa;
        cfa.Flags = CF_ENABLEHOOK|CF_INITTOLOGFONTSTRUCT|CF_PRINTERFONTS;
        cfa.hDC = printer_ic;
        cfa.lpfnHook = CFHookProcOK;

        ret = ChooseFontA(&cfa);

        expected_pointsize = MulDiv(16, 72, dpiy) * 10;
        expected_lfheight = -MulDiv(expected_pointsize, dpiy, 720);

        ok(ret == TRUE, "ChooseFontA returned FALSE\n");
138 139
        ok(cfa.iPointSize == expected_pointsize, "Expected %i, got %i\n", expected_pointsize, cfa.iPointSize);
        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 142
        ok((strcmp(lfa.lfFaceName, "Symbol") == 0) ||
            broken(*lfa.lfFaceName == 0), "Expected Symbol, got %s\n", lfa.lfFaceName);
143 144 145

        DeleteDC(printer_ic);
    }
146 147 148 149 150 151
}

START_TEST(fontdlg)
{
    test_ChooseFontA();
}