xref: /trunk/main/io/test/stm/datatest.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_io.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include <stdio.h>
32*cdf0e10cSrcweir 
33*cdf0e10cSrcweir #include <com/sun/star/test/XSimpleTest.hpp>
34*cdf0e10cSrcweir #include <com/sun/star/io/XActiveDataSink.hpp>
35*cdf0e10cSrcweir #include <com/sun/star/io/XActiveDataSource.hpp>
36*cdf0e10cSrcweir #include <com/sun/star/io/XObjectInputStream.hpp>
37*cdf0e10cSrcweir #include <com/sun/star/io/XObjectOutputStream.hpp>
38*cdf0e10cSrcweir #include <com/sun/star/io/XMarkableStream.hpp>
39*cdf0e10cSrcweir #include <com/sun/star/io/XConnectable.hpp>
40*cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp>
41*cdf0e10cSrcweir #include <com/sun/star/lang/WrappedTargetException.hpp>
42*cdf0e10cSrcweir 
43*cdf0e10cSrcweir #include <com/sun/star/lang/IllegalArgumentException.hpp>
44*cdf0e10cSrcweir 
45*cdf0e10cSrcweir #include <com/sun/star/lang/XServiceInfo.hpp>
46*cdf0e10cSrcweir 
47*cdf0e10cSrcweir #include <cppuhelper/factory.hxx>
48*cdf0e10cSrcweir 
49*cdf0e10cSrcweir #include <cppuhelper/implbase1.hxx>
50*cdf0e10cSrcweir #include <cppuhelper/implbase2.hxx>
51*cdf0e10cSrcweir 
52*cdf0e10cSrcweir #include <osl/conditn.hxx>
53*cdf0e10cSrcweir #include <osl/mutex.hxx>
54*cdf0e10cSrcweir 
55*cdf0e10cSrcweir #include <string.h>
56*cdf0e10cSrcweir 
57*cdf0e10cSrcweir using namespace ::rtl;
58*cdf0e10cSrcweir using namespace ::osl;
59*cdf0e10cSrcweir using namespace ::cppu;
60*cdf0e10cSrcweir //using namespace ::vos;
61*cdf0e10cSrcweir using namespace ::com::sun::star::uno;
62*cdf0e10cSrcweir using namespace ::com::sun::star::io;
63*cdf0e10cSrcweir using namespace ::com::sun::star::lang;
64*cdf0e10cSrcweir using namespace ::com::sun::star::test;
65*cdf0e10cSrcweir using namespace ::com::sun::star::beans;
66*cdf0e10cSrcweir // streams
67*cdf0e10cSrcweir 
68*cdf0e10cSrcweir #include "testfactreg.hxx"
69*cdf0e10cSrcweir 
70*cdf0e10cSrcweir #define DATASTREAM_TEST_MAX_HANDLE 1
71*cdf0e10cSrcweir 
72*cdf0e10cSrcweir /****
73*cdf0e10cSrcweir * The following test class tests XDataInputStream and XDataOutputStream at equal terms,
74*cdf0e10cSrcweir * so when errors occur, it may be in either one implementation.
75*cdf0e10cSrcweir * The class also  uses stardiv.uno.io.pipe. If problems occur, make sure to run also the
76*cdf0e10cSrcweir * pipe test routines ( test.com.sun.star.io.pipe ).
77*cdf0e10cSrcweir *
78*cdf0e10cSrcweir *
79*cdf0e10cSrcweir *****/
80*cdf0e10cSrcweir 
81*cdf0e10cSrcweir class ODataStreamTest :
82*cdf0e10cSrcweir         public WeakImplHelper1< XSimpleTest >
83*cdf0e10cSrcweir {
84*cdf0e10cSrcweir public:
85*cdf0e10cSrcweir     ODataStreamTest( const Reference < XMultiServiceFactory > & rFactory ) :
86*cdf0e10cSrcweir         m_rFactory( rFactory )
87*cdf0e10cSrcweir         {}
88*cdf0e10cSrcweir 
89*cdf0e10cSrcweir public:
90*cdf0e10cSrcweir     virtual void SAL_CALL testInvariant(const OUString& TestName, const Reference < XInterface >& TestObject)
91*cdf0e10cSrcweir         throw ( IllegalArgumentException,
92*cdf0e10cSrcweir                     RuntimeException);
93*cdf0e10cSrcweir 
94*cdf0e10cSrcweir     virtual sal_Int32 SAL_CALL test(    const OUString& TestName,
95*cdf0e10cSrcweir                                         const Reference < XInterface >& TestObject,
96*cdf0e10cSrcweir                                         sal_Int32 hTestHandle)
97*cdf0e10cSrcweir         throw ( IllegalArgumentException,
98*cdf0e10cSrcweir                 RuntimeException);
99*cdf0e10cSrcweir 
100*cdf0e10cSrcweir     virtual sal_Bool SAL_CALL testPassed(void)                              throw ( RuntimeException);
101*cdf0e10cSrcweir     virtual Sequence< OUString > SAL_CALL getErrors(void)               throw (RuntimeException);
102*cdf0e10cSrcweir     virtual Sequence< Any > SAL_CALL getErrorExceptions(void)       throw (RuntimeException);
103*cdf0e10cSrcweir     virtual Sequence< OUString > SAL_CALL getWarnings(void)                 throw (RuntimeException);
104*cdf0e10cSrcweir 
105*cdf0e10cSrcweir private:
106*cdf0e10cSrcweir     void testSimple( const Reference < XDataInputStream > & , const Reference < XDataOutputStream > &);
107*cdf0e10cSrcweir 
108*cdf0e10cSrcweir protected:
109*cdf0e10cSrcweir     Sequence<Any>  m_seqExceptions;
110*cdf0e10cSrcweir     Sequence<OUString> m_seqErrors;
111*cdf0e10cSrcweir     Sequence<OUString> m_seqWarnings;
112*cdf0e10cSrcweir 
113*cdf0e10cSrcweir     Reference < XMultiServiceFactory > m_rFactory;
114*cdf0e10cSrcweir };
115*cdf0e10cSrcweir 
116*cdf0e10cSrcweir 
117*cdf0e10cSrcweir 
118*cdf0e10cSrcweir 
119*cdf0e10cSrcweir void ODataStreamTest::testInvariant(
120*cdf0e10cSrcweir     const OUString& TestName,
121*cdf0e10cSrcweir     const Reference < XInterface >& TestObject )
122*cdf0e10cSrcweir     throw ( IllegalArgumentException,
123*cdf0e10cSrcweir             RuntimeException)
124*cdf0e10cSrcweir {
125*cdf0e10cSrcweir     if( OUString::createFromAscii("com.sun.star.io.DataInputStream") == TestName ) {
126*cdf0e10cSrcweir         Reference < XConnectable > connect( TestObject , UNO_QUERY );
127*cdf0e10cSrcweir         Reference < XActiveDataSink > active( TestObject , UNO_QUERY );
128*cdf0e10cSrcweir         Reference < XInputStream >  input( TestObject , UNO_QUERY );
129*cdf0e10cSrcweir         Reference < XDataInputStream > dataInput( TestObject , UNO_QUERY );
130*cdf0e10cSrcweir 
131*cdf0e10cSrcweir         WARNING_ASSERT( connect.is(), "XConnectable cannot be queried" );
132*cdf0e10cSrcweir         WARNING_ASSERT( active.is() , "XActiveDataSink cannot be queried" );
133*cdf0e10cSrcweir         ERROR_ASSERT( input.is() , "XInputStream cannot be queried" );
134*cdf0e10cSrcweir         ERROR_ASSERT( dataInput.is() , "XDataInputStream cannot be queried" );
135*cdf0e10cSrcweir 
136*cdf0e10cSrcweir 
137*cdf0e10cSrcweir     }
138*cdf0e10cSrcweir     else if( OUString::createFromAscii("com.sun.star.io.DataInputStream") == TestName ) {
139*cdf0e10cSrcweir         Reference < XConnectable >  connect( TestObject , UNO_QUERY );
140*cdf0e10cSrcweir         Reference < XActiveDataSource > active( TestObject , UNO_QUERY );
141*cdf0e10cSrcweir         Reference < XOutputStream > output( TestObject , UNO_QUERY );
142*cdf0e10cSrcweir         Reference < XDataOutputStream > dataOutput( TestObject , UNO_QUERY );
143*cdf0e10cSrcweir 
144*cdf0e10cSrcweir         WARNING_ASSERT( connect.is(),       "XConnectable cannot be queried" );
145*cdf0e10cSrcweir         WARNING_ASSERT( active.is() ,   "XActiveDataSink cannot be queried" );
146*cdf0e10cSrcweir         ERROR_ASSERT(   output.is() ,   "XInputStream cannot be queried" );
147*cdf0e10cSrcweir         ERROR_ASSERT(   dataOutput.is(),    "XDataInputStream cannot be queried" );
148*cdf0e10cSrcweir 
149*cdf0e10cSrcweir     }
150*cdf0e10cSrcweir 
151*cdf0e10cSrcweir     Reference < XServiceInfo >  info( TestObject, UNO_QUERY );
152*cdf0e10cSrcweir     ERROR_ASSERT( info.is() , "XServiceInfo not supported !" );
153*cdf0e10cSrcweir     if( info.is() )
154*cdf0e10cSrcweir     {
155*cdf0e10cSrcweir         ERROR_ASSERT( info->supportsService( TestName ), "XServiceInfo test failed" );
156*cdf0e10cSrcweir         ERROR_ASSERT( ! info->supportsService( OUString::createFromAscii("bla bluzb") ) , "XServiceInfo test failed" );
157*cdf0e10cSrcweir     }
158*cdf0e10cSrcweir 
159*cdf0e10cSrcweir }
160*cdf0e10cSrcweir 
161*cdf0e10cSrcweir 
162*cdf0e10cSrcweir sal_Int32 ODataStreamTest::test(
163*cdf0e10cSrcweir     const OUString& TestName,
164*cdf0e10cSrcweir     const Reference < XInterface >& TestObject,
165*cdf0e10cSrcweir     sal_Int32 hTestHandle)
166*cdf0e10cSrcweir     throw ( IllegalArgumentException,
167*cdf0e10cSrcweir             RuntimeException)
168*cdf0e10cSrcweir {
169*cdf0e10cSrcweir     if( OUString::createFromAscii("com.sun.star.io.DataInputStream") == TestName ||
170*cdf0e10cSrcweir         OUString::createFromAscii("com.sun.star.io.DataOutputStream") == TestName )  {
171*cdf0e10cSrcweir 
172*cdf0e10cSrcweir         try
173*cdf0e10cSrcweir         {
174*cdf0e10cSrcweir             if( 0 == hTestHandle ) {
175*cdf0e10cSrcweir                 testInvariant( TestName , TestObject );
176*cdf0e10cSrcweir             }
177*cdf0e10cSrcweir             else {
178*cdf0e10cSrcweir                 Reference <XActiveDataSink > rSink( TestObject, UNO_QUERY );
179*cdf0e10cSrcweir                 Reference <XActiveDataSource > rSource( TestObject , UNO_QUERY );
180*cdf0e10cSrcweir 
181*cdf0e10cSrcweir                 Reference < XDataInputStream > rInput( TestObject , UNO_QUERY );
182*cdf0e10cSrcweir                 Reference < XDataOutputStream > rOutput( TestObject , UNO_QUERY );
183*cdf0e10cSrcweir 
184*cdf0e10cSrcweir 
185*cdf0e10cSrcweir                 Reference < XInterface > x = m_rFactory->createInstance(
186*cdf0e10cSrcweir                     OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.io.Pipe" )));
187*cdf0e10cSrcweir 
188*cdf0e10cSrcweir                 Reference < XInputStream >   rPipeInput( x , UNO_QUERY );
189*cdf0e10cSrcweir                 Reference < XOutputStream >  rPipeOutput( x , UNO_QUERY );
190*cdf0e10cSrcweir 
191*cdf0e10cSrcweir                 if( ! rSink.is() ) {
192*cdf0e10cSrcweir                     x = m_rFactory->createInstance(
193*cdf0e10cSrcweir                         OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.io.DataInputStream")) );
194*cdf0e10cSrcweir                     rInput = Reference < XDataInputStream > ( x , UNO_QUERY);
195*cdf0e10cSrcweir                     rSink = Reference<  XActiveDataSink > ( x , UNO_QUERY );
196*cdf0e10cSrcweir                 }
197*cdf0e10cSrcweir                 else if ( !rSource.is() )
198*cdf0e10cSrcweir                 {
199*cdf0e10cSrcweir                     x = m_rFactory->createInstance(
200*cdf0e10cSrcweir                         OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.io.DataOutputStream") ) );
201*cdf0e10cSrcweir                     rOutput = Reference< XDataOutputStream > ( x , UNO_QUERY );
202*cdf0e10cSrcweir                     rSource = Reference< XActiveDataSource > ( x, UNO_QUERY );
203*cdf0e10cSrcweir                 }
204*cdf0e10cSrcweir 
205*cdf0e10cSrcweir                 OSL_ASSERT( rPipeInput.is() );
206*cdf0e10cSrcweir                 OSL_ASSERT( rPipeOutput.is() );
207*cdf0e10cSrcweir                 rSink->setInputStream( rPipeInput );
208*cdf0e10cSrcweir                 rSource->setOutputStream( rPipeOutput );
209*cdf0e10cSrcweir 
210*cdf0e10cSrcweir                 OSL_ASSERT( rSink->getInputStream().is() );
211*cdf0e10cSrcweir                 OSL_ASSERT( rSource->getOutputStream().is() );
212*cdf0e10cSrcweir 
213*cdf0e10cSrcweir                 if( 1 == hTestHandle ) {
214*cdf0e10cSrcweir                     testSimple( rInput , rOutput );
215*cdf0e10cSrcweir                 }
216*cdf0e10cSrcweir             }
217*cdf0e10cSrcweir         }
218*cdf0e10cSrcweir         catch( Exception & e )
219*cdf0e10cSrcweir         {
220*cdf0e10cSrcweir             OString o = OUStringToOString( e.Message , RTL_TEXTENCODING_ASCII_US );
221*cdf0e10cSrcweir             BUILD_ERROR( 0 , o.getStr() );
222*cdf0e10cSrcweir         }
223*cdf0e10cSrcweir         catch( ... )
224*cdf0e10cSrcweir         {
225*cdf0e10cSrcweir             BUILD_ERROR( 0 , "unknown exception (Exception is  not base class)" );
226*cdf0e10cSrcweir         }
227*cdf0e10cSrcweir 
228*cdf0e10cSrcweir         hTestHandle ++;
229*cdf0e10cSrcweir 
230*cdf0e10cSrcweir         if( hTestHandle >= 2) {
231*cdf0e10cSrcweir             // all tests finished.
232*cdf0e10cSrcweir             hTestHandle = -1;
233*cdf0e10cSrcweir         }
234*cdf0e10cSrcweir     }
235*cdf0e10cSrcweir     else {
236*cdf0e10cSrcweir         BUILD_ERROR( 0 , "service not supported by test." );
237*cdf0e10cSrcweir     }
238*cdf0e10cSrcweir     return hTestHandle;
239*cdf0e10cSrcweir }
240*cdf0e10cSrcweir 
241*cdf0e10cSrcweir 
242*cdf0e10cSrcweir 
243*cdf0e10cSrcweir sal_Bool ODataStreamTest::testPassed(void)                                      throw (RuntimeException)
244*cdf0e10cSrcweir {
245*cdf0e10cSrcweir     return m_seqErrors.getLength() == 0;
246*cdf0e10cSrcweir }
247*cdf0e10cSrcweir 
248*cdf0e10cSrcweir 
249*cdf0e10cSrcweir Sequence< OUString > ODataStreamTest::getErrors(void)                           throw (RuntimeException)
250*cdf0e10cSrcweir {
251*cdf0e10cSrcweir     return m_seqErrors;
252*cdf0e10cSrcweir }
253*cdf0e10cSrcweir 
254*cdf0e10cSrcweir 
255*cdf0e10cSrcweir Sequence< Any > ODataStreamTest::getErrorExceptions(void)                   throw (RuntimeException)
256*cdf0e10cSrcweir {
257*cdf0e10cSrcweir     return m_seqExceptions;
258*cdf0e10cSrcweir }
259*cdf0e10cSrcweir 
260*cdf0e10cSrcweir 
261*cdf0e10cSrcweir Sequence< OUString > ODataStreamTest::getWarnings(void)                         throw (RuntimeException)
262*cdf0e10cSrcweir {
263*cdf0e10cSrcweir     return m_seqWarnings;
264*cdf0e10cSrcweir }
265*cdf0e10cSrcweir 
266*cdf0e10cSrcweir void ODataStreamTest::testSimple(   const Reference < XDataInputStream > &rInput,
267*cdf0e10cSrcweir                                     const Reference < XDataOutputStream > &rOutput )
268*cdf0e10cSrcweir {
269*cdf0e10cSrcweir     rOutput->writeLong( 0x34ff3c );
270*cdf0e10cSrcweir     rOutput->writeLong( 0x34ff3d );
271*cdf0e10cSrcweir     rOutput->writeLong( -1027 );
272*cdf0e10cSrcweir 
273*cdf0e10cSrcweir     ERROR_ASSERT( 0x34ff3c ==  rInput->readLong() , "long read/write mismatch" );
274*cdf0e10cSrcweir     ERROR_ASSERT( 0x34ff3d ==  rInput->readLong() , "long read/write mismatch" );
275*cdf0e10cSrcweir     ERROR_ASSERT( -1027    ==  rInput->readLong() , "long read/write mismatch" );
276*cdf0e10cSrcweir 
277*cdf0e10cSrcweir     rOutput->writeByte( 0x77 );
278*cdf0e10cSrcweir     ERROR_ASSERT( 0x77 == rInput->readByte() , "byte read/write mismatch" );
279*cdf0e10cSrcweir 
280*cdf0e10cSrcweir     rOutput->writeBoolean( 25 );
281*cdf0e10cSrcweir     ERROR_ASSERT( rInput->readBoolean() , "boolean read/write mismatch" );
282*cdf0e10cSrcweir 
283*cdf0e10cSrcweir     rOutput->writeBoolean( sal_False );
284*cdf0e10cSrcweir     ERROR_ASSERT( ! rInput->readBoolean() , "boolean read/write mismatch" );
285*cdf0e10cSrcweir 
286*cdf0e10cSrcweir     rOutput->writeFloat( (float) 42.42 );
287*cdf0e10cSrcweir     ERROR_ASSERT( rInput->readFloat() == ((float)42.42) , "float read/write mismatch" );
288*cdf0e10cSrcweir 
289*cdf0e10cSrcweir     rOutput->writeDouble( (double) 42.42 );
290*cdf0e10cSrcweir     ERROR_ASSERT( rInput->readDouble() == 42.42 , "double read/write mismatch" );
291*cdf0e10cSrcweir 
292*cdf0e10cSrcweir     rOutput->writeHyper( 0x123456789abcdefLL );
293*cdf0e10cSrcweir     ERROR_ASSERT( rInput->readHyper() == 0x123456789abcdefLL , "int64 read/write mismatch" );
294*cdf0e10cSrcweir 
295*cdf0e10cSrcweir     rOutput->writeUTF( OUString::createFromAscii("Live long and prosper !") );
296*cdf0e10cSrcweir     ERROR_ASSERT( rInput->readUTF() == OUString::createFromAscii("Live long and prosper !") ,
297*cdf0e10cSrcweir                     "UTF read/write mismatch" );
298*cdf0e10cSrcweir 
299*cdf0e10cSrcweir     Sequence<sal_Unicode> wc(0x10001);
300*cdf0e10cSrcweir     for( int i = 0 ; i < 0x10000  ; i ++ ) {
301*cdf0e10cSrcweir         wc.getArray()[i] = L'c';
302*cdf0e10cSrcweir     }
303*cdf0e10cSrcweir     wc.getArray()[0x10000] = 0;
304*cdf0e10cSrcweir     OUString str( wc.getArray() , 0x10000 );
305*cdf0e10cSrcweir     rOutput->writeUTF( str );
306*cdf0e10cSrcweir     ERROR_ASSERT( rInput->readUTF() == str , "error reading 64k block" );
307*cdf0e10cSrcweir 
308*cdf0e10cSrcweir     rOutput->closeOutput();
309*cdf0e10cSrcweir     try
310*cdf0e10cSrcweir     {
311*cdf0e10cSrcweir         rInput->readLong();
312*cdf0e10cSrcweir         ERROR_ASSERT( 0 , "eof-exception does not occur !" );
313*cdf0e10cSrcweir     }
314*cdf0e10cSrcweir     catch ( IOException & )
315*cdf0e10cSrcweir     {
316*cdf0e10cSrcweir         //ok
317*cdf0e10cSrcweir     }
318*cdf0e10cSrcweir     catch( ... )
319*cdf0e10cSrcweir     {
320*cdf0e10cSrcweir         ERROR_ASSERT( 0 , "wrong exception after reading beyond eof" );
321*cdf0e10cSrcweir     }
322*cdf0e10cSrcweir 
323*cdf0e10cSrcweir     Sequence<sal_Int8> dummy (1);
324*cdf0e10cSrcweir     ERROR_ASSERT( ! rInput->readBytes( dummy , 1 ),
325*cdf0e10cSrcweir                     "stream must be on eof !" );
326*cdf0e10cSrcweir 
327*cdf0e10cSrcweir     rInput->closeInput();
328*cdf0e10cSrcweir 
329*cdf0e10cSrcweir     try
330*cdf0e10cSrcweir     {
331*cdf0e10cSrcweir         rOutput->writeByte( 1 );
332*cdf0e10cSrcweir         ERROR_ASSERT( 0 , "writing still possible though chain must be interrupted" );
333*cdf0e10cSrcweir     }
334*cdf0e10cSrcweir     catch( IOException & )
335*cdf0e10cSrcweir     {
336*cdf0e10cSrcweir         // ok
337*cdf0e10cSrcweir     }
338*cdf0e10cSrcweir     catch( ... ) {
339*cdf0e10cSrcweir         ERROR_ASSERT( 0 , "IOException  expected, but another exception was thrown" );
340*cdf0e10cSrcweir     }
341*cdf0e10cSrcweir 
342*cdf0e10cSrcweir }
343*cdf0e10cSrcweir 
344*cdf0e10cSrcweir 
345*cdf0e10cSrcweir 
346*cdf0e10cSrcweir /**
347*cdf0e10cSrcweir * for external binding
348*cdf0e10cSrcweir *
349*cdf0e10cSrcweir *
350*cdf0e10cSrcweir **/
351*cdf0e10cSrcweir Reference < XInterface > SAL_CALL ODataStreamTest_CreateInstance( const Reference < XMultiServiceFactory > & rSMgr ) throw(Exception)
352*cdf0e10cSrcweir {
353*cdf0e10cSrcweir     ODataStreamTest *p = new ODataStreamTest( rSMgr );
354*cdf0e10cSrcweir     return Reference < XInterface > ( SAL_STATIC_CAST( OWeakObject * , p ) );
355*cdf0e10cSrcweir }
356*cdf0e10cSrcweir 
357*cdf0e10cSrcweir Sequence<OUString> ODataStreamTest_getSupportedServiceNames( int i) throw ()
358*cdf0e10cSrcweir {
359*cdf0e10cSrcweir     Sequence<OUString> aRet(1);
360*cdf0e10cSrcweir 
361*cdf0e10cSrcweir     aRet.getArray()[0] = ODataStreamTest_getImplementationName( i);
362*cdf0e10cSrcweir 
363*cdf0e10cSrcweir 
364*cdf0e10cSrcweir     return aRet;
365*cdf0e10cSrcweir }
366*cdf0e10cSrcweir 
367*cdf0e10cSrcweir OUString     ODataStreamTest_getServiceName( int i) throw ()
368*cdf0e10cSrcweir {
369*cdf0e10cSrcweir     if( 1 == i ) {
370*cdf0e10cSrcweir         return OUString( RTL_CONSTASCII_USTRINGPARAM("test.com.sun.star.io.DataInputStream" ));
371*cdf0e10cSrcweir     }
372*cdf0e10cSrcweir     else {
373*cdf0e10cSrcweir         return OUString( RTL_CONSTASCII_USTRINGPARAM("test.com.sun.star.io.DataOutputStream" ));
374*cdf0e10cSrcweir     }
375*cdf0e10cSrcweir }
376*cdf0e10cSrcweir 
377*cdf0e10cSrcweir OUString    ODataStreamTest_getImplementationName( int i) throw ()
378*cdf0e10cSrcweir {
379*cdf0e10cSrcweir     if( 1 == i ) {
380*cdf0e10cSrcweir         return OUString(
381*cdf0e10cSrcweir             RTL_CONSTASCII_USTRINGPARAM("test.com.sun.star.comp.extensions.stm.DataInputStream") );
382*cdf0e10cSrcweir     }
383*cdf0e10cSrcweir     else {
384*cdf0e10cSrcweir         return OUString( RTL_CONSTASCII_USTRINGPARAM(
385*cdf0e10cSrcweir             "test.com.sun.star.comp.extensions.stm.DataOutputStream" ) );
386*cdf0e10cSrcweir     }
387*cdf0e10cSrcweir }
388*cdf0e10cSrcweir 
389*cdf0e10cSrcweir 
390*cdf0e10cSrcweir /**------------------------------------------------------
391*cdf0e10cSrcweir *
392*cdf0e10cSrcweir *
393*cdf0e10cSrcweir *
394*cdf0e10cSrcweir *
395*cdf0e10cSrcweir *
396*cdf0e10cSrcweir *------------------------------------------------------*/
397*cdf0e10cSrcweir class MyPersistObject : public WeakImplHelper2< XPersistObject , XPropertySet >
398*cdf0e10cSrcweir {
399*cdf0e10cSrcweir public:
400*cdf0e10cSrcweir     MyPersistObject( ) : m_sServiceName( OMyPersistObject_getServiceName() ) ,
401*cdf0e10cSrcweir         m_l( -392 ),
402*cdf0e10cSrcweir         m_f( 7883.2 ),
403*cdf0e10cSrcweir         m_d( -123923.5 ),
404*cdf0e10cSrcweir         m_b( sal_True ),
405*cdf0e10cSrcweir         m_byte( 42 ),
406*cdf0e10cSrcweir         m_c( 429 ),
407*cdf0e10cSrcweir         m_s( OUString( RTL_CONSTASCII_USTRINGPARAM( "foo" ) ) )
408*cdf0e10cSrcweir         {}
409*cdf0e10cSrcweir     MyPersistObject( const OUString & sServiceName ) : m_sServiceName( sServiceName )
410*cdf0e10cSrcweir         {}
411*cdf0e10cSrcweir 
412*cdf0e10cSrcweir 
413*cdf0e10cSrcweir public:
414*cdf0e10cSrcweir     virtual OUString SAL_CALL getServiceName(void)  throw (RuntimeException);
415*cdf0e10cSrcweir     virtual void SAL_CALL write( const Reference< XObjectOutputStream >& OutStream )
416*cdf0e10cSrcweir         throw (IOException, RuntimeException);
417*cdf0e10cSrcweir     virtual void SAL_CALL read(const Reference< XObjectInputStream >& InStream)
418*cdf0e10cSrcweir         throw (IOException, RuntimeException);
419*cdf0e10cSrcweir 
420*cdf0e10cSrcweir public:
421*cdf0e10cSrcweir 
422*cdf0e10cSrcweir     virtual Reference< XPropertySetInfo > SAL_CALL getPropertySetInfo(void)
423*cdf0e10cSrcweir         throw (RuntimeException);
424*cdf0e10cSrcweir 
425*cdf0e10cSrcweir     virtual void SAL_CALL setPropertyValue(const OUString& aPropertyName, const Any& aValue)
426*cdf0e10cSrcweir         throw ( UnknownPropertyException,
427*cdf0e10cSrcweir                 PropertyVetoException,
428*cdf0e10cSrcweir                 IllegalArgumentException,
429*cdf0e10cSrcweir                 WrappedTargetException,
430*cdf0e10cSrcweir                 RuntimeException);
431*cdf0e10cSrcweir     virtual Any SAL_CALL getPropertyValue(const OUString& PropertyName)
432*cdf0e10cSrcweir         throw ( UnknownPropertyException,
433*cdf0e10cSrcweir                 WrappedTargetException,
434*cdf0e10cSrcweir                 RuntimeException);
435*cdf0e10cSrcweir     virtual void SAL_CALL addPropertyChangeListener(
436*cdf0e10cSrcweir         const OUString& aPropertyName,
437*cdf0e10cSrcweir         const Reference < XPropertyChangeListener > & xListener)
438*cdf0e10cSrcweir         throw ( UnknownPropertyException,
439*cdf0e10cSrcweir                 WrappedTargetException,
440*cdf0e10cSrcweir                 RuntimeException);
441*cdf0e10cSrcweir 
442*cdf0e10cSrcweir     virtual void SAL_CALL removePropertyChangeListener(
443*cdf0e10cSrcweir         const OUString& aPropertyName,
444*cdf0e10cSrcweir         const Reference< XPropertyChangeListener > & aListener)
445*cdf0e10cSrcweir         throw ( UnknownPropertyException,
446*cdf0e10cSrcweir                 WrappedTargetException,
447*cdf0e10cSrcweir                 RuntimeException);
448*cdf0e10cSrcweir     virtual void SAL_CALL addVetoableChangeListener(
449*cdf0e10cSrcweir         const OUString& PropertyName,
450*cdf0e10cSrcweir         const Reference< XVetoableChangeListener > & aListener)
451*cdf0e10cSrcweir         throw ( UnknownPropertyException,
452*cdf0e10cSrcweir                 WrappedTargetException,
453*cdf0e10cSrcweir                 RuntimeException);
454*cdf0e10cSrcweir 
455*cdf0e10cSrcweir     virtual void SAL_CALL removeVetoableChangeListener(
456*cdf0e10cSrcweir         const OUString& PropertyName,
457*cdf0e10cSrcweir         const Reference<  XVetoableChangeListener >& aListener)
458*cdf0e10cSrcweir         throw ( UnknownPropertyException,
459*cdf0e10cSrcweir                 WrappedTargetException,
460*cdf0e10cSrcweir                 RuntimeException);
461*cdf0e10cSrcweir 
462*cdf0e10cSrcweir public:
463*cdf0e10cSrcweir     sal_Int32   m_l;
464*cdf0e10cSrcweir     float   m_f;
465*cdf0e10cSrcweir     double  m_d;
466*cdf0e10cSrcweir     sal_Bool    m_b;
467*cdf0e10cSrcweir     sal_Int8    m_byte;
468*cdf0e10cSrcweir     sal_Unicode m_c;
469*cdf0e10cSrcweir     OUString    m_s;
470*cdf0e10cSrcweir     Reference< XPersistObject > m_ref;
471*cdf0e10cSrcweir     OUString m_sServiceName;
472*cdf0e10cSrcweir };
473*cdf0e10cSrcweir 
474*cdf0e10cSrcweir 
475*cdf0e10cSrcweir 
476*cdf0e10cSrcweir Reference <XPropertySetInfo > MyPersistObject::getPropertySetInfo(void)
477*cdf0e10cSrcweir     throw (RuntimeException)
478*cdf0e10cSrcweir {
479*cdf0e10cSrcweir     return Reference< XPropertySetInfo >();
480*cdf0e10cSrcweir }
481*cdf0e10cSrcweir 
482*cdf0e10cSrcweir void MyPersistObject::setPropertyValue(
483*cdf0e10cSrcweir     const OUString& aPropertyName,
484*cdf0e10cSrcweir     const Any& aValue)
485*cdf0e10cSrcweir     throw ( UnknownPropertyException,
486*cdf0e10cSrcweir             PropertyVetoException,
487*cdf0e10cSrcweir             IllegalArgumentException,
488*cdf0e10cSrcweir             WrappedTargetException,
489*cdf0e10cSrcweir             RuntimeException)
490*cdf0e10cSrcweir {
491*cdf0e10cSrcweir     if( 0 == aPropertyName.compareToAscii("long")  ) {
492*cdf0e10cSrcweir         aValue >>= m_l;
493*cdf0e10cSrcweir     }
494*cdf0e10cSrcweir     else if ( 0 == aPropertyName.compareToAscii("float") ) {
495*cdf0e10cSrcweir         aValue >>= m_f;
496*cdf0e10cSrcweir     }
497*cdf0e10cSrcweir     else if( 0 == aPropertyName.compareToAscii("double") ) {
498*cdf0e10cSrcweir         aValue >>= m_d;
499*cdf0e10cSrcweir     }
500*cdf0e10cSrcweir     else if( 0  == aPropertyName.compareToAscii("bool") ) {
501*cdf0e10cSrcweir         aValue >>= m_b;
502*cdf0e10cSrcweir     }
503*cdf0e10cSrcweir     else if( 0 == aPropertyName.compareToAscii("byte" ) ) {
504*cdf0e10cSrcweir         aValue >>= m_byte;
505*cdf0e10cSrcweir     }
506*cdf0e10cSrcweir     else if( 0 == aPropertyName.compareToAscii("char") ) {
507*cdf0e10cSrcweir         aValue >>= m_c;
508*cdf0e10cSrcweir     }
509*cdf0e10cSrcweir     else if( 0 == aPropertyName.compareToAscii("string") ) {
510*cdf0e10cSrcweir         aValue >>= m_s;
511*cdf0e10cSrcweir     }
512*cdf0e10cSrcweir     else if( 0 == aPropertyName.compareToAscii("object") ) {
513*cdf0e10cSrcweir         if( aValue.getValueType() == getCppuType( (Reference< XPersistObject> *)0 ) )
514*cdf0e10cSrcweir         {
515*cdf0e10cSrcweir             aValue >>= m_ref;
516*cdf0e10cSrcweir         }
517*cdf0e10cSrcweir         else
518*cdf0e10cSrcweir         {
519*cdf0e10cSrcweir             m_ref = 0;
520*cdf0e10cSrcweir         }
521*cdf0e10cSrcweir     }
522*cdf0e10cSrcweir }
523*cdf0e10cSrcweir 
524*cdf0e10cSrcweir 
525*cdf0e10cSrcweir Any MyPersistObject::getPropertyValue(const OUString& aPropertyName)
526*cdf0e10cSrcweir     throw ( UnknownPropertyException,
527*cdf0e10cSrcweir             WrappedTargetException,
528*cdf0e10cSrcweir             RuntimeException)
529*cdf0e10cSrcweir {
530*cdf0e10cSrcweir     Any aValue;
531*cdf0e10cSrcweir     if( 0 == aPropertyName.compareToAscii("long" )  ) {
532*cdf0e10cSrcweir         aValue <<= m_l;
533*cdf0e10cSrcweir     }
534*cdf0e10cSrcweir     else if ( 0 == aPropertyName.compareToAscii("float") ) {
535*cdf0e10cSrcweir         aValue <<= m_f;
536*cdf0e10cSrcweir     }
537*cdf0e10cSrcweir     else if( 0 == aPropertyName.compareToAscii("double") ) {
538*cdf0e10cSrcweir         aValue <<= m_d;
539*cdf0e10cSrcweir     }
540*cdf0e10cSrcweir     else if( 0 == aPropertyName.compareToAscii("bool") ) {
541*cdf0e10cSrcweir         aValue <<= m_b;
542*cdf0e10cSrcweir     }
543*cdf0e10cSrcweir     else if( 0 == aPropertyName.compareToAscii("byte") ) {
544*cdf0e10cSrcweir         aValue <<= m_byte;
545*cdf0e10cSrcweir     }
546*cdf0e10cSrcweir     else if( 0 == aPropertyName.compareToAscii("char" ) ) {
547*cdf0e10cSrcweir         aValue <<= m_c;
548*cdf0e10cSrcweir     }
549*cdf0e10cSrcweir     else if( 0 == aPropertyName.compareToAscii("string") ) {
550*cdf0e10cSrcweir         aValue <<= m_s;
551*cdf0e10cSrcweir     }
552*cdf0e10cSrcweir     else if( 0 == aPropertyName.compareToAscii("object" ) )
553*cdf0e10cSrcweir     {
554*cdf0e10cSrcweir         aValue <<= m_ref;
555*cdf0e10cSrcweir     }
556*cdf0e10cSrcweir     return aValue;
557*cdf0e10cSrcweir }
558*cdf0e10cSrcweir 
559*cdf0e10cSrcweir 
560*cdf0e10cSrcweir void MyPersistObject::addPropertyChangeListener(
561*cdf0e10cSrcweir     const OUString& aPropertyName,
562*cdf0e10cSrcweir     const Reference< XPropertyChangeListener > & xListener)
563*cdf0e10cSrcweir     throw ( UnknownPropertyException,
564*cdf0e10cSrcweir             WrappedTargetException,
565*cdf0e10cSrcweir             RuntimeException)
566*cdf0e10cSrcweir {
567*cdf0e10cSrcweir 
568*cdf0e10cSrcweir }
569*cdf0e10cSrcweir 
570*cdf0e10cSrcweir void MyPersistObject::removePropertyChangeListener(
571*cdf0e10cSrcweir     const OUString& aPropertyName,
572*cdf0e10cSrcweir     const Reference < XPropertyChangeListener > & aListener)
573*cdf0e10cSrcweir     throw ( UnknownPropertyException,
574*cdf0e10cSrcweir             WrappedTargetException,
575*cdf0e10cSrcweir             RuntimeException)
576*cdf0e10cSrcweir {
577*cdf0e10cSrcweir }
578*cdf0e10cSrcweir 
579*cdf0e10cSrcweir 
580*cdf0e10cSrcweir void MyPersistObject::addVetoableChangeListener(
581*cdf0e10cSrcweir     const OUString& PropertyName,
582*cdf0e10cSrcweir     const Reference <XVetoableChangeListener >& aListener)
583*cdf0e10cSrcweir     throw ( UnknownPropertyException,
584*cdf0e10cSrcweir             WrappedTargetException,
585*cdf0e10cSrcweir             RuntimeException)
586*cdf0e10cSrcweir {
587*cdf0e10cSrcweir 
588*cdf0e10cSrcweir }
589*cdf0e10cSrcweir 
590*cdf0e10cSrcweir void MyPersistObject::removeVetoableChangeListener(
591*cdf0e10cSrcweir     const OUString& PropertyName,
592*cdf0e10cSrcweir     const Reference < XVetoableChangeListener > & aListener)
593*cdf0e10cSrcweir     throw ( UnknownPropertyException,
594*cdf0e10cSrcweir             WrappedTargetException,
595*cdf0e10cSrcweir             RuntimeException)
596*cdf0e10cSrcweir {
597*cdf0e10cSrcweir 
598*cdf0e10cSrcweir }
599*cdf0e10cSrcweir 
600*cdf0e10cSrcweir 
601*cdf0e10cSrcweir 
602*cdf0e10cSrcweir 
603*cdf0e10cSrcweir OUString MyPersistObject::getServiceName() throw (RuntimeException)
604*cdf0e10cSrcweir {
605*cdf0e10cSrcweir     return m_sServiceName;
606*cdf0e10cSrcweir }
607*cdf0e10cSrcweir 
608*cdf0e10cSrcweir void MyPersistObject::write( const Reference< XObjectOutputStream >  & rOut )
609*cdf0e10cSrcweir     throw (IOException,RuntimeException)
610*cdf0e10cSrcweir {
611*cdf0e10cSrcweir     rOut->writeLong( m_l);
612*cdf0e10cSrcweir     rOut->writeFloat( m_f );
613*cdf0e10cSrcweir     rOut->writeDouble( m_d );
614*cdf0e10cSrcweir     rOut->writeBoolean( m_b );
615*cdf0e10cSrcweir     rOut->writeByte( m_byte );
616*cdf0e10cSrcweir     rOut->writeChar( m_c );
617*cdf0e10cSrcweir     rOut->writeUTF( m_s );
618*cdf0e10cSrcweir     rOut->writeObject( m_ref );
619*cdf0e10cSrcweir }
620*cdf0e10cSrcweir 
621*cdf0e10cSrcweir 
622*cdf0e10cSrcweir void MyPersistObject::read( const Reference< XObjectInputStream > & rIn )
623*cdf0e10cSrcweir     throw (IOException, RuntimeException)
624*cdf0e10cSrcweir {
625*cdf0e10cSrcweir     m_l = rIn->readLong();
626*cdf0e10cSrcweir     m_f = rIn->readFloat();
627*cdf0e10cSrcweir     m_d = rIn->readDouble();
628*cdf0e10cSrcweir     m_b = rIn->readBoolean();
629*cdf0e10cSrcweir     m_byte = rIn->readByte();
630*cdf0e10cSrcweir     m_c = rIn->readChar();
631*cdf0e10cSrcweir     m_s = rIn->readUTF();
632*cdf0e10cSrcweir     m_ref = rIn->readObject();
633*cdf0e10cSrcweir }
634*cdf0e10cSrcweir 
635*cdf0e10cSrcweir Reference < XInterface > SAL_CALL OMyPersistObject_CreateInstance(
636*cdf0e10cSrcweir     const Reference < XMultiServiceFactory > & rSMgr )
637*cdf0e10cSrcweir     throw(Exception)
638*cdf0e10cSrcweir {
639*cdf0e10cSrcweir     MyPersistObject *p = new MyPersistObject( );
640*cdf0e10cSrcweir     return Reference < XInterface > ( SAL_STATIC_CAST( OWeakObject * , p ) );
641*cdf0e10cSrcweir }
642*cdf0e10cSrcweir 
643*cdf0e10cSrcweir Sequence<OUString> OMyPersistObject_getSupportedServiceNames( ) throw ()
644*cdf0e10cSrcweir {
645*cdf0e10cSrcweir     Sequence<OUString> aRet(1);
646*cdf0e10cSrcweir     aRet.getArray()[0] = OMyPersistObject_getImplementationName();
647*cdf0e10cSrcweir     return aRet;
648*cdf0e10cSrcweir }
649*cdf0e10cSrcweir 
650*cdf0e10cSrcweir OUString     OMyPersistObject_getServiceName( ) throw ()
651*cdf0e10cSrcweir {
652*cdf0e10cSrcweir     return OUString( RTL_CONSTASCII_USTRINGPARAM("test.com.sun.star.io.PersistTest" ));
653*cdf0e10cSrcweir }
654*cdf0e10cSrcweir 
655*cdf0e10cSrcweir OUString    OMyPersistObject_getImplementationName( ) throw ()
656*cdf0e10cSrcweir {
657*cdf0e10cSrcweir     return OUString( RTL_CONSTASCII_USTRINGPARAM( "test.com.sun.star.io.PersistTest" ) );
658*cdf0e10cSrcweir }
659*cdf0e10cSrcweir 
660*cdf0e10cSrcweir 
661*cdf0e10cSrcweir // ---------------------------------------------
662*cdf0e10cSrcweir // -----------------------------------------------
663*cdf0e10cSrcweir class OObjectStreamTest :
664*cdf0e10cSrcweir         public ODataStreamTest
665*cdf0e10cSrcweir {
666*cdf0e10cSrcweir public:
667*cdf0e10cSrcweir     OObjectStreamTest( const Reference < XMultiServiceFactory > &r) : ODataStreamTest(r) {}
668*cdf0e10cSrcweir 
669*cdf0e10cSrcweir public:
670*cdf0e10cSrcweir     virtual void SAL_CALL testInvariant(const OUString& TestName,
671*cdf0e10cSrcweir                                const Reference < XInterface >& TestObject)
672*cdf0e10cSrcweir         throw ( IllegalArgumentException,
673*cdf0e10cSrcweir                 RuntimeException);
674*cdf0e10cSrcweir 
675*cdf0e10cSrcweir     virtual sal_Int32 SAL_CALL test(
676*cdf0e10cSrcweir         const OUString& TestName,
677*cdf0e10cSrcweir         const Reference < XInterface >& TestObject,
678*cdf0e10cSrcweir         sal_Int32 hTestHandle)
679*cdf0e10cSrcweir         throw ( IllegalArgumentException,
680*cdf0e10cSrcweir                 RuntimeException);
681*cdf0e10cSrcweir 
682*cdf0e10cSrcweir 
683*cdf0e10cSrcweir private:
684*cdf0e10cSrcweir     void OObjectStreamTest::testObject(     const Reference <XObjectOutputStream > &rOut,
685*cdf0e10cSrcweir                                             const Reference <XObjectInputStream> &rIn );
686*cdf0e10cSrcweir 
687*cdf0e10cSrcweir private:
688*cdf0e10cSrcweir };
689*cdf0e10cSrcweir 
690*cdf0e10cSrcweir 
691*cdf0e10cSrcweir void OObjectStreamTest::testInvariant( const OUString& TestName,
692*cdf0e10cSrcweir                                        const Reference < XInterface >& TestObject )
693*cdf0e10cSrcweir     throw ( IllegalArgumentException, RuntimeException)
694*cdf0e10cSrcweir {
695*cdf0e10cSrcweir 
696*cdf0e10cSrcweir     if( OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.io.ObjectInputStream" ) )
697*cdf0e10cSrcweir                   == TestName )
698*cdf0e10cSrcweir     {
699*cdf0e10cSrcweir         ODataStreamTest::testInvariant( TestName , TestObject );
700*cdf0e10cSrcweir         Reference< XObjectInputStream > dataInput( TestObject , UNO_QUERY );
701*cdf0e10cSrcweir         Reference< XMarkableStream >  markable( TestObject , UNO_QUERY );
702*cdf0e10cSrcweir         ERROR_ASSERT( dataInput.is() , "XObjectInputStream cannot be queried" );
703*cdf0e10cSrcweir         ERROR_ASSERT(   markable.is() , "XMarkableStream cannot be queried" );
704*cdf0e10cSrcweir     }
705*cdf0e10cSrcweir     else if( OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.io.ObjectOutputStream") )
706*cdf0e10cSrcweir              == TestName )
707*cdf0e10cSrcweir     {
708*cdf0e10cSrcweir         ODataStreamTest::testInvariant( TestName , TestObject );
709*cdf0e10cSrcweir         Reference < XMarkableStream > markable( TestObject , UNO_QUERY );
710*cdf0e10cSrcweir         Reference < XObjectOutputStream > dataOutput( TestObject , UNO_QUERY );
711*cdf0e10cSrcweir         ERROR_ASSERT(   dataOutput.is(),    "XObjectOutputStream cannot be queried" );
712*cdf0e10cSrcweir         ERROR_ASSERT(   markable.is() , "XMarkableStream cannot be queried" );
713*cdf0e10cSrcweir     }
714*cdf0e10cSrcweir 
715*cdf0e10cSrcweir     Reference < XServiceInfo > info( TestObject, UNO_QUERY );
716*cdf0e10cSrcweir     ERROR_ASSERT( info.is() , "XServiceInfo not supported !" );
717*cdf0e10cSrcweir     if( info.is() )
718*cdf0e10cSrcweir     {
719*cdf0e10cSrcweir         ERROR_ASSERT( info->supportsService( TestName ), "XServiceInfo test failed" );
720*cdf0e10cSrcweir         ERROR_ASSERT( ! info->supportsService( OUString::createFromAscii("bla bluzb") ) , "XServiceInfo test failed" );
721*cdf0e10cSrcweir     }
722*cdf0e10cSrcweir 
723*cdf0e10cSrcweir }
724*cdf0e10cSrcweir 
725*cdf0e10cSrcweir sal_Int32 OObjectStreamTest::test(  const OUString& TestName,
726*cdf0e10cSrcweir                         const Reference < XInterface >& TestObject,
727*cdf0e10cSrcweir                         sal_Int32 hTestHandle)
728*cdf0e10cSrcweir     throw ( IllegalArgumentException,
729*cdf0e10cSrcweir             RuntimeException)
730*cdf0e10cSrcweir {
731*cdf0e10cSrcweir     if( 0 == TestName.compareToAscii("com.sun.star.io.ObjectInputStream") ||
732*cdf0e10cSrcweir         0 == TestName.compareToAscii("com.sun.star.io.ObjectOutputStream" ) )  {
733*cdf0e10cSrcweir 
734*cdf0e10cSrcweir         try
735*cdf0e10cSrcweir         {
736*cdf0e10cSrcweir             if( 0 == hTestHandle ) {
737*cdf0e10cSrcweir                 testInvariant( TestName , TestObject );
738*cdf0e10cSrcweir             }
739*cdf0e10cSrcweir             else if( DATASTREAM_TEST_MAX_HANDLE >= hTestHandle ) {
740*cdf0e10cSrcweir                 sal_Int32 hOldHandle = hTestHandle;
741*cdf0e10cSrcweir                 hTestHandle = ODataStreamTest::test(
742*cdf0e10cSrcweir                     OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.io.DataInputStream" )),
743*cdf0e10cSrcweir                     TestObject , hTestHandle );
744*cdf0e10cSrcweir                 if( hTestHandle == -1 ){
745*cdf0e10cSrcweir                     hTestHandle = hOldHandle;
746*cdf0e10cSrcweir                 }
747*cdf0e10cSrcweir             }
748*cdf0e10cSrcweir             else {
749*cdf0e10cSrcweir 
750*cdf0e10cSrcweir                 Reference<XActiveDataSink >  rSink( TestObject, UNO_QUERY );
751*cdf0e10cSrcweir                 Reference<XActiveDataSource >  rSource( TestObject , UNO_QUERY );
752*cdf0e10cSrcweir 
753*cdf0e10cSrcweir                 Reference< XObjectInputStream >  rInput( TestObject , UNO_QUERY );
754*cdf0e10cSrcweir                 Reference< XObjectOutputStream > rOutput( TestObject , UNO_QUERY );
755*cdf0e10cSrcweir 
756*cdf0e10cSrcweir 
757*cdf0e10cSrcweir                 Reference < XInterface > x = m_rFactory->createInstance(
758*cdf0e10cSrcweir                     OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.io.Pipe" )) );
759*cdf0e10cSrcweir 
760*cdf0e10cSrcweir                 Reference <XInputStream > rPipeInput( x , UNO_QUERY );
761*cdf0e10cSrcweir                 Reference <XOutputStream >  rPipeOutput( x , UNO_QUERY );
762*cdf0e10cSrcweir 
763*cdf0e10cSrcweir                 x = m_rFactory->createInstance(
764*cdf0e10cSrcweir                     OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.io.MarkableInputStream") ) );
765*cdf0e10cSrcweir 
766*cdf0e10cSrcweir                 Reference <XInputStream > markableInput( x , UNO_QUERY );
767*cdf0e10cSrcweir                 Reference <XActiveDataSink> markableSink( x , UNO_QUERY );
768*cdf0e10cSrcweir 
769*cdf0e10cSrcweir                 x = m_rFactory->createInstance( OUString(
770*cdf0e10cSrcweir                     RTL_CONSTASCII_USTRINGPARAM("com.sun.star.io.MarkableOutputStream" ) ) );
771*cdf0e10cSrcweir                 Reference <XOutputStream >  markableOutput( x , UNO_QUERY );
772*cdf0e10cSrcweir                 Reference <XActiveDataSource >  markableSource( x , UNO_QUERY );
773*cdf0e10cSrcweir 
774*cdf0e10cSrcweir                 OSL_ASSERT( markableInput.is()  );
775*cdf0e10cSrcweir                 OSL_ASSERT( markableOutput.is() );
776*cdf0e10cSrcweir                 OSL_ASSERT( markableSink.is()   );
777*cdf0e10cSrcweir                 OSL_ASSERT( markableSource.is() );
778*cdf0e10cSrcweir 
779*cdf0e10cSrcweir                 markableSink->setInputStream( rPipeInput );
780*cdf0e10cSrcweir                 markableSource->setOutputStream( rPipeOutput );
781*cdf0e10cSrcweir 
782*cdf0e10cSrcweir                 if( ! rSink.is() ) {
783*cdf0e10cSrcweir                     x = m_rFactory->createInstance(
784*cdf0e10cSrcweir                         OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.io.ObjectInputStream") ));
785*cdf0e10cSrcweir                     rInput = Reference < XObjectInputStream > ( x , UNO_QUERY );
786*cdf0e10cSrcweir                     rSink = Reference < XActiveDataSink > ( x , UNO_QUERY );
787*cdf0e10cSrcweir                 }
788*cdf0e10cSrcweir                 else if ( !rSource.is() ) {
789*cdf0e10cSrcweir                     x = m_rFactory->createInstance(
790*cdf0e10cSrcweir                         OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.io.ObjectOutputStream" )));
791*cdf0e10cSrcweir                     rOutput = Reference <XObjectOutputStream > ( x , UNO_QUERY );
792*cdf0e10cSrcweir                     rSource = Reference <XActiveDataSource>( x, UNO_QUERY );
793*cdf0e10cSrcweir                 }
794*cdf0e10cSrcweir 
795*cdf0e10cSrcweir                 OSL_ASSERT( rPipeInput.is() );
796*cdf0e10cSrcweir                 OSL_ASSERT( rPipeOutput.is() );
797*cdf0e10cSrcweir 
798*cdf0e10cSrcweir                 rSink->setInputStream( markableInput );
799*cdf0e10cSrcweir                 rSource->setOutputStream( markableOutput );
800*cdf0e10cSrcweir 
801*cdf0e10cSrcweir                 OSL_ASSERT( rSink->getInputStream().is() );
802*cdf0e10cSrcweir                 OSL_ASSERT( rSource->getOutputStream().is() );
803*cdf0e10cSrcweir 
804*cdf0e10cSrcweir                 if( 1 + DATASTREAM_TEST_MAX_HANDLE == hTestHandle ) {
805*cdf0e10cSrcweir                     testObject( rOutput , rInput);
806*cdf0e10cSrcweir                 }
807*cdf0e10cSrcweir                 rInput->closeInput();
808*cdf0e10cSrcweir                 rOutput->closeOutput();
809*cdf0e10cSrcweir 
810*cdf0e10cSrcweir             }
811*cdf0e10cSrcweir         }
812*cdf0e10cSrcweir         catch( Exception &e )  {
813*cdf0e10cSrcweir             OString o = OUStringToOString( e.Message , RTL_TEXTENCODING_ASCII_US );
814*cdf0e10cSrcweir             BUILD_ERROR( 0 , o.getStr() );
815*cdf0e10cSrcweir         }
816*cdf0e10cSrcweir         catch( ... ) {
817*cdf0e10cSrcweir             BUILD_ERROR( 0 , "unknown exception (Exception is  not base class)" );
818*cdf0e10cSrcweir         }
819*cdf0e10cSrcweir 
820*cdf0e10cSrcweir         hTestHandle ++;
821*cdf0e10cSrcweir 
822*cdf0e10cSrcweir         if( hTestHandle > 1 +DATASTREAM_TEST_MAX_HANDLE ) {
823*cdf0e10cSrcweir             // all tests finished.
824*cdf0e10cSrcweir             hTestHandle = -1;
825*cdf0e10cSrcweir         }
826*cdf0e10cSrcweir     }
827*cdf0e10cSrcweir     else {
828*cdf0e10cSrcweir         BUILD_ERROR( 0 , "service not supported by test." );
829*cdf0e10cSrcweir     }
830*cdf0e10cSrcweir     return hTestHandle;
831*cdf0e10cSrcweir }
832*cdf0e10cSrcweir 
833*cdf0e10cSrcweir 
834*cdf0e10cSrcweir sal_Bool compareMyPropertySet( Reference< XPropertySet > &r1 , Reference < XPropertySet > &r2 )
835*cdf0e10cSrcweir {
836*cdf0e10cSrcweir     sal_Bool b = sal_True;
837*cdf0e10cSrcweir 
838*cdf0e10cSrcweir     if( r1->getPropertyValue( OUString::createFromAscii("long") ).getValueType() == getCppuVoidType() ||
839*cdf0e10cSrcweir         r2->getPropertyValue( OUString::createFromAscii("long") ).getValueType() == getCppuVoidType() ) {
840*cdf0e10cSrcweir 
841*cdf0e10cSrcweir         // one of the objects is not the correct propertyset !
842*cdf0e10cSrcweir         fprintf( stderr, "compareMyPropertySet: 1\n" );
843*cdf0e10cSrcweir         return sal_False;
844*cdf0e10cSrcweir     }
845*cdf0e10cSrcweir 
846*cdf0e10cSrcweir     b = b && (  r1->getPropertyValue( OUString(RTL_CONSTASCII_USTRINGPARAM("long")) ) ==
847*cdf0e10cSrcweir                 r2->getPropertyValue( OUString(RTL_CONSTASCII_USTRINGPARAM("long")) ) );
848*cdf0e10cSrcweir     if( ! b ) fprintf( stderr, "compareMyPropertySet: 2\n" );
849*cdf0e10cSrcweir 
850*cdf0e10cSrcweir     b = b && (  r1->getPropertyValue( OUString(RTL_CONSTASCII_USTRINGPARAM("float")) ) ==
851*cdf0e10cSrcweir                 r2->getPropertyValue( OUString(RTL_CONSTASCII_USTRINGPARAM("float")) ) );
852*cdf0e10cSrcweir     if( ! b ){
853*cdf0e10cSrcweir         float f1(0.0);
854*cdf0e10cSrcweir         float f2(0.0);
855*cdf0e10cSrcweir         r1->getPropertyValue( OUString(RTL_CONSTASCII_USTRINGPARAM("float")) ) >>= f1;
856*cdf0e10cSrcweir         r2->getPropertyValue( OUString(RTL_CONSTASCII_USTRINGPARAM("float")) ) >>= f2;
857*cdf0e10cSrcweir         fprintf( stderr, "compareMyPropertySet: %f %f 3\n",f1,f2 );
858*cdf0e10cSrcweir     }
859*cdf0e10cSrcweir 
860*cdf0e10cSrcweir     b = b && (  r1->getPropertyValue( OUString(RTL_CONSTASCII_USTRINGPARAM("double")) ) ==
861*cdf0e10cSrcweir                 r2->getPropertyValue( OUString(RTL_CONSTASCII_USTRINGPARAM("double" ))) );
862*cdf0e10cSrcweir     if( ! b ) fprintf( stderr, "compareMyPropertySet: 4\n" );
863*cdf0e10cSrcweir 
864*cdf0e10cSrcweir     sal_Bool b1(sal_False), b2(sal_False);
865*cdf0e10cSrcweir     Any a =r1->getPropertyValue( OUString(RTL_CONSTASCII_USTRINGPARAM("bool")) );
866*cdf0e10cSrcweir     a >>= b1;
867*cdf0e10cSrcweir     a = r2->getPropertyValue( OUString(RTL_CONSTASCII_USTRINGPARAM("bool")) );
868*cdf0e10cSrcweir     a >>= b2;
869*cdf0e10cSrcweir     b = b && ( (b1 && b2) || b1 == b2 );
870*cdf0e10cSrcweir     if( ! b ) fprintf( stderr, "compareMyPropertySet: 5\n" );
871*cdf0e10cSrcweir 
872*cdf0e10cSrcweir //      b = b &&    r1->getPropertyValue( OUString(RTL_CONSTASCII_USTRINGPARAM("bool")) ) ==
873*cdf0e10cSrcweir //                  r2->getPropertyValue( OUString(RTL_CONSTASCII_USTRINGPARAM("bool")) ) );
874*cdf0e10cSrcweir 
875*cdf0e10cSrcweir     b = b && (  r1->getPropertyValue( OUString(RTL_CONSTASCII_USTRINGPARAM("byte")) ) ==
876*cdf0e10cSrcweir                 r2->getPropertyValue( OUString(RTL_CONSTASCII_USTRINGPARAM("byte")) ) );
877*cdf0e10cSrcweir     if( ! b ) fprintf( stderr, "compareMyPropertySet: 6\n" );
878*cdf0e10cSrcweir 
879*cdf0e10cSrcweir     b = b && (  r1->getPropertyValue( OUString(RTL_CONSTASCII_USTRINGPARAM("char")) ) ==
880*cdf0e10cSrcweir                 r2->getPropertyValue( OUString(RTL_CONSTASCII_USTRINGPARAM("char")) ) );
881*cdf0e10cSrcweir     if( ! b ) fprintf( stderr, "compareMyPropertySet: 7\n" );
882*cdf0e10cSrcweir 
883*cdf0e10cSrcweir     b = b && (  r1->getPropertyValue( OUString(RTL_CONSTASCII_USTRINGPARAM("string")) ) ==
884*cdf0e10cSrcweir                 r2->getPropertyValue( OUString(RTL_CONSTASCII_USTRINGPARAM("string")) ));
885*cdf0e10cSrcweir     if( ! b ) fprintf( stderr, "compareMyPropertySet: 8\n" );
886*cdf0e10cSrcweir 
887*cdf0e10cSrcweir     Any o1 = r1->getPropertyValue( OUString(RTL_CONSTASCII_USTRINGPARAM("object")) );
888*cdf0e10cSrcweir     Any o2 = r2->getPropertyValue( OUString(RTL_CONSTASCII_USTRINGPARAM("object")) );
889*cdf0e10cSrcweir 
890*cdf0e10cSrcweir     if( o1.getValueType() == getCppuType( (Reference<XPersistObject>*)0 ) ) {
891*cdf0e10cSrcweir 
892*cdf0e10cSrcweir         if( o2.getValueType() == getCppuType( (Reference<XPersistObject>*)0 ) ) {
893*cdf0e10cSrcweir             Reference < XPersistObject > rPersist1;
894*cdf0e10cSrcweir             Reference < XPersistObject > rPersist2;
895*cdf0e10cSrcweir             o1 >>= rPersist1;
896*cdf0e10cSrcweir             o2 >>= rPersist2;
897*cdf0e10cSrcweir             Reference <XPropertySet > rProp1( rPersist1 , UNO_QUERY );
898*cdf0e10cSrcweir             Reference < XPropertySet > rProp2( rPersist2 , UNO_QUERY );
899*cdf0e10cSrcweir 
900*cdf0e10cSrcweir             if( rProp1.is() && rProp2.is() && ! ( rProp1 == rProp2 )
901*cdf0e10cSrcweir                 &&( rProp1 != r1 )) {
902*cdf0e10cSrcweir                     b = b && compareMyPropertySet( rProp1 , rProp2 );
903*cdf0e10cSrcweir             }
904*cdf0e10cSrcweir         }
905*cdf0e10cSrcweir         else {
906*cdf0e10cSrcweir             b = sal_False;
907*cdf0e10cSrcweir         }
908*cdf0e10cSrcweir         if( ! b ) fprintf( stderr, "compareMyPropertySet: 9\n" );
909*cdf0e10cSrcweir     }
910*cdf0e10cSrcweir     else {
911*cdf0e10cSrcweir         if( o2.getValueType()  == getCppuType( (Reference<XPersistObject>*)0 ) ) {
912*cdf0e10cSrcweir             b = sal_False;
913*cdf0e10cSrcweir         }
914*cdf0e10cSrcweir         if( ! b ) fprintf( stderr, "compareMyPropertySet: 10\n" );
915*cdf0e10cSrcweir     }
916*cdf0e10cSrcweir 
917*cdf0e10cSrcweir     return b;
918*cdf0e10cSrcweir }
919*cdf0e10cSrcweir 
920*cdf0e10cSrcweir void OObjectStreamTest::testObject(     const Reference<  XObjectOutputStream >  &rOut,
921*cdf0e10cSrcweir                                         const Reference < XObjectInputStream > &rIn )
922*cdf0e10cSrcweir {
923*cdf0e10cSrcweir     ERROR_ASSERT( rOut.is() , "no objectOutputStream" );
924*cdf0e10cSrcweir     ERROR_ASSERT( rIn.is() , "no objectInputStream" );
925*cdf0e10cSrcweir 
926*cdf0e10cSrcweir 
927*cdf0e10cSrcweir 
928*cdf0e10cSrcweir     // tests, if saving an object with an unknown service name allows
929*cdf0e10cSrcweir     // reading the data behind the object !
930*cdf0e10cSrcweir     {
931*cdf0e10cSrcweir         Reference < XInterface > x = * new MyPersistObject(
932*cdf0e10cSrcweir             OUString( RTL_CONSTASCII_USTRINGPARAM("bla blubs")) );
933*cdf0e10cSrcweir 
934*cdf0e10cSrcweir         Reference< XPersistObject > persistRef( x , UNO_QUERY );
935*cdf0e10cSrcweir         ERROR_ASSERT( persistRef.is() , "couldn't instantiate PersistTest object" );
936*cdf0e10cSrcweir 
937*cdf0e10cSrcweir         rOut->writeObject( persistRef );
938*cdf0e10cSrcweir         rOut->writeLong( (sal_Int32) 0xdeadbeef );
939*cdf0e10cSrcweir 
940*cdf0e10cSrcweir         ERROR_ASSERT( 0 != rIn->available() , "no data arrived at input" );
941*cdf0e10cSrcweir 
942*cdf0e10cSrcweir         try
943*cdf0e10cSrcweir         {
944*cdf0e10cSrcweir             Reference <XPersistObject >  xReadPersistRef = rIn->readObject();
945*cdf0e10cSrcweir             ERROR_ASSERT( 0 , "expected exception not thrown" );
946*cdf0e10cSrcweir         }
947*cdf0e10cSrcweir         catch( IOException & )
948*cdf0e10cSrcweir         {
949*cdf0e10cSrcweir             // all is ok
950*cdf0e10cSrcweir         }
951*cdf0e10cSrcweir 
952*cdf0e10cSrcweir         ERROR_ASSERT( (sal_Int32) 0xdeadbeef == rIn->readLong() ,
953*cdf0e10cSrcweir                       "wrong data after object with unknown service name." );
954*cdf0e10cSrcweir     }
955*cdf0e10cSrcweir 
956*cdf0e10cSrcweir     {
957*cdf0e10cSrcweir         Reference < XInterface > x = m_rFactory->createInstance(
958*cdf0e10cSrcweir             OUString( RTL_CONSTASCII_USTRINGPARAM("test.com.sun.star.io.PersistTest")));
959*cdf0e10cSrcweir         Reference< XPersistObject > persistRef( x , UNO_QUERY );
960*cdf0e10cSrcweir 
961*cdf0e10cSrcweir         ERROR_ASSERT( persistRef.is() , "couldn't instantiate PersistTest object" );
962*cdf0e10cSrcweir 
963*cdf0e10cSrcweir         Reference < XPropertySet > rProp( persistRef , UNO_QUERY );
964*cdf0e10cSrcweir         ERROR_ASSERT( rProp.is() , "test object is no property set " );
965*cdf0e10cSrcweir 
966*cdf0e10cSrcweir         Any any;
967*cdf0e10cSrcweir         sal_Int32 i = 0x83482;
968*cdf0e10cSrcweir         any <<= i;
969*cdf0e10cSrcweir         rProp->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM("long")) , any );
970*cdf0e10cSrcweir 
971*cdf0e10cSrcweir         float f = (float)42.23;
972*cdf0e10cSrcweir         any <<= f;
973*cdf0e10cSrcweir         rProp->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM("float")) , any );
974*cdf0e10cSrcweir 
975*cdf0e10cSrcweir         double d = 233.321412;
976*cdf0e10cSrcweir         any <<= d;
977*cdf0e10cSrcweir         rProp->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM("double")) , any );
978*cdf0e10cSrcweir 
979*cdf0e10cSrcweir         sal_Bool b = sal_True;
980*cdf0e10cSrcweir         any.setValue( &b , getCppuBooleanType() );
981*cdf0e10cSrcweir         rProp->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM("bool")) , any );
982*cdf0e10cSrcweir 
983*cdf0e10cSrcweir         sal_Int8 by = 120;
984*cdf0e10cSrcweir         any <<= by;
985*cdf0e10cSrcweir         rProp->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM("byte")) , any );
986*cdf0e10cSrcweir 
987*cdf0e10cSrcweir         sal_Unicode c = 'h';
988*cdf0e10cSrcweir         any.setValue( &c , getCppuCharType() );
989*cdf0e10cSrcweir         rProp->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM("char")) , any );
990*cdf0e10cSrcweir 
991*cdf0e10cSrcweir         OUString str( RTL_CONSTASCII_USTRINGPARAM( "hi du !" ) );
992*cdf0e10cSrcweir         any <<= str;
993*cdf0e10cSrcweir         rProp->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM("string")) , any );
994*cdf0e10cSrcweir 
995*cdf0e10cSrcweir         any <<= persistRef;
996*cdf0e10cSrcweir         rProp->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM("object")) , any );
997*cdf0e10cSrcweir 
998*cdf0e10cSrcweir         // do read and write
999*cdf0e10cSrcweir         rOut->writeObject( persistRef );
1000*cdf0e10cSrcweir         ERROR_ASSERT( 0 != rIn->available() , "no data arrived at input" );
1001*cdf0e10cSrcweir         Reference< XPersistObject > xReadPersist    =   rIn->readObject( );
1002*cdf0e10cSrcweir 
1003*cdf0e10cSrcweir         Reference< XPropertySet >  rPropRead( xReadPersist , UNO_QUERY );
1004*cdf0e10cSrcweir         ERROR_ASSERT( compareMyPropertySet( rProp , rPropRead ) , "objects has not been read properly !" );
1005*cdf0e10cSrcweir 
1006*cdf0e10cSrcweir         // destroy selfreferences
1007*cdf0e10cSrcweir         rProp->setPropertyValue( OUString::createFromAscii("object"), Any() );
1008*cdf0e10cSrcweir         rPropRead->setPropertyValue( OUString::createFromAscii("object"), Any() );
1009*cdf0e10cSrcweir     }
1010*cdf0e10cSrcweir 
1011*cdf0e10cSrcweir     {
1012*cdf0e10cSrcweir         Reference< XMarkableStream > markableOut( rOut , UNO_QUERY );
1013*cdf0e10cSrcweir         ERROR_ASSERT( markableOut.is() , "markable stream cannot be queried" );
1014*cdf0e10cSrcweir 
1015*cdf0e10cSrcweir         // do the same thing multiple times to check if
1016*cdf0e10cSrcweir         // buffering and marks work correctly
1017*cdf0e10cSrcweir         for( int i = 0 ; i < 2000 ; i ++ ) {
1018*cdf0e10cSrcweir 
1019*cdf0e10cSrcweir             Reference < XInterface > x = m_rFactory->createInstance(OUString::createFromAscii("test.com.sun.star.io.PersistTest"));
1020*cdf0e10cSrcweir             Reference< XPersistObject >  persistRef( x , UNO_QUERY );
1021*cdf0e10cSrcweir 
1022*cdf0e10cSrcweir             Reference < XPropertySet >  rProp( persistRef , UNO_QUERY );
1023*cdf0e10cSrcweir             ERROR_ASSERT( rProp.is() , "test object is no property set " );
1024*cdf0e10cSrcweir 
1025*cdf0e10cSrcweir             Any any;
1026*cdf0e10cSrcweir             sal_Int32 i = 0x83482;
1027*cdf0e10cSrcweir             any <<= i;
1028*cdf0e10cSrcweir             rProp->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM("long")) , any );
1029*cdf0e10cSrcweir 
1030*cdf0e10cSrcweir             float f = 42.23;
1031*cdf0e10cSrcweir             any <<= f;
1032*cdf0e10cSrcweir             rProp->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM("float")) , any );
1033*cdf0e10cSrcweir 
1034*cdf0e10cSrcweir             double d = 233.321412;
1035*cdf0e10cSrcweir             any <<= d;
1036*cdf0e10cSrcweir             rProp->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM("double")) , any );
1037*cdf0e10cSrcweir 
1038*cdf0e10cSrcweir             sal_Bool b = sal_True;
1039*cdf0e10cSrcweir             any.setValue( &b , getCppuBooleanType() );
1040*cdf0e10cSrcweir             rProp->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM("bool")) , any );
1041*cdf0e10cSrcweir 
1042*cdf0e10cSrcweir             sal_Int8 by = 120;
1043*cdf0e10cSrcweir             any <<= by;
1044*cdf0e10cSrcweir             rProp->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM("byte")) , any );
1045*cdf0e10cSrcweir 
1046*cdf0e10cSrcweir             sal_Unicode c = 'h';
1047*cdf0e10cSrcweir             any.setValue( &c , getCppuCharType() );
1048*cdf0e10cSrcweir             rProp->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM("char")) , any );
1049*cdf0e10cSrcweir 
1050*cdf0e10cSrcweir             OUString str( RTL_CONSTASCII_USTRINGPARAM( "hi du !" ) );
1051*cdf0e10cSrcweir             any <<= str;
1052*cdf0e10cSrcweir             rProp->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM("string")) , any );
1053*cdf0e10cSrcweir 
1054*cdf0e10cSrcweir             x = m_rFactory->createInstance(OUString::createFromAscii("test.com.sun.star.io.PersistTest"));
1055*cdf0e10cSrcweir             Reference <XPersistObject > persist2ndRef( x , UNO_QUERY );
1056*cdf0e10cSrcweir 
1057*cdf0e10cSrcweir             // Note : persist2ndRef contains coincident values, but also coincident values must be
1058*cdf0e10cSrcweir             // saved properly !
1059*cdf0e10cSrcweir             any <<= persist2ndRef;
1060*cdf0e10cSrcweir             rProp->setPropertyValue( OUString::createFromAscii("object") , any );
1061*cdf0e10cSrcweir 
1062*cdf0e10cSrcweir             // simply test, if markable operations and object operations do not interfere
1063*cdf0e10cSrcweir             sal_Int32 nMark = markableOut->createMark();
1064*cdf0e10cSrcweir 
1065*cdf0e10cSrcweir             // do read and write
1066*cdf0e10cSrcweir             rOut->writeObject( persistRef );
1067*cdf0e10cSrcweir 
1068*cdf0e10cSrcweir             // further markable tests !
1069*cdf0e10cSrcweir             sal_Int32 nOffset = markableOut->offsetToMark( nMark );
1070*cdf0e10cSrcweir             markableOut->jumpToMark( nMark );
1071*cdf0e10cSrcweir             markableOut->deleteMark( nMark );
1072*cdf0e10cSrcweir             markableOut->jumpToFurthest();
1073*cdf0e10cSrcweir 
1074*cdf0e10cSrcweir 
1075*cdf0e10cSrcweir 
1076*cdf0e10cSrcweir 
1077*cdf0e10cSrcweir 
1078*cdf0e10cSrcweir             ERROR_ASSERT( 0 != rIn->available() , "no data arrived at input" );
1079*cdf0e10cSrcweir             Reference < XPersistObject > xReadPersistRef    =   rIn->readObject( );
1080*cdf0e10cSrcweir 
1081*cdf0e10cSrcweir             Reference< XPropertySet > rProp1( persistRef , UNO_QUERY );
1082*cdf0e10cSrcweir             Reference< XPropertySet >  rProp2( xReadPersistRef , UNO_QUERY );
1083*cdf0e10cSrcweir             ERROR_ASSERT( compareMyPropertySet( rProp1, rProp2) ,
1084*cdf0e10cSrcweir                           "objects has not been read properly !" );
1085*cdf0e10cSrcweir         }
1086*cdf0e10cSrcweir     }
1087*cdf0e10cSrcweir }
1088*cdf0e10cSrcweir 
1089*cdf0e10cSrcweir 
1090*cdf0e10cSrcweir Reference < XInterface > SAL_CALL OObjectStreamTest_CreateInstance( const Reference < XMultiServiceFactory > & rSMgr ) throw(Exception)
1091*cdf0e10cSrcweir {
1092*cdf0e10cSrcweir     OObjectStreamTest *p = new OObjectStreamTest( rSMgr );
1093*cdf0e10cSrcweir     return Reference < XInterface > ( SAL_STATIC_CAST( OWeakObject * , p ) );
1094*cdf0e10cSrcweir }
1095*cdf0e10cSrcweir 
1096*cdf0e10cSrcweir Sequence<OUString> OObjectStreamTest_getSupportedServiceNames( int i) throw ()
1097*cdf0e10cSrcweir {
1098*cdf0e10cSrcweir     Sequence<OUString> aRet(1);
1099*cdf0e10cSrcweir     aRet.getArray()[0] = OObjectStreamTest_getImplementationName( i);
1100*cdf0e10cSrcweir     return aRet;
1101*cdf0e10cSrcweir }
1102*cdf0e10cSrcweir 
1103*cdf0e10cSrcweir OUString     OObjectStreamTest_getServiceName( int i) throw ()
1104*cdf0e10cSrcweir {
1105*cdf0e10cSrcweir     if( 1 == i ) {
1106*cdf0e10cSrcweir         return OUString( RTL_CONSTASCII_USTRINGPARAM("test.com.sun.star.io.ObjectInputStream" ));
1107*cdf0e10cSrcweir     }
1108*cdf0e10cSrcweir     else {
1109*cdf0e10cSrcweir         return OUString( RTL_CONSTASCII_USTRINGPARAM("test.com.sun.star.io.ObjectOutputStream"));
1110*cdf0e10cSrcweir     }
1111*cdf0e10cSrcweir }
1112*cdf0e10cSrcweir 
1113*cdf0e10cSrcweir OUString    OObjectStreamTest_getImplementationName( int i) throw ()
1114*cdf0e10cSrcweir {
1115*cdf0e10cSrcweir     if( 1 == i ) {
1116*cdf0e10cSrcweir         return OUString( RTL_CONSTASCII_USTRINGPARAM("test.com.sun.star.comp.extensions.stm.ObjectInputStream" ));
1117*cdf0e10cSrcweir     }
1118*cdf0e10cSrcweir     else {
1119*cdf0e10cSrcweir         return OUString( RTL_CONSTASCII_USTRINGPARAM("test.com.sun.star.comp.extensions.stm.ObjectOutputStream"));
1120*cdf0e10cSrcweir     }
1121*cdf0e10cSrcweir }
1122*cdf0e10cSrcweir 
1123*cdf0e10cSrcweir 
1124