1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 // testcomponent - Loads a service and its testcomponent from dlls performs a test.
22 // Expands the dll-names depending on the actual environment.
23 // Example : testcomponent com.sun.star.io.Pipe stm
25 // Therefore the testcode must exist in teststm and the testservice must be named com.sun.star.io.Pipe
29 #include <com/sun/star/registry/XImplementationRegistration.hpp>
30 #include <com/sun/star/lang/XComponent.hpp>
32 #include <com/sun/star/test/XSimpleTest.hpp>
34 #include <cppuhelper/servicefactory.hxx>
37 using namespace ::cppu
;
38 using namespace ::com::sun::star::uno
;
39 using namespace ::com::sun::star::test
;
40 using namespace ::com::sun::star::lang
;
41 using namespace ::com::sun::star::registry
;
43 // Needed to switch on solaris threads
45 extern "C" void ChangeGlobalInit();
48 int main (int argc
, char **argv
)
52 printf( "usage : testcomponent service dll [additional dlls]\n" );
56 // switch on threads in solaris
60 // create service manager
61 Reference
< XMultiServiceFactory
> xSMgr
=
62 createRegistryServiceFactory( OUString( "applicat.rdb") );
64 Reference
< XImplementationRegistration
> xReg
;
65 Reference
< XSimpleRegistry
> xSimpleReg
;
69 // Create registration service
70 Reference
< XInterface
> x
= xSMgr
->createInstance( "com.sun.star.registry.ImplementationRegistration" );
71 xReg
.set( x
, UNO_QUERY
);
73 catch (const Exception
&)
75 printf( "Couldn't create ImplementationRegistration service\n" );
84 // Load dll for the tested component
85 for( int n
= 2 ; n
<argc
; n
++ ) {
87 OUString aDllName
= OStringToOUString( argv
[n
] , RTL_TEXTENCODING_ASCII_US
);
89 OUString aDllName
= "lib";
90 aDllName
+= OStringToOUString( argv
[n
] , RTL_TEXTENCODING_ASCII_US
);
93 xReg
->registerImplementation(
94 OUString("com.sun.star.loader.SharedLibrary"),
99 catch (const Exception
&e
)
101 printf( "Couldn't reach dll %s\n" , szBuf
);
102 printf( "%s\n" , OUStringToOString( e
.Message
, RTL_TEXTENCODING_ASCII_US
).getStr() );
110 // Load dll for the test component
112 sTestName
+= argv
[2];
115 OUString aDllName
= OStringToOUString( sTestName
, RTL_TEXTENCODING_ASCII_US
);
117 OUString aDllName
= "lib";
118 aDllName
+= OStringToOUString( sTestName
, RTL_TEXTENCODING_ASCII_US
);
122 xReg
->registerImplementation(
123 OUString("com.sun.star.loader.SharedLibrary") ,
127 catch (const Exception
&)
129 printf( "Couldn't reach dll %s\n" , szBuf
);
134 // Instantiate test service
136 sTestName
+= argv
[1];
138 Reference
< XInterface
> xIntTest
=
139 xSMgr
->createInstance( OStringToOUString( sTestName
, RTL_TEXTENCODING_ASCII_US
) );
140 Reference
< XSimpleTest
> xTest( xIntTest
, UNO_QUERY
);
143 printf( "Couldn't instantiate test service \n" );
148 sal_Int32 nHandle
= 0;
149 sal_Int32 nNewHandle
;
150 sal_Int32 nErrorCount
= 0;
151 sal_Int32 nWarningCount
= 0;
153 // loop until all test are performed
154 while( nHandle
!= -1 )
156 // Instantiate service
157 Reference
< XInterface
> x
=
158 xSMgr
->createInstance( OStringToOUString( argv
[1] , RTL_TEXTENCODING_ASCII_US
) );
161 printf( "Couldn't instantiate service !\n" );
168 nNewHandle
= xTest
->test(
169 OStringToOUString( argv
[1] , RTL_TEXTENCODING_ASCII_US
) , x
, nHandle
);
171 catch (const Exception
&e
)
173 OString o
= OUStringToOString( e
.Message
, RTL_TEXTENCODING_ASCII_US
);
174 printf( "testcomponent : uncaught exception %s\n" , o
.getStr() );
179 printf( "testcomponent : uncaught unknown exception\n" );
184 // print errors and warning
185 Sequence
<OUString
> seqErrors
= xTest
->getErrors();
186 Sequence
<OUString
> seqWarnings
= xTest
->getWarnings();
187 if( seqWarnings
.getLength() > nWarningCount
)
189 printf( "Warnings during test %" SAL_PRIxUINT32
"!\n" , nHandle
);
190 for( ; nWarningCount
< seqWarnings
.getLength() ; nWarningCount
++ )
192 OString o
= OUStringToOString(
193 seqWarnings
.getArray()[nWarningCount
], RTL_TEXTENCODING_ASCII_US
);
194 printf( "Warning\n%s\n---------\n" , o
.getStr() );
199 if( seqErrors
.getLength() > nErrorCount
) {
200 printf( "Errors during test %" SAL_PRIxUINT32
"!\n" , nHandle
);
201 for( ; nErrorCount
< seqErrors
.getLength() ; nErrorCount
++ ) {
202 OString o
= OUStringToOString(
203 seqErrors
.getArray()[nErrorCount
], RTL_TEXTENCODING_ASCII_US
);
204 printf( "%s\n" , o
.getStr() );
208 nHandle
= nNewHandle
;
211 if( xTest
->testPassed() ) {
212 printf( "Test passed !\n" );
215 printf( "Test failed !\n" );
218 Reference
<XComponent
> rComp( xSMgr
, UNO_QUERY
);
223 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */