diff options
-rw-r--r-- | io/test/stm/datatest.cxx | 32 | ||||
-rw-r--r-- | io/test/stm/pipetest.cxx | 25 | ||||
-rw-r--r-- | io/test/stm/pumptest.cxx | 204 |
3 files changed, 247 insertions, 14 deletions
diff --git a/io/test/stm/datatest.cxx b/io/test/stm/datatest.cxx index 0a2063b1ec45..72875d5a1349 100644 --- a/io/test/stm/datatest.cxx +++ b/io/test/stm/datatest.cxx @@ -2,9 +2,9 @@ * * $RCSfile: datatest.cxx,v $ * - * $Revision: 1.5 $ + * $Revision: 1.6 $ * - * last change: $Author: jbu $ $Date: 2001-03-15 17:58:02 $ + * last change: $Author: jbu $ $Date: 2002-09-18 12:15:51 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -349,7 +349,8 @@ void ODataStreamTest::testSimple( const Reference < XDataInputStream > &rInput ERROR_ASSERT( 0 , "wrong exception after reading beyond eof" ); } - ERROR_ASSERT( ! rInput->readBytes( Sequence<sal_Int8> (1) , 1 ), + Sequence<sal_Int8> dummy (1); + ERROR_ASSERT( ! rInput->readBytes( dummy , 1 ), "stream must be on eof !" ); rInput->closeInput(); @@ -425,7 +426,14 @@ OUString ODataStreamTest_getImplementationName( int i) throw () class MyPersistObject : public WeakImplHelper2< XPersistObject , XPropertySet > { public: - MyPersistObject( ) : m_sServiceName( OMyPersistObject_getServiceName() ) + MyPersistObject( ) : m_sServiceName( OMyPersistObject_getServiceName() ) , + m_l( -392 ), + m_f( 7883.2 ), + m_d( -123923.5 ), + m_b( sal_True ), + m_byte( 42 ), + m_c( 429 ), + m_s( OUString( RTL_CONSTASCII_USTRINGPARAM( "foo" ) ) ) {} MyPersistObject( const OUString & sServiceName ) : m_sServiceName( sServiceName ) {} @@ -860,17 +868,27 @@ sal_Bool compareMyPropertySet( Reference< XPropertySet > &r1 , Reference < XProp r2->getPropertyValue( OUString::createFromAscii("long") ).getValueType() == getCppuVoidType() ) { // one of the objects is not the correct propertyset ! + fprintf( stderr, "compareMyPropertySet: 1\n" ); return sal_False; } b = b && ( r1->getPropertyValue( OUString(RTL_CONSTASCII_USTRINGPARAM("long")) ) == r2->getPropertyValue( OUString(RTL_CONSTASCII_USTRINGPARAM("long")) ) ); + if( ! b ) fprintf( stderr, "compareMyPropertySet: 2\n" ); b = b && ( r1->getPropertyValue( OUString(RTL_CONSTASCII_USTRINGPARAM("float")) ) == r2->getPropertyValue( OUString(RTL_CONSTASCII_USTRINGPARAM("float")) ) ); + if( ! b ){ + float f1; + float f2; + r1->getPropertyValue( OUString(RTL_CONSTASCII_USTRINGPARAM("float")) ) >>= f1; + r2->getPropertyValue( OUString(RTL_CONSTASCII_USTRINGPARAM("float")) ) >>= f2; + fprintf( stderr, "compareMyPropertySet: %f %f 3\n",f1,f2 ); + } b = b && ( r1->getPropertyValue( OUString(RTL_CONSTASCII_USTRINGPARAM("double")) ) == r2->getPropertyValue( OUString(RTL_CONSTASCII_USTRINGPARAM("double" ))) ); + if( ! b ) fprintf( stderr, "compareMyPropertySet: 4\n" ); sal_Bool b1 ,b2; Any a =r1->getPropertyValue( OUString(RTL_CONSTASCII_USTRINGPARAM("bool")) ); @@ -878,18 +896,22 @@ sal_Bool compareMyPropertySet( Reference< XPropertySet > &r1 , Reference < XProp a = r2->getPropertyValue( OUString(RTL_CONSTASCII_USTRINGPARAM("bool")) ); a >>= b2; b = b && ( (b1 && b2) || b1 == b2 ); + if( ! b ) fprintf( stderr, "compareMyPropertySet: 5\n" ); // b = b && r1->getPropertyValue( OUString(RTL_CONSTASCII_USTRINGPARAM("bool")) ) == // r2->getPropertyValue( OUString(RTL_CONSTASCII_USTRINGPARAM("bool")) ) ); b = b && ( r1->getPropertyValue( OUString(RTL_CONSTASCII_USTRINGPARAM("byte")) ) == r2->getPropertyValue( OUString(RTL_CONSTASCII_USTRINGPARAM("byte")) ) ); + if( ! b ) fprintf( stderr, "compareMyPropertySet: 6\n" ); b = b && ( r1->getPropertyValue( OUString(RTL_CONSTASCII_USTRINGPARAM("char")) ) == r2->getPropertyValue( OUString(RTL_CONSTASCII_USTRINGPARAM("char")) ) ); + if( ! b ) fprintf( stderr, "compareMyPropertySet: 7\n" ); b = b && ( r1->getPropertyValue( OUString(RTL_CONSTASCII_USTRINGPARAM("string")) ) == r2->getPropertyValue( OUString(RTL_CONSTASCII_USTRINGPARAM("string")) )); + if( ! b ) fprintf( stderr, "compareMyPropertySet: 8\n" ); Any o1 = r1->getPropertyValue( OUString(RTL_CONSTASCII_USTRINGPARAM("object")) ); Any o2 = r2->getPropertyValue( OUString(RTL_CONSTASCII_USTRINGPARAM("object")) ); @@ -912,11 +934,13 @@ sal_Bool compareMyPropertySet( Reference< XPropertySet > &r1 , Reference < XProp else { b = sal_False; } + if( ! b ) fprintf( stderr, "compareMyPropertySet: 9\n" ); } else { if( o2.getValueType() == getCppuType( (Reference<XPersistObject>*)0 ) ) { b = sal_False; } + if( ! b ) fprintf( stderr, "compareMyPropertySet: 10\n" ); } return b; diff --git a/io/test/stm/pipetest.cxx b/io/test/stm/pipetest.cxx index e11aa3fe081c..c8017867d641 100644 --- a/io/test/stm/pipetest.cxx +++ b/io/test/stm/pipetest.cxx @@ -2,9 +2,9 @@ * * $RCSfile: pipetest.cxx,v $ * - * $Revision: 1.2 $ + * $Revision: 1.3 $ * - * last change: $Author: jbu $ $Date: 2001-03-15 17:58:02 $ + * last change: $Author: jbu $ $Date: 2002-09-18 12:15:51 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -344,6 +344,24 @@ void OPipeTest::testSimple( const Reference < XInterface > &r ) catch( IOException & ) { } + try + { + input->available( ); + ERROR_ASSERT( 0 , "calling available from a closed stream should thrown an io exception" ); + } + catch( IOException & ) + { + + } + try + { + input->skipBytes(42 ); + ERROR_ASSERT( 0 , "calling available from a closed stream should thrown an io exception" ); + } + catch( IOException & ) + { + + } } void OPipeTest::testBufferResizing( const Reference < XInterface > &r ) @@ -361,7 +379,8 @@ void OPipeTest::testBufferResizing( const Reference < XInterface > &r ) // this is just to better check the // internal buffers output->writeBytes( Sequence<sal_Int8>(100) ); - input->readBytes( Sequence<sal_Int8>() , 100); + Sequence< sal_Int8 > dummy; + input->readBytes( dummy , 100); for( int i = 0 ; i < iMax ; i ++ ) { output->writeBytes( createIntSeq( i ) ); diff --git a/io/test/stm/pumptest.cxx b/io/test/stm/pumptest.cxx index 78dbc14eea38..63cb14baac7a 100644 --- a/io/test/stm/pumptest.cxx +++ b/io/test/stm/pumptest.cxx @@ -2,9 +2,9 @@ * * $RCSfile: pumptest.cxx,v $ * - * $Revision: 1.5 $ + * $Revision: 1.6 $ * - * last change: $Author: jbu $ $Date: 2001-03-20 09:12:18 $ + * last change: $Author: jbu $ $Date: 2002-09-18 12:15:51 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -97,6 +97,14 @@ using namespace ::com::sun::star::test; #include "testfactreg.hxx" +static void mywait() +{ + TimeValue a = { 0, 10000 }; + osl_waitThread( &a ); + osl_yieldThread(); + osl_yieldThread(); +} + class OPumpTest : public WeakImplHelper1 < XSimpleTest > { public: @@ -125,7 +133,9 @@ public: private: void testSimple( const Reference < XInterface > & ); void testWrongUsage( const Reference < XInterface > & ); - + void testClose( const Reference< XInterface >& ); + void testTerminate( const Reference< XInterface >& ); + void testFunction( const Reference< XInterface >& ); private: Sequence<Any> m_seqExceptions; Sequence<OUString> m_seqErrors; @@ -186,6 +196,18 @@ sal_Int32 OPumpTest::test( { testWrongUsage( TestObject); } + else if ( 2 == hTestHandle ) + { + testClose( TestObject); + } + else if ( 3 == hTestHandle ) + { + testTerminate( TestObject ); + } + else if ( 4 == hTestHandle ) + { + testFunction( TestObject ); + } } catch( Exception & e ) { @@ -199,7 +221,7 @@ sal_Int32 OPumpTest::test( hTestHandle ++; - if( 2 == hTestHandle ) + if( 5 == hTestHandle ) { // all tests finished. hTestHandle = -1; @@ -249,6 +271,176 @@ void OPumpTest::testSimple( const Reference < XInterface > &r ) } +class TestListener: public WeakImplHelper1< XStreamListener > +{ +public: + sal_Bool m_bStarted; + sal_Bool m_bClosed; + sal_Bool m_bTerminated; + sal_Bool m_bError; + sal_Bool m_bDisposed; + TestListener() : m_bStarted (sal_False), + m_bClosed (sal_False), + m_bTerminated ( sal_False ), + m_bError( sal_False ), + m_bDisposed( sal_False ) + {} + + virtual void SAL_CALL disposing( const EventObject &obj ) throw (::com::sun::star::uno::RuntimeException) + { + m_bDisposed = sal_True; +// printf( "disposing called\n"); + } + + virtual void SAL_CALL started( ) throw (::com::sun::star::uno::RuntimeException) + { + m_bStarted = sal_True; +// printf( "started called\n"); + } + virtual void SAL_CALL closed( ) throw (::com::sun::star::uno::RuntimeException) + { + m_bClosed = sal_True; +// printf( "closed called\n"); + } + virtual void SAL_CALL terminated( ) throw (::com::sun::star::uno::RuntimeException) + { + m_bTerminated = sal_True; +// printf( "terminated called\n"); + } + virtual void SAL_CALL error( const ::com::sun::star::uno::Any& aException ) + throw (::com::sun::star::uno::RuntimeException) + { + m_bError = sal_True; + Exception e; + aException >>= e; +// printf( "error called %s\n", OUStringToOString( e.Message, RTL_TEXTENCODING_ASCII_US).getStr() ); + } +}; + +class TestCase +{ +public: + TestCase( const Reference< XMultiServiceFactory > & rSMgr, + const Reference< XInterface > &r ) : m_rSmgr( rSMgr ), m_pTestListener( 0 ) + { + m_rControl = Reference<XActiveDataControl>( r, UNO_QUERY ); + + Reference< XActiveDataSource > rSource ( r, UNO_QUERY ); + Reference< XActiveDataSink > rSink( r , UNO_QUERY ); + + m_rOutSource = Reference< XOutputStream > ( createPipe() ); + rSink->setInputStream(Reference< XInputStream> (m_rOutSource,UNO_QUERY)); + + Reference< XOutputStream > rOutSink( createPipe() ); + m_rInSink = Reference< XInputStream > ( rOutSink, UNO_QUERY ); + rSource->setOutputStream( rOutSink ); + + m_pTestListener = new TestListener(); + m_pTestListener->acquire(); + m_rControl->addListener( m_pTestListener ); + } + + ~TestCase() + { + if( m_pTestListener ) + m_pTestListener->release(); + } + + TestListener *m_pTestListener; + Reference< XActiveDataControl > m_rControl; + Reference< XOutputStream > m_rOutSource; + Reference< XInputStream > m_rInSink; + Reference< XMultiServiceFactory > m_rSmgr; + +private: + Reference< XOutputStream > createPipe() + { + Reference< XOutputStream > rOut( m_rSmgr->createInstance( + OUString::createFromAscii( "com.sun.star.io.Pipe" )),UNO_QUERY); + return rOut; + } +}; + + + +void OPumpTest::testClose( const Reference< XInterface > &r ) +{ + TestCase t( m_rSmgr, r ); + + ERROR_ASSERT( ! t.m_pTestListener->m_bStarted , "started too early" ); + ERROR_ASSERT( ! t.m_pTestListener->m_bTerminated , "terminiation unexpected" ); + ERROR_ASSERT( ! t.m_pTestListener->m_bError, "unexpected error" ); + ERROR_ASSERT( ! t.m_pTestListener->m_bClosed, "unexpected clase" ); + + t.m_rControl->start(); + mywait(); + + ERROR_ASSERT( t.m_pTestListener->m_bStarted , "should have been started already" ); + ERROR_ASSERT( ! t.m_pTestListener->m_bTerminated , "terminiation unexpected" ); + ERROR_ASSERT( ! t.m_pTestListener->m_bError, "unexpected error" ); + ERROR_ASSERT( ! t.m_pTestListener->m_bClosed, "unexpected clase" ); + + Reference< XStreamListener > rListener( new TestListener() ); + t.m_rControl->addListener( rListener ); + t.m_rControl->removeListener( rListener ); + + t.m_rOutSource->closeOutput(); + mywait(); + ERROR_ASSERT( t.m_pTestListener->m_bStarted , "should have been started already" ); + ERROR_ASSERT( ! t.m_pTestListener->m_bTerminated , "should be terminiated already" ); + ERROR_ASSERT( ! t.m_pTestListener->m_bError, "unexpected error" ); + ERROR_ASSERT( t.m_pTestListener->m_bClosed, "should be closed already" ); +} + +void OPumpTest::testTerminate( const Reference< XInterface > &r ) +{ + TestCase t( m_rSmgr, r ); + + ERROR_ASSERT( ! t.m_pTestListener->m_bStarted , "started too early" ); + ERROR_ASSERT( ! t.m_pTestListener->m_bTerminated , "terminiation unexpected" ); + ERROR_ASSERT( ! t.m_pTestListener->m_bError, "unexpected error" ); + ERROR_ASSERT( ! t.m_pTestListener->m_bClosed, "unexpected clase" ); + + t.m_rControl->start(); + mywait(); + + ERROR_ASSERT( t.m_pTestListener->m_bStarted , "should have been started already" ); + ERROR_ASSERT( ! t.m_pTestListener->m_bTerminated , "terminiation unexpected" ); + ERROR_ASSERT( ! t.m_pTestListener->m_bError, "unexpected error" ); + ERROR_ASSERT( ! t.m_pTestListener->m_bClosed, "unexpected clase" ); + + t.m_rControl->terminate(); + + mywait(); + ERROR_ASSERT( t.m_pTestListener->m_bStarted , "should have been started already" ); + ERROR_ASSERT( t.m_pTestListener->m_bTerminated , "should be terminiated already" ); + // terminte leads to an error, that is no surprise, in fact + // one can't tell wether the error occurs because of the terminate + // call or for some other reason ! +// ERROR_ASSERT( ! t.m_pTestListener->m_bError, "unexpected error" ); + ERROR_ASSERT( t.m_pTestListener->m_bClosed, "should be closed already" ); +} + +void OPumpTest::testFunction( const Reference< XInterface > &r ) +{ + TestCase t( m_rSmgr, r ); + + t.m_rControl->start(); + + t.m_rOutSource->writeBytes( Sequence< sal_Int8 > ( 5 ) ); + + Sequence< sal_Int8 > dummy; + ERROR_ASSERT( 5 == t.m_rInSink->readBytes( dummy , 5 ), "couldn't read the expected number of bytes" ); + + t.m_rOutSource->closeOutput(); + mywait(); + + ERROR_ASSERT( t.m_pTestListener->m_bStarted , "should have been started already" ); + ERROR_ASSERT( ! t.m_pTestListener->m_bTerminated , "should be terminiated already" ); + ERROR_ASSERT( ! t.m_pTestListener->m_bError, "unexpected error" ); + ERROR_ASSERT( t.m_pTestListener->m_bClosed, "should be closed already" ); +} + void OPumpTest::testWrongUsage( const Reference< XInterface > &r ) { Reference< XActiveDataSource > rSource ( r, UNO_QUERY ); @@ -265,9 +457,7 @@ void OPumpTest::testWrongUsage( const Reference< XInterface > &r ) rControl->start(); - //wait a second, so that the pumpthread can terminate - TimeValue w = {1,1}; - osl_waitThread( &w ); + mywait(); } Reference< XInterface > SAL_CALL OPumpTest_CreateInstance( const Reference< XMultiServiceFactory > & rSMgr ) throw( Exception ) |