diff options
author | Stephan Bergmann <sbergman@redhat.com> | 2021-05-25 15:21:06 +0200 |
---|---|---|
committer | Stephan Bergmann <sbergman@redhat.com> | 2021-05-25 16:13:08 +0200 |
commit | ef88aa5e7400769c0a17c28e66b1ee957c2f667e (patch) | |
tree | 5c29a7c3a609c0152da21e7378c27778dca5e9a0 /io | |
parent | ecf48b2d4f3e54dbb2c1e295120d73e7b7a11338 (diff) |
Resurrect io testconnection executable
...which appears to be the only code that exercises osl's socket (rather than
named pipe) connections, so lets have that available at least for manual
execution.
Addresses various compiler and loplugin warnings, and extends a wait time to
more reliably have the MyThread instance already accept when the second accept
(on the main thread) is done.
Change-Id: I761d747b08ab45f1ac03dad8b4197fae63228e16
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/116103
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
Diffstat (limited to 'io')
-rw-r--r-- | io/Module_io.mk | 6 | ||||
-rw-r--r-- | io/test/testconnection.cxx | 114 |
2 files changed, 59 insertions, 61 deletions
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 & ) |