1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <smart/com/sun/star/test/XSimpleTest.hxx>
21 #include <smart/com/sun/star/io/XObjectOutputStream.hxx>
22 #include <smart/com/sun/star/io/XObjectInputStream.hxx>
23 #include <smart/com/sun/star/io/XActiveDataSink.hxx>
24 #include <smart/com/sun/star/io/XActiveDataSource.hxx>
25 #include <smart/com/sun/star/io/XConnectable.hxx>
26 #include <smart/com/sun/star/io/XMarkableStream.hxx>
28 #include <smart/com/sun/star/lang/XServiceInfo.hxx>
30 #include <smart/com/sun/star/beans/XPropertySet.hxx>
32 #include <usr/services.hxx>
33 #include <usr/factoryhlp.hxx>
35 #include <usr/reflserv.hxx> // for EXTERN_SERVICE_CALLTYPE
36 #include <usr/weak.hxx> // OWeakObject
38 #include <osl/conditn.hxx>
39 #include <osl/mutex.hxx>
40 #include <osl/thread.hxx>
44 #include "testfactreg.hxx"
48 #define DATASTREAM_TEST_MAX_HANDLE 1
51 * The following test class tests XDataInputStream and XDataOutputStream at equal terms,
52 * so when errors occur, it may be in either one implementation.
53 * The class also uses stardiv.uno.io.pipe. If problems occur, make sure to run also the
54 * pipe test routines ( test.com.sun.star.io.pipe ).
59 class ODataStreamTest
:
64 ODataStreamTest( const XMultiServiceFactoryRef
& rFactory
) : m_rFactory( rFactory
){}
66 public: // refcounting
67 BOOL
queryInterface( Uik aUik
, XInterfaceRef
& rOut
);
68 void acquire() { OWeakObject::acquire(); }
69 void release() { OWeakObject::release(); }
70 void* getImplementation(Reflection
*p
) { return OWeakObject::getImplementation(p
); }
73 virtual void testInvariant(const UString
& TestName
, const XInterfaceRef
& TestObject
)
74 THROWS( ( IllegalArgumentException
,
75 UsrSystemException
) );
77 virtual INT32
test( const UString
& TestName
,
78 const XInterfaceRef
& TestObject
,
79 INT32 hTestHandle
) THROWS( ( IllegalArgumentException
,
80 UsrSystemException
) );
82 virtual BOOL
testPassed(void) THROWS( ( UsrSystemException
) );
83 virtual Sequence
< UString
> getErrors(void) THROWS( (UsrSystemException
) );
84 virtual Sequence
< UsrAny
> getErrorExceptions(void) THROWS( (UsrSystemException
) );
85 virtual Sequence
< UString
> getWarnings(void) THROWS( (UsrSystemException
) );
88 void testSimple( const XDataInputStreamRef
& , const XDataOutputStreamRef
&);
91 Sequence
<UsrAny
> m_seqExceptions
;
92 Sequence
<UString
> m_seqErrors
;
93 Sequence
<UString
> m_seqWarnings
;
95 XMultiServiceFactoryRef m_rFactory
;
99 BOOL
ODataStreamTest::queryInterface( Uik uik
, XInterfaceRef
&rOut
)
101 if( XSimpleTest::getSmartUik() == uik
) {
102 rOut
= (XSimpleTest
*) this;
105 return OWeakObject::queryInterface( uik
, rOut
);
111 void ODataStreamTest::testInvariant( const UString
& TestName
, const XInterfaceRef
& TestObject
)
112 THROWS( ( IllegalArgumentException
,
113 UsrSystemException
) )
115 if( L
"com.sun.star.io.DataInputStream" == TestName
) {
116 XConnectableRef
connect( TestObject
, USR_QUERY
);
117 XActiveDataSinkRef
active( TestObject
, USR_QUERY
);
118 XInputStreamRef
input( TestObject
, USR_QUERY
);
119 XDataInputStreamRef
dataInput( TestObject
, USR_QUERY
);
121 WARNING_ASSERT( connect
.is(), "XConnectable cannot be queried" );
122 WARNING_ASSERT( active
.is() , "XActiveDataSink cannot be queried" );
123 ERROR_ASSERT( input
.is() , "XInputStream cannot be queried" );
124 ERROR_ASSERT( dataInput
.is() , "XDataInputStream cannot be queried" );
128 else if( L
"com.sun.star.io.DataInputStream" == TestName
) {
129 XConnectableRef
connect( TestObject
, USR_QUERY
);
130 XActiveDataSourceRef
active( TestObject
, USR_QUERY
);
131 XOutputStreamRef
output( TestObject
, USR_QUERY
);
132 XDataOutputStreamRef
dataOutput( TestObject
, USR_QUERY
);
134 WARNING_ASSERT( connect
.is(), "XConnectable cannot be queried" );
135 WARNING_ASSERT( active
.is() , "XActiveDataSink cannot be queried" );
136 ERROR_ASSERT( output
.is() , "XInputStream cannot be queried" );
137 ERROR_ASSERT( dataOutput
.is(), "XDataInputStream cannot be queried" );
141 XServiceInfoRef
info( TestObject
, USR_QUERY
);
142 ERROR_ASSERT( info
.is() , "XServiceInfo not supported !" );
145 ERROR_ASSERT( info
->supportsService( TestName
), "XServiceInfo test failed" );
146 ERROR_ASSERT( ! info
->supportsService( L
"bla bluzb" ) , "XServiceInfo test failed" );
152 INT32
ODataStreamTest::test( const UString
& TestName
,
153 const XInterfaceRef
& TestObject
,
154 INT32 hTestHandle
) THROWS( ( IllegalArgumentException
,
155 UsrSystemException
) )
157 if( L
"com.sun.star.io.DataInputStream" == TestName
||
158 L
"com.sun.star.io.DataOutputStream" == TestName
) {
161 if( 0 == hTestHandle
) {
162 testInvariant( TestName
, TestObject
);
165 XActiveDataSinkRef
rSink( TestObject
, USR_QUERY
);
166 XActiveDataSourceRef
rSource( TestObject
, USR_QUERY
);
168 XDataInputStreamRef
rInput( TestObject
, USR_QUERY
);
169 XDataOutputStreamRef
rOutput( TestObject
, USR_QUERY
);
172 XInterfaceRef x
= m_rFactory
->createInstance( L
"com.sun.star.io.Pipe");
174 XInputStreamRef
rPipeInput( x
, USR_QUERY
);
175 XOutputStreamRef
rPipeOutput( x
, USR_QUERY
);
178 x
= m_rFactory
->createInstance( L
"com.sun.star.io.DataInputStream" );
179 x
->queryInterface( XDataInputStream::getSmartUik() , rInput
);
180 x
->queryInterface( XActiveDataSink::getSmartUik() , rSink
);
182 else if ( !rSource
.is() ) {
184 x
= m_rFactory
->createInstance( L
"com.sun.star.io.DataOutputStream" );
185 x
->queryInterface( XDataOutputStream::getSmartUik() , rOutput
);
186 x
->queryInterface( XActiveDataSource::getSmartUik() , rSource
);
189 OSL_ASSERT( rPipeInput
.is() );
190 OSL_ASSERT( rPipeOutput
.is() );
191 rSink
->setInputStream( rPipeInput
);
192 rSource
->setOutputStream( rPipeOutput
);
194 OSL_ASSERT( rSink
->getInputStream().is() );
195 OSL_ASSERT( rSource
->getOutputStream().is() );
197 if( 1 == hTestHandle
) {
198 testSimple( rInput
, rOutput
);
202 catch( Exception
& e
) {
203 BUILD_ERROR( 0 , UStringToString( e
.getName() , CHARSET_SYSTEM
).GetCharStr() );
206 BUILD_ERROR( 0 , "unknown exception (Exception is not base class)" );
211 if( hTestHandle
>= 2) {
212 // all tests finished.
217 BUILD_ERROR( 0 , "service not supported by test." );
224 BOOL
ODataStreamTest::testPassed(void) THROWS( (UsrSystemException
) )
226 return m_seqErrors
.getLen() == 0;
230 Sequence
< UString
> ODataStreamTest::getErrors(void) THROWS( (UsrSystemException
) )
236 Sequence
< UsrAny
> ODataStreamTest::getErrorExceptions(void) THROWS( (UsrSystemException
) )
238 return m_seqExceptions
;
242 Sequence
< UString
> ODataStreamTest::getWarnings(void) THROWS( (UsrSystemException
) )
244 return m_seqWarnings
;
247 void ODataStreamTest::testSimple( const XDataInputStreamRef
&rInput
,
248 const XDataOutputStreamRef
&rOutput
)
250 rOutput
->writeLong( 0x34ff3c );
251 rOutput
->writeLong( 0x34ff3d );
253 ERROR_ASSERT( 0x34ff3c == rInput
->readLong() , "long read/write mismatch" );
254 ERROR_ASSERT( 0x34ff3d == rInput
->readLong() , "long read/write mismatch" );
256 rOutput
->writeByte( 0x87 );
257 ERROR_ASSERT( 0x87 == rInput
->readByte() , "byte read/write mismatch" );
259 rOutput
->writeBoolean( 25 );
260 ERROR_ASSERT( rInput
->readBoolean() , "boolean read/write mismatch" );
262 rOutput
->writeBoolean( FALSE
);
263 ERROR_ASSERT( ! rInput
->readBoolean() , "boolean read/write mismatch" );
265 rOutput
->writeFloat( (float) 42.42 );
266 ERROR_ASSERT( rInput
->readFloat() == ((float)42.42) , "float read/write mismatch" );
268 rOutput
->writeDouble( (double) 42.42 );
269 ERROR_ASSERT( rInput
->readDouble() == 42.42 , "double read/write mismatch" );
271 rOutput
->writeUTF( L
"Live long and prosper !" );
272 ERROR_ASSERT( rInput
->readUTF() == L
"Live long and prosper !" ,
273 "UTF read/write mismatch" );
275 Sequence
<wchar_t> wc(0x10001);
276 for( int i
= 0 ; i
< 0x10000 ; i
++ ) {
277 wc
.getArray()[i
] = L
'c';
279 wc
.getArray()[0x10000] = 0;
280 UString
str( wc
.getArray() , 0x10000 );
281 rOutput
->writeUTF( str
);
282 ERROR_ASSERT( rInput
->readUTF() == str
, "error reading 64k block" );
284 rOutput
->closeOutput();
287 ERROR_ASSERT( 0 , "eof-exception does not occur !" );
289 catch ( IOException
& e
){
294 ERROR_ASSERT( 0 , "wrong exception after reading beyond eof" );
297 ERROR_ASSERT( ! rInput
->readBytes( Sequence
<BYTE
> (1) , 1 ),
298 "stream must be on eof !" );
300 rInput
->closeInput();
303 rOutput
->writeByte( 1 );
304 ERROR_ASSERT( 0 , "writing still possible though chain must be interrupted" );
306 catch( IOException
& e
)
312 ERROR_ASSERT( 0 , "IOException expected, but another exception was thrown" );
320 * for external binding
324 XInterfaceRef
ODataStreamTest_CreateInstance( const XMultiServiceFactoryRef
& rSMgr
) THROWS((Exception
))
326 ODataStreamTest
*p
= new ODataStreamTest( rSMgr
);
327 XInterfaceRef xService
= *p
;
331 Sequence
<UString
> ODataStreamTest_getSupportedServiceNames( int i
) THROWS(())
333 Sequence
<UString
> aRet(1);
335 aRet
.getArray()[0] = ODataStreamTest_getImplementationName( i
);
341 UString
ODataStreamTest_getServiceName( int i
) THROWS(())
344 return L
"test.com.sun.star.io.DataInputStream";
347 return L
"test.com.sun.star.io.DataOutputStream";
351 UString
ODataStreamTest_getImplementationName( int i
) THROWS(())
354 return L
"test.com.sun.star.comp.extensions.stm.DataInputStream";
357 return L
"test.com.sun.star.comp.extensions.stm.DataOutputStream";
361 class MyPersistObject
:
362 public XPersistObject
,
367 MyPersistObject( ) : m_sServiceName( OMyPersistObject_getServiceName() )
369 MyPersistObject( const UString
& sServiceName
) : m_sServiceName( sServiceName
)
375 BOOL
queryInterface( Uik aUik
, XInterfaceRef
& rOut
);
376 void acquire() { OWeakObject::acquire(); }
377 void release() { OWeakObject::release(); }
378 void* getImplementation(Reflection
*p
) { return OWeakObject::getImplementation(p
); }
381 virtual UString
getServiceName(void) const THROWS( (UsrSystemException
) );
382 virtual void write(const XObjectOutputStreamRef
& OutStream
) THROWS( (IOException
, UsrSystemException
) );
383 virtual void read(const XObjectInputStreamRef
& InStream
) THROWS( (IOException
, UsrSystemException
) );
387 virtual XPropertySetInfoRef
getPropertySetInfo(void) const THROWS( (UsrSystemException
) );
388 virtual void setPropertyValue(const UString
& aPropertyName
, const UsrAny
& aValue
)
389 THROWS( ( UnknownPropertyException
,
390 PropertyVetoException
,
391 IllegalArgumentException
,
392 WrappedTargetException
,
393 UsrSystemException
) );
394 virtual UsrAny
getPropertyValue(const UString
& PropertyName
) const
395 THROWS( ( UnknownPropertyException
,
396 WrappedTargetException
,
397 UsrSystemException
) );
398 virtual void addPropertyChangeListener( const UString
& aPropertyName
,
399 const XPropertyChangeListenerRef
& xListener
)
400 THROWS( ( UnknownPropertyException
,
401 WrappedTargetException
,
402 UsrSystemException
) );
403 virtual void removePropertyChangeListener( const UString
& aPropertyName
,
404 const XPropertyChangeListenerRef
& aListener
)
405 THROWS( ( UnknownPropertyException
,
406 WrappedTargetException
,
407 UsrSystemException
) );
408 virtual void addVetoableChangeListener( const UString
& PropertyName
,
409 const XVetoableChangeListenerRef
& aListener
)
410 THROWS( ( UnknownPropertyException
,
411 WrappedTargetException
,
412 UsrSystemException
) );
413 virtual void removeVetoableChangeListener( const UString
& PropertyName
,
414 const XVetoableChangeListenerRef
& aListener
)
415 THROWS( ( UnknownPropertyException
,
416 WrappedTargetException
,
417 UsrSystemException
) );
427 XPersistObjectRef m_ref
;
428 UString m_sServiceName
;
433 XPropertySetInfoRef
MyPersistObject::getPropertySetInfo(void) const THROWS( (UsrSystemException
) )
435 return XPropertySetInfoRef();
438 void MyPersistObject::setPropertyValue(const UString
& aPropertyName
, const UsrAny
& aValue
)
439 THROWS( ( UnknownPropertyException
,
440 PropertyVetoException
,
441 IllegalArgumentException
,
442 WrappedTargetException
,
443 UsrSystemException
) )
445 if( L
"long" == aPropertyName
) {
446 m_l
= aValue
.getINT32();
448 else if ( L
"float" == aPropertyName
) {
449 m_f
= aValue
.getFloat();
451 else if( L
"double" == aPropertyName
) {
452 m_d
= aValue
.getDouble();
454 else if( L
"bool" == aPropertyName
) {
455 m_b
= aValue
.getBOOL();
457 else if( L
"byte" == aPropertyName
) {
458 m_byte
= aValue
.getBYTE();
460 else if( L
"char" == aPropertyName
) {
461 m_c
= aValue
.getChar();
463 else if( L
"string" == aPropertyName
) {
464 m_s
= aValue
.getString();
466 else if( L
"object" == aPropertyName
) {
467 if( aValue
.getReflection() == XPersistObject_getReflection() ) {
468 XPersistObjectRef
*pRef
= (XPersistObjectRef
*) aValue
.get();
484 UsrAny
MyPersistObject::getPropertyValue(const UString
& aPropertyName
) const
485 THROWS( ( UnknownPropertyException
,
486 WrappedTargetException
,
487 UsrSystemException
) )
490 if( L
"long" == aPropertyName
) {
491 aValue
.setINT32( m_l
);
493 else if ( L
"float" == aPropertyName
) {
494 aValue
.setFloat( m_f
);
496 else if( L
"double" == aPropertyName
) {
497 aValue
.setDouble( m_d
);
499 else if( L
"bool" == aPropertyName
) {
500 aValue
.setBOOL( m_b
);
502 else if( L
"byte" == aPropertyName
) {
503 aValue
.setBYTE( m_byte
);
505 else if( L
"char" == aPropertyName
) {
506 aValue
.setChar( m_c
);
508 else if( L
"string" == aPropertyName
) {
509 aValue
.setString( m_s
);
511 else if( L
"object" == aPropertyName
) {
512 aValue
.set( &m_ref
, XPersistObject_getReflection() );
518 void MyPersistObject::addPropertyChangeListener( const UString
& aPropertyName
,
519 const XPropertyChangeListenerRef
& xListener
)
520 THROWS( ( UnknownPropertyException
,
521 WrappedTargetException
,
522 UsrSystemException
) )
527 void MyPersistObject::removePropertyChangeListener( const UString
& aPropertyName
,
528 const XPropertyChangeListenerRef
& aListener
)
529 THROWS( ( UnknownPropertyException
,
530 WrappedTargetException
,
531 UsrSystemException
) )
534 void MyPersistObject::addVetoableChangeListener(const UString
& PropertyName
,
535 const XVetoableChangeListenerRef
& aListener
)
536 THROWS( ( UnknownPropertyException
,
537 WrappedTargetException
,
538 UsrSystemException
) )
543 void MyPersistObject::removeVetoableChangeListener( const UString
& PropertyName
,
544 const XVetoableChangeListenerRef
& aListener
)
545 THROWS( ( UnknownPropertyException
,
546 WrappedTargetException
,
547 UsrSystemException
) )
554 BOOL
MyPersistObject::queryInterface( Uik aUik
, XInterfaceRef
&rOut
)
556 if( XPersistObject::getSmartUik() == aUik
) {
557 rOut
= ( XPersistObject
* ) this;
559 else if( XPropertySet::getSmartUik() == aUik
) {
560 rOut
= ( XPropertySet
* ) this;
563 return OWeakObject::queryInterface( aUik
, rOut
);
568 UString
MyPersistObject::getServiceName() const THROWS( (UsrSystemException
) )
570 return m_sServiceName
;
573 void MyPersistObject::write( const XObjectOutputStreamRef
& rOut
)
574 THROWS( (IOException
,UsrSystemException
))
576 rOut
->writeLong( m_l
);
577 rOut
->writeFloat( m_f
);
578 rOut
->writeDouble( m_d
);
579 rOut
->writeBoolean( m_b
);
580 rOut
->writeByte( m_byte
);
581 rOut
->writeChar( m_c
);
582 rOut
->writeUTF( m_s
);
583 rOut
->writeObject( m_ref
);
587 void MyPersistObject::read( const XObjectInputStreamRef
& rIn
)
588 THROWS( (IOException
, UsrSystemException
) )
590 m_l
= rIn
->readLong();
591 m_f
= rIn
->readFloat();
592 m_d
= rIn
->readDouble();
593 m_b
= rIn
->readBoolean();
594 m_byte
= rIn
->readByte();
595 m_c
= rIn
->readChar();
596 m_s
= rIn
->readUTF();
597 m_ref
= rIn
->readObject();
600 XInterfaceRef
OMyPersistObject_CreateInstance( const XMultiServiceFactoryRef
& rSMgr
)
603 MyPersistObject
*p
= new MyPersistObject( );
604 XInterfaceRef xService
= *p
;
608 Sequence
<UString
> OMyPersistObject_getSupportedServiceNames( ) THROWS(())
610 Sequence
<UString
> aRet(1);
611 aRet
.getArray()[0] = OMyPersistObject_getImplementationName();
615 UString
OMyPersistObject_getServiceName( ) THROWS(())
617 return L
"test.com.sun.star.io.PersistTest";
620 UString
OMyPersistObject_getImplementationName( ) THROWS(())
622 return L
"test.com.sun.star.io.PersistTest";
626 // ---------------------------------------------
627 // -----------------------------------------------
628 class OObjectStreamTest
:
629 public ODataStreamTest
632 OObjectStreamTest( const XMultiServiceFactoryRef
&r
) : ODataStreamTest(r
) {}
633 public: // refcounting
634 BOOL
queryInterface( Uik aUik
, XInterfaceRef
& rOut
);
637 virtual void testInvariant(const UString
& TestName
, const XInterfaceRef
& TestObject
)
638 THROWS( ( IllegalArgumentException
,
639 UsrSystemException
) );
641 virtual INT32
test( const UString
& TestName
,
642 const XInterfaceRef
& TestObject
,
643 INT32 hTestHandle
) THROWS( ( IllegalArgumentException
,
644 UsrSystemException
) );
648 void testObject( const XObjectOutputStreamRef
&rOut
,
649 const XObjectInputStreamRef
&rIn
);
657 BOOL
OObjectStreamTest::queryInterface( Uik uik
, XInterfaceRef
&rOut
)
659 if( XSimpleTest::getSmartUik() == uik
) {
660 rOut
= (XSimpleTest
*) this;
663 return ODataStreamTest::queryInterface( uik
, rOut
);
669 void OObjectStreamTest::testInvariant( const UString
& TestName
, const XInterfaceRef
& TestObject
)
670 THROWS( ( IllegalArgumentException
,
671 UsrSystemException
) )
675 if( L
"com.sun.star.io.ObjectInputStream" == TestName
) {
676 ODataStreamTest::testInvariant( TestName
, TestObject
);
677 XObjectInputStreamRef
dataInput( TestObject
, USR_QUERY
);
678 XMarkableStreamRef
markable( TestObject
, USR_QUERY
);
679 ERROR_ASSERT( dataInput
.is() , "XObjectInputStream cannot be queried" );
680 ERROR_ASSERT( markable
.is() , "XMarkableStream cannot be queried" );
682 else if( L
"com.sun.star.io.ObjectOutputStream" == TestName
) {
683 ODataStreamTest::testInvariant( TestName
, TestObject
);
684 XMarkableStreamRef
markable( TestObject
, USR_QUERY
);
685 XObjectOutputStreamRef
dataOutput( TestObject
, USR_QUERY
);
686 ERROR_ASSERT( dataOutput
.is(), "XObjectOutputStream cannot be queried" );
687 ERROR_ASSERT( markable
.is() , "XMarkableStream cannot be queried" );
690 XServiceInfoRef
info( TestObject
, USR_QUERY
);
691 ERROR_ASSERT( info
.is() , "XServiceInfo not supported !" );
694 ERROR_ASSERT( info
->supportsService( TestName
), "XServiceInfo test failed" );
695 ERROR_ASSERT( ! info
->supportsService( L
"bla bluzb" ) , "XServiceInfo test failed" );
700 INT32
OObjectStreamTest::test( const UString
& TestName
,
701 const XInterfaceRef
& TestObject
,
702 INT32 hTestHandle
) THROWS( ( IllegalArgumentException
,
703 UsrSystemException
) )
705 if( L
"com.sun.star.io.ObjectInputStream" == TestName
||
706 L
"com.sun.star.io.ObjectOutputStream" == TestName
) {
709 if( 0 == hTestHandle
) {
710 testInvariant( TestName
, TestObject
);
712 else if( DATASTREAM_TEST_MAX_HANDLE
>= hTestHandle
) {
713 INT32 hOldHandle
= hTestHandle
;
714 hTestHandle
= ODataStreamTest::test( L
"com.sun.star.io.DataInputStream" ,
715 TestObject
, hTestHandle
);
716 if( hTestHandle
== -1 ){
717 hTestHandle
= hOldHandle
;
722 XActiveDataSinkRef
rSink( TestObject
, USR_QUERY
);
723 XActiveDataSourceRef
rSource( TestObject
, USR_QUERY
);
725 XObjectInputStreamRef
rInput( TestObject
, USR_QUERY
);
726 XObjectOutputStreamRef
rOutput( TestObject
, USR_QUERY
);
729 XInterfaceRef x
= m_rFactory
->createInstance( L
"com.sun.star.io.Pipe");
731 XInputStreamRef
rPipeInput( x
, USR_QUERY
);
732 XOutputStreamRef
rPipeOutput( x
, USR_QUERY
);
734 x
= m_rFactory
->createInstance( L
"com.sun.star.io.MarkableInputStream" );
735 XInputStreamRef
markableInput( x
, USR_QUERY
);
736 XActiveDataSinkRef
markableSink( x
, USR_QUERY
);
738 x
= m_rFactory
->createInstance( L
"com.sun.star.io.MarkableOutputStream" );
739 XOutputStreamRef
markableOutput( x
, USR_QUERY
);
740 XActiveDataSourceRef
markableSource( x
, USR_QUERY
);
742 OSL_ASSERT( markableInput
.is() );
743 OSL_ASSERT( markableOutput
.is() );
744 OSL_ASSERT( markableSink
.is() );
745 OSL_ASSERT( markableSource
.is() );
747 markableSink
->setInputStream( rPipeInput
);
748 markableSource
->setOutputStream( rPipeOutput
);
751 x
= m_rFactory
->createInstance( L
"com.sun.star.io.ObjectInputStream" );
752 x
->queryInterface( XObjectInputStream::getSmartUik() , rInput
);
753 x
->queryInterface( XActiveDataSink::getSmartUik() , rSink
);
755 else if ( !rSource
.is() ) {
756 x
= m_rFactory
->createInstance( L
"com.sun.star.io.ObjectOutputStream" );
757 x
->queryInterface( XObjectOutputStream::getSmartUik() , rOutput
);
758 x
->queryInterface( XActiveDataSource::getSmartUik() , rSource
);
761 OSL_ASSERT( rPipeInput
.is() );
762 OSL_ASSERT( rPipeOutput
.is() );
764 rSink
->setInputStream( markableInput
);
765 rSource
->setOutputStream( markableOutput
);
767 OSL_ASSERT( rSink
->getInputStream().is() );
768 OSL_ASSERT( rSource
->getOutputStream().is() );
770 if( 1 + DATASTREAM_TEST_MAX_HANDLE
== hTestHandle
) {
771 testObject( rOutput
, rInput
);
773 rInput
->closeInput();
774 rOutput
->closeOutput();
778 catch( Exception
& e
) {
779 BUILD_ERROR( 0 , UStringToString( e
.getName() , CHARSET_SYSTEM
).GetCharStr() );
782 BUILD_ERROR( 0 , "unknown exception (Exception is not base class)" );
787 if( hTestHandle
> 1 +DATASTREAM_TEST_MAX_HANDLE
) {
788 // all tests finished.
793 BUILD_ERROR( 0 , "service not supported by test." );
799 BOOL
compareMyPropertySet( XPropertySetRef
&r1
, XPropertySetRef
&r2
)
803 if( r1
->getPropertyValue( L
"long" ).getReflection() == Void_getReflection() ||
804 r2
->getPropertyValue( L
"long" ).getReflection() == Void_getReflection() ) {
806 // one of the objects is not the correct propertyset !
810 b
= b
&& ( r1
->getPropertyValue( L
"long" ).getINT32() ==
811 r2
->getPropertyValue( L
"long" ).getINT32() );
813 b
= b
&& ( r1
->getPropertyValue( L
"float" ).getFloat() ==
814 r2
->getPropertyValue( L
"float" ).getFloat() );
816 b
= b
&& ( r1
->getPropertyValue( L
"double" ).getDouble() ==
817 r2
->getPropertyValue( L
"double" ).getDouble() );
819 b
= b
&& ( r1
->getPropertyValue( L
"bool" ).getBOOL() ==
820 r2
->getPropertyValue( L
"bool" ).getBOOL() );
822 b
= b
&& ( r1
->getPropertyValue( L
"byte" ).getBYTE() ==
823 r2
->getPropertyValue( L
"byte" ).getBYTE() );
825 b
= b
&& ( r1
->getPropertyValue( L
"char" ).getChar() ==
826 r2
->getPropertyValue( L
"char" ).getChar() );
828 b
= b
&& ( r1
->getPropertyValue( L
"string" ).getString() ==
829 r2
->getPropertyValue( L
"string" ).getString() );
831 UsrAny o1
= r1
->getPropertyValue( L
"object" );
832 UsrAny o2
= r2
->getPropertyValue( L
"object" );
834 if( o1
.getReflection() == XPersistObject_getReflection() ) {
836 if( o2
.getReflection() == XPersistObject_getReflection() ) {
837 XPersistObjectRef rPersist1
= *((XPersistObjectRef
*) o1
.get());
838 XPersistObjectRef rPersist2
= *((XPersistObjectRef
*) o2
.get());
839 XPropertySetRef
rProp1( rPersist1
, USR_QUERY
);
840 XPropertySetRef
rProp2( rPersist2
, USR_QUERY
);
842 if( rProp1
.is() && rProp2
.is() && ! ( rProp1
== rProp2
)
843 &&( rProp1
!= r1
)) {
844 compareMyPropertySet( rProp1
, rProp2
);
852 if( o2
.getReflection() == XPersistObject_getReflection() ) {
860 void OObjectStreamTest::testObject( const XObjectOutputStreamRef
&rOut
,
861 const XObjectInputStreamRef
&rIn
)
863 ERROR_ASSERT( rOut
.is() , "no objectOutputStream" );
864 ERROR_ASSERT( rIn
.is() , "no objectInputStream" );
866 XMultiServiceFactoryRef xProv
= getProcessServiceManager();
867 ERROR_ASSERT( xProv
.is() , "no global service manager" );
870 // tests, if saving an object with an unknown service name allows
871 // reading the data behind the object !
873 XInterfaceRef x
= * new MyPersistObject( L
"bla blubs" );
875 XPersistObjectRef
persistRef( x
, USR_QUERY
);
876 ERROR_ASSERT( persistRef
.is() , "couldn't instantiate PersistTest object" );
878 rOut
->writeObject( persistRef
);
879 rOut
->writeLong( (INT32
) 0xdeadbeef );
881 ERROR_ASSERT( 0 != rIn
->available() , "no data arrived at input" );
885 XPersistObjectRef xReadPersistRef
= rIn
->readObject();
886 ERROR_ASSERT( 0 , "expected exception not thrown" );
888 catch( IOException
& e
)
893 ERROR_ASSERT( (INT32
) 0xdeadbeef == rIn
->readLong() ,
894 "wrong data after object with unknown service name." );
898 XInterfaceRef x
= xProv
->createInstance(L
"test.com.sun.star.io.PersistTest");
899 XPersistObjectRef
persistRef( x
, USR_QUERY
);
901 ERROR_ASSERT( persistRef
.is() , "couldn't instantiate PersistTest object" );
903 XPropertySetRef
rProp( persistRef
, USR_QUERY
);
904 ERROR_ASSERT( rProp
.is() , "test object is no property set " );
907 any
.setINT32( 0x83482 );
908 rProp
->setPropertyValue( L
"long" , any
);
910 any
.setFloat( 42.23 );
911 rProp
->setPropertyValue( L
"float" , any
);
913 any
.setDouble( 233.321412 );
914 rProp
->setPropertyValue( L
"double" , any
);
917 rProp
->setPropertyValue( L
"bool" , any
);
920 rProp
->setPropertyValue( L
"byte" , any
);
923 rProp
->setPropertyValue( L
"char" , any
);
925 any
.setString( L
"hi du !" );
926 rProp
->setPropertyValue( L
"string" , any
);
928 any
.set( &persistRef
, XPersistObject_getReflection() ); // try a self reference
929 rProp
->setPropertyValue( L
"object" , any
);
932 rOut
->writeObject( persistRef
);
933 ERROR_ASSERT( 0 != rIn
->available() , "no data arrived at input" );
934 XPersistObjectRef xReadPersistRef
= rIn
->readObject( );
936 XPropertySetRef
rPropRead( xReadPersistRef
, USR_QUERY
);
937 ERROR_ASSERT( compareMyPropertySet( rProp
, rPropRead
) , "objects has not been read properly !" );
939 // destroy selfreferences
940 rProp
->setPropertyValue( L
"object", UsrAny() );
941 rPropRead
->setPropertyValue( L
"object", UsrAny() );
945 XMarkableStreamRef
markableOut( rOut
, USR_QUERY
);
946 ERROR_ASSERT( markableOut
.is() , "markable stream cannot be queried" );
948 // do the same thing multiple times to check if
949 // buffering and marks work correctly
950 for( int i
= 0 ; i
< 2000 ; i
++ ) {
952 XInterfaceRef x
= xProv
->createInstance(L
"test.com.sun.star.io.PersistTest");
953 XPersistObjectRef
persistRef( x
, USR_QUERY
);
955 XPropertySetRef
rProp( persistRef
, USR_QUERY
);
956 ERROR_ASSERT( rProp
.is() , "test object is no property set " );
959 any
.setINT32( 0x83482 );
960 rProp
->setPropertyValue( L
"long" , any
);
962 any
.setFloat( 42.23 );
963 rProp
->setPropertyValue( L
"float" , any
);
965 any
.setDouble( 233.321412 );
966 rProp
->setPropertyValue( L
"double" , any
);
969 rProp
->setPropertyValue( L
"bool" , any
);
972 rProp
->setPropertyValue( L
"byte" , any
);
975 rProp
->setPropertyValue( L
"char" , any
);
977 any
.setString( L
"hi du !" );
978 rProp
->setPropertyValue( L
"string" , any
);
981 x
= xProv
->createInstance(L
"test.com.sun.star.io.PersistTest");
982 XPersistObjectRef
persist2ndRef( x
, USR_QUERY
);
985 // Note : persist2ndRef contains coincident values, but also coincident values must be
987 any
.set( &persist2ndRef
, XPersistObject_getReflection() ); // try a self reference
988 rProp
->setPropertyValue( L
"object" , any
);
990 // simply test, if markable operations and object operations do not interfere
991 INT32 nMark
= markableOut
->createMark();
994 rOut
->writeObject( persistRef
);
996 // further markable tests !
997 INT32 nOffset
= markableOut
->offsetToMark( nMark
);
998 markableOut
->jumpToMark( nMark
);
999 markableOut
->deleteMark( nMark
);
1000 markableOut
->jumpToFurthest();
1006 ERROR_ASSERT( 0 != rIn
->available() , "no data arrived at input" );
1007 XPersistObjectRef xReadPersistRef
= rIn
->readObject( );
1009 XPropertySetRef
rProp1( persistRef
, USR_QUERY
);
1010 XPropertySetRef
rProp2( xReadPersistRef
, USR_QUERY
);
1011 ERROR_ASSERT( compareMyPropertySet( rProp1
, rProp2
) , "objects has not been read properly !" );
1017 XInterfaceRef
OObjectStreamTest_CreateInstance( const XMultiServiceFactoryRef
& rSMgr
) THROWS((Exception
))
1019 OObjectStreamTest
*p
= new OObjectStreamTest( rSMgr
);
1020 XInterfaceRef xService
= *p
;
1024 Sequence
<UString
> OObjectStreamTest_getSupportedServiceNames( int i
) THROWS(())
1026 Sequence
<UString
> aRet(1);
1027 aRet
.getArray()[0] = OObjectStreamTest_getImplementationName( i
);
1031 UString
OObjectStreamTest_getServiceName( int i
) THROWS(())
1034 return L
"test.com.sun.star.io.ObjectInputStream";
1037 return L
"test.com.sun.star.io.ObjectOutputStream";
1041 UString
OObjectStreamTest_getImplementationName( int i
) THROWS(())
1044 return L
"test.com.sun.star.comp.extensions.stm.ObjectInputStream";
1047 return L
"test.com.sun.star.comp.extensions.stm.ObjectOutputStream";
1052 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */