Teach symstore more duplicated DLLs
[LibreOffice.git] / io / test / stm / datatest.cxx
bloba085bf6d7d5bd41414910224a1d091405d02c171
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 <stdio.h>
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>
39 #include <string.h>
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;
48 // streams
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 >
64 public:
65 explicit ODataStreamTest( const Reference < XMultiServiceFactory > & rFactory ) :
66 m_rFactory( rFactory )
69 public:
70 virtual void SAL_CALL testInvariant(const OUString& TestName, const Reference < XInterface >& TestObject)
71 throw ( IllegalArgumentException,
72 RuntimeException);
74 virtual sal_Int32 SAL_CALL test( const OUString& TestName,
75 const Reference < XInterface >& TestObject,
76 sal_Int32 hTestHandle)
77 throw ( IllegalArgumentException,
78 RuntimeException);
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);
85 private:
86 void testSimple( const Reference < XDataInputStream > & , const Reference < XDataOutputStream > &);
88 protected:
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,
101 RuntimeException)
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 !" );
131 if( info.is() )
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,
145 RuntimeException)
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 );
155 else {
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 );
169 if( ! rSink.is() ) {
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() );
201 catch( ... )
203 BUILD_ERROR( 0 , "unknown exception (Exception is not base class)" );
206 hTestHandle ++;
208 if( hTestHandle >= 2) {
209 // all tests finished.
210 hTestHandle = -1;
213 else {
214 BUILD_ERROR( 0 , "service not supported by test." );
216 return hTestHandle;
220 sal_Bool ODataStreamTest::testPassed() throw (RuntimeException)
222 return m_seqErrors.getLength() == 0;
226 Sequence< OUString > ODataStreamTest::getErrors() throw (RuntimeException)
228 return m_seqErrors;
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();
288 rInput->readLong();
289 ERROR_ASSERT( 0 , "eof-exception does not occur !" );
291 catch ( IOException & )
293 //ok
295 catch( ... )
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 & )
313 // ok
315 catch( ... ) {
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) };
336 return aRet;
339 OUString ODataStreamTest_getServiceName( int i) throw ()
341 if( 1 == i ) {
342 return OUString( "test.com.sun.star.io.DataInputStream" );
344 else {
345 return OUString( "test.com.sun.star.io.DataOutputStream" );
349 OUString ODataStreamTest_getImplementationName( int i) throw ()
351 if( 1 == i ) {
352 return OUString(
353 "test.com.sun.star.comp.extensions.stm.DataInputStream" );
355 else {
356 return OUString( "test.com.sun.star.comp.extensions.stm.DataOutputStream" );
360 class MyPersistObject : public WeakImplHelper< XPersistObject , XPropertySet >
362 public:
363 MyPersistObject( ) : m_sServiceName( OMyPersistObject_getServiceName() ) ,
364 m_l( -392 ),
365 m_f( 7883.2 ),
366 m_d( -123923.5 ),
367 m_b( sal_True ),
368 m_byte( 42 ),
369 m_c( 429 ),
370 m_s( OUString( "foo" ) )
372 explicit MyPersistObject( const OUString & sServiceName ) : m_sServiceName( sServiceName )
376 public:
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);
383 public:
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,
393 RuntimeException);
394 virtual Any SAL_CALL getPropertyValue(const OUString& PropertyName)
395 throw ( UnknownPropertyException,
396 WrappedTargetException,
397 RuntimeException);
398 virtual void SAL_CALL addPropertyChangeListener(
399 const OUString& aPropertyName,
400 const Reference < XPropertyChangeListener > & xListener)
401 throw ( UnknownPropertyException,
402 WrappedTargetException,
403 RuntimeException);
405 virtual void SAL_CALL removePropertyChangeListener(
406 const OUString& aPropertyName,
407 const Reference< XPropertyChangeListener > & aListener)
408 throw ( UnknownPropertyException,
409 WrappedTargetException,
410 RuntimeException);
411 virtual void SAL_CALL addVetoableChangeListener(
412 const OUString& PropertyName,
413 const Reference< XVetoableChangeListener > & aListener)
414 throw ( UnknownPropertyException,
415 WrappedTargetException,
416 RuntimeException);
418 virtual void SAL_CALL removeVetoableChangeListener(
419 const OUString& PropertyName,
420 const Reference< XVetoableChangeListener >& aListener)
421 throw ( UnknownPropertyException,
422 WrappedTargetException,
423 RuntimeException);
425 public:
426 sal_Int32 m_l;
427 float m_f;
428 double m_d;
429 sal_Bool m_b;
430 sal_Int8 m_byte;
431 sal_Unicode m_c;
432 OUString m_s;
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,
446 const Any& aValue)
447 throw ( UnknownPropertyException,
448 PropertyVetoException,
449 IllegalArgumentException,
450 WrappedTargetException,
451 RuntimeException)
453 if( aPropertyName.equalsAscii("long") ) {
454 aValue >>= m_l;
456 else if ( aPropertyName.equalsAscii("float") ) {
457 aValue >>= m_f;
459 else if( aPropertyName.equalsAscii("double") ) {
460 aValue >>= m_d;
462 else if( aPropertyName.equalsAscii("bool") ) {
463 aValue >>= m_b;
465 else if( aPropertyName.equalsAscii("byte" ) ) {
466 aValue >>= m_byte;
468 else if( aPropertyName.equalsAscii("char") ) {
469 aValue >>= m_c;
471 else if( aPropertyName.equalsAscii("string") ) {
472 aValue >>= m_s;
474 else if( aPropertyName.equalsAscii("object") ) {
475 if( aValue.getValueType() == cppu::UnoType<XPersistObject>::get())
477 aValue >>= m_ref;
479 else
481 m_ref = 0;
487 Any MyPersistObject::getPropertyValue(const OUString& aPropertyName)
488 throw ( UnknownPropertyException,
489 WrappedTargetException,
490 RuntimeException)
492 Any aValue;
493 if( aPropertyName.equalsAscii("long" ) ) {
494 aValue <<= m_l;
496 else if ( aPropertyName.equalsAscii("float") ) {
497 aValue <<= m_f;
499 else if( aPropertyName.equalsAscii("double") ) {
500 aValue <<= m_d;
502 else if( aPropertyName.equalsAscii("bool") ) {
503 aValue <<= m_b;
505 else if( aPropertyName.equalsAscii("byte") ) {
506 aValue <<= m_byte;
508 else if( aPropertyName.equalsAscii("char" ) ) {
509 aValue <<= m_c;
511 else if( aPropertyName.equalsAscii("string") ) {
512 aValue <<= m_s;
514 else if( aPropertyName.equalsAscii("object" ) )
516 aValue <<= m_ref;
518 return aValue;
522 void MyPersistObject::addPropertyChangeListener(
523 const OUString& aPropertyName,
524 const Reference< XPropertyChangeListener > & xListener)
525 throw ( UnknownPropertyException,
526 WrappedTargetException,
527 RuntimeException)
532 void MyPersistObject::removePropertyChangeListener(
533 const OUString& aPropertyName,
534 const Reference < XPropertyChangeListener > & aListener)
535 throw ( UnknownPropertyException,
536 WrappedTargetException,
537 RuntimeException)
542 void MyPersistObject::addVetoableChangeListener(
543 const OUString& PropertyName,
544 const Reference <XVetoableChangeListener >& aListener)
545 throw ( UnknownPropertyException,
546 WrappedTargetException,
547 RuntimeException)
552 void MyPersistObject::removeVetoableChangeListener(
553 const OUString& PropertyName,
554 const Reference < XVetoableChangeListener > & aListener)
555 throw ( UnknownPropertyException,
556 WrappedTargetException,
557 RuntimeException)
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 )
597 throw(Exception)
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() };
606 return aRet;
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
622 public:
623 explicit OObjectStreamTest( const Reference < XMultiServiceFactory > &r) : ODataStreamTest(r) {}
625 public:
626 virtual void SAL_CALL testInvariant(const OUString& TestName,
627 const Reference < XInterface >& TestObject)
628 throw ( IllegalArgumentException,
629 RuntimeException);
631 virtual sal_Int32 SAL_CALL test(
632 const OUString& TestName,
633 const Reference < XInterface >& TestObject,
634 sal_Int32 hTestHandle)
635 throw ( IllegalArgumentException,
636 RuntimeException);
639 private:
640 void testObject( const Reference <XObjectOutputStream > &rOut,
641 const Reference <XObjectInputStream> &rIn );
643 private:
647 void OObjectStreamTest::testInvariant( const OUString& TestName,
648 const Reference < XInterface >& TestObject )
649 throw ( IllegalArgumentException, RuntimeException)
652 if( OUString( "com.sun.star.io.ObjectInputStream" )
653 == TestName )
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" )
662 == TestName )
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 !" );
673 if( info.is() )
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,
685 RuntimeException)
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;
704 else {
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 );
737 if( ! rSink.is() ) {
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() );
771 catch( ... ) {
772 BUILD_ERROR( 0 , "unknown exception (Exception is not base class)" );
775 hTestHandle ++;
777 if( hTestHandle > 1 +DATASTREAM_TEST_MAX_HANDLE ) {
778 // all tests finished.
779 hTestHandle = -1;
782 else {
783 BUILD_ERROR( 0 , "service not supported by test." );
785 return hTestHandle;
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" );
798 return sal_False;
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") );
807 if( ! b ){
808 float f1(0.0);
809 float f2(0.0);
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");
821 a >>= b1;
822 a = r2->getPropertyValue("bool");
823 a >>= b2;
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;
850 o1 >>= rPersist1;
851 o2 >>= 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 );
860 else {
861 b = sal_False;
863 if( ! b ) fprintf( stderr, "compareMyPropertySet: 9\n" );
865 else {
866 if( o2.getValueType() == cppu::UnoType<XPersistObject>::get()) {
867 b = sal_False;
869 if( ! b ) fprintf( stderr, "compareMyPropertySet: 10\n" );
872 return b;
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 & )
903 // all is ok
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 " );
920 Any any;
921 sal_Int32 i = 0x83482;
922 any <<= i;
923 rProp->setPropertyValue("long", any );
925 float f = (float)42.23;
926 any <<= f;
927 rProp->setPropertyValue("float", any );
929 double d = 233.321412;
930 any <<= d;
931 rProp->setPropertyValue("double", any );
933 sal_Bool b = sal_True;
934 any.setValue( &b , cppu::UnoType<bool>::get() );
935 rProp->setPropertyValue("bool", any );
937 sal_Int8 by = 120;
938 any <<= by;
939 rProp->setPropertyValue("byte", any );
941 sal_Unicode c = 'h';
942 any.setValue( &c , cppu::UnoType<cppu::UnoCharType>::get() );
943 rProp->setPropertyValue("char", any );
945 OUString str( "hi du !" );
946 any <<= str;
947 rProp->setPropertyValue("string", any );
949 any <<= persistRef;
950 rProp->setPropertyValue("object", any );
952 // do read and write
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 " );
979 Any any;
980 sal_Int32 i = 0x83482;
981 any <<= i;
982 rProp->setPropertyValue("long", any );
984 float f = 42.23;
985 any <<= f;
986 rProp->setPropertyValue("float", any );
988 double d = 233.321412;
989 any <<= d;
990 rProp->setPropertyValue("double", any );
992 sal_Bool b = sal_True;
993 any.setValue( &b , cppu::UnoType<bool>::get() );
994 rProp->setPropertyValue("bool", any );
996 sal_Int8 by = 120;
997 any <<= by;
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 !" );
1005 any <<= str;
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
1012 // saved properly !
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) };
1050 return aRet;
1053 OUString OObjectStreamTest_getServiceName( int i) throw ()
1055 if( 1 == i ) {
1056 return OUString( "test.com.sun.star.io.ObjectInputStream" );
1058 else {
1059 return OUString( "test.com.sun.star.io.ObjectOutputStream");
1063 OUString OObjectStreamTest_getImplementationName( int i) throw ()
1065 if( 1 == i ) {
1066 return OUString( "test.com.sun.star.comp.extensions.stm.ObjectInputStream" );
1068 else {
1069 return OUString( "test.com.sun.star.comp.extensions.stm.ObjectOutputStream");
1074 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */