1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_extensions.hxx"
31 //------------------------------------------------------
32 // testcomponent - Loads a service and its testcomponent from dlls performs a test.
33 // Expands the dll-names depending on the actual environment.
34 // Example : testcomponent stardiv.uno.io.Pipe stm
36 // Therefor the testcode must exist in teststm and the testservice must be named test.stardiv.uno.io.Pipe
40 #include <smart/com/sun/star/registry/XImplementationRegistration.hxx>
41 #include <smart/com/sun/star/lang/XComponent.hxx>
42 //#include <com/sun/star/registry/ stardiv/uno/repos/simplreg.hxx>
44 #include <vos/dynload.hxx>
45 #include <vos/diagnose.hxx>
46 #include <usr/services.hxx>
47 #include <vcl/svapp.hxx>
48 #include <usr/ustring.hxx>
49 #include <tools/string.hxx>
50 #include <vos/conditn.hxx>
52 #include <smart/com/sun/star/test/XSimpleTest.hxx>
59 // Needed to switch on solaris threads
61 extern "C" void ChangeGlobalInit();
64 int __LOADONCALLAPI
main (int argc
, char **argv
)
68 printf( "usage : testcomponent service dll [additional dlls]\n" );
72 // switch on threads in solaris
76 // create service manager
77 // XMultiServiceFactoryRef xSMgr = getProcessServiceManager();
78 XMultiServiceFactoryRef xSMgr
= createRegistryServiceManager();
79 OSL_ASSERT( xSMgr
.is() );
80 registerUsrServices( xSMgr
);
81 setProcessServiceManager( xSMgr
);
83 XImplementationRegistrationRef xReg
;
84 XSimpleRegistryRef xSimpleReg
;
87 // Create registration service
88 XInterfaceRef x
= xSMgr
->createInstance(
89 UString::createFromAscii( "com.sun.star.registry.ImplementationRegistration" ) );
90 x
->queryInterface( XImplementationRegistration::getSmartUik() , xReg
);
92 /* x = xSMgr->createInstance( L"stardiv.uno.repos.SimpleRegistry" );
94 x->queryInterface( XSimpleRegistry::getSmartUik() , xSimpleReg );
95 OSL_ASSERT( xSimpleReg.is() );
96 xSimpleReg->open( L"testcomp.rdb" , FALSE , TRUE );
98 catch( Exception
& e
) {
99 printf( "%s\n" , OWStringToOString( e
.getName() , CHARSET_SYSTEM
).getStr() );
103 sal_Char szBuf
[1024];
107 // Load dll for the tested component
108 for( int n
= 2 ; n
<argc
; n
++ ) {
109 ORealDynamicLoader::computeModuleName( argv
[n
] , szBuf
, 1024 );
110 UString
aDllName( OStringToOWString( szBuf
, CHARSET_SYSTEM
) );
112 xReg
->registerImplementation(
113 UString::createFromAscii( "com.sun.star.loader.SharedLibrary" ),
118 catch( Exception
& e
) {
119 printf( "Couldn't reach dll %s\n" , szBuf
);
120 printf( "%s\n" , OWStringToOString( e
.getName() , CHARSET_SYSTEM
).getStr() );
127 // Load dll for the test component
129 sTestName
+= argv
[2];
131 ORealDynamicLoader::computeModuleName( sTestName
.getStr() , szBuf
, 1024 );
132 UString aDllName
= OStringToOWString( szBuf
, CHARSET_SYSTEM
);
133 xReg
->registerImplementation(
134 UString::createFromAscii( "com.sun.star.loader.SharedLibrary" ) ,
138 catch( Exception
& e
) {
139 printf( "Couldn't reach dll %s\n" , szBuf
);
140 printf( "%s\n" , OWStringToOString( e
.getName() , CHARSET_SYSTEM
).getStr() );
145 // Instantiate test service
147 sTestName
+= argv
[1];
149 XInterfaceRef xIntTest
= xSMgr
->createInstance( OStringToOWString( sTestName
, CHARSET_SYSTEM
) );
150 XSimpleTestRef
xTest( xIntTest
, USR_QUERY
);
153 printf( "Couldn't instantiate test service \n" );
160 INT32 nErrorCount
= 0;
161 INT32 nWarningCount
= 0;
163 // loop until all test are performed
164 while( nHandle
!= -1 ) {
166 // Instantiate serivce
167 XInterfaceRef x
= xSMgr
->createInstance( OStringToOWString( argv
[1] , CHARSET_SYSTEM
) );
169 printf( "Couldn't instantiate service !\n" );
175 nNewHandle
= xTest
->test( OStringToOWString( argv
[1] , CHARSET_SYSTEM
) , x
, nHandle
);
177 catch ( Exception
& e
) {
178 printf( "testcomponent : uncaught exception %s\n" ,
179 OWStringToOString( e
.getName(), CHARSET_SYSTEM
).getStr() );
183 printf( "testcomponent : uncaught unknown exception\n" );
188 // print errors and warning
189 Sequence
<UString
> seqErrors
= xTest
->getErrors();
190 Sequence
<UString
> seqWarnings
= xTest
->getWarnings();
191 if( seqWarnings
.getLen() > nWarningCount
) {
192 printf( "Warnings during test %d!\n" , nHandle
);
193 for( ; nWarningCount
< seqWarnings
.getLen() ; nWarningCount
++ ) {
194 printf( "Warning\n%s\n---------\n" ,
195 OWStringToOString( seqWarnings
.getArray()[nWarningCount
], CHARSET_SYSTEM
).getStr() );
200 if( seqErrors
.getLen() > nErrorCount
) {
201 printf( "Errors during test %d!\n" , nHandle
);
202 for( ; nErrorCount
< seqErrors
.getLen() ; nErrorCount
++ ) {
205 seqErrors
.getArray()[nErrorCount
], CHARSET_SYSTEM
).getStr() );
209 nHandle
= nNewHandle
;
212 if( xTest
->testPassed() ) {
213 printf( "Test passed !\n" );
216 printf( "Test failed !\n" );
219 XComponentRef
rComp( xSMgr
, USR_QUERY
);