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: spadmin_tools.inc,v $
13 '* last change: $Author: jsi $ $Date: 2008-06-16 12:19:06 $
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 : helper functions for SPAdmin
38 '\******************************************************************************
40 function hGetPrinterPosition( cName as string, bWarn as boolean ) as integer
42 '///<h3>Find a printer queue in the SpAdmin list</h3>
44 ' cName = Name of the queue to look for
45 ' bWarn = if TRUE we warn if the queue does not exist
47 const CFN = "hGetPrinterPosition::"
49 if ( cName = "" ) then
50 warnlog( CFN & "Invalid Parameter passed to function: Empty String" )
51 hGetPrinterPosition() = -1
55 dim iCurrentQueue as integer
57 dim iPrinterCount as integer
58 iPrintercount = LBPrinters.getItemCount()
63 for iCurrentQueue = 1 to iPrinterCount
67 LBPrinters.select( iCurrentQueue )
68 if ( LBPrinters.getseltext() = cName ) then
75 ' warn if queue was not found and we requested a warning
76 if ( not bFound and bWarn ) then
78 printlog( CFN & "The specified printer queue could not be found" )
81 ' print a message that the printer queue exists
83 printlog( CFN & "Printer Queue was found at pos " & iCurrentQueue )
87 hGetPrinterPosition() = iCurrentQueue
91 '*******************************************************************************
93 function hDelPrinter( cPrinterName as string ) as integer
95 '///<h3>Delete a printer queue by its name in SpAdmin</h3>
97 const CFN = "hDelPrinter::"
99 ' delete a printer-queue from the printers-list by name. Only exact matches
103 ' - Name of the queue
105 ' -1 = Bad function call
107 ' 1 = Confirmation Dialog for Delete is missing
108 ' 2 = Unable to press "OK" on Confirm-Delete Dialog
109 ' 3 = Printer queue does not exist so it was not deleted
111 if ( cPrinterName = "" ) then
112 warnlog( CFN & "Invalid Parameter passed to function: Empty String" )
117 dim iPrinterPos as integer
122 iPrinterPos = hGetPrinterPosition( cPrinterName , true )
124 if ( iPrinterPos > 0 ) then
126 LBPrinters.select( iPrinterPos )
131 if ( active.exists( 2 ) ) then
133 printlog( CFN & "Printer Queue deleted" )
136 warnlog( CFN & "Confirm Delete Dialog is missing" )
140 warnlog( CFN & "Unable to confirm printer deletion" )
146 printlog( CFN & "The printer queue does not exist" )
156 '*******************************************************************************
158 function hGetSpadminPath() as string
160 '///<h3>Retrieve the path to the SpAdmin script/binary</h3>
161 const CFN = "hGetSpadminPath::"
162 const C_REL_PATH = "program\spadmin"
166 sPath = gNetzOfficePath & C_REL_PATH
167 sPath = convertpath( sPath )
169 printlog( CFN & "Using SPAdmin from: " & sPath
171 hGetSpadminPath() = sPath
175 '*******************************************************************************
177 function hShutdownOffice() as integer
179 '///<h3>Shutdown the office by closing all docs and the backing window</h3>
180 const CFN = "hShutdownOffice::"
182 dim iOpenDocs as integer
183 iOpenDocs = getDocumentCount()
184 dim iThisDoc as integer
186 ' close all open documents (One open document to remain)
187 for iThisDoc = 1 to iOpenDocs
188 call hCloseDocument()
191 ' see how many documents are still open - should be exactly one
192 iOpenDocs = getDocumentCount()
193 if ( iOpenDocs <> 0 ) then
194 warnlog( CFN & "No open documents expected but found: " & iOpenDocs )
197 ' shutdown the backing window, do not test with getDocumentCount() because
198 ' this would inevitably restart the office
199 ' we need some additional parameter for FileExit, this is a bug
200 FileExit( "SynchronMode", TRUE )
202 ' wait long enough to ensure all office threads are removed from memory
205 ' Print a somehow fuzzy message, we do not know for sure whether the office
206 ' has been shutdown or not
207 printlog( CFN & "The office should have been closed by now." )
208 hShutdownOffice() = iOpenDocs
212 '*******************************************************************************
214 function hOpenSpadmin() as boolean
216 '///<h3>Execute the SpAdmin binary/Script and verify that it is open</h3>
217 ' Return TRUE if hWaitForSpadmin() completes successfully
219 const CFN = "hOpenSpadmin::"
221 dim cSpadminPath as string
222 cSpadminPath = hGetSpadminPath()
226 ' start SPAdmin in automation mode.
228 start( cSpadminPath , "-enableautomation" )
229 printlog( CFN & "SpAdmin command executed successfully" )
232 warnlog( CFN & "Failure: SpAdmin command did not succeed" )
240 '********************************************************************************
242 function hWaitForSpAdmin() as boolean
244 '///<h3>Wait for SpAdmin to be loaded and displayed</h3>
245 const CFN = "hWaitForSpAdmin::"
249 ' Wait for SpAdmin to open
251 if ( SpAdmin.exists( 10 ) ) then
252 printlog( CFN & "SpAdmin is open. Good." )
256 warnlog( CFN & "SpAdmin is not open, the test cannot continue" )
260 hWaitForSpadmin() = bOpen
264 '*******************************************************************************
266 function hCreateFaxDevice( cName as string ) as boolean
268 '///<h3>Open the printer creation dialog and create a fax device</h3>
269 ' The function verifies that the device has been created and returns
273 const CFN = "hCreateFaxDevice::"
275 if ( cName = "" ) then
276 warnlog( CFN & "Invalid Parmeter passed to function: Empty String" )
277 hCreateFaxDevice() = false
281 ' quickly greates a fax device accepting all defaults
282 '///+<li>Click on "New Printer"</li>
286 '///+<li>Click on "Next..."</li>
287 Kontext "SpPrinterWizard"
290 '///+<li>Click on "Next..."</li>
291 Kontext "SpPrinterWizard"
294 '///+<li>Enter "(PHONE)" as queue command</li>
295 Kontext "TabPWQueueCommand"
296 CBCommand.setText( """(PHONE)""" )
298 '///+<li>Click on "Next..."</li>
299 Kontext "SpPrinterWizard"
302 '///+<li>Enter a Fax-Printer Name</li>
303 Kontext "TabPWPrinterName"
304 EFFaxName.setText( cName )
306 '///+<li>Finish the wizard by pressing OK</li>
307 Kontext "SpPrinterWizard"
312 '///+<li>Verify that the Queue has been created in SpAdmin</li>
314 if ( hgetPrinterPosition( cName ) <> 0 ) then
315 hCreateFaxDevice() = true
316 printlog( CFN & "Successfully created Fax device" )
318 hCreateFaxDevice() = false
319 warnlog( CFN & "Failed to create a Fax device" )