Update ooo320-m1
[ooovba.git] / io / test / testcomponent.cxx
blobdd976b3cf3fe94cb2deb05426a6fd17d65153c93
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.12 $
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_io.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 <com/sun/star/registry/XImplementationRegistration.hpp>
44 #include <com/sun/star/lang/XComponent.hpp>
46 #include <com/sun/star/test/XSimpleTest.hpp>
48 #include <cppuhelper/servicefactory.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
59 int main (int argc, char **argv)
62 if( argc < 3) {
63 printf( "usage : testcomponent service dll [additional dlls]\n" );
64 exit( 0 );
67 // create service manager
68 Reference< XMultiServiceFactory > xSMgr = createRegistryServiceFactory(
69 OUString( RTL_CONSTASCII_USTRINGPARAM( "applicat.rdb" ) ) );
71 Reference < XImplementationRegistration > xReg;
72 Reference < XSimpleRegistry > xSimpleReg;
74 try
76 // Create registration service
77 Reference < XInterface > x = xSMgr->createInstance(
78 OUString::createFromAscii( "com.sun.star.registry.ImplementationRegistration" ) );
79 xReg = Reference< XImplementationRegistration > ( x , UNO_QUERY );
81 catch( Exception & ) {
82 printf( "Couldn't create ImplementationRegistration service\n" );
83 exit(1);
86 sal_Char szBuf[1024];
87 OString sTestName;
89 try
91 // Load dll for the tested component
92 for( int n = 2 ; n <argc ; n ++ ) {
93 OUString aDllName = OStringToOUString( argv[n] , RTL_TEXTENCODING_ASCII_US );
94 xReg->registerImplementation(
95 OUString::createFromAscii( "com.sun.star.loader.SharedLibrary" ),
96 aDllName,
97 xSimpleReg );
100 catch( Exception &e ) {
101 printf( "%s\n" , OUStringToOString( e.Message , RTL_TEXTENCODING_ASCII_US ).getStr() );
103 exit(1);
109 // Load dll for the test component
110 sTestName = "test";
111 sTestName += argv[2];
113 #if defined(SAL_W32) || defined(SAL_OS2)
114 OUString aDllName = OStringToOUString( sTestName , RTL_TEXTENCODING_ASCII_US );
115 #else
116 OUString aDllName = OUString::createFromAscii("lib");
117 aDllName += OStringToOUString( sTestName , RTL_TEXTENCODING_ASCII_US );
118 aDllName += OUString::createFromAscii(".so");
119 #endif
121 xReg->registerImplementation(
122 OUString::createFromAscii( "com.sun.star.loader.SharedLibrary" ) ,
123 aDllName,
124 xSimpleReg );
126 catch( Exception & e )
128 printf( "Couldn't reach dll %s\n" , szBuf );
129 exit(1);
133 // Instantiate test service
134 sTestName = "test.";
135 sTestName += argv[1];
137 Reference < XInterface > xIntTest =
138 xSMgr->createInstance( OStringToOUString( sTestName , RTL_TEXTENCODING_ASCII_US ) );
139 Reference< XSimpleTest > xTest( xIntTest , UNO_QUERY );
141 if( ! xTest.is() ) {
142 printf( "Couldn't instantiate test service \n" );
143 exit( 1 );
147 sal_Int32 nHandle = 0;
148 sal_Int32 nNewHandle;
149 sal_Int32 nErrorCount = 0;
150 sal_Int32 nWarningCount = 0;
152 // loop until all test are performed
153 while( nHandle != -1 )
155 // Instantiate serivce
156 Reference< XInterface > x =
157 xSMgr->createInstance( OStringToOUString( argv[1] , RTL_TEXTENCODING_ASCII_US ) );
158 if( ! x.is() )
160 printf( "Couldn't instantiate service !\n" );
161 exit( 1 );
164 // do the test
167 nNewHandle = xTest->test(
168 OStringToOUString( argv[1] , RTL_TEXTENCODING_ASCII_US ) , x , nHandle );
170 catch( Exception & e ) {
171 OString o = OUStringToOString( e.Message, RTL_TEXTENCODING_ASCII_US );
172 printf( "testcomponent : uncaught exception %s\n" , o.getStr() );
173 exit(1);
175 catch( ... )
177 printf( "testcomponent : uncaught unknown exception\n" );
178 exit(1);
182 // print errors and warning
183 Sequence<OUString> seqErrors = xTest->getErrors();
184 Sequence<OUString> seqWarnings = xTest->getWarnings();
185 if( seqWarnings.getLength() > nWarningCount )
187 printf( "Warnings during test %d!\n" , nHandle );
188 for( ; nWarningCount < seqWarnings.getLength() ; nWarningCount ++ )
190 OString o = OUStringToOString(
191 seqWarnings.getArray()[nWarningCount], RTL_TEXTENCODING_ASCII_US );
192 printf( "Warning\n%s\n---------\n" , o.getStr() );
197 if( seqErrors.getLength() > nErrorCount ) {
198 printf( "Errors during test %d!\n" , nHandle );
199 for( ; nErrorCount < seqErrors.getLength() ; nErrorCount ++ )
201 OString o = OUStringToOString(
202 seqErrors.getArray()[nErrorCount], RTL_TEXTENCODING_ASCII_US );
203 printf( "%s\n" , o.getStr() );
207 nHandle = nNewHandle;
210 if( xTest->testPassed() ) {
211 printf( "Test passed !\n" );
213 else {
214 printf( "Test failed !\n" );
217 Reference <XComponent > rComp( xSMgr , UNO_QUERY );
218 rComp->dispose();
219 return 0;