summaryrefslogtreecommitdiff
path: root/testautomation/global/tools/includes/required/t_tools2.inc
blob: 8ea2ed6315eee460c23546a027b3558000490f00 (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
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
'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 : helge.delfs@sun.com
'*
'* short description : Global Tools II
'*
'\*************************************************************************************

sub GetOLEDefaultNames

 '/// Reads the names of all OLE objects from a reference file.
'///+ The OLE name-files are language dependent and should be created 
'///+ using the the <i>getnames.bas</i> script running on Windows
'///+ The files are (per this revision) written and read utf-8 encoded.
'///+ The OLE names are stored in global variables.

    const CFN = "t_tools2::GetOLEDefaultNames():"
  
    dim sPath as string
        sPath = gTesttoolPath & "global\input\olenames\" & gProductName
      
    dim sFile as String              ' the file that contains the OLE names
        sFile = convertpath( sPath & "\ole_" & iSprache & ".txt" )
      
    dim sFilterList(20) as String    ' the list that temporarily holds the OLE names
        sFilterlist( 0 ) = "0"
      
    printlog( CFN & "Using OLE names from: " & sFile )

    ' Find the reference file. Warn if not found and exit
    if ( Dir ( sFile ) = "" ) then
   
        Warnlog( CFN & " The file for default-filter-names is missing."
        PrintLog( "Please create the list with ..\global\tools\getnames.bas::GetFilterNames!" )
        exit sub
      
    end if

    ' Read the file data into an array (sFilterList), utf-8 encoded
    call ListRead ( sFilterList(), sFile, "utf8" )

    ' Evaluate the array and assign the data to global variables.
    gOLEWriter  = hGetValueForKeyAsString( sFilterList() , "WRITER"  )
    gOLECalc    = hGetValueForKeyAsString( sFilterList() , "CALC"    )
    gOLEImpress = hGetValueForKeyAsString( sFilterList() , "IMPRESS" )
    gOLEDraw    = hGetValueForKeyAsString( sFilterList() , "DRAW"    )
    gOLEMath    = hGetValueForKeyAsString( sFilterList() , "MATH"    )
    gOLEChart   = hGetValueForKeyAsString( sFilterList() , "CHART"   )
    gOLEOthers  = hGetValueForKeyAsString( sFilterList() , "OTHER"   )

end sub

'-------------------------------------------------------------------------

function hSetLocaleStrings (fLocale as String, TBOstringLocale() as String ) as Boolean
'TODO: JSI, make real description from it!
' creator: TBO @ 25.10.2001
'/// function to set a string array with language dependant strings ///
'/// format of file (fLocale): ///
'///+ 1.line: entries/lines per language => x ///
'///+ 2.line: first language (A) number (iSprache) ///
'///+ 3.line: 1. string language A ///
'///+ 4.lin3: 2.language string  A ///
'///+ ... ///
'///+ (((x+1)*1) +2).line second language (B) number ///
'///+ (((x+1)*1) +2)+1.line:  1. string language B ///
'///+ ... ///
'///+ example file @ "input\\writer\\la_sp\\locale.txt" ///'
'
'/// the function parses the file until it finds the language (iSprache) or until EOF ///
'///+ on success the variable from th ecalling argument ///
'///+ gets set, ///
   dim lLocale (15*20) as string ' list, where file gets loaded into
   dim i,y,x as integer
   dim bFoundLanguage as Boolean
   hSetLocaleStrings = FALSE
   lLocale(0)=0
   fLocale = ConvertPath(fLocale)
   if ListRead (lLocale (), fLocale, "UTF8" ) then
'      printlog "LOCALE: read file :-)"

      bFoundLanguage = FALSE
  ' check file format
      if ( (ListCount(lLocale ()) -1) mod (val(lLocale (1))+1) ) <> 0 then
         warnlog "file has wrong format :-( : lines: "+ ListCount(lLocale ()) +", lenght of entries: "+ lLocale (1) +", (lenght -1) modulo lenghtOfEntries: "+ ( ListCount(lLocale ()) -1) mod ( val(lLocale (1)) +1 )
      else
      '                ( all lines in file  )          (trnsl words)
         for i=0 to ( ( (ListCount(lLocale ())-1) / (val(lLocale (1))+1) )-1)
           '    ( (val(lLocale (1))+1) *i+2)
            x = ( (val(lLocale (1))  ) *i+2 +i) ' line number of entry language
  ' print every language found:
'            printlog "position: "+i+" @ line: "+x+" Language: "+lLocale (x)
  ' check if at suspected language number position is a number
            if (val(lLocale (x)) > 0) then
  ' set string variable if it is the right language
               if (iSprache = val(lLocale (x))) then
'                  printlog "          ^ LOCALE: found needed language :-)"
                  for y=1 to val(lLocale (1))
                     TBOstringLocale(y) = lLocale (x+y)
                     if (TBOstringLocale(y) = "") then
                         qaErrorLog("missing string: " + y + ": '" + lLocale (2+y) + "'")
                     endif
                  next y
                  bFoundLanguage = TRUE
               endif
            else
               warnlog "LOCALE: this is no number :-( FileFormatError"
            end if
         next i
         if (bFoundLanguage = FALSE) then
            qaErrorLog "LOCALE: please add language to LOCALE file!: "+ iSprache
         endif
      endif
   else
      warnlog "LOCALE: file doesn't exist :-( : "+fLocale
   endif
   hSetLocaleStrings = bFoundLanguage
end function

'-------------------------------------------------------------------------

sub GetHTMLCharSet as String
'///function to get the Character Set for HTML export
'///+(tools/options/load&save/HTML compatibility -> Character Set)
   ToolsOptions
   hToolsOptions ( "LoadSave", "HTMLCompatibility" )
   GetHTMLCharSet = Zeichensatz.GetSelText
   Kontext "ExtrasOptionenDlg"
   ExtrasOptionenDlg.OK
end sub

'-------------------------------------------------------------------------

sub SetHTMLCharSet ( CharSet as String )
'///routine to set the Character Set for HTML export
'///+( tools/options/load&save/HTML compatibility -> Character Set )
   ToolsOptions
   hToolsOptions ( "LoadSave", "HTMLCompatibility" )
   Zeichensatz.Select CharSet
   Kontext "ExtrasOptionenDlg"
   ExtrasOptionenDlg.OK
end sub

'-------------------------------------------------------------------------

sub SetHTMLCharSetToUTF8 as Boolean
'///function to set the Character Set for HTML export to 'Unicode UTF8'
'///+( tools/options/load&save/HTML compatibility -> Character Set )
  Dim i as Integer
  Dim sDum as String

   ToolsOptions
   hToolsOptions ( "LoadSave", "HTMLCompatibility" )

   for i=1 to Zeichensatz.GetItemCount
      sDum = Zeichensatz.GetItemText (i)
      if Instr ( lcase (sDum), "utf-8" ) <> 0 then
         Zeichensatz.Select (i)
         i=1000
      else
         if Instr ( lcase (sDum), "utf8" ) <> 0 then
            Zeichensatz.Select (i)
            i=1000
         else
            if Instr ( lcase (sDum), "utf 8" ) <> 0 then
               Zeichensatz.Select (i)
               i=1000
            end if
         end if
      end if
   next i
   if i<1000 then
      SetHTMLCharSetToUTF8 = FALSE
   else
      SetHTMLCharSetToUTF8 = TRUE
   end if
   Kontext "ExtrasOptionenDlg"
    ExtrasOptionenDlg.OK
end sub

'-------------------------------------------------------------------------

function dec(Ref as integer)
'/// decrement variable, call it like 'dec variable' ///'
' reference or value .-) an excursion :-))
' to give this func a var as ref: call without ANY brackets => 'dec Variable'
' opposite of this to call it via value ! WE DON'T WANT THIS !
' (would be 'dec (Variable)' or in declaration 'function dec (ByVal x)')
   Ref = Ref - 1
end function

'-------------------------------------------------------------------------

function inc(Ref as integer)
'/// increment variable, call it like 'dec variable' ///'
   Ref = Ref + 1
end function

'-------------------------------------------------------------------------

function ActivateAutoPilot ( sWhichOne as String ) as Boolean
'Author: TZ
'///Routine to activate (WebPage Autopilot, Form Autopilot, Documentconverter and Euroconveter)
'///Open via menu items (not via SlotID or Macro URL)
'///<u>input</u>: Which Autopilot (<i>webpage</i>, <i>form</i>, <i>documentconverter</i>, <i>euroconverter</i>,<i>addressdatasource</i>)
'///<u>output</u>:<ul><li>TRUE: Autopilot is open</li><li>FALSE: Autopilot can not be opened</li></ul>
  Dim bIsLoaded as boolean, LoadTime as integer, PrintTime as Integer

   bIsLoaded = FALSE
   LoadTime = 0

   select case gApplication
      case "WRITER"
                       Kontext "DocumentWriter"
                       DocumentWriter.UseMenu
      case "HTML"
                       Kontext "DocumentWriterWeb"
                       DocumentWriterWeb.UseMenu
      case "MASTERDOCUMENT"
                       Kontext "DocumentMasterDoc"
                       DocumentMasterDoc.UseMenu
      case "CALC"
                       Kontext "DocumentCalc"
                       DocumentCalc.UseMenu
      case "IMPRESS"
                       Kontext "DocumentImpress"
                       DocumentImpress.UseMenu
      case "DRAW"
                       Kontext "DocumentDraw"
                       DocumentDraw.UseMenu
      case "MATH"
                       Kontext "DocumentMath"
                       DocumentMath.UseMenu
      case else
                       Kontext "DocumentWriter"
                       DocumentWriter.UseMenu
   end select
   sleep(2)
   hMenuSelectNr(1)
   sleep(2)
   hMenuSelectNr(4)
   sleep(2)

   select case lcase (sWhichOne)
      case "webpage"            : hMenuSelectNr(5)
      case "documentconverter"  : hMenuSelectNr(6)
      case "euroconverter"      : hMenuSelectNr(7)
      case "addressdatasource"  : hMenuSelectNr(8)
   end select
   sleep(5)

   while bIsLoaded = False
      while LoadTime < 20
         PrintTime = LoadTime * 3
         select case lcase ( sWhichOne )
            case "webpage"            : Kontext "AutopilotWebPage"
                                        if AutopilotWebPage.Exists(1) then
                                           bIsLoaded = true
                                           printlog "Autopilot is loaded in " + PrintTime + " seconds!"
                                           LoadTime = 20
                                           ActivateAutoPilot = TRUE
                                        end if
            case "report"             : Kontext "AutoPilotReport"
                                        if AutoPilotReport.Exists(1) then
                                           bIsLoaded = true
                                           printlog "Autopilot is loaded in " + PrintTime + " seconds!"
                                           LoadTime = 20
                                           ActivateAutoPilot = TRUE
                                        end if
            case "form"               : Kontext "ChooseDatabase"
                                        if ChooseDatabase.Exists(1) then
                                           bIsLoaded = true
                                           printlog "Autopilot is loaded in " + PrintTime  + " seconds!"
                                           LoadTime = 20
                                           ActivateAutoPilot = TRUE
                                        end if
            case "documentconverter"  : Kontext "DocumentConverter"
                                        if DocumentConverter.Exists(1) then
                                           bIsLoaded = true
                                           printlog "Autopilot is loaded in " + PrintTime + " seconds!"
                                           LoadTime = 20
                                           ActivateAutoPilot = TRUE
                                        end if
            case "euroconverter"      : Kontext "AutoPilotEuroKonverter"
                                        if AutoPilotEuroKonverter.Exists(1) then
                                           bIsLoaded = true
                                           printlog "Autopilot is loaded in " + PrintTime + " seconds!"
                                           LoadTime = 20
                                           ActivateAutoPilot = TRUE
                                        end if
            case "addressdatasource"  : Kontext "AddressSourceAutopilot"
                                        if AddressSourceAutopilot.Exists(1) then
                                           bIsLoaded = true
                                           printlog "Autopilot is loaded in " + PrintTime + " seconds!"
                                           LoadTime = 20
                                           ActivateAutoPilot = TRUE
                                        end if

         end select
         'NOTE: Maybe a messagebox occurs.
         Kontext "Active"
         if Active.Exists (1) then
            warnlog Active.GetText
            try
               Active.OK
            catch
               Active.Cancel
            endcatch
            ActivateAutoPilot = FALSE
         end if
         sleep(1)
         LoadTime = LoadTime + 1
         if LoadTime = 20 and bIsLoaded = False then
            warnlog "Autopilot has not been loaded!"
            ActivateAutoPilot = FALSE
            bIsLoaded = TRUE
         end if
      wend
   wend
end function

'-------------------------------------------------------------------------

function SetURL ( sURL as String )
'Author: TZ
'/// Routine to open a special URL with <i>file open</i>-dialog
'/// <u>input</u>: The URL as string
  FileOpen
  Kontext "OeffnenDlg"
   Dateiname.SetText sURL
   Oeffnen.Click
   wait 500
end function

'-------------------------------------------------------------------------

function fGetFileText (sFilename as string, iCount as long) as string
'/// This function is for getting  the first or last n characters of a file
'///+<u>Input</u>:<ul><li>filename</li><li>number</li></ul>If the number greater 0 then get n characters from start.
'///+A number smaller 0 get from end of file.
'///+<u>Output</u>:<ul><li>string with <b><i>n</i></b> characters</li></ul>

   dim iFile as integer ' filehandle
   dim iTem as integer  ' get 2 bytes of the file
   dim iTemByte(2) as integer ' move 1 byte from iTem in each item
   dim sTemp as string   ' string of file
   dim iSize as long  ' size in bytes of file
   dim i as long      ' runner :-)

   iFile = FreeFile
'   Printlog "FreeFile: " + iFile
   if (dir (sFilename) <> "") then
'      Printlog "FileLen: " + FileLen(sFile)
      Open sFilename For binary access read shared As #iFile
'      Printlog "Loc: " + Loc(#iFile)  ' LONG! where am i in the file?

      iSize = Lof(#iFile) ' get size in bytes of file
      if (iSize > 65530) then '65536 = 64kB
         'Warnlog "fGetFileText: file '" + sFilename + "' might get problems on reading it? size is > 65530 Byte: '" + iSize + "'"
      else
'         printlog "iSize: " + iSize
      endif

      sTemp = ""
      if (iCount >= 0) then   ' get bytes from file start
         get iFile,1,sTemp    ' get max 64kByte; but not the 1st 2 bytes :-(
         get iFile,1,iTem     ' get the first 2 bytes of the file
         iTemByte(2) = (iTem AND &H0000FF00) \ &H100   ' and seperate the bytes
         iTemByte(1) = (iTem AND &H000000FF)
         sTemp = chr(iTemByte(1)) + chr(iTemByte(2)) + sTemp  ' put them together
       else     ' get bytes from file end
         if ((iSize+iCount) > 0) then
               select case (iSize+iCount)
                  case 1: get iFile,1,sTemp ' take bytes from the end of the file
                          get iFile,1,iTem     ' get the first 2 bytes of the file
                          sTemp = chr(iTemByte(2)) + sTemp  ' put them together
                  case else: get iFile,(iSize+iCount)-1,sTemp ' take bytes from the end of the file
               end select
         else
            get iFile,1,sTemp ' take bytes from the end of the file
            get iFile,1,iTem     ' get the first 2 bytes of the file
            iTemByte(2) = (iTem AND &H0000FF00) \ &H100   ' and seperate the bytes
            iTemByte(1) = (iTem AND &H000000FF)
            sTemp = chr(iTemByte(1)) + chr(iTemByte(2)) + sTemp  ' put them together
         endif
       endif
'      printlog "'"+left(sTemp,iSize)+"'"  ' gotcha!

      if (iSize-(Abs(iCount)) >= 0) then
         fGetFileText = left(sTemp,Abs(iCount))
      else
         'Warnlog "fGetFileText: file '" + sFilename + "' isn't as big as expected; will only return '" + iSize+ "' bytes fom: " + iCount
         fGetFileText = left(sTemp,iSize)
      endif

   ' debugging routine --------------------------------------
   '   iSize = Lof(#iFile)
   '   printlog "iSize: " + iSize
   '   sTemp = ""
   '   if iSize > 0 then
   '      printlog "iSize \ 2: " + (iSize \ 2)
   '      for i = 0 to ((iSize \ 2)-1)
   '         get iFile,(i*2)+1,iTem
   '         Printlog "i: " + i + ": 0x" + hex(iTem)
   '       iTemByte(2) = (iTem AND &H0000FF00) \ &H100
   '       iTemByte(1) = (iTem AND &H000000FF)
   '         sTemp = sTemp + chr(iTemByte(1)) + chr(iTemByte(2))
   '      next i
   '      if (iSize MOD 2) = 1 then
   '         get iFile,iSize,iTem
   '         Printlog "i: " + iSize + ": 0x" + hex(iTem)
   '       iTemByte(1) = (iTem AND &H000000FF)
   '         sTemp = sTemp + chr(iTemByte(1))
   '      endif
   '   endif
   '   printlog "'"+sTemp+"'"
   ' debugging routine --------------------------------------
      Close #iFile
   else  ' does file exist
      Warnlog "fGetFileText: file '" + sFilename + "' doesn't exist"
      fGetFileText = ""
   endif
end function
'
'-------------------------------------------------------------------------
'
function fSetMeasurementToCM() as string
'/// Sets the measurement unit to centimeter (cm) and returns the unit.
    Dim i as integer
    
    Call hNewDocument
    ToolsOptions
        select case UCase(gApplication)
            case "WRITER"
            Call hToolsOptions("WRITER","GENERAL")
                                                Masseinheit.Select(2)
                                                if iSprache = 81 then
                                                    fSetMeasurementToCM = Right$( Tabulatorenabstand.Gettext, 3 )        
                                                else
                                                    fSetMeasurementToCM = Right$( Tabulatorenabstand.Gettext, 2 )        
                                                endif            
            case "CALC"
            Call hToolsOptions("CALC","GENERAL")
                                                Masseinheit.Select(2)
                                                if iSprache = 81 then
                                                    fSetMeasurementToCM = Right$( Tabulator.Gettext , 3 )        
                                                else
                                                    fSetMeasurementToCM = Right$( Tabulator.Gettext , 2 )        
                                                endif
            case "IMPRESS"
            Call hToolsOptions("IMPRESS","GENERAL")
                                                Masseinheit.Select(2)
                                                if iSprache = 81 then
                                                    fSetMeasurementToCM = Right$( Tabulatorabstand.Gettext, 3 )        
                                                else
                                                    fSetMeasurementToCM = Right$( Tabulatorabstand.Gettext, 2 )        
                                                endif            
            case "DRAW"
            Call hToolsOptions("DRAW","GENERAL")
                                                Masseinheit.Select(2)
                                                if iSprache = 81 then
                                                    fSetMeasurementToCM = Right$( Tabulatorabstand.Gettext, 3 )        
                                                else
                                                    fSetMeasurementToCM = Right$( Tabulatorabstand.Gettext, 2 )        
                                                endif                        
            case "MASTERDOCUMENT"
            Call hToolsOptions("WRITER","GENERAL")
                                                Masseinheit.Select(2)
                                                if iSprache = 81 then
                                                    fSetMeasurementToCM = Right$( Tabulatorenabstand.Gettext, 3 )        
                                                else
                                                    fSetMeasurementToCM = Right$( Tabulatorenabstand.Gettext, 2 )        
                                                endif                        
            case "HTML"
            Call hToolsOptions("HTML","VIEW")
                                                Masseinheit.Select(2)
                                                'in Writer/Web also the Writer has to be set to cm 
                                                'because .sdw, .sxw etc. export to HTML depends on it.
                                                Call hToolsOptions("WRITER","GENERAL")
                                                Masseinheit.Select(2)
                                                if iSprache = 81 then
                                                    fSetMeasurementToCM = Right$( Tabulatorenabstand.Gettext, 3 )        
                                                else
                                                    fSetMeasurementToCM = Right$( Tabulatorenabstand.Gettext, 2 )        
                                                endif            
            case else                         : warnlog swhereIsThisFunction & "For this module ("& gApplication &") no decimal seperator setting exists."
        end select                   
    printlog "Info: Measurement unit has been set to centimeters."
    Kontext "ExtrasOptionenDlg"
    ExtrasOptionenDlg.OK
    Call hCloseDocument
end function

'-------------------------------------------------------------------------

function fRemoveDoubleCharacter(stringToChange as string, sCharacter as string) As String   
'/// Removes every Character' after a 'Character' in a given string.   
   Dim lLength, n As Long
   Dim sNextLetter As String
   Dim sLastLetter As String
   Dim sFinalString As String
   Dim sTxt, sChar As String

    'store all arguments in
   sTxt = stringToChange
   lLength = Len(sTxt)
   sLastLetter = left(sTxt, 1)
   sFinalString = sLastLetter

   For n = 2 To lLength Step 1
      sNextLetter = Mid(sTxt, n, 1)
      If (sCharacter+sCharacter <> sLastLetter + sNextLetter) Then
         sFinalString = sFinalString + sNextLetter
      End If
      sLastLetter = sNextLetter
   Next n
   fRemoveDoubleCharacter = sFinalString
End Function

'-------------------------------------------------------------------------

function fRemoveDoubleSpace(stringToChange as string) As String
    fRemoveDoubleSpace = fRemoveDoubleCharacter(stringToChange, " ")
End Function

'-------------------------------------------------------------------------

function writeCrashRepFile()
'/// Creates a file <i>(gOfficePath)</i>/user/work/crashrep.txt with two lines:
'///+ <ol><li>name of .bas file</li>
'///+ <li>name of testcase</li></ol>  
    Dim sFile as string
    Dim sContent(5) as string
    
    sFile = ConvertPath (gOfficePath + "user\work\crashrep.txt")
    listAppend(sContent(), gTestName) ' get's set in hStatusIn()
    listAppend(sContent(), getTestcaseName)
    listWrite(sContent(), sFile)
end function

'-------------------------------------------------------------------------

function GetBuildNumHidLst as String
'/// Get the &quot;BuildId&quot; out of the <i>hid.lst</i>.
  Dim FileNum as Integer
  Dim xmlZeile as String
  dim iIndex as integer
  dim sTemp as string

   if Dir (gtHidLstPath + "hid.lst") <> "" then
      FileNum = FreeFile
      Open (gtHidLstPath + "hid.lst") For Input As #FileNum
      do until EOF(#FileNum) = True
         line input #FileNum, xmlZeile
         iIndex = inStr (1, xmlZeile, "010101010101010", 1)
         sTemp = Left (xmlZeile, abs(iIndex - 1))
         ' usually only the first line is read
         if (sTemp <> "") then exit do
      loop
      Close #FileNum
      GetBuildNumHidLst = sTemp
    else
      GetBuildNumHidLst = ""
   end if
end function

'-------------------------------------------------------------------------

function hGetUNOService(optional bSilent as boolean, optional byRef sUnoPortExternal as string) as object
'/// Function enables the UNO communication inside the
'///+ TestTool to the office application.
'/// INPUT: optional <i>bSilent</i> to suppress informal messages, but no warnings
'/// INPUT: optional <i>sUnoPortExternal</i> to just get the UNO port number passed to that variable
    Dim sResultUno as string
    Dim sUnoPort as string
    Dim sOfficeParameters as string
    Dim sUnoOffice as string
    Dim bJustGettingPort as boolean
    Dim sTTPort as string
    
    ' To not to change the old behaviour, set variable if parameter is not given
    if (isMissing(bSilent)) then
        bSilent = FALSE
    end if

    ' master.inc::sStartUpOffice needs just the Port Numberr from UNO, to pass it to first start up
    if (isMissing(sUnoPortExternal)) then
        bJustGettingPort = FALSE
    else
        bJustGettingPort = TRUE
        sUnoPortExternal = "" ' clear it 
    end if
     
    'To enable spaces and special chars in path;
    'This doesn't work for the TestTool command 'start'
    'But for the 'shell' command it is ok.
    sUnoOffice = convertToURL(sAppExe)
  
    '/// Get the TestTool port value from the TestTool control file  
    sTTPort = GetIniValue (gTesttoolIni, "Communication", "TTPort")
    '/// Get the UNO port value from the TestTool control file  
    sResultUno = GetIniValue (gTesttoolIni, "Communication", "UnoPort")
    ' make sure both ports are different
    if sTTPort = sResultUno then
        warnlog "TestTool and UNO port are the same ("+sResultUno+")! Please change the UNO port in the TestTool application: Extra -> Settings -> Misc -> Remote UNO Port and exit OpenOffice.org."
        exit function
    end if
    if NOT bSilent then
        printlog "Trying to use Office/Testtool UNO Port '" + sResultUno + "'."
    endif
    if (sResultUno <> "") then
        sUnoPort = sResultUno
    else
        warnlog ("Please add an entry to your '" + gTesttoolIni + "' in section 'Communication': 'UnoPort=82352' and restart your testtool and exit OpenOffice.org.")
        warnlog ("You also can check the setting in TestTool: Extra->Settings->Misc: and change the value for 'Remote UNO Port' and then exit OpenOffice.org.")
        exit function
    end if
    if (NOT bJustGettingPort) then
        '/// <i>-accept=socket,host=localhost,port=(PortNr);urp</i> has to be added to the start command. 
        sOfficeParameters = "-accept=socket,host=localhost,port=" + sUnoPort + ";urp"
        try
            '/// If this service has been used before the connection will be established.
            hGetUNOService = getUnoApp
            if NOT bSilent then
                printlog "Office/Testtool UNO: CONNECTION SUCCESSFULL"
            end if
            ' If this tree will be used the connection has been established before!
        catch        
            ' If the connection has not been established before this tree will be used.
            '/// If the UNO service has not been used before the application will be <i>started</i> with the additional parameters.
            qaerrorLog "/qa/qatesttool/global/tools/inc/t_tools2.inc::hGetUNOService 'getUnoApp' needn't fail anymore!"
            Shell (sUnoOffice, 1,sOfficeParameters,false)
            if NOT bSilent then
                printlog "Office/Testtool UNO: TRYING TO CONNECT"
            end if
            sleep(10)
        endcatch
        
        '/// This will be tried twice.
        ' Second chance
        if isNull(hGetUNOService) then
            try
                hGetUNOService = GetUnoApp
                if NOT bSilent then
                    printlog "Office/Testtool UNO: CONNECTION SUCCESSFULL"
                endif
            catch
                '/// If the UNO service could not be started a warnlog will be written to the result file. 
                warnlog "Office/Testtool UNO: CONNECTION FAILED"
            endcatch
        end if
    else
        sUnoPortExternal = sUnoPort
    end if
end function

'-------------------------------------------------------------------------

function fopenConfig( sPackage   as String  ,_
                     sPath      as String  ,_
                     bReadWrite as Boolean ,_
                     bAllLocale as Boolean ) as Object
'/// Open a configuration package from the Office installation via UNO API.
'/// <ul><b>Input</b> 
'///+ <li>Parameter: <i>sPackage</i>
'///+ describe the package which should be handled by the returned
'///+ configuration access object
'///+ <u>Example</u>: "/org.openoffice.Office.TypeDetection"</li>
'///+ <li>Parameter: <i>sPath</i>
'///+ Specify the relativ path inside the new opened package,
'///+ where we are interested on
'///+ <u>Example</u>: "Types/xxx" => "/org.openoffice.Office.TypeDetection/Types/xxx"</li>
'///+ <li>Parameter: <i>bReadWrite</i>
'///+ Describe how the package should be opened (readonly/writable)</li>
'///+ <li>Parameter: <i>bAsLocale</i>
'///+ Enable/disable the special ALL LOCALE mode of the configuration API.
'///+ It makes it possible to have access on localized nodes directly instead
'///+ of using the generic handling of used API for it.</li></ul>
'///+ <b>Return</b>: <i>Object</i>
'///+ Object provides access to the required package or directly to a config key.
    Dim sFullPath as String
    Dim aConfig as Object
    Dim aConfigProvider as Object
    Dim lNormalParams(0) as new com.sun.star.beans.PropertyValue
    Dim lLocaleParams(1) as new com.sun.star.beans.PropertyValue
    Dim lParams() as Object
    Dim oUno as Object

    sFullPath = sPackage+"/"+sPath

    if (bAllLocale=true) then
        lLocaleParams(0).Name  = "nodepath"
        lLocaleParams(0).Value = sFullPath
        lLocaleParams(1).Name  = "locale"
        lLocaleParams(1).Value = "*"
        lParams() = lLocaleParams()
    else
        lNormalParams(0).Name  = "nodepath"
        lNormalParams(0).Value = sFullPath
        lParams() = lNormalParams()
    end if

    oUno = hGetUnoService
    
    aConfigProvider = oUno.createInstance("com.sun.star.configuration.ConfigurationProvider")

    if (bReadWrite=true) then
        aConfig = aConfigProvider.createInstanceWithArguments( _
            "com.sun.star.configuration.ConfigurationUpdateAccess", _
            lParams() )
    else
        aConfig = aConfigProvider.createInstanceWithArguments( _
            "com.sun.star.configuration.ConfigurationAccess", _
            lParams() )
    end if

    fopenConfig = aConfig
end function

'-------------------------------------------------------------------------

function fGetProductName as string
'/// Reads the ProductKey from bootstrap/version file and cuts of version number,
    Dim sProduct as string
    Dim sSplit() as string
    Dim i as integer
    Dim u as integer
    Dim sFile as string
    Dim sIniEntry as string
    Dim cFileExt as string
       
    'Using the bootstraprc/bootstrap.ini file in ../program dir
    'to get the value of 'ProductKey'
    
    if ( lcase( gPlatform ) = "osx" ) then
    	sfile = convertPath(gNetzOfficePath + "MacOS/bootstrap")
    else
    	sfile = convertPath(gNetzOfficePath + "program/bootstrap")
    end if
    
    sIniEntry = "Bootstrap"
    
    'Setting the differnt extension to the files.
    if gPlatGroup = "unx" then
        cFileExt = "rc"
    else
        cFileExt = ".ini"
    end if

    'Getting the value of 'ProductKey'-entry or setting it to 'OpenOffice.org 2.0'
    if (dir(sFile+cFileExt) <> "") then
        sProduct = getIniValue(sFile+cFileExt, sIniEntry , "ProductKey")
    else
        warnlog "Could not get the ProductKey value! Setting it to 'OpenOffice.org 2.0' and trying to run the tests!"
        sProduct = "OpenOffice.org 2.0"
    end if
    if (sProduct <> "" AND sProduct <> "NOT EXISTING") then
        sSplit = split(sProduct, " ") ' get count of spaces
        sProduct = ""
        'Presupposition: Version number is not seperated by spaces, 
        'but seperated with space from ProductName
        u = uBound(sSplit)
        if (u > 0) then
            for i = 0 to (u-1)
                sProduct = sProduct + sSplit(i)        ' add strings until last Space
                if (i <> (u-1)) then 
                    sProduct = sProduct + " "
                end if
            next i
        else
            sProduct = sSplit(0)
        end if
    end if
    fGetProductName = sProduct 
end function

'-------------------------------------------------------------------------

function FindBuildID as String
'/// Get BuildID out of <i>bootstrap.ini/boostraprc</i>
'///+or search in <i>.../program/resource/isoxxx??.res</i> for the BuildID.
  Dim sOfficePath as String
  Dim FileNum, iStart, i as Integer
  Dim xmlZeile, sZ1, sZ2, sIsofile as String
  Dim sTemp as String
  Dim sFile as string
  Dim sPlatformProgramPath as string
    
  if (gNetzInst = TRUE) then
     sOfficePath = gNetzOfficePath
   else
     sOfficePath = gOfficePath
  end if

   ' bootstrap.ini/rc part
   if (gSamePC = TRUE) then
        ' since CWS nativefixer18 the information from bootstrap file is spread across bootstrap and version
        if ( lcase( gPlatform ) = "osx" ) then
            sPlatformProgramPath = "MacOS"
        else
            sPlatformProgramPath = "program"
        end if        
        sfile = convertPath(gOfficeBasisPath & "program/version")
        if gPlatGroup = "unx" then
            sFile = sFile + "rc"
            if (dir(sFile) <> "") then
                sTemp = getIniValue(sFile, "Version", "buildid")
                gMajor = getIniValue(sFile, "Version", "ProductSource")
            else
                sfile = convertPath(gNetzOfficePath & sPlatformProgramPath & "/versionrc")
                sTemp = getIniValue(sFile, "Version", "buildid")
            end if
        else
            sFile = sFile + ".ini"
            if (dir(sFile) <> "") then
                sTemp = getIniValue(sFile, "Version", "buildid")
                gMajor = getIniValue(sFile, "Version", "ProductSource")
            else
                sfile = convertPath(gNetzOfficePath & sPlatformProgramPath & "/version.ini")
                sTemp = getIniValue(sFile, "Version", "buildid")
            end if
        end if
   end if
   
   ' fallback to get the buildID via isoxxx??.res part
   if (sTemp = "") then
      sIsofile = Dir (sOfficePath & sPlatformProgramPath & gPathSigne & "resource" & gPathSigne & "iso*.res")
      if sIsofile = "" then
         sIsofile = App.Dir (sOfficePath & sPlatformProgramPath & gPathSigne & "resource" & gPathSigne & "iso*.res")
      end if
      sIsofile = ConvertPath (sOfficePath & sPlatformProgramPath & gPathSigne & "resource" & gPathSigne & sIsofile)
      if sIsofile= "" then
         warnlog "FindBuildID : No isoxxx??.res-file was found!"
         exit function
      end if

      FileNum = FreeFile
      Open sIsofile For Input As #FileNum
      do until EOF(#FileNum) = True
         line input #FileNum, xmlZeile
         for i=1 to 100
             if i=1 then
                sZ1 = left (xmlzeile, 2048)
             else
                sZ1 = left (sZ2, 2048)
             end if
             if sZ1 < 2048 then
                i=101
             else
                iStart = instr (1, sZ1, "Build", 1)
                if iStart <> 0 then
                   iStart = iStart-5
                   sTemp = Mid (sZ1, iStart, 16)
                   exit do
                end if
                sZ2 = right (sZ1, len (sZ1)-2048)
            end if
         next i
      loop
      Close #FileNum
   end if

   ' WorkAround version information starting with 'SRC' or any other letter code as announced
   iStart = len(sTemp)
   i = 1
   ' take the first character
   sZ1 = mid(sTemp,i,1)
   ' if there is more than one character in the string AND the first character is not a number
   if ((iStart > 0) AND (NOT isNumeric(sZ1))) then
       ' increment counter as long as there is no number found in the string
       while ((i < iStart) AND (NOT isNumeric(mid(sTemp,i,1)) ))
           inc(i)
       wend
       ' cut of the not number characters at the start of the string
       sTemp = right(sTemp, len(sTemp)-(i-1))
   end if
   
   FindBuildID = sTemp
end function

'-------------------------------------------------------------------------

sub hSetBuildVersionInformation(bQuite as boolean)
'/// set global version information variables: gMajor, gMinor, gBuild ///'
'/// presupposition: global variable gVersionsnummer is initialised by FindBuildID() ///'
    dim slVersion() as string
    dim ilVersion as integer
    dim sLastVersion as string
    dim iPosA as integer
    dim iPosB as integer

    slVersion() = Split(gVersionsnummer, ",") 
    ilVersion = uBound(slVersion()) ' array counts from 0 on!
    sLastVersion = slVersion(ilVersion)
    ' major is from start to 'm'
    iPosA = 1
    iPosB = instr(sLastVersion, "m")
    if (iPosB = 0) then ' there is no minor
        if (Not bQuite) then
            warnlog "Product Version Information is missing (mXX). Please tell the developer to build with 'setsolar -ver'"
        endif
        iPosB = instr(sLastVersion, "(")
    endif
    if gMajor = "" then
        gMajor  = Mid(sLastVersion, iPosA, (iPosB-iPosA))  '(1) Major
    endif
    iPosA = iPosB
    iPosB = instr(sLastVersion, "(")
    gMinor  = Mid(sLastVersion, iPosA, iPosB-iPosA)        '(2) Minor
    iPosA = instr(sLastVersion, ":") + 1
    iPosB = instr(sLastVersion, ")")
    gBuild = cInt(Mid(sLastVersion, iPosA, iPosB-iPosA))   '(3) Build
end sub

'-------------------------------------------------------------------------

function fRelativeToAbsolutePath (sRelativePath as string) as string
'/// INPUT: provide a path with relative indicators ".." ///'
'///+ The input needs to konsist of the parts: where was the relative string found, and ///'
'///+ the relative path itself as one string. E.g: "/opt/var/../../here/is/it"///'
'/// RETURN: String with the removed parts for each relative iteration. E.g. This returns: "/here/is/it"///'

    dim iHowOften as string
    dim aSplitOnDoublePoints() as string
    dim aSplitOnPathSign() as string
    dim aJoinWithPathSign() as string
    dim i,x,y as integer
    dim sIntern as string

    ' save the input
    sIntern = sRelativePath
    ' get count of 'relative path ups'
    aSplitOnDoublePoints = split(sIntern, gPathSigne+"..")
    ' for every occurence cut part from path
    iHowOften = uBound(aSplitOnDoublePoints)-1
    for i = 0 to iHowOften
        ' Split on every "/.."
        aSplitOnDoublePoints = split(sIntern, gPathSigne+"..")
        ' always work on the first part (The one before the first "/..")
        ' Split the first path at the PathSeperators
        aSplitOnPathSign = split(aSplitOnDoublePoints(0), gPathSigne)
        ' define new size for the first part destination
        redim aJoinWithPathSign(uBound(aSplitOnPathSign())-1)
        ' copy the parts, but not the last part
        for x = 0 to uBound(aJoinWithPathSign())
            aJoinWithPathSign(x) = aSplitOnPathSign(x)
        next x
        ' make one string of the parts with PathSeperators
        aSplitOnDoublePoints(0) = join(aJoinWithPathSign(), gPathSigne)
        ' cut the .. for this run from the string
        redim aJoinWithPathSign(uBound(aSplitOnDoublePoints())-1)
        y=0
        for x = 0 to uBound(aJoinWithPathSign())+1
            if x <> 1 then
                aJoinWithPathSign(x-y) = aSplitOnDoublePoints(x)
            else
                y=1
            endif
        next x
        ' set put all parts together again into one string
        if iHowOften <> i then
            sIntern = join(aJoinWithPathSign(), gPathSigne+"..")
        else
            sIntern = join(aSplitOnDoublePoints(), "")
        endif
    next i
    ' set the returnvalue
    fRelativeToAbsolutePath = sIntern
end function

'-------------------------------------------------------------------------

sub sCheckValgrindStatus()
    ' valgrind only exists on Linux 
    ' If testlauncher is started with parameter --valgrind, a file called
    ' $HOME/tcs.txt is created, with the name of the .bas file
    ' If you don't know the testlauncher, just make sure that the file is created
    ' and contains the name of the .bas file, if you want to use valgrind tests.
    Dim sTestCaseSpecification as string
    Dim sList(10) as string
    Dim sTemp as string
    
    sTemp = environ("HOME")
    sTemp = sTemp + "/tcs.txt"
    if fileExists(sTemp) then
        ListRead(sList(), sTemp)
        if (ListCount(sList())>0) then
            sTemp = sList(1)
            sTemp = right(sTemp, len(sTemp)-1)
            printlog "**  Valgrind mode detected: '" + sTemp + "'"
            setChildEnv("tcs",sTemp)
        end if
    end if
end sub

'-------------------------------------------------------------------------

function fgetDocumentLanguages(byRef aDefaultLocale(), optional bInteger as boolean)
'/// INPUT: aDefaultLocale - array from 0 to 3
'/// INPUT: OPTIONAL: bInteger - TRUE: return language as number en: 1; FALSE: (default) return the short text for locale e.g en_US
'/// RETURN: write in the deliverd array aDefaultLocale depending on bInteger the language from Tools->Options->Language Settings->Languages->Default language for documents
'///+ either the short string representing the language (default) e.g. en_US or the number e.g. 1
'///+ The index of the array is defined:
'///+ (1) Western
'///+ (2) Asian
'///+ (3) CTL

    dim uno
    dim ap
    dim xViewRoot
    dim apara(1) As new com.sun.star.beans.PropertyValue
    dim i as integer
    dim blInteger as boolean

    if isMissing(bInteger) then
        blInteger = FALSE
    else
        blInteger = bInteger
    endif

    uno=hGetUnoService(true)
    ap=uno.createInstance("com.sun.star.configuration.ConfigurationProvider")
    apara(0).Name="nodepath"
    apara(0).Value="/org.openoffice.Office.Linguistic/General"
    apara(1).Name="lazywrite"
    apara(1).Value=False
    xViewRoot=ap.createInstanceWithArguments("com.sun.star.configuration.ConfigurationUpdateAccess",aPara())
    aDefaultLocale(1) = xViewRoot.getPropertyValue("DefaultLocale")
    aDefaultLocale(2) = xViewRoot.getPropertyValue("DefaultLocale_CJK")
    aDefaultLocale(3) = xViewRoot.getPropertyValue("DefaultLocale_CTL")
    xViewRoot.dispose()
    
    ' If the return of the language number is requested, convert it
    if blInteger then
        for i = 1 to 3
            if aDefaultLocale(i) <> "" then
                aDefaultLocale(i) = convertLanguage2(aDefaultLocale(i))
            else
                aDefaultLocale(i) = 0
            endif
        next i
    endif
end function

'-------------------------------------------------------------------------

function hDisableQuickstarterAPI as boolean
    Dim xQuickStarter as object
    Dim oUnoOfficeConnection as object
    Dim bResult as boolean

    bResult = TRUE
    'Second, closing the Quickstarter process that a restart of the office
    'would result into one process (the Quickstart would hinder otherwise
    'the communication to the office.    
    'On mac this results in a disbaled quickstarter imediately, but not persistant on restart.
    oUnoOfficeConnection=hGetUnoService(TRUE)
    if (isNull(oUnoOfficeConnection)) then
        QAErrorLog "Couldn't create UNO access. Can't disable Quickstarter via UNO API."                
        bResult = FALSE
    else
        try
            xQuickStarter = oUnoOfficeConnection.createInstance("com.sun.star.office.Quickstart")        
            'DEBUG: printlog xQuickStarter.dbg_supportedinterfaces
            'disable quickstart veto (not quickstart UI)
            xQuickStarter.setFastPropertyValue(0, FALSE)        
        catch
            qaErrorLog "Join Quickstarter and OOo process failed. There will be problems on shutdown"
            bResult = FALSE
        endcatch
    end if
    hDisableQuickstarterAPI = bResult    
end function

'-------------------------------------------------------------------------