Branch libreoffice-5-0-4
[LibreOffice.git] / cppuhelper / test / testdefaultbootstrapping.pl
blob278e759fb44c5e01a8839f02b4a1209c9f3ed08c
2 eval 'exec perl -wS $0 ${1+"$@"}'
3 if 0;
5 # This file is part of the LibreOffice project.
7 # This Source Code Form is subject to the terms of the Mozilla Public
8 # License, v. 2.0. If a copy of the MPL was not distributed with this
9 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
11 # This file incorporates work covered by the following license notice:
13 # Licensed to the Apache Software Foundation (ASF) under one or more
14 # contributor license agreements. See the NOTICE file distributed
15 # with this work for additional information regarding copyright
16 # ownership. The ASF licenses this file to you under the Apache
17 # License, Version 2.0 (the "License"); you may not use this file
18 # except in compliance with the License. You may obtain a copy of
19 # the License at http://www.apache.org/licenses/LICENSE-2.0 .
23 # deliver.pl - copy from module output tree to solver
26 my $progname = "testdefaultbootstrapping";
27 my $defExeExt;
29 if ($ENV{OS} eq "WNT") {
30 %services = (
31 'com.sun.star.uno.NamingService' => 'namingservice.uno.dll',
32 'com.sun.star.reflection.CoreReflection' => 'reflection.uno.dll',
33 'com.sun.star.script.InvocationAdapterFactory' => 'invocadapt.uno.dll',
36 $defExeExt = ".exe";
39 else {
40 %services = (
41 'com.sun.star.uno.NamingService' => 'namingservice.uno.so',
42 'com.sun.star.reflection.CoreReflection' => 'reflection.uno.so',
43 'com.sun.star.script.InvocationAdapterFactory' => 'invocadapt.uno.so'
46 $defExeExt = "";
49 sub extendProgName($) {
50 my $_extension = shift;
51 my $_result;
53 if ($ENV{OS} eq "WNT") {
54 $_result = $progname . $_extension;
56 else {
57 $_result = $ENV{PWD} . "/" . $progname . $_extension;
60 return $_result;
64 sub rmDefRDB() {
65 unlink $progname . "_services.rdb";
69 sub unregisterService($){
70 my $service_name = shift;
72 my $rdb_name = $service_name . '.rdb';
74 unlink $rdb_name;
76 return 1;
79 sub testForServices($$$) {
80 my $_services = shift;
81 my $_pars = shift;
82 my $_testexe = shift;
85 # my $_rc = system 'echo', $_testexe, @{$_services}, $_pars;
86 my $_rc = system $_testexe, @{$_services}, $_pars;
88 return $_rc >> 8;
92 sub registerService($$){
93 my $service_lib = shift;
94 my $rdb_name = shift;
96 # system 'echo', "regcomp -register -r " . $rdb_name . " -c $service_lib";
97 my $rc = system "regcomp -register -r " . $rdb_name . " -c $service_lib";
100 return ! ( $rc >> 8 );
105 my $state = 1;
106 my @allservices;
107 my $allservices_rdbs="";
108 my $rc;
109 my $comment;
110 my $testexe;
113 sub registerServices() {
114 use Cwd;
116 # ensure that services can not be instantiated
117 foreach $service ( keys %services ) {
118 # ensure that the current service is not reachable
119 unregisterService($service);
120 $rc = !testForServices([$service], "", $testexe);
121 if(!$rc) {
122 $comment = $comment . "\tcouldn't unregister service " . $service . "\n";
123 $state = 0;
127 # register the service and ensure that it is reachable
128 $rc = registerService($services{$service}, $service . '.rdb');
129 if(!$rc) {
130 $comment = $comment . "\tcouldn't register service " . $service . "\n";
131 $state = 0;
134 $rc = testForServices([$service], "-env:UNO_SERVICES=" . $service . ".rdb", $testexe);
135 if(!$rc) {
136 $comment = $comment . "\tcouldn't reach service " . $service . "\n";
137 $state = 0;
140 # memorize all services
141 if (length($allservices_rdbs)) {
142 $allservices_rdbs = $allservices_rdbs . " ";
144 $allservices_rdbs = $allservices_rdbs . "file://" . getcwd() . "/" . $service . ".rdb";
145 push @allservices, $service;
149 sub testIndirection() {
150 #test indirection
151 $rc = testForServices(['com.sun.star.uno.NamingService'], '-env:UNO_SERVICES=${testrc:Tests:TestKey1}', $testexe);
152 if (!$rc) {
153 $comment = $comment . "\tindirection test not passed\n";
154 $state = 0;
159 sub testBeneathExe() {
160 my $service = 'com.sun.star.reflection.CoreReflection';
161 my $_testexe;
163 my @_exes = (extendProgName(".exe"),
164 extendProgName(".Exe"),
165 extendProgName(".bin"),
166 extendProgName(".Bin"));
168 foreach $_testexe ( @_exes ) {
169 #test rdb found beneath executable
170 registerService($services{$service}, $progname . "_services.rdb");
171 my $_rc = testForServices([$service], "", $_testexe);
172 if (!$_rc) {
173 $comment = $comment . "\tbeneath executable test not passed: " . $_testexe . "\n";
174 $state = 0;
179 sub testBeneathLib_rdb() {
180 my $_service = 'com.sun.star.uno.NamingService';
182 use UNO;
184 my $_rdb_name;
186 if ($ENV{OS} eq "WNT") {
187 $_rdb_name = "UNO" . "_services.rdb";
189 else {
190 $_rdb_name = "../lib/UNO" . "_services.rdb";
193 registerService($services{$_service}, $_rdb_name);
194 my $_rc = UNO::tryService($_service);
195 if (!$_rc) {
196 $comment = $comment . "\tbeneath lib test not passed\n";
197 $state = 0;
199 unlink $_rdb_name;
202 sub testBeneathLib_rc() {
203 my $_service = 'com.sun.star.uno.NamingService';
205 use UNO;
207 my $_rc_name;
209 if ($ENV{OS} eq "WNT") {
210 $_rc_name = "UNO.ini";
212 else {
213 $_rc_name = "../lib/UNOrc";
216 my $_rdb_name = "../lib/test.rdb";
218 my $_handle;
219 open $_handle, ">" . $_rc_name;
220 print $_handle "UNO_SERVICES=" . $_rdb_name . "\n";
221 close $_handle;
223 registerService($services{$_service}, $_rdb_name);
224 my $_rc = UNO::tryService($_service);
225 if (!$_rc) {
226 $comment = $comment . "\tbeneath lib rc test not passed\n";
227 $state = 0;
229 unlink $_rdb_name;
230 unlink $_rc_name;
233 sub testAllAvailable() {
234 # test that all services are reachable through different rdbs
235 # change the directory to ensure, that all paths become expanded
236 chdir "..";
238 $rc = testForServices(\@allservices, "-env:UNO_SERVICES=" . $allservices_rdbs, $testexe);
239 if (!$rc) {
240 $comment = $comment . "\tmulti rdb test not passed\n";
241 $state = 0;
245 $testexe = extendProgName($defExeExt);
247 rmDefRDB();
248 registerServices();
249 #print "alls:", @allservices, $allservices_rdbs, "\n";
251 testIndirection();
252 testBeneathExe();
253 testBeneathLib_rc();
254 testBeneathLib_rdb();
255 testAllAvailable();
257 print "**************************\n";
258 if($state) {
259 print "****** tests passed ******\n";
261 else {
262 print "**** tests NOT passed ****\n";
263 print "Commnent:\n", $comment, "\n";
265 print "**************************\n";