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: extras_file_open.inc,v $
13 '* last change: $Author: rt $ $Date: 2008-09-04 09:15:59 $
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 : Perform standard operations on all samples/templates etc.
38 '\***********************************************************************
40 private const MAX_FILE_COUNT = 3000 ' the max number of templates or samples
42 ' NOTE: Usually we have only about a 100 templates but in multi-language
43 ' installations there are more than 2100. You should not run these
44 ' tests on multi language installations. Really.
46 testcase tOpenObjectsWithFileDialog( cCategory as string )
48 const CFN = "tOpenObjectsWithFileDialog::"
50 '///<h1>Open all templates using the File-Open dialog</h1>
51 '///<i>Retrieve the templates out of ..\share\template\-directory</i><br>
54 dim lsFile ( MAX_FILE_COUNT ) as String ' list of all files below samples or templates
55 dim sRootPath as String ' rootpath, depends on cCategory
56 dim sRootPathFallback as string
60 dim sFileIn as String ' file to open
61 dim sFileOut as string ' file to save, reload, delete
62 dim sPathOut as string
63 sPathOut = hGetWorkPath()
64 dim sExtension as String ' filter: determines whether to test the file
66 dim iCurrentTemplate as Integer ' increment: current template from lsFile()
67 dim iTemplateCount as integer
69 dim bSkipFile as boolean ' turns true if file is to be skipped
70 dim brc as boolean ' some multi purpose boolan returncode
71 dim cOfficePath as string
73 ' the path where the samples/templates are located, verify function params
74 ' note that for some time the suffixes for the different filetypes are changed,
75 ' so we have separate names for samples and templates.
77 if ( FileExists( gOfficeBasisPath ) ) then
78 cOfficePath = gOfficeBasisPath
80 cOfficePath = mid( gOfficeBasisPath, len( gNetzOfficePath ) + 1 )
82 printlog( "Using: " & cOfficePath )
85 case "SAMPLES" : sRootPath = cOfficePath & "share\samples\" & gISOLang
86 sRootPathFallback = "/opt/openoffice.org/basis3.0/share/samples/" & gISOLang
88 case "TEMPLATES" : sRootPath = cOfficePath & "share\template\" & gISOLang
89 sRootPathFallback = "/opt/openoffice.org/basis3.0/share/template/" & gISOLang
92 warnlog( CFN & "Invalid category passed to function" )
96 sRootPath = convertpath( sRootPath )
98 '///+<li>Get the complete list of all files below templates/samples</li>
99 if ( dir( sRootPath ) = "" ) then
100 qaerrorlog( "Root Path does not exist: " & sRootPath )
101 sRootPath = sRootPathFallback
102 if ( dir( sRootPathFallback ) = "" ) then
103 warnlog( "No usable office root path found. Aborting test" )
105 printlog( "Using hard coded fallback" )
109 printlog( "Using path..: " & sRootPath )
110 printlog( "Using filter: " & sFilter )
111 GetAllFileList ( sRootPath, sFilter, lsFile() )
112 hListDelete( lsFile(), 1 )
115 iTemplateCount = listCount( lsFile() )
117 while( iCurrentTemplate <= iTemplateCount )
118 if ( instr( lsFile( iCurrentTemplate ), "~lock." ) > 0 ) then
119 hListDelete( lsFile(), iCurrentTemplate )
120 iTemplateCount = iTemplateCount - 1
122 iCurrentTemplate = iCurrentTemplate + 1
126 ' do not test wizard related files
127 iTemplateCount = listCount( lsFile() )
129 while( iCurrentTemplate <= iTemplateCount )
130 if ( instr( lsFile( iCurrentTemplate ), "wizard" ) > 0 ) then
131 hListDelete( lsFile(), iCurrentTemplate )
132 iTemplateCount = iTemplateCount - 1
134 iCurrentTemplate = iCurrentTemplate + 1
138 hListPrint ( lsFile() , "" , "" )
139 if ( listcount( lsfile() ) = 1 ) then
140 if ( gProductName = "OpenOffice.org" ) then
141 printlog( gProductName & " comes with no samples, skipping" )
144 warnlog( "Filelist seems to be incomplete. GetAllFileList() failed!" )
149 '///+<li>Go through the list of samples/templates and do things</li>
151 iTemplateCount = listCount( lsFile() )
152 for iCurrentTemplate = 1 to iTemplateCount
155 printlog( "Loading file " & iCurrentTemplate & " of " & iTemplateCount )
157 ' sFileIn holds the file we currently work with
158 sFileIn = lsFile( iCurrentTemplate )
160 '///+<li>Load the file</li>
161 brc = hFileOpen( sFileIn )
162 brc = hHandleActivesOnLoad( 0 , 2 )
164 '///+<li>Cancel the filterdialog if present -> bug</li>
165 Kontext "FilterAuswahl"
166 if ( FilterAuswahl.exists( 1 ) ) then
167 warnlog( "Loading failed, ASCII filter dialog present" )
168 FilterAuswahl.cancel()
169 while( getDocumentCount > 0 )
174 '///+<li>Close the navigator if present</li>
175 brc = hCloseNavigator()
178 sFileOut = cCategory & "_" & iCurrentTemplate
179 sFileOut = convertpath( sPathOut & sFileOut )
181 '///+<li>Save the file, use autoextension</li>
182 brc = hFileSaveAsKill( sFileOut )
184 '///+<li>Close possible dialogs like "Update links" etc.</li>
185 ' note: this is delayed, because the dialogs take time to pop up
186 ' even while the dialog is visible, we can work with the doc.
187 brc = hHandleInitialDialogs()
189 '///+<li>Close the document</li>
190 brc = hDestroyDocument()
192 '///+<li>Load the file, close the navigator if present</li>
193 brc = hFileOpen( sFileOut )
194 brc = hHandleActivesOnLoad( 0 , 2 )
195 brc = hCloseNavigator()
197 '///+<li>Close the file</li>
198 brc = hDestroyDocument()
202 '///+<li>Delete the file</li>
203 brc = hDeleteFile( sFileOut )
206 next iCurrentTemplate