bump product version to 4.1.6.2
[LibreOffice.git] / bridges / test / testclient.cxx
blob52f70bff08f921361f28ec25127048cefb6190f3
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 .
20 #include <string.h>
22 #include <osl/time.h>
24 #include <osl/mutex.hxx>
25 #include <osl/module.h>
26 #include <osl/thread.h>
27 #include <osl/conditn.h>
28 #include <osl/diagnose.h>
30 #include <uno/mapping.hxx>
32 #include <cppuhelper/servicefactory.hxx>
34 #include <com/sun/star/connection/XConnector.hpp>
36 #include <com/sun/star/bridge/XBridgeFactory.hpp>
38 #include <com/sun/star/lang/XComponent.hpp>
39 #include <com/sun/star/lang/DisposedException.hpp>
40 #include <com/sun/star/lang/XMain.hpp>
42 #include <com/sun/star/test/performance/XPerformanceTest.hpp>
44 #include <cppuhelper/weak.hxx>
45 #include <cppuhelper/factory.hxx>
47 #include <test/XTestFactory.hpp>
50 using namespace ::test;
51 using namespace ::rtl;
52 using namespace ::cppu;
53 using namespace ::com::sun::star::uno;
54 using namespace ::com::sun::star::lang;
55 using namespace ::com::sun::star::bridge;
56 using namespace ::com::sun::star::registry;
57 using namespace ::com::sun::star::connection;
58 using namespace ::com::sun::star::test::performance;
60 #include "testcomp.h"
63 void doPerformanceTest( const Reference < XPerformanceTest > & /* xBench */)
65 printf( "not implemented\n" );
66 // sal_Int32 i,nLoop = 2000;
67 // sal_Int32 tStart, tEnd , tEnd2;
68 // //------------------------------------
69 // // oneway calls
70 // i = nLoop;
71 // tStart = GetTickCount();
72 // while (i--)
73 // xBench->async();
74 // tEnd = GetTickCount();
75 // xBench->sync();
76 // tEnd2 = GetTickCount();
77 // printf( "%d %d %d\n" , nLoop, tEnd - tStart , tEnd2 -tStart );
78 // // synchron calls
79 // i = nLoop;
80 // tStart = GetTickCount();
81 // while (i--)
82 // xBench->sync();
83 // tEnd = GetTickCount();
84 // printf( "%d %d \n" , nLoop, tEnd - tStart );
88 void testLatency( const Reference < XConnection > &r , sal_Bool /* bReply */)
90 sal_Int32 nLoop = 10000;
91 TimeValue aStartTime, aEndTime;
92 osl_getSystemTime( &aStartTime );
94 sal_Int32 i;
95 for( i = 0 ; i < nLoop ; i++ )
97 Sequence< sal_Int8 > s1( 200 );
98 r->write( s1 );
99 r->read( s1 , 12 );
100 r->read( s1 , 48 );
102 osl_getSystemTime( &aEndTime );
104 double fStart = (double)aStartTime.Seconds + ((double)aStartTime.Nanosec / 1000000000.0);
105 double fEnd = (double)aEndTime.Seconds + ((double)aEndTime.Nanosec / 1000000000.0);
107 printf( "System latency per call : %g\n" , (( fEnd-fStart )/2.) / ((double)(nLoop)) );
110 int main( int argc, char *argv[] )
112 if( argc < 2 )
114 printf(
115 "usage : testclient [-r] connectionstring\n"
116 " -r reverse call me test (server calls client)"
118 return 0;
121 OUString sConnectionString;
122 OUString sProtocol;
123 sal_Bool bLatency = sal_False;
124 sal_Bool bReverse = sal_False;
126 parseCommandLine( argv , &sConnectionString , &sProtocol , &bLatency , &bReverse );
129 Reference< XMultiServiceFactory > rSMgr = createRegistryServiceFactory(
130 OUString("client.rdb") );
133 Reference < XConnector > rConnector(
134 createComponent( OUString("com.sun.star.connection.Connector"),
135 OUString( "connector.uno" SAL_DLLEXTENSION),
136 rSMgr ),
137 UNO_QUERY );
142 Reference < XConnection > rConnection =
143 rConnector->connect( sConnectionString );
145 printf( "%s\n" , OUStringToOString( rConnection->getDescription(),
146 RTL_TEXTENCODING_ASCII_US ).pData->buffer );
149 if( bLatency )
151 testLatency( rConnection , sal_False );
152 testLatency( rConnection , sal_True );
154 else
156 // just ensure that it is registered
157 createComponent( OUString("com.sun.star.bridge.Bridge.iiop"),
158 OUString( "remotebridge.uno" SAL_DLLEXTENSION),
159 rSMgr );
161 Reference < XBridgeFactory > rFactory(
162 createComponent( OUString("com.sun.star.bridge.BridgeFactory"),
163 OUString( "bridgefac.uno" SAL_DLLEXTENSION),
164 rSMgr ),
165 UNO_QUERY );
167 if( rFactory.is() )
170 Reference < XBridge > rBridge = rFactory->createBridge(
171 OUString("bla blub"),
172 sProtocol,
173 rConnection,
174 new OInstanceProvider );
176 // test the factory
177 Reference < XBridge > rBridge2 = rFactory->getBridge( OUString("bla blub") );
178 OSL_ASSERT( rBridge2.is() );
179 OSL_ASSERT( rBridge2->getDescription() == rBridge->getDescription( ) );
180 OSL_ASSERT( rBridge2->getName() == rBridge->getName() );
181 OSL_ASSERT( rBridge2 == rBridge );
185 Reference < XInterface > rInitialObject = rBridge->getInstance(
186 OUString("bridges-testobject") );
188 if( rInitialObject.is() )
190 printf( "got the remote object\n" );
191 if( ! bReverse )
193 // Reference < XComponent > rPerfTest( rInitialObject , UNO_QUERY );
194 // if( rPerfTest.is() )
195 // {
196 // // doPerformanceTest( rPerfTest );
197 // }
198 // else
199 // {
200 testRemote( rInitialObject );
201 // }
204 // Reference < XComponent > rComp( rBridge , UNO_QUERY );
205 // rComp->dispose();
207 rInitialObject = Reference < XInterface > ();
208 printf( "Waiting...\n" );
209 TimeValue value={bReverse ?1000 :2,0};
210 osl_waitThread( &value );
211 printf( "Closing...\n" );
214 Reference < XBridge > rBridge = rFactory->getBridge( OUString("bla blub") );
215 // OSL_ASSERT( ! rBridge.is() );
219 catch( DisposedException & e )
221 OString o = OUStringToOString( e.Message , RTL_TEXTENCODING_ASCII_US );
222 printf( "A remote object reference became invalid\n%s\n" , o.pData->buffer );
224 catch( Exception &e )
226 OString o = OUStringToOString( e.Message , RTL_TEXTENCODING_ASCII_US );
227 printf( "Login failed, got an Exception !\n%s\n" , o.pData->buffer );
231 Reference < XComponent > rComp( rSMgr , UNO_QUERY );
232 rComp->dispose();
234 printf( "Closed\n" );
235 return 0;
238 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */