pyWinAuto: c:\.projects\py_pywinauto\pywinauto\tests\comparetoreffont.py

0001# GUI Application automation and testing library
0002# Copyright (C) 2006 Mark Mc Mahon
0003#
0004# This library is free software; you can redistribute it and/or
0005# modify it under the terms of the GNU Lesser General Public License
0006# as published by the Free Software Foundation; either version 2.1
0007# of the License, or (at your option) any later version.
0008#
0009# This library is distributed in the hope that it will be useful,
0010# but WITHOUT ANY WARRANTY; without even the implied warranty of
0011# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
0012# See the GNU Lesser General Public License for more details.
0013#
0014# You should have received a copy of the GNU Lesser General Public
0015# License along with this library; if not, write to the
0016#    Free Software Foundation, Inc.,
0017#    59 Temple Place,
0018#    Suite 330,
0019#    Boston, MA 02111-1307 USA
0020
0021"""Compare against reference font test
0022
0023**What is checked**
0024This test checks all the parameters of the font for the control against the
0025font for the reference control. If any value is different then this is reported
0026as a bug.
0027Here is a list of all the possible values that are tested:
0028lfFaceName      The name of the font
0029lfHeight        The height of the font
0030lfWidth         Average width of characters
0031lfEscapement    Angle of text
0032lfOrientation   Another angle for the text!
0033lfWeight        How bold the text is
0034lfItalic        If the font is italic
0035lfUnderline     If the font is underlined
0036lfStrikeOut     If the font is struck out
0037lfCharSet       The character set of the font
0038lfOutPrecision  The output precision
0039lfClipPrecision The clipping precision
0040lfQuality       The output quality
0041lfPitchAndFamily        The pitch and family
0042
0043
0044**How is it checked**
0045Each property of the font for the control being tested is compared against the
0046equivalent property of the reference control font for equality.
0047
0048**When is a bug reported**
0049For each property of the font that is not identical to the reference font a bug
0050is reported. So for example if the Font Face has changed and the text is bold
0051then (at least) 2 bugs will be reported.
0052
0053**Bug Extra Information**
0054The bug contains the following extra information
0055Name    Description
0056ValueType       What value is incorrect (see above), String
0057Ref     The reference value converted to a string, String
0058Loc     The localised value converted to a string, String
0059
0060**Is Reference dialog needed**
0061This test will not run if the reference controls are not available.
0062
0063**False positive bug reports**
0064Running this test for Asian languages will result in LOTS and LOTS of false
0065positives, because the font HAS to change for the localised text to display
0066properly.
0067
0068**Test Identifier**
0069The identifier for this test/bug is "CompareToRefFont"
0070"""
0071
0072__revision__ = "$Revision: 276 $"
0073
0074testname = "CompareToRefFont"
0075
0076from pywinauto import win32structures
0077_font_attribs = [field[0] for field in win32structures.LOGFONTW._fields_]
0078
0079def CompareToRefFontTest(windows):
0080    "Compare the font to the font of the reference control"
0081
0082
0083    bugs = []
0084    for win in windows:
0085        # if no reference then skip the control
0086        if not win.ref:
0087            continue
0088
0089        # find each of the bugs
0090        for font_attrib in _font_attribs:
0091
0092            loc_value = getattr(win.Font(), font_attrib)
0093            # get the reference value
0094            ref_value = getattr(win.ref.Font(), font_attrib)
0095
0096            # If they are different
0097            if loc_value != ref_value:
0098
0099                # Add the bug information
0100                bugs.append((
0101                    [win, ],
0102                    {
0103                        "ValueType": fname,
0104                        "Ref": unicode(ref_value),
0105                        "Loc": unicode(loc_value),
0106                    },
0107                    testname,
0108                    0,)
0109                )
0110    return bugs