1*cdf0e10cSrcweir:
2*cdf0e10cSrcweireval 'exec perl -wS $0 ${1+"$@"}'
3*cdf0e10cSrcweir    if 0;
4*cdf0e10cSrcweir#*************************************************************************
5*cdf0e10cSrcweir#
6*cdf0e10cSrcweir# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7*cdf0e10cSrcweir#
8*cdf0e10cSrcweir# Copyright 2000, 2010 Oracle and/or its affiliates.
9*cdf0e10cSrcweir#
10*cdf0e10cSrcweir# OpenOffice.org - a multi-platform office productivity suite
11*cdf0e10cSrcweir#
12*cdf0e10cSrcweir# This file is part of OpenOffice.org.
13*cdf0e10cSrcweir#
14*cdf0e10cSrcweir# OpenOffice.org is free software: you can redistribute it and/or modify
15*cdf0e10cSrcweir# it under the terms of the GNU Lesser General Public License version 3
16*cdf0e10cSrcweir# only, as published by the Free Software Foundation.
17*cdf0e10cSrcweir#
18*cdf0e10cSrcweir# OpenOffice.org is distributed in the hope that it will be useful,
19*cdf0e10cSrcweir# but WITHOUT ANY WARRANTY; without even the implied warranty of
20*cdf0e10cSrcweir# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21*cdf0e10cSrcweir# GNU Lesser General Public License version 3 for more details
22*cdf0e10cSrcweir# (a copy is included in the LICENSE file that accompanied this code).
23*cdf0e10cSrcweir#
24*cdf0e10cSrcweir# You should have received a copy of the GNU Lesser General Public License
25*cdf0e10cSrcweir# version 3 along with OpenOffice.org.  If not, see
26*cdf0e10cSrcweir# <http://www.openoffice.org/license.html>
27*cdf0e10cSrcweir# for a copy of the LGPLv3 License.
28*cdf0e10cSrcweir#
29*cdf0e10cSrcweir#*************************************************************************
30*cdf0e10cSrcweir
31*cdf0e10cSrcweir#
32*cdf0e10cSrcweir# deliver.pl - copy from module output tree to solver
33*cdf0e10cSrcweir#
34*cdf0e10cSrcweir
35*cdf0e10cSrcweirmy $progname = "testdefaultbootstrapping";
36*cdf0e10cSrcweirmy $defExeExt;
37*cdf0e10cSrcweir
38*cdf0e10cSrcweirif ($ENV{GUI} eq "WNT") {
39*cdf0e10cSrcweir	%services = (
40*cdf0e10cSrcweir				 'com.sun.star.uno.NamingService'               => 'namingservice.uno.dll',
41*cdf0e10cSrcweir				 'com.sun.star.reflection.CoreReflection'       => 'reflection.uno.dll',
42*cdf0e10cSrcweir				 'com.sun.star.script.InvocationAdapterFactory' => 'invocadapt.uno.dll',
43*cdf0e10cSrcweir				 );
44*cdf0e10cSrcweir
45*cdf0e10cSrcweir	$defExeExt = ".exe";
46*cdf0e10cSrcweir
47*cdf0e10cSrcweir}
48*cdf0e10cSrcweirelse {
49*cdf0e10cSrcweir	%services = (
50*cdf0e10cSrcweir				 'com.sun.star.uno.NamingService'               => 'namingservice.uno.so',
51*cdf0e10cSrcweir				 'com.sun.star.reflection.CoreReflection'       => 'reflection.uno.so',
52*cdf0e10cSrcweir				 'com.sun.star.script.InvocationAdapterFactory' => 'invocadapt.uno.so'
53*cdf0e10cSrcweir				 );
54*cdf0e10cSrcweir
55*cdf0e10cSrcweir	$defExeExt = "";
56*cdf0e10cSrcweir}
57*cdf0e10cSrcweir
58*cdf0e10cSrcweirsub extendProgName($) {
59*cdf0e10cSrcweir	my $_extension = shift;
60*cdf0e10cSrcweir	my $_result;
61*cdf0e10cSrcweir
62*cdf0e10cSrcweir	if ($ENV{GUI} eq "WNT") {
63*cdf0e10cSrcweir		$_result = $progname . $_extension;
64*cdf0e10cSrcweir	}
65*cdf0e10cSrcweir	else {
66*cdf0e10cSrcweir		$_result = $ENV{PWD} . "/" . $progname . $_extension;
67*cdf0e10cSrcweir	}
68*cdf0e10cSrcweir
69*cdf0e10cSrcweir	return $_result;
70*cdf0e10cSrcweir}
71*cdf0e10cSrcweir
72*cdf0e10cSrcweir
73*cdf0e10cSrcweirsub rmDefRDB() {
74*cdf0e10cSrcweir	unlink $progname . "_services.rdb";
75*cdf0e10cSrcweir}
76*cdf0e10cSrcweir
77*cdf0e10cSrcweir
78*cdf0e10cSrcweirsub unregisterService($){
79*cdf0e10cSrcweir	my $service_name = shift;
80*cdf0e10cSrcweir
81*cdf0e10cSrcweir	my $rdb_name = $service_name . '.rdb';
82*cdf0e10cSrcweir
83*cdf0e10cSrcweir	unlink $rdb_name;
84*cdf0e10cSrcweir
85*cdf0e10cSrcweir	return 1;
86*cdf0e10cSrcweir}
87*cdf0e10cSrcweir
88*cdf0e10cSrcweirsub testForServices($$$) {
89*cdf0e10cSrcweir	my $_services = shift;
90*cdf0e10cSrcweir	my $_pars     = shift;
91*cdf0e10cSrcweir	my $_testexe  = shift;
92*cdf0e10cSrcweir
93*cdf0e10cSrcweir
94*cdf0e10cSrcweir#	my $_rc = system 'echo', $_testexe, @{$_services}, $_pars;
95*cdf0e10cSrcweir	my $_rc = system $_testexe, @{$_services}, $_pars;
96*cdf0e10cSrcweir
97*cdf0e10cSrcweir	return $_rc >> 8;
98*cdf0e10cSrcweir}
99*cdf0e10cSrcweir
100*cdf0e10cSrcweir
101*cdf0e10cSrcweirsub registerService($$){
102*cdf0e10cSrcweir	my $service_lib  = shift;
103*cdf0e10cSrcweir	my $rdb_name = shift;
104*cdf0e10cSrcweir
105*cdf0e10cSrcweir#	system 'echo', "regcomp -register -r " . $rdb_name . " -c $service_lib";
106*cdf0e10cSrcweir	my $rc = system "regcomp -register -r " . $rdb_name . " -c $service_lib";
107*cdf0e10cSrcweir
108*cdf0e10cSrcweir
109*cdf0e10cSrcweir	return ! ( $rc >> 8 );
110*cdf0e10cSrcweir}
111*cdf0e10cSrcweir
112*cdf0e10cSrcweir
113*cdf0e10cSrcweir
114*cdf0e10cSrcweirmy $state = 1;
115*cdf0e10cSrcweirmy @allservices;
116*cdf0e10cSrcweirmy $allservices_rdbs="";
117*cdf0e10cSrcweirmy $rc;
118*cdf0e10cSrcweirmy $comment;
119*cdf0e10cSrcweirmy $testexe;
120*cdf0e10cSrcweir
121*cdf0e10cSrcweir
122*cdf0e10cSrcweirsub registerServices() {
123*cdf0e10cSrcweir	use Cwd;
124*cdf0e10cSrcweir
125*cdf0e10cSrcweir	# ensure that services can not be instantiated
126*cdf0e10cSrcweir	foreach $service ( keys %services ) {
127*cdf0e10cSrcweir		# ensure that the current service is not reachable
128*cdf0e10cSrcweir		unregisterService($service);
129*cdf0e10cSrcweir		$rc = !testForServices([$service], "", $testexe);
130*cdf0e10cSrcweir		if(!$rc) {
131*cdf0e10cSrcweir			$comment = $comment . "\tcouldn't unregister service " . $service . "\n";
132*cdf0e10cSrcweir			$state = 0;
133*cdf0e10cSrcweir		}
134*cdf0e10cSrcweir
135*cdf0e10cSrcweir
136*cdf0e10cSrcweir		# register the service and ensure that it is reachable
137*cdf0e10cSrcweir		$rc = registerService($services{$service}, $service . '.rdb');
138*cdf0e10cSrcweir		if(!$rc) {
139*cdf0e10cSrcweir			$comment = $comment . "\tcouldn't register service " . $service . "\n";
140*cdf0e10cSrcweir			$state = 0;
141*cdf0e10cSrcweir		}
142*cdf0e10cSrcweir
143*cdf0e10cSrcweir		$rc = testForServices([$service], "-env:UNO_SERVICES=" . $service . ".rdb", $testexe);
144*cdf0e10cSrcweir		if(!$rc) {
145*cdf0e10cSrcweir			$comment = $comment . "\tcouldn't reach service " . $service . "\n";
146*cdf0e10cSrcweir			$state = 0;
147*cdf0e10cSrcweir		}
148*cdf0e10cSrcweir
149*cdf0e10cSrcweir		# memorize all services
150*cdf0e10cSrcweir		if (length($allservices_rdbs)) {
151*cdf0e10cSrcweir			$allservices_rdbs = $allservices_rdbs . " ";
152*cdf0e10cSrcweir		}
153*cdf0e10cSrcweir		$allservices_rdbs = $allservices_rdbs . "file://" . getcwd() . "/" . $service . ".rdb";
154*cdf0e10cSrcweir		push @allservices, $service;
155*cdf0e10cSrcweir	}
156*cdf0e10cSrcweir}
157*cdf0e10cSrcweir
158*cdf0e10cSrcweirsub testIndirection() {
159*cdf0e10cSrcweir	#test indirection
160*cdf0e10cSrcweir	$rc = testForServices(['com.sun.star.uno.NamingService'], '-env:UNO_SERVICES=${testrc:Tests:TestKey1}', $testexe);
161*cdf0e10cSrcweir	if (!$rc) {
162*cdf0e10cSrcweir		$comment = $comment . "\tindirection test not passed\n";
163*cdf0e10cSrcweir		$state = 0;
164*cdf0e10cSrcweir	}
165*cdf0e10cSrcweir}
166*cdf0e10cSrcweir
167*cdf0e10cSrcweir
168*cdf0e10cSrcweirsub testBeneathExe() {
169*cdf0e10cSrcweir	my $service = 'com.sun.star.reflection.CoreReflection';
170*cdf0e10cSrcweir	my $_testexe;
171*cdf0e10cSrcweir
172*cdf0e10cSrcweir    my @_exes = (extendProgName(".exe"),
173*cdf0e10cSrcweir				 extendProgName(".Exe"),
174*cdf0e10cSrcweir				 extendProgName(".bin"),
175*cdf0e10cSrcweir				 extendProgName(".Bin"));
176*cdf0e10cSrcweir
177*cdf0e10cSrcweir	foreach $_testexe ( @_exes ) {
178*cdf0e10cSrcweir		#test rdb found beneath executable
179*cdf0e10cSrcweir		registerService($services{$service}, $progname . "_services.rdb");
180*cdf0e10cSrcweir		my $_rc = testForServices([$service], "", $_testexe);
181*cdf0e10cSrcweir		if (!$_rc) {
182*cdf0e10cSrcweir			$comment = $comment . "\tbeneath executable test not passed: " . $_testexe . "\n";
183*cdf0e10cSrcweir			$state = 0;
184*cdf0e10cSrcweir		}
185*cdf0e10cSrcweir	}
186*cdf0e10cSrcweir}
187*cdf0e10cSrcweir
188*cdf0e10cSrcweirsub testBeneathLib_rdb() {
189*cdf0e10cSrcweir	my $_service = 'com.sun.star.uno.NamingService';
190*cdf0e10cSrcweir
191*cdf0e10cSrcweir	use UNO;
192*cdf0e10cSrcweir
193*cdf0e10cSrcweir	my $_rdb_name;
194*cdf0e10cSrcweir
195*cdf0e10cSrcweir	if ($ENV{GUI} eq "WNT") {
196*cdf0e10cSrcweir		$_rdb_name = "UNO" . "_services.rdb";
197*cdf0e10cSrcweir	}
198*cdf0e10cSrcweir	else {
199*cdf0e10cSrcweir		$_rdb_name = "../lib/UNO" . "_services.rdb";
200*cdf0e10cSrcweir	}
201*cdf0e10cSrcweir
202*cdf0e10cSrcweir	registerService($services{$_service}, $_rdb_name);
203*cdf0e10cSrcweir    my $_rc = UNO::tryService($_service);
204*cdf0e10cSrcweir	if (!$_rc) {
205*cdf0e10cSrcweir		$comment = $comment . "\tbeneath lib test not passed\n";
206*cdf0e10cSrcweir		$state = 0;
207*cdf0e10cSrcweir	}
208*cdf0e10cSrcweir	unlink $_rdb_name;
209*cdf0e10cSrcweir}
210*cdf0e10cSrcweir
211*cdf0e10cSrcweirsub testBeneathLib_rc() {
212*cdf0e10cSrcweir	my $_service = 'com.sun.star.uno.NamingService';
213*cdf0e10cSrcweir
214*cdf0e10cSrcweir	use UNO;
215*cdf0e10cSrcweir
216*cdf0e10cSrcweir	my $_rc_name;
217*cdf0e10cSrcweir
218*cdf0e10cSrcweir	if ($ENV{GUI} eq "WNT") {
219*cdf0e10cSrcweir		$_rc_name = "UNO.ini";
220*cdf0e10cSrcweir	}
221*cdf0e10cSrcweir	else {
222*cdf0e10cSrcweir		$_rc_name = "../lib/UNOrc";
223*cdf0e10cSrcweir	}
224*cdf0e10cSrcweir
225*cdf0e10cSrcweir	my $_rdb_name = "../lib/test.rdb";
226*cdf0e10cSrcweir
227*cdf0e10cSrcweir	my $_handle;
228*cdf0e10cSrcweir	open $_handle, ">" . $_rc_name;
229*cdf0e10cSrcweir	print $_handle "UNO_SERVICES=" . $_rdb_name . "\n";
230*cdf0e10cSrcweir	close $_handle;
231*cdf0e10cSrcweir
232*cdf0e10cSrcweir	registerService($services{$_service}, $_rdb_name);
233*cdf0e10cSrcweir	my $_rc = UNO::tryService($_service);
234*cdf0e10cSrcweir	if (!$_rc) {
235*cdf0e10cSrcweir		$comment = $comment . "\tbeneath lib rc test not passed\n";
236*cdf0e10cSrcweir		$state = 0;
237*cdf0e10cSrcweir	}
238*cdf0e10cSrcweir	unlink $_rdb_name;
239*cdf0e10cSrcweir    unlink $_rc_name;
240*cdf0e10cSrcweir}
241*cdf0e10cSrcweir
242*cdf0e10cSrcweirsub testAllAvailable() {
243*cdf0e10cSrcweir	# test that all services are reachable through different rdbs
244*cdf0e10cSrcweir	# change the directory to ensure, that all paths become expanded
245*cdf0e10cSrcweir	chdir "..";
246*cdf0e10cSrcweir
247*cdf0e10cSrcweir	$rc = testForServices(\@allservices, "-env:UNO_SERVICES=" . $allservices_rdbs, $testexe);
248*cdf0e10cSrcweir	if (!$rc) {
249*cdf0e10cSrcweir		$comment = $comment . "\tmulti rdb test not passed\n";
250*cdf0e10cSrcweir		$state = 0;
251*cdf0e10cSrcweir	}
252*cdf0e10cSrcweir}
253*cdf0e10cSrcweir
254*cdf0e10cSrcweir$testexe = extendProgName($defExeExt);
255*cdf0e10cSrcweir
256*cdf0e10cSrcweirrmDefRDB();
257*cdf0e10cSrcweirregisterServices();
258*cdf0e10cSrcweir#print "alls:", @allservices, $allservices_rdbs, "\n";
259*cdf0e10cSrcweir
260*cdf0e10cSrcweirtestIndirection();
261*cdf0e10cSrcweirtestBeneathExe();
262*cdf0e10cSrcweirtestBeneathLib_rc();
263*cdf0e10cSrcweirtestBeneathLib_rdb();
264*cdf0e10cSrcweirtestAllAvailable();
265*cdf0e10cSrcweir
266*cdf0e10cSrcweirprint "**************************\n";
267*cdf0e10cSrcweirif($state) {
268*cdf0e10cSrcweir	print "****** tests passed ******\n";
269*cdf0e10cSrcweir}
270*cdf0e10cSrcweirelse {
271*cdf0e10cSrcweir	print "**** tests NOT passed ****\n";
272*cdf0e10cSrcweir	print "Commnent:\n", $comment, "\n";
273*cdf0e10cSrcweir}
274*cdf0e10cSrcweirprint "**************************\n";
275*cdf0e10cSrcweir
276*cdf0e10cSrcweir
277*cdf0e10cSrcweir
278