1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: testoffice.cxx,v $
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
39 #include <osl/mutex.hxx>
40 #include <osl/thread.h>
42 #include <cppuhelper/servicefactory.hxx>
44 #include <com/sun/star/connection/XConnector.hpp>
46 #include <com/sun/star/bridge/XBridgeFactory.hpp>
48 #include <com/sun/star/uno/XNamingService.hpp>
49 #include <com/sun/star/io/XInputStream.hpp>
50 #include <com/sun/star/io/XOutputStream.hpp>
52 #include <com/sun/star/text/XTextDocument.hpp>
54 #include <com/sun/star/lang/XServiceInfo.hpp>
56 #include <com/sun/star/lang/XComponent.hpp>
58 #include <com/sun/star/frame/XComponentLoader.hpp>
60 #include <cppuhelper/weak.hxx>
62 #include <test/XTestFactory.hpp>
64 using namespace ::test
;
65 using namespace ::rtl
;
66 using namespace ::cppu
;
67 using namespace ::com::sun::star::uno
;
68 using namespace ::com::sun::star::io
;
69 using namespace ::com::sun::star::lang
;
70 using namespace ::com::sun::star::bridge
;
71 using namespace ::com::sun::star::registry
;
72 using namespace ::com::sun::star::connection
;
73 using namespace ::com::sun::star::frame
;
74 using namespace ::com::sun::star::text
;
93 void testPipe( const Reference
< XMultiServiceFactory
> & rSmgr
)
95 Reference
< XOutputStream
> rOut(
96 rSmgr
->createInstance( OUString::createFromAscii( "com.sun.star.io.Pipe" ) ),
102 Sequence
< sal_Int8
> seq( 10 );
103 seq
.getArray()[0] = 42;
104 rOut
->writeBytes( seq
);
109 Sequence
< sal_Int8
> seq
;
110 Reference
< XInputStream
> rIn( rOut
, UNO_QUERY
);
111 if( ! ( rIn
->available() == 10) )
112 printf( "wrong bytes available\n" );
113 if( ! ( rIn
->readBytes( seq
, 10 ) == 10 ) )
114 printf( "wrong bytes read\n" );
115 if( ! ( 42 == seq
.getArray()[0] ) )
116 printf( "wrong element in sequence\n" );
124 void testWriter( const Reference
< XComponent
> & rCmp
)
127 Reference
< XTextDocument
> rTextDoc( rCmp
, UNO_QUERY
);
129 Reference
< XText
> rText
= rTextDoc
->getText();
130 Reference
< XTextCursor
> rCursor
= rText
->createTextCursor();
131 Reference
< XTextRange
> rRange ( rCursor
, UNO_QUERY
);
135 printf( "pleast type any text\n" );
138 scanf( "%s" , pcText
);
140 if( !strcmp( pcText
, "end" ) )
145 if ( strlen( pcText
) < sizeof(pcText
)-1 )
146 strcat( pcText
, " " ); // #100211# - checked
148 rText
->insertString( rRange
, OUString::createFromAscii( pcText
) , sal_False
);
152 void testDocument( const Reference
< XMultiServiceFactory
> & rSmgr
)
154 Reference
< XComponentLoader
> rLoader(
155 rSmgr
->createInstance( OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.frame.Desktop" ))),
158 assert( rLoader
.is() );
161 "private:factory/swriter",
162 "private:factory/scalc",
163 "private:factory/sdraw",
164 "http://www.heise.de",
165 "file://h|/remote_interfaces.sdw"
169 "a new writer document ...\n",
170 "a new calc document ...\n",
171 "a new draw document ...\n",
173 "the remote_interfaces.sdw doc\n"
177 for( i
= 0 ; i
< 1 ; i
++ )
179 printf( "press any key to open %s\n" , docu
[i
] );
182 Reference
< XComponent
> rComponent
=
183 rLoader
->loadComponentFromURL(
184 OUString::createFromAscii( urls
[i
] ) ,
185 OUString( RTL_CONSTASCII_USTRINGPARAM("_blank")),
187 Sequence
< ::com::sun::star::beans::PropertyValue
>() );
189 testWriter( rComponent
);
190 printf( "press any key to close the document\n" );
192 rComponent
->dispose();
197 void doSomething( const Reference
< XInterface
> &r
)
199 Reference
< XNamingService
> rName( r
, UNO_QUERY
);
202 printf( "got the remote naming service !\n" );
203 Reference
< XInterface
> rXsmgr
= rName
->getRegisteredObject(
204 OUString::createFromAscii( "StarOffice.ServiceManager" ) );
206 Reference
< XMultiServiceFactory
> rSmgr( rXsmgr
, UNO_QUERY
);
209 printf( "got the remote service manager !\n" );
211 testDocument( rSmgr
);
217 int main( int argc
, char *argv
[] )
221 printf( "usage : testclient host:port" );
225 OUString sConnectionString
;
227 sal_Bool bLatency
= sal_False
;
228 sal_Bool bReverse
= sal_False
;
229 parseCommandLine( argv
, &sConnectionString
, &sProtocol
, &bLatency
, &bReverse
);
231 Reference
< XMultiServiceFactory
> rSMgr
= createRegistryServiceFactory(
232 OUString( RTL_CONSTASCII_USTRINGPARAM( "client.rdb" ) ) );
234 // just ensure that it is registered
236 Reference
< XConnector
> rConnector(
237 createComponent( OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.connection.Connector")),
238 OUString( RTL_CONSTASCII_USTRINGPARAM("connector.uno" SAL_DLLEXTENSION
)),
242 createComponent( OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.bridge.Bridge.iiop")),
243 OUString( RTL_CONSTASCII_USTRINGPARAM("remotebridge.uno" SAL_DLLEXTENSION
)),
246 Reference
< XBridgeFactory
> rFactory(
247 createComponent( OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.bridge.BridgeFactory")),
248 OUString( RTL_CONSTASCII_USTRINGPARAM("bridgefac.uno" SAL_DLLEXTENSION
)),
254 if( rFactory
.is() && rConnector
.is() )
256 Reference
< XConnection
> rConnection
=
257 rConnector
->connect( sConnectionString
);
259 Reference
< XBridge
> rBridge
= rFactory
->createBridge(
260 OUString( RTL_CONSTASCII_USTRINGPARAM("bla blub")),
263 Reference
< XInstanceProvider
> () );
265 Reference
< XInterface
> rInitialObject
266 = rBridge
->getInstance( OUString( RTL_CONSTASCII_USTRINGPARAM("NamingService")) );
268 if( rInitialObject
.is() )
270 printf( "got the remote object\n" );
271 doSomething( rInitialObject
);
273 TimeValue value
={2,0};
274 osl_waitThread( &value
);
278 printf( "Exception thrown\n" );
281 Reference
< XComponent
> rComp( rSMgr
, UNO_QUERY
);