pyWinAuto: c:\.projects\py_pywinauto\pywinauto\tests\asianhotkey.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"""Asian Hotkey Format Test
0022
0023**What is checked**
0024
0025This test checks whether the format for shortcuts/hotkeys follows the
0026standards for localised Windows applications. This format is
0027{localised text}({uppercase hotkey})
0028so for example if the English control is
0029"&Help"
0030the localised control for Asian languages should be
0031"LocHelp(H)"
0032
0033**How is it checked**
0034
0035After checking whether this control displays hotkeys it examines the 1st
0036string of the control to make sure that the format is correct.
0037If the reference control is available then it also makes sure that the
0038hotkey character is the same as the reference.
0039Controls with a title of less than 4 characters are ignored. This has been
0040done to avoid false positive bug reports for strings like "&X:".
0041
0042**When is a bug reported**
0043
0044A bug is reported when a control has a hotkey and it is not in the correct
0045format.
0046Also if the reference control is available a bug will be reported if the
0047hotkey character is not the same as used in the reference
0048
0049**Bug Extra Information**
0050
0051This test produces 2 different types of bug:
0052BugType: "AsianHotkeyFormat"
0053There is no extra information associated with this bug type
0054
0055**BugType: "AsianHotkeyDiffRef"**
0056
0057There is no extra information associated with this bug type
0058
0059**Is Reference dialog needed**
0060
0061The reference dialog is not needed.
0062If it is unavailable then only bugs of type "AsianHotkeyFormat" will be
0063reported, bug of type "AsianHotkeyDiffRef" will not be found.
0064
0065**False positive bug reports**
0066
0067There should be very few false positive bug reports when testing Asian
0068software. If a string is very short (eg "&Y:") but is padded with spaces
0069then it will get reported.
0070
0071**Test Identifier**
0072
0073The identifier for this test/bug is "AsianHotkeyTests"
0074"""
0075
0076__revision__ = "$Revision: 286 $"
0077
0078
0079testname = "AsianHotkeyFormat"
0080
0081
0082import re
0083
0084from repeatedhotkey import ImplementsHotkey, GetHotkey
0085
0086
0087#-----------------------------------------------------------------------------
0088def AsianHotkeyTest(windows):
0089    "Return the repeated hotkey errors"
0090
0091    bugs = []
0092
0093    for win in windows:
0094        # skip it if it doesn't implement hotkey functionality
0095        if not ImplementsHotkey(win):
0096            continue
0097
0098        if _IsAsianHotkeyFormatIncorrect(win.WindowText()):
0099
0100            bugs.append((
0101                [win,],
0102                {},
0103                testname,
0104                0)
0105            )
0106
0107    return bugs
0108
0109
0110_asianHotkeyRE = re.compile (r"""
0111    \(&.\)      # the hotkey
0112    (
0113        (\t.*)|     # tab, and then anything
0114        #(\\t.*)|   # escaped tab, and then anything
0115        (\(.*\)     # anything in brackets
0116    )|
0117    \s*|            # any whitespace
0118    :|              # colon
0119    (\.\.\.)|       # elipsis
0120    >|              # greater than sign
0121    <|              # less than sign
0122    (\n.*)          # newline, and then anything
0123    \s)*$""", re.VERBOSE)
0124
0125#-----------------------------------------------------------------------------
0126def _IsAsianHotkeyFormatIncorrect(text):
0127    "Check if the format of the hotkey is correct or not"
0128    # get the hotkey
0129    pos, char = GetHotkey(text)
0130
0131    # if it has a hotkey then check that it is correct Asian format
0132    if char:
0133        found = _asianHotkeyRE.search(text)
0134        if not found:
0135            return True
0136
0137
0138    return False
0139
0140
0141#       if (hotkeyPos - 2  >= 0 &&      // at least 4th character ".(&..."
0142#        // at most 2nd last character "...(&H)"
0143#               hotkeyPos + 1 <= title.length()-1 &&
0144#               title[hotkeyPos-2] == '(' &&
0145#               title[hotkeyPos+1] == ')' &&
0146#               hotkeyPos +1 == title.find_last_not_of("\n\t :")
0147#          )
0148#       {
0149#               // OK So we know now that the format "..(&X).."
0150#       // is correct and that it is the
0151#               // last non space character in the title
0152#               ; // SO NO BUG!
0153
0154
0155AsianHotkeyTest.TestsMenus = True