diff options
author | Mark Spruiell <mes@zeroc.com> | 2012-10-12 15:31:48 -0700 |
---|---|---|
committer | Mark Spruiell <mes@zeroc.com> | 2012-10-12 15:31:48 -0700 |
commit | ed09446f6ab09a14abbbf3080bfa5986927a070d (patch) | |
tree | 4b3735e7b7b1c2ffe8056f7b9be7adbeb4d50f16 /php/test | |
parent | WinRT port updates (diff) | |
download | ice-ed09446f6ab09a14abbbf3080bfa5986927a070d.tar.bz2 ice-ed09446f6ab09a14abbbf3080bfa5986927a070d.tar.xz ice-ed09446f6ab09a14abbbf3080bfa5986927a070d.zip |
PHP optionals
Diffstat (limited to 'php/test')
-rw-r--r-- | php/test/Ice/Makefile | 3 | ||||
-rw-r--r-- | php/test/Ice/Makefile.mak | 3 | ||||
-rw-r--r-- | php/test/Ice/optional/.depend | 2 | ||||
-rw-r--r-- | php/test/Ice/optional/.depend.mak | 2 | ||||
-rw-r--r-- | php/test/Ice/optional/.gitignore | 2 | ||||
-rw-r--r-- | php/test/Ice/optional/Client.php | 736 | ||||
-rw-r--r-- | php/test/Ice/optional/ClientPrivate.ice | 37 | ||||
-rw-r--r-- | php/test/Ice/optional/Makefile | 27 | ||||
-rw-r--r-- | php/test/Ice/optional/Makefile.mak | 25 | ||||
-rw-r--r-- | php/test/Ice/optional/Test.ice | 246 | ||||
-rwxr-xr-x | php/test/Ice/optional/run.py | 26 | ||||
-rw-r--r-- | php/test/Ice/slicing/objects/Client.php | 13 | ||||
-rw-r--r-- | php/test/Ice/slicing/objects/Test.ice | 1 |
13 files changed, 1119 insertions, 4 deletions
diff --git a/php/test/Ice/Makefile b/php/test/Ice/Makefile index 8aa9b1b4cc1..03fa41079bf 100644 --- a/php/test/Ice/Makefile +++ b/php/test/Ice/Makefile @@ -11,7 +11,8 @@ top_srcdir = ../.. include $(top_srcdir)/config/Make.rules.php -SUBDIRS = binding checksum exceptions facets info inheritance objects operations proxy slicing defaultValue +SUBDIRS = binding checksum exceptions facets info inheritance objects operations proxy slicing defaultValue \ + optional $(EVERYTHING):: @for subdir in $(SUBDIRS); \ diff --git a/php/test/Ice/Makefile.mak b/php/test/Ice/Makefile.mak index 3a850306641..fdf514dc7b7 100644 --- a/php/test/Ice/Makefile.mak +++ b/php/test/Ice/Makefile.mak @@ -11,7 +11,8 @@ top_srcdir = ..\.. !include $(top_srcdir)\config\Make.rules.mak.php
-SUBDIRS = binding checksum exceptions facets info inheritance objects operations proxy slicing defaultValue
+SUBDIRS = binding checksum exceptions facets info inheritance objects operations proxy slicing defaultValue \
+ optional
$(EVERYTHING)::
@for %i in ( $(SUBDIRS) ) do \
diff --git a/php/test/Ice/optional/.depend b/php/test/Ice/optional/.depend new file mode 100644 index 00000000000..ef3f3f858ca --- /dev/null +++ b/php/test/Ice/optional/.depend @@ -0,0 +1,2 @@ +ClientPrivate.php: ClientPrivate.ice ./Test.ice $(SLICE2PHP) $(SLICEPARSERLIB) +Test.php: Test.ice $(SLICE2PHP) $(SLICEPARSERLIB) diff --git a/php/test/Ice/optional/.depend.mak b/php/test/Ice/optional/.depend.mak new file mode 100644 index 00000000000..c0d82ee1596 --- /dev/null +++ b/php/test/Ice/optional/.depend.mak @@ -0,0 +1,2 @@ +ClientPrivate.php: ClientPrivate.ice ./Test.ice "$(SLICE2PHP)" "$(SLICEPARSERLIB)" +Test.php: Test.ice "$(SLICE2PHP)" "$(SLICEPARSERLIB)" diff --git a/php/test/Ice/optional/.gitignore b/php/test/Ice/optional/.gitignore new file mode 100644 index 00000000000..a3053d5debf --- /dev/null +++ b/php/test/Ice/optional/.gitignore @@ -0,0 +1,2 @@ +ClientPrivate.php +Test.php diff --git a/php/test/Ice/optional/Client.php b/php/test/Ice/optional/Client.php new file mode 100644 index 00000000000..f3f8b469da4 --- /dev/null +++ b/php/test/Ice/optional/Client.php @@ -0,0 +1,736 @@ +<? +// ********************************************************************** +// +// Copyright (c) 2003-2012 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. +// +// ********************************************************************** + +error_reporting(E_ALL | E_STRICT); + +if(!extension_loaded("ice")) +{ + echo "\nerror: Ice extension is not loaded.\n\n"; + exit(1); +} + +$NS = function_exists("Ice\\initialize"); +require_once ($NS ? 'Ice_ns.php' : 'Ice.php'); +require_once 'ClientPrivate.php'; + +function test($b) +{ + if(!$b) + { + $bt = debug_backtrace(); + die("\ntest failed in ".$bt[0]["file"]." line ".$bt[0]["line"]."\n"); + } +} + +function allTests($communicator) +{ + global $NS; + + $enum = $NS ? constant("Test\\MyEnum::MyEnumMember") : constant("Test_MyEnum::MyEnumMember"); + + echo "testing stringToProxy... "; + flush(); + $ref = "initial:default -p 12010"; + $base = $communicator->stringToProxy($ref); + echo "ok\n"; + + echo "testing checked cast... "; + flush(); + $initial = $base->ice_checkedCast("::Test::Initial"); + echo "ok\n"; + + echo "testing optional data members... "; + flush(); + + $oocls = $NS ? "Test\\OneOptional" : "Test_OneOptional"; + $oo1 = new $oocls; + test($oo1->a == Ice_Unset); + $oo1->a = 15; + + $oo2 = new $oocls(16); + test($oo2->a == 16); + + $mocls = $NS ? "Test\\MultiOptional" : "Test_MultiOptional"; + $mo1 = new $mocls; + test($mo1->a == Ice_Unset); + test($mo1->b == Ice_Unset); + test($mo1->c == Ice_Unset); + test($mo1->d == Ice_Unset); + test($mo1->e == Ice_Unset); + test($mo1->f == Ice_Unset); + test($mo1->g == Ice_Unset); + test($mo1->h == Ice_Unset); + test($mo1->i == Ice_Unset); + test($mo1->j == Ice_Unset); + test($mo1->k == Ice_Unset); + test($mo1->bs == Ice_Unset); + test($mo1->ss == Ice_Unset); + test($mo1->iid == Ice_Unset); + test($mo1->sid == Ice_Unset); + test($mo1->fs == Ice_Unset); + test($mo1->vs == Ice_Unset); + + test($mo1->shs == Ice_Unset); + test($mo1->es == Ice_Unset); + test($mo1->fss == Ice_Unset); + test($mo1->vss == Ice_Unset); + test($mo1->oos == Ice_Unset); + test($mo1->oops == Ice_Unset); + + test($mo1->ied == Ice_Unset); + test($mo1->ifsd == Ice_Unset); + test($mo1->ivsd == Ice_Unset); + test($mo1->iood == Ice_Unset); + test($mo1->ioopd == Ice_Unset); + + test($mo1->bos == Ice_Unset); + + $fscls = $NS ? "Test\\FixedStruct" : "Test_FixedStruct"; + $fs = new $fscls(78); + $vscls = $NS ? "Test\\VarStruct" : "Test_VarStruct"; + $vs = new $vscls("hello"); + $prx = $communicator->stringToProxy("test"); + $moprx = $NS ? eval("return Test\\MultiOptionalPrxHelper::uncheckedCast(\$prx);") : + eval("return Test_MultiOptionalPrxHelper::uncheckedCast(\$prx);"); + $ooprx = $NS ? eval("return Test\\OneOptionalPrxHelper::uncheckedCast(\$prx);") : + eval("return Test_OneOptionalPrxHelper::uncheckedCast(\$prx);"); + $oo15 = new $oocls(15); + $mocls = $NS ? "Test\\MultiOptional" : "Test_MultiOptional"; + $mo1 = new $mocls(15, true, 19, 78, 99, 5.5, 1.0, 'test', $enum, + $moprx, null, array(5), array('test', 'test2'), array(4=>3), array('test'=>10), + $fs, $vs, array(1), array($enum, $enum), array($fs), array($vs), array($oo1), + array($ooprx), array(4=>$enum), array(4=>$fs), array(5=>$vs), + array(5=>$oo15), array(5=>$ooprx), array(false, true, false)); + + test($mo1->a == 15); + test($mo1->b == true); + test($mo1->c == 19); + test($mo1->d == 78); + test($mo1->e == 99); + test($mo1->f == 5.5); + test($mo1->g == 1.0); + test($mo1->h == "test"); + test($mo1->i == $enum); + test($mo1->j == $moprx); + test($mo1->k == null); + test($mo1->bs == array(5)); + test($mo1->ss == array("test", "test2")); + test($mo1->iid[4] == 3); + test($mo1->sid["test"] == 10); + test($mo1->fs == $fs); + test($mo1->vs == $vs); + + test($mo1->shs[0] == 1); + test($mo1->es[0] == $enum && $mo1->es[1] == $enum); + test($mo1->fss[0] == $fs); + test($mo1->vss[0] == $vs); + test($mo1->oos[0] == $oo1); + test($mo1->oops[0] == $ooprx); + + test($mo1->ied[4] == $enum); + test($mo1->ifsd[4] == $fs); + test($mo1->ivsd[5] == $vs); + test($mo1->iood[5]->a == 15); + test($mo1->ioopd[5] == $ooprx); + + test($mo1->bos == array(false, true, false)); + + echo "ok\n"; + + echo "testing marshaling... "; + flush(); + + $oo4 = $initial->pingPong(new $oocls); + test($oo4->a == Ice_Unset); + + $oo5 = $initial->pingPong($oo1); + test($oo1->a == $oo5->a); + + $mo4 = $initial->pingPong(new $mocls); + test($mo4->a == Ice_Unset); + test($mo4->b == Ice_Unset); + test($mo4->c == Ice_Unset); + test($mo4->d == Ice_Unset); + test($mo4->e == Ice_Unset); + test($mo4->f == Ice_Unset); + test($mo4->g == Ice_Unset); + test($mo4->h == Ice_Unset); + test($mo4->i == Ice_Unset); + test($mo4->j == Ice_Unset); + test($mo4->k == Ice_Unset); + test($mo4->bs == Ice_Unset); + test($mo4->ss == Ice_Unset); + test($mo4->iid == Ice_Unset); + test($mo4->sid == Ice_Unset); + test($mo4->fs == Ice_Unset); + test($mo4->vs == Ice_Unset); + + test($mo4->shs == Ice_Unset); + test($mo4->es == Ice_Unset); + test($mo4->fss == Ice_Unset); + test($mo4->vss == Ice_Unset); + test($mo4->oos == Ice_Unset); + test($mo4->oops == Ice_Unset); + + test($mo4->ied == Ice_Unset); + test($mo4->ifsd == Ice_Unset); + test($mo4->ivsd == Ice_Unset); + test($mo4->iood == Ice_Unset); + test($mo4->ioopd == Ice_Unset); + + test($mo4->bos == Ice_Unset); + + $mo5 = $initial->pingPong($mo1); + test($mo5->a == $mo1->a); + test($mo5->b == $mo1->b); + test($mo5->c == $mo1->c); + test($mo5->d == $mo1->d); + test($mo5->e == $mo1->e); + test($mo5->f == $mo1->f); + test($mo5->g == $mo1->g); + test($mo5->h == $mo1->h); + test($mo5->i == $mo1->i); + test($mo5->j == $mo1->j); + test($mo5->k == null); + test($mo5->bs[0] == 5); + test($mo5->ss == $mo1->ss); + test($mo5->iid[4] == 3); + test($mo5->sid["test"] == 10); + test($mo5->fs == $mo1->fs); + test($mo5->vs == $mo1->vs); + test($mo5->shs == $mo1->shs); + test($mo5->es[0] == $enum && $mo1->es[1] == $enum); + test($mo5->fss[0] == $fs); + test($mo5->vss[0] == $vs); + test($mo5->oos[0]->a == 15); + test($mo5->oops[0] == $ooprx); + + test($mo5->ied[4] == $enum); + test($mo5->ifsd[4] == $fs); + test($mo5->ivsd[5] == $vs); + test($mo5->iood[5]->a == 15); + test($mo5->ioopd[5] == $ooprx); + + test($mo5->bos == $mo1->bos); + + // Clear the first half of the optional members + $mo6 = new $mocls; + $mo6->b = $mo5->b; + $mo6->d = $mo5->d; + $mo6->f = $mo5->f; + $mo6->h = $mo5->h; + $mo6->j = $mo5->j; + $mo6->bs = $mo5->bs; + $mo6->iid = $mo5->iid; + $mo6->fs = $mo5->fs; + $mo6->shs = $mo5->shs; + $mo6->fss = $mo5->fss; + $mo6->oos = $mo5->oos; + $mo6->ifsd = $mo5->ifsd; + $mo6->iood = $mo5->iood; + $mo6->bos = $mo5->bos; + + $mo7 = $initial->pingPong($mo6); + test($mo7->a == Ice_Unset); + test($mo7->b == $mo1->b); + test($mo7->c == Ice_Unset); + test($mo7->d == $mo1->d); + test($mo7->e == Ice_Unset); + test($mo7->f == $mo1->f); + test($mo7->g == Ice_Unset); + test($mo7->h == $mo1->h); + test($mo7->i == Ice_Unset); + test($mo7->j == $mo1->j); + test($mo7->k == Ice_Unset); + test($mo7->bs[0] == 5); + test($mo7->ss == Ice_Unset); + test($mo7->iid[4] == 3); + test($mo7->sid == Ice_Unset); + test($mo7->fs == $mo1->fs); + test($mo7->vs == Ice_Unset); + + test($mo7->shs == $mo1->shs); + test($mo7->es == Ice_Unset); + test($mo7->fss[0] == $fs); + test($mo7->vss == Ice_Unset); + test($mo7->oos[0]->a == 15); + test($mo7->oops == Ice_Unset); + + test($mo7->ied == Ice_Unset); + test($mo7->ifsd[4] == $fs); + test($mo7->ivsd == Ice_Unset); + test($mo7->iood[5]->a == 15); + test($mo7->ioopd == Ice_Unset); + + test($mo7->bos == array(false, true, false)); + + // Clear the second half of the optional members + $mo8 = new $mocls; + $mo8->a = $mo5->a; + $mo8->c = $mo5->c; + $mo8->e = $mo5->e; + $mo8->g = $mo5->g; + $mo8->i = $mo5->i; + $mo8->k = $mo8; + $mo8->ss = $mo5->ss; + $mo8->sid = $mo5->sid; + $mo8->vs = $mo5->vs; + + $mo8->es = $mo5->es; + $mo8->vss = $mo5->vss; + $mo8->oops = $mo5->oops; + + $mo8->ied = $mo5->ied; + $mo8->ivsd = $mo5->ivsd; + $mo8->ioopd = $mo5->ioopd; + + $mo9 = $initial->pingPong($mo8); + test($mo9->a == $mo1->a); + test($mo9->b == Ice_Unset); + test($mo9->c == $mo1->c); + test($mo9->d == Ice_Unset); + test($mo9->e == $mo1->e); + test($mo9->f == Ice_Unset); + test($mo9->g == $mo1->g); + test($mo9->h == Ice_Unset); + test($mo9->i == $mo1->i); + test($mo9->j == Ice_Unset); + test($mo9->k == $mo9); + test($mo9->bs == Ice_Unset); + test($mo9->ss == $mo1->ss); + test($mo9->iid == Ice_Unset); + test($mo9->sid["test"] == 10); + test($mo9->fs == Ice_Unset); + test($mo9->vs == $mo1->vs); + + test($mo9->shs == Ice_Unset); + test($mo9->es[0] == $enum && $mo1->es[1] == $enum); + test($mo9->fss == Ice_Unset); + test($mo9->vss[0] == $vs); + test($mo9->oos == Ice_Unset); + test($mo9->oops[0] == $ooprx); + + test($mo9->ied[4] == $enum); + test($mo9->ifsd == Ice_Unset); + test($mo9->ivsd[5] == $vs); + test($mo9->iood == Ice_Unset); + test($mo9->ioopd[5] == $ooprx); + + test($mo9->bos == Ice_Unset); + + echo "ok\n"; + + echo "testing marshaling of large containers with fixed size elements... "; + flush(); + + $mc = new $mocls; + $mc->bs = array(); + for($i = 0; $i < 1000; $i++) + { + $mc->bs[$i] = 0; + } + $mc->shs = array(); + for($i = 0; $i < 300; $i++) + { + $mc->shs[$i] = 0; + } + $mc->fss = array(); + for($i = 0; $i < 300; $i++) + { + $mc->fss[$i] = new $fscls; + } + $mc->ifsd = array(); + for($i = 0; $i < 300; $i++) + { + $mc->ifsd[$i] = new $fscls; + } + + $mc = $initial->pingPong($mc); + test(count($mc->bs) == 1000); + test(count($mc->shs) == 300); + test(count($mc->fss) == 300); + test(count($mc->ifsd) == 300); + + echo "ok\n"; + + echo "testing tag marshaling... "; + flush(); + + $bcls = $NS ? "Test\\B" : "Test_B"; + $b = new $bcls; + $b2 = $initial->pingPong($b); + test($b2->ma == Ice_Unset); + test($b2->mb == Ice_Unset); + test($b2->mc == Ice_Unset); + + $b->ma = 10; + $b->mb = 11; + $b->mc = 12; + $b->md = 13; + + $b2 = $initial->pingPong($b); + test($b2->ma == 10); + test($b2->mb == 11); + test($b2->mc == 12); + test($b2->md == 13); + + echo "ok\n"; + + echo "testing optional with default values... "; + flush(); + + $wdcls = $NS ? "Test\\WD" : "Test_WD"; + $wd = $initial->pingPong(new $wdcls); + test($wd->a == 5); + test($wd->s == "test"); + $wd->a = Ice_Unset; + $wd->s = Ice_Unset; + $wd = $initial->pingPong($wd); + test($wd->a == Ice_Unset); + test($wd->s == Ice_Unset); + + echo "ok\n"; + + if($communicator->getProperties()->getPropertyAsInt("Ice.Default.SlicedFormat") > 0) + { + echo "testing marshaling with unknown class slices... "; + flush(); + + $ccls = $NS ? "Test\\C" : "Test_C"; + $c = new $ccls; + $c->ss = "test"; + $c->ms = "testms"; + $c = $initial->pingPong($c); + test($c->ma == Ice_Unset); + test($c->mb == Ice_Unset); + test($c->mc == Ice_Unset); + test($c->md == Ice_Unset); + test($c->ss == "test"); + test($c->ms == "testms"); + + echo "ok\n"; + + echo "testing optionals with unknown classes... "; + flush(); + + $initial2 = $NS ? eval("return Test\\Initial2PrxHelper::uncheckedCast(\$base);") : + eval("return Test_Initial2PrxHelper::uncheckedCast(\$base);"); + $acls = $NS ? "Test\\A" : "Test_A"; + $dcls = $NS ? "Test\\D" : "Test_D"; + $d = new $dcls; + $d->ds = "test"; + $d->seq = array("test1", "test2", "test3", "test4"); + $d->ao = new $acls(18); + $d->requiredB = 14; + $d->requiredA = 14; + $initial2->opClassAndUnknownOptional(new $acls, $d); + + echo "ok\n"; + } + + echo "testing optional parameters... "; + flush(); + + $p2 = 0; + $p3 = $initial->opByte(Ice_Unset, $p2); + test($p2 == Ice_Unset && $p3 == Ice_Unset); + $p3 = $initial->opByte(56, $p2); + test($p2 == 56 && $p3 == 56); + + $p3 = $initial->opBool(Ice_Unset, $p2); + test($p2 == Ice_Unset && $p3 == Ice_Unset); + $p3 = $initial->opBool(true, $p2); + test($p2 == true && $p3 == true); + + $p3 = $initial->opShort(Ice_Unset, $p2); + test($p2 == Ice_Unset && $p3 == Ice_Unset); + $p3 = $initial->opShort(56, $p2); + test($p2 == 56 && $p3 == 56); + + $p3 = $initial->opInt(Ice_Unset, $p2); + test($p2 == Ice_Unset && $p3 == Ice_Unset); + $p3 = $initial->opInt(56, $p2); + test($p2 == 56 && $p3 == 56); + + $p3 = $initial->opLong(Ice_Unset, $p2); + test($p2 == Ice_Unset && $p3 == Ice_Unset); + $p3 = $initial->opLong(56, $p2); + test($p2 == 56 && $p3 == 56); + + $p3 = $initial->opFloat(Ice_Unset, $p2); + test($p2 == Ice_Unset && $p3 == Ice_Unset); + $p3 = $initial->opFloat(1.0, $p2); + test($p2 == 1.0 && $p3 == 1.0); + + $p3 = $initial->opDouble(Ice_Unset, $p2); + test($p2 == Ice_Unset && $p3 == Ice_Unset); + $p3 = $initial->opDouble(1.0, $p2); + test($p2 == 1.0 && $p3 == 1.0); + + $p3 = $initial->opString(Ice_Unset, $p2); + test($p2 == Ice_Unset && $p3 == Ice_Unset); + $p3 = $initial->opString("test", $p2); + test($p2 == "test" && $p3 == "test"); + + $p3 = $initial->opMyEnum(Ice_Unset, $p2); + test($p2 == Ice_Unset && $p3 == Ice_Unset); + $p3 = $initial->opMyEnum($enum, $p2); + test($p2 == $enum && $p3 == $enum); + + $sscls = $NS ? "Test\\SmallStruct" : "Test_SmallStruct"; + $p3 = $initial->opSmallStruct(Ice_Unset, $p2); + test($p2 == Ice_Unset && $p3 == Ice_Unset); + $p1 = new $sscls(56); + $p3 = $initial->opSmallStruct($p1, $p2); + test($p2 == $p1 && $p3 == $p1); + + $p3 = $initial->opFixedStruct(Ice_Unset, $p2); + test($p2 == Ice_Unset && $p3 == Ice_Unset); + $p1 = new $fscls(56); + $p3 = $initial->opFixedStruct($p1, $p2); + test($p2 == $p1 && $p3 == $p1); + + $p3 = $initial->opVarStruct(Ice_Unset, $p2); + test($p2 == Ice_Unset && $p3 == Ice_Unset); + $p1 = new $vscls("test"); + $p3 = $initial->opVarStruct($p1, $p2); + test($p2 == $p1 && $p3 == $p1); + + $p3 = $initial->opOneOptional(Ice_Unset, $p2); + test($p2 == Ice_Unset && $p3 == Ice_Unset); + $p1 = new $oocls(58); + $p3 = $initial->opOneOptional($p1, $p2); + test($p2->a == $p1->a && $p3->a == $p1->a); + + $p3 = $initial->opOneOptionalProxy(Ice_Unset, $p2); + test($p2 == Ice_Unset && $p3 == Ice_Unset); + $p3 = $initial->opOneOptionalProxy($ooprx, $p2); + test($p2 == $ooprx && $p3 == $ooprx); + + $p3 = $initial->opByteSeq(Ice_Unset, $p2); + test($p2 == Ice_Unset && $p3 == Ice_Unset); + $p1 = array(); + for($i = 0; $i < 100; $i++) + { + $p1[$i] = 56; + } + $p3 = $initial->opByteSeq($p1, $p2); + test($p2 == $p1 && $p3 == $p1); + + $p3 = $initial->opBoolSeq(Ice_Unset, $p2); + test($p2 == Ice_Unset && $p3 == Ice_Unset); + $p1 = array(); + for($i = 0; $i < 100; $i++) + { + $p1[$i] = true; + } + $p3 = $initial->opBoolSeq($p1, $p2); + test($p2 == $p1 && $p3 == $p1); + + $p3 = $initial->opShortSeq(Ice_Unset, $p2); + test($p2 == Ice_Unset && $p3 == Ice_Unset); + $p1 = array(); + for($i = 0; $i < 100; $i++) + { + $p1[$i] = 56; + } + $p3 = $initial->opShortSeq($p1, $p2); + test($p2 == $p1 && $p3 == $p1); + + $p3 = $initial->opIntSeq(Ice_Unset, $p2); + test($p2 == Ice_Unset && $p3 == Ice_Unset); + $p1 = array(); + for($i = 0; $i < 100; $i++) + { + $p1[$i] = 56; + } + $p3 = $initial->opIntSeq($p1, $p2); + test($p2 == $p1 && $p3 == $p1); + + $p3 = $initial->opLongSeq(Ice_Unset, $p2); + test($p2 == Ice_Unset && $p3 == Ice_Unset); + $p1 = array(); + for($i = 0; $i < 100; $i++) + { + $p1[$i] = 56; + } + $p3 = $initial->opLongSeq($p1, $p2); + test($p2 == $p1 && $p3 == $p1); + + $p3 = $initial->opFloatSeq(Ice_Unset, $p2); + test($p2 == Ice_Unset && $p3 == Ice_Unset); + $p1 = array(); + for($i = 0; $i < 100; $i++) + { + $p1[$i] = 1.0; + } + $p3 = $initial->opFloatSeq($p1, $p2); + test($p2 == $p1 && $p3 == $p1); + + $p3 = $initial->opDoubleSeq(Ice_Unset, $p2); + test($p2 == Ice_Unset && $p3 == Ice_Unset); + $p1 = array(); + for($i = 0; $i < 100; $i++) + { + $p1[$i] = 1.0; + } + $p3 = $initial->opDoubleSeq($p1, $p2); + test($p2 == $p1 && $p3 == $p1); + + $p3 = $initial->opStringSeq(Ice_Unset, $p2); + test($p2 == Ice_Unset && $p3 == Ice_Unset); + $p1 = array(); + for($i = 0; $i < 100; $i++) + { + $p1[$i] = "test1"; + } + $p3 = $initial->opStringSeq($p1, $p2); + test($p2 == $p1 && $p3 == $p1); + + $p3 = $initial->opSmallStructSeq(Ice_Unset, $p2); + test($p2 == Ice_Unset && $p3 == Ice_Unset); + $p1 = array(); + for($i = 0; $i < 10; $i++) + { + $p1[$i] = new $sscls(1); + } + $p3 = $initial->opSmallStructSeq($p1, $p2); + test($p2 == $p1 && $p3 == $p1); + + $p3 = $initial->opFixedStructSeq(Ice_Unset, $p2); + test($p2 == Ice_Unset && $p3 == Ice_Unset); + $p1 = array(); + for($i = 0; $i < 10; $i++) + { + $p1[$i] = new $fscls(1); + } + $p3 = $initial->opFixedStructSeq($p1, $p2); + test($p2 == $p1 && $p3 == $p1); + + $p3 = $initial->opVarStructSeq(Ice_Unset, $p2); + test($p2 == Ice_Unset && $p3 == Ice_Unset); + $p1 = array(); + for($i = 0; $i < 10; $i++) + { + $p1[$i] = new $vscls("test"); + } + $p3 = $initial->opVarStructSeq($p1, $p2); + test($p2 == $p1 && $p3 == $p1); + + $p3 = $initial->opIntIntDict(Ice_Unset, $p2); + test($p2 == Ice_Unset && $p3 == Ice_Unset); + $p1 = array(1=>2, 2=>3); + $p3 = $initial->opIntIntDict($p1, $p2); + test($p2 == $p1 && $p3 == $p1); + + $p3 = $initial->opStringIntDict(Ice_Unset, $p2); + test($p2 == Ice_Unset && $p3 == Ice_Unset); + $p1 = array("1"=>2, "2"=>3); + $p3 = $initial->opStringIntDict($p1, $p2); + test($p2 == $p1 && $p3 == $p1); + + echo "ok\n"; + + echo "testing exception optionals... "; + flush(); + + try + { + $initial->opOptionalException(Ice_Unset, Ice_Unset, Ice_Unset); + } + catch(Exception $ex) + { + $excls = $NS ? "Test\\OptionalException" : "Test_OptionalException"; + if(!($ex instanceof $excls)) + { + throw $ex; + } + test($ex->a == Ice_Unset); + test($ex->b == Ice_Unset); + test($ex->o == Ice_Unset); + } + + try + { + $initial->opOptionalException(30, "test", new $oocls(53)); + } + catch(Exception $ex) + { + test($ex->a == 30); + test($ex->b == "test"); + test($ex->o->a == 53); + } + + try + { + $initial->opDerivedException(Ice_Unset, Ice_Unset, Ice_Unset); + } + catch(Exception $ex) + { + test($ex->a == Ice_Unset); + test($ex->b == Ice_Unset); + test($ex->o == Ice_Unset); + test($ex->ss == Ice_Unset); + test($ex->o2 == Ice_Unset); + } + + try + { + $initial->opDerivedException(30, "test", new $oocls(53)); + } + catch(Exception $ex) + { + test($ex->a == 30); + test($ex->b == "test"); + test($ex->o->a == 53); + test($ex->ss == "test"); + test($ex->o2 == $ex->o); + } + + try + { + $initial->opRequiredException(Ice_Unset, Ice_Unset, Ice_Unset); + } + catch(Exception $ex) + { + test($ex->a == Ice_Unset); + test($ex->b == Ice_Unset); + test($ex->o == Ice_Unset); + test($ex->ss != Ice_Unset); + test($ex->o2 != Ice_Unset); + } + + try + { + $initial->opRequiredException(30, "test", new $oocls(53)); + } + catch(Exception $ex) + { + test($ex->a == 30); + test($ex->b == "test"); + test($ex->o->a == 53); + test($ex->ss == "test"); + test($ex->o2 == $ex->o); + } + + echo "ok\n"; + + return $initial; +} + +$communicator = Ice_initialize($argv); + +$initial = allTests($communicator); + +$initial->shutdown(); +$communicator->destroy(); + +exit(); +?> diff --git a/php/test/Ice/optional/ClientPrivate.ice b/php/test/Ice/optional/ClientPrivate.ice new file mode 100644 index 00000000000..a456124b4ec --- /dev/null +++ b/php/test/Ice/optional/ClientPrivate.ice @@ -0,0 +1,37 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2012 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. +// +// ********************************************************************** + +#pragma once + +#include <Test.ice> + +module Test +{ + +// +// The server doesn't know this class. +// +class D extends B +{ + string ds; + optional(990) StringSeq seq; + optional(1000) A ao; +}; + +// +// This class is a hack that allows us to invoke the opClassAndUnknownOptional operation +// on the server and pass an optional argument. This isn't necessary in other language +// mappings where the public stream API is available. +// +class Initial2 +{ + void opClassAndUnknownOptional(A p, optional(1) Object o); +}; + +}; diff --git a/php/test/Ice/optional/Makefile b/php/test/Ice/optional/Makefile new file mode 100644 index 00000000000..a390fe5e62b --- /dev/null +++ b/php/test/Ice/optional/Makefile @@ -0,0 +1,27 @@ +# ********************************************************************** +# +# Copyright (c) 2003-2012 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. +# +# ********************************************************************** + +top_srcdir = ../../.. + +SLICE_SRCS = ClientPrivate.ice Test.ice + +include $(top_srcdir)/config/Make.rules.php + +SRCS = ClientPrivate.php Test.php +SLICE2PHPFLAGS := -I. $(SLICE2PHPFLAGS) + +all:: $(SRCS) + +%.php: %.ice + $(SLICE2PHP) $(SLICE2PHPFLAGS) $< + +clean:: + rm -f $(SRCS) + +include .depend diff --git a/php/test/Ice/optional/Makefile.mak b/php/test/Ice/optional/Makefile.mak new file mode 100644 index 00000000000..7d43d824315 --- /dev/null +++ b/php/test/Ice/optional/Makefile.mak @@ -0,0 +1,25 @@ +# **********************************************************************
+#
+# Copyright (c) 2003-2012 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.
+#
+# **********************************************************************
+
+top_srcdir = ..\..\..
+
+!include $(top_srcdir)\config\Make.rules.mak.php
+
+SRCS = ClientPrivate.php Test.php
+SLICE2PHPFLAGS = -I. $(SLICE2PHPFLAGS)
+
+all:: $(SRCS)
+
+$(SRCS): $*.ice
+ -"$(SLICE2PHP)" $(SLICE2PHPFLAGS) $*.ice
+
+clean::
+ del /q $(SRCS)
+
+include .depend.mak
diff --git a/php/test/Ice/optional/Test.ice b/php/test/Ice/optional/Test.ice new file mode 100644 index 00000000000..7f0342b8df4 --- /dev/null +++ b/php/test/Ice/optional/Test.ice @@ -0,0 +1,246 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2012 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. +// +// ********************************************************************** + +#pragma once + +module Test +{ + +class OneOptional +{ + optional(1) int a; +}; + +enum MyEnum +{ + MyEnumMember +}; + +struct SmallStruct +{ + byte m; +}; + +struct FixedStruct +{ + int m; +}; + +struct VarStruct +{ + string m; +}; + +struct ClassVarStruct +{ + int a; +}; + +sequence<byte> ByteSeq; +sequence<bool> BoolSeq; +sequence<short> ShortSeq; +sequence<int> IntSeq; +sequence<long> LongSeq; +sequence<float> FloatSeq; +sequence<double> DoubleSeq; +sequence<string> StringSeq; +sequence<MyEnum> MyEnumSeq; +sequence<SmallStruct> SmallStructSeq; +sequence<SmallStruct> SmallStructList; +sequence<FixedStruct> FixedStructSeq; +sequence<FixedStruct> FixedStructList; +sequence<VarStruct> VarStructSeq; +sequence<OneOptional> OneOptionalSeq; +sequence<OneOptional*> OneOptionalPrxSeq; + +sequence<byte> Serializable; + +dictionary<int, int> IntIntDict; +dictionary<string, int> StringIntDict; +dictionary<int, MyEnum> IntEnumDict; +dictionary<int, FixedStruct> IntFixedStructDict; +dictionary<int, VarStruct> IntVarStructDict; +dictionary<int, OneOptional> IntOneOptionalDict; +dictionary<int, OneOptional*> IntOneOptionalPrxDict; + +class MultiOptional +{ + optional(1) byte a; + optional(2) bool b; + optional(3) short c; + optional(4) int d; + optional(5) long e; + optional(6) float f; + optional(7) double g; + optional(8) string h; + optional(9) MyEnum i; + optional(10) MultiOptional* j; + optional(11) MultiOptional k; + optional(12) ByteSeq bs; + optional(13) StringSeq ss; + optional(14) IntIntDict iid; + optional(15) StringIntDict sid; + optional(16) FixedStruct fs; + optional(17) VarStruct vs; + + optional(18) ShortSeq shs; + optional(19) MyEnumSeq es; + optional(20) FixedStructSeq fss; + optional(21) VarStructSeq vss; + optional(22) OneOptionalSeq oos; + optional(23) OneOptionalPrxSeq oops; + + optional(24) IntEnumDict ied; + optional(25) IntFixedStructDict ifsd; + optional(26) IntVarStructDict ivsd; + optional(27) IntOneOptionalDict iood; + optional(28) IntOneOptionalPrxDict ioopd; + + optional(29) BoolSeq bos; + + optional(30) Serializable ser; +}; + +class A +{ + int requiredA; + optional(1) int ma; + optional(50) int mb; + optional(500) int mc; +}; + +["preserve-slice"] +class B extends A +{ + int requiredB; + optional(10) int md; +}; + +class C extends B +{ + string ss; + optional(890) string ms; +}; + +class WD +{ + optional(1) int a = 5; + optional(2) string s = "test"; +}; + +exception OptionalException +{ + optional(1) int a = 5; + optional(2) string b; + optional(50) OneOptional o; +}; + +exception DerivedException extends OptionalException +{ + optional(600) string ss = "test"; + optional(601) OneOptional o2; +}; + +exception RequiredException extends OptionalException +{ + string ss = "test"; + OneOptional o2; +}; + +class OptionalWithCustom +{ + optional(1) SmallStructList l; + ["protected"] optional(2) SmallStructList lp; + optional(3) ClassVarStruct s; +}; + +["ami"] +class Initial +{ + void shutdown(); + + Object pingPong(Object o); + + void opOptionalException(optional(1) int a, optional(2) string b, optional(3) OneOptional o) + throws OptionalException; + + void opDerivedException(optional(1) int a, optional(2) string b, optional(3) OneOptional o) + throws OptionalException; + + void opRequiredException(optional(1) int a, optional(2) string b, optional(3) OneOptional o) + throws OptionalException; + + optional(1) byte opByte(optional(2) byte p1, out optional(3) byte p3); + + optional(1) bool opBool(optional(2) bool p1, out optional(3) bool p3); + + optional(1) short opShort(optional(2) short p1, out optional(3) short p3); + + optional(1) int opInt(optional(2) int p1, out optional(3) int p3); + + optional(3) long opLong(optional(1) long p1, out optional(2) long p3); + + optional(1) float opFloat(optional(2) float p1, out optional(3) float p3); + + optional(1) double opDouble(optional(2) double p1, out optional(3) double p3); + + optional(1) string opString(optional(2) string p1, out optional(3) string p3); + + optional(1) MyEnum opMyEnum(optional(2) MyEnum p1, out optional(3) MyEnum p3); + + optional(1) SmallStruct opSmallStruct(optional(2) SmallStruct p1, out optional(3) SmallStruct p3); + + optional(1) FixedStruct opFixedStruct(optional(2) FixedStruct p1, out optional(3) FixedStruct p3); + + optional(1) VarStruct opVarStruct(optional(2) VarStruct p1, out optional(3) VarStruct p3); + + optional(1) OneOptional opOneOptional(optional(2) OneOptional p1, out optional(3) OneOptional p3); + + optional(1) OneOptional* opOneOptionalProxy(optional(2) OneOptional* p1, out optional(3) OneOptional* p3); + + optional(1) ByteSeq opByteSeq(optional(2) ByteSeq p1, out optional(3) ByteSeq p3); + + optional(1) BoolSeq opBoolSeq(optional(2) BoolSeq p1, out optional(3) BoolSeq p3); + + optional(1) ShortSeq opShortSeq(optional(2) ShortSeq p1, out optional(3) ShortSeq p3); + + optional(1) IntSeq opIntSeq(optional(2) IntSeq p1, out optional(3) IntSeq p3); + + optional(1) LongSeq opLongSeq(optional(2) LongSeq p1, out optional(3) LongSeq p3); + + optional(1) FloatSeq opFloatSeq(optional(2) FloatSeq p1, out optional(3) FloatSeq p3); + + optional(1) DoubleSeq opDoubleSeq(optional(2) DoubleSeq p1, out optional(3) DoubleSeq p3); + + optional(1) StringSeq opStringSeq(optional(2) StringSeq p1, out optional(3) StringSeq p3); + + optional(1) SmallStructSeq opSmallStructSeq(optional(2) SmallStructSeq p1, out optional(3) SmallStructSeq p3); + + optional(1) SmallStructList opSmallStructList(optional(2) SmallStructList p1, out optional(3) SmallStructList p3); + + optional(1) FixedStructSeq opFixedStructSeq(optional(2) FixedStructSeq p1, out optional(3) FixedStructSeq p3); + + optional(1) FixedStructList opFixedStructList(optional(2) FixedStructList p1, out optional(3) FixedStructList p3); + + optional(1) VarStructSeq opVarStructSeq(optional(2) VarStructSeq p1, out optional(3) VarStructSeq p3); + + optional(1) IntIntDict opIntIntDict(optional(2) IntIntDict p1, out optional(3) IntIntDict p3); + + optional(1) StringIntDict opStringIntDict(optional(2) StringIntDict p1, out optional(3) StringIntDict p3); + + void opClassAndUnknownOptional(A p); + + bool supportsRequiredParams(); + + bool supportsJavaSerializable(); + + bool supportsCsharpSerializable(); +}; + +}; diff --git a/php/test/Ice/optional/run.py b/php/test/Ice/optional/run.py new file mode 100755 index 00000000000..13f58435db4 --- /dev/null +++ b/php/test/Ice/optional/run.py @@ -0,0 +1,26 @@ +#!/usr/bin/env python +# ********************************************************************** +# +# Copyright (c) 2003-2012 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 os, sys + +path = [ ".", "..", "../..", "../../..", "../../../..", "../../../../.." ] +head = os.path.dirname(sys.argv[0]) +if len(head) > 0: + path = [os.path.join(head, p) for p in path] +path = [os.path.abspath(p) for p in path if os.path.exists(os.path.join(p, "scripts", "TestUtil.py")) ] +if len(path) == 0: + raise RuntimeError("can't find toplevel directory!") +sys.path.append(os.path.join(path[0], "scripts")) +import TestUtil + +print("Running test with compact (default) format.") +TestUtil.clientServerTest() +print("Running test with sliced format.") +TestUtil.clientServerTest(additionalClientOptions="--Ice.Default.SlicedFormat", additionalServerOptions="--Ice.Default.SlicedFormat") diff --git a/php/test/Ice/slicing/objects/Client.php b/php/test/Ice/slicing/objects/Client.php index e57f3b44269..a2e817ef2ad 100644 --- a/php/test/Ice/slicing/objects/Client.php +++ b/php/test/Ice/slicing/objects/Client.php @@ -110,15 +110,24 @@ function allTests($communicator) echo "unknown with Object as Object... "; flush(); { + $usocls = $NS ? "Ice\\UnknownSlicedObject" : "Ice_UnknownSlicedObject"; try { $o = $test->SUnknownAsObject(); - test(false); + test($test->ice_getEncodingVersion() != $Ice_Encoding_1_0); + test($o instanceof $usocls); + test($o->unknownTypeId == "::Test::SUnknown"); + test($o->_ice_slicedData != null); + $test->checkSUnknown($o); } catch(Exception $b) { $excls = $NS ? "Ice\\NoObjectFactoryException" : "Ice_NoObjectFactoryException"; - if(!($b instanceof $excls)) + if($b instanceof $excls) + { + test($test->ice_getEncodingVersion() == $Ice_Encoding_1_0); + } + else { throw $ex; } diff --git a/php/test/Ice/slicing/objects/Test.ice b/php/test/Ice/slicing/objects/Test.ice index 8e20db55def..1272f947d8b 100644 --- a/php/test/Ice/slicing/objects/Test.ice +++ b/php/test/Ice/slicing/objects/Test.ice @@ -110,6 +110,7 @@ interface TestIntf ["format:compact"] SBase SBSUnknownDerivedAsSBaseCompact(); Object SUnknownAsObject(); + void checkSUnknown(Object o); B oneElementCycle(); B twoElementCycle(); |