merge the formfield patch from ooo-build
[ooovba.git] / extensions / workben / testcomponent.cxx
blob6d0436504155347bc3ee4f8b640216c9cac3ebec
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.7 $
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 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_extensions.hxx"
34 //------------------------------------------------------
35 // testcomponent - Loads a service and its testcomponent from dlls performs a test.
36 // Expands the dll-names depending on the actual environment.
37 // Example : testcomponent stardiv.uno.io.Pipe stm
39 // Therefor the testcode must exist in teststm and the testservice must be named test.stardiv.uno.io.Pipe
42 #include <stdio.h>
43 #include <smart/com/sun/star/registry/XImplementationRegistration.hxx>
44 #include <smart/com/sun/star/lang/XComponent.hxx>
45 //#include <com/sun/star/registry/ stardiv/uno/repos/simplreg.hxx>
47 #include <vos/dynload.hxx>
48 #include <vos/diagnose.hxx>
49 #include <usr/services.hxx>
50 #include <vcl/svapp.hxx>
51 #include <usr/ustring.hxx>
52 #include <tools/string.hxx>
53 #include <vos/conditn.hxx>
55 #if OSL_DEBUG_LEVEL == 0
56 #define NDEBUG
57 #endif
58 #include <assert.h>
60 #include <smart/com/sun/star/test/XSimpleTest.hxx>
62 using namespace rtl;
63 using namespace vos;
64 using namespace usr;
67 // Needed to switch on solaris threads
68 #ifdef SOLARIS
69 extern "C" void ChangeGlobalInit();
70 #endif
72 int __LOADONCALLAPI main (int argc, char **argv)
75 if( argc < 3) {
76 printf( "usage : testcomponent service dll [additional dlls]\n" );
77 exit( 0 );
79 #ifdef SOLARIS
80 // switch on threads in solaris
81 ChangeGlobalInit();
82 #endif
84 // create service manager
85 // XMultiServiceFactoryRef xSMgr = getProcessServiceManager();
86 XMultiServiceFactoryRef xSMgr = createRegistryServiceManager();
87 assert( xSMgr.is() );
88 registerUsrServices( xSMgr );
89 setProcessServiceManager( xSMgr );
91 XImplementationRegistrationRef xReg;
92 XSimpleRegistryRef xSimpleReg;
94 try {
95 // Create registration service
96 XInterfaceRef x = xSMgr->createInstance(
97 UString::createFromAscii( "com.sun.star.registry.ImplementationRegistration" ) );
98 x->queryInterface( XImplementationRegistration::getSmartUik() , xReg );
100 /* x = xSMgr->createInstance( L"stardiv.uno.repos.SimpleRegistry" );
101 assert( x.is() );
102 x->queryInterface( XSimpleRegistry::getSmartUik() , xSimpleReg );
103 assert( xSimpleReg.is() );
104 xSimpleReg->open( L"testcomp.rdb" , FALSE , TRUE );
105 */ }
106 catch( Exception& e ) {
107 printf( "%s\n" , OWStringToOString( e.getName() , CHARSET_SYSTEM ).getStr() );
108 exit(1);
111 sal_Char szBuf[1024];
112 OString sTestName;
114 try {
115 // Load dll for the tested component
116 for( int n = 2 ; n <argc ; n ++ ) {
117 ORealDynamicLoader::computeModuleName( argv[n] , szBuf, 1024 );
118 UString aDllName( OStringToOWString( szBuf, CHARSET_SYSTEM ) );
120 xReg->registerImplementation(
121 UString::createFromAscii( "com.sun.star.loader.SharedLibrary" ),
122 aDllName,
123 xSimpleReg );
126 catch( Exception& e ) {
127 printf( "Couldn't reach dll %s\n" , szBuf );
128 printf( "%s\n" , OWStringToOString( e.getName() , CHARSET_SYSTEM ).getStr() );
130 exit(1);
134 try {
135 // Load dll for the test component
136 sTestName = "test";
137 sTestName += argv[2];
139 ORealDynamicLoader::computeModuleName( sTestName.getStr() , szBuf, 1024 );
140 UString aDllName = OStringToOWString( szBuf, CHARSET_SYSTEM );
141 xReg->registerImplementation(
142 UString::createFromAscii( "com.sun.star.loader.SharedLibrary" ) ,
143 aDllName,
144 xSimpleReg );
146 catch( Exception& e ) {
147 printf( "Couldn't reach dll %s\n" , szBuf );
148 printf( "%s\n" , OWStringToOString( e.getName() , CHARSET_SYSTEM ).getStr() );
149 exit(1);
153 // Instantiate test service
154 sTestName = "test.";
155 sTestName += argv[1];
157 XInterfaceRef xIntTest = xSMgr->createInstance( OStringToOWString( sTestName , CHARSET_SYSTEM ) );
158 XSimpleTestRef xTest( xIntTest , USR_QUERY );
160 if( ! xTest.is() ) {
161 printf( "Couldn't instantiate test service \n" );
162 exit( 1 );
166 INT32 nHandle = 0;
167 INT32 nNewHandle;
168 INT32 nErrorCount = 0;
169 INT32 nWarningCount = 0;
171 // loop until all test are performed
172 while( nHandle != -1 ) {
174 // Instantiate serivce
175 XInterfaceRef x = xSMgr->createInstance( OStringToOWString( argv[1] , CHARSET_SYSTEM ) );
176 if( ! x.is() ) {
177 printf( "Couldn't instantiate service !\n" );
178 exit( 1 );
181 // do the test
182 try {
183 nNewHandle = xTest->test( OStringToOWString( argv[1] , CHARSET_SYSTEM ) , x , nHandle );
185 catch ( Exception& e ) {
186 printf( "testcomponent : uncaught exception %s\n" ,
187 OWStringToOString( e.getName(), CHARSET_SYSTEM ).getStr() );
188 exit(1);
190 catch(...) {
191 printf( "testcomponent : uncaught unknown exception\n" );
192 exit(1);
196 // print errors and warning
197 Sequence<UString> seqErrors = xTest->getErrors();
198 Sequence<UString> seqWarnings = xTest->getWarnings();
199 if( seqWarnings.getLen() > nWarningCount ) {
200 printf( "Warnings during test %d!\n" , nHandle );
201 for( ; nWarningCount < seqWarnings.getLen() ; nWarningCount ++ ) {
202 printf( "Warning\n%s\n---------\n" ,
203 OWStringToOString( seqWarnings.getArray()[nWarningCount], CHARSET_SYSTEM ).getStr() );
208 if( seqErrors.getLen() > nErrorCount ) {
209 printf( "Errors during test %d!\n" , nHandle );
210 for( ; nErrorCount < seqErrors.getLen() ; nErrorCount ++ ) {
211 printf( "%s\n" ,
212 OWStringToOString(
213 seqErrors.getArray()[nErrorCount], CHARSET_SYSTEM ).getStr() );
217 nHandle = nNewHandle;
220 if( xTest->testPassed() ) {
221 printf( "Test passed !\n" );
223 else {
224 printf( "Test failed !\n" );
227 XComponentRef rComp( xSMgr , USR_QUERY );
228 rComp->dispose();
229 return 0;