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
30 #include <smart/com/sun/star/registry/XImplementationRegistration.hxx>
31 #include <smart/com/sun/star/lang/XComponent.hxx>
33 #include <osl/diagnose.h>
34 #include <usr/services.hxx>
35 #include <vcl/svapp.hxx>
36 #include <usr/ustring.hxx>
37 #include <osl/conditn.hxx>
39 #include <smart/com/sun/star/test/XSimpleTest.hxx>
43 using ::rtl::OWStringToOString
;
46 // Needed to switch on solaris threads
48 extern "C" void ChangeGlobalInit();
51 int SAL_CALL
main (int argc
, char **argv
)
55 printf( "usage : testcomponent service dll [additional dlls]\n" );
59 // switch on threads in solaris
63 // create service manager
64 // XMultiServiceFactoryRef xSMgr = getProcessServiceManager();
65 XMultiServiceFactoryRef xSMgr
= createRegistryServiceManager();
66 OSL_ASSERT( xSMgr
.is() );
67 registerUsrServices( xSMgr
);
68 setProcessServiceManager( xSMgr
);
70 XImplementationRegistrationRef xReg
;
71 XSimpleRegistryRef xSimpleReg
;
74 // Create registration service
75 XInterfaceRef x
= xSMgr
->createInstance(
76 UString(RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.registry.ImplementationRegistration" )) );
77 x
->queryInterface( XImplementationRegistration::getSmartUik() , xReg
);
80 catch( Exception
& e
) {
81 printf( "%s\n" , OWStringToOString( e
.getName() , CHARSET_SYSTEM
).getStr() );
89 // Load dll for the tested component
90 for( int n
= 2 ; n
<argc
; n
++ ) {
91 ORealDynamicLoader::computeModuleName( argv
[n
] , szBuf
, 1024 );
92 UString
aDllName( OStringToOWString( szBuf
, CHARSET_SYSTEM
) );
94 xReg
->registerImplementation(
95 UString(RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.loader.SharedLibrary" )),
100 catch( Exception
& e
) {
101 printf( "Couldn't reach dll %s\n" , szBuf
);
102 printf( "%s\n" , OWStringToOString( e
.getName() , CHARSET_SYSTEM
).getStr() );
109 // Load dll for the test component
111 sTestName
+= argv
[2];
113 ORealDynamicLoader::computeModuleName( sTestName
.getStr() , szBuf
, 1024 );
114 UString aDllName
= OStringToOWString( szBuf
, CHARSET_SYSTEM
);
115 xReg
->registerImplementation(
116 UString(RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.loader.SharedLibrary" )) ,
120 catch( Exception
& e
) {
121 printf( "Couldn't reach dll %s\n" , szBuf
);
122 printf( "%s\n" , OWStringToOString( e
.getName() , CHARSET_SYSTEM
).getStr() );
127 // Instantiate test service
129 sTestName
+= argv
[1];
131 XInterfaceRef xIntTest
= xSMgr
->createInstance( OStringToOWString( sTestName
, CHARSET_SYSTEM
) );
132 XSimpleTestRef
xTest( xIntTest
, USR_QUERY
);
135 printf( "Couldn't instantiate test service \n" );
142 INT32 nErrorCount
= 0;
143 INT32 nWarningCount
= 0;
145 // loop until all test are performed
146 while( nHandle
!= -1 ) {
148 // Instantiate serivce
149 XInterfaceRef x
= xSMgr
->createInstance( OStringToOWString( argv
[1] , CHARSET_SYSTEM
) );
151 printf( "Couldn't instantiate service !\n" );
157 nNewHandle
= xTest
->test( OStringToOWString( argv
[1] , CHARSET_SYSTEM
) , x
, nHandle
);
159 catch ( Exception
& e
) {
160 printf( "testcomponent : uncaught exception %s\n" ,
161 OWStringToOString( e
.getName(), CHARSET_SYSTEM
).getStr() );
165 printf( "testcomponent : uncaught unknown exception\n" );
170 // print errors and warning
171 Sequence
<UString
> seqErrors
= xTest
->getErrors();
172 Sequence
<UString
> seqWarnings
= xTest
->getWarnings();
173 if( seqWarnings
.getLen() > nWarningCount
) {
174 printf( "Warnings during test %d!\n" , nHandle
);
175 for( ; nWarningCount
< seqWarnings
.getLen() ; nWarningCount
++ ) {
176 printf( "Warning\n%s\n---------\n" ,
177 OWStringToOString( seqWarnings
.getArray()[nWarningCount
], CHARSET_SYSTEM
).getStr() );
182 if( seqErrors
.getLen() > nErrorCount
) {
183 printf( "Errors during test %d!\n" , nHandle
);
184 for( ; nErrorCount
< seqErrors
.getLen() ; nErrorCount
++ ) {
187 seqErrors
.getArray()[nErrorCount
], CHARSET_SYSTEM
).getStr() );
191 nHandle
= nNewHandle
;
194 if( xTest
->testPassed() ) {
195 printf( "Test passed !\n" );
198 printf( "Test failed !\n" );
201 XComponentRef
rComp( xSMgr
, USR_QUERY
);
206 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */