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 ************************************************************************/
32 #include <com/sun/star/test/XSimpleTest.hpp>
33 #include <com/sun/star/io/XActiveDataSink.hpp>
34 #include <com/sun/star/io/XActiveDataSource.hpp>
35 #include <com/sun/star/io/XObjectInputStream.hpp>
36 #include <com/sun/star/io/XObjectOutputStream.hpp>
37 #include <com/sun/star/io/XMarkableStream.hpp>
38 #include <com/sun/star/io/XConnectable.hpp>
39 #include <com/sun/star/beans/XPropertySet.hpp>
40 #include <com/sun/star/lang/WrappedTargetException.hpp>
42 #include <com/sun/star/lang/IllegalArgumentException.hpp>
44 #include <com/sun/star/lang/XServiceInfo.hpp>
46 #include <cppuhelper/factory.hxx>
48 #include <cppuhelper/implbase1.hxx>
49 #include <cppuhelper/implbase2.hxx>
51 #include <osl/conditn.hxx>
52 #include <osl/mutex.hxx>
56 using namespace ::rtl
;
57 using namespace ::osl
;
58 using namespace ::cppu
;
59 using namespace ::com::sun::star::uno
;
60 using namespace ::com::sun::star::io
;
61 using namespace ::com::sun::star::lang
;
62 using namespace ::com::sun::star::test
;
63 using namespace ::com::sun::star::beans
;
66 #include "testfactreg.hxx"
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
:
80 public WeakImplHelper1
< XSimpleTest
>
83 ODataStreamTest( const Reference
< XMultiServiceFactory
> & rFactory
) :
84 m_rFactory( rFactory
)
88 virtual void SAL_CALL
testInvariant(const OUString
& TestName
, const Reference
< XInterface
>& TestObject
)
89 throw ( IllegalArgumentException
,
92 virtual sal_Int32 SAL_CALL
test( const OUString
& TestName
,
93 const Reference
< XInterface
>& TestObject
,
94 sal_Int32 hTestHandle
)
95 throw ( IllegalArgumentException
,
98 virtual sal_Bool SAL_CALL
testPassed(void) throw ( RuntimeException
);
99 virtual Sequence
< OUString
> SAL_CALL
getErrors(void) throw (RuntimeException
);
100 virtual Sequence
< Any
> SAL_CALL
getErrorExceptions(void) throw (RuntimeException
);
101 virtual Sequence
< OUString
> SAL_CALL
getWarnings(void) throw (RuntimeException
);
104 void testSimple( const Reference
< XDataInputStream
> & , const Reference
< XDataOutputStream
> &);
107 Sequence
<Any
> m_seqExceptions
;
108 Sequence
<OUString
> m_seqErrors
;
109 Sequence
<OUString
> m_seqWarnings
;
111 Reference
< XMultiServiceFactory
> m_rFactory
;
117 void ODataStreamTest::testInvariant(
118 const OUString
& TestName
,
119 const Reference
< XInterface
>& TestObject
)
120 throw ( IllegalArgumentException
,
123 if( OUString("com.sun.star.io.DataInputStream") == TestName
) {
124 Reference
< XConnectable
> connect( TestObject
, UNO_QUERY
);
125 Reference
< XActiveDataSink
> active( TestObject
, UNO_QUERY
);
126 Reference
< XInputStream
> input( TestObject
, UNO_QUERY
);
127 Reference
< XDataInputStream
> dataInput( TestObject
, UNO_QUERY
);
129 WARNING_ASSERT( connect
.is(), "XConnectable cannot be queried" );
130 WARNING_ASSERT( active
.is() , "XActiveDataSink cannot be queried" );
131 ERROR_ASSERT( input
.is() , "XInputStream cannot be queried" );
132 ERROR_ASSERT( dataInput
.is() , "XDataInputStream cannot be queried" );
136 else if( OUString("com.sun.star.io.DataInputStream") == TestName
) {
137 Reference
< XConnectable
> connect( TestObject
, UNO_QUERY
);
138 Reference
< XActiveDataSource
> active( TestObject
, UNO_QUERY
);
139 Reference
< XOutputStream
> output( TestObject
, UNO_QUERY
);
140 Reference
< XDataOutputStream
> dataOutput( TestObject
, UNO_QUERY
);
142 WARNING_ASSERT( connect
.is(), "XConnectable cannot be queried" );
143 WARNING_ASSERT( active
.is() , "XActiveDataSink cannot be queried" );
144 ERROR_ASSERT( output
.is() , "XInputStream cannot be queried" );
145 ERROR_ASSERT( dataOutput
.is(), "XDataInputStream cannot be queried" );
149 Reference
< XServiceInfo
> info( TestObject
, UNO_QUERY
);
150 ERROR_ASSERT( info
.is() , "XServiceInfo not supported !" );
153 ERROR_ASSERT( info
->supportsService( TestName
), "XServiceInfo test failed" );
154 ERROR_ASSERT( ! info
->supportsService( OUString("bla bluzb") ) , "XServiceInfo test failed" );
160 sal_Int32
ODataStreamTest::test(
161 const OUString
& TestName
,
162 const Reference
< XInterface
>& TestObject
,
163 sal_Int32 hTestHandle
)
164 throw ( IllegalArgumentException
,
167 if( OUString("com.sun.star.io.DataInputStream") == TestName
||
168 OUString("com.sun.star.io.DataOutputStream") == TestName
) {
172 if( 0 == hTestHandle
) {
173 testInvariant( TestName
, TestObject
);
176 Reference
<XActiveDataSink
> rSink( TestObject
, UNO_QUERY
);
177 Reference
<XActiveDataSource
> rSource( TestObject
, UNO_QUERY
);
179 Reference
< XDataInputStream
> rInput( TestObject
, UNO_QUERY
);
180 Reference
< XDataOutputStream
> rOutput( TestObject
, UNO_QUERY
);
183 Reference
< XInterface
> x
= m_rFactory
->createInstance(
184 OUString( "com.sun.star.io.Pipe" ));
186 Reference
< XInputStream
> rPipeInput( x
, UNO_QUERY
);
187 Reference
< XOutputStream
> rPipeOutput( x
, UNO_QUERY
);
190 x
= m_rFactory
->createInstance(
191 OUString( "com.sun.star.io.DataInputStream") );
192 rInput
= Reference
< XDataInputStream
> ( x
, UNO_QUERY
);
193 rSink
= Reference
< XActiveDataSink
> ( x
, UNO_QUERY
);
195 else if ( !rSource
.is() )
197 x
= m_rFactory
->createInstance(
198 OUString( "com.sun.star.io.DataOutputStream" ) );
199 rOutput
= Reference
< XDataOutputStream
> ( x
, UNO_QUERY
);
200 rSource
= Reference
< XActiveDataSource
> ( x
, UNO_QUERY
);
203 OSL_ASSERT( rPipeInput
.is() );
204 OSL_ASSERT( rPipeOutput
.is() );
205 rSink
->setInputStream( rPipeInput
);
206 rSource
->setOutputStream( rPipeOutput
);
208 OSL_ASSERT( rSink
->getInputStream().is() );
209 OSL_ASSERT( rSource
->getOutputStream().is() );
211 if( 1 == hTestHandle
) {
212 testSimple( rInput
, rOutput
);
216 catch( const Exception
& e
)
218 OString o
= OUStringToOString( e
.Message
, RTL_TEXTENCODING_ASCII_US
);
219 BUILD_ERROR( 0 , o
.getStr() );
223 BUILD_ERROR( 0 , "unknown exception (Exception is not base class)" );
228 if( hTestHandle
>= 2) {
229 // all tests finished.
234 BUILD_ERROR( 0 , "service not supported by test." );
241 sal_Bool
ODataStreamTest::testPassed(void) throw (RuntimeException
)
243 return m_seqErrors
.getLength() == 0;
247 Sequence
< OUString
> ODataStreamTest::getErrors(void) throw (RuntimeException
)
253 Sequence
< Any
> ODataStreamTest::getErrorExceptions(void) throw (RuntimeException
)
255 return m_seqExceptions
;
259 Sequence
< OUString
> ODataStreamTest::getWarnings(void) throw (RuntimeException
)
261 return m_seqWarnings
;
264 void ODataStreamTest::testSimple( const Reference
< XDataInputStream
> &rInput
,
265 const Reference
< XDataOutputStream
> &rOutput
)
267 rOutput
->writeLong( 0x34ff3c );
268 rOutput
->writeLong( 0x34ff3d );
269 rOutput
->writeLong( -1027 );
271 ERROR_ASSERT( 0x34ff3c == rInput
->readLong() , "long read/write mismatch" );
272 ERROR_ASSERT( 0x34ff3d == rInput
->readLong() , "long read/write mismatch" );
273 ERROR_ASSERT( -1027 == rInput
->readLong() , "long read/write mismatch" );
275 rOutput
->writeByte( 0x77 );
276 ERROR_ASSERT( 0x77 == rInput
->readByte() , "byte read/write mismatch" );
278 rOutput
->writeBoolean( 25 );
279 ERROR_ASSERT( rInput
->readBoolean() , "boolean read/write mismatch" );
281 rOutput
->writeBoolean( sal_False
);
282 ERROR_ASSERT( ! rInput
->readBoolean() , "boolean read/write mismatch" );
284 rOutput
->writeFloat( (float) 42.42 );
285 ERROR_ASSERT( rInput
->readFloat() == ((float)42.42) , "float read/write mismatch" );
287 rOutput
->writeDouble( (double) 42.42 );
288 ERROR_ASSERT( rInput
->readDouble() == 42.42 , "double read/write mismatch" );
290 rOutput
->writeHyper( 0x123456789abcdefLL
);
291 ERROR_ASSERT( rInput
->readHyper() == 0x123456789abcdefLL
, "int64 read/write mismatch" );
293 rOutput
->writeUTF( OUString("Live long and prosper !") );
294 ERROR_ASSERT( rInput
->readUTF() == OUString("Live long and prosper !") ,
295 "UTF read/write mismatch" );
297 Sequence
<sal_Unicode
> wc(0x10001);
298 for( int i
= 0 ; i
< 0x10000 ; i
++ ) {
299 wc
.getArray()[i
] = L
'c';
301 wc
.getArray()[0x10000] = 0;
302 OUString
str( wc
.getArray() , 0x10000 );
303 rOutput
->writeUTF( str
);
304 ERROR_ASSERT( rInput
->readUTF() == str
, "error reading 64k block" );
306 rOutput
->closeOutput();
310 ERROR_ASSERT( 0 , "eof-exception does not occur !" );
312 catch ( IOException
& )
318 ERROR_ASSERT( 0 , "wrong exception after reading beyond eof" );
321 Sequence
<sal_Int8
> dummy (1);
322 ERROR_ASSERT( ! rInput
->readBytes( dummy
, 1 ),
323 "stream must be on eof !" );
325 rInput
->closeInput();
329 rOutput
->writeByte( 1 );
330 ERROR_ASSERT( 0 , "writing still possible though chain must be interrupted" );
332 catch( IOException
& )
337 ERROR_ASSERT( 0 , "IOException expected, but another exception was thrown" );
345 * for external binding
349 Reference
< XInterface
> SAL_CALL
ODataStreamTest_CreateInstance( const Reference
< XMultiServiceFactory
> & rSMgr
) throw(Exception
)
351 ODataStreamTest
*p
= new ODataStreamTest( rSMgr
);
352 return Reference
< XInterface
> ( (static_cast< OWeakObject
* >(p
)) );
355 Sequence
<OUString
> ODataStreamTest_getSupportedServiceNames( int i
) throw ()
357 Sequence
<OUString
> aRet(1);
359 aRet
.getArray()[0] = ODataStreamTest_getImplementationName( i
);
365 OUString
ODataStreamTest_getServiceName( int i
) throw ()
368 return OUString( "test.com.sun.star.io.DataInputStream" );
371 return OUString( "test.com.sun.star.io.DataOutputStream" );
375 OUString
ODataStreamTest_getImplementationName( int i
) throw ()
379 "test.com.sun.star.comp.extensions.stm.DataInputStream" );
382 return OUString( "test.com.sun.star.comp.extensions.stm.DataOutputStream" );
386 class MyPersistObject
: public WeakImplHelper2
< XPersistObject
, XPropertySet
>
389 MyPersistObject( ) : m_sServiceName( OMyPersistObject_getServiceName() ) ,
396 m_s( OUString( "foo" ) )
398 MyPersistObject( const OUString
& sServiceName
) : m_sServiceName( sServiceName
)
403 virtual OUString SAL_CALL
getServiceName(void) throw (RuntimeException
);
404 virtual void SAL_CALL
write( const Reference
< XObjectOutputStream
>& OutStream
)
405 throw (IOException
, RuntimeException
);
406 virtual void SAL_CALL
read(const Reference
< XObjectInputStream
>& InStream
)
407 throw (IOException
, RuntimeException
);
411 virtual Reference
< XPropertySetInfo
> SAL_CALL
getPropertySetInfo(void)
412 throw (RuntimeException
);
414 virtual void SAL_CALL
setPropertyValue(const OUString
& aPropertyName
, const Any
& aValue
)
415 throw ( UnknownPropertyException
,
416 PropertyVetoException
,
417 IllegalArgumentException
,
418 WrappedTargetException
,
420 virtual Any SAL_CALL
getPropertyValue(const OUString
& PropertyName
)
421 throw ( UnknownPropertyException
,
422 WrappedTargetException
,
424 virtual void SAL_CALL
addPropertyChangeListener(
425 const OUString
& aPropertyName
,
426 const Reference
< XPropertyChangeListener
> & xListener
)
427 throw ( UnknownPropertyException
,
428 WrappedTargetException
,
431 virtual void SAL_CALL
removePropertyChangeListener(
432 const OUString
& aPropertyName
,
433 const Reference
< XPropertyChangeListener
> & aListener
)
434 throw ( UnknownPropertyException
,
435 WrappedTargetException
,
437 virtual void SAL_CALL
addVetoableChangeListener(
438 const OUString
& PropertyName
,
439 const Reference
< XVetoableChangeListener
> & aListener
)
440 throw ( UnknownPropertyException
,
441 WrappedTargetException
,
444 virtual void SAL_CALL
removeVetoableChangeListener(
445 const OUString
& PropertyName
,
446 const Reference
< XVetoableChangeListener
>& aListener
)
447 throw ( UnknownPropertyException
,
448 WrappedTargetException
,
459 Reference
< XPersistObject
> m_ref
;
460 OUString m_sServiceName
;
465 Reference
<XPropertySetInfo
> MyPersistObject::getPropertySetInfo(void)
466 throw (RuntimeException
)
468 return Reference
< XPropertySetInfo
>();
471 void MyPersistObject::setPropertyValue(
472 const OUString
& aPropertyName
,
474 throw ( UnknownPropertyException
,
475 PropertyVetoException
,
476 IllegalArgumentException
,
477 WrappedTargetException
,
480 if( 0 == aPropertyName
.compareToAscii("long") ) {
483 else if ( 0 == aPropertyName
.compareToAscii("float") ) {
486 else if( 0 == aPropertyName
.compareToAscii("double") ) {
489 else if( 0 == aPropertyName
.compareToAscii("bool") ) {
492 else if( 0 == aPropertyName
.compareToAscii("byte" ) ) {
495 else if( 0 == aPropertyName
.compareToAscii("char") ) {
498 else if( 0 == aPropertyName
.compareToAscii("string") ) {
501 else if( 0 == aPropertyName
.compareToAscii("object") ) {
502 if( aValue
.getValueType() == getCppuType( (Reference
< XPersistObject
> *)0 ) )
514 Any
MyPersistObject::getPropertyValue(const OUString
& aPropertyName
)
515 throw ( UnknownPropertyException
,
516 WrappedTargetException
,
520 if( 0 == aPropertyName
.compareToAscii("long" ) ) {
523 else if ( 0 == aPropertyName
.compareToAscii("float") ) {
526 else if( 0 == aPropertyName
.compareToAscii("double") ) {
529 else if( 0 == aPropertyName
.compareToAscii("bool") ) {
532 else if( 0 == aPropertyName
.compareToAscii("byte") ) {
535 else if( 0 == aPropertyName
.compareToAscii("char" ) ) {
538 else if( 0 == aPropertyName
.compareToAscii("string") ) {
541 else if( 0 == aPropertyName
.compareToAscii("object" ) )
549 void MyPersistObject::addPropertyChangeListener(
550 const OUString
& aPropertyName
,
551 const Reference
< XPropertyChangeListener
> & xListener
)
552 throw ( UnknownPropertyException
,
553 WrappedTargetException
,
559 void MyPersistObject::removePropertyChangeListener(
560 const OUString
& aPropertyName
,
561 const Reference
< XPropertyChangeListener
> & aListener
)
562 throw ( UnknownPropertyException
,
563 WrappedTargetException
,
569 void MyPersistObject::addVetoableChangeListener(
570 const OUString
& PropertyName
,
571 const Reference
<XVetoableChangeListener
>& aListener
)
572 throw ( UnknownPropertyException
,
573 WrappedTargetException
,
579 void MyPersistObject::removeVetoableChangeListener(
580 const OUString
& PropertyName
,
581 const Reference
< XVetoableChangeListener
> & aListener
)
582 throw ( UnknownPropertyException
,
583 WrappedTargetException
,
592 OUString
MyPersistObject::getServiceName() throw (RuntimeException
)
594 return m_sServiceName
;
597 void MyPersistObject::write( const Reference
< XObjectOutputStream
> & rOut
)
598 throw (IOException
,RuntimeException
)
600 rOut
->writeLong( m_l
);
601 rOut
->writeFloat( m_f
);
602 rOut
->writeDouble( m_d
);
603 rOut
->writeBoolean( m_b
);
604 rOut
->writeByte( m_byte
);
605 rOut
->writeChar( m_c
);
606 rOut
->writeUTF( m_s
);
607 rOut
->writeObject( m_ref
);
611 void MyPersistObject::read( const Reference
< XObjectInputStream
> & rIn
)
612 throw (IOException
, RuntimeException
)
614 m_l
= rIn
->readLong();
615 m_f
= rIn
->readFloat();
616 m_d
= rIn
->readDouble();
617 m_b
= rIn
->readBoolean();
618 m_byte
= rIn
->readByte();
619 m_c
= rIn
->readChar();
620 m_s
= rIn
->readUTF();
621 m_ref
= rIn
->readObject();
624 Reference
< XInterface
> SAL_CALL
OMyPersistObject_CreateInstance(
625 const Reference
< XMultiServiceFactory
> & rSMgr
)
628 MyPersistObject
*p
= new MyPersistObject( );
629 return Reference
< XInterface
> ( (static_cast< OWeakObject
* >(p
)) );
632 Sequence
<OUString
> OMyPersistObject_getSupportedServiceNames( ) throw ()
634 Sequence
<OUString
> aRet(1);
635 aRet
.getArray()[0] = OMyPersistObject_getImplementationName();
639 OUString
OMyPersistObject_getServiceName( ) throw ()
641 return OUString( "test.com.sun.star.io.PersistTest" );
644 OUString
OMyPersistObject_getImplementationName( ) throw ()
646 return OUString( "test.com.sun.star.io.PersistTest" );
649 class OObjectStreamTest
:
650 public ODataStreamTest
653 OObjectStreamTest( const Reference
< XMultiServiceFactory
> &r
) : ODataStreamTest(r
) {}
656 virtual void SAL_CALL
testInvariant(const OUString
& TestName
,
657 const Reference
< XInterface
>& TestObject
)
658 throw ( IllegalArgumentException
,
661 virtual sal_Int32 SAL_CALL
test(
662 const OUString
& TestName
,
663 const Reference
< XInterface
>& TestObject
,
664 sal_Int32 hTestHandle
)
665 throw ( IllegalArgumentException
,
670 void testObject( const Reference
<XObjectOutputStream
> &rOut
,
671 const Reference
<XObjectInputStream
> &rIn
);
677 void OObjectStreamTest::testInvariant( const OUString
& TestName
,
678 const Reference
< XInterface
>& TestObject
)
679 throw ( IllegalArgumentException
, RuntimeException
)
682 if( OUString( "com.sun.star.io.ObjectInputStream" )
685 ODataStreamTest::testInvariant( TestName
, TestObject
);
686 Reference
< XObjectInputStream
> dataInput( TestObject
, UNO_QUERY
);
687 Reference
< XMarkableStream
> markable( TestObject
, UNO_QUERY
);
688 ERROR_ASSERT( dataInput
.is() , "XObjectInputStream cannot be queried" );
689 ERROR_ASSERT( markable
.is() , "XMarkableStream cannot be queried" );
691 else if( OUString( "com.sun.star.io.ObjectOutputStream" )
694 ODataStreamTest::testInvariant( TestName
, TestObject
);
695 Reference
< XMarkableStream
> markable( TestObject
, UNO_QUERY
);
696 Reference
< XObjectOutputStream
> dataOutput( TestObject
, UNO_QUERY
);
697 ERROR_ASSERT( dataOutput
.is(), "XObjectOutputStream cannot be queried" );
698 ERROR_ASSERT( markable
.is() , "XMarkableStream cannot be queried" );
701 Reference
< XServiceInfo
> info( TestObject
, UNO_QUERY
);
702 ERROR_ASSERT( info
.is() , "XServiceInfo not supported !" );
705 ERROR_ASSERT( info
->supportsService( TestName
), "XServiceInfo test failed" );
706 ERROR_ASSERT( ! info
->supportsService( OUString("bla bluzb") ) , "XServiceInfo test failed" );
711 sal_Int32
OObjectStreamTest::test( const OUString
& TestName
,
712 const Reference
< XInterface
>& TestObject
,
713 sal_Int32 hTestHandle
)
714 throw ( IllegalArgumentException
,
717 if( 0 == TestName
.compareToAscii("com.sun.star.io.ObjectInputStream") ||
718 0 == TestName
.compareToAscii("com.sun.star.io.ObjectOutputStream" ) ) {
722 if( 0 == hTestHandle
) {
723 testInvariant( TestName
, TestObject
);
725 else if( DATASTREAM_TEST_MAX_HANDLE
>= hTestHandle
) {
726 sal_Int32 hOldHandle
= hTestHandle
;
727 hTestHandle
= ODataStreamTest::test(
728 OUString( "com.sun.star.io.DataInputStream" ),
729 TestObject
, hTestHandle
);
730 if( hTestHandle
== -1 ){
731 hTestHandle
= hOldHandle
;
736 Reference
<XActiveDataSink
> rSink( TestObject
, UNO_QUERY
);
737 Reference
<XActiveDataSource
> rSource( TestObject
, UNO_QUERY
);
739 Reference
< XObjectInputStream
> rInput( TestObject
, UNO_QUERY
);
740 Reference
< XObjectOutputStream
> rOutput( TestObject
, UNO_QUERY
);
743 Reference
< XInterface
> x
= m_rFactory
->createInstance(
744 OUString( "com.sun.star.io.Pipe" ) );
746 Reference
<XInputStream
> rPipeInput( x
, UNO_QUERY
);
747 Reference
<XOutputStream
> rPipeOutput( x
, UNO_QUERY
);
749 x
= m_rFactory
->createInstance(
750 OUString( "com.sun.star.io.MarkableInputStream" ) );
752 Reference
<XInputStream
> markableInput( x
, UNO_QUERY
);
753 Reference
<XActiveDataSink
> markableSink( x
, UNO_QUERY
);
755 x
= m_rFactory
->createInstance( OUString(
756 "com.sun.star.io.MarkableOutputStream" ) );
757 Reference
<XOutputStream
> markableOutput( x
, UNO_QUERY
);
758 Reference
<XActiveDataSource
> markableSource( x
, UNO_QUERY
);
760 OSL_ASSERT( markableInput
.is() );
761 OSL_ASSERT( markableOutput
.is() );
762 OSL_ASSERT( markableSink
.is() );
763 OSL_ASSERT( markableSource
.is() );
765 markableSink
->setInputStream( rPipeInput
);
766 markableSource
->setOutputStream( rPipeOutput
);
769 x
= m_rFactory
->createInstance(
770 OUString( "com.sun.star.io.ObjectInputStream" ));
771 rInput
= Reference
< XObjectInputStream
> ( x
, UNO_QUERY
);
772 rSink
= Reference
< XActiveDataSink
> ( x
, UNO_QUERY
);
774 else if ( !rSource
.is() ) {
775 x
= m_rFactory
->createInstance(
776 OUString( "com.sun.star.io.ObjectOutputStream" ));
777 rOutput
= Reference
<XObjectOutputStream
> ( x
, UNO_QUERY
);
778 rSource
= Reference
<XActiveDataSource
>( x
, UNO_QUERY
);
781 OSL_ASSERT( rPipeInput
.is() );
782 OSL_ASSERT( rPipeOutput
.is() );
784 rSink
->setInputStream( markableInput
);
785 rSource
->setOutputStream( markableOutput
);
787 OSL_ASSERT( rSink
->getInputStream().is() );
788 OSL_ASSERT( rSource
->getOutputStream().is() );
790 if( 1 + DATASTREAM_TEST_MAX_HANDLE
== hTestHandle
) {
791 testObject( rOutput
, rInput
);
793 rInput
->closeInput();
794 rOutput
->closeOutput();
798 catch( const Exception
&e
) {
799 OString o
= OUStringToOString( e
.Message
, RTL_TEXTENCODING_ASCII_US
);
800 BUILD_ERROR( 0 , o
.getStr() );
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 sal_Bool
compareMyPropertySet( Reference
< XPropertySet
> &r1
, Reference
< XPropertySet
> &r2
)
822 sal_Bool b
= sal_True
;
824 if( r1
->getPropertyValue( OUString("long") ).getValueType() == getCppuVoidType() ||
825 r2
->getPropertyValue( OUString("long") ).getValueType() == getCppuVoidType() ) {
827 // one of the objects is not the correct propertyset !
828 fprintf( stderr
, "compareMyPropertySet: 1\n" );
832 b
= b
&& ( r1
->getPropertyValue( OUString("long") ) ==
833 r2
->getPropertyValue( OUString("long") ) );
834 if( ! b
) fprintf( stderr
, "compareMyPropertySet: 2\n" );
836 b
= b
&& ( r1
->getPropertyValue( OUString("float") ) ==
837 r2
->getPropertyValue( OUString("float") ) );
841 r1
->getPropertyValue( OUString("float") ) >>= f1
;
842 r2
->getPropertyValue( OUString("float") ) >>= f2
;
843 fprintf( stderr
, "compareMyPropertySet: %f %f 3\n",f1
,f2
);
846 b
= b
&& ( r1
->getPropertyValue( OUString("double") ) ==
847 r2
->getPropertyValue( OUString("double" )) );
848 if( ! b
) fprintf( stderr
, "compareMyPropertySet: 4\n" );
850 sal_Bool
b1(sal_False
), b2(sal_False
);
851 Any a
=r1
->getPropertyValue( OUString("bool") );
853 a
= r2
->getPropertyValue( OUString("bool") );
855 b
= b
&& ( (b1
&& b2
) || b1
== b2
);
856 if( ! b
) fprintf( stderr
, "compareMyPropertySet: 5\n" );
858 // b = b && r1->getPropertyValue( OUString("bool") ) ==
859 // r2->getPropertyValue( OUString("bool") ) );
861 b
= b
&& ( r1
->getPropertyValue( OUString("byte") ) ==
862 r2
->getPropertyValue( OUString("byte") ) );
863 if( ! b
) fprintf( stderr
, "compareMyPropertySet: 6\n" );
865 b
= b
&& ( r1
->getPropertyValue( OUString("char") ) ==
866 r2
->getPropertyValue( OUString("char") ) );
867 if( ! b
) fprintf( stderr
, "compareMyPropertySet: 7\n" );
869 b
= b
&& ( r1
->getPropertyValue( OUString("string") ) ==
870 r2
->getPropertyValue( OUString("string") ));
871 if( ! b
) fprintf( stderr
, "compareMyPropertySet: 8\n" );
873 Any o1
= r1
->getPropertyValue( OUString("object") );
874 Any o2
= r2
->getPropertyValue( OUString("object") );
876 if( o1
.getValueType() == getCppuType( (Reference
<XPersistObject
>*)0 ) ) {
878 if( o2
.getValueType() == getCppuType( (Reference
<XPersistObject
>*)0 ) ) {
879 Reference
< XPersistObject
> rPersist1
;
880 Reference
< XPersistObject
> rPersist2
;
883 Reference
<XPropertySet
> rProp1( rPersist1
, UNO_QUERY
);
884 Reference
< XPropertySet
> rProp2( rPersist2
, UNO_QUERY
);
886 if( rProp1
.is() && rProp2
.is() && ! ( rProp1
== rProp2
)
887 &&( rProp1
!= r1
)) {
888 b
= b
&& compareMyPropertySet( rProp1
, rProp2
);
894 if( ! b
) fprintf( stderr
, "compareMyPropertySet: 9\n" );
897 if( o2
.getValueType() == getCppuType( (Reference
<XPersistObject
>*)0 ) ) {
900 if( ! b
) fprintf( stderr
, "compareMyPropertySet: 10\n" );
906 void OObjectStreamTest::testObject( const Reference
< XObjectOutputStream
> &rOut
,
907 const Reference
< XObjectInputStream
> &rIn
)
909 ERROR_ASSERT( rOut
.is() , "no objectOutputStream" );
910 ERROR_ASSERT( rIn
.is() , "no objectInputStream" );
914 // tests, if saving an object with an unknown service name allows
915 // reading the data behind the object !
917 Reference
< XInterface
> x
= * new MyPersistObject(
918 OUString( "bla blubs") );
920 Reference
< XPersistObject
> persistRef( x
, UNO_QUERY
);
921 ERROR_ASSERT( persistRef
.is() , "couldn't instantiate PersistTest object" );
923 rOut
->writeObject( persistRef
);
924 rOut
->writeLong( (sal_Int32
) 0xdeadbeef );
926 ERROR_ASSERT( 0 != rIn
->available() , "no data arrived at input" );
930 Reference
<XPersistObject
> xReadPersistRef
= rIn
->readObject();
931 ERROR_ASSERT( 0 , "expected exception not thrown" );
933 catch( IOException
& )
938 ERROR_ASSERT( (sal_Int32
) 0xdeadbeef == rIn
->readLong() ,
939 "wrong data after object with unknown service name." );
943 Reference
< XInterface
> x
= m_rFactory
->createInstance(
944 OUString( "test.com.sun.star.io.PersistTest"));
945 Reference
< XPersistObject
> persistRef( x
, UNO_QUERY
);
947 ERROR_ASSERT( persistRef
.is() , "couldn't instantiate PersistTest object" );
949 Reference
< XPropertySet
> rProp( persistRef
, UNO_QUERY
);
950 ERROR_ASSERT( rProp
.is() , "test object is no property set " );
953 sal_Int32 i
= 0x83482;
955 rProp
->setPropertyValue( OUString( "long") , any
);
957 float f
= (float)42.23;
959 rProp
->setPropertyValue( OUString( "float") , any
);
961 double d
= 233.321412;
963 rProp
->setPropertyValue( OUString( "double") , any
);
965 sal_Bool b
= sal_True
;
966 any
.setValue( &b
, getCppuBooleanType() );
967 rProp
->setPropertyValue( OUString( "bool") , any
);
971 rProp
->setPropertyValue( OUString( "byte") , any
);
974 any
.setValue( &c
, getCppuCharType() );
975 rProp
->setPropertyValue( OUString( "char") , any
);
977 OUString
str( "hi du !" );
979 rProp
->setPropertyValue( OUString( "string") , any
);
982 rProp
->setPropertyValue( OUString( "object") , any
);
985 rOut
->writeObject( persistRef
);
986 ERROR_ASSERT( 0 != rIn
->available() , "no data arrived at input" );
987 Reference
< XPersistObject
> xReadPersist
= rIn
->readObject( );
989 Reference
< XPropertySet
> rPropRead( xReadPersist
, UNO_QUERY
);
990 ERROR_ASSERT( compareMyPropertySet( rProp
, rPropRead
) , "objects has not been read properly !" );
992 // destroy selfreferences
993 rProp
->setPropertyValue( OUString("object"), Any() );
994 rPropRead
->setPropertyValue( OUString("object"), Any() );
998 Reference
< XMarkableStream
> markableOut( rOut
, UNO_QUERY
);
999 ERROR_ASSERT( markableOut
.is() , "markable stream cannot be queried" );
1001 // do the same thing multiple times to check if
1002 // buffering and marks work correctly
1003 for( int i
= 0 ; i
< 2000 ; i
++ ) {
1005 Reference
< XInterface
> x
= m_rFactory
->createInstance(OUString("test.com.sun.star.io.PersistTest"));
1006 Reference
< XPersistObject
> persistRef( x
, UNO_QUERY
);
1008 Reference
< XPropertySet
> rProp( persistRef
, UNO_QUERY
);
1009 ERROR_ASSERT( rProp
.is() , "test object is no property set " );
1012 sal_Int32 i
= 0x83482;
1014 rProp
->setPropertyValue( OUString( "long") , any
);
1018 rProp
->setPropertyValue( OUString( "float") , any
);
1020 double d
= 233.321412;
1022 rProp
->setPropertyValue( OUString( "double") , any
);
1024 sal_Bool b
= sal_True
;
1025 any
.setValue( &b
, getCppuBooleanType() );
1026 rProp
->setPropertyValue( OUString( "bool") , any
);
1030 rProp
->setPropertyValue( OUString( "byte") , any
);
1032 sal_Unicode c
= 'h';
1033 any
.setValue( &c
, getCppuCharType() );
1034 rProp
->setPropertyValue( OUString( "char") , any
);
1036 OUString
str( "hi du !" );
1038 rProp
->setPropertyValue( OUString( "string") , any
);
1040 x
= m_rFactory
->createInstance(OUString("test.com.sun.star.io.PersistTest"));
1041 Reference
<XPersistObject
> persist2ndRef( x
, UNO_QUERY
);
1043 // Note : persist2ndRef contains coincident values, but also coincident values must be
1045 any
<<= persist2ndRef
;
1046 rProp
->setPropertyValue( OUString("object") , any
);
1048 // simply test, if markable operations and object operations do not interfere
1049 sal_Int32 nMark
= markableOut
->createMark();
1051 // do read and write
1052 rOut
->writeObject( persistRef
);
1054 // further markable tests !
1055 sal_Int32 nOffset
= markableOut
->offsetToMark( nMark
);
1056 markableOut
->jumpToMark( nMark
);
1057 markableOut
->deleteMark( nMark
);
1058 markableOut
->jumpToFurthest();
1064 ERROR_ASSERT( 0 != rIn
->available() , "no data arrived at input" );
1065 Reference
< XPersistObject
> xReadPersistRef
= rIn
->readObject( );
1067 Reference
< XPropertySet
> rProp1( persistRef
, UNO_QUERY
);
1068 Reference
< XPropertySet
> rProp2( xReadPersistRef
, UNO_QUERY
);
1069 ERROR_ASSERT( compareMyPropertySet( rProp1
, rProp2
) ,
1070 "objects has not been read properly !" );
1076 Reference
< XInterface
> SAL_CALL
OObjectStreamTest_CreateInstance( const Reference
< XMultiServiceFactory
> & rSMgr
) throw(Exception
)
1078 OObjectStreamTest
*p
= new OObjectStreamTest( rSMgr
);
1079 return Reference
< XInterface
> ( (static_cast< OWeakObject
* >(p
)) );
1082 Sequence
<OUString
> OObjectStreamTest_getSupportedServiceNames( int i
) throw ()
1084 Sequence
<OUString
> aRet(1);
1085 aRet
.getArray()[0] = OObjectStreamTest_getImplementationName( i
);
1089 OUString
OObjectStreamTest_getServiceName( int i
) throw ()
1092 return OUString( "test.com.sun.star.io.ObjectInputStream" );
1095 return OUString( "test.com.sun.star.io.ObjectOutputStream");
1099 OUString
OObjectStreamTest_getImplementationName( int i
) throw ()
1102 return OUString( "test.com.sun.star.comp.extensions.stm.ObjectInputStream" );
1105 return OUString( "test.com.sun.star.comp.extensions.stm.ObjectOutputStream");
1110 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */