calc: on editing invalidation of view with different zoom is wrong
[LibreOffice.git] / io / test / testcomponent.cxx
blob2b317c90341c08a3acba39d89b629dd4b6c62786
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 test.com.sun.star.io.Pipe
27 #include <stdio.h>
28 #include <com/sun/star/registry/XImplementationRegistration.hpp>
29 #include <com/sun/star/lang/XComponent.hpp>
31 #include <com/sun/star/test/XSimpleTest.hpp>
33 #include <cppuhelper/servicefactory.hxx>
35 using namespace ::cppu;
36 using namespace ::com::sun::star::uno;
37 using namespace ::com::sun::star::test;
38 using namespace ::com::sun::star::lang;
39 using namespace ::com::sun::star::registry;
41 // Needed to switch on solaris threads
43 int main (int argc, char **argv)
46 if( argc < 3) {
47 printf( "usage : testcomponent service dll [additional dlls]\n" );
48 exit( 0 );
51 // create service manager
52 Reference< XMultiServiceFactory > xSMgr = createRegistryServiceFactory(
53 OUString( "applicat.rdb" ) );
55 Reference < XImplementationRegistration > xReg;
56 Reference < XSimpleRegistry > xSimpleReg;
58 try
60 // Create registration service
61 Reference < XInterface > x = xSMgr->createInstance(
62 "com.sun.star.registry.ImplementationRegistration" );
63 xReg.set( x , UNO_QUERY );
65 catch( Exception & ) {
66 printf( "Couldn't create ImplementationRegistration service\n" );
67 exit(1);
70 char szBuf[1024];
71 OString sTestName;
73 try
75 // Load dll for the tested component
76 for( int n = 2 ; n <argc ; n ++ ) {
77 OUString aDllName = OStringToOUString( argv[n] , RTL_TEXTENCODING_ASCII_US );
78 xReg->registerImplementation(
79 OUString("com.sun.star.loader.SharedLibrary"),
80 aDllName,
81 xSimpleReg );
84 catch( const Exception &e ) {
85 printf( "%s\n" , OUStringToOString( e.Message , RTL_TEXTENCODING_ASCII_US ).getStr() );
87 exit(1);
91 try
93 // Load dll for the test component
94 sTestName = "test";
95 sTestName += argv[2];
97 #if defined(_WIN32)
98 OUString aDllName = OStringToOUString( sTestName , RTL_TEXTENCODING_ASCII_US );
99 #else
100 OUString aDllName("lib");
101 aDllName += OStringToOUString( sTestName , RTL_TEXTENCODING_ASCII_US );
102 aDllName += ".so";
103 #endif
105 xReg->registerImplementation(
106 OUString("com.sun.star.loader.SharedLibrary") ,
107 aDllName,
108 xSimpleReg );
110 catch( Exception & )
112 printf( "Couldn't reach dll %s\n" , szBuf );
113 exit(1);
117 // Instantiate test service
118 sTestName = "test.";
119 sTestName += argv[1];
121 Reference < XInterface > xIntTest =
122 xSMgr->createInstance( OStringToOUString( sTestName , RTL_TEXTENCODING_ASCII_US ) );
123 Reference< XSimpleTest > xTest( xIntTest , UNO_QUERY );
125 if( ! xTest.is() ) {
126 printf( "Couldn't instantiate test service \n" );
127 exit( 1 );
131 sal_Int32 nHandle = 0;
132 sal_Int32 nNewHandle;
133 sal_Int32 nErrorCount = 0;
134 sal_Int32 nWarningCount = 0;
136 // loop until all test are performed
137 while( nHandle != -1 )
139 // Instantiate service
140 Reference< XInterface > x =
141 xSMgr->createInstance( OStringToOUString( argv[1] , RTL_TEXTENCODING_ASCII_US ) );
142 if( ! x.is() )
144 printf( "Couldn't instantiate service !\n" );
145 exit( 1 );
148 // do the test
151 nNewHandle = xTest->test(
152 OStringToOUString( argv[1] , RTL_TEXTENCODING_ASCII_US ) , x , nHandle );
154 catch( const Exception & e ) {
155 OString o = OUStringToOString( e.Message, RTL_TEXTENCODING_ASCII_US );
156 printf( "testcomponent : uncaught exception %s\n" , o.getStr() );
157 exit(1);
159 catch( ... )
161 printf( "testcomponent : uncaught unknown exception\n" );
162 exit(1);
166 // print errors and warning
167 Sequence<OUString> seqErrors = xTest->getErrors();
168 Sequence<OUString> seqWarnings = xTest->getWarnings();
169 if( seqWarnings.getLength() > nWarningCount )
171 printf( "Warnings during test %d!\n" , nHandle );
172 for( ; nWarningCount < seqWarnings.getLength() ; nWarningCount ++ )
174 OString o = OUStringToOString(
175 seqWarnings.getArray()[nWarningCount], RTL_TEXTENCODING_ASCII_US );
176 printf( "Warning\n%s\n---------\n" , o.getStr() );
181 if( seqErrors.getLength() > nErrorCount ) {
182 printf( "Errors during test %d!\n" , nHandle );
183 for( ; nErrorCount < seqErrors.getLength() ; nErrorCount ++ )
185 OString o = OUStringToOString(
186 seqErrors.getArray()[nErrorCount], RTL_TEXTENCODING_ASCII_US );
187 printf( "%s\n" , o.getStr() );
191 nHandle = nNewHandle;
194 if( xTest->testPassed() ) {
195 printf( "Test passed !\n" );
197 else {
198 printf( "Test failed !\n" );
201 Reference <XComponent > rComp( xSMgr , UNO_QUERY );
202 rComp->dispose();
203 return 0;
206 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */