summaryrefslogtreecommitdiff
path: root/objective-c/test/Ice/stream/Client.m
blob: 415d113787e04b720bae38ff8d16025753cb0851 (plain)
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
// **********************************************************************
//
// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved.
//
// This copy of Ice is licensed to you under the terms described in the
// ICE_LICENSE file included in this distribution.
//
// **********************************************************************

#import <objc/Ice.h>
#import <TestCommon.h>
#import <StreamTest.h>

static int
run(id<ICECommunicator> communicator)
{
    id<ICEInputStream> in;
    id<ICEOutputStream> out;
    NSMutableData* data;

    //
    // Test the stream api.
    //
    tprintf("testing primitive types... ");
    
    {
        NSData* byte = [NSData data];
        in = [ICEUtil createInputStream:communicator data:byte];
    }

    {
        out = [ICEUtil createOutputStream:communicator];
        [out startEncapsulation];
        [out writeBool:YES];
        [out endEncapsulation];
        data = [out finished];
        NSData* d = [out finishedNoCopy];
        test([d isEqual:data]);
        out = nil;

        in = [ICEUtil createInputStream:communicator data:data];
        [in startEncapsulation];
        BOOL v;
        v = [in readBool];
        test(v);
        [in endEncapsulation];

        in = [ICEUtil wrapInputStream:communicator data:data];
        [in startEncapsulation];
        v = [in readBool];
        test(v);
        [in endEncapsulation];
    }

    {
        NSData* byte = [NSData data];
        in = [ICEUtil createInputStream:communicator data:byte];
        @try
        {
            BOOL v;
            v = [in readBool];
            test(NO);
        }
        @catch(ICEUnmarshalOutOfBoundsException* ex)
        {
        }
    }

    {
        out = [ICEUtil createOutputStream:communicator];
        [out writeBool:YES];
        data = [out finished];
        in = [ICEUtil createInputStream:communicator data:data];
        BOOL v = [in readBool];
        test(v);
    }

    {
        out = [ICEUtil createOutputStream:communicator];
        [out writeByte:(ICEByte)1];
        data = [out finished];
        in = [ICEUtil createInputStream:communicator data:data];
        ICEByte v = [in readByte];
        test(v == 1);
    }

    {
        out = [ICEUtil createOutputStream:communicator];
        [out writeShort:(ICEShort)2];
        data = [out finished];
        in = [ICEUtil createInputStream:communicator data:data];
        ICEShort v = [in readShort];
        test(v == 2);
    }

    {
        out = [ICEUtil createOutputStream:communicator];
        [out writeInt:(ICEInt)3];
        data = [out finished];
        in = [ICEUtil createInputStream:communicator data:data];
        ICEInt v;
        v = [in readInt];
        test(v == 3);
    }

    {
        out = [ICEUtil createOutputStream:communicator];
        [out writeLong:(ICELong)4];
        data = [out finished];
        in = [ICEUtil createInputStream:communicator data:data];
        ICELong v;
        v = [in readLong];
        test(v == 4);
    }

    {
        out = [ICEUtil createOutputStream:communicator];
        [out writeFloat:(ICEFloat)5.0];
        data = [out finished];
        in = [ICEUtil createInputStream:communicator data:data];
        ICEFloat v;
        v = [in readFloat];
        test(v == 5.0);
    }

    {
        out = [ICEUtil createOutputStream:communicator];
        [out writeDouble:(ICEDouble)6.0];
        data = [out finished];
        in = [ICEUtil createInputStream:communicator data:data];
        ICEDouble v;
        v = [in readDouble];
        test(v == 6.0);
    }

    {
        out = [ICEUtil createOutputStream:communicator];
        [out writeString:@"hello world"];
        data = [out finished];
        in = [ICEUtil createInputStream:communicator data:data];
        NSString* v;
        v = [in readString];
        test([v isEqualToString:@"hello world"]);
    }

    tprintf("ok\n");
    
    tprintf("testing constructed types... ");
    
    {
        out = [ICEUtil createOutputStream:communicator];
        [TestStreamMyEnumHelper write:@(TestStreamenum3) stream:out];
        data = [out finished];
        in = [ICEUtil createInputStream:communicator data:data];
        id e = [TestStreamMyEnumHelper read:in];
        test([e isEqual:@(TestStreamenum3)]);
    }

    {
        out = [ICEUtil createOutputStream:communicator];
        TestStreamSmallStruct* s = [TestStreamSmallStruct smallStruct];
        s.bo = YES;
        s.by = 1;
        s.sh = 2;
        s.i = 3;
        s.l = 4;
        s.f = 5.0;
        s.d = 6.0;
        s.str = @"7";
        s.e = TestStreamenum2;
        s.p = [TestStreamMyClassPrx uncheckedCast:[communicator stringToProxy:@"test:default"]];
        [TestStreamSmallStructHelper write:s stream:out];
        data = [out finished];
        in = [ICEUtil createInputStream:communicator data:data];
        TestStreamSmallStruct* s2 = [TestStreamSmallStructHelper read:in];
        test([s2 isEqual:s]);
    }

    {
        out = [ICEUtil createOutputStream:communicator];
        TestStreamClassStruct* s = [TestStreamClassStruct classStruct];
        s.i = 10;
        [TestStreamClassStructHelper write:s stream:out];
        data = [out finished];
        in = [ICEUtil createInputStream:communicator data:data];
        TestStreamClassStruct* s2 = [TestStreamClassStructHelper read:in];
        test(s2.i == s.i);
    }

    {
        out = [ICEUtil createOutputStream:communicator];
        TestStreamOptionalClass* o = [TestStreamOptionalClass optionalClass];
        o.bo = NO;
        o.by = 5;
        o.sh = 4;
        o.i = 3;
        [TestStreamOptionalClassHelper write:o stream:out];
        [out writePendingObjects];
        data = [out finished];
        in = [ICEUtil createInputStream:communicator data:data];
        TestStreamOptionalClass* ICE_AUTORELEASING_QUALIFIER o2;
        [TestStreamOptionalClassHelper read:&o2 stream:in];
        [in readPendingObjects];
        test(o2.bo == o.bo);
        test(o2.by == o.by);
        if([in getEncoding] == ICEEncoding_1_0)
        {
            test(![o2 hasSh]);
            test(![o2 hasI]);
        }
        else
        {
            test(o2.sh == o.sh);
            test(o2.i == o.i);
        }
    }

    {
        out = [ICEUtil createOutputStream:communicator encoding:ICEEncoding_1_0];
        TestStreamOptionalClass* o = [TestStreamOptionalClass optionalClass];
        o.bo = NO;
        o.by = 5;
        o.sh = 4;
        o.i = 3;
        [TestStreamOptionalClassHelper write:o stream:out];
        [out writePendingObjects];
        data = [out finished];
        in = [ICEUtil createInputStream:communicator data:data encoding:ICEEncoding_1_0];
        TestStreamOptionalClass* ICE_AUTORELEASING_QUALIFIER o2;
        [TestStreamOptionalClassHelper read:&o2 stream:in];
        [in readPendingObjects];
        test(o2.bo == o.bo);
        test(o2.by == o.by);
        test(![o2 hasSh]);
        test(![o2 hasI]);
    }

    {
	BOOL buf[] = { YES, YES, NO, YES };
        ICEBoolSeq* arr = [ICEBoolSeq dataWithBytes:buf length:sizeof(buf)];

        out = [ICEUtil createOutputStream:communicator];
        [ICEBoolSeqHelper write:arr stream:out];
        data = [out finished];

        in = [ICEUtil createInputStream:communicator data:data];
        ICEBoolSeq* arr2 = [ICEBoolSeqHelper read:in];
        test([arr2 isEqual:arr]);

        TestStreamMutableBoolSS* arrS = [TestStreamMutableBoolSS array];
        [arrS addObject:arr];
        [arrS addObject:[ICEBoolSeq data]];
        [arrS addObject:arr];

        out = [ICEUtil createOutputStream:communicator];
        [TestStreamBoolSSHelper write:arrS stream:out];
        data = [out finished];

        in = [ICEUtil createInputStream:communicator data:data];
        TestStreamBoolSS* arr2S = [TestStreamBoolSSHelper read:in];
        test([arr2S isEqual:arrS]);
    }

    {
        ICEByte buf[] = { 0x01, 0x11, 0x12, 0x22 };
        ICEByteSeq* arr = [ICEByteSeq dataWithBytes:buf length:sizeof(buf)];

        out = [ICEUtil createOutputStream:communicator];
        [ICEByteSeqHelper write:arr stream:out];
        data = [out finished];
        in = [ICEUtil createInputStream:communicator data:data];
        ICEByteSeq* arr2 = [ICEByteSeqHelper read:in];
        test([arr2 isEqual:arr]);

        TestStreamMutableByteSS* arrS = [TestStreamMutableByteSS array];
        [arrS addObject:arr];
        [arrS addObject:[ICEByteSeq data]];
        [arrS addObject:arr];

        out = [ICEUtil createOutputStream:communicator];
        [TestStreamByteSSHelper write:arrS stream:out];
        data = [out finished];

        in = [ICEUtil createInputStream:communicator data:data];
        TestStreamByteSS* arr2S = [TestStreamByteSSHelper read:in];
        test([arr2S isEqual:arrS]);
    }

    {
        ICEShort buf[] = { 1, 11, 12, 22 };
        ICEShortSeq* arr = [ICEShortSeq dataWithBytes:buf length:sizeof(buf)];

        out = [ICEUtil createOutputStream:communicator];
        [ICEShortSeqHelper write:arr stream:out];
        data = [out finished];
        in = [ICEUtil createInputStream:communicator data:data];
        ICEShortSeq* arr2 = [ICEShortSeqHelper read:in];
        test([arr2 isEqual:arr]);

        TestStreamMutableShortSS* arrS = [TestStreamMutableShortSS array];
        [arrS addObject:arr];
        [arrS addObject:[ICEShortSeq data]];
        [arrS addObject:arr];

        out = [ICEUtil createOutputStream:communicator];
        [TestStreamShortSSHelper write:arrS stream:out];
        data = [out finished];

        in = [ICEUtil createInputStream:communicator data:data];
        TestStreamShortSS* arr2S = [TestStreamShortSSHelper read:in];
        test([arr2S isEqual:arrS]);
    }

    {
        ICEInt buf[] = { 1, 11, 12, 22 };
        ICEIntSeq* arr = [ICEIntSeq dataWithBytes:buf length:sizeof(buf)];

        out = [ICEUtil createOutputStream:communicator];
        [ICEIntSeqHelper write:arr stream:out];
        data = [out finished];
        in = [ICEUtil createInputStream:communicator data:data];
        ICEIntSeq* arr2 = [ICEIntSeqHelper read:in];
        test([arr2 isEqual:arr]);

        TestStreamMutableIntSS* arrS = [TestStreamMutableIntSS array];
        [arrS addObject:arr];
        [arrS addObject:[ICEIntSeq data]];
        [arrS addObject:arr];

        out = [ICEUtil createOutputStream:communicator];
        [TestStreamIntSSHelper write:arrS stream:out];
        data = [out finished];

        in = [ICEUtil createInputStream:communicator data:data];
        TestStreamIntSS* arr2S = [TestStreamIntSSHelper read:in];
        test([arr2S isEqual:arrS]);
    }

    {
        ICELong buf[] = { 1, 11, 12, 22 };
        ICELongSeq* arr = [ICELongSeq dataWithBytes:buf length:sizeof(buf)];

        out = [ICEUtil createOutputStream:communicator];
        [ICELongSeqHelper write:arr stream:out];
        data = [out finished];
        in = [ICEUtil createInputStream:communicator data:data];
        ICELongSeq* arr2 = [ICELongSeqHelper read:in];
        test([arr2 isEqual:arr]);

        TestStreamMutableLongSS* arrS = [TestStreamMutableLongSS array];
        [arrS addObject:arr];
        [arrS addObject:[ICELongSeq data]];
        [arrS addObject:arr];

        out = [ICEUtil createOutputStream:communicator];
        [TestStreamLongSSHelper write:arrS stream:out];
        data = [out finished];

        in = [ICEUtil createInputStream:communicator data:data];
        TestStreamLongSS* arr2S = [TestStreamLongSSHelper read:in];
        test([arr2S isEqual:arrS]);
    }

    {
        ICEFloat buf[] = { 1, 2, 3, 4 };
        ICEFloatSeq* arr = [ICEFloatSeq dataWithBytes:buf length:sizeof(buf)];

        out = [ICEUtil createOutputStream:communicator];
        [ICEFloatSeqHelper write:arr stream:out];
        data = [out finished];
        in = [ICEUtil createInputStream:communicator data:data];
        ICEFloatSeq* arr2 = [ICEFloatSeqHelper read:in];
        test([arr2 isEqual:arr]);

        TestStreamMutableFloatSS* arrS = [TestStreamMutableFloatSS array];
        [arrS addObject:arr];
        [arrS addObject:[ICEFloatSeq data]];
        [arrS addObject:arr];

        out = [ICEUtil createOutputStream:communicator];
        [TestStreamFloatSSHelper write:arrS stream:out];
        data = [out finished];

        in = [ICEUtil createInputStream:communicator data:data];
        TestStreamFloatSS* arr2S = [TestStreamFloatSSHelper read:in];
        test([arr2S isEqual:arrS]);
    }

    {
        ICEDouble buf[] = { 1, 2, 3, 4 };
        ICEDoubleSeq* arr = [ICEDoubleSeq dataWithBytes:buf length:sizeof(buf)];

        out = [ICEUtil createOutputStream:communicator];
        [ICEDoubleSeqHelper write:arr stream:out];
        data = [out finished];
        in = [ICEUtil createInputStream:communicator data:data];
        ICEDoubleSeq* arr2 = [ICEDoubleSeqHelper read:in];
        test([arr2 isEqual:arr]);

        TestStreamMutableDoubleSS* arrS = [TestStreamMutableDoubleSS array];
        [arrS addObject:arr];
        [arrS addObject:[ICEDoubleSeq data]];
        [arrS addObject:arr];

        out = [ICEUtil createOutputStream:communicator];
        [TestStreamDoubleSSHelper write:arrS stream:out];
        data = [out finished];

        in = [ICEUtil createInputStream:communicator data:data];
        TestStreamDoubleSS* arr2S = [TestStreamDoubleSSHelper read:in];
        test([arr2S isEqual:arrS]);
    }

    {
        ICEMutableStringSeq* arr = [ICEMutableStringSeq array];
        [arr addObject:@"string1"];
        [arr addObject:@"string2"];
        [arr addObject:@"string3"];
        [arr addObject:@"string4"];
        out = [ICEUtil createOutputStream:communicator];
        [ICEStringSeqHelper write:arr stream:out];
        data = [out finished];
        in = [ICEUtil createInputStream:communicator data:data];
        ICEStringSeq* arr2 = [ICEStringSeqHelper read:in];
        test([arr2 isEqual:arr]);

        TestStreamMutableStringSS* arrS = [TestStreamMutableStringSS array];
        [arrS addObject:arr];
        [arrS addObject:[ICEStringSeq array]];
        [arrS addObject:arr];

        out = [ICEUtil createOutputStream:communicator];
        [TestStreamStringSSHelper write:arrS stream:out];
        data = [out finished];

        in = [ICEUtil createInputStream:communicator data:data];
        TestStreamStringSS* arr2S = [TestStreamStringSSHelper read:in];
        test([arr2S isEqual:arrS]);
    }

    {
        TestStreamMyEnum buf[] = { TestStreamenum3, TestStreamenum2, TestStreamenum1, TestStreamenum2 };
        TestStreamMutableMyEnumS* arr = [TestStreamMutableMyEnumS dataWithBytes:buf length:sizeof(buf)];

        out = [ICEUtil createOutputStream:communicator];
        [TestStreamMyEnumSHelper write:arr stream:out];
        data = [out finished];
        in = [ICEUtil createInputStream:communicator data:data];
        TestStreamMyEnumS* arr2 = [TestStreamMyEnumSHelper read:in];
        test([arr2 isEqual:arr]);

        TestStreamMutableMyEnumSS* arrS = [TestStreamMutableMyEnumSS array];
        [arrS addObject:arr];
        [arrS addObject:[TestStreamMyEnumS data]];
        [arrS addObject:arr];

        out = [ICEUtil createOutputStream:communicator];
        [TestStreamMyEnumSSHelper write:arrS stream:out];
        data = [out finished];

        in = [ICEUtil createInputStream:communicator data:data];
        TestStreamMyEnumSS* arr2S = [TestStreamMyEnumSSHelper read:in];
        test([arr2S isEqual:arrS]);
    }

    {
        TestStreamMutableSmallStructS* arr = [TestStreamMutableSmallStructS array];
        for(int i = 0; i < 4; ++i)
        {
            TestStreamSmallStruct* s = [TestStreamSmallStruct smallStruct];
            s.bo = YES;
            s.by = 1;
            s.sh = 2;
            s.i = 3;
            s.l = 4;
            s.f = 5.0;
            s.d = 6.0;
            s.str = @"7";
            s.e = TestStreamenum2;
            s.p = [TestStreamMyClassPrx uncheckedCast:[communicator stringToProxy:@"test:default"]];
            [arr addObject:s];
        }
        out = [ICEUtil createOutputStream:communicator];
        [TestStreamSmallStructSHelper write:arr stream:out];
        [out writePendingObjects];
        data = [out finished];
        in = [ICEUtil createInputStream:communicator data:data];
        TestStreamSmallStructS* arr2 = [TestStreamSmallStructSHelper read:in];
        [in readPendingObjects];
        test([arr2 count] == [arr count]);
        for(int j = 0; j < [arr2 count]; ++j)
        {
            test([[arr objectAtIndex:j] isEqual:[arr2 objectAtIndex:j]]);
        }

        TestStreamMutableSmallStructSS* arrS = [TestStreamMutableSmallStructSS array];
        [arrS addObject:arr];
        [arrS addObject:[TestStreamSmallStructS array]];
        [arrS addObject:arr];

        out = [ICEUtil createOutputStream:communicator];
        [TestStreamSmallStructSSHelper write:arrS stream:out];
        data = [out finished];

        in = [ICEUtil createInputStream:communicator data:data];
        TestStreamSmallStructSS* arr2S = [TestStreamSmallStructSSHelper read:in];
        test([arr2S isEqual:arrS]);
    }

    {
        TestStreamMutableMyClassS* arr = [TestStreamMutableMyClassS array];
        for(int i = 0; i < 4; ++i)
        {
            TestStreamMyClass* c = [TestStreamMyClass myClass];
            c.c = c;
            c.o = c;
            c.s = [TestStreamSmallStruct smallStruct];
            c.s.e = TestStreamenum2;

            BOOL boolS[] = { YES, NO, YES, NO };
            c.seq1 = [NSMutableData dataWithBytes:boolS length:sizeof(boolS)];

            ICEByte byteS[] = { 1, 2, 3, 4 };
            c.seq2 = [NSMutableData dataWithBytes:byteS length:sizeof(byteS)];

            ICEShort shortS[] = { 1, 2, 3, 4 };
            c.seq3 = [NSMutableData dataWithBytes:shortS length:sizeof(shortS)];

            ICEInt intS[] = { 1, 2, 3, 4 };
            c.seq4 = [NSMutableData dataWithBytes:intS length:sizeof(intS)];

            ICELong longS[] = { 1, 2, 3, 4 };
            c.seq5 = [NSMutableData dataWithBytes:longS length:sizeof(longS)];

            ICEFloat floatS[] = { 1, 2, 3, 4 };
            c.seq6 = [NSMutableData dataWithBytes:floatS length:sizeof(floatS)];

            ICEDouble doubleS[] = { 1, 2, 3, 4 };
            c.seq7 = [NSMutableData dataWithBytes:doubleS length:sizeof(doubleS)];
            
            c.seq8 = [ICEMutableStringSeq array];
            [(ICEMutableStringSeq*)c.seq8 addObject:@"string1"];
            [(ICEMutableStringSeq*)c.seq8 addObject:@"string2"];
            [(ICEMutableStringSeq*)c.seq8 addObject:@"string3"];
            [(ICEMutableStringSeq*)c.seq8 addObject:@"string4"];

            TestStreamMyEnum enumS[] = { TestStreamenum3, TestStreamenum2, TestStreamenum1 };
            c.seq9 = [NSMutableData dataWithBytes:enumS length:sizeof(enumS)];
            
            c.d = [NSDictionary dictionaryWithObject:[TestStreamMyClass myClass] forKey:@"hi"];
            [arr addObject:c];
        }
        out = [ICEUtil createOutputStream:communicator];
        [TestStreamMyClassSHelper write:arr stream:out];
        [out writePendingObjects];
        data = [out finished];
        in = [ICEUtil createInputStream:communicator data:data];
        TestStreamMyClassS* arr2 = [TestStreamMyClassSHelper read:in];
        [in readPendingObjects];
        test([arr2 count] > 0);
        test([arr2 count] == [arr count]);
        for(int j = 0; j < [arr2 count]; ++j)
        {
            TestStreamMyClass* e = [arr2 objectAtIndex:j];
            TestStreamMyClass* f = [arr objectAtIndex:j];
            test(e);
            test(e.c == e);
            test(e.o == e);
            test(e.s.e == TestStreamenum2);
            test([e.seq1 isEqual:f.seq1]);
            test([e.seq2 isEqual:f.seq2]);
            test([e.seq3 isEqual:f.seq3]);
            test([e.seq4 isEqual:f.seq4]);
            test([e.seq5 isEqual:f.seq5]);
            test([e.seq6 isEqual:f.seq6]);
            test([e.seq7 isEqual:f.seq7]);
            test([e.seq8 isEqual:f.seq8]);
            test([e.seq9 isEqual:f.seq9]);
            test([e.d objectForKey:@"hi"] != nil);

            e.c = nil;
            e.o = nil;
            f.c = nil;
            f.o = nil;
        }
                
        TestStreamMutableMyClassSS* arrS = [TestStreamMutableMyClassSS array];
        [arrS addObject:arr];
        [arrS addObject:[TestStreamMyClassS array]];
        [arrS addObject:arr];

        out = [ICEUtil createOutputStream:communicator];
        [TestStreamMyClassSSHelper write:arrS stream:out];
        data = [out finished];

        in = [ICEUtil createInputStream:communicator data:data];
        TestStreamMyClassSS* arr2S = [TestStreamMyClassSSHelper read:in];
        test([arr2S count] == [arrS count]);
    }

    {
        TestStreamMyInterface ICE_AUTORELEASING_QUALIFIER * i = [TestStreamMyInterface new];
        out = [ICEUtil createOutputStream:communicator];
        [TestStreamMyInterfaceHelper write:i stream:out];
        [out writePendingObjects];
        data = [out finished];
        in = [ICEUtil createInputStream:communicator data:data];
        i = nil;
        [TestStreamMyInterfaceHelper read:&i stream:in];
        [in readPendingObjects];
        test(i != nil);
    }

    //
    // ObjectWriter/ObjectReader not supported.
    //
    // {
    //     out = [ICEUtil createOutputStream:communicator];
    //     TestStreamMyClass* obj = [TestStreamMyClass myClass];
    //     obj.s.e = TestStreamenum2;
    //     TestObjectWriterPtr writer = new TestObjectWriter:obj];
    //     [out writeObject:writer];
    //     [out writePendingObjects];
    //     data = [out finished];
    //     test([writer called);
    // }

    // {
    //     out = [ICEUtil createOutputStream:communicator];
    //     TestStreamMyClassPtr obj = new TestStreamMyClass;
    //     obj->s.e = TestStreamenum2;
    //     TestObjectWriterPtr writer = new TestObjectWriter:obj];
    //     [out writeObject:writer];
    //     [out writePendingObjects];
    //     data = [out finished];
    //     test([writer called]);
    //     [factoryWrapper setFactory:new TestObjectFactory];
    //     in = [ICEUtil createInputStream:communicator data:data];
    //     TestReadObjectCallbackPtr cb = new TestReadObjectCallback;
    //     [in readObject:cb];
    //     [in readPendingObjects];
    //     test([cb obj]);
    //     TestObjectReaderPtr reader = TestObjectReaderPtr::dynamicCast(cb->obj);
    //     test(reader);
    //     test([reader called]);
    //     test([reader obj]);
    //     test([reader obj]->s.e == TestStreamenum2);
    //     [factoryWrapper setFactory:0];
    // }

    {
        out = [ICEUtil createOutputStream:communicator];
        TestStreamMyException* ex = [TestStreamMyException myException];
        TestStreamMyClass* c = [TestStreamMyClass myClass];
        c.c = c;
        c.o = c;
        c.s = [TestStreamSmallStruct smallStruct];
        c.s.e = TestStreamenum2;

        BOOL boolS[] = { YES, NO, YES, NO };
        c.seq1 = [NSMutableData dataWithBytes:boolS length:sizeof(boolS)];

        ICEByte byteS[] = { 1, 2, 3, 4 };
        c.seq2 = [NSMutableData dataWithBytes:byteS length:sizeof(byteS)];

        ICEShort shortS[] = { 1, 2, 3, 4 };
        c.seq3 = [NSMutableData dataWithBytes:shortS length:sizeof(shortS)];

        ICEInt intS[] = { 1, 2, 3, 4 };
        c.seq4 = [NSMutableData dataWithBytes:intS length:sizeof(intS)];

        ICELong longS[] = { 1, 2, 3, 4 };
        c.seq5 = [NSMutableData dataWithBytes:longS length:sizeof(longS)];

        ICEFloat floatS[] = { 1, 2, 3, 4 };
        c.seq6 = [NSMutableData dataWithBytes:floatS length:sizeof(floatS)];

        ICEDouble doubleS[] = { 1, 2, 3, 4 };
        c.seq7 = [NSMutableData dataWithBytes:doubleS length:sizeof(doubleS)];
            
        c.seq8 = [ICEMutableStringSeq array];
        [(ICEMutableStringSeq*)c.seq8 addObject:@"string1"];
        [(ICEMutableStringSeq*)c.seq8 addObject:@"string2"];
        [(ICEMutableStringSeq*)c.seq8 addObject:@"string3"];
        [(ICEMutableStringSeq*)c.seq8 addObject:@"string4"];

        TestStreamMyEnum enumS[] = { TestStreamenum3, TestStreamenum2, TestStreamenum1 };
        c.seq9 = [NSMutableData dataWithBytes:enumS length:sizeof(enumS)];
            
        c.d = [NSDictionary dictionaryWithObject:[TestStreamMyClass myClass] forKey:@"hi"];

        ex.c = c;

        [out writeException:ex];
        data = [out finished];

        in = [ICEUtil createInputStream:communicator data:data];
        @try
        {
            [in throwException];
            test(NO);
        }
        @catch(TestStreamMyException* ex1)
        {
            test(ex1.c);
            test(ex1.c.c == ex1.c);
            test(ex1.c.o == ex1.c);
            test(ex1.c.s.e == TestStreamenum2);
            test([ex1.c.seq1 isEqual:c.seq1]);
            test([ex1.c.seq2 isEqual:c.seq2]);
            test([ex1.c.seq3 isEqual:c.seq3]);
            test([ex1.c.seq4 isEqual:c.seq4]);
            test([ex1.c.seq5 isEqual:c.seq5]);
            test([ex1.c.seq6 isEqual:c.seq6]);
            test([ex1.c.seq7 isEqual:c.seq7]);
            test([ex1.c.seq8 isEqual:c.seq8]);
            test([ex1.c.seq9 isEqual:c.seq9]);
            test([ex1.c.d objectForKey:@"hi"] != nil);

            ex1.c.c = nil;
            ex1.c.o = nil;
            c.c = nil;
            c.o = nil;
        }
    }

    {
        TestStreamMutableByteBoolD* dict = [TestStreamMutableByteBoolD dictionary];
        [dict setObject:@YES forKey:@(0x04)];
        [dict setObject:@NO forKey:@(0x01)];
        out = [ICEUtil createOutputStream:communicator];
        [TestStreamByteBoolDHelper write:dict stream:out];
        data = [out finished];
        in = [ICEUtil createInputStream:communicator data:data];
        TestStreamByteBoolD* dict2 = [TestStreamByteBoolDHelper read:in];
        test([dict2 isEqual:dict]);
    }

    {
        TestStreamMutableShortIntD* dict = [TestStreamMutableShortIntD dictionary];
        [dict setObject:@9 forKey:@1];
        [dict setObject:@8 forKey:@4];
        out = [ICEUtil createOutputStream:communicator];
        [TestStreamShortIntDHelper write:dict stream:out];
        data = [out finished];
        in = [ICEUtil createInputStream:communicator data:data];
        TestStreamShortIntD* dict2 = [TestStreamShortIntDHelper read:in];
        test([dict2 isEqual:dict]);
    }

    {
        TestStreamMutableLongFloatD* dict = [TestStreamMutableLongFloatD dictionary];
        [dict setObject:@0.51f forKey:@123809828];
        [dict setObject:@0.56f forKey:@123809829];
        out = [ICEUtil createOutputStream:communicator];
        [TestStreamLongFloatDHelper write:dict stream:out];
        data = [out finished];
        in = [ICEUtil createInputStream:communicator data:data];
        TestStreamLongFloatD* dict2 = [TestStreamLongFloatDHelper read:in];
        test([dict2 isEqual:dict]);
    }

    {
        TestStreamMutableStringStringD* dict = [TestStreamMutableStringStringD dictionary];
        [dict setObject:@"value1" forKey:@"key1"];
        [dict setObject:@"value2" forKey:@"key2"];
        out = [ICEUtil createOutputStream:communicator];
        [TestStreamStringStringDHelper write:dict stream:out];
        data = [out finished];
        in = [ICEUtil createInputStream:communicator data:data];
        TestStreamStringStringD* dict2 = [TestStreamStringStringDHelper read:in];
        test([dict2 isEqual:dict]);
    }

    {
        TestStreamMutableStringMyClassD* dict = [TestStreamMutableStringMyClassD dictionary];
        TestStreamMyClass* c = [TestStreamMyClass myClass];
        c.s = [TestStreamSmallStruct smallStruct];
        c.s.e = TestStreamenum2;
        [dict setObject:c forKey:@"key1"];
        c = [TestStreamMyClass myClass];
        c.s = [TestStreamSmallStruct smallStruct];
        c.s.e = TestStreamenum3;
        [dict setObject:c forKey:@"key2"];
        out = [ICEUtil createOutputStream:communicator];
        [TestStreamStringMyClassDHelper write:dict stream:out];
        [out writePendingObjects];
        data = [out finished];
        in = [ICEUtil createInputStream:communicator data:data];
        TestStreamStringMyClassD* dict2 = [TestStreamStringMyClassDHelper read:in];
        [in readPendingObjects];
        test([dict2 count] == [dict count]);
        test([dict2 objectForKey:@"key1"] != nil && 
             ((TestStreamMyClass*)[dict2 objectForKey:@"key1"]).s.e == TestStreamenum2);
        test([dict2 objectForKey:@"key2"] != nil && 
             ((TestStreamMyClass*)[dict2 objectForKey:@"key2"]).s.e == TestStreamenum3);
        
    }

    {
        out = [ICEUtil createOutputStream:communicator];
        [TestStreamSubNestedEnumHelper write:@(TestStreamSubnestedEnum3) stream:out];
        data = [out finished];
        in = [ICEUtil createInputStream:communicator data:data];
        id e = [TestStreamSubNestedEnumHelper read:in];
        test([e isEqual:@(TestStreamSubnestedEnum3)]);
    }

    {
        out = [ICEUtil createOutputStream:communicator];
        TestStreamSubNestedStruct* s = [TestStreamSubNestedStruct nestedStruct];
        s.bo = YES;
        s.by = 1;
        s.sh = 2;
        s.i = 3;
        s.l = 4;
        s.f = 5.0;
        s.d = 6.0;
        s.str = @"7";
        s.e = TestStreamSubnestedEnum2;
        [TestStreamSubNestedStructHelper write:s stream:out];
        data = [out finished];
        in = [ICEUtil createInputStream:communicator data:data];
        TestStreamSubNestedStruct* s2 = [TestStreamSubNestedStructHelper read:in];
        test([s2 isEqual:s]);
    }

    {
        out = [ICEUtil createOutputStream:communicator];
        TestStreamSubNestedClassStruct* s = [TestStreamSubNestedClassStruct nestedClassStruct];
        s.i = 10;
        [TestStreamSubNestedClassStructHelper write:s stream:out];
        data = [out finished];
        in = [ICEUtil createInputStream:communicator data:data];
        TestStreamSubNestedClassStruct* s2 = [TestStreamSubNestedClassStructHelper read:in];
        test(s2.i == s.i);
    }

    {
        out = [ICEUtil createOutputStream:communicator];
        TestStreamSubNestedException* ex = [TestStreamSubNestedException nestedException];
        ex.str = @"str";

        [out writeException:ex];
        data = [out finished];

        in = [ICEUtil createInputStream:communicator data:data];
        @try
        {
            [in throwException];
            test(NO);
        }
        @catch(TestStreamSubNestedException* ex1)
        {
            test([ex1.str isEqualToString:ex.str]);
        }
    }

    {
        out = [ICEUtil createOutputStream:communicator];
        [TestStream2Sub2NestedEnum2Helper write:@(TestStream2Sub2nestedEnum4) stream:out];
        data = [out finished];
        in = [ICEUtil createInputStream:communicator data:data];
        id e = [TestStream2Sub2NestedEnum2Helper read:in];
        test([e isEqual:@(TestStream2Sub2nestedEnum4)]);
    }

    {
        out = [ICEUtil createOutputStream:communicator];
        TestStream2Sub2NestedStruct2* s = [TestStream2Sub2NestedStruct2 nestedStruct2];
        s.bo = YES;
        s.by = 1;
        s.sh = 2;
        s.i = 3;
        s.l = 4;
        s.f = 5.0;
        s.d = 6.0;
        s.str = @"7";
        s.e = TestStream2Sub2nestedEnum5;
        [TestStream2Sub2NestedStruct2Helper write:s stream:out];
        data = [out finished];
        in = [ICEUtil createInputStream:communicator data:data];
        TestStream2Sub2NestedStruct2* s2 = [TestStream2Sub2NestedStruct2Helper read:in];
        test([s2 isEqual:s]);
    }

    {
        out = [ICEUtil createOutputStream:communicator];
        TestStream2Sub2NestedClassStruct2* s = [TestStream2Sub2NestedClassStruct2 nestedClassStruct2];
        s.i = 10;
        [TestStream2Sub2NestedClassStruct2Helper write:s stream:out];
        data = [out finished];
        in = [ICEUtil createInputStream:communicator data:data];
        TestStream2Sub2NestedClassStruct2* s2 = [TestStream2Sub2NestedClassStruct2Helper read:in];
        test(s2.i == s.i);
    }

    {
        out = [ICEUtil createOutputStream:communicator];
        TestStream2Sub2NestedException2* ex = [TestStream2Sub2NestedException2 nestedException2];
        ex.str = @"str";

        [out writeException:ex];
        data = [out finished];

        in = [ICEUtil createInputStream:communicator data:data];
        @try
        {
            [in throwException];
            test(NO);
        }
        @catch(TestStream2Sub2NestedException2* ex1)
        {
            test([ex1.str isEqualToString:ex.str]);
        }
    }

    tprintf("ok\n");
    return 0;
}

