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:
parent
ecf48b2d4f
commit
ef88aa5e74
3 changed files with 62 additions and 63 deletions
|
@ -37,6 +37,7 @@ $(eval $(call gb_Helper_register_executables,NONE, \
|
|||
genindex_data \
|
||||
helpex \
|
||||
idxdict \
|
||||
io-testconnection \
|
||||
langsupport \
|
||||
$(if $(filter iOS,$(OS)),LibreOffice) \
|
||||
lngconvex \
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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 );
|
||||
|
@ -114,12 +118,11 @@ void MyThread::run()
|
|||
void testConnection( const OUString &sConnectionDescription ,
|
||||
const Reference < XAcceptor > &rAcceptor,
|
||||
const Reference < XConnector > &rConnector )
|
||||
{
|
||||
{
|
||||
MyThread thread( rAcceptor , sConnectionDescription );
|
||||
thread.create();
|
||||
|
||||
sal_Bool bGotit = sal_False;
|
||||
bool bGotit = false;
|
||||
Reference < XConnection > r;
|
||||
|
||||
while( ! bGotit )
|
||||
|
@ -132,7 +135,7 @@ void testConnection( const OUString &sConnectionDescription ,
|
|||
OSL_ASSERT( r.is() );
|
||||
doWrite( r );
|
||||
doRead( r );
|
||||
bGotit = sal_True;
|
||||
bGotit = true;
|
||||
}
|
||||
catch( ... )
|
||||
{
|
||||
|
@ -160,25 +163,14 @@ void testConnection( const OUString &sConnectionDescription ,
|
|||
|
||||
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 & )
|
||||
|
|
Loading…
Reference in a new issue