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 .
22 // testcomponent - Loads a service and its testcomponent from dlls performs a test.
23 // Expands the dll-names depending on the actual environment.
24 // Example : testcomponent com.sun.star.io.Pipe stm
26 // Therefore the testcode must exist in teststm and the testservice must be named test.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>
36 using namespace ::cppu
;
37 using namespace ::com::sun::star::uno
;
38 using namespace ::com::sun::star::test
;
39 using namespace ::com::sun::star::lang
;
40 using namespace ::com::sun::star::registry
;
42 // Needed to switch on solaris threads
44 int main (int argc
, char **argv
)
48 printf( "usage : testcomponent service dll [additional dlls]\n" );
52 // create service manager
53 Reference
< XMultiServiceFactory
> xSMgr
= createRegistryServiceFactory(
54 OUString( "applicat.rdb" ) );
56 Reference
< XImplementationRegistration
> xReg
;
57 Reference
< XSimpleRegistry
> xSimpleReg
;
61 // Create registration service
62 Reference
< XInterface
> x
= xSMgr
->createInstance(
63 OUString("com.sun.star.registry.ImplementationRegistration") );
64 xReg
= Reference
< XImplementationRegistration
> ( x
, UNO_QUERY
);
66 catch( Exception
& ) {
67 printf( "Couldn't create ImplementationRegistration service\n" );
76 // Load dll for the tested component
77 for( int n
= 2 ; n
<argc
; n
++ ) {
78 OUString aDllName
= OStringToOUString( argv
[n
] , RTL_TEXTENCODING_ASCII_US
);
79 xReg
->registerImplementation(
80 OUString("com.sun.star.loader.SharedLibrary"),
85 catch( const Exception
&e
) {
86 printf( "%s\n" , OUStringToOString( e
.Message
, RTL_TEXTENCODING_ASCII_US
).getStr() );
94 // Load dll for the test component
99 OUString aDllName
= OStringToOUString( sTestName
, RTL_TEXTENCODING_ASCII_US
);
101 OUString
aDllName("lib");
102 aDllName
+= OStringToOUString( sTestName
, RTL_TEXTENCODING_ASCII_US
);
106 xReg
->registerImplementation(
107 OUString("com.sun.star.loader.SharedLibrary") ,
113 printf( "Couldn't reach dll %s\n" , szBuf
);
118 // Instantiate test service
120 sTestName
+= argv
[1];
122 Reference
< XInterface
> xIntTest
=
123 xSMgr
->createInstance( OStringToOUString( sTestName
, RTL_TEXTENCODING_ASCII_US
) );
124 Reference
< XSimpleTest
> xTest( xIntTest
, UNO_QUERY
);
127 printf( "Couldn't instantiate test service \n" );
132 sal_Int32 nHandle
= 0;
133 sal_Int32 nNewHandle
;
134 sal_Int32 nErrorCount
= 0;
135 sal_Int32 nWarningCount
= 0;
137 // loop until all test are performed
138 while( nHandle
!= -1 )
140 // Instantiate serivce
141 Reference
< XInterface
> x
=
142 xSMgr
->createInstance( OStringToOUString( argv
[1] , RTL_TEXTENCODING_ASCII_US
) );
145 printf( "Couldn't instantiate service !\n" );
152 nNewHandle
= xTest
->test(
153 OStringToOUString( argv
[1] , RTL_TEXTENCODING_ASCII_US
) , x
, nHandle
);
155 catch( const Exception
& e
) {
156 OString o
= OUStringToOString( e
.Message
, RTL_TEXTENCODING_ASCII_US
);
157 printf( "testcomponent : uncaught exception %s\n" , o
.getStr() );
162 printf( "testcomponent : uncaught unknown exception\n" );
167 // print errors and warning
168 Sequence
<OUString
> seqErrors
= xTest
->getErrors();
169 Sequence
<OUString
> seqWarnings
= xTest
->getWarnings();
170 if( seqWarnings
.getLength() > nWarningCount
)
172 printf( "Warnings during test %d!\n" , nHandle
);
173 for( ; nWarningCount
< seqWarnings
.getLength() ; nWarningCount
++ )
175 OString o
= OUStringToOString(
176 seqWarnings
.getArray()[nWarningCount
], RTL_TEXTENCODING_ASCII_US
);
177 printf( "Warning\n%s\n---------\n" , o
.getStr() );
182 if( seqErrors
.getLength() > nErrorCount
) {
183 printf( "Errors during test %d!\n" , nHandle
);
184 for( ; nErrorCount
< seqErrors
.getLength() ; nErrorCount
++ )
186 OString o
= OUStringToOString(
187 seqErrors
.getArray()[nErrorCount
], RTL_TEXTENCODING_ASCII_US
);
188 printf( "%s\n" , o
.getStr() );
192 nHandle
= nNewHandle
;
195 if( xTest
->testPassed() ) {
196 printf( "Test passed !\n" );
199 printf( "Test failed !\n" );
202 Reference
<XComponent
> rComp( xSMgr
, UNO_QUERY
);
207 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */