diff options
Diffstat (limited to 'extensions/test/stm')
-rw-r--r-- | extensions/test/stm/datatest.cxx | 1108 | ||||
-rw-r--r-- | extensions/test/stm/exports.dxp | 2 | ||||
-rw-r--r-- | extensions/test/stm/makefile.mk | 99 | ||||
-rw-r--r-- | extensions/test/stm/marktest.cxx | 718 | ||||
-rw-r--r-- | extensions/test/stm/pipetest.cxx | 483 | ||||
-rw-r--r-- | extensions/test/stm/testfactreg.cxx | 203 | ||||
-rw-r--r-- | extensions/test/stm/testfactreg.hxx | 144 |
7 files changed, 2757 insertions, 0 deletions
diff --git a/extensions/test/stm/datatest.cxx b/extensions/test/stm/datatest.cxx new file mode 100644 index 000000000000..e3d268fba74b --- /dev/null +++ b/extensions/test/stm/datatest.cxx @@ -0,0 +1,1108 @@ +/************************************************************************* + * + * $RCSfile: datatest.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 16:16:56 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ +#include <smart/com/sun/star/test/XSimpleTest.hxx> +#include <smart/com/sun/star/io/XObjectOutputStream.hxx> +#include <smart/com/sun/star/io/XObjectInputStream.hxx> +#include <smart/com/sun/star/io/XActiveDataSink.hxx> +#include <smart/com/sun/star/io/XActiveDataSource.hxx> +#include <smart/com/sun/star/io/XConnectable.hxx> +#include <smart/com/sun/star/io/XMarkableStream.hxx> + +#include <smart/com/sun/star/lang/XServiceInfo.hxx> + +#include <smart/com/sun/star/beans/XPropertySet.hxx> + +#include <usr/services.hxx> +#include <usr/factoryhlp.hxx> + +#include <usr/reflserv.hxx> // for EXTERN_SERVICE_CALLTYPE +#include <usr/weak.hxx> // OWeakObject + +#include <vos/conditn.hxx> +#include <vos/mutex.hxx> +#include <vos/thread.hxx> + +#include <assert.h> +#include <string.h> + +#include "testfactreg.hxx" + +#ifndef _VOS_NO_NAMESPACE +using namespace vos; +using namespace usr; +#endif + +#define DATASTREAM_TEST_MAX_HANDLE 1 + +/**** +* The following test class tests XDataInputStream and XDataOutputStream at equal terms, +* so when errors occur, it may be in either one implementation. +* The class also uses stardiv.uno.io.pipe. If problems occur, make sure to run also the +* pipe test routines ( test.com.sun.star.io.pipe ). +* +* +*****/ + +class ODataStreamTest : + public XSimpleTest, + public OWeakObject +{ +public: + ODataStreamTest( const XMultiServiceFactoryRef & rFactory ) : m_rFactory( rFactory ){} + +public: // refcounting + BOOL queryInterface( Uik aUik, XInterfaceRef & rOut ); + void acquire() { OWeakObject::acquire(); } + void release() { OWeakObject::release(); } + void* getImplementation(Reflection *p) { return OWeakObject::getImplementation(p); } + +public: + virtual void testInvariant(const UString& TestName, const XInterfaceRef& TestObject) + THROWS( ( IllegalArgumentException, + UsrSystemException) ); + + virtual INT32 test( const UString& TestName, + const XInterfaceRef& TestObject, + INT32 hTestHandle) THROWS( ( IllegalArgumentException, + UsrSystemException) ); + + virtual BOOL testPassed(void) THROWS( ( UsrSystemException) ); + virtual Sequence< UString > getErrors(void) THROWS( (UsrSystemException) ); + virtual Sequence< UsrAny > getErrorExceptions(void) THROWS( (UsrSystemException) ); + virtual Sequence< UString > getWarnings(void) THROWS( (UsrSystemException) ); + +private: + void testSimple( const XDataInputStreamRef & , const XDataOutputStreamRef &); + +protected: + Sequence<UsrAny> m_seqExceptions; + Sequence<UString> m_seqErrors; + Sequence<UString> m_seqWarnings; + + XMultiServiceFactoryRef m_rFactory; +}; + + +BOOL ODataStreamTest::queryInterface( Uik uik , XInterfaceRef &rOut ) +{ + if( XSimpleTest::getSmartUik() == uik ) { + rOut = (XSimpleTest *) this; + } + else { + return OWeakObject::queryInterface( uik , rOut ); + } + return TRUE; +} + + +void ODataStreamTest::testInvariant( const UString& TestName, const XInterfaceRef& TestObject ) + THROWS( ( IllegalArgumentException, + UsrSystemException) ) +{ + if( L"com.sun.star.io.DataInputStream" == TestName ) { + XConnectableRef connect( TestObject , USR_QUERY ); + XActiveDataSinkRef active( TestObject , USR_QUERY ); + XInputStreamRef input( TestObject , USR_QUERY ); + XDataInputStreamRef dataInput( TestObject , USR_QUERY ); + + WARNING_ASSERT( connect.is(), "XConnectable cannot be queried" ); + WARNING_ASSERT( active.is() , "XActiveDataSink cannot be queried" ); + ERROR_ASSERT( input.is() , "XInputStream cannot be queried" ); + ERROR_ASSERT( dataInput.is() , "XDataInputStream cannot be queried" ); + + + } + else if( L"com.sun.star.io.DataInputStream" == TestName ) { + XConnectableRef connect( TestObject , USR_QUERY ); + XActiveDataSourceRef active( TestObject , USR_QUERY ); + XOutputStreamRef output( TestObject , USR_QUERY ); + XDataOutputStreamRef dataOutput( TestObject , USR_QUERY ); + + WARNING_ASSERT( connect.is(), "XConnectable cannot be queried" ); + WARNING_ASSERT( active.is() , "XActiveDataSink cannot be queried" ); + ERROR_ASSERT( output.is() , "XInputStream cannot be queried" ); + ERROR_ASSERT( dataOutput.is(), "XDataInputStream cannot be queried" ); + + } + + XServiceInfoRef info( TestObject, USR_QUERY ); + ERROR_ASSERT( info.is() , "XServiceInfo not supported !" ); + if( info.is() ) + { + ERROR_ASSERT( info->supportsService( TestName ), "XServiceInfo test failed" ); + ERROR_ASSERT( ! info->supportsService( L"bla bluzb" ) , "XServiceInfo test failed" ); + } + +} + + +INT32 ODataStreamTest::test( const UString& TestName, + const XInterfaceRef& TestObject, + INT32 hTestHandle) THROWS( ( IllegalArgumentException, + UsrSystemException) ) +{ + if( L"com.sun.star.io.DataInputStream" == TestName || + L"com.sun.star.io.DataOutputStream" == TestName ) { + + TRY { + if( 0 == hTestHandle ) { + testInvariant( TestName , TestObject ); + } + else { + XActiveDataSinkRef rSink( TestObject, USR_QUERY ); + XActiveDataSourceRef rSource( TestObject , USR_QUERY ); + + XDataInputStreamRef rInput( TestObject , USR_QUERY ); + XDataOutputStreamRef rOutput( TestObject , USR_QUERY ); + + + XInterfaceRef x = m_rFactory->createInstance( L"com.sun.star.io.Pipe"); + + XInputStreamRef rPipeInput( x , USR_QUERY ); + XOutputStreamRef rPipeOutput( x , USR_QUERY ); + + if( ! rSink.is() ) { + x = m_rFactory->createInstance( L"com.sun.star.io.DataInputStream" ); + x->queryInterface( XDataInputStream::getSmartUik() , rInput ); + x->queryInterface( XActiveDataSink::getSmartUik() , rSink ); + } + else if ( !rSource.is() ) { + + x = m_rFactory->createInstance( L"com.sun.star.io.DataOutputStream" ); + x->queryInterface( XDataOutputStream::getSmartUik() , rOutput ); + x->queryInterface( XActiveDataSource::getSmartUik() , rSource ); + } + + assert( rPipeInput.is() ); + assert( rPipeOutput.is() ); + rSink->setInputStream( rPipeInput ); + rSource->setOutputStream( rPipeOutput ); + + assert( rSink->getInputStream().is() ); + assert( rSource->getOutputStream().is() ); + + if( 1 == hTestHandle ) { + testSimple( rInput , rOutput ); + } + } + } + CATCH( Exception , e ) { + BUILD_ERROR( 0 , UStringToString( e.getName() , CHARSET_SYSTEM ).GetCharStr() ); + } + AND_CATCH_ALL() { + BUILD_ERROR( 0 , "unknown exception (Exception is not base class)" ); + } + END_CATCH; + + hTestHandle ++; + + if( hTestHandle >= 2) { + // all tests finished. + hTestHandle = -1; + } + } + else { + BUILD_ERROR( 0 , "service not supported by test." ); + } + return hTestHandle; +} + + + +BOOL ODataStreamTest::testPassed(void) THROWS( (UsrSystemException) ) +{ + return m_seqErrors.getLen() == 0; +} + + +Sequence< UString > ODataStreamTest::getErrors(void) THROWS( (UsrSystemException) ) +{ + return m_seqErrors; +} + + +Sequence< UsrAny > ODataStreamTest::getErrorExceptions(void) THROWS( (UsrSystemException) ) +{ + return m_seqExceptions; +} + + +Sequence< UString > ODataStreamTest::getWarnings(void) THROWS( (UsrSystemException) ) +{ + return m_seqWarnings; +} + +void ODataStreamTest::testSimple( const XDataInputStreamRef &rInput, + const XDataOutputStreamRef &rOutput ) +{ + rOutput->writeLong( 0x34ff3c ); + rOutput->writeLong( 0x34ff3d ); + + ERROR_ASSERT( 0x34ff3c == rInput->readLong() , "long read/write mismatch" ); + ERROR_ASSERT( 0x34ff3d == rInput->readLong() , "long read/write mismatch" ); + + rOutput->writeByte( 0x87 ); + ERROR_ASSERT( 0x87 == rInput->readByte() , "byte read/write mismatch" ); + + rOutput->writeBoolean( 25 ); + ERROR_ASSERT( rInput->readBoolean() , "boolean read/write mismatch" ); + + rOutput->writeBoolean( FALSE ); + ERROR_ASSERT( ! rInput->readBoolean() , "boolean read/write mismatch" ); + + rOutput->writeFloat( (float) 42.42 ); + ERROR_ASSERT( rInput->readFloat() == ((float)42.42) , "float read/write mismatch" ); + + rOutput->writeDouble( (double) 42.42 ); + ERROR_ASSERT( rInput->readDouble() == 42.42 , "double read/write mismatch" ); + + rOutput->writeUTF( L"Live long and prosper !" ); + ERROR_ASSERT( rInput->readUTF() == L"Live long and prosper !" , + "UTF read/write mismatch" ); + + Sequence<wchar_t> wc(0x10001); + for( int i = 0 ; i < 0x10000 ; i ++ ) { + wc.getArray()[i] = L'c'; + } + wc.getArray()[0x10000] = 0; + UString str( wc.getArray() , 0x10000 ); + rOutput->writeUTF( str ); + ERROR_ASSERT( rInput->readUTF() == str , "error reading 64k block" ); + + rOutput->closeOutput(); + TRY { + rInput->readLong(); + ERROR_ASSERT( 0 , "eof-exception does not occur !" ); + } + CATCH ( IOException ,e ){ + //ok + e.getName(); + } + AND_CATCH_ALL() { + ERROR_ASSERT( 0 , "wrong exception after reading beyond eof" ); + } + END_CATCH; + + ERROR_ASSERT( ! rInput->readBytes( Sequence<BYTE> (1) , 1 ), + "stream must be on eof !" ); + + rInput->closeInput(); + + TRY { + rOutput->writeByte( 1 ); + ERROR_ASSERT( 0 , "writing still possible though chain must be interrupted" ); + } + CATCH( IOException , e ) + { + e.getName(); + // ok + } + AND_CATCH_ALL() { + ERROR_ASSERT( 0 , "IOException expected, but another exception was thrown" ); + } + END_CATCH; + +} + + + +/** +* for external binding +* +* +**/ +XInterfaceRef ODataStreamTest_CreateInstance( const XMultiServiceFactoryRef & rSMgr ) THROWS((Exception)) +{ + ODataStreamTest *p = new ODataStreamTest( rSMgr ); + XInterfaceRef xService = *p; + return xService; +} + +Sequence<UString> ODataStreamTest_getSupportedServiceNames( int i) THROWS( () ) +{ + Sequence<UString> aRet(1); + + aRet.getArray()[0] = ODataStreamTest_getImplementationName( i); + + + return aRet; +} + +UString ODataStreamTest_getServiceName( int i) THROWS( () ) +{ + if( 1 == i ) { + return L"test.com.sun.star.io.DataInputStream"; + } + else { + return L"test.com.sun.star.io.DataOutputStream"; + } +} + +UString ODataStreamTest_getImplementationName( int i) THROWS( () ) +{ + if( 1 == i ) { + return L"test.com.sun.star.comp.extensions.stm.DataInputStream"; + } + else { + return L"test.com.sun.star.comp.extensions.stm.DataOutputStream"; + } +} + + +/**------------------------------------------------------ +* +* +* +* +* +*------------------------------------------------------*/ +class MyPersistObject : + public XPersistObject, + public XPropertySet, + public OWeakObject +{ +public: + MyPersistObject( ) : m_sServiceName( OMyPersistObject_getServiceName() ) + {} + MyPersistObject( const UString & sServiceName ) : m_sServiceName( sServiceName ) + {} + ~MyPersistObject() + {} + +public: + BOOL queryInterface( Uik aUik, XInterfaceRef & rOut ); + void acquire() { OWeakObject::acquire(); } + void release() { OWeakObject::release(); } + void* getImplementation(Reflection *p) { return OWeakObject::getImplementation(p); } + +public: + virtual UString getServiceName(void) const THROWS( (UsrSystemException) ); + virtual void write(const XObjectOutputStreamRef& OutStream) THROWS( (IOException, UsrSystemException) ); + virtual void read(const XObjectInputStreamRef& InStream) THROWS( (IOException, UsrSystemException) ); + +public: + + virtual XPropertySetInfoRef getPropertySetInfo(void) const THROWS( (UsrSystemException) ); + virtual void setPropertyValue(const UString& aPropertyName, const UsrAny& aValue) + THROWS( ( UnknownPropertyException, + PropertyVetoException, + IllegalArgumentException, + WrappedTargetException, + UsrSystemException) ); + virtual UsrAny getPropertyValue(const UString& PropertyName) const + THROWS( ( UnknownPropertyException, + WrappedTargetException, + UsrSystemException) ); + virtual void addPropertyChangeListener( const UString& aPropertyName, + const XPropertyChangeListenerRef& xListener) + THROWS( ( UnknownPropertyException, + WrappedTargetException, + UsrSystemException) ); + virtual void removePropertyChangeListener( const UString& aPropertyName, + const XPropertyChangeListenerRef& aListener) + THROWS( ( UnknownPropertyException, + WrappedTargetException, + UsrSystemException) ); + virtual void addVetoableChangeListener( const UString& PropertyName, + const XVetoableChangeListenerRef& aListener) + THROWS( ( UnknownPropertyException, + WrappedTargetException, + UsrSystemException) ); + virtual void removeVetoableChangeListener( const UString& PropertyName, + const XVetoableChangeListenerRef& aListener) + THROWS( ( UnknownPropertyException, + WrappedTargetException, + UsrSystemException) ); + +public: + INT32 m_l; + float m_f; + double m_d; + BOOL m_b; + BYTE m_byte; + wchar_t m_c; + UString m_s; + XPersistObjectRef m_ref; + UString m_sServiceName; +}; + + + +XPropertySetInfoRef MyPersistObject::getPropertySetInfo(void) const THROWS( (UsrSystemException) ) +{ + return XPropertySetInfoRef(); +} + +void MyPersistObject::setPropertyValue(const UString& aPropertyName, const UsrAny& aValue) + THROWS( ( UnknownPropertyException, + PropertyVetoException, + IllegalArgumentException, + WrappedTargetException, + UsrSystemException) ) +{ + if( L"long" == aPropertyName ) { + m_l = aValue.getINT32(); + } + else if ( L"float" == aPropertyName ) { + m_f = aValue.getFloat(); + } + else if( L"double" == aPropertyName ) { + m_d = aValue.getDouble(); + } + else if( L"bool" == aPropertyName ) { + m_b = aValue.getBOOL(); + } + else if( L"byte" == aPropertyName ) { + m_byte = aValue.getBYTE(); + } + else if( L"char" == aPropertyName ) { + m_c = aValue.getChar(); + } + else if( L"string" == aPropertyName ) { + m_s = aValue.getString(); + } + else if( L"object" == aPropertyName ) { + if( aValue.getReflection() == XPersistObject_getReflection() ) { + XPersistObjectRef *pRef = (XPersistObjectRef*) aValue.get(); + if( pRef ) { + m_ref = *pRef; + } + else { + m_ref = 0; + } + } + else + { + m_ref = 0; + } + } +} + + +UsrAny MyPersistObject::getPropertyValue(const UString& aPropertyName) const + THROWS( ( UnknownPropertyException, + WrappedTargetException, + UsrSystemException) ) +{ + UsrAny aValue; + if( L"long" == aPropertyName ) { + aValue.setINT32( m_l ); + } + else if ( L"float" == aPropertyName ) { + aValue.setFloat( m_f ); + } + else if( L"double" == aPropertyName ) { + aValue.setDouble( m_d ); + } + else if( L"bool" == aPropertyName ) { + aValue.setBOOL( m_b ); + } + else if( L"byte" == aPropertyName ) { + aValue.setBYTE( m_byte ); + } + else if( L"char" == aPropertyName ) { + aValue.setChar( m_c ); + } + else if( L"string" == aPropertyName ) { + aValue.setString( m_s ); + } + else if( L"object" == aPropertyName ) { + aValue.set( &m_ref , XPersistObject_getReflection() ); + } + return aValue; +} + + +void MyPersistObject::addPropertyChangeListener( const UString& aPropertyName, + const XPropertyChangeListenerRef& xListener) + THROWS( ( UnknownPropertyException, + WrappedTargetException, + UsrSystemException) ) +{ + +} + +void MyPersistObject::removePropertyChangeListener( const UString& aPropertyName, + const XPropertyChangeListenerRef& aListener) + THROWS( ( UnknownPropertyException, + WrappedTargetException, + UsrSystemException) ) +{ +} +void MyPersistObject::addVetoableChangeListener(const UString& PropertyName, + const XVetoableChangeListenerRef& aListener) + THROWS( ( UnknownPropertyException, + WrappedTargetException, + UsrSystemException) ) +{ + +} + +void MyPersistObject::removeVetoableChangeListener( const UString& PropertyName, + const XVetoableChangeListenerRef& aListener) + THROWS( ( UnknownPropertyException, + WrappedTargetException, + UsrSystemException) ) +{ + +} + + + +BOOL MyPersistObject::queryInterface( Uik aUik , XInterfaceRef &rOut ) +{ + if( XPersistObject::getSmartUik() == aUik ) { + rOut = ( XPersistObject * ) this; + } + else if( XPropertySet::getSmartUik() == aUik ) { + rOut = ( XPropertySet * ) this; + } + else + return OWeakObject::queryInterface( aUik , rOut ); + + return TRUE; +} + +UString MyPersistObject::getServiceName() const THROWS( (UsrSystemException) ) +{ + return m_sServiceName; +} + +void MyPersistObject::write( const XObjectOutputStreamRef & rOut ) + THROWS( (IOException,UsrSystemException)) +{ + rOut->writeLong( m_l); + rOut->writeFloat( m_f ); + rOut->writeDouble( m_d ); + rOut->writeBoolean( m_b ); + rOut->writeByte( m_byte ); + rOut->writeChar( m_c ); + rOut->writeUTF( m_s ); + rOut->writeObject( m_ref ); +} + + +void MyPersistObject::read( const XObjectInputStreamRef & rIn ) + THROWS( (IOException, UsrSystemException) ) +{ + m_l = rIn->readLong(); + m_f = rIn->readFloat(); + m_d = rIn->readDouble(); + m_b = rIn->readBoolean(); + m_byte = rIn->readByte(); + m_c = rIn->readChar(); + m_s = rIn->readUTF(); + m_ref = rIn->readObject(); +} + +XInterfaceRef OMyPersistObject_CreateInstance( const XMultiServiceFactoryRef & rSMgr ) + THROWS((Exception)) +{ + MyPersistObject *p = new MyPersistObject( ); + XInterfaceRef xService = *p; + return xService; +} + +Sequence<UString> OMyPersistObject_getSupportedServiceNames( ) THROWS( () ) +{ + Sequence<UString> aRet(1); + aRet.getArray()[0] = OMyPersistObject_getImplementationName(); + return aRet; +} + +UString OMyPersistObject_getServiceName( ) THROWS( () ) +{ + return L"test.com.sun.star.io.PersistTest"; +} + +UString OMyPersistObject_getImplementationName( ) THROWS( () ) +{ + return L"test.com.sun.star.io.PersistTest"; +} + + +// --------------------------------------------- +// ----------------------------------------------- +class OObjectStreamTest : + public ODataStreamTest +{ +public: + OObjectStreamTest( const XMultiServiceFactoryRef &r) : ODataStreamTest(r) {} +public: // refcounting + BOOL queryInterface( Uik aUik, XInterfaceRef & rOut ); + +public: + virtual void testInvariant(const UString& TestName, const XInterfaceRef& TestObject) + THROWS( ( IllegalArgumentException, + UsrSystemException) ); + + virtual INT32 test( const UString& TestName, + const XInterfaceRef& TestObject, + INT32 hTestHandle) THROWS( ( IllegalArgumentException, + UsrSystemException) ); + + +private: + void OObjectStreamTest::testObject( const XObjectOutputStreamRef &rOut, + const XObjectInputStreamRef &rIn ); + +private: +}; + + + + +BOOL OObjectStreamTest::queryInterface( Uik uik , XInterfaceRef &rOut ) +{ + if( XSimpleTest::getSmartUik() == uik ) { + rOut = (XSimpleTest *) this; + } + else { + return ODataStreamTest::queryInterface( uik , rOut ); + } + return TRUE; +} + + +void OObjectStreamTest::testInvariant( const UString& TestName, const XInterfaceRef& TestObject ) + THROWS( ( IllegalArgumentException, + UsrSystemException) ) +{ + + + if( L"com.sun.star.io.ObjectInputStream" == TestName ) { + ODataStreamTest::testInvariant( TestName , TestObject ); + XObjectInputStreamRef dataInput( TestObject , USR_QUERY ); + XMarkableStreamRef markable( TestObject , USR_QUERY ); + ERROR_ASSERT( dataInput.is() , "XObjectInputStream cannot be queried" ); + ERROR_ASSERT( markable.is() , "XMarkableStream cannot be queried" ); + } + else if( L"com.sun.star.io.ObjectOutputStream" == TestName ) { + ODataStreamTest::testInvariant( TestName , TestObject ); + XMarkableStreamRef markable( TestObject , USR_QUERY ); + XObjectOutputStreamRef dataOutput( TestObject , USR_QUERY ); + ERROR_ASSERT( dataOutput.is(), "XObjectOutputStream cannot be queried" ); + ERROR_ASSERT( markable.is() , "XMarkableStream cannot be queried" ); + } + + XServiceInfoRef info( TestObject, USR_QUERY ); + ERROR_ASSERT( info.is() , "XServiceInfo not supported !" ); + if( info.is() ) + { + ERROR_ASSERT( info->supportsService( TestName ), "XServiceInfo test failed" ); + ERROR_ASSERT( ! info->supportsService( L"bla bluzb" ) , "XServiceInfo test failed" ); + } + +} + +INT32 OObjectStreamTest::test( const UString& TestName, + const XInterfaceRef& TestObject, + INT32 hTestHandle) THROWS( ( IllegalArgumentException, + UsrSystemException) ) +{ + if( L"com.sun.star.io.ObjectInputStream" == TestName || + L"com.sun.star.io.ObjectOutputStream" == TestName ) { + + TRY { + if( 0 == hTestHandle ) { + testInvariant( TestName , TestObject ); + } + else if( DATASTREAM_TEST_MAX_HANDLE >= hTestHandle ) { + INT32 hOldHandle = hTestHandle; + hTestHandle = ODataStreamTest::test( L"com.sun.star.io.DataInputStream" , + TestObject , hTestHandle ); + if( hTestHandle == -1 ){ + hTestHandle = hOldHandle; + } + } + else { + + XActiveDataSinkRef rSink( TestObject, USR_QUERY ); + XActiveDataSourceRef rSource( TestObject , USR_QUERY ); + + XObjectInputStreamRef rInput( TestObject , USR_QUERY ); + XObjectOutputStreamRef rOutput( TestObject , USR_QUERY ); + + + XInterfaceRef x = m_rFactory->createInstance( L"com.sun.star.io.Pipe"); + + XInputStreamRef rPipeInput( x , USR_QUERY ); + XOutputStreamRef rPipeOutput( x , USR_QUERY ); + + x = m_rFactory->createInstance( L"com.sun.star.io.MarkableInputStream" ); + XInputStreamRef markableInput( x , USR_QUERY ); + XActiveDataSinkRef markableSink( x , USR_QUERY ); + + x = m_rFactory->createInstance( L"com.sun.star.io.MarkableOutputStream" ); + XOutputStreamRef markableOutput( x , USR_QUERY ); + XActiveDataSourceRef markableSource( x , USR_QUERY ); + + assert( markableInput.is() ); + assert( markableOutput.is() ); + assert( markableSink.is() ); + assert( markableSource.is() ); + + markableSink->setInputStream( rPipeInput ); + markableSource->setOutputStream( rPipeOutput ); + + if( ! rSink.is() ) { + x = m_rFactory->createInstance( L"com.sun.star.io.ObjectInputStream" ); + x->queryInterface( XObjectInputStream::getSmartUik() , rInput ); + x->queryInterface( XActiveDataSink::getSmartUik() , rSink ); + } + else if ( !rSource.is() ) { + x = m_rFactory->createInstance( L"com.sun.star.io.ObjectOutputStream" ); + x->queryInterface( XObjectOutputStream::getSmartUik() , rOutput ); + x->queryInterface( XActiveDataSource::getSmartUik() , rSource ); + } + + assert( rPipeInput.is() ); + assert( rPipeOutput.is() ); + + rSink->setInputStream( markableInput ); + rSource->setOutputStream( markableOutput ); + + assert( rSink->getInputStream().is() ); + assert( rSource->getOutputStream().is() ); + + if( 1 + DATASTREAM_TEST_MAX_HANDLE == hTestHandle ) { + testObject( rOutput , rInput); + } + rInput->closeInput(); + rOutput->closeOutput(); + + } + } + CATCH( Exception , e ) { + BUILD_ERROR( 0 , UStringToString( e.getName() , CHARSET_SYSTEM ).GetCharStr() ); + } + AND_CATCH_ALL() { + BUILD_ERROR( 0 , "unknown exception (Exception is not base class)" ); + } + END_CATCH; + + hTestHandle ++; + + if( hTestHandle > 1 +DATASTREAM_TEST_MAX_HANDLE ) { + // all tests finished. + hTestHandle = -1; + } + } + else { + BUILD_ERROR( 0 , "service not supported by test." ); + } + return hTestHandle; +} + + +BOOL compareMyPropertySet( XPropertySetRef &r1 , XPropertySetRef &r2 ) +{ + BOOL b = TRUE; + + if( r1->getPropertyValue( L"long" ).getReflection() == Void_getReflection() || + r2->getPropertyValue( L"long" ).getReflection() == Void_getReflection() ) { + + // one of the objects is not the correct propertyset ! + return FALSE; + } + + b = b && ( r1->getPropertyValue( L"long" ).getINT32() == + r2->getPropertyValue( L"long" ).getINT32() ); + + b = b && ( r1->getPropertyValue( L"float" ).getFloat() == + r2->getPropertyValue( L"float" ).getFloat() ); + + b = b && ( r1->getPropertyValue( L"double" ).getDouble() == + r2->getPropertyValue( L"double" ).getDouble() ); + + b = b && ( r1->getPropertyValue( L"bool" ).getBOOL() == + r2->getPropertyValue( L"bool" ).getBOOL() ); + + b = b && ( r1->getPropertyValue( L"byte" ).getBYTE() == + r2->getPropertyValue( L"byte" ).getBYTE() ); + + b = b && ( r1->getPropertyValue( L"char" ).getChar() == + r2->getPropertyValue( L"char" ).getChar() ); + + b = b && ( r1->getPropertyValue( L"string" ).getString() == + r2->getPropertyValue( L"string" ).getString() ); + + UsrAny o1 = r1->getPropertyValue( L"object" ); + UsrAny o2 = r2->getPropertyValue( L"object" ); + + if( o1.getReflection() == XPersistObject_getReflection() ) { + + if( o2.getReflection() == XPersistObject_getReflection() ) { + XPersistObjectRef rPersist1 = *((XPersistObjectRef*) o1.get()); + XPersistObjectRef rPersist2 = *((XPersistObjectRef*) o2.get()); + XPropertySetRef rProp1( rPersist1 , USR_QUERY ); + XPropertySetRef rProp2( rPersist2 , USR_QUERY ); + + if( rProp1.is() && rProp2.is() && ! ( rProp1 == rProp2 ) + &&( rProp1 != r1 )) { + compareMyPropertySet( rProp1 , rProp2 ); + } + } + else { + b = FALSE; + } + } + else { + if( o2.getReflection() == XPersistObject_getReflection() ) { + b = FALSE; + } + } + + return b; +} + +void OObjectStreamTest::testObject( const XObjectOutputStreamRef &rOut, + const XObjectInputStreamRef &rIn ) +{ + ERROR_ASSERT( rOut.is() , "no objectOutputStream" ); + ERROR_ASSERT( rIn.is() , "no objectInputStream" ); + + XMultiServiceFactoryRef xProv = getProcessServiceManager(); + ERROR_ASSERT( xProv.is() , "no global service manager" ); + + + // tests, if saving an object with an unknown service name allows + // reading the data behind the object ! + { + XInterfaceRef x = * new MyPersistObject( L"bla blubs" ); + + XPersistObjectRef persistRef( x , USR_QUERY ); + ERROR_ASSERT( persistRef.is() , "couldn't instantiate PersistTest object" ); + + rOut->writeObject( persistRef ); + rOut->writeLong( (INT32) 0xdeadbeef ); + + ERROR_ASSERT( 0 != rIn->available() , "no data arrived at input" ); + + TRY + { + XPersistObjectRef xReadPersistRef = rIn->readObject(); + ERROR_ASSERT( 0 , "expected exception not thrown" ); + } + CATCH( IOException , e ) + { + // all is ok + } + + ERROR_ASSERT( (INT32) 0xdeadbeef == rIn->readLong() , + "wrong data after object with unknown service name." ); + } + + { + XInterfaceRef x = xProv->createInstance(L"test.com.sun.star.io.PersistTest"); + XPersistObjectRef persistRef( x , USR_QUERY ); + + ERROR_ASSERT( persistRef.is() , "couldn't instantiate PersistTest object" ); + + XPropertySetRef rProp( persistRef , USR_QUERY ); + ERROR_ASSERT( rProp.is() , "test object is no property set " ); + + UsrAny any; + any.setINT32( 0x83482 ); + rProp->setPropertyValue( L"long" , any ); + + any.setFloat( 42.23 ); + rProp->setPropertyValue( L"float" , any ); + + any.setDouble( 233.321412 ); + rProp->setPropertyValue( L"double" , any ); + + any.setBOOL( TRUE ); + rProp->setPropertyValue( L"bool" , any ); + + any.setBYTE( 130 ); + rProp->setPropertyValue( L"byte" , any ); + + any.setChar( 'h' ); + rProp->setPropertyValue( L"char" , any ); + + any.setString( L"hi du !" ); + rProp->setPropertyValue( L"string" , any ); + + any.set( &persistRef, XPersistObject_getReflection() ); // try a self reference + rProp->setPropertyValue( L"object" , any ); + + // do read and write + rOut->writeObject( persistRef ); + ERROR_ASSERT( 0 != rIn->available() , "no data arrived at input" ); + XPersistObjectRef xReadPersistRef = rIn->readObject( ); + + XPropertySetRef rPropRead( xReadPersistRef , USR_QUERY ); + ERROR_ASSERT( compareMyPropertySet( rProp , rPropRead ) , "objects has not been read properly !" ); + + // destroy selfreferences + rProp->setPropertyValue( L"object", UsrAny() ); + rPropRead->setPropertyValue( L"object", UsrAny() ); + } + + { + XMarkableStreamRef markableOut( rOut , USR_QUERY ); + ERROR_ASSERT( markableOut.is() , "markable stream cannot be queried" ); + + // do the same thing multiple times to check if + // buffering and marks work correctly + for( int i = 0 ; i < 2000 ; i ++ ) { + + XInterfaceRef x = xProv->createInstance(L"test.com.sun.star.io.PersistTest"); + XPersistObjectRef persistRef( x , USR_QUERY ); + + XPropertySetRef rProp( persistRef , USR_QUERY ); + ERROR_ASSERT( rProp.is() , "test object is no property set " ); + + UsrAny any; + any.setINT32( 0x83482 ); + rProp->setPropertyValue( L"long" , any ); + + any.setFloat( 42.23 ); + rProp->setPropertyValue( L"float" , any ); + + any.setDouble( 233.321412 ); + rProp->setPropertyValue( L"double" , any ); + + any.setBOOL( TRUE ); + rProp->setPropertyValue( L"bool" , any ); + + any.setBYTE( 130 ); + rProp->setPropertyValue( L"byte" , any ); + + any.setChar( 'h' ); + rProp->setPropertyValue( L"char" , any ); + + any.setString( L"hi du !" ); + rProp->setPropertyValue( L"string" , any ); + + + x = xProv->createInstance(L"test.com.sun.star.io.PersistTest"); + XPersistObjectRef persist2ndRef( x , USR_QUERY ); + + + // Note : persist2ndRef contains coincident values, but also coincident values must be + // saved properly ! + any.set( &persist2ndRef, XPersistObject_getReflection() ); // try a self reference + rProp->setPropertyValue( L"object" , any ); + + // simply test, if markable operations and object operations do not interfere + INT32 nMark = markableOut->createMark(); + + // do read and write + rOut->writeObject( persistRef ); + + // further markable tests ! + INT32 nOffset = markableOut->offsetToMark( nMark ); + markableOut->jumpToMark( nMark ); + markableOut->deleteMark( nMark ); + markableOut->jumpToFurthest(); + + + + + + ERROR_ASSERT( 0 != rIn->available() , "no data arrived at input" ); + XPersistObjectRef xReadPersistRef = rIn->readObject( ); + + XPropertySetRef rProp1( persistRef , USR_QUERY ); + XPropertySetRef rProp2( xReadPersistRef , USR_QUERY ); + ERROR_ASSERT( compareMyPropertySet( rProp1, rProp2) , "objects has not been read properly !" ); + } + } +} + + +XInterfaceRef OObjectStreamTest_CreateInstance( const XMultiServiceFactoryRef & rSMgr ) THROWS((Exception)) +{ + OObjectStreamTest *p = new OObjectStreamTest( rSMgr ); + XInterfaceRef xService = *p; + return xService; +} + +Sequence<UString> OObjectStreamTest_getSupportedServiceNames( int i) THROWS( () ) +{ + Sequence<UString> aRet(1); + aRet.getArray()[0] = OObjectStreamTest_getImplementationName( i); + return aRet; +} + +UString OObjectStreamTest_getServiceName( int i) THROWS( () ) +{ + if( 1 == i ) { + return L"test.com.sun.star.io.ObjectInputStream"; + } + else { + return L"test.com.sun.star.io.ObjectOutputStream"; + } +} + +UString OObjectStreamTest_getImplementationName( int i) THROWS( () ) +{ + if( 1 == i ) { + return L"test.com.sun.star.comp.extensions.stm.ObjectInputStream"; + } + else { + return L"test.com.sun.star.comp.extensions.stm.ObjectOutputStream"; + } +} + + diff --git a/extensions/test/stm/exports.dxp b/extensions/test/stm/exports.dxp new file mode 100644 index 000000000000..e4bc69d23003 --- /dev/null +++ b/extensions/test/stm/exports.dxp @@ -0,0 +1,2 @@ +exService_writeRegEntry +exService_getFactory diff --git a/extensions/test/stm/makefile.mk b/extensions/test/stm/makefile.mk new file mode 100644 index 000000000000..f2781bca51d7 --- /dev/null +++ b/extensions/test/stm/makefile.mk @@ -0,0 +1,99 @@ +#************************************************************************* +# +# $RCSfile: makefile.mk,v $ +# +# $Revision: 1.1.1.1 $ +# +# last change: $Author: hr $ $Date: 2000-09-18 16:16:56 $ +# +# The Contents of this file are made available subject to the terms of +# either of the following licenses +# +# - GNU Lesser General Public License Version 2.1 +# - Sun Industry Standards Source License Version 1.1 +# +# Sun Microsystems Inc., October, 2000 +# +# GNU Lesser General Public License Version 2.1 +# ============================================= +# Copyright 2000 by Sun Microsystems, Inc. +# 901 San Antonio Road, Palo Alto, CA 94303, USA +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License version 2.1, as published by the Free Software Foundation. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, +# MA 02111-1307 USA +# +# +# Sun Industry Standards Source License Version 1.1 +# ================================================= +# The contents of this file are subject to the Sun Industry Standards +# Source License Version 1.1 (the "License"); You may not use this file +# except in compliance with the License. You may obtain a copy of the +# License at http://www.openoffice.org/license.html. +# +# Software provided under this License is provided on an "AS IS" basis, +# WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, +# WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, +# MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. +# See the License for the specific provisions governing your rights and +# obligations concerning the Software. +# +# The Initial Developer of the Original Code is: Sun Microsystems, Inc. +# +# Copyright: 2000 by Sun Microsystems, Inc. +# +# All Rights Reserved. +# +# Contributor(s): _______________________________________ +# +# +# +#************************************************************************* +PRJ=..$/.. + +PRJNAME=extensions +TARGET=teststm +USE_DEFFILE=TRUE +ENABLE_EXCEPTIONS=TRUE + +# --- Settings ----------------------------------------------------- +.INCLUDE : $(PRJ)$/util$/makefile.pmk + +# --- Files -------------------------------------------------------- +OBJFILES= $(SLO)$/pipetest.obj $(SLO)$/testfactreg.obj $(SLO)$/datatest.obj \ + $(SLO)$/marktest.obj +CXXFILES = pipetest.cxx testfactreg.cxx datatest.cxx marktest.cxx + +SHL1TARGET= $(TARGET)$(UPD)$(DLLPOSTFIX) +LIB1TARGET= $(SLB)$/$(TARGET).lib + +SHL1STDLIBS= \ + $(USRLIB) \ + $(VOSLIB) \ + $(SALLIB) \ + $(TOOLSLIB) + +LIB1OBJFILES= $(OBJFILES) +SHL1LIBS= $(LIB1TARGET) +SHL1IMPLIB= i$(TARGET) +SHL1DEPN= makefile.mk $(SHL1LIBS) +SHL1DEF= $(MISC)$/$(SHL1TARGET).def + +DEF1NAME= $(SHL1TARGET) +DEF1EXPORTFILE= exports.dxp + + +# --- Targets ------------------------------------------------------ + +.INCLUDE : target.mk +.INCLUDE : $(PRJ)$/util$/target.pmk diff --git a/extensions/test/stm/marktest.cxx b/extensions/test/stm/marktest.cxx new file mode 100644 index 000000000000..5041f86feae7 --- /dev/null +++ b/extensions/test/stm/marktest.cxx @@ -0,0 +1,718 @@ +/************************************************************************* + * + * $RCSfile: marktest.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 16:16:56 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ +#include <smart/com/sun/star/test/XSimpleTest.hxx> +#include <smart/com/sun/star/io/XMarkableStream.hxx> +#include <smart/com/sun/star/io/XActiveDataSink.hxx> +#include <smart/com/sun/star/io/XActiveDataSource.hxx> +#include <smart/com/sun/star/io/XConnectable.hxx> + +#include <smart/com/sun/star/lang/XServiceInfo.hxx> + + +#include <usr/factoryhlp.hxx> + +#include <usr/reflserv.hxx> // for EXTERN_SERVICE_CALLTYPE +#include <usr/weak.hxx> // OWeakObject + +#include <vos/conditn.hxx> +#include <vos/mutex.hxx> +#include <vos/thread.hxx> + +#include <assert.h> +#include <string.h> + +#include "testfactreg.hxx" + + +#ifndef _VOS_NO_NAMESPACE +using namespace vos; +using namespace usr; +#endif + + + +class OMarkableOutputStreamTest : + public XSimpleTest, + public OWeakObject +{ +public: + OMarkableOutputStreamTest( const XMultiServiceFactoryRef & rFactory ); + ~OMarkableOutputStreamTest(); + +public: // refcounting + BOOL queryInterface( Uik aUik, XInterfaceRef & rOut ); + void acquire() { OWeakObject::acquire(); } + void release() { OWeakObject::release(); } + void* getImplementation(Reflection *p) { return OWeakObject::getImplementation(p); } + +public: // implementation names + static Sequence< UString > getSupportedServiceNames_Static(void) THROWS( () ); + static UString getImplementationName_Static() THROWS( () ); + +public: + virtual void testInvariant(const UString& TestName, const XInterfaceRef& TestObject) + THROWS( ( IllegalArgumentException, + UsrSystemException) ); + + virtual INT32 test( const UString& TestName, + const XInterfaceRef& TestObject, + INT32 hTestHandle) THROWS( ( IllegalArgumentException, + UsrSystemException) ); + + virtual BOOL testPassed(void) THROWS( ( UsrSystemException) ); + virtual Sequence< UString > getErrors(void) THROWS( (UsrSystemException) ); + virtual Sequence< UsrAny > getErrorExceptions(void) THROWS( (UsrSystemException) ); + virtual Sequence< UString > getWarnings(void) THROWS( (UsrSystemException) ); + +private: + void testSimple( const XOutputStreamRef &r, const XInputStreamRef &rInput ); + +private: + Sequence<UsrAny> m_seqExceptions; + Sequence<UString> m_seqErrors; + Sequence<UString> m_seqWarnings; + XMultiServiceFactoryRef m_rFactory; + +}; + +OMarkableOutputStreamTest::OMarkableOutputStreamTest( const XMultiServiceFactoryRef &rFactory ) + : m_rFactory( rFactory ) +{ + +} + +OMarkableOutputStreamTest::~OMarkableOutputStreamTest() +{ + +} + + +BOOL OMarkableOutputStreamTest::queryInterface( Uik uik , XInterfaceRef &rOut ) +{ + if( XSimpleTest::getSmartUik() == uik ) { + rOut = (XSimpleTest *) this; + } + else { + return OWeakObject::queryInterface( uik , rOut ); + } + return TRUE; +} + + +void OMarkableOutputStreamTest::testInvariant( const UString& TestName, const XInterfaceRef& TestObject ) + THROWS( ( IllegalArgumentException, + UsrSystemException) ) +{ + XServiceInfoRef info( TestObject, USR_QUERY ); + ERROR_ASSERT( info.is() , "XServiceInfo not supported !" ); + if( info.is() ) + { + ERROR_ASSERT( info->supportsService( TestName ), "XServiceInfo test failed" ); + ERROR_ASSERT( ! info->supportsService( L"bla bluzb" ) , "XServiceInfo test failed" ); + } +} + + +INT32 OMarkableOutputStreamTest::test( const UString& TestName, + const XInterfaceRef& TestObject, + INT32 hTestHandle) THROWS( ( IllegalArgumentException, + UsrSystemException) ) +{ + if( L"com.sun.star.io.MarkableOutputStream" == TestName ) { + TRY { + if( 0 == hTestHandle ) { + testInvariant( TestName , TestObject ); + } + else { + XInterfaceRef x = m_rFactory->createInstance( L"com.sun.star.io.Pipe"); + XOutputStreamRef rPipeOutput( x , USR_QUERY ); + XInputStreamRef rPipeInput( x , USR_QUERY ); + + XActiveDataSourceRef source( TestObject , USR_QUERY ); + source->setOutputStream( rPipeOutput ); + + XOutputStreamRef rOutput( TestObject , USR_QUERY ); + + assert( rPipeInput.is() ); + assert( rOutput.is() ); + if( 1 == hTestHandle ) { + // checks usual streaming + testSimple( rOutput , rPipeInput ); + } + } + + } + CATCH( Exception , e ) { + BUILD_ERROR( 0 , UStringToString( e.getName() , CHARSET_SYSTEM ).GetCharStr() ); + } + AND_CATCH_ALL() { + BUILD_ERROR( 0 , "unknown exception (Exception is not base class)" ); + } + END_CATCH; + + hTestHandle ++; + + if( 2 == hTestHandle ) { + // all tests finished. + hTestHandle = -1; + } + } + else { + THROW( IllegalArgumentException() ); + } + return hTestHandle; +} + + + +BOOL OMarkableOutputStreamTest::testPassed(void) THROWS( (UsrSystemException) ) +{ + return m_seqErrors.getLen() == 0; +} + + +Sequence< UString > OMarkableOutputStreamTest::getErrors(void) THROWS( (UsrSystemException) ) +{ + return m_seqErrors; +} + + +Sequence< UsrAny > OMarkableOutputStreamTest::getErrorExceptions(void) THROWS( (UsrSystemException) ) +{ + return m_seqExceptions; +} + + +Sequence< UString > OMarkableOutputStreamTest::getWarnings(void) THROWS( (UsrSystemException) ) +{ + return m_seqWarnings; +} + + +void OMarkableOutputStreamTest::testSimple( const XOutputStreamRef &rOutput , + const XInputStreamRef &rInput ) +{ + XMarkableStreamRef rMarkable( rOutput , USR_QUERY ); + + ERROR_ASSERT( rMarkable.is() , "no MarkableStream implemented" ); + + // first check normal input/output facility + char pcStr[] = "Live long and prosper !"; + + Sequence<BYTE> seqWrite( strlen( pcStr )+1 ); + memcpy( seqWrite.getArray() , pcStr , seqWrite.getLen() ); + + Sequence<BYTE> seqRead( seqWrite.getLen() ); + + int nMax = 10,i; + + for( i = 0 ; i < nMax ; i ++ ) { + rOutput->writeBytes( seqWrite ); + rInput->readBytes( seqRead , rInput->available() ); + ERROR_ASSERT( ! strcmp( (char *) seqWrite.getArray() , (char * )seqRead.getArray() ) , + "error during read/write/skip" ); + } + + // Check buffer resizing + nMax = 3000; + for( i = 0 ; i < nMax ; i ++ ) { + rOutput->writeBytes( seqWrite ); + } + + for( i = 0 ; i < nMax ; i ++ ) { + rInput->readBytes( seqRead , seqWrite.getLen() ); + ERROR_ASSERT( ! strcmp( (char *) seqWrite.getArray() , (char * )seqRead.getArray() ) , + "error during read/write" ); + } + + // Check creating marks ! + INT32 nMark = rMarkable->createMark(); + + for( i = 0 ; i < nMax ; i ++ ) { + rOutput->writeBytes( seqWrite ); + } + + ERROR_ASSERT( 0 == rInput->available() , "bytes available though mark is holded" ); + + ERROR_ASSERT( nMax*seqWrite.getLen() == rMarkable->offsetToMark( nMark ) , + "offsetToMark failure" ); + + rMarkable->deleteMark( nMark ); + ERROR_ASSERT( nMax*seqWrite.getLen() == rInput->available(),"bytes are not available though mark has been deleted" ); + + rInput->skipBytes( nMax*seqWrite.getLen() ); + ERROR_ASSERT( 0 == rInput->available(), "skip bytes failure" ); + + TRY { + rMarkable->jumpToMark( nMark ); + ERROR_ASSERT( 0 , "jump to non existing mark possible !" ); + } + CATCH ( IllegalArgumentException , e ) + { + e;// ok, exception was thrown + } + END_CATCH; + + // test putting marks not at the end of the stream! + ERROR_ASSERT( 0 == rInput->available(), "stream isn't clean" ); + { + Sequence< BYTE > aByte(256); + + for( i = 0 ; i < 256 ; i ++ ) + { + aByte.getArray()[i] = i; + } + INT32 nMark1 = rMarkable->createMark(); + + rOutput->writeBytes( aByte ); + rMarkable->jumpToMark( nMark1 ); + aByte.realloc( 10 ); + rOutput->writeBytes( aByte ); + + INT32 nMark2 = rMarkable->createMark( ); + + for( i = 0 ; i < 10 ; i ++ ) + { + aByte.getArray()[i] = i+10; + } + + rOutput->writeBytes( aByte ); + + // allow the bytes to be written ! + rMarkable->jumpToFurthest(); + rMarkable->deleteMark( nMark1 ); + rMarkable->deleteMark( nMark2 ); + + ERROR_ASSERT( 256 == rInput->available(), "in between mark failure" ); + rInput->readBytes( aByte ,256); + for( i = 0 ; i < 256 ; i ++ ) + { + ERROR_ASSERT( i == aByte.getArray()[i] , "in between mark failure" ); + } + } + + { + // now a more extensive mark test ! + Sequence<BYTE> as[4]; + INT32 an[4]; + + for( i = 0 ; i < 4 ; i ++ ) { + as[i].realloc(1); + as[i].getArray()[0] = i; + an[i] = rMarkable->createMark(); + rOutput->writeBytes( as[i] ); + } + + // check offset to mark + for( i = 0 ; i < 4 ; i ++ ) { + ERROR_ASSERT( rMarkable->offsetToMark( an[i] ) == 4-i , "offsetToMark failure" ); + } + + rMarkable->jumpToMark( an[1] ); + ERROR_ASSERT( rMarkable->offsetToMark( an[3] ) == -2 , "offsetToMark failure" ); + + rMarkable->jumpToFurthest( ); + ERROR_ASSERT( rMarkable->offsetToMark( an[0] ) == 4 , "offsetToMark failure" ); + + // now do a rewrite ! + for( i = 0 ; i < 4 ; i ++ ) { + rMarkable->jumpToMark( an[3-i] ); + rOutput->writeBytes( as[i] ); + } + // NOTE : CursorPos 1 + + // now delete the marks ! + for( i = 0 ; i < 4 ; i ++ ) { + rMarkable->deleteMark( an[i] ); + } + ERROR_ASSERT( rInput->available() == 1 , "wrong number of bytes flushed" ); + + rMarkable->jumpToFurthest(); + + ERROR_ASSERT( rInput->available() == 4 , "wrong number of bytes flushed" ); + + rInput->readBytes( seqRead , 4 ); + + ERROR_ASSERT( 3 == seqRead.getArray()[0] , "rewrite didn't work" ); + ERROR_ASSERT( 2 == seqRead.getArray()[1] , "rewrite didn't work" ); + ERROR_ASSERT( 1 == seqRead.getArray()[2] , "rewrite didn't work" ); + ERROR_ASSERT( 0 == seqRead.getArray()[3] , "rewrite didn't work" ); + + rOutput->closeOutput(); + rInput->closeInput(); + } + +} + +/*** +* the test methods +* +****/ + + + + + +/** +* for external binding +* +* +**/ +XInterfaceRef OMarkableOutputStreamTest_CreateInstance( const XMultiServiceFactoryRef & rSMgr ) THROWS((Exception)) +{ + OMarkableOutputStreamTest *p = new OMarkableOutputStreamTest( rSMgr ); + XInterfaceRef xService = *p; + return xService; +} + + + +Sequence<UString> OMarkableOutputStreamTest_getSupportedServiceNames(void) THROWS( () ) +{ + Sequence<UString> aRet(1); + aRet.getArray()[0] = OMarkableOutputStreamTest_getImplementationName(); + + return aRet; +} + +UString OMarkableOutputStreamTest_getServiceName() THROWS( () ) +{ + return L"test.com.sun.star.io.MarkableOutputStream"; +} + +UString OMarkableOutputStreamTest_getImplementationName() THROWS( () ) +{ + return L"test.com.sun.starextensions.stm.MarkableOutputStream"; +} + + + + + + + +//----------------------------------------------------- +// Input stream + + +class OMarkableInputStreamTest : + public XSimpleTest, + public OWeakObject +{ +public: + OMarkableInputStreamTest( const XMultiServiceFactoryRef & rFactory ); + ~OMarkableInputStreamTest(); + +public: // refcounting + BOOL queryInterface( Uik aUik, XInterfaceRef & rOut ); + void acquire() { OWeakObject::acquire(); } + void release() { OWeakObject::release(); } + void* getImplementation(Reflection *p) { return OWeakObject::getImplementation(p); } + +public: // implementation names + static Sequence< UString > getSupportedServiceNames_Static(void) THROWS( () ); + static UString getImplementationName_Static() THROWS( () ); + +public: + virtual void testInvariant(const UString& TestName, const XInterfaceRef& TestObject) + THROWS( ( IllegalArgumentException, + UsrSystemException) ); + + virtual INT32 test( const UString& TestName, + const XInterfaceRef& TestObject, + INT32 hTestHandle) THROWS( ( IllegalArgumentException, + UsrSystemException) ); + + virtual BOOL testPassed(void) THROWS( ( UsrSystemException) ); + virtual Sequence< UString > getErrors(void) THROWS( (UsrSystemException) ); + virtual Sequence< UsrAny > getErrorExceptions(void) THROWS( (UsrSystemException) ); + virtual Sequence< UString > getWarnings(void) THROWS( (UsrSystemException) ); + +private: + void testSimple( const XOutputStreamRef &r, const XInputStreamRef &rInput ); + +private: + Sequence<UsrAny> m_seqExceptions; + Sequence<UString> m_seqErrors; + Sequence<UString> m_seqWarnings; + XMultiServiceFactoryRef m_rFactory; + +}; + +OMarkableInputStreamTest::OMarkableInputStreamTest( const XMultiServiceFactoryRef &rFactory ) + : m_rFactory( rFactory ) +{ + +} + +OMarkableInputStreamTest::~OMarkableInputStreamTest() +{ + +} + + +BOOL OMarkableInputStreamTest::queryInterface( Uik uik , XInterfaceRef &rOut ) +{ + if( XSimpleTest::getSmartUik() == uik ) { + rOut = (XSimpleTest *) this; + } + else { + return OWeakObject::queryInterface( uik , rOut ); + } + return TRUE; +} + + +void OMarkableInputStreamTest::testInvariant( const UString& TestName, const XInterfaceRef& TestObject ) + THROWS( ( IllegalArgumentException, + UsrSystemException) ) +{ + if( L"com.sun.star.io.MarkableInputStream" == TestName ) { + XServiceInfoRef info( TestObject, USR_QUERY ); + ERROR_ASSERT( info.is() , "XServiceInfo not supported !" ); + if( info.is() ) + { + ERROR_ASSERT( info->supportsService( TestName ), "XServiceInfo test failed" ); + ERROR_ASSERT( ! info->supportsService( L"bla bluzb" ) , "XServiceInfo test failed" ); + } + } + else { + THROW( IllegalArgumentException() ); + } +} + + +INT32 OMarkableInputStreamTest::test( const UString& TestName, + const XInterfaceRef& TestObject, + INT32 hTestHandle) THROWS( ( IllegalArgumentException, + UsrSystemException) ) +{ + if( L"com.sun.star.io.MarkableInputStream" == TestName ) { + TRY { + if( 0 == hTestHandle ) { + testInvariant( TestName , TestObject ); + } + else { + XInterfaceRef x = m_rFactory->createInstance( L"com.sun.star.io.Pipe"); + XOutputStreamRef rPipeOutput( x , USR_QUERY ); + XInputStreamRef rPipeInput( x , USR_QUERY ); + + XActiveDataSinkRef sink( TestObject , USR_QUERY ); + sink->setInputStream( rPipeInput ); + + XInputStreamRef rInput( TestObject , USR_QUERY ); + + assert( rPipeOutput.is() ); + assert( rInput.is() ); + if( 1 == hTestHandle ) { + // checks usual streaming + testSimple( rPipeOutput , rInput ); + } + } + + } + CATCH( Exception , e ) { + BUILD_ERROR( 0 , UStringToString( e.getName() , CHARSET_SYSTEM ).GetCharStr() ); + } + AND_CATCH_ALL() { + BUILD_ERROR( 0 , "unknown exception (Exception is not base class)" ); + } + END_CATCH; + + hTestHandle ++; + + if( 2 == hTestHandle ) { + // all tests finished. + hTestHandle = -1; + } + } + else { + THROW( IllegalArgumentException() ); + } + return hTestHandle; +} + + + +BOOL OMarkableInputStreamTest::testPassed(void) THROWS( (UsrSystemException) ) +{ + return m_seqErrors.getLen() == 0; +} + + +Sequence< UString > OMarkableInputStreamTest::getErrors(void) THROWS( (UsrSystemException) ) +{ + return m_seqErrors; +} + + +Sequence< UsrAny > OMarkableInputStreamTest::getErrorExceptions(void) THROWS( (UsrSystemException) ) +{ + return m_seqExceptions; +} + + +Sequence< UString > OMarkableInputStreamTest::getWarnings(void) THROWS( (UsrSystemException) ) +{ + return m_seqWarnings; +} + + +void OMarkableInputStreamTest::testSimple( const XOutputStreamRef &rOutput , + const XInputStreamRef &rInput ) +{ + XMarkableStreamRef rMarkable( rInput , USR_QUERY ); + + Sequence<BYTE> seqWrite( 256 ); + Sequence<BYTE> seqRead(10); + + for( int i = 0 ; i < 256 ; i ++ ) + { + seqWrite.getArray()[i] = i; + } + + rOutput->writeBytes( seqWrite ); + ERROR_ASSERT( 256 == rInput->available() , "basic read/write failure" ); + + rInput->readBytes( seqRead , 10 ); + ERROR_ASSERT( 9 == seqRead.getArray()[9] , "basic read/write failure" ); + + INT32 nMark = rMarkable->createMark(); + + rInput->skipBytes( 50 ); + ERROR_ASSERT( 256-10-50 == rInput->available() , "marking error" ); + ERROR_ASSERT( 50 == rMarkable->offsetToMark( nMark ) , "marking error" ); + + rMarkable->jumpToMark( nMark ); + ERROR_ASSERT( 256-10 == rInput->available() , "marking error" ); + + rInput->readBytes( seqRead , 10 ); + ERROR_ASSERT( 10 == seqRead.getArray()[0] , "marking error" ); + + // pos 20 + { + INT32 nInBetweenMark = rMarkable->createMark( ); + rMarkable->jumpToMark( nMark ); + rMarkable->jumpToMark( nInBetweenMark ); + + rInput->readBytes( seqRead , 10 ); + ERROR_ASSERT( 20 == seqRead.getArray()[0] , "Inbetween mark failed!\n" ); + + rMarkable->deleteMark( nMark ); + + // Check if releasing the first bytes works correct. + rMarkable->jumpToMark( nInBetweenMark); + rInput->readBytes( seqRead , 10 ); + ERROR_ASSERT( 20 == seqRead.getArray()[0] , "Inbetween mark failed!\n" ); + + rMarkable->deleteMark( nInBetweenMark ); + } + + rMarkable->jumpToFurthest(); + ERROR_ASSERT( 256-10-50 == rInput->available() , "marking error" ); + + + ERROR_ASSERT( 100 == rInput->readSomeBytes( seqRead , 100 ) , "wrong results using readSomeBytes" ); + ERROR_ASSERT( 96 == rInput->readSomeBytes( seqRead , 1000) , "wrong results using readSomeBytes" ); + rOutput->closeOutput(); + rInput->closeInput(); +} + +/*** +* the test methods +* +****/ + + + + + +/** +* for external binding +* +* +**/ +XInterfaceRef OMarkableInputStreamTest_CreateInstance( const XMultiServiceFactoryRef & rSMgr ) THROWS((Exception)) +{ + OMarkableInputStreamTest *p = new OMarkableInputStreamTest( rSMgr ); + XInterfaceRef xService = *p; + return xService; +} + + + +Sequence<UString> OMarkableInputStreamTest_getSupportedServiceNames(void) THROWS( () ) +{ + Sequence<UString> aRet(1); + aRet.getArray()[0] = OMarkableInputStreamTest_getImplementationName(); + + return aRet; +} + +UString OMarkableInputStreamTest_getServiceName() THROWS( () ) +{ + return L"test.com.sun.star.io.MarkableInputStream"; +} + +UString OMarkableInputStreamTest_getImplementationName() THROWS( () ) +{ + return L"test.com.sun.star.extensions.stm.MarkableInputStream"; +} diff --git a/extensions/test/stm/pipetest.cxx b/extensions/test/stm/pipetest.cxx new file mode 100644 index 000000000000..4747e5352e7f --- /dev/null +++ b/extensions/test/stm/pipetest.cxx @@ -0,0 +1,483 @@ +/************************************************************************* + * + * $RCSfile: pipetest.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 16:16:56 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ +#include <smart/com/sun/star/test/XSimpleTest.hxx> +#include <smart/com/sun/star/io/XOutputStream.hxx> +#include <smart/com/sun/star/io/XInputStream.hxx> + +#include <smart/com/sun/star/lang/XServiceInfo.hxx> + +#include <usr/factoryhlp.hxx> + +#include <usr/reflserv.hxx> // for EXTERN_SERVICE_CALLTYPE +#include <usr/weak.hxx> // OWeakObject + +#include <vos/conditn.hxx> +#include <vos/mutex.hxx> +#include <vos/thread.hxx> + +#include <assert.h> +#include <string.h> + +#include "testfactreg.hxx" +#define IMPLEMENTATION_NAME L"test.com.sun.star.comp.extensions.stm.Pipe" +#define SERVICE_NAME L"test.com.sun.star.io.Pipe" + +#ifndef _VOS_NO_NAMESPACE +using namespace vos; +using namespace usr; +#endif + +class WriteToStreamThread : + public OThread +{ + +public: + + WriteToStreamThread( XOutputStreamRef xOutput , int iMax ) + { + m_output = xOutput; + m_iMax = iMax; + } + + virtual ~WriteToStreamThread() {} + + +protected: + + /// Working method which should be overridden. + virtual void run() { + for( int i = 0 ; i < m_iMax ; i ++ ) { + m_output->writeBytes( createIntSeq(i) ); + } + m_output->closeOutput(); + } + + /** Called when run() is done. + * You might want to override it to do some cleanup. + */ + virtual void onTerminated() + { + delete this; + } + + +private: + + XOutputStreamRef m_output; + int m_iMax; +}; + + + +class OPipeTest : + public XSimpleTest, + public OWeakObject +{ +public: + OPipeTest( const XMultiServiceFactoryRef & rFactory ); + ~OPipeTest(); + +public: // refcounting + BOOL queryInterface( Uik aUik, XInterfaceRef & rOut ); + void acquire() { OWeakObject::acquire(); } + void release() { OWeakObject::release(); } + void* getImplementation(Reflection *p) { return OWeakObject::getImplementation(p); } + +public: // implementation names + static Sequence< UString > getSupportedServiceNames_Static(void) THROWS( () ); + static UString getImplementationName_Static() THROWS( () ); + +public: + virtual void testInvariant(const UString& TestName, const XInterfaceRef& TestObject) + THROWS( ( IllegalArgumentException, + UsrSystemException) ); + + virtual INT32 test( const UString& TestName, + const XInterfaceRef& TestObject, + INT32 hTestHandle) THROWS( ( IllegalArgumentException, + UsrSystemException) ); + + virtual BOOL testPassed(void) THROWS( ( UsrSystemException) ); + virtual Sequence< UString > getErrors(void) THROWS( (UsrSystemException) ); + virtual Sequence< UsrAny > getErrorExceptions(void) THROWS( (UsrSystemException) ); + virtual Sequence< UString > getWarnings(void) THROWS( (UsrSystemException) ); + +private: + void testSimple( const XInterfaceRef & ); + void testBufferResizing( const XInterfaceRef & ); + void testMultithreading( const XInterfaceRef & ); + +private: + Sequence<UsrAny> m_seqExceptions; + Sequence<UString> m_seqErrors; + Sequence<UString> m_seqWarnings; + +}; + + + +OPipeTest::OPipeTest( const XMultiServiceFactoryRef &rFactory ) +{ + +} + +OPipeTest::~OPipeTest() +{ + +} + + +BOOL OPipeTest::queryInterface( Uik uik , XInterfaceRef &rOut ) +{ + if( XSimpleTest::getSmartUik() == uik ) { + rOut = (XSimpleTest *) this; + } + else { + return OWeakObject::queryInterface( uik , rOut ); + } + return TRUE; +} + + +void OPipeTest::testInvariant( const UString& TestName, const XInterfaceRef& TestObject ) + THROWS( ( IllegalArgumentException, + UsrSystemException) ) +{ + XServiceInfoRef info( TestObject, USR_QUERY ); + ERROR_ASSERT( info.is() , "XServiceInfo not supported !" ); + if( info.is() ) + { + ERROR_ASSERT( info->supportsService( TestName ), "XServiceInfo test failed" ); + ERROR_ASSERT( ! info->supportsService( L"bla bluzb" ) , "XServiceInfo test failed" ); + } + +} + + +INT32 OPipeTest::test( const UString& TestName, + const XInterfaceRef& TestObject, + INT32 hTestHandle) THROWS( ( IllegalArgumentException, + UsrSystemException) ) +{ + if( L"com.sun.star.io.Pipe" == TestName ) { + TRY { + if( 0 == hTestHandle ) { + testInvariant( TestName , TestObject ); + } + else if( 1 == hTestHandle ) { + testSimple( TestObject ); + } + else if( 2 == hTestHandle ) { + testBufferResizing( TestObject ); + } + else if( 3 == hTestHandle ) { + testMultithreading( TestObject ); + } + } + CATCH( Exception , e ) { + BUILD_ERROR( 0 , UStringToString( e.getName() , CHARSET_SYSTEM ).GetCharStr() ); + } + AND_CATCH_ALL() { + BUILD_ERROR( 0 , "unknown exception (Exception is not base class)" ); + } + END_CATCH; + + hTestHandle ++; + + if( 4 == hTestHandle ) { + // all tests finished. + hTestHandle = -1; + } + } + else { + THROW( IllegalArgumentException() ); + } + return hTestHandle; +} + + + +BOOL OPipeTest::testPassed(void) THROWS( (UsrSystemException) ) +{ + return m_seqErrors.getLen() == 0; +} + + +Sequence< UString > OPipeTest::getErrors(void) THROWS( (UsrSystemException) ) +{ + return m_seqErrors; +} + + +Sequence< UsrAny > OPipeTest::getErrorExceptions(void) THROWS( (UsrSystemException) ) +{ + return m_seqExceptions; +} + + +Sequence< UString > OPipeTest::getWarnings(void) THROWS( (UsrSystemException) ) +{ + return m_seqWarnings; +} + + +/*** +* the test methods +* +****/ + + +void OPipeTest::testSimple( const XInterfaceRef &r ) +{ + + XInputStreamRef input( r , USR_QUERY ); + XOutputStreamRef output( r , USR_QUERY ); + + ERROR_ASSERT( input.is() , "queryInterface on XInputStream failed" ); + ERROR_ASSERT( output.is() , "queryInterface onXOutputStream failed" ); + + // basic read/write + Sequence<BYTE> seqWrite = createSeq( "Hallo, du Ei !" ); + + Sequence<BYTE> seqRead; + for( int i = 0 ; i < 5000 ; i ++ ) { + output->writeBytes( seqWrite ); + input->readBytes( seqRead , input->available() ); + + ERROR_ASSERT( ! strcmp( (char *) seqWrite.getArray() , (char * )seqRead.getArray() ) , + "error during read/write/skip" ); + ERROR_ASSERT( 0 == input->available() , + "error during read/write/skip" ); + + // available shouldn't return a negative value + input->skipBytes( seqWrite.getLen() - 5 ); + ERROR_ASSERT( 0 == input->available() , "wrong available after skip" ); + + // 5 bytes should be available + output->writeBytes( seqWrite ); + ERROR_ASSERT( 5 == input->available() , "wrong available after skip/write " ); + + input->readBytes( seqRead , 5 ); + ERROR_ASSERT( ! strcmp( (char*) seqRead.getArray() , + (char*) &( seqWrite.getArray()[seqWrite.getLen()-5] ) ), + "write/read mismatich" ); + + } + + output->writeBytes( seqWrite ); + ERROR_ASSERT( seqWrite.getLen() == input->available(), "wrong available() after write" ); + + ERROR_ASSERT( 10 == input->readSomeBytes( seqRead , 10 ) , "maximal number of bytes ignored" ); + ERROR_ASSERT( seqWrite.getLen() -10 == input->readSomeBytes( seqRead , 100 ) , + "something wrong with readSomeBytes" ); + + + output->closeOutput(); + TRY { + output->writeBytes( Sequence<BYTE> (100) ); + ERROR_ASSERT( 0 , "writing on a closed stream does not cause an exception" ); + } + CATCH (IOException , e ) { + e; // just to suppress warning during compile + } + END_CATCH; + + ERROR_ASSERT(! input->readBytes( seqRead , 1 ), "eof not found !" ); + + input->closeInput(); + TRY { + input->readBytes( seqRead , 1 ); + ERROR_ASSERT( 0 , "reading from a closed stream does not cause an exception" ); + } + CATCH( IOException , e ) { + e; // just to suppress warning during compile + } + END_CATCH; + +} + +void OPipeTest::testBufferResizing( const XInterfaceRef &r ) +{ + + int iMax = 20000; + XInputStreamRef input( r , USR_QUERY ); + XOutputStreamRef output( r , USR_QUERY ); + + ERROR_ASSERT( input.is() , "queryInterface on XInputStream failed" ); + ERROR_ASSERT( output.is() , "queryInterface on XOutputStream failed" ); + + Sequence<BYTE> seqRead; + + // this is just to better check the + // internal buffers + output->writeBytes( Sequence<BYTE>(100) ); + input->readBytes( Sequence<BYTE>() , 100); + + for( int i = 0 ; i < iMax ; i ++ ) { + output->writeBytes( createIntSeq( i ) ); + } + + for( i = 0 ; i < iMax ; i ++ ) { + input->readBytes( seqRead, createIntSeq(i).getLen() ); + ERROR_ASSERT( ! strcmp( (char*) seqRead.getArray() , + (char*) createIntSeq(i).getArray() ) , + "written/read mismatch\n" ); + } + + output->closeOutput(); + ERROR_ASSERT( ! input->readBytes( seqRead , 1 ) , "eof not reached !" ); + input->closeInput(); +} + + + +void OPipeTest::testMultithreading( const XInterfaceRef &r ) +{ + + + int iMax = 30000; + + XInputStreamRef input( r , USR_QUERY ); + XOutputStreamRef output( r , USR_QUERY ); + + ERROR_ASSERT( input.is() , "queryInterface on XInputStream failed" ); + ERROR_ASSERT( output.is() , "queryInterface on XOutputStream failed" ); + + Sequence<BYTE> seqRead; + + // deletes itself + OThread *p = new WriteToStreamThread( output, iMax ); + + ERROR_ASSERT( p , "couldn't create thread for testing !\n" ); + + p->create(); + + for(int i = 0 ; TRUE ; i ++ ) { + if( 0 == input->readBytes( seqRead, createIntSeq(i).getLen() ) ) { + // eof reached ! + break; + } + + ERROR_ASSERT( ! strcmp( (char*) seqRead.getArray() , + (char*) createIntSeq(i).getArray() ) , + "written/read mismatch\n" ); + } + + ERROR_ASSERT( i == iMax , "less elements read than written !"); + input->closeInput(); +} + +/* { + TRY { + XInterfaceRef x = xSMgr->createInstance( strService ); + + XInputStreamRef input( x , USR_QUERY ); + XOutputStreamRef output( x , USR_QUERY ); + + assert( output.is() ); + while( TRUE ) { + // basic read/write + Sequence<BYTE> seqWrite( 500 ); + output->writeBytes( seqWrite ); + + } + } + CATCH( IOException , e ) { + printf( "%s %s\n" , UStringToString( e.getName() , CHARSET_SYSTEM ).GetCharStr() , + UStringToString( e.Message , CHARSET_SYSTEM ).GetCharStr() ); + } + } +*/ + + + + +/** +* for external binding +* +* +**/ +XInterfaceRef OPipeTest_CreateInstance( const XMultiServiceFactoryRef & rSMgr ) THROWS((Exception)) +{ + OPipeTest *p = new OPipeTest( rSMgr ); + XInterfaceRef xService = *p; + return xService; +} + + + +Sequence<UString> OPipeTest_getSupportedServiceNames(void) THROWS( () ) +{ + Sequence<UString> aRet(1); + aRet.getArray()[0] = OPipeTest_getImplementationName(); + + return aRet; +} + +UString OPipeTest_getServiceName() THROWS( () ) +{ + return SERVICE_NAME; +} + +UString OPipeTest_getImplementationName() THROWS( () ) +{ + return IMPLEMENTATION_NAME; +} diff --git a/extensions/test/stm/testfactreg.cxx b/extensions/test/stm/testfactreg.cxx new file mode 100644 index 000000000000..a9fc2fa46d55 --- /dev/null +++ b/extensions/test/stm/testfactreg.cxx @@ -0,0 +1,203 @@ +/************************************************************************* + * + * $RCSfile: testfactreg.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 16:16:56 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ +#include <string.h> + +#include <usr/reflserv.hxx> // for EXTERN_SERVICE_CALLTYPE + +#include <usr/factoryhlp.hxx> +#include "testfactreg.hxx" + + +#ifndef _VOS_NO_NAMESPACE +using namespace vos; +using namespace usr; +#endif + +#ifdef __cplusplus +extern "C" +{ +#endif + +BOOL EXTERN_SERVICE_CALLTYPE exService_writeRegEntry( + const UNO_INTERFACE(XRegistryKey)* xUnoKey) + +{ + XRegistryKeyRef xKey; + uno2smart(xKey, *xUnoKey); + + UString str = UString( L"/" ) + OPipeTest_getImplementationName() + UString( L"/UNO/SERVICES" ); + XRegistryKeyRef xNewKey = xKey->createKey( str ); + xNewKey->createKey( OPipeTest_getServiceName() ); + + str = UString( L"/" ) + ODataStreamTest_getImplementationName(1) + UString( L"/UNO/SERVICES" ); + xNewKey = xKey->createKey( str ); + xNewKey->createKey( ODataStreamTest_getServiceName(1) ); + + str = UString( L"/" ) + ODataStreamTest_getImplementationName(2) + UString( L"/UNO/SERVICES" ); + xNewKey = xKey->createKey( str ); + xNewKey->createKey( ODataStreamTest_getServiceName(2) ); + + str = UString( L"/" ) + OObjectStreamTest_getImplementationName(1) + UString( L"/UNO/SERVICES" ); + xNewKey = xKey->createKey( str ); + xNewKey->createKey( OObjectStreamTest_getServiceName(1) ); + + str = UString( L"/" ) + OObjectStreamTest_getImplementationName(2) + UString( L"/UNO/SERVICES" ); + xNewKey = xKey->createKey( str ); + xNewKey->createKey( OObjectStreamTest_getServiceName(2) ); + + str = UString( L"/" ) + OMarkableOutputStreamTest_getImplementationName() + UString( L"/UNO/SERVICES" ); + xNewKey = xKey->createKey( str ); + xNewKey->createKey( OMarkableOutputStreamTest_getServiceName() ); + + str = UString( L"/" ) + OMarkableInputStreamTest_getImplementationName() + UString( L"/UNO/SERVICES" ); + xNewKey = xKey->createKey( str ); + xNewKey->createKey( OMarkableInputStreamTest_getServiceName() ); + + str = UString( L"/" ) + OMyPersistObject_getImplementationName() + UString( L"/UNO/SERVICES" ); + xNewKey = xKey->createKey( str ); + xNewKey->createKey( OMyPersistObject_getServiceName() ); + + return TRUE; +} + + +UNO_INTERFACE(XInterface) EXTERN_SERVICE_CALLTYPE exService_getFactory +( + const wchar_t* implementationName, + const UNO_INTERFACE(XMultiServiceFactory)* xUnoFact, + const UNO_INTERFACE(XRegistryKey)* +) +{ + UNO_INTERFACE(XInterface) xUnoRet = {0, 0}; + + XInterfaceRef xRet; + XMultiServiceFactoryRef xSMgr; + UString aImplementationName(implementationName); + + uno2smart(xSMgr, *xUnoFact); + + if (aImplementationName == OPipeTest_getImplementationName() ) + { + xRet = createSingleFactory( xSMgr, implementationName, + OPipeTest_CreateInstance, + OPipeTest_getSupportedServiceNames() ); + } + else if( aImplementationName == ODataStreamTest_getImplementationName(1) ) { + xRet = createSingleFactory( xSMgr , implementationName, + ODataStreamTest_CreateInstance, + ODataStreamTest_getSupportedServiceNames(1) ); + } + else if( aImplementationName == ODataStreamTest_getImplementationName(2) ) { + xRet = createSingleFactory( xSMgr , implementationName, + ODataStreamTest_CreateInstance, + ODataStreamTest_getSupportedServiceNames(2) ); + } + else if( aImplementationName == OObjectStreamTest_getImplementationName(1) ) { + xRet = createSingleFactory( xSMgr , implementationName, + OObjectStreamTest_CreateInstance, + OObjectStreamTest_getSupportedServiceNames(1) ); + } + else if( aImplementationName == OObjectStreamTest_getImplementationName(2) ) { + xRet = createSingleFactory( xSMgr , implementationName, + OObjectStreamTest_CreateInstance, + OObjectStreamTest_getSupportedServiceNames(2) ); + } + else if( aImplementationName == OMarkableOutputStreamTest_getImplementationName() ) { + xRet = createSingleFactory( xSMgr , implementationName, + OMarkableOutputStreamTest_CreateInstance, + OMarkableOutputStreamTest_getSupportedServiceNames() ); + } + else if( aImplementationName == OMarkableInputStreamTest_getImplementationName() ) { + xRet = createSingleFactory( xSMgr , implementationName, + OMarkableInputStreamTest_CreateInstance, + OMarkableInputStreamTest_getSupportedServiceNames() ); + } + else if( aImplementationName == OMyPersistObject_getImplementationName() ) { + xRet = createSingleFactory( xSMgr , implementationName, + OMyPersistObject_CreateInstance, + OMyPersistObject_getSupportedServiceNames() ); + } + if (xRet.is()) + { + smart2uno(xRet, xUnoRet); + } + + return xUnoRet; +} + +#ifdef __cplusplus +} +#endif + +Sequence<BYTE> createSeq( char * p ) +{ + Sequence<BYTE> seq( strlen( p )+1 ); + strcpy( (char * ) seq.getArray() , p ); + return seq; +} + +Sequence<BYTE> createIntSeq( INT32 i ) +{ + char pcCount[20]; + sprintf( pcCount , "%d" , i ); + return createSeq( pcCount ); +} + diff --git a/extensions/test/stm/testfactreg.hxx b/extensions/test/stm/testfactreg.hxx new file mode 100644 index 000000000000..25dcdea362f2 --- /dev/null +++ b/extensions/test/stm/testfactreg.hxx @@ -0,0 +1,144 @@ +/************************************************************************* + * + * $RCSfile: testfactreg.hxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 16:16:56 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ +XInterfaceRef OPipeTest_CreateInstance( const XMultiServiceFactoryRef & rSMgr ) THROWS((Exception)); +Sequence<UString> OPipeTest_getSupportedServiceNames(void) THROWS( () ); +UString OPipeTest_getServiceName() THROWS( () ); +UString OPipeTest_getImplementationName() THROWS( () ); + +XInterfaceRef ODataStreamTest_CreateInstance( const XMultiServiceFactoryRef & rSMgr ) THROWS((Exception)); +Sequence<UString> ODataStreamTest_getSupportedServiceNames( int i) THROWS( () ); +UString ODataStreamTest_getServiceName( int i) THROWS( ( ) ); +UString ODataStreamTest_getImplementationName( int i) THROWS( () ); + +XInterfaceRef OMarkableOutputStreamTest_CreateInstance( const XMultiServiceFactoryRef & rSMgr ) THROWS((Exception)); +Sequence<UString> OMarkableOutputStreamTest_getSupportedServiceNames(void) THROWS( () ); +UString OMarkableOutputStreamTest_getServiceName() THROWS( () ); +UString OMarkableOutputStreamTest_getImplementationName() THROWS( () ); + +XInterfaceRef OMarkableInputStreamTest_CreateInstance( const XMultiServiceFactoryRef & rSMgr ) THROWS((Exception)); +Sequence<UString> OMarkableInputStreamTest_getSupportedServiceNames(void) THROWS( () ); +UString OMarkableInputStreamTest_getServiceName() THROWS( () ); +UString OMarkableInputStreamTest_getImplementationName() THROWS( () ); + +XInterfaceRef OObjectStreamTest_CreateInstance( const XMultiServiceFactoryRef & rSMgr ) THROWS((Exception)); +Sequence<UString> OObjectStreamTest_getSupportedServiceNames( int i) THROWS( () ); +UString OObjectStreamTest_getServiceName( int i) THROWS( () ); +UString OObjectStreamTest_getImplementationName( int i) THROWS( () ); + +XInterfaceRef OMyPersistObject_CreateInstance( const XMultiServiceFactoryRef & rSMgr ) THROWS((Exception)); +Sequence<UString> OMyPersistObject_getSupportedServiceNames( ) THROWS( () ); +UString OMyPersistObject_getServiceName( ) THROWS( () ); +UString OMyPersistObject_getImplementationName( ) THROWS( () ); + +Sequence<BYTE> createSeq( char * p ); +Sequence<BYTE> createIntSeq( INT32 i ); + +#define BUILD_ERROR(expr, Message)\ + {\ + m_seqErrors.realloc( m_seqErrors.getLen() + 1 ); \ + m_seqExceptions.realloc( m_seqExceptions.getLen() + 1 ); \ + String str; \ + str += __FILE__;\ + str += " "; \ + str += "(" ; \ + str += __LINE__ ;\ + str += ")\n";\ + str += "[ " ; \ + str += #expr; \ + str += " ] : " ; \ + str += Message; \ + m_seqErrors.getArray()[ m_seqErrors.getLen()-1] = StringToOUString( str , CHARSET_SYSTEM ); \ + }\ + ((void)0) + + +#define WARNING_ASSERT(expr, Message) \ + if( ! (expr) ) { \ + m_seqWarnings.realloc( m_seqErrors.getLen() +1 ); \ + String str;\ + str += __FILE__;\ + str += " "; \ + str += "(" ; \ + str += __LINE__ ;\ + str += ")\n";\ + str += "[ " ; \ + str += #expr; \ + str += " ] : " ; \ + str += Message; \ + m_seqWarnings.getArray()[ m_seqWarnings.getLen()-1] = StringToOUString( str , CHARSET_SYSTEM ); \ + return; \ + }\ + ((void)0) + +#define ERROR_ASSERT(expr, Message) \ + if( ! (expr) ) { \ + BUILD_ERROR(expr, Message );\ + return; \ + }\ + ((void)0) + +#define ERROR_EXCEPTION_ASSERT(expr, Message, Exception) \ + if( !(expr)) { \ + BUILD_ERROR(expr,Message);\ + m_seqExceptions.getArray()[ m_seqExceptions.getLen()-1] = UsrAny( Exception );\ + return; \ + } \ + ((void)0) |