fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / sax / test / testcomponent.cxx
blobd34776789f8a289c680cb741cccfd13849fd6f5c
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 // testcomponent - Loads a service and its testcomponent from dlls performs a test.
22 // Expands the dll-names depending on the actual environment.
23 // Example : testcomponent com.sun.star.io.Pipe stm
25 // Therefore the testcode must exist in teststm and the testservice must be named com.sun.star.io.Pipe
28 #include <stdio.h>
29 #include <com/sun/star/registry/XImplementationRegistration.hpp>
30 #include <com/sun/star/lang/XComponent.hpp>
32 #include <com/sun/star/test/XSimpleTest.hpp>
34 #include <cppuhelper/servicefactory.hxx>
36 #include <osl/diagnose.h>
38 using namespace ::cppu;
39 using namespace ::com::sun::star::uno;
40 using namespace ::com::sun::star::test;
41 using namespace ::com::sun::star::lang;
42 using namespace ::com::sun::star::registry;
44 // Needed to switch on solaris threads
45 #ifdef SOLARIS
46 extern "C" void ChangeGlobalInit();
47 #endif
49 int main (int argc, char **argv)
52 if( argc < 3) {
53 printf( "usage : testcomponent service dll [additional dlls]\n" );
54 exit( 0 );
56 #ifdef SOLARIS
57 // switch on threads in solaris
58 ChangeGlobalInit();
59 #endif
61 // create service manager
62 Reference< XMultiServiceFactory > xSMgr =
63 createRegistryServiceFactory( OUString( "applicat.rdb") );
65 Reference < XImplementationRegistration > xReg;
66 Reference < XSimpleRegistry > xSimpleReg;
68 try
70 // Create registration service
71 Reference < XInterface > x = xSMgr->createInstance(
72 OUString("com.sun.star.registry.ImplementationRegistration") );
73 xReg = Reference< XImplementationRegistration > ( x , UNO_QUERY );
75 catch (const Exception&)
77 printf( "Couldn't create ImplementationRegistration service\n" );
78 exit(1);
81 sal_Char szBuf[1024];
82 OString sTestName;
84 try
86 // Load dll for the tested component
87 for( int n = 2 ; n <argc ; n ++ ) {
88 #ifdef SAL_W32
89 OUString aDllName = OStringToOUString( argv[n] , RTL_TEXTENCODING_ASCII_US );
90 #else
91 OUString aDllName = "lib";
92 aDllName += OStringToOUString( argv[n] , RTL_TEXTENCODING_ASCII_US );
93 aDllName += ".so";
94 #endif
95 xReg->registerImplementation(
96 OUString("com.sun.star.loader.SharedLibrary"),
97 aDllName,
98 xSimpleReg );
101 catch (const Exception &e)
103 printf( "Couldn't reach dll %s\n" , szBuf );
104 printf( "%s\n" , OUStringToOString( e.Message , RTL_TEXTENCODING_ASCII_US ).getStr() );
106 exit(1);
112 // Load dll for the test component
113 sTestName = "test";
114 sTestName += argv[2];
116 #ifdef SAL_W32
117 OUString aDllName = OStringToOUString( sTestName , RTL_TEXTENCODING_ASCII_US );
118 #else
119 OUString aDllName = "lib";
120 aDllName += OStringToOUString( sTestName , RTL_TEXTENCODING_ASCII_US );
121 aDllName += ".so";
122 #endif
124 xReg->registerImplementation(
125 OUString("com.sun.star.loader.SharedLibrary") ,
126 aDllName,
127 xSimpleReg );
129 catch (const Exception&)
131 printf( "Couldn't reach dll %s\n" , szBuf );
132 exit(1);
136 // Instantiate test service
137 sTestName = "test.";
138 sTestName += argv[1];
140 Reference < XInterface > xIntTest =
141 xSMgr->createInstance( OStringToOUString( sTestName , RTL_TEXTENCODING_ASCII_US ) );
142 Reference< XSimpleTest > xTest( xIntTest , UNO_QUERY );
144 if( ! xTest.is() ) {
145 printf( "Couldn't instantiate test service \n" );
146 exit( 1 );
150 sal_Int32 nHandle = 0;
151 sal_Int32 nNewHandle;
152 sal_Int32 nErrorCount = 0;
153 sal_Int32 nWarningCount = 0;
155 // loop until all test are performed
156 while( nHandle != -1 )
158 // Instantiate serivce
159 Reference< XInterface > x =
160 xSMgr->createInstance( OStringToOUString( argv[1] , RTL_TEXTENCODING_ASCII_US ) );
161 if( ! x.is() )
163 printf( "Couldn't instantiate service !\n" );
164 exit( 1 );
167 // do the test
170 nNewHandle = xTest->test(
171 OStringToOUString( argv[1] , RTL_TEXTENCODING_ASCII_US ) , x , nHandle );
173 catch (const Exception &e)
175 OString o = OUStringToOString( e.Message, RTL_TEXTENCODING_ASCII_US );
176 printf( "testcomponent : uncaught exception %s\n" , o.getStr() );
177 exit(1);
179 catch (...)
181 printf( "testcomponent : uncaught unknown exception\n" );
182 exit(1);
186 // print errors and warning
187 Sequence<OUString> seqErrors = xTest->getErrors();
188 Sequence<OUString> seqWarnings = xTest->getWarnings();
189 if( seqWarnings.getLength() > nWarningCount )
191 printf( "Warnings during test %" SAL_PRIxUINT32 "!\n" , nHandle );
192 for( ; nWarningCount < seqWarnings.getLength() ; nWarningCount ++ )
194 OString o = OUStringToOString(
195 seqWarnings.getArray()[nWarningCount], RTL_TEXTENCODING_ASCII_US );
196 printf( "Warning\n%s\n---------\n" , o.getStr() );
201 if( seqErrors.getLength() > nErrorCount ) {
202 printf( "Errors during test %" SAL_PRIxUINT32 "!\n" , nHandle );
203 for( ; nErrorCount < seqErrors.getLength() ; nErrorCount ++ ) {
204 OString o = OUStringToOString(
205 seqErrors.getArray()[nErrorCount], RTL_TEXTENCODING_ASCII_US );
206 printf( "%s\n" , o.getStr() );
210 nHandle = nNewHandle;
213 if( xTest->testPassed() ) {
214 printf( "Test passed !\n" );
216 else {
217 printf( "Test failed !\n" );
220 Reference <XComponent > rComp( xSMgr , UNO_QUERY );
221 rComp->dispose();
222 return 0;
225 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */