1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
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 ::cppu
;
52 using namespace ::com::sun::star::uno
;
53 using namespace ::com::sun::star::lang
;
54 using namespace ::com::sun::star::bridge
;
55 using namespace ::com::sun::star::registry
;
56 using namespace ::com::sun::star::connection
;
57 using namespace ::com::sun::star::test::performance
;
62 void doPerformanceTest( const Reference
< XPerformanceTest
> & /* xBench */)
64 printf( "not implemented\n" );
65 // sal_Int32 i,nLoop = 2000;
66 // sal_Int32 tStart, tEnd , tEnd2;
70 // tStart = GetTickCount();
73 // tEnd = GetTickCount();
75 // tEnd2 = GetTickCount();
76 // printf( "%d %d %d\n" , nLoop, tEnd - tStart , tEnd2 -tStart );
79 // tStart = GetTickCount();
82 // tEnd = GetTickCount();
83 // printf( "%d %d \n" , nLoop, tEnd - tStart );
87 void testLatency( const Reference
< XConnection
> &r
, sal_Bool
/* bReply */)
89 sal_Int32 nLoop
= 10000;
90 TimeValue aStartTime
, aEndTime
;
91 osl_getSystemTime( &aStartTime
);
94 for( i
= 0 ; i
< nLoop
; i
++ )
96 Sequence
< sal_Int8
> s1( 200 );
101 osl_getSystemTime( &aEndTime
);
103 double fStart
= (double)aStartTime
.Seconds
+ ((double)aStartTime
.Nanosec
/ 1000000000.0);
104 double fEnd
= (double)aEndTime
.Seconds
+ ((double)aEndTime
.Nanosec
/ 1000000000.0);
106 printf( "System latency per call : %g\n" , (( fEnd
-fStart
)/2.) / ((double)(nLoop
)) );
109 int main( int argc
, char *argv
[] )
114 "usage : testclient [-r] connectionstring\n"
115 " -r reverse call me test (server calls client)"
120 OUString sConnectionString
;
122 sal_Bool bLatency
= sal_False
;
123 sal_Bool bReverse
= sal_False
;
125 parseCommandLine( argv
, &sConnectionString
, &sProtocol
, &bLatency
, &bReverse
);
128 Reference
< XMultiServiceFactory
> rSMgr
= createRegistryServiceFactory(
129 OUString("client.rdb") );
132 Reference
< XConnector
> rConnector(
133 createComponent( OUString("com.sun.star.connection.Connector"),
134 OUString( "connector.uno" SAL_DLLEXTENSION
),
141 Reference
< XConnection
> rConnection
=
142 rConnector
->connect( sConnectionString
);
144 printf( "%s\n" , OUStringToOString( rConnection
->getDescription(),
145 RTL_TEXTENCODING_ASCII_US
).pData
->buffer
);
150 testLatency( rConnection
, sal_False
);
151 testLatency( rConnection
, sal_True
);
155 // just ensure that it is registered
156 createComponent( OUString("com.sun.star.bridge.Bridge.iiop"),
157 OUString( "remotebridge.uno" SAL_DLLEXTENSION
),
160 Reference
< XBridgeFactory
> rFactory(
161 createComponent( OUString("com.sun.star.bridge.BridgeFactory"),
162 OUString( "bridgefac.uno" SAL_DLLEXTENSION
),
169 Reference
< XBridge
> rBridge
= rFactory
->createBridge(
170 OUString("bla blub"),
173 new OInstanceProvider
);
176 Reference
< XBridge
> rBridge2
= rFactory
->getBridge( OUString("bla blub") );
177 OSL_ASSERT( rBridge2
.is() );
178 OSL_ASSERT( rBridge2
->getDescription() == rBridge
->getDescription( ) );
179 OSL_ASSERT( rBridge2
->getName() == rBridge
->getName() );
180 OSL_ASSERT( rBridge2
== rBridge
);
184 Reference
< XInterface
> rInitialObject
= rBridge
->getInstance(
185 OUString("bridges-testobject") );
187 if( rInitialObject
.is() )
189 printf( "got the remote object\n" );
192 // Reference < XComponent > rPerfTest( rInitialObject , UNO_QUERY );
193 // if( rPerfTest.is() )
195 // // doPerformanceTest( rPerfTest );
199 testRemote( rInitialObject
);
203 // Reference < XComponent > rComp( rBridge , UNO_QUERY );
206 rInitialObject
= Reference
< XInterface
> ();
207 printf( "Waiting...\n" );
208 TimeValue value
={bReverse
?1000 :2,0};
209 osl_waitThread( &value
);
210 printf( "Closing...\n" );
213 Reference
< XBridge
> rBridge
= rFactory
->getBridge( OUString("bla blub") );
214 // OSL_ASSERT( ! rBridge.is() );
218 catch( DisposedException
& e
)
220 OString o
= OUStringToOString( e
.Message
, RTL_TEXTENCODING_ASCII_US
);
221 printf( "A remote object reference became invalid\n%s\n" , o
.pData
->buffer
);
223 catch( Exception
&e
)
225 OString o
= OUStringToOString( e
.Message
, RTL_TEXTENCODING_ASCII_US
);
226 printf( "Login failed, got an Exception !\n%s\n" , o
.pData
->buffer
);
230 Reference
< XComponent
> rComp( rSMgr
, UNO_QUERY
);
233 printf( "Closed\n" );
237 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */