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 : gregor.hartmann@oracle.com
30 '* short description : check the internal file dialog ( extended tests )
32 '\******************************************************************************
34 function hSaveLoadDelSuccess( cFile as string ) as integer
36 '///<h3>Successfully save, close, load, close and delete a file</h3>
37 '///<i>Uses</i>: framework\tools\t_stringtools.inc<br><br>
40 '///+<li>Filename incl. extension (string)</li>
44 '///+<li>Errorcode (integer)</li>
46 '///+<li>0 = all ok</li>
47 '///+<li>1 = Saving failed</li>
48 '///+<li>2 = Closing the file failed</li>
49 '///+<li>3 = Reloading failed</li>
50 '///+<li>4 = Closing the file failed</li>
51 '///+<li>5 = Deleting failed</li>
52 '///+<li>-1 = Post operation error</li>
55 '///<u>Description</u>:
59 dim cFileExt as string : cFileExt = cFile & hGetSuffix( "current" )
61 const CFN = "hSaveLoadDelSuccess::"
64 printlog( CFN & "Enter with option: " & cFile & "/" & cFileExt )
66 '///+<li>Close the navigator if it exists</li>
68 hCloseDialog( Navigator, "close,optional" )
70 '///+<li>Save the current file, overwriting existing</li>
71 brc = hSaveFileExpectSuccess( cFile , TRUE ) ' save and overwrite
74 '///+<li>Close the file</li>
75 brc = hDestroyDocument()
78 '///+<li>Reload the file</li>
79 brc = hLoadFileExpectSuccess( cFileExt )
82 '///+<li>Close the document</li>
83 brc = hDestroyDocument()
86 '///+<li>Delete the file via FileOpen</li>
87 brc = hDeleteFileViaFileOpen( cFileExt )
89 printlog( CFN & "Save, close, load, close, delete ok" )
90 hSaveLoadDelSuccess() = 0
92 warnlog( CFN & "Failed to delete file" )
93 hSaveLoadDelSuccess() = 5
97 warnlog( CFN & "Failed to close file" )
98 hSaveLoadDelSuccess() = 4
102 warnlog( CFN & "Failed to load file" )
103 hSaveLoadDelSuccess() = 3
108 warnlog( CFN & "Closing file failed" )
109 hSaveLoadDelSuccess() = 2
113 warnlog( CFN & "Saving failed" )
114 hSaveLoadDelSuccess() = 1
117 '///+<li>Close possible Messagebox (#i33946#)</li>
119 if ( active.exists( 1 ) ) then
120 printlog( CFN & "Unexpected message: " & active.getText() )
121 qaerrorlog( "#i33946# - message when deleting last document in folder" )
123 hSaveLoadDelSuccess() = 6
126 '///+<li>Close document</li>
127 brc = hDestroyDocument()
133 '*******************************************************************************
135 function hLoadFileExpectSuccess( fpath as string ) as boolean
137 '///<h3>Load a file where failure is expected</h3>
138 '///<i>Uses</i>: framework\tools\t_stringtools.inc<br><br>
139 '///<i>This function is quite similar to hLoadFile but does much less
140 '///+ errorhandling so the information of the type of failure is a little
141 '///+ more exact</i><br><br>
144 '///+<li>Filename incl. extension (string)</li>
148 '///+<li>Errorcondition (boolean)</li>
150 '///+<li>TRUE = File was loaded without problems</li>
151 '///+<li>FALSE = Any error</li>
154 '///<u>Description</u>:
157 dim brc as boolean : brc = true
159 const CFN = "hLoadFileExpectSuccess::"
160 printlog( CFN & "Enter with option: " & fpath )
162 '///+<li>Click FileOpen (or use the menu)</li>
163 hUseAsyncSlot( "FileOpen" )
165 '///+<li>Enter the filename (with extension)</li>
166 'printlog( " - Type the filepath/name into the entryfield" )
168 if ( OeffnenDlg.exists( 1 ) ) then
169 DateiName.setText( fpath )
171 '///+<li>Click "Open"</li>
172 'printlog( " - Click 'Open'" )
175 '///+<li>Watch out for an unexpected messagebox<br>
177 if ( Active.Exists( 1 ) ) then
178 printlog( "Unexpected active: " & active.getText() )
186 '///+recover in case of error so the test has a chance to continue</li>
187 ' try to recover in case of failure so the test can continue.
189 if ( Oeffnen.exists( 1 ) ) then
190 warnlog( "The file was not opened, it doesn't appear to exist" )
195 warnlog( CFN & "File Open dialog did not open" )
198 '///+<li>Return the errorcode</li>
199 printlog( CFN & "Exit with result: " & brc )
200 hLoadFileExpectSuccess() = brc
205 '*******************************************************************************
207 function hSaveFileExpectSuccess( fpath as string , bReplace as boolean ) as boolean
209 '///<h3>Save a file with optional replace where success is expected</h3>
210 '///<i>Uses</i>: framework\tools\t_stringtools.inc<br><br>
213 '///+<li>Filename incl. extension (string)</li>
214 '///+<li>Replace file (boolean)</li>
216 '///+<li>TRUE = Replace the file</li>
217 '///+<li>FALSE = Do not replace the file</li>
222 '///+<li>Errorcondition (boolean)</li>
224 '///+<li>TRUE = There was an error loading the file (as expected)</li>
225 '///+<li>FALSE = The file was loaded without problems/any other error</li>
228 '///<u>Description</u>:
231 const CFN = "hSaveFileExpectSuccess::"
232 dim brc as boolean : brc = true
234 dim iDocumentCount as integer
236 printlog( CFN & "Enter with options: " & fpath & ", " & bReplace )
238 '///+<li>Make sure we start from the backing window</li>
242 '///+<li>Open a new document</li>
245 '///+<li>Click "Save As..."</li>
246 hUseAsyncSlot( "FileSaveAs" )
248 Kontext "SpeichernDlg"
249 if ( SpeichernDlg.exists( 1 ) ) then
251 '///+<li>Enter a filename (with extension)</li>
252 Dateiname.setText( hGetWorkPath() & fpath )
254 '///+<li>Click "Save"</li>
257 '///+<li>If the file exists, say "yes" to replace it</li>
260 if ( active.exists( 2 ) ) then
261 printlog( CFN & "Overwriting file" )
262 printlog( "Message: " & active.getText() )
266 warnlog( CFN & "Unexpected active - no YES button available." )
267 printlog( CFN & "if any this should have been overwrite warning." )
272 '///+<li>Handle any unexpected errormessage with "OK"</li>
274 if ( active.exists( 2 ) ) then
275 printlog( CFN & "Unexpected active: " & active.getText() )
280 '///+<li>The FileSave dialog should be closed at this point</li>
281 kontext "SpeichernDlg"
282 if ( SpeichernDlg.exists( 1 ) ) then
283 warnlog( CFN & "File Save dialog is still open, it should be closed" )
284 SpeichernDlg.cancel()
287 warnlog( CFN & "Failed to open File Open dialog" )
291 '///+<li>Verify that exactly one document is open</li>
292 if( getDocumentCount <> 1 ) then
293 warnlog( CFN & "Incorrect number of open documents" )
297 printlog( CFN & "Exit with result: " & brc )
298 hSaveFileExpectSuccess() = brc
303 '*******************************************************************************
305 function hSaveFileExpectFailure( fpath as string , errortype as integer ) as boolean
307 '///<h3>Save a file where failure is expected</h3>
308 '///<i>Uses</i>: framework\tools\t_stringtools.inc<br><br>
311 '///+<li>Filename incl. extension (string)</li>
312 '///+<li>Errortype (Integer). Valid options are:</li>
314 '///+<li>0 = Invalid characters in string</li>
315 '///+<li>1 = Filename is interpreted as device</li>
320 '///+<li>Errorcondition (boolean)</li>
322 '///+<li>TRUE = <b><i>There was an error saving the file (as expected)</i></b></li>
323 '///+<li>FALSE = The file was saved without problems/any other error</li>
326 '///<u>Description</u>:
329 ' currently we have two different kinds of failure
330 ' 1. File cannot be saved due to invalid character(s)
331 ' This is errortype = 0
332 ' 2. File cannot be saved because the given name is interpreted as device
333 ' This is errortype = 1
334 ' This sequence tries to save a document with an invalid name. The errormsg
335 ' is closed, the filedialog cancelled and the file closed.
337 dim brc as boolean : brc = false
341 const CFN = "hSaveFileExpectFailure::"
343 '///+<li>Open an new document</li>
346 '///+<li>Click "Save As;"</li>
348 printlog( CFN & "Enter with options: " & fpath & ", " & errortype )
349 hUseAsyncSlot( "FileSaveAs" )
351 '///+<li>Enter the filename</li>
352 kontext "SpeichernDlg"
353 if ( SpeichernDlg.exists( 1 ) ) then
355 Kontext "SpeichernDlg"
356 Dateiname.setText( fpath )
358 '///+<li>Click "Save"</li>
362 '///+<li>Handle invalid characters (Errormessages)</li>
363 select case( errortype )
369 if ( Active.exists( 1 ) ) then
371 printlog( CFN & "Check for possible overwrite warning..." )
374 printlog( CFN & "Closed Messagebox with <YES>" )
375 printlog( CFN & "This was the overwrite warning" )
381 if ( Active.exists( 1 ) ) then
382 cMsg = active.getText()
385 printlog( CFN & "Closed Save-Failure warning with <OK>" )
388 qaerrorlog( CFN & "Unknown dialog encountered, <OK> failed:" )
397 if ( Active.exists( 1 ) ) then
398 printlog( CFN & "Expected active: " & active.getText() )
401 Kontext "SpeichernDLG"
402 if ( SpeichernDlg.exists( 1 ) ) then
403 SpeichernDLG.cancel()
406 warnlog( CFN & "File Save dialog is missing. Bad!" )
410 warnlog( CFN & "Errormessage for '/', '\' or ':' is missing" )
417 warnlog( CFN & "Failed to open File Save dialog" )
421 '///+<li>Close the document</li>
424 '///+<li>Return errorcondition</li>
425 printlog( CFN & "Exit with status: " & brc )
426 hSaveFileExpectFailure() = brc
432 '*******************************************************************************
434 function hDeleteFileViaFileOpen( cFile as String ) as boolean
436 '///<h3>Delete a file using the File Open dialog</h3>
437 '///<i>Uses</i>: framework\tools\t_stringtools.inc<br><br>
440 '///+<li>Filename incl. extension (string)</li>
444 '///+<li>Errorcondition (boolean)</li>
446 '///+<li>TRUE = File was deleted</li>
447 '///+<li>FALSE = Any other condition</li>
450 '///<u>Description</u>:
453 ' This sub deletes a file by name. No errors or warnings are expected.
454 ' if everything goes well, we're back to the originating document after
457 dim iSelectedFilePosition as integer
460 const CFN = "hDeleteFileViaFileOpen::"
461 printlog( CFN & "Enter with option: " & cFile )
463 ' Test for wildcards - the dialog cannot handle those
464 if ( instr( cFile , "?" ) <> 0 ) then
465 warnlog( CFN & "Incorrect call to function, wildcards are not allowed" )
466 hDeleteFileViaFileOpen() = false
470 ' Test for wildcards - the dialog cannot handle those
471 if ( instr( cFile , "*" ) <> 0 ) then
472 warnlog( CFN & "Incorrect call to function, wildcards are not allowed" )
473 hDeleteFileViaFileOpen() = false
477 '///+<li>Click "File Open"</li>
478 hUseAsyncSlot( "FileOpen" )
480 '///+<li>Look for the requested file, get the position from the filelist</li>
482 iSelectedFilePosition = hFindFileObjectViaFileOpen( cFile )
484 '///+<li>If the file exists, delete it + verify, if not: Warn and exit</li>
485 if ( iSelectedFilePosition > 0 ) then
488 'printlog( CFN & "Requested file: " & cFile )
489 'printlog( CFN & "Object is at..: " & iSelectedFilePosition )
490 'printlog( CFN & "Object name is: " & DateiAuswahl.getSelText() )
492 DateiAuswahl.TypeKeys( "<DELETE>" )
494 ' Confirm deletion. This dialog should always pop up when deleting
495 Kontext "ConfirmDelete"
496 if ( ConfirmDelete.exists( 1 ) ) then
498 printlog( CFN & "Deleted file: " & cFile )
500 warnlog( CFN & "Messagebox to confirm deletion of file is missing" )
503 ' Handle possible Warnings/Errormessages. If no errors happen,
504 ' verify that the file has been deleted. Note that this dialog will not
505 ' change the returnvalue.
507 if( Active.exists( 1 ) ) then
508 warnlog( CFN & "Unexpected active: " & active.getText() )
512 ' Verify that the file does no longer exist in the filelist.
513 iSelectedFilePosition = hFindFileObjectViaFileOpen( cFile )
514 if ( iSelectedFilePosition = 0 ) then
523 warnlog( CFN & "File not found in workdir: " & cFile )
527 '///+<li>Cancel the FileOpen dialog</li>
531 '///+<li>Return errorcondition</li>
532 printlog( CFN & "Exit with result: " & brc )
533 hDeleteFileViaFileOpen() = brc
539 '*******************************************************************************
541 function hNameGen_append( iDecChar as long ) as string
543 '///<h3>Create a filename with specified character at the end</h3>
546 '///+<li>Character as number (integer)</li>
548 '///+<li>Only positive numbers are allowed</li>
549 '///+<li>Respect integer boundaries</li>
554 '///+<li>A filename containing a special character at the end (before suffix)</li>
556 '///<u>Description</u>:
560 const CFN = "hNameGen_append::"
562 '///+<li>Create a string "test", append ascii char</li>
563 cFile = "test" & CHR$( iDecChar )
564 printlog( CFN & "ASCII " & iDecChar & " appended, len = " & len( cFile ) )
565 if ( len( cFile ) <> 5 ) then
566 warnlog( CFN & "Character not appended" )
569 '///+<li>Return the new filename</li>
570 hNameGen_append() = cFile
576 '*******************************************************************************
578 function hNameGen_lead( iDecChar as long ) as string
580 '///<h3>Create a filename with specified character at the beginning</h3>
583 '///+<li>Character as number (integer)</li>
585 '///+<li>Only positive numbers are allowed</li>
586 '///+<li>Respect integer boundaries</li>
591 '///+<li>A filename containing a special character at the beginning</li>
593 '///<u>Description</u>:
597 const CFN = "hNameGen_lead::"
599 '///+<li>Create a string beginning with ascii char and append "test"</li>
600 cFile = CHR$( iDecChar ) & "test"
601 printlog( CFN & "ASCII " & iDecChar & " prepended, len = " & len( cFile ) )
602 if ( len( cFile ) <> 5 ) then
603 warnlog( CFN & "Character not prepended" )
606 '///+<li>Return the new filename</li>
607 hNamegen_lead() = cFile
613 '*******************************************************************************
615 function hFindFileObjectViaFileOpen( cName as string ) as integer
617 '///<h3>Get the position of a filesystem object in filelist of fileopen dialog</h3>
618 '///<i>Note that the filepicker must be open in order to use this function.<br>
619 '///The object with the given name is selected when leaving the function.</i><br>
622 '///+<li>Filename incl. extension (string) but without any pathseparator</li>
626 '///+<li>Position of the object in the filepicker list</li>
628 '///+<li>0: Object not found</li>
629 '///+<li>> 0: Position</li>
632 '///<u>Description</u>:
635 const CFN = "hFindFileObjectViaFileOpen::"
637 dim iCurrentObject as integer
638 dim cCurrentName as string
639 dim iFileOpenItemCount as integer
641 dim iPos as integer : iPos = 0
642 dim cPath as string : cPath = cName
644 dim iPathItems as integer
645 dim asPathList( 100 ) as string
647 dim iWait as integer ' some increment variable
649 printlog( CFN & "Enter with option (File): " & cName )
651 '///+<li>If a fully qualified path has been provided we have to split it up</li>
652 iPathItems = DirNameList( cPath, asPathList() )
653 'printlog( CFN & "iPathItems (new): " & iPathItems )
655 if ( iPathItems > 3 ) then
656 cName = asPathList( iPathItems )
657 printlog( CFN & "CNAME from plist: " & cName )
659 '///+<li>And walk to the directory</li>
660 cPath = left( cPath , ( len ( cPath ) - len( cName ) ) - 1 )
661 printlog( CFN & "CPATH from plist: " & cPath )
664 if ( OeffnenDlg.exists( 1 ) ) then
665 Dateiname.setText( cPath )
668 warnlog( CFN & "File Open dialog is not open" )
669 hFindFileObjectViaFileOpen() = 0
674 '///+<li>get the number of items in the filepicker</li>
677 while ( DateiAuswahl.getItemCount() = 0 )
680 if ( iWait = 10 ) then
681 warnlog( "Filepicker is not populated within reasonable timeframe, aborting" )
684 hFindFileObjectViaFileOpen() = 0
687 printlog( "Waiting for filepicker list to populate..." )
691 iFileOpenItemCount = DateiAuswahl.getItemCount()
693 '///+<li>Jump to the first item in the filelist and select it with SPACE</li>
694 DateiAuswahl.typeKeys( "<HOME>" )
695 DateiAuswahl.typeKeys( "<SPACE>" )
697 '///+<li>Navigate through the list until we find the requested object</li>
698 for iCurrentObject = 1 to iFileOpenItemCount
700 cCurrentName = DateiAuswahl.getSelText()
702 if ( cCurrentName = cName ) then
703 iPos = iCurrentObject
707 DateiAuswahl.typeKeys( "<DOWN>" )
711 '///+<li>Print some info to the log</li>
713 printlog( CFN & "Exit: Found item [" & cName & "] at pos: " & iPos )
715 printlog( CFN & "Exit: Requested item [" & cName & "] was not found." )
718 '///+<li>return the position or 0 on failure</li>
719 hFindFileObjectViaFileOpen() = iPos