pyWinAuto: c:\.projects\py_pywinauto\pywinauto\tests\missalignment.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"""Missalignment Test
0022
0023**What is checked**
0024This test checks that if a set of controls were aligned on a particular axis
0025in the reference dialog  that they are all aligned on the same axis.
0026
0027**How is it checked**
0028A list of all the reference controls that are aligned is created (ie more than
0029one control with the same Top, Left, Bottom or Right coordinates). These
0030controls are then analysed in the localised dialog to make sure that they are
0031all aligned on the same axis.
0032
0033**When is a bug reported**
0034A bug is reported when any of the controls that were aligned in the reference
0035dialog are no longer aligned in the localised control.
0036
0037**Bug Extra Information**
0038The bug contains the following extra information
0039Name    Description
0040AlignmentType   This is either LEFT, TOP, RIGHT or BOTTOM. It tells you how
0041the controls were aligned in the reference dialog. String
0042AlignmentRect   Gives the smallest rectangle that surrounds ALL the controls
0043concerned in the bug, Rectangle
0044
0045**Is Reference dialog needed**
0046This test cannot be performed without the reference control. It is required
0047to see which controls should be aligned.
0048
0049**False positive bug reports**
0050It is quite possible that this test reports false positives:
00511.      Where the controls only just happen to be aligned in the reference dialog
0052(by coincidence)
00532.      Where the control does not have a clear boundary (for example static
0054labels or checkboxes)  they may be miss-aligned but it is not noticeable that
0055they are not.
0056
0057
0058**Test Identifier**
0059The identifier for this test/bug is "Missalignment" """
0060
0061__revision__ = "$Revision: 221 $"
0062
0063testname = "Missalignment"
0064
0065from pywinauto.win32structures import RECT
0066
0067#====================================================================
0068def MissalignmentTest(windows):
0069    "Run the test on the windows passed in"
0070    refAlignments = {}
0071
0072    #find the controls alligned along each axis
0073    for win in windows:
0074        if not win.ref:
0075            continue
0076
0077
0078        for side in ("top", "left", "right", "bottom"):
0079            sideValue = getattr(win.ref.Rectangle(), side)
0080
0081            # make sure that the side dictionary has been created
0082            sideAlignments = refAlignments.setdefault(side, {})
0083
0084            # make sure that the array of controls for this
0085            # alignment line has been created and add the current window
0086            sideAlignments.setdefault(sideValue, []).append(win)
0087
0088    bugs = []
0089    for side in refAlignments:
0090        for alignment in refAlignments[side]:
0091            controls = refAlignments[side][alignment]
0092            sides = [getattr(ctrl.Rectangle(), side) for ctrl in controls]
0093            sides = set(sides)
0094
0095            if len(sides) > 1:
0096
0097                overAllRect = RECT()
0098                overAllRect.left = min(
0099                    [ctrl.Rectangle().left for ctrl in controls])
0100                overAllRect.top = min(
0101                    [ctrl.Rectangle().top for ctrl in controls])
0102                overAllRect.right = max(
0103                    [ctrl.Rectangle().right for ctrl in controls])
0104                overAllRect.bottom = max(
0105                    [ctrl.Rectangle().bottom for ctrl in controls])
0106
0107
0108                bugs.append((
0109                    controls,
0110                    {
0111                        "AlignmentType": side.upper(),
0112                        "AlignmentRect": overAllRect
0113                    },
0114                    testname,
0115                    0)
0116                )
0117
0118    return bugs