1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
29 // MARKER(update_precomp.py): autogen include statement, do not remove
30 #include "precompiled_extensions.hxx"
31 #include <smart/com/sun/star/test/XSimpleTest.hxx>
32 #include <smart/com/sun/star/io/XObjectOutputStream.hxx>
33 #include <smart/com/sun/star/io/XObjectInputStream.hxx>
34 #include <smart/com/sun/star/io/XActiveDataSink.hxx>
35 #include <smart/com/sun/star/io/XActiveDataSource.hxx>
36 #include <smart/com/sun/star/io/XConnectable.hxx>
37 #include <smart/com/sun/star/io/XMarkableStream.hxx>
39 #include <smart/com/sun/star/lang/XServiceInfo.hxx>
41 #include <smart/com/sun/star/beans/XPropertySet.hxx>
43 #include <usr/services.hxx>
44 #include <usr/factoryhlp.hxx>
46 #include <usr/reflserv.hxx> // for EXTERN_SERVICE_CALLTYPE
47 #include <usr/weak.hxx> // OWeakObject
49 #include <osl/conditn.hxx>
50 #include <osl/mutex.hxx>
51 #include <osl/thread.hxx>
55 #include "testfactreg.hxx"
57 #ifndef _VOS_NO_NAMESPACE
61 #define DATASTREAM_TEST_MAX_HANDLE 1
64 * The following test class tests XDataInputStream and XDataOutputStream at equal terms,
65 * so when errors occur, it may be in either one implementation.
66 * The class also uses stardiv.uno.io.pipe. If problems occur, make sure to run also the
67 * pipe test routines ( test.com.sun.star.io.pipe ).
72 class ODataStreamTest
:
77 ODataStreamTest( const XMultiServiceFactoryRef
& rFactory
) : m_rFactory( rFactory
){}
79 public: // refcounting
80 BOOL
queryInterface( Uik aUik
, XInterfaceRef
& rOut
);
81 void acquire() { OWeakObject::acquire(); }
82 void release() { OWeakObject::release(); }
83 void* getImplementation(Reflection
*p
) { return OWeakObject::getImplementation(p
); }
86 virtual void testInvariant(const UString
& TestName
, const XInterfaceRef
& TestObject
)
87 THROWS( ( IllegalArgumentException
,
88 UsrSystemException
) );
90 virtual INT32
test( const UString
& TestName
,
91 const XInterfaceRef
& TestObject
,
92 INT32 hTestHandle
) THROWS( ( IllegalArgumentException
,
93 UsrSystemException
) );
95 virtual BOOL
testPassed(void) THROWS( ( UsrSystemException
) );
96 virtual Sequence
< UString
> getErrors(void) THROWS( (UsrSystemException
) );
97 virtual Sequence
< UsrAny
> getErrorExceptions(void) THROWS( (UsrSystemException
) );
98 virtual Sequence
< UString
> getWarnings(void) THROWS( (UsrSystemException
) );
101 void testSimple( const XDataInputStreamRef
& , const XDataOutputStreamRef
&);
104 Sequence
<UsrAny
> m_seqExceptions
;
105 Sequence
<UString
> m_seqErrors
;
106 Sequence
<UString
> m_seqWarnings
;
108 XMultiServiceFactoryRef m_rFactory
;
112 BOOL
ODataStreamTest::queryInterface( Uik uik
, XInterfaceRef
&rOut
)
114 if( XSimpleTest::getSmartUik() == uik
) {
115 rOut
= (XSimpleTest
*) this;
118 return OWeakObject::queryInterface( uik
, rOut
);
124 void ODataStreamTest::testInvariant( const UString
& TestName
, const XInterfaceRef
& TestObject
)
125 THROWS( ( IllegalArgumentException
,
126 UsrSystemException
) )
128 if( L
"com.sun.star.io.DataInputStream" == TestName
) {
129 XConnectableRef
connect( TestObject
, USR_QUERY
);
130 XActiveDataSinkRef
active( TestObject
, USR_QUERY
);
131 XInputStreamRef
input( TestObject
, USR_QUERY
);
132 XDataInputStreamRef
dataInput( TestObject
, USR_QUERY
);
134 WARNING_ASSERT( connect
.is(), "XConnectable cannot be queried" );
135 WARNING_ASSERT( active
.is() , "XActiveDataSink cannot be queried" );
136 ERROR_ASSERT( input
.is() , "XInputStream cannot be queried" );
137 ERROR_ASSERT( dataInput
.is() , "XDataInputStream cannot be queried" );
141 else if( L
"com.sun.star.io.DataInputStream" == TestName
) {
142 XConnectableRef
connect( TestObject
, USR_QUERY
);
143 XActiveDataSourceRef
active( TestObject
, USR_QUERY
);
144 XOutputStreamRef
output( TestObject
, USR_QUERY
);
145 XDataOutputStreamRef
dataOutput( TestObject
, USR_QUERY
);
147 WARNING_ASSERT( connect
.is(), "XConnectable cannot be queried" );
148 WARNING_ASSERT( active
.is() , "XActiveDataSink cannot be queried" );
149 ERROR_ASSERT( output
.is() , "XInputStream cannot be queried" );
150 ERROR_ASSERT( dataOutput
.is(), "XDataInputStream cannot be queried" );
154 XServiceInfoRef
info( TestObject
, USR_QUERY
);
155 ERROR_ASSERT( info
.is() , "XServiceInfo not supported !" );
158 ERROR_ASSERT( info
->supportsService( TestName
), "XServiceInfo test failed" );
159 ERROR_ASSERT( ! info
->supportsService( L
"bla bluzb" ) , "XServiceInfo test failed" );
165 INT32
ODataStreamTest::test( const UString
& TestName
,
166 const XInterfaceRef
& TestObject
,
167 INT32 hTestHandle
) THROWS( ( IllegalArgumentException
,
168 UsrSystemException
) )
170 if( L
"com.sun.star.io.DataInputStream" == TestName
||
171 L
"com.sun.star.io.DataOutputStream" == TestName
) {
174 if( 0 == hTestHandle
) {
175 testInvariant( TestName
, TestObject
);
178 XActiveDataSinkRef
rSink( TestObject
, USR_QUERY
);
179 XActiveDataSourceRef
rSource( TestObject
, USR_QUERY
);
181 XDataInputStreamRef
rInput( TestObject
, USR_QUERY
);
182 XDataOutputStreamRef
rOutput( TestObject
, USR_QUERY
);
185 XInterfaceRef x
= m_rFactory
->createInstance( L
"com.sun.star.io.Pipe");
187 XInputStreamRef
rPipeInput( x
, USR_QUERY
);
188 XOutputStreamRef
rPipeOutput( x
, USR_QUERY
);
191 x
= m_rFactory
->createInstance( L
"com.sun.star.io.DataInputStream" );
192 x
->queryInterface( XDataInputStream::getSmartUik() , rInput
);
193 x
->queryInterface( XActiveDataSink::getSmartUik() , rSink
);
195 else if ( !rSource
.is() ) {
197 x
= m_rFactory
->createInstance( L
"com.sun.star.io.DataOutputStream" );
198 x
->queryInterface( XDataOutputStream::getSmartUik() , rOutput
);
199 x
->queryInterface( XActiveDataSource::getSmartUik() , rSource
);
202 OSL_ASSERT( rPipeInput
.is() );
203 OSL_ASSERT( rPipeOutput
.is() );
204 rSink
->setInputStream( rPipeInput
);
205 rSource
->setOutputStream( rPipeOutput
);
207 OSL_ASSERT( rSink
->getInputStream().is() );
208 OSL_ASSERT( rSource
->getOutputStream().is() );
210 if( 1 == hTestHandle
) {
211 testSimple( rInput
, rOutput
);
215 catch( Exception
& e
) {
216 BUILD_ERROR( 0 , UStringToString( e
.getName() , CHARSET_SYSTEM
).GetCharStr() );
219 BUILD_ERROR( 0 , "unknown exception (Exception is not base class)" );
224 if( hTestHandle
>= 2) {
225 // all tests finished.
230 BUILD_ERROR( 0 , "service not supported by test." );
237 BOOL
ODataStreamTest::testPassed(void) THROWS( (UsrSystemException
) )
239 return m_seqErrors
.getLen() == 0;
243 Sequence
< UString
> ODataStreamTest::getErrors(void) THROWS( (UsrSystemException
) )
249 Sequence
< UsrAny
> ODataStreamTest::getErrorExceptions(void) THROWS( (UsrSystemException
) )
251 return m_seqExceptions
;
255 Sequence
< UString
> ODataStreamTest::getWarnings(void) THROWS( (UsrSystemException
) )
257 return m_seqWarnings
;
260 void ODataStreamTest::testSimple( const XDataInputStreamRef
&rInput
,
261 const XDataOutputStreamRef
&rOutput
)
263 rOutput
->writeLong( 0x34ff3c );
264 rOutput
->writeLong( 0x34ff3d );
266 ERROR_ASSERT( 0x34ff3c == rInput
->readLong() , "long read/write mismatch" );
267 ERROR_ASSERT( 0x34ff3d == rInput
->readLong() , "long read/write mismatch" );
269 rOutput
->writeByte( 0x87 );
270 ERROR_ASSERT( 0x87 == rInput
->readByte() , "byte read/write mismatch" );
272 rOutput
->writeBoolean( 25 );
273 ERROR_ASSERT( rInput
->readBoolean() , "boolean read/write mismatch" );
275 rOutput
->writeBoolean( FALSE
);
276 ERROR_ASSERT( ! rInput
->readBoolean() , "boolean read/write mismatch" );
278 rOutput
->writeFloat( (float) 42.42 );
279 ERROR_ASSERT( rInput
->readFloat() == ((float)42.42) , "float read/write mismatch" );
281 rOutput
->writeDouble( (double) 42.42 );
282 ERROR_ASSERT( rInput
->readDouble() == 42.42 , "double read/write mismatch" );
284 rOutput
->writeUTF( L
"Live long and prosper !" );
285 ERROR_ASSERT( rInput
->readUTF() == L
"Live long and prosper !" ,
286 "UTF read/write mismatch" );
288 Sequence
<wchar_t> wc(0x10001);
289 for( int i
= 0 ; i
< 0x10000 ; i
++ ) {
290 wc
.getArray()[i
] = L
'c';
292 wc
.getArray()[0x10000] = 0;
293 UString
str( wc
.getArray() , 0x10000 );
294 rOutput
->writeUTF( str
);
295 ERROR_ASSERT( rInput
->readUTF() == str
, "error reading 64k block" );
297 rOutput
->closeOutput();
300 ERROR_ASSERT( 0 , "eof-exception does not occur !" );
302 catch ( IOException
& e
){
307 ERROR_ASSERT( 0 , "wrong exception after reading beyond eof" );
310 ERROR_ASSERT( ! rInput
->readBytes( Sequence
<BYTE
> (1) , 1 ),
311 "stream must be on eof !" );
313 rInput
->closeInput();
316 rOutput
->writeByte( 1 );
317 ERROR_ASSERT( 0 , "writing still possible though chain must be interrupted" );
319 catch( IOException
& e
)
325 ERROR_ASSERT( 0 , "IOException expected, but another exception was thrown" );
333 * for external binding
337 XInterfaceRef
ODataStreamTest_CreateInstance( const XMultiServiceFactoryRef
& rSMgr
) THROWS((Exception
))
339 ODataStreamTest
*p
= new ODataStreamTest( rSMgr
);
340 XInterfaceRef xService
= *p
;
344 Sequence
<UString
> ODataStreamTest_getSupportedServiceNames( int i
) THROWS( () )
346 Sequence
<UString
> aRet(1);
348 aRet
.getArray()[0] = ODataStreamTest_getImplementationName( i
);
354 UString
ODataStreamTest_getServiceName( int i
) THROWS( () )
357 return L
"test.com.sun.star.io.DataInputStream";
360 return L
"test.com.sun.star.io.DataOutputStream";
364 UString
ODataStreamTest_getImplementationName( int i
) THROWS( () )
367 return L
"test.com.sun.star.comp.extensions.stm.DataInputStream";
370 return L
"test.com.sun.star.comp.extensions.stm.DataOutputStream";
375 /**------------------------------------------------------
381 *------------------------------------------------------*/
382 class MyPersistObject
:
383 public XPersistObject
,
388 MyPersistObject( ) : m_sServiceName( OMyPersistObject_getServiceName() )
390 MyPersistObject( const UString
& sServiceName
) : m_sServiceName( sServiceName
)
396 BOOL
queryInterface( Uik aUik
, XInterfaceRef
& rOut
);
397 void acquire() { OWeakObject::acquire(); }
398 void release() { OWeakObject::release(); }
399 void* getImplementation(Reflection
*p
) { return OWeakObject::getImplementation(p
); }
402 virtual UString
getServiceName(void) const THROWS( (UsrSystemException
) );
403 virtual void write(const XObjectOutputStreamRef
& OutStream
) THROWS( (IOException
, UsrSystemException
) );
404 virtual void read(const XObjectInputStreamRef
& InStream
) THROWS( (IOException
, UsrSystemException
) );
408 virtual XPropertySetInfoRef
getPropertySetInfo(void) const THROWS( (UsrSystemException
) );
409 virtual void setPropertyValue(const UString
& aPropertyName
, const UsrAny
& aValue
)
410 THROWS( ( UnknownPropertyException
,
411 PropertyVetoException
,
412 IllegalArgumentException
,
413 WrappedTargetException
,
414 UsrSystemException
) );
415 virtual UsrAny
getPropertyValue(const UString
& PropertyName
) const
416 THROWS( ( UnknownPropertyException
,
417 WrappedTargetException
,
418 UsrSystemException
) );
419 virtual void addPropertyChangeListener( const UString
& aPropertyName
,
420 const XPropertyChangeListenerRef
& xListener
)
421 THROWS( ( UnknownPropertyException
,
422 WrappedTargetException
,
423 UsrSystemException
) );
424 virtual void removePropertyChangeListener( const UString
& aPropertyName
,
425 const XPropertyChangeListenerRef
& aListener
)
426 THROWS( ( UnknownPropertyException
,
427 WrappedTargetException
,
428 UsrSystemException
) );
429 virtual void addVetoableChangeListener( const UString
& PropertyName
,
430 const XVetoableChangeListenerRef
& aListener
)
431 THROWS( ( UnknownPropertyException
,
432 WrappedTargetException
,
433 UsrSystemException
) );
434 virtual void removeVetoableChangeListener( const UString
& PropertyName
,
435 const XVetoableChangeListenerRef
& aListener
)
436 THROWS( ( UnknownPropertyException
,
437 WrappedTargetException
,
438 UsrSystemException
) );
448 XPersistObjectRef m_ref
;
449 UString m_sServiceName
;
454 XPropertySetInfoRef
MyPersistObject::getPropertySetInfo(void) const THROWS( (UsrSystemException
) )
456 return XPropertySetInfoRef();
459 void MyPersistObject::setPropertyValue(const UString
& aPropertyName
, const UsrAny
& aValue
)
460 THROWS( ( UnknownPropertyException
,
461 PropertyVetoException
,
462 IllegalArgumentException
,
463 WrappedTargetException
,
464 UsrSystemException
) )
466 if( L
"long" == aPropertyName
) {
467 m_l
= aValue
.getINT32();
469 else if ( L
"float" == aPropertyName
) {
470 m_f
= aValue
.getFloat();
472 else if( L
"double" == aPropertyName
) {
473 m_d
= aValue
.getDouble();
475 else if( L
"bool" == aPropertyName
) {
476 m_b
= aValue
.getBOOL();
478 else if( L
"byte" == aPropertyName
) {
479 m_byte
= aValue
.getBYTE();
481 else if( L
"char" == aPropertyName
) {
482 m_c
= aValue
.getChar();
484 else if( L
"string" == aPropertyName
) {
485 m_s
= aValue
.getString();
487 else if( L
"object" == aPropertyName
) {
488 if( aValue
.getReflection() == XPersistObject_getReflection() ) {
489 XPersistObjectRef
*pRef
= (XPersistObjectRef
*) aValue
.get();
505 UsrAny
MyPersistObject::getPropertyValue(const UString
& aPropertyName
) const
506 THROWS( ( UnknownPropertyException
,
507 WrappedTargetException
,
508 UsrSystemException
) )
511 if( L
"long" == aPropertyName
) {
512 aValue
.setINT32( m_l
);
514 else if ( L
"float" == aPropertyName
) {
515 aValue
.setFloat( m_f
);
517 else if( L
"double" == aPropertyName
) {
518 aValue
.setDouble( m_d
);
520 else if( L
"bool" == aPropertyName
) {
521 aValue
.setBOOL( m_b
);
523 else if( L
"byte" == aPropertyName
) {
524 aValue
.setBYTE( m_byte
);
526 else if( L
"char" == aPropertyName
) {
527 aValue
.setChar( m_c
);
529 else if( L
"string" == aPropertyName
) {
530 aValue
.setString( m_s
);
532 else if( L
"object" == aPropertyName
) {
533 aValue
.set( &m_ref
, XPersistObject_getReflection() );
539 void MyPersistObject::addPropertyChangeListener( const UString
& aPropertyName
,
540 const XPropertyChangeListenerRef
& xListener
)
541 THROWS( ( UnknownPropertyException
,
542 WrappedTargetException
,
543 UsrSystemException
) )
548 void MyPersistObject::removePropertyChangeListener( const UString
& aPropertyName
,
549 const XPropertyChangeListenerRef
& aListener
)
550 THROWS( ( UnknownPropertyException
,
551 WrappedTargetException
,
552 UsrSystemException
) )
555 void MyPersistObject::addVetoableChangeListener(const UString
& PropertyName
,
556 const XVetoableChangeListenerRef
& aListener
)
557 THROWS( ( UnknownPropertyException
,
558 WrappedTargetException
,
559 UsrSystemException
) )
564 void MyPersistObject::removeVetoableChangeListener( const UString
& PropertyName
,
565 const XVetoableChangeListenerRef
& aListener
)
566 THROWS( ( UnknownPropertyException
,
567 WrappedTargetException
,
568 UsrSystemException
) )
575 BOOL
MyPersistObject::queryInterface( Uik aUik
, XInterfaceRef
&rOut
)
577 if( XPersistObject::getSmartUik() == aUik
) {
578 rOut
= ( XPersistObject
* ) this;
580 else if( XPropertySet::getSmartUik() == aUik
) {
581 rOut
= ( XPropertySet
* ) this;
584 return OWeakObject::queryInterface( aUik
, rOut
);
589 UString
MyPersistObject::getServiceName() const THROWS( (UsrSystemException
) )
591 return m_sServiceName
;
594 void MyPersistObject::write( const XObjectOutputStreamRef
& rOut
)
595 THROWS( (IOException
,UsrSystemException
))
597 rOut
->writeLong( m_l
);
598 rOut
->writeFloat( m_f
);
599 rOut
->writeDouble( m_d
);
600 rOut
->writeBoolean( m_b
);
601 rOut
->writeByte( m_byte
);
602 rOut
->writeChar( m_c
);
603 rOut
->writeUTF( m_s
);
604 rOut
->writeObject( m_ref
);
608 void MyPersistObject::read( const XObjectInputStreamRef
& rIn
)
609 THROWS( (IOException
, UsrSystemException
) )
611 m_l
= rIn
->readLong();
612 m_f
= rIn
->readFloat();
613 m_d
= rIn
->readDouble();
614 m_b
= rIn
->readBoolean();
615 m_byte
= rIn
->readByte();
616 m_c
= rIn
->readChar();
617 m_s
= rIn
->readUTF();
618 m_ref
= rIn
->readObject();
621 XInterfaceRef
OMyPersistObject_CreateInstance( const XMultiServiceFactoryRef
& rSMgr
)
624 MyPersistObject
*p
= new MyPersistObject( );
625 XInterfaceRef xService
= *p
;
629 Sequence
<UString
> OMyPersistObject_getSupportedServiceNames( ) THROWS( () )
631 Sequence
<UString
> aRet(1);
632 aRet
.getArray()[0] = OMyPersistObject_getImplementationName();
636 UString
OMyPersistObject_getServiceName( ) THROWS( () )
638 return L
"test.com.sun.star.io.PersistTest";
641 UString
OMyPersistObject_getImplementationName( ) THROWS( () )
643 return L
"test.com.sun.star.io.PersistTest";
647 // ---------------------------------------------
648 // -----------------------------------------------
649 class OObjectStreamTest
:
650 public ODataStreamTest
653 OObjectStreamTest( const XMultiServiceFactoryRef
&r
) : ODataStreamTest(r
) {}
654 public: // refcounting
655 BOOL
queryInterface( Uik aUik
, XInterfaceRef
& rOut
);
658 virtual void testInvariant(const UString
& TestName
, const XInterfaceRef
& TestObject
)
659 THROWS( ( IllegalArgumentException
,
660 UsrSystemException
) );
662 virtual INT32
test( const UString
& TestName
,
663 const XInterfaceRef
& TestObject
,
664 INT32 hTestHandle
) THROWS( ( IllegalArgumentException
,
665 UsrSystemException
) );
669 void OObjectStreamTest::testObject( const XObjectOutputStreamRef
&rOut
,
670 const XObjectInputStreamRef
&rIn
);
678 BOOL
OObjectStreamTest::queryInterface( Uik uik
, XInterfaceRef
&rOut
)
680 if( XSimpleTest::getSmartUik() == uik
) {
681 rOut
= (XSimpleTest
*) this;
684 return ODataStreamTest::queryInterface( uik
, rOut
);
690 void OObjectStreamTest::testInvariant( const UString
& TestName
, const XInterfaceRef
& TestObject
)
691 THROWS( ( IllegalArgumentException
,
692 UsrSystemException
) )
696 if( L
"com.sun.star.io.ObjectInputStream" == TestName
) {
697 ODataStreamTest::testInvariant( TestName
, TestObject
);
698 XObjectInputStreamRef
dataInput( TestObject
, USR_QUERY
);
699 XMarkableStreamRef
markable( TestObject
, USR_QUERY
);
700 ERROR_ASSERT( dataInput
.is() , "XObjectInputStream cannot be queried" );
701 ERROR_ASSERT( markable
.is() , "XMarkableStream cannot be queried" );
703 else if( L
"com.sun.star.io.ObjectOutputStream" == TestName
) {
704 ODataStreamTest::testInvariant( TestName
, TestObject
);
705 XMarkableStreamRef
markable( TestObject
, USR_QUERY
);
706 XObjectOutputStreamRef
dataOutput( TestObject
, USR_QUERY
);
707 ERROR_ASSERT( dataOutput
.is(), "XObjectOutputStream cannot be queried" );
708 ERROR_ASSERT( markable
.is() , "XMarkableStream cannot be queried" );
711 XServiceInfoRef
info( TestObject
, USR_QUERY
);
712 ERROR_ASSERT( info
.is() , "XServiceInfo not supported !" );
715 ERROR_ASSERT( info
->supportsService( TestName
), "XServiceInfo test failed" );
716 ERROR_ASSERT( ! info
->supportsService( L
"bla bluzb" ) , "XServiceInfo test failed" );
721 INT32
OObjectStreamTest::test( const UString
& TestName
,
722 const XInterfaceRef
& TestObject
,
723 INT32 hTestHandle
) THROWS( ( IllegalArgumentException
,
724 UsrSystemException
) )
726 if( L
"com.sun.star.io.ObjectInputStream" == TestName
||
727 L
"com.sun.star.io.ObjectOutputStream" == TestName
) {
730 if( 0 == hTestHandle
) {
731 testInvariant( TestName
, TestObject
);
733 else if( DATASTREAM_TEST_MAX_HANDLE
>= hTestHandle
) {
734 INT32 hOldHandle
= hTestHandle
;
735 hTestHandle
= ODataStreamTest::test( L
"com.sun.star.io.DataInputStream" ,
736 TestObject
, hTestHandle
);
737 if( hTestHandle
== -1 ){
738 hTestHandle
= hOldHandle
;
743 XActiveDataSinkRef
rSink( TestObject
, USR_QUERY
);
744 XActiveDataSourceRef
rSource( TestObject
, USR_QUERY
);
746 XObjectInputStreamRef
rInput( TestObject
, USR_QUERY
);
747 XObjectOutputStreamRef
rOutput( TestObject
, USR_QUERY
);
750 XInterfaceRef x
= m_rFactory
->createInstance( L
"com.sun.star.io.Pipe");
752 XInputStreamRef
rPipeInput( x
, USR_QUERY
);
753 XOutputStreamRef
rPipeOutput( x
, USR_QUERY
);
755 x
= m_rFactory
->createInstance( L
"com.sun.star.io.MarkableInputStream" );
756 XInputStreamRef
markableInput( x
, USR_QUERY
);
757 XActiveDataSinkRef
markableSink( x
, USR_QUERY
);
759 x
= m_rFactory
->createInstance( L
"com.sun.star.io.MarkableOutputStream" );
760 XOutputStreamRef
markableOutput( x
, USR_QUERY
);
761 XActiveDataSourceRef
markableSource( x
, USR_QUERY
);
763 OSL_ASSERT( markableInput
.is() );
764 OSL_ASSERT( markableOutput
.is() );
765 OSL_ASSERT( markableSink
.is() );
766 OSL_ASSERT( markableSource
.is() );
768 markableSink
->setInputStream( rPipeInput
);
769 markableSource
->setOutputStream( rPipeOutput
);
772 x
= m_rFactory
->createInstance( L
"com.sun.star.io.ObjectInputStream" );
773 x
->queryInterface( XObjectInputStream::getSmartUik() , rInput
);
774 x
->queryInterface( XActiveDataSink::getSmartUik() , rSink
);
776 else if ( !rSource
.is() ) {
777 x
= m_rFactory
->createInstance( L
"com.sun.star.io.ObjectOutputStream" );
778 x
->queryInterface( XObjectOutputStream::getSmartUik() , rOutput
);
779 x
->queryInterface( XActiveDataSource::getSmartUik() , rSource
);
782 OSL_ASSERT( rPipeInput
.is() );
783 OSL_ASSERT( rPipeOutput
.is() );
785 rSink
->setInputStream( markableInput
);
786 rSource
->setOutputStream( markableOutput
);
788 OSL_ASSERT( rSink
->getInputStream().is() );
789 OSL_ASSERT( rSource
->getOutputStream().is() );
791 if( 1 + DATASTREAM_TEST_MAX_HANDLE
== hTestHandle
) {
792 testObject( rOutput
, rInput
);
794 rInput
->closeInput();
795 rOutput
->closeOutput();
799 catch( Exception
& e
) {
800 BUILD_ERROR( 0 , UStringToString( e
.getName() , CHARSET_SYSTEM
).GetCharStr() );
803 BUILD_ERROR( 0 , "unknown exception (Exception is not base class)" );
808 if( hTestHandle
> 1 +DATASTREAM_TEST_MAX_HANDLE
) {
809 // all tests finished.
814 BUILD_ERROR( 0 , "service not supported by test." );
820 BOOL
compareMyPropertySet( XPropertySetRef
&r1
, XPropertySetRef
&r2
)
824 if( r1
->getPropertyValue( L
"long" ).getReflection() == Void_getReflection() ||
825 r2
->getPropertyValue( L
"long" ).getReflection() == Void_getReflection() ) {
827 // one of the objects is not the correct propertyset !
831 b
= b
&& ( r1
->getPropertyValue( L
"long" ).getINT32() ==
832 r2
->getPropertyValue( L
"long" ).getINT32() );
834 b
= b
&& ( r1
->getPropertyValue( L
"float" ).getFloat() ==
835 r2
->getPropertyValue( L
"float" ).getFloat() );
837 b
= b
&& ( r1
->getPropertyValue( L
"double" ).getDouble() ==
838 r2
->getPropertyValue( L
"double" ).getDouble() );
840 b
= b
&& ( r1
->getPropertyValue( L
"bool" ).getBOOL() ==
841 r2
->getPropertyValue( L
"bool" ).getBOOL() );
843 b
= b
&& ( r1
->getPropertyValue( L
"byte" ).getBYTE() ==
844 r2
->getPropertyValue( L
"byte" ).getBYTE() );
846 b
= b
&& ( r1
->getPropertyValue( L
"char" ).getChar() ==
847 r2
->getPropertyValue( L
"char" ).getChar() );
849 b
= b
&& ( r1
->getPropertyValue( L
"string" ).getString() ==
850 r2
->getPropertyValue( L
"string" ).getString() );
852 UsrAny o1
= r1
->getPropertyValue( L
"object" );
853 UsrAny o2
= r2
->getPropertyValue( L
"object" );
855 if( o1
.getReflection() == XPersistObject_getReflection() ) {
857 if( o2
.getReflection() == XPersistObject_getReflection() ) {
858 XPersistObjectRef rPersist1
= *((XPersistObjectRef
*) o1
.get());
859 XPersistObjectRef rPersist2
= *((XPersistObjectRef
*) o2
.get());
860 XPropertySetRef
rProp1( rPersist1
, USR_QUERY
);
861 XPropertySetRef
rProp2( rPersist2
, USR_QUERY
);
863 if( rProp1
.is() && rProp2
.is() && ! ( rProp1
== rProp2
)
864 &&( rProp1
!= r1
)) {
865 compareMyPropertySet( rProp1
, rProp2
);
873 if( o2
.getReflection() == XPersistObject_getReflection() ) {
881 void OObjectStreamTest::testObject( const XObjectOutputStreamRef
&rOut
,
882 const XObjectInputStreamRef
&rIn
)
884 ERROR_ASSERT( rOut
.is() , "no objectOutputStream" );
885 ERROR_ASSERT( rIn
.is() , "no objectInputStream" );
887 XMultiServiceFactoryRef xProv
= getProcessServiceManager();
888 ERROR_ASSERT( xProv
.is() , "no global service manager" );
891 // tests, if saving an object with an unknown service name allows
892 // reading the data behind the object !
894 XInterfaceRef x
= * new MyPersistObject( L
"bla blubs" );
896 XPersistObjectRef
persistRef( x
, USR_QUERY
);
897 ERROR_ASSERT( persistRef
.is() , "couldn't instantiate PersistTest object" );
899 rOut
->writeObject( persistRef
);
900 rOut
->writeLong( (INT32
) 0xdeadbeef );
902 ERROR_ASSERT( 0 != rIn
->available() , "no data arrived at input" );
906 XPersistObjectRef xReadPersistRef
= rIn
->readObject();
907 ERROR_ASSERT( 0 , "expected exception not thrown" );
909 catch( IOException
& e
)
914 ERROR_ASSERT( (INT32
) 0xdeadbeef == rIn
->readLong() ,
915 "wrong data after object with unknown service name." );
919 XInterfaceRef x
= xProv
->createInstance(L
"test.com.sun.star.io.PersistTest");
920 XPersistObjectRef
persistRef( x
, USR_QUERY
);
922 ERROR_ASSERT( persistRef
.is() , "couldn't instantiate PersistTest object" );
924 XPropertySetRef
rProp( persistRef
, USR_QUERY
);
925 ERROR_ASSERT( rProp
.is() , "test object is no property set " );
928 any
.setINT32( 0x83482 );
929 rProp
->setPropertyValue( L
"long" , any
);
931 any
.setFloat( 42.23 );
932 rProp
->setPropertyValue( L
"float" , any
);
934 any
.setDouble( 233.321412 );
935 rProp
->setPropertyValue( L
"double" , any
);
938 rProp
->setPropertyValue( L
"bool" , any
);
941 rProp
->setPropertyValue( L
"byte" , any
);
944 rProp
->setPropertyValue( L
"char" , any
);
946 any
.setString( L
"hi du !" );
947 rProp
->setPropertyValue( L
"string" , any
);
949 any
.set( &persistRef
, XPersistObject_getReflection() ); // try a self reference
950 rProp
->setPropertyValue( L
"object" , any
);
953 rOut
->writeObject( persistRef
);
954 ERROR_ASSERT( 0 != rIn
->available() , "no data arrived at input" );
955 XPersistObjectRef xReadPersistRef
= rIn
->readObject( );
957 XPropertySetRef
rPropRead( xReadPersistRef
, USR_QUERY
);
958 ERROR_ASSERT( compareMyPropertySet( rProp
, rPropRead
) , "objects has not been read properly !" );
960 // destroy selfreferences
961 rProp
->setPropertyValue( L
"object", UsrAny() );
962 rPropRead
->setPropertyValue( L
"object", UsrAny() );
966 XMarkableStreamRef
markableOut( rOut
, USR_QUERY
);
967 ERROR_ASSERT( markableOut
.is() , "markable stream cannot be queried" );
969 // do the same thing multiple times to check if
970 // buffering and marks work correctly
971 for( int i
= 0 ; i
< 2000 ; i
++ ) {
973 XInterfaceRef x
= xProv
->createInstance(L
"test.com.sun.star.io.PersistTest");
974 XPersistObjectRef
persistRef( x
, USR_QUERY
);
976 XPropertySetRef
rProp( persistRef
, USR_QUERY
);
977 ERROR_ASSERT( rProp
.is() , "test object is no property set " );
980 any
.setINT32( 0x83482 );
981 rProp
->setPropertyValue( L
"long" , any
);
983 any
.setFloat( 42.23 );
984 rProp
->setPropertyValue( L
"float" , any
);
986 any
.setDouble( 233.321412 );
987 rProp
->setPropertyValue( L
"double" , any
);
990 rProp
->setPropertyValue( L
"bool" , any
);
993 rProp
->setPropertyValue( L
"byte" , any
);
996 rProp
->setPropertyValue( L
"char" , any
);
998 any
.setString( L
"hi du !" );
999 rProp
->setPropertyValue( L
"string" , any
);
1002 x
= xProv
->createInstance(L
"test.com.sun.star.io.PersistTest");
1003 XPersistObjectRef
persist2ndRef( x
, USR_QUERY
);
1006 // Note : persist2ndRef contains coincident values, but also coincident values must be
1008 any
.set( &persist2ndRef
, XPersistObject_getReflection() ); // try a self reference
1009 rProp
->setPropertyValue( L
"object" , any
);
1011 // simply test, if markable operations and object operations do not interfere
1012 INT32 nMark
= markableOut
->createMark();
1014 // do read and write
1015 rOut
->writeObject( persistRef
);
1017 // further markable tests !
1018 INT32 nOffset
= markableOut
->offsetToMark( nMark
);
1019 markableOut
->jumpToMark( nMark
);
1020 markableOut
->deleteMark( nMark
);
1021 markableOut
->jumpToFurthest();
1027 ERROR_ASSERT( 0 != rIn
->available() , "no data arrived at input" );
1028 XPersistObjectRef xReadPersistRef
= rIn
->readObject( );
1030 XPropertySetRef
rProp1( persistRef
, USR_QUERY
);
1031 XPropertySetRef
rProp2( xReadPersistRef
, USR_QUERY
);
1032 ERROR_ASSERT( compareMyPropertySet( rProp1
, rProp2
) , "objects has not been read properly !" );
1038 XInterfaceRef
OObjectStreamTest_CreateInstance( const XMultiServiceFactoryRef
& rSMgr
) THROWS((Exception
))
1040 OObjectStreamTest
*p
= new OObjectStreamTest( rSMgr
);
1041 XInterfaceRef xService
= *p
;
1045 Sequence
<UString
> OObjectStreamTest_getSupportedServiceNames( int i
) THROWS( () )
1047 Sequence
<UString
> aRet(1);
1048 aRet
.getArray()[0] = OObjectStreamTest_getImplementationName( i
);
1052 UString
OObjectStreamTest_getServiceName( int i
) THROWS( () )
1055 return L
"test.com.sun.star.io.ObjectInputStream";
1058 return L
"test.com.sun.star.io.ObjectOutputStream";
1062 UString
OObjectStreamTest_getImplementationName( int i
) THROWS( () )
1065 return L
"test.com.sun.star.comp.extensions.stm.ObjectInputStream";
1068 return L
"test.com.sun.star.comp.extensions.stm.ObjectOutputStream";
1073 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */