summaryrefslogtreecommitdiff
path: root/testautomation/framework/optional/includes/menuentries.inc
blob: f2006915c8b19aa69f34ff06c1b9d7cce9e470f8 (plain)
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
'encoding UTF-8  Do not remove or change this line!
'**************************************************************************
' DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
'
' Copyright 2000, 2010 Oracle and/or its affiliates.
'
' OpenOffice.org - a multi-platform office productivity suite
'
' This file is part of OpenOffice.org.
'
' OpenOffice.org is free software: you can redistribute it and/or modify
' it under the terms of the GNU Lesser General Public License version 3
' only, as published by the Free Software Foundation.
'
' OpenOffice.org 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 version 3 for more details
' (a copy is included in the LICENSE file that accompanied this code).
'
' You should have received a copy of the GNU Lesser General Public License
' version 3 along with OpenOffice.org.  If not, see
' <http://www.openoffice.org/license.html>
' for a copy of the LGPLv3 License.
'
'/************************************************************************
'*
'* Owner : thorsten.bosbach@oracle.com
'*
'* short description : Read menubar and first level drop down lists and compare to reference
'*
'\*****************************************************************

sub t_getMenuText
    dim k,c as integer
    dim sApplication() as string

    sApplication = array("WRITER","MASTERDOCUMENT","HTML","CALC","IMPRESS","DRAW","MATH","BASIC","DATABASE")

    ' for every application
    c = uBound(sApplication())
    for k = 0 to c
        gApplication = sApplication(k)
        printlog "********** " + gApplication
        call s_getMenuText
    next k
    gApplication = "WRITER"
end sub

testcase s_getMenuText
    dim i,j,l,m,a,b,d,e as integer
    dim sReference(400) as string
    dim sCurrent(400) as string
    dim sFileName as string
    dim sTemp as string
    dim bError as boolean
    dim iTopLevelCount as integer
    dim iOffset as integer
    
        for i=0 to uBound(sReference())
            sReference(i) = 0
            sCurrent(i) = 0
        next i
        bError = FALSE
        hNewDocument
        hUseMenu
        ' for every item in main menu bar
        a = MenuGetItemCount
        iTopLevelCount = a
        MenuSelect (0)
        for i = 1 to a
            hUseMenu
            stemp = MenuGetItemText(MenuGetItemID(i))
            'printlog sTemp
            listAppend(sCurrent(),"********** "+sTemp)
            MenuSelect(MenuGetItemID(i))
            b = MenuGetItemCount
            for j = 1 to b
                sTemp = MenuGetItemText(MenuGetItemID(j))
                'printlog "    " + sTemp
                listAppend(sCurrent(),sTemp)
            next j
            MenuSelect (0)
        next i
        hCloseDocument
        sFileName = convertPath(gTestToolPath+"framework\optional\input/menu/"+lCase(gISOLang+"_"+gApplication+".txt"))
        printlog( "Using reference file: " & sFileName )
        ' gProductName should not make a big difference.
        if fileExists(sFileName) then
            ' load to compare
            listRead(sReference(), sFileName, "utf8")
            d = listCount(sCurrent())
            m = d
            e = listCount(sReference())
            if (d <> e) then
                warnlog "The count of Menuentries differs from reference "+gApplication+". should: '" + e + "'; delta is: '" + (d - e) + "'"
                bError = TRUE
                ' always take the shorter list count
                if cBool(d - e) then
                    d = e
                endif
                e = m - e
            else
                printlog "Count of Menuentries is ok"
                e = 0
            endif
            ' compare all entries
            iOffset = 0
            m = 0
            for l=1 to d 
                ' count main menu bar items
                if inStr(sReference(l), "********** ") > 0 then
                    m = m + 1
                    ' bug in inc m :-(
                    printlog mid(sReference(l),12)
                endif
                ' complain non existing accelerator
                if (sReference(l) <> "") AND (inStr(sReference(l),"~") < 1) then
                    qaErrorLog "No accelerator (~) in item: '" + sReference(l) + "'"
                endif
                ' compare the menu entries
                if (sReference(l) <> sCurrent(l+iOffset))then
                    ' try to syncronize different count of entries
                    if (e <> 0) then
                        iOffset = iOffset + sgn(e)
                        'qaerrorlog "io: " + ioffset
                        e = e - sgn(e)
                        'qaerrorlog "e: " + e
                    endif
                    '
                    if (m = (iTopLevelCount-1)) then
                        ' tolerate the window menu
                        printlog "String differs: " + chr(13) + "current  : '"+sCurrent(l) + "'" + chr(13) + "reference: '" + sReference(l) + "'"
                    else
                        bError = TRUE
                        warnlog "String differs: " + chr(13) + "current  : '"+sCurrent(l) + "'" + chr(13) + "reference: '" + sReference(l) + "'"
                    endif
                endif
            next l
          '  for l=d-5 to d+5
          '  printlog "------"
          '  printlog sreference(l)
          '  printlog scurrent(l)
          '  next l
            ' if there is still is a difference in count
            if (e <> 0) then
                if sgn(e) then
                    warnlog "Not all reference entries are there, e.g.: '" + sReference(l+1) + "'"
                else
                    warnlog "There are too much entries, e.g.: '" + sCurrent(l+1) + "'"
                endif
            endif
            if bError then
                sFileName = convertPath(gOfficePath+"user/work/menu/"+lCase(gISOLang+"_"+gApplication+".txt"))
                listWrite(sCurrent(), sFileName, "utf8")
                printlog "Written strings from this build to: " + chr(13) + sFileName
            else
                ' OK
            endif
        else
            ' write to checkin
            warnlog "No reference found; please copy:"+lCase(gISOLang+"_"+gApplication+".txt")
            sFileName = convertPath(gOfficePath+"user/work/menu/"+lCase(gISOLang+"_"+gApplication+".txt"))
            listWrite(sCurrent(), sFileName, "utf8")
            printlog sFileName + chr(13) + "to"
            sFileName = convertPath(gTestToolPath+"framework/level1/input/menu/"+lCase(gISOLang+"_"+gApplication+".txt"))
            printlog sFilename
            'listWrite(sCurrent(), sFileName, "utf8")
        endif
    'speichern: (vendor?) sprache gISOLang applikation
endcase