#if TARGET_OS_IPHONE
#  define main streamClient
#endif

int
main(int argc, char* argv[])
{
    int status;
    @autoreleasepool
    {
        id<ICECommunicator> communicator = nil;
        @try
        {

            ICEInitializationData* initData = [ICEInitializationData initializationData];
            initData.properties = defaultClientProperties(&argc, argv);
#if TARGET_OS_IPHONE
            initData.prefixTable__ = [NSDictionary dictionaryWithObjectsAndKeys:
                                      @"TestStream", @"::Test", 
                                      @"TestStreamSub", @"::Test::Sub", 
                                      @"TestStream2", @"::Test2", 
                                      @"TestStream2Sub2", @"::Test2::Sub2", 
                                      nil];
#endif
            communicator = [ICEUtil createCommunicator:&argc argv:argv initData:initData];
            status = run(communicator);
        }
        @catch(ICEException* ex)
        {
            tprintf("%@\n", ex);
            status = EXIT_FAILURE;
        }
        @catch(TestFailedException* ex)
        {
            status = EXIT_FAILURE;
        }

        if(communicator)
        {
            @try
            {
                [communicator destroy];
            }
            @catch(ICEException* ex)
            {
            tprintf("%@\n", ex);
                status = EXIT_FAILURE;
            }
        }
    }
    return status;
}