masterfix DEV300: #i10000# build fix
[LibreOffice.git] / extensions / workben / testcomponent.cxx
blob3ac3c634f2c3b7f97ed54a1fe3340e56a14f0dfd
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_extensions.hxx"
31 //------------------------------------------------------
32 // testcomponent - Loads a service and its testcomponent from dlls performs a test.
33 // Expands the dll-names depending on the actual environment.
34 // Example : testcomponent stardiv.uno.io.Pipe stm
36 // Therefor the testcode must exist in teststm and the testservice must be named test.stardiv.uno.io.Pipe
39 #include <stdio.h>
40 #include <smart/com/sun/star/registry/XImplementationRegistration.hxx>
41 #include <smart/com/sun/star/lang/XComponent.hxx>
42 //#include <com/sun/star/registry/ stardiv/uno/repos/simplreg.hxx>
44 #include <vos/dynload.hxx>
45 #include <vos/diagnose.hxx>
46 #include <usr/services.hxx>
47 #include <vcl/svapp.hxx>
48 #include <usr/ustring.hxx>
49 #include <tools/string.hxx>
50 #include <vos/conditn.hxx>
52 #include <smart/com/sun/star/test/XSimpleTest.hxx>
54 using namespace rtl;
55 using namespace vos;
56 using namespace usr;
59 // Needed to switch on solaris threads
60 #ifdef SOLARIS
61 extern "C" void ChangeGlobalInit();
62 #endif
64 int __LOADONCALLAPI main (int argc, char **argv)
67 if( argc < 3) {
68 printf( "usage : testcomponent service dll [additional dlls]\n" );
69 exit( 0 );
71 #ifdef SOLARIS
72 // switch on threads in solaris
73 ChangeGlobalInit();
74 #endif
76 // create service manager
77 // XMultiServiceFactoryRef xSMgr = getProcessServiceManager();
78 XMultiServiceFactoryRef xSMgr = createRegistryServiceManager();
79 OSL_ASSERT( xSMgr.is() );
80 registerUsrServices( xSMgr );
81 setProcessServiceManager( xSMgr );
83 XImplementationRegistrationRef xReg;
84 XSimpleRegistryRef xSimpleReg;
86 try {
87 // Create registration service
88 XInterfaceRef x = xSMgr->createInstance(
89 UString::createFromAscii( "com.sun.star.registry.ImplementationRegistration" ) );
90 x->queryInterface( XImplementationRegistration::getSmartUik() , xReg );
92 /* x = xSMgr->createInstance( L"stardiv.uno.repos.SimpleRegistry" );
93 OSL_ASSERT( x.is() );
94 x->queryInterface( XSimpleRegistry::getSmartUik() , xSimpleReg );
95 OSL_ASSERT( xSimpleReg.is() );
96 xSimpleReg->open( L"testcomp.rdb" , FALSE , TRUE );
97 */ }
98 catch( Exception& e ) {
99 printf( "%s\n" , OWStringToOString( e.getName() , CHARSET_SYSTEM ).getStr() );
100 exit(1);
103 sal_Char szBuf[1024];
104 OString sTestName;
106 try {
107 // Load dll for the tested component
108 for( int n = 2 ; n <argc ; n ++ ) {
109 ORealDynamicLoader::computeModuleName( argv[n] , szBuf, 1024 );
110 UString aDllName( OStringToOWString( szBuf, CHARSET_SYSTEM ) );
112 xReg->registerImplementation(
113 UString::createFromAscii( "com.sun.star.loader.SharedLibrary" ),
114 aDllName,
115 xSimpleReg );
118 catch( Exception& e ) {
119 printf( "Couldn't reach dll %s\n" , szBuf );
120 printf( "%s\n" , OWStringToOString( e.getName() , CHARSET_SYSTEM ).getStr() );
122 exit(1);
126 try {
127 // Load dll for the test component
128 sTestName = "test";
129 sTestName += argv[2];
131 ORealDynamicLoader::computeModuleName( sTestName.getStr() , szBuf, 1024 );
132 UString aDllName = OStringToOWString( szBuf, CHARSET_SYSTEM );
133 xReg->registerImplementation(
134 UString::createFromAscii( "com.sun.star.loader.SharedLibrary" ) ,
135 aDllName,
136 xSimpleReg );
138 catch( Exception& e ) {
139 printf( "Couldn't reach dll %s\n" , szBuf );
140 printf( "%s\n" , OWStringToOString( e.getName() , CHARSET_SYSTEM ).getStr() );
141 exit(1);
145 // Instantiate test service
146 sTestName = "test.";
147 sTestName += argv[1];
149 XInterfaceRef xIntTest = xSMgr->createInstance( OStringToOWString( sTestName , CHARSET_SYSTEM ) );
150 XSimpleTestRef xTest( xIntTest , USR_QUERY );
152 if( ! xTest.is() ) {
153 printf( "Couldn't instantiate test service \n" );
154 exit( 1 );
158 INT32 nHandle = 0;
159 INT32 nNewHandle;
160 INT32 nErrorCount = 0;
161 INT32 nWarningCount = 0;
163 // loop until all test are performed
164 while( nHandle != -1 ) {
166 // Instantiate serivce
167 XInterfaceRef x = xSMgr->createInstance( OStringToOWString( argv[1] , CHARSET_SYSTEM ) );
168 if( ! x.is() ) {
169 printf( "Couldn't instantiate service !\n" );
170 exit( 1 );
173 // do the test
174 try {
175 nNewHandle = xTest->test( OStringToOWString( argv[1] , CHARSET_SYSTEM ) , x , nHandle );
177 catch ( Exception& e ) {
178 printf( "testcomponent : uncaught exception %s\n" ,
179 OWStringToOString( e.getName(), CHARSET_SYSTEM ).getStr() );
180 exit(1);
182 catch(...) {
183 printf( "testcomponent : uncaught unknown exception\n" );
184 exit(1);
188 // print errors and warning
189 Sequence<UString> seqErrors = xTest->getErrors();
190 Sequence<UString> seqWarnings = xTest->getWarnings();
191 if( seqWarnings.getLen() > nWarningCount ) {
192 printf( "Warnings during test %d!\n" , nHandle );
193 for( ; nWarningCount < seqWarnings.getLen() ; nWarningCount ++ ) {
194 printf( "Warning\n%s\n---------\n" ,
195 OWStringToOString( seqWarnings.getArray()[nWarningCount], CHARSET_SYSTEM ).getStr() );
200 if( seqErrors.getLen() > nErrorCount ) {
201 printf( "Errors during test %d!\n" , nHandle );
202 for( ; nErrorCount < seqErrors.getLen() ; nErrorCount ++ ) {
203 printf( "%s\n" ,
204 OWStringToOString(
205 seqErrors.getArray()[nErrorCount], CHARSET_SYSTEM ).getStr() );
209 nHandle = nNewHandle;
212 if( xTest->testPassed() ) {
213 printf( "Test passed !\n" );
215 else {
216 printf( "Test failed !\n" );
219 XComponentRef rComp( xSMgr , USR_QUERY );
220 rComp->dispose();
221 return 0;