Update ooo320-m1
[ooovba.git] / bridges / test / testsameprocess.cxx
blob589efa73247177866ca11a0083c1ad003431f629
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: testsameprocess.cxx,v $
10 * $Revision: 1.13 $
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 #if OSL_DEBUG_LEVEL == 0
34 #undef NDEBUG
35 #define NDEBUG
36 #endif
37 #include <assert.h>
38 #include <osl/time.h>
40 #include <osl/mutex.hxx>
41 #include <osl/thread.hxx>
43 #include <cppuhelper/servicefactory.hxx>
45 #include <com/sun/star/bridge/XBridgeFactory.hpp>
46 #include <com/sun/star/connection/XAcceptor.hpp>
47 #include <com/sun/star/connection/XConnector.hpp>
49 #include <com/sun/star/lang/XComponent.hpp>
51 #include <cppuhelper/weak.hxx>
53 #include <test/XTestFactory.hpp>
56 using namespace ::test;
57 using namespace ::rtl;
58 using namespace ::cppu;
59 using namespace ::osl;
60 using namespace ::com::sun::star::uno;
61 using namespace ::com::sun::star::lang;
62 using namespace ::com::sun::star::bridge;
63 using namespace ::com::sun::star::connection;
65 #ifdef SAL_W32
66 #include <conio.h>
67 #endif
69 #include "testcomp.h"
70 #include "osl/mutex.h"
72 /*********
74 ********/
76 class MyThread :
77 public Thread
79 public:
80 MyThread( const Reference< XAcceptor > &r ,
81 const Reference< XBridgeFactory > &rFactory,
82 const OUString &sConnectionDescription) :
83 m_rAcceptor( r ),
84 m_rBridgeFactory ( rFactory ),
85 m_sConnectionDescription( sConnectionDescription )
87 virtual void SAL_CALL run();
89 private:
90 Reference < XAcceptor > m_rAcceptor;
91 Reference < XBridgeFactory > m_rBridgeFactory;
92 OUString m_sConnectionDescription;
97 void MyThread::run()
100 while ( sal_True )
104 Reference < XConnection > rConnection =
105 m_rAcceptor->accept( m_sConnectionDescription );
107 if( ! rConnection.is() )
109 break;
112 Reference < XBridge > rBridge =
113 m_rBridgeFactory->createBridge(
114 OUString() ,
115 OUString( RTL_CONSTASCII_USTRINGPARAM("iiop")) ,
116 rConnection ,
117 (XInstanceProvider * ) new OInstanceProvider );
121 catch ( ... )
123 printf( "Exception was thrown by acceptor thread\n" );
124 break;
130 int main( int argc, char *argv[] )
132 if( argc < 2 )
134 printf( "usage : testsamprocess host:port\n" );
135 return 0;
139 Reference< XMultiServiceFactory > rSMgr = createRegistryServiceFactory(
140 OUString( RTL_CONSTASCII_USTRINGPARAM( "client.rdb" ) ) );
142 Reference < XConnector > rConnector(
143 createComponent( OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.connection.Connector")),
144 OUString( RTL_CONSTASCII_USTRINGPARAM("connector.uno" SAL_DLLEXTENSION)),
145 rSMgr ),
146 UNO_QUERY );
148 Reference < XAcceptor > rAcceptor(
149 createComponent( OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.connection.Acceptor")),
150 OUString( RTL_CONSTASCII_USTRINGPARAM("acceptor.uno" SAL_DLLEXTENSION)),
151 rSMgr ),
152 UNO_QUERY );
154 // just ensure that it is registered
155 // createComponent( OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.bridge.Bridge.iiop")),
156 // OUString( RTL_CONSTASCII_USTRINGPARAM("iiopbrdg" SAL_DLLEXTENSION)),
157 // rSMgr );
159 Reference < XBridgeFactory > rFactory(
160 createComponent( OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.bridge.BridgeFactory")),
161 OUString( RTL_CONSTASCII_USTRINGPARAM("bridgefac.uno" SAL_DLLEXTENSION)),
162 rSMgr ),
163 UNO_QUERY );
166 MyThread threadAcceptor( rAcceptor , rFactory , OUString::createFromAscii( argv[1] ) );
168 threadAcceptor.create();
169 TimeValue value={2,0};
170 osl_waitThread( &value );
174 Reference < XConnection > rConnection =
175 rConnector->connect( OUString::createFromAscii( argv[1] ) );
177 printf( "%s\n" , OUStringToOString( rConnection->getDescription(),
178 RTL_TEXTENCODING_ASCII_US ).pData->buffer );
180 if( rFactory.is() )
183 Reference < XBridge > rBridge = rFactory->createBridge(
184 OUString( RTL_CONSTASCII_USTRINGPARAM("bla blub")),
185 OUString( RTL_CONSTASCII_USTRINGPARAM("iiop")),
186 rConnection,
187 Reference < XInstanceProvider > () );
189 Reference < XInterface > rInitialObject
190 = rBridge->getInstance( OUString( RTL_CONSTASCII_USTRINGPARAM("bla")) );
192 if( rInitialObject.is() )
194 printf( "got the remote object\n" );
195 testRemote( rInitialObject );
197 printf( "Closing...\n" );
198 TimeValue timeValue={2,0};
199 osl_waitThread( &timeValue );
202 Reference < XBridge > rBridge = rFactory->getBridge(
203 OUString( RTL_CONSTASCII_USTRINGPARAM("bla blub")) );
204 assert( ! rBridge.is() );
207 catch( Exception & )
209 printf( "Login failed, got an Exception !\n" );
212 rAcceptor->stopAccepting();
213 threadAcceptor.join();
215 Reference < XComponent > rComp( rFactory , UNO_QUERY );
216 rComp->dispose();
219 rComp = Reference < XComponent > ( rSMgr , UNO_QUERY );
220 rComp->dispose();
222 return 0;