merge the formfield patch from ooo-build
[ooovba.git] / bridges / test / testclient.cxx
blob706a3710f217a7cbef8112f5927df0ca0f5dbb20
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: testclient.cxx,v $
10 * $Revision: 1.14 $
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_bridges.hxx"
33 #include <string.h>
35 #if OSL_DEBUG_LEVEL == 0
36 #undef NDEBUG
37 #define NDEBUG
38 #endif
39 #include <assert.h>
40 #include <osl/time.h>
42 #include <osl/mutex.hxx>
43 #include <osl/module.h>
44 #include <osl/thread.h>
45 #include <osl/conditn.h>
46 #include <osl/diagnose.h>
48 #include <uno/mapping.hxx>
50 #include <cppuhelper/servicefactory.hxx>
52 #include <com/sun/star/connection/XConnector.hpp>
54 #include <com/sun/star/bridge/XBridgeFactory.hpp>
56 #include <com/sun/star/lang/XComponent.hpp>
57 #include <com/sun/star/lang/DisposedException.hpp>
58 #include <com/sun/star/lang/XMain.hpp>
60 #include <com/sun/star/test/performance/XPerformanceTest.hpp>
62 #include <cppuhelper/weak.hxx>
63 #include <cppuhelper/factory.hxx>
65 #include <test/XTestFactory.hpp>
68 using namespace ::test;
69 using namespace ::rtl;
70 using namespace ::cppu;
71 using namespace ::com::sun::star::uno;
72 using namespace ::com::sun::star::lang;
73 using namespace ::com::sun::star::bridge;
74 using namespace ::com::sun::star::registry;
75 using namespace ::com::sun::star::connection;
76 using namespace ::com::sun::star::test::performance;
78 #include "testcomp.h"
81 void doPerformanceTest( const Reference < XPerformanceTest > & /* xBench */)
83 printf( "not implemented\n" );
84 // sal_Int32 i,nLoop = 2000;
85 // sal_Int32 tStart, tEnd , tEnd2;
86 // //------------------------------------
87 // // oneway calls
88 // i = nLoop;
89 // tStart = GetTickCount();
90 // while (i--)
91 // xBench->async();
92 // tEnd = GetTickCount();
93 // xBench->sync();
94 // tEnd2 = GetTickCount();
95 // printf( "%d %d %d\n" , nLoop, tEnd - tStart , tEnd2 -tStart );
96 // // synchron calls
97 // i = nLoop;
98 // tStart = GetTickCount();
99 // while (i--)
100 // xBench->sync();
101 // tEnd = GetTickCount();
102 // printf( "%d %d \n" , nLoop, tEnd - tStart );
106 void testLatency( const Reference < XConnection > &r , sal_Bool /* bReply */)
108 sal_Int32 nLoop = 10000;
109 TimeValue aStartTime, aEndTime;
110 osl_getSystemTime( &aStartTime );
112 sal_Int32 i;
113 for( i = 0 ; i < nLoop ; i++ )
115 Sequence< sal_Int8 > s1( 200 );
116 r->write( s1 );
117 r->read( s1 , 12 );
118 r->read( s1 , 48 );
120 osl_getSystemTime( &aEndTime );
122 double fStart = (double)aStartTime.Seconds + ((double)aStartTime.Nanosec / 1000000000.0);
123 double fEnd = (double)aEndTime.Seconds + ((double)aEndTime.Nanosec / 1000000000.0);
125 printf( "System latency per call : %g\n" , (( fEnd-fStart )/2.) / ((double)(nLoop)) );
128 int main( int argc, char *argv[] )
130 if( argc < 2 )
132 printf(
133 "usage : testclient [-r] connectionstring\n"
134 " -r reverse call me test (server calls client)"
136 return 0;
139 OUString sConnectionString;
140 OUString sProtocol;
141 sal_Bool bLatency = sal_False;
142 sal_Bool bReverse = sal_False;
144 parseCommandLine( argv , &sConnectionString , &sProtocol , &bLatency , &bReverse );
147 Reference< XMultiServiceFactory > rSMgr = createRegistryServiceFactory(
148 OUString( RTL_CONSTASCII_USTRINGPARAM("client.rdb")) );
151 Reference < XConnector > rConnector(
152 createComponent( OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.connection.Connector")),
153 OUString( RTL_CONSTASCII_USTRINGPARAM("connector.uno" SAL_DLLEXTENSION)),
154 rSMgr ),
155 UNO_QUERY );
160 Reference < XConnection > rConnection =
161 rConnector->connect( sConnectionString );
163 printf( "%s\n" , OUStringToOString( rConnection->getDescription(),
164 RTL_TEXTENCODING_ASCII_US ).pData->buffer );
167 if( bLatency )
169 testLatency( rConnection , sal_False );
170 testLatency( rConnection , sal_True );
172 else
174 // just ensure that it is registered
175 createComponent( OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.bridge.Bridge.iiop")),
176 OUString( RTL_CONSTASCII_USTRINGPARAM("remotebridge.uno" SAL_DLLEXTENSION)),
177 rSMgr );
179 Reference < XBridgeFactory > rFactory(
180 createComponent( OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.bridge.BridgeFactory")),
181 OUString( RTL_CONSTASCII_USTRINGPARAM("bridgefac.uno" SAL_DLLEXTENSION)),
182 rSMgr ),
183 UNO_QUERY );
185 if( rFactory.is() )
188 Reference < XBridge > rBridge = rFactory->createBridge(
189 OUString( RTL_CONSTASCII_USTRINGPARAM("bla blub")),
190 sProtocol,
191 rConnection,
192 new OInstanceProvider );
194 // test the factory
195 Reference < XBridge > rBridge2 = rFactory->getBridge( OUString( RTL_CONSTASCII_USTRINGPARAM("bla blub")) );
196 assert( rBridge2.is() );
197 assert( rBridge2->getDescription() == rBridge->getDescription( ) );
198 assert( rBridge2->getName() == rBridge->getName() );
199 assert( rBridge2 == rBridge );
203 Reference < XInterface > rInitialObject = rBridge->getInstance(
204 OUString( RTL_CONSTASCII_USTRINGPARAM("bridges-testobject")) );
206 if( rInitialObject.is() )
208 printf( "got the remote object\n" );
209 if( ! bReverse )
211 // Reference < XComponent > rPerfTest( rInitialObject , UNO_QUERY );
212 // if( rPerfTest.is() )
213 // {
214 // // doPerformanceTest( rPerfTest );
215 // }
216 // else
217 // {
218 testRemote( rInitialObject );
219 // }
222 // Reference < XComponent > rComp( rBridge , UNO_QUERY );
223 // rComp->dispose();
225 rInitialObject = Reference < XInterface > ();
226 printf( "Waiting...\n" );
227 TimeValue value={bReverse ?1000 :2,0};
228 osl_waitThread( &value );
229 printf( "Closing...\n" );
232 Reference < XBridge > rBridge = rFactory->getBridge( OUString( RTL_CONSTASCII_USTRINGPARAM("bla blub")) );
233 // assert( ! rBridge.is() );
237 catch( DisposedException & e )
239 OString o = OUStringToOString( e.Message , RTL_TEXTENCODING_ASCII_US );
240 printf( "A remote object reference became invalid\n%s\n" , o.pData->buffer );
242 catch( Exception &e )
244 OString o = OUStringToOString( e.Message , RTL_TEXTENCODING_ASCII_US );
245 printf( "Login failed, got an Exception !\n%s\n" , o.pData->buffer );
249 Reference < XComponent > rComp( rSMgr , UNO_QUERY );
250 rComp->dispose();
252 printf( "Closed\n" );
253 return 0;