summaryrefslogtreecommitdiff
path: root/automation/source/testtool/objtest.cxx
blob: d061dcdf2e0b334629223b758acc5cbe88ee0b6b (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
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*************************************************************************
 *
 * 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.
 *
 ************************************************************************/

// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_automation.hxx"

#ifdef OS2
#define INCL_DOS
#include <svpm.h>
#endif

#include "sysdir_win.hxx"
#include "registry_win.hxx"
#include "sttresid.hxx"
#include <osl/file.hxx>
#include <vcl/msgbox.hxx>
#include <vcl/sound.hxx>
#include <tools/config.hxx>
#include <vcl/svapp.hxx>
#include <svtools/stringtransfer.hxx>
#include <svl/brdcst.hxx>
#include <basic/sbx.hxx>
#include <com/sun/star/uno/Any.hxx>
#include <com/sun/star/frame/XDesktop.hpp>
#include <comphelper/processfactory.hxx>
#include <com/sun/star/bridge/XBridgeFactory.hpp>
#include <com/sun/star/connection/XConnector.hpp>
#include <com/sun/star/connection/XConnection.hpp>
#include <com/sun/star/lang/XMultiServiceFactory.hpp>
#include <com/sun/star/uno/XNamingService.hpp>

#include <cppuhelper/servicefactory.hxx>

using namespace com::sun::star::uno;
using namespace com::sun::star::lang;
using namespace com::sun::star::frame;
using namespace com::sun::star::bridge;
using namespace com::sun::star::connection;

using ::rtl::OUString;

#include <svtools/svmedit.hxx>

#ifdef UNX
#include <unistd.h> // readlink
#include <errno.h>
#endif

#include <basic/sbuno.hxx>

#include <basic/basicrt.hxx>
#include <basic/ttstrhlp.hxx>
#include "tcommuni.hxx"
#include "comm_bas.hxx"
#include <cretstrm.hxx>

#include "objtest.hxx"
#include "rcontrol.hxx"

#include <basic/testtool.hrc>
#include <basic/ttmsg.hrc>

#include <basic/mybasic.hxx>
#include <basic/testtool.hxx>
#include <basic/sbstar.hxx>

#include <algorithm>

#ifndef SBX_VALUE_DECL_DEFINED
#define SBX_VALUE_DECL_DEFINED
SV_DECL_REF(SbxValue)
#endif
SV_IMPL_REF(SbxValue)

static CommunicationFactory aComManFac;

#define cMyDelim ' '
#define P_FEHLERLISTE pFehlerListe
#define KEEP_SEQUENCES      100         // Keep Names of last 100 Calls


ControlDefLoad const Controls::arClasses [] =
#include "classes.hxx"
CNames *Controls::pClasses = NULL;

ControlDefLoad const TestToolObj::arR_Cmds [] =
#include "r_cmds.hxx"
CNames *TestToolObj::pRCommands = NULL;
CErrors *TestToolObj::pFehlerListe = NULL;      // Hier werden die Fehler des Testtools gespeichert


DBG_NAME( ControlItem )
DBG_NAME( ControlDef )

ControlItem::ControlItem( const sal_Char *Name, SmartId aUIdP )
{
DBG_CTOR(ControlItem,0);
    InitData();
    pData->Kurzname.AssignAscii( Name );
    pData->aUId = aUIdP;
}

ControlItem::ControlItem( const String &Name, SmartId aUIdP )
{
DBG_CTOR(ControlItem,0);
    InitData();
    pData->Kurzname = Name;
    pData->aUId = aUIdP;
}

ControlItem::ControlItem( ControlData *pDataP )
{
DBG_CTOR(ControlItem,0);
    pData = pDataP;
}

ControlSon::~ControlSon()
{
    if (pSons)
    {
        delete pSons;
        pSons = NULL;
    }
}

ControlItemSon::ControlItemSon(const String &Name, SmartId aUIdP )
: ControlItem( Name, aUIdP )
{}

BOOL ControlDef::operator < (const ControlItem &rPar)
{
    return pData->Kurzname.CompareIgnoreCaseToAscii(rPar.pData->Kurzname) == COMPARE_LESS;
}

BOOL ControlDef::operator == (const ControlItem &rPar)
{
    return pData->Kurzname.CompareIgnoreCaseToAscii(rPar.pData->Kurzname) == COMPARE_EQUAL;
}

void ControlDef::Write( SvStream &aStream )
{
    if ( pSons )
        aStream.WriteByteString( String('*').Append( pData->Kurzname ), RTL_TEXTENCODING_UTF8 );
    else
        aStream.WriteByteString( pData->Kurzname, RTL_TEXTENCODING_UTF8 );
    aStream << ((USHORT)pData->aUId.HasNumeric());
    if ( pData->aUId.HasString() )
        aStream.WriteByteString( pData->aUId.GetStr(), RTL_TEXTENCODING_UTF8 );
    else
        aStream << static_cast<comm_ULONG>(pData->aUId.GetNum()); //GetNum() ULONG != comm_ULONG on 64bit
    if ( pSons )
        for ( USHORT i = 0 ; pSons->Count() > i ; i++ )
            ((ControlDef*)(*pSons)[i])->Write(aStream);
}

ControlDef::ControlDef(const String &Name, SmartId aUIdP )
: ControlItemSon( Name, aUIdP)
{
    DBG_CTOR(ControlDef,0);
}

ControlDef::ControlDef(const String &aOldName, const String &aNewName, ControlDef *pOriginal, BOOL bWithSons )
: ControlItemSon("", pOriginal->pData->aUId)
{
    DBG_CTOR(ControlDef,0);
    if ( pOriginal->pData->Kurzname == aOldName )
        pData->Kurzname = aNewName;
    else
        pData->Kurzname = pOriginal->pData->Kurzname;

    if ( bWithSons && pOriginal->pSons )
    {
        pSons = new CNames();
        for ( USHORT i = 0; i < pOriginal->pSons->Count() ; i++)
        {
            ControlDef *pNewDef;
            pNewDef = new ControlDef( aOldName, aNewName, pOriginal->SonGetObject(i) ,TRUE );
            if (! SonInsert(pNewDef))
            {
                OSL_FAIL("Name Doppelt im CopyConstructor. Neuer Name = Controlname!!");
                delete pNewDef;
            }
        }

    }
    else
        pSons = NULL;
}

BOOL ControlItemUId::operator < (const ControlItem &rPar)
{
    return pData->aUId < rPar.pData->aUId;
}

BOOL ControlItemUId::operator == (const ControlItem &rPar)
{
    return pData->aUId == rPar.pData->aUId;
}

SV_IMPL_OP_PTRARR_SORT( CNames, ControlItem* )

void CRevNames::Insert( String aName, SmartId aUId, ULONG nSeq )
{
    ControlItem *pRN = new ReverseName(aName,aUId,nSeq);
    USHORT nPos;
    if ( Seek_Entry(pRN,&nPos) )
        DeleteAndDestroy(nPos);

    if ( !CNames::C40_PTR_INSERT( ControlItem, pRN) )
    {
        OSL_FAIL("Interner Fehler beim Speichern der Lokalen KurzNamen");
        delete pRN;
    }

}

String CRevNames::GetName( SmartId aUId )
{
    ReverseName *pRN = new ReverseName(UniString(),aUId,0);
    USHORT nPos;
    BOOL bSeekOK = Seek_Entry(pRN,&nPos);

    delete pRN;
    if ( bSeekOK )
        return GetObject(nPos)->pData->Kurzname;
    else
    {
        if ( aUId.Matches( UID_ACTIVE ) )
            return CUniString("Active");
        else
            return GEN_RES_STR1( S_NAME_NOT_THERE, aUId.GetText() );
    }
}

void CRevNames::Invalidate ( ULONG nSeq )
{
    USHORT i;
    for (i = 0; i < Count() ;)
    {
        if (((ReverseName*)GetObject(i))->LastSequence < nSeq)
            DeleteAndDestroy(i);
        else
            i++;
    }
}


SV_IMPL_PTRARR(CErrors, ErrorEntry*)


SbxTransportMethod::SbxTransportMethod( SbxDataType DT )
: SbxMethod(CUniString("Dummy"),DT)
{
    nValue = 0;
}


TestToolObj::TestToolObj( String aName, String aFilePath )              // Interner Aufruf
: SbxObject( aName )
, bUseIPC(FALSE)
, bReturnOK(TRUE)
, nSequence(KEEP_SEQUENCES)
, ProgPath()
, IsBlock(FALSE)
, SingleCommandBlock(TRUE)
, m_pControls(NULL)
, m_pNameKontext(NULL)
, m_pSIds(NULL)
, m_pReverseSlots(NULL)
, m_pReverseControls(NULL)
, m_pReverseControlsSon(NULL)
, m_pReverseUIds(NULL)
, pCommunicationManager(NULL)
, aDialogHandlerName()
, nWindowHandlerCallLevel(0)
, nIdleCount(0)
{
    pImpl = new ImplTestToolObj;
    pImpl->ProgParam = String();
    pImpl->aFileBase = DirEntry(aFilePath);
    pImpl->aHIDDir = DirEntry(aFilePath);
    pImpl->bIsStart = FALSE;
    pImpl->pMyBasic = NULL;

    pImpl->aServerTimeout = Time(0,1,00);           // 1:00 Minuten fest
    InitTestToolObj();
}

TestToolObj::TestToolObj( String aName, MyBasic* pBas )                // Aufruf im Testtool
: SbxObject( aName )
, bUseIPC(TRUE)
, bReturnOK(TRUE)
, nSequence(KEEP_SEQUENCES)
, ProgPath()
, IsBlock(FALSE)
, SingleCommandBlock(TRUE)
, m_pControls(NULL)
, m_pNameKontext(NULL)
, m_pSIds(NULL)
, m_pReverseSlots(NULL)
, m_pReverseControls(NULL)
, m_pReverseControlsSon(NULL)
, m_pReverseUIds(NULL)
, pCommunicationManager(NULL)
, aDialogHandlerName()
, nWindowHandlerCallLevel(0)
, nIdleCount(0)
{
    pImpl = new ImplTestToolObj;
    pImpl->ProgParam = String();
    pImpl->bIsStart = FALSE;
    pImpl->pMyBasic = pBas;

    LoadIniFile();
    InitTestToolObj();

    pCommunicationManager = new CommunicationManagerClientViaSocketTT();
    pCommunicationManager->SetDataReceivedHdl( LINK( this, TestToolObj, ReturnResultsLink ));
}

void TestToolObj::LoadIniFile()             // Laden der IniEinstellungen, die durch den ConfigDialog ge�ndert werden k�nnen
{
#define GETSET(aVar, KeyName, Dafault)                          \
    {                                                           \
        ByteString __##aVar##__;                                \
        __##aVar##__ = aConf.ReadKey(KeyName);      \
        if ( !__##aVar##__.Len() )                  \
        {                                                       \
            __##aVar##__ = Dafault;                             \
            aConf.WriteKey(KeyName, __##aVar##__);              \
        }                                                       \
        aVar = UniString( __##aVar##__, RTL_TEXTENCODING_UTF8 );\
    }

#define NEWOLD( NewKey, OldKey )                                                                \
    {                                                                                           \
        ByteString aValue;                                                                      \
        if ( ( (aValue = aConf.ReadKey( OldKey )).Len() ) && !aConf.ReadKey( NewKey ).Len() )   \
            aConf.WriteKey( NewKey, aValue );                                                   \
    }


    Config aConf(Config::GetConfigName( Config::GetDefDirectory(), CUniString("testtool") ));
    aConf.SetGroup("Misc");
    ByteString aCurrentProfile = aConf.ReadKey( "CurrentProfile", "Path" );
    aConf.SetGroup( aCurrentProfile );

    NEWOLD( "BaseDir", "Basisverzeichnis" )
    String aFB;
    GETSET( aFB, "BaseDir", "" );
    pImpl->aFileBase = DirEntry(aFB);

    // remove old keys
    if ( aConf.ReadKey("KeyCodes + Classes").Len() != 0 ||
         aConf.ReadKey("KeyCodes + Classes + Res_Type").Len() != 0 )
    {
        aConf.DeleteKey("KeyCodes + Classes + Res_Type");
        aConf.DeleteKey("KeyCodes + Classes");
    }

    NEWOLD( "LogBaseDir", "LogBasisverzeichnis" )
    String aLFB;
    GETSET( aLFB, "LogBaseDir", ByteString( aFB, RTL_TEXTENCODING_UTF8 ) );
    pImpl->aLogFileBase = DirEntry(aLFB);

    NEWOLD( "HIDDir", "HIDVerzeichnis" )
    String aHID;
    GETSET( aHID, "HIDDir", "" );
    pImpl->aHIDDir = DirEntry(aHID);


    aConf.SetGroup("Misc");

    String aST;
    GETSET( aST, "ServerTimeout", ByteString::CreateFromInt64(Time(0,0,45).GetTime()) );     // 45 Sekunden Initial
    pImpl->aServerTimeout = Time(ULONG(aST.ToInt64()));

    String aSOSE;
    aCurrentProfile = aConf.ReadKey( "CurrentProfile", "Misc" );
    aConf.SetGroup( aCurrentProfile );
    GETSET( aSOSE, "StopOnSyntaxError", "0" );
    pImpl->bStopOnSyntaxError = aSOSE.EqualsAscii("1");


    aConf.SetGroup("GUI Platform");

    String aGP;
    ByteString abGP;
#if defined WNT && defined INTEL
    abGP.Append( "501" );  // Windows on x86
#elif defined WNT && defined X86_64
    abGP.Append( "502" );  // Windows on x64
#elif defined SOLARIS && defined SPARC
    abGP.Append( "01" );  // Solaris SPARC
#elif defined LINUX && defined INTEL
    abGP.Append( "03" );  // Linux
#elif defined AIX
    abGP.Append( "04" );
#elif defined SOLARIS && defined INTEL
    abGP.Append( "05" );  // Solaris x86
#elif defined FREEBSD
    abGP.Append( "08" );
#elif defined MACOSX
    abGP.Append( "12" );
#elif defined LINUX && defined PPC
    abGP.Append( "13" );
#elif defined NETBSD && defined INTEL
    abGP.Append( "14" );  // NetBSD/i386
#elif defined LINUX && defined X86_64
    abGP.Append( "15" );  // Linux x86-64
#elif defined LINUX && defined SPARC
    abGP.Append( "16" );  // Linux SPARC
#elif defined OS2
    abGP.Append( "17" );
#elif defined LINUX && defined MIPS
    abGP.Append( "18" );  // Linux MIPS
#elif defined LINUX && defined ARM
    abGP.Append( "19" );  // Linux ARM
#elif defined LINUX && defined IA64
    abGP.Append( "20" );  // Linux ia64
#elif defined LINUX && defined S390
    abGP.Append( "21" );  // Linux S390
#elif defined LINUX && defined HPPA
    abGP.Append( "22" );  // Linux PA-RISC
#elif defined LINUX && defined AXP
    abGP.Append( "23" );  // Linux ALPHA
#elif defined NETBSD && defined X86_64
    abGP.Append( "24" );  // NetBSD/amd64
#elif defined OPENBSD && defined X86
    abGP.Append( "25" );  // OpenBSD/i386
#elif defined OPENBSD && defined X86_64
    abGP.Append( "26" );  // OpenBSD/amd64
#elif defined DRAGONFLY && defined X86
    abGP.Append( "27" );  // DragonFly/i386
#elif defined DRAGONFLY && defined X86_64
    abGP.Append( "28" );  // DragonFly/x86-64
#else
#error ("unknown platform. please request an ID for your platform on qa/dev")
#endif
    GETSET( aGP, "Current", abGP );

// #i68804# Write default Communication section to testtoolrc/.ini
//  this is not fastest but too keep defaultsettings in one place in the code
    GetHostConfig();
    GetTTPortConfig();
    GetUnoPortConfig();
}

#define MAKE_TT_KEYWORD( cName, aType, aResultType, nID )                       \
{                                                                               \
    SbxVariableRef pMeth;                                                       \
    pMeth = Make( CUniString(cName), aType, aResultType );                      \
    pMeth->SetUserData( nID );                                                  \
}

// SetUserData muß irgendwas sein, sonst wird es im Find rausgefiltert!!!
#define MAKE_USHORT_CONSTANT(cName, nValue)                                     \
    {                                                                           \
        SbxProperty *pVal = new SbxProperty( CUniString( cName) , SbxINTEGER ); \
        pVal->PutInteger( nValue ) ;                                            \
        pVal->SetUserData( 32000 );                                             \
        Insert( pVal );                                                         \
    }

#define RTLNAME "@SBRTL"    // copied from basic/source/classes/sb.cxx

void TestToolObj::InitTestToolObj()
{
    pImpl->nNumBorders = 0;                 // F�r Profiling mit k�stchen

    pImpl->nMinRemoteCommandDelay = 0;
    pImpl->nMaxRemoteCommandDelay = 0;
    pImpl->bDoRemoteCommandDelay = FALSE;

    pImpl->bLnaguageExtensionLoaded= FALSE;
    pImpl->pTTSfxBroadcaster = NULL;

    pImpl->nErrorCount = 0;
    pImpl->nWarningCount = 0;
    pImpl->nQAErrorCount = 0;
    pImpl->nIncludeFileWarningCount = 0;

    pImpl->xErrorList = new SbxDimArray( SbxSTRING );
    pImpl->xWarningList = new SbxDimArray( SbxSTRING );
    pImpl->xQAErrorList = new SbxDimArray( SbxSTRING );
    pImpl->xIncludeFileWarningList = new SbxDimArray( SbxSTRING );

    pImpl->nTestCaseLineNr = 0;

    pImpl->bEnableQaErrors = TRUE;
    pImpl->bDebugFindNoErrors = FALSE;

    pImpl->pChildEnv = new Environment;

    if (!pFehlerListe)
        pFehlerListe = new CErrors;             // Vor allem anderen. Wer weiss, wer alles einen Fehler ausl�st.

    In = new CmdStream();

    pShortNames = new CRevNames;

    pImpl->pHttpRequest = NULL;

// overwrite standard "wait" method, cause we can do better than that!!
// Insert Object into SbiStdObject but change listening.
    SbxVariable* pRTL = pImpl->pMyBasic->Find( CUniString(RTLNAME), SbxCLASS_DONTCARE );
    SbxObject* pRTLObject = PTR_CAST( SbxObject, pRTL );
    if ( pRTLObject )
    {
        SbxVariableRef pWait;
        pWait = pRTLObject->Make( CUniString("Wait"), SbxCLASS_METHOD, SbxNULL );
        pWait->SetUserData( ID_Wait );
    // change listener here
        pRTLObject->EndListening( pWait->GetBroadcaster(), TRUE );
        StartListening( pWait->GetBroadcaster(), TRUE );
    }
    else
    {
        OSL_FAIL("Testtool: Could not replace Wait method");
    }

    MAKE_TT_KEYWORD( "Kontext", SbxCLASS_METHOD, SbxNULL, ID_Kontext );
    MAKE_TT_KEYWORD( "GetNextError", SbxCLASS_VARIABLE, SbxVARIANT, ID_GetError );
    MAKE_TT_KEYWORD( "Start", SbxCLASS_METHOD, SbxSTRING, ID_Start );
    MAKE_TT_KEYWORD( "Use", SbxCLASS_METHOD, SbxNULL, ID_Use );
    MAKE_TT_KEYWORD( "StartUse", SbxCLASS_METHOD, SbxNULL, ID_StartUse );
    MAKE_TT_KEYWORD( "FinishUse", SbxCLASS_METHOD, SbxNULL, ID_FinishUse );

    MAKE_TT_KEYWORD( "CaseLog", SbxCLASS_METHOD, SbxNULL, ID_CaseLog );
    MAKE_TT_KEYWORD( "ExceptLog", SbxCLASS_METHOD, SbxNULL, ID_ExceptLog );
    MAKE_TT_KEYWORD( "PrintLog", SbxCLASS_METHOD, SbxNULL, ID_PrintLog );
    MAKE_TT_KEYWORD( "WarnLog", SbxCLASS_METHOD, SbxNULL, ID_WarnLog );
    MAKE_TT_KEYWORD( "ErrorLog", SbxCLASS_METHOD, SbxNULL, ID_ErrorLog );
    MAKE_TT_KEYWORD( "QAErrorLog", SbxCLASS_METHOD, SbxNULL, ID_QAErrorLog );
    MAKE_TT_KEYWORD( "EnableQaErrors", SbxCLASS_PROPERTY, SbxBOOL, ID_EnableQaErrors );
    MAKE_TT_KEYWORD( "MaybeAddErr", SbxCLASS_METHOD, SbxNULL, ID_MaybeAddErr );
    MAKE_TT_KEYWORD( "ClearError", SbxCLASS_METHOD, SbxNULL, ID_ClearError );
    MAKE_TT_KEYWORD( "SaveIDs", SbxCLASS_METHOD, SbxBOOL, ID_SaveIDs );
    MAKE_TT_KEYWORD( "AutoExecute", SbxCLASS_PROPERTY, SbxBOOL, ID_AutoExecute );   // Achtung! PROPERTY Also eine Variable
    MAKE_TT_KEYWORD( "Execute", SbxCLASS_METHOD, SbxNULL, ID_Execute );
    MAKE_TT_KEYWORD( "StopOnSyntaxError", SbxCLASS_PROPERTY, SbxBOOL, ID_StopOnSyntaxError );

/*  Dialog Handler werden gebraucht, wenn im internen Testtool ein Dialog
    hochgerissen wird. Nach versenden der Remote-Kommandos wird IdleHandler aktiviert.
    Er testet, ob das Reschedule zum WaitForAnswer zur�ckkehrt. Bleibt das aus, so
    wird erst der RemoteHandler zur�ckgesetzt und dann die Handler-Sub im Basic
    gerufen.(Entkoppelt �ber PostUserEvent.)

    In returndaten_verarbeiten wird flag f�r ausf�hrung des n�chsten remote-befehls
    r�ckgesetzt. Der Handler wird damit auch entwertet. Er gilt also nur f�r den
    n�chsten Remotebefehl.
*/
    MAKE_TT_KEYWORD( "DialogHandler", SbxCLASS_METHOD, SbxNULL, ID_DialogHandler );

    MAKE_TT_KEYWORD( "GetUnoApp", SbxCLASS_METHOD, SbxOBJECT, ID_GetUnoApp );
    MAKE_TT_KEYWORD( "GetIServer", SbxCLASS_METHOD, SbxOBJECT, ID_GetIServer );

    MAKE_TT_KEYWORD( "RemoteCommandDelay", SbxCLASS_METHOD, SbxNULL, ID_RemoteCommandDelay );

       MAKE_TT_KEYWORD( "GetApplicationPath", SbxCLASS_METHOD, SbxSTRING, ID_GetApplicationPath );
       MAKE_TT_KEYWORD( "GetCommonApplicationPath", SbxCLASS_METHOD, SbxSTRING, ID_GetCommonApplicationPath );
       MAKE_TT_KEYWORD( "MakeIniFileName", SbxCLASS_METHOD, SbxSTRING, ID_MakeIniFileName );

/// active constants returning error and warning count
    MAKE_TT_KEYWORD( "GetErrorCount", SbxCLASS_METHOD, SbxULONG, ID_GetErrorCount );
    MAKE_TT_KEYWORD( "GetWarningCount", SbxCLASS_METHOD, SbxULONG, ID_GetWarningCount );
    MAKE_TT_KEYWORD( "GetQAErrorCount", SbxCLASS_METHOD, SbxULONG, ID_GetQAErrorCount );
    MAKE_TT_KEYWORD( "GetUseFileWarningCount", SbxCLASS_METHOD, SbxULONG, ID_GetUseFileWarningCount );

    MAKE_TT_KEYWORD( "GetErrorList", SbxCLASS_METHOD, SbxOBJECT, ID_GetErrorList );
    MAKE_TT_KEYWORD( "GetWarningList", SbxCLASS_METHOD, SbxOBJECT, ID_GetWarningList );
    MAKE_TT_KEYWORD( "GetQAErrorList", SbxCLASS_METHOD, SbxOBJECT, ID_GetQAErrorList );
    MAKE_TT_KEYWORD( "GetUseFileWarningList", SbxCLASS_METHOD, SbxOBJECT, ID_GetUseFileWarningList );

    MAKE_TT_KEYWORD( "GetTestCaseName", SbxCLASS_METHOD, SbxSTRING, ID_GetTestCaseName );
    MAKE_TT_KEYWORD( "GetTestCaseFileName", SbxCLASS_METHOD, SbxSTRING, ID_GetTestCaseFileName );
    MAKE_TT_KEYWORD( "GetTestCaseLineNr", SbxCLASS_METHOD, SbxUSHORT, ID_GetTestCaseLineNr );

    MAKE_TT_KEYWORD( "SetChildEnv", SbxCLASS_METHOD, SbxNULL, ID_SetChildEnv );
    MAKE_TT_KEYWORD( "GetChildEnv", SbxCLASS_METHOD, SbxSTRING, ID_GetChildEnv );

    MAKE_TT_KEYWORD( "GetLinkDestination", SbxCLASS_METHOD, SbxSTRING, ID_GetLinkDestination );
    MAKE_TT_KEYWORD( "GetRegistryValue", SbxCLASS_METHOD, SbxSTRING, ID_GetRegistryValue );

    MAKE_TT_KEYWORD( "KillApp", SbxCLASS_METHOD, SbxNULL, ID_KillApp );

    MAKE_TT_KEYWORD( "HTTPSend", SbxCLASS_METHOD, SbxUSHORT, ID_HTTPSend );
    MAKE_TT_KEYWORD( "HTTPSetProxy", SbxCLASS_METHOD, SbxNULL, ID_HTTPSetProxy );

    // Load the Remote Commands from list
    if ( !pRCommands )                 // Ist static, wird also nur einmal geladen
        ReadFlatArray( arR_Cmds, pRCommands );
    USHORT i;
    for ( i = 0 ; i < pRCommands->Count() ; i++ )
    {
        SbxTransportMethod *pMeth = new SbxTransportMethod( SbxVARIANT );
        pMeth->SetName( pRCommands->GetObject( i )->pData->Kurzname );
        pMeth->SetUserData( ID_RemoteCommand );
        pMeth->nValue = pRCommands->GetObject( i )->pData->aUId.GetNum();
        Insert( pMeth );
        StartListening( pMeth->GetBroadcaster(), TRUE );
    }

// Konstanten f�r SetControlType
    MAKE_USHORT_CONSTANT("CTBrowseBox",CONST_CTBrowseBox);
    MAKE_USHORT_CONSTANT("CTValueSet",CONST_CTValueSet);

// Konstanten f�r das Alignment des gesuchten Splitters
    MAKE_USHORT_CONSTANT("AlignLeft",CONST_ALIGN_LEFT);
    MAKE_USHORT_CONSTANT("AlignTop",CONST_ALIGN_TOP);
    MAKE_USHORT_CONSTANT("AlignRight",CONST_ALIGN_RIGHT);
    MAKE_USHORT_CONSTANT("AlignBottom",CONST_ALIGN_BOTTOM);

/// What dialog to use in RC_CloseSysDialog or RC_ExistsSysDialog
    MAKE_USHORT_CONSTANT("FilePicker",CONST_FilePicker);
    MAKE_USHORT_CONSTANT("FolderPicker",CONST_FolderPicker);

/// NodeTypes of the SAX Parser
    MAKE_USHORT_CONSTANT("NodeTypeCharacter",CONST_NodeTypeCharacter);
    MAKE_USHORT_CONSTANT("NodeTypeElement",CONST_NodeTypeElement);
    MAKE_USHORT_CONSTANT("NodeTypeComment",CONST_NodeTypeComment);


/// ItemTypes for TreeListBox and maybe others
    MAKE_USHORT_CONSTANT("ItemTypeText",CONST_ItemTypeText);
    MAKE_USHORT_CONSTANT("ItemTypeBMP",CONST_ItemTypeBMP);
    MAKE_USHORT_CONSTANT("ItemTypeCheckbox",CONST_ItemTypeCheckbox);
    MAKE_USHORT_CONSTANT("ItemTypeContextBMP",CONST_ItemTypeContextBMP);
    MAKE_USHORT_CONSTANT("ItemTypeUnknown",CONST_ItemTypeUnknown);


/// Return values for WaitSlot
    MAKE_USHORT_CONSTANT("WSTimeout",CONST_WSTimeout);
    MAKE_USHORT_CONSTANT("WSAborted",CONST_WSAborted);
    MAKE_USHORT_CONSTANT("WSFinished",CONST_WSFinished);


    pImpl->pControlsObj = new Controls( CUniString("GetNextCloseWindow") );
    pImpl->pControlsObj->SetType( SbxVARIANT );
    Insert( pImpl->pControlsObj );
    pImpl->pControlsObj->SetUserData( ID_GetNextCloseWindow );
    pImpl->pControlsObj->ChangeListener( this );

    for ( i=0;i<VAR_POOL_SIZE;i++)
    {
        pImpl->pMyVars[i] = new SbxTransportMethod( SbxVARIANT );
        pImpl->pMyVars[i]->SetName( CUniString("VarDummy").Append(String::CreateFromInt32(i) ) );

        Insert( pImpl->pMyVars[i] );
    }

    m_pControls = new CNames();
    m_pSIds = new CNames();
    m_pNameKontext = m_pControls;

    nMyVar = 0;

    pImpl->pMyBasic->AddFactory( &aComManFac );
}


TestToolObj::~TestToolObj()
{
    pImpl->pMyBasic->RemoveFactory( &aComManFac );
    EndListening( ((StarBASIC*)GetParent())->GetBroadcaster() );
    pImpl->pNextReturn.Clear();

    pImpl->pControlsObj.Clear();

    for ( int i = 0 ; i < VAR_POOL_SIZE ; i++ )
    {
        pImpl->pMyVars[i].Clear();
    }

    if (m_pControls)
        delete m_pControls;
    if (m_pReverseSlots)
        delete m_pReverseSlots;
    if (m_pReverseControls)
        delete m_pReverseControls;
    if (m_pReverseControlsSon)
        delete m_pReverseControlsSon;
    if (m_pReverseUIds)
        delete m_pReverseUIds;
    if (m_pSIds)
        delete m_pSIds;
    if (pFehlerListe)
    {
        delete pFehlerListe;
        pFehlerListe = NULL;    // da pFehlerListe static ist!!
    }
    if ( pCommunicationManager )
    {
        pCommunicationManager->StopCommunication();
        delete pCommunicationManager;
    }
    delete In;
    if ( pImpl->pTTSfxBroadcaster )
        delete pImpl->pTTSfxBroadcaster;
    delete pImpl->pChildEnv;

    pImpl->xErrorList.Clear();
    pImpl->xWarningList.Clear();
    pImpl->xQAErrorList.Clear();
    pImpl->xIncludeFileWarningList.Clear();

    delete pImpl;

    delete pShortNames;
}

SfxBroadcaster& TestToolObj::GetTTBroadcaster()
{
    if ( !pImpl->pTTSfxBroadcaster )
        pImpl->pTTSfxBroadcaster = new SfxBroadcaster;
    return *pImpl->pTTSfxBroadcaster;
}

void TestToolObj::ReadNames( String Filename, CNames *&pNames, CNames *&pUIds, BOOL bIsFlat )
{
/*******************************************************************************
**
**               Folgende Dateiendungen sind vorhanden
**
**               hid.lst                Langname UId
**               *.sid                  Slot Ids Kurzname Langname Datei ist flach
**               *.win                  Controlname Langname Datei mit *name und +name Notation
**
**
*******************************************************************************/


    SvFileStream Stream;
    String       aLine,aShortname,aLongname;
    SmartId      aUId;
    xub_StrLen   nLineNr;
    USHORT       nElement;
    ControlDef   *pNewDef, *pNewDef2;
    ControlDef   *pFatherDef = NULL;

    nLineNr = 0;    // Wir sind ja noch vor der Datei

    if (! pUIds)
    {
        String aFileName = (pImpl->aHIDDir + DirEntry(CUniString("hid.lst"))).GetFull();
        {
            TTExecutionStatusHint aHint( TT_EXECUTION_SHOW_ACTION, String(SttResId(S_READING_LONGNAMES)), aFileName );
            GetTTBroadcaster().Broadcast( aHint );
        }
        ReadFlat( aFileName ,pUIds, TRUE );
        if ( !pUIds )
            return;
        pNewDef = new ControlDef("Active",SmartId(0));
        const ControlItem *pItem = pNewDef;
        if (! pUIds->Insert(pItem))
        {
            ADD_WARNING_LOG2( GEN_RES_STR1c( S_DOUBLE_NAME, "Active" ), Filename, nLineNr );
            delete pNewDef;
        }

    }

    ADD_MESSAGE_LOG( Filename );

    Stream.Open(Filename, STREAM_STD_READ);
    if (!Stream.IsOpen())
    {
        ADD_ERROR(ERR_NO_FILE,GEN_RES_STR1(S_CANNOT_OPEN_FILE, Filename));
        return;
    }

    if ( bIsFlat && !pNames )
    {
        TTExecutionStatusHint aHint( TT_EXECUTION_SHOW_ACTION, String(SttResId(S_READING_SLOT_IDS)), Filename );
        GetTTBroadcaster().Broadcast( aHint );
    }
    else
    {
        TTExecutionStatusHint aHint( TT_EXECUTION_SHOW_ACTION, String(SttResId(S_READING_CONTROLS)), Filename );
        GetTTBroadcaster().Broadcast( aHint );
    }

    if ( !pNames )
        pNames = new CNames();

    {
        TTExecutionStatusHint aHint( TT_EXECUTION_ENTERWAIT );
        GetTTBroadcaster().Broadcast( aHint );
    }
    while (!Stream.IsEof())
    {
        nLineNr++;

        Stream.ReadByteStringLine(aLine, RTL_TEXTENCODING_IBM_850);
        aLine.EraseLeadingChars();
        aLine.EraseTrailingChars();
        while ( aLine.SearchAscii("  ") != STRING_NOTFOUND )
            aLine.SearchAndReplaceAllAscii("  ",UniString(' '));
        if (aLine.Len() == 0) continue;
        if (aLine.Copy(0,4).CompareIgnoreCaseToAscii("Rem ") == COMPARE_EQUAL) continue;
        if (aLine.Copy(0,1).CompareToAscii("'") == COMPARE_EQUAL) continue;

        if ( (aLine.GetTokenCount(cMyDelim) < 2 || aLine.GetTokenCount(cMyDelim) > 3) && aLine.CompareIgnoreCaseToAscii("*Active") != COMPARE_EQUAL )
        {
            ADD_WARNING_LOG2( GEN_RES_STR1( S_INVALID_LINE, aLine ), Filename, nLineNr );
            continue;
        }

        aShortname = aLine.GetToken(0,cMyDelim);
        aLongname = aLine.GetToken(1,cMyDelim);

        String aFirstAllowedExtra, aAllowed;
        aFirstAllowedExtra.AssignAscii("+*");
        aAllowed.AssignAscii("_");
        xub_StrLen nIndex = 0;
        BOOL bOK = TRUE;

        while ( bOK && nIndex < aShortname.Len() )
        {
            sal_Unicode aChar = aShortname.GetChar( nIndex );
            BOOL bOKThis = FALSE;
            bOKThis |= ( aAllowed.Search( aChar ) != STRING_NOTFOUND );
            if ( !nIndex )
                bOKThis |= ( aFirstAllowedExtra.Search( aChar ) != STRING_NOTFOUND );
            bOKThis |= ( aChar >= 'A' && aChar <= 'Z' );
            bOKThis |= ( aChar >= 'a' && aChar <= 'z' );
            bOKThis |= ( aChar >= '0' && aChar <= '9' );

            bOK &= bOKThis;
            nIndex++;
        }
        if ( !bOK )
        {
            ADD_WARNING_LOG2( CUniString("Zeile \"").Append(aLine).AppendAscii("\" enth�lt ung�ltige Zeichen."), Filename, nLineNr );
            continue;
        }

        BOOL bUnoName = ( aLongname.Copy( 0, 5 ).EqualsIgnoreCaseAscii( ".uno:" )
            || aLongname.Copy( 0, 4 ).EqualsIgnoreCaseAscii( "http" )
            || aLongname.Copy( 0, 15 ).EqualsIgnoreCaseAscii( "private:factory" )
            || aLongname.Copy( 0, 8 ).EqualsIgnoreCaseAscii( "service:" )
            || aLongname.Copy( 0, 6 ).EqualsIgnoreCaseAscii( "macro:" )
            || aLongname.Copy( 0, 8 ).EqualsIgnoreCaseAscii( ".HelpId:" ) );
        // generic method to mark longnames as symbolic
        if ( aLongname.Copy( 0, 4 ).EqualsIgnoreCaseAscii( "sym:" ) )
        {
            bUnoName = TRUE;
            aLongname.Erase( 0, 4 );
        }
        BOOL bMozillaName = ( !bIsFlat && aLongname.Copy( 0, 4 ).EqualsIgnoreCaseAscii( ".moz" ) );

        if ( aShortname.GetChar(0) == '+' )          // Kompletten Eintrag kopieren
        {
            aShortname.Erase(0,1);
            ControlDef WhatName(aLongname,SmartId());
            ControlDef *OldTree;
            if (pNames->Seek_Entry(&WhatName,&nElement))
            {
                OldTree = (ControlDef*)pNames->GetObject(nElement);
                pNewDef = new ControlDef(aLongname,aShortname,OldTree,TRUE);

                const ControlItem *pItem = pNewDef;
                if (! pNames->Insert(pItem))
                {
                    ADD_WARNING_LOG2( GEN_RES_STR1( S_DOUBLE_NAME, aLine ), Filename, nLineNr );
                    delete pNewDef;
                    pFatherDef = NULL;
                }
                else
                {
                    pFatherDef = pNewDef;
                }
            }
            else
            {
                ADD_WARNING_LOG2( GEN_RES_STR1( S_SHORTNAME_UNKNOWN, aLine ), Filename, nLineNr );
                continue;
            }

        }
        else
        {

            if (aShortname.CompareIgnoreCaseToAscii("*Active") == COMPARE_EQUAL)
                aUId = SmartId( UID_ACTIVE );
            else if ( !bUnoName && !bMozillaName )
            {   // Bestimmen der ID aus der Hid.Lst
                ControlDef WhatName(aLongname,SmartId());
                if (pUIds->Seek_Entry(&WhatName,&nElement))
                    aUId = pUIds->GetObject(nElement)->pData->aUId;
                else
                {
                    ADD_WARNING_LOG2( GEN_RES_STR1( S_LONGNAME_UNKNOWN, aLine ), Filename, nLineNr );
                    continue;
                }
            }
            else
            {
                if ( bUnoName )
                    aUId = SmartId( aLongname );
                else if ( bMozillaName )
                    aUId = SmartId( aLongname );
                else
                {
                    OSL_FAIL("Unknown URL schema");
                }
            }



            if (aShortname.GetChar(0) == '*' || bIsFlat)     // Globaler Kurzname (Dialogname oder SId)
            {
                if (!bIsFlat)
                    aShortname.Erase(0,1);

                   pNewDef = new ControlDef(aShortname,aUId);

                if (!bIsFlat)
                {
                    pNewDef->Sons( new CNames() );

                       pNewDef2 = new ControlDef(aShortname,aUId);
                    if (!pNewDef->SonInsert( pNewDef2 ))         // Dialog in eigenen Namespace eintragen
                    {
                        delete pNewDef2;
                        OSL_FAIL(" !!!! ACHTUNG !!!!  Fehler beim einf�gen in leere Liste!");
                    }
                }

                const ControlItem *pItem = pNewDef;
                if (! pNames->Insert(pItem))
                {
                    ADD_WARNING_LOG2( GEN_RES_STR1( S_DOUBLE_NAME, aLine ), Filename, nLineNr );
                    delete pNewDef;
                    pFatherDef = NULL;
                }
                else
                {
                    pFatherDef = pNewDef;
                }
            }
            else
            {
                if (!pFatherDef)
                {
                    ADD_WARNING_LOG2( GEN_RES_STR0( S_FIRST_SHORTNAME_REQ_ASTRX ), Filename, nLineNr );
                }
                else
                {
                    pNewDef = new ControlDef(aShortname,aUId);
                    if (! pFatherDef->SonInsert(pNewDef))
                    {
                        ADD_WARNING_LOG2( GEN_RES_STR1( S_DOUBLE_NAME, aLine ), Filename, nLineNr );
                        delete pNewDef;
                    }
                }
            }
        }
        GetpApp()->Reschedule();
    }
    {
        TTExecutionStatusHint aHint( TT_EXECUTION_LEAVEWAIT );
        GetTTBroadcaster().Broadcast( aHint );
    }
    {
        TTExecutionStatusHint aHint( TT_EXECUTION_HIDE_ACTION );
        GetTTBroadcaster().Broadcast( aHint );
    }

    Stream.Close();
}


void TestToolObj::AddName(String &aBisher, String &aNeu )
{
    String aSl( '/' );
    if ( UniString(aSl).Append(aBisher).Append(aSl).ToUpperAscii().Search( UniString(aSl).Append(aNeu).Append(aSl).ToUpperAscii() ) == STRING_NOTFOUND )
    {
        aBisher += aSl;
        aBisher += aNeu;
    }
}


void TestToolObj::ReadFlat( String Filename, CNames *&pNames, BOOL bSortByName )
//  Wenn bSortByName == FALSE, dann nach UId Sortieren (ControlItemUId statt ControlDef)
{
    SvFileStream Stream;
    String       aLine,aLongname;
    SmartId      aUId;
    xub_StrLen   nLineNr;
    ControlItem  *pNewItem;
    USHORT       nDoubleCount = 0;

    Stream.Open(Filename, STREAM_STD_READ);

    if (!Stream.IsOpen())
    {
        ADD_ERROR(ERR_NO_FILE,GEN_RES_STR1(S_CANNOT_OPEN_FILE, Filename));
        return;
    }

    nLineNr = 0;    // Wir sind ja noch vor der Datei

    if ( !pNames )
        pNames = new CNames();

    {
        TTExecutionStatusHint aHint( TT_EXECUTION_ENTERWAIT );
        GetTTBroadcaster().Broadcast( aHint );
    }
    ADD_MESSAGE_LOG( Filename );
    while (!Stream.IsEof())
    {
        nLineNr++;

        Stream.ReadByteStringLine(aLine, RTL_TEXTENCODING_IBM_850);
        aLine.EraseLeadingChars();
        aLine.EraseTrailingChars();
        while ( aLine.SearchAscii("  ") != STRING_NOTFOUND )
            aLine.SearchAndReplaceAllAscii("  ",UniString(' '));
        if (aLine.Len() == 0) continue;

        if ( (aLine.GetTokenCount(cMyDelim) < 2 || aLine.GetTokenCount(cMyDelim) > 3) && aLine.CompareIgnoreCaseToAscii("*Active") != COMPARE_EQUAL )
        {
            ADD_WARNING_LOG2( GEN_RES_STR1( S_INVALID_LINE, aLine ), Filename, nLineNr );
            continue;
        }

        aLongname = aLine.GetToken(0,cMyDelim);
        aUId = SmartId( (ULONG)aLine.GetToken(1,cMyDelim).ToInt64() );

        if ( bSortByName )
            pNewItem = new ControlDef( aLongname, aUId );
        else
            pNewItem = new ControlItemUId( aLongname, aUId );
        if ( !pNames->C40_PTR_INSERT( ControlItem, pNewItem ) )
        {
            if ( bSortByName )
            {
                if ( nDoubleCount++ < 10 )
                {
                    ADD_WARNING_LOG2( GEN_RES_STR1( S_DOUBLE_NAME, aLine ), Filename, nLineNr );
                }
            }
            else
            {
                USHORT nNr;
                pNames->Seek_Entry( pNewItem, &nNr );
                AddName( pNames->GetObject(nNr)->pData->Kurzname, pNewItem->pData->Kurzname );
            }
            delete pNewItem;
        }
        GetpApp()->Reschedule();
    }
    {
        TTExecutionStatusHint aHint( TT_EXECUTION_LEAVEWAIT );
        GetTTBroadcaster().Broadcast( aHint );
    }

    Stream.Close();
}

void ReadFlatArray( const ControlDefLoad arWas [], CNames *&pNames )
{
    USHORT nIndex = 0;

    if ( !pNames )
        pNames = new CNames();

    while ( String::CreateFromAscii(arWas[nIndex].Kurzname).Len() > 0 )
    {
        SmartId aUId (arWas[nIndex].nUId);
        const ControlItem *pX = new ControlDef( arWas[nIndex].Kurzname, aUId);
        pNames->C40_PTR_INSERT(ControlItem, pX);
        nIndex++;
    }
}

void TestToolObj::WaitForAnswer ()
{
    if ( bUseIPC )
    {
        BOOL bWasRealWait = !bReturnOK;
        BasicRuntime aRun( NULL );
        if ( BasicRuntimeAccess::HasRuntime() )
            aRun = BasicRuntimeAccess::GetRuntime();

        // this timer to terminate Yield below
        Timer aTimer;
        aTimer.SetTimeout( pImpl->aServerTimeout.GetMSFromTime() );
        aTimer.Start();
        while ( !bReturnOK && aTimer.IsActive() && pCommunicationManager->IsCommunicationRunning()
                && aRun.IsValid() && aRun.IsRun() )
        {
            #ifdef OS2
            DosSleep(100);
            #endif
            GetpApp()->Yield();
            if ( BasicRuntimeAccess::HasRuntime() )
                aRun = BasicRuntimeAccess::GetRuntime();
            else
                aRun = BasicRuntime( NULL );
        }
        if ( bWasRealWait && aDialogHandlerName.Len() > 0 )     // Damit das ganze auch im Testtool l�uft
            CallDialogHandler(GetpApp());
    }
    else
    {
        Time Ende;

        Ende += pImpl->aServerTimeout;
        SvStream *pTemp = NULL;

        while ( !bReturnOK && Ende > Time() )
        {
            if ( pTemp )
            {
                ReturnResults( pTemp );
                bReturnOK = TRUE;
            }
            else
            {
                GetpApp()->Reschedule();
            }
            nIdleCount = 0;
        }
    }


    if ( !bReturnOK )
    {
        ADD_ERROR(ERR_EXEC_TIMEOUT,GEN_RES_STR1(S_TIMOUT_WAITING, String::CreateFromInt64(nSequence)));
        bReturnOK = TRUE;
        nSequence++;
    }
}


IMPL_LINK( TestToolObj, IdleHdl, Application*, EMPTYARG )
{
    if ( !bReturnOK )
        nIdleCount++;
    if ( nIdleCount > 10 )  // d.h. Schon 10 mal hier gewesen und noch keinmal im WaitForAnswer
    {
        GetpApp()->RemoveIdleHdl( LINK( this, TestToolObj, IdleHdl ) );
        GetpApp()->PostUserEvent( LINK( this, TestToolObj, CallDialogHandler ) );
    }
    return 0;
}

IMPL_LINK( TestToolObj, CallDialogHandler, Application*, EMPTYARG )
{
    nWindowHandlerCallLevel++;
    String aHandlerName(aDialogHandlerName);
    aDialogHandlerName.Erase();

    ULONG nRememberSequence = nSequence; // Da sich die Sequence im DialogHandler �ndert
    ((StarBASIC*)GetParent())->Call( aHandlerName );
    nSequence = nRememberSequence;
    // Die Sequenznummern werden dann zwar doppelt vergeben, aber wen k�mmerts.

    nWindowHandlerCallLevel--;
    return 0;
}


void TestToolObj::BeginBlock()
{
    WaitForAnswer();
    if ( IsError() )
        return;

    DBG_ASSERT(!IsBlock,"BeginBlock innerhalb eines Blockes");
    In->Reset(nSequence);
    IsBlock = TRUE;
}


void TestToolObj::SendViaSocket()
{
    if ( !pCommunicationManager )
    {
        OSL_FAIL("Kein CommunicationManager vorhanden!!");
        return;
    }

    if ( !pCommunicationManager->IsCommunicationRunning() )
    {
        // first try to run basic sub "startTheOffice" see i86540
        SbxVariable* pMeth = pImpl->pMyBasic->Find( CUniString( "startTheOffice" ), SbxCLASS_DONTCARE);
        if( !pImpl->bIsStart && pMeth && pMeth->ISA(SbxMethod) )
        {
            pImpl->pMyBasic->Call( CUniString( "startTheOffice" ) );
        }
        else
        {
            pImpl->pMyBasic->ResetError();  // reset error produced by failed Find above
            if ( !pCommunicationManager->StartCommunication( ProgPath, pImpl->ProgParam, pImpl->pChildEnv ) )
            {
                ADD_ERROR(ERR_RESTART_FAIL,GEN_RES_STR1(S_APPLICATION_START_FAILED, ProgPath));
            }
            else
            {
                if ( !pImpl->bIsStart )
                {
                    ADD_ERROR(ERR_RESTART,GEN_RES_STR0(S_APPLICATION_RESTARTED));
                }
            }
        }
    }

    bReturnOK = FALSE;
    if ( pCommunicationManager->GetLastNewLink() )
    {
        if ( !pCommunicationManager->GetLastNewLink()->TransferDataStream( In->GetStream() ) )
        {
            ADD_ERROR(ERR_SEND_TIMEOUT,GEN_RES_STR1(S_TIMOUT_SENDING, String::CreateFromInt64(nSequence)));
            nSequence++;
            bReturnOK = TRUE;               // Kein Return zu erwarten
        }
    }
    else
    {
        ADD_ERROR(ERR_SEND_TIMEOUT,GEN_RES_STR1(S_NO_CONNECTION, String::CreateFromInt64(nSequence)));
        nSequence++;
        bReturnOK = TRUE;               // Kein Return zu erwarten
    }

}

void TestToolObj::EndBlock()
{
    if (IsBlock)
    {
        pImpl->LocalStarttime = Time::GetSystemTicks(); // Setzen der Anfangszeit f�r Performancemessung

        In->GenCmdFlow (F_EndCommandBlock);

        if ( pImpl->bDoRemoteCommandDelay )
        {
            ULONG nTimeWait = pImpl->nMinRemoteCommandDelay;
            if ( pImpl->nMaxRemoteCommandDelay != pImpl->nMinRemoteCommandDelay )
                nTimeWait += Time::GetSystemTicks() % ( pImpl->nMaxRemoteCommandDelay - pImpl->nMinRemoteCommandDelay );
            Timer aTimer;
            aTimer.SetTimeout( nTimeWait );
            aTimer.Start();
            while ( aTimer.IsActive() && pCommunicationManager->IsCommunicationRunning() )
            {
                #ifdef OS2
                DosSleep(100);
                #endif
                GetpApp()->Yield();
            }
        }

        if ( bUseIPC )
            SendViaSocket();
        else
        {
            bReturnOK = FALSE;
            if ( aDialogHandlerName.Len() > 0 )
                GetpApp()->InsertIdleHdl( LINK( this, TestToolObj, IdleHdl ), 1 );
        }
        IsBlock = FALSE;
    }
    else
    {
        OSL_FAIL("EndBlock au�erhalb eines Blockes");
    }
}


BOOL TestToolObj::Load( String aFileName, SbModule *pMod )
{
    BOOL bOk = TRUE;
    SvFileStream aStrm( aFileName, STREAM_STD_READ );
    if( aStrm.IsOpen() )
    {
        String aText, aLine;
        BOOL bIsFirstLine = TRUE;
        rtl_TextEncoding aFileEncoding = RTL_TEXTENCODING_IBM_850;
        while( !aStrm.IsEof() && bOk )
        {
            aStrm.ReadByteStringLine( aLine, aFileEncoding );
            if ( bIsFirstLine && IsTTSignatureForUnicodeTextfile( aLine ) )
                aFileEncoding = RTL_TEXTENCODING_UTF8;
            else
            {
                if ( !bIsFirstLine )
                    aText += '\n';
                aText += aLine;
                bIsFirstLine = FALSE;
            }
            if( aStrm.GetError() != SVSTREAM_OK )
                bOk = FALSE;
        }
        aText.ConvertLineEnd();
        pMod->SetName(CUniString("--").Append(aFileName));

        pMod->SetComment( GetRevision( aText ) );

        SbModule* pOldModule = MyBasic::GetCompileModule();
        MyBasic::SetCompileModule( pMod );

        pMod->SetSource( PreCompile( aText ) );

        MyBasic::SetCompileModule( pOldModule );
        if ( WasPrecompilerError() )
            bOk = FALSE;

    }
    else
        bOk = FALSE;
    return bOk;
}


BOOL TestToolObj::ReadNamesBin( String Filename, CNames *&pSIds, CNames *&pControls )
{
    SvFileStream aStream;
    String       aName,aURL;
    SmartId      aUId;
    ControlDef   *pNewDef, *pNewDef2;
    ControlDef   *pFatherDef = NULL;


    aStream.Open(Filename, STREAM_STD_READ);
    if (!aStream.IsOpen())
    {
        ADD_ERROR(ERR_NO_FILE,GEN_RES_STR1(S_CANNOT_OPEN_FILE, Filename));
        return FALSE;
    }

    if ( !pSIds )
        pSIds = new CNames();
    if ( !pControls )
        pControls = new CNames();

    {
        TTExecutionStatusHint aHint( TT_EXECUTION_ENTERWAIT );
        GetTTBroadcaster().Broadcast( aHint );
    }

    USHORT nAnz;
    aStream >> nAnz;
    CNames *pNames = pSIds; // first read all the slots
    BOOL bIsFlat = TRUE;    // Slots do not have children

    while ( nAnz && !aStream.IsEof() )
    {

        aStream.ReadByteString( aName, RTL_TEXTENCODING_UTF8 );

        USHORT nType;
         aStream >> nType;
        if ( !nType /* HasNumeric() */)
        {
            String aStrId;
            aStream.ReadByteString( aStrId, RTL_TEXTENCODING_UTF8 );
            aUId = SmartId( aStrId );
        }
        else
        {
            comm_ULONG nUId;
            aStream >> nUId;
            aUId = SmartId( nUId );
        }

        if (aName.GetChar(0) == '*' || bIsFlat )     // Globaler Kurzname (Dialogname oder SId)
        {
            if (!bIsFlat)
                aName.Erase(0,1);
              pNewDef = new ControlDef(aName,aUId);

            if (!bIsFlat)
            {
                pNewDef->Sons(new CNames());

                pNewDef2 = new ControlDef(aName,aUId);      // Noch einen machen
                if (!pNewDef->SonInsert(pNewDef2))                              // Dialog in eigenen Namespace eintragen
                {
                    delete pNewDef2;
                    OSL_FAIL(" !!!! ACHTUNG !!!!  Fehler beim einf�gen in leere Liste!");
                }
            }

            const ControlItem *pItem = pNewDef;
            if (! pNames->Insert(pItem))
            {
                OSL_FAIL(" !!!! ACHTUNG !!!!  Fehler beim einf�gen eines namens!");
                delete pNewDef;
                pFatherDef = NULL;
            }
            else
            {
                pFatherDef = pNewDef;
            }
        }
        else
        {
            if (!pFatherDef)
            {
                OSL_FAIL( "Internal Error: Erster Kurzname mu� mit * beginnen. �berspringe." );
            }
            else
            {
                   pNewDef = new ControlDef(aName,aUId);
                if (! pFatherDef->SonInsert(pNewDef))
                {
                    delete pNewDef;
                    OSL_FAIL(" !!!! ACHTUNG !!!!  Fehler beim einf�gen eines namens!");
                }
            }
        }


        nAnz--;
        if ( !nAnz && bIsFlat )     // We have read all slots
        {
            aStream >> nAnz;
            pNames = pControls; // Now read the controls
            bIsFlat = FALSE;    // Controls *do* have children
        }


        GetpApp()->Reschedule();
    }
    {
        TTExecutionStatusHint aHint( TT_EXECUTION_LEAVEWAIT );
        GetTTBroadcaster().Broadcast( aHint );
    }

    aStream.Close();
    return TRUE;
}


BOOL TestToolObj::WriteNamesBin( String Filename, CNames *pSIds, CNames *pControls )
{
    BOOL bOk = TRUE;
    SvFileStream aStrm( String(Filename).AppendAscii(".bin"), STREAM_STD_WRITE );
    if( aStrm.IsOpen() )
    {
        USHORT i;
        if ( pSIds )
        {
            aStrm << pSIds->Count();
            for ( i = 0 ; pSIds->Count() > i && bOk ; i++ )
            {
                ((ControlDef*)(*pSIds)[i])->Write(aStrm);
                if( aStrm.GetError() != SVSTREAM_OK )
                    bOk = FALSE;
            }
        }
        else
            aStrm << USHORT( 0 );

        if ( pControls )
        {
            aStrm << pControls->Count();
            for ( i = 0 ; pControls->Count() > i && bOk ; i++ )
            {
                ((ControlDef*)(*pControls)[i])->Write(aStrm);
                if( aStrm.GetError() != SVSTREAM_OK )
                    bOk = FALSE;
            }
        }
        else
            aStrm << USHORT( 0 );
    }
    else
        bOk = FALSE;
    return bOk;
}


void TestToolObj::SFX_NOTIFY( SfxBroadcaster&, const TypeId&,
                            const SfxHint& rHint, const TypeId& )
{
    static CNames *pUIds = NULL;    // Halten der hid.lst

    const SbxHint* p = PTR_CAST(SbxHint,&rHint);
    if( p )
    {
        SbxVariable* pVar = p->GetVar();
        SbxArray* rPar = pVar->GetParameters();

        ULONG nHintId = p->GetId();
        ULONG nHintUserData = pVar->GetUserData();
        if( nHintId == SBX_HINT_DATAWANTED )
        {
            nMyVar = 0;
            switch( nHintUserData )
            {
                case ID_Kontext:
                    if ( !rPar )
                    {
                        m_pNameKontext = m_pControls;

                        // So da� nicht immer mal wieder was aus einem alten Kontext dazwischenhaut
                        for (USHORT i=0;i<VAR_POOL_SIZE;i++)
                        {
                            pImpl->pMyVars[i]->SetName( CUniString("VarDummy").Append(UniString::CreateFromInt32(i)) );
                        }
                    }
                    else if ( rPar && rPar->Count() == 2 )
                    {
                        USHORT nElement;
                        SbxVariableRef pArg = rPar->Get( 1 );
                        String aKontext = pArg->GetString();
                        ControlDef WhatName(aKontext,SmartId());
                        if (m_pControls && m_pControls->Seek_Entry(&WhatName,&nElement))
                        {
                            m_pNameKontext = ((ControlDef*)m_pControls->GetObject(nElement))->GetSons();

                            // So da� nicht immer mal wieder was aus einem alten Kontext dazwischenhaut
                            for (USHORT i=0;i<VAR_POOL_SIZE;i++)
                            {
                                pImpl->pMyVars[i]->SetName( CUniString("VarDummy").Append(UniString::CreateFromInt32(i)) );
                            }
                        }
                    }
                    else
                        SetError( SbxERR_WRONG_ARGS );
                    break;
                case ID_Start:
                    if ( rPar && rPar->Count() >= 2 )
                    {
                        SbxVariableRef pArg = rPar->Get( 1 );
                        ProgPath = pArg->GetString();
                        if ( rPar && rPar->Count() >= 3 )
                        {
                            pArg = rPar->Get( 2 );
                            pImpl->ProgParam = pArg->GetString();
                        }
                        else
                            pImpl->ProgParam.Erase();

                        String aTmpStr(ProgPath);
                        aTmpStr += ' ';
                        aTmpStr += pImpl->ProgParam;
                        {
                            TTExecutionStatusHint aHint( TT_EXECUTION_SHOW_ACTION, String(SttResId(S_STARTING_APPLICATION)), aTmpStr );
                            GetTTBroadcaster().Broadcast( aHint );
                        }

                        pImpl->bIsStart = TRUE;
                        BeginBlock();
                        EndBlock();
                        pImpl->bIsStart = FALSE;
                        {
                            TTExecutionStatusHint aHint( TT_EXECUTION_HIDE_ACTION );
                            GetTTBroadcaster().Broadcast( aHint );
                        }
                    }
                    break;
                case ID_KillApp:
                    pCommunicationManager->KillApplication();
                    break;
                case ID_SaveIDs:
                    if ( rPar && rPar->Count() >= 2 )  // Genau ein Parameter
                    {
                        SbxVariableRef pArg = rPar->Get( 1 );
                        DirEntry FilePath = pImpl->aFileBase + DirEntry(pArg->GetString(),FSYS_STYLE_VFAT);
                        WriteNamesBin( FilePath.GetFull(), m_pSIds, m_pControls );
                    }
                    else
                        SetError( SbxERR_WRONG_ARGS );
                    break;
                case ID_AutoExecute:
                    if ( !rPar )  // rPar = NULL  <=>  Kein Parameter
                    {
                        pVar->PutBool(SingleCommandBlock);
                    }
                    else
                        SetError( SbxERR_WRONG_ARGS );
                    break;
                case ID_Execute:
                    if ( !rPar )  // rPar = NULL  <=>  Kein Parameter
                    {
                        EndBlock();
                        BeginBlock();
                    }
                    else
                        SetError( SbxERR_WRONG_ARGS );
                    break;
                case ID_DialogHandler:
                    if ( rPar && rPar->Count() >= 2 )  // Genau ein Parameter
                    {
                        SbxVariableRef pArg = rPar->Get( 1 );
                        aDialogHandlerName = pArg->GetString();
                    }
                    else
                        SetError( SbxERR_WRONG_ARGS );
                    break;
                case ID_GetError:
                    if ( !rPar )  // rPar = NULL  <=>  Kein Parameter
                    {
                        WaitForAnswer();
                        if ( IS_ERROR() )
                        {
                            pVar->PutString( GET_ERROR()->aText );
                            POP_ERROR();
                        }
                        else
                        {
                            pVar->PutString( String() );
                        }
                    }
                    else
                        SetError( SbxERR_WRONG_ARGS );
                    break;
                case ID_StartUse:
                    if ( !rPar )  // rPar = NULL  <=>  Kein Parameter
                    {
                        {
                            BasicRuntime aRun = BasicRuntimeAccess::GetRuntime();
                            aLogFileName = DirEntry(aRun.GetModuleName(SbxNAME_NONE)).GetBase().AppendAscii(".res");
                        }

                        ADD_RUN_LOG();
                        ADD_CASE_LOG(GEN_RES_STR0(S_READING_FILE));

                        pCommunicationManager->StopCommunication();
                        // Wait for asynchronous events to be processed, so communication will be restarted properly
                        while ( pCommunicationManager->IsCommunicationRunning() )
                            Application::Reschedule();

                        SingleCommandBlock = TRUE;
                        IsBlock = FALSE;

                        for (USHORT i=0;i<VAR_POOL_SIZE;i++)
                        {
                            pImpl->pMyVars[i]->SetName( CUniString("VarDummy").Append(UniString::CreateFromInt32(i)) );
                        }
                        nMyVar = 0;

                        if (m_pControls)
                        {
                            delete m_pControls;
                            m_pControls = NULL;
                        }
                        if (m_pReverseSlots)
                        {
                            delete m_pReverseSlots;
                            m_pReverseSlots = NULL;
                        }
                        if (m_pReverseControls)
                        {
                            delete m_pReverseControls;
                            m_pReverseControls = NULL;
                        }
                        if (m_pReverseControlsSon)
                        {
                            delete m_pReverseControlsSon;
                            m_pReverseControlsSon = NULL;
                        }
                        if (m_pSIds)
                        {
                            delete m_pSIds;
                            m_pSIds = NULL;
                        }
                        if (pUIds)
                        {
                            delete pUIds;
                            pUIds = NULL;
                        }
                        if (m_pReverseUIds)
                        {
                            delete m_pReverseUIds;
                            m_pReverseUIds = NULL;
                        }
                        m_pNameKontext = m_pControls;
                        pImpl->bLnaguageExtensionLoaded = FALSE;
                        SfxSimpleHint aHint( SBX_HINT_LANGUAGE_EXTENSION_LOADED );
                        GetTTBroadcaster().Broadcast( aHint );

                        pImpl->nMinRemoteCommandDelay = 0;
                        pImpl->nMaxRemoteCommandDelay = 0;
                        pImpl->bDoRemoteCommandDelay = FALSE;
                        pImpl->aTestCaseName.Erase();
                        pImpl->aTestCaseFileName.Erase();
                        pImpl->nTestCaseLineNr = 0;

                        pImpl->bEnableQaErrors = TRUE;
                        pImpl->bDebugFindNoErrors = FALSE;

                        pImpl->pChildEnv->clear();

                        String aName( CUniString( "StopOnSyntaxError" ) );
                        SbxVariableRef xStopOnSyntaxError = SbxObject::Find( aName, SbxCLASS_PROPERTY );
                        if ( xStopOnSyntaxError.Is() )
                            xStopOnSyntaxError->PutBool( pImpl->bStopOnSyntaxError );
                        else
                            SetError( SbxERR_BAD_ACTION );
                    }
                    else
                        SetError( SbxERR_WRONG_ARGS );
                    break;
                case ID_Use:
                    if ( rPar && rPar->Count() >= 2 )
                    {
                        SbxVariableRef pArg = rPar->Get( 1 );
                        DirEntry FilePath(pArg->GetString(),FSYS_STYLE_VFAT);
                        if ( !FilePath.IsAbs() )
                            FilePath = pImpl->aFileBase + FilePath;
                        String Ext = FilePath.GetExtension();
                        if ( Ext.CompareIgnoreCaseToAscii("Win") == COMPARE_EQUAL )
                        {
                            ReadNames( FilePath.GetFull(),m_pControls,pUIds);
                            pImpl->bLnaguageExtensionLoaded = TRUE;
                            SfxSimpleHint aHint( SBX_HINT_LANGUAGE_EXTENSION_LOADED );
                            GetTTBroadcaster().Broadcast( aHint );
                        }
                        else if ( Ext.CompareIgnoreCaseToAscii("Sid") == COMPARE_EQUAL )
                        {
                            ReadNames( FilePath.GetFull(),m_pSIds,pUIds,FLAT);
                            pImpl->bLnaguageExtensionLoaded = TRUE;
                            SfxSimpleHint aHint( SBX_HINT_LANGUAGE_EXTENSION_LOADED );
                            GetTTBroadcaster().Broadcast( aHint );
                        }
                        else if ( Ext.CompareIgnoreCaseToAscii("Bin") == COMPARE_EQUAL )
                        {
                            ReadNamesBin( FilePath.GetFull(), m_pSIds, m_pControls );
                            pImpl->bLnaguageExtensionLoaded = TRUE;
                            SfxSimpleHint aHint( SBX_HINT_LANGUAGE_EXTENSION_LOADED );
                            GetTTBroadcaster().Broadcast( aHint );
                        }
                        else if ( Ext.CompareIgnoreCaseToAscii("Inc") == COMPARE_EQUAL )
                        {
                            {
                                TTExecutionStatusHint aHint( TT_EXECUTION_SHOW_ACTION, String(SttResId(S_READING_BASIC_MODULE)), FilePath.GetFull() );
                                GetTTBroadcaster().Broadcast( aHint );
                            }
                            String aFullPathname = FilePath.GetFull();
                            StarBASIC *pBasic = (StarBASIC*)GetParent();
                            if ( !aModuleWinExistsHdl.Call( &aFullPathname ) &&
                                 !pBasic->FindModule( CUniString( "--" ).Append(aFullPathname) ) )
                            {
                                SbModule *pMod;
                                pMod = pBasic->MakeModule( CUniString("--"), String() );
                                pMod->Clear();
                                if ( Load( aFullPathname, pMod ) )
                                {
                                    if ( !IS_ERROR() )
                                    {
                                        pBasic->Compile( pMod );
                                        pMod->RunInit();
                                    }
                                }
                                else
                                {
                                    ADD_ERROR( SbxERR_CANNOT_LOAD, FilePath.GetFull() );
                                }
                            }
                            {
                                TTExecutionStatusHint aHint( TT_EXECUTION_HIDE_ACTION );
                                GetTTBroadcaster().Broadcast( aHint );
                            }
                        }
                        else
                        {
                            ADD_ERROR(SbxERR_CANNOT_LOAD,FilePath.GetFull());
                        }
                    }
                    else
                        SetError( SbxERR_WRONG_ARGS );
                    break;
                case ID_FinishUse:
                    if ( !rPar )  // rPar = NULL  <=>  Kein Parameter
                    {
                        ADD_CASE_LOG( String() );       // Case abschliessen
                        if (!m_pControls)
                            m_pControls = new CNames();

                        if (!m_pSIds)
                            m_pSIds = new CNames();

                        if (pUIds)
                        {   // save some memory
                            delete pUIds;
                            pUIds = NULL;
                        }

                        m_pNameKontext = m_pControls;

                        if ( pImpl->bLnaguageExtensionLoaded )
                        {
                            SfxSimpleHint aHint( SBX_HINT_LANGUAGE_EXTENSION_LOADED );
                            GetTTBroadcaster().Broadcast( aHint );
                        }

                        pImpl->nIncludeFileWarningCount = pImpl->nWarningCount;
                        pImpl->nWarningCount = 0;

                        *pImpl->xIncludeFileWarningList = *pImpl->xWarningList;
                        pImpl->xWarningList->SbxArray::Clear();
                    }
                    else
                        SetError( SbxERR_WRONG_ARGS );
                    break;
                case ID_CaseLog:
                    if ( rPar )  // rPar != NULL  <=>  Es gibt Parameter
                    {
                        USHORT n;
                        String aX;
                        for ( n = 1; n < rPar->Count(); n++ )
                        {
                            SbxVariableRef pArg = rPar->Get( n );
                            aX += pArg->GetString();
                        }
                        pImpl->aTestCaseName = aX;
                        if ( pImpl->aTestCaseName.Len() && BasicRuntimeAccess::HasRuntime() )
                        {
                            BasicRuntime aRun = BasicRuntimeAccess::GetRuntime();
                            pImpl->aTestCaseFileName = aRun.GetModuleName(SbxNAME_SHORT_TYPES);
                            if ( pImpl->aTestCaseFileName.Copy(0,2).CompareToAscii( "--" ) == COMPARE_EQUAL )
                                pImpl->aTestCaseFileName.Erase(0,2);
                            pImpl->nTestCaseLineNr = aRun.GetLine();
                        }
                        else
                        {
                            pImpl->aTestCaseFileName.Erase();
                            pImpl->nTestCaseLineNr = 0;
                        }
                        ADD_CASE_LOG( aX );
                    }
                    break;
                case ID_ExceptLog:
                    if ( IS_ERROR() )
                    {
                        BasicRuntime aRun = BasicRuntimeAccess::GetRuntime();
                        BOOL bWasNewError = FALSE;

                        if ( BasicRuntimeAccess::HasStack() )
                        {
                            for ( USHORT i = 0 ; i < BasicRuntimeAccess::GetStackEntryCount() -1 ; i++ )
                            {
                                BasicErrorStackEntry aThisEntry = BasicRuntimeAccess::GetStackEntry(i);
                                if ( !bWasNewError )
                                {
                                    bWasNewError = TRUE;
                                    ADD_ERROR_LOG( GET_ERROR()->aText, aThisEntry.GetModuleName(SbxNAME_SHORT_TYPES),
                                        aThisEntry.GetLine(), aThisEntry.GetCol1(), aThisEntry.GetCol2(), aThisEntry.GetSourceRevision() );
                                }
                                ADD_CALL_STACK_LOG( String(aThisEntry.GetModuleName(SbxNAME_SHORT_TYPES))
                                    .AppendAscii(": ").Append(aThisEntry.GetMethodName(SbxNAME_SHORT_TYPES)),
                                    aThisEntry.GetModuleName(SbxNAME_SHORT_TYPES),
                                    aThisEntry.GetLine(), aThisEntry.GetCol1(), aThisEntry.GetCol2() );

                            }
                            BasicRuntimeAccess::DeleteStack();
                        }

                        BOOL bIsFirst = TRUE;
                        while ( aRun.IsValid() )
                        {
                            xub_StrLen nErrLn;
                            xub_StrLen nCol1;
                            xub_StrLen nCol2;
                            if ( bIsFirst )
                            {
                                bIsFirst = FALSE;
                                nErrLn = GET_ERROR()->nLine;
                                nCol1 = GET_ERROR()->nCol1;
                                nCol2 = GET_ERROR()->nCol2;
                            }
                            else
                            {
                                nErrLn = aRun.GetLine();
                                nCol1 = aRun.GetCol1();
                                nCol2 = aRun.GetCol2();
                            }

                            if ( !bWasNewError )
                            {
                                bWasNewError = TRUE;
                                ADD_ERROR_LOG( GET_ERROR()->aText, aRun.GetModuleName(SbxNAME_SHORT_TYPES),
                                    nErrLn, nCol1, nCol2, aRun.GetSourceRevision() );
                            }
                            ADD_CALL_STACK_LOG( String(aRun.GetModuleName(SbxNAME_SHORT_TYPES))
                                .AppendAscii(": ").Append(aRun.GetMethodName(SbxNAME_SHORT_TYPES)),
                                aRun.GetModuleName(SbxNAME_SHORT_TYPES),
                                nErrLn, nCol1, nCol2 );
                            aRun = aRun.GetNextRuntime();
                        }
                    }
                    break;
                case ID_ErrorLog:
                    if ( IS_ERROR() )
                    {
                        BasicRuntime aRun = BasicRuntimeAccess::GetRuntime();
                        if ( BasicRuntimeAccess::HasStack() )
                        {
                            BasicErrorStackEntry aThisEntry = BasicRuntimeAccess::GetStackEntry( 0 );
                            ADD_ERROR_LOG( GET_ERROR()->aText, aThisEntry.GetModuleName(SbxNAME_SHORT_TYPES),
                                aThisEntry.GetLine(), aThisEntry.GetCol1(), aThisEntry.GetCol2(), aThisEntry.GetSourceRevision() );
                            BasicRuntimeAccess::DeleteStack();
                        }
                        else
                        {
                            ADD_ERROR_LOG( GET_ERROR()->aText, aRun.GetModuleName(SbxNAME_SHORT_TYPES),
                                StarBASIC::GetErl(), aRun.GetCol1(), aRun.GetCol2(), aRun.GetSourceRevision() );
                        }
                    }
                    break;
                case ID_QAErrorLog:
                    if ( rPar )  // rPar != NULL  <=>  Es gibt Parameter
                    {
                        USHORT n;
                        String aSammel;
                        for ( n = 1; n < rPar->Count(); n++ )
                        {
                            SbxVariableRef pArg = rPar->Get( n );
                            aSammel += pArg->GetString();
                        }
                        ADD_QA_ERROR_LOG( aSammel );
                    }
                    break;
                case ID_PrintLog:
                    if ( rPar )  // rPar != NULL  <=>  Es gibt Parameter
                    {
                        USHORT n;
                        String aSammel;
                        for ( n = 1; n < rPar->Count(); n++ )
                        {
                            SbxVariableRef pArg = rPar->Get( n );
                            aSammel += pArg->GetString();
                        }
                        ADD_MESSAGE_LOG( aSammel );
                    }
                    break;
                case ID_WarnLog:
                    if ( rPar )  // rPar != NULL  <=>  Es gibt Parameter
                    {
                        USHORT n;
                        String aSammel;
                        for ( n = 1; n < rPar->Count(); n++ )
                        {
                            SbxVariableRef pArg = rPar->Get( n );
                            aSammel += pArg->GetString();
                        }
                        ADD_WARNING_LOG( aSammel );

                    }
                    break;
                case ID_ClearError:
                    while ( IS_ERROR() )
                    {
                        POP_ERROR();
                    }
                    break;
                case ID_MaybeAddErr:
                    if ( ((StarBASIC*)GetParent())->GetErrBasic() && ( !IS_ERROR() ||
                         pFehlerListe->GetObject(pFehlerListe->Count()-1)->nError != ((StarBASIC*)GetParent())->GetErrBasic() ) )
                    {
                        ((StarBASIC*)GetParent())->MakeErrorText(((StarBASIC*)GetParent())->GetErrBasic(),String());
                        ADD_ERROR_QUIET(((StarBASIC*)GetParent())->GetErrBasic() , ((StarBASIC*)GetParent())->GetErrorText())
                    }
                    break;
                case ID_GetNextCloseWindow:
                    if ( !rPar )  // rPar = NULL  <=>  Kein Parameter
                    {
                        SetError( SbxERR_NOTIMP );
                    }
                    else
                        SetError( SbxERR_WRONG_ARGS );
                    break;
                case ID_RemoteCommand:
                    {
                        if ( SingleCommandBlock )
                            BeginBlock();
                        else
                            if ( ((SbxTransportMethod*)pVar)->nValue & M_WITH_RETURN )
                            {
                                SetError( SbxERR_NOTIMP );
                            }
                        if ( !IsError() )
                            In->GenCmdCommand ((USHORT)(((SbxTransportMethod*)pVar)->nValue),rPar);
                        if ( !IsError() && ((SbxTransportMethod*)pVar)->nValue & M_WITH_RETURN )
                        {
                            pImpl->pNextReturn = ((SbxTransportMethod*)pVar);
                            aNextReturnId = SmartId( ((SbxTransportMethod*)pVar)->nValue );
                        }
                        if ( SingleCommandBlock )
                            EndBlock();
                        if ( !IsError() && (USHORT)((SbxTransportMethod*)pVar)->nValue & M_WITH_RETURN )
                        {
                            WaitForAnswer();
                        }
                        // f�r einige noch etwas Nachbehandlung
                        switch ( ((SbxTransportMethod*)pVar)->nValue )
                        {
                            case RC_WinTree:
                                break;
                        }

                    }
                    break;
                case ID_Dispatch:
                    if ( !rPar || (rPar->Count() % 2) == 1 )  // rPar = NULL  <=>  Kein Parameter ansonsten Gerade Anzahl(Ungerade, da immer Anzahl+1
                    {
                        if ( SingleCommandBlock )
                            BeginBlock();
                        if ( !IsError() )
                            In->GenCmdSlot ( (USHORT)((SbxTransportMethod*)pVar)->nValue, rPar );
                        pVar->PutInteger( (USHORT)((SbxTransportMethod*)pVar)->nValue );
                        if ( SingleCommandBlock )
                            EndBlock();
                    }
                    else
                        SetError( SbxERR_WRONG_ARGS );
                    break;
                case ID_UNODispatch:
                    if ( !rPar )  // rPar = NULL  <=>  Kein Parameter ansonsten Gerade Anzahl(Ungerade, da immer Anzahl+1
                    {
                        if ( SingleCommandBlock )
                            BeginBlock();
                        if ( !IsError() )
                            In->GenCmdUNOSlot ( ((SbxTransportMethod*)pVar)->aUnoSlot );
                        pVar->PutString( ((SbxTransportMethod*)pVar)->aUnoSlot );
                        if ( SingleCommandBlock )
                            EndBlock();
                    }
                    else
                        SetError( SbxERR_WRONG_ARGS );
                    break;
                case ID_Control:
                case ID_StringControl:
                    // if only the object is given in the script we don't have to do anything (object stands for itself)
                    if ( !pVar->ISA( SbxObject ) )
                    {
                        if ( SingleCommandBlock )
                            BeginBlock();
                        else
                            if ( ((SbxTransportMethod*)pVar)->nValue & M_WITH_RETURN )
                            {
                                SetError( SbxERR_NOTIMP );
                            }
                        if ( !IsError() )
                        {
                            SbxVariable *pMember = NULL;
                            if ( pVar->GetParent() )
                                pMember = pVar->GetParent()->Find(CUniString("ID"),SbxCLASS_DONTCARE);
                            if ( pMember == NULL )
                            {
                                SetError( SbxERR_NAMED_NOT_FOUND );
                            }
                            else
                            {
                                if ( nHintUserData == ID_Control )
                                {
                                    In->GenCmdControl (pMember->GetULong(),
                                        (USHORT)((SbxTransportMethod*)pVar)->nValue, rPar);
                                    aNextReturnId = SmartId( pMember->GetULong() );
                                }
                                else
                                {
                                    In->GenCmdControl (pMember->GetString(),
                                        (USHORT)((SbxTransportMethod*)pVar)->nValue, rPar);
                                    aNextReturnId = SmartId( pMember->GetString() );
                                }
                            }

                            if ( !IsError() && ((SbxTransportMethod*)pVar)->nValue & M_WITH_RETURN )
                            {
                                pImpl->pNextReturn = ((SbxTransportMethod*)pVar);
                            }
                            else
                            {
                                pImpl->pNextReturn = NULL;
                                aNextReturnId = SmartId();
                            }

                        }
                        if ( SingleCommandBlock )
                            EndBlock();
                        if ( !IsError() && (USHORT)((SbxTransportMethod*)pVar)->nValue & M_WITH_RETURN )
                        {
                            WaitForAnswer();
                        }
                    }

                    break;
                case ID_GetUnoApp:
                    {
                        // Hier wird der Remote UNO Kram gestartet
                        // Eintrag in die Konfiguration unter
                        // org.openoffice.Office.Common/Start/Connection
                        //  socket,host=0,port=12345;iiop;XBla
                        // oder
                        //  socket,host=0,port=12345;urp;;XBla

                        String aString;
                        aString.AppendAscii( "socket,host=" );
                        aString += GetHostConfig();
                        aString.AppendAscii( ",port=" );
                        aString += String::CreateFromInt32( GetUnoPortConfig() );

                           Reference< XMultiServiceFactory > smgr_xMultiserviceFactory;
                        try
                        {
                            Reference< XMultiServiceFactory > xSMgr = comphelper::getProcessServiceFactory();

                            OUString aURL( aString );
                            Reference< XConnector > xConnector( xSMgr->createInstance(
                                OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.connection.Connector") ) ), UNO_QUERY );
                            Reference< XConnection > xConnection( xConnector->connect( aURL ) );

                            Reference< XBridgeFactory > xBridgeFactory( xSMgr->createInstance(
                                OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.bridge.BridgeFactory") ) ), UNO_QUERY );
                            Reference< XBridge > xBridge( xBridgeFactory->createBridge(
                                OUString(), OUString( RTL_CONSTASCII_USTRINGPARAM("urp") ),
                                xConnection, Reference< XInstanceProvider >() ) );

                            Reference< XInterface > xRet( xBridge->getInstance( OUString( RTL_CONSTASCII_USTRINGPARAM("StarOffice.ServiceManager")) ) );

                            smgr_xMultiserviceFactory = Reference< XMultiServiceFactory >(xRet, UNO_QUERY);
    //MBA fragen!!
                        }
                        catch( class Exception & rEx)
                        {
                            ADD_ERROR(SbxERR_BAD_ACTION, String( rEx.Message ) );
                        }
                        catch( ... )
                        {
                            ADD_ERROR(SbxERR_BAD_ACTION, CUniString( "Unknown Error" ) );
                        }

                        if( smgr_xMultiserviceFactory.is() )
                        {
                            Any aAny;
                            aAny <<= smgr_xMultiserviceFactory;

                            SbxObjectRef xMySbxObj = GetSbUnoObject( CUniString("RemoteUnoAppFuerTesttool"), aAny );
                            if ( xMySbxObj.Is() )
                                pVar->PutObject( xMySbxObj );
                        }
                    }
                    break;
                case ID_GetIServer:
                    {
                        // Hier wird der Remote UNO Kram gestartet

                        String aString;

                        Reference< XMultiServiceFactory > xSMgr;
                        {
                            xSMgr = ::cppu::createRegistryServiceFactory(OUString(RTL_CONSTASCII_USTRINGPARAM("g:\\iserverproxy.rdb")), sal_True);
                        }

                        OUString aURL( aString );
                        Reference< XConnector > xConnector( xSMgr->createInstance(
                            OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.connection.Connector") ) ), UNO_QUERY );
                        Reference< XConnection > xConnection( xConnector->connect( OUString( RTL_CONSTASCII_USTRINGPARAM("socket,host=grande,port=7453")) ) );

                        Reference< XBridgeFactory > xBridgeFactory( xSMgr->createInstance(
                            OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.bridge.BridgeFactory") ) ), UNO_QUERY );
                        Reference< XBridge > xBridge( xBridgeFactory->createBridge(
                            OUString(), OUString( RTL_CONSTASCII_USTRINGPARAM("urp") ),
                            xConnection, Reference< XInstanceProvider >() ) );

                        Reference< XInterface > xRet( xBridge->getInstance( OUString( RTL_CONSTASCII_USTRINGPARAM("XIServerProxy")) ) );


                        if( xRet.is() )
                        {
                            Any aAny;
                            aAny <<= xRet;

                            SbxObjectRef xMySbxObj = GetSbUnoObject( CUniString("IServerProxy"), aAny );
                            if ( xMySbxObj.Is() )
                                pVar->PutObject( xMySbxObj );
                        }
                        // In Basic:
                        // msgbox dbg_SupportedInterfaces
                        // msgbox dbg_Properties
                        // msgbox dbg_Methods
                    }
                    break;
                case ID_RemoteCommandDelay:
                    if ( rPar && rPar->Count() >= 2 && rPar->Count() <=3 )
                    {
                        switch (rPar->Get( 1 )->GetType())
                        {
                            case SbxLONG:       // alles immer als Short �bertragen
                            case SbxULONG:
                            case SbxSALINT64:
                            case SbxSALUINT64:
                            case SbxDOUBLE:
                            case SbxINTEGER:
                            case SbxBYTE:
                            case SbxUSHORT:
                            case SbxINT:
                            case SbxUINT:
                            case SbxSINGLE:
                                pImpl->nMinRemoteCommandDelay = rPar->Get( 1 )->GetULong();
                                if ( rPar->Count() == 3 )
                                    pImpl->nMaxRemoteCommandDelay = rPar->Get( 2 )->GetULong();
                                else
                                    pImpl->nMaxRemoteCommandDelay = pImpl->nMinRemoteCommandDelay;
                                break;
                            case SbxBOOL:
                                pImpl->bDoRemoteCommandDelay = rPar->Get( 1 )->GetBool();
                                break;
                            default:
                                SbxBase::SetError( SbxERR_WRONG_ARGS );
                                break;
                        }
                    }
                    else
                        SetError( SbxERR_WRONG_ARGS );
                    break;
                case ID_GetApplicationPath:
                    if ( !rPar )
                    {
                        OUString aUrl = Config::GetDefDirectory();
                        OUString aPath;
                        osl::FileBase::getSystemPathFromFileURL( aUrl, aPath );
                        pVar->PutString( String( aPath ) );
                    }
                    else
                        SetError( SbxERR_WRONG_ARGS );
                    break;
                case ID_GetCommonApplicationPath:
                    if ( !rPar )
                    {
#ifdef WNT
                        ////////  adapted this from setup2\win\source\system\winos.cxx
                        String aSysPath;
                        aSysPath = _SHGetSpecialFolder_COMMON_APPDATA();
                        if ( aSysPath.Len() )
                        {
                            pVar->PutString( aSysPath );
                        }
                        else    // default to ID_GetApplicationPath (same as in setup)
                        {
                            OUString aUrl = Config::GetDefDirectory();
                            OUString aPath;
                            osl::FileBase::getSystemPathFromFileURL( aUrl, aPath );
                            pVar->PutString( String( aPath ) );
                        }
#elif defined OS2
                        {
                            char* etc = getenv("ETC");
                            if (etc)
                               pVar->PutString( CUniString( etc ) );
                            else
                               pVar->PutString( CUniString( "/etc" ) );
                        }
#else
#if UNX
                        pVar->PutString( CUniString( "/etc" ) );
#else
#error not implemented
#endif
#endif
                    }
                    else
                        SetError( SbxERR_WRONG_ARGS );
                    break;
                case ID_MakeIniFileName:
                    if ( rPar && rPar->Count() == 2 )
                    {
                        OUString aUrl = Config::GetConfigName( String(), rPar->Get( 1 )->GetString() );
                        OUString aPath;
                        osl::FileBase::getSystemPathFromFileURL( aUrl, aPath );
                        pVar->PutString( String( aPath ) );
                    }
                    else
                        SetError( SbxERR_WRONG_ARGS );
                    break;
                case ID_Wait:
                    {
                        if( rPar && rPar->Count() == 2 )
                        {
                            long nWait = rPar->Get(1)->GetLong();
                            if( nWait >= 0 )
                            {
#ifdef DEBUG
                                Time aStart;
#endif
                                Timer aTimer;
                                aTimer.SetTimeout( nWait );
                                aTimer.Start();
                                while ( aTimer.IsActive() )
                                    Application::Yield();
#ifdef DEBUG
                                Time aEnd;
                                Time aDiff = aEnd - aStart;
                                long aMS = long( aDiff.GetMSFromTime() );
                                if ( Abs( aMS - nWait ) > 100 )
                                {
                                    DBG_ERROR1("Wait was off limit by %i", aDiff.GetMSFromTime() - nWait );
                                }
#endif
                            }
                        }
                        else
                            SetError( SbERR_BAD_NUMBER_OF_ARGS );
                    }
                    break;
                case ID_GetErrorCount:
                    {
                        pVar->PutULong( pImpl->nErrorCount );
                    }
                    break;
                case ID_GetWarningCount:
                    {
                        pVar->PutULong( pImpl->nWarningCount );
                    }
                    break;
                case ID_GetQAErrorCount:
                    {
                        pVar->PutULong( pImpl->nQAErrorCount );
                    }
                    break;
                case ID_GetUseFileWarningCount:
                    {
                        pVar->PutULong( pImpl->nIncludeFileWarningCount );
                    }
                    break;
                case ID_GetErrorList:
                    {
                        if ( ! pImpl->xErrorList->GetDims() )
                            pImpl->xErrorList->AddDim( 1, 32000 );
                        pVar->PutObject( pImpl->xErrorList );
                    }
                    break;
                case ID_GetWarningList:
                    {
                        if ( ! pImpl->xWarningList->GetDims() )
                            pImpl->xWarningList->AddDim( 1, 32000 );
                        pVar->PutObject( pImpl->xWarningList );
                    }
                    break;
                case ID_GetQAErrorList:
                    {
                        if ( ! pImpl->xQAErrorList->GetDims() )
                            pImpl->xQAErrorList->AddDim( 1, 32000 );
                        pVar->PutObject( pImpl->xQAErrorList );
                    }
                    break;
                case ID_GetUseFileWarningList:
                    {
                        if ( ! pImpl->xIncludeFileWarningList->GetDims() )
                            pImpl->xIncludeFileWarningList->AddDim( 1, 32000 );
                        pVar->PutObject( pImpl->xIncludeFileWarningList );
                    }
                    break;
                case ID_GetTestCaseName:
                    {
                        pVar->PutString( pImpl->aTestCaseName );
                    }
                    break;
                case ID_GetTestCaseFileName:
                    {
                        pVar->PutString( pImpl->aTestCaseFileName );
                    }
                    break;
                case ID_GetTestCaseLineNr:
                    {
                        pVar->PutUShort( pImpl->nTestCaseLineNr );
                    }
                    break;
                case ID_SetChildEnv:
                    {
                        if( rPar && rPar->Count() == 3 )
                        {
                            pImpl->pChildEnv->erase( rPar->Get(1)->GetString() );
                            pImpl->pChildEnv->insert( EnvironmentVariable( rPar->Get(1)->GetString(), rPar->Get(2)->GetString() ) );
                        }
                        else
                            SetError( SbERR_BAD_NUMBER_OF_ARGS );
                    }
                    break;
                case ID_GetChildEnv:
                    {
                        if( rPar && rPar->Count() == 2 )
                        {
                            Environment::const_iterator aIter = pImpl->pChildEnv->find( rPar->Get(1)->GetString() );
                            if ( aIter != pImpl->pChildEnv->end() )
                                pVar->PutString( (*aIter).second );
                            else
                                pVar->PutString( String() );
                        }
                        else
                            SetError( SbERR_BAD_NUMBER_OF_ARGS );
                    }
                    break;
                case ID_GetLinkDestination:
                    {
                        if( rPar && rPar->Count() == 2 )
                        {
                            String aSource,aDest;
                            aSource = rPar->Get(1)->GetString();
#ifdef UNX
                            ByteString aByteSource( aSource, osl_getThreadTextEncoding() );
                            char cDest[1024];
                            int nLen = 0;
                            if ( ( nLen = readlink( aByteSource.GetBuffer(), cDest, sizeof(cDest) ) ) >= 0 )
                            {
                                aDest = String( cDest, nLen, osl_getThreadTextEncoding() );
                            }
                            else
                            {
                                int nErr = errno;
                                switch ( nErr )
                                {
                                    case EINVAL: aDest = aSource;
                                        break;
                                    default:
                                        SetError( SbERR_ACCESS_ERROR );
                                }
                            }
#else
                            aDest = aSource;
#endif
                            pVar->PutString( aDest );
                        }
                        else
                            SetError( SbERR_BAD_NUMBER_OF_ARGS );
                    }
                    break;
                case ID_GetRegistryValue:
                    {
                        if( rPar && rPar->Count() == 3 )
                        {
                            String aValue;
#ifdef WNT
                            aValue = ReadRegistry( rPar->Get(1)->GetString(), rPar->Get(2)->GetString() );
#endif
                            pVar->PutString( aValue );
                        }
                        else
                            SetError( SbERR_BAD_NUMBER_OF_ARGS );
                    }
                    break;
                case ID_HTTPSend:
                    {
                        if( rPar && ( rPar->Count() == 4 || rPar->Count() == 5 ) )
                        {
                            if ( !pImpl->pHttpRequest )
                                pImpl->pHttpRequest = new HttpRequest;
                            pImpl->pHttpRequest->SetRequest( ByteString( rPar->Get(1)->GetString(), RTL_TEXTENCODING_ASCII_US ), ByteString( rPar->Get(2)->GetString(), RTL_TEXTENCODING_ASCII_US ), rPar->Get(3)->GetUShort() );

                            if ( pImpl->pHttpRequest->Execute() )
                            {
                                if ( rPar->Count() == 5 )
                                {   // filename is given
                                    SvFileStream aDestination( rPar->Get(4)->GetString(), STREAM_STD_READWRITE | STREAM_TRUNC );
                                    (*(pImpl->pHttpRequest->GetBody())) >> aDestination;
                                    if ( aDestination.GetError() != ERRCODE_NONE )
                                        SetError( SbERR_ACCESS_ERROR );
                                    aDestination.Close();
                                }
                                pVar->PutUShort( pImpl->pHttpRequest->GetResultId() );
                            }
                            else
                                SetError( SbERR_ACCESS_ERROR );
                        }
                        else
                            SetError( SbERR_BAD_NUMBER_OF_ARGS  );
                    }
                    break;
                case ID_HTTPSetProxy:
                    {
                        if( rPar && rPar->Count() == 3 )
                        {
                            if ( !pImpl->pHttpRequest )
                                pImpl->pHttpRequest = new HttpRequest;
                            pImpl->pHttpRequest->SetProxy( ByteString( rPar->Get(1)->GetString(), RTL_TEXTENCODING_ASCII_US ), rPar->Get(2)->GetUShort() );
                        }
                        else
                            SetError( SbERR_BAD_NUMBER_OF_ARGS );
                    }
                    break;
            }  //  switch( nHintUserData )
        }  // if( nHintId == SBX_HINT_DATAWANTED )
        else if( nHintId == SBX_HINT_DATACHANGED )
        {
            switch( nHintUserData )
            {
                case ID_AutoExecute:
                    if ( !rPar )  // rPar = NULL  <=>  Kein Parameter
                    {
                        SingleCommandBlock = pVar->GetBool();
                        if ( SingleCommandBlock )
                            EndBlock();
                        else
                            BeginBlock();
                    }
                    else
                        SetError( SbxERR_WRONG_ARGS );
                    break;
                case ID_EnableQaErrors:
                    if ( !rPar )  // rPar = NULL  <=>  Kein Parameter
                        pImpl->bEnableQaErrors = pVar->GetBool();
                    else
                        SetError( SbxERR_WRONG_ARGS );
                    break;
            }
        }  // if( nHintId == SBX_HINT_DATACHANGED )
        else if( nHintId == SBX_HINT_BASICSTART )
        {
            pImpl->nErrorCount = 0;
            pImpl->nWarningCount = 0;
            pImpl->nQAErrorCount = 0;
            pImpl->nIncludeFileWarningCount = 0;

            pImpl->xErrorList->SbxArray::Clear();   // call SbxArray::Clear because SbxVarArray::Clear only clears dimensions but no content
            pImpl->xWarningList->SbxArray::Clear(); // call SbxArray::Clear because SbxVarArray::Clear only clears dimensions but no content
            pImpl->xQAErrorList->SbxArray::Clear();   // call SbxArray::Clear because SbxVarArray::Clear only clears dimensions but no content
            pImpl->xIncludeFileWarningList->SbxArray::Clear();  // call SbxArray::Clear because SbxVarArray::Clear only clears dimensions but no content

            if (pFehlerListe)
                delete pFehlerListe;
            pFehlerListe = new CErrors;

            for (USHORT i=0;i<VAR_POOL_SIZE;i++)
            {
                pImpl->pMyVars[i]->SetName( CUniString("VarDummy").Append(UniString::CreateFromInt32(i)) );
            }
            nMyVar = 0;

        }  // if( nHintId == SBX_HINT_BASICSTART )
        else if( nHintId == SBX_HINT_BASICSTOP )
        {
            // Log summary to journal
            ADD_CASE_LOG( String() );       // Case abschliessen
            ADD_MESSAGE_LOG( CUniString("***************************************************") );
            if ( pImpl->nErrorCount )
            {
                ADD_WARNING_LOG( GEN_RES_STR1( S_ERRORS_DETECTED, String::CreateFromInt32( pImpl->nErrorCount ) ) );
                pImpl->nWarningCount--;     // Anpassen, da diese Warnung nicht in die Statistik soll
            }
            else
                ADD_MESSAGE_LOG( GEN_RES_STR0( S_NO_ERRORS_DETECTED ) );

            if ( pImpl->nWarningCount )
                ADD_WARNING_LOG( GEN_RES_STR1( S_WARNINGS_DETECTED, String::CreateFromInt32( pImpl->nWarningCount ) ) )
            else
                ADD_MESSAGE_LOG( GEN_RES_STR0( S_NO_WARNINGS_DETECTED ) );

            if ( pImpl->nIncludeFileWarningCount )
                ADD_WARNING_LOG( GEN_RES_STR1( S_INCLUDE_FILE_WARNINGS_DETECTED, String::CreateFromInt32( pImpl->nIncludeFileWarningCount ) ) )
            else
                ADD_MESSAGE_LOG( GEN_RES_STR0( S_NO_INCLUDE_FILE_WARNINGS_DETECTED ) );
            ADD_MESSAGE_LOG( CUniString("***************************************************") );

            pImpl->nErrorCount = 0;
            pImpl->nWarningCount = 0;
            pImpl->nQAErrorCount = 0;
            pImpl->nIncludeFileWarningCount = 0;

            pImpl->xErrorList->SbxArray::Clear();   // call SbxArray::Clear because SbxVarArray::Clear only clears dimensions but no content
            pImpl->xWarningList->SbxArray::Clear(); // call SbxArray::Clear because SbxVarArray::Clear only clears dimensions but no content
            pImpl->xQAErrorList->SbxArray::Clear();   // call SbxArray::Clear because SbxVarArray::Clear only clears dimensions but no content
            pImpl->xIncludeFileWarningList->SbxArray::Clear();  // call SbxArray::Clear because SbxVarArray::Clear only clears dimensions but no content
        }  // if( nHintId == SBX_HINT_BASICSTOP )
        WaitForAnswer();
        if ( IsError() && ( !IS_ERROR() || GET_ERROR()->nError != GetError() ) )
        {
            ((StarBASIC*)GetParent())->MakeErrorText(GetError(),String());
            ADD_ERROR_QUIET(GetError(),String(pVar->GetName()).AppendAscii(": ").
                Append(((StarBASIC*)GetParent())->GetErrorText()));
        }
    }
}

void TestToolObj::DebugFindNoErrors( BOOL bDebugFindNoErrors )
{
    pImpl->bDebugFindNoErrors = bDebugFindNoErrors;
}

SbxVariable* TestToolObj::Find( const String& aStr, SbxClassType aType)
{
    if ( BasicRuntimeAccess::IsRunInit() )            // wegen Find im "Global" Befehl des Basic
        return NULL;

    SbxVariableRef Old = SbxObject::Find(aStr, aType );
    // do not return any objects from pMyVars[]
    if (Old && Old->GetUserData() != ID_Dispatch
            && Old->GetUserData() != ID_UNODispatch
            && Old->GetUserData() != ID_ErrorDummy
            && Old->GetUserData() != 0 )
        return Old;
    else if ( aStr.SearchAscii(":") != STRING_NOTFOUND )
    {   // ignore qualified names e.g.  main:FormWizard     If this was removed an error would be generated
    }
    else
    {

        USHORT nElement;
        ControlDef *pWhatName = new ControlDef(aStr,SmartId());

        /// nach Controls suchen
        if (m_pNameKontext && m_pNameKontext->Seek_Entry(pWhatName,&nElement))
        {
            delete pWhatName;
            pWhatName = ((ControlDef*)m_pNameKontext->GetObject(nElement));

//// new Controls Object every time
            pImpl->pControlsObj = new Controls( pWhatName->pData->Kurzname );
            pImpl->pControlsObj->SetType( SbxOBJECT );
            pImpl->pControlsObj->ChangeListener( this );


            // Will be set on method-child further down
            if ( pWhatName->pData->aUId.HasNumeric() )
                pImpl->pControlsObj->SetUserData( ID_Control );
            else
                pImpl->pControlsObj->SetUserData( ID_StringControl );

            pShortNames->Insert(pWhatName->pData->Kurzname,pWhatName->pData->aUId,nSequence);

            SbxVariable *pMember = pImpl->pControlsObj->Find(CUniString("ID"),SbxCLASS_DONTCARE);
            if ( pMember == NULL )
            {
                SbxProperty* pID = new SbxProperty(CUniString("ID"),SbxVARIANT);
                pImpl->pControlsObj->Insert(pID);
                pImpl->pControlsObj->SetDfltProperty(pID);
                pMember = pID;
            }
            if ( pWhatName->pData->aUId.HasNumeric() )
                pMember->PutULong(pWhatName->pData->aUId.GetNum());
            else
                pMember->PutString(pWhatName->pData->aUId.GetStr());

            pMember = pImpl->pControlsObj->Find(CUniString("name"),SbxCLASS_DONTCARE);
            if ( pMember != NULL )
                pMember->PutString(pWhatName->pData->Kurzname);

            return pImpl->pControlsObj;
        }

        /// Nach slots suchen
        if (m_pSIds && m_pSIds->Seek_Entry(pWhatName,&nElement))
        {
            SbxTransportMethodRef pMyVar;
            pMyVar = pImpl->pMyVars[nMyVar++];
            if ( nMyVar >= VAR_POOL_SIZE )
                nMyVar = 0;
            delete pWhatName;
            pWhatName = ( (ControlDef*)m_pSIds->GetObject( nElement ) );
            pMyVar->SetName( pWhatName->pData->Kurzname );

            if ( pWhatName->pData->aUId.HasNumeric() )
            {
                pMyVar->SetUserData( ID_Dispatch );
                pMyVar->nValue = pWhatName->pData->aUId.GetNum();
                pShortNames->Insert( aStr, pWhatName->pData->aUId, nSequence );
            }
            else
            {
                pMyVar->SetUserData( ID_UNODispatch );
                pMyVar->aUnoSlot = pWhatName->pData->aUId.GetStr();
            }
            return pMyVar;
        }

        /// es kann sich noch um eine SlotID handeln, die numerisch abgefragt wird, statt ausgef�hrt zu werden
        if ( aStr.Copy( aStr.Len()-3, 3 ).CompareIgnoreCaseToAscii("_ID") == COMPARE_EQUAL && m_pSIds )
        {
            delete pWhatName;
            pWhatName = new ControlDef( aStr.Copy( 0, aStr.Len()-3 ), SmartId() );
            if ( m_pSIds->Seek_Entry( pWhatName, &nElement ) )
            {   // Nach slots suchen
                SbxVariable *pReturn = new SbxVariable;
                delete pWhatName;
                pWhatName = ( (ControlDef*)m_pSIds->GetObject( nElement ) );
                pReturn->SetName( pWhatName->pData->Kurzname );

                if ( pWhatName->pData->aUId.HasNumeric() )
                    pReturn->PutULong(pWhatName->pData->aUId.GetNum());
                else
                    pReturn->PutString(pWhatName->pData->aUId.GetStr());
                return pReturn;
            }
        }
        if ( !pImpl->bDebugFindNoErrors )
        {
            ADD_ERROR(SbxERR_PROC_UNDEFINED,GEN_RES_STR1(S_UNKNOWN_SLOT_CONTROL, aStr) );
        }
    }
    return NULL;
}

String TestToolObj::GetRevision( String const &aSourceIn )
{
    // search $Revision: 1.40 $
    xub_StrLen nPos;
    if ( ( nPos = aSourceIn.SearchAscii( "$Revision:" ) ) != STRING_NOTFOUND )
        return aSourceIn.Copy( nPos+ 10, aSourceIn.SearchAscii( "$", nPos+10 ) -nPos-10);
    else
        return String::CreateFromAscii("No Revision found");
}

BOOL TestToolObj::CError( ULONG code, const String& rMsg, xub_StrLen l, xub_StrLen c1, xub_StrLen c2 )
{
    bWasPrecompilerError = TRUE;
    if ( aCErrorHdl.IsSet() )
    {
        ErrorEntry aErrorEntry( code, rMsg, l, c1, c2 );
        return (BOOL)aCErrorHdl.Call( &aErrorEntry );
    }
    else
    {
        ADD_ERROR( code, rMsg )
        return TRUE;
    }
}

void TestToolObj::CalcPosition( String const &aSource, xub_StrLen nPos, xub_StrLen &l, xub_StrLen &c )
{
    l = 1;
    xub_StrLen nAkt = 0;
    xub_StrLen nNext;
    while ( (nNext = aSource.Search( '\n', nAkt )) != STRING_NOTFOUND && nNext < nPos )
    {
        l++;
        nAkt = nNext+1;
    }
    c = nPos - nAkt;
}


#define CATCH_LABEL         CUniString( "ctch" )
#define CATCHRES_LABEL      CUniString( "ctchres" )
#define ENDCATCH_LABEL      CUniString( "endctch" )

BOOL IsAlphaChar( sal_Unicode cChar )
{
    return  ( cChar >= 'a' && cChar <= 'z' ) ||
            ( cChar >= 'A' && cChar <= 'Z' );
}

BOOL IsInsideString( const String& aSource, const xub_StrLen nStart )
{
    BOOL bInside = FALSE;
    xub_StrLen nPos = nStart-1;

    while ( nPos && aSource.GetChar(nPos) != _CR && aSource.GetChar(nPos) != _LF )
    {
        if ( aSource.GetChar(nPos) == '"' )
            bInside = !bInside;
        nPos--;
    }
    return bInside;
}

BOOL IsValidHit( const String& aSource, const xub_StrLen nStart, const xub_StrLen nEnd )
{
    return !IsAlphaChar( aSource.GetChar(nStart-1) ) && !IsAlphaChar( aSource.GetChar(nEnd+1))
        && !IsInsideString( aSource, nStart );
}


xub_StrLen TestToolObj::ImplSearch( const String &aSource, const xub_StrLen nStart, const xub_StrLen nEnd, const String &aSearch, const xub_StrLen nSearchStart )
{
    xub_StrLen nPos = aSource.Search( aSearch, std::max( nSearchStart, nStart ) );
    if ( nPos > nEnd - aSearch.Len() || nPos == STRING_NOTFOUND )
        return STRING_NOTFOUND;
    else
    {
        if ( IsValidHit( aSource, nPos, nPos+aSearch.Len()-1 ) )
            return nPos;
        else
            return ImplSearch( aSource, nStart, nEnd, aSearch, nPos+aSearch.Len() );
    }
}

xub_StrLen TestToolObj::PreCompilePart( String &aSource, xub_StrLen nStart, xub_StrLen nEnd, String aFinalErrorLabel, USHORT &nLabelCount )
{
    xub_StrLen nTry,nCatch,nEndcatch;
    if( (nTry = ImplSearch( aSource, nStart, nEnd, CUniString("try"), nStart )) == STRING_NOTFOUND )
        return nEnd;
    if ( (nCatch = ImplSearch( aSource, nStart, nEnd, CUniString("catch"), nTry )) == STRING_NOTFOUND )
    {
        xub_StrLen l,c;
        CalcPosition( aSource, nTry, l, c );
        CError( SbERR_BAD_BLOCK, CUniString("catch"), l, c, c+2 );
        return nEnd;
    }
    if ( (nEndcatch = ImplSearch( aSource, nStart, nEnd, CUniString("endcatch"), nCatch )) == STRING_NOTFOUND )
    {
        xub_StrLen l,c;
        CalcPosition( aSource, nCatch, l, c );
        CError( SbERR_BAD_BLOCK, CUniString("endcatch"), l, c, c+4 );
        return nEnd;
    }

    nLabelCount++;
    String aStr = String::CreateFromInt32( nLabelCount );
    String aCatchLabel(CATCH_LABEL);
    aCatchLabel += aStr;
    String aCatchresLabel(CATCHRES_LABEL);
    aCatchresLabel += aStr;
    String aEndcatchLabel( ENDCATCH_LABEL);
    aEndcatchLabel += aStr;

    xub_StrLen nTry2 = 0;
    while ( !WasPrecompilerError() && (nTry2 = ImplSearch( aSource, nStart, nEnd, CUniString("try"), nTry+1 )) != STRING_NOTFOUND )
    {   // Wir rekursieren erstmal mit dem 2. Try
        if ( nTry2 < nCatch )
            nEnd += PreCompilePart( aSource, nTry2, nEndcatch+8, aCatchLabel, nLabelCount ) - nEndcatch-8;
        else
            nEnd = PreCompilePart( aSource, nTry2, nEnd, aFinalErrorLabel, nLabelCount );

        if ( (nCatch = ImplSearch( aSource, nStart, nEnd, CUniString("catch"), nTry )) == STRING_NOTFOUND )
        {
            xub_StrLen l,c;
            CalcPosition( aSource, nTry, l, c );
            CError( SbERR_BAD_BLOCK, CUniString("catch"), l, c, c+2 );
            return nEnd;
        }
        if ( (nEndcatch = ImplSearch( aSource, nStart, nEnd, CUniString("endcatch"), nCatch )) == STRING_NOTFOUND )
        {
            xub_StrLen l,c;
            CalcPosition( aSource, nCatch, l, c );
            CError( SbERR_BAD_BLOCK, CUniString("endcatch"), l, c, c+4 );
            return nEnd;
        }
    }

    String aReplacement;
    int nTotalLength = -3 -5 -8;    // try, catch und endcatch fallen raus

    aReplacement.AppendAscii( "on error goto " );
    aReplacement += aCatchLabel;
    aSource.SearchAndReplaceAscii( "try", aReplacement, nTry );
    nTotalLength += aReplacement.Len();

    aReplacement.Erase();
    aReplacement.AppendAscii( "on error goto " );
    aReplacement += aFinalErrorLabel;
    aReplacement.AppendAscii( " : goto " );
    aReplacement += aEndcatchLabel;
    aReplacement.AppendAscii( " : " );
    aReplacement += aCatchLabel;
    aReplacement.AppendAscii( ": if err = 35 or err = 18 then : on error goto 0 : resume : endif" );
    aReplacement.AppendAscii( " : MaybeAddErr : on error goto " );
    aReplacement += aFinalErrorLabel;
    aReplacement.AppendAscii( " : resume " );
    aReplacement += aCatchresLabel;
    aReplacement.AppendAscii( " : " );
    aReplacement += aCatchresLabel;
    aReplacement.AppendAscii( ": " );
    aSource.SearchAndReplaceAscii( "catch", aReplacement, nCatch );
    nTotalLength += aReplacement.Len();


    aReplacement.Erase();
    aReplacement.AppendAscii("ClearError : ");
    aReplacement += aEndcatchLabel;
    aReplacement.AppendAscii(": ");
    aSource.SearchAndReplaceAscii( "endcatch", aReplacement, nEndcatch );
    nTotalLength += aReplacement.Len();

    if ( aSource.Len() >= STRING_MAXLEN )
    {
        xub_StrLen l,c;
        CalcPosition( aSource, nEndcatch, l, c );
        CError( SbERR_PROG_TOO_LARGE, CUniString("endcatch"), l, c, c+2 );
    }

    return xub_StrLen( nEnd + nTotalLength );
}


void TestToolObj::PreCompileDispatchParts( String &aSource, String aStart, String aEnd, String aFinalLable )
{
    USHORT nLabelCount = 0;
    xub_StrLen nPartPos = 0;

    while ( !WasPrecompilerError() && (nPartPos = ImplSearch( aSource, nPartPos, aSource.Len(), aStart )) != STRING_NOTFOUND )
    {
        xub_StrLen nEndPart = ImplSearch( aSource, nPartPos, aSource.Len(), aEnd );
        if ( nEndPart == STRING_NOTFOUND )
            return;
        nPartPos = PreCompilePart( aSource, nPartPos, nEndPart, aFinalLable, nLabelCount );
        nPartPos = nPartPos + aEnd.Len();
    }
}


BOOL TestToolObj::WasPrecompilerError()
{
    return bWasPrecompilerError;
}

String TestToolObj::PreCompile( String const &aSourceIn )
{
    // Im CTOR zu fr�h, und hier grade nicg rechtzeitig. Start und Stop von Programmausf�hrung
    StartListening( ((StarBASIC*)GetParent())->GetBroadcaster(), TRUE );

    xub_StrLen nTestCase;
    xub_StrLen nEndCase;
    xub_StrLen nStartPos = 0;
    String aSource(aSourceIn);
    bWasPrecompilerError = FALSE;

HACK("Ich gestehe alles: Ich war zu faul das richtig zu machen.")
    aSource = String(' ').Append( aSource );        // Da Schl�sselworte an Position 0 sonst nicht gefunden werden


//      Erstmal alle "'" Kommentare raus

    xub_StrLen nComment;
    while ( (nComment = aSource.SearchAscii("'",nStartPos)) != STRING_NOTFOUND )
    {
        USHORT nStringEndCount = 0;
        xub_StrLen nIndex = nComment;
        while ( nIndex && aSource.GetChar(nIndex) != '\n' )
        {
            if ( aSource.GetChar(nIndex) == '"' )
                nStringEndCount++;
            nIndex--;
        }
        if ( (nStringEndCount & 1) == 0 )       // Wir waren also nicht innerhalb eines Strings
        {
            xub_StrLen nComEnd = aSource.SearchAscii("\n",nComment);

            while ( aSource.GetChar(nComEnd) == _CR || aSource.GetChar(nComEnd) == _LF )
                nComEnd--;

            nComEnd++;

            aSource.Erase(nComment,nComEnd-nComment);
        }
        else
            nComment++;
        nStartPos = nComment;
    }


    PreCompileDispatchParts( aSource, CUniString("sub"), CUniString("end sub"), CUniString("0") );
    PreCompileDispatchParts( aSource, CUniString("function"), CUniString("end function"), CUniString("0") );
    PreCompileDispatchParts( aSource, CUniString("testcase"), CUniString("endcase"), CUniString("endcse") );


    xub_StrLen nMainPos = ImplSearch( aSource, 0, aSource.Len(), CUniString("sub main") );
    aSource.SearchAndReplaceAscii("sub main",CUniString("Sub Main StartUse : LoadIncludeFiles : FinishUse "), nMainPos );
    if ( aSource.Len() >= STRING_MAXLEN )
    {
        xub_StrLen l,c;
        CalcPosition( aSource, nMainPos, l, c );
        CError( SbERR_PROG_TOO_LARGE, CUniString("endcatch"), l, c, c+2 );
    }

    while ( (nTestCase = ImplSearch( aSource, 0, aSource.Len(), CUniString("testcase") ) ) != STRING_NOTFOUND )
    {
        xub_StrLen nTcEnd = aSource.SearchAscii("\n",nTestCase);

        while ( aSource.GetChar(nTcEnd) == _CR || aSource.GetChar(nTcEnd) == _LF )
            nTcEnd--;

        nTcEnd++;

        if ( aSource.SearchAscii(":",nTestCase) < nTcEnd )
            nTcEnd = aSource.SearchAscii(":",nTestCase) -1;
        String aSuffix = aSource.Copy(nTestCase+8,nTcEnd-nTestCase-8);
        USHORT nOldLen;
        do
        {
            nOldLen = aSuffix.Len();
            aSuffix.EraseLeadingAndTrailingChars( ' ' );
            aSuffix.EraseLeadingAndTrailingChars( 0x09 );
        } while ( nOldLen != aSuffix.Len() );
        aSource.Erase(nTestCase,nTcEnd-nTestCase);
        aSource.Insert(CUniString("Sub ").Append(aSuffix).AppendAscii(" CaseLog \"").Append(aSuffix).AppendAscii("\" : on error goto endcse : TestEnter "),nTestCase);
    }

    /////////////////////////////////////////////////////////////////////////////////////////////////////////
    // Attention!!! The lable endsub is officially used to exit a sub instead of using 'exit sub' or 'return'
    /////////////////////////////////////////////////////////////////////////////////////////////////////////
    while ( (nEndCase = ImplSearch( aSource, 0, aSource.Len(), CUniString("endcase") ) ) != STRING_NOTFOUND )
        aSource.SearchAndReplaceAscii("endcase",CUniString("goto endsub : endcse: if ( err = 35 and StopOnSyntaxError ) or err = 18 then : on error goto 0 : resume : endif : MaybeAddErr : ExceptLog : resume endcse_res : endcse_res: on error goto 0 : endsub: TestExit : ClearError : CaseLog \"\" : end sub "), nEndCase );

    if ( aSource.Len() >= STRING_MAXLEN )
    {
        xub_StrLen l,c;
        CalcPosition( aSource, 0, l, c );
        CError( SbERR_PROG_TOO_LARGE, CUniString("endcatch"), l, c, c+2 );
    }
    return aSource;
}

void TestToolObj::AddToListByNr( CNames *&pControls, ControlItemUId *&pNewItem )
{
    USHORT nNr;
    if ( pControls->Seek_Entry( pNewItem, &nNr ) )
    {
        AddName( pControls->GetObject(nNr)->pData->Kurzname, pNewItem->pData->Kurzname );
        delete pNewItem;
        pNewItem = (ControlItemUId*)pControls->GetObject(nNr);  // f�r einf�gen der S�hne
    }
    else
    {
        ControlItem* pNI = pNewItem;
        pControls->C40_PTR_INSERT(ControlItem,pNI);
    }
}

IMPL_LINK( TestToolObj, ReturnResultsLink, CommunicationLink*, pCommLink )
{
    return ReturnResults( pCommLink->GetServiceData() );
}

void TestToolObj::ReadHidLstByNumber()
{
    // Die Hid.Lst nach Nummern sortiert einlesen
    if ( !m_pReverseUIds )
    {
        String aName = (pImpl->aHIDDir + DirEntry(CUniString("hid.lst"))).GetFull();

        {
            TTExecutionStatusHint aHint( TT_EXECUTION_SHOW_ACTION, String(SttResId(S_READING_LONGNAMES)), aName );
            GetTTBroadcaster().Broadcast( aHint );
        }

        ReadFlat( aName, m_pReverseUIds, FALSE );

        {
            TTExecutionStatusHint aHint( TT_EXECUTION_HIDE_ACTION );
            GetTTBroadcaster().Broadcast( aHint );
        }
    }
}

void TestToolObj::SortControlsByNumber( BOOL bIncludeActive )
{
    // Die Controls einmal hirarchisch und einmal alle flach nach nummer sortiert
    if ( !m_pReverseControls && !m_pReverseControlsSon && m_pControls )
    {
        m_pReverseControls = new CNames;
        m_pReverseControlsSon = new CNames;
        USHORT nWin,nCont;
        const String aSl('/');
        for ( nWin = 0 ; nWin < m_pControls->Count() ; nWin++ )
        {
            String aFatherName( m_pControls->GetObject(nWin)->pData->Kurzname );
            ControlItemUId *pNewFather = new ControlItemUIdSon(aFatherName,m_pControls->GetObject(nWin)->pData->aUId);
            AddToListByNr( m_pReverseControlsSon, pNewFather );
            if (! ((ControlItemUIdSon*)pNewFather)->GetSons() )
                ((ControlItemUIdSon*)pNewFather)->Sons( new CNames );

            // Existieren S�hne, diese in beide Listen eintragen
            CNames *pControlList = ((ControlItemSon*)m_pControls->GetObject(nWin))->GetSons();
            if ( pControlList )
                for ( nCont = 0 ; nCont < pControlList->Count() ; nCont++ )
                {
                    ControlItemUId *pNewItem;

                    String aCombinedName( aFatherName );
                    aCombinedName.AppendAscii( ":" );
                    aCombinedName.Append( pControlList->GetObject(nCont)->pData->Kurzname );
                    pNewItem = new ControlItemUId( aCombinedName, pControlList->GetObject(nCont)->pData->aUId );
                    AddToListByNr( m_pReverseControls, pNewItem );

                    pNewItem = new ControlItemUId( pControlList->GetObject(nCont)->pData->Kurzname, pControlList->GetObject(nCont)->pData->aUId );
                    AddToListByNr( ((ControlItemUIdSon*)pNewFather)->GetSons(), pNewItem );
                }
        }
        if ( !bIncludeActive )
        {
            ControlItem *pZeroItem = new ControlItemUId( UniString(), SmartId(0) );
            USHORT nNr;
            if ( m_pReverseControls->Seek_Entry( pZeroItem, &nNr ) )
            {
                m_pReverseControls->DeleteAndDestroy( nNr );
// um VorlagenLaden/UntergeordneteIniDatei/SpeichernDlg/OrdnerDlg/OeffnenDlg/MessageBox/LetzteVersion/GrafikEinfuegenDlg/FarbeDlg/ExportierenDlg/DruckerEinrichten/DruckenDlg/DateiEinfuegenDlg/Active zu verhindern
            }
            delete pZeroItem;
        }
    }
}


BOOL TestToolObj::ReturnResults( SvStream *pIn )
{

    USHORT nId;
    ULONG nClearSequence = 0;
    BOOL bSequenceOK = TRUE;
    CNames *pReverseControlsKontext = NULL;

    CRetStream *pRetStream = new CRetStream(pIn);

    pRetStream->Read( nId );
    while( !pIn->IsEof() )
    {
    switch( nId )
    {
        case SIReturn:
        {
            USHORT nRet,nParams;
            SmartId aUId;
            pRetStream->Read(nRet);
            if ( pRetStream->GetNextType() == BinString )
            {
                String aUStrId;     // UniqueStringID Used for Mozilla Integration
                pRetStream->Read( aUStrId );
                aUId = SmartId( aUStrId );
            }
            else
            {
                comm_ULONG nUId;
                pRetStream->Read( nUId );         // bei Sequence einfach die Sequence
                aUId = SmartId( nUId );
            }
            pRetStream->Read(nParams);

            USHORT nNr1 = 0;
            comm_ULONG nLNr1 = 0;
            String aString1;
            BOOL bBool1 = FALSE;
            SbxValueRef xValue1 = new SbxValue;

            if( nParams & PARAM_USHORT_1 )
                pRetStream->Read( nNr1 );
            if( nParams & PARAM_ULONG_1 )
                pRetStream->Read( nLNr1 );
            if( nParams & PARAM_STR_1 )
            {
                pRetStream->Read( aString1 );
                ReplaceNumbers ( aString1 );
            }
            else
                aString1.Erase();
            if( nParams & PARAM_BOOL_1 )
                pRetStream->Read( bBool1 );
            if( nParams & PARAM_SBXVALUE_1 )
                pRetStream->Read( *xValue1 );
            switch (nRet)
            {
                case RET_Sequence:
                    {
                        ULONG nUId = aUId.GetNum();
                        if ( nSequence != nUId )
                        {
                            bSequenceOK = FALSE;
                            ADD_ERROR(SbxERR_BAD_ACTION, GEN_RES_STR2(S_RETURN_SEQUENCE_MISSMATCH, String::CreateFromInt64(nUId), String::CreateFromInt64(nSequence)) );
                        }
                        else
                        {
                            nClearSequence = nUId;
                        }
                    }
                    break;
                case RET_Value:
                    if ( pImpl->pNextReturn )
                    {
                        if ( aNextReturnId.Matches( aUId ) )
                        {
                            if( nParams & PARAM_ULONG_1 )
                            {
                                if ( nLNr1 > 0x7fffffff )
                                    pImpl->pNextReturn->PutLong( long(nLNr1 - 0xffffffff) -1 );
                                else
                                    pImpl->pNextReturn->PutULong( nLNr1 );
                            }
                            if( nParams & PARAM_USHORT_1 )      pImpl->pNextReturn->PutUShort( nNr1 );
                            if( nParams & PARAM_STR_1 )         pImpl->pNextReturn->PutString( aString1 );
                            if( nParams & PARAM_BOOL_1 )        pImpl->pNextReturn->PutBool( bBool1 );
                            if( nParams & PARAM_SBXVALUE_1 )
                            {
                                SbxValues aValues( SbxDATE );
                                xValue1->Get( aValues );
                                pImpl->pNextReturn->Put( aValues );
                            }
                        }
                        else
                        {
                            ADD_ERROR(SbxERR_BAD_ACTION, GEN_RES_STR0(S_RETURNED_VALUE_ID_MISSMATCH) )
                        }
                        pImpl->pNextReturn = NULL;
                    }
                    else
                    {
                        ADD_ERROR(SbxERR_BAD_ACTION, GEN_RES_STR0(S_RETURNED_VALUE_NO_RECEIVER) )
                    }
                    break;
                case RET_WinInfo:
                    {
                        if ( !m_pReverseControls && !m_pReverseControlsSon )
                            pReverseControlsKontext = NULL;

                        ReadHidLstByNumber();
                        SortControlsByNumber();

                        // Alle Slots nach Nummer Sortiert
                        if ( !m_pReverseSlots && m_pSIds )
                        {
                            m_pReverseSlots = new CNames;
                            USHORT nWin;
                            const String aSl('/');
                            for ( nWin = 0 ; nWin < m_pSIds->Count() ; nWin++ )
                            {
                                ControlItemUId *pNewItem = new ControlItemUId(m_pSIds->GetObject(nWin)->pData->Kurzname,m_pSIds->GetObject(nWin)->pData->aUId);
                                AddToListByNr( m_pReverseSlots, pNewItem );
                            }
                        }

                        WinInfoRec *pWinInfo = new WinInfoRec;
                        pWinInfo->aUId = aUId.GetText();
                        pWinInfo->nRType = (USHORT)nLNr1;   // just ULONG for Transport, data is always USHORT
                        pWinInfo->aRName = aString1;
                        pWinInfo->bIsReset = bBool1;
                        pWinInfo->aKurzname.Erase();
                        pWinInfo->aSlotname.Erase();

                        // eventuell den Kontext feststellen. Passiert nur beim ersten Eintrag nach reset
                        if ( !pReverseControlsKontext && m_pReverseControlsSon )
                        {
                            USHORT nNr;
                            ControlItem *pNewItem = new ControlItemUId( String(), aUId );
                            if ( m_pReverseControlsSon->Seek_Entry(pNewItem,&nNr) )
                            {
                                pReverseControlsKontext = ((ControlItemUIdSon*)m_pReverseControlsSon->GetObject(nNr))->GetSons();
                                pWinInfo->aKurzname = CUniString("*");
                            }
                            else
                                pReverseControlsKontext = m_pReverseControls;

                            delete pNewItem;
                        }

                        // Reset. Mu� nach bestimmen des Kontext stehen, da sonst mit dem reset-record
                        // der Kontext falsch gesetzt wird.
                        if ( pWinInfo->bIsReset )
                            pReverseControlsKontext = NULL; // Reihenfolge wichtig!


                        // Kurzname feststellen
                        if ( pReverseControlsKontext )
                        {
                            USHORT nNr;
                            ControlItem *pNewItem = new ControlItemUId( String(), aUId );
                            if ( pReverseControlsKontext->Seek_Entry(pNewItem,&nNr) )
                            {
                                pWinInfo->aKurzname += pReverseControlsKontext->GetObject(nNr)->pData->Kurzname;
                            }
                            delete pNewItem;
                        }

                        // Slotname feststellen
                        if ( m_pReverseSlots )
                        {
                            USHORT nNr;
                            ControlItem *pNewItem = new ControlItemUId( String(), aUId );
                            if ( m_pReverseSlots->Seek_Entry(pNewItem,&nNr) )
                                pWinInfo->aSlotname = m_pReverseSlots->GetObject(nNr)->pData->Kurzname;
                            delete pNewItem;
                        }

                        // Langname feststellen
                        if ( aUId.HasString() )
                        {   // use the String ID since there is no LongName in hid.lst
                            pWinInfo->aLangname = aUId.GetStr();
                        }
                        else
                        {
                            if ( m_pReverseUIds )
                            {
                                USHORT nNr;
                                ControlItem *pNewItem = new ControlItemUId( String(), aUId );
                                if ( m_pReverseUIds->Seek_Entry(pNewItem,&nNr) )
                                    pWinInfo->aLangname = m_pReverseUIds->GetObject(nNr)->pData->Kurzname;
                                delete pNewItem;
                            }
                        }

                        aWinInfoHdl.Call( pWinInfo );

                        delete pWinInfo;
                    }
                    break;
                case RET_ProfileInfo:
                    {
                        ULONG nUId = aUId.GetNum();
                        if ( nParams & PARAM_STR_1 )
                        {
                            DirEntry FilePath = pImpl->aLogFileBase + DirEntry(DirEntry(aLogFileName).GetBase().AppendAscii(".prf"));
                            SvFileStream aStrm( FilePath.GetFull(), STREAM_STD_WRITE );
                            if( aStrm.IsOpen() )
                            {
                                aString1.ConvertLineEnd(LINEEND_CRLF);
                                aStrm.Seek(STREAM_SEEK_TO_END);
                                aStrm << ByteString( aString1, RTL_TEXTENCODING_UTF8 ).GetBuffer();
                                aStrm.Close();
                            }
                        }
                        if ( nParams & PARAM_ULONG_1 )
                        {
                            switch ( nUId )
                            {
                                case S_ProfileReset:    // nLNr1 = Anzahl Borders
                                {
                                    pImpl->nNumBorders = (USHORT)nLNr1;     // Borders are 0 to 4
                                    USHORT i;
                                    for ( i=0 ; i<4 ; i++ )
                                        pImpl->naValBorders[i] = 0;

                                    for ( i=0 ; i<5 ; i++ )
                                    {
                                        pImpl->naNumEntries[i] = 0;
                                        pImpl->naRemoteTime[i] = 0;
                                        pImpl->naLocalTime[i] = 0;
                                    }
                                    break;
                                }
                                case S_ProfileBorder1:  // nLNr1 = Border1 in ms
                                case S_ProfileBorder2:  // nLNr1 = Border2 in ms
                                case S_ProfileBorder3:  // nLNr1 = Border3 in ms
                                case S_ProfileBorder4:  // nLNr1 = Border4 in ms
                                {
                                    pImpl->naValBorders[ nUId - S_ProfileBorder1 ] = nLNr1;
                                    break;
                                }
                                case S_ProfileTime:     // nLNr1 = remote Zeit des Befehls
                                {
                                    USHORT i;
                                    for ( i=0 ; i<pImpl->nNumBorders &&
                                        pImpl->naValBorders[i] <= nLNr1 ; i++ ) {};

                                    pImpl->naNumEntries[ i ]++;
                                    pImpl->naRemoteTime[ i ] += nLNr1;
                                    pImpl->naLocalTime[ i ] += Time::GetSystemTicks() - pImpl->LocalStarttime;

    #if OSL_DEBUG_LEVEL > 1
                                    if ( nLNr1 > (Time::GetSystemTicks() - pImpl->LocalStarttime) )
                                    {
                                        String aLine = CUniString("Testtoolzeit(").Append(String::CreateFromInt64(Time::GetSystemTicks() - pImpl->LocalStarttime)).AppendAscii(") kleiner Officezeit(").Append(String::CreateFromInt64(nLNr1)).AppendAscii(")\n");
                                        DirEntry FilePath = pImpl->aLogFileBase + DirEntry(DirEntry(aLogFileName).GetBase().AppendAscii(".prf"));
                                        SvFileStream aStrm( FilePath.GetFull(), STREAM_STD_WRITE );
                                        if( aStrm.IsOpen() )
                                        {
                                            aLine.ConvertLineEnd(LINEEND_CRLF);
                                            aStrm.Seek(STREAM_SEEK_TO_END);
                                            aStrm << ByteString( aLine, RTL_TEXTENCODING_UTF8 ).GetBuffer();
                                            aStrm.Close();
                                        }
                                    }
    #endif

                                    break;
                                }
                                case S_ProfileDump:     // Gibt die daten aus.
                                {
                                    if ( pImpl->nNumBorders == 0 )  // Also keine alte R�ckmeldung vom Office
                                        break;
                                    DirEntry FilePath = pImpl->aLogFileBase + DirEntry(DirEntry(aLogFileName).GetBase().AppendAscii(".prf"));
                                    SvFileStream aStrm( FilePath.GetFull(), STREAM_STD_WRITE );
                                    if( aStrm.IsOpen() )
                                    {
                                        String aProfile;
                                        USHORT i;

                                        aProfile += String().Expand(15);
                                        for ( i=0 ; i<pImpl->nNumBorders ; i++ )
                                            aProfile += (CUniString("< ").Append(String::CreateFromInt64(pImpl->naValBorders[i]))).Expand(20);

                                        aProfile += (CUniString(">= ").Append(TTFormat::ms2s(pImpl->naValBorders[pImpl->nNumBorders-1])));

                                        aProfile += '\n';

                                        aProfile += CUniString("Ereignisse").Expand(15);
                                        for ( i=0 ; i<=pImpl->nNumBorders ; i++ )
                                            aProfile += TTFormat::ms2s(pImpl->naNumEntries[i]).Expand(20);

                                        aProfile += '\n';

                                        aProfile += CUniString("Server Zeit").Expand(15);
                                        for ( i=0 ; i<=pImpl->nNumBorders ; i++ )
                                            aProfile += TTFormat::ms2s(pImpl->naRemoteTime[i]).Expand(20);

                                        aProfile += '\n';

                                        aProfile += CUniString("Testtool Zeit").Expand(15);
                                        for ( i=0 ; i<=pImpl->nNumBorders ; i++ )
                                            aProfile += TTFormat::ms2s(pImpl->naLocalTime[i]).Expand(20);

                                        aProfile += '\n';

                                        aProfile += CUniString("Overhead p.e.").Expand(15);
                                        for ( i=0 ; i<=pImpl->nNumBorders ; i++ )
                                        {
                                            if ( pImpl->naNumEntries[i] > 0 )
                                                aProfile += TTFormat::ms2s((pImpl->naLocalTime[i]-pImpl->naRemoteTime[i])/pImpl->naNumEntries[i]).Expand(20);
                                            else
                                                aProfile += CUniString( "??" ).Expand(20);
                                        }

                                        aProfile += '\n';

                                        aProfile.ConvertLineEnd(LINEEND_CRLF);
                                        aStrm.Seek(STREAM_SEEK_TO_END);
                                        aStrm << ByteString( aProfile, RTL_TEXTENCODING_UTF8 ).GetBuffer();
                                        aStrm.Close();
                                    }
                                    break;
                                }
                                default:
                                    DBG_ERROR1("Unbekannter Sub Return Code bei Profile: %hu", nUId );
                                    break;
                            }
                        }
                    }
                    break;
                case RET_DirectLoging:
                    {
                        ULONG nUId = aUId.GetNum();
                        switch ( nUId )
                        {
                        case S_AssertError:
                            {
                                ADD_ASSERTION_LOG( aString1 );
                            }
                            break;
                        case S_QAError:
                            {
                                ADD_QA_ERROR_LOG( aString1 );
                            }
                            break;
                        default:
                            ;
                        }
                    }
                    break;
                case RET_MacroRecorder:
                    {
                        SortControlsByNumber( TRUE );
                        String aCommand,aControls,aControl,aULongNames,aULongName;
                        BOOL bWriteNewKontext = FALSE;

                        aControls.Erase();
                        // Kurzname feststellen
                        if ( m_pReverseControls )
                        {
                            USHORT nNr;
                            ControlItem *pNewItem = new ControlItemUId( String(), aUId );
                            if ( m_pReverseControls->Seek_Entry(pNewItem,&nNr) )
                                aControls = m_pReverseControls->GetObject(nNr)->pData->Kurzname;
                            delete pNewItem;
                        }
                        if ( !aControls.Len() )
                        {
                            aControls = String::CreateFromAscii("UnknownControl:UnknownControl");
                            Sound::Beep( SOUND_WARNING );
                        }

                        aULongNames.Erase();
                        if( (nParams & PARAM_ULONG_1) && (nNr1 & M_RET_NUM_CONTROL) )
                        {
                            if ( m_pReverseControls )
                            {
                                USHORT nNr;
                                ControlItem *pNewItem = new ControlItemUId( String(), SmartId( nLNr1 ) );
                                if ( m_pReverseControls->Seek_Entry(pNewItem,&nNr) )
                                    aULongNames = m_pReverseControls->GetObject(nNr)->pData->Kurzname;
                                delete pNewItem;
                            }
                            if ( !aULongNames.Len() )
                            {
                                aULongNames = String::CreateFromAscii("Unknown:Unknown");
                                Sound::Beep( SOUND_WARNING );
                            }

                            // now determin the best common kontext
                            USHORT i,j;
                            BOOL bFoundUlongName = FALSE, bFoundControl = FALSE;
                            // check for current kontext
                            for ( i = 0 ; !bFoundUlongName && i < aULongNames.GetTokenCount('/') ; i++ )
                                bFoundUlongName = aLastRecordedKontext.Equals( aULongNames.GetToken(i,'/').GetToken( 0,':') );

                            for ( j = 0 ; !bFoundControl && j < aControls.GetTokenCount('/') ; j++ )
                                bFoundControl = aLastRecordedKontext.Equals( aControls.GetToken(j,'/').GetToken( 0,':') );

                            if ( bFoundUlongName && bFoundControl )
                            {
                                aULongName = aULongNames.GetToken(i-1,'/').GetToken( 1,':');
                                aControl = aControls.GetToken(j-1,'/').GetToken( 1,':');
                            }
                            else
                            {   // see if we can find common kontext
                                BOOL bFound = FALSE;

                                String aCurrentKontext;
                                for ( i = 0 ; !bFound && i < aULongNames.GetTokenCount('/') ; i++ )
                                {
                                    aCurrentKontext = aULongNames.GetToken(i,'/').GetToken( 0,':');

                                    for ( j = 0 ; !bFound && j < aControls.GetTokenCount('/') ; j++ )
                                    {
                                        if ( aCurrentKontext.Equals( aControls.GetToken(j,'/').GetToken( 0,':') ) )
                                        {
                                            bFound = TRUE;
                                            aULongName = aULongNames.GetToken(i,'/').GetToken( 1,':');
                                            aControl = aControls.GetToken(j,'/').GetToken( 1,':');
                                            aLastRecordedKontext = aCurrentKontext;
                                            bWriteNewKontext = TRUE;
                                        }
                                    }
                                }
                                if ( !bFound )
                                {
                                    // check if both contain toplevel
                                    bFoundUlongName = FALSE;
                                    bFoundControl = FALSE;
                                    for ( i = 0 ; !bFoundUlongName && i < aULongNames.GetTokenCount('/') ; i++ )
                                        bFoundUlongName = aULongNames.GetToken(i,'/').GetToken( 0,':').Equals( aULongNames.GetToken(i,'/').GetToken( 1,':') );

                                    for ( j = 0 ; !bFoundControl && j < aControls.GetTokenCount('/') ; j++ )
                                        bFoundControl = aControls.GetToken(j,'/').GetToken( 0,':').Equals( aControls.GetToken(j,'/').GetToken( 1,':') );

                                    if ( bFoundUlongName && bFoundControl )
                                    {
                                        aULongName = aULongNames.GetToken(i-1,'/').GetToken( 1,':');
                                        aControl = aControls.GetToken(j-1,'/').GetToken( 1,':');
                                        if ( aLastRecordedKontext.Len() )
                                        {
                                            aLastRecordedKontext.Erase();
                                            bWriteNewKontext = TRUE;
                                        }
                                    }
                                    else
                                    {
                                        String aComment;
                                        aComment = CUniString( "'could not Determin common kontext\n" );
                                        Sound::Beep( SOUND_WARNING );
                                        aWriteStringHdl.Call( &aComment );
                                        aULongName = aULongNames.GetToken(i,'/');
                                        aControl = aControls.GetToken(j,'/');
                                    }
                                }
                            }

                        }
                        else
                        {   // we only have a Control
                            USHORT i;
                            BOOL bFoundControl = FALSE;
                            // check for current kontext
                            for ( i = 0 ; !bFoundControl && i < aControls.GetTokenCount('/') ; i++ )
                                bFoundControl = aLastRecordedKontext.Equals( aControls.GetToken(i,'/').GetToken( 0,':') );
                            if ( bFoundControl )
                                aControl = aControls.GetToken(i-1,'/').GetToken( 1,':');
                            else
                            {
                                aLastRecordedKontext = aControls.GetToken(0,'/').GetToken( 0,':');
                                bWriteNewKontext = TRUE;
                                aControl = aControls.GetToken(0,'/').GetToken( 1,':');
                            }

                        }


                        if ( bWriteNewKontext )
                        {
                            String aKontextCommand = CUniString( "Kontext" );
                            if ( aLastRecordedKontext.Len() )
                            {
                                aKontextCommand.AppendAscii ( " \"" );
                                aKontextCommand += aLastRecordedKontext;
                                aKontextCommand.AppendAscii ( "\"" );
                            }
                            aKontextCommand.AppendAscii( "\n" );
                            aWriteStringHdl.Call( &aKontextCommand );
                        }

                        aCommand = aControl;

                        // Add Method name
                        String aMethod = GetMethodName( nNr1 & ~M_RET_NUM_CONTROL );
                        aCommand += '.';
                        aCommand += aMethod;

                        BOOL bWasParam = FALSE;

                        if( nParams & PARAM_STR_1 )
                        {
                            bWasParam = TRUE;
                            aCommand.AppendAscii( " \"" );
                            if ( nNr1 & M_KEY_STRING )
                            {
                                USHORT nModify = 0;
                                BOOL bIsProsa = FALSE;
                                xub_StrLen i;
                                for ( i = 0; i < aString1.Len(); i++ )
                                {
                                    if ( ((USHORT)aString1.GetChar(i)) == 1 )   // we have a spechial char
                                    {
                                        i++;
                                        if ( !bIsProsa )
                                        {
                                            aCommand.AppendAscii( "<" );
                                            bIsProsa = TRUE;
                                        }
                                        else
                                            aCommand.AppendAscii( " " );

                                        USHORT nKeyCode = (USHORT)aString1.GetChar(i) & KEY_CODE;
                                        USHORT nNewModify = (USHORT)aString1.GetChar(i) & KEY_MODTYPE;
                                        if ( nNewModify != nModify )
                                        {   // generate modifiers
                                            USHORT nChanged = ( nNewModify ^ nModify );
                                            if ( nChanged & KEY_SHIFT )
                                            {
                                                aCommand += GetKeyName( KEY_SHIFT );
                                                aCommand.AppendAscii( " " );
                                            }
                                            if ( nChanged & KEY_MOD1 )
                                            {
                                                aCommand += GetKeyName( KEY_MOD1 );
                                                aCommand.AppendAscii( " " );
                                            }
                                            if ( nChanged & KEY_MOD2 )
                                            {
                                                aCommand += GetKeyName( KEY_MOD2 );
                                                aCommand.AppendAscii( " " );
                                            }
                                        }
                                        aCommand += GetKeyName( nKeyCode );
                                        nModify = nNewModify;
                                    }
                                    else
                                    {
                                        if ( bIsProsa )
                                        {
                                            aCommand.AppendAscii( ">" );
                                            bIsProsa = FALSE;
                                        }
                                        aCommand += aString1.GetChar(i);
                                        nModify = 0;
                                    }
                                }
                                if ( bIsProsa )
                                {
                                    aCommand.AppendAscii( ">" );
                                    bIsProsa = FALSE;
                                }
                            }
                            else
                            {
                                aCommand += aString1;
                            }
                            aCommand.AppendAscii( "\"" );
                        }
                        if( nParams & PARAM_ULONG_1 )
                        {
                            if ( bWasParam )
                                aCommand.AppendAscii( ", " );
                            else
                                aCommand.AppendAscii( " " );
                            bWasParam = TRUE;
                            if ( nNr1 & M_RET_NUM_CONTROL )
                            {
                                aCommand.Append( aULongName );
                            }
                            else
                            {
                                aCommand.Append( String::CreateFromInt64( nLNr1 ) );
                            }
                        }
                        if( nParams & PARAM_BOOL_1 )
                        {
                            if ( bWasParam )
                                aCommand.AppendAscii( ", " );
                            else
                                aCommand.AppendAscii( " " );
                            bWasParam = TRUE;
                            if ( bBool1 )
                                aCommand.AppendAscii( "true" );
                            else
                                aCommand.AppendAscii( "false" );
                        }

                        aCommand.AppendAscii( "\n" );

                           aWriteStringHdl.Call( &aCommand );
                    }
                    break;
                default:
                    DBG_ERROR1( "Unbekannter Return Code: %iu", nRet );
                    break;
            }

            break;
        }
        case SIReturnError:
        {
            String aString;
            SmartId aUId;
            if ( pRetStream->GetNextType() == BinString )
            {
                String aUStrId;     // UniqueStringID Used for Mozilla Integration
                pRetStream->Read( aUStrId );
                aUId = SmartId( aUStrId );
            }
            else
            {
                comm_ULONG nUId;
                pRetStream->Read( nUId );         // bei Sequence einfach die Sequence
                aUId = SmartId( nUId );
            }
            pRetStream->Read( aString );
            ReplaceNumbers (aString);

            String aShortName;
            aShortName = pShortNames->GetName(aUId);
            aShortName.AppendAscii( " : " );

            String aTmpStr(aShortName);
            aTmpStr += aString;
            ADD_ERROR(SbxERR_BAD_ACTION, aTmpStr/*, nNr*/);
            break;
        }
        default:
            DBG_ERROR1( "Unbekannter Request im Return Stream Nr: %iu", nId );
        break;
    }
        if( !pIn->IsEof() )
            pRetStream->Read( nId );
        else
        {
            OSL_FAIL( "truncated input stream" );
        }

    }

    delete pRetStream;
    if ( bSequenceOK )
    {
        nSequence++;
        pShortNames->Invalidate( nClearSequence - KEEP_SEQUENCES );
    }

    bReturnOK = TRUE;

    return TRUE;
} // RetService::Request()

String TestToolObj::GetMethodName( ULONG nMethodId )
{
    USHORT nElement;
    if ( !Controls::pClasses )                        // Ist static, wird also nur einmal geladen
        ReadFlatArray( Controls::arClasses, Controls::pClasses );
    if ( Controls::pClasses )
    {
        for ( nElement = 0 ; nElement < Controls::pClasses->Count() ; nElement++ )
            if ( Controls::pClasses->GetObject(nElement)->pData->aUId.Matches( nMethodId ) )
                return Controls::pClasses->GetObject(nElement)->pData->Kurzname;
    }
    return String();
}

String TestToolObj::GetKeyName( USHORT nKeyCode )
{
    USHORT nElement;
    if ( !CmdStream::pKeyCodes )                        // Ist static, wird also nur einmal geladen
        ReadFlatArray( CmdStream::arKeyCodes, CmdStream::pKeyCodes );
    if ( CmdStream::pKeyCodes )
    {
        for ( nElement = 0 ; nElement < CmdStream::pKeyCodes->Count() ; nElement++ )
            if ( CmdStream::pKeyCodes->GetObject(nElement)->pData->aUId.Matches( nKeyCode ) )
                return CmdStream::pKeyCodes->GetObject(nElement)->pData->Kurzname;
    }
    return CUniString( "UnknownKeyCode" );
}

void TestToolObj::ReplaceNumbers(String &aText)
{
static ControlDefLoad const arRes_Type [] =
#include "res_type.hxx"

    static CNames *pRTypes = NULL;
    xub_StrLen nStart = STRING_NOTFOUND;
    xub_StrLen nGleich = STRING_NOTFOUND;
    xub_StrLen nEnd = STRING_NOTFOUND;
    xub_StrLen nStartPos = 0;
    ULONG nNumber;
    String aType;
    String aResult;
    BOOL bFound;

    while ( (nStart = aText.Search(StartKenn,nStartPos)) != STRING_NOTFOUND &&
            (nGleich = aText.SearchAscii("=",nStart+StartKenn.Len())) != STRING_NOTFOUND &&
            (nEnd = aText.Search(EndKenn,nGleich+1)) != STRING_NOTFOUND)
    {
        aType = aText.Copy(nStart,nGleich-nStart);
        nNumber = (ULONG)aText.Copy(nGleich+1,nEnd-nGleich-1).ToInt64();
        bFound = FALSE;
        if ( aType.CompareTo(UIdKenn) == COMPARE_EQUAL )
        {
            aResult = pShortNames->GetName(SmartId(nNumber));
            bFound = TRUE;
        }
        if ( aType.CompareTo(MethodKenn ) == COMPARE_EQUAL )
        {
            bFound = TRUE;
            aResult = GetMethodName( nNumber );
        }
        if ( aType.CompareTo(RcKenn ) == COMPARE_EQUAL )
        {
            bFound = TRUE;
            if ( !pRCommands )                 // Ist static, wird also nur einmal geladen
                ReadFlatArray( arR_Cmds, pRCommands );

            USHORT nElement;
            if ( pRCommands )
            {
                for ( nElement = 0 ; nElement < pRCommands->Count() ; nElement++ )
                    if ( pRCommands->GetObject(nElement)->pData->aUId.Matches( nNumber ) )
                    {
                        aResult = pRCommands->GetObject(nElement)->pData->Kurzname;
                        nElement = pRCommands->Count();
                    }
            }
        }
        if ( aType.CompareTo(TypeKenn ) == COMPARE_EQUAL )
        {
            bFound = TRUE;
            if ( !pRTypes )                 // Ist static, wird also nur einmal geladen
                ReadFlatArray( arRes_Type, pRTypes );

            USHORT nElement;
            if ( pRTypes )
            {
                for ( nElement = 0 ; nElement < pRTypes->Count() ; nElement++ )
                    if ( pRTypes->GetObject(nElement)->pData->aUId.Matches( nNumber ) )
                    {
                        aResult = pRTypes->GetObject(nElement)->pData->Kurzname;
                        nElement = pRTypes->Count();
                    }
            }
        }
        if ( aType.CompareTo(SlotKenn ) == COMPARE_EQUAL )
        {
            aResult = pShortNames->GetName(SmartId(nNumber));
            bFound = TRUE;
        }
        if ( aType.CompareTo(TabKenn ) == COMPARE_EQUAL )
        {
            if ( nNumber > nStart )
                aResult.Fill( (USHORT)nNumber - nStart +1 );
            else
                aResult = CUniString(" ");
            bFound = TRUE;
        }

        nStartPos = nStart;
        if ( bFound )
        {
            aText.Erase(nStart,nEnd+EndKenn.Len()-nStart);
            aText.Insert(aResult,nStart);
            nStartPos = nStartPos + aResult.Len();
        }
        else
            nStartPos = nStartPos + StartKenn.Len();
    }
}


SbTextType TestToolObj::GetSymbolType( const String &rSymbol, BOOL bWasControl )
{
    if (    rSymbol.CompareToAscii( "try" ) == COMPARE_EQUAL
        ||  rSymbol.CompareToAscii( "catch" ) == COMPARE_EQUAL
        ||  rSymbol.CompareToAscii( "endcatch" ) == COMPARE_EQUAL
        ||  rSymbol.CompareToAscii( "testcase" ) == COMPARE_EQUAL
        ||  rSymbol.CompareToAscii( "endcase" ) == COMPARE_EQUAL )
    {
        return TT_KEYWORD;
    }


    ControlDef WhatName( rSymbol, SmartId() );

    if ( bWasControl )
    {
        if ( !Controls::pClasses )                        // Ist static, wird also nur einmal geladen
            ReadFlatArray( Controls::arClasses, Controls::pClasses );

        if ( (Controls::pClasses && Controls::pClasses->Seek_Entry( &WhatName ))
            || rSymbol.EqualsIgnoreCaseAscii( "ID" )
            || rSymbol.EqualsIgnoreCaseAscii( "Name" ) )
            return TT_METHOD;
        else
            return TT_NOMETHOD;
    }

    // Die Controls durchsuchen
    if ( m_pControls )
    {
        USHORT nWin;

        for ( nWin = 0 ; nWin < m_pControls->Count() ; nWin++ )
        {
            if ( ((ControlDef*)m_pControls->GetObject( nWin ))->SonSeek_Entry( &WhatName ) )
                return TT_CONTROL;
        }
    }

    // Die Slots durchsuchen
    if ( m_pSIds && m_pSIds->Seek_Entry( &WhatName ) )
        return TT_SLOT;

    // Ist es ein RemoteCommand
    if ( !pRCommands )                 // Ist static, wird also nur einmal geladen
        ReadFlatArray( arR_Cmds, pRCommands );
    if ( pRCommands && pRCommands->Seek_Entry( &WhatName ) )
        return TT_REMOTECMD;

    // Wenns sonst nix war, dann vielleicht ein Lokales Kommando
    SbxVariable *pVar = SbxObject::Find( rSymbol, SbxCLASS_DONTCARE );
    if ( pVar && ( pVar->ISA(SbxMethod) || pVar->ISA(SbxProperty) ) )
    {
        return TT_LOCALCMD;
    }

    return SB_SYMBOL;   // Alles was hier landet ist vom Typ SB_SYMBOL und bleibt es auch
}


#undef P_FEHLERLISTE
#define P_FEHLERLISTE TestToolObj::pFehlerListe

Controls::Controls( String aCName )
: SbxObject( aCName)
{
    pMethodVar = new SbxTransportMethod( SbxVARIANT );
    pMethodVar->SetName( CUniString("Dummy") );
    Insert( pMethodVar );
}


Controls::~Controls()
{}


void Controls::ChangeListener( SbxObject* parent )
{
    EndListening( pMethodVar->GetBroadcaster(), TRUE );
    parent->StartListening( pMethodVar->GetBroadcaster(), TRUE );
}

void Controls::SFX_NOTIFY( SfxBroadcaster&, const TypeId&,
                                const SfxHint&, const TypeId& )
{}



SbxVariable* Controls::Find( const String& aStr, SbxClassType aType)
{
    if ( !pClasses )                        // Ist static, wird also nur einmal geladen
        ReadFlatArray( arClasses, pClasses );

    if ( GetUserData() == ID_ErrorDummy )
    {
        pMethodVar->SetName(UniString(GetName()).AppendAscii(".").Append(aStr));
        pMethodVar->SetUserData( ID_ErrorDummy );
        return pMethodVar;
    }


    USHORT nElement;
    ControlDef WhatName(aStr,SmartId());
    if (pClasses && pClasses->Seek_Entry(&WhatName,&nElement))
    {
        pMethodVar->SetName(aStr);
        ULONG nUId = pClasses->GetObject(nElement)->pData->aUId.GetNum();
        pMethodVar->nValue = nUId;

         pMethodVar->SetUserData( GetUserData() );
        return pMethodVar;
    }
    else
    {   // mainly for ID and name
        SbxVariableRef Old = SbxObject::Find(aStr, aType );
        if (Old)
            return Old;
        else if ( aStr.EqualsIgnoreCaseAscii("ID") )
            return NULL;    // suppress generation of error in this case
    }
    ADD_ERROR(SbxERR_BAD_METHOD,GEN_RES_STR2(S_UNKNOWN_METHOD, GetName(), aStr));
    return NULL;
}


String TTFormat::ms2s( ULONG nMilliSeconds )
{
    if ( nMilliSeconds < 100000 )       // 100 Sekunden
        return String::CreateFromInt64( nMilliSeconds );
    if ( nMilliSeconds < 100000*60 )    // 100 Minuten
        return String::CreateFromInt32( nMilliSeconds / 1000 ).AppendAscii("Sec");
    return String::CreateFromInt32( nMilliSeconds / 1000 / 60 ).AppendAscii("Min");
}


/* vim:set shiftwidth=4 softtabstop=4 expandtab: */