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>
This commit is contained in:
Stephan Bergmann
2021-05-25 15:21:06 +02:00
parent ecf48b2d4f
commit ef88aa5e74
3 changed files with 62 additions and 63 deletions

View File

@@ -37,6 +37,7 @@ $(eval $(call gb_Helper_register_executables,NONE, \
genindex_data \ genindex_data \
helpex \ helpex \
idxdict \ idxdict \
io-testconnection \
langsupport \ langsupport \
$(if $(filter iOS,$(OS)),LibreOffice) \ $(if $(filter iOS,$(OS)),LibreOffice) \
lngconvex \ lngconvex \

View File

@@ -17,4 +17,10 @@ $(eval $(call gb_Module_add_subsequentcheck_targets,io,\
CppunitTest_io_textinputstream \ 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: # vim:set noet sw=4 ts=4:

View File

@@ -23,24 +23,29 @@
#include <osl/diagnose.h> #include <osl/diagnose.h>
#include <osl/thread.hxx> #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/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/XConnector.hpp>
#include <com/sun/star/connection/XAcceptor.hpp> #include <com/sun/star/connection/XAcceptor.hpp>
#include <cppuhelper/bootstrap.hxx>
using namespace ::osl; using namespace ::osl;
using namespace ::cppu; using namespace ::cppu;
using namespace ::com::sun::star::uno; using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::io; using namespace ::com::sun::star::io;
using namespace ::com::sun::star::lang; using namespace ::com::sun::star::lang;
using namespace ::com::sun::star::registry;
using namespace ::com::sun::star::connection; using namespace ::com::sun::star::connection;
namespace {
class MyThread : class MyThread :
public Thread public Thread
{ {
@@ -95,7 +100,6 @@ void MyThread::run()
if( m_rConnection.is() ) if( m_rConnection.is() )
{ {
Sequence < sal_Int8 > seq(12);
try try
{ {
doWrite( m_rConnection ); doWrite( m_rConnection );
@@ -115,70 +119,58 @@ void testConnection( const OUString &sConnectionDescription ,
const Reference < XAcceptor > &rAcceptor, const Reference < XAcceptor > &rAcceptor,
const Reference < XConnector > &rConnector ) const Reference < XConnector > &rConnector )
{ {
MyThread thread( rAcceptor , sConnectionDescription );
thread.create();
bool bGotit = false;
Reference < XConnection > r;
while( ! bGotit )
{ {
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" );
}
}
r->close();
try try
{ {
Sequence < sal_Int8 > seq(10); // Why is this wait necessary ????
r->write( seq ); osl::Thread::wait(std::chrono::seconds(1));
OSL_FAIL( "expected exception not thrown" ); r = rConnector->connect( sConnectionDescription );
OSL_ASSERT( r.is() );
doWrite( r );
doRead( r );
bGotit = true;
} }
catch ( IOException & ) catch( ... )
{ {
// everything is ok printf( "Couldn't connect, retrying ...\n" );
}
catch ( ... )
{
OSL_FAIL( "wrong exception was thrown" );
}
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( Reference< XMultiServiceFactory > xMgr(
createRegistryServiceFactory( OUString( "applicat.rdb") ) ); defaultBootstrap_InitialComponentContext()->getServiceManager(), UNO_QUERY );
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 >() );
Reference < XAcceptor > rAcceptor( Reference < XAcceptor > rAcceptor(
xMgr->createInstance( "com.sun.star.connection.Acceptor" ) , UNO_QUERY ); xMgr->createInstance( "com.sun.star.connection.Acceptor" ) , UNO_QUERY );
@@ -192,12 +184,12 @@ int SAL_CALL main( int argc, char * argv[] )
printf( "Testing sockets" ); printf( "Testing sockets" );
fflush( stdout ); fflush( stdout );
testConnection( OUString("socket,host=localhost,port=2001"), rAcceptor , rConnector ); testConnection( "socket,host=localhost,port=2001", rAcceptor , rConnector );
printf( " Done\n" ); printf( " Done\n" );
printf( "Testing pipe" ); printf( "Testing pipe" );
fflush( stdout ); fflush( stdout );
testConnection( OUString("pipe,name=bla") , rAcceptorPipe , rConnector ); testConnection( "pipe,name=bla" , rAcceptorPipe , rConnector );
printf( " Done\n" ); printf( " Done\n" );
// check, if erroneous strings make any problem // 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(); thread.create();
osl::Thread::wait(std::chrono::nanoseconds(1)); osl::Thread::wait(std::chrono::seconds(1));
try try
{ {
rAcceptor->accept( OUString("socket,host=localhost,port=2001") ); rAcceptor->accept( "socket,host=localhost,port=2001" );
OSL_FAIL( "already existing exception expected" ); OSL_FAIL( "already existing exception expected" );
} }
catch( AlreadyAcceptingException & ) catch( AlreadyAcceptingException & )