1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: testcomponent.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_extensions.hxx"
34 //------------------------------------------------------
35 // testcomponent - Loads a service and its testcomponent from dlls performs a test.
36 // Expands the dll-names depending on the actual environment.
37 // Example : testcomponent stardiv.uno.io.Pipe stm
39 // Therefor the testcode must exist in teststm and the testservice must be named test.stardiv.uno.io.Pipe
43 #include <smart/com/sun/star/registry/XImplementationRegistration.hxx>
44 #include <smart/com/sun/star/lang/XComponent.hxx>
45 //#include <com/sun/star/registry/ stardiv/uno/repos/simplreg.hxx>
47 #include <vos/dynload.hxx>
48 #include <vos/diagnose.hxx>
49 #include <usr/services.hxx>
50 #include <vcl/svapp.hxx>
51 #include <usr/ustring.hxx>
52 #include <tools/string.hxx>
53 #include <vos/conditn.hxx>
55 #if OSL_DEBUG_LEVEL == 0
60 #include <smart/com/sun/star/test/XSimpleTest.hxx>
67 // Needed to switch on solaris threads
69 extern "C" void ChangeGlobalInit();
72 int __LOADONCALLAPI
main (int argc
, char **argv
)
76 printf( "usage : testcomponent service dll [additional dlls]\n" );
80 // switch on threads in solaris
84 // create service manager
85 // XMultiServiceFactoryRef xSMgr = getProcessServiceManager();
86 XMultiServiceFactoryRef xSMgr
= createRegistryServiceManager();
88 registerUsrServices( xSMgr
);
89 setProcessServiceManager( xSMgr
);
91 XImplementationRegistrationRef xReg
;
92 XSimpleRegistryRef xSimpleReg
;
95 // Create registration service
96 XInterfaceRef x
= xSMgr
->createInstance(
97 UString::createFromAscii( "com.sun.star.registry.ImplementationRegistration" ) );
98 x
->queryInterface( XImplementationRegistration::getSmartUik() , xReg
);
100 /* x = xSMgr->createInstance( L"stardiv.uno.repos.SimpleRegistry" );
102 x->queryInterface( XSimpleRegistry::getSmartUik() , xSimpleReg );
103 assert( xSimpleReg.is() );
104 xSimpleReg->open( L"testcomp.rdb" , FALSE , TRUE );
106 catch( Exception
& e
) {
107 printf( "%s\n" , OWStringToOString( e
.getName() , CHARSET_SYSTEM
).getStr() );
111 sal_Char szBuf
[1024];
115 // Load dll for the tested component
116 for( int n
= 2 ; n
<argc
; n
++ ) {
117 ORealDynamicLoader::computeModuleName( argv
[n
] , szBuf
, 1024 );
118 UString
aDllName( OStringToOWString( szBuf
, CHARSET_SYSTEM
) );
120 xReg
->registerImplementation(
121 UString::createFromAscii( "com.sun.star.loader.SharedLibrary" ),
126 catch( Exception
& e
) {
127 printf( "Couldn't reach dll %s\n" , szBuf
);
128 printf( "%s\n" , OWStringToOString( e
.getName() , CHARSET_SYSTEM
).getStr() );
135 // Load dll for the test component
137 sTestName
+= argv
[2];
139 ORealDynamicLoader::computeModuleName( sTestName
.getStr() , szBuf
, 1024 );
140 UString aDllName
= OStringToOWString( szBuf
, CHARSET_SYSTEM
);
141 xReg
->registerImplementation(
142 UString::createFromAscii( "com.sun.star.loader.SharedLibrary" ) ,
146 catch( Exception
& e
) {
147 printf( "Couldn't reach dll %s\n" , szBuf
);
148 printf( "%s\n" , OWStringToOString( e
.getName() , CHARSET_SYSTEM
).getStr() );
153 // Instantiate test service
155 sTestName
+= argv
[1];
157 XInterfaceRef xIntTest
= xSMgr
->createInstance( OStringToOWString( sTestName
, CHARSET_SYSTEM
) );
158 XSimpleTestRef
xTest( xIntTest
, USR_QUERY
);
161 printf( "Couldn't instantiate test service \n" );
168 INT32 nErrorCount
= 0;
169 INT32 nWarningCount
= 0;
171 // loop until all test are performed
172 while( nHandle
!= -1 ) {
174 // Instantiate serivce
175 XInterfaceRef x
= xSMgr
->createInstance( OStringToOWString( argv
[1] , CHARSET_SYSTEM
) );
177 printf( "Couldn't instantiate service !\n" );
183 nNewHandle
= xTest
->test( OStringToOWString( argv
[1] , CHARSET_SYSTEM
) , x
, nHandle
);
185 catch ( Exception
& e
) {
186 printf( "testcomponent : uncaught exception %s\n" ,
187 OWStringToOString( e
.getName(), CHARSET_SYSTEM
).getStr() );
191 printf( "testcomponent : uncaught unknown exception\n" );
196 // print errors and warning
197 Sequence
<UString
> seqErrors
= xTest
->getErrors();
198 Sequence
<UString
> seqWarnings
= xTest
->getWarnings();
199 if( seqWarnings
.getLen() > nWarningCount
) {
200 printf( "Warnings during test %d!\n" , nHandle
);
201 for( ; nWarningCount
< seqWarnings
.getLen() ; nWarningCount
++ ) {
202 printf( "Warning\n%s\n---------\n" ,
203 OWStringToOString( seqWarnings
.getArray()[nWarningCount
], CHARSET_SYSTEM
).getStr() );
208 if( seqErrors
.getLen() > nErrorCount
) {
209 printf( "Errors during test %d!\n" , nHandle
);
210 for( ; nErrorCount
< seqErrors
.getLen() ; nErrorCount
++ ) {
213 seqErrors
.getArray()[nErrorCount
], CHARSET_SYSTEM
).getStr() );
217 nHandle
= nNewHandle
;
220 if( xTest
->testPassed() ) {
221 printf( "Test passed !\n" );
224 printf( "Test failed !\n" );
227 XComponentRef
rComp( xSMgr
, USR_QUERY
);