1<?php
2//
3// Copyright (c) ZeroC, Inc. All rights reserved.
4//
5
6require_once('ClientPrivate.php');
7
8function allTests($helper)
9{
10    global $NS;
11    global $Ice_Encoding_1_0;
12
13    $enum = $NS ? constant("Test\\MyEnum::MyEnumMember") : constant("Test_MyEnum::MyEnumMember");
14    $none = $NS ? constant("Ice\\None") : constant("Ice_Unset");
15
16    echo "testing stringToProxy... ";
17    flush();
18    $ref = sprintf("initial:%s", $helper->getTestEndpoint());
19    $communicator = $helper->communicator();
20    $base = $communicator->stringToProxy($ref);
21    echo "ok\n";
22
23    echo "testing checked cast... ";
24    flush();
25    $initial = $base->ice_checkedCast("::Test::Initial");
26    echo "ok\n";
27
28    echo "testing optional data members... ";
29    flush();
30
31    $oocls = $NS ? "Test\\OneOptional" : "Test_OneOptional";
32    $oo1 = new $oocls;
33    test($oo1->a == $none);
34    $oo1->a = 15;
35
36    $oo2 = new $oocls(16);
37    test($oo2->a == 16);
38
39    $mocls = $NS ? "Test\\MultiOptional" : "Test_MultiOptional";
40    $mo1 = new $mocls;
41    test($mo1->a == $none);
42    test($mo1->b == $none);
43    test($mo1->c == $none);
44    test($mo1->d == $none);
45    test($mo1->e == $none);
46    test($mo1->f == $none);
47    test($mo1->g == $none);
48    test($mo1->h == $none);
49    test($mo1->i == $none);
50    test($mo1->j == $none);
51    test($mo1->k == $none);
52    test($mo1->bs == $none);
53    test($mo1->ss == $none);
54    test($mo1->iid == $none);
55    test($mo1->sid == $none);
56    test($mo1->fs == $none);
57    test($mo1->vs == $none);
58
59    test($mo1->shs == $none);
60    test($mo1->es == $none);
61    test($mo1->fss == $none);
62    test($mo1->vss == $none);
63    test($mo1->oos == $none);
64    test($mo1->oops == $none);
65
66    test($mo1->ied == $none);
67    test($mo1->ifsd == $none);
68    test($mo1->ivsd == $none);
69    test($mo1->iood == $none);
70    test($mo1->ioopd == $none);
71
72    test($mo1->bos == $none);
73
74    $sscls = $NS ? "Test\\SmallStruct" : "Test_SmallStruct";
75    $ss = new $sscls();
76    $fscls = $NS ? "Test\\FixedStruct" : "Test_FixedStruct";
77    $fs = new $fscls(78);
78    $vscls = $NS ? "Test\\VarStruct" : "Test_VarStruct";
79    $vs = new $vscls("hello");
80    $prx = $communicator->stringToProxy("test");
81    $oo15 = new $oocls(15);
82    $mocls = $NS ? "Test\\MultiOptional" : "Test_MultiOptional";
83    $mo1 = new $mocls(15, true, 19, 78, 99, 5.5, 1.0, 'test', $enum,
84                      $prx, null, array(5), array('test', 'test2'), array(4=>3), array('test'=>10),
85                      $fs, $vs, array(1), array($enum, $enum), array($fs), array($vs), array($oo1),
86                      array($prx), array(4=>$enum), array(4=>$fs), array(5=>$vs),
87                      array(5=>$oo15), array(5=>$prx), array(false, true, false));
88
89    test($mo1->a == 15);
90    test($mo1->b == true);
91    test($mo1->c == 19);
92    test($mo1->d == 78);
93    test($mo1->e == 99);
94    test($mo1->f == 5.5);
95    test($mo1->g == 1.0);
96    test($mo1->h == "test");
97    test($mo1->i == $enum);
98    test($mo1->j == $prx);
99    test($mo1->k == null);
100    test($mo1->bs == array(5));
101    test($mo1->ss == array("test", "test2"));
102    test($mo1->iid[4] == 3);
103    test($mo1->sid["test"] == 10);
104    test($mo1->fs == $fs);
105    test($mo1->vs == $vs);
106
107    test($mo1->shs[0] == 1);
108    test($mo1->es[0] == $enum && $mo1->es[1] == $enum);
109    test($mo1->fss[0] == $fs);
110    test($mo1->vss[0] == $vs);
111    test($mo1->oos[0] == $oo1);
112    test($mo1->oops[0] == $prx);
113
114    test($mo1->ied[4] == $enum);
115    test($mo1->ifsd[4] == $fs);
116    test($mo1->ivsd[5] == $vs);
117    test($mo1->iood[5]->a == 15);
118    test($mo1->ioopd[5] == $prx);
119
120    test($mo1->bos == array(false, true, false));
121
122    //
123    // Test generated struct and classes compare with $none
124    //
125    test($ss != $none);
126    test($fs != $none);
127    test($vs != $none);
128    test($mo1 != $none);
129
130    echo "ok\n";
131
132    echo "testing marshaling... ";
133    flush();
134
135    $oo4 = $initial->pingPong(new $oocls);
136    test($oo4->a == $none);
137
138    $oo5 = $initial->pingPong($oo1);
139    test($oo1->a == $oo5->a);
140
141    $mo4 = $initial->pingPong(new $mocls);
142    test($mo4->a == $none);
143    test($mo4->b == $none);
144    test($mo4->c == $none);
145    test($mo4->d == $none);
146    test($mo4->e == $none);
147    test($mo4->f == $none);
148    test($mo4->g == $none);
149    test($mo4->h == $none);
150    test($mo4->i == $none);
151    test($mo4->j == $none);
152    test($mo4->k == $none);
153    test($mo4->bs == $none);
154    test($mo4->ss == $none);
155    test($mo4->iid == $none);
156    test($mo4->sid == $none);
157    test($mo4->fs == $none);
158    test($mo4->vs == $none);
159
160    test($mo4->shs == $none);
161    test($mo4->es == $none);
162    test($mo4->fss == $none);
163    test($mo4->vss == $none);
164    test($mo4->oos == $none);
165    test($mo4->oops == $none);
166
167    test($mo4->ied == $none);
168    test($mo4->ifsd == $none);
169    test($mo4->ivsd == $none);
170    test($mo4->iood == $none);
171    test($mo4->ioopd == $none);
172
173    test($mo4->bos == $none);
174
175    $mo5 = $initial->pingPong($mo1);
176    test($mo5->a == $mo1->a);
177    test($mo5->b == $mo1->b);
178    test($mo5->c == $mo1->c);
179    test($mo5->d == $mo1->d);
180    test($mo5->e == $mo1->e);
181    test($mo5->f == $mo1->f);
182    test($mo5->g == $mo1->g);
183    test($mo5->h == $mo1->h);
184    test($mo5->i == $mo1->i);
185    test($mo5->j == $mo1->j);
186    test($mo5->k == null);
187    test($mo5->bs[0] == 5);
188    test($mo5->ss == $mo1->ss);
189    test($mo5->iid[4] == 3);
190    test($mo5->sid["test"] == 10);
191    test($mo5->fs == $mo1->fs);
192    test($mo5->vs == $mo1->vs);
193    test($mo5->shs == $mo1->shs);
194    test($mo5->es[0] == $enum && $mo1->es[1] == $enum);
195    test($mo5->fss[0] == $fs);
196    test($mo5->vss[0] == $vs);
197    test($mo5->oos[0]->a == 15);
198    test($mo5->oops[0] == $prx);
199
200    test($mo5->ied[4] == $enum);
201    test($mo5->ifsd[4] == $fs);
202    test($mo5->ivsd[5] == $vs);
203    test($mo5->iood[5]->a == 15);
204    test($mo5->ioopd[5] == $prx);
205
206    test($mo5->bos == $mo1->bos);
207
208    // Clear the first half of the optional members
209    $mo6 = new $mocls;
210    $mo6->b = $mo5->b;
211    $mo6->d = $mo5->d;
212    $mo6->f = $mo5->f;
213    $mo6->h = $mo5->h;
214    $mo6->j = $mo5->j;
215    $mo6->bs = $mo5->bs;
216    $mo6->iid = $mo5->iid;
217    $mo6->fs = $mo5->fs;
218    $mo6->shs = $mo5->shs;
219    $mo6->fss = $mo5->fss;
220    $mo6->oos = $mo5->oos;
221    $mo6->ifsd = $mo5->ifsd;
222    $mo6->iood = $mo5->iood;
223    $mo6->bos = $mo5->bos;
224
225    $mo7 = $initial->pingPong($mo6);
226    test($mo7->a == $none);
227    test($mo7->b == $mo1->b);
228    test($mo7->c == $none);
229    test($mo7->d == $mo1->d);
230    test($mo7->e == $none);
231    test($mo7->f == $mo1->f);
232    test($mo7->g == $none);
233    test($mo7->h == $mo1->h);
234    test($mo7->i == $none);
235    test($mo7->j == $mo1->j);
236    test($mo7->k == $none);
237    test($mo7->bs[0] == 5);
238    test($mo7->ss == $none);
239    test($mo7->iid[4] == 3);
240    test($mo7->sid == $none);
241    test($mo7->fs == $mo1->fs);
242    test($mo7->vs == $none);
243
244    test($mo7->shs == $mo1->shs);
245    test($mo7->es == $none);
246    test($mo7->fss[0] == $fs);
247    test($mo7->vss == $none);
248    test($mo7->oos[0]->a == 15);
249    test($mo7->oops == $none);
250
251    test($mo7->ied == $none);
252    test($mo7->ifsd[4] == $fs);
253    test($mo7->ivsd == $none);
254    test($mo7->iood[5]->a == 15);
255    test($mo7->ioopd == $none);
256
257    test($mo7->bos == array(false, true, false));
258
259    // Clear the second half of the optional members
260    $mo8 = new $mocls;
261    $mo8->a = $mo5->a;
262    $mo8->c = $mo5->c;
263    $mo8->e = $mo5->e;
264    $mo8->g = $mo5->g;
265    $mo8->i = $mo5->i;
266    $mo8->k = $mo8;
267    $mo8->ss = $mo5->ss;
268    $mo8->sid = $mo5->sid;
269    $mo8->vs = $mo5->vs;
270
271    $mo8->es = $mo5->es;
272    $mo8->vss = $mo5->vss;
273    $mo8->oops = $mo5->oops;
274
275    $mo8->ied = $mo5->ied;
276    $mo8->ivsd = $mo5->ivsd;
277    $mo8->ioopd = $mo5->ioopd;
278
279    $mo9 = $initial->pingPong($mo8);
280    test($mo9->a == $mo1->a);
281    test($mo9->b == $none);
282    test($mo9->c == $mo1->c);
283    test($mo9->d == $none);
284    test($mo9->e == $mo1->e);
285    test($mo9->f == $none);
286    test($mo9->g == $mo1->g);
287    test($mo9->h == $none);
288    test($mo9->i == $mo1->i);
289    test($mo9->j == $none);
290    test($mo9->k == $mo9);
291    test($mo9->bs == $none);
292    test($mo9->ss == $mo1->ss);
293    test($mo9->iid == $none);
294    test($mo9->sid["test"] == 10);
295    test($mo9->fs == $none);
296    test($mo9->vs == $mo1->vs);
297
298    test($mo9->shs == $none);
299    test($mo9->es[0] == $enum && $mo1->es[1] == $enum);
300    test($mo9->fss == $none);
301    test($mo9->vss[0] == $vs);
302    test($mo9->oos == $none);
303    test($mo9->oops[0] == $prx);
304
305    test($mo9->ied[4] == $enum);
306    test($mo9->ifsd == $none);
307    test($mo9->ivsd[5] == $vs);
308    test($mo9->iood == $none);
309    test($mo9->ioopd[5] == $prx);
310
311    test($mo9->bos == $none);
312
313    //
314    // Use the 1.0 encoding with operations whose only class parameters are optional.
315    //
316    $oo = new $oocls(53);
317    $initial->sendOptionalClass(true, $oo);
318    $initial->ice_encodingVersion($Ice_Encoding_1_0)->sendOptionalClass(true, $oo);
319
320    $initial->returnOptionalClass(true, $oo);
321    test($oo != $none);
322    $initial->ice_encodingVersion($Ice_Encoding_1_0)->returnOptionalClass(true, $oo);
323    test($oo == $none);
324
325    $gcls = $NS ? "Test\\G" : "Test_G";
326    $g1cls = $NS ? "Test\\G1" : "Test_G1";
327    $g2cls = $NS ? "Test\\G2" : "Test_G2";
328
329    $g = new $gcls;
330    $g->gg1Opt = new $g1cls("gg1Opt");
331    $g->gg2 = new $g2cls(10);
332    $g->gg2Opt = new $g2cls(20);
333    $g->gg1 = new $g1cls("gg1");
334    $r = $initial->opG($g);
335    test($r->gg1Opt->a == "gg1Opt");
336    test($r->gg2->a == 10);
337    test($r->gg2Opt->a == 20);
338    test($r->gg1->a == "gg1");
339
340    $initial2 = $NS ? eval("return Test\\Initial2PrxHelper::uncheckedCast(\$base);") :
341                      eval("return Test_Initial2PrxHelper::uncheckedCast(\$base);");
342    $initial2->opVoid(15, "test");
343
344    echo "ok\n";
345
346    echo "testing marshaling of large containers with fixed size elements... ";
347    flush();
348
349    $mc = new $mocls;
350    $mc->bs = array();
351    for($i = 0; $i < 1000; $i++)
352    {
353        $mc->bs[$i] = 0;
354    }
355    $mc->shs = array();
356    for($i = 0; $i < 300; $i++)
357    {
358        $mc->shs[$i] = 0;
359    }
360    $mc->fss = array();
361    for($i = 0; $i < 300; $i++)
362    {
363        $mc->fss[$i] = new $fscls;
364    }
365    $mc->ifsd = array();
366    for($i = 0; $i < 300; $i++)
367    {
368        $mc->ifsd[$i] = new $fscls;
369    }
370
371    $mc = $initial->pingPong($mc);
372    test(count($mc->bs) == 1000);
373    test(count($mc->shs) == 300);
374    test(count($mc->fss) == 300);
375    test(count($mc->ifsd) == 300);
376
377    echo "ok\n";
378
379    echo "testing tag marshaling... ";
380    flush();
381
382    $bcls = $NS ? "Test\\B" : "Test_B";
383    $b = new $bcls;
384    $b2 = $initial->pingPong($b);
385    test($b2->ma == $none);
386    test($b2->mb == $none);
387    test($b2->mc == $none);
388
389    $b->ma = 10;
390    $b->mb = 11;
391    $b->mc = 12;
392    $b->md = 13;
393
394    $b2 = $initial->pingPong($b);
395    test($b2->ma == 10);
396    test($b2->mb == 11);
397    test($b2->mc == 12);
398    test($b2->md == 13);
399
400    echo "ok\n";
401
402    echo "testing marshalling of objects with optional objects...";
403    flush();
404
405    $fcls = $NS ? "Test\\F" : "Test_F";
406    $f = new $fcls;
407
408    $acls = $NS ? "Test\\A" : "Test_A";
409    $f->af = new $acls;
410    $f->ae = $f->af;
411
412    $rf = $initial->pingPong($f);
413    test($rf->ae == $rf->af);
414
415    echo "ok\n";
416
417    echo "testing optional with default values... ";
418    flush();
419
420    $wdcls = $NS ? "Test\\WD" : "Test_WD";
421    $wd = $initial->pingPong(new $wdcls);
422    test($wd->a == 5);
423    test($wd->s == "test");
424    $wd->a = $none;
425    $wd->s = $none;
426    $wd = $initial->pingPong($wd);
427    test($wd->a == $none);
428    test($wd->s == $none);
429
430    echo "ok\n";
431
432    if($communicator->getProperties()->getPropertyAsInt("Ice.Default.SlicedFormat") > 0)
433    {
434        echo "testing marshaling with unknown class slices... ";
435        flush();
436
437        $ccls = $NS ? "Test\\C" : "Test_C";
438        $c = new $ccls;
439        $c->ss = "test";
440        $c->ms = "testms";
441        $c = $initial->pingPong($c);
442        test($c->ma == $none);
443        test($c->mb == $none);
444        test($c->mc == $none);
445        test($c->md == $none);
446        test($c->ss == "test");
447        test($c->ms == "testms");
448
449        echo "ok\n";
450
451        echo "testing optionals with unknown classes... ";
452        flush();
453
454        $initial2 = $NS ? eval("return Test\\Initial2PrxHelper::uncheckedCast(\$base);") :
455                          eval("return Test_Initial2PrxHelper::uncheckedCast(\$base);");
456        $acls = $NS ? "Test\\A" : "Test_A";
457        $dcls = $NS ? "Test\\D" : "Test_D";
458        $d = new $dcls;
459        $d->ds = "test";
460        $d->seq = array("test1", "test2", "test3", "test4");
461        $d->ao = new $acls(18);
462        $d->requiredB = 14;
463        $d->requiredA = 14;
464        $initial2->opClassAndUnknownOptional(new $acls, $d);
465
466        echo "ok\n";
467    }
468
469    echo "testing optional parameters... ";
470    flush();
471
472    $p2 = 0;
473    $p3 = $initial->opByte($none, $p2);
474    test($p2 == $none && $p3 == $none);
475    $p3 = $initial->opByte(56, $p2);
476    test($p2 == 56 && $p3 == 56);
477
478    $p3 = $initial->opBool($none, $p2);
479    test($p2 == $none && $p3 == $none);
480    $p3 = $initial->opBool(true, $p2);
481    test($p2 == true && $p3 == true);
482
483    $p3 = $initial->opShort($none, $p2);
484    test($p2 == $none && $p3 == $none);
485    $p3 = $initial->opShort(56, $p2);
486    test($p2 == 56 && $p3 == 56);
487
488    $p3 = $initial->opInt($none, $p2);
489    test($p2 == $none && $p3 == $none);
490    $p3 = $initial->opInt(56, $p2);
491    test($p2 == 56 && $p3 == 56);
492
493    $p3 = $initial->opLong($none, $p2);
494    test($p2 == $none && $p3 == $none);
495    $p3 = $initial->opLong(56, $p2);
496    test($p2 == 56 && $p3 == 56);
497
498    $p3 = $initial->opFloat($none, $p2);
499    test($p2 == $none && $p3 == $none);
500    $p3 = $initial->opFloat(1.0, $p2);
501    test($p2 == 1.0 && $p3 == 1.0);
502
503    $p3 = $initial->opDouble($none, $p2);
504    test($p2 == $none && $p3 == $none);
505    $p3 = $initial->opDouble(1.0, $p2);
506    test($p2 == 1.0 && $p3 == 1.0);
507
508    $p3 = $initial->opString($none, $p2);
509    test($p2 == $none && $p3 == $none);
510    $p3 = $initial->opString("test", $p2);
511    test($p2 == "test" && $p3 == "test");
512
513    $p3 = $initial->opMyEnum($none, $p2);
514    test($p2 == $none && $p3 == $none);
515    $p3 = $initial->opMyEnum($enum, $p2);
516    test($p2 == $enum && $p3 == $enum);
517
518    $p3 = $initial->opSmallStruct($none, $p2);
519    test($p2 == $none && $p3 == $none);
520    $p1 = new $sscls(56);
521    $p3 = $initial->opSmallStruct($p1, $p2);
522    test($p2 == $p1 && $p3 == $p1);
523    $p3 = $initial->opSmallStruct(null, $p2); // Testing null struct
524    test($p2->m == 0 && $p3->m == 0);
525
526    $p3 = $initial->opFixedStruct($none, $p2);
527    test($p2 == $none && $p3 == $none);
528    $p1 = new $fscls(56);
529    $p3 = $initial->opFixedStruct($p1, $p2);
530    test($p2 == $p1 && $p3 == $p1);
531
532    $p3 = $initial->opVarStruct($none, $p2);
533    test($p2 == $none && $p3 == $none);
534    $p1 = new $vscls("test");
535    $p3 = $initial->opVarStruct($p1, $p2);
536    test($p2 == $p1 && $p3 == $p1);
537
538    $p3 = $initial->opOneOptional($none, $p2);
539    test($p2 == $none && $p3 == $none);
540    if($initial->supportsNullOptional())
541    {
542        $p3 = $initial->opOneOptional(null, $p2);
543        test($p2 == null && $p3 == null);
544    }
545    $p1 = new $oocls(58);
546    $p3 = $initial->opOneOptional($p1, $p2);
547    test($p2->a == $p1->a && $p3->a == $p1->a);
548
549    $p3 = $initial->opOneOptionalProxy($none, $p2);
550    test($p2 == $none && $p3 == $none);
551    $p3 = $initial->opOneOptionalProxy($prx, $p2);
552    test($p2 == $prx && $p3 == $prx);
553
554    $p3 = $initial->opByteSeq($none, $p2);
555    test($p2 == $none && $p3 == $none);
556    $p1 = array();
557    for($i = 0; $i < 100; $i++)
558    {
559        $p1[$i] = 56;
560    }
561    $p3 = $initial->opByteSeq($p1, $p2);
562    test($p2 == $p1 && $p3 == $p1);
563
564    $p3 = $initial->opBoolSeq($none, $p2);
565    test($p2 == $none && $p3 == $none);
566    $p1 = array();
567    for($i = 0; $i < 100; $i++)
568    {
569        $p1[$i] = true;
570    }
571    $p3 = $initial->opBoolSeq($p1, $p2);
572    test($p2 == $p1 && $p3 == $p1);
573
574    $p3 = $initial->opShortSeq($none, $p2);
575    test($p2 == $none && $p3 == $none);
576    $p1 = array();
577    for($i = 0; $i < 100; $i++)
578    {
579        $p1[$i] = 56;
580    }
581    $p3 = $initial->opShortSeq($p1, $p2);
582    test($p2 == $p1 && $p3 == $p1);
583
584    $p3 = $initial->opIntSeq($none, $p2);
585    test($p2 == $none && $p3 == $none);
586    $p1 = array();
587    for($i = 0; $i < 100; $i++)
588    {
589        $p1[$i] = 56;
590    }
591    $p3 = $initial->opIntSeq($p1, $p2);
592    test($p2 == $p1 && $p3 == $p1);
593
594    $p3 = $initial->opLongSeq($none, $p2);
595    test($p2 == $none && $p3 == $none);
596    $p1 = array();
597    for($i = 0; $i < 100; $i++)
598    {
599        $p1[$i] = 56;
600    }
601    $p3 = $initial->opLongSeq($p1, $p2);
602    test($p2 == $p1 && $p3 == $p1);
603
604    $p3 = $initial->opFloatSeq($none, $p2);
605    test($p2 == $none && $p3 == $none);
606    $p1 = array();
607    for($i = 0; $i < 100; $i++)
608    {
609        $p1[$i] = 1.0;
610    }
611    $p3 = $initial->opFloatSeq($p1, $p2);
612    test($p2 == $p1 && $p3 == $p1);
613
614    $p3 = $initial->opDoubleSeq($none, $p2);
615    test($p2 == $none && $p3 == $none);
616    $p1 = array();
617    for($i = 0; $i < 100; $i++)
618    {
619        $p1[$i] = 1.0;
620    }
621    $p3 = $initial->opDoubleSeq($p1, $p2);
622    test($p2 == $p1 && $p3 == $p1);
623
624    $p3 = $initial->opStringSeq($none, $p2);
625    test($p2 == $none && $p3 == $none);
626    $p1 = array();
627    for($i = 0; $i < 100; $i++)
628    {
629        $p1[$i] = "test1";
630    }
631    $p3 = $initial->opStringSeq($p1, $p2);
632    test($p2 == $p1 && $p3 == $p1);
633
634    $p3 = $initial->opSmallStructSeq($none, $p2);
635    test($p2 == $none && $p3 == $none);
636    $p1 = array();
637    for($i = 0; $i < 10; $i++)
638    {
639        $p1[$i] = new $sscls(1);
640    }
641    $p3 = $initial->opSmallStructSeq($p1, $p2);
642    test($p2 == $p1 && $p3 == $p1);
643
644    $p3 = $initial->opFixedStructSeq($none, $p2);
645    test($p2 == $none && $p3 == $none);
646    $p1 = array();
647    for($i = 0; $i < 10; $i++)
648    {
649        $p1[$i] = new $fscls(1);
650    }
651    $p3 = $initial->opFixedStructSeq($p1, $p2);
652    test($p2 == $p1 && $p3 == $p1);
653
654    $p3 = $initial->opVarStructSeq($none, $p2);
655    test($p2 == $none && $p3 == $none);
656    $p1 = array();
657    for($i = 0; $i < 10; $i++)
658    {
659        $p1[$i] = new $vscls("test");
660    }
661    $p3 = $initial->opVarStructSeq($p1, $p2);
662    test($p2 == $p1 && $p3 == $p1);
663
664    $p3 = $initial->opIntIntDict($none, $p2);
665    test($p2 == $none && $p3 == $none);
666    $p1 = array(1=>2, 2=>3);
667    $p3 = $initial->opIntIntDict($p1, $p2);
668    test($p2 == $p1 && $p3 == $p1);
669
670    $p3 = $initial->opStringIntDict($none, $p2);
671    test($p2 == $none && $p3 == $none);
672    $p1 = array("1"=>2, "2"=>3);
673    $p3 = $initial->opStringIntDict($p1, $p2);
674    test($p2 == $p1 && $p3 == $p1);
675
676    $p3 = $initial->opIntOneOptionalDict($none, $p2);
677    test($p2 == $none && $p3 == $none);
678    $p1 = array(1=>new $oocls(58), 2=>new $oocls(59));
679    $p3 = $initial->opIntOneOptionalDict($p1, $p2);
680    test($p2[1]->a == 58 && $p3[1]->a == 58);
681
682    echo "ok\n";
683
684    echo "testing exception optionals... ";
685    flush();
686
687    try
688    {
689        $initial->opOptionalException($none, $none, $none);
690    }
691    catch(Exception $ex)
692    {
693        $excls = $NS ? "Test\\OptionalException" : "Test_OptionalException";
694        if(!($ex instanceof $excls))
695        {
696            throw $ex;
697        }
698        test($ex->a == $none);
699        test($ex->b == $none);
700        test($ex->o == $none);
701    }
702
703    try
704    {
705        $initial->opOptionalException(30, "test", new $oocls(53));
706    }
707    catch(Exception $ex)
708    {
709        test($ex->a == 30);
710        test($ex->b == "test");
711        test($ex->o->a == 53);
712    }
713
714    try
715    {
716        //
717        // Use the 1.0 encoding with an exception whose only class members are optional.
718        //
719        $initial->ice_encodingVersion($Ice_Encoding_1_0)->opOptionalException(30, "test", new $oocls(53));
720    }
721    catch(Exception $ex)
722    {
723        test($ex->a == $none);
724        test($ex->b == $none);
725        test($ex->o == $none);
726    }
727
728    try
729    {
730        $initial->opDerivedException($none, $none, $none);
731    }
732    catch(Exception $ex)
733    {
734        test($ex->a == $none);
735        test($ex->b == $none);
736        test($ex->o == $none);
737        test($ex->ss == $none);
738        test($ex->o2 == $none);
739    }
740
741    try
742    {
743        $initial->opDerivedException(30, "test", new $oocls(53));
744    }
745    catch(Exception $ex)
746    {
747        test($ex->a == 30);
748        test($ex->b == "test");
749        test($ex->o->a == 53);
750        test($ex->ss == "test");
751        test($ex->o2 == $ex->o);
752    }
753
754    try
755    {
756        $initial->opRequiredException($none, $none, $none);
757    }
758    catch(Exception $ex)
759    {
760        test($ex->a == $none);
761        test($ex->b == $none);
762        test($ex->o == $none);
763        test($ex->ss != $none);
764        test($ex->o2 != $none);
765    }
766
767    try
768    {
769        $initial->opRequiredException(30, "test", new $oocls(53));
770    }
771    catch(Exception $ex)
772    {
773        test($ex->a == 30);
774        test($ex->b == "test");
775        test($ex->o->a == 53);
776        test($ex->ss == "test");
777        test($ex->o2 == $ex->o);
778    }
779
780    echo "ok\n";
781
782    echo "testing optionals with marshaled results... ";
783    flush();
784
785    test($initial->opMStruct1() != $none);
786    test($initial->opMDict1() != $none);
787    test($initial->opMSeq1() != $none);
788    test($initial->opMG1() != $none);
789
790    $p3 = $initial->opMStruct2($none, $p2);
791    test($p2 == $none && $p3 == $none);
792
793    $sscls = $NS ? "Test\\SmallStruct" : "Test_SmallStruct";
794    $p1 = new $sscls(56);
795    $p3 = $initial->opMStruct2($p1, $p2);
796    test($p2 == $p1 && $p3 == $p1);
797
798    $p3 = $initial->opMSeq2($none, $p2);
799    test($p2 == $none && $p3 == $none);
800
801    $p1 = array("hello");
802    $p3 = $initial->opMSeq2($p1, $p2);
803    test($p2[0] == "hello" && $p3[0] == "hello");
804
805    $p3 = $initial->opMDict2($none, $p2);
806    test($p2 == $none && $p3 == $none);
807
808    $p1 = array("test" => 54);
809    $p3 = $initial->opMDict2($p1, $p2);
810    test($p2["test"] == 54 && $p3["test"] == 54);
811
812    $p3 = $initial->opMG2($none, $p2);
813    test($p2 == $none && $p3 == $none);
814
815    $p1 = new $gcls;
816    $p3 = $initial->opMG2($p1, $p2);
817    test($p2 != $none && $p3 != $none && $p3 == $p2);
818
819    echo "ok\n";
820
821    return $initial;
822}
823
824class Client extends TestHelper
825{
826    function run($args)
827    {
828        try
829        {
830            $communicator = $this->initialize($args);
831            $proxy = allTests($this);
832            $proxy->shutdown();
833            $communicator->destroy();
834        }
835        catch(Exception $ex)
836        {
837            $communicator->destroy();
838            throw $ex;
839       }
840    }
841}
842?>
843