merge the formfield patch from ooo-build
[ooovba.git] / sax / test / testcomponent.cxx
blob7b7dfa993aa8ed44e76b5e31f88c4fb804f66922
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: testcomponent.cxx,v $
10 * $Revision: 1.5 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
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 <com/sun/star/registry/XImplementationRegistration.hpp>
41 #include <com/sun/star/lang/XComponent.hpp>
43 #include <com/sun/star/test/XSimpleTest.hpp>
45 #include <cppuhelper/servicefactory.hxx>
47 #include <vos/dynload.hxx>
48 #include <vos/diagnose.hxx>
50 using namespace ::rtl;
51 using namespace ::cppu;
52 using namespace ::com::sun::star::uno;
53 using namespace ::com::sun::star::test;
54 using namespace ::com::sun::star::lang;
55 using namespace ::com::sun::star::registry;
57 // Needed to switch on solaris threads
58 #ifdef SOLARIS
59 extern "C" void ChangeGlobalInit();
60 #endif
62 int main (int argc, char **argv)
65 if( argc < 3) {
66 printf( "usage : testcomponent service dll [additional dlls]\n" );
67 exit( 0 );
69 #ifdef SOLARIS
70 // switch on threads in solaris
71 ChangeGlobalInit();
72 #endif
74 // create service manager
75 Reference< XMultiServiceFactory > xSMgr =
76 createRegistryServiceFactory( OUString( RTL_CONSTASCII_USTRINGPARAM("applicat.rdb")) );
78 Reference < XImplementationRegistration > xReg;
79 Reference < XSimpleRegistry > xSimpleReg;
81 try
83 // Create registration service
84 Reference < XInterface > x = xSMgr->createInstance(
85 OUString::createFromAscii( "com.sun.star.registry.ImplementationRegistration" ) );
86 xReg = Reference< XImplementationRegistration > ( x , UNO_QUERY );
88 catch( Exception & ) {
89 printf( "Couldn't create ImplementationRegistration service\n" );
90 exit(1);
93 sal_Char szBuf[1024];
94 OString sTestName;
96 try
98 // Load dll for the tested component
99 for( int n = 2 ; n <argc ; n ++ ) {
100 #ifdef SAL_W32
101 OUString aDllName = OStringToOUString( argv[n] , RTL_TEXTENCODING_ASCII_US );
102 #else
103 OUString aDllName = OUString( RTL_CONSTASCII_USTRINGPARAM("lib"));
104 aDllName += OStringToOUString( argv[n] , RTL_TEXTENCODING_ASCII_US );
105 aDllName += OUString( RTL_CONSTASCII_USTRINGPARAM(".so"));
106 #endif
107 xReg->registerImplementation(
108 OUString::createFromAscii( "com.sun.star.loader.SharedLibrary" ),
109 aDllName,
110 xSimpleReg );
113 catch( Exception &e ) {
114 printf( "Couldn't reach dll %s\n" , szBuf );
115 printf( "%s\n" , OUStringToOString( e.Message , RTL_TEXTENCODING_ASCII_US ).getStr() );
117 exit(1);
123 // Load dll for the test component
124 sTestName = "test";
125 sTestName += argv[2];
127 #ifdef SAL_W32
128 OUString aDllName = OStringToOUString( sTestName , RTL_TEXTENCODING_ASCII_US );
129 #else
130 OUString aDllName = OUString( RTL_CONSTASCII_USTRINGPARAM("lib"));
131 aDllName += OStringToOUString( sTestName , RTL_TEXTENCODING_ASCII_US );
132 aDllName += OUString( RTL_CONSTASCII_USTRINGPARAM(".so"));
133 #endif
135 xReg->registerImplementation(
136 OUString::createFromAscii( "com.sun.star.loader.SharedLibrary" ) ,
137 aDllName,
138 xSimpleReg );
140 catch( Exception & e )
142 printf( "Couldn't reach dll %s\n" , szBuf );
143 exit(1);
147 // Instantiate test service
148 sTestName = "test.";
149 sTestName += argv[1];
151 Reference < XInterface > xIntTest =
152 xSMgr->createInstance( OStringToOUString( sTestName , RTL_TEXTENCODING_ASCII_US ) );
153 Reference< XSimpleTest > xTest( xIntTest , UNO_QUERY );
155 if( ! xTest.is() ) {
156 printf( "Couldn't instantiate test service \n" );
157 exit( 1 );
161 sal_Int32 nHandle = 0;
162 sal_Int32 nNewHandle;
163 sal_Int32 nErrorCount = 0;
164 sal_Int32 nWarningCount = 0;
166 // loop until all test are performed
167 while( nHandle != -1 )
169 // Instantiate serivce
170 Reference< XInterface > x =
171 xSMgr->createInstance( OStringToOUString( argv[1] , RTL_TEXTENCODING_ASCII_US ) );
172 if( ! x.is() )
174 printf( "Couldn't instantiate service !\n" );
175 exit( 1 );
178 // do the test
181 nNewHandle = xTest->test(
182 OStringToOUString( argv[1] , RTL_TEXTENCODING_ASCII_US ) , x , nHandle );
184 catch( Exception & e ) {
185 OString o = OUStringToOString( e.Message, RTL_TEXTENCODING_ASCII_US );
186 printf( "testcomponent : uncaught exception %s\n" , o.getStr() );
187 exit(1);
189 catch( ... )
191 printf( "testcomponent : uncaught unknown exception\n" );
192 exit(1);
196 // print errors and warning
197 Sequence<OUString> seqErrors = xTest->getErrors();
198 Sequence<OUString> seqWarnings = xTest->getWarnings();
199 if( seqWarnings.getLength() > nWarningCount )
201 printf( "Warnings during test %d!\n" , nHandle );
202 for( ; nWarningCount < seqWarnings.getLength() ; nWarningCount ++ )
204 OString o = OUStringToOString(
205 seqWarnings.getArray()[nWarningCount], RTL_TEXTENCODING_ASCII_US );
206 printf( "Warning\n%s\n---------\n" , o.getStr() );
211 if( seqErrors.getLength() > nErrorCount ) {
212 printf( "Errors during test %d!\n" , nHandle );
213 for( ; nErrorCount < seqErrors.getLength() ; nErrorCount ++ ) {
214 OString o = OUStringToOString(
215 seqErrors.getArray()[nErrorCount], RTL_TEXTENCODING_ASCII_US );
216 printf( "%s\n" , o.getStr() );
220 nHandle = nNewHandle;
223 if( xTest->testPassed() ) {
224 printf( "Test passed !\n" );
226 else {
227 printf( "Test failed !\n" );
230 Reference <XComponent > rComp( xSMgr , UNO_QUERY );
231 rComp->dispose();
232 return 0;