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 ::rtl
;
49 using namespace ::cppu
;
50 using namespace ::com::sun::star::uno
;
51 using namespace ::com::sun::star::io
;
52 using namespace ::com::sun::star::lang
;
53 using namespace ::com::sun::star::bridge
;
54 using namespace ::com::sun::star::registry
;
55 using namespace ::com::sun::star::connection
;
56 using namespace ::com::sun::star::frame
;
57 using namespace ::com::sun::star::text
;
76 void testPipe( const Reference
< XMultiServiceFactory
> & rSmgr
)
78 Reference
< XPipe
> rPipe( Pipe::create(comphelper::getComponentContext(rSmgr
)), UNO_QUERY_THROW
);
81 Sequence
< sal_Int8
> seq( 10 );
82 seq
.getArray()[0] = 42;
83 rPipe
->writeBytes( seq
);
88 Sequence
< sal_Int8
> seq
;
89 if( ! ( rPipe
->available() == 10) )
90 printf( "wrong bytes available\n" );
91 if( ! ( rPipe
->readBytes( seq
, 10 ) == 10 ) )
92 printf( "wrong bytes read\n" );
93 if( ! ( 42 == seq
.getArray()[0] ) )
94 printf( "wrong element in sequence\n" );
102 void testWriter( const Reference
< XComponent
> & rCmp
)
105 Reference
< XTextDocument
> rTextDoc( rCmp
, UNO_QUERY
);
107 Reference
< XText
> rText
= rTextDoc
->getText();
108 Reference
< XTextCursor
> rCursor
= rText
->createTextCursor();
109 Reference
< XTextRange
> rRange ( rCursor
, UNO_QUERY
);
113 printf( "pleast type any text\n" );
116 scanf( "%s" , pcText
);
118 if( !strcmp( pcText
, "end" ) )
123 if ( strlen( pcText
) < sizeof(pcText
)-1 )
124 strcat( pcText
, " " ); // #100211# - checked
126 rText
->insertString( rRange
, OUString::createFromAscii( pcText
) , sal_False
);
130 void testDocument( const Reference
< XMultiServiceFactory
> & rSmgr
)
132 Reference
< XDesktop2
> rLoader
= Desktop::create( comphelper::getComponentContext(rSmgr
) );
135 "private:factory/swriter",
136 "private:factory/scalc",
137 "private:factory/sdraw",
138 "http://www.heise.de",
139 "file://h|/remote_interfaces.sdw"
143 "a new writer document ...\n",
144 "a new calc document ...\n",
145 "a new draw document ...\n",
147 "the remote_interfaces.sdw doc\n"
151 for( i
= 0 ; i
< 1 ; i
++ )
153 printf( "press any key to open %s\n" , docu
[i
] );
156 Reference
< XComponent
> rComponent
=
157 rLoader
->loadComponentFromURL(
158 OUString::createFromAscii( urls
[i
] ) ,
161 Sequence
< ::com::sun::star::beans::PropertyValue
>() );
163 testWriter( rComponent
);
164 printf( "press any key to close the document\n" );
166 rComponent
->dispose();
171 void doSomething( const Reference
< XInterface
> &r
)
173 Reference
< XNamingService
> rName( r
, UNO_QUERY
);
176 printf( "got the remote naming service !\n" );
177 Reference
< XInterface
> rXsmgr
= rName
->getRegisteredObject(
178 OUString( "StarOffice.ServiceManager" ) );
180 Reference
< XMultiServiceFactory
> rSmgr( rXsmgr
, UNO_QUERY
);
183 printf( "got the remote service manager !\n" );
185 testDocument( rSmgr
);
191 int main( int argc
, char *argv
[] )
195 printf( "usage : testclient host:port" );
199 OUString sConnectionString
;
201 sal_Bool bLatency
= sal_False
;
202 sal_Bool bReverse
= sal_False
;
203 parseCommandLine( argv
, &sConnectionString
, &sProtocol
, &bLatency
, &bReverse
);
205 Reference
< XMultiServiceFactory
> rSMgr
= createRegistryServiceFactory(
206 OUString( "client.rdb" ) );
208 // just ensure that it is registered
210 Reference
< XConnector
> rConnector(
211 createComponent( OUString("com.sun.star.connection.Connector"),
212 OUString( "connector.uno" SAL_DLLEXTENSION
),
216 createComponent( OUString("com.sun.star.bridge.Bridge.iiop"),
217 OUString( "remotebridge.uno" SAL_DLLEXTENSION
),
220 Reference
< XBridgeFactory
> rFactory(
221 createComponent( OUString("com.sun.star.bridge.BridgeFactory"),
222 OUString( "bridgefac.uno" SAL_DLLEXTENSION
),
228 if( rFactory
.is() && rConnector
.is() )
230 Reference
< XConnection
> rConnection
=
231 rConnector
->connect( sConnectionString
);
233 Reference
< XBridge
> rBridge
= rFactory
->createBridge(
234 OUString("bla blub"),
237 Reference
< XInstanceProvider
> () );
239 Reference
< XInterface
> rInitialObject
240 = rBridge
->getInstance( OUString("NamingService") );
242 if( rInitialObject
.is() )
244 printf( "got the remote object\n" );
245 doSomething( rInitialObject
);
247 TimeValue value
={2,0};
248 osl_waitThread( &value
);
252 printf( "Exception thrown\n" );
255 Reference
< XComponent
> rComp( rSMgr
, UNO_QUERY
);
262 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */