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