Bump for 3.6-28
[LibreOffice.git] / sax / test / testcomponent.cxx
blobbd05ac608c31a69502a2e34bc8347ac6f40879d7
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
29 //------------------------------------------------------
30 // testcomponent - Loads a service and its testcomponent from dlls performs a test.
31 // Expands the dll-names depending on the actual environment.
32 // Example : testcomponent stardiv.uno.io.Pipe stm
34 // Therefor the testcode must exist in teststm and the testservice must be named test.stardiv.uno.io.Pipe
37 #include <stdio.h>
38 #include <com/sun/star/registry/XImplementationRegistration.hpp>
39 #include <com/sun/star/lang/XComponent.hpp>
41 #include <com/sun/star/test/XSimpleTest.hpp>
43 #include <cppuhelper/servicefactory.hxx>
45 #include <osl/diagnose.h>
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;
54 // Needed to switch on solaris threads
55 #ifdef SOLARIS
56 extern "C" void ChangeGlobalInit();
57 #endif
59 int main (int argc, char **argv)
62 if( argc < 3) {
63 printf( "usage : testcomponent service dll [additional dlls]\n" );
64 exit( 0 );
66 #ifdef SOLARIS
67 // switch on threads in solaris
68 ChangeGlobalInit();
69 #endif
71 // create service manager
72 Reference< XMultiServiceFactory > xSMgr =
73 createRegistryServiceFactory( OUString( "applicat.rdb") );
75 Reference < XImplementationRegistration > xReg;
76 Reference < XSimpleRegistry > xSimpleReg;
78 try
80 // Create registration service
81 Reference < XInterface > x = xSMgr->createInstance(
82 OUString("com.sun.star.registry.ImplementationRegistration") );
83 xReg = Reference< XImplementationRegistration > ( x , UNO_QUERY );
85 catch (const Exception&)
87 printf( "Couldn't create ImplementationRegistration service\n" );
88 exit(1);
91 sal_Char szBuf[1024];
92 OString sTestName;
94 try
96 // Load dll for the tested component
97 for( int n = 2 ; n <argc ; n ++ ) {
98 #ifdef SAL_W32
99 OUString aDllName = OStringToOUString( argv[n] , RTL_TEXTENCODING_ASCII_US );
100 #else
101 OUString aDllName = OUString( "lib");
102 aDllName += OStringToOUString( argv[n] , RTL_TEXTENCODING_ASCII_US );
103 aDllName += OUString( ".so");
104 #endif
105 xReg->registerImplementation(
106 OUString("com.sun.star.loader.SharedLibrary"),
107 aDllName,
108 xSimpleReg );
111 catch (const Exception &e)
113 printf( "Couldn't reach dll %s\n" , szBuf );
114 printf( "%s\n" , OUStringToOString( e.Message , RTL_TEXTENCODING_ASCII_US ).getStr() );
116 exit(1);
122 // Load dll for the test component
123 sTestName = "test";
124 sTestName += argv[2];
126 #ifdef SAL_W32
127 OUString aDllName = OStringToOUString( sTestName , RTL_TEXTENCODING_ASCII_US );
128 #else
129 OUString aDllName = OUString( "lib");
130 aDllName += OStringToOUString( sTestName , RTL_TEXTENCODING_ASCII_US );
131 aDllName += OUString( ".so");
132 #endif
134 xReg->registerImplementation(
135 OUString("com.sun.star.loader.SharedLibrary") ,
136 aDllName,
137 xSimpleReg );
139 catch (const Exception&)
141 printf( "Couldn't reach dll %s\n" , szBuf );
142 exit(1);
146 // Instantiate test service
147 sTestName = "test.";
148 sTestName += argv[1];
150 Reference < XInterface > xIntTest =
151 xSMgr->createInstance( OStringToOUString( sTestName , RTL_TEXTENCODING_ASCII_US ) );
152 Reference< XSimpleTest > xTest( xIntTest , UNO_QUERY );
154 if( ! xTest.is() ) {
155 printf( "Couldn't instantiate test service \n" );
156 exit( 1 );
160 sal_Int32 nHandle = 0;
161 sal_Int32 nNewHandle;
162 sal_Int32 nErrorCount = 0;
163 sal_Int32 nWarningCount = 0;
165 // loop until all test are performed
166 while( nHandle != -1 )
168 // Instantiate serivce
169 Reference< XInterface > x =
170 xSMgr->createInstance( OStringToOUString( argv[1] , RTL_TEXTENCODING_ASCII_US ) );
171 if( ! x.is() )
173 printf( "Couldn't instantiate service !\n" );
174 exit( 1 );
177 // do the test
180 nNewHandle = xTest->test(
181 OStringToOUString( argv[1] , RTL_TEXTENCODING_ASCII_US ) , x , nHandle );
183 catch (const 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 %" SAL_PRIxUINT32 "!\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 %" SAL_PRIxUINT32 "!\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;
235 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */