1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: datatest.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_extensions.hxx"
33 #include <smart/com/sun/star/test/XSimpleTest.hxx>
34 #include <smart/com/sun/star/io/XObjectOutputStream.hxx>
35 #include <smart/com/sun/star/io/XObjectInputStream.hxx>
36 #include <smart/com/sun/star/io/XActiveDataSink.hxx>
37 #include <smart/com/sun/star/io/XActiveDataSource.hxx>
38 #include <smart/com/sun/star/io/XConnectable.hxx>
39 #include <smart/com/sun/star/io/XMarkableStream.hxx>
41 #include <smart/com/sun/star/lang/XServiceInfo.hxx>
43 #include <smart/com/sun/star/beans/XPropertySet.hxx>
45 #include <usr/services.hxx>
46 #include <usr/factoryhlp.hxx>
48 #include <usr/reflserv.hxx> // for EXTERN_SERVICE_CALLTYPE
49 #include <usr/weak.hxx> // OWeakObject
51 #include <vos/conditn.hxx>
52 #include <vos/mutex.hxx>
53 #include <vos/thread.hxx>
55 #if OSL_DEBUG_LEVEL == 0
61 #include "testfactreg.hxx"
63 #ifndef _VOS_NO_NAMESPACE
68 #define DATASTREAM_TEST_MAX_HANDLE 1
71 * The following test class tests XDataInputStream and XDataOutputStream at equal terms,
72 * so when errors occur, it may be in either one implementation.
73 * The class also uses stardiv.uno.io.pipe. If problems occur, make sure to run also the
74 * pipe test routines ( test.com.sun.star.io.pipe ).
79 class ODataStreamTest
:
84 ODataStreamTest( const XMultiServiceFactoryRef
& rFactory
) : m_rFactory( rFactory
){}
86 public: // refcounting
87 BOOL
queryInterface( Uik aUik
, XInterfaceRef
& rOut
);
88 void acquire() { OWeakObject::acquire(); }
89 void release() { OWeakObject::release(); }
90 void* getImplementation(Reflection
*p
) { return OWeakObject::getImplementation(p
); }
93 virtual void testInvariant(const UString
& TestName
, const XInterfaceRef
& TestObject
)
94 THROWS( ( IllegalArgumentException
,
95 UsrSystemException
) );
97 virtual INT32
test( const UString
& TestName
,
98 const XInterfaceRef
& TestObject
,
99 INT32 hTestHandle
) THROWS( ( IllegalArgumentException
,
100 UsrSystemException
) );
102 virtual BOOL
testPassed(void) THROWS( ( UsrSystemException
) );
103 virtual Sequence
< UString
> getErrors(void) THROWS( (UsrSystemException
) );
104 virtual Sequence
< UsrAny
> getErrorExceptions(void) THROWS( (UsrSystemException
) );
105 virtual Sequence
< UString
> getWarnings(void) THROWS( (UsrSystemException
) );
108 void testSimple( const XDataInputStreamRef
& , const XDataOutputStreamRef
&);
111 Sequence
<UsrAny
> m_seqExceptions
;
112 Sequence
<UString
> m_seqErrors
;
113 Sequence
<UString
> m_seqWarnings
;
115 XMultiServiceFactoryRef m_rFactory
;
119 BOOL
ODataStreamTest::queryInterface( Uik uik
, XInterfaceRef
&rOut
)
121 if( XSimpleTest::getSmartUik() == uik
) {
122 rOut
= (XSimpleTest
*) this;
125 return OWeakObject::queryInterface( uik
, rOut
);
131 void ODataStreamTest::testInvariant( const UString
& TestName
, const XInterfaceRef
& TestObject
)
132 THROWS( ( IllegalArgumentException
,
133 UsrSystemException
) )
135 if( L
"com.sun.star.io.DataInputStream" == TestName
) {
136 XConnectableRef
connect( TestObject
, USR_QUERY
);
137 XActiveDataSinkRef
active( TestObject
, USR_QUERY
);
138 XInputStreamRef
input( TestObject
, USR_QUERY
);
139 XDataInputStreamRef
dataInput( TestObject
, USR_QUERY
);
141 WARNING_ASSERT( connect
.is(), "XConnectable cannot be queried" );
142 WARNING_ASSERT( active
.is() , "XActiveDataSink cannot be queried" );
143 ERROR_ASSERT( input
.is() , "XInputStream cannot be queried" );
144 ERROR_ASSERT( dataInput
.is() , "XDataInputStream cannot be queried" );
148 else if( L
"com.sun.star.io.DataInputStream" == TestName
) {
149 XConnectableRef
connect( TestObject
, USR_QUERY
);
150 XActiveDataSourceRef
active( TestObject
, USR_QUERY
);
151 XOutputStreamRef
output( TestObject
, USR_QUERY
);
152 XDataOutputStreamRef
dataOutput( TestObject
, USR_QUERY
);
154 WARNING_ASSERT( connect
.is(), "XConnectable cannot be queried" );
155 WARNING_ASSERT( active
.is() , "XActiveDataSink cannot be queried" );
156 ERROR_ASSERT( output
.is() , "XInputStream cannot be queried" );
157 ERROR_ASSERT( dataOutput
.is(), "XDataInputStream cannot be queried" );
161 XServiceInfoRef
info( TestObject
, USR_QUERY
);
162 ERROR_ASSERT( info
.is() , "XServiceInfo not supported !" );
165 ERROR_ASSERT( info
->supportsService( TestName
), "XServiceInfo test failed" );
166 ERROR_ASSERT( ! info
->supportsService( L
"bla bluzb" ) , "XServiceInfo test failed" );
172 INT32
ODataStreamTest::test( const UString
& TestName
,
173 const XInterfaceRef
& TestObject
,
174 INT32 hTestHandle
) THROWS( ( IllegalArgumentException
,
175 UsrSystemException
) )
177 if( L
"com.sun.star.io.DataInputStream" == TestName
||
178 L
"com.sun.star.io.DataOutputStream" == TestName
) {
181 if( 0 == hTestHandle
) {
182 testInvariant( TestName
, TestObject
);
185 XActiveDataSinkRef
rSink( TestObject
, USR_QUERY
);
186 XActiveDataSourceRef
rSource( TestObject
, USR_QUERY
);
188 XDataInputStreamRef
rInput( TestObject
, USR_QUERY
);
189 XDataOutputStreamRef
rOutput( TestObject
, USR_QUERY
);
192 XInterfaceRef x
= m_rFactory
->createInstance( L
"com.sun.star.io.Pipe");
194 XInputStreamRef
rPipeInput( x
, USR_QUERY
);
195 XOutputStreamRef
rPipeOutput( x
, USR_QUERY
);
198 x
= m_rFactory
->createInstance( L
"com.sun.star.io.DataInputStream" );
199 x
->queryInterface( XDataInputStream::getSmartUik() , rInput
);
200 x
->queryInterface( XActiveDataSink::getSmartUik() , rSink
);
202 else if ( !rSource
.is() ) {
204 x
= m_rFactory
->createInstance( L
"com.sun.star.io.DataOutputStream" );
205 x
->queryInterface( XDataOutputStream::getSmartUik() , rOutput
);
206 x
->queryInterface( XActiveDataSource::getSmartUik() , rSource
);
209 assert( rPipeInput
.is() );
210 assert( rPipeOutput
.is() );
211 rSink
->setInputStream( rPipeInput
);
212 rSource
->setOutputStream( rPipeOutput
);
214 assert( rSink
->getInputStream().is() );
215 assert( rSource
->getOutputStream().is() );
217 if( 1 == hTestHandle
) {
218 testSimple( rInput
, rOutput
);
222 catch( Exception
& e
) {
223 BUILD_ERROR( 0 , UStringToString( e
.getName() , CHARSET_SYSTEM
).GetCharStr() );
226 BUILD_ERROR( 0 , "unknown exception (Exception is not base class)" );
231 if( hTestHandle
>= 2) {
232 // all tests finished.
237 BUILD_ERROR( 0 , "service not supported by test." );
244 BOOL
ODataStreamTest::testPassed(void) THROWS( (UsrSystemException
) )
246 return m_seqErrors
.getLen() == 0;
250 Sequence
< UString
> ODataStreamTest::getErrors(void) THROWS( (UsrSystemException
) )
256 Sequence
< UsrAny
> ODataStreamTest::getErrorExceptions(void) THROWS( (UsrSystemException
) )
258 return m_seqExceptions
;
262 Sequence
< UString
> ODataStreamTest::getWarnings(void) THROWS( (UsrSystemException
) )
264 return m_seqWarnings
;
267 void ODataStreamTest::testSimple( const XDataInputStreamRef
&rInput
,
268 const XDataOutputStreamRef
&rOutput
)
270 rOutput
->writeLong( 0x34ff3c );
271 rOutput
->writeLong( 0x34ff3d );
273 ERROR_ASSERT( 0x34ff3c == rInput
->readLong() , "long read/write mismatch" );
274 ERROR_ASSERT( 0x34ff3d == rInput
->readLong() , "long read/write mismatch" );
276 rOutput
->writeByte( 0x87 );
277 ERROR_ASSERT( 0x87 == rInput
->readByte() , "byte read/write mismatch" );
279 rOutput
->writeBoolean( 25 );
280 ERROR_ASSERT( rInput
->readBoolean() , "boolean read/write mismatch" );
282 rOutput
->writeBoolean( FALSE
);
283 ERROR_ASSERT( ! rInput
->readBoolean() , "boolean read/write mismatch" );
285 rOutput
->writeFloat( (float) 42.42 );
286 ERROR_ASSERT( rInput
->readFloat() == ((float)42.42) , "float read/write mismatch" );
288 rOutput
->writeDouble( (double) 42.42 );
289 ERROR_ASSERT( rInput
->readDouble() == 42.42 , "double read/write mismatch" );
291 rOutput
->writeUTF( L
"Live long and prosper !" );
292 ERROR_ASSERT( rInput
->readUTF() == L
"Live long and prosper !" ,
293 "UTF read/write mismatch" );
295 Sequence
<wchar_t> wc(0x10001);
296 for( int i
= 0 ; i
< 0x10000 ; i
++ ) {
297 wc
.getArray()[i
] = L
'c';
299 wc
.getArray()[0x10000] = 0;
300 UString
str( wc
.getArray() , 0x10000 );
301 rOutput
->writeUTF( str
);
302 ERROR_ASSERT( rInput
->readUTF() == str
, "error reading 64k block" );
304 rOutput
->closeOutput();
307 ERROR_ASSERT( 0 , "eof-exception does not occur !" );
309 catch ( IOException
& e
){
314 ERROR_ASSERT( 0 , "wrong exception after reading beyond eof" );
317 ERROR_ASSERT( ! rInput
->readBytes( Sequence
<BYTE
> (1) , 1 ),
318 "stream must be on eof !" );
320 rInput
->closeInput();
323 rOutput
->writeByte( 1 );
324 ERROR_ASSERT( 0 , "writing still possible though chain must be interrupted" );
326 catch( IOException
& e
)
332 ERROR_ASSERT( 0 , "IOException expected, but another exception was thrown" );
340 * for external binding
344 XInterfaceRef
ODataStreamTest_CreateInstance( const XMultiServiceFactoryRef
& rSMgr
) THROWS((Exception
))
346 ODataStreamTest
*p
= new ODataStreamTest( rSMgr
);
347 XInterfaceRef xService
= *p
;
351 Sequence
<UString
> ODataStreamTest_getSupportedServiceNames( int i
) THROWS( () )
353 Sequence
<UString
> aRet(1);
355 aRet
.getArray()[0] = ODataStreamTest_getImplementationName( i
);
361 UString
ODataStreamTest_getServiceName( int i
) THROWS( () )
364 return L
"test.com.sun.star.io.DataInputStream";
367 return L
"test.com.sun.star.io.DataOutputStream";
371 UString
ODataStreamTest_getImplementationName( int i
) THROWS( () )
374 return L
"test.com.sun.star.comp.extensions.stm.DataInputStream";
377 return L
"test.com.sun.star.comp.extensions.stm.DataOutputStream";
382 /**------------------------------------------------------
388 *------------------------------------------------------*/
389 class MyPersistObject
:
390 public XPersistObject
,
395 MyPersistObject( ) : m_sServiceName( OMyPersistObject_getServiceName() )
397 MyPersistObject( const UString
& sServiceName
) : m_sServiceName( sServiceName
)
403 BOOL
queryInterface( Uik aUik
, XInterfaceRef
& rOut
);
404 void acquire() { OWeakObject::acquire(); }
405 void release() { OWeakObject::release(); }
406 void* getImplementation(Reflection
*p
) { return OWeakObject::getImplementation(p
); }
409 virtual UString
getServiceName(void) const THROWS( (UsrSystemException
) );
410 virtual void write(const XObjectOutputStreamRef
& OutStream
) THROWS( (IOException
, UsrSystemException
) );
411 virtual void read(const XObjectInputStreamRef
& InStream
) THROWS( (IOException
, UsrSystemException
) );
415 virtual XPropertySetInfoRef
getPropertySetInfo(void) const THROWS( (UsrSystemException
) );
416 virtual void setPropertyValue(const UString
& aPropertyName
, const UsrAny
& aValue
)
417 THROWS( ( UnknownPropertyException
,
418 PropertyVetoException
,
419 IllegalArgumentException
,
420 WrappedTargetException
,
421 UsrSystemException
) );
422 virtual UsrAny
getPropertyValue(const UString
& PropertyName
) const
423 THROWS( ( UnknownPropertyException
,
424 WrappedTargetException
,
425 UsrSystemException
) );
426 virtual void addPropertyChangeListener( const UString
& aPropertyName
,
427 const XPropertyChangeListenerRef
& xListener
)
428 THROWS( ( UnknownPropertyException
,
429 WrappedTargetException
,
430 UsrSystemException
) );
431 virtual void removePropertyChangeListener( const UString
& aPropertyName
,
432 const XPropertyChangeListenerRef
& aListener
)
433 THROWS( ( UnknownPropertyException
,
434 WrappedTargetException
,
435 UsrSystemException
) );
436 virtual void addVetoableChangeListener( const UString
& PropertyName
,
437 const XVetoableChangeListenerRef
& aListener
)
438 THROWS( ( UnknownPropertyException
,
439 WrappedTargetException
,
440 UsrSystemException
) );
441 virtual void removeVetoableChangeListener( const UString
& PropertyName
,
442 const XVetoableChangeListenerRef
& aListener
)
443 THROWS( ( UnknownPropertyException
,
444 WrappedTargetException
,
445 UsrSystemException
) );
455 XPersistObjectRef m_ref
;
456 UString m_sServiceName
;
461 XPropertySetInfoRef
MyPersistObject::getPropertySetInfo(void) const THROWS( (UsrSystemException
) )
463 return XPropertySetInfoRef();
466 void MyPersistObject::setPropertyValue(const UString
& aPropertyName
, const UsrAny
& aValue
)
467 THROWS( ( UnknownPropertyException
,
468 PropertyVetoException
,
469 IllegalArgumentException
,
470 WrappedTargetException
,
471 UsrSystemException
) )
473 if( L
"long" == aPropertyName
) {
474 m_l
= aValue
.getINT32();
476 else if ( L
"float" == aPropertyName
) {
477 m_f
= aValue
.getFloat();
479 else if( L
"double" == aPropertyName
) {
480 m_d
= aValue
.getDouble();
482 else if( L
"bool" == aPropertyName
) {
483 m_b
= aValue
.getBOOL();
485 else if( L
"byte" == aPropertyName
) {
486 m_byte
= aValue
.getBYTE();
488 else if( L
"char" == aPropertyName
) {
489 m_c
= aValue
.getChar();
491 else if( L
"string" == aPropertyName
) {
492 m_s
= aValue
.getString();
494 else if( L
"object" == aPropertyName
) {
495 if( aValue
.getReflection() == XPersistObject_getReflection() ) {
496 XPersistObjectRef
*pRef
= (XPersistObjectRef
*) aValue
.get();
512 UsrAny
MyPersistObject::getPropertyValue(const UString
& aPropertyName
) const
513 THROWS( ( UnknownPropertyException
,
514 WrappedTargetException
,
515 UsrSystemException
) )
518 if( L
"long" == aPropertyName
) {
519 aValue
.setINT32( m_l
);
521 else if ( L
"float" == aPropertyName
) {
522 aValue
.setFloat( m_f
);
524 else if( L
"double" == aPropertyName
) {
525 aValue
.setDouble( m_d
);
527 else if( L
"bool" == aPropertyName
) {
528 aValue
.setBOOL( m_b
);
530 else if( L
"byte" == aPropertyName
) {
531 aValue
.setBYTE( m_byte
);
533 else if( L
"char" == aPropertyName
) {
534 aValue
.setChar( m_c
);
536 else if( L
"string" == aPropertyName
) {
537 aValue
.setString( m_s
);
539 else if( L
"object" == aPropertyName
) {
540 aValue
.set( &m_ref
, XPersistObject_getReflection() );
546 void MyPersistObject::addPropertyChangeListener( const UString
& aPropertyName
,
547 const XPropertyChangeListenerRef
& xListener
)
548 THROWS( ( UnknownPropertyException
,
549 WrappedTargetException
,
550 UsrSystemException
) )
555 void MyPersistObject::removePropertyChangeListener( const UString
& aPropertyName
,
556 const XPropertyChangeListenerRef
& aListener
)
557 THROWS( ( UnknownPropertyException
,
558 WrappedTargetException
,
559 UsrSystemException
) )
562 void MyPersistObject::addVetoableChangeListener(const UString
& PropertyName
,
563 const XVetoableChangeListenerRef
& aListener
)
564 THROWS( ( UnknownPropertyException
,
565 WrappedTargetException
,
566 UsrSystemException
) )
571 void MyPersistObject::removeVetoableChangeListener( const UString
& PropertyName
,
572 const XVetoableChangeListenerRef
& aListener
)
573 THROWS( ( UnknownPropertyException
,
574 WrappedTargetException
,
575 UsrSystemException
) )
582 BOOL
MyPersistObject::queryInterface( Uik aUik
, XInterfaceRef
&rOut
)
584 if( XPersistObject::getSmartUik() == aUik
) {
585 rOut
= ( XPersistObject
* ) this;
587 else if( XPropertySet::getSmartUik() == aUik
) {
588 rOut
= ( XPropertySet
* ) this;
591 return OWeakObject::queryInterface( aUik
, rOut
);
596 UString
MyPersistObject::getServiceName() const THROWS( (UsrSystemException
) )
598 return m_sServiceName
;
601 void MyPersistObject::write( const XObjectOutputStreamRef
& rOut
)
602 THROWS( (IOException
,UsrSystemException
))
604 rOut
->writeLong( m_l
);
605 rOut
->writeFloat( m_f
);
606 rOut
->writeDouble( m_d
);
607 rOut
->writeBoolean( m_b
);
608 rOut
->writeByte( m_byte
);
609 rOut
->writeChar( m_c
);
610 rOut
->writeUTF( m_s
);
611 rOut
->writeObject( m_ref
);
615 void MyPersistObject::read( const XObjectInputStreamRef
& rIn
)
616 THROWS( (IOException
, UsrSystemException
) )
618 m_l
= rIn
->readLong();
619 m_f
= rIn
->readFloat();
620 m_d
= rIn
->readDouble();
621 m_b
= rIn
->readBoolean();
622 m_byte
= rIn
->readByte();
623 m_c
= rIn
->readChar();
624 m_s
= rIn
->readUTF();
625 m_ref
= rIn
->readObject();
628 XInterfaceRef
OMyPersistObject_CreateInstance( const XMultiServiceFactoryRef
& rSMgr
)
631 MyPersistObject
*p
= new MyPersistObject( );
632 XInterfaceRef xService
= *p
;
636 Sequence
<UString
> OMyPersistObject_getSupportedServiceNames( ) THROWS( () )
638 Sequence
<UString
> aRet(1);
639 aRet
.getArray()[0] = OMyPersistObject_getImplementationName();
643 UString
OMyPersistObject_getServiceName( ) THROWS( () )
645 return L
"test.com.sun.star.io.PersistTest";
648 UString
OMyPersistObject_getImplementationName( ) THROWS( () )
650 return L
"test.com.sun.star.io.PersistTest";
654 // ---------------------------------------------
655 // -----------------------------------------------
656 class OObjectStreamTest
:
657 public ODataStreamTest
660 OObjectStreamTest( const XMultiServiceFactoryRef
&r
) : ODataStreamTest(r
) {}
661 public: // refcounting
662 BOOL
queryInterface( Uik aUik
, XInterfaceRef
& rOut
);
665 virtual void testInvariant(const UString
& TestName
, const XInterfaceRef
& TestObject
)
666 THROWS( ( IllegalArgumentException
,
667 UsrSystemException
) );
669 virtual INT32
test( const UString
& TestName
,
670 const XInterfaceRef
& TestObject
,
671 INT32 hTestHandle
) THROWS( ( IllegalArgumentException
,
672 UsrSystemException
) );
676 void OObjectStreamTest::testObject( const XObjectOutputStreamRef
&rOut
,
677 const XObjectInputStreamRef
&rIn
);
685 BOOL
OObjectStreamTest::queryInterface( Uik uik
, XInterfaceRef
&rOut
)
687 if( XSimpleTest::getSmartUik() == uik
) {
688 rOut
= (XSimpleTest
*) this;
691 return ODataStreamTest::queryInterface( uik
, rOut
);
697 void OObjectStreamTest::testInvariant( const UString
& TestName
, const XInterfaceRef
& TestObject
)
698 THROWS( ( IllegalArgumentException
,
699 UsrSystemException
) )
703 if( L
"com.sun.star.io.ObjectInputStream" == TestName
) {
704 ODataStreamTest::testInvariant( TestName
, TestObject
);
705 XObjectInputStreamRef
dataInput( TestObject
, USR_QUERY
);
706 XMarkableStreamRef
markable( TestObject
, USR_QUERY
);
707 ERROR_ASSERT( dataInput
.is() , "XObjectInputStream cannot be queried" );
708 ERROR_ASSERT( markable
.is() , "XMarkableStream cannot be queried" );
710 else if( L
"com.sun.star.io.ObjectOutputStream" == TestName
) {
711 ODataStreamTest::testInvariant( TestName
, TestObject
);
712 XMarkableStreamRef
markable( TestObject
, USR_QUERY
);
713 XObjectOutputStreamRef
dataOutput( TestObject
, USR_QUERY
);
714 ERROR_ASSERT( dataOutput
.is(), "XObjectOutputStream cannot be queried" );
715 ERROR_ASSERT( markable
.is() , "XMarkableStream cannot be queried" );
718 XServiceInfoRef
info( TestObject
, USR_QUERY
);
719 ERROR_ASSERT( info
.is() , "XServiceInfo not supported !" );
722 ERROR_ASSERT( info
->supportsService( TestName
), "XServiceInfo test failed" );
723 ERROR_ASSERT( ! info
->supportsService( L
"bla bluzb" ) , "XServiceInfo test failed" );
728 INT32
OObjectStreamTest::test( const UString
& TestName
,
729 const XInterfaceRef
& TestObject
,
730 INT32 hTestHandle
) THROWS( ( IllegalArgumentException
,
731 UsrSystemException
) )
733 if( L
"com.sun.star.io.ObjectInputStream" == TestName
||
734 L
"com.sun.star.io.ObjectOutputStream" == TestName
) {
737 if( 0 == hTestHandle
) {
738 testInvariant( TestName
, TestObject
);
740 else if( DATASTREAM_TEST_MAX_HANDLE
>= hTestHandle
) {
741 INT32 hOldHandle
= hTestHandle
;
742 hTestHandle
= ODataStreamTest::test( L
"com.sun.star.io.DataInputStream" ,
743 TestObject
, hTestHandle
);
744 if( hTestHandle
== -1 ){
745 hTestHandle
= hOldHandle
;
750 XActiveDataSinkRef
rSink( TestObject
, USR_QUERY
);
751 XActiveDataSourceRef
rSource( TestObject
, USR_QUERY
);
753 XObjectInputStreamRef
rInput( TestObject
, USR_QUERY
);
754 XObjectOutputStreamRef
rOutput( TestObject
, USR_QUERY
);
757 XInterfaceRef x
= m_rFactory
->createInstance( L
"com.sun.star.io.Pipe");
759 XInputStreamRef
rPipeInput( x
, USR_QUERY
);
760 XOutputStreamRef
rPipeOutput( x
, USR_QUERY
);
762 x
= m_rFactory
->createInstance( L
"com.sun.star.io.MarkableInputStream" );
763 XInputStreamRef
markableInput( x
, USR_QUERY
);
764 XActiveDataSinkRef
markableSink( x
, USR_QUERY
);
766 x
= m_rFactory
->createInstance( L
"com.sun.star.io.MarkableOutputStream" );
767 XOutputStreamRef
markableOutput( x
, USR_QUERY
);
768 XActiveDataSourceRef
markableSource( x
, USR_QUERY
);
770 assert( markableInput
.is() );
771 assert( markableOutput
.is() );
772 assert( markableSink
.is() );
773 assert( markableSource
.is() );
775 markableSink
->setInputStream( rPipeInput
);
776 markableSource
->setOutputStream( rPipeOutput
);
779 x
= m_rFactory
->createInstance( L
"com.sun.star.io.ObjectInputStream" );
780 x
->queryInterface( XObjectInputStream::getSmartUik() , rInput
);
781 x
->queryInterface( XActiveDataSink::getSmartUik() , rSink
);
783 else if ( !rSource
.is() ) {
784 x
= m_rFactory
->createInstance( L
"com.sun.star.io.ObjectOutputStream" );
785 x
->queryInterface( XObjectOutputStream::getSmartUik() , rOutput
);
786 x
->queryInterface( XActiveDataSource::getSmartUik() , rSource
);
789 assert( rPipeInput
.is() );
790 assert( rPipeOutput
.is() );
792 rSink
->setInputStream( markableInput
);
793 rSource
->setOutputStream( markableOutput
);
795 assert( rSink
->getInputStream().is() );
796 assert( rSource
->getOutputStream().is() );
798 if( 1 + DATASTREAM_TEST_MAX_HANDLE
== hTestHandle
) {
799 testObject( rOutput
, rInput
);
801 rInput
->closeInput();
802 rOutput
->closeOutput();
806 catch( Exception
& e
) {
807 BUILD_ERROR( 0 , UStringToString( e
.getName() , CHARSET_SYSTEM
).GetCharStr() );
810 BUILD_ERROR( 0 , "unknown exception (Exception is not base class)" );
815 if( hTestHandle
> 1 +DATASTREAM_TEST_MAX_HANDLE
) {
816 // all tests finished.
821 BUILD_ERROR( 0 , "service not supported by test." );
827 BOOL
compareMyPropertySet( XPropertySetRef
&r1
, XPropertySetRef
&r2
)
831 if( r1
->getPropertyValue( L
"long" ).getReflection() == Void_getReflection() ||
832 r2
->getPropertyValue( L
"long" ).getReflection() == Void_getReflection() ) {
834 // one of the objects is not the correct propertyset !
838 b
= b
&& ( r1
->getPropertyValue( L
"long" ).getINT32() ==
839 r2
->getPropertyValue( L
"long" ).getINT32() );
841 b
= b
&& ( r1
->getPropertyValue( L
"float" ).getFloat() ==
842 r2
->getPropertyValue( L
"float" ).getFloat() );
844 b
= b
&& ( r1
->getPropertyValue( L
"double" ).getDouble() ==
845 r2
->getPropertyValue( L
"double" ).getDouble() );
847 b
= b
&& ( r1
->getPropertyValue( L
"bool" ).getBOOL() ==
848 r2
->getPropertyValue( L
"bool" ).getBOOL() );
850 b
= b
&& ( r1
->getPropertyValue( L
"byte" ).getBYTE() ==
851 r2
->getPropertyValue( L
"byte" ).getBYTE() );
853 b
= b
&& ( r1
->getPropertyValue( L
"char" ).getChar() ==
854 r2
->getPropertyValue( L
"char" ).getChar() );
856 b
= b
&& ( r1
->getPropertyValue( L
"string" ).getString() ==
857 r2
->getPropertyValue( L
"string" ).getString() );
859 UsrAny o1
= r1
->getPropertyValue( L
"object" );
860 UsrAny o2
= r2
->getPropertyValue( L
"object" );
862 if( o1
.getReflection() == XPersistObject_getReflection() ) {
864 if( o2
.getReflection() == XPersistObject_getReflection() ) {
865 XPersistObjectRef rPersist1
= *((XPersistObjectRef
*) o1
.get());
866 XPersistObjectRef rPersist2
= *((XPersistObjectRef
*) o2
.get());
867 XPropertySetRef
rProp1( rPersist1
, USR_QUERY
);
868 XPropertySetRef
rProp2( rPersist2
, USR_QUERY
);
870 if( rProp1
.is() && rProp2
.is() && ! ( rProp1
== rProp2
)
871 &&( rProp1
!= r1
)) {
872 compareMyPropertySet( rProp1
, rProp2
);
880 if( o2
.getReflection() == XPersistObject_getReflection() ) {
888 void OObjectStreamTest::testObject( const XObjectOutputStreamRef
&rOut
,
889 const XObjectInputStreamRef
&rIn
)
891 ERROR_ASSERT( rOut
.is() , "no objectOutputStream" );
892 ERROR_ASSERT( rIn
.is() , "no objectInputStream" );
894 XMultiServiceFactoryRef xProv
= getProcessServiceManager();
895 ERROR_ASSERT( xProv
.is() , "no global service manager" );
898 // tests, if saving an object with an unknown service name allows
899 // reading the data behind the object !
901 XInterfaceRef x
= * new MyPersistObject( L
"bla blubs" );
903 XPersistObjectRef
persistRef( x
, USR_QUERY
);
904 ERROR_ASSERT( persistRef
.is() , "couldn't instantiate PersistTest object" );
906 rOut
->writeObject( persistRef
);
907 rOut
->writeLong( (INT32
) 0xdeadbeef );
909 ERROR_ASSERT( 0 != rIn
->available() , "no data arrived at input" );
913 XPersistObjectRef xReadPersistRef
= rIn
->readObject();
914 ERROR_ASSERT( 0 , "expected exception not thrown" );
916 catch( IOException
& e
)
921 ERROR_ASSERT( (INT32
) 0xdeadbeef == rIn
->readLong() ,
922 "wrong data after object with unknown service name." );
926 XInterfaceRef x
= xProv
->createInstance(L
"test.com.sun.star.io.PersistTest");
927 XPersistObjectRef
persistRef( x
, USR_QUERY
);
929 ERROR_ASSERT( persistRef
.is() , "couldn't instantiate PersistTest object" );
931 XPropertySetRef
rProp( persistRef
, USR_QUERY
);
932 ERROR_ASSERT( rProp
.is() , "test object is no property set " );
935 any
.setINT32( 0x83482 );
936 rProp
->setPropertyValue( L
"long" , any
);
938 any
.setFloat( 42.23 );
939 rProp
->setPropertyValue( L
"float" , any
);
941 any
.setDouble( 233.321412 );
942 rProp
->setPropertyValue( L
"double" , any
);
945 rProp
->setPropertyValue( L
"bool" , any
);
948 rProp
->setPropertyValue( L
"byte" , any
);
951 rProp
->setPropertyValue( L
"char" , any
);
953 any
.setString( L
"hi du !" );
954 rProp
->setPropertyValue( L
"string" , any
);
956 any
.set( &persistRef
, XPersistObject_getReflection() ); // try a self reference
957 rProp
->setPropertyValue( L
"object" , any
);
960 rOut
->writeObject( persistRef
);
961 ERROR_ASSERT( 0 != rIn
->available() , "no data arrived at input" );
962 XPersistObjectRef xReadPersistRef
= rIn
->readObject( );
964 XPropertySetRef
rPropRead( xReadPersistRef
, USR_QUERY
);
965 ERROR_ASSERT( compareMyPropertySet( rProp
, rPropRead
) , "objects has not been read properly !" );
967 // destroy selfreferences
968 rProp
->setPropertyValue( L
"object", UsrAny() );
969 rPropRead
->setPropertyValue( L
"object", UsrAny() );
973 XMarkableStreamRef
markableOut( rOut
, USR_QUERY
);
974 ERROR_ASSERT( markableOut
.is() , "markable stream cannot be queried" );
976 // do the same thing multiple times to check if
977 // buffering and marks work correctly
978 for( int i
= 0 ; i
< 2000 ; i
++ ) {
980 XInterfaceRef x
= xProv
->createInstance(L
"test.com.sun.star.io.PersistTest");
981 XPersistObjectRef
persistRef( x
, USR_QUERY
);
983 XPropertySetRef
rProp( persistRef
, USR_QUERY
);
984 ERROR_ASSERT( rProp
.is() , "test object is no property set " );
987 any
.setINT32( 0x83482 );
988 rProp
->setPropertyValue( L
"long" , any
);
990 any
.setFloat( 42.23 );
991 rProp
->setPropertyValue( L
"float" , any
);
993 any
.setDouble( 233.321412 );
994 rProp
->setPropertyValue( L
"double" , any
);
997 rProp
->setPropertyValue( L
"bool" , any
);
1000 rProp
->setPropertyValue( L
"byte" , any
);
1003 rProp
->setPropertyValue( L
"char" , any
);
1005 any
.setString( L
"hi du !" );
1006 rProp
->setPropertyValue( L
"string" , any
);
1009 x
= xProv
->createInstance(L
"test.com.sun.star.io.PersistTest");
1010 XPersistObjectRef
persist2ndRef( x
, USR_QUERY
);
1013 // Note : persist2ndRef contains coincident values, but also coincident values must be
1015 any
.set( &persist2ndRef
, XPersistObject_getReflection() ); // try a self reference
1016 rProp
->setPropertyValue( L
"object" , any
);
1018 // simply test, if markable operations and object operations do not interfere
1019 INT32 nMark
= markableOut
->createMark();
1021 // do read and write
1022 rOut
->writeObject( persistRef
);
1024 // further markable tests !
1025 INT32 nOffset
= markableOut
->offsetToMark( nMark
);
1026 markableOut
->jumpToMark( nMark
);
1027 markableOut
->deleteMark( nMark
);
1028 markableOut
->jumpToFurthest();
1034 ERROR_ASSERT( 0 != rIn
->available() , "no data arrived at input" );
1035 XPersistObjectRef xReadPersistRef
= rIn
->readObject( );
1037 XPropertySetRef
rProp1( persistRef
, USR_QUERY
);
1038 XPropertySetRef
rProp2( xReadPersistRef
, USR_QUERY
);
1039 ERROR_ASSERT( compareMyPropertySet( rProp1
, rProp2
) , "objects has not been read properly !" );
1045 XInterfaceRef
OObjectStreamTest_CreateInstance( const XMultiServiceFactoryRef
& rSMgr
) THROWS((Exception
))
1047 OObjectStreamTest
*p
= new OObjectStreamTest( rSMgr
);
1048 XInterfaceRef xService
= *p
;
1052 Sequence
<UString
> OObjectStreamTest_getSupportedServiceNames( int i
) THROWS( () )
1054 Sequence
<UString
> aRet(1);
1055 aRet
.getArray()[0] = OObjectStreamTest_getImplementationName( i
);
1059 UString
OObjectStreamTest_getServiceName( int i
) THROWS( () )
1062 return L
"test.com.sun.star.io.ObjectInputStream";
1065 return L
"test.com.sun.star.io.ObjectOutputStream";
1069 UString
OObjectStreamTest_getImplementationName( int i
) THROWS( () )
1072 return L
"test.com.sun.star.comp.extensions.stm.ObjectInputStream";
1075 return L
"test.com.sun.star.comp.extensions.stm.ObjectOutputStream";