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_io.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 <com/sun/star/registry/XImplementationRegistration.hpp> 41 #include <com/sun/star/lang/XComponent.hpp> 42 43 #include <com/sun/star/test/XSimpleTest.hpp> 44 45 #include <cppuhelper/servicefactory.hxx> 46 47 using namespace ::rtl; 48 using namespace ::cppu; 49 using namespace ::com::sun::star::uno; 50 using namespace ::com::sun::star::test; 51 using namespace ::com::sun::star::lang; 52 using namespace ::com::sun::star::registry; 53 54 // Needed to switch on solaris threads 55 56 int main (int argc, char **argv) 57 { 58 59 if( argc < 3) { 60 printf( "usage : testcomponent service dll [additional dlls]\n" ); 61 exit( 0 ); 62 } 63 64 // create service manager 65 Reference< XMultiServiceFactory > xSMgr = createRegistryServiceFactory( 66 OUString( RTL_CONSTASCII_USTRINGPARAM( "applicat.rdb" ) ) ); 67 68 Reference < XImplementationRegistration > xReg; 69 Reference < XSimpleRegistry > xSimpleReg; 70 71 try 72 { 73 // Create registration service 74 Reference < XInterface > x = xSMgr->createInstance( 75 OUString::createFromAscii( "com.sun.star.registry.ImplementationRegistration" ) ); 76 xReg = Reference< XImplementationRegistration > ( x , UNO_QUERY ); 77 } 78 catch( Exception & ) { 79 printf( "Couldn't create ImplementationRegistration service\n" ); 80 exit(1); 81 } 82 83 sal_Char szBuf[1024]; 84 OString sTestName; 85 86 try 87 { 88 // Load dll for the tested component 89 for( int n = 2 ; n <argc ; n ++ ) { 90 OUString aDllName = OStringToOUString( argv[n] , RTL_TEXTENCODING_ASCII_US ); 91 xReg->registerImplementation( 92 OUString::createFromAscii( "com.sun.star.loader.SharedLibrary" ), 93 aDllName, 94 xSimpleReg ); 95 } 96 } 97 catch( Exception &e ) { 98 printf( "%s\n" , OUStringToOString( e.Message , RTL_TEXTENCODING_ASCII_US ).getStr() ); 99 100 exit(1); 101 } 102 103 104 try 105 { 106 // Load dll for the test component 107 sTestName = "test"; 108 sTestName += argv[2]; 109 110 #if defined(SAL_W32) || defined(SAL_OS2) 111 OUString aDllName = OStringToOUString( sTestName , RTL_TEXTENCODING_ASCII_US ); 112 #else 113 OUString aDllName = OUString::createFromAscii("lib"); 114 aDllName += OStringToOUString( sTestName , RTL_TEXTENCODING_ASCII_US ); 115 aDllName += OUString::createFromAscii(".so"); 116 #endif 117 118 xReg->registerImplementation( 119 OUString::createFromAscii( "com.sun.star.loader.SharedLibrary" ) , 120 aDllName, 121 xSimpleReg ); 122 } 123 catch( Exception & e ) 124 { 125 printf( "Couldn't reach dll %s\n" , szBuf ); 126 exit(1); 127 } 128 129 130 // Instantiate test service 131 sTestName = "test."; 132 sTestName += argv[1]; 133 134 Reference < XInterface > xIntTest = 135 xSMgr->createInstance( OStringToOUString( sTestName , RTL_TEXTENCODING_ASCII_US ) ); 136 Reference< XSimpleTest > xTest( xIntTest , UNO_QUERY ); 137 138 if( ! xTest.is() ) { 139 printf( "Couldn't instantiate test service \n" ); 140 exit( 1 ); 141 } 142 143 144 sal_Int32 nHandle = 0; 145 sal_Int32 nNewHandle; 146 sal_Int32 nErrorCount = 0; 147 sal_Int32 nWarningCount = 0; 148 149 // loop until all test are performed 150 while( nHandle != -1 ) 151 { 152 // Instantiate serivce 153 Reference< XInterface > x = 154 xSMgr->createInstance( OStringToOUString( argv[1] , RTL_TEXTENCODING_ASCII_US ) ); 155 if( ! x.is() ) 156 { 157 printf( "Couldn't instantiate service !\n" ); 158 exit( 1 ); 159 } 160 161 // do the test 162 try 163 { 164 nNewHandle = xTest->test( 165 OStringToOUString( argv[1] , RTL_TEXTENCODING_ASCII_US ) , x , nHandle ); 166 } 167 catch( Exception & e ) { 168 OString o = OUStringToOString( e.Message, RTL_TEXTENCODING_ASCII_US ); 169 printf( "testcomponent : uncaught exception %s\n" , o.getStr() ); 170 exit(1); 171 } 172 catch( ... ) 173 { 174 printf( "testcomponent : uncaught unknown exception\n" ); 175 exit(1); 176 } 177 178 179 // print errors and warning 180 Sequence<OUString> seqErrors = xTest->getErrors(); 181 Sequence<OUString> seqWarnings = xTest->getWarnings(); 182 if( seqWarnings.getLength() > nWarningCount ) 183 { 184 printf( "Warnings during test %d!\n" , nHandle ); 185 for( ; nWarningCount < seqWarnings.getLength() ; nWarningCount ++ ) 186 { 187 OString o = OUStringToOString( 188 seqWarnings.getArray()[nWarningCount], RTL_TEXTENCODING_ASCII_US ); 189 printf( "Warning\n%s\n---------\n" , o.getStr() ); 190 } 191 } 192 193 194 if( seqErrors.getLength() > nErrorCount ) { 195 printf( "Errors during test %d!\n" , nHandle ); 196 for( ; nErrorCount < seqErrors.getLength() ; nErrorCount ++ ) 197 { 198 OString o = OUStringToOString( 199 seqErrors.getArray()[nErrorCount], RTL_TEXTENCODING_ASCII_US ); 200 printf( "%s\n" , o.getStr() ); 201 } 202 } 203 204 nHandle = nNewHandle; 205 } 206 207 if( xTest->testPassed() ) { 208 printf( "Test passed !\n" ); 209 } 210 else { 211 printf( "Test failed !\n" ); 212 } 213 214 Reference <XComponent > rComp( xSMgr , UNO_QUERY ); 215 rComp->dispose(); 216 return 0; 217 } 218