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 ************************************************************************/
29 //------------------------------------------------------
30 // testcomponent - Loads a service and its testcomponent from dlls performs a test.
31 // Expands the dll-names depending on the actual environment.
32 // Example : testcomponent stardiv.uno.io.Pipe stm
34 // Therefor the testcode must exist in teststm and the testservice must be named test.stardiv.uno.io.Pipe
38 #include <com/sun/star/registry/XImplementationRegistration.hpp>
39 #include <com/sun/star/lang/XComponent.hpp>
41 #include <com/sun/star/test/XSimpleTest.hpp>
43 #include <cppuhelper/servicefactory.hxx>
45 #include <osl/diagnose.h>
47 using namespace ::rtl
;
48 using namespace ::cppu
;
49 using namespace ::com::sun::star::uno
;
50 using namespace ::com::sun::star::test
;
51 using namespace ::com::sun::star::lang
;
52 using namespace ::com::sun::star::registry
;
54 // Needed to switch on solaris threads
56 extern "C" void ChangeGlobalInit();
59 int main (int argc
, char **argv
)
63 printf( "usage : testcomponent service dll [additional dlls]\n" );
67 // switch on threads in solaris
71 // create service manager
72 Reference
< XMultiServiceFactory
> xSMgr
=
73 createRegistryServiceFactory( OUString( "applicat.rdb") );
75 Reference
< XImplementationRegistration
> xReg
;
76 Reference
< XSimpleRegistry
> xSimpleReg
;
80 // Create registration service
81 Reference
< XInterface
> x
= xSMgr
->createInstance(
82 OUString("com.sun.star.registry.ImplementationRegistration") );
83 xReg
= Reference
< XImplementationRegistration
> ( x
, UNO_QUERY
);
85 catch (const Exception
&)
87 printf( "Couldn't create ImplementationRegistration service\n" );
96 // Load dll for the tested component
97 for( int n
= 2 ; n
<argc
; n
++ ) {
99 OUString aDllName
= OStringToOUString( argv
[n
] , RTL_TEXTENCODING_ASCII_US
);
101 OUString aDllName
= OUString( "lib");
102 aDllName
+= OStringToOUString( argv
[n
] , RTL_TEXTENCODING_ASCII_US
);
103 aDllName
+= OUString( ".so");
105 xReg
->registerImplementation(
106 OUString("com.sun.star.loader.SharedLibrary"),
111 catch (const Exception
&e
)
113 printf( "Couldn't reach dll %s\n" , szBuf
);
114 printf( "%s\n" , OUStringToOString( e
.Message
, RTL_TEXTENCODING_ASCII_US
).getStr() );
122 // Load dll for the test component
124 sTestName
+= argv
[2];
127 OUString aDllName
= OStringToOUString( sTestName
, RTL_TEXTENCODING_ASCII_US
);
129 OUString aDllName
= OUString( "lib");
130 aDllName
+= OStringToOUString( sTestName
, RTL_TEXTENCODING_ASCII_US
);
131 aDllName
+= OUString( ".so");
134 xReg
->registerImplementation(
135 OUString("com.sun.star.loader.SharedLibrary") ,
139 catch (const Exception
&)
141 printf( "Couldn't reach dll %s\n" , szBuf
);
146 // Instantiate test service
148 sTestName
+= argv
[1];
150 Reference
< XInterface
> xIntTest
=
151 xSMgr
->createInstance( OStringToOUString( sTestName
, RTL_TEXTENCODING_ASCII_US
) );
152 Reference
< XSimpleTest
> xTest( xIntTest
, UNO_QUERY
);
155 printf( "Couldn't instantiate test service \n" );
160 sal_Int32 nHandle
= 0;
161 sal_Int32 nNewHandle
;
162 sal_Int32 nErrorCount
= 0;
163 sal_Int32 nWarningCount
= 0;
165 // loop until all test are performed
166 while( nHandle
!= -1 )
168 // Instantiate serivce
169 Reference
< XInterface
> x
=
170 xSMgr
->createInstance( OStringToOUString( argv
[1] , RTL_TEXTENCODING_ASCII_US
) );
173 printf( "Couldn't instantiate service !\n" );
180 nNewHandle
= xTest
->test(
181 OStringToOUString( argv
[1] , RTL_TEXTENCODING_ASCII_US
) , x
, nHandle
);
183 catch (const 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 %" SAL_PRIxUINT32
"!\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 %" SAL_PRIxUINT32
"!\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
);
235 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */