bump product version to 4.1.6.2
[LibreOffice.git] / bridges / test / testsameprocess.cxx
blob675ec857e08ecb3c24c981a7b8702896d86d11a0
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 <osl/time.h>
22 #include <osl/mutex.hxx>
23 #include <osl/thread.hxx>
25 #include <cppuhelper/servicefactory.hxx>
27 #include <com/sun/star/bridge/XBridgeFactory.hpp>
28 #include <com/sun/star/connection/XAcceptor.hpp>
29 #include <com/sun/star/connection/XConnector.hpp>
31 #include <com/sun/star/lang/XComponent.hpp>
33 #include <cppuhelper/weak.hxx>
35 #include <test/XTestFactory.hpp>
38 using namespace ::test;
39 using namespace ::rtl;
40 using namespace ::cppu;
41 using namespace ::osl;
42 using namespace ::com::sun::star::uno;
43 using namespace ::com::sun::star::lang;
44 using namespace ::com::sun::star::bridge;
45 using namespace ::com::sun::star::connection;
47 #ifdef SAL_W32
48 #include <conio.h>
49 #endif
51 #include "testcomp.h"
52 #include "osl/mutex.h"
54 /*********
56 ********/
58 class MyThread :
59 public Thread
61 public:
62 MyThread( const Reference< XAcceptor > &r ,
63 const Reference< XBridgeFactory > &rFactory,
64 const OUString &sConnectionDescription) :
65 m_rAcceptor( r ),
66 m_rBridgeFactory ( rFactory ),
67 m_sConnectionDescription( sConnectionDescription )
69 virtual void SAL_CALL run();
71 private:
72 Reference < XAcceptor > m_rAcceptor;
73 Reference < XBridgeFactory > m_rBridgeFactory;
74 OUString m_sConnectionDescription;
79 void MyThread::run()
82 while ( true )
84 try
86 Reference < XConnection > rConnection =
87 m_rAcceptor->accept( m_sConnectionDescription );
89 if( ! rConnection.is() )
91 break;
94 Reference < XBridge > rBridge =
95 m_rBridgeFactory->createBridge(
96 OUString() ,
97 OUString("iiop") ,
98 rConnection ,
99 (XInstanceProvider * ) new OInstanceProvider );
103 catch ( ... )
105 printf( "Exception was thrown by acceptor thread\n" );
106 break;
112 int main( int argc, char *argv[] )
114 if( argc < 2 )
116 printf( "usage : testsamprocess host:port\n" );
117 return 0;
121 Reference< XMultiServiceFactory > rSMgr = createRegistryServiceFactory(
122 OUString( "client.rdb" ) );
124 Reference < XConnector > rConnector(
125 createComponent( OUString("com.sun.star.connection.Connector"),
126 OUString( "connector.uno" SAL_DLLEXTENSION),
127 rSMgr ),
128 UNO_QUERY );
130 Reference < XAcceptor > rAcceptor(
131 createComponent( OUString("com.sun.star.connection.Acceptor"),
132 OUString( "acceptor.uno" SAL_DLLEXTENSION),
133 rSMgr ),
134 UNO_QUERY );
136 // just ensure that it is registered
137 // createComponent( OUString("com.sun.star.bridge.Bridge.iiop"),
138 // OUString( "iiopbrdg" SAL_DLLEXTENSION),
139 // rSMgr );
141 Reference < XBridgeFactory > rFactory(
142 createComponent( OUString("com.sun.star.bridge.BridgeFactory"),
143 OUString( "bridgefac.uno" SAL_DLLEXTENSION),
144 rSMgr ),
145 UNO_QUERY );
148 MyThread threadAcceptor( rAcceptor , rFactory , OUString::createFromAscii( argv[1] ) );
150 threadAcceptor.create();
151 TimeValue value={2,0};
152 osl_waitThread( &value );
156 Reference < XConnection > rConnection =
157 rConnector->connect( OUString::createFromAscii( argv[1] ) );
159 printf( "%s\n" , OUStringToOString( rConnection->getDescription(),
160 RTL_TEXTENCODING_ASCII_US ).pData->buffer );
162 if( rFactory.is() )
165 Reference < XBridge > rBridge = rFactory->createBridge(
166 OUString("bla blub"),
167 OUString("iiop"),
168 rConnection,
169 Reference < XInstanceProvider > () );
171 Reference < XInterface > rInitialObject
172 = rBridge->getInstance( OUString("bla") );
174 if( rInitialObject.is() )
176 printf( "got the remote object\n" );
177 testRemote( rInitialObject );
179 printf( "Closing...\n" );
180 TimeValue timeValue={2,0};
181 osl_waitThread( &timeValue );
184 Reference < XBridge > rBridge = rFactory->getBridge(
185 OUString("bla blub") );
186 OSL_ASSERT( ! rBridge.is() );
189 catch( Exception & )
191 printf( "Login failed, got an Exception !\n" );
194 rAcceptor->stopAccepting();
195 threadAcceptor.join();
197 Reference < XComponent > rComp( rFactory , UNO_QUERY );
198 rComp->dispose();
201 rComp = Reference < XComponent > ( rSMgr , UNO_QUERY );
202 rComp->dispose();
204 return 0;
207 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */