1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
30 //------------------------------------------------------
31 // testcomponent - Loads a service and its testcomponent from dlls performs a test.
32 // Expands the dll-names depending on the actual environment.
33 // Example : testcomponent stardiv.uno.io.Pipe stm
35 // Therefor the testcode must exist in teststm and the testservice must be named test.stardiv.uno.io.Pipe
39 #include <com/sun/star/registry/XImplementationRegistration.hpp>
40 #include <com/sun/star/lang/XComponent.hpp>
42 #include <com/sun/star/test/XSimpleTest.hpp>
44 #include <cppuhelper/servicefactory.hxx>
46 using namespace ::rtl
;
47 using namespace ::cppu
;
48 using namespace ::com::sun::star::uno
;
49 using namespace ::com::sun::star::test
;
50 using namespace ::com::sun::star::lang
;
51 using namespace ::com::sun::star::registry
;
53 // Needed to switch on solaris threads
55 int main (int argc
, char **argv
)
59 printf( "usage : testcomponent service dll [additional dlls]\n" );
63 // create service manager
64 Reference
< XMultiServiceFactory
> xSMgr
= createRegistryServiceFactory(
65 OUString( "applicat.rdb" ) );
67 Reference
< XImplementationRegistration
> xReg
;
68 Reference
< XSimpleRegistry
> xSimpleReg
;
72 // Create registration service
73 Reference
< XInterface
> x
= xSMgr
->createInstance(
74 OUString("com.sun.star.registry.ImplementationRegistration") );
75 xReg
= Reference
< XImplementationRegistration
> ( x
, UNO_QUERY
);
77 catch( Exception
& ) {
78 printf( "Couldn't create ImplementationRegistration service\n" );
87 // Load dll for the tested component
88 for( int n
= 2 ; n
<argc
; n
++ ) {
89 OUString aDllName
= OStringToOUString( argv
[n
] , RTL_TEXTENCODING_ASCII_US
);
90 xReg
->registerImplementation(
91 OUString("com.sun.star.loader.SharedLibrary"),
96 catch( const Exception
&e
) {
97 printf( "%s\n" , OUStringToOString( e
.Message
, RTL_TEXTENCODING_ASCII_US
).getStr() );
105 // Load dll for the test component
107 sTestName
+= argv
[2];
110 OUString aDllName
= OStringToOUString( sTestName
, RTL_TEXTENCODING_ASCII_US
);
112 OUString
aDllName("lib");
113 aDllName
+= OStringToOUString( sTestName
, RTL_TEXTENCODING_ASCII_US
);
114 aDllName
+= OUString(".so");
117 xReg
->registerImplementation(
118 OUString("com.sun.star.loader.SharedLibrary") ,
124 printf( "Couldn't reach dll %s\n" , szBuf
);
129 // Instantiate test service
131 sTestName
+= argv
[1];
133 Reference
< XInterface
> xIntTest
=
134 xSMgr
->createInstance( OStringToOUString( sTestName
, RTL_TEXTENCODING_ASCII_US
) );
135 Reference
< XSimpleTest
> xTest( xIntTest
, UNO_QUERY
);
138 printf( "Couldn't instantiate test service \n" );
143 sal_Int32 nHandle
= 0;
144 sal_Int32 nNewHandle
;
145 sal_Int32 nErrorCount
= 0;
146 sal_Int32 nWarningCount
= 0;
148 // loop until all test are performed
149 while( nHandle
!= -1 )
151 // Instantiate serivce
152 Reference
< XInterface
> x
=
153 xSMgr
->createInstance( OStringToOUString( argv
[1] , RTL_TEXTENCODING_ASCII_US
) );
156 printf( "Couldn't instantiate service !\n" );
163 nNewHandle
= xTest
->test(
164 OStringToOUString( argv
[1] , RTL_TEXTENCODING_ASCII_US
) , x
, nHandle
);
166 catch( const Exception
& e
) {
167 OString o
= OUStringToOString( e
.Message
, RTL_TEXTENCODING_ASCII_US
);
168 printf( "testcomponent : uncaught exception %s\n" , o
.getStr() );
173 printf( "testcomponent : uncaught unknown exception\n" );
178 // print errors and warning
179 Sequence
<OUString
> seqErrors
= xTest
->getErrors();
180 Sequence
<OUString
> seqWarnings
= xTest
->getWarnings();
181 if( seqWarnings
.getLength() > nWarningCount
)
183 printf( "Warnings during test %d!\n" , nHandle
);
184 for( ; nWarningCount
< seqWarnings
.getLength() ; nWarningCount
++ )
186 OString o
= OUStringToOString(
187 seqWarnings
.getArray()[nWarningCount
], RTL_TEXTENCODING_ASCII_US
);
188 printf( "Warning\n%s\n---------\n" , o
.getStr() );
193 if( seqErrors
.getLength() > nErrorCount
) {
194 printf( "Errors during test %d!\n" , nHandle
);
195 for( ; nErrorCount
< seqErrors
.getLength() ; nErrorCount
++ )
197 OString o
= OUStringToOString(
198 seqErrors
.getArray()[nErrorCount
], RTL_TEXTENCODING_ASCII_US
);
199 printf( "%s\n" , o
.getStr() );
203 nHandle
= nNewHandle
;
206 if( xTest
->testPassed() ) {
207 printf( "Test passed !\n" );
210 printf( "Test failed !\n" );
213 Reference
<XComponent
> rComp( xSMgr
, UNO_QUERY
);
218 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */