summaryrefslogtreecommitdiff
path: root/testautomation/framework/optional/includes/filedlg_tools.inc
blob: b04fdc3f92ecae112ce17338d682632c6fbbd586 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
'encoding UTF-8  Do not remove or change this line!
'**************************************************************************
' DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
'
' Copyright 2000, 2010 Oracle and/or its affiliates.
'
' OpenOffice.org - a multi-platform office productivity suite
'
' This file is part of OpenOffice.org.
'
' OpenOffice.org is free software: you can redistribute it and/or modify
' it under the terms of the GNU Lesser General Public License version 3
' only, as published by the Free Software Foundation.
'
' OpenOffice.org is distributed in the hope that it will be useful,
' but WITHOUT ANY WARRANTY; without even the implied warranty of
' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
' GNU Lesser General Public License version 3 for more details
' (a copy is included in the LICENSE file that accompanied this code).
'
' You should have received a copy of the GNU Lesser General Public License
' version 3 along with OpenOffice.org.  If not, see
' <http://www.openoffice.org/license.html>
' for a copy of the LGPLv3 License.
'
'/************************************************************************
'*
'* owner : joerg.skottke@oracle.com
'*
'* short description : check the internal file dialog ( 1. part )
'*
'\***************************************************************************

sub CheckDirectoryName( dirname as string )
    
    ' Try to create a folder twice and make sure a warning comes up that the
    ' folder already exists
    
    dim i as integer
    dim FULLPATH as string
    FULLPATH = gOfficePath + "user\work\" + dirname + "\"
    
    printlog( " - Create the folder and verify it's existence" )
    
    try
        
        for i=1 to 2
            
            printlog( " - creating folder for the " + i + ". time" )
            
            Kontext "OeffnenDlg"
            printlog( " - press 'new folder' button" )
            NeuerOrdner.Click()
            
            Kontext "NeuerOrdner"
            if ( NeuerOrdner.exists( 2 ) ) then
                printlog( " - name the folder" )
                OrdnerName.SetText( dirname )
                printlog( " - press OK")
                NeuerOrdner.OK()
            else
                warnlog( "New Folder dialog not displayed" )
            endif
            
            ' Take care of the File Exists Dialog
            printlog( " - check for 'File Exists'-Dialog" )
            Kontext "Active"
            If Active.Exists() then
                Active.OK()
                
                'if the file exists during first run of the test: just go on
                if i =  1 then
                    warnlog( "File exists. Did you clean the output-dir?" )
                end if
                
                'if the active exists, we will return to the 'new folder' dialog
                'it must be closed as well
                Kontext "NeuerOrdner"
                NeuerOrdner.Cancel()
            else
                'this should only be displayed on second run
                if i = 2 then
                    warnlog( "No message that the folder '" + dirname + "' exists!" )
                end if
            end if
            
        next i
        
        printlog( " - verify the existence of the new directory" )
        if App.Dir ( ConvertPath ( FULLPATH ), 16 ) = "" then
            Warnlog( "The directory'" + dirname + "' wasn't created!" )
        else
            printlog( " - delete it")
            App.RmDir ( ConvertPath ( FULLPATH ) )
        end if
        
        
    catch
        
        warnlog( "Could not create the directory. Bugid: #108256# or #106510# ?" )
        
    endcatch
    
end sub

'*******************************************************************************

sub CreateInvalidDirectory( dirname as string )
    
    'Try to create a directory with a name that is invalid by using characters
    'that are not allowed for a filesystems. An errormessage is expected.
    
    dim i as integer
    dim FULLPATH as string
    FULLPATH = gOfficePath + "user\work\" + dirname + "\" 'experimental
    
    printlog( " - Trying to create directory <" + FULLPATH + ">" )
    
    try
        
        Kontext "OeffnenDlg"
        if ( OeffnenDlg.exists( 2 ) ) then
            
            NeuerOrdner.Click()
            
            Kontext "NeuerOrdner"
            if ( NeuerOrdner.exists( 2 ) ) then
                
                OrdnerName.SetText( dirname )
                NeuerOrdner.OK()
            else
                warnlog( "New Folder dialog did not open" )
            endif
            
            
            if gPlatgroup() = "unx" then
                
                'unx allows weird filenames
                if App.Dir ( ConvertPath ( FULLPATH ), 16 ) = "" then
                    Warnlog "  the '" + dirname + "'-dir wasn't created!"
                else
                    App.RmDir ( ConvertPath ( FULLPATH ) )
                end if
                
            else
                
                'windows
                Kontext "Active"
                if Active.Exists( 2 ) then
                    
                    printlog( " - handle the 'Active' dialog" )
                    Active.OK()
                    
                    Kontext "Active"
                    if Active.Exists( 2 ) then
                        warnlog( "Double errormessage displayed, one expected." )
                        Active.OK()
                    end if
                    
                    Kontext "NeuerOrdner"
                    NeuerOrdner.Cancel()
                    
                else
                    
                    warnlog( "No warning that the folder can't be created!" )
                    
                end if
                
                if App.Dir( ConvertPath ( FULLPATH ), 16 ) <> "" then
                    Warnlog "The directory '"+ dirname + "' contains invalid chars"
                    App.RmDir( ConvertPath ( FULLPATH ) )
                end if
                
            end if
            
        endif
            
    catch
        
        warnlog( "Could not create the directory. Bugid: #108256# or #106510# ?" )
        
    endcatch
        
