1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 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. 14 * 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). 20 * 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. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_extensions.hxx" 30 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 35 // 36 // Therefor the testcode must exist in teststm and the testservice must be named test.stardiv.uno.io.Pipe 37 // 38 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> 43 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> 51 52 #include <smart/com/sun/star/test/XSimpleTest.hxx> 53 54 using namespace rtl; 55 using namespace vos; 56 using namespace usr; 57 58 59 // Needed to switch on solaris threads 60 #ifdef SOLARIS 61 extern "C" void ChangeGlobalInit(); 62 #endif 63 64 int __LOADONCALLAPI main (int argc, char **argv) 65 { 66 67 if( argc < 3) { 68 printf( "usage : testcomponent service dll [additional dlls]\n" ); 69 exit( 0 ); 70 } 71 #ifdef SOLARIS 72 // switch on threads in solaris 73 ChangeGlobalInit(); 74 #endif 75 76 // create service manager 77 // XMultiServiceFactoryRef xSMgr = getProcessServiceManager(); 78 XMultiServiceFactoryRef xSMgr = createRegistryServiceManager(); 79 OSL_ASSERT( xSMgr.is() ); 80 registerUsrServices( xSMgr ); 81 setProcessServiceManager( xSMgr ); 82 83 XImplementationRegistrationRef xReg; 84 XSimpleRegistryRef xSimpleReg; 85 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 ); 91 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); 101 } 102 103 sal_Char szBuf[1024]; 104 OString sTestName; 105 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 ) ); 111 112 xReg->registerImplementation( 113 UString::createFromAscii( "com.sun.star.loader.SharedLibrary" ), 114 aDllName, 115 xSimpleReg ); 116 } 117 } 118 catch( Exception& e ) { 119 printf( "Couldn't reach dll %s\n" , szBuf ); 120 printf( "%s\n" , OWStringToOString( e.getName() , CHARSET_SYSTEM ).getStr() ); 121 122 exit(1); 123 } 124 125 126 try { 127 // Load dll for the test component 128 sTestName = "test"; 129 sTestName += argv[2]; 130 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 ); 137 } 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); 142 } 143 144 145 // Instantiate test service 146 sTestName = "test."; 147 sTestName += argv[1]; 148 149 XInterfaceRef xIntTest = xSMgr->createInstance( OStringToOWString( sTestName , CHARSET_SYSTEM ) ); 150 XSimpleTestRef xTest( xIntTest , USR_QUERY ); 151 152 if( ! xTest.is() ) { 153 printf( "Couldn't instantiate test service \n" ); 154 exit( 1 ); 155 } 156 157 158 INT32 nHandle = 0; 159 INT32 nNewHandle; 160 INT32 nErrorCount = 0; 161 INT32 nWarningCount = 0; 162 163 // loop until all test are performed 164 while( nHandle != -1 ) { 165 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 ); 171 } 172 173 // do the test 174 try { 175 nNewHandle = xTest->test( OStringToOWString( argv[1] , CHARSET_SYSTEM ) , x , nHandle ); 176 } 177 catch ( Exception& e ) { 178 printf( "testcomponent : uncaught exception %s\n" , 179 OWStringToOString( e.getName(), CHARSET_SYSTEM ).getStr() ); 180 exit(1); 181 } 182 catch(...) { 183 printf( "testcomponent : uncaught unknown exception\n" ); 184 exit(1); 185 } 186 187 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() ); 196 } 197 } 198 199 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() ); 206 } 207 } 208 209 nHandle = nNewHandle; 210 } 211 212 if( xTest->testPassed() ) { 213 printf( "Test passed !\n" ); 214 } 215 else { 216 printf( "Test failed !\n" ); 217 } 218 219 XComponentRef rComp( xSMgr , USR_QUERY ); 220 rComp->dispose(); 221 return 0; 222 } 223