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: basic_modulenames.inc,v $
13 '* last change: $Author: jsi $ $Date: 2008-06-16 12:18:13 $
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 : Test modulenames on the tabbar
38 '\******************************************************************************
40 testcase tBasicIdeModuleNames
42 '///<h1>Naming conventions in BASIC-IDE module-/dialog-tabs</h1>
47 dim iCurrentName as integer
48 const CMODULE = "TModuleNames"
49 dim cTabName as string
51 gApplication = "WRITER"
54 ' ------ prerequisites ---------
57 '///+<li>Create a new module for the current (writer) document</li>
58 brc = hInitBasicIde( CMODULE )
61 brc = hInsertMacro( 1 )
63 warnlog( "Failed to insert macro" )
66 '///+<li>Verify that the name makes it to the BASIC macro organizer</li>
67 cTabName = hGetTabNameFromOrganizer()
69 '///+<li>Try to name the tab something containing invalid characters (should fail)</li>
71 iCurrentName = Int( 24 * RND ) + 1 ' Range from 1 to 24
73 cTabName = hCreateInvalidModuleName( iCurrentName )
74 rc = hRenameTab( cTabName )
76 hHandleInvalidNameWarning( cTabname )
78 warnlog( "Warning missing" )
81 '///+<li>Try to name the tab to the current name (should work)</li>
83 rc = hRenameTab( cTabname )
85 brc = hHandleInvalidNameWarning( cTabname )
87 warnlog( "Failed to set valid name" )
92 '///+<li>Finally try to give the tab a valid name (should work)</li>
93 cTabname = hCreateInvalidModuleName( 0 )
94 rc = hRenameTab( cTabName )
96 brc = hHandleInvalidNameWarning( cTabname )
98 warnlog( "Failed to set valid name" )
103 '///+<li>Verify that we are still in the same IDE-Window</li>
106 warnlog( "The open macro-module is not the one that was expected" )
109 '///+<li>Close IDE and document</li>
117 '*******************************************************************************
119 testcase tInvalidModuleNames
121 '///<h1>Module naming conventions: Forbidden characters in module names</h1>
125 dim iCurrentName as Integer
127 dim sSeparator as String
128 dim cModuleName as string
131 '///+<li>Open a new writer document</li>
132 '///+<li>Open the BASIC Macro Organizer</li>
133 '///+<li>Select the last module (Document BASIC)</li>
134 '///+<li>Click the "New" button</li>
135 hBasicModuleCreateNew()
137 '///+<li>Try a couple of names including '-', '+', '!', '(' ... <br>
138 '///+ -> Invalid name warnings are expected for all of these names</li>
141 iCurrentName = Int( 24 * RND ) + 1 ' Range from 1 to 24
143 cModuleName = hCreateInvalidModuleName( iCurrentName )
145 printlog( "Trying module name: " & cModuleName )
147 brc = hNameBasicModule( cModuleName )
149 '///+<li>Check if the Basic-Ide is open (should not be)</li>
151 warnlog( "Basic-Ide should not open for invalid module names" )
153 ' try to recover and continue for other names
154 brc = hCloseBasicIde()
155 brc = hDestroyDocument
156 brc = hBasicModuleCreateNew()
158 ' if we cannot recover, exit the test
165 '///+<li>Close the naming dialog</li>
166 printlog( "Close the naming dialog (cancel)" )
168 if ( NeuesModul.Exists() ) then
172 '///+<li>Close the macro dialog</li>
173 printlog( "Clsoe macro dialog (if it exists)" )
175 if ( Makro.Exists() ) then
179 '///+<li>Close the last document</li>
180 printlog( "Close the document" )
181 brc = hDestroyDocument()
186 '*******************************************************************************
188 testcase tValidModuleNames
190 '///<h1>Module naming conventions: Basic keywords, underscores, long names</h1>
194 dim iCurrentName as Integer
196 dim sKeyword as String
199 '///+<li>Open a new writer document</li>
200 '///+<li>Open the BASIC Macro Organizer</li>
201 '///+<li>Select the last module (Document BASIC)</li>
202 '///+<li>Click the "New" button</li>
203 hBasicModuleCreateNew()
205 '///+<li>Try a couple of basic keywords as module names such as
206 '///+ open, print, select, function etc.</li>
208 iCurrentName = Int( 8 * RND ) + 1 ' Range from 1 to 8
210 select case iCurrentName
211 case 1 : sKeyword = "option"
212 case 2 : sKeyword = "sub"
213 case 3 : sKeyword = "function"
214 case 4 : sKeyword = "end"
215 case 5 : sKeyword = "exit"
216 case 6 : sKeyword = "_underscore1"
217 case 7 : sKeyword = "underscore_2"
218 case 8 : sKeyWord = "ThisIsQuiteALongNameForAModuleDontYouThink"
222 printlog( "Trying module name: " & sKeyword )
224 brc = hNameBasicModule( sKeyword )
226 '///+<li>Check if the Basic-Ide is open (should not be)</li>
229 ' try to recover and continue for other names
230 brc = hCloseBasicIde()
231 brc = hDestroyDocument
232 brc = hBasicModuleCreateNew()
234 ' if we cannot recover, exit the test
240 '///+<li>Close the naming dialog</li>
241 printlog( "Close the naming dialog (cancel)" )
243 if ( NeuesModul.Exists() ) then
247 '///+<li>Close the macro dialog</li>
248 printlog( "Clsoe macro dialog (if it exists)" )
250 if ( Makro.Exists() ) then
254 '///+<li>Close the last document</li>
255 printlog( "Close the document" )
256 brc = hDestroyDocument()
261 '*******************************************************************************
263 function hBasicModuleCreateNew() as boolean
265 '///<h3>Create a new doc, open Basic organizer, select last module, click New...</h3>
266 '///<i>Starting point: The first doc!</i><br>
269 '///+<li>Nothing</li>
273 '///+<li>Errorcode (boolean) </li>
275 '///+<li>True if module naming dialog is open</li>
276 '///+<li>False on any other condition</li>
279 '///<u>Description</u>:
287 const CFN = "hBasicModuleCreateNew::"
289 '///+<li>Open a new writer document</li>
290 gApplication = "WRITER"
291 brc = hCreateDocument()
293 '///+<li>Open the BASIC Macro Organizer</li>
294 brc = hOpenBasicOrganizerFromDoc()
296 warnlog( CFN & "Could not open the BASIC Macro Organizer, aborting" )
300 '///+<li>Select the last module (Document BASIC)</li>
302 iPos = hSelectTheLastNode( MakroAus )
303 if ( not Neu.isEnabled() ) then
304 warnlog( CFN & "New button is disabled for the current module, aborting" )
307 brc = hDestroyDocument()
311 '///+<li>Click the "New" button</li>
312 '///+<li>Verify that the renaming dialog is open</li>
315 printlog( "Click 'New'" )
319 if ( Neuesmodul.exists() ) then
321 printlog( CFN & "Naming dialog is open"
325 hBasicModuleCreateNew() = brc
330 '*******************************************************************************
332 function hHandleInvalidNameWarning( cTabName as string ) as boolean
334 '///<h3>Handle the "Invalid name" dialog when renaming a module</h3>
337 '///+<li>Name of the tab</li>
339 '///+<li>Used for debugging purpose (printlogs only)</li>
344 '///+<li>Errorcondition (boolean)</li>
346 '///+<li>TRUE if warning was displayed and closed correctly</li>
347 '///+<li>FALSE on any other condition</li>
350 '///<u>Description</u>:
353 dim brc as boolean : brc = false
356 const CFN = "hHandleInvalidNameWarning::"
358 '///+<li>Test for a messagebox (Invalid name warning), warn if missing</li>
362 if ( active.exists( 1 ) ) then
365 warnlog( CFN & "Too many invalid name warnings" )
368 '///+<li>Retrieve the text from the messagebox, printlog</li>
369 printlog( CFN & "Message: " & active.getText() )
371 '///+<li>Click OK on the messagebox</li>
378 warnlog( CFN & "Invalid name warning missing" )
385 '///+<li>Return to Basic Ide, take focus from Tabbar</li>
387 tabbar.typekeys( "<ESCAPE>" , true )
388 hHandleInvalidNameWarning() = brc
393 '*******************************************************************************
395 function hCreateInvalidModuleName( iName as integer ) as string
397 '///<h3>Retrieve an invalid module name for Basic IDE by index</h3>
400 '///+<li>Index (integer)</li>
402 '///+<li>0 = insert underscore which creates a valid name</li>
403 '///+<li>1 ... 23 = insert characters like &, +, i, ;, etc. (invalid)</li>
404 '///+<li>> 23 = no character will be definde</li>
409 '///+<li>Name for a module (string)</li>
411 '///+<li>Name of type "ttModule<Char>X"</li>
414 '///<u>Description</u>:
417 dim sSeparator as string
419 ' Note: We cannot test for "<" and ">" because these are the characters
420 ' that identify keystrokes for the .typeKeys() method.
422 '///+<li>Assign a character by index</li>
424 case 0 : sSeparator = "_"
425 case 1 : sSeparator = "-"
426 case 2 : sSeparator = "."
427 case 3 : sSeparator = ","
428 case 4 : sSeparator = "+"
429 case 5 : sSeparator = ":"
430 case 6 : sSeparator = "!"
431 case 7 : sSeparator = "$"
432 case 8 : sSeparator = "("
433 case 9 : sSeparator = ")"
434 case 10 : sSeparator = "="
435 case 11 : sSeparator = "?"
436 case 12 : sSeparator = "*"
437 case 13 : sSeparator = " "
438 case 14 : sSeparator = "&"
439 case 15 : sSeparator = "\"
440 case 16 : sSeparator = "/"
441 case 17 : sSeparator = "ยง"
442 case 18 : sSeparator = """"
443 case 19 : sSeparator = "'"
444 case 20 : sSeparator = "@"
445 case 21 : sSeparator = "["
446 case 22 : sSeparator = "]"
447 case 23 : sSeparator = "%"
448 case 24 : sSeparator = CHR$( 387 )
449 case else : sSeparator = ""
452 '///+<li>Build a string containing the character</li>
453 hCreateInvalidModuleName() = "ttModule" & sSeparator & "X"