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