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