merge the formfield patch from ooo-build
[ooovba.git] / testautomation / framework / optional / includes / basic_eventbinding.inc
blob75771c0897e293fa110cb220650a73446cbb7af4
1 'encoding UTF-8  Do not remove or change this line!
2 '**************************************************************************
3 '* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 '* 
5 '* Copyright 2008 by Sun Microsystems, Inc.
6 '*
7 '* OpenOffice.org - a multi-platform office productivity suite
8 '*
9 '* $RCSfile: basic_eventbinding.inc,v $
11 '* $Revision: 1.1 $
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 : thorsten.bosbach@sun.com
36 '* short description : Function test of Basic IDE Assign Componenet
38 '\************************************************************************
41 testcase tAssignComponent
42     dim j,b,i,a,x,y as integer
43     dim sTemp as string
44     dim sTemp2 as string
45     dim sDialogName as string
46   
47     ' make sure we start from backingwindow
48     b = getDocumentCount
49     for j = 1 to b
50         printlog "closing: " + j
51         hCloseDocument()
52     next j
53     ' make sure we only have one document window
54     hNewDocument()
55     sleep (5)
56     
57     '/// Call Tools - Macros - Organize Dialogs... ///'
58     ToolsMacrosOrganizeDialogs
59     Kontext "TabDialogs"
60     '/// Dialog 'OOo Basic Macro Organizer' is open ///'
61     if TabDialogs.exists(5) then
62         '/// go to top in list 'Dialog' ///'
63         ModuleList.typeKeys("<home>")
64         sTemp = ModuleList.getSelText
65         sTemp2 = ""
66         '/// go down in list with <cursor down>, until the button 'New...' is enabled ///'
67         while (NOT newDialog.isEnabled) AND (sTemp <> sTemp2)
68             ModuleList.typeKeys("<down>")
69             sTemp2 = sTemp
70             sTemp = ModuleList.getSelText
71         wend
72         if sTemp = sTemp2 then
73             warnlog "Couldn't find a way to enable the 'New...' button - aborting"
74             goto endsub
75         endif
76         printlog ModuleList.getSelText
77         '/// click the button 'New...' ///'
78         newDialog.click
79         kontext "NeuerDialog"
80         '/// dialog 'New Dialog' is open ///'
81         if NeuerDialog.exists(5) then
82             ' save dialog name, for deleting it later
83             sDialogName = Dialogname.getText
84             printlog sDialogName
85             '/// remember suggested dialog name, for deleting it later ///'
86             '/// accept the name and close dialog by pressing button 'OK' ///'
87             NeuerDialog.OK
88             '/// dialog 'New Dialog' is up again ///'
89             Kontext "TabDialogs"
90             if TabDialogs.exists(5) then
91                 '/// New created dialog name is highlited in list 'Dialog' ///'
92                 printlog ModuleList.getSelText
93                 '/// click button 'Edit' ///'
94                 edit.click
95                 Kontext "BasicIDE"
96                 '/// Basic IDE Dialog editor is up 'My Macros & Dialogs.Standard - OpenOffice.org Basic' ///'
97                 if DialogWindow.exists(5) then ' you can't use exists on BasicIDE; check for a control
98                     '/// type key <Tab> to select the dialog in the editor ///'
99                     DialogWindow.TypeKeys("tab")
100                     DialogWindow.TypeKeys("tab",true)
101                     '/// open context menu and select entry 'Properties...' ///'
102                     try
103                         ContextProperties
104                     catch
105                         qaErrorLog "#i70901# .typeKeys doesn't work in DialogWindow"
106                         ' works better, but also not always
107                         DialogWindow.mouseDown( 10 , 10 )
108                         DialogWindow.mouseMove( 90 , 90 )
109                         DialogWindow.mouseUp( 90 , 90 )
110                         try
111                             ContextProperties
112                         catch
113                             qaErrorLog "Even Workaround doesn't work! - exiting"
114                             goto endsub
115                         endcatch
116                     endcatch
117                     kontext "ControlPropertiesDialog"
118                     '/// flyer is open 'Properties: Dialog' ///'
119                     'printlog TabEventsControl.exists(5)
120                     if NOT ControlPropertiesDialog.exists(5) then
121                         qaErrorLog "#i70901# can't use exists on tabpage parent"
122                     endif
123                     'printlog TabGeneralControl.exists(5)
124                     ' doesn't work...
125 '                    if ControlPropertiesDialog.exists(5) then
126                     kontext "TabGeneralControl"
127                     if TabGeneralControl.exists(5) then
128                         kontext "ControlPropertiesTabControl"
129                         ControlPropertiesTabcontrol.setPage (TabEventsControl)
130                         '/// switch to tabpage 'Events' ///'
131                         Kontext "TabEventsControl"
132                         if TabEventsControl.exists(5) then
133                             '/// press button '...' beside 'Key pressed'///'
134                             PBKeyTyped.click
135                             Kontext "AssignMacro"
136                             '/// dialog comes up 'Assing Macro' ///'
137                             if AssignMacro.exists(5) then
138                                 '/// click button 'Component' ///'
139                                 Component.click
140                                 Kontext "AssingComponent"
141                                 '/// dialog is open 'Assign component' ///'
142                                 if AssingComponent.exists(5) then
143                                     DialogTest(AssingComponent)
144                                     '/// set Component Method Name to 'compost' ///'
145                                     ComponentMethodName.setText ("vnd.sun.star.script:Library1.Module1.TestDialogComponent?language=Basic&location=document")
146                                     '/// press button 'OK' to close dialog///'
147                                     AssingComponent.OK
148                                     Kontext "AssignMacro"
149                                     if AssignMacro.exists(5) then
150                                         ' doesn't work, because featureset is not implemted on component EditListBox... expected for xmas 2006
151                                         'printlog eventListBox.getItemText
152                                         '/// close dialog 'Assign Macro' with button 'OK' ///'
153                                         AssignMacro.OK
154                                         Kontext "TabEventsControl"
155                                         printlog evtKeyTyped.getText
156                                         Kontext "ControlPropertiesDialog"
157                                         '/// close flyer 'Properties: Dialog' by openening context menu and selecting 'Properties'///'
158                                         ContextProperties
159                                     endif
160                                 else
161                                     warnlog "couldn't open dialog 'Assign Component'"
162                                 endif
163                             else
164                                 warnlog "couldn't open dialog 'Assign Macro'"
165                             endif
166                         else
167                             warnlog "couldn't switch to tab page 'Events''"
168                         endif
169                     else
170                         warnlog "couldn't open flyer 'Properties: Dialog'"
171                     endif
172                 else
173                     warnlog "couldn't open Basic IDE Dialog editor"
174                 endif
175             else
176                 warnlog "couldn't open dialog 'New Dialog'"
177             endif
178         else
179             warnlog "couldn't open dialog 'New Dialog'"
180         endif
181     else
182         warnlog "couldn't open dialog 'OOo Basic Macro Organizer'"
183     endif
184     
185     'delete dialog!
186     '/// Call Tools - Macros - Organize Dialogs... ///'
187     ToolsMacrosOrganizeDialogs
188     Kontext "TabDialogs"
189     '/// Dialog 'OOo Basic Macro Organizer' is open ///'
190     if TabDialogs.exists(5) then
191         '/// go to top in list 'Dialog' ///'
192         ModuleList.typeKeys("<home>")
193         sTemp = ModuleList.getSelText
194         sTemp2 = ""
195         '/// go down in list with <cursor down>, until the created dialog name is found ///'
196         while (sTemp <> sDialogName) AND (sTemp <> sTemp2)
197             ModuleList.typeKeys("<down>")
198             sTemp2 = sTemp
199             sTemp = ModuleList.getSelText
200         wend
201         if sTemp = sTemp2 then
202             warnlog "Couldn't find the created dialog - aborting"
203             goto endsub
204         endif
205         printlog ModuleList.getSelText
206         '/// click the button 'Delete...' ///'
207         delete.click
208         kontext
209         '/// active 'Do you want to delete...' is open ///'
210         if active.exists(5) then
211             printlog active.getText
212             '/// delete dialog by pressing button 'YES' ///'
213             active.yes
214         else
215             warnlog "couldn't delete dialog '"+sDialogName+"'"
216         endif
217         Kontext "TabDialogs"
218         TabDialogs.cancel
219     else
220         warnlog "couldn't open dialog 'OOo Basic Macro Organizer'"
221     endif
222         
223 'Sub Main
224 '       oSimpleComponent = CreateUnoService( "my_module.MyService1" )
225 '       oActiveFrame = StarDesktop.getActiveFrame()
226 '       oSimpleComponent.createDialog("vnd.sun.star.script:Standard.Dialog1?location=application", oActiveFrame )
227 'End Sub
228     '/// close Basic IDE by calling File->Close///'
229     hCloseDocument()
230     '/// close opened document///'
231     hCloseDocument()
232 endcase
234 testcase tAssignComponentFunction
235     dim x,i,a as integer
236     dim sTemp as string
237     dim sPath as string
238         sPath = gTesttoolPath & "framework\optional\input/eventbinding/"
239     dim sExtension as string
240         sExtension = "DialogComponent.oxt"
241     
242     sExtensionCLI("list","")
243     'sExtensionCLI("add","DialogComponent.oxt",convertPath(gTestToolPath + "framework\optional\input/eventbinding/") )
244     hExtensionAddGUI( sPath & sExtension, "" )
245     hFileOpen(convertPath(gTestToolPath + "framework\optional\input/eventbinding/DialogComponent.odt"))
246     kontext "SecurityWarning"
247     if SecurityWarning.exists(5) then
248         SecurityWarning.ok
249     endif
250     ToolsMacrosRunMacro
251     Kontext "ScriptSelector"
252     if ScriptSelector.exists(10) then
253         x = LibraryTreeList.getItemCount
254         'There have to show up 3 libraries, else the document isn't loaded
255         if x <> 3 then
256             printlog "Try again..."
257             ScriptSelector.cancel
258             sleep 10
259             ToolsMacrosRunMacro
260             Kontext "ScriptSelector"
261             x = LibraryTreeList.getItemCount
262         endif
263         'Look for library 'DialogComponent' and 'DIALOGCOMPONENT'
264         for i = 1 to x
265             sTemp = LibraryTreeList.getItemText(i)
266             'printlog "("+i+"/"+x+"): '" + sTemp + "'"
267             if (("DialogComponent.odt"=sTemp) OR ("DIALOGCOMPONENT.ODT"=sTemp)) then
268                 a = i
269                 printlog "Found library ("+i+"/"+x+"): '" + sTemp + "'"
270             endif
271         next i
272         if 0 <> a then
273             'Select the library and unfold it
274             LibraryTreeList.select(a)
275             LibraryTreeList.typeKeys("+")
276             'Go to 'Standard' and unfold
277             LibraryTreeList.typeKeys("<down>")
278             LibraryTreeList.typeKeys("+")
279             'Go to 'Global'
280             LibraryTreeList.typeKeys("<down>")
282             'Select macro name 'TestDialogComponent'
283             x = ScriptList.getItemCount
284             for i = 1 to x
285                 sTemp = ScriptList.getItemText(i)
286                 'printlog "("+i+"/"+x+"): '" + sTemp + "'"
287                 if "TestDialogComponent" = sTemp then
288                     a = i
289                     printlog "Found macro ("+i+"/"+x+"): '" + sTemp + "'"
290                 endif
291             next i
292             if (0 <> a) then
293                 'Select the macro
294                 ScriptList.select(a)
295                 'Start the macro by pressing the button 'run'
296                 qaErrorLog ("#i68892# The test can't go on, because no help ids are useable in BASIC right now.")
297                 ScriptSelector.cancel
298                 'ScriptSelector.ok
299         '       sleep... at least 60 seconds
300                 call sleep(10)
301             else
302                 warnlog "Macro not found: 'TestDialogComponent'"
303             endif
304         else
305             warnlog "Library not found: 'DialogComponent' or 'DIALOGCOMPONENT'"
306         endif
307     else
308         warnlog "'Run macro dialog' didn't came up"
309     endif
310     'printlog resetapplication
311     
312    ' vnd.sun.star.UNO:doit1
313    ' vnd.sun.star.UNO:doit2
314    ' vnd.sun.star.UNO:doit3
315    ' vnd.sun.star.UNO:handleEventWithArguments
316    ' vnd.sun.star.UNO:handleEvent
317    ' vnd.sun.star.UNO:copyText
318     
319     sExtensionCLI("remove","DialogComponent.oxt" )
320     'hExtension RemoveGUI( sExtension )
321     hCloseDocument()
322 endcase