diff options
-rw-r--r-- | Repository.mk | 1 | ||||
-rw-r--r-- | io/Module_io.mk | 6 | ||||
-rw-r--r-- | io/test/testconnection.cxx | 114 |
3 files changed, 60 insertions, 61 deletions
diff --git a/Repository.mk b/Repository.mk index e95ea304ffda..218a4417f96e 100644 --- a/Repository.mk +++ b/Repository.mk @@ -37,6 +37,7 @@ $(eval $(call gb_Helper_register_executables,NONE, \ genindex_data \ helpex \ idxdict \ + io-testconnection \ langsupport \ $(if $(filter iOS,$(OS)),LibreOffice) \ lngconvex \ diff --git a/io/Module_io.mk b/io/Module_io.mk index c9751d9bea04..c4a75e74e7ec 100644 --- a/io/Module_io.mk +++ b/io/Module_io.mk @@ -17,4 +17,10 @@ $(eval $(call gb_Module_add_subsequentcheck_targets,io,\ CppunitTest_io_textinputstream \ )) +ifneq (,$(filter Executable_io-testconnection,$(MAKECMDGOALS))) +$(eval $(call gb_Module_add_targets,io, \ + Executable_io-testconnection \ +)) +endif + # vim:set noet sw=4 ts=4: diff --git a/io/test/testconnection.cxx b/io/test/testconnection.cxx index 35bc697c9a76..4131bcf74dd3 100644 --- a/io/test/testconnection.cxx +++ b/io/test/testconnection.cxx @@ -23,24 +23,29 @@ #include <osl/diagnose.h> #include <osl/thread.hxx> -#include <cppuhelper/servicefactory.hxx> - +#include <com/sun/star/io/IOException.hpp> +#include <com/sun/star/lang/IllegalArgumentException.hpp> #include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <com/sun/star/uno/XComponentContext.hpp> -#include <com/sun/star/registry/XImplementationRegistration.hpp> - +#include <com/sun/star/connection/AlreadyAcceptingException.hpp> +#include <com/sun/star/connection/ConnectionSetupException.hpp> #include <com/sun/star/connection/XConnector.hpp> #include <com/sun/star/connection/XAcceptor.hpp> +#include <cppuhelper/bootstrap.hxx> + using namespace ::osl; using namespace ::cppu; using namespace ::com::sun::star::uno; using namespace ::com::sun::star::io; using namespace ::com::sun::star::lang; -using namespace ::com::sun::star::registry; using namespace ::com::sun::star::connection; +namespace { + class MyThread : public Thread { @@ -95,7 +100,6 @@ void MyThread::run() if( m_rConnection.is() ) { - Sequence < sal_Int8 > seq(12); try { doWrite( m_rConnection ); @@ -115,70 +119,58 @@ void testConnection( const OUString &sConnectionDescription , const Reference < XAcceptor > &rAcceptor, const Reference < XConnector > &rConnector ) { - { - MyThread thread( rAcceptor , sConnectionDescription ); - thread.create(); - - sal_Bool bGotit = sal_False; - Reference < XConnection > r; - - while( ! bGotit ) - { - try - { - // Why is this wait necessary ???? - osl::Thread::wait(std::chrono::seconds(1)); - r = rConnector->connect( sConnectionDescription ); - OSL_ASSERT( r.is() ); - doWrite( r ); - doRead( r ); - bGotit = sal_True; - } - catch( ... ) - { - printf( "Couldn't connect, retrying ...\n" ); - - } - } + MyThread thread( rAcceptor , sConnectionDescription ); + thread.create(); - r->close(); + bool bGotit = false; + Reference < XConnection > r; + while( ! bGotit ) + { try { - Sequence < sal_Int8 > seq(10); - r->write( seq ); - OSL_FAIL( "expected exception not thrown" ); + // Why is this wait necessary ???? + osl::Thread::wait(std::chrono::seconds(1)); + r = rConnector->connect( sConnectionDescription ); + OSL_ASSERT( r.is() ); + doWrite( r ); + doRead( r ); + bGotit = true; } - catch ( IOException & ) + catch( ... ) { - // everything is ok - } - catch ( ... ) - { - OSL_FAIL( "wrong exception was thrown" ); + printf( "Couldn't connect, retrying ...\n" ); + } + } - thread.join(); + r->close(); + + try + { + Sequence < sal_Int8 > seq(10); + r->write( seq ); + OSL_FAIL( "expected exception not thrown" ); + } + catch ( IOException & ) + { + // everything is ok + } + catch ( ... ) + { + OSL_FAIL( "wrong exception was thrown" ); } + + thread.join(); +} + } -int SAL_CALL main( int argc, char * argv[] ) +int main() { Reference< XMultiServiceFactory > xMgr( - createRegistryServiceFactory( OUString( "applicat.rdb") ) ); - - Reference< XImplementationRegistration > xImplReg( - xMgr->createInstance("com.sun.star.registry.ImplementationRegistration"), UNO_QUERY ); - OSL_ENSURE( xImplReg.is(), "### no impl reg!" ); - - OUString aLibName = "connector.uno" SAL_DLLEXTENSION; - xImplReg->registerImplementation( - OUString("com.sun.star.loader.SharedLibrary"), aLibName, Reference< XSimpleRegistry >() ); - - aLibName = "acceptor.uno" SAL_DLLEXTENSION; - xImplReg->registerImplementation( - OUString("com.sun.star.loader.SharedLibrary"), aLibName, Reference< XSimpleRegistry >() ); + defaultBootstrap_InitialComponentContext()->getServiceManager(), UNO_QUERY ); Reference < XAcceptor > rAcceptor( xMgr->createInstance( "com.sun.star.connection.Acceptor" ) , UNO_QUERY ); @@ -192,12 +184,12 @@ int SAL_CALL main( int argc, char * argv[] ) printf( "Testing sockets" ); fflush( stdout ); - testConnection( OUString("socket,host=localhost,port=2001"), rAcceptor , rConnector ); + testConnection( "socket,host=localhost,port=2001", rAcceptor , rConnector ); printf( " Done\n" ); printf( "Testing pipe" ); fflush( stdout ); - testConnection( OUString("pipe,name=bla") , rAcceptorPipe , rConnector ); + testConnection( "pipe,name=bla" , rAcceptorPipe , rConnector ); printf( " Done\n" ); // check, if erroneous strings make any problem @@ -234,13 +226,13 @@ int SAL_CALL main( int argc, char * argv[] ) } - MyThread thread( rAcceptor , OUString("socket,host=localhost,port=2001") ); + MyThread thread( rAcceptor , "socket,host=localhost,port=2001" ); thread.create(); - osl::Thread::wait(std::chrono::nanoseconds(1)); + osl::Thread::wait(std::chrono::seconds(1)); try { - rAcceptor->accept( OUString("socket,host=localhost,port=2001") ); + rAcceptor->accept( "socket,host=localhost,port=2001" ); OSL_FAIL( "already existing exception expected" ); } catch( AlreadyAcceptingException & ) |