end sub

'*******************************************************************************

sub CreateValidDirectory( dirname as string )
    
    'Create a directory that has a valid name at a valid location
    'The directory should not exist.
    'It will be created in the user's directory
    
    dim FULLPATH as string
    FULLPATH = gOfficePath() + "user\work\" + dirname + "\" 'experimental
    
    
    printlog( " - Trying to create directory: <" + FULLPATH + ">" )
    
    try
        
        printlog( " - Open the file-open dialog" )
        Kontext "OeffnenDlg"
        NeuerOrdner.Click()
        
        printlog( " - name the folder" )
        Kontext "NeuerOrdner"
        OrdnerName.SetText( dirname )
        NeuerOrdner.OK()
        
        printlog( " - check if the directory has been created" )
        if App.Dir ( ConvertPath ( FULLPATH ) , 16 ) = "" then
            warnlog( "The '" + dirname + "' has not been created!" )
        else
            App.RmDir( ConvertPath ( FULLPATH ) )
            printlog( " - existing file was successfully deleted" )
        end if
        
    catch
        
        warnlog( "Could not create the directory. Bugid: #108256# or #106510# ?" )
        
    endcatch
    
end sub

'*******************************************************************************

sub CreateValidDirectoryCrop( dirname as string , cropname as string)
    
    'Create a directory that has a name with leading or trailing spaces.
    'Those names are valid but must be cropped.
    'The directory should not exist.
    'It will be created in the user's directory.
    
    dim FULLPATH as string
    FULLPATH = gOfficePath + "user\work\" + dirname + "\" 'experimental
    dim CROPPATH as string
    CROPPATH = gOfficePath + "user\work\" + cropname + "\" 'experimental
    
    printlog( " - Trying to create directory: <" + FULLPATH + ">" )
    
    try
        
        printlog( " - open the file-open dialog" )
        Kontext "OeffnenDlg"
        NeuerOrdner.Click()
        
        printlog( " - name the folder" )
        Kontext "NeuerOrdner"
        OrdnerName.SetText( dirname )
        NeuerOrdner.OK()

        
        printlog( " - check if the directory has been created" )
        if App.Dir( ConvertPath ( CROPPATH ), 16 ) = "" then
            
            warnlog( "The leading or trailing spaces have not been deleted!" )
            
        else
            

            App.RmDir( ConvertPath ( CROPPATH ) )
            printlog( " - existing directory was successfully deleted." )
            
        end if
        
    catch
        
        warnlog( "Could not create the directory. Bugid: #108256# or #106510# ?" )
        
    endcatch
    
end sub

'*******************************************************************************

function LoadDocumentReadOnly ( sDatei as String, TypeOfDocument as Integer, ReadOnlyFlag as Boolean ) as Boolean
    
    LoadDocumentReadOnly = TRUE
    
    FileOpen
    
    Kontext "OeffnenDlg"
    Dateiname.SetText sDatei
    
    if ReadOnlyFlag = TRUE then
        NurLesen.Check()
    endif
    
    Oeffnen.Click
    hFileWait( FALSE )
    
    Kontext "Active"
    if Active.Exists( 2 ) then
        LoadDocumentReadOnly = FALSE
        Warnlog Active.GetText
        Active.OK

        if Active.Exists( 1 ) then
            Warnlog "A second messagebox is active!"
            Active.OK
        end if
        
        Kontext "Filterauswahl"
        If FilterAuswahl.Exists( 2 ) then
            Warnlog "Filterbox is also active!"
            FilterAuswahl.Cancel
        end if
    end if
    
    'printlog( " - check for (unexpected) filter-dialog" )
    Kontext "Filterauswahl"
    
    If ( FilterAuswahl.Exists( 2 ) ) then
        Warnlog( "Filterbox is active, this is not expected" )
        FilterAuswahl.Cancel()
        
        qaerrorlog( "TODO: There is no way that this function can handle " & _
        "the filterdialog correctly, rewrite it!" )
        warnlog( "The test will most likely fail!" )
        
        LoadDocumentReadOnly() = false
        exit function
        
    endif
    
    
    
    kontext "OeffnenDlg"
    
    if ( OeffnenDlg.exists( 2 ) ) then
        warnlog( "File-Open dialog is open, this is not expected at this point" )
        printlog( "Exiting routine to recover" )
        
        OeffnenDlg.cancel()
        
        LoadDocumentReadOnly() = false
        exit function
        
    endif
    
    try
        
        select case TypeOfDocument
            
        case 1  : InsertSection                           ' Writer
            Kontext
            Active.Setpage TabBereiche
            Kontext "TabBereiche"
            TabBereiche.Cancel
        case 2  : FormatCells                             ' Calc
            Kontext
            Active.SetPage TabZahlen
            Kontext "TabZahlen"
            TabZahlen.Cancel
        case 3  : SlideShowPresentationSettings           ' Impress
            Kontext "Bildschirmpraesentation"
            Bildschirmpraesentation.Cancel
        case 4  : InsertLayer                             ' Draw
            Kontext "EbeneEinfuegenDlg"
            EbeneEinfuegenDlg.Cancel
        case 5  : FormatLegend                            ' Chart
            Kontext "TabUmrandungChart" :
            TabUmrandungChart.Cancel
        case 6  : FormatFonts                             ' Math
            Kontext "Schriftarten"
            Schriftarten.Cancel
        end select
        
        if LoadDocumentReadOnly = TRUE then
            Warnlog "The document wasn't loaded read only"
        endif
        
    catch
        
    endcatch
    
end function

'*******************************************************************************

sub hSetUNIXAttributes()
    
    ' NOTE: Requested by TBO
    ' This sub tries to set the file-attributes on the qatesttool-snapshot on
    ' mahler.germany.
    ' Since all BASIC commands are platform independent, it cannot be checked
    ' exactly.
    ' If you are not the owner of the testtool snapshot, this is *not* going to
    ' work.
    
    
    dim cFullPath as string
    dim cParameter as string
    dim cCommand as string
    dim rc as integer
    
    if ( gPLatGroup = "unx" ) then
        
        cCommand = "chmod" ' Fallback, if no following definition matches
        if ( gPlatform = "sol" ) then
            cCommand = "/usr/bin/chmod"
        endif
        if ( gPlatform = "x86" ) then
            cCommand = "/usr/bin/chmod"
        endif
        if ( gPlatform = "lin" ) then
            cCommand = "/bin/chmod"
        endif
        
        cFullPath = convertpath( gTesttoolPath + "framework/filedlg/input/noentry" )
        printlog( "Trying to set attributes for "  + cFullPath )
        cParameter = "-R 000 " + cFullPath
        rc = shell( cCommand , 0 , cParameter , false )
        
        ' the readentry-directory must be readonly, the files as well
        cFullPath = convertpath( gTesttoolPath + "framework/filedlg/input/readentry" )
        printlog( "Trying to set attributes for " + cFullPath )
        cParameter = "-R 444 " + cFullPath
        rc = shell( cCommand , 0 , cParameter , false )
        'need to remove the "S" attribute
        cParameter = "-R -s " + cFullPath
        rc = shell( cCommand , 0 , cParameter , false )
        
        ' the readonly-directory: Only the directory is read-only, the files are rw
        cFullPath = convertpath( gTesttoolPath + "framework/filedlg/input/readonly/*.*" )
        printlog( "Trying to set attributes for " + cFullPath )
        cParameter = "444 " + cFullPath
        rc = shell( cCommand , 0 , cParameter , false )
        
    else
        
        printlog( "No file-attribute setting for non-UNIX platforms" )
        
    endif
    
end sub


'*******************************************************************************

function hGetFirstNameFromFileList() as string
    
    
    
    
    
    
    const CFN = "hGetFirstNameFromFileList()::"
    dim brc as boolean 'a multi purpose boolean returnvalue
    dim cFileName as string
    
    
    Kontext "OeffnenDlg"
    Dateiauswahl.typeKeys( "<HOME>" )
    Dateiauswahl.typeKeys( "<SPACE>" )
    
    cFileName =lcase( Dateiauswahl.GetSelText() )
    printlog( CFN & "File: " & cFileName )
    
    if ( cFileName = "" ) then
        warnlog( CFN & "Filename is empty, probably a timing issue" )
    endif
    
    if ( cFileName = "cvs" ) then
        printlog( CFN & "Skipping CVS directory" )
        Dateiauswahl.TypeKeys( "<Down>" )
        
        cFileName = lcase ( Dateiauswahl.GetSelText() )
        printlog( CFN & "File: " & cFileName )
    endif
    
    hGetFirstNameFromFileList() = cFileName
    
    
end function