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 2008 by Sun Microsystems, Inc.
7 '* OpenOffice.org - a multi-platform office productivity suite
9 '* $RCSfile: t_docfuncs.inc,v $
13 '* last change: $Author: jsk $ $Date: 2008-06-20 07:57:47 $
15 '* This file is part of OpenOffice.org.
17 '* OpenOffice.org is free software: you can redistribute it and/or modify
18 '* it under the terms of the GNU Lesser General Public License version 3
19 '* only, as published by the Free Software Foundation.
21 '* OpenOffice.org is distributed in the hope that it will be useful,
22 '* but WITHOUT ANY WARRANTY; without even the implied warranty of
23 '* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 '* GNU Lesser General Public License version 3 for more details
25 '* (a copy is included in the LICENSE file that accompanied this code).
27 '* You should have received a copy of the GNU Lesser General Public License
28 '* version 3 along with OpenOffice.org. If not, see
29 '* <http://www.openoffice.org/license.html>
30 '* for a copy of the LGPLv3 License.
32 '/************************************************************************
34 '* owner : joerg.skottke@sun.com
36 '* short description : misc functions to handle documents
38 '\******************************************************************************
40 private const VERBOSE = FALSE
42 function hUseImpressAutopilot( bEnable as boolean ) as boolean
44 '///<h3>Enable/disable the Impress Autopilot in Tools/Options</h3>
45 '///<i>Starting point: Any plain document</i>
47 const CFN = "global::tools::includes::optional::t_docfuncs.inc::hUseImpressAutopilot::"
49 if ( VERBOSE ) then printlog( CFN & "Enter" )
51 '///+<li>Create a new IMPRESS document</li>
52 gApplication = "IMPRESS"
55 '///+<li>Open Tools/Options, go to Presentataion/General page</li>
57 hToolsOptions( gApplication , "General" )
59 '///+<li>Check or uncheck to start with autopilot</li>
60 Kontext "TabSonstigesDraw"
61 if ( mitAutopilotStarten.exists( 2 ) ) then
64 mitAutopilotStarten.check()
65 printlog( CFN & "Enable Impress Autopilot" )
67 mitAutopilotStarten.uncheck()
68 printlog( CFN & "Disable Impress Autopilot" )
71 '///+<li>Return Status of Checkbox (checked=TRUE)</li>
72 hUseImpressAutopilot() = mitAutopilotStarten.isChecked()
76 warnlog( CFN & "Cannot find Autopilot Checkbox" )
80 '///+<li>Close Tools/Options</li>
84 '///+<li>Close IMPRESS document</li>
87 '///+<li>Returncode is undefined</li>
88 if ( VERBOSE ) then printlog( CFN & "Exit" )
93 '*******************************************************************************
95 function hCloseNavigator() as boolean
97 '///<h3>Function to close the navigator</h3>
98 '///<i>Starting point: Any document</i>
100 const CFN = "global::tools::includes::optional::t_docfuncs.inc::hCloseNavigator::"
102 if ( VERBOSE ) then printlog( CFN & "Enter" )
104 '///+<li>close the navigator if found</li>
106 if ( Navigator.Exists() ) then
108 printlog( CFN & "Closed Navigator" )
110 printlog( CFN & "Navigator not present" )
113 '///+<li>verify that the navigator is indeed closed, return true on success</li>
115 if ( Navigator.exists() ) then
116 hCloseNavigator() = false
117 warnlog( CFN & "Failed to close Navigator, it is still open." )
119 hCloseNavigator() = true
122 if ( VERBOSE ) then printlog( CFN & "Exit" )
127 '*******************************************************************************
129 function hNumericDocType( doctype as integer ) as string
131 '///<h3>Convert a numeric expression to a gApplication</h3>
132 '///<i>BEWARE: This is a core function used by many testcases!</i><br>
133 '///<u>Using file: global/input/applications.txt as reference</u>
136 const CFN = "global::tools::includes::optional::t_docfuncs.inc::hNumericDocType::"
139 sFile = gTesttoolPath & "global\input\applications.txt"
140 sFile = convertpath( sFile )
142 dim sList( 100 ) as string
143 dim iDocTypes as integer
145 if ( VERBOSE ) then printlog( CFN & "Enter" )
147 '///+<li>Retrieve matching list from file</li>
148 hGetDataFileSection( sFile , sList() , "application" , "" , "" )
149 iDocTypes = val( sList( 0 ) )
151 '///+<li>Verify that the functionparameter (documenttype) is valid</li>
152 if ( ( doctype < 0 ) or ( doctype > iDocTypes ) ) then
153 warnlog( CFN & "Undefined numeric doctype: " & doctype )
154 hNumericDocType() = ""
158 '///+<li>Set gApplication to the requested document type</li>
159 gApplication = hGetValueForKeyAsString( sList() , doctype )
161 '///+<li>Set a plain text name as returnvalue for the function</li>
162 hGetDataFileSection( sFile , sList() , "application_names" , "" , "" )
163 hNumericDocType() = hGetValueForKeyAsString( sList() , gApplication )
164 if ( VERBOSE ) then printlog( CFN & "Exit" )
169 '*******************************************************************************
171 function hChangeDoc() as string
173 '///<h3>Function to modify all documenttypes to set the "changed" flag</h3>
174 '///<i>Starting point: Any plain document</i><br>
177 '///+<li>Nothing</li>
181 '///+<li>String, ready to use in printlog</li>
183 '///+<li>"Changed <Documenttype>"</li>
186 '///<u>Description</u>:
191 select case gApplication
193 '///+<li>WRITER: Type some text</li>
194 case "WRITER", "HTML", "MASTERDOCUMENT"
195 Kontext "DocumentWriter"
196 DocumentWriter.TypeKeys "<Return>This doc is changed!"
197 hChangeDoc() = "Changed WRITER/HTML/MASTERDOC"
199 '///+<li>CALC: Write some text into the current location (usually A1)</li>
200 case "CALC" : Kontext "DocumentCalc"
201 DocumentCalc.TypeKeys "<Down>This doc is changed!<Return>"
202 hChangeDoc() = "Changed CALC"
204 '///+<li>DRAW: Draw a rectangle</li>
205 case "DRAW" : Kontext "DocumentDraw"
206 hRechteckErstellen ( 20, 20, 25, 25 )
208 hChangeDoc() = "Changed DRAW"
210 '///+<li>IMPRESS: Draw a rectangle</li>
211 case "IMPRESS": Kontext "DocumentImpress"
212 hRechteckErstellen ( 20, 20, 25, 25 )
214 hChangeDoc() = "Changed IMPRESS"
216 '///+<li>MATH: Create a simple formaula</li>
217 case "MATH" : SchreibenInMathdok( "b over c" )
218 hChangeDoc() = "Changed MATH"
225 '*******************************************************************************
227 function hIdentifyWriterDoc( cString as string, bWarn as boolean ) as boolean
229 '///<h3>Function to validate that the expected WRITER doc has the focus</h3>
230 '///<i>Starting point: Any WRITER document containing some text</i>
233 use "global\tools\includes\optional\t_stringtools.inc"
235 const CFN = "global::tools::includes::optional::t_docfuncs.inc::hIdentifyWriterDoc::"
236 dim cIdentifier as string
237 dim irc as integer ' some temporary returnvalue
239 if ( VERBOSE ) then printlog( CFN & "Enter" )
241 '///+<li>Test the function parameter</li>
242 if ( cString = "" ) then
243 qaerrorlog( CFN & "Function parameter is empty string. Aborting" )
244 hIdentifyWriterDoc() = false
248 '///+<li>Verify function prerequisites</li>
249 kontext "DocumentWriter"
250 if ( not DocumentWriter.exists() ) then
251 printlog( CFN & "There is no Writer document. Aborting" )
252 hIdentifyWriterDoc() = false
256 hIdentifyWriterDoc() = true
258 '///+<li>Go to the very beginning of the current writer document</li>
259 kontext "DocumentWriter"
260 DocumentWriter.typeKeys( "<MOD1 HOME>" )
262 '///+<li>Select the entire line</li>
263 DocumentWriter.typeKeys( "<SHIFT END>" )
265 '///+<li>copy the string to the clipboard and store it into a variable</li>
268 cIdentifier = getClipboardText()
270 warnlog( "EditCopy failed. Probably the document is empty" )
271 cIdentifier = "**** invalid ****"
275 '///+<li>compare the string to the reference (given as parameter)</li>
276 irc = hCompareSubstrings( cIdentifier, cString )
278 '///+<li>Write the result to the printlog if desired</li>
282 warnlog ( CFN & "The focus is not on the expected document" )
284 printlog( CFN & "The focus is not on the expected document" )
287 printlog( CFN & "Expected: " & cString )
288 printlog( CFN & "Found...: " & cIdentifier )
289 hIdentifyWriterDoc() = false
292 printlog( CFN & "OK: The document contains the requested string" )
294 '///+<li>Return TRUE only if the current document is the expected one</li>
296 if ( VERBOSE ) then printlog( CFN & "Exit" )
301 '*******************************************************************************
303 function hCreateDocument() as boolean
305 '///<h3>Create anew document, extends hNewDocument()</h3>
306 '///<i>Starting point: Any document</i><br>
307 '///<i>Note: When calling this function with gApplication "BACKGROUND" the
308 '///+ function will actually close one document to get to the backing window</i><br>
311 '///+<li>Nothing, valid gApplication must be set</li>
315 '///+<li>Errorstatus (boolean)</li>
317 '///+<li>TRUE if a new document was created successfully</li>
318 '///+<li>FALSE if anything went wrong</li>
321 '///<u>Description</u>:
325 const CFN = "global::tools::includes::optional::t_docfuncs.inc::hCreateDocument::"
327 dim iDocCountBefore as integer
328 dim iDocCountAfter as integer
330 '///+<li>Retrieve the number of open documents</li>
331 iDocCountBefore = getDocumentCount
332 if ( VERBOSE ) then printlog( CFN & "Number of open documents before: " & iDocCountBefore )
334 '///+<li>Special treatment if gApplication = BACKGROUND (virtual gApplication)</li>
335 if ( ucase( gApplication ) = "BACKGROUND" ) then
336 do while( getDocumentCount > 0 )
339 hCreateDocument() = true
342 '///+<li>Open a new document using hNewDocument()</li>
345 '///+<li>Retrieve the number of open documents</li>
346 iDocCountAfter = getDocumentCount()
348 '///+<li>Verify that there is exactly one more document than before</li>
349 if ( iDocCountAfter = ( iDocCountBefore + 1 ) ) then
350 hCreateDocument() = true
352 hCreateDocument() = false
355 printlog( CFN & "New document created. Open: " & iDocCountAfter )
360 '*******************************************************************************
362 function hDocumentTypeKeys( cString as string ) as boolean
364 '///<h3>Type a string to a document</h3>
365 '///<i>The documenttype is determined by gApplication.<br>
366 '///See hNumericDocType for details and number/gApplication matching</i><br>
369 '///+<li>Keystrokes to be sent to the document (string), e.g.</li>
371 '///+<li>"<SHIFT HOME>"</li>
372 '///+<li>"<MOD1 A>"</li>
373 '///+<li>"<MOD2 Q>"</li>
374 '///+<li>"Hello"</li>
379 '///+<li>Errorstatus (boolean)</li>
381 '///+<li>TRUE if all went well</li>
382 '///+<li>FALSE on any error</li>
385 '///<u>Description</u>:
388 const CFN = "global::tools::includes::optional::t_docfuncs.inc::hDocumentTypeKeys::"
392 if ( VERBOSE ) then printlog( CFN & "Enter" )
394 '///+<li>Set focus to the current documenttype determined by gApplication</li>
395 '///+<li>Type the string passed as function parameter</li>
396 select case gApplication
397 case "WRITER" : kontext "DocumentWriter"
398 DocumentWriter.typeKeys( cString )
399 case "CALC" : kontext "DocumentCalc"
400 DocumentCalc.typeKeys( cString )
401 case "IMPRESS" : kontext "DocumentImpress"
402 DocumentImpress.typeKeys( cString )
403 case "DRAW" : kontext "DocumentDraw"
404 DocumentDraw.typeKeys( cString )
405 case "MATH" : kontext "DocumentMath"
406 DocumentMath.typeKeys( cString )
407 case "MASTERDOCUMENT": kontext "DocumentWriter"
408 DocumentWriter.typeKeys( cString )
409 case "HTML" : kontext "DocumentWriter"
410 DocumentWriter.typeKeys( cString )
412 warnlog( CFN & "Exit: Unknown gApplication: " & gApplication )
416 '///+<li>Print some message to the log on success</li>
418 printlog( CFN & "Exit: Sent keystroke to " & gApplication )
421 hDocumentTypeKeys() = brc
427 '*******************************************************************************
429 function hDestroyDocument() as boolean
431 const CFN = "global::tools::includes::optional::t_docfuncs.inc::hDestroyDocument: "
432 dim iDocCount as integer : iDocCount = getDocumentCount()
433 hDestroyDocument() = false
435 if ( iDocCount = 0 ) then exit function
436 if ( VERBOSE ) then printlog( CFN & "In.: Open: " & iDocCount )
438 hUseAsyncSlot( "FileClose" )
441 if ( Active.Exists( 2 ) ) then
442 printlog( "Msgbox: " & Active.getText() )
451 if ( getDocumentCount() = iDocCount ) then hCloseDocument()
452 if ( getDocumentCount() = iDocCount - 1 ) then hDestroyDocument() = true
453 if ( VERBOSE ) then printlog( CFN & "Out: Open: " & getDocumentCount() )
457 '*******************************************************************************
459 function hInitSingleDoc() as boolean
461 '///<h3>Make sure exactly one single writer document is open</h3>
462 '///<i>The wizards cannot be triggered correctly from the backing window.
463 '///+ As a workaround this function checks the amount of open documents and
464 '///+ creates exactly one unchanged Writer document</i><br><br>
466 '///<u>Parameter(s):</u><br>
468 '///+<li>No input parameters</li>
472 '///<u>Returns:</u><br>
474 '///+<li>Errorcondition (Boolean)</li>
476 '///+<li>TRUE: Exactly one Writer document is open</li>
477 '///+<li>FALSE: Any error</li>
481 const CFN = "global::tools::includes::optional::t_docfuncs.inc::hInitSingleDoc::"
482 dim cOldApplication as string
484 '///<u>Description:</u>
486 '///+<li>Close all documents until we are on the backing window</li>
487 do while ( getDocumentCount > 0 )
488 call hCloseDocument()
491 '///+<li>Save the previous gApplication</li>
492 cOldApplication = gApplication
494 '///+<li>Set gApplication to WRITER</li>
495 gApplication = "WRITER"
497 '///+<li>Open one new Writer document</li>
500 '///+<li>Verify that exactly one document is open</li>
501 if ( getDocumentCount = 1 ) then
502 printlog( CFN & "A single unchanged writer document is open" )
503 hInitSingleDoc() = true
505 printlog( CFN & "Failed to open just one single writer document" )
506 hInitSingleDoc() = false
509 '///+<li>Restore gApplication</li>
510 gApplication = cOldApplication
515 '*******************************************************************************
517 function hInitBackingMode() as boolean
519 '///<h3>Make that we are on the backing window (no open documents)</h3>
520 '///<i>Close all open documents</i><br><br>
522 '///<u>Parameter(s):</u><br>
524 '///+<li>No input parameters</li>
528 '///<u>Returns:</u><br>
530 '///+<li>Errorcondition (Boolean)</li>
532 '///+<li>TRUE: No open documents are present</li>
533 '///+<li>FALSE: Any error</li>
537 const CFN = "global::tools::includes::optional::t_docfuncs.inc::hInitBackingMode::"
539 '///<u>Description:</u>
541 '///+<li>Close all documents until we are on the backing window</li>
542 do while ( getDocumentCount > 0 )
546 '///+<li>verify that we do not have any open documents left (redundant check)</li>
547 if ( getDocumentCount = 0 ) then
548 printlog( CFN & "Office is in backing mode." )
549 hInitBackingMode() = true
551 printlog( CFN & "Office is in undefined state." )
552 hInitBackingMode() = false
558 '*******************************************************************************
560 function hInitWriteDocIdentifier( cString as string ) as boolean
563 '///<h3>Write a specific string to an open writer document</h3>
564 '///<i>This function verifies that exactly one document is open, that this is a
565 '///+ Writer document and writes the string to the document</i><br><br>
567 '///<u>Parameter(s):</u><br>
570 '///+<li>A free form string (String) which serves as identifier for the document</li>
572 '///+<li>The first character should be uppercase</li>
578 '///<u>Returns:</u><br>
580 '///+<li>Errorcondition (Boolean)</li>
582 '///+<li>TRUE: The string was written correctly</li>
583 '///+<li>FALSE: Too many open documents</li>
584 '///+<li>FALSE: Not a Writer document</li>
585 '///+<li>FALSE: Any other error</li>
589 const CFN = "global::tools::includes::optional::t_docfuncs.inc::hInitWriteDocIdentifier::"
591 '///<u>Description:</u>
593 '///+<li>Verify number of open documents</li>
594 if ( getDocumentCount <> 1 ) then
595 printlog( CFN & "Incorrect document count" )
596 hInitWriteDocIdentifier() = false
600 '///+<li>Verify that it is a writer document</li>
601 kontext "DocumentWriter"
602 if ( not DocumentWriter.exists() ) then
603 printlog( CFN & "Open document is not a text document" )
604 hInitWriteDocIdentifier() = false
608 '///+<li>Write the string</li>
609 kontext "DocumentWriter"
610 DocumentWriter.typeKeys( "<MOD1 END>" )
611 DocumentWriter.typeKeys( "<MOD1 SHIFT HOME>" )
612 DocumentWriter.typeKeys( "<DELETE>" )
613 DocumentWriter.typekeys( cString )
615 '///+<li>Verify the string</li>
616 DocumentWriter.typeKeys( "<MOD1 END>" )
617 DocumentWriter.typeKeys( "<MOD1 SHIFT HOME>" )
619 if ( getClipboardText = cString ) then
620 printlog( CFN & "Document has been successfully modified." )
621 hInitWriteDocIdentifier() = true
623 printlog( CFN & "Could not verify document identification string" )
624 hInitWriteDocIdentifier() = false