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 .
22 #include <osl/mutex.hxx>
23 #include <osl/thread.h>
25 #include <cppuhelper/servicefactory.hxx>
27 #include <com/sun/star/connection/XConnector.hpp>
29 #include <com/sun/star/bridge/XBridgeFactory.hpp>
31 #include <com/sun/star/uno/XNamingService.hpp>
32 #include <com/sun/star/io/Pipe.hpp>
34 #include <com/sun/star/text/XTextDocument.hpp>
36 #include <com/sun/star/lang/XServiceInfo.hpp>
38 #include <com/sun/star/lang/XComponent.hpp>
40 #include <com/sun/star/frame/Desktop.hpp>
41 #include <com/sun/star/frame/XComponentLoader.hpp>
43 #include <cppuhelper/weak.hxx>
45 #include <test/XTestFactory.hpp>
47 using namespace ::test
;
48 using namespace ::cppu
;
49 using namespace ::com::sun::star::uno
;
50 using namespace ::com::sun::star::io
;
51 using namespace ::com::sun::star::lang
;
52 using namespace ::com::sun::star::bridge
;
53 using namespace ::com::sun::star::registry
;
54 using namespace ::com::sun::star::connection
;
55 using namespace ::com::sun::star::frame
;
56 using namespace ::com::sun::star::text
;
75 void testPipe( const Reference
< XMultiServiceFactory
> & rSmgr
)
77 Reference
< XPipe
> rPipe( Pipe::create(comphelper::getComponentContext(rSmgr
)), UNO_QUERY_THROW
);
80 Sequence
< sal_Int8
> seq( 10 );
81 seq
.getArray()[0] = 42;
82 rPipe
->writeBytes( seq
);
87 Sequence
< sal_Int8
> seq
;
88 if( ! ( rPipe
->available() == 10) )
89 printf( "wrong bytes available\n" );
90 if( ! ( rPipe
->readBytes( seq
, 10 ) == 10 ) )
91 printf( "wrong bytes read\n" );
92 if( ! ( 42 == seq
.getArray()[0] ) )
93 printf( "wrong element in sequence\n" );
101 void testWriter( const Reference
< XComponent
> & rCmp
)
104 Reference
< XTextDocument
> rTextDoc( rCmp
, UNO_QUERY
);
106 Reference
< XText
> rText
= rTextDoc
->getText();
107 Reference
< XTextCursor
> rCursor
= rText
->createTextCursor();
108 Reference
< XTextRange
> rRange ( rCursor
, UNO_QUERY
);
112 printf( "pleast type any text\n" );
115 scanf( "%s" , pcText
);
117 if( !strcmp( pcText
, "end" ) )
122 if ( strlen( pcText
) < sizeof(pcText
)-1 )
123 strcat( pcText
, " " ); // #100211# - checked
125 rText
->insertString( rRange
, OUString::createFromAscii( pcText
) , sal_False
);
129 void testDocument( const Reference
< XMultiServiceFactory
> & rSmgr
)
131 Reference
< XDesktop2
> rLoader
= Desktop::create( comphelper::getComponentContext(rSmgr
) );
134 "private:factory/swriter",
135 "private:factory/scalc",
136 "private:factory/sdraw",
137 "http://www.heise.de",
138 "file://h|/remote_interfaces.sdw"
142 "a new writer document ...\n",
143 "a new calc document ...\n",
144 "a new draw document ...\n",
146 "the remote_interfaces.sdw doc\n"
150 for( i
= 0 ; i
< 1 ; i
++ )
152 printf( "press any key to open %s\n" , docu
[i
] );
155 Reference
< XComponent
> rComponent
=
156 rLoader
->loadComponentFromURL(
157 OUString::createFromAscii( urls
[i
] ) ,
160 Sequence
< ::com::sun::star::beans::PropertyValue
>() );
162 testWriter( rComponent
);
163 printf( "press any key to close the document\n" );
165 rComponent
->dispose();
170 void doSomething( const Reference
< XInterface
> &r
)
172 Reference
< XNamingService
> rName( r
, UNO_QUERY
);
175 printf( "got the remote naming service !\n" );
176 Reference
< XInterface
> rXsmgr
= rName
->getRegisteredObject(
177 OUString( "StarOffice.ServiceManager" ) );
179 Reference
< XMultiServiceFactory
> rSmgr( rXsmgr
, UNO_QUERY
);
182 printf( "got the remote service manager !\n" );
184 testDocument( rSmgr
);
190 int main( int argc
, char *argv
[] )
194 printf( "usage : testclient host:port" );
198 OUString sConnectionString
;
200 sal_Bool bLatency
= sal_False
;
201 sal_Bool bReverse
= sal_False
;
202 parseCommandLine( argv
, &sConnectionString
, &sProtocol
, &bLatency
, &bReverse
);
204 Reference
< XMultiServiceFactory
> rSMgr
= createRegistryServiceFactory(
205 OUString( "client.rdb" ) );
207 // just ensure that it is registered
209 Reference
< XConnector
> rConnector(
210 createComponent( OUString("com.sun.star.connection.Connector"),
211 OUString( "connector.uno" SAL_DLLEXTENSION
),
215 createComponent( OUString("com.sun.star.bridge.Bridge.iiop"),
216 OUString( "remotebridge.uno" SAL_DLLEXTENSION
),
219 Reference
< XBridgeFactory
> rFactory(
220 createComponent( OUString("com.sun.star.bridge.BridgeFactory"),
221 OUString( "bridgefac.uno" SAL_DLLEXTENSION
),
227 if( rFactory
.is() && rConnector
.is() )
229 Reference
< XConnection
> rConnection
=
230 rConnector
->connect( sConnectionString
);
232 Reference
< XBridge
> rBridge
= rFactory
->createBridge(
233 OUString("bla blub"),
236 Reference
< XInstanceProvider
> () );
238 Reference
< XInterface
> rInitialObject
239 = rBridge
->getInstance( OUString("NamingService") );
241 if( rInitialObject
.is() )
243 printf( "got the remote object\n" );
244 doSomething( rInitialObject
);
246 TimeValue value
={2,0};
247 osl_waitThread( &value
);
251 printf( "Exception thrown\n" );
254 Reference
< XComponent
> rComp( rSMgr
, UNO_QUERY
);
261 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */