jl165 merging heads
[LibreOffice.git] / testautomation / xml / optional / includes / c_xml_scenario.inc
blobddaf8fbcd18cbe7fea7e3c09a3214ec6b3ea788d
1 'encoding UTF-8  Do not remove or change this line!
2 '**************************************************************************
3 ' DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 ' Copyright 2000, 2010 Oracle and/or its affiliates.
7 ' OpenOffice.org - a multi-platform office productivity suite
9 ' This file is part of OpenOffice.org.
11 ' OpenOffice.org is free software: you can redistribute it and/or modify
12 ' it under the terms of the GNU Lesser General Public License version 3
13 ' only, as published by the Free Software Foundation.
15 ' OpenOffice.org is distributed in the hope that it will be useful,
16 ' but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 ' GNU Lesser General Public License version 3 for more details
19 ' (a copy is included in the LICENSE file that accompanied this code).
21 ' You should have received a copy of the GNU Lesser General Public License
22 ' version 3 along with OpenOffice.org.  If not, see
23 ' <http://www.openoffice.org/license.html>
24 ' for a copy of the LGPLv3 License.
26 '/************************************************************************
28 '* owner : oliver.craemer@oracle.com
30 '* short description : Check content.xml for correct scenario attributes
32 '*************************************************************************************************
34 ' #1 subScenarioAttributes
35 ' #1 tScenarioAttributes
36 ' #1 subCreateScenario
37 ' #1 subCheckScenarioInContentXML
39 '\*************************************************************************************************
40 sub subScenarioAttributes
41   printLog Chr(13) + "---------  scenario attributes  ----------"
43      call tScenarioAttributes
45 end sub
47 '************************************************************
48 testcase tScenarioAttributes
49     dim iIndex as INTEGER
50     
51     dim sExtension
52     sExtension = ".ods"
54     dim sNameSheet1 as STRING
55     sNameSheet1 = "Ten"
56     dim sNameSheet2 as STRING
57     sNameSheet2 = "Moves"
58     dim sNameSheet3 as STRING
59     sNameSheet3 = "Ahead"
61     
62     dim sOutputFile as STRING
63     sOutputFile = ( gOfficePath & ConvertPath( "user\work\scenarioAttributes" ) & sExtension )
64     
65     dim sUnpackedStorageDir as STRING
66     sUnpackedStorageDir = ( gOfficePath & ConvertPath( "user\work\scenarioAttributes" ))
67     if (dir ( sUnpackedStorageDir ) <> "" ) then
68         rmDir ( sUnpackedStorageDir )
69         if (dir ( sUnpackedStorageDir ) <> "" ) then
70             warnlog "Diretory has not been deleted. Exiting test."
71             goto endsub
72         endif
73     endif
74     
75     dim sContentXML as STRING
76     sContentXML = ( gOfficePath & ConvertPath( "user\work\scenarioAttributes" ) & ConvertPath( "\content.xml" ))
78     printlog "Create a new spreadsheet document"
79     Call hNewDocument
80     sleep(2)    
81     for iIndex = 1 to 3
82         printlog "Type in the first cell the number 1 and press RETURN"
83         Kontext "DocumentCalc"
84         DocumentCalc.TypeKeys "1<RETURN>"
85         sleep(1)
86         printlog "Format / Sheet / Rename"
87         FormatSheetRename
88         Kontext "TabelleUmbenennen"
89         select case iIndex
90                case 1 : Tabellenname.SetText sNameSheet1
91                         printlog " In first round name it 'Ten'"                                              
92                case 2 : Tabellenname.SetText sNameSheet2
93                         printlog " In first round name it 'Moves'"
94                case 3 : Tabellenname.SetText sNameSheet3
95                         printlog " In first round name it 'Ahead'"
96         end select
97         printlog "Press OK on dialog" 
98         TabelleUmbenennen.OK
99         sleep(1)        
100         printlog "Edit / Sheet / Select"
101         EditSheetSelect
102         Kontext "SelectSheets"
103         printlog "In round 1 and 2 select the next sheet."
104         printlog "In round three select the first sheet."
105         if iIndex = 3 then            
106             SheetSelectionBox.Select sNameSheet1
107         else             
108             SheetSelectionBox.Select ( iIndex + 1 )
109         endif
110         printlog "Press OK on dialog."
111         SelectSheets.OK
112         sleep(1)
113     next iIndex            
114     printlog "If not visible: View / Toolbars / Formula bar"
115     Kontext "RechenleisteCalc"
116     if not RechenleisteCalc.isvisible then
117         ViewToolbarsFormulaBar
118     end if
119     sleep(1)    
120     Kontext "RechenleisteCalc"
121     printlog "In the Formular bar edit area type:"
122     Bereich.TypeKeys "<MOD1 A>"
123     printlog "[CTRL+A]"    
124     Bereich.TypeKeys "C3"
125     printlog "C3"
126     sleep(1)
127     printlog "[RETURN]"
128     Bereich.TypeKeys "<RETURN>"
129     sleep(1)
130     Kontext "DocumentCalc"
131     printlog "Type in the spreadsheet document:"
132     printlog "1[RETURN]2[RETURN]3[RETURN]"
133     DocumentCalc.typekeys "1<RETURN>2<RETURN>3<RETURN>"    
134     Kontext "RechenleisteCalc"
135     printlog "In the Formula bar type in the edit area:"
136     printlog "[CTRL+A]"
137     Bereich.TypeKeys "<MOD1 A>"
138     printlog "C3:C5"
139     Bereich.TypeKeys "C3:C5"
140     sleep(1)
141     printlog "[RETURN]"
142     Bereich.TypeKeys "<RETURN>"
143     sleep(1)
144     printlog "Tools / scenarios..."
145     printlog "Scenario name: Scenario_XML_Test"
146     printlog "Scenario comment: Created by Peter Junge"
147     printlog "Color index: 1"
148     printlog "Display border unchecked"
149     printlog "Copy back unchecked"
150     printlog "Copy entire sheet unchecked"
151     printlog "Prevent changes unchecked"
152     subCreateScenario ( "Scenario_XML_Test" , "Created by Peter Junge" , 1 , 0 , 0 , 0 , 0 )
153     sleep(1)    
154     printlog "Create a another scenario on this selection with the following parameters:"
155     printlog "Scenario name: AnotherScenario"
156     printlog "Scenario comment: Random Comment"
157     printlog "Color index: 13"
158     printlog "Display border checked"
159     printlog "Copy back checked"
160     printlog "Copy entire sheet checked"
161     printlog "Prevent changes checked"        
162     subCreateScenario ( "AnotherScenario" , "Random Comment" , 13 , 1 , 1 , 1 , 1 )
163     sleep(1)
164     printlog "Edit / Sheet / Select"
165     EditSheetSelect
166     Kontext "SelectSheets"
167     printlog "Select 'Moves'"
168     SheetSelectionBox.Select "Moves"
169     printlog "OK"
170     SelectSheets.OK
171     sleep(1)
172     printlog "Type in Formula bar:"    
173     Kontext "RechenleisteCalc"
174     printlog "[CTRL+A]"
175     Bereich.TypeKeys "<MOD1 A>"
176     printlog "d5"
177     Bereich.TypeKeys "d5"
178     sleep(1)
179     printlog "[RETURN]"
180     Bereich.TypeKeys "<RETURN>"
181     sleep(1)
182     printlog "Type in spreadsheet document"
183     Kontext "DocumentCalc"
184     printlog "1[RETURN]2[RETURN]3[RETURN]"
185     DocumentCalc.typekeys "1<RETURN>2<RETURN>3<RETURN>"    
186     Kontext "RechenleisteCalc"
187     printlog "Type in Formula bar:"
188     printlog "[CTRL+A]"
189     Bereich.TypeKeys "<MOD1 A>"
190     printlog "d5:d7"
191     Bereich.TypeKeys "d5:d7"
192     sleep(1)
193     printlog "[RETURN]"
194     Bereich.TypeKeys "<RETURN>"
195     sleep(1)
196     printlog "Creat another scenario:"
197     subCreateScenario ( "標準" , "기본값" , 9 , 1 , 1 , 0 , 0 )
198     printlog "Scenario name: 標準"
199     printlog "Scenario comment: 기본값"
200     printlog "Color index: 9"
201     printlog "Display border checked"
202     printlog "Copy back checked"
203     printlog "Copy entire sheet unchecked"
204     printlog "Prevent changes unchecked"            
205     sleep(1)
206     '///<li>Create a another scenario on this selection</li>///
207     subCreateScenario ( "1标准9" , "2預設0" , 16 , 0 , 0 , 1 , 1 )
208     printlog "Scenario name: 1标准9"
209     printlog "Scenario comment: 2預設0"
210     printlog "Color index: 16"
211     printlog "Display border unchecked"
212     printlog "Copy back unchecked"
213     printlog "Copy entire sheet checked"
214     printlog "Prevent changes checked"            
215     sleep(1)        
216     printlog "Save in current default format"
217     if hFileSaveAsWithFilterKill ( sOutputFile , "calc8" ) = FALSE then
218        warnlog "Saving " & sOutputFile & " failed! -> Exiting test!"
219        call hCloseDocument
220     else
221        printlog "Close the document."
222        call hCloseDocument
223        sleep(3)       
224        printlog "Unpack storage of test document."
225        UnpackStorage( sOutputFile , sUnpackedStorageDir )
226        printlog "Read the test documents DOM."       
227        SAXReadFile( sContentXML )
228        sleep(2)       
229        printlog "Set the DOM pointer on element 'office:spreadsheet'"
230        printlog "|-/"
231        SAXSeekElement( "/" )
232        printlog "  |-office:document-content"
233        SAXSeekElement( "office:document-content" )
234        printlog "    |-office:body"
235        SAXSeekElement( "office:body" )
236        printlog "      |-office:spreadsheet"
237        SAXSeekElement( "office:spreadsheet" )       
238        printlog "For all tables check if they are scenarios"       
239        printlog "For those tables which are scenarios check correct attributes"
240        for iIndex = 1 to 7
241            printlog "        |-table:table"
242            SAXSeekElement( "table:table" , iIndex )
243            select case iIndex
244                   case 1 : subCheckScenarioInContentXML ( "Ten" , FALSE )
245                   case 2 : subCheckScenarioInContentXML ( _
246                            "Scenario_XML_Test" , TRUE , TRUE , "#000000" , TRUE , "false" , FALSE , "false" , _
247                            "Scenario_XML_Test.C3:Scenario_XML_Test.C5" , "Created by Peter Junge" )
248                   case 3 : subCheckScenarioInContentXML ( _
249                            "AnotherScenario" , TRUE , FALSE , "#ff0000" , FALSE , "false" , TRUE , "true" , _
250                            "AnotherScenario.C3:AnotherScenario.C5" , "Random Comment" )
251                   case 4 : subCheckScenarioInContentXML ( "Moves" , FALSE )
252                   case 5 : subCheckScenarioInContentXML ( _
253                            "標準" , TRUE , FALSE , "#c0c0c0" , FALSE , "false" , FALSE , "false" , _
254                            "標準.D5:標準.D7" , "기본값" )
255                   case 6 : subCheckScenarioInContentXML ( _
256                            "1标准9" , TRUE , TRUE , "#ffffff" , TRUE , "false" , TRUE , "true" , _
257                            "1标准9.D5:1标准9.D7" , "2預設0" )
258                   case 7 : subCheckScenarioInContentXML ( "Ahead" , FALSE )
259            end select           
260            SAXSeekElement( 0 )
261        next iIndex       
262        printlog "Check if too much sheets exist"
263        try 
264            SAXSeekElement( "table:table" , 8 )
265            warnlog "OOPS, it's expected to have only seven sheet but we got eight or more -> Check this out!"
266            SAXSeekElement( 0 )
267        catch           
268        endcatch
269     endif
270     SAXRelease
271 endcase
273 '---------------------------------------------------------------------------
275 sub subCreateScenario ( sScenarioName as STRING, _
276                         sComment as STRING, _
277                         iColorIndex as INTEGER, _
278                         bDisplayBorder as BOOLEAN, _
279                         bCopyBack as BOOLEAN, _
280                         bCopyEntireSheet as BOOLEAN, _
281                         bPreventChanges as BOOLEAN )
282         
283         printlog "tools / scenarios..."
284         ToolsScenarios
285         Kontext "SzenarioAnlegen"        
286         printlog "Set options as requested through arguments"
287         SzenarioName.SetText ( sScenarioName )
288         Kommentar.SetText ( sComment )
289         Rahmenfarbe.Select ( iColorIndex )
290         if bDisplayBorder then
291             RahmenAnzeigen.Check
292         else
293             RahmenAnzeigen.UnCheck
294         endif
295         if bCopyBack then
296             Zurueckkopieren.Check
297         else
298             Zurueckkopieren.UnCheck
299         endif
300         if bCopyEntireSheet then
301             GanzeTabelle.Check
302         else
303             GanzeTabelle.UnCheck
304         endif
305         if bPreventChanges then
306             PreventChanges.Check
307         else
308             PreventChanges.UnCheck
309         endif
310         printlog "OK"        
311         SzenarioAnlegen.OK
312         sleep(1)        
313 end sub
315 '---------------------------------------------------------------------------
317 sub subCheckScenarioInContentXML ( sTableName as STRING , _
318                                    bTableShouldBeScenario as BOOLEAN , _
319                                    optional bCheckDisplayBorder as BOOLEAN , _
320                                    optional sBorderColor as STRING , _
321                                    optional bCheckCopyBack as BOOLEAN , _
322                                    optional sCopyStyles as STRING , _
323                                    optional bCheckProtected as BOOLEAN , _
324                                    optional sIsActive as STRING , _
325                                    optional sScenarioRanges as STRING , _
326                                    optional sComment as STRING)
327                                    
328 '///<u><b>Check attibutes for scenarios in 'content.xml'</b></u>///
329 dim bTableIsScenario as BOOLEAN
330     bTableIsScenario = FALSE
331 '///<ul>
332     '///<li>Check correct table name</li>///                           
333     if SAXGetAttributeValue( "table:name" ) = sTableName then
334         printlog "Table name is as expected"
335     else
336         warnlog "Table name is " & SAXGetAttributeValue( "table:name" ) & " instead of " & sTableName
337     endif
338     '///<li>Find out if current table is a scenario</li>///
339     try 
340         SAXSeekElement( "table:scenario")
341         bTableIsScenario = TRUE
342         if bTableShouldBeScenario then
343             printlog "OK, this table is a scenario!"
344         else
345             warnlog "OOPS, this table shouldn't be a scenario -> Check this out!"
346         endif
347     catch
348         if bTableShouldBeScenario then
349             warnlog "OOPS, this table should be a scenario but it isn't -> Check this out!"
350         else
351             printlog "Right, this table isn't a scenario"
352         endif
353     endcatch
354     '///<li>Check scenario attributes</li>///
355     if bTableShouldBeScenario AND bTableIsScenario then
356         if bCheckDisplayBorder then 
357             if SAXGetAttributeValue ( "table:display-border" ) = "false" then
358                 printlog "OK, attribute 'table:display-border' has expected value: 'false'"
359             else
360                 warnlog "OOPS, attribute 'table:display-border' has unexpected value: " & SAXGetAttributeValue( "table:display-border" )
361             endif
362         else 
363             if SAXGetAttributeValue ( "table:display-border" ) <> "" then
364                 warnlog "OOPS, attribute 'table:display-border' shouldn't exist here"
365             endif
366         endif
368         if SAXGetAttributeValue( "table:border-color" ) = sBorderColor then
369             printlog "OK, attribute 'table:border-color' has expected value"
370         else
371             warnlog "OOPS, attribute 'table:border-color' has unexpected value: " & SAXGetAttributeValue( "table:border-color" )
372         endif
373         
374         if bCheckCopyBack then
375             if SAXGetAttributeValue( "table:copy-back" ) = "false" then
376                 printlog "OK, attribute 'table:copy-back' has expected value: 'false'"
377             else
378                 warnlog "OOPS, attribute 'table:copy-back' has unexpected value: " & SAXGetAttributeValue( "table:copy-back" )
379             endif
380         else 
381             if SAXGetAttributeValue ( "table:copy-back" ) <> "" then
382                 warnlog "OOPS, attribute 'table:copy-back' shouldn't exist here"
383             endif
384         endif
385         
386         if SAXGetAttributeValue( "table:copy-styles" ) = sCopyStyles then
387             printlog "OK, attribute 'table:copy-styles' has expected value"
388         else
389             warnlog "OOPS, attribute 'table:copy-styles' has unexpected value: " & SAXGetAttributeValue( "table:copy-styles" )
390         endif
391         
392         if bCheckProtected then
393             if SAXGetAttributeValue( "table:protected" ) = "true" then
394                 printlog "OK, attribute 'table:protected' has expected value: 'true'"
395             else
396                 warnlog "OOPS, attribute 'table:protected' has unexpected value: " & SAXGetAttributeValue( "table:protected" )
397             endif
398         else 
399             if SAXGetAttributeValue ( "table:protected" ) <> "" then
400                 warnlog "OOPS, attribute 'table:protected' shouldn't exist here"
401             endif
402         endif
404         if SAXGetAttributeValue( "table:is-active" ) = sIsActive then
405             printlog "OK, attribute 'table:is-active' has expected value"
406         else
407             warnlog "OOPS, attribute 'table:is-active' has unexpected value: " & SAXGetAttributeValue( "table:is-active" )
408         endif
410         if SAXGetAttributeValue( "table:scenario-ranges" ) = sScenarioRanges then
411             printlog "OK, attribute 'table:scenario-ranges' has expected value"
412         else
413             warnlog "OOPS, attribute 'table:scenario-ranges' has unexpected value: " & SAXGetAttributeValue( "table:scenario-ranges" )
414             qaErrorLog "Expected: " & sScenarioRanges
415         endif
417         if SAXGetAttributeValue( "table:comment" ) = sComment then
418             printlog "OK, attribute 'table:comment' has expected value"
419         else
420             warnlog "OOPS, attribute 'table:comment' has unexpected value: " & SAXGetAttributeValue( "table:comment" )
421             qaErrorLog "Expected: " & sComment
422         endif
423     else
424         printlog "Checking scenario details was skipped!"
425     endif
426     
427     if bTableIsScenario then
428         SAXSeekElement( 0 )
429     endif
430 '///</ul>
431 end sub