merge the formfield patch from ooo-build
[ooovba.git] / bridges / test / testoffice.cxx
blobf578cc47711f51f367c1a43e0fce70764ef5738c
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: testoffice.cxx,v $
10 * $Revision: 1.10 $
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 #define NDEBUG
35 #endif
36 #include <assert.h>
37 #include <osl/time.h>
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;
76 #include "testcomp.h"
78 #ifdef SAL_W32
79 #include <conio.h>
80 #endif
83 void mygetchar()
85 #ifdef SAL_W32
86 _getch();
87 #else
88 getchar();
89 #endif
93 void testPipe( const Reference < XMultiServiceFactory > & rSmgr )
95 Reference < XOutputStream > rOut(
96 rSmgr->createInstance( OUString::createFromAscii( "com.sun.star.io.Pipe" ) ),
97 UNO_QUERY );
99 assert( rOut.is() );
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" );
118 // assert( 0 );
121 #include<stdio.h>
122 #include<string.h>
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 );
133 char pcText[1024];
134 pcText[0] = 0;
135 printf( "pleast type any text\n" );
136 while( sal_True )
138 scanf( "%s" , pcText );
140 if( !strcmp( pcText , "end" ) )
142 break;
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" ))),
156 UNO_QUERY );
158 assert( rLoader.is() );
160 sal_Char *urls[] = {
161 "private:factory/swriter",
162 "private:factory/scalc",
163 "private:factory/sdraw",
164 "http://www.heise.de",
165 "file://h|/remote_interfaces.sdw"
168 sal_Char *docu[]= {
169 "a new writer document ...\n",
170 "a new calc document ...\n",
171 "a new draw document ...\n",
172 "www.heise.de\n",
173 "the remote_interfaces.sdw doc\n"
176 sal_Int32 i;
177 for( i = 0 ; i < 1 ; i ++ )
179 printf( "press any key to open %s\n" , docu[i] );
180 mygetchar();
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" );
191 mygetchar();
192 rComponent->dispose();
197 void doSomething( const Reference < XInterface > &r )
199 Reference < XNamingService > rName( r, UNO_QUERY );
200 if( rName.is() )
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 );
207 if( rSmgr.is() )
209 printf( "got the remote service manager !\n" );
210 testPipe( rSmgr );
211 testDocument( rSmgr );
217 int main( int argc, char *argv[] )
219 if( argc < 2 )
221 printf( "usage : testclient host:port" );
222 return 0;
225 OUString sConnectionString;
226 OUString sProtocol;
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)),
239 rSMgr ),
240 UNO_QUERY );
242 createComponent( OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.bridge.Bridge.iiop")),
243 OUString( RTL_CONSTASCII_USTRINGPARAM("remotebridge.uno" SAL_DLLEXTENSION)),
244 rSMgr );
246 Reference < XBridgeFactory > rFactory(
247 createComponent( OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.bridge.BridgeFactory")),
248 OUString( RTL_CONSTASCII_USTRINGPARAM("bridgefac.uno" SAL_DLLEXTENSION)),
249 rSMgr ),
250 UNO_QUERY );
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")),
261 sProtocol,
262 rConnection,
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 );
277 catch (... ) {
278 printf( "Exception thrown\n" );
281 Reference < XComponent > rComp( rSMgr , UNO_QUERY );
282 rComp->dispose();
284 //_getch();
285 return 0;