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 //------------------------------------------------------
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 <com/sun/star/registry/XImplementationRegistration.hpp>
41 #include <com/sun/star/lang/XComponent.hpp>
43 #include <com/sun/star/test/XSimpleTest.hpp>
45 #include <cppuhelper/servicefactory.hxx>
47 #include <vos/dynload.hxx>
48 #include <vos/diagnose.hxx>
50 using namespace ::rtl
;
51 using namespace ::cppu
;
52 using namespace ::com::sun::star::uno
;
53 using namespace ::com::sun::star::test
;
54 using namespace ::com::sun::star::lang
;
55 using namespace ::com::sun::star::registry
;
57 // Needed to switch on solaris threads
59 extern "C" void ChangeGlobalInit();
62 int main (int argc
, char **argv
)
66 printf( "usage : testcomponent service dll [additional dlls]\n" );
70 // switch on threads in solaris
74 // create service manager
75 Reference
< XMultiServiceFactory
> xSMgr
=
76 createRegistryServiceFactory( OUString( RTL_CONSTASCII_USTRINGPARAM("applicat.rdb")) );
78 Reference
< XImplementationRegistration
> xReg
;
79 Reference
< XSimpleRegistry
> xSimpleReg
;
83 // Create registration service
84 Reference
< XInterface
> x
= xSMgr
->createInstance(
85 OUString::createFromAscii( "com.sun.star.registry.ImplementationRegistration" ) );
86 xReg
= Reference
< XImplementationRegistration
> ( x
, UNO_QUERY
);
88 catch( Exception
& ) {
89 printf( "Couldn't create ImplementationRegistration service\n" );
98 // Load dll for the tested component
99 for( int n
= 2 ; n
<argc
; n
++ ) {
101 OUString aDllName
= OStringToOUString( argv
[n
] , RTL_TEXTENCODING_ASCII_US
);
103 OUString aDllName
= OUString( RTL_CONSTASCII_USTRINGPARAM("lib"));
104 aDllName
+= OStringToOUString( argv
[n
] , RTL_TEXTENCODING_ASCII_US
);
105 aDllName
+= OUString( RTL_CONSTASCII_USTRINGPARAM(".so"));
107 xReg
->registerImplementation(
108 OUString::createFromAscii( "com.sun.star.loader.SharedLibrary" ),
113 catch( Exception
&e
) {
114 printf( "Couldn't reach dll %s\n" , szBuf
);
115 printf( "%s\n" , OUStringToOString( e
.Message
, RTL_TEXTENCODING_ASCII_US
).getStr() );
123 // Load dll for the test component
125 sTestName
+= argv
[2];
128 OUString aDllName
= OStringToOUString( sTestName
, RTL_TEXTENCODING_ASCII_US
);
130 OUString aDllName
= OUString( RTL_CONSTASCII_USTRINGPARAM("lib"));
131 aDllName
+= OStringToOUString( sTestName
, RTL_TEXTENCODING_ASCII_US
);
132 aDllName
+= OUString( RTL_CONSTASCII_USTRINGPARAM(".so"));
135 xReg
->registerImplementation(
136 OUString::createFromAscii( "com.sun.star.loader.SharedLibrary" ) ,
140 catch( Exception
& e
)
142 printf( "Couldn't reach dll %s\n" , szBuf
);
147 // Instantiate test service
149 sTestName
+= argv
[1];
151 Reference
< XInterface
> xIntTest
=
152 xSMgr
->createInstance( OStringToOUString( sTestName
, RTL_TEXTENCODING_ASCII_US
) );
153 Reference
< XSimpleTest
> xTest( xIntTest
, UNO_QUERY
);
156 printf( "Couldn't instantiate test service \n" );
161 sal_Int32 nHandle
= 0;
162 sal_Int32 nNewHandle
;
163 sal_Int32 nErrorCount
= 0;
164 sal_Int32 nWarningCount
= 0;
166 // loop until all test are performed
167 while( nHandle
!= -1 )
169 // Instantiate serivce
170 Reference
< XInterface
> x
=
171 xSMgr
->createInstance( OStringToOUString( argv
[1] , RTL_TEXTENCODING_ASCII_US
) );
174 printf( "Couldn't instantiate service !\n" );
181 nNewHandle
= xTest
->test(
182 OStringToOUString( argv
[1] , RTL_TEXTENCODING_ASCII_US
) , x
, nHandle
);
184 catch( Exception
& e
) {
185 OString o
= OUStringToOString( e
.Message
, RTL_TEXTENCODING_ASCII_US
);
186 printf( "testcomponent : uncaught exception %s\n" , o
.getStr() );
191 printf( "testcomponent : uncaught unknown exception\n" );
196 // print errors and warning
197 Sequence
<OUString
> seqErrors
= xTest
->getErrors();
198 Sequence
<OUString
> seqWarnings
= xTest
->getWarnings();
199 if( seqWarnings
.getLength() > nWarningCount
)
201 printf( "Warnings during test %d!\n" , nHandle
);
202 for( ; nWarningCount
< seqWarnings
.getLength() ; nWarningCount
++ )
204 OString o
= OUStringToOString(
205 seqWarnings
.getArray()[nWarningCount
], RTL_TEXTENCODING_ASCII_US
);
206 printf( "Warning\n%s\n---------\n" , o
.getStr() );
211 if( seqErrors
.getLength() > nErrorCount
) {
212 printf( "Errors during test %d!\n" , nHandle
);
213 for( ; nErrorCount
< seqErrors
.getLength() ; nErrorCount
++ ) {
214 OString o
= OUStringToOString(
215 seqErrors
.getArray()[nErrorCount
], RTL_TEXTENCODING_ASCII_US
);
216 printf( "%s\n" , o
.getStr() );
220 nHandle
= nNewHandle
;
223 if( xTest
->testPassed() ) {
224 printf( "Test passed !\n" );
227 printf( "Test failed !\n" );
230 Reference
<XComponent
> rComp( xSMgr
, UNO_QUERY
);