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 .
22 #include <com/sun/star/test/XSimpleTest.hpp>
23 #include <com/sun/star/io/XActiveDataSink.hpp>
24 #include <com/sun/star/io/XActiveDataSource.hpp>
25 #include <com/sun/star/io/XObjectInputStream.hpp>
26 #include <com/sun/star/io/XObjectOutputStream.hpp>
27 #include <com/sun/star/io/XMarkableStream.hpp>
28 #include <com/sun/star/io/XConnectable.hpp>
29 #include <com/sun/star/beans/XPropertySet.hpp>
30 #include <com/sun/star/lang/WrappedTargetException.hpp>
31 #include <com/sun/star/lang/IllegalArgumentException.hpp>
32 #include <com/sun/star/lang/XServiceInfo.hpp>
34 #include <cppuhelper/factory.hxx>
35 #include <cppuhelper/implbase.hxx>
37 #include <osl/conditn.hxx>
41 using namespace ::osl
;
42 using namespace ::cppu
;
43 using namespace ::com::sun::star::uno
;
44 using namespace ::com::sun::star::io
;
45 using namespace ::com::sun::star::lang
;
46 using namespace ::com::sun::star::test
;
47 using namespace ::com::sun::star::beans
;
50 #include "testfactreg.hxx"
52 #define DATASTREAM_TEST_MAX_HANDLE 1
55 * The following test class tests XDataInputStream and XDataOutputStream at equal terms,
56 * so when errors occur, it may be in either one implementation.
57 * The class also uses com.sun.star.io.pipe. If problems occur, make sure to run also the
58 * pipe test routines ( test.com.sun.star.io.pipe ).
61 class ODataStreamTest
:
62 public WeakImplHelper
< XSimpleTest
>
65 explicit ODataStreamTest( const Reference
< XMultiServiceFactory
> & rFactory
) :
66 m_rFactory( rFactory
)
70 virtual void SAL_CALL
testInvariant(const OUString
& TestName
, const Reference
< XInterface
>& TestObject
)
71 throw ( IllegalArgumentException
,
74 virtual sal_Int32 SAL_CALL
test( const OUString
& TestName
,
75 const Reference
< XInterface
>& TestObject
,
76 sal_Int32 hTestHandle
)
77 throw ( IllegalArgumentException
,
80 virtual sal_Bool SAL_CALL
testPassed() throw ( RuntimeException
);
81 virtual Sequence
< OUString
> SAL_CALL
getErrors() throw (RuntimeException
);
82 virtual Sequence
< Any
> SAL_CALL
getErrorExceptions() throw (RuntimeException
);
83 virtual Sequence
< OUString
> SAL_CALL
getWarnings() throw (RuntimeException
);
86 void testSimple( const Reference
< XDataInputStream
> & , const Reference
< XDataOutputStream
> &);
89 Sequence
<Any
> m_seqExceptions
;
90 Sequence
<OUString
> m_seqErrors
;
91 Sequence
<OUString
> m_seqWarnings
;
93 Reference
< XMultiServiceFactory
> m_rFactory
;
97 void ODataStreamTest::testInvariant(
98 const OUString
& TestName
,
99 const Reference
< XInterface
>& TestObject
)
100 throw ( IllegalArgumentException
,
103 if( OUString("com.sun.star.io.DataInputStream") == TestName
) {
104 Reference
< XConnectable
> connect( TestObject
, UNO_QUERY
);
105 Reference
< XActiveDataSink
> active( TestObject
, UNO_QUERY
);
106 Reference
< XInputStream
> input( TestObject
, UNO_QUERY
);
107 Reference
< XDataInputStream
> dataInput( TestObject
, UNO_QUERY
);
109 WARNING_ASSERT( connect
.is(), "XConnectable cannot be queried" );
110 WARNING_ASSERT( active
.is() , "XActiveDataSink cannot be queried" );
111 ERROR_ASSERT( input
.is() , "XInputStream cannot be queried" );
112 ERROR_ASSERT( dataInput
.is() , "XDataInputStream cannot be queried" );
116 else if( OUString("com.sun.star.io.DataOutputStream") == TestName
) {
117 Reference
< XConnectable
> connect( TestObject
, UNO_QUERY
);
118 Reference
< XActiveDataSource
> active( TestObject
, UNO_QUERY
);
119 Reference
< XOutputStream
> output( TestObject
, UNO_QUERY
);
120 Reference
< XDataOutputStream
> dataOutput( TestObject
, UNO_QUERY
);
122 WARNING_ASSERT( connect
.is(), "XConnectable cannot be queried" );
123 WARNING_ASSERT( active
.is() , "XActiveDataSink cannot be queried" );
124 ERROR_ASSERT( output
.is() , "XInputStream cannot be queried" );
125 ERROR_ASSERT( dataOutput
.is(), "XDataInputStream cannot be queried" );
129 Reference
< XServiceInfo
> info( TestObject
, UNO_QUERY
);
130 ERROR_ASSERT( info
.is() , "XServiceInfo not supported !" );
133 ERROR_ASSERT( info
->supportsService( TestName
), "XServiceInfo test failed" );
134 ERROR_ASSERT( ! info
->supportsService("bla bluzb") , "XServiceInfo test failed" );
140 sal_Int32
ODataStreamTest::test(
141 const OUString
& TestName
,
142 const Reference
< XInterface
>& TestObject
,
143 sal_Int32 hTestHandle
)
144 throw ( IllegalArgumentException
,
147 if( OUString("com.sun.star.io.DataInputStream") == TestName
||
148 OUString("com.sun.star.io.DataOutputStream") == TestName
) {
152 if( 0 == hTestHandle
) {
153 testInvariant( TestName
, TestObject
);
156 Reference
<XActiveDataSink
> rSink( TestObject
, UNO_QUERY
);
157 Reference
<XActiveDataSource
> rSource( TestObject
, UNO_QUERY
);
159 Reference
< XDataInputStream
> rInput( TestObject
, UNO_QUERY
);
160 Reference
< XDataOutputStream
> rOutput( TestObject
, UNO_QUERY
);
163 Reference
< XInterface
> x
= m_rFactory
->createInstance(
164 "com.sun.star.io.Pipe" );
166 Reference
< XInputStream
> rPipeInput( x
, UNO_QUERY
);
167 Reference
< XOutputStream
> rPipeOutput( x
, UNO_QUERY
);
170 x
= m_rFactory
->createInstance(
171 "com.sun.star.io.DataInputStream" );
172 rInput
.set( x
, UNO_QUERY
);
173 rSink
.set( x
, UNO_QUERY
);
175 else if ( !rSource
.is() )
177 x
= m_rFactory
->createInstance(
178 "com.sun.star.io.DataOutputStream" );
179 rOutput
.set( x
, UNO_QUERY
);
180 rSource
.set( x
, UNO_QUERY
);
183 OSL_ASSERT( rPipeInput
.is() );
184 OSL_ASSERT( rPipeOutput
.is() );
185 rSink
->setInputStream( rPipeInput
);
186 rSource
->setOutputStream( rPipeOutput
);
188 OSL_ASSERT( rSink
->getInputStream().is() );
189 OSL_ASSERT( rSource
->getOutputStream().is() );
191 if( 1 == hTestHandle
) {
192 testSimple( rInput
, rOutput
);
196 catch( const Exception
& e
)
198 OString o
= OUStringToOString( e
.Message
, RTL_TEXTENCODING_ASCII_US
);
199 BUILD_ERROR( 0 , o
.getStr() );
203 BUILD_ERROR( 0 , "unknown exception (Exception is not base class)" );
208 if( hTestHandle
>= 2) {
209 // all tests finished.
214 BUILD_ERROR( 0 , "service not supported by test." );
220 sal_Bool
ODataStreamTest::testPassed() throw (RuntimeException
)
222 return m_seqErrors
.getLength() == 0;
226 Sequence
< OUString
> ODataStreamTest::getErrors() throw (RuntimeException
)
232 Sequence
< Any
> ODataStreamTest::getErrorExceptions() throw (RuntimeException
)
234 return m_seqExceptions
;
238 Sequence
< OUString
> ODataStreamTest::getWarnings() throw (RuntimeException
)
240 return m_seqWarnings
;
243 void ODataStreamTest::testSimple( const Reference
< XDataInputStream
> &rInput
,
244 const Reference
< XDataOutputStream
> &rOutput
)
246 rOutput
->writeLong( 0x34ff3c );
247 rOutput
->writeLong( 0x34ff3d );
248 rOutput
->writeLong( -1027 );
250 ERROR_ASSERT( 0x34ff3c == rInput
->readLong() , "long read/write mismatch" );
251 ERROR_ASSERT( 0x34ff3d == rInput
->readLong() , "long read/write mismatch" );
252 ERROR_ASSERT( -1027 == rInput
->readLong() , "long read/write mismatch" );
254 rOutput
->writeByte( 0x77 );
255 ERROR_ASSERT( 0x77 == rInput
->readByte() , "byte read/write mismatch" );
257 rOutput
->writeBoolean( 25 );
258 ERROR_ASSERT( rInput
->readBoolean() , "boolean read/write mismatch" );
260 rOutput
->writeBoolean( sal_False
);
261 ERROR_ASSERT( ! rInput
->readBoolean() , "boolean read/write mismatch" );
263 rOutput
->writeFloat( (float) 42.42 );
264 ERROR_ASSERT( rInput
->readFloat() == ((float)42.42) , "float read/write mismatch" );
266 rOutput
->writeDouble( (double) 42.42 );
267 ERROR_ASSERT( rInput
->readDouble() == 42.42 , "double read/write mismatch" );
269 rOutput
->writeHyper( 0x123456789abcdefLL
);
270 ERROR_ASSERT( rInput
->readHyper() == 0x123456789abcdefLL
, "int64 read/write mismatch" );
272 rOutput
->writeUTF( OUString("Live long and prosper !") );
273 ERROR_ASSERT( rInput
->readUTF() == "Live long and prosper !",
274 "UTF read/write mismatch" );
276 Sequence
<sal_Unicode
> wc(0x10001);
277 for( int i
= 0 ; i
< 0x10000 ; i
++ ) {
278 wc
.getArray()[i
] = L
'c';
280 wc
.getArray()[0x10000] = 0;
281 OUString
str( wc
.getArray() , 0x10000 );
282 rOutput
->writeUTF( str
);
283 ERROR_ASSERT( rInput
->readUTF() == str
, "error reading 64k block" );
285 rOutput
->closeOutput();
289 ERROR_ASSERT( 0 , "eof-exception does not occur !" );
291 catch ( IOException
& )
297 ERROR_ASSERT( 0 , "wrong exception after reading beyond eof" );
300 Sequence
<sal_Int8
> dummy (1);
301 ERROR_ASSERT( ! rInput
->readBytes( dummy
, 1 ),
302 "stream must be on eof !" );
304 rInput
->closeInput();
308 rOutput
->writeByte( 1 );
309 ERROR_ASSERT( 0 , "writing still possible though chain must be interrupted" );
311 catch( IOException
& )
316 ERROR_ASSERT( 0 , "IOException expected, but another exception was thrown" );
323 * for external binding
327 Reference
< XInterface
> SAL_CALL
ODataStreamTest_CreateInstance( const Reference
< XMultiServiceFactory
> & rSMgr
) throw(Exception
)
329 ODataStreamTest
*p
= new ODataStreamTest( rSMgr
);
330 return Reference
< XInterface
> ( (static_cast< OWeakObject
* >(p
)) );
333 Sequence
<OUString
> ODataStreamTest_getSupportedServiceNames( int i
) throw ()
335 Sequence
<OUString
> aRet
{ ODataStreamTest_getImplementationName( i
) };
339 OUString
ODataStreamTest_getServiceName( int i
) throw ()
342 return OUString( "test.com.sun.star.io.DataInputStream" );
345 return OUString( "test.com.sun.star.io.DataOutputStream" );
349 OUString
ODataStreamTest_getImplementationName( int i
) throw ()
353 "test.com.sun.star.comp.extensions.stm.DataInputStream" );
356 return OUString( "test.com.sun.star.comp.extensions.stm.DataOutputStream" );
360 class MyPersistObject
: public WeakImplHelper
< XPersistObject
, XPropertySet
>
363 MyPersistObject( ) : m_sServiceName( OMyPersistObject_getServiceName() ) ,
370 m_s( OUString( "foo" ) )
372 explicit MyPersistObject( const OUString
& sServiceName
) : m_sServiceName( sServiceName
)
377 virtual OUString SAL_CALL
getServiceName() throw (RuntimeException
);
378 virtual void SAL_CALL
write( const Reference
< XObjectOutputStream
>& OutStream
)
379 throw (IOException
, RuntimeException
);
380 virtual void SAL_CALL
read(const Reference
< XObjectInputStream
>& InStream
)
381 throw (IOException
, RuntimeException
);
385 virtual Reference
< XPropertySetInfo
> SAL_CALL
getPropertySetInfo()
386 throw (RuntimeException
);
388 virtual void SAL_CALL
setPropertyValue(const OUString
& aPropertyName
, const Any
& aValue
)
389 throw ( UnknownPropertyException
,
390 PropertyVetoException
,
391 IllegalArgumentException
,
392 WrappedTargetException
,
394 virtual Any SAL_CALL
getPropertyValue(const OUString
& PropertyName
)
395 throw ( UnknownPropertyException
,
396 WrappedTargetException
,
398 virtual void SAL_CALL
addPropertyChangeListener(
399 const OUString
& aPropertyName
,
400 const Reference
< XPropertyChangeListener
> & xListener
)
401 throw ( UnknownPropertyException
,
402 WrappedTargetException
,
405 virtual void SAL_CALL
removePropertyChangeListener(
406 const OUString
& aPropertyName
,
407 const Reference
< XPropertyChangeListener
> & aListener
)
408 throw ( UnknownPropertyException
,
409 WrappedTargetException
,
411 virtual void SAL_CALL
addVetoableChangeListener(
412 const OUString
& PropertyName
,
413 const Reference
< XVetoableChangeListener
> & aListener
)
414 throw ( UnknownPropertyException
,
415 WrappedTargetException
,
418 virtual void SAL_CALL
removeVetoableChangeListener(
419 const OUString
& PropertyName
,
420 const Reference
< XVetoableChangeListener
>& aListener
)
421 throw ( UnknownPropertyException
,
422 WrappedTargetException
,
433 Reference
< XPersistObject
> m_ref
;
434 OUString m_sServiceName
;
438 Reference
<XPropertySetInfo
> MyPersistObject::getPropertySetInfo()
439 throw (RuntimeException
)
441 return Reference
< XPropertySetInfo
>();
444 void MyPersistObject::setPropertyValue(
445 const OUString
& aPropertyName
,
447 throw ( UnknownPropertyException
,
448 PropertyVetoException
,
449 IllegalArgumentException
,
450 WrappedTargetException
,
453 if( aPropertyName
.equalsAscii("long") ) {
456 else if ( aPropertyName
.equalsAscii("float") ) {
459 else if( aPropertyName
.equalsAscii("double") ) {
462 else if( aPropertyName
.equalsAscii("bool") ) {
465 else if( aPropertyName
.equalsAscii("byte" ) ) {
468 else if( aPropertyName
.equalsAscii("char") ) {
471 else if( aPropertyName
.equalsAscii("string") ) {
474 else if( aPropertyName
.equalsAscii("object") ) {
475 if( aValue
.getValueType() == cppu::UnoType
<XPersistObject
>::get())
487 Any
MyPersistObject::getPropertyValue(const OUString
& aPropertyName
)
488 throw ( UnknownPropertyException
,
489 WrappedTargetException
,
493 if( aPropertyName
.equalsAscii("long" ) ) {
496 else if ( aPropertyName
.equalsAscii("float") ) {
499 else if( aPropertyName
.equalsAscii("double") ) {
502 else if( aPropertyName
.equalsAscii("bool") ) {
505 else if( aPropertyName
.equalsAscii("byte") ) {
508 else if( aPropertyName
.equalsAscii("char" ) ) {
511 else if( aPropertyName
.equalsAscii("string") ) {
514 else if( aPropertyName
.equalsAscii("object" ) )
522 void MyPersistObject::addPropertyChangeListener(
523 const OUString
& aPropertyName
,
524 const Reference
< XPropertyChangeListener
> & xListener
)
525 throw ( UnknownPropertyException
,
526 WrappedTargetException
,
532 void MyPersistObject::removePropertyChangeListener(
533 const OUString
& aPropertyName
,
534 const Reference
< XPropertyChangeListener
> & aListener
)
535 throw ( UnknownPropertyException
,
536 WrappedTargetException
,
542 void MyPersistObject::addVetoableChangeListener(
543 const OUString
& PropertyName
,
544 const Reference
<XVetoableChangeListener
>& aListener
)
545 throw ( UnknownPropertyException
,
546 WrappedTargetException
,
552 void MyPersistObject::removeVetoableChangeListener(
553 const OUString
& PropertyName
,
554 const Reference
< XVetoableChangeListener
> & aListener
)
555 throw ( UnknownPropertyException
,
556 WrappedTargetException
,
563 OUString
MyPersistObject::getServiceName() throw (RuntimeException
)
565 return m_sServiceName
;
568 void MyPersistObject::write( const Reference
< XObjectOutputStream
> & rOut
)
569 throw (IOException
,RuntimeException
)
571 rOut
->writeLong( m_l
);
572 rOut
->writeFloat( m_f
);
573 rOut
->writeDouble( m_d
);
574 rOut
->writeBoolean( m_b
);
575 rOut
->writeByte( m_byte
);
576 rOut
->writeChar( m_c
);
577 rOut
->writeUTF( m_s
);
578 rOut
->writeObject( m_ref
);
582 void MyPersistObject::read( const Reference
< XObjectInputStream
> & rIn
)
583 throw (IOException
, RuntimeException
)
585 m_l
= rIn
->readLong();
586 m_f
= rIn
->readFloat();
587 m_d
= rIn
->readDouble();
588 m_b
= rIn
->readBoolean();
589 m_byte
= rIn
->readByte();
590 m_c
= rIn
->readChar();
591 m_s
= rIn
->readUTF();
592 m_ref
= rIn
->readObject();
595 Reference
< XInterface
> SAL_CALL
OMyPersistObject_CreateInstance(
596 const Reference
< XMultiServiceFactory
> & rSMgr
)
599 MyPersistObject
*p
= new MyPersistObject( );
600 return Reference
< XInterface
> ( (static_cast< OWeakObject
* >(p
)) );
603 Sequence
<OUString
> OMyPersistObject_getSupportedServiceNames( ) throw ()
605 Sequence
<OUString
> aRet
{ OMyPersistObject_getImplementationName() };
609 OUString
OMyPersistObject_getServiceName( ) throw ()
611 return OUString( "test.com.sun.star.io.PersistTest" );
614 OUString
OMyPersistObject_getImplementationName( ) throw ()
616 return OUString( "test.com.sun.star.io.PersistTest" );
619 class OObjectStreamTest
:
620 public ODataStreamTest
623 explicit OObjectStreamTest( const Reference
< XMultiServiceFactory
> &r
) : ODataStreamTest(r
) {}
626 virtual void SAL_CALL
testInvariant(const OUString
& TestName
,
627 const Reference
< XInterface
>& TestObject
)
628 throw ( IllegalArgumentException
,
631 virtual sal_Int32 SAL_CALL
test(
632 const OUString
& TestName
,
633 const Reference
< XInterface
>& TestObject
,
634 sal_Int32 hTestHandle
)
635 throw ( IllegalArgumentException
,
640 void testObject( const Reference
<XObjectOutputStream
> &rOut
,
641 const Reference
<XObjectInputStream
> &rIn
);
647 void OObjectStreamTest::testInvariant( const OUString
& TestName
,
648 const Reference
< XInterface
>& TestObject
)
649 throw ( IllegalArgumentException
, RuntimeException
)
652 if( OUString( "com.sun.star.io.ObjectInputStream" )
655 ODataStreamTest::testInvariant( TestName
, TestObject
);
656 Reference
< XObjectInputStream
> dataInput( TestObject
, UNO_QUERY
);
657 Reference
< XMarkableStream
> markable( TestObject
, UNO_QUERY
);
658 ERROR_ASSERT( dataInput
.is() , "XObjectInputStream cannot be queried" );
659 ERROR_ASSERT( markable
.is() , "XMarkableStream cannot be queried" );
661 else if( OUString( "com.sun.star.io.ObjectOutputStream" )
664 ODataStreamTest::testInvariant( TestName
, TestObject
);
665 Reference
< XMarkableStream
> markable( TestObject
, UNO_QUERY
);
666 Reference
< XObjectOutputStream
> dataOutput( TestObject
, UNO_QUERY
);
667 ERROR_ASSERT( dataOutput
.is(), "XObjectOutputStream cannot be queried" );
668 ERROR_ASSERT( markable
.is() , "XMarkableStream cannot be queried" );
671 Reference
< XServiceInfo
> info( TestObject
, UNO_QUERY
);
672 ERROR_ASSERT( info
.is() , "XServiceInfo not supported !" );
675 ERROR_ASSERT( info
->supportsService( TestName
), "XServiceInfo test failed" );
676 ERROR_ASSERT( ! info
->supportsService("bla bluzb") , "XServiceInfo test failed" );
681 sal_Int32
OObjectStreamTest::test( const OUString
& TestName
,
682 const Reference
< XInterface
>& TestObject
,
683 sal_Int32 hTestHandle
)
684 throw ( IllegalArgumentException
,
687 if( TestName
.equalsAscii("com.sun.star.io.ObjectInputStream") ||
688 TestName
.equalsAscii("com.sun.star.io.ObjectOutputStream") ) {
692 if( 0 == hTestHandle
) {
693 testInvariant( TestName
, TestObject
);
695 else if( DATASTREAM_TEST_MAX_HANDLE
>= hTestHandle
) {
696 sal_Int32 hOldHandle
= hTestHandle
;
697 hTestHandle
= ODataStreamTest::test(
698 OUString( "com.sun.star.io.DataInputStream" ),
699 TestObject
, hTestHandle
);
700 if( hTestHandle
== -1 ){
701 hTestHandle
= hOldHandle
;
706 Reference
<XActiveDataSink
> rSink( TestObject
, UNO_QUERY
);
707 Reference
<XActiveDataSource
> rSource( TestObject
, UNO_QUERY
);
709 Reference
< XObjectInputStream
> rInput( TestObject
, UNO_QUERY
);
710 Reference
< XObjectOutputStream
> rOutput( TestObject
, UNO_QUERY
);
713 Reference
< XInterface
> x
= m_rFactory
->createInstance(
714 "com.sun.star.io.Pipe" );
716 Reference
<XInputStream
> rPipeInput( x
, UNO_QUERY
);
717 Reference
<XOutputStream
> rPipeOutput( x
, UNO_QUERY
);
719 x
= m_rFactory
->createInstance(
720 "com.sun.star.io.MarkableInputStream" );
722 Reference
<XInputStream
> markableInput( x
, UNO_QUERY
);
723 Reference
<XActiveDataSink
> markableSink( x
, UNO_QUERY
);
725 x
= m_rFactory
->createInstance( "com.sun.star.io.MarkableOutputStream" );
726 Reference
<XOutputStream
> markableOutput( x
, UNO_QUERY
);
727 Reference
<XActiveDataSource
> markableSource( x
, UNO_QUERY
);
729 OSL_ASSERT( markableInput
.is() );
730 OSL_ASSERT( markableOutput
.is() );
731 OSL_ASSERT( markableSink
.is() );
732 OSL_ASSERT( markableSource
.is() );
734 markableSink
->setInputStream( rPipeInput
);
735 markableSource
->setOutputStream( rPipeOutput
);
738 x
= m_rFactory
->createInstance(
739 "com.sun.star.io.ObjectInputStream" );
740 rInput
.set( x
, UNO_QUERY
);
741 rSink
.set( x
, UNO_QUERY
);
743 else if ( !rSource
.is() ) {
744 x
= m_rFactory
->createInstance(
745 "com.sun.star.io.ObjectOutputStream" );
746 rOutput
.set( x
, UNO_QUERY
);
747 rSource
.set( x
, UNO_QUERY
);
750 OSL_ASSERT( rPipeInput
.is() );
751 OSL_ASSERT( rPipeOutput
.is() );
753 rSink
->setInputStream( markableInput
);
754 rSource
->setOutputStream( markableOutput
);
756 OSL_ASSERT( rSink
->getInputStream().is() );
757 OSL_ASSERT( rSource
->getOutputStream().is() );
759 if( 1 + DATASTREAM_TEST_MAX_HANDLE
== hTestHandle
) {
760 testObject( rOutput
, rInput
);
762 rInput
->closeInput();
763 rOutput
->closeOutput();
767 catch( const Exception
&e
) {
768 OString o
= OUStringToOString( e
.Message
, RTL_TEXTENCODING_ASCII_US
);
769 BUILD_ERROR( 0 , o
.getStr() );
772 BUILD_ERROR( 0 , "unknown exception (Exception is not base class)" );
777 if( hTestHandle
> 1 +DATASTREAM_TEST_MAX_HANDLE
) {
778 // all tests finished.
783 BUILD_ERROR( 0 , "service not supported by test." );
789 sal_Bool
compareMyPropertySet( Reference
< XPropertySet
> &r1
, Reference
< XPropertySet
> &r2
)
791 sal_Bool b
= sal_True
;
793 if( r1
->getPropertyValue("long").getValueType() == cppu::UnoType
<void>::get() ||
794 r2
->getPropertyValue("long").getValueType() == cppu::UnoType
<void>::get() ) {
796 // one of the objects is not the correct propertyset !
797 fprintf( stderr
, "compareMyPropertySet: 1\n" );
801 b
= b
&& ( r1
->getPropertyValue("long") ==
802 r2
->getPropertyValue("long") );
803 if( ! b
) fprintf( stderr
, "compareMyPropertySet: 2\n" );
805 b
= b
&& ( r1
->getPropertyValue("float") ==
806 r2
->getPropertyValue("float") );
810 r1
->getPropertyValue("float") >>= f1
;
811 r2
->getPropertyValue("float") >>= f2
;
812 fprintf( stderr
, "compareMyPropertySet: %f %f 3\n",f1
,f2
);
815 b
= b
&& ( r1
->getPropertyValue("double") ==
816 r2
->getPropertyValue("double") );
817 if( ! b
) fprintf( stderr
, "compareMyPropertySet: 4\n" );
819 sal_Bool
b1(sal_False
), b2(sal_False
);
820 Any a
=r1
->getPropertyValue("bool");
822 a
= r2
->getPropertyValue("bool");
824 b
= b
&& ( (b1
&& b2
) || b1
== b2
);
825 if( ! b
) fprintf( stderr
, "compareMyPropertySet: 5\n" );
827 // b = b && r1->getPropertyValue("bool") ==
828 // r2->getPropertyValue("bool") );
830 b
= b
&& ( r1
->getPropertyValue("byte") ==
831 r2
->getPropertyValue("byte") );
832 if( ! b
) fprintf( stderr
, "compareMyPropertySet: 6\n" );
834 b
= b
&& ( r1
->getPropertyValue("char") ==
835 r2
->getPropertyValue("char") );
836 if( ! b
) fprintf( stderr
, "compareMyPropertySet: 7\n" );
838 b
= b
&& ( r1
->getPropertyValue("string") ==
839 r2
->getPropertyValue("string"));
840 if( ! b
) fprintf( stderr
, "compareMyPropertySet: 8\n" );
842 Any o1
= r1
->getPropertyValue("object");
843 Any o2
= r2
->getPropertyValue("object");
845 if( o1
.getValueType() == cppu::UnoType
<XPersistObject
>::get()) {
847 if( o2
.getValueType() == cppu::UnoType
<XPersistObject
>::get()) {
848 Reference
< XPersistObject
> rPersist1
;
849 Reference
< XPersistObject
> rPersist2
;
852 Reference
<XPropertySet
> rProp1( rPersist1
, UNO_QUERY
);
853 Reference
< XPropertySet
> rProp2( rPersist2
, UNO_QUERY
);
855 if( rProp1
.is() && rProp2
.is() && ! ( rProp1
== rProp2
)
856 &&( rProp1
!= r1
)) {
857 b
= b
&& compareMyPropertySet( rProp1
, rProp2
);
863 if( ! b
) fprintf( stderr
, "compareMyPropertySet: 9\n" );
866 if( o2
.getValueType() == cppu::UnoType
<XPersistObject
>::get()) {
869 if( ! b
) fprintf( stderr
, "compareMyPropertySet: 10\n" );
875 void OObjectStreamTest::testObject( const Reference
< XObjectOutputStream
> &rOut
,
876 const Reference
< XObjectInputStream
> &rIn
)
878 ERROR_ASSERT( rOut
.is() , "no objectOutputStream" );
879 ERROR_ASSERT( rIn
.is() , "no objectInputStream" );
882 // tests, if saving an object with an unknown service name allows
883 // reading the data behind the object !
885 Reference
< XInterface
> x
= * new MyPersistObject(
886 OUString( "bla blubs") );
888 Reference
< XPersistObject
> persistRef( x
, UNO_QUERY
);
889 ERROR_ASSERT( persistRef
.is() , "couldn't instantiate PersistTest object" );
891 rOut
->writeObject( persistRef
);
892 rOut
->writeLong( (sal_Int32
) 0xdeadbeef );
894 ERROR_ASSERT( 0 != rIn
->available() , "no data arrived at input" );
898 Reference
<XPersistObject
> xReadPersistRef
= rIn
->readObject();
899 ERROR_ASSERT( 0 , "expected exception not thrown" );
901 catch( IOException
& )
906 ERROR_ASSERT( (sal_Int32
) 0xdeadbeef == rIn
->readLong() ,
907 "wrong data after object with unknown service name." );
911 Reference
< XInterface
> x
= m_rFactory
->createInstance(
912 "test.com.sun.star.io.PersistTest");
913 Reference
< XPersistObject
> persistRef( x
, UNO_QUERY
);
915 ERROR_ASSERT( persistRef
.is() , "couldn't instantiate PersistTest object" );
917 Reference
< XPropertySet
> rProp( persistRef
, UNO_QUERY
);
918 ERROR_ASSERT( rProp
.is() , "test object is no property set " );
921 sal_Int32 i
= 0x83482;
923 rProp
->setPropertyValue("long", any
);
925 float f
= (float)42.23;
927 rProp
->setPropertyValue("float", any
);
929 double d
= 233.321412;
931 rProp
->setPropertyValue("double", any
);
933 sal_Bool b
= sal_True
;
934 any
.setValue( &b
, cppu::UnoType
<bool>::get() );
935 rProp
->setPropertyValue("bool", any
);
939 rProp
->setPropertyValue("byte", any
);
942 any
.setValue( &c
, cppu::UnoType
<cppu::UnoCharType
>::get() );
943 rProp
->setPropertyValue("char", any
);
945 OUString
str( "hi du !" );
947 rProp
->setPropertyValue("string", any
);
950 rProp
->setPropertyValue("object", any
);
953 rOut
->writeObject( persistRef
);
954 ERROR_ASSERT( 0 != rIn
->available() , "no data arrived at input" );
955 Reference
< XPersistObject
> xReadPersist
= rIn
->readObject( );
957 Reference
< XPropertySet
> rPropRead( xReadPersist
, UNO_QUERY
);
958 ERROR_ASSERT( compareMyPropertySet( rProp
, rPropRead
) , "objects has not been read properly !" );
960 // destroy selfreferences
961 rProp
->setPropertyValue("object", Any() );
962 rPropRead
->setPropertyValue("object", Any() );
966 Reference
< XMarkableStream
> markableOut( rOut
, UNO_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 Reference
< XInterface
> x
= m_rFactory
->createInstance("test.com.sun.star.io.PersistTest");
974 Reference
< XPersistObject
> persistRef( x
, UNO_QUERY
);
976 Reference
< XPropertySet
> rProp( persistRef
, UNO_QUERY
);
977 ERROR_ASSERT( rProp
.is() , "test object is no property set " );
980 sal_Int32 i
= 0x83482;
982 rProp
->setPropertyValue("long", any
);
986 rProp
->setPropertyValue("float", any
);
988 double d
= 233.321412;
990 rProp
->setPropertyValue("double", any
);
992 sal_Bool b
= sal_True
;
993 any
.setValue( &b
, cppu::UnoType
<bool>::get() );
994 rProp
->setPropertyValue("bool", any
);
998 rProp
->setPropertyValue("byte", any
);
1000 sal_Unicode c
= 'h';
1001 any
.setValue( &c
, cppu::UnoType
<cppu::UnoCharType
>::get() );
1002 rProp
->setPropertyValue("char", any
);
1004 OUString
str( "hi du !" );
1006 rProp
->setPropertyValue("string", any
);
1008 x
= m_rFactory
->createInstance("test.com.sun.star.io.PersistTest");
1009 Reference
<XPersistObject
> persist2ndRef( x
, UNO_QUERY
);
1011 // Note : persist2ndRef contains coincident values, but also coincident values must be
1013 any
<<= persist2ndRef
;
1014 rProp
->setPropertyValue("object", any
);
1016 // simply test, if markable operations and object operations do not interfere
1017 sal_Int32 nMark
= markableOut
->createMark();
1019 // do read and write
1020 rOut
->writeObject( persistRef
);
1022 // further markable tests !
1023 sal_Int32 nOffset
= markableOut
->offsetToMark( nMark
);
1024 markableOut
->jumpToMark( nMark
);
1025 markableOut
->deleteMark( nMark
);
1026 markableOut
->jumpToFurthest();
1029 ERROR_ASSERT( 0 != rIn
->available() , "no data arrived at input" );
1030 Reference
< XPersistObject
> xReadPersistRef
= rIn
->readObject( );
1032 Reference
< XPropertySet
> rProp1( persistRef
, UNO_QUERY
);
1033 Reference
< XPropertySet
> rProp2( xReadPersistRef
, UNO_QUERY
);
1034 ERROR_ASSERT( compareMyPropertySet( rProp1
, rProp2
) ,
1035 "objects has not been read properly !" );
1041 Reference
< XInterface
> SAL_CALL
OObjectStreamTest_CreateInstance( const Reference
< XMultiServiceFactory
> & rSMgr
) throw(Exception
)
1043 OObjectStreamTest
*p
= new OObjectStreamTest( rSMgr
);
1044 return Reference
< XInterface
> ( (static_cast< OWeakObject
* >(p
)) );
1047 Sequence
<OUString
> OObjectStreamTest_getSupportedServiceNames( int i
) throw ()
1049 Sequence
<OUString
> aRet
{ OObjectStreamTest_getImplementationName( i
) };
1053 OUString
OObjectStreamTest_getServiceName( int i
) throw ()
1056 return OUString( "test.com.sun.star.io.ObjectInputStream" );
1059 return OUString( "test.com.sun.star.io.ObjectOutputStream");
1063 OUString
OObjectStreamTest_getImplementationName( int i
) throw ()
1066 return OUString( "test.com.sun.star.comp.extensions.stm.ObjectInputStream" );
1069 return OUString( "test.com.sun.star.comp.extensions.stm.ObjectOutputStream");
1074 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */