package.xml0000644000077100007710000005336412110565610013061 0ustar xinchenxinchen msgpack pecl.php.net PHP extension for interfacing with MessagePack This extension provide API for communicating with MessagePack serialization. Advect advect advect@gmail.com yes Xinchen Hui laruence laruence@php.net yes 2013-02-19 0.5.5 0.5.5 beta beta New BSD - Fix ZTS build - Fixed Bug #14 ("Invalid read" reported by valgrind) - Fixed FR #8 (Return on unserialization) 5.0.0 1.4.3 msgpack 2013-02-19 0.5.5 0.5.5 beta beta PHP License - Fix ZTS build - Fixed Bug #14 ("Invalid read" reported by valgrind) - Fixed FR #8 (Return on unserialization) 2013-02-18 0.5.4 0.5.4 beta beta PHP License - Fixed Bug #12 (msgpack_seriallize interfere with php serialize). - Fixed Bug #11 (unpacking empty array / segmentation fault). 2012-10-12 0.5.3 0.5.3 beta beta PHP License - Fixed Bug #6 (bug with incorrect packing of mixed arrays) 2012-09-14 0.5.2 0.5.2 beta beta PHP License - Initial release msgpack-0.5.5/tests/001.phpt0000644000077100007710000000031412110565607015364 0ustar xinchenxinchen--TEST-- Check for msgpack presence --SKIPIF-- --FILE-- --EXPECT-- msgpack extension is available msgpack-0.5.5/tests/002.phpt0000644000077100007710000000075112110565607015372 0ustar xinchenxinchen--TEST-- Check for null serialisation --SKIPIF-- --FILE-- --EXPECT-- null c0 NULL OK msgpack-0.5.5/tests/003.phpt0000644000077100007710000000106312110565607015370 0ustar xinchenxinchen--TEST-- Check for bool serialisation --SKIPIF-- --FILE-- --EXPECT-- bool true c3 bool(true) OK bool false c2 bool(false) OK msgpack-0.5.5/tests/004.phpt0000644000077100007710000000153512110565607015375 0ustar xinchenxinchen--TEST-- Check for integer serialisation --SKIPIF-- --FILE-- --EXPECT-- zero: 0 00 int(0) OK small: 1 01 int(1) OK small: -1 ff int(-1) OK medium: 1000 cd03e8 int(1000) OK medium: -1000 d1fc18 int(-1000) OK large: 100000 ce000186a0 int(100000) OK large: -100000 d2fffe7960 int(-100000) OK msgpack-0.5.5/tests/005.phpt0000644000077100007710000000103612110565607015372 0ustar xinchenxinchen--TEST-- Check for double serialisation --SKIPIF-- --FILE-- --EXPECT-- double: 123.456 cb405edd2f1a9fbe77 float(123.456) OK msgpack-0.5.5/tests/006.phpt0000644000077100007710000000113412110565607015372 0ustar xinchenxinchen--TEST-- Check for simple string serialization --SKIPIF-- --FILE-- --EXPECT-- empty: "" a0 string(0) "" OK string: "foobar" a6666f6f626172 string(6) "foobar" OK msgpack-0.5.5/tests/007.phpt0000644000077100007710000000207312110565607015376 0ustar xinchenxinchen--TEST-- Check for simple array serialization --SKIPIF-- --FILE-- --EXPECT-- empty array: 90 array(0) { } OK array(1, 2, 3) 93010203 array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } OK array(array(1, 2, 3), arr... 93930102039304050693070809 array(3) { [0]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } [1]=> array(3) { [0]=> int(4) [1]=> int(5) [2]=> int(6) } [2]=> array(3) { [0]=> int(7) [1]=> int(8) [2]=> int(9) } } OK msgpack-0.5.5/tests/008.phpt0000644000077100007710000000231212110565607015373 0ustar xinchenxinchen--TEST-- Check for array+string serialization --SKIPIF-- --FILE-- 1, "two" => 2))', array("one" => 1, "two" => 2)); test('array("kek" => "lol", "lol" => "kek")', array("kek" => "lol", "lol" => "kek")); test('array("" => "empty")', array("" => "empty")); ?> --EXPECT-- array("foo", "foo", "foo") 93a3666f6fa3666f6fa3666f6f array(3) { [0]=> string(3) "foo" [1]=> string(3) "foo" [2]=> string(3) "foo" } OK array("one" => 1, "two" => 2)) 82a36f6e6501a374776f02 array(2) { ["one"]=> int(1) ["two"]=> int(2) } OK array("kek" => "lol", "lol" => "kek") 82a36b656ba36c6f6ca36c6f6ca36b656b array(2) { ["kek"]=> string(3) "lol" ["lol"]=> string(3) "kek" } OK array("" => "empty") 81a0a5656d707479 array(1) { [""]=> string(5) "empty" } OK msgpack-0.5.5/tests/009.phpt0000644000077100007710000000313012110565607015373 0ustar xinchenxinchen--TEST-- Check for reference serialization --SKIPIF-- = 0 && version_compare(PHP_VERSION, '5.3.2') <= 0)) { echo "skip tests in PHP 5.2.14/5.3.3 or newer"; } --FILE-- array(1) { [0]=> string(3) "foo" } [1]=> array(1) { [0]=> string(3) "foo" } } OK array(&$a, &$a) 9282c00100a3666f6f82c0020002 array(2) { [0]=> &array(1) { [0]=> string(3) "foo" } [1]=> &array(1) { [0]=> string(3) "foo" } } OK cyclic 9182c0010082c0010082c0020002 array(1) { [0]=> &array(1) { [0]=> &array(1) { [0]=> *RECURSION* } } } OK array(1) { [0]=> &array(1) { [0]=> &array(1) { [0]=> *RECURSION* } } } array(1) { [0]=> &array(1) { [0]=> &array(1) { [0]=> *RECURSION* } } } msgpack-0.5.5/tests/009b.phpt0000644000077100007710000000354512110565607015547 0ustar xinchenxinchen--TEST-- Check for reference serialization --SKIPIF-- = 0) || (version_compare(PHP_VERSION, '5.3.3') >= 0)) { echo "skip tests in PHP 5.2.13/5.3.2 or older"; } --FILE-- array(1) { [0]=> string(3) "foo" } [1]=> array(1) { [0]=> string(3) "foo" } } OK array(&$a, &$a) 9282c00100a3666f6f82c0020002 array(2) { [0]=> &array(1) { [0]=> string(3) "foo" } [1]=> &array(1) { [0]=> string(3) "foo" } } OK cyclic 9182c0010082c0010082c0020002 array(1) { [0]=> &array(1) { [0]=> &array(1) { [0]=> &array(1) { [0]=> &array(1) { [0]=> *RECURSION* } } } } } OK array(1) { [0]=> &array(1) { [0]=> &array(1) { [0]=> &array(1) { [0]=> &array(1) { [0]=> *RECURSION* } } } } } array(1) { [0]=> &array(1) { [0]=> &array(1) { [0]=> &array(1) { [0]=> &array(1) { [0]=> *RECURSION* } } } } } msgpack-0.5.5/tests/010.phpt0000644000077100007710000000144412110565607015371 0ustar xinchenxinchen--TEST-- Array test --SKIPIF-- --FILE-- array( 'b' => 'c', 'd' => 'e' ), 'f' => array( 'g' => 'h' ) ); test('array', $a, false); ?> --EXPECT-- array 82a16182a162a163a164a165a16681a167a168 array(2) { ["a"]=> array(2) { ["b"]=> string(1) "c" ["d"]=> string(1) "e" } ["f"]=> array(1) { ["g"]=> string(1) "h" } } OK msgpack-0.5.5/tests/012.phpt0000644000077100007710000000170312110565607015371 0ustar xinchenxinchen--TEST-- Object test --SKIPIF-- a = $a; $this->b = $b; $this->c = $c; } } $o = new Obj(1, 2, 3); test('object', $o, false); ?> --EXPECTF-- object 84c0a34f626aa16101a4002a006202a6004f626a006303 object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK msgpack-0.5.5/tests/012c.phpt0000644000077100007710000000165312110565607015540 0ustar xinchenxinchen--TEST-- Object test --SKIPIF-- = 0) { echo "skip tests in PHP 5.1 or older"; } --FILE-- a = $a; $this->b = $b; $this->c = $c; } } $o = new Obj(1, 2, 3); test('object', $o, false); ?> --EXPECTF-- object 84c0a34f626aa16101a4002a006202a6004f626a006303 object(Obj)#%d (3) { ["a"]=> int(1) ["b:protected"]=> int(2) ["c:private"]=> int(3) } OK msgpack-0.5.5/tests/013.phpt0000644000077100007710000000157412110565607015400 0ustar xinchenxinchen--TEST-- Object-Array test --SKIPIF-- --FILE-- a = $a; $this->b = $b; } } $o = array(new Obj(1, 2), new Obj(3, 4)); test('object', $o, false); ?> --EXPECTF-- object 9283c0a34f626aa16101a1620283c0a34f626aa16103a16204 array(2) { [0]=> object(Obj)#%d (2) { ["a"]=> int(1) ["b"]=> int(2) } [1]=> object(Obj)#%d (2) { ["a"]=> int(3) ["b"]=> int(4) } } OK msgpack-0.5.5/tests/014.phpt0000644000077100007710000000156712110565607015403 0ustar xinchenxinchen--TEST-- Object-Reference test --SKIPIF-- --FILE-- a = $a; $this->b = $b; } } $o = new Obj(1, 2); $a = array(&$o, &$o); test('object', $a, false); ?> --EXPECTF-- object 9284c001c0a34f626aa16101a1620282c0050002 array(2) { [0]=> &object(Obj)#%d (2) { ["a"]=> int(1) ["b"]=> int(2) } [1]=> &object(Obj)#%d (2) { ["a"]=> int(1) ["b"]=> int(2) } } OK msgpack-0.5.5/tests/015.phpt0000644000077100007710000000176112110565607015400 0ustar xinchenxinchen--TEST-- Check for serialization handler --SKIPIF-- --EXPECT-- 2 82c001a3666f6f02 array(1) { ["foo"]=> int(2) } msgpack-0.5.5/tests/015b.phpt0000644000077100007710000000177012110565607015542 0ustar xinchenxinchen--TEST-- Check for serialization handler, ini-directive --SKIPIF-- --EXPECT-- 2 82c001a3666f6f02 array(1) { ["foo"]=> int(2) } msgpack-0.5.5/tests/015d.phpt0000644000077100007710000000164112110565607015541 0ustar xinchenxinchen--TEST-- Check for serialization handler --SKIPIF-- = 0) { echo "skip tests in PHP 5.2 or older"; } --FILE-- --EXPECT-- 2 81a3666f6f02 array(1) { ["foo"]=> int(2) } msgpack-0.5.5/tests/015e.phpt0000644000077100007710000000203012110565607015533 0ustar xinchenxinchen--TEST-- Check for serialization handler, broken --SKIPIF-- --EXPECT-- 1 82c001a3666f6f01 array(1) { ["foo"]=> int(1) } msgpack-0.5.5/tests/015f.phpt0000644000077100007710000000171112110565607015541 0ustar xinchenxinchen--TEST-- Check for serialization handler, broken --SKIPIF-- = 0) { echo "skip tests in PHP 5.2 or older"; } --FILE-- --EXPECT-- 1 81a3666f6f01 array(1) { ["foo"]=> int(1) } msgpack-0.5.5/tests/016.phpt0000644000077100007710000000223712110565607015400 0ustar xinchenxinchen--TEST-- Object test, __sleep --SKIPIF-- a = $a; $this->b = $b; $this->c = $c; $this->d = $d; } function __sleep() { return array('a', 'b', 'c'); } # function __wakeup() { # $this->d = $this->a + $this->b + $this->c; # } } $o = new Obj(1, 2, 3, 4); test('object', $o, true); ?> --EXPECTF-- object 84c0a34f626aa16101a4002a006202a6004f626a006303 object(Obj)#%d (4) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) ["d"]=> NULL } OK msgpack-0.5.5/tests/016c.phpt0000644000077100007710000000220712110565607015540 0ustar xinchenxinchen--TEST-- Object test, __sleep --SKIPIF-- = 0) { echo "skip tests in PHP 5.1 or older"; } --FILE-- a = $a; $this->b = $b; $this->c = $c; $this->d = $d; } function __sleep() { return array('a', 'b', 'c'); } # function __wakeup() { # $this->d = $this->a + $this->b + $this->c; # } } $o = new Obj(1, 2, 3, 4); test('object', $o, true); ?> --EXPECTF-- object 84c0a34f626aa16101a4002a006202a6004f626a006303 object(Obj)#%d (4) { ["a"]=> int(1) ["b:protected"]=> int(2) ["c:private"]=> int(3) ["d"]=> NULL } OK msgpack-0.5.5/tests/017.phpt0000644000077100007710000000143312110565607015376 0ustar xinchenxinchen--TEST-- Object test, __wakeup --SKIPIF-- --FILE-- b == 3 ? 'OK' : 'ERROR', PHP_EOL; } class Obj { var $a; var $b; function __construct($a, $b) { $this->a = $a; $this->b = $b; } function __wakeup() { $this->b = $this->a * 3; } } $o = new Obj(1, 2); test('object', $o, false); ?> --EXPECTF-- object 83c0a34f626aa16101a16202 object(Obj)#%d (2) { ["a"]=> int(1) ["b"]=> int(3) } OK msgpack-0.5.5/tests/018.phpt0000644000077100007710000000305112110565607015375 0ustar xinchenxinchen--TEST-- Object test, __sleep error cases --SKIPIF-- --FILE-- a = $a; $this->b = $b; } function __sleep() { return array('c'); } # function __wakeup() { # $this->b = $this->a * 3; # } } class Opj { var $a; var $b; function __construct($a, $b) { $this->a = $a; $this->b = $b; } function __sleep() { return array(1); } # function __wakeup() { # # } } $o = new Obj(1, 2); $p = new Opj(1, 2); test('nonexisting', $o, true); test('wrong', $p, true); ?> --EXPECTF-- Notice: [msgpack] (msgpack_serialize_class) "c" returned as member variable from __sleep() but does not exist in %s on line %d nonexisting 82c0a34f626aa163c0 object(Obj)#%d (3) { ["a"]=> NULL ["b"]=> NULL ["c"]=> NULL } OK Notice: [msgpack] (msgpack_serialize_class) __sleep should return an array only containing the names of instance-variables to serialize in %s018.php on line %d Warning: [msgpack] (php_msgpack_unserialize) Insufficient data for unserializing in %s018.php on line %d wrong 82c0a34f706a bool(false) OK msgpack-0.5.5/tests/019.phpt0000644000077100007710000000143612110565607015403 0ustar xinchenxinchen--TEST-- Object test, __autoload --SKIPIF-- --FILE-- b == 2 ? 'OK' : 'ERROR', PHP_EOL; } function __autoload($classname) { class Obj { var $a; var $b; function __construct($a, $b) { $this->a = $a; $this->b = $b; } } } test('autoload', '83c0a34f626aa16101a16202', false); ?> --EXPECTF-- autoload 83c0a34f626aa16101a16202 object(Obj)#%d (2) { ["a"]=> int(1) ["b"]=> int(2) } OK msgpack-0.5.5/tests/020.phpt0000644000077100007710000000113612110565607015370 0ustar xinchenxinchen--TEST-- Object test, incomplete class --SKIPIF-- --FILE-- --EXPECTF-- incom 83c0a34f626aa16101a16202 object(__PHP_Incomplete_Class)#%d (3) { ["__PHP_Incomplete_Class_Name"]=> string(3) "Obj" ["a"]=> int(1) ["b"]=> int(2) } msgpack-0.5.5/tests/021.phpt0000644000077100007710000000211712110565607015371 0ustar xinchenxinchen--TEST-- Object Serializable interface --SKIPIF-- a = $a; $this->b = $b; } public function serialize() { return pack('NN', $this->a, $this->b); } public function unserialize($serialized) { $tmp = unpack('N*', $serialized); $this->__construct($tmp[1], $tmp[2]); } } $o = new Obj(1, 2); test('object', $o, false); ?> --EXPECTF-- object 82c003a34f626aa80000000100000002 object(Obj)#%d (2) { ["a"]=> int(1) ["b"]=> int(2) } OK msgpack-0.5.5/tests/022.phpt0000644000077100007710000000152612110565607015375 0ustar xinchenxinchen--TEST-- Object test, unserialize_callback_func --SKIPIF-- --INI-- unserialize_callback_func=autoload --FILE-- b == 2 ? 'OK' : 'ERROR', PHP_EOL; } function autoload($classname) { class Obj { var $a; var $b; function __construct($a, $b) { $this->a = $a; $this->b = $b; } } } test('autoload', '83c0a34f626aa16101a16202', false); ?> --EXPECTF-- autoload 83c0a34f626aa16101a16202 object(Obj)#%d (2) { ["a"]=> int(1) ["b"]=> int(2) } OK msgpack-0.5.5/tests/023.phpt0000644000077100007710000000144112110565607015372 0ustar xinchenxinchen--TEST-- Resource --SKIPIF-- --FILE-- --EXPECT-- resource c0 NULL OK msgpack-0.5.5/tests/024.phpt0000644000077100007710000000645012110565607015400 0ustar xinchenxinchen--TEST-- Recursive objects --SKIPIF-- = 0 && version_compare(PHP_VERSION, '5.3.2') <= 0)) { echo "skip tests in PHP 5.2.14/5.3.3 or newer"; } --FILE-- a = $a; $this->b = $b; $this->c = $c; } } class Obj2 { public $aa; protected $bb; private $cc; private $obj; function __construct($a, $b, $c) { $this->a = $a; $this->b = $b; $this->c = $c; $this->obj = new Obj($a, $b, $c); } } class Obj3 { private $objs; function __construct($a, $b, $c) { $this->objs = array(); for ($i = $a; $i < $c; $i += $b) { $this->objs[] = new Obj($a, $i, $c); } } } class Obj4 { private $a; private $obj; function __construct($a) { $this->a = $a; } public function set($obj) { $this->obj = $obj; } } $o2 = new Obj2(1, 2, 3); test('objectrec', $o2, false); $o3 = new Obj3(0, 1, 4); test('objectrecarr', $o3, false); $o4 = new Obj4(100); $o4->set($o4); test('objectselfrec', $o4, true); ?> --EXPECTF-- objectrec 88c0a44f626a32a26161c0a5002a006262c0a8004f626a32006363c0a9004f626a32006f626a84c0a34f626aa16101a4002a006202a6004f626a006303a16101a16202a16303 object(Obj2)#%d (7) { ["aa"]=> NULL [%r"?bb"?:protected"?%r]=> NULL [%r"?cc"?:("Obj2":)?private"?%r]=> NULL [%r"?obj"?:("Obj2":)?private"?%r]=> object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } ["a"]=> int(1) ["b"]=> int(2) ["c"]=> int(3) } OK objectrecarr 82c0a44f626a33aa004f626a33006f626a739484c0a34f626aa16100a4002a006200a6004f626a00630484c0a34f626aa16100a4002a006201a6004f626a00630484c0a34f626aa16100a4002a006202a6004f626a00630484c0a34f626aa16100a4002a006203a6004f626a006304 object(Obj3)#%d (1) { [%r"?objs"?:("Obj3":)?private"?%r]=> array(4) { [0]=> object(Obj)#%d (3) { ["a"]=> int(0) [%r"?b"?:protected"?%r]=> int(0) [%r"?c"?:("Obj":)?private"?%r]=> int(4) } [1]=> object(Obj)#%d (3) { ["a"]=> int(0) [%r"?b"?:protected"?%r]=> int(1) [%r"?c"?:("Obj":)?private"?%r]=> int(4) } [2]=> object(Obj)#%d (3) { ["a"]=> int(0) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(4) } [3]=> object(Obj)#%d (3) { ["a"]=> int(0) [%r"?b"?:protected"?%r]=> int(3) [%r"?c"?:("Obj":)?private"?%r]=> int(4) } } } OK objectselfrec 83c0a44f626a34a7004f626a34006164a9004f626a34006f626a82c0040001 object(Obj4)#%d (2) { [%r"?a"?:("Obj4":)?private"?%r]=> int(100) [%r"?obj"?:("Obj4":)?private"?%r]=> *RECURSION* } OK msgpack-0.5.5/tests/024b.phpt0000644000077100007710000000677612110565607015555 0ustar xinchenxinchen--TEST-- Recursive objects --SKIPIF-- = 0) || (version_compare(PHP_VERSION, '5.3.3') >= 0)) { echo "skip tests in PHP 5.2.13/5.3.2 or older"; } if (version_compare(PHP_VERSION, '5.2.0') < 0) { echo "skip tests in PHP 5.2 or newer"; } --FILE-- a = $a; $this->b = $b; $this->c = $c; } } class Obj2 { public $aa; protected $bb; private $cc; private $obj; function __construct($a, $b, $c) { $this->a = $a; $this->b = $b; $this->c = $c; $this->obj = new Obj($a, $b, $c); } } class Obj3 { private $objs; function __construct($a, $b, $c) { $this->objs = array(); for ($i = $a; $i < $c; $i += $b) { $this->objs[] = new Obj($a, $i, $c); } } } class Obj4 { private $a; private $obj; function __construct($a) { $this->a = $a; } public function set($obj) { $this->obj = $obj; } } $o2 = new Obj2(1, 2, 3); test('objectrec', $o2, false); $o3 = new Obj3(0, 1, 4); test('objectrecarr', $o3, false); $o4 = new Obj4(100); $o4->set($o4); test('objectselfrec', $o4, true); ?> --EXPECTF-- objectrec 88c0a44f626a32a26161c0a5002a006262c0a8004f626a32006363c0a9004f626a32006f626a84c0a34f626aa16101a4002a006202a6004f626a006303a16101a16202a16303 object(Obj2)#%d (7) { ["aa"]=> NULL [%r"?bb"?:protected"?%r]=> NULL [%r"?cc"?:("Obj2":)?private"?%r]=> NULL [%r"?obj"?:("Obj2":)?private"?%r]=> object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } ["a"]=> int(1) ["b"]=> int(2) ["c"]=> int(3) } OK objectrecarr 82c0a44f626a33aa004f626a33006f626a739484c0a34f626aa16100a4002a006200a6004f626a00630484c0a34f626aa16100a4002a006201a6004f626a00630484c0a34f626aa16100a4002a006202a6004f626a00630484c0a34f626aa16100a4002a006203a6004f626a006304 object(Obj3)#%d (1) { [%r"?objs"?:("Obj3":)?private"?%r]=> array(4) { [0]=> object(Obj)#%d (3) { ["a"]=> int(0) [%r"?b"?:protected"?%r]=> int(0) [%r"?c"?:("Obj":)?private"?%r]=> int(4) } [1]=> object(Obj)#%d (3) { ["a"]=> int(0) [%r"?b"?:protected"?%r]=> int(1) [%r"?c"?:("Obj":)?private"?%r]=> int(4) } [2]=> object(Obj)#%d (3) { ["a"]=> int(0) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(4) } [3]=> object(Obj)#%d (3) { ["a"]=> int(0) [%r"?b"?:protected"?%r]=> int(3) [%r"?c"?:("Obj":)?private"?%r]=> int(4) } } } OK objectselfrec 83c0a44f626a34a7004f626a34006164a9004f626a34006f626a82c0040001 object(Obj4)#%d (2) { [%r"?a"?:("Obj4":)?private"?%r]=> int(100) [%r"?obj"?:("Obj4":)?private"?%r]=> object(Obj4)#%d (2) { [%r"?a"?:("Obj4":)?private"?%r]=> int(100) [%r"?obj"?:("Obj4":)?private"?%r]=> *RECURSION* } } OK msgpack-0.5.5/tests/024c.phpt0000644000077100007710000000605312110565607015542 0ustar xinchenxinchen--TEST-- Recursive objects --SKIPIF-- = 0) { echo "skip tests in PHP 5.1 or older"; } --FILE-- a = $a; $this->b = $b; $this->c = $c; } } class Obj2 { public $aa; protected $bb; private $cc; private $obj; function __construct($a, $b, $c) { $this->a = $a; $this->b = $b; $this->c = $c; $this->obj = new Obj($a, $b, $c); } } class Obj3 { private $objs; function __construct($a, $b, $c) { $this->objs = array(); for ($i = $a; $i < $c; $i += $b) { $this->objs[] = new Obj($a, $i, $c); } } } class Obj4 { private $a; private $obj; function __construct($a) { $this->a = $a; } public function set($obj) { $this->obj = $obj; } } $o2 = new Obj2(1, 2, 3); test('objectrec', $o2, false); $o3 = new Obj3(0, 1, 4); test('objectrecarr', $o3, false); $o4 = new Obj4(100); $o4->set($o4); test('objectselfrec', $o4, true); ?> --EXPECTF-- objectrec 88c0a44f626a32a26161c0a5002a006262c0a8004f626a32006363c0a9004f626a32006f626a84c0a34f626aa16101a4002a006202a6004f626a006303a16101a16202a16303 object(Obj2)#%d (7) { ["aa"]=> NULL ["bb:protected"]=> NULL ["cc:private"]=> NULL ["obj:private"]=> object(Obj)#%d (3) { ["a"]=> int(1) ["b:protected"]=> int(2) ["c:private"]=> int(3) } ["a"]=> int(1) ["b"]=> int(2) ["c"]=> int(3) } OK objectrecarr 82c0a44f626a33aa004f626a33006f626a739484c0a34f626aa16100a4002a006200a6004f626a00630484c0a34f626aa16100a4002a006201a6004f626a00630484c0a34f626aa16100a4002a006202a6004f626a00630484c0a34f626aa16100a4002a006203a6004f626a006304 object(Obj3)#%d (1) { ["objs:private"]=> array(4) { [0]=> object(Obj)#%d (3) { ["a"]=> int(0) ["b:protected"]=> int(0) ["c:private"]=> int(4) } [1]=> object(Obj)#%d (3) { ["a"]=> int(0) ["b:protected"]=> int(1) ["c:private"]=> int(4) } [2]=> object(Obj)#%d (3) { ["a"]=> int(0) ["b:protected"]=> int(2) ["c:private"]=> int(4) } [3]=> object(Obj)#%d (3) { ["a"]=> int(0) ["b:protected"]=> int(3) ["c:private"]=> int(4) } } } OK objectselfrec 83c0a44f626a34a7004f626a34006164a9004f626a34006f626a82c0040001 object(Obj4)#%d (2) { ["a:private"]=> int(100) ["obj:private"]=> object(Obj4)#%d (2) { ["a:private"]=> int(100) ["obj:private"]=> *RECURSION* } } OK msgpack-0.5.5/tests/025.phpt0000644000077100007710000000413112110565607015373 0ustar xinchenxinchen--TEST-- Object test, array of objects with __sleep --SKIPIF-- a = $a; $this->b = $b; $this->c = $c; $this->d = $d; } function __sleep() { return array('a', 'b', 'c'); } # function __wakeup() { # $this->d = $this->a + $this->b + $this->c; # } } $array = array( new Obj("aa", "bb", "cc", "dd"), new Obj("ee", "ff", "gg", "hh"), new Obj(1, 2, 3, 4), ); test('array', $array, true); ?> --EXPECTF-- array(3) { [0]=> object(Obj)#1 (4) { ["a"]=> string(2) "aa" [%r"?b"?:protected"?%r]=> string(2) "bb" [%r"?c"?:("Obj":)?private"?%r]=> string(2) "cc" ["d"]=> string(2) "dd" } [1]=> object(Obj)#2 (4) { ["a"]=> string(2) "ee" [%r"?b"?:protected"?%r]=> string(2) "ff" [%r"?c"?:("Obj":)?private"?%r]=> string(2) "gg" ["d"]=> string(2) "hh" } [2]=> object(Obj)#3 (4) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) ["d"]=> int(4) } } array(3) { [0]=> object(Obj)#4 (4) { ["a"]=> string(2) "aa" [%r"?b"?:protected"?%r]=> string(2) "bb" [%r"?c"?:("Obj":)?private"?%r]=> string(2) "cc" ["d"]=> NULL } [1]=> object(Obj)#5 (4) { ["a"]=> string(2) "ee" [%r"?b"?:protected"?%r]=> string(2) "ff" [%r"?c"?:("Obj":)?private"?%r]=> string(2) "gg" ["d"]=> NULL } [2]=> object(Obj)#6 (4) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) ["d"]=> NULL } } msgpack-0.5.5/tests/025c.phpt0000644000077100007710000000370412110565607015543 0ustar xinchenxinchen--TEST-- Object test, array of objects with __sleep --SKIPIF-- = 0) { echo "skip tests in PHP 5.1 or older"; } --FILE-- a = $a; $this->b = $b; $this->c = $c; $this->d = $d; } function __sleep() { return array('a', 'b', 'c'); } # function __wakeup() { # $this->d = $this->a + $this->b + $this->c; # } } $array = array( new Obj("aa", "bb", "cc", "dd"), new Obj("ee", "ff", "gg", "hh"), new Obj(1, 2, 3, 4), ); test('array', $array, true); ?> --EXPECTF-- array(3) { [0]=> object(Obj)#1 (4) { ["a"]=> string(2) "aa" ["b:protected"]=> string(2) "bb" ["c:private"]=> string(2) "cc" ["d"]=> string(2) "dd" } [1]=> object(Obj)#2 (4) { ["a"]=> string(2) "ee" ["b:protected"]=> string(2) "ff" ["c:private"]=> string(2) "gg" ["d"]=> string(2) "hh" } [2]=> object(Obj)#3 (4) { ["a"]=> int(1) ["b:protected"]=> int(2) ["c:private"]=> int(3) ["d"]=> int(4) } } array(3) { [0]=> object(Obj)#4 (4) { ["a"]=> string(2) "aa" ["b:protected"]=> string(2) "bb" ["c:private"]=> string(2) "cc" ["d"]=> NULL } [1]=> object(Obj)#5 (4) { ["a"]=> string(2) "ee" ["b:protected"]=> string(2) "ff" ["c:private"]=> string(2) "gg" ["d"]=> NULL } [2]=> object(Obj)#6 (4) { ["a"]=> int(1) ["b:protected"]=> int(2) ["c:private"]=> int(3) ["d"]=> NULL } } msgpack-0.5.5/tests/026.phpt0000644000077100007710000000326212110565607015400 0ustar xinchenxinchen--TEST-- Cyclic array test --INI-- --SKIPIF-- = 0 && version_compare(PHP_VERSION, '5.3.2') <= 0)) { echo "skip tests in PHP 5.2.14/5.3.3 or newer"; } --FILE-- array( 'b' => 'c', 'd' => 'e' ), ); $a['f'] = &$a; test('array', $a, true); $a = array("foo" => &$b); $b = array(1, 2, $a); var_dump($a); var_dump($k = msgpack_unserialize(msgpack_serialize($a))); $k["foo"][1] = "b"; var_dump($k); ?> --EXPECT-- array 82a16182a162a163a164a165a16683c001a16182a162a163a164a165a16682c0020003 array(2) { ["a"]=> array(2) { ["b"]=> string(1) "c" ["d"]=> string(1) "e" } ["f"]=> &array(2) { ["a"]=> array(2) { ["b"]=> string(1) "c" ["d"]=> string(1) "e" } ["f"]=> *RECURSION* } } OK array(1) { ["foo"]=> &array(3) { [0]=> int(1) [1]=> int(2) [2]=> *RECURSION* } } array(1) { ["foo"]=> &array(3) { [0]=> int(1) [1]=> int(2) [2]=> array(1) { ["foo"]=> *RECURSION* } } } array(1) { ["foo"]=> &array(3) { [0]=> int(1) [1]=> string(1) "b" [2]=> array(1) { ["foo"]=> *RECURSION* } } } msgpack-0.5.5/tests/026b.phpt0000644000077100007710000000455012110565607015543 0ustar xinchenxinchen--TEST-- Cyclic array test --INI-- --SKIPIF-- = 0) || (version_compare(PHP_VERSION, '5.3.3') >= 0)) { echo "skip tests in PHP 5.2.13/5.3.2 or older"; } if (version_compare(PHP_VERSION, '5.1.0') < 0) { echo "skip tests in PHP 5.1 or newer"; } --FILE-- array( 'b' => 'c', 'd' => 'e' ), ); $a['f'] = &$a; test('array', $a, true); $a = array("foo" => &$b); $b = array(1, 2, $a); var_dump($a); var_dump($k = msgpack_unserialize(msgpack_serialize($a))); $k["foo"][1] = "b"; var_dump($k); ?> --EXPECT-- array 82a16182a162a163a164a165a16683c001a16182a162a163a164a165a16682c0020003 array(2) { ["a"]=> array(2) { ["b"]=> string(1) "c" ["d"]=> string(1) "e" } ["f"]=> &array(2) { ["a"]=> array(2) { ["b"]=> string(1) "c" ["d"]=> string(1) "e" } ["f"]=> &array(2) { ["a"]=> array(2) { ["b"]=> string(1) "c" ["d"]=> string(1) "e" } ["f"]=> *RECURSION* } } } OK array(1) { ["foo"]=> &array(3) { [0]=> int(1) [1]=> int(2) [2]=> array(1) { ["foo"]=> &array(3) { [0]=> int(1) [1]=> int(2) [2]=> *RECURSION* } } } } array(1) { ["foo"]=> &array(3) { [0]=> int(1) [1]=> int(2) [2]=> array(1) { ["foo"]=> &array(3) { [0]=> int(1) [1]=> int(2) [2]=> array(1) { ["foo"]=> *RECURSION* } } } } } array(1) { ["foo"]=> &array(3) { [0]=> int(1) [1]=> string(1) "b" [2]=> array(1) { ["foo"]=> &array(3) { [0]=> int(1) [1]=> string(1) "b" [2]=> array(1) { ["foo"]=> *RECURSION* } } } } } msgpack-0.5.5/tests/026d.phpt0000644000077100007710000000423712110565607015547 0ustar xinchenxinchen--TEST-- Cyclic array test --INI-- --SKIPIF-- = 0) { echo "skip tests in PHP 5.0 or older"; } --FILE-- array( 'b' => 'c', 'd' => 'e' ), ); $a['f'] = &$a; test('array', $a, true); $a = array("foo" => &$b); $b = array(1, 2, $a); var_dump($a); var_dump($k = msgpack_unserialize(msgpack_serialize($a))); $k["foo"][1] = "b"; var_dump($k); ?> --EXPECT-- array 82a16182a162a163a164a165a16682a16182a162a163a164a165a16682a16182a162a163a164a165a166c0 array(2) { ["a"]=> array(2) { ["b"]=> string(1) "c" ["d"]=> string(1) "e" } ["f"]=> array(2) { ["a"]=> array(2) { ["b"]=> string(1) "c" ["d"]=> string(1) "e" } ["f"]=> array(2) { ["a"]=> array(2) { ["b"]=> string(1) "c" ["d"]=> string(1) "e" } ["f"]=> NULL } } } OK array(1) { ["foo"]=> &array(3) { [0]=> int(1) [1]=> int(2) [2]=> array(1) { ["foo"]=> &array(3) { [0]=> int(1) [1]=> int(2) [2]=> *RECURSION* } } } } array(1) { ["foo"]=> &array(3) { [0]=> int(1) [1]=> int(2) [2]=> array(1) { ["foo"]=> &array(3) { [0]=> int(1) [1]=> int(2) [2]=> array(1) { ["foo"]=> *RECURSION* } } } } } array(1) { ["foo"]=> &array(3) { [0]=> int(1) [1]=> string(1) "b" [2]=> array(1) { ["foo"]=> &array(3) { [0]=> int(1) [1]=> string(1) "b" [2]=> array(1) { ["foo"]=> *RECURSION* } } } } } msgpack-0.5.5/tests/027.phpt0000644000077100007710000000233512110565607015401 0ustar xinchenxinchen--TEST-- Check for serialization handler --SKIPIF-- --EXPECT-- bool(true) read wrote: 83c001a3666f6f01a474657374a6666f6f626172 array(2) { ["foo"]=> int(1) ["test"]=> string(6) "foobar" } msgpack-0.5.5/tests/027d.phpt0000644000077100007710000000221612110565607015543 0ustar xinchenxinchen--TEST-- Check for serialization handler --SKIPIF-- = 0) { echo "skip tests in PHP 5.2 or older"; } --FILE-- --EXPECT-- bool(true) read wrote: 82a3666f6f01a474657374a6666f6f626172 array(2) { ["foo"]=> int(1) ["test"]=> string(6) "foobar" } msgpack-0.5.5/tests/028.phpt0000644000077100007710000000700612110565607015402 0ustar xinchenxinchen--TEST-- Serialize object into session, full set --SKIPIF-- = 0 && version_compare(PHP_VERSION, '5.3.2') <= 0)) { echo "skip tests in PHP 5.2.14/5.3.3 or newer"; } if (!extension_loaded("session")) { echo "skip needs session enabled"; } --FILE-- d1 = $foo; $this->d2 = $foo; $this->d3 = $foo; } } class Bar { private static $s1 = array(); protected static $s2 = array(); public static $s3 = array(); public $d1; private $d2; protected $d3; public function __construct() { } public function set($foo) { $this->d1 = $foo; $this->d2 = $foo; $this->d3 = $foo; } } $output = ''; function open($path, $name) { return true; } function close() { return true; } function read($id) { global $output; $output .= "read" . PHP_EOL; $a = new Bar(); $b = new Foo($a); $a->set($b); $session = array('old' => $b); return msgpack_serialize($session); } function write($id, $data) { global $output; $output .= "write: "; $output .= bin2hex($data) . PHP_EOL; return true; } function destroy($id) { return true; } function gc($time) { return true; } ini_set('session.serialize_handler', 'msgpack'); session_set_save_handler('open', 'close', 'read', 'write', 'destroy', 'gc'); session_start(); $_SESSION['test'] = "foobar"; $a = new Bar(); $b = new Foo($a); $a->set($b); $_SESSION['new'] = $a; session_write_close(); echo $output; var_dump($_SESSION); ?> --EXPECTF-- read write: 84c001a36f6c6484c0a3466f6fa700466f6f00643184c0a3426172a2643182c0040002a70042617200643282c0040002a5002a00643382c0040002a5002a00643282c0040003a2643382c0040003a474657374a6666f6f626172a36e657784c0a3426172a2643184c0a3466f6fa700466f6f00643182c0040009a5002a00643282c0040009a2643382c0040009a70042617200643282c004000aa5002a00643382c004000a array(3) { ["old"]=> object(Foo)#3 (3) { [%r"?d1"?:("Foo":)?private"?%r]=> object(Bar)#4 (3) { ["d1"]=> *RECURSION* [%r"?d2"?:("Bar":)?private"?%r]=> *RECURSION* [%r"?d3"?:protected"?%r]=> *RECURSION* } [%r"?d2"?:protected"?%r]=> object(Bar)#4 (3) { ["d1"]=> *RECURSION* [%r"?d2"?:("Bar":)?private"?%r]=> *RECURSION* [%r"?d3"?:protected"?%r]=> *RECURSION* } ["d3"]=> object(Bar)#4 (3) { ["d1"]=> *RECURSION* [%r"?d2"?:("Bar":)?private"?%r]=> *RECURSION* [%r"?d3"?:protected"?%r]=> *RECURSION* } } ["test"]=> string(6) "foobar" ["new"]=> object(Bar)#5 (3) { ["d1"]=> object(Foo)#6 (3) { [%r"?d1"?:("Foo":)?private"?%r]=> *RECURSION* [%r"?d2"?:protected"?%r]=> *RECURSION* ["d3"]=> *RECURSION* } [%r"?d2"?:("Bar":)?private"?%r]=> object(Foo)#6 (3) { [%r"?d1"?:("Foo":)?private"?%r]=> *RECURSION* [%r"?d2"?:protected"?%r]=> *RECURSION* ["d3"]=> *RECURSION* } [%r"?d3"?:protected"?%r]=> object(Foo)#6 (3) { [%r"?d1"?:("Foo":)?private"?%r]=> *RECURSION* [%r"?d2"?:protected"?%r]=> *RECURSION* ["d3"]=> *RECURSION* } } } msgpack-0.5.5/tests/028b.phpt0000644000077100007710000004033312110565607015544 0ustar xinchenxinchen--TEST-- Serialize object into session, full set --SKIPIF-- = 0) || (version_compare(PHP_VERSION, '5.3.3') >= 0)) { echo "skip tests in PHP 5.2.13/5.3.2 or older"; } if (version_compare(PHP_VERSION, '5.2.0') < 0) { echo "skip tests in PHP 5.2 or newer"; } --FILE-- d1 = $foo; $this->d2 = $foo; $this->d3 = $foo; } } class Bar { private static $s1 = array(); protected static $s2 = array(); public static $s3 = array(); public $d1; private $d2; protected $d3; public function __construct() { } public function set($foo) { $this->d1 = $foo; $this->d2 = $foo; $this->d3 = $foo; } } $output = ''; function open($path, $name) { return true; } function close() { return true; } function read($id) { global $output; $output .= "read" . PHP_EOL; $a = new Bar(); $b = new Foo($a); $a->set($b); $session = array('old' => $b); return msgpack_serialize($session); } function write($id, $data) { global $output; $output .= "write: "; $output .= bin2hex($data) . PHP_EOL; return true; } function destroy($id) { return true; } function gc($time) { return true; } ini_set('session.serialize_handler', 'msgpack'); session_set_save_handler('open', 'close', 'read', 'write', 'destroy', 'gc'); session_start(); $_SESSION['test'] = "foobar"; $a = new Bar(); $b = new Foo($a); $a->set($b); $_SESSION['new'] = $a; session_write_close(); echo $output; var_dump($_SESSION); ?> --EXPECTF-- read write: 84c001a36f6c6484c0a3466f6fa700466f6f00643184c0a3426172a2643182c0040002a70042617200643282c0040002a5002a00643382c0040002a5002a00643282c0040003a2643382c0040003a474657374a6666f6f626172a36e657784c0a3426172a2643184c0a3466f6fa700466f6f00643182c0040009a5002a00643282c0040009a2643382c0040009a70042617200643282c004000aa5002a00643382c004000a array(3) { ["old"]=> object(Foo)#3 (3) { [%r"?d1"?:("Foo":)?private"?%r]=> object(Bar)#4 (3) { ["d1"]=> object(Foo)#3 (3) { [%r"?d1"?:("Foo":)?private"?%r]=> object(Bar)#4 (3) { ["d1"]=> *RECURSION* [%r"?d2"?:("Bar":)?private"?%r]=> *RECURSION* [%r"?d3"?:protected"?%r]=> *RECURSION* } [%r"?d2"?:protected"?%r]=> object(Bar)#4 (3) { ["d1"]=> *RECURSION* [%r"?d2"?:("Bar":)?private"?%r]=> *RECURSION* [%r"?d3"?:protected"?%r]=> *RECURSION* } ["d3"]=> object(Bar)#4 (3) { ["d1"]=> *RECURSION* [%r"?d2"?:("Bar":)?private"?%r]=> *RECURSION* [%r"?d3"?:protected"?%r]=> *RECURSION* } } [%r"?d2"?:("Bar":)?private"?%r]=> object(Foo)#3 (3) { [%r"?d1"?:("Foo":)?private"?%r]=> object(Bar)#4 (3) { ["d1"]=> *RECURSION* [%r"?d2"?:("Bar":)?private"?%r]=> *RECURSION* [%r"?d3"?:protected"?%r]=> *RECURSION* } [%r"?d2"?:protected"?%r]=> object(Bar)#4 (3) { ["d1"]=> *RECURSION* [%r"?d2"?:("Bar":)?private"?%r]=> *RECURSION* [%r"?d3"?:protected"?%r]=> *RECURSION* } ["d3"]=> object(Bar)#4 (3) { ["d1"]=> *RECURSION* [%r"?d2"?:("Bar":)?private"?%r]=> *RECURSION* [%r"?d3"?:protected"?%r]=> *RECURSION* } } [%r"?d3"?:protected"?%r]=> object(Foo)#3 (3) { [%r"?d1"?:("Foo":)?private"?%r]=> object(Bar)#4 (3) { ["d1"]=> *RECURSION* [%r"?d2"?:("Bar":)?private"?%r]=> *RECURSION* [%r"?d3"?:protected"?%r]=> *RECURSION* } [%r"?d2"?:protected"?%r]=> object(Bar)#4 (3) { ["d1"]=> *RECURSION* [%r"?d2"?:("Bar":)?private"?%r]=> *RECURSION* [%r"?d3"?:protected"?%r]=> *RECURSION* } ["d3"]=> object(Bar)#4 (3) { ["d1"]=> *RECURSION* [%r"?d2"?:("Bar":)?private"?%r]=> *RECURSION* [%r"?d3"?:protected"?%r]=> *RECURSION* } } } [%r"?d2"?:protected"?%r]=> object(Bar)#4 (3) { ["d1"]=> object(Foo)#3 (3) { [%r"?d1"?:("Foo":)?private"?%r]=> object(Bar)#4 (3) { ["d1"]=> *RECURSION* [%r"?d2"?:("Bar":)?private"?%r]=> *RECURSION* [%r"?d3"?:protected"?%r]=> *RECURSION* } [%r"?d2"?:protected"?%r]=> object(Bar)#4 (3) { ["d1"]=> *RECURSION* [%r"?d2"?:("Bar":)?private"?%r]=> *RECURSION* [%r"?d3"?:protected"?%r]=> *RECURSION* } ["d3"]=> object(Bar)#4 (3) { ["d1"]=> *RECURSION* [%r"?d2"?:("Bar":)?private"?%r]=> *RECURSION* [%r"?d3"?:protected"?%r]=> *RECURSION* } } [%r"?d2"?:("Bar":)?private"?%r]=> object(Foo)#3 (3) { [%r"?d1"?:("Foo":)?private"?%r]=> object(Bar)#4 (3) { ["d1"]=> *RECURSION* [%r"?d2"?:("Bar":)?private"?%r]=> *RECURSION* [%r"?d3"?:protected"?%r]=> *RECURSION* } [%r"?d2"?:protected"?%r]=> object(Bar)#4 (3) { ["d1"]=> *RECURSION* [%r"?d2"?:("Bar":)?private"?%r]=> *RECURSION* [%r"?d3"?:protected"?%r]=> *RECURSION* } ["d3"]=> object(Bar)#4 (3) { ["d1"]=> *RECURSION* [%r"?d2"?:("Bar":)?private"?%r]=> *RECURSION* [%r"?d3"?:protected"?%r]=> *RECURSION* } } [%r"?d3"?:protected"?%r]=> object(Foo)#3 (3) { [%r"?d1"?:("Foo":)?private"?%r]=> object(Bar)#4 (3) { ["d1"]=> *RECURSION* [%r"?d2"?:("Bar":)?private"?%r]=> *RECURSION* [%r"?d3"?:protected"?%r]=> *RECURSION* } [%r"?d2"?:protected"?%r]=> object(Bar)#4 (3) { ["d1"]=> *RECURSION* [%r"?d2"?:("Bar":)?private"?%r]=> *RECURSION* [%r"?d3"?:protected"?%r]=> *RECURSION* } ["d3"]=> object(Bar)#4 (3) { ["d1"]=> *RECURSION* [%r"?d2"?:("Bar":)?private"?%r]=> *RECURSION* [%r"?d3"?:protected"?%r]=> *RECURSION* } } } ["d3"]=> object(Bar)#4 (3) { ["d1"]=> object(Foo)#3 (3) { [%r"?d1"?:("Foo":)?private"?%r]=> object(Bar)#4 (3) { ["d1"]=> *RECURSION* [%r"?d2"?:("Bar":)?private"?%r]=> *RECURSION* [%r"?d3"?:protected"?%r]=> *RECURSION* } [%r"?d2"?:protected"?%r]=> object(Bar)#4 (3) { ["d1"]=> *RECURSION* [%r"?d2"?:("Bar":)?private"?%r]=> *RECURSION* [%r"?d3"?:protected"?%r]=> *RECURSION* } ["d3"]=> object(Bar)#4 (3) { ["d1"]=> *RECURSION* [%r"?d2"?:("Bar":)?private"?%r]=> *RECURSION* [%r"?d3"?:protected"?%r]=> *RECURSION* } } [%r"?d2"?:("Bar":)?private"?%r]=> object(Foo)#3 (3) { [%r"?d1"?:("Foo":)?private"?%r]=> object(Bar)#4 (3) { ["d1"]=> *RECURSION* [%r"?d2"?:("Bar":)?private"?%r]=> *RECURSION* [%r"?d3"?:protected"?%r]=> *RECURSION* } [%r"?d2"?:protected"?%r]=> object(Bar)#4 (3) { ["d1"]=> *RECURSION* [%r"?d2"?:("Bar":)?private"?%r]=> *RECURSION* [%r"?d3"?:protected"?%r]=> *RECURSION* } ["d3"]=> object(Bar)#4 (3) { ["d1"]=> *RECURSION* [%r"?d2"?:("Bar":)?private"?%r]=> *RECURSION* [%r"?d3"?:protected"?%r]=> *RECURSION* } } [%r"?d3"?:protected"?%r]=> object(Foo)#3 (3) { [%r"?d1"?:("Foo":)?private"?%r]=> object(Bar)#4 (3) { ["d1"]=> *RECURSION* [%r"?d2"?:("Bar":)?private"?%r]=> *RECURSION* [%r"?d3"?:protected"?%r]=> *RECURSION* } [%r"?d2"?:protected"?%r]=> object(Bar)#4 (3) { ["d1"]=> *RECURSION* [%r"?d2"?:("Bar":)?private"?%r]=> *RECURSION* [%r"?d3"?:protected"?%r]=> *RECURSION* } ["d3"]=> object(Bar)#4 (3) { ["d1"]=> *RECURSION* [%r"?d2"?:("Bar":)?private"?%r]=> *RECURSION* [%r"?d3"?:protected"?%r]=> *RECURSION* } } } } ["test"]=> string(6) "foobar" ["new"]=> object(Bar)#5 (3) { ["d1"]=> object(Foo)#6 (3) { [%r"?d1"?:("Foo":)?private"?%r]=> object(Bar)#5 (3) { ["d1"]=> object(Foo)#6 (3) { [%r"?d1"?:("Foo":)?private"?%r]=> *RECURSION* [%r"?d2"?:protected"?%r]=> *RECURSION* ["d3"]=> *RECURSION* } [%r"?d2"?:("Bar":)?private"?%r]=> object(Foo)#6 (3) { [%r"?d1"?:("Foo":)?private"?%r]=> *RECURSION* [%r"?d2"?:protected"?%r]=> *RECURSION* ["d3"]=> *RECURSION* } [%r"?d3"?:protected"?%r]=> object(Foo)#6 (3) { [%r"?d1"?:("Foo":)?private"?%r]=> *RECURSION* [%r"?d2"?:protected"?%r]=> *RECURSION* ["d3"]=> *RECURSION* } } [%r"?d2"?:protected"?%r]=> object(Bar)#5 (3) { ["d1"]=> object(Foo)#6 (3) { [%r"?d1"?:("Foo":)?private"?%r]=> *RECURSION* [%r"?d2"?:protected"?%r]=> *RECURSION* ["d3"]=> *RECURSION* } [%r"?d2"?:("Bar":)?private"?%r]=> object(Foo)#6 (3) { [%r"?d1"?:("Foo":)?private"?%r]=> *RECURSION* [%r"?d2"?:protected"?%r]=> *RECURSION* ["d3"]=> *RECURSION* } [%r"?d3"?:protected"?%r]=> object(Foo)#6 (3) { [%r"?d1"?:("Foo":)?private"?%r]=> *RECURSION* [%r"?d2"?:protected"?%r]=> *RECURSION* ["d3"]=> *RECURSION* } } ["d3"]=> object(Bar)#5 (3) { ["d1"]=> object(Foo)#6 (3) { [%r"?d1"?:("Foo":)?private"?%r]=> *RECURSION* [%r"?d2"?:protected"?%r]=> *RECURSION* ["d3"]=> *RECURSION* } [%r"?d2"?:("Bar":)?private"?%r]=> object(Foo)#6 (3) { [%r"?d1"?:("Foo":)?private"?%r]=> *RECURSION* [%r"?d2"?:protected"?%r]=> *RECURSION* ["d3"]=> *RECURSION* } [%r"?d3"?:protected"?%r]=> object(Foo)#6 (3) { [%r"?d1"?:("Foo":)?private"?%r]=> *RECURSION* [%r"?d2"?:protected"?%r]=> *RECURSION* ["d3"]=> *RECURSION* } } } [%r"?d2"?:("Bar":)?private"?%r]=> object(Foo)#6 (3) { [%r"?d1"?:("Foo":)?private"?%r]=> object(Bar)#5 (3) { ["d1"]=> object(Foo)#6 (3) { [%r"?d1"?:("Foo":)?private"?%r]=> *RECURSION* [%r"?d2"?:protected"?%r]=> *RECURSION* ["d3"]=> *RECURSION* } [%r"?d2"?:("Bar":)?private"?%r]=> object(Foo)#6 (3) { [%r"?d1"?:("Foo":)?private"?%r]=> *RECURSION* [%r"?d2"?:protected"?%r]=> *RECURSION* ["d3"]=> *RECURSION* } [%r"?d3"?:protected"?%r]=> object(Foo)#6 (3) { [%r"?d1"?:("Foo":)?private"?%r]=> *RECURSION* [%r"?d2"?:protected"?%r]=> *RECURSION* ["d3"]=> *RECURSION* } } [%r"?d2"?:protected"?%r]=> object(Bar)#5 (3) { ["d1"]=> object(Foo)#6 (3) { [%r"?d1"?:("Foo":)?private"?%r]=> *RECURSION* [%r"?d2"?:protected"?%r]=> *RECURSION* ["d3"]=> *RECURSION* } [%r"?d2"?:("Bar":)?private"?%r]=> object(Foo)#6 (3) { [%r"?d1"?:("Foo":)?private"?%r]=> *RECURSION* [%r"?d2"?:protected"?%r]=> *RECURSION* ["d3"]=> *RECURSION* } [%r"?d3"?:protected"?%r]=> object(Foo)#6 (3) { [%r"?d1"?:("Foo":)?private"?%r]=> *RECURSION* [%r"?d2"?:protected"?%r]=> *RECURSION* ["d3"]=> *RECURSION* } } ["d3"]=> object(Bar)#5 (3) { ["d1"]=> object(Foo)#6 (3) { [%r"?d1"?:("Foo":)?private"?%r]=> *RECURSION* [%r"?d2"?:protected"?%r]=> *RECURSION* ["d3"]=> *RECURSION* } [%r"?d2"?:("Bar":)?private"?%r]=> object(Foo)#6 (3) { [%r"?d1"?:("Foo":)?private"?%r]=> *RECURSION* [%r"?d2"?:protected"?%r]=> *RECURSION* ["d3"]=> *RECURSION* } [%r"?d3"?:protected"?%r]=> object(Foo)#6 (3) { [%r"?d1"?:("Foo":)?private"?%r]=> *RECURSION* [%r"?d2"?:protected"?%r]=> *RECURSION* ["d3"]=> *RECURSION* } } } [%r"?d3"?:protected"?%r]=> object(Foo)#6 (3) { [%r"?d1"?:("Foo":)?private"?%r]=> object(Bar)#5 (3) { ["d1"]=> object(Foo)#6 (3) { [%r"?d1"?:("Foo":)?private"?%r]=> *RECURSION* [%r"?d2"?:protected"?%r]=> *RECURSION* ["d3"]=> *RECURSION* } [%r"?d2"?:("Bar":)?private"?%r]=> object(Foo)#6 (3) { [%r"?d1"?:("Foo":)?private"?%r]=> *RECURSION* [%r"?d2"?:protected"?%r]=> *RECURSION* ["d3"]=> *RECURSION* } [%r"?d3"?:protected"?%r]=> object(Foo)#6 (3) { [%r"?d1"?:("Foo":)?private"?%r]=> *RECURSION* [%r"?d2"?:protected"?%r]=> *RECURSION* ["d3"]=> *RECURSION* } } [%r"?d2"?:protected"?%r]=> object(Bar)#5 (3) { ["d1"]=> object(Foo)#6 (3) { [%r"?d1"?:("Foo":)?private"?%r]=> *RECURSION* [%r"?d2"?:protected"?%r]=> *RECURSION* ["d3"]=> *RECURSION* } [%r"?d2"?:("Bar":)?private"?%r]=> object(Foo)#6 (3) { [%r"?d1"?:("Foo":)?private"?%r]=> *RECURSION* [%r"?d2"?:protected"?%r]=> *RECURSION* ["d3"]=> *RECURSION* } [%r"?d3"?:protected"?%r]=> object(Foo)#6 (3) { [%r"?d1"?:("Foo":)?private"?%r]=> *RECURSION* [%r"?d2"?:protected"?%r]=> *RECURSION* ["d3"]=> *RECURSION* } } ["d3"]=> object(Bar)#5 (3) { ["d1"]=> object(Foo)#6 (3) { [%r"?d1"?:("Foo":)?private"?%r]=> *RECURSION* [%r"?d2"?:protected"?%r]=> *RECURSION* ["d3"]=> *RECURSION* } [%r"?d2"?:("Bar":)?private"?%r]=> object(Foo)#6 (3) { [%r"?d1"?:("Foo":)?private"?%r]=> *RECURSION* [%r"?d2"?:protected"?%r]=> *RECURSION* ["d3"]=> *RECURSION* } [%r"?d3"?:protected"?%r]=> object(Foo)#6 (3) { [%r"?d1"?:("Foo":)?private"?%r]=> *RECURSION* [%r"?d2"?:protected"?%r]=> *RECURSION* ["d3"]=> *RECURSION* } } } } } msgpack-0.5.5/tests/028c.phpt0000644000077100007710000003413712110565607015552 0ustar xinchenxinchen--TEST-- Serialize object into session, full set --SKIPIF-- = 0) { echo "skip tests in PHP 5.1"; } --FILE-- d1 = $foo; $this->d2 = $foo; $this->d3 = $foo; } } class Bar { private static $s1 = array(); protected static $s2 = array(); public static $s3 = array(); public $d1; private $d2; protected $d3; public function __construct() { } public function set($foo) { $this->d1 = $foo; $this->d2 = $foo; $this->d3 = $foo; } } $output = ''; function open($path, $name) { return true; } function close() { return true; } function read($id) { global $output; $output .= "read" . PHP_EOL; $a = new Bar(); $b = new Foo($a); $a->set($b); $session = array('old' => $b); return msgpack_serialize($session); } function write($id, $data) { global $output; $output .= "write: "; $output .= bin2hex($data) . PHP_EOL; return true; } function destroy($id) { return true; } function gc($time) { return true; } ini_set('session.serialize_handler', 'msgpack'); session_set_save_handler('open', 'close', 'read', 'write', 'destroy', 'gc'); session_start(); $_SESSION['test'] = "foobar"; $a = new Bar(); $b = new Foo($a); $a->set($b); $_SESSION['new'] = $a; session_write_close(); echo $output; var_dump($_SESSION); ?> --EXPECTF-- read write: 83a36f6c6484c0a3466f6fa700466f6f00643184c0a3426172a2643182c0040002a70042617200643282c0040002a5002a00643382c0040002a5002a00643282c0040003a2643382c0040003a474657374a6666f6f626172a36e657784c0a3426172a2643184c0a3466f6fa700466f6f00643182c0040009a5002a00643282c0040009a2643382c0040009a70042617200643282c004000aa5002a00643382c004000a array(3) { ["old"]=> object(Foo)#3 (3) { ["d1:private"]=> object(Bar)#4 (3) { ["d1"]=> object(Foo)#3 (3) { ["d1:private"]=> object(Bar)#4 (3) { ["d1"]=> *RECURSION* ["d2:private"]=> *RECURSION* ["d3:protected"]=> *RECURSION* } ["d2:protected"]=> object(Bar)#4 (3) { ["d1"]=> *RECURSION* ["d2:private"]=> *RECURSION* ["d3:protected"]=> *RECURSION* } ["d3"]=> object(Bar)#4 (3) { ["d1"]=> *RECURSION* ["d2:private"]=> *RECURSION* ["d3:protected"]=> *RECURSION* } } ["d2:private"]=> object(Foo)#3 (3) { ["d1:private"]=> object(Bar)#4 (3) { ["d1"]=> *RECURSION* ["d2:private"]=> *RECURSION* ["d3:protected"]=> *RECURSION* } ["d2:protected"]=> object(Bar)#4 (3) { ["d1"]=> *RECURSION* ["d2:private"]=> *RECURSION* ["d3:protected"]=> *RECURSION* } ["d3"]=> object(Bar)#4 (3) { ["d1"]=> *RECURSION* ["d2:private"]=> *RECURSION* ["d3:protected"]=> *RECURSION* } } ["d3:protected"]=> object(Foo)#3 (3) { ["d1:private"]=> object(Bar)#4 (3) { ["d1"]=> *RECURSION* ["d2:private"]=> *RECURSION* ["d3:protected"]=> *RECURSION* } ["d2:protected"]=> object(Bar)#4 (3) { ["d1"]=> *RECURSION* ["d2:private"]=> *RECURSION* ["d3:protected"]=> *RECURSION* } ["d3"]=> object(Bar)#4 (3) { ["d1"]=> *RECURSION* ["d2:private"]=> *RECURSION* ["d3:protected"]=> *RECURSION* } } } ["d2:protected"]=> object(Bar)#4 (3) { ["d1"]=> object(Foo)#3 (3) { ["d1:private"]=> object(Bar)#4 (3) { ["d1"]=> *RECURSION* ["d2:private"]=> *RECURSION* ["d3:protected"]=> *RECURSION* } ["d2:protected"]=> object(Bar)#4 (3) { ["d1"]=> *RECURSION* ["d2:private"]=> *RECURSION* ["d3:protected"]=> *RECURSION* } ["d3"]=> object(Bar)#4 (3) { ["d1"]=> *RECURSION* ["d2:private"]=> *RECURSION* ["d3:protected"]=> *RECURSION* } } ["d2:private"]=> object(Foo)#3 (3) { ["d1:private"]=> object(Bar)#4 (3) { ["d1"]=> *RECURSION* ["d2:private"]=> *RECURSION* ["d3:protected"]=> *RECURSION* } ["d2:protected"]=> object(Bar)#4 (3) { ["d1"]=> *RECURSION* ["d2:private"]=> *RECURSION* ["d3:protected"]=> *RECURSION* } ["d3"]=> object(Bar)#4 (3) { ["d1"]=> *RECURSION* ["d2:private"]=> *RECURSION* ["d3:protected"]=> *RECURSION* } } ["d3:protected"]=> object(Foo)#3 (3) { ["d1:private"]=> object(Bar)#4 (3) { ["d1"]=> *RECURSION* ["d2:private"]=> *RECURSION* ["d3:protected"]=> *RECURSION* } ["d2:protected"]=> object(Bar)#4 (3) { ["d1"]=> *RECURSION* ["d2:private"]=> *RECURSION* ["d3:protected"]=> *RECURSION* } ["d3"]=> object(Bar)#4 (3) { ["d1"]=> *RECURSION* ["d2:private"]=> *RECURSION* ["d3:protected"]=> *RECURSION* } } } ["d3"]=> object(Bar)#4 (3) { ["d1"]=> object(Foo)#3 (3) { ["d1:private"]=> object(Bar)#4 (3) { ["d1"]=> *RECURSION* ["d2:private"]=> *RECURSION* ["d3:protected"]=> *RECURSION* } ["d2:protected"]=> object(Bar)#4 (3) { ["d1"]=> *RECURSION* ["d2:private"]=> *RECURSION* ["d3:protected"]=> *RECURSION* } ["d3"]=> object(Bar)#4 (3) { ["d1"]=> *RECURSION* ["d2:private"]=> *RECURSION* ["d3:protected"]=> *RECURSION* } } ["d2:private"]=> object(Foo)#3 (3) { ["d1:private"]=> object(Bar)#4 (3) { ["d1"]=> *RECURSION* ["d2:private"]=> *RECURSION* ["d3:protected"]=> *RECURSION* } ["d2:protected"]=> object(Bar)#4 (3) { ["d1"]=> *RECURSION* ["d2:private"]=> *RECURSION* ["d3:protected"]=> *RECURSION* } ["d3"]=> object(Bar)#4 (3) { ["d1"]=> *RECURSION* ["d2:private"]=> *RECURSION* ["d3:protected"]=> *RECURSION* } } ["d3:protected"]=> object(Foo)#3 (3) { ["d1:private"]=> object(Bar)#4 (3) { ["d1"]=> *RECURSION* ["d2:private"]=> *RECURSION* ["d3:protected"]=> *RECURSION* } ["d2:protected"]=> object(Bar)#4 (3) { ["d1"]=> *RECURSION* ["d2:private"]=> *RECURSION* ["d3:protected"]=> *RECURSION* } ["d3"]=> object(Bar)#4 (3) { ["d1"]=> *RECURSION* ["d2:private"]=> *RECURSION* ["d3:protected"]=> *RECURSION* } } } } ["test"]=> string(6) "foobar" ["new"]=> object(Bar)#5 (3) { ["d1"]=> object(Foo)#6 (3) { ["d1:private"]=> object(Bar)#5 (3) { ["d1"]=> object(Foo)#6 (3) { ["d1:private"]=> *RECURSION* ["d2:protected"]=> *RECURSION* ["d3"]=> *RECURSION* } ["d2:private"]=> object(Foo)#6 (3) { ["d1:private"]=> *RECURSION* ["d2:protected"]=> *RECURSION* ["d3"]=> *RECURSION* } ["d3:protected"]=> object(Foo)#6 (3) { ["d1:private"]=> *RECURSION* ["d2:protected"]=> *RECURSION* ["d3"]=> *RECURSION* } } ["d2:protected"]=> object(Bar)#5 (3) { ["d1"]=> object(Foo)#6 (3) { ["d1:private"]=> *RECURSION* ["d2:protected"]=> *RECURSION* ["d3"]=> *RECURSION* } ["d2:private"]=> object(Foo)#6 (3) { ["d1:private"]=> *RECURSION* ["d2:protected"]=> *RECURSION* ["d3"]=> *RECURSION* } ["d3:protected"]=> object(Foo)#6 (3) { ["d1:private"]=> *RECURSION* ["d2:protected"]=> *RECURSION* ["d3"]=> *RECURSION* } } ["d3"]=> object(Bar)#5 (3) { ["d1"]=> object(Foo)#6 (3) { ["d1:private"]=> *RECURSION* ["d2:protected"]=> *RECURSION* ["d3"]=> *RECURSION* } ["d2:private"]=> object(Foo)#6 (3) { ["d1:private"]=> *RECURSION* ["d2:protected"]=> *RECURSION* ["d3"]=> *RECURSION* } ["d3:protected"]=> object(Foo)#6 (3) { ["d1:private"]=> *RECURSION* ["d2:protected"]=> *RECURSION* ["d3"]=> *RECURSION* } } } ["d2:private"]=> object(Foo)#6 (3) { ["d1:private"]=> object(Bar)#5 (3) { ["d1"]=> object(Foo)#6 (3) { ["d1:private"]=> *RECURSION* ["d2:protected"]=> *RECURSION* ["d3"]=> *RECURSION* } ["d2:private"]=> object(Foo)#6 (3) { ["d1:private"]=> *RECURSION* ["d2:protected"]=> *RECURSION* ["d3"]=> *RECURSION* } ["d3:protected"]=> object(Foo)#6 (3) { ["d1:private"]=> *RECURSION* ["d2:protected"]=> *RECURSION* ["d3"]=> *RECURSION* } } ["d2:protected"]=> object(Bar)#5 (3) { ["d1"]=> object(Foo)#6 (3) { ["d1:private"]=> *RECURSION* ["d2:protected"]=> *RECURSION* ["d3"]=> *RECURSION* } ["d2:private"]=> object(Foo)#6 (3) { ["d1:private"]=> *RECURSION* ["d2:protected"]=> *RECURSION* ["d3"]=> *RECURSION* } ["d3:protected"]=> object(Foo)#6 (3) { ["d1:private"]=> *RECURSION* ["d2:protected"]=> *RECURSION* ["d3"]=> *RECURSION* } } ["d3"]=> object(Bar)#5 (3) { ["d1"]=> object(Foo)#6 (3) { ["d1:private"]=> *RECURSION* ["d2:protected"]=> *RECURSION* ["d3"]=> *RECURSION* } ["d2:private"]=> object(Foo)#6 (3) { ["d1:private"]=> *RECURSION* ["d2:protected"]=> *RECURSION* ["d3"]=> *RECURSION* } ["d3:protected"]=> object(Foo)#6 (3) { ["d1:private"]=> *RECURSION* ["d2:protected"]=> *RECURSION* ["d3"]=> *RECURSION* } } } ["d3:protected"]=> object(Foo)#6 (3) { ["d1:private"]=> object(Bar)#5 (3) { ["d1"]=> object(Foo)#6 (3) { ["d1:private"]=> *RECURSION* ["d2:protected"]=> *RECURSION* ["d3"]=> *RECURSION* } ["d2:private"]=> object(Foo)#6 (3) { ["d1:private"]=> *RECURSION* ["d2:protected"]=> *RECURSION* ["d3"]=> *RECURSION* } ["d3:protected"]=> object(Foo)#6 (3) { ["d1:private"]=> *RECURSION* ["d2:protected"]=> *RECURSION* ["d3"]=> *RECURSION* } } ["d2:protected"]=> object(Bar)#5 (3) { ["d1"]=> object(Foo)#6 (3) { ["d1:private"]=> *RECURSION* ["d2:protected"]=> *RECURSION* ["d3"]=> *RECURSION* } ["d2:private"]=> object(Foo)#6 (3) { ["d1:private"]=> *RECURSION* ["d2:protected"]=> *RECURSION* ["d3"]=> *RECURSION* } ["d3:protected"]=> object(Foo)#6 (3) { ["d1:private"]=> *RECURSION* ["d2:protected"]=> *RECURSION* ["d3"]=> *RECURSION* } } ["d3"]=> object(Bar)#5 (3) { ["d1"]=> object(Foo)#6 (3) { ["d1:private"]=> *RECURSION* ["d2:protected"]=> *RECURSION* ["d3"]=> *RECURSION* } ["d2:private"]=> object(Foo)#6 (3) { ["d1:private"]=> *RECURSION* ["d2:protected"]=> *RECURSION* ["d3"]=> *RECURSION* } ["d3:protected"]=> object(Foo)#6 (3) { ["d1:private"]=> *RECURSION* ["d2:protected"]=> *RECURSION* ["d3"]=> *RECURSION* } } } } } msgpack-0.5.5/tests/028d.phpt0000644000077100007710000003406712110565607015555 0ustar xinchenxinchen--TEST-- Serialize object into session, full set --SKIPIF-- = 0) { echo "skip tests in PHP 5.0 or older"; } --FILE-- d1 = $foo; $this->d2 = $foo; $this->d3 = $foo; } } class Bar { private static $s1 = array(); protected static $s2 = array(); public static $s3 = array(); public $d1; private $d2; protected $d3; public function __construct() { } public function set($foo) { $this->d1 = $foo; $this->d2 = $foo; $this->d3 = $foo; } } $output = ''; function open($path, $name) { return true; } function close() { return true; } function read($id) { global $output; $output .= "read" . PHP_EOL; $a = new Bar(); $b = new Foo($a); $a->set($b); $session = array('old' => $b); return msgpack_serialize($session); } function write($id, $data) { global $output; $output .= "write: "; $output .= bin2hex($data) . PHP_EOL; return true; } function destroy($id) { return true; } function gc($time) { return true; } ini_set('session.serialize_handler', 'msgpack'); session_set_save_handler('open', 'close', 'read', 'write', 'destroy', 'gc'); session_start(); $_SESSION['test'] = "foobar"; $a = new Bar(); $b = new Foo($a); $a->set($b); $_SESSION['new'] = $a; session_write_close(); echo $output; var_dump($_SESSION); ?> --EXPECTF-- read write: 83a36f6c6484c0a3466f6fa700466f6f00643184c0a3426172a2643182c0040002a70042617200643282c0040002a5002a00643382c0040002a5002a00643282c0040003a2643382c0040003a474657374a6666f6f626172a36e657784c0a3426172a2643184c0a3466f6fa700466f6f00643182c0040009a5002a00643282c0040009a2643382c0040009a70042617200643282c004000aa5002a00643382c004000a array(3) { ["old"]=> object(Foo)#3 (3) { ["d1:private"]=> object(Bar)#4 (3) { ["d1"]=> object(Foo)#3 (3) { ["d1:private"]=> object(Bar)#4 (3) { ["d1"]=> *RECURSION* ["d2:private"]=> *RECURSION* ["d3:protected"]=> *RECURSION* } ["d2:protected"]=> object(Bar)#4 (3) { ["d1"]=> *RECURSION* ["d2:private"]=> *RECURSION* ["d3:protected"]=> *RECURSION* } ["d3"]=> object(Bar)#4 (3) { ["d1"]=> *RECURSION* ["d2:private"]=> *RECURSION* ["d3:protected"]=> *RECURSION* } } ["d2:private"]=> object(Foo)#3 (3) { ["d1:private"]=> object(Bar)#4 (3) { ["d1"]=> *RECURSION* ["d2:private"]=> *RECURSION* ["d3:protected"]=> *RECURSION* } ["d2:protected"]=> object(Bar)#4 (3) { ["d1"]=> *RECURSION* ["d2:private"]=> *RECURSION* ["d3:protected"]=> *RECURSION* } ["d3"]=> object(Bar)#4 (3) { ["d1"]=> *RECURSION* ["d2:private"]=> *RECURSION* ["d3:protected"]=> *RECURSION* } } ["d3:protected"]=> object(Foo)#3 (3) { ["d1:private"]=> object(Bar)#4 (3) { ["d1"]=> *RECURSION* ["d2:private"]=> *RECURSION* ["d3:protected"]=> *RECURSION* } ["d2:protected"]=> object(Bar)#4 (3) { ["d1"]=> *RECURSION* ["d2:private"]=> *RECURSION* ["d3:protected"]=> *RECURSION* } ["d3"]=> object(Bar)#4 (3) { ["d1"]=> *RECURSION* ["d2:private"]=> *RECURSION* ["d3:protected"]=> *RECURSION* } } } ["d2:protected"]=> object(Bar)#4 (3) { ["d1"]=> object(Foo)#3 (3) { ["d1:private"]=> object(Bar)#4 (3) { ["d1"]=> *RECURSION* ["d2:private"]=> *RECURSION* ["d3:protected"]=> *RECURSION* } ["d2:protected"]=> object(Bar)#4 (3) { ["d1"]=> *RECURSION* ["d2:private"]=> *RECURSION* ["d3:protected"]=> *RECURSION* } ["d3"]=> object(Bar)#4 (3) { ["d1"]=> *RECURSION* ["d2:private"]=> *RECURSION* ["d3:protected"]=> *RECURSION* } } ["d2:private"]=> object(Foo)#3 (3) { ["d1:private"]=> object(Bar)#4 (3) { ["d1"]=> *RECURSION* ["d2:private"]=> *RECURSION* ["d3:protected"]=> *RECURSION* } ["d2:protected"]=> object(Bar)#4 (3) { ["d1"]=> *RECURSION* ["d2:private"]=> *RECURSION* ["d3:protected"]=> *RECURSION* } ["d3"]=> object(Bar)#4 (3) { ["d1"]=> *RECURSION* ["d2:private"]=> *RECURSION* ["d3:protected"]=> *RECURSION* } } ["d3:protected"]=> object(Foo)#3 (3) { ["d1:private"]=> object(Bar)#4 (3) { ["d1"]=> *RECURSION* ["d2:private"]=> *RECURSION* ["d3:protected"]=> *RECURSION* } ["d2:protected"]=> object(Bar)#4 (3) { ["d1"]=> *RECURSION* ["d2:private"]=> *RECURSION* ["d3:protected"]=> *RECURSION* } ["d3"]=> object(Bar)#4 (3) { ["d1"]=> *RECURSION* ["d2:private"]=> *RECURSION* ["d3:protected"]=> *RECURSION* } } } ["d3"]=> object(Bar)#4 (3) { ["d1"]=> object(Foo)#3 (3) { ["d1:private"]=> object(Bar)#4 (3) { ["d1"]=> *RECURSION* ["d2:private"]=> *RECURSION* ["d3:protected"]=> *RECURSION* } ["d2:protected"]=> object(Bar)#4 (3) { ["d1"]=> *RECURSION* ["d2:private"]=> *RECURSION* ["d3:protected"]=> *RECURSION* } ["d3"]=> object(Bar)#4 (3) { ["d1"]=> *RECURSION* ["d2:private"]=> *RECURSION* ["d3:protected"]=> *RECURSION* } } ["d2:private"]=> object(Foo)#3 (3) { ["d1:private"]=> object(Bar)#4 (3) { ["d1"]=> *RECURSION* ["d2:private"]=> *RECURSION* ["d3:protected"]=> *RECURSION* } ["d2:protected"]=> object(Bar)#4 (3) { ["d1"]=> *RECURSION* ["d2:private"]=> *RECURSION* ["d3:protected"]=> *RECURSION* } ["d3"]=> object(Bar)#4 (3) { ["d1"]=> *RECURSION* ["d2:private"]=> *RECURSION* ["d3:protected"]=> *RECURSION* } } ["d3:protected"]=> object(Foo)#3 (3) { ["d1:private"]=> object(Bar)#4 (3) { ["d1"]=> *RECURSION* ["d2:private"]=> *RECURSION* ["d3:protected"]=> *RECURSION* } ["d2:protected"]=> object(Bar)#4 (3) { ["d1"]=> *RECURSION* ["d2:private"]=> *RECURSION* ["d3:protected"]=> *RECURSION* } ["d3"]=> object(Bar)#4 (3) { ["d1"]=> *RECURSION* ["d2:private"]=> *RECURSION* ["d3:protected"]=> *RECURSION* } } } } ["test"]=> string(6) "foobar" ["new"]=> object(Bar)#5 (3) { ["d1"]=> object(Foo)#6 (3) { ["d1:private"]=> object(Bar)#5 (3) { ["d1"]=> object(Foo)#6 (3) { ["d1:private"]=> *RECURSION* ["d2:protected"]=> *RECURSION* ["d3"]=> *RECURSION* } ["d2:private"]=> object(Foo)#6 (3) { ["d1:private"]=> *RECURSION* ["d2:protected"]=> *RECURSION* ["d3"]=> *RECURSION* } ["d3:protected"]=> object(Foo)#6 (3) { ["d1:private"]=> *RECURSION* ["d2:protected"]=> *RECURSION* ["d3"]=> *RECURSION* } } ["d2:protected"]=> object(Bar)#5 (3) { ["d1"]=> object(Foo)#6 (3) { ["d1:private"]=> *RECURSION* ["d2:protected"]=> *RECURSION* ["d3"]=> *RECURSION* } ["d2:private"]=> object(Foo)#6 (3) { ["d1:private"]=> *RECURSION* ["d2:protected"]=> *RECURSION* ["d3"]=> *RECURSION* } ["d3:protected"]=> object(Foo)#6 (3) { ["d1:private"]=> *RECURSION* ["d2:protected"]=> *RECURSION* ["d3"]=> *RECURSION* } } ["d3"]=> object(Bar)#5 (3) { ["d1"]=> object(Foo)#6 (3) { ["d1:private"]=> *RECURSION* ["d2:protected"]=> *RECURSION* ["d3"]=> *RECURSION* } ["d2:private"]=> object(Foo)#6 (3) { ["d1:private"]=> *RECURSION* ["d2:protected"]=> *RECURSION* ["d3"]=> *RECURSION* } ["d3:protected"]=> object(Foo)#6 (3) { ["d1:private"]=> *RECURSION* ["d2:protected"]=> *RECURSION* ["d3"]=> *RECURSION* } } } ["d2:private"]=> object(Foo)#6 (3) { ["d1:private"]=> object(Bar)#5 (3) { ["d1"]=> object(Foo)#6 (3) { ["d1:private"]=> *RECURSION* ["d2:protected"]=> *RECURSION* ["d3"]=> *RECURSION* } ["d2:private"]=> object(Foo)#6 (3) { ["d1:private"]=> *RECURSION* ["d2:protected"]=> *RECURSION* ["d3"]=> *RECURSION* } ["d3:protected"]=> object(Foo)#6 (3) { ["d1:private"]=> *RECURSION* ["d2:protected"]=> *RECURSION* ["d3"]=> *RECURSION* } } ["d2:protected"]=> object(Bar)#5 (3) { ["d1"]=> object(Foo)#6 (3) { ["d1:private"]=> *RECURSION* ["d2:protected"]=> *RECURSION* ["d3"]=> *RECURSION* } ["d2:private"]=> object(Foo)#6 (3) { ["d1:private"]=> *RECURSION* ["d2:protected"]=> *RECURSION* ["d3"]=> *RECURSION* } ["d3:protected"]=> object(Foo)#6 (3) { ["d1:private"]=> *RECURSION* ["d2:protected"]=> *RECURSION* ["d3"]=> *RECURSION* } } ["d3"]=> object(Bar)#5 (3) { ["d1"]=> object(Foo)#6 (3) { ["d1:private"]=> *RECURSION* ["d2:protected"]=> *RECURSION* ["d3"]=> *RECURSION* } ["d2:private"]=> object(Foo)#6 (3) { ["d1:private"]=> *RECURSION* ["d2:protected"]=> *RECURSION* ["d3"]=> *RECURSION* } ["d3:protected"]=> object(Foo)#6 (3) { ["d1:private"]=> *RECURSION* ["d2:protected"]=> *RECURSION* ["d3"]=> *RECURSION* } } } ["d3:protected"]=> object(Foo)#6 (3) { ["d1:private"]=> object(Bar)#5 (3) { ["d1"]=> object(Foo)#6 (3) { ["d1:private"]=> *RECURSION* ["d2:protected"]=> *RECURSION* ["d3"]=> *RECURSION* } ["d2:private"]=> object(Foo)#6 (3) { ["d1:private"]=> *RECURSION* ["d2:protected"]=> *RECURSION* ["d3"]=> *RECURSION* } ["d3:protected"]=> object(Foo)#6 (3) { ["d1:private"]=> *RECURSION* ["d2:protected"]=> *RECURSION* ["d3"]=> *RECURSION* } } ["d2:protected"]=> object(Bar)#5 (3) { ["d1"]=> object(Foo)#6 (3) { ["d1:private"]=> *RECURSION* ["d2:protected"]=> *RECURSION* ["d3"]=> *RECURSION* } ["d2:private"]=> object(Foo)#6 (3) { ["d1:private"]=> *RECURSION* ["d2:protected"]=> *RECURSION* ["d3"]=> *RECURSION* } ["d3:protected"]=> object(Foo)#6 (3) { ["d1:private"]=> *RECURSION* ["d2:protected"]=> *RECURSION* ["d3"]=> *RECURSION* } } ["d3"]=> object(Bar)#5 (3) { ["d1"]=> object(Foo)#6 (3) { ["d1:private"]=> *RECURSION* ["d2:protected"]=> *RECURSION* ["d3"]=> *RECURSION* } ["d2:private"]=> object(Foo)#6 (3) { ["d1:private"]=> *RECURSION* ["d2:protected"]=> *RECURSION* ["d3"]=> *RECURSION* } ["d3:protected"]=> object(Foo)#6 (3) { ["d1:private"]=> *RECURSION* ["d2:protected"]=> *RECURSION* ["d3"]=> *RECURSION* } } } } } msgpack-0.5.5/tests/029.phpt0000644000077100007710000000157612110565607015411 0ustar xinchenxinchen--TEST-- Msgpack module info --SKIPIF-- --FILE-- $val) { if (strcmp($val, 'msgpack') == 0 || $section) { $section = true; } else { continue; } if (empty($val)) { $blank++; if ($blank == 3) { $section = false; } } echo $val, PHP_EOL; } --EXPECTF-- msgpack MessagePack Support => enabled Session Support => enabled extension Version => %s header Version => %s Directive => Local Value => Master Value msgpack.error_display => On => On msgpack.illegal_key_insert => Off => Off msgpack.php_only => On => On msgpack-0.5.5/tests/030.phpt0000644000077100007710000000441012110565607015367 0ustar xinchenxinchen--TEST-- Unserialize invalid data --SKIPIF-- --FILE-- 10, "foo"), true, false, 0.187182, "dakjdh98389\000", null, (object)array(1,2,3), ); error_reporting(0); foreach ($datas as $data) { $str = msgpack_serialize($data); $len = strlen($str); // truncated for ($i = 0; $i < $len - 1; $i++) { $v = msgpack_unserialize(substr($str, 0, $i)); if (is_object($data) || is_array($data)) { if ($v !== null && $v !== false && $v != $data) { echo "output at $i:\n"; var_dump($v); } } else if ($v !== null && $v == $data) { continue; } else if ($v !== null && $v !== $data) { echo "output at $i:\n"; var_dump($v); echo "vs.\n"; var_dump($data); } } // padded $str .= "98398afa\000y21_ "; $v = msgpack_unserialize($str); if ($v !== $data && !(is_object($data) && $v == $data)) { echo "padded should get original\n"; var_dump($v); echo "vs.\n"; var_dump($data); } } ?> --EXPECTF-- output at 1: bool(false) vs. int(87817) output at 2: bool(false) vs. int(87817) output at 3: bool(false) vs. int(87817) output at 1: bool(false) vs. float(0.187182) output at 2: bool(false) vs. float(0.187182) output at 3: bool(false) vs. float(0.187182) output at 4: bool(false) vs. float(0.187182) output at 5: bool(false) vs. float(0.187182) output at 6: bool(false) vs. float(0.187182) output at 7: bool(false) vs. float(0.187182) output at 1: bool(false) vs. string(12) "dakjdh98389" output at 2: bool(false) vs. string(12) "dakjdh98389" output at 3: bool(false) vs. string(12) "dakjdh98389" output at 4: bool(false) vs. string(12) "dakjdh98389" output at 5: bool(false) vs. string(12) "dakjdh98389" output at 6: bool(false) vs. string(12) "dakjdh98389" output at 7: bool(false) vs. string(12) "dakjdh98389" output at 8: bool(false) vs. string(12) "dakjdh98389" output at 9: bool(false) vs. string(12) "dakjdh98389" output at 10: bool(false) vs. string(12) "dakjdh98389" output at 11: bool(false) vs. string(12) "dakjdh98389" msgpack-0.5.5/tests/031.phpt0000644000077100007710000000407112110565607015373 0ustar xinchenxinchen--TEST-- Object Serializable interface throws exceptions --SKIPIF-- a = $a; $this->b = $b; } public function serialize() { $c = self::$count++; echo "call serialize, ", ($this->a ? "throw" : "no throw"), PHP_EOL; if ($this->a) { throw new Exception("exception in serialize $c"); } return pack('NN', $this->a, $this->b); } public function unserialize($serialized) { $tmp = unpack('N*', $serialized); $this->__construct($tmp[1], $tmp[2]); $c = self::$count++; echo "call unserialize, ", ($this->b ? "throw" : "no throw"), PHP_EOL; if ($this->b) { throw new Exception("exception in unserialize $c"); } } } $a = new Obj(1, 0); $a = new Obj(0, 0); $b = new Obj(0, 0); $c = new Obj(1, 0); $d = new Obj(0, 1); echo "a, a, c", PHP_EOL; try { test(array($a, $a, $c)); } catch (Exception $e) { if (version_compare(phpversion(), "5.3.0", ">=")) { if ($e->getPrevious()) { $e = $e->getPrevious(); } } echo $e->getMessage(), PHP_EOL; } echo "b, b, d", PHP_EOL; try { test(array($b, $b, $d)); } catch (Exception $e) { if (version_compare(phpversion(), "5.3.0", ">=")) { if ($e->getPrevious()) { $e = $e->getPrevious(); } } echo $e->getMessage(), PHP_EOL; } ?> --EXPECT-- a, a, c call serialize, no throw call serialize, throw exception in serialize 2 b, b, d call serialize, no throw call serialize, no throw call unserialize, no throw call unserialize, throw exception in unserialize 6 msgpack-0.5.5/tests/032.phpt0000644000077100007710000000243612110565607015377 0ustar xinchenxinchen--TEST-- Object test, __sleep and __wakeup exceptions --SKIPIF-- --FILE-- a = $a; $this->b = $b; } function __sleep() { $c = self::$count++; if ($this->a) { throw new Exception("exception in __sleep $c"); } return array('a', 'b'); } function __wakeup() { $c = self::$count++; if ($this->b) { throw new Exception("exception in __wakeup $c"); } $this->b = $this->a * 3; } } $a = new Obj(1, 0); $b = new Obj(0, 1); $c = new Obj(0, 0); try { test($a); } catch (Exception $e) { echo $e->getMessage(), PHP_EOL; } try { test($b); } catch (Exception $e) { echo $e->getMessage(), PHP_EOL; } try { test($c); } catch (Exception $e) { echo $e->getMessage(), PHP_EOL; } ?> --EXPECTF-- exception in __sleep 0 exception in __wakeup 2 object(Obj)#%d (2) { ["a"]=> int(0) ["b"]=> int(0) } msgpack-0.5.5/tests/033.phpt0000644000077100007710000000170512110565607015376 0ustar xinchenxinchen--TEST-- Object test, cyclic references --SKIPIF-- --FILE-- parent = null; $this->children = array(); } public function addChild(Foo $obj) { $this->children[] = $obj; $obj->setParent($this); } public function setParent(Foo $obj) { $this->parent = $obj; } } $obj1 = new Foo(); for ($i = 0; $i < 10; $i++) { $obj = new Foo(); $obj1->addChild($obj); } $o = msgpack_unserialize(msgpack_serialize($obj1->children)); foreach ($obj1->children as $k => $v) { $obj_v = $v; $o_v = $o[$k]; echo gettype($obj_v), " ", gettype($o_v), PHP_EOL; } ?> --EXPECT-- object object object object object object object object object object object object object object object object object object object object msgpack-0.5.5/tests/034.phpt0000644000077100007710000000133412110565607015375 0ustar xinchenxinchen--TEST-- Unserialize invalid random data --SKIPIF-- --FILE-- 10, "foo"), true, false, 0.187182, "dakjdh98389\000", null, (object)array(1,2,3), ); error_reporting(0); foreach ($datas as $data) { $str = msgpack_serialize($data); $len = strlen($str); for ($j = 0; $j < 200; $j++) { for ($i = 0; $i < $len - 1; $i++) { $sub = substr($str, 0, $i); $sub .= mcrypt_create_iv(30, MCRYPT_DEV_URANDOM); $php_errormsg = null; $v = msgpack_unserialize($sub); } } } --EXPECT-- msgpack-0.5.5/tests/035.phpt0000644000077100007710000000157512110565607015405 0ustar xinchenxinchen--TEST-- Profiling perf test. --SKIPIF-- --FILE-- 400 ? "GOOD" : "BAD")); } ?> --EXPECTF-- %d iterations took %f seconds: %d/s (GOOD) msgpack-0.5.5/tests/040.phpt0000644000077100007710000000151012110565607015366 0ustar xinchenxinchen--TEST-- broken random data test --SKIPIF-- --FILE-- --EXPECT-- msgpack-0.5.5/tests/040b.phpt0000644000077100007710000000157312110565607015541 0ustar xinchenxinchen--TEST-- broken random data test : MessagePack class --SKIPIF-- --FILE-- unpack($serialized)) === null) { return true; } // whole data is read? if ($serialized !== msgpack_serialize($unserialized)) { return true; } echo bin2hex($serialized), "\n"; var_dump($unserialized); return false; } mt_srand(0x4c05b583); for ($i = 0; $i < 100; ++$i) { if (!test()) break; } ?> --EXPECT-- msgpack-0.5.5/tests/040c.phpt0000644000077100007710000000203612110565607015535 0ustar xinchenxinchen--TEST-- broken random data test : MessagePackUnpacker::feed --SKIPIF-- --FILE-- feed($serialized); if ($unpacker->execute()) { if (($unserialized = $unpacker->data()) === null) { return true; } $unpacker->reset(); } else { return true; } // whole data is read? if ($serialized !== msgpack_serialize($unserialized)) { return true; } echo bin2hex($serialized), "\n"; var_dump($unserialized); return false; } mt_srand(0x4c05b583); for ($i = 0; $i < 100; ++$i) { if (!test()) break; } ?> --EXPECT-- msgpack-0.5.5/tests/040d.phpt0000644000077100007710000000202312110565607015532 0ustar xinchenxinchen--TEST-- broken random data test : MessagePackUnpacker::execute --SKIPIF-- --FILE-- execute($serialized, $offset)) { if (($unserialized = $unpacker->data()) === null) { return true; } $unpacker->reset(); } else { return true; } // whole data is read? if ($serialized !== msgpack_serialize($unserialized)) { return true; } echo bin2hex($serialized), "\n"; var_dump($unserialized); return false; } mt_srand(0x4c05b583); for ($i = 0; $i < 100; ++$i) { if (!test()) break; } ?> --EXPECT-- msgpack-0.5.5/tests/041.phpt0000644000077100007710000000136512110565607015377 0ustar xinchenxinchen--TEST-- Check for double NaN, Inf, -Inf, 0, and -0 --FILE-- --EXPECT-- empty array: 90 array(0) { } array(1, 2, 3) 93010203 array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } array(array(1, 2, 3), arr... 93930102039304050693070809 array(3) { [0]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } [1]=> array(3) { [0]=> int(4) [1]=> int(5) [2]=> int(6) } [2]=> array(3) { [0]=> int(7) [1]=> int(8) [2]=> int(9) } } array("foo", "FOO", "Foo") 93a3666f6fa3464f4fa3466f6f array(3) { [0]=> string(3) "foo" [1]=> string(3) "FOO" [2]=> string(3) "Foo" } array(1, 123.45, true, ... 9701cb405edccccccccccdc3c293010293090807c0a3666f6f array(7) { [0]=> int(1) [1]=> float(123.45) [2]=> bool(true) [3]=> bool(false) [4]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> array(3) { [0]=> int(9) [1]=> int(8) [2]=> int(7) } } [5]=> NULL [6]=> string(3) "foo" } msgpack-0.5.5/tests/060.phpt0000644000077100007710000001117412110565607015377 0ustar xinchenxinchen--TEST-- Check for buffered streaming unserialization --SKIPIF-- = 0 && version_compare(PHP_VERSION, '5.3.2') <= 0)) { echo "skip tests in PHP 5.2.14/5.3.3 or newer"; } --FILE-- feed($str); if ($unpacker->execute()) { $unserialized = $unpacker->data(); var_dump($unserialized); $unpacker->reset(); } $i += $len; } if (!is_bool($test)) { echo $unserialized === $variable ? 'OK' : 'ERROR', PHP_EOL; } else { echo $test || $unserialized == $variable ? 'OK' : 'ERROR', PHP_EOL; } } test('null', null); test('bool: true', true); test('bool: false', false); test('zero: 0', 0); test('small: 1', 1); test('small: -1', -1); test('medium: 1000', 1000); test('medium: -1000', -1000); test('large: 100000', 100000); test('large: -100000', -100000); test('double: 123.456', 123.456); test('empty: ""', ""); test('string: "foobar"', "foobar"); test('array', array(), false); test('array(1, 2, 3)', array(1, 2, 3), false); test('array(array(1, 2, 3), arr...', array(array(1, 2, 3), array(4, 5, 6), array(7, 8, 9)), false); test('array("foo", "foo", "foo")', array("foo", "foo", "foo"), false); test('array("one" => 1, "two" => 2))', array("one" => 1, "two" => 2), false); test('array("kek" => "lol", "lol" => "kek")', array("kek" => "lol", "lol" => "kek"), false); test('array("" => "empty")', array("" => "empty"), false); $a = array('foo'); test('array($a, $a)', array($a, $a), false); test('array(&$a, &$a)', array(&$a, &$a), false); $a = array(null); $b = array(&$a); $a[0] = &$b; test('cyclic', $a, true); $a = array( 'a' => array( 'b' => 'c', 'd' => 'e' ), 'f' => array( 'g' => 'h' ) ); test('array', $a, false); class Obj { public $a; protected $b; private $c; function __construct($a, $b, $c) { $this->a = $a; $this->b = $b; $this->c = $c; } } test('object', new Obj(1, 2, 3), false); test('object', array(new Obj(1, 2, 3), new Obj(4, 5, 6)), false); $o = new Obj(1, 2, 3); test('object', array(&$o, &$o), false); --EXPECTF-- NULL OK bool(true) OK bool(false) OK int(0) OK int(1) OK int(-1) OK int(1000) OK int(-1000) OK int(100000) OK int(-100000) OK float(123.456) OK string(0) "" OK string(6) "foobar" OK array(0) { } OK array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } OK array(3) { [0]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } [1]=> array(3) { [0]=> int(4) [1]=> int(5) [2]=> int(6) } [2]=> array(3) { [0]=> int(7) [1]=> int(8) [2]=> int(9) } } OK array(3) { [0]=> string(3) "foo" [1]=> string(3) "foo" [2]=> string(3) "foo" } OK array(2) { ["one"]=> int(1) ["two"]=> int(2) } OK array(2) { ["kek"]=> string(3) "lol" ["lol"]=> string(3) "kek" } OK array(1) { [""]=> string(5) "empty" } OK array(2) { [0]=> array(1) { [0]=> string(3) "foo" } [1]=> array(1) { [0]=> string(3) "foo" } } OK array(2) { [0]=> &array(1) { [0]=> string(3) "foo" } [1]=> &array(1) { [0]=> string(3) "foo" } } OK array(1) { [0]=> &array(1) { [0]=> &array(1) { [0]=> *RECURSION* } } } OK array(2) { ["a"]=> array(2) { ["b"]=> string(1) "c" ["d"]=> string(1) "e" } ["f"]=> array(1) { ["g"]=> string(1) "h" } } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK array(2) { [0]=> object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } [1]=> object(Obj)#%d (3) { ["a"]=> int(4) [%r"?b"?:protected"?%r]=> int(5) [%r"?c"?:("Obj":)?private"?%r]=> int(6) } } OK array(2) { [0]=> &object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } [1]=> &object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } } OK msgpack-0.5.5/tests/060b.phpt0000644000077100007710000001146312110565607015542 0ustar xinchenxinchen--TEST-- Check for buffered streaming unserialization --SKIPIF-- = 0) || (version_compare(PHP_VERSION, '5.3.3') >= 0)) { echo "skip tests in PHP 5.2.13/5.3.2 or older"; } if (version_compare(PHP_VERSION, '5.2.0') < 0) { echo "skip tests in PHP 5.2 or newer"; } --FILE-- feed($str); if ($unpacker->execute()) { $unserialized = $unpacker->data(); var_dump($unserialized); $unpacker->reset(); } $i += $len; } if (!is_bool($test)) { echo $unserialized === $variable ? 'OK' : 'ERROR', PHP_EOL; } else { echo $test || $unserialized == $variable ? 'OK' : 'ERROR', PHP_EOL; } } test('null', null); test('bool: true', true); test('bool: false', false); test('zero: 0', 0); test('small: 1', 1); test('small: -1', -1); test('medium: 1000', 1000); test('medium: -1000', -1000); test('large: 100000', 100000); test('large: -100000', -100000); test('double: 123.456', 123.456); test('empty: ""', ""); test('string: "foobar"', "foobar"); test('array', array(), false); test('array(1, 2, 3)', array(1, 2, 3), false); test('array(array(1, 2, 3), arr...', array(array(1, 2, 3), array(4, 5, 6), array(7, 8, 9)), false); test('array("foo", "foo", "foo")', array("foo", "foo", "foo"), false); test('array("one" => 1, "two" => 2))', array("one" => 1, "two" => 2), false); test('array("kek" => "lol", "lol" => "kek")', array("kek" => "lol", "lol" => "kek"), false); test('array("" => "empty")', array("" => "empty"), false); $a = array('foo'); test('array($a, $a)', array($a, $a), false); test('array(&$a, &$a)', array(&$a, &$a), false); $a = array(null); $b = array(&$a); $a[0] = &$b; test('cyclic', $a, true); $a = array( 'a' => array( 'b' => 'c', 'd' => 'e' ), 'f' => array( 'g' => 'h' ) ); test('array', $a, false); class Obj { public $a; protected $b; private $c; function __construct($a, $b, $c) { $this->a = $a; $this->b = $b; $this->c = $c; } } test('object', new Obj(1, 2, 3), false); test('object', array(new Obj(1, 2, 3), new Obj(4, 5, 6)), false); $o = new Obj(1, 2, 3); test('object', array(&$o, &$o), false); --EXPECTF-- NULL OK bool(true) OK bool(false) OK int(0) OK int(1) OK int(-1) OK int(1000) OK int(-1000) OK int(100000) OK int(-100000) OK float(123.456) OK string(0) "" OK string(6) "foobar" OK array(0) { } OK array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } OK array(3) { [0]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } [1]=> array(3) { [0]=> int(4) [1]=> int(5) [2]=> int(6) } [2]=> array(3) { [0]=> int(7) [1]=> int(8) [2]=> int(9) } } OK array(3) { [0]=> string(3) "foo" [1]=> string(3) "foo" [2]=> string(3) "foo" } OK array(2) { ["one"]=> int(1) ["two"]=> int(2) } OK array(2) { ["kek"]=> string(3) "lol" ["lol"]=> string(3) "kek" } OK array(1) { [""]=> string(5) "empty" } OK array(2) { [0]=> array(1) { [0]=> string(3) "foo" } [1]=> array(1) { [0]=> string(3) "foo" } } OK array(2) { [0]=> &array(1) { [0]=> string(3) "foo" } [1]=> &array(1) { [0]=> string(3) "foo" } } OK array(1) { [0]=> &array(1) { [0]=> &array(1) { [0]=> &array(1) { [0]=> &array(1) { [0]=> *RECURSION* } } } } } OK array(2) { ["a"]=> array(2) { ["b"]=> string(1) "c" ["d"]=> string(1) "e" } ["f"]=> array(1) { ["g"]=> string(1) "h" } } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK array(2) { [0]=> object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } [1]=> object(Obj)#%d (3) { ["a"]=> int(4) [%r"?b"?:protected"?%r]=> int(5) [%r"?c"?:("Obj":)?private"?%r]=> int(6) } } OK array(2) { [0]=> &object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } [1]=> &object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } } OK msgpack-0.5.5/tests/060c.phpt0000644000077100007710000001074612110565607015546 0ustar xinchenxinchen--TEST-- Check for buffered streaming unserialization --SKIPIF-- = 0) { echo "skip tests in PHP 5.1 or older"; } --FILE-- feed($str); if ($unpacker->execute()) { $unserialized = $unpacker->data(); var_dump($unserialized); $unpacker->reset(); } $i += $len; } if (!is_bool($test)) { echo $unserialized === $variable ? 'OK' : 'ERROR', PHP_EOL; } else { echo $test || $unserialized == $variable ? 'OK' : 'ERROR', PHP_EOL; } } test('null', null); test('bool: true', true); test('bool: false', false); test('zero: 0', 0); test('small: 1', 1); test('small: -1', -1); test('medium: 1000', 1000); test('medium: -1000', -1000); test('large: 100000', 100000); test('large: -100000', -100000); test('double: 123.456', 123.456); test('empty: ""', ""); test('string: "foobar"', "foobar"); test('array', array(), false); test('array(1, 2, 3)', array(1, 2, 3), false); test('array(array(1, 2, 3), arr...', array(array(1, 2, 3), array(4, 5, 6), array(7, 8, 9)), false); test('array("foo", "foo", "foo")', array("foo", "foo", "foo"), false); test('array("one" => 1, "two" => 2))', array("one" => 1, "two" => 2), false); test('array("kek" => "lol", "lol" => "kek")', array("kek" => "lol", "lol" => "kek"), false); test('array("" => "empty")', array("" => "empty"), false); $a = array('foo'); test('array($a, $a)', array($a, $a), false); test('array(&$a, &$a)', array(&$a, &$a), false); $a = array(null); $b = array(&$a); $a[0] = &$b; test('cyclic', $a, true); $a = array( 'a' => array( 'b' => 'c', 'd' => 'e' ), 'f' => array( 'g' => 'h' ) ); test('array', $a, false); class Obj { public $a; protected $b; private $c; function __construct($a, $b, $c) { $this->a = $a; $this->b = $b; $this->c = $c; } } test('object', new Obj(1, 2, 3), false); test('object', array(new Obj(1, 2, 3), new Obj(4, 5, 6)), false); $o = new Obj(1, 2, 3); test('object', array(&$o, &$o), false); --EXPECTF-- NULL OK bool(true) OK bool(false) OK int(0) OK int(1) OK int(-1) OK int(1000) OK int(-1000) OK int(100000) OK int(-100000) OK float(123.456) OK string(0) "" OK string(6) "foobar" OK array(0) { } OK array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } OK array(3) { [0]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } [1]=> array(3) { [0]=> int(4) [1]=> int(5) [2]=> int(6) } [2]=> array(3) { [0]=> int(7) [1]=> int(8) [2]=> int(9) } } OK array(3) { [0]=> string(3) "foo" [1]=> string(3) "foo" [2]=> string(3) "foo" } OK array(2) { ["one"]=> int(1) ["two"]=> int(2) } OK array(2) { ["kek"]=> string(3) "lol" ["lol"]=> string(3) "kek" } OK array(1) { [""]=> string(5) "empty" } OK array(2) { [0]=> array(1) { [0]=> string(3) "foo" } [1]=> array(1) { [0]=> string(3) "foo" } } OK array(2) { [0]=> &array(1) { [0]=> string(3) "foo" } [1]=> &array(1) { [0]=> string(3) "foo" } } OK array(1) { [0]=> &array(1) { [0]=> &array(1) { [0]=> &array(1) { [0]=> &array(1) { [0]=> *RECURSION* } } } } } OK array(2) { ["a"]=> array(2) { ["b"]=> string(1) "c" ["d"]=> string(1) "e" } ["f"]=> array(1) { ["g"]=> string(1) "h" } } OK object(Obj)#%d (3) { ["a"]=> int(1) ["b:protected"]=> int(2) ["c:private"]=> int(3) } OK array(2) { [0]=> object(Obj)#%d (3) { ["a"]=> int(1) ["b:protected"]=> int(2) ["c:private"]=> int(3) } [1]=> object(Obj)#%d (3) { ["a"]=> int(4) ["b:protected"]=> int(5) ["c:private"]=> int(6) } } OK array(2) { [0]=> &object(Obj)#%d (3) { ["a"]=> int(1) ["b:protected"]=> int(2) ["c:private"]=> int(3) } [1]=> &object(Obj)#%d (3) { ["a"]=> int(1) ["b:protected"]=> int(2) ["c:private"]=> int(3) } } OK msgpack-0.5.5/tests/061.phpt0000644000077100007710000001130612110565607015375 0ustar xinchenxinchen--TEST-- Check for unbuffered streaming unserialization --SKIPIF-- = 0 && version_compare(PHP_VERSION, '5.3.2') <= 0)) { echo "skip tests in PHP 5.2.14/5.3.3 or newer"; } --FILE-- execute($str, $offset)) { $unserialized = $unpacker->data(); var_dump($unserialized); $unpacker->reset(); $str = ""; $offset = 0; } $i += $len; } if (!is_bool($test)) { echo $unserialized === $variable ? 'OK' : 'ERROR', PHP_EOL; } else { echo $test || $unserialized == $variable ? 'OK' : 'ERROR', PHP_EOL; } } test('null', null); test('bool: true', true); test('bool: false', false); test('zero: 0', 0); test('small: 1', 1); test('small: -1', -1); test('medium: 1000', 1000); test('medium: -1000', -1000); test('large: 100000', 100000); test('large: -100000', -100000); test('double: 123.456', 123.456); test('empty: ""', ""); test('string: "foobar"', "foobar"); test('array: empty', array(), false); test('array(1, 2, 3)', array(1, 2, 3), false); test('array(array(1, 2, 3), arr...', array(array(1, 2, 3), array(4, 5, 6), array(7, 8, 9)), false); test('array("foo", "foo", "foo")', array("foo", "foo", "foo"), false); test('array("one" => 1, "two" => 2))', array("one" => 1, "two" => 2), false); test('array("kek" => "lol", "lol" => "kek")', array("kek" => "lol", "lol" => "kek"), false); test('array("" => "empty")', array("" => "empty"), false); $a = array('foo'); test('array($a, $a)', array($a, $a), false); test('array(&$a, &$a)', array(&$a, &$a), false); $a = array(null); $b = array(&$a); $a[0] = &$b; test('cyclic', $a, true); $a = array( 'a' => array( 'b' => 'c', 'd' => 'e' ), 'f' => array( 'g' => 'h' ) ); test('array', $a, false); class Obj { public $a; protected $b; private $c; function __construct($a, $b, $c) { $this->a = $a; $this->b = $b; $this->c = $c; } } test('object', new Obj(1, 2, 3), false); test('object', array(new Obj(1, 2, 3), new Obj(4, 5, 6)), false); $o = new Obj(1, 2, 3); test('object', array(&$o, &$o), false); --EXPECTF-- NULL OK bool(true) OK bool(false) OK int(0) OK int(1) OK int(-1) OK int(1000) OK int(-1000) OK int(100000) OK int(-100000) OK float(123.456) OK string(0) "" OK string(6) "foobar" OK array(0) { } OK array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } OK array(3) { [0]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } [1]=> array(3) { [0]=> int(4) [1]=> int(5) [2]=> int(6) } [2]=> array(3) { [0]=> int(7) [1]=> int(8) [2]=> int(9) } } OK array(3) { [0]=> string(3) "foo" [1]=> string(3) "foo" [2]=> string(3) "foo" } OK array(2) { ["one"]=> int(1) ["two"]=> int(2) } OK array(2) { ["kek"]=> string(3) "lol" ["lol"]=> string(3) "kek" } OK array(1) { [""]=> string(5) "empty" } OK array(2) { [0]=> array(1) { [0]=> string(3) "foo" } [1]=> array(1) { [0]=> string(3) "foo" } } OK array(2) { [0]=> &array(1) { [0]=> string(3) "foo" } [1]=> &array(1) { [0]=> string(3) "foo" } } OK array(1) { [0]=> &array(1) { [0]=> &array(1) { [0]=> *RECURSION* } } } OK array(2) { ["a"]=> array(2) { ["b"]=> string(1) "c" ["d"]=> string(1) "e" } ["f"]=> array(1) { ["g"]=> string(1) "h" } } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK array(2) { [0]=> object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } [1]=> object(Obj)#%d (3) { ["a"]=> int(4) [%r"?b"?:protected"?%r]=> int(5) [%r"?c"?:("Obj":)?private"?%r]=> int(6) } } OK array(2) { [0]=> &object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } [1]=> &object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } } OK msgpack-0.5.5/tests/061b.phpt0000644000077100007710000001157512110565607015547 0ustar xinchenxinchen--TEST-- Check for unbuffered streaming unserialization --SKIPIF-- = 0) || (version_compare(PHP_VERSION, '5.3.3') >= 0)) { echo "skip tests in PHP 5.2.13/5.3.2 or older"; } if (version_compare(PHP_VERSION, '5.2.0') < 0) { echo "skip tests in PHP 5.2 or newer"; } --FILE-- execute($str, $offset)) { $unserialized = $unpacker->data(); var_dump($unserialized); $unpacker->reset(); $str = ""; $offset = 0; } $i += $len; } if (!is_bool($test)) { echo $unserialized === $variable ? 'OK' : 'ERROR', PHP_EOL; } else { echo $test || $unserialized == $variable ? 'OK' : 'ERROR', PHP_EOL; } } test('null', null); test('bool: true', true); test('bool: false', false); test('zero: 0', 0); test('small: 1', 1); test('small: -1', -1); test('medium: 1000', 1000); test('medium: -1000', -1000); test('large: 100000', 100000); test('large: -100000', -100000); test('double: 123.456', 123.456); test('empty: ""', ""); test('string: "foobar"', "foobar"); test('array: empty', array(), false); test('array(1, 2, 3)', array(1, 2, 3), false); test('array(array(1, 2, 3), arr...', array(array(1, 2, 3), array(4, 5, 6), array(7, 8, 9)), false); test('array("foo", "foo", "foo")', array("foo", "foo", "foo"), false); test('array("one" => 1, "two" => 2))', array("one" => 1, "two" => 2), false); test('array("kek" => "lol", "lol" => "kek")', array("kek" => "lol", "lol" => "kek"), false); test('array("" => "empty")', array("" => "empty"), false); $a = array('foo'); test('array($a, $a)', array($a, $a), false); test('array(&$a, &$a)', array(&$a, &$a), false); $a = array(null); $b = array(&$a); $a[0] = &$b; test('cyclic', $a, true); $a = array( 'a' => array( 'b' => 'c', 'd' => 'e' ), 'f' => array( 'g' => 'h' ) ); test('array', $a, false); class Obj { public $a; protected $b; private $c; function __construct($a, $b, $c) { $this->a = $a; $this->b = $b; $this->c = $c; } } test('object', new Obj(1, 2, 3), false); test('object', array(new Obj(1, 2, 3), new Obj(4, 5, 6)), false); $o = new Obj(1, 2, 3); test('object', array(&$o, &$o), false); --EXPECTF-- NULL OK bool(true) OK bool(false) OK int(0) OK int(1) OK int(-1) OK int(1000) OK int(-1000) OK int(100000) OK int(-100000) OK float(123.456) OK string(0) "" OK string(6) "foobar" OK array(0) { } OK array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } OK array(3) { [0]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } [1]=> array(3) { [0]=> int(4) [1]=> int(5) [2]=> int(6) } [2]=> array(3) { [0]=> int(7) [1]=> int(8) [2]=> int(9) } } OK array(3) { [0]=> string(3) "foo" [1]=> string(3) "foo" [2]=> string(3) "foo" } OK array(2) { ["one"]=> int(1) ["two"]=> int(2) } OK array(2) { ["kek"]=> string(3) "lol" ["lol"]=> string(3) "kek" } OK array(1) { [""]=> string(5) "empty" } OK array(2) { [0]=> array(1) { [0]=> string(3) "foo" } [1]=> array(1) { [0]=> string(3) "foo" } } OK array(2) { [0]=> &array(1) { [0]=> string(3) "foo" } [1]=> &array(1) { [0]=> string(3) "foo" } } OK array(1) { [0]=> &array(1) { [0]=> &array(1) { [0]=> &array(1) { [0]=> &array(1) { [0]=> *RECURSION* } } } } } OK array(2) { ["a"]=> array(2) { ["b"]=> string(1) "c" ["d"]=> string(1) "e" } ["f"]=> array(1) { ["g"]=> string(1) "h" } } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK array(2) { [0]=> object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } [1]=> object(Obj)#%d (3) { ["a"]=> int(4) [%r"?b"?:protected"?%r]=> int(5) [%r"?c"?:("Obj":)?private"?%r]=> int(6) } } OK array(2) { [0]=> &object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } [1]=> &object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } } OK msgpack-0.5.5/tests/061c.phpt0000644000077100007710000001106012110565607015535 0ustar xinchenxinchen--TEST-- Check for unbuffered streaming unserialization --SKIPIF-- = 0) { echo "skip tests in PHP 5.1 or older"; } --FILE-- execute($str, $offset)) { $unserialized = $unpacker->data(); var_dump($unserialized); $unpacker->reset(); $str = ""; $offset = 0; } $i += $len; } if (!is_bool($test)) { echo $unserialized === $variable ? 'OK' : 'ERROR', PHP_EOL; } else { echo $test || $unserialized == $variable ? 'OK' : 'ERROR', PHP_EOL; } } test('null', null); test('bool: true', true); test('bool: false', false); test('zero: 0', 0); test('small: 1', 1); test('small: -1', -1); test('medium: 1000', 1000); test('medium: -1000', -1000); test('large: 100000', 100000); test('large: -100000', -100000); test('double: 123.456', 123.456); test('empty: ""', ""); test('string: "foobar"', "foobar"); test('array: empty', array(), false); test('array(1, 2, 3)', array(1, 2, 3), false); test('array(array(1, 2, 3), arr...', array(array(1, 2, 3), array(4, 5, 6), array(7, 8, 9)), false); test('array("foo", "foo", "foo")', array("foo", "foo", "foo"), false); test('array("one" => 1, "two" => 2))', array("one" => 1, "two" => 2), false); test('array("kek" => "lol", "lol" => "kek")', array("kek" => "lol", "lol" => "kek"), false); test('array("" => "empty")', array("" => "empty"), false); $a = array('foo'); test('array($a, $a)', array($a, $a), false); test('array(&$a, &$a)', array(&$a, &$a), false); $a = array(null); $b = array(&$a); $a[0] = &$b; test('cyclic', $a, true); $a = array( 'a' => array( 'b' => 'c', 'd' => 'e' ), 'f' => array( 'g' => 'h' ) ); test('array', $a, false); class Obj { public $a; protected $b; private $c; function __construct($a, $b, $c) { $this->a = $a; $this->b = $b; $this->c = $c; } } test('object', new Obj(1, 2, 3), false); test('object', array(new Obj(1, 2, 3), new Obj(4, 5, 6)), false); $o = new Obj(1, 2, 3); test('object', array(&$o, &$o), false); --EXPECTF-- NULL OK bool(true) OK bool(false) OK int(0) OK int(1) OK int(-1) OK int(1000) OK int(-1000) OK int(100000) OK int(-100000) OK float(123.456) OK string(0) "" OK string(6) "foobar" OK array(0) { } OK array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } OK array(3) { [0]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } [1]=> array(3) { [0]=> int(4) [1]=> int(5) [2]=> int(6) } [2]=> array(3) { [0]=> int(7) [1]=> int(8) [2]=> int(9) } } OK array(3) { [0]=> string(3) "foo" [1]=> string(3) "foo" [2]=> string(3) "foo" } OK array(2) { ["one"]=> int(1) ["two"]=> int(2) } OK array(2) { ["kek"]=> string(3) "lol" ["lol"]=> string(3) "kek" } OK array(1) { [""]=> string(5) "empty" } OK array(2) { [0]=> array(1) { [0]=> string(3) "foo" } [1]=> array(1) { [0]=> string(3) "foo" } } OK array(2) { [0]=> &array(1) { [0]=> string(3) "foo" } [1]=> &array(1) { [0]=> string(3) "foo" } } OK array(1) { [0]=> &array(1) { [0]=> &array(1) { [0]=> &array(1) { [0]=> &array(1) { [0]=> *RECURSION* } } } } } OK array(2) { ["a"]=> array(2) { ["b"]=> string(1) "c" ["d"]=> string(1) "e" } ["f"]=> array(1) { ["g"]=> string(1) "h" } } OK object(Obj)#%d (3) { ["a"]=> int(1) ["b:protected"]=> int(2) ["c:private"]=> int(3) } OK array(2) { [0]=> object(Obj)#%d (3) { ["a"]=> int(1) ["b:protected"]=> int(2) ["c:private"]=> int(3) } [1]=> object(Obj)#%d (3) { ["a"]=> int(4) ["b:protected"]=> int(5) ["c:private"]=> int(6) } } OK array(2) { [0]=> &object(Obj)#%d (3) { ["a"]=> int(1) ["b:protected"]=> int(2) ["c:private"]=> int(3) } [1]=> &object(Obj)#%d (3) { ["a"]=> int(1) ["b:protected"]=> int(2) ["c:private"]=> int(3) } } OK msgpack-0.5.5/tests/062.phpt0000644000077100007710000000222712110565607015400 0ustar xinchenxinchen--TEST-- Extra bytes buffered streaming unserialization --SKIPIF-- --FILE-- feed($str); while (true) { if ($unpacker->execute()) { $unserialized = $unpacker->data(); var_dump($unserialized); $unpacker->reset(); } else { break; } } $i += $len; } } } test('array(1, 2, 3)', array('9301020392')); test('array(1, 2, 3), array(3, 9), 4', array('9301020392', '030904')); --EXPECTF-- array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } array(2) { [0]=> int(3) [1]=> int(9) } int(4) msgpack-0.5.5/tests/063.phpt0000644000077100007710000000237012110565607015400 0ustar xinchenxinchen--TEST-- Extra bytes unbuffered streaming unserialization --SKIPIF-- --FILE-- execute($str, $offset)) { $unserialized = $unpacker->data(); var_dump($unserialized); $unpacker->reset(); $str = substr($str, $offset); $offset = 0; } else { break; } } $i += $len; } } } test('array(1, 2, 3)', array('9301020392')); test('array(1, 2, 3), array(3, 9), 4', array('9301020392', '030904')); --EXPECTF-- array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } array(2) { [0]=> int(3) [1]=> int(9) } int(4) msgpack-0.5.5/tests/064.phpt0000644000077100007710000001123012110565607015374 0ustar xinchenxinchen--TEST-- Check for buffered streaming unserialization (single) --SKIPIF-- = 0 && version_compare(PHP_VERSION, '5.3.2') <= 0)) { echo "skip tests in PHP 5.2.14/5.3.3 or newer"; } --FILE-- feed($str); if ($unpacker->execute()) { $unserialized = $unpacker->data(); var_dump($unserialized); $unpacker->reset(); } $i += $len; } if (!is_bool($test)) { echo $unserialized === $variable ? 'OK' : 'ERROR', PHP_EOL; } else { echo $test || $unserialized == $variable ? 'OK' : 'ERROR', PHP_EOL; } } test('null', null); test('bool: true', true); test('bool: false', false); test('zero: 0', 0); test('small: 1', 1); test('small: -1', -1); test('medium: 1000', 1000); test('medium: -1000', -1000); test('large: 100000', 100000); test('large: -100000', -100000); test('double: 123.456', 123.456); test('empty: ""', ""); test('string: "foobar"', "foobar"); test('array', array(), false); test('array(1, 2, 3)', array(1, 2, 3), false); test('array(array(1, 2, 3), arr...', array(array(1, 2, 3), array(4, 5, 6), array(7, 8, 9)), false); test('array("foo", "foo", "foo")', array("foo", "foo", "foo"), false); test('array("one" => 1, "two" => 2))', array("one" => 1, "two" => 2), false); test('array("kek" => "lol", "lol" => "kek")', array("kek" => "lol", "lol" => "kek"), false); test('array("" => "empty")', array("" => "empty"), false); $a = array('foo'); test('array($a, $a)', array($a, $a), false); test('array(&$a, &$a)', array(&$a, &$a), false); $a = array(null); $b = array(&$a); $a[0] = &$b; test('cyclic', $a, true); $a = array( 'a' => array( 'b' => 'c', 'd' => 'e' ), 'f' => array( 'g' => 'h' ) ); test('array', $a, false); class Obj { public $a; protected $b; private $c; function __construct($a, $b, $c) { $this->a = $a; $this->b = $b; $this->c = $c; } } test('object', new Obj(1, 2, 3), false); test('object', array(new Obj(1, 2, 3), new Obj(4, 5, 6)), false); $o = new Obj(1, 2, 3); test('object', array(&$o, &$o), false); --EXPECTF-- NULL OK bool(true) OK bool(false) OK int(0) OK int(1) OK int(-1) OK int(1000) OK int(-1000) OK int(100000) OK int(-100000) OK float(123.456) OK string(0) "" OK string(6) "foobar" OK array(0) { } OK array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } OK array(3) { [0]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } [1]=> array(3) { [0]=> int(4) [1]=> int(5) [2]=> int(6) } [2]=> array(3) { [0]=> int(7) [1]=> int(8) [2]=> int(9) } } OK array(3) { [0]=> string(3) "foo" [1]=> string(3) "foo" [2]=> string(3) "foo" } OK array(2) { ["one"]=> int(1) ["two"]=> int(2) } OK array(2) { ["kek"]=> string(3) "lol" ["lol"]=> string(3) "kek" } OK array(1) { [""]=> string(5) "empty" } OK array(2) { [0]=> array(1) { [0]=> string(3) "foo" } [1]=> array(1) { [0]=> string(3) "foo" } } OK array(2) { [0]=> &array(1) { [0]=> string(3) "foo" } [1]=> &array(1) { [0]=> string(3) "foo" } } OK array(1) { [0]=> &array(1) { [0]=> &array(1) { [0]=> *RECURSION* } } } OK array(2) { ["a"]=> array(2) { ["b"]=> string(1) "c" ["d"]=> string(1) "e" } ["f"]=> array(1) { ["g"]=> string(1) "h" } } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK array(2) { [0]=> object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } [1]=> object(Obj)#%d (3) { ["a"]=> int(4) [%r"?b"?:protected"?%r]=> int(5) [%r"?c"?:("Obj":)?private"?%r]=> int(6) } } OK array(2) { [0]=> &object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } [1]=> &object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } } OK msgpack-0.5.5/tests/064b.phpt0000644000077100007710000001151712110565607015546 0ustar xinchenxinchen--TEST-- Check for buffered streaming unserialization (single) --SKIPIF-- = 0) || (version_compare(PHP_VERSION, '5.3.3') >= 0)) { echo "skip tests in PHP 5.2.13/5.3.2 or older"; } if (version_compare(PHP_VERSION, '5.2.0') < 0) { echo "skip tests in PHP 5.2 or newer"; } --FILE-- feed($str); if ($unpacker->execute()) { $unserialized = $unpacker->data(); var_dump($unserialized); $unpacker->reset(); } $i += $len; } if (!is_bool($test)) { echo $unserialized === $variable ? 'OK' : 'ERROR', PHP_EOL; } else { echo $test || $unserialized == $variable ? 'OK' : 'ERROR', PHP_EOL; } } test('null', null); test('bool: true', true); test('bool: false', false); test('zero: 0', 0); test('small: 1', 1); test('small: -1', -1); test('medium: 1000', 1000); test('medium: -1000', -1000); test('large: 100000', 100000); test('large: -100000', -100000); test('double: 123.456', 123.456); test('empty: ""', ""); test('string: "foobar"', "foobar"); test('array', array(), false); test('array(1, 2, 3)', array(1, 2, 3), false); test('array(array(1, 2, 3), arr...', array(array(1, 2, 3), array(4, 5, 6), array(7, 8, 9)), false); test('array("foo", "foo", "foo")', array("foo", "foo", "foo"), false); test('array("one" => 1, "two" => 2))', array("one" => 1, "two" => 2), false); test('array("kek" => "lol", "lol" => "kek")', array("kek" => "lol", "lol" => "kek"), false); test('array("" => "empty")', array("" => "empty"), false); $a = array('foo'); test('array($a, $a)', array($a, $a), false); test('array(&$a, &$a)', array(&$a, &$a), false); $a = array(null); $b = array(&$a); $a[0] = &$b; test('cyclic', $a, true); $a = array( 'a' => array( 'b' => 'c', 'd' => 'e' ), 'f' => array( 'g' => 'h' ) ); test('array', $a, false); class Obj { public $a; protected $b; private $c; function __construct($a, $b, $c) { $this->a = $a; $this->b = $b; $this->c = $c; } } test('object', new Obj(1, 2, 3), false); test('object', array(new Obj(1, 2, 3), new Obj(4, 5, 6)), false); $o = new Obj(1, 2, 3); test('object', array(&$o, &$o), false); --EXPECTF-- NULL OK bool(true) OK bool(false) OK int(0) OK int(1) OK int(-1) OK int(1000) OK int(-1000) OK int(100000) OK int(-100000) OK float(123.456) OK string(0) "" OK string(6) "foobar" OK array(0) { } OK array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } OK array(3) { [0]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } [1]=> array(3) { [0]=> int(4) [1]=> int(5) [2]=> int(6) } [2]=> array(3) { [0]=> int(7) [1]=> int(8) [2]=> int(9) } } OK array(3) { [0]=> string(3) "foo" [1]=> string(3) "foo" [2]=> string(3) "foo" } OK array(2) { ["one"]=> int(1) ["two"]=> int(2) } OK array(2) { ["kek"]=> string(3) "lol" ["lol"]=> string(3) "kek" } OK array(1) { [""]=> string(5) "empty" } OK array(2) { [0]=> array(1) { [0]=> string(3) "foo" } [1]=> array(1) { [0]=> string(3) "foo" } } OK array(2) { [0]=> &array(1) { [0]=> string(3) "foo" } [1]=> &array(1) { [0]=> string(3) "foo" } } OK array(1) { [0]=> &array(1) { [0]=> &array(1) { [0]=> &array(1) { [0]=> &array(1) { [0]=> *RECURSION* } } } } } OK array(2) { ["a"]=> array(2) { ["b"]=> string(1) "c" ["d"]=> string(1) "e" } ["f"]=> array(1) { ["g"]=> string(1) "h" } } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK array(2) { [0]=> object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } [1]=> object(Obj)#%d (3) { ["a"]=> int(4) [%r"?b"?:protected"?%r]=> int(5) [%r"?c"?:("Obj":)?private"?%r]=> int(6) } } OK array(2) { [0]=> &object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } [1]=> &object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } } OK msgpack-0.5.5/tests/064c.phpt0000644000077100007710000001100212110565607015534 0ustar xinchenxinchen--TEST-- Check for buffered streaming unserialization (single) --SKIPIF-- = 0) { echo "skip tests in PHP 5.1 or older"; } --FILE-- feed($str); if ($unpacker->execute()) { $unserialized = $unpacker->data(); var_dump($unserialized); $unpacker->reset(); } $i += $len; } if (!is_bool($test)) { echo $unserialized === $variable ? 'OK' : 'ERROR', PHP_EOL; } else { echo $test || $unserialized == $variable ? 'OK' : 'ERROR', PHP_EOL; } } test('null', null); test('bool: true', true); test('bool: false', false); test('zero: 0', 0); test('small: 1', 1); test('small: -1', -1); test('medium: 1000', 1000); test('medium: -1000', -1000); test('large: 100000', 100000); test('large: -100000', -100000); test('double: 123.456', 123.456); test('empty: ""', ""); test('string: "foobar"', "foobar"); test('array', array(), false); test('array(1, 2, 3)', array(1, 2, 3), false); test('array(array(1, 2, 3), arr...', array(array(1, 2, 3), array(4, 5, 6), array(7, 8, 9)), false); test('array("foo", "foo", "foo")', array("foo", "foo", "foo"), false); test('array("one" => 1, "two" => 2))', array("one" => 1, "two" => 2), false); test('array("kek" => "lol", "lol" => "kek")', array("kek" => "lol", "lol" => "kek"), false); test('array("" => "empty")', array("" => "empty"), false); $a = array('foo'); test('array($a, $a)', array($a, $a), false); test('array(&$a, &$a)', array(&$a, &$a), false); $a = array(null); $b = array(&$a); $a[0] = &$b; test('cyclic', $a, true); $a = array( 'a' => array( 'b' => 'c', 'd' => 'e' ), 'f' => array( 'g' => 'h' ) ); test('array', $a, false); class Obj { public $a; protected $b; private $c; function __construct($a, $b, $c) { $this->a = $a; $this->b = $b; $this->c = $c; } } test('object', new Obj(1, 2, 3), false); test('object', array(new Obj(1, 2, 3), new Obj(4, 5, 6)), false); $o = new Obj(1, 2, 3); test('object', array(&$o, &$o), false); --EXPECTF-- NULL OK bool(true) OK bool(false) OK int(0) OK int(1) OK int(-1) OK int(1000) OK int(-1000) OK int(100000) OK int(-100000) OK float(123.456) OK string(0) "" OK string(6) "foobar" OK array(0) { } OK array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } OK array(3) { [0]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } [1]=> array(3) { [0]=> int(4) [1]=> int(5) [2]=> int(6) } [2]=> array(3) { [0]=> int(7) [1]=> int(8) [2]=> int(9) } } OK array(3) { [0]=> string(3) "foo" [1]=> string(3) "foo" [2]=> string(3) "foo" } OK array(2) { ["one"]=> int(1) ["two"]=> int(2) } OK array(2) { ["kek"]=> string(3) "lol" ["lol"]=> string(3) "kek" } OK array(1) { [""]=> string(5) "empty" } OK array(2) { [0]=> array(1) { [0]=> string(3) "foo" } [1]=> array(1) { [0]=> string(3) "foo" } } OK array(2) { [0]=> &array(1) { [0]=> string(3) "foo" } [1]=> &array(1) { [0]=> string(3) "foo" } } OK array(1) { [0]=> &array(1) { [0]=> &array(1) { [0]=> &array(1) { [0]=> &array(1) { [0]=> *RECURSION* } } } } } OK array(2) { ["a"]=> array(2) { ["b"]=> string(1) "c" ["d"]=> string(1) "e" } ["f"]=> array(1) { ["g"]=> string(1) "h" } } OK object(Obj)#%d (3) { ["a"]=> int(1) ["b:protected"]=> int(2) ["c:private"]=> int(3) } OK array(2) { [0]=> object(Obj)#%d (3) { ["a"]=> int(1) ["b:protected"]=> int(2) ["c:private"]=> int(3) } [1]=> object(Obj)#%d (3) { ["a"]=> int(4) ["b:protected"]=> int(5) ["c:private"]=> int(6) } } OK array(2) { [0]=> &object(Obj)#%d (3) { ["a"]=> int(1) ["b:protected"]=> int(2) ["c:private"]=> int(3) } [1]=> &object(Obj)#%d (3) { ["a"]=> int(1) ["b:protected"]=> int(2) ["c:private"]=> int(3) } } OK msgpack-0.5.5/tests/065.phpt0000644000077100007710000001134212110565607015401 0ustar xinchenxinchen--TEST-- Check for unbuffered streaming unserialization (single) --SKIPIF-- = 0 && version_compare(PHP_VERSION, '5.3.2') <= 0)) { echo "skip tests in PHP 5.2.14/5.3.3 or newer"; } --FILE-- execute($str, $offset)) { $unserialized = $unpacker->data(); var_dump($unserialized); $unpacker->reset(); $str = ""; $offset = 0; } $i += $len; } if (!is_bool($test)) { echo $unserialized === $variable ? 'OK' : 'ERROR', PHP_EOL; } else { echo $test || $unserialized == $variable ? 'OK' : 'ERROR', PHP_EOL; } } test('null', null); test('bool: true', true); test('bool: false', false); test('zero: 0', 0); test('small: 1', 1); test('small: -1', -1); test('medium: 1000', 1000); test('medium: -1000', -1000); test('large: 100000', 100000); test('large: -100000', -100000); test('double: 123.456', 123.456); test('empty: ""', ""); test('string: "foobar"', "foobar"); test('array: empty', array(), false); test('array(1, 2, 3)', array(1, 2, 3), false); test('array(array(1, 2, 3), arr...', array(array(1, 2, 3), array(4, 5, 6), array(7, 8, 9)), false); test('array("foo", "foo", "foo")', array("foo", "foo", "foo"), false); test('array("one" => 1, "two" => 2))', array("one" => 1, "two" => 2), false); test('array("kek" => "lol", "lol" => "kek")', array("kek" => "lol", "lol" => "kek"), false); test('array("" => "empty")', array("" => "empty"), false); $a = array('foo'); test('array($a, $a)', array($a, $a), false); test('array(&$a, &$a)', array(&$a, &$a), false); $a = array(null); $b = array(&$a); $a[0] = &$b; test('cyclic', $a, true); $a = array( 'a' => array( 'b' => 'c', 'd' => 'e' ), 'f' => array( 'g' => 'h' ) ); test('array', $a, false); class Obj { public $a; protected $b; private $c; function __construct($a, $b, $c) { $this->a = $a; $this->b = $b; $this->c = $c; } } test('object', new Obj(1, 2, 3), false); test('object', array(new Obj(1, 2, 3), new Obj(4, 5, 6)), false); $o = new Obj(1, 2, 3); test('object', array(&$o, &$o), false); --EXPECTF-- NULL OK bool(true) OK bool(false) OK int(0) OK int(1) OK int(-1) OK int(1000) OK int(-1000) OK int(100000) OK int(-100000) OK float(123.456) OK string(0) "" OK string(6) "foobar" OK array(0) { } OK array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } OK array(3) { [0]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } [1]=> array(3) { [0]=> int(4) [1]=> int(5) [2]=> int(6) } [2]=> array(3) { [0]=> int(7) [1]=> int(8) [2]=> int(9) } } OK array(3) { [0]=> string(3) "foo" [1]=> string(3) "foo" [2]=> string(3) "foo" } OK array(2) { ["one"]=> int(1) ["two"]=> int(2) } OK array(2) { ["kek"]=> string(3) "lol" ["lol"]=> string(3) "kek" } OK array(1) { [""]=> string(5) "empty" } OK array(2) { [0]=> array(1) { [0]=> string(3) "foo" } [1]=> array(1) { [0]=> string(3) "foo" } } OK array(2) { [0]=> &array(1) { [0]=> string(3) "foo" } [1]=> &array(1) { [0]=> string(3) "foo" } } OK array(1) { [0]=> &array(1) { [0]=> &array(1) { [0]=> *RECURSION* } } } OK array(2) { ["a"]=> array(2) { ["b"]=> string(1) "c" ["d"]=> string(1) "e" } ["f"]=> array(1) { ["g"]=> string(1) "h" } } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK array(2) { [0]=> object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } [1]=> object(Obj)#%d (3) { ["a"]=> int(4) [%r"?b"?:protected"?%r]=> int(5) [%r"?c"?:("Obj":)?private"?%r]=> int(6) } } OK array(2) { [0]=> &object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } [1]=> &object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } } OK msgpack-0.5.5/tests/065b.phpt0000644000077100007710000001163112110565607015544 0ustar xinchenxinchen--TEST-- Check for unbuffered streaming unserialization (single) --SKIPIF-- = 0) || (version_compare(PHP_VERSION, '5.3.3') >= 0)) { echo "skip tests in PHP 5.2.13/5.3.2 or older"; } if (version_compare(PHP_VERSION, '5.2.0') < 0) { echo "skip tests in PHP 5.2 or newer"; } --FILE-- execute($str, $offset)) { $unserialized = $unpacker->data(); var_dump($unserialized); $unpacker->reset(); $str = ""; $offset = 0; } $i += $len; } if (!is_bool($test)) { echo $unserialized === $variable ? 'OK' : 'ERROR', PHP_EOL; } else { echo $test || $unserialized == $variable ? 'OK' : 'ERROR', PHP_EOL; } } test('null', null); test('bool: true', true); test('bool: false', false); test('zero: 0', 0); test('small: 1', 1); test('small: -1', -1); test('medium: 1000', 1000); test('medium: -1000', -1000); test('large: 100000', 100000); test('large: -100000', -100000); test('double: 123.456', 123.456); test('empty: ""', ""); test('string: "foobar"', "foobar"); test('array: empty', array(), false); test('array(1, 2, 3)', array(1, 2, 3), false); test('array(array(1, 2, 3), arr...', array(array(1, 2, 3), array(4, 5, 6), array(7, 8, 9)), false); test('array("foo", "foo", "foo")', array("foo", "foo", "foo"), false); test('array("one" => 1, "two" => 2))', array("one" => 1, "two" => 2), false); test('array("kek" => "lol", "lol" => "kek")', array("kek" => "lol", "lol" => "kek"), false); test('array("" => "empty")', array("" => "empty"), false); $a = array('foo'); test('array($a, $a)', array($a, $a), false); test('array(&$a, &$a)', array(&$a, &$a), false); $a = array(null); $b = array(&$a); $a[0] = &$b; test('cyclic', $a, true); $a = array( 'a' => array( 'b' => 'c', 'd' => 'e' ), 'f' => array( 'g' => 'h' ) ); test('array', $a, false); class Obj { public $a; protected $b; private $c; function __construct($a, $b, $c) { $this->a = $a; $this->b = $b; $this->c = $c; } } test('object', new Obj(1, 2, 3), false); test('object', array(new Obj(1, 2, 3), new Obj(4, 5, 6)), false); $o = new Obj(1, 2, 3); test('object', array(&$o, &$o), false); --EXPECTF-- NULL OK bool(true) OK bool(false) OK int(0) OK int(1) OK int(-1) OK int(1000) OK int(-1000) OK int(100000) OK int(-100000) OK float(123.456) OK string(0) "" OK string(6) "foobar" OK array(0) { } OK array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } OK array(3) { [0]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } [1]=> array(3) { [0]=> int(4) [1]=> int(5) [2]=> int(6) } [2]=> array(3) { [0]=> int(7) [1]=> int(8) [2]=> int(9) } } OK array(3) { [0]=> string(3) "foo" [1]=> string(3) "foo" [2]=> string(3) "foo" } OK array(2) { ["one"]=> int(1) ["two"]=> int(2) } OK array(2) { ["kek"]=> string(3) "lol" ["lol"]=> string(3) "kek" } OK array(1) { [""]=> string(5) "empty" } OK array(2) { [0]=> array(1) { [0]=> string(3) "foo" } [1]=> array(1) { [0]=> string(3) "foo" } } OK array(2) { [0]=> &array(1) { [0]=> string(3) "foo" } [1]=> &array(1) { [0]=> string(3) "foo" } } OK array(1) { [0]=> &array(1) { [0]=> &array(1) { [0]=> &array(1) { [0]=> &array(1) { [0]=> *RECURSION* } } } } } OK array(2) { ["a"]=> array(2) { ["b"]=> string(1) "c" ["d"]=> string(1) "e" } ["f"]=> array(1) { ["g"]=> string(1) "h" } } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK array(2) { [0]=> object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } [1]=> object(Obj)#%d (3) { ["a"]=> int(4) [%r"?b"?:protected"?%r]=> int(5) [%r"?c"?:("Obj":)?private"?%r]=> int(6) } } OK array(2) { [0]=> &object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } [1]=> &object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } } OK msgpack-0.5.5/tests/065c.phpt0000644000077100007710000001111412110565607015541 0ustar xinchenxinchen--TEST-- Check for unbuffered streaming unserialization (single) --SKIPIF-- = 0) { echo "skip tests in PHP 5.1 or older"; } --FILE-- execute($str, $offset)) { $unserialized = $unpacker->data(); var_dump($unserialized); $unpacker->reset(); $str = ""; $offset = 0; } $i += $len; } if (!is_bool($test)) { echo $unserialized === $variable ? 'OK' : 'ERROR', PHP_EOL; } else { echo $test || $unserialized == $variable ? 'OK' : 'ERROR', PHP_EOL; } } test('null', null); test('bool: true', true); test('bool: false', false); test('zero: 0', 0); test('small: 1', 1); test('small: -1', -1); test('medium: 1000', 1000); test('medium: -1000', -1000); test('large: 100000', 100000); test('large: -100000', -100000); test('double: 123.456', 123.456); test('empty: ""', ""); test('string: "foobar"', "foobar"); test('array: empty', array(), false); test('array(1, 2, 3)', array(1, 2, 3), false); test('array(array(1, 2, 3), arr...', array(array(1, 2, 3), array(4, 5, 6), array(7, 8, 9)), false); test('array("foo", "foo", "foo")', array("foo", "foo", "foo"), false); test('array("one" => 1, "two" => 2))', array("one" => 1, "two" => 2), false); test('array("kek" => "lol", "lol" => "kek")', array("kek" => "lol", "lol" => "kek"), false); test('array("" => "empty")', array("" => "empty"), false); $a = array('foo'); test('array($a, $a)', array($a, $a), false); test('array(&$a, &$a)', array(&$a, &$a), false); $a = array(null); $b = array(&$a); $a[0] = &$b; test('cyclic', $a, true); $a = array( 'a' => array( 'b' => 'c', 'd' => 'e' ), 'f' => array( 'g' => 'h' ) ); test('array', $a, false); class Obj { public $a; protected $b; private $c; function __construct($a, $b, $c) { $this->a = $a; $this->b = $b; $this->c = $c; } } test('object', new Obj(1, 2, 3), false); test('object', array(new Obj(1, 2, 3), new Obj(4, 5, 6)), false); $o = new Obj(1, 2, 3); test('object', array(&$o, &$o), false); --EXPECTF-- NULL OK bool(true) OK bool(false) OK int(0) OK int(1) OK int(-1) OK int(1000) OK int(-1000) OK int(100000) OK int(-100000) OK float(123.456) OK string(0) "" OK string(6) "foobar" OK array(0) { } OK array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } OK array(3) { [0]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } [1]=> array(3) { [0]=> int(4) [1]=> int(5) [2]=> int(6) } [2]=> array(3) { [0]=> int(7) [1]=> int(8) [2]=> int(9) } } OK array(3) { [0]=> string(3) "foo" [1]=> string(3) "foo" [2]=> string(3) "foo" } OK array(2) { ["one"]=> int(1) ["two"]=> int(2) } OK array(2) { ["kek"]=> string(3) "lol" ["lol"]=> string(3) "kek" } OK array(1) { [""]=> string(5) "empty" } OK array(2) { [0]=> array(1) { [0]=> string(3) "foo" } [1]=> array(1) { [0]=> string(3) "foo" } } OK array(2) { [0]=> &array(1) { [0]=> string(3) "foo" } [1]=> &array(1) { [0]=> string(3) "foo" } } OK array(1) { [0]=> &array(1) { [0]=> &array(1) { [0]=> &array(1) { [0]=> &array(1) { [0]=> *RECURSION* } } } } } OK array(2) { ["a"]=> array(2) { ["b"]=> string(1) "c" ["d"]=> string(1) "e" } ["f"]=> array(1) { ["g"]=> string(1) "h" } } OK object(Obj)#%d (3) { ["a"]=> int(1) ["b:protected"]=> int(2) ["c:private"]=> int(3) } OK array(2) { [0]=> object(Obj)#%d (3) { ["a"]=> int(1) ["b:protected"]=> int(2) ["c:private"]=> int(3) } [1]=> object(Obj)#%d (3) { ["a"]=> int(4) ["b:protected"]=> int(5) ["c:private"]=> int(6) } } OK array(2) { [0]=> &object(Obj)#%d (3) { ["a"]=> int(1) ["b:protected"]=> int(2) ["c:private"]=> int(3) } [1]=> &object(Obj)#%d (3) { ["a"]=> int(1) ["b:protected"]=> int(2) ["c:private"]=> int(3) } } OK msgpack-0.5.5/tests/066.phpt0000644000077100007710000000235412110565607015405 0ustar xinchenxinchen--TEST-- Extra bytes buffered streaming unserialization (single) --SKIPIF-- --FILE-- feed($str); while (true) { if ($unpacker->execute()) { $unserialized = $unpacker->data(); var_dump($unserialized); $unpacker->reset(); } else { break; } } $i += $len; } } } test('array(1, 2, 3)', array('9301020392')); test('array(1, 2, 3), array(3, 9), 4', array('9301020392', '030904')); --EXPECTF-- array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } array(2) { [0]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } [1]=> array(2) { [0]=> int(3) [1]=> int(9) } } int(4) msgpack-0.5.5/tests/067.phpt0000644000077100007710000000251512110565607015405 0ustar xinchenxinchen--TEST-- Extra bytes unbuffered streaming unserialization (single) --SKIPIF-- --FILE-- execute($str, $offset)) { $unserialized = $unpacker->data(); var_dump($unserialized); $unpacker->reset(); $str = substr($str, $offset); $offset = 0; } else { break; } } $i += $len; } } } test('array(1, 2, 3)', array('9301020392')); test('array(1, 2, 3), array(3, 9), 4', array('9301020392', '030904')); --EXPECTF-- array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } array(2) { [0]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } [1]=> array(2) { [0]=> int(3) [1]=> int(9) } } int(4) msgpack-0.5.5/tests/070.phpt0000644000077100007710000001043012110565607015372 0ustar xinchenxinchen--TEST-- Check for alias functions --SKIPIF-- = 0 && version_compare(PHP_VERSION, '5.3.2') <= 0)) { echo "skip tests in PHP 5.2.14/5.3.3 or newer"; } --FILE-- 1, "two" => 2))', array("one" => 1, "two" => 2), false); test('array("kek" => "lol", "lol" => "kek")', array("kek" => "lol", "lol" => "kek"), false); test('array("" => "empty")', array("" => "empty"), false); $a = array('foo'); test('array($a, $a)', array($a, $a), false); test('array(&$a, &$a)', array(&$a, &$a), false); $a = array(null); $b = array(&$a); $a[0] = &$b; test('cyclic', $a, true); $a = array( 'a' => array( 'b' => 'c', 'd' => 'e' ), 'f' => array( 'g' => 'h' ) ); test('array', $a, false); class Obj { public $a; protected $b; private $c; function __construct($a, $b, $c) { $this->a = $a; $this->b = $b; $this->c = $c; } } test('object', new Obj(1, 2, 3), false); test('object', array(new Obj(1, 2, 3), new Obj(4, 5, 6)), false); $o = new Obj(1, 2, 3); test('object', array(&$o, &$o), false); --EXPECTF-- NULL OK bool(true) OK bool(false) OK int(0) OK int(1) OK int(-1) OK int(1000) OK int(-1000) OK int(100000) OK int(-100000) OK float(123.456) OK string(0) "" OK string(6) "foobar" OK array(0) { } OK array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } OK array(3) { [0]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } [1]=> array(3) { [0]=> int(4) [1]=> int(5) [2]=> int(6) } [2]=> array(3) { [0]=> int(7) [1]=> int(8) [2]=> int(9) } } OK array(3) { [0]=> string(3) "foo" [1]=> string(3) "foo" [2]=> string(3) "foo" } OK array(2) { ["one"]=> int(1) ["two"]=> int(2) } OK array(2) { ["kek"]=> string(3) "lol" ["lol"]=> string(3) "kek" } OK array(1) { [""]=> string(5) "empty" } OK array(2) { [0]=> array(1) { [0]=> string(3) "foo" } [1]=> array(1) { [0]=> string(3) "foo" } } OK array(2) { [0]=> &array(1) { [0]=> string(3) "foo" } [1]=> &array(1) { [0]=> string(3) "foo" } } OK array(1) { [0]=> &array(1) { [0]=> &array(1) { [0]=> *RECURSION* } } } OK array(2) { ["a"]=> array(2) { ["b"]=> string(1) "c" ["d"]=> string(1) "e" } ["f"]=> array(1) { ["g"]=> string(1) "h" } } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK array(2) { [0]=> object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } [1]=> object(Obj)#%d (3) { ["a"]=> int(4) [%r"?b"?:protected"?%r]=> int(5) [%r"?c"?:("Obj":)?private"?%r]=> int(6) } } OK array(2) { [0]=> &object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } [1]=> &object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } } OK msgpack-0.5.5/tests/070b.phpt0000644000077100007710000001071712110565607015544 0ustar xinchenxinchen--TEST-- Check for alias functions --SKIPIF-- = 0) || (version_compare(PHP_VERSION, '5.3.3') >= 0)) { echo "skip tests in PHP 5.2.13/5.3.2 or older"; } if (version_compare(PHP_VERSION, '5.2.0') < 0) { echo "skip tests in PHP 5.2 or newer"; } --FILE-- 1, "two" => 2))', array("one" => 1, "two" => 2), false); test('array("kek" => "lol", "lol" => "kek")', array("kek" => "lol", "lol" => "kek"), false); test('array("" => "empty")', array("" => "empty"), false); $a = array('foo'); test('array($a, $a)', array($a, $a), false); test('array(&$a, &$a)', array(&$a, &$a), false); $a = array(null); $b = array(&$a); $a[0] = &$b; test('cyclic', $a, true); $a = array( 'a' => array( 'b' => 'c', 'd' => 'e' ), 'f' => array( 'g' => 'h' ) ); test('array', $a, false); class Obj { public $a; protected $b; private $c; function __construct($a, $b, $c) { $this->a = $a; $this->b = $b; $this->c = $c; } } test('object', new Obj(1, 2, 3), false); test('object', array(new Obj(1, 2, 3), new Obj(4, 5, 6)), false); $o = new Obj(1, 2, 3); test('object', array(&$o, &$o), false); --EXPECTF-- NULL OK bool(true) OK bool(false) OK int(0) OK int(1) OK int(-1) OK int(1000) OK int(-1000) OK int(100000) OK int(-100000) OK float(123.456) OK string(0) "" OK string(6) "foobar" OK array(0) { } OK array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } OK array(3) { [0]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } [1]=> array(3) { [0]=> int(4) [1]=> int(5) [2]=> int(6) } [2]=> array(3) { [0]=> int(7) [1]=> int(8) [2]=> int(9) } } OK array(3) { [0]=> string(3) "foo" [1]=> string(3) "foo" [2]=> string(3) "foo" } OK array(2) { ["one"]=> int(1) ["two"]=> int(2) } OK array(2) { ["kek"]=> string(3) "lol" ["lol"]=> string(3) "kek" } OK array(1) { [""]=> string(5) "empty" } OK array(2) { [0]=> array(1) { [0]=> string(3) "foo" } [1]=> array(1) { [0]=> string(3) "foo" } } OK array(2) { [0]=> &array(1) { [0]=> string(3) "foo" } [1]=> &array(1) { [0]=> string(3) "foo" } } OK array(1) { [0]=> &array(1) { [0]=> &array(1) { [0]=> &array(1) { [0]=> &array(1) { [0]=> *RECURSION* } } } } } OK array(2) { ["a"]=> array(2) { ["b"]=> string(1) "c" ["d"]=> string(1) "e" } ["f"]=> array(1) { ["g"]=> string(1) "h" } } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK array(2) { [0]=> object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } [1]=> object(Obj)#%d (3) { ["a"]=> int(4) [%r"?b"?:protected"?%r]=> int(5) [%r"?c"?:("Obj":)?private"?%r]=> int(6) } } OK array(2) { [0]=> &object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } [1]=> &object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } } OK msgpack-0.5.5/tests/070c.phpt0000644000077100007710000001020212110565607015532 0ustar xinchenxinchen--TEST-- Check for alias functions --SKIPIF-- = 0) { echo "skip tests in PHP 5.1 or older"; } --FILE-- 1, "two" => 2))', array("one" => 1, "two" => 2), false); test('array("kek" => "lol", "lol" => "kek")', array("kek" => "lol", "lol" => "kek"), false); test('array("" => "empty")', array("" => "empty"), false); $a = array('foo'); test('array($a, $a)', array($a, $a), false); test('array(&$a, &$a)', array(&$a, &$a), false); $a = array(null); $b = array(&$a); $a[0] = &$b; test('cyclic', $a, true); $a = array( 'a' => array( 'b' => 'c', 'd' => 'e' ), 'f' => array( 'g' => 'h' ) ); test('array', $a, false); class Obj { public $a; protected $b; private $c; function __construct($a, $b, $c) { $this->a = $a; $this->b = $b; $this->c = $c; } } test('object', new Obj(1, 2, 3), false); test('object', array(new Obj(1, 2, 3), new Obj(4, 5, 6)), false); $o = new Obj(1, 2, 3); test('object', array(&$o, &$o), false); --EXPECTF-- NULL OK bool(true) OK bool(false) OK int(0) OK int(1) OK int(-1) OK int(1000) OK int(-1000) OK int(100000) OK int(-100000) OK float(123.456) OK string(0) "" OK string(6) "foobar" OK array(0) { } OK array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } OK array(3) { [0]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } [1]=> array(3) { [0]=> int(4) [1]=> int(5) [2]=> int(6) } [2]=> array(3) { [0]=> int(7) [1]=> int(8) [2]=> int(9) } } OK array(3) { [0]=> string(3) "foo" [1]=> string(3) "foo" [2]=> string(3) "foo" } OK array(2) { ["one"]=> int(1) ["two"]=> int(2) } OK array(2) { ["kek"]=> string(3) "lol" ["lol"]=> string(3) "kek" } OK array(1) { [""]=> string(5) "empty" } OK array(2) { [0]=> array(1) { [0]=> string(3) "foo" } [1]=> array(1) { [0]=> string(3) "foo" } } OK array(2) { [0]=> &array(1) { [0]=> string(3) "foo" } [1]=> &array(1) { [0]=> string(3) "foo" } } OK array(1) { [0]=> &array(1) { [0]=> &array(1) { [0]=> &array(1) { [0]=> &array(1) { [0]=> *RECURSION* } } } } } OK array(2) { ["a"]=> array(2) { ["b"]=> string(1) "c" ["d"]=> string(1) "e" } ["f"]=> array(1) { ["g"]=> string(1) "h" } } OK object(Obj)#%d (3) { ["a"]=> int(1) ["b:protected"]=> int(2) ["c:private"]=> int(3) } OK array(2) { [0]=> object(Obj)#%d (3) { ["a"]=> int(1) ["b:protected"]=> int(2) ["c:private"]=> int(3) } [1]=> object(Obj)#%d (3) { ["a"]=> int(4) ["b:protected"]=> int(5) ["c:private"]=> int(6) } } OK array(2) { [0]=> &object(Obj)#%d (3) { ["a"]=> int(1) ["b:protected"]=> int(2) ["c:private"]=> int(3) } [1]=> &object(Obj)#%d (3) { ["a"]=> int(1) ["b:protected"]=> int(2) ["c:private"]=> int(3) } } OK msgpack-0.5.5/tests/071.phpt0000644000077100007710000001047512110565607015404 0ustar xinchenxinchen--TEST-- Check for class methods --SKIPIF-- = 0 && version_compare(PHP_VERSION, '5.3.2') <= 0)) { echo "skip tests in PHP 5.2.14/5.3.3 or newer"; } --FILE-- pack($variable); $unserialized = $msgpack->unpack($serialized); var_dump($unserialized); if (!is_bool($test)) { echo $unserialized === $variable ? 'OK' : 'ERROR', PHP_EOL; } else { echo $test || $unserialized == $variable ? 'OK' : 'ERROR', PHP_EOL; } } test('null', null); test('bool: true', true); test('bool: false', false); test('zero: 0', 0); test('small: 1', 1); test('small: -1', -1); test('medium: 1000', 1000); test('medium: -1000', -1000); test('large: 100000', 100000); test('large: -100000', -100000); test('double: 123.456', 123.456); test('empty: ""', ""); test('string: "foobar"', "foobar"); test('array: empty', array(), false); test('array(1, 2, 3)', array(1, 2, 3), false); test('array(array(1, 2, 3), arr...', array(array(1, 2, 3), array(4, 5, 6), array(7, 8, 9)), false); test('array("foo", "foo", "foo")', array("foo", "foo", "foo"), false); test('array("one" => 1, "two" => 2))', array("one" => 1, "two" => 2), false); test('array("kek" => "lol", "lol" => "kek")', array("kek" => "lol", "lol" => "kek"), false); test('array("" => "empty")', array("" => "empty"), false); $a = array('foo'); test('array($a, $a)', array($a, $a), false); test('array(&$a, &$a)', array(&$a, &$a), false); $a = array(null); $b = array(&$a); $a[0] = &$b; test('cyclic', $a, true); $a = array( 'a' => array( 'b' => 'c', 'd' => 'e' ), 'f' => array( 'g' => 'h' ) ); test('array', $a, false); class Obj { public $a; protected $b; private $c; function __construct($a, $b, $c) { $this->a = $a; $this->b = $b; $this->c = $c; } } test('object', new Obj(1, 2, 3), false); test('object', array(new Obj(1, 2, 3), new Obj(4, 5, 6)), false); $o = new Obj(1, 2, 3); test('object', array(&$o, &$o), false); --EXPECTF-- NULL OK bool(true) OK bool(false) OK int(0) OK int(1) OK int(-1) OK int(1000) OK int(-1000) OK int(100000) OK int(-100000) OK float(123.456) OK string(0) "" OK string(6) "foobar" OK array(0) { } OK array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } OK array(3) { [0]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } [1]=> array(3) { [0]=> int(4) [1]=> int(5) [2]=> int(6) } [2]=> array(3) { [0]=> int(7) [1]=> int(8) [2]=> int(9) } } OK array(3) { [0]=> string(3) "foo" [1]=> string(3) "foo" [2]=> string(3) "foo" } OK array(2) { ["one"]=> int(1) ["two"]=> int(2) } OK array(2) { ["kek"]=> string(3) "lol" ["lol"]=> string(3) "kek" } OK array(1) { [""]=> string(5) "empty" } OK array(2) { [0]=> array(1) { [0]=> string(3) "foo" } [1]=> array(1) { [0]=> string(3) "foo" } } OK array(2) { [0]=> &array(1) { [0]=> string(3) "foo" } [1]=> &array(1) { [0]=> string(3) "foo" } } OK array(1) { [0]=> &array(1) { [0]=> &array(1) { [0]=> *RECURSION* } } } OK array(2) { ["a"]=> array(2) { ["b"]=> string(1) "c" ["d"]=> string(1) "e" } ["f"]=> array(1) { ["g"]=> string(1) "h" } } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK array(2) { [0]=> object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } [1]=> object(Obj)#%d (3) { ["a"]=> int(4) [%r"?b"?:protected"?%r]=> int(5) [%r"?c"?:("Obj":)?private"?%r]=> int(6) } } OK array(2) { [0]=> &object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } [1]=> &object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } } OK msgpack-0.5.5/tests/071b.phpt0000644000077100007710000001076412110565607015547 0ustar xinchenxinchen--TEST-- Check for class methods --SKIPIF-- = 0) || (version_compare(PHP_VERSION, '5.3.3') >= 0)) { echo "skip tests in PHP 5.2.13/5.3.2 or older"; } if (version_compare(PHP_VERSION, '5.2.0') < 0) { echo "skip tests in PHP 5.2 or newer"; } --FILE-- pack($variable); $unserialized = $msgpack->unpack($serialized); var_dump($unserialized); if (!is_bool($test)) { echo $unserialized === $variable ? 'OK' : 'ERROR', PHP_EOL; } else { echo $test || $unserialized == $variable ? 'OK' : 'ERROR', PHP_EOL; } } test('null', null); test('bool: true', true); test('bool: false', false); test('zero: 0', 0); test('small: 1', 1); test('small: -1', -1); test('medium: 1000', 1000); test('medium: -1000', -1000); test('large: 100000', 100000); test('large: -100000', -100000); test('double: 123.456', 123.456); test('empty: ""', ""); test('string: "foobar"', "foobar"); test('array: empty', array(), false); test('array(1, 2, 3)', array(1, 2, 3), false); test('array(array(1, 2, 3), arr...', array(array(1, 2, 3), array(4, 5, 6), array(7, 8, 9)), false); test('array("foo", "foo", "foo")', array("foo", "foo", "foo"), false); test('array("one" => 1, "two" => 2))', array("one" => 1, "two" => 2), false); test('array("kek" => "lol", "lol" => "kek")', array("kek" => "lol", "lol" => "kek"), false); test('array("" => "empty")', array("" => "empty"), false); $a = array('foo'); test('array($a, $a)', array($a, $a), false); test('array(&$a, &$a)', array(&$a, &$a), false); $a = array(null); $b = array(&$a); $a[0] = &$b; test('cyclic', $a, true); $a = array( 'a' => array( 'b' => 'c', 'd' => 'e' ), 'f' => array( 'g' => 'h' ) ); test('array', $a, false); class Obj { public $a; protected $b; private $c; function __construct($a, $b, $c) { $this->a = $a; $this->b = $b; $this->c = $c; } } test('object', new Obj(1, 2, 3), false); test('object', array(new Obj(1, 2, 3), new Obj(4, 5, 6)), false); $o = new Obj(1, 2, 3); test('object', array(&$o, &$o), false); --EXPECTF-- NULL OK bool(true) OK bool(false) OK int(0) OK int(1) OK int(-1) OK int(1000) OK int(-1000) OK int(100000) OK int(-100000) OK float(123.456) OK string(0) "" OK string(6) "foobar" OK array(0) { } OK array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } OK array(3) { [0]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } [1]=> array(3) { [0]=> int(4) [1]=> int(5) [2]=> int(6) } [2]=> array(3) { [0]=> int(7) [1]=> int(8) [2]=> int(9) } } OK array(3) { [0]=> string(3) "foo" [1]=> string(3) "foo" [2]=> string(3) "foo" } OK array(2) { ["one"]=> int(1) ["two"]=> int(2) } OK array(2) { ["kek"]=> string(3) "lol" ["lol"]=> string(3) "kek" } OK array(1) { [""]=> string(5) "empty" } OK array(2) { [0]=> array(1) { [0]=> string(3) "foo" } [1]=> array(1) { [0]=> string(3) "foo" } } OK array(2) { [0]=> &array(1) { [0]=> string(3) "foo" } [1]=> &array(1) { [0]=> string(3) "foo" } } OK array(1) { [0]=> &array(1) { [0]=> &array(1) { [0]=> &array(1) { [0]=> &array(1) { [0]=> *RECURSION* } } } } } OK array(2) { ["a"]=> array(2) { ["b"]=> string(1) "c" ["d"]=> string(1) "e" } ["f"]=> array(1) { ["g"]=> string(1) "h" } } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK array(2) { [0]=> object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } [1]=> object(Obj)#%d (3) { ["a"]=> int(4) [%r"?b"?:protected"?%r]=> int(5) [%r"?c"?:("Obj":)?private"?%r]=> int(6) } } OK array(2) { [0]=> &object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } [1]=> &object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } } OK msgpack-0.5.5/tests/071c.phpt0000644000077100007710000001024712110565607015544 0ustar xinchenxinchen--TEST-- Check for class methods --SKIPIF-- = 0) { echo "skip tests in PHP 5.1 or older"; } --FILE-- pack($variable); $unserialized = $msgpack->unpack($serialized); var_dump($unserialized); if (!is_bool($test)) { echo $unserialized === $variable ? 'OK' : 'ERROR', PHP_EOL; } else { echo $test || $unserialized == $variable ? 'OK' : 'ERROR', PHP_EOL; } } test('null', null); test('bool: true', true); test('bool: false', false); test('zero: 0', 0); test('small: 1', 1); test('small: -1', -1); test('medium: 1000', 1000); test('medium: -1000', -1000); test('large: 100000', 100000); test('large: -100000', -100000); test('double: 123.456', 123.456); test('empty: ""', ""); test('string: "foobar"', "foobar"); test('array: empty', array(), false); test('array(1, 2, 3)', array(1, 2, 3), false); test('array(array(1, 2, 3), arr...', array(array(1, 2, 3), array(4, 5, 6), array(7, 8, 9)), false); test('array("foo", "foo", "foo")', array("foo", "foo", "foo"), false); test('array("one" => 1, "two" => 2))', array("one" => 1, "two" => 2), false); test('array("kek" => "lol", "lol" => "kek")', array("kek" => "lol", "lol" => "kek"), false); test('array("" => "empty")', array("" => "empty"), false); $a = array('foo'); test('array($a, $a)', array($a, $a), false); test('array(&$a, &$a)', array(&$a, &$a), false); $a = array(null); $b = array(&$a); $a[0] = &$b; test('cyclic', $a, true); $a = array( 'a' => array( 'b' => 'c', 'd' => 'e' ), 'f' => array( 'g' => 'h' ) ); test('array', $a, false); class Obj { public $a; protected $b; private $c; function __construct($a, $b, $c) { $this->a = $a; $this->b = $b; $this->c = $c; } } test('object', new Obj(1, 2, 3), false); test('object', array(new Obj(1, 2, 3), new Obj(4, 5, 6)), false); $o = new Obj(1, 2, 3); test('object', array(&$o, &$o), false); --EXPECTF-- NULL OK bool(true) OK bool(false) OK int(0) OK int(1) OK int(-1) OK int(1000) OK int(-1000) OK int(100000) OK int(-100000) OK float(123.456) OK string(0) "" OK string(6) "foobar" OK array(0) { } OK array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } OK array(3) { [0]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } [1]=> array(3) { [0]=> int(4) [1]=> int(5) [2]=> int(6) } [2]=> array(3) { [0]=> int(7) [1]=> int(8) [2]=> int(9) } } OK array(3) { [0]=> string(3) "foo" [1]=> string(3) "foo" [2]=> string(3) "foo" } OK array(2) { ["one"]=> int(1) ["two"]=> int(2) } OK array(2) { ["kek"]=> string(3) "lol" ["lol"]=> string(3) "kek" } OK array(1) { [""]=> string(5) "empty" } OK array(2) { [0]=> array(1) { [0]=> string(3) "foo" } [1]=> array(1) { [0]=> string(3) "foo" } } OK array(2) { [0]=> &array(1) { [0]=> string(3) "foo" } [1]=> &array(1) { [0]=> string(3) "foo" } } OK array(1) { [0]=> &array(1) { [0]=> &array(1) { [0]=> &array(1) { [0]=> &array(1) { [0]=> *RECURSION* } } } } } OK array(2) { ["a"]=> array(2) { ["b"]=> string(1) "c" ["d"]=> string(1) "e" } ["f"]=> array(1) { ["g"]=> string(1) "h" } } OK object(Obj)#%d (3) { ["a"]=> int(1) ["b:protected"]=> int(2) ["c:private"]=> int(3) } OK array(2) { [0]=> object(Obj)#%d (3) { ["a"]=> int(1) ["b:protected"]=> int(2) ["c:private"]=> int(3) } [1]=> object(Obj)#%d (3) { ["a"]=> int(4) ["b:protected"]=> int(5) ["c:private"]=> int(6) } } OK array(2) { [0]=> &object(Obj)#%d (3) { ["a"]=> int(1) ["b:protected"]=> int(2) ["c:private"]=> int(3) } [1]=> &object(Obj)#%d (3) { ["a"]=> int(1) ["b:protected"]=> int(2) ["c:private"]=> int(3) } } OK msgpack-0.5.5/tests/072.phpt0000644000077100007710000001230412110565607015376 0ustar xinchenxinchen--TEST-- Check for class methods unpacker --SKIPIF-- = 0 && version_compare(PHP_VERSION, '5.3.2') <= 0)) { echo "skip tests in PHP 5.2.14/5.3.3 or newer"; } --FILE-- pack($variable); $unpacker = $msgpack->unpacker(); $length = strlen($serialized); if (rand(0, 1)) { for ($i = 0; $i < $length;) { $len = rand(1, 10); $str = substr($serialized, $i, $len); $unpacker->feed($str); if ($unpacker->execute()) { $unserialized = $unpacker->data(); var_dump($unserialized); $unpacker->reset(); } $i += $len; } } else { $str = ""; $offset = 0; for ($i = 0; $i < $length;) { $len = rand(1, 10); $str .= substr($serialized, $i, $len); if ($unpacker->execute($str, $offset)) { $unserialized = $unpacker->data(); var_dump($unserialized); $unpacker->reset(); $str = ""; $offset = 0; } $i += $len; } } if (!is_bool($test)) { echo $unserialized === $variable ? 'OK' : 'ERROR', PHP_EOL; } else { echo $test || $unserialized == $variable ? 'OK' : 'ERROR', PHP_EOL; } } test('null', null); test('bool: true', true); test('bool: false', false); test('zero: 0', 0); test('small: 1', 1); test('small: -1', -1); test('medium: 1000', 1000); test('medium: -1000', -1000); test('large: 100000', 100000); test('large: -100000', -100000); test('double: 123.456', 123.456); test('empty: ""', ""); test('string: "foobar"', "foobar"); test('array: empty', array(), false); test('array(1, 2, 3)', array(1, 2, 3), false); test('array(array(1, 2, 3), arr...', array(array(1, 2, 3), array(4, 5, 6), array(7, 8, 9)), false); test('array("foo", "foo", "foo")', array("foo", "foo", "foo"), false); test('array("one" => 1, "two" => 2))', array("one" => 1, "two" => 2), false); test('array("kek" => "lol", "lol" => "kek")', array("kek" => "lol", "lol" => "kek"), false); test('array("" => "empty")', array("" => "empty"), false); $a = array('foo'); test('array($a, $a)', array($a, $a), false); test('array(&$a, &$a)', array(&$a, &$a), false); $a = array(null); $b = array(&$a); $a[0] = &$b; test('cyclic', $a, true); $a = array( 'a' => array( 'b' => 'c', 'd' => 'e' ), 'f' => array( 'g' => 'h' ) ); test('array', $a, false); class Obj { public $a; protected $b; private $c; function __construct($a, $b, $c) { $this->a = $a; $this->b = $b; $this->c = $c; } } test('object', new Obj(1, 2, 3), false); test('object', array(new Obj(1, 2, 3), new Obj(4, 5, 6)), false); $o = new Obj(1, 2, 3); test('object', array(&$o, &$o), false); --EXPECTF-- NULL OK bool(true) OK bool(false) OK int(0) OK int(1) OK int(-1) OK int(1000) OK int(-1000) OK int(100000) OK int(-100000) OK float(123.456) OK string(0) "" OK string(6) "foobar" OK array(0) { } OK array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } OK array(3) { [0]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } [1]=> array(3) { [0]=> int(4) [1]=> int(5) [2]=> int(6) } [2]=> array(3) { [0]=> int(7) [1]=> int(8) [2]=> int(9) } } OK array(3) { [0]=> string(3) "foo" [1]=> string(3) "foo" [2]=> string(3) "foo" } OK array(2) { ["one"]=> int(1) ["two"]=> int(2) } OK array(2) { ["kek"]=> string(3) "lol" ["lol"]=> string(3) "kek" } OK array(1) { [""]=> string(5) "empty" } OK array(2) { [0]=> array(1) { [0]=> string(3) "foo" } [1]=> array(1) { [0]=> string(3) "foo" } } OK array(2) { [0]=> &array(1) { [0]=> string(3) "foo" } [1]=> &array(1) { [0]=> string(3) "foo" } } OK array(1) { [0]=> &array(1) { [0]=> &array(1) { [0]=> *RECURSION* } } } OK array(2) { ["a"]=> array(2) { ["b"]=> string(1) "c" ["d"]=> string(1) "e" } ["f"]=> array(1) { ["g"]=> string(1) "h" } } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK array(2) { [0]=> object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } [1]=> object(Obj)#%d (3) { ["a"]=> int(4) [%r"?b"?:protected"?%r]=> int(5) [%r"?c"?:("Obj":)?private"?%r]=> int(6) } } OK array(2) { [0]=> &object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } [1]=> &object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } } OK msgpack-0.5.5/tests/072b.phpt0000644000077100007710000001257312110565607015550 0ustar xinchenxinchen--TEST-- Check for class methods unpacker --SKIPIF-- = 0) || (version_compare(PHP_VERSION, '5.3.3') >= 0)) { echo "skip tests in PHP 5.2.13/5.3.2 or older"; } if (version_compare(PHP_VERSION, '5.2.0') < 0) { echo "skip tests in PHP 5.2 or newer"; } --FILE-- pack($variable); $unpacker = $msgpack->unpacker(); $length = strlen($serialized); if (rand(0, 1)) { for ($i = 0; $i < $length;) { $len = rand(1, 10); $str = substr($serialized, $i, $len); $unpacker->feed($str); if ($unpacker->execute()) { $unserialized = $unpacker->data(); var_dump($unserialized); $unpacker->reset(); } $i += $len; } } else { $str = ""; $offset = 0; for ($i = 0; $i < $length;) { $len = rand(1, 10); $str .= substr($serialized, $i, $len); if ($unpacker->execute($str, $offset)) { $unserialized = $unpacker->data(); var_dump($unserialized); $unpacker->reset(); $str = ""; $offset = 0; } $i += $len; } } if (!is_bool($test)) { echo $unserialized === $variable ? 'OK' : 'ERROR', PHP_EOL; } else { echo $test || $unserialized == $variable ? 'OK' : 'ERROR', PHP_EOL; } } test('null', null); test('bool: true', true); test('bool: false', false); test('zero: 0', 0); test('small: 1', 1); test('small: -1', -1); test('medium: 1000', 1000); test('medium: -1000', -1000); test('large: 100000', 100000); test('large: -100000', -100000); test('double: 123.456', 123.456); test('empty: ""', ""); test('string: "foobar"', "foobar"); test('array: empty', array(), false); test('array(1, 2, 3)', array(1, 2, 3), false); test('array(array(1, 2, 3), arr...', array(array(1, 2, 3), array(4, 5, 6), array(7, 8, 9)), false); test('array("foo", "foo", "foo")', array("foo", "foo", "foo"), false); test('array("one" => 1, "two" => 2))', array("one" => 1, "two" => 2), false); test('array("kek" => "lol", "lol" => "kek")', array("kek" => "lol", "lol" => "kek"), false); test('array("" => "empty")', array("" => "empty"), false); $a = array('foo'); test('array($a, $a)', array($a, $a), false); test('array(&$a, &$a)', array(&$a, &$a), false); $a = array(null); $b = array(&$a); $a[0] = &$b; test('cyclic', $a, true); $a = array( 'a' => array( 'b' => 'c', 'd' => 'e' ), 'f' => array( 'g' => 'h' ) ); test('array', $a, false); class Obj { public $a; protected $b; private $c; function __construct($a, $b, $c) { $this->a = $a; $this->b = $b; $this->c = $c; } } test('object', new Obj(1, 2, 3), false); test('object', array(new Obj(1, 2, 3), new Obj(4, 5, 6)), false); $o = new Obj(1, 2, 3); test('object', array(&$o, &$o), false); --EXPECTF-- NULL OK bool(true) OK bool(false) OK int(0) OK int(1) OK int(-1) OK int(1000) OK int(-1000) OK int(100000) OK int(-100000) OK float(123.456) OK string(0) "" OK string(6) "foobar" OK array(0) { } OK array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } OK array(3) { [0]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } [1]=> array(3) { [0]=> int(4) [1]=> int(5) [2]=> int(6) } [2]=> array(3) { [0]=> int(7) [1]=> int(8) [2]=> int(9) } } OK array(3) { [0]=> string(3) "foo" [1]=> string(3) "foo" [2]=> string(3) "foo" } OK array(2) { ["one"]=> int(1) ["two"]=> int(2) } OK array(2) { ["kek"]=> string(3) "lol" ["lol"]=> string(3) "kek" } OK array(1) { [""]=> string(5) "empty" } OK array(2) { [0]=> array(1) { [0]=> string(3) "foo" } [1]=> array(1) { [0]=> string(3) "foo" } } OK array(2) { [0]=> &array(1) { [0]=> string(3) "foo" } [1]=> &array(1) { [0]=> string(3) "foo" } } OK array(1) { [0]=> &array(1) { [0]=> &array(1) { [0]=> &array(1) { [0]=> &array(1) { [0]=> *RECURSION* } } } } } OK array(2) { ["a"]=> array(2) { ["b"]=> string(1) "c" ["d"]=> string(1) "e" } ["f"]=> array(1) { ["g"]=> string(1) "h" } } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK array(2) { [0]=> object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } [1]=> object(Obj)#%d (3) { ["a"]=> int(4) [%r"?b"?:protected"?%r]=> int(5) [%r"?c"?:("Obj":)?private"?%r]=> int(6) } } OK array(2) { [0]=> &object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } [1]=> &object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } } OK msgpack-0.5.5/tests/072c.phpt0000644000077100007710000001205612110565607015545 0ustar xinchenxinchen--TEST-- Check for class methods unpacker --SKIPIF-- = 0) { echo "skip tests in PHP 5.1 or older"; } --FILE-- pack($variable); $unpacker = $msgpack->unpacker(); $length = strlen($serialized); if (rand(0, 1)) { for ($i = 0; $i < $length;) { $len = rand(1, 10); $str = substr($serialized, $i, $len); $unpacker->feed($str); if ($unpacker->execute()) { $unserialized = $unpacker->data(); var_dump($unserialized); $unpacker->reset(); } $i += $len; } } else { $str = ""; $offset = 0; for ($i = 0; $i < $length;) { $len = rand(1, 10); $str .= substr($serialized, $i, $len); if ($unpacker->execute($str, $offset)) { $unserialized = $unpacker->data(); var_dump($unserialized); $unpacker->reset(); $str = ""; $offset = 0; } $i += $len; } } if (!is_bool($test)) { echo $unserialized === $variable ? 'OK' : 'ERROR', PHP_EOL; } else { echo $test || $unserialized == $variable ? 'OK' : 'ERROR', PHP_EOL; } } test('null', null); test('bool: true', true); test('bool: false', false); test('zero: 0', 0); test('small: 1', 1); test('small: -1', -1); test('medium: 1000', 1000); test('medium: -1000', -1000); test('large: 100000', 100000); test('large: -100000', -100000); test('double: 123.456', 123.456); test('empty: ""', ""); test('string: "foobar"', "foobar"); test('array: empty', array(), false); test('array(1, 2, 3)', array(1, 2, 3), false); test('array(array(1, 2, 3), arr...', array(array(1, 2, 3), array(4, 5, 6), array(7, 8, 9)), false); test('array("foo", "foo", "foo")', array("foo", "foo", "foo"), false); test('array("one" => 1, "two" => 2))', array("one" => 1, "two" => 2), false); test('array("kek" => "lol", "lol" => "kek")', array("kek" => "lol", "lol" => "kek"), false); test('array("" => "empty")', array("" => "empty"), false); $a = array('foo'); test('array($a, $a)', array($a, $a), false); test('array(&$a, &$a)', array(&$a, &$a), false); $a = array(null); $b = array(&$a); $a[0] = &$b; test('cyclic', $a, true); $a = array( 'a' => array( 'b' => 'c', 'd' => 'e' ), 'f' => array( 'g' => 'h' ) ); test('array', $a, false); class Obj { public $a; protected $b; private $c; function __construct($a, $b, $c) { $this->a = $a; $this->b = $b; $this->c = $c; } } test('object', new Obj(1, 2, 3), false); test('object', array(new Obj(1, 2, 3), new Obj(4, 5, 6)), false); $o = new Obj(1, 2, 3); test('object', array(&$o, &$o), false); --EXPECTF-- NULL OK bool(true) OK bool(false) OK int(0) OK int(1) OK int(-1) OK int(1000) OK int(-1000) OK int(100000) OK int(-100000) OK float(123.456) OK string(0) "" OK string(6) "foobar" OK array(0) { } OK array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } OK array(3) { [0]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } [1]=> array(3) { [0]=> int(4) [1]=> int(5) [2]=> int(6) } [2]=> array(3) { [0]=> int(7) [1]=> int(8) [2]=> int(9) } } OK array(3) { [0]=> string(3) "foo" [1]=> string(3) "foo" [2]=> string(3) "foo" } OK array(2) { ["one"]=> int(1) ["two"]=> int(2) } OK array(2) { ["kek"]=> string(3) "lol" ["lol"]=> string(3) "kek" } OK array(1) { [""]=> string(5) "empty" } OK array(2) { [0]=> array(1) { [0]=> string(3) "foo" } [1]=> array(1) { [0]=> string(3) "foo" } } OK array(2) { [0]=> &array(1) { [0]=> string(3) "foo" } [1]=> &array(1) { [0]=> string(3) "foo" } } OK array(1) { [0]=> &array(1) { [0]=> &array(1) { [0]=> &array(1) { [0]=> &array(1) { [0]=> *RECURSION* } } } } } OK array(2) { ["a"]=> array(2) { ["b"]=> string(1) "c" ["d"]=> string(1) "e" } ["f"]=> array(1) { ["g"]=> string(1) "h" } } OK object(Obj)#%d (3) { ["a"]=> int(1) ["b:protected"]=> int(2) ["c:private"]=> int(3) } OK array(2) { [0]=> object(Obj)#%d (3) { ["a"]=> int(1) ["b:protected"]=> int(2) ["c:private"]=> int(3) } [1]=> object(Obj)#%d (3) { ["a"]=> int(4) ["b:protected"]=> int(5) ["c:private"]=> int(6) } } OK array(2) { [0]=> &object(Obj)#%d (3) { ["a"]=> int(1) ["b:protected"]=> int(2) ["c:private"]=> int(3) } [1]=> &object(Obj)#%d (3) { ["a"]=> int(1) ["b:protected"]=> int(2) ["c:private"]=> int(3) } } OK msgpack-0.5.5/tests/073.phpt0000644000077100007710000001230212110565607015375 0ustar xinchenxinchen--TEST-- Check for class unpacker --SKIPIF-- = 0 && version_compare(PHP_VERSION, '5.3.2') <= 0)) { echo "skip tests in PHP 5.2.14/5.3.3 or newer"; } --FILE-- pack($variable); $unpacker = new MessagePackUnpacker(); $length = strlen($serialized); if (rand(0, 1)) { for ($i = 0; $i < $length;) { $len = rand(1, 10); $str = substr($serialized, $i, $len); $unpacker->feed($str); if ($unpacker->execute()) { $unserialized = $unpacker->data(); var_dump($unserialized); $unpacker->reset(); } $i += $len; } } else { $str = ""; $offset = 0; for ($i = 0; $i < $length;) { $len = rand(1, 10); $str .= substr($serialized, $i, $len); if ($unpacker->execute($str, $offset)) { $unserialized = $unpacker->data(); var_dump($unserialized); $unpacker->reset(); $str = ""; $offset = 0; } $i += $len; } } if (!is_bool($test)) { echo $unserialized === $variable ? 'OK' : 'ERROR', PHP_EOL; } else { echo $test || $unserialized == $variable ? 'OK' : 'ERROR', PHP_EOL; } } test('null', null); test('bool: true', true); test('bool: false', false); test('zero: 0', 0); test('small: 1', 1); test('small: -1', -1); test('medium: 1000', 1000); test('medium: -1000', -1000); test('large: 100000', 100000); test('large: -100000', -100000); test('double: 123.456', 123.456); test('empty: ""', ""); test('string: "foobar"', "foobar"); test('array: empty', array(), false); test('array(1, 2, 3)', array(1, 2, 3), false); test('array(array(1, 2, 3), arr...', array(array(1, 2, 3), array(4, 5, 6), array(7, 8, 9)), false); test('array("foo", "foo", "foo")', array("foo", "foo", "foo"), false); test('array("one" => 1, "two" => 2))', array("one" => 1, "two" => 2), false); test('array("kek" => "lol", "lol" => "kek")', array("kek" => "lol", "lol" => "kek"), false); test('array("" => "empty")', array("" => "empty"), false); $a = array('foo'); test('array($a, $a)', array($a, $a), false); test('array(&$a, &$a)', array(&$a, &$a), false); $a = array(null); $b = array(&$a); $a[0] = &$b; test('cyclic', $a, true); $a = array( 'a' => array( 'b' => 'c', 'd' => 'e' ), 'f' => array( 'g' => 'h' ) ); test('array', $a, false); class Obj { public $a; protected $b; private $c; function __construct($a, $b, $c) { $this->a = $a; $this->b = $b; $this->c = $c; } } test('object', new Obj(1, 2, 3), false); test('object', array(new Obj(1, 2, 3), new Obj(4, 5, 6)), false); $o = new Obj(1, 2, 3); test('object', array(&$o, &$o), false); --EXPECTF-- NULL OK bool(true) OK bool(false) OK int(0) OK int(1) OK int(-1) OK int(1000) OK int(-1000) OK int(100000) OK int(-100000) OK float(123.456) OK string(0) "" OK string(6) "foobar" OK array(0) { } OK array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } OK array(3) { [0]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } [1]=> array(3) { [0]=> int(4) [1]=> int(5) [2]=> int(6) } [2]=> array(3) { [0]=> int(7) [1]=> int(8) [2]=> int(9) } } OK array(3) { [0]=> string(3) "foo" [1]=> string(3) "foo" [2]=> string(3) "foo" } OK array(2) { ["one"]=> int(1) ["two"]=> int(2) } OK array(2) { ["kek"]=> string(3) "lol" ["lol"]=> string(3) "kek" } OK array(1) { [""]=> string(5) "empty" } OK array(2) { [0]=> array(1) { [0]=> string(3) "foo" } [1]=> array(1) { [0]=> string(3) "foo" } } OK array(2) { [0]=> &array(1) { [0]=> string(3) "foo" } [1]=> &array(1) { [0]=> string(3) "foo" } } OK array(1) { [0]=> &array(1) { [0]=> &array(1) { [0]=> *RECURSION* } } } OK array(2) { ["a"]=> array(2) { ["b"]=> string(1) "c" ["d"]=> string(1) "e" } ["f"]=> array(1) { ["g"]=> string(1) "h" } } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK array(2) { [0]=> object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } [1]=> object(Obj)#%d (3) { ["a"]=> int(4) [%r"?b"?:protected"?%r]=> int(5) [%r"?c"?:("Obj":)?private"?%r]=> int(6) } } OK array(2) { [0]=> &object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } [1]=> &object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } } OK msgpack-0.5.5/tests/073b.phpt0000644000077100007710000001257112110565607015547 0ustar xinchenxinchen--TEST-- Check for class unpacker --SKIPIF-- = 0) || (version_compare(PHP_VERSION, '5.3.3') >= 0)) { echo "skip tests in PHP 5.2.13/5.3.2 or older"; } if (version_compare(PHP_VERSION, '5.2.0') < 0) { echo "skip tests in PHP 5.2 or newer"; } --FILE-- pack($variable); $unpacker = new MessagePackUnpacker(); $length = strlen($serialized); if (rand(0, 1)) { for ($i = 0; $i < $length;) { $len = rand(1, 10); $str = substr($serialized, $i, $len); $unpacker->feed($str); if ($unpacker->execute()) { $unserialized = $unpacker->data(); var_dump($unserialized); $unpacker->reset(); } $i += $len; } } else { $str = ""; $offset = 0; for ($i = 0; $i < $length;) { $len = rand(1, 10); $str .= substr($serialized, $i, $len); if ($unpacker->execute($str, $offset)) { $unserialized = $unpacker->data(); var_dump($unserialized); $unpacker->reset(); $str = ""; $offset = 0; } $i += $len; } } if (!is_bool($test)) { echo $unserialized === $variable ? 'OK' : 'ERROR', PHP_EOL; } else { echo $test || $unserialized == $variable ? 'OK' : 'ERROR', PHP_EOL; } } test('null', null); test('bool: true', true); test('bool: false', false); test('zero: 0', 0); test('small: 1', 1); test('small: -1', -1); test('medium: 1000', 1000); test('medium: -1000', -1000); test('large: 100000', 100000); test('large: -100000', -100000); test('double: 123.456', 123.456); test('empty: ""', ""); test('string: "foobar"', "foobar"); test('array: empty', array(), false); test('array(1, 2, 3)', array(1, 2, 3), false); test('array(array(1, 2, 3), arr...', array(array(1, 2, 3), array(4, 5, 6), array(7, 8, 9)), false); test('array("foo", "foo", "foo")', array("foo", "foo", "foo"), false); test('array("one" => 1, "two" => 2))', array("one" => 1, "two" => 2), false); test('array("kek" => "lol", "lol" => "kek")', array("kek" => "lol", "lol" => "kek"), false); test('array("" => "empty")', array("" => "empty"), false); $a = array('foo'); test('array($a, $a)', array($a, $a), false); test('array(&$a, &$a)', array(&$a, &$a), false); $a = array(null); $b = array(&$a); $a[0] = &$b; test('cyclic', $a, true); $a = array( 'a' => array( 'b' => 'c', 'd' => 'e' ), 'f' => array( 'g' => 'h' ) ); test('array', $a, false); class Obj { public $a; protected $b; private $c; function __construct($a, $b, $c) { $this->a = $a; $this->b = $b; $this->c = $c; } } test('object', new Obj(1, 2, 3), false); test('object', array(new Obj(1, 2, 3), new Obj(4, 5, 6)), false); $o = new Obj(1, 2, 3); test('object', array(&$o, &$o), false); --EXPECTF-- NULL OK bool(true) OK bool(false) OK int(0) OK int(1) OK int(-1) OK int(1000) OK int(-1000) OK int(100000) OK int(-100000) OK float(123.456) OK string(0) "" OK string(6) "foobar" OK array(0) { } OK array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } OK array(3) { [0]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } [1]=> array(3) { [0]=> int(4) [1]=> int(5) [2]=> int(6) } [2]=> array(3) { [0]=> int(7) [1]=> int(8) [2]=> int(9) } } OK array(3) { [0]=> string(3) "foo" [1]=> string(3) "foo" [2]=> string(3) "foo" } OK array(2) { ["one"]=> int(1) ["two"]=> int(2) } OK array(2) { ["kek"]=> string(3) "lol" ["lol"]=> string(3) "kek" } OK array(1) { [""]=> string(5) "empty" } OK array(2) { [0]=> array(1) { [0]=> string(3) "foo" } [1]=> array(1) { [0]=> string(3) "foo" } } OK array(2) { [0]=> &array(1) { [0]=> string(3) "foo" } [1]=> &array(1) { [0]=> string(3) "foo" } } OK array(1) { [0]=> &array(1) { [0]=> &array(1) { [0]=> &array(1) { [0]=> &array(1) { [0]=> *RECURSION* } } } } } OK array(2) { ["a"]=> array(2) { ["b"]=> string(1) "c" ["d"]=> string(1) "e" } ["f"]=> array(1) { ["g"]=> string(1) "h" } } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK array(2) { [0]=> object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } [1]=> object(Obj)#%d (3) { ["a"]=> int(4) [%r"?b"?:protected"?%r]=> int(5) [%r"?c"?:("Obj":)?private"?%r]=> int(6) } } OK array(2) { [0]=> &object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } [1]=> &object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } } OK msgpack-0.5.5/tests/073c.phpt0000644000077100007710000001205412110565607015544 0ustar xinchenxinchen--TEST-- Check for class unpacker --SKIPIF-- = 0) { echo "skip tests in PHP 5.1 or older"; } --FILE-- pack($variable); $unpacker = new MessagePackUnpacker(); $length = strlen($serialized); if (rand(0, 1)) { for ($i = 0; $i < $length;) { $len = rand(1, 10); $str = substr($serialized, $i, $len); $unpacker->feed($str); if ($unpacker->execute()) { $unserialized = $unpacker->data(); var_dump($unserialized); $unpacker->reset(); } $i += $len; } } else { $str = ""; $offset = 0; for ($i = 0; $i < $length;) { $len = rand(1, 10); $str .= substr($serialized, $i, $len); if ($unpacker->execute($str, $offset)) { $unserialized = $unpacker->data(); var_dump($unserialized); $unpacker->reset(); $str = ""; $offset = 0; } $i += $len; } } if (!is_bool($test)) { echo $unserialized === $variable ? 'OK' : 'ERROR', PHP_EOL; } else { echo $test || $unserialized == $variable ? 'OK' : 'ERROR', PHP_EOL; } } test('null', null); test('bool: true', true); test('bool: false', false); test('zero: 0', 0); test('small: 1', 1); test('small: -1', -1); test('medium: 1000', 1000); test('medium: -1000', -1000); test('large: 100000', 100000); test('large: -100000', -100000); test('double: 123.456', 123.456); test('empty: ""', ""); test('string: "foobar"', "foobar"); test('array: empty', array(), false); test('array(1, 2, 3)', array(1, 2, 3), false); test('array(array(1, 2, 3), arr...', array(array(1, 2, 3), array(4, 5, 6), array(7, 8, 9)), false); test('array("foo", "foo", "foo")', array("foo", "foo", "foo"), false); test('array("one" => 1, "two" => 2))', array("one" => 1, "two" => 2), false); test('array("kek" => "lol", "lol" => "kek")', array("kek" => "lol", "lol" => "kek"), false); test('array("" => "empty")', array("" => "empty"), false); $a = array('foo'); test('array($a, $a)', array($a, $a), false); test('array(&$a, &$a)', array(&$a, &$a), false); $a = array(null); $b = array(&$a); $a[0] = &$b; test('cyclic', $a, true); $a = array( 'a' => array( 'b' => 'c', 'd' => 'e' ), 'f' => array( 'g' => 'h' ) ); test('array', $a, false); class Obj { public $a; protected $b; private $c; function __construct($a, $b, $c) { $this->a = $a; $this->b = $b; $this->c = $c; } } test('object', new Obj(1, 2, 3), false); test('object', array(new Obj(1, 2, 3), new Obj(4, 5, 6)), false); $o = new Obj(1, 2, 3); test('object', array(&$o, &$o), false); --EXPECTF-- NULL OK bool(true) OK bool(false) OK int(0) OK int(1) OK int(-1) OK int(1000) OK int(-1000) OK int(100000) OK int(-100000) OK float(123.456) OK string(0) "" OK string(6) "foobar" OK array(0) { } OK array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } OK array(3) { [0]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } [1]=> array(3) { [0]=> int(4) [1]=> int(5) [2]=> int(6) } [2]=> array(3) { [0]=> int(7) [1]=> int(8) [2]=> int(9) } } OK array(3) { [0]=> string(3) "foo" [1]=> string(3) "foo" [2]=> string(3) "foo" } OK array(2) { ["one"]=> int(1) ["two"]=> int(2) } OK array(2) { ["kek"]=> string(3) "lol" ["lol"]=> string(3) "kek" } OK array(1) { [""]=> string(5) "empty" } OK array(2) { [0]=> array(1) { [0]=> string(3) "foo" } [1]=> array(1) { [0]=> string(3) "foo" } } OK array(2) { [0]=> &array(1) { [0]=> string(3) "foo" } [1]=> &array(1) { [0]=> string(3) "foo" } } OK array(1) { [0]=> &array(1) { [0]=> &array(1) { [0]=> &array(1) { [0]=> &array(1) { [0]=> *RECURSION* } } } } } OK array(2) { ["a"]=> array(2) { ["b"]=> string(1) "c" ["d"]=> string(1) "e" } ["f"]=> array(1) { ["g"]=> string(1) "h" } } OK object(Obj)#%d (3) { ["a"]=> int(1) ["b:protected"]=> int(2) ["c:private"]=> int(3) } OK array(2) { [0]=> object(Obj)#%d (3) { ["a"]=> int(1) ["b:protected"]=> int(2) ["c:private"]=> int(3) } [1]=> object(Obj)#%d (3) { ["a"]=> int(4) ["b:protected"]=> int(5) ["c:private"]=> int(6) } } OK array(2) { [0]=> &object(Obj)#%d (3) { ["a"]=> int(1) ["b:protected"]=> int(2) ["c:private"]=> int(3) } [1]=> &object(Obj)#%d (3) { ["a"]=> int(1) ["b:protected"]=> int(2) ["c:private"]=> int(3) } } OK msgpack-0.5.5/tests/080.phpt0000644000077100007710000000760412110565607015404 0ustar xinchenxinchen--TEST-- disabled php only (ini_set) --SKIPIF-- --FILE-- 1, "two" => 2))', array("one" => 1, "two" => 2), false); test('array("kek" => "lol", "lol" => "kek")', array("kek" => "lol", "lol" => "kek"), false); test('array("" => "empty")', array("" => "empty"), false); $a = array('foo'); test('array($a, $a)', array($a, $a), false); test('array(&$a, &$a)', array(&$a, &$a), false); $a = array(null); $b = array(&$a); $a[0] = &$b; test('cyclic', $a, true); $a = array( 'a' => array( 'b' => 'c', 'd' => 'e' ), 'f' => array( 'g' => 'h' ) ); test('array', $a, false); class Obj { public $a; protected $b; private $c; function __construct($a, $b, $c) { $this->a = $a; $this->b = $b; $this->c = $c; } } test('object', new Obj(1, 2, 3), true); test('object', array(new Obj(1, 2, 3), new Obj(4, 5, 6)), true); $o = new Obj(1, 2, 3); test('object', array(&$o, &$o), true); --EXPECTF-- NULL OK bool(true) OK bool(false) OK int(0) OK int(1) OK int(-1) OK int(1000) OK int(-1000) OK int(100000) OK int(-100000) OK float(123.456) OK string(0) "" OK string(6) "foobar" OK array(0) { } OK array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } OK array(3) { [0]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } [1]=> array(3) { [0]=> int(4) [1]=> int(5) [2]=> int(6) } [2]=> array(3) { [0]=> int(7) [1]=> int(8) [2]=> int(9) } } OK array(3) { [0]=> string(3) "foo" [1]=> string(3) "foo" [2]=> string(3) "foo" } OK array(2) { ["one"]=> int(1) ["two"]=> int(2) } OK array(2) { ["kek"]=> string(3) "lol" ["lol"]=> string(3) "kek" } OK array(1) { [""]=> string(5) "empty" } OK array(2) { [0]=> array(1) { [0]=> string(3) "foo" } [1]=> array(1) { [0]=> string(3) "foo" } } OK array(2) { [0]=> array(1) { [0]=> string(3) "foo" } [1]=> array(1) { [0]=> string(3) "foo" } } OK array(1) { [0]=> array(1) { [0]=> array(1) { [0]=> array(1) { [0]=> array(1) { [0]=> NULL } } } } } OK array(2) { ["a"]=> array(2) { ["b"]=> string(1) "c" ["d"]=> string(1) "e" } ["f"]=> array(1) { ["g"]=> string(1) "h" } } OK array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } OK array(2) { [0]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } [1]=> array(3) { [0]=> int(4) [1]=> int(5) [2]=> int(6) } } OK array(2) { [0]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } [1]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } } OK msgpack-0.5.5/tests/081.phpt0000644000077100007710000000767512110565607015415 0ustar xinchenxinchen--TEST-- disabled php only for class methods (ini_set) --SKIPIF-- --FILE-- pack($variable); $unserialized = $msgpack->unpack($serialized); var_dump($unserialized); if (!is_bool($test)) { echo $unserialized === $variable ? 'OK' : 'ERROR', PHP_EOL; } else { echo $test || $unserialized == $variable ? 'OK' : 'ERROR', PHP_EOL; } } test('null', null); test('bool: true', true); test('bool: false', false); test('zero: 0', 0); test('small: 1', 1); test('small: -1', -1); test('medium: 1000', 1000); test('medium: -1000', -1000); test('large: 100000', 100000); test('large: -100000', -100000); test('double: 123.456', 123.456); test('empty: ""', ""); test('string: "foobar"', "foobar"); test('array: empty', array(), false); test('array(1, 2, 3)', array(1, 2, 3), false); test('array(array(1, 2, 3), arr...', array(array(1, 2, 3), array(4, 5, 6), array(7, 8, 9)), false); test('array("foo", "foo", "foo")', array("foo", "foo", "foo"), false); test('array("one" => 1, "two" => 2))', array("one" => 1, "two" => 2), false); test('array("kek" => "lol", "lol" => "kek")', array("kek" => "lol", "lol" => "kek"), false); test('array("" => "empty")', array("" => "empty"), false); $a = array('foo'); test('array($a, $a)', array($a, $a), false); test('array(&$a, &$a)', array(&$a, &$a), false); $a = array(null); $b = array(&$a); $a[0] = &$b; test('cyclic', $a, true); $a = array( 'a' => array( 'b' => 'c', 'd' => 'e' ), 'f' => array( 'g' => 'h' ) ); test('array', $a, false); class Obj { public $a; protected $b; private $c; function __construct($a, $b, $c) { $this->a = $a; $this->b = $b; $this->c = $c; } } test('object', new Obj(1, 2, 3), true); test('object', array(new Obj(1, 2, 3), new Obj(4, 5, 6)), true); $o = new Obj(1, 2, 3); test('object', array(&$o, &$o), true); --EXPECTF-- NULL OK bool(true) OK bool(false) OK int(0) OK int(1) OK int(-1) OK int(1000) OK int(-1000) OK int(100000) OK int(-100000) OK float(123.456) OK string(0) "" OK string(6) "foobar" OK array(0) { } OK array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } OK array(3) { [0]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } [1]=> array(3) { [0]=> int(4) [1]=> int(5) [2]=> int(6) } [2]=> array(3) { [0]=> int(7) [1]=> int(8) [2]=> int(9) } } OK array(3) { [0]=> string(3) "foo" [1]=> string(3) "foo" [2]=> string(3) "foo" } OK array(2) { ["one"]=> int(1) ["two"]=> int(2) } OK array(2) { ["kek"]=> string(3) "lol" ["lol"]=> string(3) "kek" } OK array(1) { [""]=> string(5) "empty" } OK array(2) { [0]=> array(1) { [0]=> string(3) "foo" } [1]=> array(1) { [0]=> string(3) "foo" } } OK array(2) { [0]=> array(1) { [0]=> string(3) "foo" } [1]=> array(1) { [0]=> string(3) "foo" } } OK array(1) { [0]=> array(1) { [0]=> array(1) { [0]=> array(1) { [0]=> array(1) { [0]=> NULL } } } } } OK array(2) { ["a"]=> array(2) { ["b"]=> string(1) "c" ["d"]=> string(1) "e" } ["f"]=> array(1) { ["g"]=> string(1) "h" } } OK array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } OK array(2) { [0]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } [1]=> array(3) { [0]=> int(4) [1]=> int(5) [2]=> int(6) } } OK array(2) { [0]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } [1]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } } OK msgpack-0.5.5/tests/082.phpt0000644000077100007710000001152412110565607015402 0ustar xinchenxinchen--TEST-- disabled php only for class methods unpacker (ini_set) --SKIPIF-- --FILE-- pack($variable); $unpacker = $msgpack->unpacker(); $length = strlen($serialized); if (rand(0, 1)) { for ($i = 0; $i < $length;) { $len = rand(1, 10); $str = substr($serialized, $i, $len); $unpacker->feed($str); if ($unpacker->execute()) { $unserialized = $unpacker->data(); var_dump($unserialized); $unpacker->reset(); } $i += $len; } } else { $str = ""; $offset = 0; for ($i = 0; $i < $length;) { $len = rand(1, 10); $str .= substr($serialized, $i, $len); if ($unpacker->execute($str, $offset)) { $unserialized = $unpacker->data(); var_dump($unserialized); $unpacker->reset(); $str = ""; $offset = 0; } $i += $len; } } if (!is_bool($test)) { echo $unserialized === $variable ? 'OK' : 'ERROR', PHP_EOL; } else { echo $test || $unserialized == $variable ? 'OK' : 'ERROR', PHP_EOL; } } test('null', null); test('bool: true', true); test('bool: false', false); test('zero: 0', 0); test('small: 1', 1); test('small: -1', -1); test('medium: 1000', 1000); test('medium: -1000', -1000); test('large: 100000', 100000); test('large: -100000', -100000); test('double: 123.456', 123.456); test('empty: ""', ""); test('string: "foobar"', "foobar"); test('array: empty', array(), false); test('array(1, 2, 3)', array(1, 2, 3), false); test('array(array(1, 2, 3), arr...', array(array(1, 2, 3), array(4, 5, 6), array(7, 8, 9)), false); test('array("foo", "foo", "foo")', array("foo", "foo", "foo"), false); test('array("one" => 1, "two" => 2))', array("one" => 1, "two" => 2), false); test('array("kek" => "lol", "lol" => "kek")', array("kek" => "lol", "lol" => "kek"), false); test('array("" => "empty")', array("" => "empty"), false); $a = array('foo'); test('array($a, $a)', array($a, $a), false); test('array(&$a, &$a)', array(&$a, &$a), false); $a = array(null); $b = array(&$a); $a[0] = &$b; test('cyclic', $a, true); $a = array( 'a' => array( 'b' => 'c', 'd' => 'e' ), 'f' => array( 'g' => 'h' ) ); test('array', $a, false); class Obj { public $a; protected $b; private $c; function __construct($a, $b, $c) { $this->a = $a; $this->b = $b; $this->c = $c; } } test('object', new Obj(1, 2, 3), true); test('object', array(new Obj(1, 2, 3), new Obj(4, 5, 6)), true); $o = new Obj(1, 2, 3); test('object', array(&$o, &$o), true); --EXPECTF-- NULL OK bool(true) OK bool(false) OK int(0) OK int(1) OK int(-1) OK int(1000) OK int(-1000) OK int(100000) OK int(-100000) OK float(123.456) OK string(0) "" OK string(6) "foobar" OK array(0) { } OK array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } OK array(3) { [0]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } [1]=> array(3) { [0]=> int(4) [1]=> int(5) [2]=> int(6) } [2]=> array(3) { [0]=> int(7) [1]=> int(8) [2]=> int(9) } } OK array(3) { [0]=> string(3) "foo" [1]=> string(3) "foo" [2]=> string(3) "foo" } OK array(2) { ["one"]=> int(1) ["two"]=> int(2) } OK array(2) { ["kek"]=> string(3) "lol" ["lol"]=> string(3) "kek" } OK array(1) { [""]=> string(5) "empty" } OK array(2) { [0]=> array(1) { [0]=> string(3) "foo" } [1]=> array(1) { [0]=> string(3) "foo" } } OK array(2) { [0]=> array(1) { [0]=> string(3) "foo" } [1]=> array(1) { [0]=> string(3) "foo" } } OK array(1) { [0]=> array(1) { [0]=> array(1) { [0]=> array(1) { [0]=> array(1) { [0]=> NULL } } } } } OK array(2) { ["a"]=> array(2) { ["b"]=> string(1) "c" ["d"]=> string(1) "e" } ["f"]=> array(1) { ["g"]=> string(1) "h" } } OK array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } OK array(2) { [0]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } [1]=> array(3) { [0]=> int(4) [1]=> int(5) [2]=> int(6) } } OK array(2) { [0]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } [1]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } } OK msgpack-0.5.5/tests/083.phpt0000644000077100007710000001152212110565607015401 0ustar xinchenxinchen--TEST-- disabled php only for class unpacker (ini_set) --SKIPIF-- --FILE-- pack($variable); $unpacker = new MessagePackUnpacker(); $length = strlen($serialized); if (rand(0, 1)) { for ($i = 0; $i < $length;) { $len = rand(1, 10); $str = substr($serialized, $i, $len); $unpacker->feed($str); if ($unpacker->execute()) { $unserialized = $unpacker->data(); var_dump($unserialized); $unpacker->reset(); } $i += $len; } } else { $str = ""; $offset = 0; for ($i = 0; $i < $length;) { $len = rand(1, 10); $str .= substr($serialized, $i, $len); if ($unpacker->execute($str, $offset)) { $unserialized = $unpacker->data(); var_dump($unserialized); $unpacker->reset(); $str = ""; $offset = 0; } $i += $len; } } if (!is_bool($test)) { echo $unserialized === $variable ? 'OK' : 'ERROR', PHP_EOL; } else { echo $test || $unserialized == $variable ? 'OK' : 'ERROR', PHP_EOL; } } test('null', null); test('bool: true', true); test('bool: false', false); test('zero: 0', 0); test('small: 1', 1); test('small: -1', -1); test('medium: 1000', 1000); test('medium: -1000', -1000); test('large: 100000', 100000); test('large: -100000', -100000); test('double: 123.456', 123.456); test('empty: ""', ""); test('string: "foobar"', "foobar"); test('array: empty', array(), false); test('array(1, 2, 3)', array(1, 2, 3), false); test('array(array(1, 2, 3), arr...', array(array(1, 2, 3), array(4, 5, 6), array(7, 8, 9)), false); test('array("foo", "foo", "foo")', array("foo", "foo", "foo"), false); test('array("one" => 1, "two" => 2))', array("one" => 1, "two" => 2), false); test('array("kek" => "lol", "lol" => "kek")', array("kek" => "lol", "lol" => "kek"), false); test('array("" => "empty")', array("" => "empty"), false); $a = array('foo'); test('array($a, $a)', array($a, $a), false); test('array(&$a, &$a)', array(&$a, &$a), false); $a = array(null); $b = array(&$a); $a[0] = &$b; test('cyclic', $a, true); $a = array( 'a' => array( 'b' => 'c', 'd' => 'e' ), 'f' => array( 'g' => 'h' ) ); test('array', $a, false); class Obj { public $a; protected $b; private $c; function __construct($a, $b, $c) { $this->a = $a; $this->b = $b; $this->c = $c; } } test('object', new Obj(1, 2, 3), true); test('object', array(new Obj(1, 2, 3), new Obj(4, 5, 6)), true); $o = new Obj(1, 2, 3); test('object', array(&$o, &$o), true); --EXPECTF-- NULL OK bool(true) OK bool(false) OK int(0) OK int(1) OK int(-1) OK int(1000) OK int(-1000) OK int(100000) OK int(-100000) OK float(123.456) OK string(0) "" OK string(6) "foobar" OK array(0) { } OK array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } OK array(3) { [0]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } [1]=> array(3) { [0]=> int(4) [1]=> int(5) [2]=> int(6) } [2]=> array(3) { [0]=> int(7) [1]=> int(8) [2]=> int(9) } } OK array(3) { [0]=> string(3) "foo" [1]=> string(3) "foo" [2]=> string(3) "foo" } OK array(2) { ["one"]=> int(1) ["two"]=> int(2) } OK array(2) { ["kek"]=> string(3) "lol" ["lol"]=> string(3) "kek" } OK array(1) { [""]=> string(5) "empty" } OK array(2) { [0]=> array(1) { [0]=> string(3) "foo" } [1]=> array(1) { [0]=> string(3) "foo" } } OK array(2) { [0]=> array(1) { [0]=> string(3) "foo" } [1]=> array(1) { [0]=> string(3) "foo" } } OK array(1) { [0]=> array(1) { [0]=> array(1) { [0]=> array(1) { [0]=> array(1) { [0]=> NULL } } } } } OK array(2) { ["a"]=> array(2) { ["b"]=> string(1) "c" ["d"]=> string(1) "e" } ["f"]=> array(1) { ["g"]=> string(1) "h" } } OK array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } OK array(2) { [0]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } [1]=> array(3) { [0]=> int(4) [1]=> int(5) [2]=> int(6) } } OK array(2) { [0]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } [1]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } } OK msgpack-0.5.5/tests/084.phpt0000644000077100007710000000764312110565607015413 0ustar xinchenxinchen--TEST-- disabled php only for class methods (constract) --SKIPIF-- --FILE-- pack($variable); $unserialized = $msgpack->unpack($serialized); var_dump($unserialized); if (!is_bool($test)) { echo $unserialized === $variable ? 'OK' : 'ERROR', PHP_EOL; } else { echo $test || $unserialized == $variable ? 'OK' : 'ERROR', PHP_EOL; } } test('null', null); test('bool: true', true); test('bool: false', false); test('zero: 0', 0); test('small: 1', 1); test('small: -1', -1); test('medium: 1000', 1000); test('medium: -1000', -1000); test('large: 100000', 100000); test('large: -100000', -100000); test('double: 123.456', 123.456); test('empty: ""', ""); test('string: "foobar"', "foobar"); test('array: empty', array(), false); test('array(1, 2, 3)', array(1, 2, 3), false); test('array(array(1, 2, 3), arr...', array(array(1, 2, 3), array(4, 5, 6), array(7, 8, 9)), false); test('array("foo", "foo", "foo")', array("foo", "foo", "foo"), false); test('array("one" => 1, "two" => 2))', array("one" => 1, "two" => 2), false); test('array("kek" => "lol", "lol" => "kek")', array("kek" => "lol", "lol" => "kek"), false); test('array("" => "empty")', array("" => "empty"), false); $a = array('foo'); test('array($a, $a)', array($a, $a), false); test('array(&$a, &$a)', array(&$a, &$a), false); $a = array(null); $b = array(&$a); $a[0] = &$b; test('cyclic', $a, true); $a = array( 'a' => array( 'b' => 'c', 'd' => 'e' ), 'f' => array( 'g' => 'h' ) ); test('array', $a, false); class Obj { public $a; protected $b; private $c; function __construct($a, $b, $c) { $this->a = $a; $this->b = $b; $this->c = $c; } } test('object', new Obj(1, 2, 3), true); test('object', array(new Obj(1, 2, 3), new Obj(4, 5, 6)), true); $o = new Obj(1, 2, 3); test('object', array(&$o, &$o), true); --EXPECTF-- NULL OK bool(true) OK bool(false) OK int(0) OK int(1) OK int(-1) OK int(1000) OK int(-1000) OK int(100000) OK int(-100000) OK float(123.456) OK string(0) "" OK string(6) "foobar" OK array(0) { } OK array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } OK array(3) { [0]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } [1]=> array(3) { [0]=> int(4) [1]=> int(5) [2]=> int(6) } [2]=> array(3) { [0]=> int(7) [1]=> int(8) [2]=> int(9) } } OK array(3) { [0]=> string(3) "foo" [1]=> string(3) "foo" [2]=> string(3) "foo" } OK array(2) { ["one"]=> int(1) ["two"]=> int(2) } OK array(2) { ["kek"]=> string(3) "lol" ["lol"]=> string(3) "kek" } OK array(1) { [""]=> string(5) "empty" } OK array(2) { [0]=> array(1) { [0]=> string(3) "foo" } [1]=> array(1) { [0]=> string(3) "foo" } } OK array(2) { [0]=> array(1) { [0]=> string(3) "foo" } [1]=> array(1) { [0]=> string(3) "foo" } } OK array(1) { [0]=> array(1) { [0]=> array(1) { [0]=> array(1) { [0]=> array(1) { [0]=> NULL } } } } } OK array(2) { ["a"]=> array(2) { ["b"]=> string(1) "c" ["d"]=> string(1) "e" } ["f"]=> array(1) { ["g"]=> string(1) "h" } } OK array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } OK array(2) { [0]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } [1]=> array(3) { [0]=> int(4) [1]=> int(5) [2]=> int(6) } } OK array(2) { [0]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } [1]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } } OK msgpack-0.5.5/tests/085.phpt0000644000077100007710000001147212110565607015407 0ustar xinchenxinchen--TEST-- disabled php only for class methods unpacker (constract) --SKIPIF-- --FILE-- pack($variable); $unpacker = $msgpack->unpacker(); $length = strlen($serialized); if (rand(0, 1)) { for ($i = 0; $i < $length;) { $len = rand(1, 10); $str = substr($serialized, $i, $len); $unpacker->feed($str); if ($unpacker->execute()) { $unserialized = $unpacker->data(); var_dump($unserialized); $unpacker->reset(); } $i += $len; } } else { $str = ""; $offset = 0; for ($i = 0; $i < $length;) { $len = rand(1, 10); $str .= substr($serialized, $i, $len); if ($unpacker->execute($str, $offset)) { $unserialized = $unpacker->data(); var_dump($unserialized); $unpacker->reset(); $str = ""; $offset = 0; } $i += $len; } } if (!is_bool($test)) { echo $unserialized === $variable ? 'OK' : 'ERROR', PHP_EOL; } else { echo $test || $unserialized == $variable ? 'OK' : 'ERROR', PHP_EOL; } } test('null', null); test('bool: true', true); test('bool: false', false); test('zero: 0', 0); test('small: 1', 1); test('small: -1', -1); test('medium: 1000', 1000); test('medium: -1000', -1000); test('large: 100000', 100000); test('large: -100000', -100000); test('double: 123.456', 123.456); test('empty: ""', ""); test('string: "foobar"', "foobar"); test('array: empty', array(), false); test('array(1, 2, 3)', array(1, 2, 3), false); test('array(array(1, 2, 3), arr...', array(array(1, 2, 3), array(4, 5, 6), array(7, 8, 9)), false); test('array("foo", "foo", "foo")', array("foo", "foo", "foo"), false); test('array("one" => 1, "two" => 2))', array("one" => 1, "two" => 2), false); test('array("kek" => "lol", "lol" => "kek")', array("kek" => "lol", "lol" => "kek"), false); test('array("" => "empty")', array("" => "empty"), false); $a = array('foo'); test('array($a, $a)', array($a, $a), false); test('array(&$a, &$a)', array(&$a, &$a), false); $a = array(null); $b = array(&$a); $a[0] = &$b; test('cyclic', $a, true); $a = array( 'a' => array( 'b' => 'c', 'd' => 'e' ), 'f' => array( 'g' => 'h' ) ); test('array', $a, false); class Obj { public $a; protected $b; private $c; function __construct($a, $b, $c) { $this->a = $a; $this->b = $b; $this->c = $c; } } test('object', new Obj(1, 2, 3), true); test('object', array(new Obj(1, 2, 3), new Obj(4, 5, 6)), true); $o = new Obj(1, 2, 3); test('object', array(&$o, &$o), true); --EXPECTF-- NULL OK bool(true) OK bool(false) OK int(0) OK int(1) OK int(-1) OK int(1000) OK int(-1000) OK int(100000) OK int(-100000) OK float(123.456) OK string(0) "" OK string(6) "foobar" OK array(0) { } OK array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } OK array(3) { [0]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } [1]=> array(3) { [0]=> int(4) [1]=> int(5) [2]=> int(6) } [2]=> array(3) { [0]=> int(7) [1]=> int(8) [2]=> int(9) } } OK array(3) { [0]=> string(3) "foo" [1]=> string(3) "foo" [2]=> string(3) "foo" } OK array(2) { ["one"]=> int(1) ["two"]=> int(2) } OK array(2) { ["kek"]=> string(3) "lol" ["lol"]=> string(3) "kek" } OK array(1) { [""]=> string(5) "empty" } OK array(2) { [0]=> array(1) { [0]=> string(3) "foo" } [1]=> array(1) { [0]=> string(3) "foo" } } OK array(2) { [0]=> array(1) { [0]=> string(3) "foo" } [1]=> array(1) { [0]=> string(3) "foo" } } OK array(1) { [0]=> array(1) { [0]=> array(1) { [0]=> array(1) { [0]=> array(1) { [0]=> NULL } } } } } OK array(2) { ["a"]=> array(2) { ["b"]=> string(1) "c" ["d"]=> string(1) "e" } ["f"]=> array(1) { ["g"]=> string(1) "h" } } OK array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } OK array(2) { [0]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } [1]=> array(3) { [0]=> int(4) [1]=> int(5) [2]=> int(6) } } OK array(2) { [0]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } [1]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } } OK msgpack-0.5.5/tests/086.phpt0000644000077100007710000001147512110565607015413 0ustar xinchenxinchen--TEST-- disabled php only for class unpacker (constract) --SKIPIF-- --FILE-- pack($variable); $unpacker = new MessagePackUnpacker(false); $length = strlen($serialized); if (rand(0, 1)) { for ($i = 0; $i < $length;) { $len = rand(1, 10); $str = substr($serialized, $i, $len); $unpacker->feed($str); if ($unpacker->execute()) { $unserialized = $unpacker->data(); var_dump($unserialized); $unpacker->reset(); } $i += $len; } } else { $str = ""; $offset = 0; for ($i = 0; $i < $length;) { $len = rand(1, 10); $str .= substr($serialized, $i, $len); if ($unpacker->execute($str, $offset)) { $unserialized = $unpacker->data(); var_dump($unserialized); $unpacker->reset(); $str = ""; $offset = 0; } $i += $len; } } if (!is_bool($test)) { echo $unserialized === $variable ? 'OK' : 'ERROR', PHP_EOL; } else { echo $test || $unserialized == $variable ? 'OK' : 'ERROR', PHP_EOL; } } test('null', null); test('bool: true', true); test('bool: false', false); test('zero: 0', 0); test('small: 1', 1); test('small: -1', -1); test('medium: 1000', 1000); test('medium: -1000', -1000); test('large: 100000', 100000); test('large: -100000', -100000); test('double: 123.456', 123.456); test('empty: ""', ""); test('string: "foobar"', "foobar"); test('array: empty', array(), false); test('array(1, 2, 3)', array(1, 2, 3), false); test('array(array(1, 2, 3), arr...', array(array(1, 2, 3), array(4, 5, 6), array(7, 8, 9)), false); test('array("foo", "foo", "foo")', array("foo", "foo", "foo"), false); test('array("one" => 1, "two" => 2))', array("one" => 1, "two" => 2), false); test('array("kek" => "lol", "lol" => "kek")', array("kek" => "lol", "lol" => "kek"), false); test('array("" => "empty")', array("" => "empty"), false); $a = array('foo'); test('array($a, $a)', array($a, $a), false); test('array(&$a, &$a)', array(&$a, &$a), false); $a = array(null); $b = array(&$a); $a[0] = &$b; test('cyclic', $a, true); $a = array( 'a' => array( 'b' => 'c', 'd' => 'e' ), 'f' => array( 'g' => 'h' ) ); test('array', $a, false); class Obj { public $a; protected $b; private $c; function __construct($a, $b, $c) { $this->a = $a; $this->b = $b; $this->c = $c; } } test('object', new Obj(1, 2, 3), true); test('object', array(new Obj(1, 2, 3), new Obj(4, 5, 6)), true); $o = new Obj(1, 2, 3); test('object', array(&$o, &$o), true); --EXPECTF-- NULL OK bool(true) OK bool(false) OK int(0) OK int(1) OK int(-1) OK int(1000) OK int(-1000) OK int(100000) OK int(-100000) OK float(123.456) OK string(0) "" OK string(6) "foobar" OK array(0) { } OK array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } OK array(3) { [0]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } [1]=> array(3) { [0]=> int(4) [1]=> int(5) [2]=> int(6) } [2]=> array(3) { [0]=> int(7) [1]=> int(8) [2]=> int(9) } } OK array(3) { [0]=> string(3) "foo" [1]=> string(3) "foo" [2]=> string(3) "foo" } OK array(2) { ["one"]=> int(1) ["two"]=> int(2) } OK array(2) { ["kek"]=> string(3) "lol" ["lol"]=> string(3) "kek" } OK array(1) { [""]=> string(5) "empty" } OK array(2) { [0]=> array(1) { [0]=> string(3) "foo" } [1]=> array(1) { [0]=> string(3) "foo" } } OK array(2) { [0]=> array(1) { [0]=> string(3) "foo" } [1]=> array(1) { [0]=> string(3) "foo" } } OK array(1) { [0]=> array(1) { [0]=> array(1) { [0]=> array(1) { [0]=> array(1) { [0]=> NULL } } } } } OK array(2) { ["a"]=> array(2) { ["b"]=> string(1) "c" ["d"]=> string(1) "e" } ["f"]=> array(1) { ["g"]=> string(1) "h" } } OK array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } OK array(2) { [0]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } [1]=> array(3) { [0]=> int(4) [1]=> int(5) [2]=> int(6) } } OK array(2) { [0]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } [1]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } } OK msgpack-0.5.5/tests/087.phpt0000644000077100007710000001015612110565607015407 0ustar xinchenxinchen--TEST-- disabled php only for class methods (set option) --SKIPIF-- --FILE-- setOption(MESSAGEPACK_OPT_PHPONLY, false); } else { $msgpack->setOption(MessagePack::OPT_PHPONLY, false); } $serialized = $msgpack->pack($variable); $unserialized = $msgpack->unpack($serialized); var_dump($unserialized); if (!is_bool($test)) { echo $unserialized === $variable ? 'OK' : 'ERROR', PHP_EOL; } else { echo $test || $unserialized == $variable ? 'OK' : 'ERROR', PHP_EOL; } } test('null', null); test('bool: true', true); test('bool: false', false); test('zero: 0', 0); test('small: 1', 1); test('small: -1', -1); test('medium: 1000', 1000); test('medium: -1000', -1000); test('large: 100000', 100000); test('large: -100000', -100000); test('double: 123.456', 123.456); test('empty: ""', ""); test('string: "foobar"', "foobar"); test('array: empty', array(), false); test('array(1, 2, 3)', array(1, 2, 3), false); test('array(array(1, 2, 3), arr...', array(array(1, 2, 3), array(4, 5, 6), array(7, 8, 9)), false); test('array("foo", "foo", "foo")', array("foo", "foo", "foo"), false); test('array("one" => 1, "two" => 2))', array("one" => 1, "two" => 2), false); test('array("kek" => "lol", "lol" => "kek")', array("kek" => "lol", "lol" => "kek"), false); test('array("" => "empty")', array("" => "empty"), false); $a = array('foo'); test('array($a, $a)', array($a, $a), false); test('array(&$a, &$a)', array(&$a, &$a), false); $a = array(null); $b = array(&$a); $a[0] = &$b; test('cyclic', $a, true); $a = array( 'a' => array( 'b' => 'c', 'd' => 'e' ), 'f' => array( 'g' => 'h' ) ); test('array', $a, false); class Obj { public $a; protected $b; private $c; function __construct($a, $b, $c) { $this->a = $a; $this->b = $b; $this->c = $c; } } test('object', new Obj(1, 2, 3), true); test('object', array(new Obj(1, 2, 3), new Obj(4, 5, 6)), true); $o = new Obj(1, 2, 3); test('object', array(&$o, &$o), true); --EXPECTF-- NULL OK bool(true) OK bool(false) OK int(0) OK int(1) OK int(-1) OK int(1000) OK int(-1000) OK int(100000) OK int(-100000) OK float(123.456) OK string(0) "" OK string(6) "foobar" OK array(0) { } OK array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } OK array(3) { [0]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } [1]=> array(3) { [0]=> int(4) [1]=> int(5) [2]=> int(6) } [2]=> array(3) { [0]=> int(7) [1]=> int(8) [2]=> int(9) } } OK array(3) { [0]=> string(3) "foo" [1]=> string(3) "foo" [2]=> string(3) "foo" } OK array(2) { ["one"]=> int(1) ["two"]=> int(2) } OK array(2) { ["kek"]=> string(3) "lol" ["lol"]=> string(3) "kek" } OK array(1) { [""]=> string(5) "empty" } OK array(2) { [0]=> array(1) { [0]=> string(3) "foo" } [1]=> array(1) { [0]=> string(3) "foo" } } OK array(2) { [0]=> array(1) { [0]=> string(3) "foo" } [1]=> array(1) { [0]=> string(3) "foo" } } OK array(1) { [0]=> array(1) { [0]=> array(1) { [0]=> array(1) { [0]=> array(1) { [0]=> NULL } } } } } OK array(2) { ["a"]=> array(2) { ["b"]=> string(1) "c" ["d"]=> string(1) "e" } ["f"]=> array(1) { ["g"]=> string(1) "h" } } OK array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } OK array(2) { [0]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } [1]=> array(3) { [0]=> int(4) [1]=> int(5) [2]=> int(6) } } OK array(2) { [0]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } [1]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } } OK msgpack-0.5.5/tests/088.phpt0000644000077100007710000001200512110565607015403 0ustar xinchenxinchen--TEST-- disabled php only for class methods unpacker (set option) --SKIPIF-- --FILE-- setOption(MESSAGEPACK_OPT_PHPONLY, false); } else { $msgpack->setOption(MessagePack::OPT_PHPONLY, false); } $serialized = $msgpack->pack($variable); $unpacker = $msgpack->unpacker(); $length = strlen($serialized); if (rand(0, 1)) { for ($i = 0; $i < $length;) { $len = rand(1, 10); $str = substr($serialized, $i, $len); $unpacker->feed($str); if ($unpacker->execute()) { $unserialized = $unpacker->data(); var_dump($unserialized); $unpacker->reset(); } $i += $len; } } else { $str = ""; $offset = 0; for ($i = 0; $i < $length;) { $len = rand(1, 10); $str .= substr($serialized, $i, $len); if ($unpacker->execute($str, $offset)) { $unserialized = $unpacker->data(); var_dump($unserialized); $unpacker->reset(); $str = ""; $offset = 0; } $i += $len; } } if (!is_bool($test)) { echo $unserialized === $variable ? 'OK' : 'ERROR', PHP_EOL; } else { echo $test || $unserialized == $variable ? 'OK' : 'ERROR', PHP_EOL; } } test('null', null); test('bool: true', true); test('bool: false', false); test('zero: 0', 0); test('small: 1', 1); test('small: -1', -1); test('medium: 1000', 1000); test('medium: -1000', -1000); test('large: 100000', 100000); test('large: -100000', -100000); test('double: 123.456', 123.456); test('empty: ""', ""); test('string: "foobar"', "foobar"); test('array: empty', array(), false); test('array(1, 2, 3)', array(1, 2, 3), false); test('array(array(1, 2, 3), arr...', array(array(1, 2, 3), array(4, 5, 6), array(7, 8, 9)), false); test('array("foo", "foo", "foo")', array("foo", "foo", "foo"), false); test('array("one" => 1, "two" => 2))', array("one" => 1, "two" => 2), false); test('array("kek" => "lol", "lol" => "kek")', array("kek" => "lol", "lol" => "kek"), false); test('array("" => "empty")', array("" => "empty"), false); $a = array('foo'); test('array($a, $a)', array($a, $a), false); test('array(&$a, &$a)', array(&$a, &$a), false); $a = array(null); $b = array(&$a); $a[0] = &$b; test('cyclic', $a, true); $a = array( 'a' => array( 'b' => 'c', 'd' => 'e' ), 'f' => array( 'g' => 'h' ) ); test('array', $a, false); class Obj { public $a; protected $b; private $c; function __construct($a, $b, $c) { $this->a = $a; $this->b = $b; $this->c = $c; } } test('object', new Obj(1, 2, 3), true); test('object', array(new Obj(1, 2, 3), new Obj(4, 5, 6)), true); $o = new Obj(1, 2, 3); test('object', array(&$o, &$o), true); --EXPECTF-- NULL OK bool(true) OK bool(false) OK int(0) OK int(1) OK int(-1) OK int(1000) OK int(-1000) OK int(100000) OK int(-100000) OK float(123.456) OK string(0) "" OK string(6) "foobar" OK array(0) { } OK array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } OK array(3) { [0]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } [1]=> array(3) { [0]=> int(4) [1]=> int(5) [2]=> int(6) } [2]=> array(3) { [0]=> int(7) [1]=> int(8) [2]=> int(9) } } OK array(3) { [0]=> string(3) "foo" [1]=> string(3) "foo" [2]=> string(3) "foo" } OK array(2) { ["one"]=> int(1) ["two"]=> int(2) } OK array(2) { ["kek"]=> string(3) "lol" ["lol"]=> string(3) "kek" } OK array(1) { [""]=> string(5) "empty" } OK array(2) { [0]=> array(1) { [0]=> string(3) "foo" } [1]=> array(1) { [0]=> string(3) "foo" } } OK array(2) { [0]=> array(1) { [0]=> string(3) "foo" } [1]=> array(1) { [0]=> string(3) "foo" } } OK array(1) { [0]=> array(1) { [0]=> array(1) { [0]=> array(1) { [0]=> array(1) { [0]=> NULL } } } } } OK array(2) { ["a"]=> array(2) { ["b"]=> string(1) "c" ["d"]=> string(1) "e" } ["f"]=> array(1) { ["g"]=> string(1) "h" } } OK array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } OK array(2) { [0]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } [1]=> array(3) { [0]=> int(4) [1]=> int(5) [2]=> int(6) } } OK array(2) { [0]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } [1]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } } OK msgpack-0.5.5/tests/089.phpt0000644000077100007710000001247012110565607015412 0ustar xinchenxinchen--TEST-- disabled php only for class unpacker (set option) --SKIPIF-- setOption(MESSAGEPACK_OPT_PHPONLY, false); } else { $msgpack->setOption(MessagePack::OPT_PHPONLY, false); } $serialized = $msgpack->pack($variable); $unpacker = new MessagePackUnpacker(); if (version_compare(PHP_VERSION, '5.1.0') < 0) { $unpacker->setOption(MESSAGEPACK_OPT_PHPONLY, false); } else { $unpacker->setOption(MessagePack::OPT_PHPONLY, false); } $length = strlen($serialized); if (rand(0, 1)) { for ($i = 0; $i < $length;) { $len = rand(1, 10); $str = substr($serialized, $i, $len); $unpacker->feed($str); if ($unpacker->execute()) { $unserialized = $unpacker->data(); var_dump($unserialized); $unpacker->reset(); } $i += $len; } } else { $str = ""; $offset = 0; for ($i = 0; $i < $length;) { $len = rand(1, 10); $str .= substr($serialized, $i, $len); if ($unpacker->execute($str, $offset)) { $unserialized = $unpacker->data(); var_dump($unserialized); $unpacker->reset(); $str = ""; $offset = 0; } $i += $len; } } if (!is_bool($test)) { echo $unserialized === $variable ? 'OK' : 'ERROR', PHP_EOL; } else { echo $test || $unserialized == $variable ? 'OK' : 'ERROR', PHP_EOL; } } test('null', null); test('bool: true', true); test('bool: false', false); test('zero: 0', 0); test('small: 1', 1); test('small: -1', -1); test('medium: 1000', 1000); test('medium: -1000', -1000); test('large: 100000', 100000); test('large: -100000', -100000); test('double: 123.456', 123.456); test('empty: ""', ""); test('string: "foobar"', "foobar"); test('array: empty', array(), false); test('array(1, 2, 3)', array(1, 2, 3), false); test('array(array(1, 2, 3), arr...', array(array(1, 2, 3), array(4, 5, 6), array(7, 8, 9)), false); test('array("foo", "foo", "foo")', array("foo", "foo", "foo"), false); test('array("one" => 1, "two" => 2))', array("one" => 1, "two" => 2), false); test('array("kek" => "lol", "lol" => "kek")', array("kek" => "lol", "lol" => "kek"), false); test('array("" => "empty")', array("" => "empty"), false); $a = array('foo'); test('array($a, $a)', array($a, $a), false); test('array(&$a, &$a)', array(&$a, &$a), false); $a = array(null); $b = array(&$a); $a[0] = &$b; test('cyclic', $a, true); $a = array( 'a' => array( 'b' => 'c', 'd' => 'e' ), 'f' => array( 'g' => 'h' ) ); test('array', $a, false); class Obj { public $a; protected $b; private $c; function __construct($a, $b, $c) { $this->a = $a; $this->b = $b; $this->c = $c; } } test('object', new Obj(1, 2, 3), true); test('object', array(new Obj(1, 2, 3), new Obj(4, 5, 6)), true); $o = new Obj(1, 2, 3); test('object', array(&$o, &$o), true); --EXPECTF-- NULL OK bool(true) OK bool(false) OK int(0) OK int(1) OK int(-1) OK int(1000) OK int(-1000) OK int(100000) OK int(-100000) OK float(123.456) OK string(0) "" OK string(6) "foobar" OK array(0) { } OK array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } OK array(3) { [0]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } [1]=> array(3) { [0]=> int(4) [1]=> int(5) [2]=> int(6) } [2]=> array(3) { [0]=> int(7) [1]=> int(8) [2]=> int(9) } } OK array(3) { [0]=> string(3) "foo" [1]=> string(3) "foo" [2]=> string(3) "foo" } OK array(2) { ["one"]=> int(1) ["two"]=> int(2) } OK array(2) { ["kek"]=> string(3) "lol" ["lol"]=> string(3) "kek" } OK array(1) { [""]=> string(5) "empty" } OK array(2) { [0]=> array(1) { [0]=> string(3) "foo" } [1]=> array(1) { [0]=> string(3) "foo" } } OK array(2) { [0]=> array(1) { [0]=> string(3) "foo" } [1]=> array(1) { [0]=> string(3) "foo" } } OK array(1) { [0]=> array(1) { [0]=> array(1) { [0]=> array(1) { [0]=> array(1) { [0]=> NULL } } } } } OK array(2) { ["a"]=> array(2) { ["b"]=> string(1) "c" ["d"]=> string(1) "e" } ["f"]=> array(1) { ["g"]=> string(1) "h" } } OK array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } OK array(2) { [0]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } [1]=> array(3) { [0]=> int(4) [1]=> int(5) [2]=> int(6) } } OK array(2) { [0]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } [1]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } } OK msgpack-0.5.5/tests/090.phpt0000644000077100007710000002411012110565607015374 0ustar xinchenxinchen--TEST-- unpack of object converter (string) --SKIPIF-- a = $a; $this->b = $b; $this->c = $c; if (is_array($d)) { foreach ($d as $key => $val) { $this->{$key} = $val; } } } } test('null', null, 'Obj', new Obj(null, null, null)); test('bool: true', true, 'Obj', new Obj(true, null, null)); test('bool: false', false, 'Obj', new Obj(false, null, null)); test('zero: 0', 0, 'Obj', new Obj(0, null, null)); test('small: 1', 1, 'Obj', new Obj(1, null, null)); test('small: -1', -1, 'Obj', new Obj(-1, null, null)); test('medium: 1000', 1000, 'Obj', new Obj(1000, null, null)); test('medium: -1000', -1000, 'Obj', new Obj(-1000, null, null)); test('large: 100000', 100000, 'Obj', new Obj(100000, null, null)); test('large: -100000', -100000, 'Obj', new Obj(-100000, null, null)); test('double: 123.456', 123.456, 'Obj', new Obj(123.456, null, null)); test('empty: ""', "", 'Obj', new Obj("", null, null)); test('string: "foobar"', "foobar", 'Obj', new Obj("foobar", null, null)); test('array: empty', array(), 'Obj', new Obj(null, null, null)); test('array(1, 2, 3)', array(1, 2, 3), 'Obj', new Obj(1, 2, 3)); test('array(array(1, 2, 3), arr...', array(array(1, 2, 3), array(4, 5, 6), array(7, 8, 9)), 'Obj', new Obj(array(1, 2, 3), array(4, 5, 6), array(7, 8, 9))); test('array(1, 2, 3, 4)', array(1, 2, 3, 4), 'Obj'); test('array("foo", "foobar", "foohoge")', array("foo", "foobar", "hoge"), 'Obj', new Obj("foo", "foobar", "hoge")); test('array("a" => 1, "b" => 2))', array("a" => 1, "b" => 2), 'Obj', new Obj(1, 2, null)); test('array("one" => 1, "two" => 2))', array("one" => 1, "two" => 2), 'Obj', new Obj(null, null, null, array("one" => 1, "two" => 2))); test('array("" => "empty")', array("" => "empty"), 'Obj'); test('array("a" => 1, "b" => 2, 3))', array("a" => 1, "b" => 2, 3), 'Obj', new Obj(1, 2, 3)); test('array(3, "a" => 1, "b" => 2))', array(3, "a" => 1, "b" => 2), 'Obj', new Obj(1, 2, 3)); test('array("a" => 1, 3, "b" => 2))', array("a" => 1, 3, "b" => 2), 'Obj', new Obj(1, 2, 3)); $a = array('foo'); test('array($a, $a)', array($a, $a), 'Obj', new Obj($a, $a, null)); test('array(&$a, &$a)', array(&$a, &$a), 'Obj', new Obj($a, $a, null)); test('array(&$a, $a)', array($a, &$a), 'Obj', new Obj($a, $a, null)); test('array(&$a, $a)', array(&$a, $a), 'Obj', new Obj($a, $a, null)); $a = array( 'a' => array( 'b' => 'c', 'd' => 'e' ), 'f' => array( 'g' => 'h' ) ); test('array', $a, 'Obj', new Obj(null, null, null, $a)); $o = new Obj(1, 2, 3); test('object', $o, 'Obj', new Obj(1, 2, 3)); class Obj2 { public $A; protected $B; private $C; function __construct($a, $b, $c) { $this->A = $a; $this->B = $b; $this->C = $c; } } $o = new Obj2(1, 2, 3); test('object', $o, 'Obj', new Obj($o)); $o1 = new Obj2(1, 2, 3); $o2 = new Obj2(4, 5, 6); test('object', array($o1, $o2), 'Obj', new Obj($o1, $o2)); $o = new Obj2(1, 2, 3); test('object', array(&$o, &$o), 'Obj', new Obj($o, $o)); $o = new Obj2(1, 2, 3); test('object', array(&$o, $o), 'Obj', new Obj($o, $o)); $o = new Obj2(1, 2, 3); test('object', array($o, &$o), 'Obj', new Obj($o, $o)); --EXPECTF-- object(Obj)#%d (3) { ["a"]=> NULL [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> bool(true) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> bool(false) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(0) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(-1) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(1000) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(-1000) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(100000) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(-100000) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> float(123.456) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> string(0) "" [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> string(6) "foobar" [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> NULL [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } [%r"?b"?:protected"?%r]=> array(3) { [0]=> int(4) [1]=> int(5) [2]=> int(6) } [%r"?c"?:("Obj":)?private"?%r]=> array(3) { [0]=> int(7) [1]=> int(8) [2]=> int(9) } } OK object(Obj)#%d (4) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) [3]=> int(4) } SKIP object(Obj)#%d (3) { ["a"]=> string(3) "foo" [%r"?b"?:protected"?%r]=> string(6) "foobar" [%r"?c"?:("Obj":)?private"?%r]=> string(4) "hoge" } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (5) { ["a"]=> NULL [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL ["one"]=> int(1) ["two"]=> int(2) } OK object(Obj)#%d (4) { ["a"]=> NULL [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL [""]=> string(5) "empty" } SKIP object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> array(1) { [0]=> string(3) "foo" } [%r"?b"?:protected"?%r]=> array(1) { [0]=> string(3) "foo" } [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> &array(1) { [0]=> string(3) "foo" } [%r"?b"?:protected"?%r]=> &array(1) { [0]=> string(3) "foo" } [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> array(1) { [0]=> string(3) "foo" } [%r"?b"?:protected"?%r]=> &array(1) { [0]=> string(3) "foo" } [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> &array(1) { [0]=> string(3) "foo" } [%r"?b"?:protected"?%r]=> array(1) { [0]=> string(3) "foo" } [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (4) { ["a"]=> array(2) { ["b"]=> string(1) "c" ["d"]=> string(1) "e" } [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL ["f"]=> array(1) { ["g"]=> string(1) "h" } } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> object(Obj2)#%d (3) { ["A"]=> int(1) [%r"?B"?:protected"?%r]=> int(2) [%r"?C"?:("Obj2":)?private"?%r]=> int(3) } [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> object(Obj2)#%d (3) { ["A"]=> int(1) [%r"?B"?:protected"?%r]=> int(2) [%r"?C"?:("Obj2":)?private"?%r]=> int(3) } [%r"?b"?:protected"?%r]=> object(Obj2)#%d (3) { ["A"]=> int(4) [%r"?B"?:protected"?%r]=> int(5) [%r"?C"?:("Obj2":)?private"?%r]=> int(6) } [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> &object(Obj2)#%d (3) { ["A"]=> int(1) [%r"?B"?:protected"?%r]=> int(2) [%r"?C"?:("Obj2":)?private"?%r]=> int(3) } [%r"?b"?:protected"?%r]=> &object(Obj2)#%d (3) { ["A"]=> int(1) [%r"?B"?:protected"?%r]=> int(2) [%r"?C"?:("Obj2":)?private"?%r]=> int(3) } [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> object(Obj2)#%d (3) { ["A"]=> int(1) [%r"?B"?:protected"?%r]=> int(2) [%r"?C"?:("Obj2":)?private"?%r]=> int(3) } [%r"?b"?:protected"?%r]=> object(Obj2)#%d (3) { ["A"]=> int(1) [%r"?B"?:protected"?%r]=> int(2) [%r"?C"?:("Obj2":)?private"?%r]=> int(3) } [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> &object(Obj2)#%d (3) { ["A"]=> int(1) [%r"?B"?:protected"?%r]=> int(2) [%r"?C"?:("Obj2":)?private"?%r]=> int(3) } [%r"?b"?:protected"?%r]=> &object(Obj2)#%d (3) { ["A"]=> int(1) [%r"?B"?:protected"?%r]=> int(2) [%r"?C"?:("Obj2":)?private"?%r]=> int(3) } [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK msgpack-0.5.5/tests/090b.phpt0000644000077100007710000002147312110565607015547 0ustar xinchenxinchen--TEST-- unpack of object converter (string) --SKIPIF-- = 0) { echo "skip tests in PHP 5.1 or older"; } --FILE-- a = $a; $this->b = $b; $this->c = $c; if (is_array($d)) { foreach ($d as $key => $val) { $this->{$key} = $val; } } } } test('null', null, 'Obj', new Obj(null, null, null)); test('bool: true', true, 'Obj', new Obj(true, null, null)); test('bool: false', false, 'Obj', new Obj(false, null, null)); test('zero: 0', 0, 'Obj', new Obj(0, null, null)); test('small: 1', 1, 'Obj', new Obj(1, null, null)); test('small: -1', -1, 'Obj', new Obj(-1, null, null)); test('medium: 1000', 1000, 'Obj', new Obj(1000, null, null)); test('medium: -1000', -1000, 'Obj', new Obj(-1000, null, null)); test('large: 100000', 100000, 'Obj', new Obj(100000, null, null)); test('large: -100000', -100000, 'Obj', new Obj(-100000, null, null)); test('double: 123.456', 123.456, 'Obj', new Obj(123.456, null, null)); test('empty: ""', "", 'Obj', new Obj("", null, null)); test('string: "foobar"', "foobar", 'Obj', new Obj("foobar", null, null)); test('array: empty', array(), 'Obj', new Obj(null, null, null)); test('array(1, 2, 3)', array(1, 2, 3), 'Obj', new Obj(1, 2, 3)); test('array(array(1, 2, 3), arr...', array(array(1, 2, 3), array(4, 5, 6), array(7, 8, 9)), 'Obj', new Obj(array(1, 2, 3), array(4, 5, 6), array(7, 8, 9))); test('array(1, 2, 3, 4)', array(1, 2, 3, 4), 'Obj'); test('array("foo", "foobar", "foohoge")', array("foo", "foobar", "hoge"), 'Obj', new Obj("foo", "foobar", "hoge")); test('array("a" => 1, "b" => 2))', array("a" => 1, "b" => 2), 'Obj', new Obj(1, 2, null)); test('array("one" => 1, "two" => 2))', array("one" => 1, "two" => 2), 'Obj', new Obj(null, null, null, array("one" => 1, "two" => 2))); test('array("a" => 1, "b" => 2, 3))', array("a" => 1, "b" => 2, 3), 'Obj', new Obj(1, 2, 3)); test('array(3, "a" => 1, "b" => 2))', array(3, "a" => 1, "b" => 2), 'Obj', new Obj(1, 2, 3)); test('array("a" => 1, 3, "b" => 2))', array("a" => 1, 3, "b" => 2), 'Obj', new Obj(1, 2, 3)); $a = array('foo'); test('array($a, $a)', array($a, $a), 'Obj', new Obj($a, $a, null)); test('array(&$a, &$a)', array(&$a, &$a), 'Obj', new Obj($a, $a, null)); test('array(&$a, $a)', array($a, &$a), 'Obj', new Obj($a, $a, null)); test('array(&$a, $a)', array(&$a, $a), 'Obj', new Obj($a, $a, null)); $a = array( 'a' => array( 'b' => 'c', 'd' => 'e' ), 'f' => array( 'g' => 'h' ) ); test('array', $a, 'Obj', new Obj(null, null, null, $a)); $o = new Obj(1, 2, 3); test('object', $o, 'Obj', new Obj(1, 2, 3)); class Obj2 { public $A; protected $B; private $C; function __construct($a, $b, $c) { $this->A = $a; $this->B = $b; $this->C = $c; } } $o = new Obj2(1, 2, 3); test('object', $o, 'Obj', new Obj($o)); $o1 = new Obj2(1, 2, 3); $o2 = new Obj2(4, 5, 6); test('object', array($o1, $o2), 'Obj', new Obj($o1, $o2)); $o = new Obj2(1, 2, 3); test('object', array(&$o, &$o), 'Obj', new Obj($o, $o)); $o = new Obj2(1, 2, 3); test('object', array(&$o, $o), 'Obj', new Obj($o, $o)); $o = new Obj2(1, 2, 3); test('object', array($o, &$o), 'Obj', new Obj($o, $o)); --EXPECTF-- object(Obj)#%d (3) { ["a"]=> NULL ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> bool(true) ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> bool(false) ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(0) ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(1) ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(-1) ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(1000) ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(-1000) ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(100000) ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(-100000) ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> float(123.456) ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> string(0) "" ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> string(6) "foobar" ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> NULL ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(1) ["b:protected"]=> int(2) ["c:private"]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } ["b:protected"]=> array(3) { [0]=> int(4) [1]=> int(5) [2]=> int(6) } ["c:private"]=> array(3) { [0]=> int(7) [1]=> int(8) [2]=> int(9) } } OK object(Obj)#%d (4) { ["a"]=> int(1) ["b:protected"]=> int(2) ["c:private"]=> int(3) [3]=> int(4) } SKIP object(Obj)#%d (3) { ["a"]=> string(3) "foo" ["b:protected"]=> string(6) "foobar" ["c:private"]=> string(4) "hoge" } OK object(Obj)#%d (3) { ["a"]=> int(1) ["b:protected"]=> int(2) ["c:private"]=> NULL } OK object(Obj)#%d (5) { ["a"]=> NULL ["b:protected"]=> NULL ["c:private"]=> NULL ["one"]=> int(1) ["two"]=> int(2) } OK object(Obj)#%d (3) { ["a"]=> int(1) ["b:protected"]=> int(2) ["c:private"]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> int(1) ["b:protected"]=> int(2) ["c:private"]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> int(1) ["b:protected"]=> int(2) ["c:private"]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> array(1) { [0]=> string(3) "foo" } ["b:protected"]=> array(1) { [0]=> string(3) "foo" } ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> &array(1) { [0]=> string(3) "foo" } ["b:protected"]=> &array(1) { [0]=> string(3) "foo" } ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> array(1) { [0]=> string(3) "foo" } ["b:protected"]=> &array(1) { [0]=> string(3) "foo" } ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> &array(1) { [0]=> string(3) "foo" } ["b:protected"]=> array(1) { [0]=> string(3) "foo" } ["c:private"]=> NULL } OK object(Obj)#%d (4) { ["a"]=> array(2) { ["b"]=> string(1) "c" ["d"]=> string(1) "e" } ["b:protected"]=> NULL ["c:private"]=> NULL ["f"]=> array(1) { ["g"]=> string(1) "h" } } OK object(Obj)#%d (3) { ["a"]=> int(1) ["b:protected"]=> int(2) ["c:private"]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> object(Obj2)#%d (3) { ["A"]=> int(1) ["B:protected"]=> int(2) ["C:private"]=> int(3) } ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> object(Obj2)#%d (3) { ["A"]=> int(1) ["B:protected"]=> int(2) ["C:private"]=> int(3) } ["b:protected"]=> object(Obj2)#%d (3) { ["A"]=> int(4) ["B:protected"]=> int(5) ["C:private"]=> int(6) } ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> &object(Obj2)#%d (3) { ["A"]=> int(1) ["B:protected"]=> int(2) ["C:private"]=> int(3) } ["b:protected"]=> &object(Obj2)#%d (3) { ["A"]=> int(1) ["B:protected"]=> int(2) ["C:private"]=> int(3) } ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> object(Obj2)#%d (3) { ["A"]=> int(1) ["B:protected"]=> int(2) ["C:private"]=> int(3) } ["b:protected"]=> object(Obj2)#%d (3) { ["A"]=> int(1) ["B:protected"]=> int(2) ["C:private"]=> int(3) } ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> &object(Obj2)#%d (3) { ["A"]=> int(1) ["B:protected"]=> int(2) ["C:private"]=> int(3) } ["b:protected"]=> &object(Obj2)#%d (3) { ["A"]=> int(1) ["B:protected"]=> int(2) ["C:private"]=> int(3) } ["c:private"]=> NULL } OK msgpack-0.5.5/tests/091.phpt0000644000077100007710000002435212110565607015405 0ustar xinchenxinchen--TEST-- unpack of object converter (object) --SKIPIF-- a = $a; $this->b = $b; $this->c = $c; if (is_array($d)) { foreach ($d as $key => $val) { $this->{$key} = $val; } } } } $object = new Obj(); test('null', null, new Obj(), new Obj(null, null, null)); test('bool: true', true, new Obj(), new Obj(true, null, null)); test('bool: false', false, new Obj(), new Obj(false, null, null)); test('zero: 0', 0, new Obj(), new Obj(0, null, null)); test('small: 1', 1, new Obj(), new Obj(1, null, null)); test('small: -1', -1, new Obj(), new Obj(-1, null, null)); test('medium: 1000', 1000, new Obj(), new Obj(1000, null, null)); test('medium: -1000', -1000, new Obj(), new Obj(-1000, null, null)); test('large: 100000', 100000, new Obj(), new Obj(100000, null, null)); test('large: -100000', -100000, new Obj(), new Obj(-100000, null, null)); test('double: 123.456', 123.456, new Obj(), new Obj(123.456, null, null)); test('empty: ""', "", new Obj(), new Obj("", null, null)); test('string: "foobar"', "foobar", new Obj(), new Obj("foobar", null, null)); test('array: empty', array(), new Obj(), new Obj(null, null, null)); test('array(1, 2, 3)', array(1, 2, 3), new Obj(), new Obj(1, 2, 3)); test('array(array(1, 2, 3), arr...', array(array(1, 2, 3), array(4, 5, 6), array(7, 8, 9)), new Obj(), new Obj(array(1, 2, 3), array(4, 5, 6), array(7, 8, 9))); test('array(1, 2, 3, 4)', array(1, 2, 3, 4), new Obj()); test('array("foo", "foobar", "foohoge")', array("foo", "foobar", "hoge"), new Obj(), new Obj("foo", "foobar", "hoge")); test('array("a" => 1, "b" => 2))', array("a" => 1, "b" => 2), new Obj(), new Obj(1, 2, null)); test('array("one" => 1, "two" => 2))', array("one" => 1, "two" => 2), new Obj(), new Obj(null, null, null, array("one" => 1, "two" => 2))); test('array("" => "empty")', array("" => "empty"), new Obj()); test('array("a" => 1, "b" => 2, 3))', array("a" => 1, "b" => 2, 3), new Obj(), new Obj(1, 2, 3)); test('array(3, "a" => 1, "b" => 2))', array(3, "a" => 1, "b" => 2), new Obj(), new Obj(1, 2, 3)); test('array("a" => 1, 3, "b" => 2))', array("a" => 1, 3, "b" => 2), new Obj(), new Obj(1, 2, 3)); $a = array('foo'); test('array($a, $a)', array($a, $a), new Obj(), new Obj($a, $a, null)); test('array(&$a, &$a)', array(&$a, &$a), new Obj(), new Obj($a, $a, null)); test('array(&$a, $a)', array($a, &$a), new Obj(), new Obj($a, $a, null)); test('array(&$a, $a)', array(&$a, $a), new Obj(), new Obj($a, $a, null)); $a = array( 'a' => array( 'b' => 'c', 'd' => 'e' ), 'f' => array( 'g' => 'h' ) ); test('array', $a, new Obj(), new Obj(null, null, null, $a)); $o = new Obj(1, 2, 3); test('object', $o, new Obj(), new Obj(1, 2, 3)); class Obj2 { public $A; protected $B; private $C; function __construct($a, $b, $c) { $this->A = $a; $this->B = $b; $this->C = $c; } } $o = new Obj2(1, 2, 3); test('object', $o, new Obj(), new Obj($o)); $o1 = new Obj2(1, 2, 3); $o2 = new Obj2(4, 5, 6); test('object', array($o1, $o2), new Obj(), new Obj($o1, $o2)); $o = new Obj2(1, 2, 3); test('object', array(&$o, &$o), new Obj(), new Obj($o, $o)); $o = new Obj2(1, 2, 3); test('object', array(&$o, $o), new Obj(), new Obj($o, $o)); $o = new Obj2(1, 2, 3); test('object', array($o, &$o), new Obj(), new Obj($o, $o)); --EXPECTF-- object(Obj)#%d (3) { ["a"]=> NULL [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> bool(true) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> bool(false) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(0) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(-1) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(1000) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(-1000) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(100000) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(-100000) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> float(123.456) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> string(0) "" [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> string(6) "foobar" [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> NULL [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } [%r"?b"?:protected"?%r]=> array(3) { [0]=> int(4) [1]=> int(5) [2]=> int(6) } [%r"?c"?:("Obj":)?private"?%r]=> array(3) { [0]=> int(7) [1]=> int(8) [2]=> int(9) } } OK object(Obj)#%d (4) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) [3]=> int(4) } SKIP object(Obj)#%d (3) { ["a"]=> string(3) "foo" [%r"?b"?:protected"?%r]=> string(6) "foobar" [%r"?c"?:("Obj":)?private"?%r]=> string(4) "hoge" } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (5) { ["a"]=> NULL [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL ["one"]=> int(1) ["two"]=> int(2) } OK object(Obj)#%d (4) { ["a"]=> NULL [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL [""]=> string(5) "empty" } SKIP object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> array(1) { [0]=> string(3) "foo" } [%r"?b"?:protected"?%r]=> array(1) { [0]=> string(3) "foo" } [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> &array(1) { [0]=> string(3) "foo" } [%r"?b"?:protected"?%r]=> &array(1) { [0]=> string(3) "foo" } [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> array(1) { [0]=> string(3) "foo" } [%r"?b"?:protected"?%r]=> &array(1) { [0]=> string(3) "foo" } [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> &array(1) { [0]=> string(3) "foo" } [%r"?b"?:protected"?%r]=> array(1) { [0]=> string(3) "foo" } [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (4) { ["a"]=> array(2) { ["b"]=> string(1) "c" ["d"]=> string(1) "e" } [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL ["f"]=> array(1) { ["g"]=> string(1) "h" } } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> object(Obj2)#%d (3) { ["A"]=> int(1) [%r"?B"?:protected"?%r]=> int(2) [%r"?C"?:("Obj2":)?private"?%r]=> int(3) } [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> object(Obj2)#%d (3) { ["A"]=> int(1) [%r"?B"?:protected"?%r]=> int(2) [%r"?C"?:("Obj2":)?private"?%r]=> int(3) } [%r"?b"?:protected"?%r]=> object(Obj2)#%d (3) { ["A"]=> int(4) [%r"?B"?:protected"?%r]=> int(5) [%r"?C"?:("Obj2":)?private"?%r]=> int(6) } [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> &object(Obj2)#%d (3) { ["A"]=> int(1) [%r"?B"?:protected"?%r]=> int(2) [%r"?C"?:("Obj2":)?private"?%r]=> int(3) } [%r"?b"?:protected"?%r]=> &object(Obj2)#%d (3) { ["A"]=> int(1) [%r"?B"?:protected"?%r]=> int(2) [%r"?C"?:("Obj2":)?private"?%r]=> int(3) } [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> object(Obj2)#%d (3) { ["A"]=> int(1) [%r"?B"?:protected"?%r]=> int(2) [%r"?C"?:("Obj2":)?private"?%r]=> int(3) } [%r"?b"?:protected"?%r]=> object(Obj2)#%d (3) { ["A"]=> int(1) [%r"?B"?:protected"?%r]=> int(2) [%r"?C"?:("Obj2":)?private"?%r]=> int(3) } [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> &object(Obj2)#%d (3) { ["A"]=> int(1) [%r"?B"?:protected"?%r]=> int(2) [%r"?C"?:("Obj2":)?private"?%r]=> int(3) } [%r"?b"?:protected"?%r]=> &object(Obj2)#%d (3) { ["A"]=> int(1) [%r"?B"?:protected"?%r]=> int(2) [%r"?C"?:("Obj2":)?private"?%r]=> int(3) } [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK msgpack-0.5.5/tests/091b.phpt0000644000077100007710000002170312110565607015544 0ustar xinchenxinchen--TEST-- unpack of object converter (object) --SKIPIF-- = 0) { echo "skip tests in PHP 5.1 or older"; } --FILE-- a = $a; $this->b = $b; $this->c = $c; if (is_array($d)) { foreach ($d as $key => $val) { $this->{$key} = $val; } } } } test('null', null, new Obj(), new Obj(null, null, null)); test('bool: true', true, new Obj(), new Obj(true, null, null)); test('bool: false', false, new Obj(), new Obj(false, null, null)); test('zero: 0', 0, new Obj(), new Obj(0, null, null)); test('small: 1', 1, new Obj(), new Obj(1, null, null)); test('small: -1', -1, new Obj(), new Obj(-1, null, null)); test('medium: 1000', 1000, new Obj(), new Obj(1000, null, null)); test('medium: -1000', -1000, new Obj(), new Obj(-1000, null, null)); test('large: 100000', 100000, new Obj(), new Obj(100000, null, null)); test('large: -100000', -100000, new Obj(), new Obj(-100000, null, null)); test('double: 123.456', 123.456, new Obj(), new Obj(123.456, null, null)); test('empty: ""', "", new Obj(), new Obj("", null, null)); test('string: "foobar"', "foobar", new Obj(), new Obj("foobar", null, null)); test('array: empty', array(), new Obj(), new Obj(null, null, null)); test('array(1, 2, 3)', array(1, 2, 3), new Obj(), new Obj(1, 2, 3)); test('array(array(1, 2, 3), arr...', array(array(1, 2, 3), array(4, 5, 6), array(7, 8, 9)), new Obj(), new Obj(array(1, 2, 3), array(4, 5, 6), array(7, 8, 9))); test('array(1, 2, 3, 4)', array(1, 2, 3, 4), new Obj()); test('array("foo", "foobar", "foohoge")', array("foo", "foobar", "hoge"), new Obj(), new Obj("foo", "foobar", "hoge")); test('array("a" => 1, "b" => 2))', array("a" => 1, "b" => 2), new Obj(), new Obj(1, 2, null)); test('array("one" => 1, "two" => 2))', array("one" => 1, "two" => 2), new Obj(), new Obj(null, null, null, array("one" => 1, "two" => 2))); test('array("a" => 1, "b" => 2, 3))', array("a" => 1, "b" => 2, 3), new Obj(), new Obj(1, 2, 3)); test('array(3, "a" => 1, "b" => 2))', array(3, "a" => 1, "b" => 2), new Obj(), new Obj(1, 2, 3)); test('array("a" => 1, 3, "b" => 2))', array("a" => 1, 3, "b" => 2), new Obj(), new Obj(1, 2, 3)); $a = array('foo'); test('array($a, $a)', array($a, $a), new Obj(), new Obj($a, $a, null)); test('array(&$a, &$a)', array(&$a, &$a), new Obj(), new Obj($a, $a, null)); test('array(&$a, $a)', array($a, &$a), new Obj(), new Obj($a, $a, null)); test('array(&$a, $a)', array(&$a, $a), new Obj(), new Obj($a, $a, null)); $a = array( 'a' => array( 'b' => 'c', 'd' => 'e' ), 'f' => array( 'g' => 'h' ) ); test('array', $a, new Obj(), new Obj(null, null, null, $a)); $o = new Obj(1, 2, 3); test('object', $o, new Obj(), new Obj(1, 2, 3)); class Obj2 { public $A; protected $B; private $C; function __construct($a, $b, $c) { $this->A = $a; $this->B = $b; $this->C = $c; } } $o = new Obj2(1, 2, 3); test('object', $o, new Obj(), new Obj($o)); $o1 = new Obj2(1, 2, 3); $o2 = new Obj2(4, 5, 6); test('object', array($o1, $o2), new Obj(), new Obj($o1, $o2)); $o = new Obj2(1, 2, 3); test('object', array(&$o, &$o), new Obj(), new Obj($o, $o)); $o = new Obj2(1, 2, 3); test('object', array(&$o, $o), new Obj(), new Obj($o, $o)); $o = new Obj2(1, 2, 3); test('object', array($o, &$o), new Obj(), new Obj($o, $o)); --EXPECTF-- object(Obj)#%d (3) { ["a"]=> NULL ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> bool(true) ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> bool(false) ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(0) ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(1) ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(-1) ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(1000) ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(-1000) ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(100000) ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(-100000) ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> float(123.456) ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> string(0) "" ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> string(6) "foobar" ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> NULL ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(1) ["b:protected"]=> int(2) ["c:private"]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } ["b:protected"]=> array(3) { [0]=> int(4) [1]=> int(5) [2]=> int(6) } ["c:private"]=> array(3) { [0]=> int(7) [1]=> int(8) [2]=> int(9) } } OK object(Obj)#%d (4) { ["a"]=> int(1) ["b:protected"]=> int(2) ["c:private"]=> int(3) [3]=> int(4) } SKIP object(Obj)#%d (3) { ["a"]=> string(3) "foo" ["b:protected"]=> string(6) "foobar" ["c:private"]=> string(4) "hoge" } OK object(Obj)#%d (3) { ["a"]=> int(1) ["b:protected"]=> int(2) ["c:private"]=> NULL } OK object(Obj)#%d (5) { ["a"]=> NULL ["b:protected"]=> NULL ["c:private"]=> NULL ["one"]=> int(1) ["two"]=> int(2) } OK object(Obj)#%d (3) { ["a"]=> int(1) ["b:protected"]=> int(2) ["c:private"]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> int(1) ["b:protected"]=> int(2) ["c:private"]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> int(1) ["b:protected"]=> int(2) ["c:private"]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> array(1) { [0]=> string(3) "foo" } ["b:protected"]=> array(1) { [0]=> string(3) "foo" } ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> &array(1) { [0]=> string(3) "foo" } ["b:protected"]=> &array(1) { [0]=> string(3) "foo" } ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> array(1) { [0]=> string(3) "foo" } ["b:protected"]=> &array(1) { [0]=> string(3) "foo" } ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> &array(1) { [0]=> string(3) "foo" } ["b:protected"]=> array(1) { [0]=> string(3) "foo" } ["c:private"]=> NULL } OK object(Obj)#%d (4) { ["a"]=> array(2) { ["b"]=> string(1) "c" ["d"]=> string(1) "e" } ["b:protected"]=> NULL ["c:private"]=> NULL ["f"]=> array(1) { ["g"]=> string(1) "h" } } OK object(Obj)#%d (3) { ["a"]=> int(1) ["b:protected"]=> int(2) ["c:private"]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> object(Obj2)#%d (3) { ["A"]=> int(1) ["B:protected"]=> int(2) ["C:private"]=> int(3) } ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> object(Obj2)#%d (3) { ["A"]=> int(1) ["B:protected"]=> int(2) ["C:private"]=> int(3) } ["b:protected"]=> object(Obj2)#%d (3) { ["A"]=> int(4) ["B:protected"]=> int(5) ["C:private"]=> int(6) } ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> &object(Obj2)#%d (3) { ["A"]=> int(1) ["B:protected"]=> int(2) ["C:private"]=> int(3) } ["b:protected"]=> &object(Obj2)#%d (3) { ["A"]=> int(1) ["B:protected"]=> int(2) ["C:private"]=> int(3) } ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> object(Obj2)#%d (3) { ["A"]=> int(1) ["B:protected"]=> int(2) ["C:private"]=> int(3) } ["b:protected"]=> object(Obj2)#%d (3) { ["A"]=> int(1) ["B:protected"]=> int(2) ["C:private"]=> int(3) } ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> &object(Obj2)#%d (3) { ["A"]=> int(1) ["B:protected"]=> int(2) ["C:private"]=> int(3) } ["b:protected"]=> &object(Obj2)#%d (3) { ["A"]=> int(1) ["B:protected"]=> int(2) ["C:private"]=> int(3) } ["c:private"]=> NULL } OK msgpack-0.5.5/tests/092.phpt0000644000077100007710000001734012110565607015405 0ustar xinchenxinchen--TEST-- unpack of object converter (string: php_only=0) --SKIPIF-- a = $a; $this->b = $b; $this->c = $c; if (is_array($d)) { foreach ($d as $key => $val) { $this->{$key} = $val; } } } } test('null', null, 'Obj', new Obj(null, null, null)); test('bool: true', true, 'Obj', new Obj(true, null, null)); test('bool: false', false, 'Obj', new Obj(false, null, null)); test('zero: 0', 0, 'Obj', new Obj(0, null, null)); test('small: 1', 1, 'Obj', new Obj(1, null, null)); test('small: -1', -1, 'Obj', new Obj(-1, null, null)); test('medium: 1000', 1000, 'Obj', new Obj(1000, null, null)); test('medium: -1000', -1000, 'Obj', new Obj(-1000, null, null)); test('large: 100000', 100000, 'Obj', new Obj(100000, null, null)); test('large: -100000', -100000, 'Obj', new Obj(-100000, null, null)); test('double: 123.456', 123.456, 'Obj', new Obj(123.456, null, null)); test('empty: ""', "", 'Obj', new Obj("", null, null)); test('string: "foobar"', "foobar", 'Obj', new Obj("foobar", null, null)); test('array: empty', array(), 'Obj', new Obj(null, null, null)); test('array(1, 2, 3)', array(1, 2, 3), 'Obj', new Obj(1, 2, 3)); test('array(array(1, 2, 3), arr...', array(array(1, 2, 3), array(4, 5, 6), array(7, 8, 9)), 'Obj', new Obj(array(1, 2, 3), array(4, 5, 6), array(7, 8, 9))); test('array(1, 2, 3, 4)', array(1, 2, 3, 4), 'Obj'); test('array("foo", "foobar", "foohoge")', array("foo", "foobar", "hoge"), 'Obj', new Obj("foo", "foobar", "hoge")); test('array("a" => 1, "b" => 2))', array("a" => 1, "b" => 2), 'Obj', new Obj(1, 2, null)); test('array("one" => 1, "two" => 2))', array("one" => 1, "two" => 2), 'Obj', new Obj(null, null, null, array("one" => 1, "two" => 2))); test('array("" => "empty")', array("" => "empty"), 'Obj'); test('array("a" => 1, "b" => 2, 3))', array("a" => 1, "b" => 2, 3), 'Obj', new Obj(1, 2, 3)); test('array(3, "a" => 1, "b" => 2))', array(3, "a" => 1, "b" => 2), 'Obj', new Obj(1, 2, 3)); test('array("a" => 1, 3, "b" => 2))', array("a" => 1, 3, "b" => 2), 'Obj', new Obj(1, 2, 3)); $a = array('foo'); test('array($a, $a)', array($a, $a), 'Obj', new Obj($a, $a, null)); $a = array( 'a' => array( 'b' => 'c', 'd' => 'e' ), 'f' => array( 'g' => 'h' ) ); test('array', $a, 'Obj', new Obj(null, null, null, $a)); $o = new Obj(1, 2, 3); test('object', $o, 'Obj', new Obj(1, 2, 3)); class Obj2 { public $A; protected $B; private $C; function __construct($a, $b, $c) { $this->A = $a; $this->B = $b; $this->C = $c; } } $o = new Obj2(1, 2, 3); test('object', $o, 'Obj', new Obj(1, 2, 3)); $o1 = new Obj2(1, 2, 3); $o2 = new Obj2(4, 5, 6); test('object', array($o1, $o2), 'Obj', new Obj(array(1, 2, 3), array(4, 5, 6))); --EXPECTF-- object(Obj)#%d (3) { ["a"]=> NULL [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> bool(true) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> bool(false) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(0) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(-1) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(1000) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(-1000) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(100000) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(-100000) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> float(123.456) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> string(0) "" [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> string(6) "foobar" [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> NULL [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } [%r"?b"?:protected"?%r]=> array(3) { [0]=> int(4) [1]=> int(5) [2]=> int(6) } [%r"?c"?:("Obj":)?private"?%r]=> array(3) { [0]=> int(7) [1]=> int(8) [2]=> int(9) } } OK object(Obj)#%d (4) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) [3]=> int(4) } SKIP object(Obj)#%d (3) { ["a"]=> string(3) "foo" [%r"?b"?:protected"?%r]=> string(6) "foobar" [%r"?c"?:("Obj":)?private"?%r]=> string(4) "hoge" } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (5) { ["a"]=> NULL [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL ["one"]=> int(1) ["two"]=> int(2) } OK object(Obj)#%d (4) { ["a"]=> NULL [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL [""]=> string(5) "empty" } SKIP object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> array(1) { [0]=> string(3) "foo" } [%r"?b"?:protected"?%r]=> array(1) { [0]=> string(3) "foo" } [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (4) { ["a"]=> array(2) { ["b"]=> string(1) "c" ["d"]=> string(1) "e" } [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL ["f"]=> array(1) { ["g"]=> string(1) "h" } } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } [%r"?b"?:protected"?%r]=> array(3) { [0]=> int(4) [1]=> int(5) [2]=> int(6) } [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK msgpack-0.5.5/tests/092b.phpt0000644000077100007710000001552312110565607015550 0ustar xinchenxinchen--TEST-- unpack of object converter (string: php_only=0) --SKIPIF-- = 0) { echo "skip tests in PHP 5.1 or older"; } --FILE-- a = $a; $this->b = $b; $this->c = $c; if (is_array($d)) { foreach ($d as $key => $val) { $this->{$key} = $val; } } } } test('null', null, 'Obj', new Obj(null, null, null)); test('bool: true', true, 'Obj', new Obj(true, null, null)); test('bool: false', false, 'Obj', new Obj(false, null, null)); test('zero: 0', 0, 'Obj', new Obj(0, null, null)); test('small: 1', 1, 'Obj', new Obj(1, null, null)); test('small: -1', -1, 'Obj', new Obj(-1, null, null)); test('medium: 1000', 1000, 'Obj', new Obj(1000, null, null)); test('medium: -1000', -1000, 'Obj', new Obj(-1000, null, null)); test('large: 100000', 100000, 'Obj', new Obj(100000, null, null)); test('large: -100000', -100000, 'Obj', new Obj(-100000, null, null)); test('double: 123.456', 123.456, 'Obj', new Obj(123.456, null, null)); test('empty: ""', "", 'Obj', new Obj("", null, null)); test('string: "foobar"', "foobar", 'Obj', new Obj("foobar", null, null)); test('array: empty', array(), 'Obj', new Obj(null, null, null)); test('array(1, 2, 3)', array(1, 2, 3), 'Obj', new Obj(1, 2, 3)); test('array(array(1, 2, 3), arr...', array(array(1, 2, 3), array(4, 5, 6), array(7, 8, 9)), 'Obj', new Obj(array(1, 2, 3), array(4, 5, 6), array(7, 8, 9))); test('array(1, 2, 3, 4)', array(1, 2, 3, 4), 'Obj'); test('array("foo", "foobar", "foohoge")', array("foo", "foobar", "hoge"), 'Obj', new Obj("foo", "foobar", "hoge")); test('array("a" => 1, "b" => 2))', array("a" => 1, "b" => 2), 'Obj', new Obj(1, 2, null)); test('array("one" => 1, "two" => 2))', array("one" => 1, "two" => 2), 'Obj', new Obj(null, null, null, array("one" => 1, "two" => 2))); test('array("a" => 1, "b" => 2, 3))', array("a" => 1, "b" => 2, 3), 'Obj', new Obj(1, 2, 3)); test('array(3, "a" => 1, "b" => 2))', array(3, "a" => 1, "b" => 2), 'Obj', new Obj(1, 2, 3)); test('array("a" => 1, 3, "b" => 2))', array("a" => 1, 3, "b" => 2), 'Obj', new Obj(1, 2, 3)); $a = array('foo'); test('array($a, $a)', array($a, $a), 'Obj', new Obj($a, $a, null)); $a = array( 'a' => array( 'b' => 'c', 'd' => 'e' ), 'f' => array( 'g' => 'h' ) ); test('array', $a, 'Obj', new Obj(null, null, null, $a)); $o = new Obj(1, 2, 3); test('object', $o, 'Obj', new Obj(1, 2, 3)); class Obj2 { public $A; protected $B; private $C; function __construct($a, $b, $c) { $this->A = $a; $this->B = $b; $this->C = $c; } } $o = new Obj2(1, 2, 3); test('object', $o, 'Obj', new Obj(1, 2, 3)); $o1 = new Obj2(1, 2, 3); $o2 = new Obj2(4, 5, 6); test('object', array($o1, $o2), 'Obj', new Obj(array(1, 2, 3), array(4, 5, 6))); --EXPECTF-- object(Obj)#%d (3) { ["a"]=> NULL ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> bool(true) ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> bool(false) ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(0) ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(1) ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(-1) ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(1000) ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(-1000) ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(100000) ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(-100000) ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> float(123.456) ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> string(0) "" ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> string(6) "foobar" ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> NULL ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(1) ["b:protected"]=> int(2) ["c:private"]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } ["b:protected"]=> array(3) { [0]=> int(4) [1]=> int(5) [2]=> int(6) } ["c:private"]=> array(3) { [0]=> int(7) [1]=> int(8) [2]=> int(9) } } OK object(Obj)#%d (4) { ["a"]=> int(1) ["b:protected"]=> int(2) ["c:private"]=> int(3) [3]=> int(4) } SKIP object(Obj)#%d (3) { ["a"]=> string(3) "foo" ["b:protected"]=> string(6) "foobar" ["c:private"]=> string(4) "hoge" } OK object(Obj)#%d (3) { ["a"]=> int(1) ["b:protected"]=> int(2) ["c:private"]=> NULL } OK object(Obj)#%d (5) { ["a"]=> NULL ["b:protected"]=> NULL ["c:private"]=> NULL ["one"]=> int(1) ["two"]=> int(2) } OK object(Obj)#%d (3) { ["a"]=> int(1) ["b:protected"]=> int(2) ["c:private"]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> int(1) ["b:protected"]=> int(2) ["c:private"]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> int(1) ["b:protected"]=> int(2) ["c:private"]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> array(1) { [0]=> string(3) "foo" } ["b:protected"]=> array(1) { [0]=> string(3) "foo" } ["c:private"]=> NULL } OK object(Obj)#%d (4) { ["a"]=> array(2) { ["b"]=> string(1) "c" ["d"]=> string(1) "e" } ["b:protected"]=> NULL ["c:private"]=> NULL ["f"]=> array(1) { ["g"]=> string(1) "h" } } OK object(Obj)#%d (3) { ["a"]=> int(1) ["b:protected"]=> int(2) ["c:private"]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> int(1) ["b:protected"]=> int(2) ["c:private"]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } ["b:protected"]=> array(3) { [0]=> int(4) [1]=> int(5) [2]=> int(6) } ["c:private"]=> NULL } OK msgpack-0.5.5/tests/093.phpt0000644000077100007710000001755212110565607015413 0ustar xinchenxinchen--TEST-- unpack of object converter (object: php_only=0) --SKIPIF-- a = $a; $this->b = $b; $this->c = $c; if (is_array($d)) { foreach ($d as $key => $val) { $this->{$key} = $val; } } } } $object = new Obj(); test('null', null, new Obj(), new Obj(null, null, null)); test('bool: true', true, new Obj(), new Obj(true, null, null)); test('bool: false', false, new Obj(), new Obj(false, null, null)); test('zero: 0', 0, new Obj(), new Obj(0, null, null)); test('small: 1', 1, new Obj(), new Obj(1, null, null)); test('small: -1', -1, new Obj(), new Obj(-1, null, null)); test('medium: 1000', 1000, new Obj(), new Obj(1000, null, null)); test('medium: -1000', -1000, new Obj(), new Obj(-1000, null, null)); test('large: 100000', 100000, new Obj(), new Obj(100000, null, null)); test('large: -100000', -100000, new Obj(), new Obj(-100000, null, null)); test('double: 123.456', 123.456, new Obj(), new Obj(123.456, null, null)); test('empty: ""', "", new Obj(), new Obj("", null, null)); test('string: "foobar"', "foobar", new Obj(), new Obj("foobar", null, null)); test('array: empty', array(), new Obj(), new Obj(null, null, null)); test('array(1, 2, 3)', array(1, 2, 3), new Obj(), new Obj(1, 2, 3)); test('array(array(1, 2, 3), arr...', array(array(1, 2, 3), array(4, 5, 6), array(7, 8, 9)), new Obj(), new Obj(array(1, 2, 3), array(4, 5, 6), array(7, 8, 9))); test('array(1, 2, 3, 4)', array(1, 2, 3, 4), new Obj()); test('array("foo", "foobar", "foohoge")', array("foo", "foobar", "hoge"), new Obj(), new Obj("foo", "foobar", "hoge")); test('array("a" => 1, "b" => 2))', array("a" => 1, "b" => 2), new Obj(), new Obj(1, 2, null)); test('array("one" => 1, "two" => 2))', array("one" => 1, "two" => 2), new Obj(), new Obj(null, null, null, array("one" => 1, "two" => 2))); test('array("" => "empty")', array("" => "empty"), new Obj()); test('array("a" => 1, "b" => 2, 3))', array("a" => 1, "b" => 2, 3), new Obj(), new Obj(1, 2, 3)); test('array(3, "a" => 1, "b" => 2))', array(3, "a" => 1, "b" => 2), new Obj(), new Obj(1, 2, 3)); test('array("a" => 1, 3, "b" => 2))', array("a" => 1, 3, "b" => 2), new Obj(), new Obj(1, 2, 3)); $a = array('foo'); test('array($a, $a)', array($a, $a), new Obj(), new Obj($a, $a, null)); $a = array( 'a' => array( 'b' => 'c', 'd' => 'e' ), 'f' => array( 'g' => 'h' ) ); test('array', $a, new Obj(), new Obj(null, null, null, $a)); $o = new Obj(1, 2, 3); test('object', $o, new Obj(), new Obj(1, 2, 3)); class Obj2 { public $A; protected $B; private $C; function __construct($a, $b, $c) { $this->A = $a; $this->B = $b; $this->C = $c; } } $o = new Obj2(1, 2, 3); test('object', $o, new Obj(), new Obj(1, 2, 3)); $o1 = new Obj2(1, 2, 3); $o2 = new Obj2(4, 5, 6); test('object', array($o1, $o2), new Obj(), new Obj(array(1, 2, 3), array(4, 5, 6))); --EXPECTF-- object(Obj)#%d (3) { ["a"]=> NULL [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> bool(true) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> bool(false) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(0) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(-1) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(1000) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(-1000) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(100000) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(-100000) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> float(123.456) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> string(0) "" [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> string(6) "foobar" [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> NULL [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } [%r"?b"?:protected"?%r]=> array(3) { [0]=> int(4) [1]=> int(5) [2]=> int(6) } [%r"?c"?:("Obj":)?private"?%r]=> array(3) { [0]=> int(7) [1]=> int(8) [2]=> int(9) } } OK object(Obj)#%d (4) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) [3]=> int(4) } SKIP object(Obj)#%d (3) { ["a"]=> string(3) "foo" [%r"?b"?:protected"?%r]=> string(6) "foobar" [%r"?c"?:("Obj":)?private"?%r]=> string(4) "hoge" } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (5) { ["a"]=> NULL [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL ["one"]=> int(1) ["two"]=> int(2) } OK object(Obj)#%d (4) { ["a"]=> NULL [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL [""]=> string(5) "empty" } SKIP object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> array(1) { [0]=> string(3) "foo" } [%r"?b"?:protected"?%r]=> array(1) { [0]=> string(3) "foo" } [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (4) { ["a"]=> array(2) { ["b"]=> string(1) "c" ["d"]=> string(1) "e" } [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL ["f"]=> array(1) { ["g"]=> string(1) "h" } } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } [%r"?b"?:protected"?%r]=> array(3) { [0]=> int(4) [1]=> int(5) [2]=> int(6) } [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK msgpack-0.5.5/tests/093b.phpt0000644000077100007710000001570312110565607015551 0ustar xinchenxinchen--TEST-- unpack of object converter (object: php_only=0) --SKIPIF-- = 0) { echo "skip tests in PHP 5.1 or older"; } --FILE-- a = $a; $this->b = $b; $this->c = $c; if (is_array($d)) { foreach ($d as $key => $val) { $this->{$key} = $val; } } } } test('null', null, new Obj(), new Obj(null, null, null)); test('bool: true', true, new Obj(), new Obj(true, null, null)); test('bool: false', false, new Obj(), new Obj(false, null, null)); test('zero: 0', 0, new Obj(), new Obj(0, null, null)); test('small: 1', 1, new Obj(), new Obj(1, null, null)); test('small: -1', -1, new Obj(), new Obj(-1, null, null)); test('medium: 1000', 1000, new Obj(), new Obj(1000, null, null)); test('medium: -1000', -1000, new Obj(), new Obj(-1000, null, null)); test('large: 100000', 100000, new Obj(), new Obj(100000, null, null)); test('large: -100000', -100000, new Obj(), new Obj(-100000, null, null)); test('double: 123.456', 123.456, new Obj(), new Obj(123.456, null, null)); test('empty: ""', "", new Obj(), new Obj("", null, null)); test('string: "foobar"', "foobar", new Obj(), new Obj("foobar", null, null)); test('array: empty', array(), new Obj(), new Obj(null, null, null)); test('array(1, 2, 3)', array(1, 2, 3), new Obj(), new Obj(1, 2, 3)); test('array(array(1, 2, 3), arr...', array(array(1, 2, 3), array(4, 5, 6), array(7, 8, 9)), new Obj(), new Obj(array(1, 2, 3), array(4, 5, 6), array(7, 8, 9))); test('array(1, 2, 3, 4)', array(1, 2, 3, 4), new Obj()); test('array("foo", "foobar", "foohoge")', array("foo", "foobar", "hoge"), new Obj(), new Obj("foo", "foobar", "hoge")); test('array("a" => 1, "b" => 2))', array("a" => 1, "b" => 2), new Obj(), new Obj(1, 2, null)); test('array("one" => 1, "two" => 2))', array("one" => 1, "two" => 2), new Obj(), new Obj(null, null, null, array("one" => 1, "two" => 2))); test('array("a" => 1, "b" => 2, 3))', array("a" => 1, "b" => 2, 3), new Obj(), new Obj(1, 2, 3)); test('array(3, "a" => 1, "b" => 2))', array(3, "a" => 1, "b" => 2), new Obj(), new Obj(1, 2, 3)); test('array("a" => 1, 3, "b" => 2))', array("a" => 1, 3, "b" => 2), new Obj(), new Obj(1, 2, 3)); $a = array('foo'); test('array($a, $a)', array($a, $a), new Obj(), new Obj($a, $a, null)); $a = array( 'a' => array( 'b' => 'c', 'd' => 'e' ), 'f' => array( 'g' => 'h' ) ); test('array', $a, new Obj(), new Obj(null, null, null, $a)); $o = new Obj(1, 2, 3); test('object', $o, new Obj(), new Obj(1, 2, 3)); class Obj2 { public $A; protected $B; private $C; function __construct($a, $b, $c) { $this->A = $a; $this->B = $b; $this->C = $c; } } $o = new Obj2(1, 2, 3); test('object', $o, new Obj(), new Obj(1, 2, 3)); $o1 = new Obj2(1, 2, 3); $o2 = new Obj2(4, 5, 6); test('object', array($o1, $o2), new Obj(), new Obj(array(1, 2, 3), array(4, 5, 6))); --EXPECTF-- object(Obj)#%d (3) { ["a"]=> NULL ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> bool(true) ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> bool(false) ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(0) ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(1) ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(-1) ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(1000) ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(-1000) ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(100000) ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(-100000) ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> float(123.456) ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> string(0) "" ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> string(6) "foobar" ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> NULL ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(1) ["b:protected"]=> int(2) ["c:private"]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } ["b:protected"]=> array(3) { [0]=> int(4) [1]=> int(5) [2]=> int(6) } ["c:private"]=> array(3) { [0]=> int(7) [1]=> int(8) [2]=> int(9) } } OK object(Obj)#%d (4) { ["a"]=> int(1) ["b:protected"]=> int(2) ["c:private"]=> int(3) [3]=> int(4) } SKIP object(Obj)#%d (3) { ["a"]=> string(3) "foo" ["b:protected"]=> string(6) "foobar" ["c:private"]=> string(4) "hoge" } OK object(Obj)#%d (3) { ["a"]=> int(1) ["b:protected"]=> int(2) ["c:private"]=> NULL } OK object(Obj)#%d (5) { ["a"]=> NULL ["b:protected"]=> NULL ["c:private"]=> NULL ["one"]=> int(1) ["two"]=> int(2) } OK object(Obj)#%d (3) { ["a"]=> int(1) ["b:protected"]=> int(2) ["c:private"]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> int(1) ["b:protected"]=> int(2) ["c:private"]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> int(1) ["b:protected"]=> int(2) ["c:private"]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> array(1) { [0]=> string(3) "foo" } ["b:protected"]=> array(1) { [0]=> string(3) "foo" } ["c:private"]=> NULL } OK object(Obj)#%d (4) { ["a"]=> array(2) { ["b"]=> string(1) "c" ["d"]=> string(1) "e" } ["b:protected"]=> NULL ["c:private"]=> NULL ["f"]=> array(1) { ["g"]=> string(1) "h" } } OK object(Obj)#%d (3) { ["a"]=> int(1) ["b:protected"]=> int(2) ["c:private"]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> int(1) ["b:protected"]=> int(2) ["c:private"]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } ["b:protected"]=> array(3) { [0]=> int(4) [1]=> int(5) [2]=> int(6) } ["c:private"]=> NULL } OK msgpack-0.5.5/tests/094.phpt0000644000077100007710000002417712110565607015415 0ustar xinchenxinchen--TEST-- unpack of object converter : class unpack (string) --SKIPIF-- pack($variable); $unserialized = $msgpack->unpack($serialized, $object); var_dump($unserialized); if ($result) { echo $unserialized == $result ? 'OK' : 'ERROR', PHP_EOL; } else { echo 'SKIP', PHP_EOL; } } class Obj { public $a; protected $b; private $c; public function __construct($a = null, $b = null, $c = null, $d = null) { $this->a = $a; $this->b = $b; $this->c = $c; if (is_array($d)) { foreach ($d as $key => $val) { $this->{$key} = $val; } } } } test('null', null, 'Obj', new Obj(null, null, null)); test('bool: true', true, 'Obj', new Obj(true, null, null)); test('bool: false', false, 'Obj', new Obj(false, null, null)); test('zero: 0', 0, 'Obj', new Obj(0, null, null)); test('small: 1', 1, 'Obj', new Obj(1, null, null)); test('small: -1', -1, 'Obj', new Obj(-1, null, null)); test('medium: 1000', 1000, 'Obj', new Obj(1000, null, null)); test('medium: -1000', -1000, 'Obj', new Obj(-1000, null, null)); test('large: 100000', 100000, 'Obj', new Obj(100000, null, null)); test('large: -100000', -100000, 'Obj', new Obj(-100000, null, null)); test('double: 123.456', 123.456, 'Obj', new Obj(123.456, null, null)); test('empty: ""', "", 'Obj', new Obj("", null, null)); test('string: "foobar"', "foobar", 'Obj', new Obj("foobar", null, null)); test('array: empty', array(), 'Obj', new Obj(null, null, null)); test('array(1, 2, 3)', array(1, 2, 3), 'Obj', new Obj(1, 2, 3)); test('array(array(1, 2, 3), arr...', array(array(1, 2, 3), array(4, 5, 6), array(7, 8, 9)), 'Obj', new Obj(array(1, 2, 3), array(4, 5, 6), array(7, 8, 9))); test('array(1, 2, 3, 4)', array(1, 2, 3, 4), 'Obj'); test('array("foo", "foobar", "foohoge")', array("foo", "foobar", "hoge"), 'Obj', new Obj("foo", "foobar", "hoge")); test('array("a" => 1, "b" => 2))', array("a" => 1, "b" => 2), 'Obj', new Obj(1, 2, null)); test('array("one" => 1, "two" => 2))', array("one" => 1, "two" => 2), 'Obj', new Obj(null, null, null, array("one" => 1, "two" => 2))); test('array("" => "empty")', array("" => "empty"), 'Obj'); test('array("a" => 1, "b" => 2, 3))', array("a" => 1, "b" => 2, 3), 'Obj', new Obj(1, 2, 3)); test('array(3, "a" => 1, "b" => 2))', array(3, "a" => 1, "b" => 2), 'Obj', new Obj(1, 2, 3)); test('array("a" => 1, 3, "b" => 2))', array("a" => 1, 3, "b" => 2), 'Obj', new Obj(1, 2, 3)); $a = array('foo'); test('array($a, $a)', array($a, $a), 'Obj', new Obj($a, $a, null)); test('array(&$a, &$a)', array(&$a, &$a), 'Obj', new Obj($a, $a, null)); test('array(&$a, $a)', array($a, &$a), 'Obj', new Obj($a, $a, null)); test('array(&$a, $a)', array(&$a, $a), 'Obj', new Obj($a, $a, null)); $a = array( 'a' => array( 'b' => 'c', 'd' => 'e' ), 'f' => array( 'g' => 'h' ) ); test('array', $a, 'Obj', new Obj(null, null, null, $a)); $o = new Obj(1, 2, 3); test('object', $o, 'Obj', new Obj(1, 2, 3)); class Obj2 { public $A; protected $B; private $C; function __construct($a, $b, $c) { $this->A = $a; $this->B = $b; $this->C = $c; } } $o = new Obj2(1, 2, 3); test('object', $o, 'Obj', new Obj($o)); $o1 = new Obj2(1, 2, 3); $o2 = new Obj2(4, 5, 6); test('object', array($o1, $o2), 'Obj', new Obj($o1, $o2)); $o = new Obj2(1, 2, 3); test('object', array(&$o, &$o), 'Obj', new Obj($o, $o)); $o = new Obj2(1, 2, 3); test('object', array(&$o, $o), 'Obj', new Obj($o, $o)); $o = new Obj2(1, 2, 3); test('object', array($o, &$o), 'Obj', new Obj($o, $o)); --EXPECTF-- object(Obj)#%d (3) { ["a"]=> NULL [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> bool(true) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> bool(false) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(0) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(-1) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(1000) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(-1000) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(100000) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(-100000) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> float(123.456) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> string(0) "" [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> string(6) "foobar" [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> NULL [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } [%r"?b"?:protected"?%r]=> array(3) { [0]=> int(4) [1]=> int(5) [2]=> int(6) } [%r"?c"?:("Obj":)?private"?%r]=> array(3) { [0]=> int(7) [1]=> int(8) [2]=> int(9) } } OK object(Obj)#%d (4) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) [3]=> int(4) } SKIP object(Obj)#%d (3) { ["a"]=> string(3) "foo" [%r"?b"?:protected"?%r]=> string(6) "foobar" [%r"?c"?:("Obj":)?private"?%r]=> string(4) "hoge" } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (5) { ["a"]=> NULL [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL ["one"]=> int(1) ["two"]=> int(2) } OK object(Obj)#%d (4) { ["a"]=> NULL [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL [""]=> string(5) "empty" } SKIP object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> array(1) { [0]=> string(3) "foo" } [%r"?b"?:protected"?%r]=> array(1) { [0]=> string(3) "foo" } [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> &array(1) { [0]=> string(3) "foo" } [%r"?b"?:protected"?%r]=> &array(1) { [0]=> string(3) "foo" } [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> array(1) { [0]=> string(3) "foo" } [%r"?b"?:protected"?%r]=> &array(1) { [0]=> string(3) "foo" } [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> &array(1) { [0]=> string(3) "foo" } [%r"?b"?:protected"?%r]=> array(1) { [0]=> string(3) "foo" } [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (4) { ["a"]=> array(2) { ["b"]=> string(1) "c" ["d"]=> string(1) "e" } [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL ["f"]=> array(1) { ["g"]=> string(1) "h" } } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> object(Obj2)#%d (3) { ["A"]=> int(1) [%r"?B"?:protected"?%r]=> int(2) [%r"?C"?:("Obj2":)?private"?%r]=> int(3) } [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> object(Obj2)#%d (3) { ["A"]=> int(1) [%r"?B"?:protected"?%r]=> int(2) [%r"?C"?:("Obj2":)?private"?%r]=> int(3) } [%r"?b"?:protected"?%r]=> object(Obj2)#%d (3) { ["A"]=> int(4) [%r"?B"?:protected"?%r]=> int(5) [%r"?C"?:("Obj2":)?private"?%r]=> int(6) } [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> &object(Obj2)#%d (3) { ["A"]=> int(1) [%r"?B"?:protected"?%r]=> int(2) [%r"?C"?:("Obj2":)?private"?%r]=> int(3) } [%r"?b"?:protected"?%r]=> &object(Obj2)#%d (3) { ["A"]=> int(1) [%r"?B"?:protected"?%r]=> int(2) [%r"?C"?:("Obj2":)?private"?%r]=> int(3) } [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> object(Obj2)#%d (3) { ["A"]=> int(1) [%r"?B"?:protected"?%r]=> int(2) [%r"?C"?:("Obj2":)?private"?%r]=> int(3) } [%r"?b"?:protected"?%r]=> object(Obj2)#%d (3) { ["A"]=> int(1) [%r"?B"?:protected"?%r]=> int(2) [%r"?C"?:("Obj2":)?private"?%r]=> int(3) } [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> &object(Obj2)#%d (3) { ["A"]=> int(1) [%r"?B"?:protected"?%r]=> int(2) [%r"?C"?:("Obj2":)?private"?%r]=> int(3) } [%r"?b"?:protected"?%r]=> &object(Obj2)#%d (3) { ["A"]=> int(1) [%r"?B"?:protected"?%r]=> int(2) [%r"?C"?:("Obj2":)?private"?%r]=> int(3) } [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK msgpack-0.5.5/tests/094b.phpt0000644000077100007710000002156212110565607015552 0ustar xinchenxinchen--TEST-- unpack of object converter : class unpack (string) --SKIPIF-- = 0) { echo "skip tests in PHP 5.1 or older"; } --FILE-- pack($variable); $unserialized = $msgpack->unpack($serialized, $object); var_dump($unserialized); if ($result) { echo $unserialized == $result ? 'OK' : 'ERROR', PHP_EOL; } else { echo 'SKIP', PHP_EOL; } } class Obj { public $a; protected $b; private $c; public function __construct($a = null, $b = null, $c = null, $d = null) { $this->a = $a; $this->b = $b; $this->c = $c; if (is_array($d)) { foreach ($d as $key => $val) { $this->{$key} = $val; } } } } test('null', null, 'Obj', new Obj(null, null, null)); test('bool: true', true, 'Obj', new Obj(true, null, null)); test('bool: false', false, 'Obj', new Obj(false, null, null)); test('zero: 0', 0, 'Obj', new Obj(0, null, null)); test('small: 1', 1, 'Obj', new Obj(1, null, null)); test('small: -1', -1, 'Obj', new Obj(-1, null, null)); test('medium: 1000', 1000, 'Obj', new Obj(1000, null, null)); test('medium: -1000', -1000, 'Obj', new Obj(-1000, null, null)); test('large: 100000', 100000, 'Obj', new Obj(100000, null, null)); test('large: -100000', -100000, 'Obj', new Obj(-100000, null, null)); test('double: 123.456', 123.456, 'Obj', new Obj(123.456, null, null)); test('empty: ""', "", 'Obj', new Obj("", null, null)); test('string: "foobar"', "foobar", 'Obj', new Obj("foobar", null, null)); test('array: empty', array(), 'Obj', new Obj(null, null, null)); test('array(1, 2, 3)', array(1, 2, 3), 'Obj', new Obj(1, 2, 3)); test('array(array(1, 2, 3), arr...', array(array(1, 2, 3), array(4, 5, 6), array(7, 8, 9)), 'Obj', new Obj(array(1, 2, 3), array(4, 5, 6), array(7, 8, 9))); test('array(1, 2, 3, 4)', array(1, 2, 3, 4), 'Obj'); test('array("foo", "foobar", "foohoge")', array("foo", "foobar", "hoge"), 'Obj', new Obj("foo", "foobar", "hoge")); test('array("a" => 1, "b" => 2))', array("a" => 1, "b" => 2), 'Obj', new Obj(1, 2, null)); test('array("one" => 1, "two" => 2))', array("one" => 1, "two" => 2), 'Obj', new Obj(null, null, null, array("one" => 1, "two" => 2))); test('array("a" => 1, "b" => 2, 3))', array("a" => 1, "b" => 2, 3), 'Obj', new Obj(1, 2, 3)); test('array(3, "a" => 1, "b" => 2))', array(3, "a" => 1, "b" => 2), 'Obj', new Obj(1, 2, 3)); test('array("a" => 1, 3, "b" => 2))', array("a" => 1, 3, "b" => 2), 'Obj', new Obj(1, 2, 3)); $a = array('foo'); test('array($a, $a)', array($a, $a), 'Obj', new Obj($a, $a, null)); test('array(&$a, &$a)', array(&$a, &$a), 'Obj', new Obj($a, $a, null)); test('array(&$a, $a)', array($a, &$a), 'Obj', new Obj($a, $a, null)); test('array(&$a, $a)', array(&$a, $a), 'Obj', new Obj($a, $a, null)); $a = array( 'a' => array( 'b' => 'c', 'd' => 'e' ), 'f' => array( 'g' => 'h' ) ); test('array', $a, 'Obj', new Obj(null, null, null, $a)); $o = new Obj(1, 2, 3); test('object', $o, 'Obj', new Obj(1, 2, 3)); class Obj2 { public $A; protected $B; private $C; function __construct($a, $b, $c) { $this->A = $a; $this->B = $b; $this->C = $c; } } $o = new Obj2(1, 2, 3); test('object', $o, 'Obj', new Obj($o)); $o1 = new Obj2(1, 2, 3); $o2 = new Obj2(4, 5, 6); test('object', array($o1, $o2), 'Obj', new Obj($o1, $o2)); $o = new Obj2(1, 2, 3); test('object', array(&$o, &$o), 'Obj', new Obj($o, $o)); $o = new Obj2(1, 2, 3); test('object', array(&$o, $o), 'Obj', new Obj($o, $o)); $o = new Obj2(1, 2, 3); test('object', array($o, &$o), 'Obj', new Obj($o, $o)); --EXPECTF-- object(Obj)#%d (3) { ["a"]=> NULL ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> bool(true) ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> bool(false) ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(0) ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(1) ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(-1) ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(1000) ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(-1000) ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(100000) ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(-100000) ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> float(123.456) ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> string(0) "" ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> string(6) "foobar" ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> NULL ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(1) ["b:protected"]=> int(2) ["c:private"]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } ["b:protected"]=> array(3) { [0]=> int(4) [1]=> int(5) [2]=> int(6) } ["c:private"]=> array(3) { [0]=> int(7) [1]=> int(8) [2]=> int(9) } } OK object(Obj)#%d (4) { ["a"]=> int(1) ["b:protected"]=> int(2) ["c:private"]=> int(3) [3]=> int(4) } SKIP object(Obj)#%d (3) { ["a"]=> string(3) "foo" ["b:protected"]=> string(6) "foobar" ["c:private"]=> string(4) "hoge" } OK object(Obj)#%d (3) { ["a"]=> int(1) ["b:protected"]=> int(2) ["c:private"]=> NULL } OK object(Obj)#%d (5) { ["a"]=> NULL ["b:protected"]=> NULL ["c:private"]=> NULL ["one"]=> int(1) ["two"]=> int(2) } OK object(Obj)#%d (3) { ["a"]=> int(1) ["b:protected"]=> int(2) ["c:private"]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> int(1) ["b:protected"]=> int(2) ["c:private"]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> int(1) ["b:protected"]=> int(2) ["c:private"]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> array(1) { [0]=> string(3) "foo" } ["b:protected"]=> array(1) { [0]=> string(3) "foo" } ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> &array(1) { [0]=> string(3) "foo" } ["b:protected"]=> &array(1) { [0]=> string(3) "foo" } ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> array(1) { [0]=> string(3) "foo" } ["b:protected"]=> &array(1) { [0]=> string(3) "foo" } ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> &array(1) { [0]=> string(3) "foo" } ["b:protected"]=> array(1) { [0]=> string(3) "foo" } ["c:private"]=> NULL } OK object(Obj)#%d (4) { ["a"]=> array(2) { ["b"]=> string(1) "c" ["d"]=> string(1) "e" } ["b:protected"]=> NULL ["c:private"]=> NULL ["f"]=> array(1) { ["g"]=> string(1) "h" } } OK object(Obj)#%d (3) { ["a"]=> int(1) ["b:protected"]=> int(2) ["c:private"]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> object(Obj2)#%d (3) { ["A"]=> int(1) ["B:protected"]=> int(2) ["C:private"]=> int(3) } ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> object(Obj2)#%d (3) { ["A"]=> int(1) ["B:protected"]=> int(2) ["C:private"]=> int(3) } ["b:protected"]=> object(Obj2)#%d (3) { ["A"]=> int(4) ["B:protected"]=> int(5) ["C:private"]=> int(6) } ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> &object(Obj2)#%d (3) { ["A"]=> int(1) ["B:protected"]=> int(2) ["C:private"]=> int(3) } ["b:protected"]=> &object(Obj2)#%d (3) { ["A"]=> int(1) ["B:protected"]=> int(2) ["C:private"]=> int(3) } ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> object(Obj2)#%d (3) { ["A"]=> int(1) ["B:protected"]=> int(2) ["C:private"]=> int(3) } ["b:protected"]=> object(Obj2)#%d (3) { ["A"]=> int(1) ["B:protected"]=> int(2) ["C:private"]=> int(3) } ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> &object(Obj2)#%d (3) { ["A"]=> int(1) ["B:protected"]=> int(2) ["C:private"]=> int(3) } ["b:protected"]=> &object(Obj2)#%d (3) { ["A"]=> int(1) ["B:protected"]=> int(2) ["C:private"]=> int(3) } ["c:private"]=> NULL } OK msgpack-0.5.5/tests/095.phpt0000644000077100007710000002444112110565607015410 0ustar xinchenxinchen--TEST-- unpack of object converter : class unpack (object) --SKIPIF-- pack($variable); $unserialized = $msgpack->unpack($serialized, $object); var_dump($unserialized); if ($result) { echo $unserialized == $result ? 'OK' : 'ERROR', PHP_EOL; } else { echo 'SKIP', PHP_EOL; } } class Obj { public $a; protected $b; private $c; public function __construct($a = null, $b = null, $c = null, $d = null) { $this->a = $a; $this->b = $b; $this->c = $c; if (is_array($d)) { foreach ($d as $key => $val) { $this->{$key} = $val; } } } } $object = new Obj(); test('null', null, new Obj(), new Obj(null, null, null)); test('bool: true', true, new Obj(), new Obj(true, null, null)); test('bool: false', false, new Obj(), new Obj(false, null, null)); test('zero: 0', 0, new Obj(), new Obj(0, null, null)); test('small: 1', 1, new Obj(), new Obj(1, null, null)); test('small: -1', -1, new Obj(), new Obj(-1, null, null)); test('medium: 1000', 1000, new Obj(), new Obj(1000, null, null)); test('medium: -1000', -1000, new Obj(), new Obj(-1000, null, null)); test('large: 100000', 100000, new Obj(), new Obj(100000, null, null)); test('large: -100000', -100000, new Obj(), new Obj(-100000, null, null)); test('double: 123.456', 123.456, new Obj(), new Obj(123.456, null, null)); test('empty: ""', "", new Obj(), new Obj("", null, null)); test('string: "foobar"', "foobar", new Obj(), new Obj("foobar", null, null)); test('array: empty', array(), new Obj(), new Obj(null, null, null)); test('array(1, 2, 3)', array(1, 2, 3), new Obj(), new Obj(1, 2, 3)); test('array(array(1, 2, 3), arr...', array(array(1, 2, 3), array(4, 5, 6), array(7, 8, 9)), new Obj(), new Obj(array(1, 2, 3), array(4, 5, 6), array(7, 8, 9))); test('array(1, 2, 3, 4)', array(1, 2, 3, 4), new Obj()); test('array("foo", "foobar", "foohoge")', array("foo", "foobar", "hoge"), new Obj(), new Obj("foo", "foobar", "hoge")); test('array("a" => 1, "b" => 2))', array("a" => 1, "b" => 2), new Obj(), new Obj(1, 2, null)); test('array("one" => 1, "two" => 2))', array("one" => 1, "two" => 2), new Obj(), new Obj(null, null, null, array("one" => 1, "two" => 2))); test('array("" => "empty")', array("" => "empty"), new Obj()); test('array("a" => 1, "b" => 2, 3))', array("a" => 1, "b" => 2, 3), new Obj(), new Obj(1, 2, 3)); test('array(3, "a" => 1, "b" => 2))', array(3, "a" => 1, "b" => 2), new Obj(), new Obj(1, 2, 3)); test('array("a" => 1, 3, "b" => 2))', array("a" => 1, 3, "b" => 2), new Obj(), new Obj(1, 2, 3)); $a = array('foo'); test('array($a, $a)', array($a, $a), new Obj(), new Obj($a, $a, null)); test('array(&$a, &$a)', array(&$a, &$a), new Obj(), new Obj($a, $a, null)); test('array(&$a, $a)', array($a, &$a), new Obj(), new Obj($a, $a, null)); test('array(&$a, $a)', array(&$a, $a), new Obj(), new Obj($a, $a, null)); $a = array( 'a' => array( 'b' => 'c', 'd' => 'e' ), 'f' => array( 'g' => 'h' ) ); test('array', $a, new Obj(), new Obj(null, null, null, $a)); $o = new Obj(1, 2, 3); test('object', $o, new Obj(), new Obj(1, 2, 3)); class Obj2 { public $A; protected $B; private $C; function __construct($a, $b, $c) { $this->A = $a; $this->B = $b; $this->C = $c; } } $o = new Obj2(1, 2, 3); test('object', $o, new Obj(), new Obj($o)); $o1 = new Obj2(1, 2, 3); $o2 = new Obj2(4, 5, 6); test('object', array($o1, $o2), new Obj(), new Obj($o1, $o2)); $o = new Obj2(1, 2, 3); test('object', array(&$o, &$o), new Obj(), new Obj($o, $o)); $o = new Obj2(1, 2, 3); test('object', array(&$o, $o), new Obj(), new Obj($o, $o)); $o = new Obj2(1, 2, 3); test('object', array($o, &$o), new Obj(), new Obj($o, $o)); --EXPECTF-- object(Obj)#%d (3) { ["a"]=> NULL [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> bool(true) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> bool(false) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(0) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(-1) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(1000) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(-1000) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(100000) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(-100000) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> float(123.456) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> string(0) "" [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> string(6) "foobar" [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> NULL [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } [%r"?b"?:protected"?%r]=> array(3) { [0]=> int(4) [1]=> int(5) [2]=> int(6) } [%r"?c"?:("Obj":)?private"?%r]=> array(3) { [0]=> int(7) [1]=> int(8) [2]=> int(9) } } OK object(Obj)#%d (4) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) [3]=> int(4) } SKIP object(Obj)#%d (3) { ["a"]=> string(3) "foo" [%r"?b"?:protected"?%r]=> string(6) "foobar" [%r"?c"?:("Obj":)?private"?%r]=> string(4) "hoge" } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (5) { ["a"]=> NULL [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL ["one"]=> int(1) ["two"]=> int(2) } OK object(Obj)#%d (4) { ["a"]=> NULL [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL [""]=> string(5) "empty" } SKIP object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> array(1) { [0]=> string(3) "foo" } [%r"?b"?:protected"?%r]=> array(1) { [0]=> string(3) "foo" } [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> &array(1) { [0]=> string(3) "foo" } [%r"?b"?:protected"?%r]=> &array(1) { [0]=> string(3) "foo" } [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> array(1) { [0]=> string(3) "foo" } [%r"?b"?:protected"?%r]=> &array(1) { [0]=> string(3) "foo" } [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> &array(1) { [0]=> string(3) "foo" } [%r"?b"?:protected"?%r]=> array(1) { [0]=> string(3) "foo" } [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (4) { ["a"]=> array(2) { ["b"]=> string(1) "c" ["d"]=> string(1) "e" } [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL ["f"]=> array(1) { ["g"]=> string(1) "h" } } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> object(Obj2)#%d (3) { ["A"]=> int(1) [%r"?B"?:protected"?%r]=> int(2) [%r"?C"?:("Obj2":)?private"?%r]=> int(3) } [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> object(Obj2)#%d (3) { ["A"]=> int(1) [%r"?B"?:protected"?%r]=> int(2) [%r"?C"?:("Obj2":)?private"?%r]=> int(3) } [%r"?b"?:protected"?%r]=> object(Obj2)#%d (3) { ["A"]=> int(4) [%r"?B"?:protected"?%r]=> int(5) [%r"?C"?:("Obj2":)?private"?%r]=> int(6) } [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> &object(Obj2)#%d (3) { ["A"]=> int(1) [%r"?B"?:protected"?%r]=> int(2) [%r"?C"?:("Obj2":)?private"?%r]=> int(3) } [%r"?b"?:protected"?%r]=> &object(Obj2)#%d (3) { ["A"]=> int(1) [%r"?B"?:protected"?%r]=> int(2) [%r"?C"?:("Obj2":)?private"?%r]=> int(3) } [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> object(Obj2)#%d (3) { ["A"]=> int(1) [%r"?B"?:protected"?%r]=> int(2) [%r"?C"?:("Obj2":)?private"?%r]=> int(3) } [%r"?b"?:protected"?%r]=> object(Obj2)#%d (3) { ["A"]=> int(1) [%r"?B"?:protected"?%r]=> int(2) [%r"?C"?:("Obj2":)?private"?%r]=> int(3) } [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> &object(Obj2)#%d (3) { ["A"]=> int(1) [%r"?B"?:protected"?%r]=> int(2) [%r"?C"?:("Obj2":)?private"?%r]=> int(3) } [%r"?b"?:protected"?%r]=> &object(Obj2)#%d (3) { ["A"]=> int(1) [%r"?B"?:protected"?%r]=> int(2) [%r"?C"?:("Obj2":)?private"?%r]=> int(3) } [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK msgpack-0.5.5/tests/095b.phpt0000644000077100007710000002177212110565607015556 0ustar xinchenxinchen--TEST-- unpack of object converter : class unpack (object) --SKIPIF-- = 0) { echo "skip tests in PHP 5.1 or older"; } --FILE-- pack($variable); $unserialized = $msgpack->unpack($serialized, $object); var_dump($unserialized); if ($result) { echo $unserialized == $result ? 'OK' : 'ERROR', PHP_EOL; } else { echo 'SKIP', PHP_EOL; } } class Obj { public $a; protected $b; private $c; public function __construct($a = null, $b = null, $c = null, $d = null) { $this->a = $a; $this->b = $b; $this->c = $c; if (is_array($d)) { foreach ($d as $key => $val) { $this->{$key} = $val; } } } } test('null', null, new Obj(), new Obj(null, null, null)); test('bool: true', true, new Obj(), new Obj(true, null, null)); test('bool: false', false, new Obj(), new Obj(false, null, null)); test('zero: 0', 0, new Obj(), new Obj(0, null, null)); test('small: 1', 1, new Obj(), new Obj(1, null, null)); test('small: -1', -1, new Obj(), new Obj(-1, null, null)); test('medium: 1000', 1000, new Obj(), new Obj(1000, null, null)); test('medium: -1000', -1000, new Obj(), new Obj(-1000, null, null)); test('large: 100000', 100000, new Obj(), new Obj(100000, null, null)); test('large: -100000', -100000, new Obj(), new Obj(-100000, null, null)); test('double: 123.456', 123.456, new Obj(), new Obj(123.456, null, null)); test('empty: ""', "", new Obj(), new Obj("", null, null)); test('string: "foobar"', "foobar", new Obj(), new Obj("foobar", null, null)); test('array: empty', array(), new Obj(), new Obj(null, null, null)); test('array(1, 2, 3)', array(1, 2, 3), new Obj(), new Obj(1, 2, 3)); test('array(array(1, 2, 3), arr...', array(array(1, 2, 3), array(4, 5, 6), array(7, 8, 9)), new Obj(), new Obj(array(1, 2, 3), array(4, 5, 6), array(7, 8, 9))); test('array(1, 2, 3, 4)', array(1, 2, 3, 4), new Obj()); test('array("foo", "foobar", "foohoge")', array("foo", "foobar", "hoge"), new Obj(), new Obj("foo", "foobar", "hoge")); test('array("a" => 1, "b" => 2))', array("a" => 1, "b" => 2), new Obj(), new Obj(1, 2, null)); test('array("one" => 1, "two" => 2))', array("one" => 1, "two" => 2), new Obj(), new Obj(null, null, null, array("one" => 1, "two" => 2))); test('array("a" => 1, "b" => 2, 3))', array("a" => 1, "b" => 2, 3), new Obj(), new Obj(1, 2, 3)); test('array(3, "a" => 1, "b" => 2))', array(3, "a" => 1, "b" => 2), new Obj(), new Obj(1, 2, 3)); test('array("a" => 1, 3, "b" => 2))', array("a" => 1, 3, "b" => 2), new Obj(), new Obj(1, 2, 3)); $a = array('foo'); test('array($a, $a)', array($a, $a), new Obj(), new Obj($a, $a, null)); test('array(&$a, &$a)', array(&$a, &$a), new Obj(), new Obj($a, $a, null)); test('array(&$a, $a)', array($a, &$a), new Obj(), new Obj($a, $a, null)); test('array(&$a, $a)', array(&$a, $a), new Obj(), new Obj($a, $a, null)); $a = array( 'a' => array( 'b' => 'c', 'd' => 'e' ), 'f' => array( 'g' => 'h' ) ); test('array', $a, new Obj(), new Obj(null, null, null, $a)); $o = new Obj(1, 2, 3); test('object', $o, new Obj(), new Obj(1, 2, 3)); class Obj2 { public $A; protected $B; private $C; function __construct($a, $b, $c) { $this->A = $a; $this->B = $b; $this->C = $c; } } $o = new Obj2(1, 2, 3); test('object', $o, new Obj(), new Obj($o)); $o1 = new Obj2(1, 2, 3); $o2 = new Obj2(4, 5, 6); test('object', array($o1, $o2), new Obj(), new Obj($o1, $o2)); $o = new Obj2(1, 2, 3); test('object', array(&$o, &$o), new Obj(), new Obj($o, $o)); $o = new Obj2(1, 2, 3); test('object', array(&$o, $o), new Obj(), new Obj($o, $o)); $o = new Obj2(1, 2, 3); test('object', array($o, &$o), new Obj(), new Obj($o, $o)); --EXPECTF-- object(Obj)#%d (3) { ["a"]=> NULL ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> bool(true) ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> bool(false) ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(0) ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(1) ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(-1) ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(1000) ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(-1000) ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(100000) ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(-100000) ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> float(123.456) ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> string(0) "" ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> string(6) "foobar" ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> NULL ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(1) ["b:protected"]=> int(2) ["c:private"]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } ["b:protected"]=> array(3) { [0]=> int(4) [1]=> int(5) [2]=> int(6) } ["c:private"]=> array(3) { [0]=> int(7) [1]=> int(8) [2]=> int(9) } } OK object(Obj)#%d (4) { ["a"]=> int(1) ["b:protected"]=> int(2) ["c:private"]=> int(3) [3]=> int(4) } SKIP object(Obj)#%d (3) { ["a"]=> string(3) "foo" ["b:protected"]=> string(6) "foobar" ["c:private"]=> string(4) "hoge" } OK object(Obj)#%d (3) { ["a"]=> int(1) ["b:protected"]=> int(2) ["c:private"]=> NULL } OK object(Obj)#%d (5) { ["a"]=> NULL ["b:protected"]=> NULL ["c:private"]=> NULL ["one"]=> int(1) ["two"]=> int(2) } OK object(Obj)#%d (3) { ["a"]=> int(1) ["b:protected"]=> int(2) ["c:private"]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> int(1) ["b:protected"]=> int(2) ["c:private"]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> int(1) ["b:protected"]=> int(2) ["c:private"]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> array(1) { [0]=> string(3) "foo" } ["b:protected"]=> array(1) { [0]=> string(3) "foo" } ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> &array(1) { [0]=> string(3) "foo" } ["b:protected"]=> &array(1) { [0]=> string(3) "foo" } ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> array(1) { [0]=> string(3) "foo" } ["b:protected"]=> &array(1) { [0]=> string(3) "foo" } ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> &array(1) { [0]=> string(3) "foo" } ["b:protected"]=> array(1) { [0]=> string(3) "foo" } ["c:private"]=> NULL } OK object(Obj)#%d (4) { ["a"]=> array(2) { ["b"]=> string(1) "c" ["d"]=> string(1) "e" } ["b:protected"]=> NULL ["c:private"]=> NULL ["f"]=> array(1) { ["g"]=> string(1) "h" } } OK object(Obj)#%d (3) { ["a"]=> int(1) ["b:protected"]=> int(2) ["c:private"]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> object(Obj2)#%d (3) { ["A"]=> int(1) ["B:protected"]=> int(2) ["C:private"]=> int(3) } ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> object(Obj2)#%d (3) { ["A"]=> int(1) ["B:protected"]=> int(2) ["C:private"]=> int(3) } ["b:protected"]=> object(Obj2)#%d (3) { ["A"]=> int(4) ["B:protected"]=> int(5) ["C:private"]=> int(6) } ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> &object(Obj2)#%d (3) { ["A"]=> int(1) ["B:protected"]=> int(2) ["C:private"]=> int(3) } ["b:protected"]=> &object(Obj2)#%d (3) { ["A"]=> int(1) ["B:protected"]=> int(2) ["C:private"]=> int(3) } ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> object(Obj2)#%d (3) { ["A"]=> int(1) ["B:protected"]=> int(2) ["C:private"]=> int(3) } ["b:protected"]=> object(Obj2)#%d (3) { ["A"]=> int(1) ["B:protected"]=> int(2) ["C:private"]=> int(3) } ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> &object(Obj2)#%d (3) { ["A"]=> int(1) ["B:protected"]=> int(2) ["C:private"]=> int(3) } ["b:protected"]=> &object(Obj2)#%d (3) { ["A"]=> int(1) ["B:protected"]=> int(2) ["C:private"]=> int(3) } ["c:private"]=> NULL } OK msgpack-0.5.5/tests/096.phpt0000644000077100007710000001742712110565607015417 0ustar xinchenxinchen--TEST-- unpack of object converter : class unpack (string: php_only=0) --SKIPIF-- pack($variable); $unserialized = $msgpack->unpack($serialized, $object); var_dump($unserialized); if ($result) { echo $unserialized == $result ? 'OK' : 'ERROR', PHP_EOL; } else { echo 'SKIP', PHP_EOL; } } class Obj { public $a; protected $b; private $c; public function __construct($a = null, $b = null, $c = null, $d = null) { $this->a = $a; $this->b = $b; $this->c = $c; if (is_array($d)) { foreach ($d as $key => $val) { $this->{$key} = $val; } } } } test('null', null, 'Obj', new Obj(null, null, null)); test('bool: true', true, 'Obj', new Obj(true, null, null)); test('bool: false', false, 'Obj', new Obj(false, null, null)); test('zero: 0', 0, 'Obj', new Obj(0, null, null)); test('small: 1', 1, 'Obj', new Obj(1, null, null)); test('small: -1', -1, 'Obj', new Obj(-1, null, null)); test('medium: 1000', 1000, 'Obj', new Obj(1000, null, null)); test('medium: -1000', -1000, 'Obj', new Obj(-1000, null, null)); test('large: 100000', 100000, 'Obj', new Obj(100000, null, null)); test('large: -100000', -100000, 'Obj', new Obj(-100000, null, null)); test('double: 123.456', 123.456, 'Obj', new Obj(123.456, null, null)); test('empty: ""', "", 'Obj', new Obj("", null, null)); test('string: "foobar"', "foobar", 'Obj', new Obj("foobar", null, null)); test('array: empty', array(), 'Obj', new Obj(null, null, null)); test('array(1, 2, 3)', array(1, 2, 3), 'Obj', new Obj(1, 2, 3)); test('array(array(1, 2, 3), arr...', array(array(1, 2, 3), array(4, 5, 6), array(7, 8, 9)), 'Obj', new Obj(array(1, 2, 3), array(4, 5, 6), array(7, 8, 9))); test('array(1, 2, 3, 4)', array(1, 2, 3, 4), 'Obj'); test('array("foo", "foobar", "foohoge")', array("foo", "foobar", "hoge"), 'Obj', new Obj("foo", "foobar", "hoge")); test('array("a" => 1, "b" => 2))', array("a" => 1, "b" => 2), 'Obj', new Obj(1, 2, null)); test('array("one" => 1, "two" => 2))', array("one" => 1, "two" => 2), 'Obj', new Obj(null, null, null, array("one" => 1, "two" => 2))); test('array("" => "empty")', array("" => "empty"), 'Obj'); test('array("a" => 1, "b" => 2, 3))', array("a" => 1, "b" => 2, 3), 'Obj', new Obj(1, 2, 3)); test('array(3, "a" => 1, "b" => 2))', array(3, "a" => 1, "b" => 2), 'Obj', new Obj(1, 2, 3)); test('array("a" => 1, 3, "b" => 2))', array("a" => 1, 3, "b" => 2), 'Obj', new Obj(1, 2, 3)); $a = array('foo'); test('array($a, $a)', array($a, $a), 'Obj', new Obj($a, $a, null)); $a = array( 'a' => array( 'b' => 'c', 'd' => 'e' ), 'f' => array( 'g' => 'h' ) ); test('array', $a, 'Obj', new Obj(null, null, null, $a)); $o = new Obj(1, 2, 3); test('object', $o, 'Obj', new Obj(1, 2, 3)); class Obj2 { public $A; protected $B; private $C; function __construct($a, $b, $c) { $this->A = $a; $this->B = $b; $this->C = $c; } } $o = new Obj2(1, 2, 3); test('object', $o, 'Obj', new Obj(1, 2, 3)); $o1 = new Obj2(1, 2, 3); $o2 = new Obj2(4, 5, 6); test('object', array($o1, $o2), 'Obj', new Obj(array(1, 2, 3), array(4, 5, 6))); --EXPECTF-- object(Obj)#%d (3) { ["a"]=> NULL [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> bool(true) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> bool(false) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(0) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(-1) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(1000) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(-1000) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(100000) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(-100000) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> float(123.456) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> string(0) "" [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> string(6) "foobar" [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> NULL [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } [%r"?b"?:protected"?%r]=> array(3) { [0]=> int(4) [1]=> int(5) [2]=> int(6) } [%r"?c"?:("Obj":)?private"?%r]=> array(3) { [0]=> int(7) [1]=> int(8) [2]=> int(9) } } OK object(Obj)#%d (4) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) [3]=> int(4) } SKIP object(Obj)#%d (3) { ["a"]=> string(3) "foo" [%r"?b"?:protected"?%r]=> string(6) "foobar" [%r"?c"?:("Obj":)?private"?%r]=> string(4) "hoge" } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (5) { ["a"]=> NULL [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL ["one"]=> int(1) ["two"]=> int(2) } OK object(Obj)#%d (4) { ["a"]=> NULL [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL [""]=> string(5) "empty" } SKIP object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> array(1) { [0]=> string(3) "foo" } [%r"?b"?:protected"?%r]=> array(1) { [0]=> string(3) "foo" } [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (4) { ["a"]=> array(2) { ["b"]=> string(1) "c" ["d"]=> string(1) "e" } [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL ["f"]=> array(1) { ["g"]=> string(1) "h" } } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } [%r"?b"?:protected"?%r]=> array(3) { [0]=> int(4) [1]=> int(5) [2]=> int(6) } [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK msgpack-0.5.5/tests/096b.phpt0000644000077100007710000001561212110565607015553 0ustar xinchenxinchen--TEST-- unpack of object converter : class unpack (string: php_only=0) --SKIPIF-- = 0) { echo "skip tests in PHP 5.1 or older"; } --FILE-- pack($variable); $unserialized = $msgpack->unpack($serialized, $object); var_dump($unserialized); if ($result) { echo $unserialized == $result ? 'OK' : 'ERROR', PHP_EOL; } else { echo 'SKIP', PHP_EOL; } } class Obj { public $a; protected $b; private $c; public function __construct($a = null, $b = null, $c = null, $d = null) { $this->a = $a; $this->b = $b; $this->c = $c; if (is_array($d)) { foreach ($d as $key => $val) { $this->{$key} = $val; } } } } test('null', null, 'Obj', new Obj(null, null, null)); test('bool: true', true, 'Obj', new Obj(true, null, null)); test('bool: false', false, 'Obj', new Obj(false, null, null)); test('zero: 0', 0, 'Obj', new Obj(0, null, null)); test('small: 1', 1, 'Obj', new Obj(1, null, null)); test('small: -1', -1, 'Obj', new Obj(-1, null, null)); test('medium: 1000', 1000, 'Obj', new Obj(1000, null, null)); test('medium: -1000', -1000, 'Obj', new Obj(-1000, null, null)); test('large: 100000', 100000, 'Obj', new Obj(100000, null, null)); test('large: -100000', -100000, 'Obj', new Obj(-100000, null, null)); test('double: 123.456', 123.456, 'Obj', new Obj(123.456, null, null)); test('empty: ""', "", 'Obj', new Obj("", null, null)); test('string: "foobar"', "foobar", 'Obj', new Obj("foobar", null, null)); test('array: empty', array(), 'Obj', new Obj(null, null, null)); test('array(1, 2, 3)', array(1, 2, 3), 'Obj', new Obj(1, 2, 3)); test('array(array(1, 2, 3), arr...', array(array(1, 2, 3), array(4, 5, 6), array(7, 8, 9)), 'Obj', new Obj(array(1, 2, 3), array(4, 5, 6), array(7, 8, 9))); test('array(1, 2, 3, 4)', array(1, 2, 3, 4), 'Obj'); test('array("foo", "foobar", "foohoge")', array("foo", "foobar", "hoge"), 'Obj', new Obj("foo", "foobar", "hoge")); test('array("a" => 1, "b" => 2))', array("a" => 1, "b" => 2), 'Obj', new Obj(1, 2, null)); test('array("one" => 1, "two" => 2))', array("one" => 1, "two" => 2), 'Obj', new Obj(null, null, null, array("one" => 1, "two" => 2))); test('array("a" => 1, "b" => 2, 3))', array("a" => 1, "b" => 2, 3), 'Obj', new Obj(1, 2, 3)); test('array(3, "a" => 1, "b" => 2))', array(3, "a" => 1, "b" => 2), 'Obj', new Obj(1, 2, 3)); test('array("a" => 1, 3, "b" => 2))', array("a" => 1, 3, "b" => 2), 'Obj', new Obj(1, 2, 3)); $a = array('foo'); test('array($a, $a)', array($a, $a), 'Obj', new Obj($a, $a, null)); $a = array( 'a' => array( 'b' => 'c', 'd' => 'e' ), 'f' => array( 'g' => 'h' ) ); test('array', $a, 'Obj', new Obj(null, null, null, $a)); $o = new Obj(1, 2, 3); test('object', $o, 'Obj', new Obj(1, 2, 3)); class Obj2 { public $A; protected $B; private $C; function __construct($a, $b, $c) { $this->A = $a; $this->B = $b; $this->C = $c; } } $o = new Obj2(1, 2, 3); test('object', $o, 'Obj', new Obj(1, 2, 3)); $o1 = new Obj2(1, 2, 3); $o2 = new Obj2(4, 5, 6); test('object', array($o1, $o2), 'Obj', new Obj(array(1, 2, 3), array(4, 5, 6))); --EXPECTF-- object(Obj)#%d (3) { ["a"]=> NULL ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> bool(true) ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> bool(false) ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(0) ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(1) ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(-1) ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(1000) ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(-1000) ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(100000) ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(-100000) ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> float(123.456) ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> string(0) "" ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> string(6) "foobar" ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> NULL ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(1) ["b:protected"]=> int(2) ["c:private"]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } ["b:protected"]=> array(3) { [0]=> int(4) [1]=> int(5) [2]=> int(6) } ["c:private"]=> array(3) { [0]=> int(7) [1]=> int(8) [2]=> int(9) } } OK object(Obj)#%d (4) { ["a"]=> int(1) ["b:protected"]=> int(2) ["c:private"]=> int(3) [3]=> int(4) } SKIP object(Obj)#%d (3) { ["a"]=> string(3) "foo" ["b:protected"]=> string(6) "foobar" ["c:private"]=> string(4) "hoge" } OK object(Obj)#%d (3) { ["a"]=> int(1) ["b:protected"]=> int(2) ["c:private"]=> NULL } OK object(Obj)#%d (5) { ["a"]=> NULL ["b:protected"]=> NULL ["c:private"]=> NULL ["one"]=> int(1) ["two"]=> int(2) } OK object(Obj)#%d (3) { ["a"]=> int(1) ["b:protected"]=> int(2) ["c:private"]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> int(1) ["b:protected"]=> int(2) ["c:private"]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> int(1) ["b:protected"]=> int(2) ["c:private"]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> array(1) { [0]=> string(3) "foo" } ["b:protected"]=> array(1) { [0]=> string(3) "foo" } ["c:private"]=> NULL } OK object(Obj)#%d (4) { ["a"]=> array(2) { ["b"]=> string(1) "c" ["d"]=> string(1) "e" } ["b:protected"]=> NULL ["c:private"]=> NULL ["f"]=> array(1) { ["g"]=> string(1) "h" } } OK object(Obj)#%d (3) { ["a"]=> int(1) ["b:protected"]=> int(2) ["c:private"]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> int(1) ["b:protected"]=> int(2) ["c:private"]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } ["b:protected"]=> array(3) { [0]=> int(4) [1]=> int(5) [2]=> int(6) } ["c:private"]=> NULL } OK msgpack-0.5.5/tests/097.phpt0000644000077100007710000001764112110565607015416 0ustar xinchenxinchen--TEST-- unpack of object converter : class unpack (object: php_only=0) --SKIPIF-- pack($variable); $unserialized = $msgpack->unpack($serialized, $object); var_dump($unserialized); if ($result) { echo $unserialized == $result ? 'OK' : 'ERROR', PHP_EOL; } else { echo 'SKIP', PHP_EOL; } } class Obj { public $a; protected $b; private $c; public function __construct($a = null, $b = null, $c = null, $d = null) { $this->a = $a; $this->b = $b; $this->c = $c; if (is_array($d)) { foreach ($d as $key => $val) { $this->{$key} = $val; } } } } $object = new Obj(); test('null', null, new Obj(), new Obj(null, null, null)); test('bool: true', true, new Obj(), new Obj(true, null, null)); test('bool: false', false, new Obj(), new Obj(false, null, null)); test('zero: 0', 0, new Obj(), new Obj(0, null, null)); test('small: 1', 1, new Obj(), new Obj(1, null, null)); test('small: -1', -1, new Obj(), new Obj(-1, null, null)); test('medium: 1000', 1000, new Obj(), new Obj(1000, null, null)); test('medium: -1000', -1000, new Obj(), new Obj(-1000, null, null)); test('large: 100000', 100000, new Obj(), new Obj(100000, null, null)); test('large: -100000', -100000, new Obj(), new Obj(-100000, null, null)); test('double: 123.456', 123.456, new Obj(), new Obj(123.456, null, null)); test('empty: ""', "", new Obj(), new Obj("", null, null)); test('string: "foobar"', "foobar", new Obj(), new Obj("foobar", null, null)); test('array: empty', array(), new Obj(), new Obj(null, null, null)); test('array(1, 2, 3)', array(1, 2, 3), new Obj(), new Obj(1, 2, 3)); test('array(array(1, 2, 3), arr...', array(array(1, 2, 3), array(4, 5, 6), array(7, 8, 9)), new Obj(), new Obj(array(1, 2, 3), array(4, 5, 6), array(7, 8, 9))); test('array(1, 2, 3, 4)', array(1, 2, 3, 4), new Obj()); test('array("foo", "foobar", "foohoge")', array("foo", "foobar", "hoge"), new Obj(), new Obj("foo", "foobar", "hoge")); test('array("a" => 1, "b" => 2))', array("a" => 1, "b" => 2), new Obj(), new Obj(1, 2, null)); test('array("one" => 1, "two" => 2))', array("one" => 1, "two" => 2), new Obj(), new Obj(null, null, null, array("one" => 1, "two" => 2))); test('array("" => "empty")', array("" => "empty"), new Obj()); test('array("a" => 1, "b" => 2, 3))', array("a" => 1, "b" => 2, 3), new Obj(), new Obj(1, 2, 3)); test('array(3, "a" => 1, "b" => 2))', array(3, "a" => 1, "b" => 2), new Obj(), new Obj(1, 2, 3)); test('array("a" => 1, 3, "b" => 2))', array("a" => 1, 3, "b" => 2), new Obj(), new Obj(1, 2, 3)); $a = array('foo'); test('array($a, $a)', array($a, $a), new Obj(), new Obj($a, $a, null)); $a = array( 'a' => array( 'b' => 'c', 'd' => 'e' ), 'f' => array( 'g' => 'h' ) ); test('array', $a, new Obj(), new Obj(null, null, null, $a)); $o = new Obj(1, 2, 3); test('object', $o, new Obj(), new Obj(1, 2, 3)); class Obj2 { public $A; protected $B; private $C; function __construct($a, $b, $c) { $this->A = $a; $this->B = $b; $this->C = $c; } } $o = new Obj2(1, 2, 3); test('object', $o, new Obj(), new Obj(1, 2, 3)); $o1 = new Obj2(1, 2, 3); $o2 = new Obj2(4, 5, 6); test('object', array($o1, $o2), new Obj(), new Obj(array(1, 2, 3), array(4, 5, 6))); --EXPECTF-- object(Obj)#%d (3) { ["a"]=> NULL [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> bool(true) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> bool(false) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(0) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(-1) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(1000) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(-1000) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(100000) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(-100000) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> float(123.456) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> string(0) "" [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> string(6) "foobar" [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> NULL [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } [%r"?b"?:protected"?%r]=> array(3) { [0]=> int(4) [1]=> int(5) [2]=> int(6) } [%r"?c"?:("Obj":)?private"?%r]=> array(3) { [0]=> int(7) [1]=> int(8) [2]=> int(9) } } OK object(Obj)#%d (4) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) [3]=> int(4) } SKIP object(Obj)#%d (3) { ["a"]=> string(3) "foo" [%r"?b"?:protected"?%r]=> string(6) "foobar" [%r"?c"?:("Obj":)?private"?%r]=> string(4) "hoge" } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (5) { ["a"]=> NULL [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL ["one"]=> int(1) ["two"]=> int(2) } OK object(Obj)#%d (4) { ["a"]=> NULL [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL [""]=> string(5) "empty" } SKIP object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> array(1) { [0]=> string(3) "foo" } [%r"?b"?:protected"?%r]=> array(1) { [0]=> string(3) "foo" } [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (4) { ["a"]=> array(2) { ["b"]=> string(1) "c" ["d"]=> string(1) "e" } [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL ["f"]=> array(1) { ["g"]=> string(1) "h" } } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } [%r"?b"?:protected"?%r]=> array(3) { [0]=> int(4) [1]=> int(5) [2]=> int(6) } [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK msgpack-0.5.5/tests/097b.phpt0000644000077100007710000001577212110565607015563 0ustar xinchenxinchen--TEST-- unpack of object converter : class unpack (object: php_only=0) --SKIPIF-- = 0) { echo "skip tests in PHP 5.1 or older"; } --FILE-- pack($variable); $unserialized = $msgpack->unpack($serialized, $object); var_dump($unserialized); if ($result) { echo $unserialized == $result ? 'OK' : 'ERROR', PHP_EOL; } else { echo 'SKIP', PHP_EOL; } } class Obj { public $a; protected $b; private $c; public function __construct($a = null, $b = null, $c = null, $d = null) { $this->a = $a; $this->b = $b; $this->c = $c; if (is_array($d)) { foreach ($d as $key => $val) { $this->{$key} = $val; } } } } test('null', null, new Obj(), new Obj(null, null, null)); test('bool: true', true, new Obj(), new Obj(true, null, null)); test('bool: false', false, new Obj(), new Obj(false, null, null)); test('zero: 0', 0, new Obj(), new Obj(0, null, null)); test('small: 1', 1, new Obj(), new Obj(1, null, null)); test('small: -1', -1, new Obj(), new Obj(-1, null, null)); test('medium: 1000', 1000, new Obj(), new Obj(1000, null, null)); test('medium: -1000', -1000, new Obj(), new Obj(-1000, null, null)); test('large: 100000', 100000, new Obj(), new Obj(100000, null, null)); test('large: -100000', -100000, new Obj(), new Obj(-100000, null, null)); test('double: 123.456', 123.456, new Obj(), new Obj(123.456, null, null)); test('empty: ""', "", new Obj(), new Obj("", null, null)); test('string: "foobar"', "foobar", new Obj(), new Obj("foobar", null, null)); test('array: empty', array(), new Obj(), new Obj(null, null, null)); test('array(1, 2, 3)', array(1, 2, 3), new Obj(), new Obj(1, 2, 3)); test('array(array(1, 2, 3), arr...', array(array(1, 2, 3), array(4, 5, 6), array(7, 8, 9)), new Obj(), new Obj(array(1, 2, 3), array(4, 5, 6), array(7, 8, 9))); test('array(1, 2, 3, 4)', array(1, 2, 3, 4), new Obj()); test('array("foo", "foobar", "foohoge")', array("foo", "foobar", "hoge"), new Obj(), new Obj("foo", "foobar", "hoge")); test('array("a" => 1, "b" => 2))', array("a" => 1, "b" => 2), new Obj(), new Obj(1, 2, null)); test('array("one" => 1, "two" => 2))', array("one" => 1, "two" => 2), new Obj(), new Obj(null, null, null, array("one" => 1, "two" => 2))); test('array("a" => 1, "b" => 2, 3))', array("a" => 1, "b" => 2, 3), new Obj(), new Obj(1, 2, 3)); test('array(3, "a" => 1, "b" => 2))', array(3, "a" => 1, "b" => 2), new Obj(), new Obj(1, 2, 3)); test('array("a" => 1, 3, "b" => 2))', array("a" => 1, 3, "b" => 2), new Obj(), new Obj(1, 2, 3)); $a = array('foo'); test('array($a, $a)', array($a, $a), new Obj(), new Obj($a, $a, null)); $a = array( 'a' => array( 'b' => 'c', 'd' => 'e' ), 'f' => array( 'g' => 'h' ) ); test('array', $a, new Obj(), new Obj(null, null, null, $a)); $o = new Obj(1, 2, 3); test('object', $o, new Obj(), new Obj(1, 2, 3)); class Obj2 { public $A; protected $B; private $C; function __construct($a, $b, $c) { $this->A = $a; $this->B = $b; $this->C = $c; } } $o = new Obj2(1, 2, 3); test('object', $o, new Obj(), new Obj(1, 2, 3)); $o1 = new Obj2(1, 2, 3); $o2 = new Obj2(4, 5, 6); test('object', array($o1, $o2), new Obj(), new Obj(array(1, 2, 3), array(4, 5, 6))); --EXPECTF-- object(Obj)#%d (3) { ["a"]=> NULL ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> bool(true) ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> bool(false) ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(0) ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(1) ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(-1) ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(1000) ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(-1000) ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(100000) ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(-100000) ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> float(123.456) ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> string(0) "" ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> string(6) "foobar" ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> NULL ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(1) ["b:protected"]=> int(2) ["c:private"]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } ["b:protected"]=> array(3) { [0]=> int(4) [1]=> int(5) [2]=> int(6) } ["c:private"]=> array(3) { [0]=> int(7) [1]=> int(8) [2]=> int(9) } } OK object(Obj)#%d (4) { ["a"]=> int(1) ["b:protected"]=> int(2) ["c:private"]=> int(3) [3]=> int(4) } SKIP object(Obj)#%d (3) { ["a"]=> string(3) "foo" ["b:protected"]=> string(6) "foobar" ["c:private"]=> string(4) "hoge" } OK object(Obj)#%d (3) { ["a"]=> int(1) ["b:protected"]=> int(2) ["c:private"]=> NULL } OK object(Obj)#%d (5) { ["a"]=> NULL ["b:protected"]=> NULL ["c:private"]=> NULL ["one"]=> int(1) ["two"]=> int(2) } OK object(Obj)#%d (3) { ["a"]=> int(1) ["b:protected"]=> int(2) ["c:private"]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> int(1) ["b:protected"]=> int(2) ["c:private"]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> int(1) ["b:protected"]=> int(2) ["c:private"]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> array(1) { [0]=> string(3) "foo" } ["b:protected"]=> array(1) { [0]=> string(3) "foo" } ["c:private"]=> NULL } OK object(Obj)#%d (4) { ["a"]=> array(2) { ["b"]=> string(1) "c" ["d"]=> string(1) "e" } ["b:protected"]=> NULL ["c:private"]=> NULL ["f"]=> array(1) { ["g"]=> string(1) "h" } } OK object(Obj)#%d (3) { ["a"]=> int(1) ["b:protected"]=> int(2) ["c:private"]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> int(1) ["b:protected"]=> int(2) ["c:private"]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } ["b:protected"]=> array(3) { [0]=> int(4) [1]=> int(5) [2]=> int(6) } ["c:private"]=> NULL } OK msgpack-0.5.5/tests/098.phpt0000644000077100007710000001746712110565607015425 0ustar xinchenxinchen--TEST-- unpack of object converter: class unpack (string: OPT_PHPONLY=false) --SKIPIF-- setOption(MessagePack::OPT_PHPONLY, false); $serialized = $msgpack->pack($variable); $unserialized = $msgpack->unpack($serialized, $object); var_dump($unserialized); if ($result) { echo $unserialized == $result ? 'OK' : 'ERROR', PHP_EOL; } else { echo 'SKIP', PHP_EOL; } } class Obj { public $a; protected $b; private $c; public function __construct($a = null, $b = null, $c = null, $d = null) { $this->a = $a; $this->b = $b; $this->c = $c; if (is_array($d)) { foreach ($d as $key => $val) { $this->{$key} = $val; } } } } test('null', null, 'Obj', new Obj(null, null, null)); test('bool: true', true, 'Obj', new Obj(true, null, null)); test('bool: false', false, 'Obj', new Obj(false, null, null)); test('zero: 0', 0, 'Obj', new Obj(0, null, null)); test('small: 1', 1, 'Obj', new Obj(1, null, null)); test('small: -1', -1, 'Obj', new Obj(-1, null, null)); test('medium: 1000', 1000, 'Obj', new Obj(1000, null, null)); test('medium: -1000', -1000, 'Obj', new Obj(-1000, null, null)); test('large: 100000', 100000, 'Obj', new Obj(100000, null, null)); test('large: -100000', -100000, 'Obj', new Obj(-100000, null, null)); test('double: 123.456', 123.456, 'Obj', new Obj(123.456, null, null)); test('empty: ""', "", 'Obj', new Obj("", null, null)); test('string: "foobar"', "foobar", 'Obj', new Obj("foobar", null, null)); test('array: empty', array(), 'Obj', new Obj(null, null, null)); test('array(1, 2, 3)', array(1, 2, 3), 'Obj', new Obj(1, 2, 3)); test('array(array(1, 2, 3), arr...', array(array(1, 2, 3), array(4, 5, 6), array(7, 8, 9)), 'Obj', new Obj(array(1, 2, 3), array(4, 5, 6), array(7, 8, 9))); test('array(1, 2, 3, 4)', array(1, 2, 3, 4), 'Obj'); test('array("foo", "foobar", "foohoge")', array("foo", "foobar", "hoge"), 'Obj', new Obj("foo", "foobar", "hoge")); test('array("a" => 1, "b" => 2))', array("a" => 1, "b" => 2), 'Obj', new Obj(1, 2, null)); test('array("one" => 1, "two" => 2))', array("one" => 1, "two" => 2), 'Obj', new Obj(null, null, null, array("one" => 1, "two" => 2))); test('array("" => "empty")', array("" => "empty"), 'Obj'); test('array("a" => 1, "b" => 2, 3))', array("a" => 1, "b" => 2, 3), 'Obj', new Obj(1, 2, 3)); test('array(3, "a" => 1, "b" => 2))', array(3, "a" => 1, "b" => 2), 'Obj', new Obj(1, 2, 3)); test('array("a" => 1, 3, "b" => 2))', array("a" => 1, 3, "b" => 2), 'Obj', new Obj(1, 2, 3)); $a = array('foo'); test('array($a, $a)', array($a, $a), 'Obj', new Obj($a, $a, null)); $a = array( 'a' => array( 'b' => 'c', 'd' => 'e' ), 'f' => array( 'g' => 'h' ) ); test('array', $a, 'Obj', new Obj(null, null, null, $a)); $o = new Obj(1, 2, 3); test('object', $o, 'Obj', new Obj(1, 2, 3)); class Obj2 { public $A; protected $B; private $C; function __construct($a, $b, $c) { $this->A = $a; $this->B = $b; $this->C = $c; } } $o = new Obj2(1, 2, 3); test('object', $o, 'Obj', new Obj(1, 2, 3)); $o1 = new Obj2(1, 2, 3); $o2 = new Obj2(4, 5, 6); test('object', array($o1, $o2), 'Obj', new Obj(array(1, 2, 3), array(4, 5, 6))); --EXPECTF-- object(Obj)#%d (3) { ["a"]=> NULL [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> bool(true) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> bool(false) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(0) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(-1) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(1000) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(-1000) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(100000) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(-100000) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> float(123.456) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> string(0) "" [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> string(6) "foobar" [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> NULL [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } [%r"?b"?:protected"?%r]=> array(3) { [0]=> int(4) [1]=> int(5) [2]=> int(6) } [%r"?c"?:("Obj":)?private"?%r]=> array(3) { [0]=> int(7) [1]=> int(8) [2]=> int(9) } } OK object(Obj)#%d (4) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) [3]=> int(4) } SKIP object(Obj)#%d (3) { ["a"]=> string(3) "foo" [%r"?b"?:protected"?%r]=> string(6) "foobar" [%r"?c"?:("Obj":)?private"?%r]=> string(4) "hoge" } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (5) { ["a"]=> NULL [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL ["one"]=> int(1) ["two"]=> int(2) } OK object(Obj)#%d (4) { ["a"]=> NULL [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL [""]=> string(5) "empty" } SKIP object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> array(1) { [0]=> string(3) "foo" } [%r"?b"?:protected"?%r]=> array(1) { [0]=> string(3) "foo" } [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (4) { ["a"]=> array(2) { ["b"]=> string(1) "c" ["d"]=> string(1) "e" } [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL ["f"]=> array(1) { ["g"]=> string(1) "h" } } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } [%r"?b"?:protected"?%r]=> array(3) { [0]=> int(4) [1]=> int(5) [2]=> int(6) } [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK msgpack-0.5.5/tests/098b.phpt0000644000077100007710000001610012110565607015546 0ustar xinchenxinchen--TEST-- unpack of object converter: class unpack (string: OPT_PHPONLY=false) --SKIPIF-- = 0) { echo "skip tests in PHP 5.1 or older"; } --FILE-- setOption(MESSAGEPACK_OPT_PHPONLY, false); } else { $msgpack->setOption(MessagePack::OPT_PHPONLY, false); } $serialized = $msgpack->pack($variable); $unserialized = $msgpack->unpack($serialized, $object); var_dump($unserialized); if ($result) { echo $unserialized == $result ? 'OK' : 'ERROR', PHP_EOL; } else { echo 'SKIP', PHP_EOL; } } class Obj { public $a; protected $b; private $c; public function __construct($a = null, $b = null, $c = null, $d = null) { $this->a = $a; $this->b = $b; $this->c = $c; if (is_array($d)) { foreach ($d as $key => $val) { $this->{$key} = $val; } } } } test('null', null, 'Obj', new Obj(null, null, null)); test('bool: true', true, 'Obj', new Obj(true, null, null)); test('bool: false', false, 'Obj', new Obj(false, null, null)); test('zero: 0', 0, 'Obj', new Obj(0, null, null)); test('small: 1', 1, 'Obj', new Obj(1, null, null)); test('small: -1', -1, 'Obj', new Obj(-1, null, null)); test('medium: 1000', 1000, 'Obj', new Obj(1000, null, null)); test('medium: -1000', -1000, 'Obj', new Obj(-1000, null, null)); test('large: 100000', 100000, 'Obj', new Obj(100000, null, null)); test('large: -100000', -100000, 'Obj', new Obj(-100000, null, null)); test('double: 123.456', 123.456, 'Obj', new Obj(123.456, null, null)); test('empty: ""', "", 'Obj', new Obj("", null, null)); test('string: "foobar"', "foobar", 'Obj', new Obj("foobar", null, null)); test('array: empty', array(), 'Obj', new Obj(null, null, null)); test('array(1, 2, 3)', array(1, 2, 3), 'Obj', new Obj(1, 2, 3)); test('array(array(1, 2, 3), arr...', array(array(1, 2, 3), array(4, 5, 6), array(7, 8, 9)), 'Obj', new Obj(array(1, 2, 3), array(4, 5, 6), array(7, 8, 9))); test('array(1, 2, 3, 4)', array(1, 2, 3, 4), 'Obj'); test('array("foo", "foobar", "foohoge")', array("foo", "foobar", "hoge"), 'Obj', new Obj("foo", "foobar", "hoge")); test('array("a" => 1, "b" => 2))', array("a" => 1, "b" => 2), 'Obj', new Obj(1, 2, null)); test('array("one" => 1, "two" => 2))', array("one" => 1, "two" => 2), 'Obj', new Obj(null, null, null, array("one" => 1, "two" => 2))); test('array("a" => 1, "b" => 2, 3))', array("a" => 1, "b" => 2, 3), 'Obj', new Obj(1, 2, 3)); test('array(3, "a" => 1, "b" => 2))', array(3, "a" => 1, "b" => 2), 'Obj', new Obj(1, 2, 3)); test('array("a" => 1, 3, "b" => 2))', array("a" => 1, 3, "b" => 2), 'Obj', new Obj(1, 2, 3)); $a = array('foo'); test('array($a, $a)', array($a, $a), 'Obj', new Obj($a, $a, null)); $a = array( 'a' => array( 'b' => 'c', 'd' => 'e' ), 'f' => array( 'g' => 'h' ) ); test('array', $a, 'Obj', new Obj(null, null, null, $a)); $o = new Obj(1, 2, 3); test('object', $o, 'Obj', new Obj(1, 2, 3)); class Obj2 { public $A; protected $B; private $C; function __construct($a, $b, $c) { $this->A = $a; $this->B = $b; $this->C = $c; } } $o = new Obj2(1, 2, 3); test('object', $o, 'Obj', new Obj(1, 2, 3)); $o1 = new Obj2(1, 2, 3); $o2 = new Obj2(4, 5, 6); test('object', array($o1, $o2), 'Obj', new Obj(array(1, 2, 3), array(4, 5, 6))); --EXPECTF-- object(Obj)#%d (3) { ["a"]=> NULL ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> bool(true) ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> bool(false) ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(0) ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(1) ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(-1) ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(1000) ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(-1000) ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(100000) ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(-100000) ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> float(123.456) ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> string(0) "" ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> string(6) "foobar" ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> NULL ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(1) ["b:protected"]=> int(2) ["c:private"]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } ["b:protected"]=> array(3) { [0]=> int(4) [1]=> int(5) [2]=> int(6) } ["c:private"]=> array(3) { [0]=> int(7) [1]=> int(8) [2]=> int(9) } } OK object(Obj)#%d (4) { ["a"]=> int(1) ["b:protected"]=> int(2) ["c:private"]=> int(3) [3]=> int(4) } SKIP object(Obj)#%d (3) { ["a"]=> string(3) "foo" ["b:protected"]=> string(6) "foobar" ["c:private"]=> string(4) "hoge" } OK object(Obj)#%d (3) { ["a"]=> int(1) ["b:protected"]=> int(2) ["c:private"]=> NULL } OK object(Obj)#%d (5) { ["a"]=> NULL ["b:protected"]=> NULL ["c:private"]=> NULL ["one"]=> int(1) ["two"]=> int(2) } OK object(Obj)#%d (3) { ["a"]=> int(1) ["b:protected"]=> int(2) ["c:private"]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> int(1) ["b:protected"]=> int(2) ["c:private"]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> int(1) ["b:protected"]=> int(2) ["c:private"]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> array(1) { [0]=> string(3) "foo" } ["b:protected"]=> array(1) { [0]=> string(3) "foo" } ["c:private"]=> NULL } OK object(Obj)#%d (4) { ["a"]=> array(2) { ["b"]=> string(1) "c" ["d"]=> string(1) "e" } ["b:protected"]=> NULL ["c:private"]=> NULL ["f"]=> array(1) { ["g"]=> string(1) "h" } } OK object(Obj)#%d (3) { ["a"]=> int(1) ["b:protected"]=> int(2) ["c:private"]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> int(1) ["b:protected"]=> int(2) ["c:private"]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } ["b:protected"]=> array(3) { [0]=> int(4) [1]=> int(5) [2]=> int(6) } ["c:private"]=> NULL } OK msgpack-0.5.5/tests/099.phpt0000644000077100007710000002435512110565607015420 0ustar xinchenxinchen--TEST-- unpack of object converter : class unpacker (string) --SKIPIF-- pack($variable); $unserialized = null; $unpacker = $msgpack->unpacker(); if ($unpacker->execute($serialized)) { $unserialized = $unpacker->data($object); } var_dump($unserialized); if ($result) { echo $unserialized == $result ? 'OK' : 'ERROR', PHP_EOL; } else { echo 'SKIP', PHP_EOL; } } class Obj { public $a; protected $b; private $c; public function __construct($a = null, $b = null, $c = null, $d = null) { $this->a = $a; $this->b = $b; $this->c = $c; if (is_array($d)) { foreach ($d as $key => $val) { $this->{$key} = $val; } } } } test('null', null, 'Obj', new Obj(null, null, null)); test('bool: true', true, 'Obj', new Obj(true, null, null)); test('bool: false', false, 'Obj', new Obj(false, null, null)); test('zero: 0', 0, 'Obj', new Obj(0, null, null)); test('small: 1', 1, 'Obj', new Obj(1, null, null)); test('small: -1', -1, 'Obj', new Obj(-1, null, null)); test('medium: 1000', 1000, 'Obj', new Obj(1000, null, null)); test('medium: -1000', -1000, 'Obj', new Obj(-1000, null, null)); test('large: 100000', 100000, 'Obj', new Obj(100000, null, null)); test('large: -100000', -100000, 'Obj', new Obj(-100000, null, null)); test('double: 123.456', 123.456, 'Obj', new Obj(123.456, null, null)); test('empty: ""', "", 'Obj', new Obj("", null, null)); test('string: "foobar"', "foobar", 'Obj', new Obj("foobar", null, null)); test('array: empty', array(), 'Obj', new Obj(null, null, null)); test('array(1, 2, 3)', array(1, 2, 3), 'Obj', new Obj(1, 2, 3)); test('array(array(1, 2, 3), arr...', array(array(1, 2, 3), array(4, 5, 6), array(7, 8, 9)), 'Obj', new Obj(array(1, 2, 3), array(4, 5, 6), array(7, 8, 9))); test('array(1, 2, 3, 4)', array(1, 2, 3, 4), 'Obj'); test('array("foo", "foobar", "foohoge")', array("foo", "foobar", "hoge"), 'Obj', new Obj("foo", "foobar", "hoge")); test('array("a" => 1, "b" => 2))', array("a" => 1, "b" => 2), 'Obj', new Obj(1, 2, null)); test('array("one" => 1, "two" => 2))', array("one" => 1, "two" => 2), 'Obj', new Obj(null, null, null, array("one" => 1, "two" => 2))); test('array("" => "empty")', array("" => "empty"), 'Obj'); test('array("a" => 1, "b" => 2, 3))', array("a" => 1, "b" => 2, 3), 'Obj', new Obj(1, 2, 3)); test('array(3, "a" => 1, "b" => 2))', array(3, "a" => 1, "b" => 2), 'Obj', new Obj(1, 2, 3)); test('array("a" => 1, 3, "b" => 2))', array("a" => 1, 3, "b" => 2), 'Obj', new Obj(1, 2, 3)); $a = array('foo'); test('array($a, $a)', array($a, $a), 'Obj', new Obj($a, $a, null)); test('array(&$a, &$a)', array(&$a, &$a), 'Obj', new Obj($a, $a, null)); test('array(&$a, $a)', array($a, &$a), 'Obj', new Obj($a, $a, null)); test('array(&$a, $a)', array(&$a, $a), 'Obj', new Obj($a, $a, null)); $a = array( 'a' => array( 'b' => 'c', 'd' => 'e' ), 'f' => array( 'g' => 'h' ) ); test('array', $a, 'Obj', new Obj(null, null, null, $a)); $o = new Obj(1, 2, 3); test('object', $o, 'Obj', new Obj(1, 2, 3)); class Obj2 { public $A; protected $B; private $C; function __construct($a, $b, $c) { $this->A = $a; $this->B = $b; $this->C = $c; } } $o = new Obj2(1, 2, 3); test('object', $o, 'Obj', new Obj($o)); $o1 = new Obj2(1, 2, 3); $o2 = new Obj2(4, 5, 6); test('object', array($o1, $o2), 'Obj', new Obj($o1, $o2)); $o = new Obj2(1, 2, 3); test('object', array(&$o, &$o), 'Obj', new Obj($o, $o)); $o = new Obj2(1, 2, 3); test('object', array(&$o, $o), 'Obj', new Obj($o, $o)); $o = new Obj2(1, 2, 3); test('object', array($o, &$o), 'Obj', new Obj($o, $o)); --EXPECTF-- object(Obj)#%d (3) { ["a"]=> NULL [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> bool(true) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> bool(false) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(0) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(-1) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(1000) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(-1000) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(100000) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(-100000) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> float(123.456) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> string(0) "" [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> string(6) "foobar" [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> NULL [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } [%r"?b"?:protected"?%r]=> array(3) { [0]=> int(4) [1]=> int(5) [2]=> int(6) } [%r"?c"?:("Obj":)?private"?%r]=> array(3) { [0]=> int(7) [1]=> int(8) [2]=> int(9) } } OK object(Obj)#%d (4) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) [3]=> int(4) } SKIP object(Obj)#%d (3) { ["a"]=> string(3) "foo" [%r"?b"?:protected"?%r]=> string(6) "foobar" [%r"?c"?:("Obj":)?private"?%r]=> string(4) "hoge" } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (5) { ["a"]=> NULL [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL ["one"]=> int(1) ["two"]=> int(2) } OK object(Obj)#%d (4) { ["a"]=> NULL [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL [""]=> string(5) "empty" } SKIP object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> array(1) { [0]=> string(3) "foo" } [%r"?b"?:protected"?%r]=> array(1) { [0]=> string(3) "foo" } [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> &array(1) { [0]=> string(3) "foo" } [%r"?b"?:protected"?%r]=> &array(1) { [0]=> string(3) "foo" } [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> array(1) { [0]=> string(3) "foo" } [%r"?b"?:protected"?%r]=> &array(1) { [0]=> string(3) "foo" } [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> &array(1) { [0]=> string(3) "foo" } [%r"?b"?:protected"?%r]=> array(1) { [0]=> string(3) "foo" } [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (4) { ["a"]=> array(2) { ["b"]=> string(1) "c" ["d"]=> string(1) "e" } [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL ["f"]=> array(1) { ["g"]=> string(1) "h" } } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> object(Obj2)#%d (3) { ["A"]=> int(1) [%r"?B"?:protected"?%r]=> int(2) [%r"?C"?:("Obj2":)?private"?%r]=> int(3) } [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> object(Obj2)#%d (3) { ["A"]=> int(1) [%r"?B"?:protected"?%r]=> int(2) [%r"?C"?:("Obj2":)?private"?%r]=> int(3) } [%r"?b"?:protected"?%r]=> object(Obj2)#%d (3) { ["A"]=> int(4) [%r"?B"?:protected"?%r]=> int(5) [%r"?C"?:("Obj2":)?private"?%r]=> int(6) } [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> &object(Obj2)#%d (3) { ["A"]=> int(1) [%r"?B"?:protected"?%r]=> int(2) [%r"?C"?:("Obj2":)?private"?%r]=> int(3) } [%r"?b"?:protected"?%r]=> &object(Obj2)#%d (3) { ["A"]=> int(1) [%r"?B"?:protected"?%r]=> int(2) [%r"?C"?:("Obj2":)?private"?%r]=> int(3) } [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> object(Obj2)#%d (3) { ["A"]=> int(1) [%r"?B"?:protected"?%r]=> int(2) [%r"?C"?:("Obj2":)?private"?%r]=> int(3) } [%r"?b"?:protected"?%r]=> object(Obj2)#%d (3) { ["A"]=> int(1) [%r"?B"?:protected"?%r]=> int(2) [%r"?C"?:("Obj2":)?private"?%r]=> int(3) } [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> &object(Obj2)#%d (3) { ["A"]=> int(1) [%r"?B"?:protected"?%r]=> int(2) [%r"?C"?:("Obj2":)?private"?%r]=> int(3) } [%r"?b"?:protected"?%r]=> &object(Obj2)#%d (3) { ["A"]=> int(1) [%r"?B"?:protected"?%r]=> int(2) [%r"?C"?:("Obj2":)?private"?%r]=> int(3) } [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK msgpack-0.5.5/tests/099b.phpt0000644000077100007710000002174012110565607015555 0ustar xinchenxinchen--TEST-- unpack of object converter : class unpacker (string) --SKIPIF-- = 0) { echo "skip tests in PHP 5.1 or older"; } --FILE-- pack($variable); $unserialized = null; $unpacker = $msgpack->unpacker(); if ($unpacker->execute($serialized)) { $unserialized = $unpacker->data($object); } var_dump($unserialized); if ($result) { echo $unserialized == $result ? 'OK' : 'ERROR', PHP_EOL; } else { echo 'SKIP', PHP_EOL; } } class Obj { public $a; protected $b; private $c; public function __construct($a = null, $b = null, $c = null, $d = null) { $this->a = $a; $this->b = $b; $this->c = $c; if (is_array($d)) { foreach ($d as $key => $val) { $this->{$key} = $val; } } } } test('null', null, 'Obj', new Obj(null, null, null)); test('bool: true', true, 'Obj', new Obj(true, null, null)); test('bool: false', false, 'Obj', new Obj(false, null, null)); test('zero: 0', 0, 'Obj', new Obj(0, null, null)); test('small: 1', 1, 'Obj', new Obj(1, null, null)); test('small: -1', -1, 'Obj', new Obj(-1, null, null)); test('medium: 1000', 1000, 'Obj', new Obj(1000, null, null)); test('medium: -1000', -1000, 'Obj', new Obj(-1000, null, null)); test('large: 100000', 100000, 'Obj', new Obj(100000, null, null)); test('large: -100000', -100000, 'Obj', new Obj(-100000, null, null)); test('double: 123.456', 123.456, 'Obj', new Obj(123.456, null, null)); test('empty: ""', "", 'Obj', new Obj("", null, null)); test('string: "foobar"', "foobar", 'Obj', new Obj("foobar", null, null)); test('array: empty', array(), 'Obj', new Obj(null, null, null)); test('array(1, 2, 3)', array(1, 2, 3), 'Obj', new Obj(1, 2, 3)); test('array(array(1, 2, 3), arr...', array(array(1, 2, 3), array(4, 5, 6), array(7, 8, 9)), 'Obj', new Obj(array(1, 2, 3), array(4, 5, 6), array(7, 8, 9))); test('array(1, 2, 3, 4)', array(1, 2, 3, 4), 'Obj'); test('array("foo", "foobar", "foohoge")', array("foo", "foobar", "hoge"), 'Obj', new Obj("foo", "foobar", "hoge")); test('array("a" => 1, "b" => 2))', array("a" => 1, "b" => 2), 'Obj', new Obj(1, 2, null)); test('array("one" => 1, "two" => 2))', array("one" => 1, "two" => 2), 'Obj', new Obj(null, null, null, array("one" => 1, "two" => 2))); test('array("a" => 1, "b" => 2, 3))', array("a" => 1, "b" => 2, 3), 'Obj', new Obj(1, 2, 3)); test('array(3, "a" => 1, "b" => 2))', array(3, "a" => 1, "b" => 2), 'Obj', new Obj(1, 2, 3)); test('array("a" => 1, 3, "b" => 2))', array("a" => 1, 3, "b" => 2), 'Obj', new Obj(1, 2, 3)); $a = array('foo'); test('array($a, $a)', array($a, $a), 'Obj', new Obj($a, $a, null)); test('array(&$a, &$a)', array(&$a, &$a), 'Obj', new Obj($a, $a, null)); test('array(&$a, $a)', array($a, &$a), 'Obj', new Obj($a, $a, null)); test('array(&$a, $a)', array(&$a, $a), 'Obj', new Obj($a, $a, null)); $a = array( 'a' => array( 'b' => 'c', 'd' => 'e' ), 'f' => array( 'g' => 'h' ) ); test('array', $a, 'Obj', new Obj(null, null, null, $a)); $o = new Obj(1, 2, 3); test('object', $o, 'Obj', new Obj(1, 2, 3)); class Obj2 { public $A; protected $B; private $C; function __construct($a, $b, $c) { $this->A = $a; $this->B = $b; $this->C = $c; } } $o = new Obj2(1, 2, 3); test('object', $o, 'Obj', new Obj($o)); $o1 = new Obj2(1, 2, 3); $o2 = new Obj2(4, 5, 6); test('object', array($o1, $o2), 'Obj', new Obj($o1, $o2)); $o = new Obj2(1, 2, 3); test('object', array(&$o, &$o), 'Obj', new Obj($o, $o)); $o = new Obj2(1, 2, 3); test('object', array(&$o, $o), 'Obj', new Obj($o, $o)); $o = new Obj2(1, 2, 3); test('object', array($o, &$o), 'Obj', new Obj($o, $o)); --EXPECTF-- object(Obj)#%d (3) { ["a"]=> NULL ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> bool(true) ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> bool(false) ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(0) ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(1) ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(-1) ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(1000) ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(-1000) ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(100000) ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(-100000) ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> float(123.456) ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> string(0) "" ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> string(6) "foobar" ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> NULL ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(1) ["b:protected"]=> int(2) ["c:private"]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } ["b:protected"]=> array(3) { [0]=> int(4) [1]=> int(5) [2]=> int(6) } ["c:private"]=> array(3) { [0]=> int(7) [1]=> int(8) [2]=> int(9) } } OK object(Obj)#%d (4) { ["a"]=> int(1) ["b:protected"]=> int(2) ["c:private"]=> int(3) [3]=> int(4) } SKIP object(Obj)#%d (3) { ["a"]=> string(3) "foo" ["b:protected"]=> string(6) "foobar" ["c:private"]=> string(4) "hoge" } OK object(Obj)#%d (3) { ["a"]=> int(1) ["b:protected"]=> int(2) ["c:private"]=> NULL } OK object(Obj)#%d (5) { ["a"]=> NULL ["b:protected"]=> NULL ["c:private"]=> NULL ["one"]=> int(1) ["two"]=> int(2) } OK object(Obj)#%d (3) { ["a"]=> int(1) ["b:protected"]=> int(2) ["c:private"]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> int(1) ["b:protected"]=> int(2) ["c:private"]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> int(1) ["b:protected"]=> int(2) ["c:private"]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> array(1) { [0]=> string(3) "foo" } ["b:protected"]=> array(1) { [0]=> string(3) "foo" } ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> &array(1) { [0]=> string(3) "foo" } ["b:protected"]=> &array(1) { [0]=> string(3) "foo" } ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> array(1) { [0]=> string(3) "foo" } ["b:protected"]=> &array(1) { [0]=> string(3) "foo" } ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> &array(1) { [0]=> string(3) "foo" } ["b:protected"]=> array(1) { [0]=> string(3) "foo" } ["c:private"]=> NULL } OK object(Obj)#%d (4) { ["a"]=> array(2) { ["b"]=> string(1) "c" ["d"]=> string(1) "e" } ["b:protected"]=> NULL ["c:private"]=> NULL ["f"]=> array(1) { ["g"]=> string(1) "h" } } OK object(Obj)#%d (3) { ["a"]=> int(1) ["b:protected"]=> int(2) ["c:private"]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> object(Obj2)#%d (3) { ["A"]=> int(1) ["B:protected"]=> int(2) ["C:private"]=> int(3) } ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> object(Obj2)#%d (3) { ["A"]=> int(1) ["B:protected"]=> int(2) ["C:private"]=> int(3) } ["b:protected"]=> object(Obj2)#%d (3) { ["A"]=> int(4) ["B:protected"]=> int(5) ["C:private"]=> int(6) } ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> &object(Obj2)#%d (3) { ["A"]=> int(1) ["B:protected"]=> int(2) ["C:private"]=> int(3) } ["b:protected"]=> &object(Obj2)#%d (3) { ["A"]=> int(1) ["B:protected"]=> int(2) ["C:private"]=> int(3) } ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> object(Obj2)#%d (3) { ["A"]=> int(1) ["B:protected"]=> int(2) ["C:private"]=> int(3) } ["b:protected"]=> object(Obj2)#%d (3) { ["A"]=> int(1) ["B:protected"]=> int(2) ["C:private"]=> int(3) } ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> &object(Obj2)#%d (3) { ["A"]=> int(1) ["B:protected"]=> int(2) ["C:private"]=> int(3) } ["b:protected"]=> &object(Obj2)#%d (3) { ["A"]=> int(1) ["B:protected"]=> int(2) ["C:private"]=> int(3) } ["c:private"]=> NULL } OK msgpack-0.5.5/tests/100.phpt0000644000077100007710000002461712110565607015400 0ustar xinchenxinchen--TEST-- unpack of object converter : class unpacker (object) --SKIPIF-- pack($variable); $unserialized = null; $unpacker = $msgpack->unpacker(); if ($unpacker->execute($serialized)) { $unserialized = $unpacker->data($object); } var_dump($unserialized); if ($result) { echo $unserialized == $result ? 'OK' : 'ERROR', PHP_EOL; } else { echo 'SKIP', PHP_EOL; } } class Obj { public $a; protected $b; private $c; public function __construct($a = null, $b = null, $c = null, $d = null) { $this->a = $a; $this->b = $b; $this->c = $c; if (is_array($d)) { foreach ($d as $key => $val) { $this->{$key} = $val; } } } } $object = new Obj(); test('null', null, new Obj(), new Obj(null, null, null)); test('bool: true', true, new Obj(), new Obj(true, null, null)); test('bool: false', false, new Obj(), new Obj(false, null, null)); test('zero: 0', 0, new Obj(), new Obj(0, null, null)); test('small: 1', 1, new Obj(), new Obj(1, null, null)); test('small: -1', -1, new Obj(), new Obj(-1, null, null)); test('medium: 1000', 1000, new Obj(), new Obj(1000, null, null)); test('medium: -1000', -1000, new Obj(), new Obj(-1000, null, null)); test('large: 100000', 100000, new Obj(), new Obj(100000, null, null)); test('large: -100000', -100000, new Obj(), new Obj(-100000, null, null)); test('double: 123.456', 123.456, new Obj(), new Obj(123.456, null, null)); test('empty: ""', "", new Obj(), new Obj("", null, null)); test('string: "foobar"', "foobar", new Obj(), new Obj("foobar", null, null)); test('array: empty', array(), new Obj(), new Obj(null, null, null)); test('array(1, 2, 3)', array(1, 2, 3), new Obj(), new Obj(1, 2, 3)); test('array(array(1, 2, 3), arr...', array(array(1, 2, 3), array(4, 5, 6), array(7, 8, 9)), new Obj(), new Obj(array(1, 2, 3), array(4, 5, 6), array(7, 8, 9))); test('array(1, 2, 3, 4)', array(1, 2, 3, 4), new Obj()); test('array("foo", "foobar", "foohoge")', array("foo", "foobar", "hoge"), new Obj(), new Obj("foo", "foobar", "hoge")); test('array("a" => 1, "b" => 2))', array("a" => 1, "b" => 2), new Obj(), new Obj(1, 2, null)); test('array("one" => 1, "two" => 2))', array("one" => 1, "two" => 2), new Obj(), new Obj(null, null, null, array("one" => 1, "two" => 2))); test('array("" => "empty")', array("" => "empty"), new Obj()); test('array("a" => 1, "b" => 2, 3))', array("a" => 1, "b" => 2, 3), new Obj(), new Obj(1, 2, 3)); test('array(3, "a" => 1, "b" => 2))', array(3, "a" => 1, "b" => 2), new Obj(), new Obj(1, 2, 3)); test('array("a" => 1, 3, "b" => 2))', array("a" => 1, 3, "b" => 2), new Obj(), new Obj(1, 2, 3)); $a = array('foo'); test('array($a, $a)', array($a, $a), new Obj(), new Obj($a, $a, null)); test('array(&$a, &$a)', array(&$a, &$a), new Obj(), new Obj($a, $a, null)); test('array(&$a, $a)', array($a, &$a), new Obj(), new Obj($a, $a, null)); test('array(&$a, $a)', array(&$a, $a), new Obj(), new Obj($a, $a, null)); $a = array( 'a' => array( 'b' => 'c', 'd' => 'e' ), 'f' => array( 'g' => 'h' ) ); test('array', $a, new Obj(), new Obj(null, null, null, $a)); $o = new Obj(1, 2, 3); test('object', $o, new Obj(), new Obj(1, 2, 3)); class Obj2 { public $A; protected $B; private $C; function __construct($a, $b, $c) { $this->A = $a; $this->B = $b; $this->C = $c; } } $o = new Obj2(1, 2, 3); test('object', $o, new Obj(), new Obj($o)); $o1 = new Obj2(1, 2, 3); $o2 = new Obj2(4, 5, 6); test('object', array($o1, $o2), new Obj(), new Obj($o1, $o2)); $o = new Obj2(1, 2, 3); test('object', array(&$o, &$o), new Obj(), new Obj($o, $o)); $o = new Obj2(1, 2, 3); test('object', array(&$o, $o), new Obj(), new Obj($o, $o)); $o = new Obj2(1, 2, 3); test('object', array($o, &$o), new Obj(), new Obj($o, $o)); --EXPECTF-- object(Obj)#%d (3) { ["a"]=> NULL [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> bool(true) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> bool(false) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(0) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(-1) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(1000) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(-1000) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(100000) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(-100000) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> float(123.456) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> string(0) "" [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> string(6) "foobar" [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> NULL [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } [%r"?b"?:protected"?%r]=> array(3) { [0]=> int(4) [1]=> int(5) [2]=> int(6) } [%r"?c"?:("Obj":)?private"?%r]=> array(3) { [0]=> int(7) [1]=> int(8) [2]=> int(9) } } OK object(Obj)#%d (4) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) [3]=> int(4) } SKIP object(Obj)#%d (3) { ["a"]=> string(3) "foo" [%r"?b"?:protected"?%r]=> string(6) "foobar" [%r"?c"?:("Obj":)?private"?%r]=> string(4) "hoge" } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (5) { ["a"]=> NULL [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL ["one"]=> int(1) ["two"]=> int(2) } OK object(Obj)#%d (4) { ["a"]=> NULL [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL [""]=> string(5) "empty" } SKIP object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> array(1) { [0]=> string(3) "foo" } [%r"?b"?:protected"?%r]=> array(1) { [0]=> string(3) "foo" } [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> &array(1) { [0]=> string(3) "foo" } [%r"?b"?:protected"?%r]=> &array(1) { [0]=> string(3) "foo" } [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> array(1) { [0]=> string(3) "foo" } [%r"?b"?:protected"?%r]=> &array(1) { [0]=> string(3) "foo" } [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> &array(1) { [0]=> string(3) "foo" } [%r"?b"?:protected"?%r]=> array(1) { [0]=> string(3) "foo" } [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (4) { ["a"]=> array(2) { ["b"]=> string(1) "c" ["d"]=> string(1) "e" } [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL ["f"]=> array(1) { ["g"]=> string(1) "h" } } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> object(Obj2)#%d (3) { ["A"]=> int(1) [%r"?B"?:protected"?%r]=> int(2) [%r"?C"?:("Obj2":)?private"?%r]=> int(3) } [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> object(Obj2)#%d (3) { ["A"]=> int(1) [%r"?B"?:protected"?%r]=> int(2) [%r"?C"?:("Obj2":)?private"?%r]=> int(3) } [%r"?b"?:protected"?%r]=> object(Obj2)#%d (3) { ["A"]=> int(4) [%r"?B"?:protected"?%r]=> int(5) [%r"?C"?:("Obj2":)?private"?%r]=> int(6) } [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> &object(Obj2)#%d (3) { ["A"]=> int(1) [%r"?B"?:protected"?%r]=> int(2) [%r"?C"?:("Obj2":)?private"?%r]=> int(3) } [%r"?b"?:protected"?%r]=> &object(Obj2)#%d (3) { ["A"]=> int(1) [%r"?B"?:protected"?%r]=> int(2) [%r"?C"?:("Obj2":)?private"?%r]=> int(3) } [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> object(Obj2)#%d (3) { ["A"]=> int(1) [%r"?B"?:protected"?%r]=> int(2) [%r"?C"?:("Obj2":)?private"?%r]=> int(3) } [%r"?b"?:protected"?%r]=> object(Obj2)#%d (3) { ["A"]=> int(1) [%r"?B"?:protected"?%r]=> int(2) [%r"?C"?:("Obj2":)?private"?%r]=> int(3) } [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> &object(Obj2)#%d (3) { ["A"]=> int(1) [%r"?B"?:protected"?%r]=> int(2) [%r"?C"?:("Obj2":)?private"?%r]=> int(3) } [%r"?b"?:protected"?%r]=> &object(Obj2)#%d (3) { ["A"]=> int(1) [%r"?B"?:protected"?%r]=> int(2) [%r"?C"?:("Obj2":)?private"?%r]=> int(3) } [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK msgpack-0.5.5/tests/100b.phpt0000644000077100007710000002215012110565607015530 0ustar xinchenxinchen--TEST-- unpack of object converter : class unpacker (object) --SKIPIF-- = 0) { echo "skip tests in PHP 5.1 or older"; } --FILE-- pack($variable); $unserialized = null; $unpacker = $msgpack->unpacker(); if ($unpacker->execute($serialized)) { $unserialized = $unpacker->data($object); } var_dump($unserialized); if ($result) { echo $unserialized == $result ? 'OK' : 'ERROR', PHP_EOL; } else { echo 'SKIP', PHP_EOL; } } class Obj { public $a; protected $b; private $c; public function __construct($a = null, $b = null, $c = null, $d = null) { $this->a = $a; $this->b = $b; $this->c = $c; if (is_array($d)) { foreach ($d as $key => $val) { $this->{$key} = $val; } } } } test('null', null, new Obj(), new Obj(null, null, null)); test('bool: true', true, new Obj(), new Obj(true, null, null)); test('bool: false', false, new Obj(), new Obj(false, null, null)); test('zero: 0', 0, new Obj(), new Obj(0, null, null)); test('small: 1', 1, new Obj(), new Obj(1, null, null)); test('small: -1', -1, new Obj(), new Obj(-1, null, null)); test('medium: 1000', 1000, new Obj(), new Obj(1000, null, null)); test('medium: -1000', -1000, new Obj(), new Obj(-1000, null, null)); test('large: 100000', 100000, new Obj(), new Obj(100000, null, null)); test('large: -100000', -100000, new Obj(), new Obj(-100000, null, null)); test('double: 123.456', 123.456, new Obj(), new Obj(123.456, null, null)); test('empty: ""', "", new Obj(), new Obj("", null, null)); test('string: "foobar"', "foobar", new Obj(), new Obj("foobar", null, null)); test('array: empty', array(), new Obj(), new Obj(null, null, null)); test('array(1, 2, 3)', array(1, 2, 3), new Obj(), new Obj(1, 2, 3)); test('array(array(1, 2, 3), arr...', array(array(1, 2, 3), array(4, 5, 6), array(7, 8, 9)), new Obj(), new Obj(array(1, 2, 3), array(4, 5, 6), array(7, 8, 9))); test('array(1, 2, 3, 4)', array(1, 2, 3, 4), new Obj()); test('array("foo", "foobar", "foohoge")', array("foo", "foobar", "hoge"), new Obj(), new Obj("foo", "foobar", "hoge")); test('array("a" => 1, "b" => 2))', array("a" => 1, "b" => 2), new Obj(), new Obj(1, 2, null)); test('array("one" => 1, "two" => 2))', array("one" => 1, "two" => 2), new Obj(), new Obj(null, null, null, array("one" => 1, "two" => 2))); test('array("a" => 1, "b" => 2, 3))', array("a" => 1, "b" => 2, 3), new Obj(), new Obj(1, 2, 3)); test('array(3, "a" => 1, "b" => 2))', array(3, "a" => 1, "b" => 2), new Obj(), new Obj(1, 2, 3)); test('array("a" => 1, 3, "b" => 2))', array("a" => 1, 3, "b" => 2), new Obj(), new Obj(1, 2, 3)); $a = array('foo'); test('array($a, $a)', array($a, $a), new Obj(), new Obj($a, $a, null)); test('array(&$a, &$a)', array(&$a, &$a), new Obj(), new Obj($a, $a, null)); test('array(&$a, $a)', array($a, &$a), new Obj(), new Obj($a, $a, null)); test('array(&$a, $a)', array(&$a, $a), new Obj(), new Obj($a, $a, null)); $a = array( 'a' => array( 'b' => 'c', 'd' => 'e' ), 'f' => array( 'g' => 'h' ) ); test('array', $a, new Obj(), new Obj(null, null, null, $a)); $o = new Obj(1, 2, 3); test('object', $o, new Obj(), new Obj(1, 2, 3)); class Obj2 { public $A; protected $B; private $C; function __construct($a, $b, $c) { $this->A = $a; $this->B = $b; $this->C = $c; } } $o = new Obj2(1, 2, 3); test('object', $o, new Obj(), new Obj($o)); $o1 = new Obj2(1, 2, 3); $o2 = new Obj2(4, 5, 6); test('object', array($o1, $o2), new Obj(), new Obj($o1, $o2)); $o = new Obj2(1, 2, 3); test('object', array(&$o, &$o), new Obj(), new Obj($o, $o)); $o = new Obj2(1, 2, 3); test('object', array(&$o, $o), new Obj(), new Obj($o, $o)); $o = new Obj2(1, 2, 3); test('object', array($o, &$o), new Obj(), new Obj($o, $o)); --EXPECTF-- object(Obj)#%d (3) { ["a"]=> NULL ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> bool(true) ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> bool(false) ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(0) ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(1) ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(-1) ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(1000) ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(-1000) ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(100000) ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(-100000) ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> float(123.456) ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> string(0) "" ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> string(6) "foobar" ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> NULL ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(1) ["b:protected"]=> int(2) ["c:private"]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } ["b:protected"]=> array(3) { [0]=> int(4) [1]=> int(5) [2]=> int(6) } ["c:private"]=> array(3) { [0]=> int(7) [1]=> int(8) [2]=> int(9) } } OK object(Obj)#%d (4) { ["a"]=> int(1) ["b:protected"]=> int(2) ["c:private"]=> int(3) [3]=> int(4) } SKIP object(Obj)#%d (3) { ["a"]=> string(3) "foo" ["b:protected"]=> string(6) "foobar" ["c:private"]=> string(4) "hoge" } OK object(Obj)#%d (3) { ["a"]=> int(1) ["b:protected"]=> int(2) ["c:private"]=> NULL } OK object(Obj)#%d (5) { ["a"]=> NULL ["b:protected"]=> NULL ["c:private"]=> NULL ["one"]=> int(1) ["two"]=> int(2) } OK object(Obj)#%d (3) { ["a"]=> int(1) ["b:protected"]=> int(2) ["c:private"]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> int(1) ["b:protected"]=> int(2) ["c:private"]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> int(1) ["b:protected"]=> int(2) ["c:private"]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> array(1) { [0]=> string(3) "foo" } ["b:protected"]=> array(1) { [0]=> string(3) "foo" } ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> &array(1) { [0]=> string(3) "foo" } ["b:protected"]=> &array(1) { [0]=> string(3) "foo" } ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> array(1) { [0]=> string(3) "foo" } ["b:protected"]=> &array(1) { [0]=> string(3) "foo" } ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> &array(1) { [0]=> string(3) "foo" } ["b:protected"]=> array(1) { [0]=> string(3) "foo" } ["c:private"]=> NULL } OK object(Obj)#%d (4) { ["a"]=> array(2) { ["b"]=> string(1) "c" ["d"]=> string(1) "e" } ["b:protected"]=> NULL ["c:private"]=> NULL ["f"]=> array(1) { ["g"]=> string(1) "h" } } OK object(Obj)#%d (3) { ["a"]=> int(1) ["b:protected"]=> int(2) ["c:private"]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> object(Obj2)#%d (3) { ["A"]=> int(1) ["B:protected"]=> int(2) ["C:private"]=> int(3) } ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> object(Obj2)#%d (3) { ["A"]=> int(1) ["B:protected"]=> int(2) ["C:private"]=> int(3) } ["b:protected"]=> object(Obj2)#%d (3) { ["A"]=> int(4) ["B:protected"]=> int(5) ["C:private"]=> int(6) } ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> &object(Obj2)#%d (3) { ["A"]=> int(1) ["B:protected"]=> int(2) ["C:private"]=> int(3) } ["b:protected"]=> &object(Obj2)#%d (3) { ["A"]=> int(1) ["B:protected"]=> int(2) ["C:private"]=> int(3) } ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> object(Obj2)#%d (3) { ["A"]=> int(1) ["B:protected"]=> int(2) ["C:private"]=> int(3) } ["b:protected"]=> object(Obj2)#%d (3) { ["A"]=> int(1) ["B:protected"]=> int(2) ["C:private"]=> int(3) } ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> &object(Obj2)#%d (3) { ["A"]=> int(1) ["B:protected"]=> int(2) ["C:private"]=> int(3) } ["b:protected"]=> &object(Obj2)#%d (3) { ["A"]=> int(1) ["B:protected"]=> int(2) ["C:private"]=> int(3) } ["c:private"]=> NULL } OK msgpack-0.5.5/tests/101.phpt0000644000077100007710000001760512110565607015400 0ustar xinchenxinchen--TEST-- unpack of object converter : class unpacker (string: php_only=0) --SKIPIF-- pack($variable); $unserialized = null; $unpacker = $msgpack->unpacker(); if ($unpacker->execute($serialized)) { $unserialized = $unpacker->data($object); } var_dump($unserialized); if ($result) { echo $unserialized == $result ? 'OK' : 'ERROR', PHP_EOL; } else { echo 'SKIP', PHP_EOL; } } class Obj { public $a; protected $b; private $c; public function __construct($a = null, $b = null, $c = null, $d = null) { $this->a = $a; $this->b = $b; $this->c = $c; if (is_array($d)) { foreach ($d as $key => $val) { $this->{$key} = $val; } } } } test('null', null, 'Obj', new Obj(null, null, null)); test('bool: true', true, 'Obj', new Obj(true, null, null)); test('bool: false', false, 'Obj', new Obj(false, null, null)); test('zero: 0', 0, 'Obj', new Obj(0, null, null)); test('small: 1', 1, 'Obj', new Obj(1, null, null)); test('small: -1', -1, 'Obj', new Obj(-1, null, null)); test('medium: 1000', 1000, 'Obj', new Obj(1000, null, null)); test('medium: -1000', -1000, 'Obj', new Obj(-1000, null, null)); test('large: 100000', 100000, 'Obj', new Obj(100000, null, null)); test('large: -100000', -100000, 'Obj', new Obj(-100000, null, null)); test('double: 123.456', 123.456, 'Obj', new Obj(123.456, null, null)); test('empty: ""', "", 'Obj', new Obj("", null, null)); test('string: "foobar"', "foobar", 'Obj', new Obj("foobar", null, null)); test('array: empty', array(), 'Obj', new Obj(null, null, null)); test('array(1, 2, 3)', array(1, 2, 3), 'Obj', new Obj(1, 2, 3)); test('array(array(1, 2, 3), arr...', array(array(1, 2, 3), array(4, 5, 6), array(7, 8, 9)), 'Obj', new Obj(array(1, 2, 3), array(4, 5, 6), array(7, 8, 9))); test('array(1, 2, 3, 4)', array(1, 2, 3, 4), 'Obj'); test('array("foo", "foobar", "foohoge")', array("foo", "foobar", "hoge"), 'Obj', new Obj("foo", "foobar", "hoge")); test('array("a" => 1, "b" => 2))', array("a" => 1, "b" => 2), 'Obj', new Obj(1, 2, null)); test('array("one" => 1, "two" => 2))', array("one" => 1, "two" => 2), 'Obj', new Obj(null, null, null, array("one" => 1, "two" => 2))); test('array("" => "empty")', array("" => "empty"), 'Obj'); test('array("a" => 1, "b" => 2, 3))', array("a" => 1, "b" => 2, 3), 'Obj', new Obj(1, 2, 3)); test('array(3, "a" => 1, "b" => 2))', array(3, "a" => 1, "b" => 2), 'Obj', new Obj(1, 2, 3)); test('array("a" => 1, 3, "b" => 2))', array("a" => 1, 3, "b" => 2), 'Obj', new Obj(1, 2, 3)); $a = array('foo'); test('array($a, $a)', array($a, $a), 'Obj', new Obj($a, $a, null)); $a = array( 'a' => array( 'b' => 'c', 'd' => 'e' ), 'f' => array( 'g' => 'h' ) ); test('array', $a, 'Obj', new Obj(null, null, null, $a)); $o = new Obj(1, 2, 3); test('object', $o, 'Obj', new Obj(1, 2, 3)); class Obj2 { public $A; protected $B; private $C; function __construct($a, $b, $c) { $this->A = $a; $this->B = $b; $this->C = $c; } } $o = new Obj2(1, 2, 3); test('object', $o, 'Obj', new Obj(1, 2, 3)); $o1 = new Obj2(1, 2, 3); $o2 = new Obj2(4, 5, 6); test('object', array($o1, $o2), 'Obj', new Obj(array(1, 2, 3), array(4, 5, 6))); --EXPECTF-- object(Obj)#%d (3) { ["a"]=> NULL [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> bool(true) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> bool(false) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(0) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(-1) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(1000) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(-1000) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(100000) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(-100000) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> float(123.456) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> string(0) "" [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> string(6) "foobar" [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> NULL [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } [%r"?b"?:protected"?%r]=> array(3) { [0]=> int(4) [1]=> int(5) [2]=> int(6) } [%r"?c"?:("Obj":)?private"?%r]=> array(3) { [0]=> int(7) [1]=> int(8) [2]=> int(9) } } OK object(Obj)#%d (4) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) [3]=> int(4) } SKIP object(Obj)#%d (3) { ["a"]=> string(3) "foo" [%r"?b"?:protected"?%r]=> string(6) "foobar" [%r"?c"?:("Obj":)?private"?%r]=> string(4) "hoge" } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (5) { ["a"]=> NULL [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL ["one"]=> int(1) ["two"]=> int(2) } OK object(Obj)#%d (4) { ["a"]=> NULL [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL [""]=> string(5) "empty" } SKIP object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> array(1) { [0]=> string(3) "foo" } [%r"?b"?:protected"?%r]=> array(1) { [0]=> string(3) "foo" } [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (4) { ["a"]=> array(2) { ["b"]=> string(1) "c" ["d"]=> string(1) "e" } [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL ["f"]=> array(1) { ["g"]=> string(1) "h" } } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } [%r"?b"?:protected"?%r]=> array(3) { [0]=> int(4) [1]=> int(5) [2]=> int(6) } [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK msgpack-0.5.5/tests/101b.phpt0000644000077100007710000001576612110565607015550 0ustar xinchenxinchen--TEST-- unpack of object converter : class unpack (string: php_only=0) --SKIPIF-- = 0) { echo "skip tests in PHP 5.1 or older"; } --FILE-- pack($variable); $unserialized = null; $unpacker = $msgpack->unpacker(); if ($unpacker->execute($serialized)) { $unserialized = $unpacker->data($object); } var_dump($unserialized); if ($result) { echo $unserialized == $result ? 'OK' : 'ERROR', PHP_EOL; } else { echo 'SKIP', PHP_EOL; } } class Obj { public $a; protected $b; private $c; public function __construct($a = null, $b = null, $c = null, $d = null) { $this->a = $a; $this->b = $b; $this->c = $c; if (is_array($d)) { foreach ($d as $key => $val) { $this->{$key} = $val; } } } } test('null', null, 'Obj', new Obj(null, null, null)); test('bool: true', true, 'Obj', new Obj(true, null, null)); test('bool: false', false, 'Obj', new Obj(false, null, null)); test('zero: 0', 0, 'Obj', new Obj(0, null, null)); test('small: 1', 1, 'Obj', new Obj(1, null, null)); test('small: -1', -1, 'Obj', new Obj(-1, null, null)); test('medium: 1000', 1000, 'Obj', new Obj(1000, null, null)); test('medium: -1000', -1000, 'Obj', new Obj(-1000, null, null)); test('large: 100000', 100000, 'Obj', new Obj(100000, null, null)); test('large: -100000', -100000, 'Obj', new Obj(-100000, null, null)); test('double: 123.456', 123.456, 'Obj', new Obj(123.456, null, null)); test('empty: ""', "", 'Obj', new Obj("", null, null)); test('string: "foobar"', "foobar", 'Obj', new Obj("foobar", null, null)); test('array: empty', array(), 'Obj', new Obj(null, null, null)); test('array(1, 2, 3)', array(1, 2, 3), 'Obj', new Obj(1, 2, 3)); test('array(array(1, 2, 3), arr...', array(array(1, 2, 3), array(4, 5, 6), array(7, 8, 9)), 'Obj', new Obj(array(1, 2, 3), array(4, 5, 6), array(7, 8, 9))); test('array(1, 2, 3, 4)', array(1, 2, 3, 4), 'Obj'); test('array("foo", "foobar", "foohoge")', array("foo", "foobar", "hoge"), 'Obj', new Obj("foo", "foobar", "hoge")); test('array("a" => 1, "b" => 2))', array("a" => 1, "b" => 2), 'Obj', new Obj(1, 2, null)); test('array("one" => 1, "two" => 2))', array("one" => 1, "two" => 2), 'Obj', new Obj(null, null, null, array("one" => 1, "two" => 2))); test('array("a" => 1, "b" => 2, 3))', array("a" => 1, "b" => 2, 3), 'Obj', new Obj(1, 2, 3)); test('array(3, "a" => 1, "b" => 2))', array(3, "a" => 1, "b" => 2), 'Obj', new Obj(1, 2, 3)); test('array("a" => 1, 3, "b" => 2))', array("a" => 1, 3, "b" => 2), 'Obj', new Obj(1, 2, 3)); $a = array('foo'); test('array($a, $a)', array($a, $a), 'Obj', new Obj($a, $a, null)); $a = array( 'a' => array( 'b' => 'c', 'd' => 'e' ), 'f' => array( 'g' => 'h' ) ); test('array', $a, 'Obj', new Obj(null, null, null, $a)); $o = new Obj(1, 2, 3); test('object', $o, 'Obj', new Obj(1, 2, 3)); class Obj2 { public $A; protected $B; private $C; function __construct($a, $b, $c) { $this->A = $a; $this->B = $b; $this->C = $c; } } $o = new Obj2(1, 2, 3); test('object', $o, 'Obj', new Obj(1, 2, 3)); $o1 = new Obj2(1, 2, 3); $o2 = new Obj2(4, 5, 6); test('object', array($o1, $o2), 'Obj', new Obj(array(1, 2, 3), array(4, 5, 6))); --EXPECTF-- object(Obj)#%d (3) { ["a"]=> NULL ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> bool(true) ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> bool(false) ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(0) ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(1) ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(-1) ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(1000) ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(-1000) ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(100000) ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(-100000) ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> float(123.456) ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> string(0) "" ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> string(6) "foobar" ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> NULL ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(1) ["b:protected"]=> int(2) ["c:private"]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } ["b:protected"]=> array(3) { [0]=> int(4) [1]=> int(5) [2]=> int(6) } ["c:private"]=> array(3) { [0]=> int(7) [1]=> int(8) [2]=> int(9) } } OK object(Obj)#%d (4) { ["a"]=> int(1) ["b:protected"]=> int(2) ["c:private"]=> int(3) [3]=> int(4) } SKIP object(Obj)#%d (3) { ["a"]=> string(3) "foo" ["b:protected"]=> string(6) "foobar" ["c:private"]=> string(4) "hoge" } OK object(Obj)#%d (3) { ["a"]=> int(1) ["b:protected"]=> int(2) ["c:private"]=> NULL } OK object(Obj)#%d (5) { ["a"]=> NULL ["b:protected"]=> NULL ["c:private"]=> NULL ["one"]=> int(1) ["two"]=> int(2) } OK object(Obj)#%d (3) { ["a"]=> int(1) ["b:protected"]=> int(2) ["c:private"]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> int(1) ["b:protected"]=> int(2) ["c:private"]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> int(1) ["b:protected"]=> int(2) ["c:private"]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> array(1) { [0]=> string(3) "foo" } ["b:protected"]=> array(1) { [0]=> string(3) "foo" } ["c:private"]=> NULL } OK object(Obj)#%d (4) { ["a"]=> array(2) { ["b"]=> string(1) "c" ["d"]=> string(1) "e" } ["b:protected"]=> NULL ["c:private"]=> NULL ["f"]=> array(1) { ["g"]=> string(1) "h" } } OK object(Obj)#%d (3) { ["a"]=> int(1) ["b:protected"]=> int(2) ["c:private"]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> int(1) ["b:protected"]=> int(2) ["c:private"]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } ["b:protected"]=> array(3) { [0]=> int(4) [1]=> int(5) [2]=> int(6) } ["c:private"]=> NULL } OK msgpack-0.5.5/tests/102.phpt0000644000077100007710000002001712110565607015370 0ustar xinchenxinchen--TEST-- unpack of object converter : class unpacker (object: php_only=0) --SKIPIF-- pack($variable); $unserialized = null; $unpacker = $msgpack->unpacker(); if ($unpacker->execute($serialized)) { $unserialized = $unpacker->data($object); } var_dump($unserialized); if ($result) { echo $unserialized == $result ? 'OK' : 'ERROR', PHP_EOL; } else { echo 'SKIP', PHP_EOL; } } class Obj { public $a; protected $b; private $c; public function __construct($a = null, $b = null, $c = null, $d = null) { $this->a = $a; $this->b = $b; $this->c = $c; if (is_array($d)) { foreach ($d as $key => $val) { $this->{$key} = $val; } } } } $object = new Obj(); test('null', null, new Obj(), new Obj(null, null, null)); test('bool: true', true, new Obj(), new Obj(true, null, null)); test('bool: false', false, new Obj(), new Obj(false, null, null)); test('zero: 0', 0, new Obj(), new Obj(0, null, null)); test('small: 1', 1, new Obj(), new Obj(1, null, null)); test('small: -1', -1, new Obj(), new Obj(-1, null, null)); test('medium: 1000', 1000, new Obj(), new Obj(1000, null, null)); test('medium: -1000', -1000, new Obj(), new Obj(-1000, null, null)); test('large: 100000', 100000, new Obj(), new Obj(100000, null, null)); test('large: -100000', -100000, new Obj(), new Obj(-100000, null, null)); test('double: 123.456', 123.456, new Obj(), new Obj(123.456, null, null)); test('empty: ""', "", new Obj(), new Obj("", null, null)); test('string: "foobar"', "foobar", new Obj(), new Obj("foobar", null, null)); test('array: empty', array(), new Obj(), new Obj(null, null, null)); test('array(1, 2, 3)', array(1, 2, 3), new Obj(), new Obj(1, 2, 3)); test('array(array(1, 2, 3), arr...', array(array(1, 2, 3), array(4, 5, 6), array(7, 8, 9)), new Obj(), new Obj(array(1, 2, 3), array(4, 5, 6), array(7, 8, 9))); test('array(1, 2, 3, 4)', array(1, 2, 3, 4), new Obj()); test('array("foo", "foobar", "foohoge")', array("foo", "foobar", "hoge"), new Obj(), new Obj("foo", "foobar", "hoge")); test('array("a" => 1, "b" => 2))', array("a" => 1, "b" => 2), new Obj(), new Obj(1, 2, null)); test('array("one" => 1, "two" => 2))', array("one" => 1, "two" => 2), new Obj(), new Obj(null, null, null, array("one" => 1, "two" => 2))); test('array("" => "empty")', array("" => "empty"), new Obj()); test('array("a" => 1, "b" => 2, 3))', array("a" => 1, "b" => 2, 3), new Obj(), new Obj(1, 2, 3)); test('array(3, "a" => 1, "b" => 2))', array(3, "a" => 1, "b" => 2), new Obj(), new Obj(1, 2, 3)); test('array("a" => 1, 3, "b" => 2))', array("a" => 1, 3, "b" => 2), new Obj(), new Obj(1, 2, 3)); $a = array('foo'); test('array($a, $a)', array($a, $a), new Obj(), new Obj($a, $a, null)); $a = array( 'a' => array( 'b' => 'c', 'd' => 'e' ), 'f' => array( 'g' => 'h' ) ); test('array', $a, new Obj(), new Obj(null, null, null, $a)); $o = new Obj(1, 2, 3); test('object', $o, new Obj(), new Obj(1, 2, 3)); class Obj2 { public $A; protected $B; private $C; function __construct($a, $b, $c) { $this->A = $a; $this->B = $b; $this->C = $c; } } $o = new Obj2(1, 2, 3); test('object', $o, new Obj(), new Obj(1, 2, 3)); $o1 = new Obj2(1, 2, 3); $o2 = new Obj2(4, 5, 6); test('object', array($o1, $o2), new Obj(), new Obj(array(1, 2, 3), array(4, 5, 6))); --EXPECTF-- object(Obj)#%d (3) { ["a"]=> NULL [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> bool(true) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> bool(false) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(0) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(-1) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(1000) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(-1000) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(100000) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(-100000) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> float(123.456) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> string(0) "" [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> string(6) "foobar" [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> NULL [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } [%r"?b"?:protected"?%r]=> array(3) { [0]=> int(4) [1]=> int(5) [2]=> int(6) } [%r"?c"?:("Obj":)?private"?%r]=> array(3) { [0]=> int(7) [1]=> int(8) [2]=> int(9) } } OK object(Obj)#%d (4) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) [3]=> int(4) } SKIP object(Obj)#%d (3) { ["a"]=> string(3) "foo" [%r"?b"?:protected"?%r]=> string(6) "foobar" [%r"?c"?:("Obj":)?private"?%r]=> string(4) "hoge" } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (5) { ["a"]=> NULL [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL ["one"]=> int(1) ["two"]=> int(2) } OK object(Obj)#%d (4) { ["a"]=> NULL [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL [""]=> string(5) "empty" } SKIP object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> array(1) { [0]=> string(3) "foo" } [%r"?b"?:protected"?%r]=> array(1) { [0]=> string(3) "foo" } [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (4) { ["a"]=> array(2) { ["b"]=> string(1) "c" ["d"]=> string(1) "e" } [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL ["f"]=> array(1) { ["g"]=> string(1) "h" } } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } [%r"?b"?:protected"?%r]=> array(3) { [0]=> int(4) [1]=> int(5) [2]=> int(6) } [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK msgpack-0.5.5/tests/102b.phpt0000644000077100007710000001615012110565607015535 0ustar xinchenxinchen--TEST-- unpack of object converter : class unpacker (object: php_only=0) --SKIPIF-- = 0) { echo "skip tests in PHP 5.1 or older"; } --FILE-- pack($variable); $unserialized = null; $unpacker = $msgpack->unpacker(); if ($unpacker->execute($serialized)) { $unserialized = $unpacker->data($object); } var_dump($unserialized); if ($result) { echo $unserialized == $result ? 'OK' : 'ERROR', PHP_EOL; } else { echo 'SKIP', PHP_EOL; } } class Obj { public $a; protected $b; private $c; public function __construct($a = null, $b = null, $c = null, $d = null) { $this->a = $a; $this->b = $b; $this->c = $c; if (is_array($d)) { foreach ($d as $key => $val) { $this->{$key} = $val; } } } } test('null', null, new Obj(), new Obj(null, null, null)); test('bool: true', true, new Obj(), new Obj(true, null, null)); test('bool: false', false, new Obj(), new Obj(false, null, null)); test('zero: 0', 0, new Obj(), new Obj(0, null, null)); test('small: 1', 1, new Obj(), new Obj(1, null, null)); test('small: -1', -1, new Obj(), new Obj(-1, null, null)); test('medium: 1000', 1000, new Obj(), new Obj(1000, null, null)); test('medium: -1000', -1000, new Obj(), new Obj(-1000, null, null)); test('large: 100000', 100000, new Obj(), new Obj(100000, null, null)); test('large: -100000', -100000, new Obj(), new Obj(-100000, null, null)); test('double: 123.456', 123.456, new Obj(), new Obj(123.456, null, null)); test('empty: ""', "", new Obj(), new Obj("", null, null)); test('string: "foobar"', "foobar", new Obj(), new Obj("foobar", null, null)); test('array: empty', array(), new Obj(), new Obj(null, null, null)); test('array(1, 2, 3)', array(1, 2, 3), new Obj(), new Obj(1, 2, 3)); test('array(array(1, 2, 3), arr...', array(array(1, 2, 3), array(4, 5, 6), array(7, 8, 9)), new Obj(), new Obj(array(1, 2, 3), array(4, 5, 6), array(7, 8, 9))); test('array(1, 2, 3, 4)', array(1, 2, 3, 4), new Obj()); test('array("foo", "foobar", "foohoge")', array("foo", "foobar", "hoge"), new Obj(), new Obj("foo", "foobar", "hoge")); test('array("a" => 1, "b" => 2))', array("a" => 1, "b" => 2), new Obj(), new Obj(1, 2, null)); test('array("one" => 1, "two" => 2))', array("one" => 1, "two" => 2), new Obj(), new Obj(null, null, null, array("one" => 1, "two" => 2))); test('array("a" => 1, "b" => 2, 3))', array("a" => 1, "b" => 2, 3), new Obj(), new Obj(1, 2, 3)); test('array(3, "a" => 1, "b" => 2))', array(3, "a" => 1, "b" => 2), new Obj(), new Obj(1, 2, 3)); test('array("a" => 1, 3, "b" => 2))', array("a" => 1, 3, "b" => 2), new Obj(), new Obj(1, 2, 3)); $a = array('foo'); test('array($a, $a)', array($a, $a), new Obj(), new Obj($a, $a, null)); $a = array( 'a' => array( 'b' => 'c', 'd' => 'e' ), 'f' => array( 'g' => 'h' ) ); test('array', $a, new Obj(), new Obj(null, null, null, $a)); $o = new Obj(1, 2, 3); test('object', $o, new Obj(), new Obj(1, 2, 3)); class Obj2 { public $A; protected $B; private $C; function __construct($a, $b, $c) { $this->A = $a; $this->B = $b; $this->C = $c; } } $o = new Obj2(1, 2, 3); test('object', $o, new Obj(), new Obj(1, 2, 3)); $o1 = new Obj2(1, 2, 3); $o2 = new Obj2(4, 5, 6); test('object', array($o1, $o2), new Obj(), new Obj(array(1, 2, 3), array(4, 5, 6))); --EXPECTF-- object(Obj)#%d (3) { ["a"]=> NULL ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> bool(true) ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> bool(false) ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(0) ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(1) ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(-1) ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(1000) ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(-1000) ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(100000) ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(-100000) ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> float(123.456) ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> string(0) "" ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> string(6) "foobar" ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> NULL ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(1) ["b:protected"]=> int(2) ["c:private"]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } ["b:protected"]=> array(3) { [0]=> int(4) [1]=> int(5) [2]=> int(6) } ["c:private"]=> array(3) { [0]=> int(7) [1]=> int(8) [2]=> int(9) } } OK object(Obj)#%d (4) { ["a"]=> int(1) ["b:protected"]=> int(2) ["c:private"]=> int(3) [3]=> int(4) } SKIP object(Obj)#%d (3) { ["a"]=> string(3) "foo" ["b:protected"]=> string(6) "foobar" ["c:private"]=> string(4) "hoge" } OK object(Obj)#%d (3) { ["a"]=> int(1) ["b:protected"]=> int(2) ["c:private"]=> NULL } OK object(Obj)#%d (5) { ["a"]=> NULL ["b:protected"]=> NULL ["c:private"]=> NULL ["one"]=> int(1) ["two"]=> int(2) } OK object(Obj)#%d (3) { ["a"]=> int(1) ["b:protected"]=> int(2) ["c:private"]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> int(1) ["b:protected"]=> int(2) ["c:private"]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> int(1) ["b:protected"]=> int(2) ["c:private"]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> array(1) { [0]=> string(3) "foo" } ["b:protected"]=> array(1) { [0]=> string(3) "foo" } ["c:private"]=> NULL } OK object(Obj)#%d (4) { ["a"]=> array(2) { ["b"]=> string(1) "c" ["d"]=> string(1) "e" } ["b:protected"]=> NULL ["c:private"]=> NULL ["f"]=> array(1) { ["g"]=> string(1) "h" } } OK object(Obj)#%d (3) { ["a"]=> int(1) ["b:protected"]=> int(2) ["c:private"]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> int(1) ["b:protected"]=> int(2) ["c:private"]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } ["b:protected"]=> array(3) { [0]=> int(4) [1]=> int(5) [2]=> int(6) } ["c:private"]=> NULL } OK msgpack-0.5.5/tests/103.phpt0000644000077100007710000001764512110565607015406 0ustar xinchenxinchen--TEST-- unpack of object converter: class unpacker (string: OPT_PHPONLY=false) --SKIPIF-- setOption(MessagePack::OPT_PHPONLY, false); $serialized = $msgpack->pack($variable); $unserialized = null; $unpacker = $msgpack->unpacker(); if ($unpacker->execute($serialized)) { $unserialized = $unpacker->data($object); } var_dump($unserialized); if ($result) { echo $unserialized == $result ? 'OK' : 'ERROR', PHP_EOL; } else { echo 'SKIP', PHP_EOL; } } class Obj { public $a; protected $b; private $c; public function __construct($a = null, $b = null, $c = null, $d = null) { $this->a = $a; $this->b = $b; $this->c = $c; if (is_array($d)) { foreach ($d as $key => $val) { $this->{$key} = $val; } } } } test('null', null, 'Obj', new Obj(null, null, null)); test('bool: true', true, 'Obj', new Obj(true, null, null)); test('bool: false', false, 'Obj', new Obj(false, null, null)); test('zero: 0', 0, 'Obj', new Obj(0, null, null)); test('small: 1', 1, 'Obj', new Obj(1, null, null)); test('small: -1', -1, 'Obj', new Obj(-1, null, null)); test('medium: 1000', 1000, 'Obj', new Obj(1000, null, null)); test('medium: -1000', -1000, 'Obj', new Obj(-1000, null, null)); test('large: 100000', 100000, 'Obj', new Obj(100000, null, null)); test('large: -100000', -100000, 'Obj', new Obj(-100000, null, null)); test('double: 123.456', 123.456, 'Obj', new Obj(123.456, null, null)); test('empty: ""', "", 'Obj', new Obj("", null, null)); test('string: "foobar"', "foobar", 'Obj', new Obj("foobar", null, null)); test('array: empty', array(), 'Obj', new Obj(null, null, null)); test('array(1, 2, 3)', array(1, 2, 3), 'Obj', new Obj(1, 2, 3)); test('array(array(1, 2, 3), arr...', array(array(1, 2, 3), array(4, 5, 6), array(7, 8, 9)), 'Obj', new Obj(array(1, 2, 3), array(4, 5, 6), array(7, 8, 9))); test('array(1, 2, 3, 4)', array(1, 2, 3, 4), 'Obj'); test('array("foo", "foobar", "foohoge")', array("foo", "foobar", "hoge"), 'Obj', new Obj("foo", "foobar", "hoge")); test('array("a" => 1, "b" => 2))', array("a" => 1, "b" => 2), 'Obj', new Obj(1, 2, null)); test('array("one" => 1, "two" => 2))', array("one" => 1, "two" => 2), 'Obj', new Obj(null, null, null, array("one" => 1, "two" => 2))); test('array("" => "empty")', array("" => "empty"), 'Obj'); test('array("a" => 1, "b" => 2, 3))', array("a" => 1, "b" => 2, 3), 'Obj', new Obj(1, 2, 3)); test('array(3, "a" => 1, "b" => 2))', array(3, "a" => 1, "b" => 2), 'Obj', new Obj(1, 2, 3)); test('array("a" => 1, 3, "b" => 2))', array("a" => 1, 3, "b" => 2), 'Obj', new Obj(1, 2, 3)); $a = array('foo'); test('array($a, $a)', array($a, $a), 'Obj', new Obj($a, $a, null)); $a = array( 'a' => array( 'b' => 'c', 'd' => 'e' ), 'f' => array( 'g' => 'h' ) ); test('array', $a, 'Obj', new Obj(null, null, null, $a)); $o = new Obj(1, 2, 3); test('object', $o, 'Obj', new Obj(1, 2, 3)); class Obj2 { public $A; protected $B; private $C; function __construct($a, $b, $c) { $this->A = $a; $this->B = $b; $this->C = $c; } } $o = new Obj2(1, 2, 3); test('object', $o, 'Obj', new Obj(1, 2, 3)); $o1 = new Obj2(1, 2, 3); $o2 = new Obj2(4, 5, 6); test('object', array($o1, $o2), 'Obj', new Obj(array(1, 2, 3), array(4, 5, 6))); --EXPECTF-- object(Obj)#%d (3) { ["a"]=> NULL [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> bool(true) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> bool(false) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(0) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(-1) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(1000) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(-1000) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(100000) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(-100000) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> float(123.456) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> string(0) "" [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> string(6) "foobar" [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> NULL [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } [%r"?b"?:protected"?%r]=> array(3) { [0]=> int(4) [1]=> int(5) [2]=> int(6) } [%r"?c"?:("Obj":)?private"?%r]=> array(3) { [0]=> int(7) [1]=> int(8) [2]=> int(9) } } OK object(Obj)#%d (4) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) [3]=> int(4) } SKIP object(Obj)#%d (3) { ["a"]=> string(3) "foo" [%r"?b"?:protected"?%r]=> string(6) "foobar" [%r"?c"?:("Obj":)?private"?%r]=> string(4) "hoge" } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (5) { ["a"]=> NULL [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL ["one"]=> int(1) ["two"]=> int(2) } OK object(Obj)#%d (4) { ["a"]=> NULL [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL [""]=> string(5) "empty" } SKIP object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> array(1) { [0]=> string(3) "foo" } [%r"?b"?:protected"?%r]=> array(1) { [0]=> string(3) "foo" } [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (4) { ["a"]=> array(2) { ["b"]=> string(1) "c" ["d"]=> string(1) "e" } [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL ["f"]=> array(1) { ["g"]=> string(1) "h" } } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } [%r"?b"?:protected"?%r]=> array(3) { [0]=> int(4) [1]=> int(5) [2]=> int(6) } [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK msgpack-0.5.5/tests/103b.phpt0000644000077100007710000001625612110565607015545 0ustar xinchenxinchen--TEST-- unpack of object converter: class unpacker (string: OPT_PHPONLY=false) --SKIPIF-- = 0) { echo "skip tests in PHP 5.1 or older"; } --FILE-- setOption(MESSAGEPACK_OPT_PHPONLY, false); } else { $msgpack->setOption(MessagePack::OPT_PHPONLY, false); } $serialized = $msgpack->pack($variable); $unserialized = null; $unpacker = $msgpack->unpacker(); if ($unpacker->execute($serialized)) { $unserialized = $unpacker->data($object); } var_dump($unserialized); if ($result) { echo $unserialized == $result ? 'OK' : 'ERROR', PHP_EOL; } else { echo 'SKIP', PHP_EOL; } } class Obj { public $a; protected $b; private $c; public function __construct($a = null, $b = null, $c = null, $d = null) { $this->a = $a; $this->b = $b; $this->c = $c; if (is_array($d)) { foreach ($d as $key => $val) { $this->{$key} = $val; } } } } test('null', null, 'Obj', new Obj(null, null, null)); test('bool: true', true, 'Obj', new Obj(true, null, null)); test('bool: false', false, 'Obj', new Obj(false, null, null)); test('zero: 0', 0, 'Obj', new Obj(0, null, null)); test('small: 1', 1, 'Obj', new Obj(1, null, null)); test('small: -1', -1, 'Obj', new Obj(-1, null, null)); test('medium: 1000', 1000, 'Obj', new Obj(1000, null, null)); test('medium: -1000', -1000, 'Obj', new Obj(-1000, null, null)); test('large: 100000', 100000, 'Obj', new Obj(100000, null, null)); test('large: -100000', -100000, 'Obj', new Obj(-100000, null, null)); test('double: 123.456', 123.456, 'Obj', new Obj(123.456, null, null)); test('empty: ""', "", 'Obj', new Obj("", null, null)); test('string: "foobar"', "foobar", 'Obj', new Obj("foobar", null, null)); test('array: empty', array(), 'Obj', new Obj(null, null, null)); test('array(1, 2, 3)', array(1, 2, 3), 'Obj', new Obj(1, 2, 3)); test('array(array(1, 2, 3), arr...', array(array(1, 2, 3), array(4, 5, 6), array(7, 8, 9)), 'Obj', new Obj(array(1, 2, 3), array(4, 5, 6), array(7, 8, 9))); test('array(1, 2, 3, 4)', array(1, 2, 3, 4), 'Obj'); test('array("foo", "foobar", "foohoge")', array("foo", "foobar", "hoge"), 'Obj', new Obj("foo", "foobar", "hoge")); test('array("a" => 1, "b" => 2))', array("a" => 1, "b" => 2), 'Obj', new Obj(1, 2, null)); test('array("one" => 1, "two" => 2))', array("one" => 1, "two" => 2), 'Obj', new Obj(null, null, null, array("one" => 1, "two" => 2))); test('array("a" => 1, "b" => 2, 3))', array("a" => 1, "b" => 2, 3), 'Obj', new Obj(1, 2, 3)); test('array(3, "a" => 1, "b" => 2))', array(3, "a" => 1, "b" => 2), 'Obj', new Obj(1, 2, 3)); test('array("a" => 1, 3, "b" => 2))', array("a" => 1, 3, "b" => 2), 'Obj', new Obj(1, 2, 3)); $a = array('foo'); test('array($a, $a)', array($a, $a), 'Obj', new Obj($a, $a, null)); $a = array( 'a' => array( 'b' => 'c', 'd' => 'e' ), 'f' => array( 'g' => 'h' ) ); test('array', $a, 'Obj', new Obj(null, null, null, $a)); $o = new Obj(1, 2, 3); test('object', $o, 'Obj', new Obj(1, 2, 3)); class Obj2 { public $A; protected $B; private $C; function __construct($a, $b, $c) { $this->A = $a; $this->B = $b; $this->C = $c; } } $o = new Obj2(1, 2, 3); test('object', $o, 'Obj', new Obj(1, 2, 3)); $o1 = new Obj2(1, 2, 3); $o2 = new Obj2(4, 5, 6); test('object', array($o1, $o2), 'Obj', new Obj(array(1, 2, 3), array(4, 5, 6))); --EXPECTF-- object(Obj)#%d (3) { ["a"]=> NULL ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> bool(true) ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> bool(false) ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(0) ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(1) ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(-1) ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(1000) ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(-1000) ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(100000) ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(-100000) ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> float(123.456) ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> string(0) "" ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> string(6) "foobar" ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> NULL ["b:protected"]=> NULL ["c:private"]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(1) ["b:protected"]=> int(2) ["c:private"]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } ["b:protected"]=> array(3) { [0]=> int(4) [1]=> int(5) [2]=> int(6) } ["c:private"]=> array(3) { [0]=> int(7) [1]=> int(8) [2]=> int(9) } } OK object(Obj)#%d (4) { ["a"]=> int(1) ["b:protected"]=> int(2) ["c:private"]=> int(3) [3]=> int(4) } SKIP object(Obj)#%d (3) { ["a"]=> string(3) "foo" ["b:protected"]=> string(6) "foobar" ["c:private"]=> string(4) "hoge" } OK object(Obj)#%d (3) { ["a"]=> int(1) ["b:protected"]=> int(2) ["c:private"]=> NULL } OK object(Obj)#%d (5) { ["a"]=> NULL ["b:protected"]=> NULL ["c:private"]=> NULL ["one"]=> int(1) ["two"]=> int(2) } OK object(Obj)#%d (3) { ["a"]=> int(1) ["b:protected"]=> int(2) ["c:private"]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> int(1) ["b:protected"]=> int(2) ["c:private"]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> int(1) ["b:protected"]=> int(2) ["c:private"]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> array(1) { [0]=> string(3) "foo" } ["b:protected"]=> array(1) { [0]=> string(3) "foo" } ["c:private"]=> NULL } OK object(Obj)#%d (4) { ["a"]=> array(2) { ["b"]=> string(1) "c" ["d"]=> string(1) "e" } ["b:protected"]=> NULL ["c:private"]=> NULL ["f"]=> array(1) { ["g"]=> string(1) "h" } } OK object(Obj)#%d (3) { ["a"]=> int(1) ["b:protected"]=> int(2) ["c:private"]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> int(1) ["b:protected"]=> int(2) ["c:private"]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } ["b:protected"]=> array(3) { [0]=> int(4) [1]=> int(5) [2]=> int(6) } ["c:private"]=> NULL } OK msgpack-0.5.5/tests/104.phpt0000644000077100007710000000273412110565607015400 0ustar xinchenxinchen--TEST-- unpack of template converter: class unpacker (array: string) --SKIPIF-- pack($variable); $unserialized = $msgpack->unpack($serialized, $object); var_dump($unserialized); if ($result) { echo $unserialized == $result ? 'OK' : 'ERROR', PHP_EOL; } else { echo 'SKIP', PHP_EOL; } } class MyObj { private $data = null; private $priv = "privdata"; public $pdata = null; function __construct() { $this->data = "datadata"; } } $obj = new MyObj(); $obj->pdata = "pubdata0"; $obj2 = new MyObj(); $obj2->pdata = "pubdata1"; $ary = array($obj, $obj2); $tpl = array("MyObj"); test("object list /w string", $ary, $tpl, $ary); --EXPECTF-- array(2) { [0]=> object(MyObj)#%d (3) { [%r"?data"?:("MyObj":)?private"?%r]=> string(8) "datadata" [%r"?priv"?:("MyObj":)?private"?%r]=> string(8) "privdata" ["pdata"]=> string(8) "pubdata0" } [1]=> object(MyObj)#%d (3) { [%r"?data"?:("MyObj":)?private"?%r]=> string(8) "datadata" [%r"?priv"?:("MyObj":)?private"?%r]=> string(8) "privdata" ["pdata"]=> string(8) "pubdata1" } } OK msgpack-0.5.5/tests/104b.phpt0000644000077100007710000000262112110565607015535 0ustar xinchenxinchen--TEST-- unpack of template converter: class unpacker (array: string) --SKIPIF-- = 0) { echo "skip tests in PHP 5.1 or older"; } --FILE-- pack($variable); $unserialized = $msgpack->unpack($serialized, $object); var_dump($unserialized); if ($result) { echo $unserialized == $result ? 'OK' : 'ERROR', PHP_EOL; } else { echo 'SKIP', PHP_EOL; } } class MyObj { private $data = null; private $priv = "privdata"; public $pdata = null; function __construct() { $this->data = "datadata"; } } $obj = new MyObj(); $obj->pdata = "pubdata0"; $obj2 = new MyObj(); $obj2->pdata = "pubdata1"; $ary = array($obj, $obj2); $tpl = array("MyObj"); test("object list /w string", $ary, $tpl, $ary); --EXPECTF-- array(2) { [0]=> object(MyObj)#%d (3) { ["data:private"]=> string(8) "datadata" ["priv:private"]=> string(8) "privdata" ["pdata"]=> string(8) "pubdata0" } [1]=> object(MyObj)#%d (3) { ["data:private"]=> string(8) "datadata" ["priv:private"]=> string(8) "privdata" ["pdata"]=> string(8) "pubdata1" } } OK msgpack-0.5.5/tests/105.phpt0000644000077100007710000000274212110565607015400 0ustar xinchenxinchen--TEST-- unpack of template converter: class unpacker (array: object) --SKIPIF-- pack($variable); $unserialized = $msgpack->unpack($serialized, $object); var_dump($unserialized); if ($result) { echo $unserialized == $result ? 'OK' : 'ERROR', PHP_EOL; } else { echo 'SKIP', PHP_EOL; } } class MyObj { private $data = null; private $priv = "privdata"; public $pdata = null; function __construct() { $this->data = "datadata"; } } $obj = new MyObj(); $obj->pdata = "pubdata0"; $obj2 = new MyObj(); $obj2->pdata = "pubdata1"; $ary = array($obj, $obj2); $tpl = array(new MyObj()); test("object list /w instance", $ary, $tpl, $ary); --EXPECTF-- array(2) { [0]=> object(MyObj)#%d (3) { [%r"?data"?:("MyObj":)?private"?%r]=> string(8) "datadata" [%r"?priv"?:("MyObj":)?private"?%r]=> string(8) "privdata" ["pdata"]=> string(8) "pubdata0" } [1]=> object(MyObj)#%d (3) { [%r"?data"?:("MyObj":)?private"?%r]=> string(8) "datadata" [%r"?priv"?:("MyObj":)?private"?%r]=> string(8) "privdata" ["pdata"]=> string(8) "pubdata1" } } OK msgpack-0.5.5/tests/105b.phpt0000644000077100007710000000262712110565607015544 0ustar xinchenxinchen--TEST-- unpack of template converter: class unpacker (array: object) --SKIPIF-- = 0) { echo "skip tests in PHP 5.1 or older"; } --FILE-- pack($variable); $unserialized = $msgpack->unpack($serialized, $object); var_dump($unserialized); if ($result) { echo $unserialized == $result ? 'OK' : 'ERROR', PHP_EOL; } else { echo 'SKIP', PHP_EOL; } } class MyObj { private $data = null; private $priv = "privdata"; public $pdata = null; function __construct() { $this->data = "datadata"; } } $obj = new MyObj(); $obj->pdata = "pubdata0"; $obj2 = new MyObj(); $obj2->pdata = "pubdata1"; $ary = array($obj, $obj2); $tpl = array(new MyObj()); test("object list /w instance", $ary, $tpl, $ary); --EXPECTF-- array(2) { [0]=> object(MyObj)#%d (3) { ["data:private"]=> string(8) "datadata" ["priv:private"]=> string(8) "privdata" ["pdata"]=> string(8) "pubdata0" } [1]=> object(MyObj)#%d (3) { ["data:private"]=> string(8) "datadata" ["priv:private"]=> string(8) "privdata" ["pdata"]=> string(8) "pubdata1" } } OK msgpack-0.5.5/tests/106.phpt0000644000077100007710000000325012110565607015374 0ustar xinchenxinchen--TEST-- unpack of template converter: class unpacker (string) --SKIPIF-- pack($variable); $unserialized = $msgpack->unpack($serialized, $object); var_dump($unserialized); if ($result) { echo $unserialized == $result ? 'OK' : 'ERROR', PHP_EOL; } else { echo 'SKIP', PHP_EOL; } } class MyObj { private $data = null; private $priv = "privdata"; public $pdata = null; public $subary = null; function __construct() { $this->data = "datadata"; $this->subary = new SubObj(); } } class SubObj { private $subdata = null; private $subpriv = "subprivdata"; public $subpdata = null; function __construct() { $this->subdata = "subdatadata"; } } $obj = new MyObj(); $obj->pdata = "pubdata"; $obj->subary->subpdata = "subpubdata"; $tpl = "MyObj"; test("recursive object /w string", $obj, $tpl, $obj); --EXPECTF-- object(MyObj)#%d (4) { [%r"?data"?:("MyObj":)?private"?%r]=> string(8) "datadata" [%r"?priv"?:("MyObj":)?private"?%r]=> string(8) "privdata" ["pdata"]=> string(7) "pubdata" ["subary"]=> object(SubObj)#%d (3) { [%r"?subdata"?:("SubObj":)?private"?%r]=> string(11) "subdatadata" [%r"?subpriv"?:("SubObj":)?private"?%r]=> string(11) "subprivdata" ["subpdata"]=> string(10) "subpubdata" } } OK msgpack-0.5.5/tests/106b.phpt0000644000077100007710000000313312110565607015536 0ustar xinchenxinchen--TEST-- unpack of template converter: class unpacker (string) --SKIPIF-- = 0) { echo "skip tests in PHP 5.1 or older"; } --FILE-- pack($variable); $unserialized = $msgpack->unpack($serialized, $object); var_dump($unserialized); if ($result) { echo $unserialized == $result ? 'OK' : 'ERROR', PHP_EOL; } else { echo 'SKIP', PHP_EOL; } } class MyObj { private $data = null; private $priv = "privdata"; public $pdata = null; public $subary = null; function __construct() { $this->data = "datadata"; $this->subary = new SubObj(); } } class SubObj { private $subdata = null; private $subpriv = "subprivdata"; public $subpdata = null; function __construct() { $this->subdata = "subdatadata"; } } $obj = new MyObj(); $obj->pdata = "pubdata"; $obj->subary->subpdata = "subpubdata"; $tpl = "MyObj"; test("recursive object /w string", $obj, $tpl, $obj); --EXPECTF-- object(MyObj)#%d (4) { ["data:private"]=> string(8) "datadata" ["priv:private"]=> string(8) "privdata" ["pdata"]=> string(7) "pubdata" ["subary"]=> object(SubObj)#%d (3) { ["subdata:private"]=> string(11) "subdatadata" ["subpriv:private"]=> string(11) "subprivdata" ["subpdata"]=> string(10) "subpubdata" } } OK msgpack-0.5.5/tests/107.phpt0000644000077100007710000000325612110565607015403 0ustar xinchenxinchen--TEST-- unpack of template converter: class unpacker (object) --SKIPIF-- pack($variable); $unserialized = $msgpack->unpack($serialized, $object); var_dump($unserialized); if ($result) { echo $unserialized == $result ? 'OK' : 'ERROR', PHP_EOL; } else { echo 'SKIP', PHP_EOL; } } class MyObj { private $data = null; private $priv = "privdata"; public $pdata = null; public $subary = null; function __construct() { $this->data = "datadata"; $this->subary = new SubObj(); } } class SubObj { private $subdata = null; private $subpriv = "subprivdata"; public $subpdata = null; function __construct() { $this->subdata = "subdatadata"; } } $obj = new MyObj(); $obj->pdata = "pubdata"; $obj->subary->subpdata = "subpubdata"; $tpl = new MyObj(); test("recursive object /w instance", $obj, $tpl, $obj); --EXPECTF-- object(MyObj)#%d (4) { [%r"?data"?:("MyObj":)?private"?%r]=> string(8) "datadata" [%r"?priv"?:("MyObj":)?private"?%r]=> string(8) "privdata" ["pdata"]=> string(7) "pubdata" ["subary"]=> object(SubObj)#%d (3) { [%r"?subdata"?:("SubObj":)?private"?%r]=> string(11) "subdatadata" [%r"?subpriv"?:("SubObj":)?private"?%r]=> string(11) "subprivdata" ["subpdata"]=> string(10) "subpubdata" } } OK msgpack-0.5.5/tests/107b.phpt0000644000077100007710000000314112110565607015536 0ustar xinchenxinchen--TEST-- unpack of template converter: class unpacker (object) --SKIPIF-- = 0) { echo "skip tests in PHP 5.1 or older"; } --FILE-- pack($variable); $unserialized = $msgpack->unpack($serialized, $object); var_dump($unserialized); if ($result) { echo $unserialized == $result ? 'OK' : 'ERROR', PHP_EOL; } else { echo 'SKIP', PHP_EOL; } } class MyObj { private $data = null; private $priv = "privdata"; public $pdata = null; public $subary = null; function __construct() { $this->data = "datadata"; $this->subary = new SubObj(); } } class SubObj { private $subdata = null; private $subpriv = "subprivdata"; public $subpdata = null; function __construct() { $this->subdata = "subdatadata"; } } $obj = new MyObj(); $obj->pdata = "pubdata"; $obj->subary->subpdata = "subpubdata"; $tpl = new MyObj(); test("recursive object /w instance", $obj, $tpl, $obj); --EXPECTF-- object(MyObj)#%d (4) { ["data:private"]=> string(8) "datadata" ["priv:private"]=> string(8) "privdata" ["pdata"]=> string(7) "pubdata" ["subary"]=> object(SubObj)#%d (3) { ["subdata:private"]=> string(11) "subdatadata" ["subpriv:private"]=> string(11) "subprivdata" ["subpdata"]=> string(10) "subpubdata" } } OK msgpack-0.5.5/tests/108.phpt0000644000077100007710000000344312110565607015402 0ustar xinchenxinchen--TEST-- unpack of template converter: multiple class: class unpacker (array: string) --SKIPIF-- pack($variable); $unserialized = $msgpack->unpack($serialized, $object); var_dump($unserialized); if ($result) { echo $unserialized == $result ? 'OK' : 'ERROR', PHP_EOL; } else { echo 'SKIP', PHP_EOL; } } class MyObj { private $data = null; private $priv = "privdata"; public $pdata = null; public $subary = null; function __construct() { $this->data = "datadata"; $this->subary = new SubObj(); } } class SubObj { private $subdata = null; private $subpriv = "subprivdata"; public $subpdata = null; function __construct() { $this->subdata = "subdatadata"; } } $obj = new MyObj(); $obj->pdata = "pubdata"; $obj->subary->subpdata = "subpubdata"; $ary = array($obj); $tpl = array("MyObj"); test("recursive object with object list /w string", $ary, $tpl, $ary); --EXPECTF-- array(1) { [0]=> object(MyObj)#%d (4) { [%r"?data"?:("MyObj":)?private"?%r]=> string(8) "datadata" [%r"?priv"?:("MyObj":)?private"?%r]=> string(8) "privdata" ["pdata"]=> string(7) "pubdata" ["subary"]=> object(SubObj)#%d (3) { [%r"?subdata"?:("SubObj":)?private"?%r]=> string(11) "subdatadata" [%r"?subpriv"?:("SubObj":)?private"?%r]=> string(11) "subprivdata" ["subpdata"]=> string(10) "subpubdata" } } } OK msgpack-0.5.5/tests/108b.phpt0000644000077100007710000000332612110565607015544 0ustar xinchenxinchen--TEST-- unpack of template converter: multiple class: class unpacker (array: string) --SKIPIF-- = 0) { echo "skip tests in PHP 5.1 or older"; } --FILE-- pack($variable); $unserialized = $msgpack->unpack($serialized, $object); var_dump($unserialized); if ($result) { echo $unserialized == $result ? 'OK' : 'ERROR', PHP_EOL; } else { echo 'SKIP', PHP_EOL; } } class MyObj { private $data = null; private $priv = "privdata"; public $pdata = null; public $subary = null; function __construct() { $this->data = "datadata"; $this->subary = new SubObj(); } } class SubObj { private $subdata = null; private $subpriv = "subprivdata"; public $subpdata = null; function __construct() { $this->subdata = "subdatadata"; } } $obj = new MyObj(); $obj->pdata = "pubdata"; $obj->subary->subpdata = "subpubdata"; $ary = array($obj); $tpl = array("MyObj"); test("recursive object with object list /w string", $ary, $tpl, $ary); --EXPECTF-- array(1) { [0]=> object(MyObj)#%d (4) { ["data:private"]=> string(8) "datadata" ["priv:private"]=> string(8) "privdata" ["pdata"]=> string(7) "pubdata" ["subary"]=> object(SubObj)#%d (3) { ["subdata:private"]=> string(11) "subdatadata" ["subpriv:private"]=> string(11) "subprivdata" ["subpdata"]=> string(10) "subpubdata" } } } OK msgpack-0.5.5/tests/109.phpt0000644000077100007710000000345112110565607015402 0ustar xinchenxinchen--TEST-- unpack of template converter: multiple class: class unpacker (array: object) --SKIPIF-- pack($variable); $unserialized = $msgpack->unpack($serialized, $object); var_dump($unserialized); if ($result) { echo $unserialized == $result ? 'OK' : 'ERROR', PHP_EOL; } else { echo 'SKIP', PHP_EOL; } } class MyObj { private $data = null; private $priv = "privdata"; public $pdata = null; public $subary = null; function __construct() { $this->data = "datadata"; $this->subary = new SubObj(); } } class SubObj { private $subdata = null; private $subpriv = "subprivdata"; public $subpdata = null; function __construct() { $this->subdata = "subdatadata"; } } $obj = new MyObj(); $obj->pdata = "pubdata"; $obj->subary->subpdata = "subpubdata"; $ary = array($obj); $tpl = array(new MyObj()); test("recursive object with object list /w instance", $ary, $tpl, $ary); --EXPECTF-- array(1) { [0]=> object(MyObj)#%d (4) { [%r"?data"?:("MyObj":)?private"?%r]=> string(8) "datadata" [%r"?priv"?:("MyObj":)?private"?%r]=> string(8) "privdata" ["pdata"]=> string(7) "pubdata" ["subary"]=> object(SubObj)#%d (3) { [%r"?subdata"?:("SubObj":)?private"?%r]=> string(11) "subdatadata" [%r"?subpriv"?:("SubObj":)?private"?%r]=> string(11) "subprivdata" ["subpdata"]=> string(10) "subpubdata" } } } OK msgpack-0.5.5/tests/109b.phpt0000644000077100007710000000333012110565607015540 0ustar xinchenxinchen--TEST-- unpack of template converter: multiple class: class unpacker (array: object) --SKIPIF-- = 0) { echo "skip tests in PHP 5.1 or older"; } --FILE-- pack($variable); $unserialized = $msgpack->unpack($serialized, $object); var_dump($unserialized); if ($result) { echo $unserialized == $result ? 'OK' : 'ERROR', PHP_EOL; } else { echo 'SKIP', PHP_EOL; } } class MyObj { private $data = null; private $priv = "privdata"; public $pdata = null; public $subary = null; function __construct() { $this->data = "datadata"; $this->subary = new SubObj(); } } class SubObj { private $subdata = null; private $subpriv = "subprivdata"; public $subpdata = null; function __construct() { $this->subdata = "subdatadata"; } } $obj = new MyObj(); $obj->pdata = "pubdata"; $obj->subary->subpdata = "subpubdata"; $ary = array($obj); $tpl = array("MyObj"); test("recursive object with object list /w instance", $ary, $tpl, $ary); --EXPECTF-- array(1) { [0]=> object(MyObj)#%d (4) { ["data:private"]=> string(8) "datadata" ["priv:private"]=> string(8) "privdata" ["pdata"]=> string(7) "pubdata" ["subary"]=> object(SubObj)#%d (3) { ["subdata:private"]=> string(11) "subdatadata" ["subpriv:private"]=> string(11) "subprivdata" ["subpdata"]=> string(10) "subpubdata" } } } OK msgpack-0.5.5/tests/110.phpt0000644000077100007710000000453312110565607015374 0ustar xinchenxinchen--TEST-- unpack of template converter: multiple variable: class unpacker (array: string) --SKIPIF-- pack($variable); $unserialized = $msgpack->unpack($serialized, $object); var_dump($unserialized); if ($result) { echo $unserialized == $result ? 'OK' : 'ERROR', PHP_EOL; } else { echo 'SKIP', PHP_EOL; } } class MyObj { private $data = null; private $priv = "privdata"; public $pdata = null; public $subary = null; function __construct() { $this->data = "datadata"; $this->subary = new SubObj(); } } class SubObj { private $subdata = null; private $subpriv = "subprivdata"; public $subpdata = null; function __construct() { $this->subdata = "subdatadata"; } } $obj0 = new MyObj(); $obj0->pdata = "pubdata0"; $obj0->subary->subpdata = "subpubdata0"; $obj1 = new MyObj(); $obj1->pdata = "pubdata1"; $obj1->subary->subpdata = "subpubdata1"; $ary = array($obj0, $obj1); $tpl = array("MyObj"); test("recursive object list /w string", $ary, $tpl, $ary); --EXPECTF-- array(2) { [0]=> object(MyObj)#%d (4) { [%r"?data"?:("MyObj":)?private"?%r]=> string(8) "datadata" [%r"?priv"?:("MyObj":)?private"?%r]=> string(8) "privdata" ["pdata"]=> string(8) "pubdata0" ["subary"]=> object(SubObj)#%d (3) { [%r"?subdata"?:("SubObj":)?private"?%r]=> string(11) "subdatadata" [%r"?subpriv"?:("SubObj":)?private"?%r]=> string(11) "subprivdata" ["subpdata"]=> string(11) "subpubdata0" } } [1]=> object(MyObj)#%d (4) { [%r"?data"?:("MyObj":)?private"?%r]=> string(8) "datadata" [%r"?priv"?:("MyObj":)?private"?%r]=> string(8) "privdata" ["pdata"]=> string(8) "pubdata1" ["subary"]=> object(SubObj)#%d (3) { [%r"?subdata"?:("SubObj":)?private"?%r]=> string(11) "subdatadata" [%r"?subpriv"?:("SubObj":)?private"?%r]=> string(11) "subprivdata" ["subpdata"]=> string(11) "subpubdata1" } } } OK msgpack-0.5.5/tests/110b.phpt0000644000077100007710000000430012110565607015526 0ustar xinchenxinchen--TEST-- unpack of template converter: multiple variable: class unpacker (array: string) --SKIPIF-- = 0) { echo "skip tests in PHP 5.1 or older"; } --FILE-- pack($variable); $unserialized = $msgpack->unpack($serialized, $object); var_dump($unserialized); if ($result) { echo $unserialized == $result ? 'OK' : 'ERROR', PHP_EOL; } else { echo 'SKIP', PHP_EOL; } } class MyObj { private $data = null; private $priv = "privdata"; public $pdata = null; public $subary = null; function __construct() { $this->data = "datadata"; $this->subary = new SubObj(); } } class SubObj { private $subdata = null; private $subpriv = "subprivdata"; public $subpdata = null; function __construct() { $this->subdata = "subdatadata"; } } $obj0 = new MyObj(); $obj0->pdata = "pubdata0"; $obj0->subary->subpdata = "subpubdata0"; $obj1 = new MyObj(); $obj1->pdata = "pubdata1"; $obj1->subary->subpdata = "subpubdata1"; $ary = array($obj0, $obj1); $tpl = array("MyObj"); test("recursive object list /w string", $ary, $tpl, $ary); --EXPECTF-- array(2) { [0]=> object(MyObj)#%d (4) { ["data:private"]=> string(8) "datadata" ["priv:private"]=> string(8) "privdata" ["pdata"]=> string(8) "pubdata0" ["subary"]=> object(SubObj)#%d (3) { ["subdata:private"]=> string(11) "subdatadata" ["subpriv:private"]=> string(11) "subprivdata" ["subpdata"]=> string(11) "subpubdata0" } } [1]=> object(MyObj)#%d (4) { ["data:private"]=> string(8) "datadata" ["priv:private"]=> string(8) "privdata" ["pdata"]=> string(8) "pubdata1" ["subary"]=> object(SubObj)#%d (3) { ["subdata:private"]=> string(11) "subdatadata" ["subpriv:private"]=> string(11) "subprivdata" ["subpdata"]=> string(11) "subpubdata1" } } } OK msgpack-0.5.5/tests/111.phpt0000644000077100007710000000454112110565607015374 0ustar xinchenxinchen--TEST-- unpack of template converter: multiple variable: class unpacker (array: object) --SKIPIF-- pack($variable); $unserialized = $msgpack->unpack($serialized, $object); var_dump($unserialized); if ($result) { echo $unserialized == $result ? 'OK' : 'ERROR', PHP_EOL; } else { echo 'SKIP', PHP_EOL; } } class MyObj { private $data = null; private $priv = "privdata"; public $pdata = null; public $subary = null; function __construct() { $this->data = "datadata"; $this->subary = new SubObj(); } } class SubObj { private $subdata = null; private $subpriv = "subprivdata"; public $subpdata = null; function __construct() { $this->subdata = "subdatadata"; } } $obj0 = new MyObj(); $obj0->pdata = "pubdata0"; $obj0->subary->subpdata = "subpubdata0"; $obj1 = new MyObj(); $obj1->pdata = "pubdata1"; $obj1->subary->subpdata = "subpubdata1"; $ary = array($obj0, $obj1); $tpl = array(new MyObj()); test("recursive object list /w instance", $ary, $tpl, $ary); --EXPECTF-- array(2) { [0]=> object(MyObj)#%d (4) { [%r"?data"?:("MyObj":)?private"?%r]=> string(8) "datadata" [%r"?priv"?:("MyObj":)?private"?%r]=> string(8) "privdata" ["pdata"]=> string(8) "pubdata0" ["subary"]=> object(SubObj)#%d (3) { [%r"?subdata"?:("SubObj":)?private"?%r]=> string(11) "subdatadata" [%r"?subpriv"?:("SubObj":)?private"?%r]=> string(11) "subprivdata" ["subpdata"]=> string(11) "subpubdata0" } } [1]=> object(MyObj)#%d (4) { [%r"?data"?:("MyObj":)?private"?%r]=> string(8) "datadata" [%r"?priv"?:("MyObj":)?private"?%r]=> string(8) "privdata" ["pdata"]=> string(8) "pubdata1" ["subary"]=> object(SubObj)#%d (3) { [%r"?subdata"?:("SubObj":)?private"?%r]=> string(11) "subdatadata" [%r"?subpriv"?:("SubObj":)?private"?%r]=> string(11) "subprivdata" ["subpdata"]=> string(11) "subpubdata1" } } } OK msgpack-0.5.5/tests/111b.phpt0000644000077100007710000000430612110565607015535 0ustar xinchenxinchen--TEST-- unpack of template converter: multiple variable: class unpacker (array: object) --SKIPIF-- = 0) { echo "skip tests in PHP 5.1 or older"; } --FILE-- pack($variable); $unserialized = $msgpack->unpack($serialized, $object); var_dump($unserialized); if ($result) { echo $unserialized == $result ? 'OK' : 'ERROR', PHP_EOL; } else { echo 'SKIP', PHP_EOL; } } class MyObj { private $data = null; private $priv = "privdata"; public $pdata = null; public $subary = null; function __construct() { $this->data = "datadata"; $this->subary = new SubObj(); } } class SubObj { private $subdata = null; private $subpriv = "subprivdata"; public $subpdata = null; function __construct() { $this->subdata = "subdatadata"; } } $obj0 = new MyObj(); $obj0->pdata = "pubdata0"; $obj0->subary->subpdata = "subpubdata0"; $obj1 = new MyObj(); $obj1->pdata = "pubdata1"; $obj1->subary->subpdata = "subpubdata1"; $ary = array($obj0, $obj1); $tpl = array(new MyObj()); test("recursive object list /w instance", $ary, $tpl, $ary); --EXPECTF-- array(2) { [0]=> object(MyObj)#%d (4) { ["data:private"]=> string(8) "datadata" ["priv:private"]=> string(8) "privdata" ["pdata"]=> string(8) "pubdata0" ["subary"]=> object(SubObj)#%d (3) { ["subdata:private"]=> string(11) "subdatadata" ["subpriv:private"]=> string(11) "subprivdata" ["subpdata"]=> string(11) "subpubdata0" } } [1]=> object(MyObj)#%d (4) { ["data:private"]=> string(8) "datadata" ["priv:private"]=> string(8) "privdata" ["pdata"]=> string(8) "pubdata1" ["subary"]=> object(SubObj)#%d (3) { ["subdata:private"]=> string(11) "subdatadata" ["subpriv:private"]=> string(11) "subprivdata" ["subpdata"]=> string(11) "subpubdata1" } } } OK msgpack-0.5.5/tests/112.phpt0000644000077100007710000000627112110565607015377 0ustar xinchenxinchen--TEST-- unpack of template converter: multiple class/variable: class unpacker (array: string) --SKIPIF-- pack($variable); $unserialized = $msgpack->unpack($serialized, $object); var_dump($unserialized); if ($result) { echo $unserialized == $result ? 'OK' : 'ERROR', PHP_EOL; } else { echo 'SKIP', PHP_EOL; } } class MyObj { private $data = null; private $priv = "privdata"; public $pdata = null; public $subary = null; function __construct() { $this->data = "datadata"; $this->subary = array(new SubObj()); } } class SubObj { private $subdata = null; private $subpriv = "subprivdata"; public $subpdata = null; function __construct() { $this->subdata = "subdatadata"; } } $obj0 = new MyObj(); $obj0->pdata = "pubdata0"; $obj0->subary[0]->subpdata = "subpubdata00"; $subobj01 = new SubObj(); $subobj01->subpdata = "subpdata01"; $obj0->subary[1] = $subobj01; $obj1 = new MyObj(); $obj1->pdata = "pubdata1"; $obj1->subary[0]->subpdata = "subpubdata1"; $subobj11 = new SubObj(); $subobj11->subpdata = "subpdata11"; $obj1->subary[1] = $subobj11; $ary = array($obj0, $obj1); $tpl = array("MyObj"); test("recursive object list with object list /w string", $ary, $tpl, $ary); --EXPECTF-- array(2) { [0]=> object(MyObj)#%d (4) { [%r"?data"?:("MyObj":)?private"?%r]=> string(8) "datadata" [%r"?priv"?:("MyObj":)?private"?%r]=> string(8) "privdata" ["pdata"]=> string(8) "pubdata0" ["subary"]=> array(2) { [0]=> object(SubObj)#%d (3) { [%r"?subdata"?:("SubObj":)?private"?%r]=> string(11) "subdatadata" [%r"?subpriv"?:("SubObj":)?private"?%r]=> string(11) "subprivdata" ["subpdata"]=> string(12) "subpubdata00" } [1]=> object(SubObj)#%d (3) { [%r"?subdata"?:("SubObj":)?private"?%r]=> string(11) "subdatadata" [%r"?subpriv"?:("SubObj":)?private"?%r]=> string(11) "subprivdata" ["subpdata"]=> string(10) "subpdata01" } } } [1]=> object(MyObj)#%d (4) { [%r"?data"?:("MyObj":)?private"?%r]=> string(8) "datadata" [%r"?priv"?:("MyObj":)?private"?%r]=> string(8) "privdata" ["pdata"]=> string(8) "pubdata1" ["subary"]=> array(2) { [0]=> object(SubObj)#%d (3) { [%r"?subdata"?:("SubObj":)?private"?%r]=> string(11) "subdatadata" [%r"?subpriv"?:("SubObj":)?private"?%r]=> string(11) "subprivdata" ["subpdata"]=> string(11) "subpubdata1" } [1]=> object(SubObj)#%d (3) { [%r"?subdata"?:("SubObj":)?private"?%r]=> string(11) "subdatadata" [%r"?subpriv"?:("SubObj":)?private"?%r]=> string(11) "subprivdata" ["subpdata"]=> string(10) "subpdata11" } } } } OK msgpack-0.5.5/tests/112b.phpt0000644000077100007710000000571612110565607015544 0ustar xinchenxinchen--TEST-- unpack of template converter: multiple class/variable: class unpacker (array: string) --SKIPIF-- = 0) { echo "skip tests in PHP 5.1 or older"; } --FILE-- pack($variable); $unserialized = $msgpack->unpack($serialized, $object); var_dump($unserialized); if ($result) { echo $unserialized == $result ? 'OK' : 'ERROR', PHP_EOL; } else { echo 'SKIP', PHP_EOL; } } class MyObj { private $data = null; private $priv = "privdata"; public $pdata = null; public $subary = null; function __construct() { $this->data = "datadata"; $this->subary = array(new SubObj()); } } class SubObj { private $subdata = null; private $subpriv = "subprivdata"; public $subpdata = null; function __construct() { $this->subdata = "subdatadata"; } } $obj0 = new MyObj(); $obj0->pdata = "pubdata0"; $obj0->subary[0]->subpdata = "subpubdata00"; $subobj01 = new SubObj(); $subobj01->subpdata = "subpdata01"; $obj0->subary[1] = $subobj01; $obj1 = new MyObj(); $obj1->pdata = "pubdata1"; $obj1->subary[0]->subpdata = "subpubdata1"; $subobj11 = new SubObj(); $subobj11->subpdata = "subpdata11"; $obj1->subary[1] = $subobj11; $ary = array($obj0, $obj1); $tpl = array("MyObj"); test("recursive object list with object list /w string", $ary, $tpl, $ary); --EXPECTF-- array(2) { [0]=> object(MyObj)#%d (4) { ["data:private"]=> string(8) "datadata" ["priv:private"]=> string(8) "privdata" ["pdata"]=> string(8) "pubdata0" ["subary"]=> array(2) { [0]=> object(SubObj)#%d (3) { ["subdata:private"]=> string(11) "subdatadata" ["subpriv:private"]=> string(11) "subprivdata" ["subpdata"]=> string(12) "subpubdata00" } [1]=> object(SubObj)#%d (3) { ["subdata:private"]=> string(11) "subdatadata" ["subpriv:private"]=> string(11) "subprivdata" ["subpdata"]=> string(10) "subpdata01" } } } [1]=> object(MyObj)#%d (4) { ["data:private"]=> string(8) "datadata" ["priv:private"]=> string(8) "privdata" ["pdata"]=> string(8) "pubdata1" ["subary"]=> array(2) { [0]=> object(SubObj)#%d (3) { ["subdata:private"]=> string(11) "subdatadata" ["subpriv:private"]=> string(11) "subprivdata" ["subpdata"]=> string(11) "subpubdata1" } [1]=> object(SubObj)#%d (3) { ["subdata:private"]=> string(11) "subdatadata" ["subpriv:private"]=> string(11) "subprivdata" ["subpdata"]=> string(10) "subpdata11" } } } } OK msgpack-0.5.5/tests/113.phpt0000644000077100007710000000627712110565607015406 0ustar xinchenxinchen--TEST-- unpack of template converter: multiple class/variable: class unpacker (array: object) --SKIPIF-- pack($variable); $unserialized = $msgpack->unpack($serialized, $object); var_dump($unserialized); if ($result) { echo $unserialized == $result ? 'OK' : 'ERROR', PHP_EOL; } else { echo 'SKIP', PHP_EOL; } } class MyObj { private $data = null; private $priv = "privdata"; public $pdata = null; public $subary = null; function __construct() { $this->data = "datadata"; $this->subary = array(new SubObj()); } } class SubObj { private $subdata = null; private $subpriv = "subprivdata"; public $subpdata = null; function __construct() { $this->subdata = "subdatadata"; } } $obj0 = new MyObj(); $obj0->pdata = "pubdata0"; $obj0->subary[0]->subpdata = "subpubdata00"; $subobj01 = new SubObj(); $subobj01->subpdata = "subpdata01"; $obj0->subary[1] = $subobj01; $obj1 = new MyObj(); $obj1->pdata = "pubdata1"; $obj1->subary[0]->subpdata = "subpubdata1"; $subobj11 = new SubObj(); $subobj11->subpdata = "subpdata11"; $obj1->subary[1] = $subobj11; $ary = array($obj0, $obj1); $tpl = array(new MyObj()); test("recursive object list with object list /w instance", $ary, $tpl, $ary); --EXPECTF-- array(2) { [0]=> object(MyObj)#%d (4) { [%r"?data"?:("MyObj":)?private"?%r]=> string(8) "datadata" [%r"?priv"?:("MyObj":)?private"?%r]=> string(8) "privdata" ["pdata"]=> string(8) "pubdata0" ["subary"]=> array(2) { [0]=> object(SubObj)#%d (3) { [%r"?subdata"?:("SubObj":)?private"?%r]=> string(11) "subdatadata" [%r"?subpriv"?:("SubObj":)?private"?%r]=> string(11) "subprivdata" ["subpdata"]=> string(12) "subpubdata00" } [1]=> object(SubObj)#%d (3) { [%r"?subdata"?:("SubObj":)?private"?%r]=> string(11) "subdatadata" [%r"?subpriv"?:("SubObj":)?private"?%r]=> string(11) "subprivdata" ["subpdata"]=> string(10) "subpdata01" } } } [1]=> object(MyObj)#%d (4) { [%r"?data"?:("MyObj":)?private"?%r]=> string(8) "datadata" [%r"?priv"?:("MyObj":)?private"?%r]=> string(8) "privdata" ["pdata"]=> string(8) "pubdata1" ["subary"]=> array(2) { [0]=> object(SubObj)#%d (3) { [%r"?subdata"?:("SubObj":)?private"?%r]=> string(11) "subdatadata" [%r"?subpriv"?:("SubObj":)?private"?%r]=> string(11) "subprivdata" ["subpdata"]=> string(11) "subpubdata1" } [1]=> object(SubObj)#%d (3) { [%r"?subdata"?:("SubObj":)?private"?%r]=> string(11) "subdatadata" [%r"?subpriv"?:("SubObj":)?private"?%r]=> string(11) "subprivdata" ["subpdata"]=> string(10) "subpdata11" } } } } OK msgpack-0.5.5/tests/113b.phpt0000644000077100007710000000572412110565607015544 0ustar xinchenxinchen--TEST-- unpack of template converter: multiple class/variable: class unpacker (array: object) --SKIPIF-- = 0) { echo "skip tests in PHP 5.1 or older"; } --FILE-- pack($variable); $unserialized = $msgpack->unpack($serialized, $object); var_dump($unserialized); if ($result) { echo $unserialized == $result ? 'OK' : 'ERROR', PHP_EOL; } else { echo 'SKIP', PHP_EOL; } } class MyObj { private $data = null; private $priv = "privdata"; public $pdata = null; public $subary = null; function __construct() { $this->data = "datadata"; $this->subary = array(new SubObj()); } } class SubObj { private $subdata = null; private $subpriv = "subprivdata"; public $subpdata = null; function __construct() { $this->subdata = "subdatadata"; } } $obj0 = new MyObj(); $obj0->pdata = "pubdata0"; $obj0->subary[0]->subpdata = "subpubdata00"; $subobj01 = new SubObj(); $subobj01->subpdata = "subpdata01"; $obj0->subary[1] = $subobj01; $obj1 = new MyObj(); $obj1->pdata = "pubdata1"; $obj1->subary[0]->subpdata = "subpubdata1"; $subobj11 = new SubObj(); $subobj11->subpdata = "subpdata11"; $obj1->subary[1] = $subobj11; $ary = array($obj0, $obj1); $tpl = array(new MyObj()); test("recursive object list with object list /w instance", $ary, $tpl, $ary); --EXPECTF-- array(2) { [0]=> object(MyObj)#%d (4) { ["data:private"]=> string(8) "datadata" ["priv:private"]=> string(8) "privdata" ["pdata"]=> string(8) "pubdata0" ["subary"]=> array(2) { [0]=> object(SubObj)#%d (3) { ["subdata:private"]=> string(11) "subdatadata" ["subpriv:private"]=> string(11) "subprivdata" ["subpdata"]=> string(12) "subpubdata00" } [1]=> object(SubObj)#%d (3) { ["subdata:private"]=> string(11) "subdatadata" ["subpriv:private"]=> string(11) "subprivdata" ["subpdata"]=> string(10) "subpdata01" } } } [1]=> object(MyObj)#%d (4) { ["data:private"]=> string(8) "datadata" ["priv:private"]=> string(8) "privdata" ["pdata"]=> string(8) "pubdata1" ["subary"]=> array(2) { [0]=> object(SubObj)#%d (3) { ["subdata:private"]=> string(11) "subdatadata" ["subpriv:private"]=> string(11) "subprivdata" ["subpdata"]=> string(11) "subpubdata1" } [1]=> object(SubObj)#%d (3) { ["subdata:private"]=> string(11) "subdatadata" ["subpriv:private"]=> string(11) "subprivdata" ["subpdata"]=> string(10) "subpdata11" } } } } OK msgpack-0.5.5/tests/114.phpt0000644000077100007710000000662112110565607015400 0ustar xinchenxinchen--TEST-- unpack of template converter: multiple class/variable: class unpacker (array) --SKIPIF-- pack($variable); $unserialized = $msgpack->unpack($serialized, $object); var_dump($unserialized); if ($result) { echo $unserialized == $result ? 'OK' : 'ERROR', PHP_EOL; } else { echo 'SKIP', PHP_EOL; } } class MyObj { private $data = null; private $priv = "privdata"; public $pdata = null; public $subary = null; function __construct() { $this->data = "datadata"; $this->subary = array(new SubObj()); } } class SubObj { private $subdata = null; private $subpriv = "subprivdata"; public $subpdata = null; function __construct() { $this->subdata = "subdatadata"; } } $arySubObj = array( "subdata" => "subdatadata", "subpriv" => "subprivdata", "subpdata" => null, ); $aryMyObj = array( "data" => "datadata", "priv" => "privdata", "pdata" => null, "subary" => array($arySubObj), ); $obj0 = new MyObj(); $obj0->pdata = "pubdata0"; $obj0->subary[0]->subpdata = "subpubdata00"; $subobj01 = new SubObj(); $subobj01->subpdata = "subpdata01"; $obj0->subary[1] = $subobj01; $obj1 = new MyObj(); $obj1->pdata = "pubdata1"; $obj1->subary[0]->subpdata = "subpubdata1"; $subobj11 = new SubObj(); $subobj11->subpdata = "subpdata11"; $obj1->subary[1] = $subobj11; $ary = array($obj0, $obj1); $tpl = array($aryMyObj); $resary = array($aryMyObj, $aryMyObj); $resary[0]["pdata"] = "pubdata0"; $resary[0]["subary"][] = $arySubObj; $resary[0]["subary"][0]["subpdata"] = "subpubdata00"; $resary[0]["subary"][1]["subpdata"] = "subpdata01"; $resary[1]["subary"][] = $arySubObj; $resary[1]["pdata"] = "pubdata1"; $resary[1]["subary"][0]["subpdata"] = "subpubdata1"; $resary[1]["subary"][1]["subpdata"] = "subpdata11"; test("recursive object list to associative array list", $ary, $tpl, $resary); --EXPECTF-- array(2) { [0]=> array(4) { ["data"]=> string(8) "datadata" ["priv"]=> string(8) "privdata" ["pdata"]=> string(8) "pubdata0" ["subary"]=> array(2) { [0]=> array(3) { ["subdata"]=> string(11) "subdatadata" ["subpriv"]=> string(11) "subprivdata" ["subpdata"]=> string(12) "subpubdata00" } [1]=> array(3) { ["subdata"]=> string(11) "subdatadata" ["subpriv"]=> string(11) "subprivdata" ["subpdata"]=> string(10) "subpdata01" } } } [1]=> array(4) { ["data"]=> string(8) "datadata" ["priv"]=> string(8) "privdata" ["pdata"]=> string(8) "pubdata1" ["subary"]=> array(2) { [0]=> array(3) { ["subdata"]=> string(11) "subdatadata" ["subpriv"]=> string(11) "subprivdata" ["subpdata"]=> string(11) "subpubdata1" } [1]=> array(3) { ["subdata"]=> string(11) "subdatadata" ["subpriv"]=> string(11) "subprivdata" ["subpdata"]=> string(10) "subpdata11" } } } } OK msgpack-0.5.5/tests/114b.phpt0000644000077100007710000000662212110565607015543 0ustar xinchenxinchen--TEST-- unpack of template converter: multiple class/variable: class unpacker (array) --SKIPIF-- = 0) { echo "skip tests in PHP 5.1 or older"; } --FILE-- pack($variable); $unserialized = $msgpack->unpack($serialized, $object); var_dump($unserialized); if ($result) { echo $unserialized == $result ? 'OK' : 'ERROR', PHP_EOL; } else { echo 'SKIP', PHP_EOL; } } class MyObj { private $data = null; private $priv = "privdata"; public $pdata = null; public $subary = null; function __construct() { $this->data = "datadata"; $this->subary = array(new SubObj()); } } class SubObj { private $subdata = null; private $subpriv = "subprivdata"; public $subpdata = null; function __construct() { $this->subdata = "subdatadata"; } } $arySubObj = array( "subdata" => "subdatadata", "subpriv" => "subprivdata", "subpdata" => null, ); $aryMyObj = array( "data" => "datadata", "priv" => "privdata", "pdata" => null, "subary" => array($arySubObj), ); $obj0 = new MyObj(); $obj0->pdata = "pubdata0"; $obj0->subary[0]->subpdata = "subpubdata00"; $subobj01 = new SubObj(); $subobj01->subpdata = "subpdata01"; $obj0->subary[1] = $subobj01; $obj1 = new MyObj(); $obj1->pdata = "pubdata1"; $obj1->subary[0]->subpdata = "subpubdata1"; $subobj11 = new SubObj(); $subobj11->subpdata = "subpdata11"; $obj1->subary[1] = $subobj11; $ary = array($obj0, $obj1); $tpl = array($aryMyObj); $resary = array($aryMyObj, $aryMyObj); $resary[0]["pdata"] = "pubdata0"; $resary[0]["subary"][] = $arySubObj; $resary[0]["subary"][0]["subpdata"] = "subpubdata00"; $resary[0]["subary"][1]["subpdata"] = "subpdata01"; $resary[1]["subary"][] = $arySubObj; $resary[1]["pdata"] = "pubdata1"; $resary[1]["subary"][0]["subpdata"] = "subpubdata1"; $resary[1]["subary"][1]["subpdata"] = "subpdata11"; test("recursive object list to associative array list", $ary, $tpl, $resary); --EXPECTF-- array(2) { [0]=> array(4) { ["data"]=> string(8) "datadata" ["priv"]=> string(8) "privdata" ["pdata"]=> string(8) "pubdata0" ["subary"]=> array(2) { [0]=> array(3) { ["subdata"]=> string(11) "subdatadata" ["subpriv"]=> string(11) "subprivdata" ["subpdata"]=> string(12) "subpubdata00" } [1]=> array(3) { ["subdata"]=> string(11) "subdatadata" ["subpriv"]=> string(11) "subprivdata" ["subpdata"]=> string(10) "subpdata01" } } } [1]=> array(4) { ["data"]=> string(8) "datadata" ["priv"]=> string(8) "privdata" ["pdata"]=> string(8) "pubdata1" ["subary"]=> array(2) { [0]=> array(3) { ["subdata"]=> string(11) "subdatadata" ["subpriv"]=> string(11) "subprivdata" ["subpdata"]=> string(11) "subpubdata1" } [1]=> array(3) { ["subdata"]=> string(11) "subdatadata" ["subpriv"]=> string(11) "subprivdata" ["subpdata"]=> string(10) "subpdata11" } } } } OK msgpack-0.5.5/tests/115.phpt0000644000077100007710000000305112110565607015373 0ustar xinchenxinchen--TEST-- unpack of template converter: class unpacker (array: string: OPT_PHPONLY=false) --SKIPIF-- setOption(MessagePack::OPT_PHPONLY, false); $serialized = $msgpack->pack($variable); $unserialized = $msgpack->unpack($serialized, $object); var_dump($unserialized); if ($result) { echo $unserialized == $result ? 'OK' : 'ERROR', PHP_EOL; } else { echo 'SKIP', PHP_EOL; } } class MyObj { private $data = null; private $priv = "privdata"; public $pdata = null; function __construct() { $this->data = "datadata"; } } $obj = new MyObj(); $obj->pdata = "pubdata0"; $obj2 = new MyObj(); $obj2->pdata = "pubdata1"; $ary = array($obj, $obj2); $tpl = array("MyObj"); test("object list /w string", $ary, $tpl, $ary); --EXPECTF-- array(2) { [0]=> object(MyObj)#%d (3) { [%r"?data"?:("MyObj":)?private"?%r]=> string(8) "datadata" [%r"?priv"?:("MyObj":)?private"?%r]=> string(8) "privdata" ["pdata"]=> string(8) "pubdata0" } [1]=> object(MyObj)#%d (3) { [%r"?data"?:("MyObj":)?private"?%r]=> string(8) "datadata" [%r"?priv"?:("MyObj":)?private"?%r]=> string(8) "privdata" ["pdata"]=> string(8) "pubdata1" } } OK msgpack-0.5.5/tests/115b.phpt0000644000077100007710000000316412110565607015542 0ustar xinchenxinchen--TEST-- unpack of template converter: class unpacker (array: string: OPT_PHPONLY=false) --SKIPIF-- = 0) { echo "skip tests in PHP 5.1 or older"; } --FILE-- setOption(MESSAGEPACK_OPT_PHPONLY, false); } else { $msgpack->setOption(MessagePack::OPT_PHPONLY, false); } $serialized = $msgpack->pack($variable); $unserialized = $msgpack->unpack($serialized, $object); var_dump($unserialized); if ($result) { echo $unserialized == $result ? 'OK' : 'ERROR', PHP_EOL; } else { echo 'SKIP', PHP_EOL; } } class MyObj { private $data = null; private $priv = "privdata"; public $pdata = null; function __construct() { $this->data = "datadata"; } } $obj = new MyObj(); $obj->pdata = "pubdata0"; $obj2 = new MyObj(); $obj2->pdata = "pubdata1"; $ary = array($obj, $obj2); $tpl = array("MyObj"); test("object list /w string", $ary, $tpl, $ary); --EXPECTF-- array(2) { [0]=> object(MyObj)#%d (3) { ["data:private"]=> string(8) "datadata" ["priv:private"]=> string(8) "privdata" ["pdata"]=> string(8) "pubdata0" } [1]=> object(MyObj)#%d (3) { ["data:private"]=> string(8) "datadata" ["priv:private"]=> string(8) "privdata" ["pdata"]=> string(8) "pubdata1" } } OK msgpack-0.5.5/tests/116.phpt0000644000077100007710000000305712110565607015402 0ustar xinchenxinchen--TEST-- unpack of template converter: class unpacker (array: object: OPT_PHPONLY=false) --SKIPIF-- setOption(MessagePack::OPT_PHPONLY, false); $serialized = $msgpack->pack($variable); $unserialized = $msgpack->unpack($serialized, $object); var_dump($unserialized); if ($result) { echo $unserialized == $result ? 'OK' : 'ERROR', PHP_EOL; } else { echo 'SKIP', PHP_EOL; } } class MyObj { private $data = null; private $priv = "privdata"; public $pdata = null; function __construct() { $this->data = "datadata"; } } $obj = new MyObj(); $obj->pdata = "pubdata0"; $obj2 = new MyObj(); $obj2->pdata = "pubdata1"; $ary = array($obj, $obj2); $tpl = array(new MyObj()); test("object list /w instance", $ary, $tpl, $ary); --EXPECTF-- array(2) { [0]=> object(MyObj)#%d (3) { [%r"?data"?:("MyObj":)?private"?%r]=> string(8) "datadata" [%r"?priv"?:("MyObj":)?private"?%r]=> string(8) "privdata" ["pdata"]=> string(8) "pubdata0" } [1]=> object(MyObj)#%d (3) { [%r"?data"?:("MyObj":)?private"?%r]=> string(8) "datadata" [%r"?priv"?:("MyObj":)?private"?%r]=> string(8) "privdata" ["pdata"]=> string(8) "pubdata1" } } OK msgpack-0.5.5/tests/116b.phpt0000644000077100007710000000317212110565607015542 0ustar xinchenxinchen--TEST-- unpack of template converter: class unpacker (array: object: OPT_PHPONLY=false) --SKIPIF-- = 0) { echo "skip tests in PHP 5.1 or older"; } --FILE-- setOption(MESSAGEPACK_OPT_PHPONLY, false); } else { $msgpack->setOption(MessagePack::OPT_PHPONLY, false); } $serialized = $msgpack->pack($variable); $unserialized = $msgpack->unpack($serialized, $object); var_dump($unserialized); if ($result) { echo $unserialized == $result ? 'OK' : 'ERROR', PHP_EOL; } else { echo 'SKIP', PHP_EOL; } } class MyObj { private $data = null; private $priv = "privdata"; public $pdata = null; function __construct() { $this->data = "datadata"; } } $obj = new MyObj(); $obj->pdata = "pubdata0"; $obj2 = new MyObj(); $obj2->pdata = "pubdata1"; $ary = array($obj, $obj2); $tpl = array(new MyObj()); test("object list /w instance", $ary, $tpl, $ary); --EXPECTF-- array(2) { [0]=> object(MyObj)#%d (3) { ["data:private"]=> string(8) "datadata" ["priv:private"]=> string(8) "privdata" ["pdata"]=> string(8) "pubdata0" } [1]=> object(MyObj)#%d (3) { ["data:private"]=> string(8) "datadata" ["priv:private"]=> string(8) "privdata" ["pdata"]=> string(8) "pubdata1" } } OK msgpack-0.5.5/tests/117.phpt0000644000077100007710000000336512110565607015405 0ustar xinchenxinchen--TEST-- unpack of template converter: class unpacker (string: OPT_PHPONLY=false) --SKIPIF-- setOption(MessagePack::OPT_PHPONLY, false); $serialized = $msgpack->pack($variable); $unserialized = $msgpack->unpack($serialized, $object); var_dump($unserialized); if ($result) { echo $unserialized == $result ? 'OK' : 'ERROR', PHP_EOL; } else { echo 'SKIP', PHP_EOL; } } class MyObj { private $data = null; private $priv = "privdata"; public $pdata = null; public $subary = null; function __construct() { $this->data = "datadata"; $this->subary = new SubObj(); } } class SubObj { private $subdata = null; private $subpriv = "subprivdata"; public $subpdata = null; function __construct() { $this->subdata = "subdatadata"; } } $obj = new MyObj(); $obj->pdata = "pubdata"; $obj->subary->subpdata = "subpubdata"; $tpl = "MyObj"; test("recursive object /w string", $obj, $tpl, $obj); --EXPECTF-- object(MyObj)#%d (4) { [%r"?data"?:("MyObj":)?private"?%r]=> string(8) "datadata" [%r"?priv"?:("MyObj":)?private"?%r]=> string(8) "privdata" ["pdata"]=> string(7) "pubdata" ["subary"]=> object(SubObj)#%d (3) { [%r"?subdata"?:("SubObj":)?private"?%r]=> string(11) "subdatadata" [%r"?subpriv"?:("SubObj":)?private"?%r]=> string(11) "subprivdata" ["subpdata"]=> string(10) "subpubdata" } } OK msgpack-0.5.5/tests/117b.phpt0000644000077100007710000000347612110565607015552 0ustar xinchenxinchen--TEST-- unpack of template converter: class unpacker (string: OPT_PHPONLY=false) --SKIPIF-- = 0) { echo "skip tests in PHP 5.1 or older"; } --FILE-- setOption(MESSAGEPACK_OPT_PHPONLY, false); } else { $msgpack->setOption(MessagePack::OPT_PHPONLY, false); } $serialized = $msgpack->pack($variable); $unserialized = $msgpack->unpack($serialized, $object); var_dump($unserialized); if ($result) { echo $unserialized == $result ? 'OK' : 'ERROR', PHP_EOL; } else { echo 'SKIP', PHP_EOL; } } class MyObj { private $data = null; private $priv = "privdata"; public $pdata = null; public $subary = null; function __construct() { $this->data = "datadata"; $this->subary = new SubObj(); } } class SubObj { private $subdata = null; private $subpriv = "subprivdata"; public $subpdata = null; function __construct() { $this->subdata = "subdatadata"; } } $obj = new MyObj(); $obj->pdata = "pubdata"; $obj->subary->subpdata = "subpubdata"; $tpl = "MyObj"; test("recursive object /w string", $obj, $tpl, $obj); --EXPECTF-- object(MyObj)#%d (4) { ["data:private"]=> string(8) "datadata" ["priv:private"]=> string(8) "privdata" ["pdata"]=> string(7) "pubdata" ["subary"]=> object(SubObj)#%d (3) { ["subdata:private"]=> string(11) "subdatadata" ["subpriv:private"]=> string(11) "subprivdata" ["subpdata"]=> string(10) "subpubdata" } } OK msgpack-0.5.5/tests/118.phpt0000644000077100007710000000337312110565607015405 0ustar xinchenxinchen--TEST-- unpack of template converter: class unpacker (object: OPT_PHPONLY=false) --SKIPIF-- setOption(MessagePack::OPT_PHPONLY, false); $serialized = $msgpack->pack($variable); $unserialized = $msgpack->unpack($serialized, $object); var_dump($unserialized); if ($result) { echo $unserialized == $result ? 'OK' : 'ERROR', PHP_EOL; } else { echo 'SKIP', PHP_EOL; } } class MyObj { private $data = null; private $priv = "privdata"; public $pdata = null; public $subary = null; function __construct() { $this->data = "datadata"; $this->subary = new SubObj(); } } class SubObj { private $subdata = null; private $subpriv = "subprivdata"; public $subpdata = null; function __construct() { $this->subdata = "subdatadata"; } } $obj = new MyObj(); $obj->pdata = "pubdata"; $obj->subary->subpdata = "subpubdata"; $tpl = new MyObj(); test("recursive object /w instance", $obj, $tpl, $obj); --EXPECTF-- object(MyObj)#%d (4) { [%r"?data"?:("MyObj":)?private"?%r]=> string(8) "datadata" [%r"?priv"?:("MyObj":)?private"?%r]=> string(8) "privdata" ["pdata"]=> string(7) "pubdata" ["subary"]=> object(SubObj)#%d (3) { [%r"?subdata"?:("SubObj":)?private"?%r]=> string(11) "subdatadata" [%r"?subpriv"?:("SubObj":)?private"?%r]=> string(11) "subprivdata" ["subpdata"]=> string(10) "subpubdata" } } OK msgpack-0.5.5/tests/118b.phpt0000644000077100007710000000350412110565607015543 0ustar xinchenxinchen--TEST-- unpack of template converter: class unpacker (object: OPT_PHPONLY=false) --SKIPIF-- = 0) { echo "skip tests in PHP 5.1 or older"; } --FILE-- setOption(MESSAGEPACK_OPT_PHPONLY, false); } else { $msgpack->setOption(MessagePack::OPT_PHPONLY, false); } $serialized = $msgpack->pack($variable); $unserialized = $msgpack->unpack($serialized, $object); var_dump($unserialized); if ($result) { echo $unserialized == $result ? 'OK' : 'ERROR', PHP_EOL; } else { echo 'SKIP', PHP_EOL; } } class MyObj { private $data = null; private $priv = "privdata"; public $pdata = null; public $subary = null; function __construct() { $this->data = "datadata"; $this->subary = new SubObj(); } } class SubObj { private $subdata = null; private $subpriv = "subprivdata"; public $subpdata = null; function __construct() { $this->subdata = "subdatadata"; } } $obj = new MyObj(); $obj->pdata = "pubdata"; $obj->subary->subpdata = "subpubdata"; $tpl = new MyObj(); test("recursive object /w instance", $obj, $tpl, $obj); --EXPECTF-- object(MyObj)#%d (4) { ["data:private"]=> string(8) "datadata" ["priv:private"]=> string(8) "privdata" ["pdata"]=> string(7) "pubdata" ["subary"]=> object(SubObj)#%d (3) { ["subdata:private"]=> string(11) "subdatadata" ["subpriv:private"]=> string(11) "subprivdata" ["subpdata"]=> string(10) "subpubdata" } } OK msgpack-0.5.5/tests/119.phpt0000644000077100007710000000356012110565607015404 0ustar xinchenxinchen--TEST-- unpack of template converter: multiple class: class unpacker (array: string: OPT_PHPONLY=false) --SKIPIF-- setOption(MessagePack::OPT_PHPONLY, false); $serialized = $msgpack->pack($variable); $unserialized = $msgpack->unpack($serialized, $object); var_dump($unserialized); if ($result) { echo $unserialized == $result ? 'OK' : 'ERROR', PHP_EOL; } else { echo 'SKIP', PHP_EOL; } } class MyObj { private $data = null; private $priv = "privdata"; public $pdata = null; public $subary = null; function __construct() { $this->data = "datadata"; $this->subary = new SubObj(); } } class SubObj { private $subdata = null; private $subpriv = "subprivdata"; public $subpdata = null; function __construct() { $this->subdata = "subdatadata"; } } $obj = new MyObj(); $obj->pdata = "pubdata"; $obj->subary->subpdata = "subpubdata"; $ary = array($obj); $tpl = array("MyObj"); test("recursive object with object list /w string", $ary, $tpl, $ary); --EXPECTF-- array(1) { [0]=> object(MyObj)#%d (4) { [%r"?data"?:("MyObj":)?private"?%r]=> string(8) "datadata" [%r"?priv"?:("MyObj":)?private"?%r]=> string(8) "privdata" ["pdata"]=> string(7) "pubdata" ["subary"]=> object(SubObj)#%d (3) { [%r"?subdata"?:("SubObj":)?private"?%r]=> string(11) "subdatadata" [%r"?subpriv"?:("SubObj":)?private"?%r]=> string(11) "subprivdata" ["subpdata"]=> string(10) "subpubdata" } } } OK msgpack-0.5.5/tests/119b.phpt0000644000077100007710000000367112110565607015551 0ustar xinchenxinchen--TEST-- unpack of template converter: multiple class: class unpacker (array: string: OPT_PHPONLY=false) --SKIPIF-- = 0) { echo "skip tests in PHP 5.1 or older"; } --FILE-- setOption(MESSAGEPACK_OPT_PHPONLY, false); } else { $msgpack->setOption(MessagePack::OPT_PHPONLY, false); } $serialized = $msgpack->pack($variable); $unserialized = $msgpack->unpack($serialized, $object); var_dump($unserialized); if ($result) { echo $unserialized == $result ? 'OK' : 'ERROR', PHP_EOL; } else { echo 'SKIP', PHP_EOL; } } class MyObj { private $data = null; private $priv = "privdata"; public $pdata = null; public $subary = null; function __construct() { $this->data = "datadata"; $this->subary = new SubObj(); } } class SubObj { private $subdata = null; private $subpriv = "subprivdata"; public $subpdata = null; function __construct() { $this->subdata = "subdatadata"; } } $obj = new MyObj(); $obj->pdata = "pubdata"; $obj->subary->subpdata = "subpubdata"; $ary = array($obj); $tpl = array("MyObj"); test("recursive object with object list /w string", $ary, $tpl, $ary); --EXPECTF-- array(1) { [0]=> object(MyObj)#%d (4) { ["data:private"]=> string(8) "datadata" ["priv:private"]=> string(8) "privdata" ["pdata"]=> string(7) "pubdata" ["subary"]=> object(SubObj)#%d (3) { ["subdata:private"]=> string(11) "subdatadata" ["subpriv:private"]=> string(11) "subprivdata" ["subpdata"]=> string(10) "subpubdata" } } } OK msgpack-0.5.5/tests/120.phpt0000644000077100007710000000356612110565607015402 0ustar xinchenxinchen--TEST-- unpack of template converter: multiple class: class unpacker (array: object: OPT_PHPONLY=false) --SKIPIF-- setOption(MessagePack::OPT_PHPONLY, false); $serialized = $msgpack->pack($variable); $unserialized = $msgpack->unpack($serialized, $object); var_dump($unserialized); if ($result) { echo $unserialized == $result ? 'OK' : 'ERROR', PHP_EOL; } else { echo 'SKIP', PHP_EOL; } } class MyObj { private $data = null; private $priv = "privdata"; public $pdata = null; public $subary = null; function __construct() { $this->data = "datadata"; $this->subary = new SubObj(); } } class SubObj { private $subdata = null; private $subpriv = "subprivdata"; public $subpdata = null; function __construct() { $this->subdata = "subdatadata"; } } $obj = new MyObj(); $obj->pdata = "pubdata"; $obj->subary->subpdata = "subpubdata"; $ary = array($obj); $tpl = array(new MyObj()); test("recursive object with object list /w instance", $ary, $tpl, $ary); --EXPECTF-- array(1) { [0]=> object(MyObj)#%d (4) { [%r"?data"?:("MyObj":)?private"?%r]=> string(8) "datadata" [%r"?priv"?:("MyObj":)?private"?%r]=> string(8) "privdata" ["pdata"]=> string(7) "pubdata" ["subary"]=> object(SubObj)#%d (3) { [%r"?subdata"?:("SubObj":)?private"?%r]=> string(11) "subdatadata" [%r"?subpriv"?:("SubObj":)?private"?%r]=> string(11) "subprivdata" ["subpdata"]=> string(10) "subpubdata" } } } OK msgpack-0.5.5/tests/120b.phpt0000644000077100007710000000367312110565607015543 0ustar xinchenxinchen--TEST-- unpack of template converter: multiple class: class unpacker (array: object: OPT_PHPONLY=false) --SKIPIF-- = 0) { echo "skip tests in PHP 5.1 or older"; } --FILE-- setOption(MESSAGEPACK_OPT_PHPONLY, false); } else { $msgpack->setOption(MessagePack::OPT_PHPONLY, false); } $serialized = $msgpack->pack($variable); $unserialized = $msgpack->unpack($serialized, $object); var_dump($unserialized); if ($result) { echo $unserialized == $result ? 'OK' : 'ERROR', PHP_EOL; } else { echo 'SKIP', PHP_EOL; } } class MyObj { private $data = null; private $priv = "privdata"; public $pdata = null; public $subary = null; function __construct() { $this->data = "datadata"; $this->subary = new SubObj(); } } class SubObj { private $subdata = null; private $subpriv = "subprivdata"; public $subpdata = null; function __construct() { $this->subdata = "subdatadata"; } } $obj = new MyObj(); $obj->pdata = "pubdata"; $obj->subary->subpdata = "subpubdata"; $ary = array($obj); $tpl = array("MyObj"); test("recursive object with object list /w instance", $ary, $tpl, $ary); --EXPECTF-- array(1) { [0]=> object(MyObj)#%d (4) { ["data:private"]=> string(8) "datadata" ["priv:private"]=> string(8) "privdata" ["pdata"]=> string(7) "pubdata" ["subary"]=> object(SubObj)#%d (3) { ["subdata:private"]=> string(11) "subdatadata" ["subpriv:private"]=> string(11) "subprivdata" ["subpdata"]=> string(10) "subpubdata" } } } OK msgpack-0.5.5/tests/121.phpt0000644000077100007710000000465012110565607015376 0ustar xinchenxinchen--TEST-- unpack of template converter: multiple variable: class unpacker (array: string: OPT_PHPONLY=false) --SKIPIF-- setOption(MessagePack::OPT_PHPONLY, false); $serialized = $msgpack->pack($variable); $unserialized = $msgpack->unpack($serialized, $object); var_dump($unserialized); if ($result) { echo $unserialized == $result ? 'OK' : 'ERROR', PHP_EOL; } else { echo 'SKIP', PHP_EOL; } } class MyObj { private $data = null; private $priv = "privdata"; public $pdata = null; public $subary = null; function __construct() { $this->data = "datadata"; $this->subary = new SubObj(); } } class SubObj { private $subdata = null; private $subpriv = "subprivdata"; public $subpdata = null; function __construct() { $this->subdata = "subdatadata"; } } $obj0 = new MyObj(); $obj0->pdata = "pubdata0"; $obj0->subary->subpdata = "subpubdata0"; $obj1 = new MyObj(); $obj1->pdata = "pubdata1"; $obj1->subary->subpdata = "subpubdata1"; $ary = array($obj0, $obj1); $tpl = array("MyObj"); test("recursive object list /w string", $ary, $tpl, $ary); --EXPECTF-- array(2) { [0]=> object(MyObj)#%d (4) { [%r"?data"?:("MyObj":)?private"?%r]=> string(8) "datadata" [%r"?priv"?:("MyObj":)?private"?%r]=> string(8) "privdata" ["pdata"]=> string(8) "pubdata0" ["subary"]=> object(SubObj)#%d (3) { [%r"?subdata"?:("SubObj":)?private"?%r]=> string(11) "subdatadata" [%r"?subpriv"?:("SubObj":)?private"?%r]=> string(11) "subprivdata" ["subpdata"]=> string(11) "subpubdata0" } } [1]=> object(MyObj)#%d (4) { [%r"?data"?:("MyObj":)?private"?%r]=> string(8) "datadata" [%r"?priv"?:("MyObj":)?private"?%r]=> string(8) "privdata" ["pdata"]=> string(8) "pubdata1" ["subary"]=> object(SubObj)#%d (3) { [%r"?subdata"?:("SubObj":)?private"?%r]=> string(11) "subdatadata" [%r"?subpriv"?:("SubObj":)?private"?%r]=> string(11) "subprivdata" ["subpdata"]=> string(11) "subpubdata1" } } } OK msgpack-0.5.5/tests/121b.phpt0000644000077100007710000000464312110565607015542 0ustar xinchenxinchen--TEST-- unpack of template converter: multiple variable: class unpacker (array: string: OPT_PHPONLY=false) --SKIPIF-- = 0) { echo "skip tests in PHP 5.1 or older"; } --FILE-- setOption(MESSAGEPACK_OPT_PHPONLY, false); } else { $msgpack->setOption(MessagePack::OPT_PHPONLY, false); } $serialized = $msgpack->pack($variable); $unserialized = $msgpack->unpack($serialized, $object); var_dump($unserialized); if ($result) { echo $unserialized == $result ? 'OK' : 'ERROR', PHP_EOL; } else { echo 'SKIP', PHP_EOL; } } class MyObj { private $data = null; private $priv = "privdata"; public $pdata = null; public $subary = null; function __construct() { $this->data = "datadata"; $this->subary = new SubObj(); } } class SubObj { private $subdata = null; private $subpriv = "subprivdata"; public $subpdata = null; function __construct() { $this->subdata = "subdatadata"; } } $obj0 = new MyObj(); $obj0->pdata = "pubdata0"; $obj0->subary->subpdata = "subpubdata0"; $obj1 = new MyObj(); $obj1->pdata = "pubdata1"; $obj1->subary->subpdata = "subpubdata1"; $ary = array($obj0, $obj1); $tpl = array("MyObj"); test("recursive object list /w string", $ary, $tpl, $ary); --EXPECTF-- array(2) { [0]=> object(MyObj)#%d (4) { ["data:private"]=> string(8) "datadata" ["priv:private"]=> string(8) "privdata" ["pdata"]=> string(8) "pubdata0" ["subary"]=> object(SubObj)#%d (3) { ["subdata:private"]=> string(11) "subdatadata" ["subpriv:private"]=> string(11) "subprivdata" ["subpdata"]=> string(11) "subpubdata0" } } [1]=> object(MyObj)#%d (4) { ["data:private"]=> string(8) "datadata" ["priv:private"]=> string(8) "privdata" ["pdata"]=> string(8) "pubdata1" ["subary"]=> object(SubObj)#%d (3) { ["subdata:private"]=> string(11) "subdatadata" ["subpriv:private"]=> string(11) "subprivdata" ["subpdata"]=> string(11) "subpubdata1" } } } OK msgpack-0.5.5/tests/122.phpt0000644000077100007710000000465612110565607015405 0ustar xinchenxinchen--TEST-- unpack of template converter: multiple variable: class unpacker (array: object: OPT_PHPONLY=false) --SKIPIF-- setOption(MessagePack::OPT_PHPONLY, false); $serialized = $msgpack->pack($variable); $unserialized = $msgpack->unpack($serialized, $object); var_dump($unserialized); if ($result) { echo $unserialized == $result ? 'OK' : 'ERROR', PHP_EOL; } else { echo 'SKIP', PHP_EOL; } } class MyObj { private $data = null; private $priv = "privdata"; public $pdata = null; public $subary = null; function __construct() { $this->data = "datadata"; $this->subary = new SubObj(); } } class SubObj { private $subdata = null; private $subpriv = "subprivdata"; public $subpdata = null; function __construct() { $this->subdata = "subdatadata"; } } $obj0 = new MyObj(); $obj0->pdata = "pubdata0"; $obj0->subary->subpdata = "subpubdata0"; $obj1 = new MyObj(); $obj1->pdata = "pubdata1"; $obj1->subary->subpdata = "subpubdata1"; $ary = array($obj0, $obj1); $tpl = array(new MyObj()); test("recursive object list /w instance", $ary, $tpl, $ary); --EXPECTF-- array(2) { [0]=> object(MyObj)#%d (4) { [%r"?data"?:("MyObj":)?private"?%r]=> string(8) "datadata" [%r"?priv"?:("MyObj":)?private"?%r]=> string(8) "privdata" ["pdata"]=> string(8) "pubdata0" ["subary"]=> object(SubObj)#%d (3) { [%r"?subdata"?:("SubObj":)?private"?%r]=> string(11) "subdatadata" [%r"?subpriv"?:("SubObj":)?private"?%r]=> string(11) "subprivdata" ["subpdata"]=> string(11) "subpubdata0" } } [1]=> object(MyObj)#%d (4) { [%r"?data"?:("MyObj":)?private"?%r]=> string(8) "datadata" [%r"?priv"?:("MyObj":)?private"?%r]=> string(8) "privdata" ["pdata"]=> string(8) "pubdata1" ["subary"]=> object(SubObj)#%d (3) { [%r"?subdata"?:("SubObj":)?private"?%r]=> string(11) "subdatadata" [%r"?subpriv"?:("SubObj":)?private"?%r]=> string(11) "subprivdata" ["subpdata"]=> string(11) "subpubdata1" } } } OK msgpack-0.5.5/tests/122b.phpt0000644000077100007710000000465112110565607015542 0ustar xinchenxinchen--TEST-- unpack of template converter: multiple variable: class unpacker (array: object: OPT_PHPONLY=false) --SKIPIF-- = 0) { echo "skip tests in PHP 5.1 or older"; } --FILE-- setOption(MESSAGEPACK_OPT_PHPONLY, false); } else { $msgpack->setOption(MessagePack::OPT_PHPONLY, false); } $serialized = $msgpack->pack($variable); $unserialized = $msgpack->unpack($serialized, $object); var_dump($unserialized); if ($result) { echo $unserialized == $result ? 'OK' : 'ERROR', PHP_EOL; } else { echo 'SKIP', PHP_EOL; } } class MyObj { private $data = null; private $priv = "privdata"; public $pdata = null; public $subary = null; function __construct() { $this->data = "datadata"; $this->subary = new SubObj(); } } class SubObj { private $subdata = null; private $subpriv = "subprivdata"; public $subpdata = null; function __construct() { $this->subdata = "subdatadata"; } } $obj0 = new MyObj(); $obj0->pdata = "pubdata0"; $obj0->subary->subpdata = "subpubdata0"; $obj1 = new MyObj(); $obj1->pdata = "pubdata1"; $obj1->subary->subpdata = "subpubdata1"; $ary = array($obj0, $obj1); $tpl = array(new MyObj()); test("recursive object list /w instance", $ary, $tpl, $ary); --EXPECTF-- array(2) { [0]=> object(MyObj)#%d (4) { ["data:private"]=> string(8) "datadata" ["priv:private"]=> string(8) "privdata" ["pdata"]=> string(8) "pubdata0" ["subary"]=> object(SubObj)#%d (3) { ["subdata:private"]=> string(11) "subdatadata" ["subpriv:private"]=> string(11) "subprivdata" ["subpdata"]=> string(11) "subpubdata0" } } [1]=> object(MyObj)#%d (4) { ["data:private"]=> string(8) "datadata" ["priv:private"]=> string(8) "privdata" ["pdata"]=> string(8) "pubdata1" ["subary"]=> object(SubObj)#%d (3) { ["subdata:private"]=> string(11) "subdatadata" ["subpriv:private"]=> string(11) "subprivdata" ["subpdata"]=> string(11) "subpubdata1" } } } OK msgpack-0.5.5/tests/123.phpt0000644000077100007710000000640612110565607015401 0ustar xinchenxinchen--TEST-- unpack of template converter: multiple class/variable: class unpacker (array: string: OPT_PHPONLY=false) --SKIPIF-- setOption(MessagePack::OPT_PHPONLY, false); $serialized = $msgpack->pack($variable); $unserialized = $msgpack->unpack($serialized, $object); var_dump($unserialized); if ($result) { echo $unserialized == $result ? 'OK' : 'ERROR', PHP_EOL; } else { echo 'SKIP', PHP_EOL; } } class MyObj { private $data = null; private $priv = "privdata"; public $pdata = null; public $subary = null; function __construct() { $this->data = "datadata"; $this->subary = array(new SubObj()); } } class SubObj { private $subdata = null; private $subpriv = "subprivdata"; public $subpdata = null; function __construct() { $this->subdata = "subdatadata"; } } $obj0 = new MyObj(); $obj0->pdata = "pubdata0"; $obj0->subary[0]->subpdata = "subpubdata00"; $subobj01 = new SubObj(); $subobj01->subpdata = "subpdata01"; $obj0->subary[1] = $subobj01; $obj1 = new MyObj(); $obj1->pdata = "pubdata1"; $obj1->subary[0]->subpdata = "subpubdata1"; $subobj11 = new SubObj(); $subobj11->subpdata = "subpdata11"; $obj1->subary[1] = $subobj11; $ary = array($obj0, $obj1); $tpl = array("MyObj"); test("recursive object list with object list /w string", $ary, $tpl, $ary); --EXPECTF-- array(2) { [0]=> object(MyObj)#%d (4) { [%r"?data"?:("MyObj":)?private"?%r]=> string(8) "datadata" [%r"?priv"?:("MyObj":)?private"?%r]=> string(8) "privdata" ["pdata"]=> string(8) "pubdata0" ["subary"]=> array(2) { [0]=> object(SubObj)#%d (3) { [%r"?subdata"?:("SubObj":)?private"?%r]=> string(11) "subdatadata" [%r"?subpriv"?:("SubObj":)?private"?%r]=> string(11) "subprivdata" ["subpdata"]=> string(12) "subpubdata00" } [1]=> object(SubObj)#%d (3) { [%r"?subdata"?:("SubObj":)?private"?%r]=> string(11) "subdatadata" [%r"?subpriv"?:("SubObj":)?private"?%r]=> string(11) "subprivdata" ["subpdata"]=> string(10) "subpdata01" } } } [1]=> object(MyObj)#%d (4) { [%r"?data"?:("MyObj":)?private"?%r]=> string(8) "datadata" [%r"?priv"?:("MyObj":)?private"?%r]=> string(8) "privdata" ["pdata"]=> string(8) "pubdata1" ["subary"]=> array(2) { [0]=> object(SubObj)#%d (3) { [%r"?subdata"?:("SubObj":)?private"?%r]=> string(11) "subdatadata" [%r"?subpriv"?:("SubObj":)?private"?%r]=> string(11) "subprivdata" ["subpdata"]=> string(11) "subpubdata1" } [1]=> object(SubObj)#%d (3) { [%r"?subdata"?:("SubObj":)?private"?%r]=> string(11) "subdatadata" [%r"?subpriv"?:("SubObj":)?private"?%r]=> string(11) "subprivdata" ["subpdata"]=> string(10) "subpdata11" } } } } OK msgpack-0.5.5/tests/123b.phpt0000644000077100007710000000626112110565607015542 0ustar xinchenxinchen--TEST-- unpack of template converter: multiple class/variable: class unpacker (array: string: OPT_PHPONLY=false) --SKIPIF-- = 0) { echo "skip tests in PHP 5.1 or older"; } --FILE-- setOption(MESSAGEPACK_OPT_PHPONLY, false); } else { $msgpack->setOption(MessagePack::OPT_PHPONLY, false); } $serialized = $msgpack->pack($variable); $unserialized = $msgpack->unpack($serialized, $object); var_dump($unserialized); if ($result) { echo $unserialized == $result ? 'OK' : 'ERROR', PHP_EOL; } else { echo 'SKIP', PHP_EOL; } } class MyObj { private $data = null; private $priv = "privdata"; public $pdata = null; public $subary = null; function __construct() { $this->data = "datadata"; $this->subary = array(new SubObj()); } } class SubObj { private $subdata = null; private $subpriv = "subprivdata"; public $subpdata = null; function __construct() { $this->subdata = "subdatadata"; } } $obj0 = new MyObj(); $obj0->pdata = "pubdata0"; $obj0->subary[0]->subpdata = "subpubdata00"; $subobj01 = new SubObj(); $subobj01->subpdata = "subpdata01"; $obj0->subary[1] = $subobj01; $obj1 = new MyObj(); $obj1->pdata = "pubdata1"; $obj1->subary[0]->subpdata = "subpubdata1"; $subobj11 = new SubObj(); $subobj11->subpdata = "subpdata11"; $obj1->subary[1] = $subobj11; $ary = array($obj0, $obj1); $tpl = array("MyObj"); test("recursive object list with object list /w string", $ary, $tpl, $ary); --EXPECTF-- array(2) { [0]=> object(MyObj)#%d (4) { ["data:private"]=> string(8) "datadata" ["priv:private"]=> string(8) "privdata" ["pdata"]=> string(8) "pubdata0" ["subary"]=> array(2) { [0]=> object(SubObj)#%d (3) { ["subdata:private"]=> string(11) "subdatadata" ["subpriv:private"]=> string(11) "subprivdata" ["subpdata"]=> string(12) "subpubdata00" } [1]=> object(SubObj)#%d (3) { ["subdata:private"]=> string(11) "subdatadata" ["subpriv:private"]=> string(11) "subprivdata" ["subpdata"]=> string(10) "subpdata01" } } } [1]=> object(MyObj)#%d (4) { ["data:private"]=> string(8) "datadata" ["priv:private"]=> string(8) "privdata" ["pdata"]=> string(8) "pubdata1" ["subary"]=> array(2) { [0]=> object(SubObj)#%d (3) { ["subdata:private"]=> string(11) "subdatadata" ["subpriv:private"]=> string(11) "subprivdata" ["subpdata"]=> string(11) "subpubdata1" } [1]=> object(SubObj)#%d (3) { ["subdata:private"]=> string(11) "subdatadata" ["subpriv:private"]=> string(11) "subprivdata" ["subpdata"]=> string(10) "subpdata11" } } } } OK msgpack-0.5.5/tests/124.phpt0000644000077100007710000000641412110565607015401 0ustar xinchenxinchen--TEST-- unpack of template converter: multiple class/variable: class unpacker (array: object: OPT_PHPONLY=false) --SKIPIF-- setOption(MessagePack::OPT_PHPONLY, false); $serialized = $msgpack->pack($variable); $unserialized = $msgpack->unpack($serialized, $object); var_dump($unserialized); if ($result) { echo $unserialized == $result ? 'OK' : 'ERROR', PHP_EOL; } else { echo 'SKIP', PHP_EOL; } } class MyObj { private $data = null; private $priv = "privdata"; public $pdata = null; public $subary = null; function __construct() { $this->data = "datadata"; $this->subary = array(new SubObj()); } } class SubObj { private $subdata = null; private $subpriv = "subprivdata"; public $subpdata = null; function __construct() { $this->subdata = "subdatadata"; } } $obj0 = new MyObj(); $obj0->pdata = "pubdata0"; $obj0->subary[0]->subpdata = "subpubdata00"; $subobj01 = new SubObj(); $subobj01->subpdata = "subpdata01"; $obj0->subary[1] = $subobj01; $obj1 = new MyObj(); $obj1->pdata = "pubdata1"; $obj1->subary[0]->subpdata = "subpubdata1"; $subobj11 = new SubObj(); $subobj11->subpdata = "subpdata11"; $obj1->subary[1] = $subobj11; $ary = array($obj0, $obj1); $tpl = array(new MyObj()); test("recursive object list with object list /w instance", $ary, $tpl, $ary); --EXPECTF-- array(2) { [0]=> object(MyObj)#%d (4) { [%r"?data"?:("MyObj":)?private"?%r]=> string(8) "datadata" [%r"?priv"?:("MyObj":)?private"?%r]=> string(8) "privdata" ["pdata"]=> string(8) "pubdata0" ["subary"]=> array(2) { [0]=> object(SubObj)#%d (3) { [%r"?subdata"?:("SubObj":)?private"?%r]=> string(11) "subdatadata" [%r"?subpriv"?:("SubObj":)?private"?%r]=> string(11) "subprivdata" ["subpdata"]=> string(12) "subpubdata00" } [1]=> object(SubObj)#%d (3) { [%r"?subdata"?:("SubObj":)?private"?%r]=> string(11) "subdatadata" [%r"?subpriv"?:("SubObj":)?private"?%r]=> string(11) "subprivdata" ["subpdata"]=> string(10) "subpdata01" } } } [1]=> object(MyObj)#%d (4) { [%r"?data"?:("MyObj":)?private"?%r]=> string(8) "datadata" [%r"?priv"?:("MyObj":)?private"?%r]=> string(8) "privdata" ["pdata"]=> string(8) "pubdata1" ["subary"]=> array(2) { [0]=> object(SubObj)#%d (3) { [%r"?subdata"?:("SubObj":)?private"?%r]=> string(11) "subdatadata" [%r"?subpriv"?:("SubObj":)?private"?%r]=> string(11) "subprivdata" ["subpdata"]=> string(11) "subpubdata1" } [1]=> object(SubObj)#%d (3) { [%r"?subdata"?:("SubObj":)?private"?%r]=> string(11) "subdatadata" [%r"?subpriv"?:("SubObj":)?private"?%r]=> string(11) "subprivdata" ["subpdata"]=> string(10) "subpdata11" } } } } OK msgpack-0.5.5/tests/124b.phpt0000644000077100007710000000626712110565607015551 0ustar xinchenxinchen--TEST-- unpack of template converter: multiple class/variable: class unpacker (array: object: OPT_PHPONLY=false) --SKIPIF-- = 0) { echo "skip tests in PHP 5.1 or older"; } --FILE-- setOption(MESSAGEPACK_OPT_PHPONLY, false); } else { $msgpack->setOption(MessagePack::OPT_PHPONLY, false); } $serialized = $msgpack->pack($variable); $unserialized = $msgpack->unpack($serialized, $object); var_dump($unserialized); if ($result) { echo $unserialized == $result ? 'OK' : 'ERROR', PHP_EOL; } else { echo 'SKIP', PHP_EOL; } } class MyObj { private $data = null; private $priv = "privdata"; public $pdata = null; public $subary = null; function __construct() { $this->data = "datadata"; $this->subary = array(new SubObj()); } } class SubObj { private $subdata = null; private $subpriv = "subprivdata"; public $subpdata = null; function __construct() { $this->subdata = "subdatadata"; } } $obj0 = new MyObj(); $obj0->pdata = "pubdata0"; $obj0->subary[0]->subpdata = "subpubdata00"; $subobj01 = new SubObj(); $subobj01->subpdata = "subpdata01"; $obj0->subary[1] = $subobj01; $obj1 = new MyObj(); $obj1->pdata = "pubdata1"; $obj1->subary[0]->subpdata = "subpubdata1"; $subobj11 = new SubObj(); $subobj11->subpdata = "subpdata11"; $obj1->subary[1] = $subobj11; $ary = array($obj0, $obj1); $tpl = array(new MyObj()); test("recursive object list with object list /w instance", $ary, $tpl, $ary); --EXPECTF-- array(2) { [0]=> object(MyObj)#%d (4) { ["data:private"]=> string(8) "datadata" ["priv:private"]=> string(8) "privdata" ["pdata"]=> string(8) "pubdata0" ["subary"]=> array(2) { [0]=> object(SubObj)#%d (3) { ["subdata:private"]=> string(11) "subdatadata" ["subpriv:private"]=> string(11) "subprivdata" ["subpdata"]=> string(12) "subpubdata00" } [1]=> object(SubObj)#%d (3) { ["subdata:private"]=> string(11) "subdatadata" ["subpriv:private"]=> string(11) "subprivdata" ["subpdata"]=> string(10) "subpdata01" } } } [1]=> object(MyObj)#%d (4) { ["data:private"]=> string(8) "datadata" ["priv:private"]=> string(8) "privdata" ["pdata"]=> string(8) "pubdata1" ["subary"]=> array(2) { [0]=> object(SubObj)#%d (3) { ["subdata:private"]=> string(11) "subdatadata" ["subpriv:private"]=> string(11) "subprivdata" ["subpdata"]=> string(11) "subpubdata1" } [1]=> object(SubObj)#%d (3) { ["subdata:private"]=> string(11) "subdatadata" ["subpriv:private"]=> string(11) "subprivdata" ["subpdata"]=> string(10) "subpdata11" } } } } OK msgpack-0.5.5/tests/125.phpt0000644000077100007710000000673612110565607015411 0ustar xinchenxinchen--TEST-- unpack of template converter: multiple class/variable: class unpacker (array: OPT_PHPONLY=false) --SKIPIF-- setOption(MessagePack::OPT_PHPONLY, false); $serialized = $msgpack->pack($variable); $unserialized = $msgpack->unpack($serialized, $object); var_dump($unserialized); if ($result) { echo $unserialized == $result ? 'OK' : 'ERROR', PHP_EOL; } else { echo 'SKIP', PHP_EOL; } } class MyObj { private $data = null; private $priv = "privdata"; public $pdata = null; public $subary = null; function __construct() { $this->data = "datadata"; $this->subary = array(new SubObj()); } } class SubObj { private $subdata = null; private $subpriv = "subprivdata"; public $subpdata = null; function __construct() { $this->subdata = "subdatadata"; } } $arySubObj = array( "subdata" => "subdatadata", "subpriv" => "subprivdata", "subpdata" => null, ); $aryMyObj = array( "data" => "datadata", "priv" => "privdata", "pdata" => null, "subary" => array($arySubObj), ); $obj0 = new MyObj(); $obj0->pdata = "pubdata0"; $obj0->subary[0]->subpdata = "subpubdata00"; $subobj01 = new SubObj(); $subobj01->subpdata = "subpdata01"; $obj0->subary[1] = $subobj01; $obj1 = new MyObj(); $obj1->pdata = "pubdata1"; $obj1->subary[0]->subpdata = "subpubdata1"; $subobj11 = new SubObj(); $subobj11->subpdata = "subpdata11"; $obj1->subary[1] = $subobj11; $ary = array($obj0, $obj1); $tpl = array($aryMyObj); $resary = array($aryMyObj, $aryMyObj); $resary[0]["pdata"] = "pubdata0"; $resary[0]["subary"][] = $arySubObj; $resary[0]["subary"][0]["subpdata"] = "subpubdata00"; $resary[0]["subary"][1]["subpdata"] = "subpdata01"; $resary[1]["subary"][] = $arySubObj; $resary[1]["pdata"] = "pubdata1"; $resary[1]["subary"][0]["subpdata"] = "subpubdata1"; $resary[1]["subary"][1]["subpdata"] = "subpdata11"; test("recursive object list to associative array list", $ary, $tpl, $resary); --EXPECTF-- array(2) { [0]=> array(4) { ["data"]=> string(8) "datadata" ["priv"]=> string(8) "privdata" ["pdata"]=> string(8) "pubdata0" ["subary"]=> array(2) { [0]=> array(3) { ["subdata"]=> string(11) "subdatadata" ["subpriv"]=> string(11) "subprivdata" ["subpdata"]=> string(12) "subpubdata00" } [1]=> array(3) { ["subdata"]=> string(11) "subdatadata" ["subpriv"]=> string(11) "subprivdata" ["subpdata"]=> string(10) "subpdata01" } } } [1]=> array(4) { ["data"]=> string(8) "datadata" ["priv"]=> string(8) "privdata" ["pdata"]=> string(8) "pubdata1" ["subary"]=> array(2) { [0]=> array(3) { ["subdata"]=> string(11) "subdatadata" ["subpriv"]=> string(11) "subprivdata" ["subpdata"]=> string(11) "subpubdata1" } [1]=> array(3) { ["subdata"]=> string(11) "subdatadata" ["subpriv"]=> string(11) "subprivdata" ["subpdata"]=> string(10) "subpdata11" } } } } OK msgpack-0.5.5/tests/125b.phpt0000644000077100007710000000716512110565607015550 0ustar xinchenxinchen--TEST-- unpack of template converter: multiple class/variable: class unpacker (array: OPT_PHPONLY=false) --SKIPIF-- = 0) { echo "skip tests in PHP 5.1 or older"; } --FILE-- setOption(MESSAGEPACK_OPT_PHPONLY, false); } else { $msgpack->setOption(MessagePack::OPT_PHPONLY, false); } $serialized = $msgpack->pack($variable); $unserialized = $msgpack->unpack($serialized, $object); var_dump($unserialized); if ($result) { echo $unserialized == $result ? 'OK' : 'ERROR', PHP_EOL; } else { echo 'SKIP', PHP_EOL; } } class MyObj { private $data = null; private $priv = "privdata"; public $pdata = null; public $subary = null; function __construct() { $this->data = "datadata"; $this->subary = array(new SubObj()); } } class SubObj { private $subdata = null; private $subpriv = "subprivdata"; public $subpdata = null; function __construct() { $this->subdata = "subdatadata"; } } $arySubObj = array( "subdata" => "subdatadata", "subpriv" => "subprivdata", "subpdata" => null, ); $aryMyObj = array( "data" => "datadata", "priv" => "privdata", "pdata" => null, "subary" => array($arySubObj), ); $obj0 = new MyObj(); $obj0->pdata = "pubdata0"; $obj0->subary[0]->subpdata = "subpubdata00"; $subobj01 = new SubObj(); $subobj01->subpdata = "subpdata01"; $obj0->subary[1] = $subobj01; $obj1 = new MyObj(); $obj1->pdata = "pubdata1"; $obj1->subary[0]->subpdata = "subpubdata1"; $subobj11 = new SubObj(); $subobj11->subpdata = "subpdata11"; $obj1->subary[1] = $subobj11; $ary = array($obj0, $obj1); $tpl = array($aryMyObj); $resary = array($aryMyObj, $aryMyObj); $resary[0]["pdata"] = "pubdata0"; $resary[0]["subary"][] = $arySubObj; $resary[0]["subary"][0]["subpdata"] = "subpubdata00"; $resary[0]["subary"][1]["subpdata"] = "subpdata01"; $resary[1]["subary"][] = $arySubObj; $resary[1]["pdata"] = "pubdata1"; $resary[1]["subary"][0]["subpdata"] = "subpubdata1"; $resary[1]["subary"][1]["subpdata"] = "subpdata11"; test("recursive object list to associative array list", $ary, $tpl, $resary); --EXPECTF-- array(2) { [0]=> array(4) { ["data"]=> string(8) "datadata" ["priv"]=> string(8) "privdata" ["pdata"]=> string(8) "pubdata0" ["subary"]=> array(2) { [0]=> array(3) { ["subdata"]=> string(11) "subdatadata" ["subpriv"]=> string(11) "subprivdata" ["subpdata"]=> string(12) "subpubdata00" } [1]=> array(3) { ["subdata"]=> string(11) "subdatadata" ["subpriv"]=> string(11) "subprivdata" ["subpdata"]=> string(10) "subpdata01" } } } [1]=> array(4) { ["data"]=> string(8) "datadata" ["priv"]=> string(8) "privdata" ["pdata"]=> string(8) "pubdata1" ["subary"]=> array(2) { [0]=> array(3) { ["subdata"]=> string(11) "subdatadata" ["subpriv"]=> string(11) "subprivdata" ["subpdata"]=> string(11) "subpubdata1" } [1]=> array(3) { ["subdata"]=> string(11) "subdatadata" ["subpriv"]=> string(11) "subprivdata" ["subpdata"]=> string(10) "subpdata11" } } } } OK msgpack-0.5.5/tests/126.phpt0000644000077100007710000000264412110565607015404 0ustar xinchenxinchen--TEST-- unpack of template converter (array: string) --SKIPIF-- data = "datadata"; } } $obj = new MyObj(); $obj->pdata = "pubdata0"; $obj2 = new MyObj(); $obj2->pdata = "pubdata1"; $ary = array($obj, $obj2); $tpl = array("MyObj"); test("object list /w string", $ary, $tpl, $ary); --EXPECTF-- array(2) { [0]=> object(MyObj)#%d (3) { [%r"?data"?:("MyObj":)?private"?%r]=> string(8) "datadata" [%r"?priv"?:("MyObj":)?private"?%r]=> string(8) "privdata" ["pdata"]=> string(8) "pubdata0" } [1]=> object(MyObj)#%d (3) { [%r"?data"?:("MyObj":)?private"?%r]=> string(8) "datadata" [%r"?priv"?:("MyObj":)?private"?%r]=> string(8) "privdata" ["pdata"]=> string(8) "pubdata1" } } OK msgpack-0.5.5/tests/126b.phpt0000644000077100007710000000253112110565607015541 0ustar xinchenxinchen--TEST-- unpack of template converter (array: string) --SKIPIF-- = 0) { echo "skip tests in PHP 5.1 or older"; } --FILE-- data = "datadata"; } } $obj = new MyObj(); $obj->pdata = "pubdata0"; $obj2 = new MyObj(); $obj2->pdata = "pubdata1"; $ary = array($obj, $obj2); $tpl = array("MyObj"); test("object list /w string", $ary, $tpl, $ary); --EXPECTF-- array(2) { [0]=> object(MyObj)#%d (3) { ["data:private"]=> string(8) "datadata" ["priv:private"]=> string(8) "privdata" ["pdata"]=> string(8) "pubdata0" } [1]=> object(MyObj)#%d (3) { ["data:private"]=> string(8) "datadata" ["priv:private"]=> string(8) "privdata" ["pdata"]=> string(8) "pubdata1" } } OK msgpack-0.5.5/tests/127.phpt0000644000077100007710000000265212110565607015404 0ustar xinchenxinchen--TEST-- unpack of template converter (array: object) --SKIPIF-- data = "datadata"; } } $obj = new MyObj(); $obj->pdata = "pubdata0"; $obj2 = new MyObj(); $obj2->pdata = "pubdata1"; $ary = array($obj, $obj2); $tpl = array(new MyObj()); test("object list /w instance", $ary, $tpl, $ary); --EXPECTF-- array(2) { [0]=> object(MyObj)#%d (3) { [%r"?data"?:("MyObj":)?private"?%r]=> string(8) "datadata" [%r"?priv"?:("MyObj":)?private"?%r]=> string(8) "privdata" ["pdata"]=> string(8) "pubdata0" } [1]=> object(MyObj)#%d (3) { [%r"?data"?:("MyObj":)?private"?%r]=> string(8) "datadata" [%r"?priv"?:("MyObj":)?private"?%r]=> string(8) "privdata" ["pdata"]=> string(8) "pubdata1" } } OK msgpack-0.5.5/tests/127b.phpt0000644000077100007710000000253712110565607015550 0ustar xinchenxinchen--TEST-- unpack of template converter (array: object) --SKIPIF-- = 0) { echo "skip tests in PHP 5.1 or older"; } --FILE-- data = "datadata"; } } $obj = new MyObj(); $obj->pdata = "pubdata0"; $obj2 = new MyObj(); $obj2->pdata = "pubdata1"; $ary = array($obj, $obj2); $tpl = array(new MyObj()); test("object list /w instance", $ary, $tpl, $ary); --EXPECTF-- array(2) { [0]=> object(MyObj)#%d (3) { ["data:private"]=> string(8) "datadata" ["priv:private"]=> string(8) "privdata" ["pdata"]=> string(8) "pubdata0" } [1]=> object(MyObj)#%d (3) { ["data:private"]=> string(8) "datadata" ["priv:private"]=> string(8) "privdata" ["pdata"]=> string(8) "pubdata1" } } OK msgpack-0.5.5/tests/128.phpt0000644000077100007710000000316012110565607015400 0ustar xinchenxinchen--TEST-- unpack of template converter (string) --SKIPIF-- data = "datadata"; $this->subary = new SubObj(); } } class SubObj { private $subdata = null; private $subpriv = "subprivdata"; public $subpdata = null; function __construct() { $this->subdata = "subdatadata"; } } $obj = new MyObj(); $obj->pdata = "pubdata"; $obj->subary->subpdata = "subpubdata"; $tpl = "MyObj"; test("recursive object /w string", $obj, $tpl, $obj); --EXPECTF-- object(MyObj)#%d (4) { [%r"?data"?:("MyObj":)?private"?%r]=> string(8) "datadata" [%r"?priv"?:("MyObj":)?private"?%r]=> string(8) "privdata" ["pdata"]=> string(7) "pubdata" ["subary"]=> object(SubObj)#%d (3) { [%r"?subdata"?:("SubObj":)?private"?%r]=> string(11) "subdatadata" [%r"?subpriv"?:("SubObj":)?private"?%r]=> string(11) "subprivdata" ["subpdata"]=> string(10) "subpubdata" } } OK msgpack-0.5.5/tests/128b.phpt0000644000077100007710000000304312110565607015542 0ustar xinchenxinchen--TEST-- unpack of template converter (string) --SKIPIF-- = 0) { echo "skip tests in PHP 5.1 or older"; } --FILE-- data = "datadata"; $this->subary = new SubObj(); } } class SubObj { private $subdata = null; private $subpriv = "subprivdata"; public $subpdata = null; function __construct() { $this->subdata = "subdatadata"; } } $obj = new MyObj(); $obj->pdata = "pubdata"; $obj->subary->subpdata = "subpubdata"; $tpl = "MyObj"; test("recursive object /w string", $obj, $tpl, $obj); --EXPECTF-- object(MyObj)#%d (4) { ["data:private"]=> string(8) "datadata" ["priv:private"]=> string(8) "privdata" ["pdata"]=> string(7) "pubdata" ["subary"]=> object(SubObj)#%d (3) { ["subdata:private"]=> string(11) "subdatadata" ["subpriv:private"]=> string(11) "subprivdata" ["subpdata"]=> string(10) "subpubdata" } } OK msgpack-0.5.5/tests/129.phpt0000644000077100007710000000316612110565607015407 0ustar xinchenxinchen--TEST-- unpack of template converter (object) --SKIPIF-- data = "datadata"; $this->subary = new SubObj(); } } class SubObj { private $subdata = null; private $subpriv = "subprivdata"; public $subpdata = null; function __construct() { $this->subdata = "subdatadata"; } } $obj = new MyObj(); $obj->pdata = "pubdata"; $obj->subary->subpdata = "subpubdata"; $tpl = new MyObj(); test("recursive object /w instance", $obj, $tpl, $obj); --EXPECTF-- object(MyObj)#%d (4) { [%r"?data"?:("MyObj":)?private"?%r]=> string(8) "datadata" [%r"?priv"?:("MyObj":)?private"?%r]=> string(8) "privdata" ["pdata"]=> string(7) "pubdata" ["subary"]=> object(SubObj)#%d (3) { [%r"?subdata"?:("SubObj":)?private"?%r]=> string(11) "subdatadata" [%r"?subpriv"?:("SubObj":)?private"?%r]=> string(11) "subprivdata" ["subpdata"]=> string(10) "subpubdata" } } OK msgpack-0.5.5/tests/129b.phpt0000644000077100007710000000305112110565607015542 0ustar xinchenxinchen--TEST-- unpack of template converter (object) --SKIPIF-- = 0) { echo "skip tests in PHP 5.1 or older"; } --FILE-- data = "datadata"; $this->subary = new SubObj(); } } class SubObj { private $subdata = null; private $subpriv = "subprivdata"; public $subpdata = null; function __construct() { $this->subdata = "subdatadata"; } } $obj = new MyObj(); $obj->pdata = "pubdata"; $obj->subary->subpdata = "subpubdata"; $tpl = new MyObj(); test("recursive object /w instance", $obj, $tpl, $obj); --EXPECTF-- object(MyObj)#%d (4) { ["data:private"]=> string(8) "datadata" ["priv:private"]=> string(8) "privdata" ["pdata"]=> string(7) "pubdata" ["subary"]=> object(SubObj)#%d (3) { ["subdata:private"]=> string(11) "subdatadata" ["subpriv:private"]=> string(11) "subprivdata" ["subpdata"]=> string(10) "subpubdata" } } OK msgpack-0.5.5/tests/130.phpt0000644000077100007710000000335412110565607015376 0ustar xinchenxinchen--TEST-- unpack of template converter: multiple class: (array: string) --SKIPIF-- data = "datadata"; $this->subary = new SubObj(); } } class SubObj { private $subdata = null; private $subpriv = "subprivdata"; public $subpdata = null; function __construct() { $this->subdata = "subdatadata"; } } $obj = new MyObj(); $obj->pdata = "pubdata"; $obj->subary->subpdata = "subpubdata"; $ary = array($obj); $tpl = array("MyObj"); test("recursive object with object list /w string", $ary, $tpl, $ary); --EXPECTF-- array(1) { [0]=> object(MyObj)#%d (4) { [%r"?data"?:("MyObj":)?private"?%r]=> string(8) "datadata" [%r"?priv"?:("MyObj":)?private"?%r]=> string(8) "privdata" ["pdata"]=> string(7) "pubdata" ["subary"]=> object(SubObj)#%d (3) { [%r"?subdata"?:("SubObj":)?private"?%r]=> string(11) "subdatadata" [%r"?subpriv"?:("SubObj":)?private"?%r]=> string(11) "subprivdata" ["subpdata"]=> string(10) "subpubdata" } } } OK msgpack-0.5.5/tests/130b.phpt0000644000077100007710000000323712110565607015540 0ustar xinchenxinchen--TEST-- unpack of template converter: multiple class: (array: string) --SKIPIF-- = 0) { echo "skip tests in PHP 5.1 or older"; } --FILE-- data = "datadata"; $this->subary = new SubObj(); } } class SubObj { private $subdata = null; private $subpriv = "subprivdata"; public $subpdata = null; function __construct() { $this->subdata = "subdatadata"; } } $obj = new MyObj(); $obj->pdata = "pubdata"; $obj->subary->subpdata = "subpubdata"; $ary = array($obj); $tpl = array("MyObj"); test("recursive object with object list /w string", $ary, $tpl, $ary); --EXPECTF-- array(1) { [0]=> object(MyObj)#%d (4) { ["data:private"]=> string(8) "datadata" ["priv:private"]=> string(8) "privdata" ["pdata"]=> string(7) "pubdata" ["subary"]=> object(SubObj)#%d (3) { ["subdata:private"]=> string(11) "subdatadata" ["subpriv:private"]=> string(11) "subprivdata" ["subpdata"]=> string(10) "subpubdata" } } } OK msgpack-0.5.5/tests/131.phpt0000644000077100007710000000336212110565607015376 0ustar xinchenxinchen--TEST-- unpack of template converter: multiple class: (array: object) --SKIPIF-- data = "datadata"; $this->subary = new SubObj(); } } class SubObj { private $subdata = null; private $subpriv = "subprivdata"; public $subpdata = null; function __construct() { $this->subdata = "subdatadata"; } } $obj = new MyObj(); $obj->pdata = "pubdata"; $obj->subary->subpdata = "subpubdata"; $ary = array($obj); $tpl = array(new MyObj()); test("recursive object with object list /w instance", $ary, $tpl, $ary); --EXPECTF-- array(1) { [0]=> object(MyObj)#%d (4) { [%r"?data"?:("MyObj":)?private"?%r]=> string(8) "datadata" [%r"?priv"?:("MyObj":)?private"?%r]=> string(8) "privdata" ["pdata"]=> string(7) "pubdata" ["subary"]=> object(SubObj)#%d (3) { [%r"?subdata"?:("SubObj":)?private"?%r]=> string(11) "subdatadata" [%r"?subpriv"?:("SubObj":)?private"?%r]=> string(11) "subprivdata" ["subpdata"]=> string(10) "subpubdata" } } } OK msgpack-0.5.5/tests/131b.phpt0000644000077100007710000000324112110565607015534 0ustar xinchenxinchen--TEST-- unpack of template converter: multiple class: (array: object) --SKIPIF-- = 0) { echo "skip tests in PHP 5.1 or older"; } --FILE-- data = "datadata"; $this->subary = new SubObj(); } } class SubObj { private $subdata = null; private $subpriv = "subprivdata"; public $subpdata = null; function __construct() { $this->subdata = "subdatadata"; } } $obj = new MyObj(); $obj->pdata = "pubdata"; $obj->subary->subpdata = "subpubdata"; $ary = array($obj); $tpl = array("MyObj"); test("recursive object with object list /w instance", $ary, $tpl, $ary); --EXPECTF-- array(1) { [0]=> object(MyObj)#%d (4) { ["data:private"]=> string(8) "datadata" ["priv:private"]=> string(8) "privdata" ["pdata"]=> string(7) "pubdata" ["subary"]=> object(SubObj)#%d (3) { ["subdata:private"]=> string(11) "subdatadata" ["subpriv:private"]=> string(11) "subprivdata" ["subpdata"]=> string(10) "subpubdata" } } } OK msgpack-0.5.5/tests/132.phpt0000644000077100007710000000444412110565607015401 0ustar xinchenxinchen--TEST-- unpack of template converter: multiple variable: (array: string) --SKIPIF-- data = "datadata"; $this->subary = new SubObj(); } } class SubObj { private $subdata = null; private $subpriv = "subprivdata"; public $subpdata = null; function __construct() { $this->subdata = "subdatadata"; } } $obj0 = new MyObj(); $obj0->pdata = "pubdata0"; $obj0->subary->subpdata = "subpubdata0"; $obj1 = new MyObj(); $obj1->pdata = "pubdata1"; $obj1->subary->subpdata = "subpubdata1"; $ary = array($obj0, $obj1); $tpl = array("MyObj"); test("recursive object list /w string", $ary, $tpl, $ary); --EXPECTF-- array(2) { [0]=> object(MyObj)#%d (4) { [%r"?data"?:("MyObj":)?private"?%r]=> string(8) "datadata" [%r"?priv"?:("MyObj":)?private"?%r]=> string(8) "privdata" ["pdata"]=> string(8) "pubdata0" ["subary"]=> object(SubObj)#%d (3) { [%r"?subdata"?:("SubObj":)?private"?%r]=> string(11) "subdatadata" [%r"?subpriv"?:("SubObj":)?private"?%r]=> string(11) "subprivdata" ["subpdata"]=> string(11) "subpubdata0" } } [1]=> object(MyObj)#%d (4) { [%r"?data"?:("MyObj":)?private"?%r]=> string(8) "datadata" [%r"?priv"?:("MyObj":)?private"?%r]=> string(8) "privdata" ["pdata"]=> string(8) "pubdata1" ["subary"]=> object(SubObj)#%d (3) { [%r"?subdata"?:("SubObj":)?private"?%r]=> string(11) "subdatadata" [%r"?subpriv"?:("SubObj":)?private"?%r]=> string(11) "subprivdata" ["subpdata"]=> string(11) "subpubdata1" } } } OK msgpack-0.5.5/tests/132b.phpt0000644000077100007710000000421112110565607015533 0ustar xinchenxinchen--TEST-- unpack of template converter: multiple variable: (array: string) --SKIPIF-- = 0) { echo "skip tests in PHP 5.1 or older"; } --FILE-- data = "datadata"; $this->subary = new SubObj(); } } class SubObj { private $subdata = null; private $subpriv = "subprivdata"; public $subpdata = null; function __construct() { $this->subdata = "subdatadata"; } } $obj0 = new MyObj(); $obj0->pdata = "pubdata0"; $obj0->subary->subpdata = "subpubdata0"; $obj1 = new MyObj(); $obj1->pdata = "pubdata1"; $obj1->subary->subpdata = "subpubdata1"; $ary = array($obj0, $obj1); $tpl = array("MyObj"); test("recursive object list /w string", $ary, $tpl, $ary); --EXPECTF-- array(2) { [0]=> object(MyObj)#%d (4) { ["data:private"]=> string(8) "datadata" ["priv:private"]=> string(8) "privdata" ["pdata"]=> string(8) "pubdata0" ["subary"]=> object(SubObj)#%d (3) { ["subdata:private"]=> string(11) "subdatadata" ["subpriv:private"]=> string(11) "subprivdata" ["subpdata"]=> string(11) "subpubdata0" } } [1]=> object(MyObj)#%d (4) { ["data:private"]=> string(8) "datadata" ["priv:private"]=> string(8) "privdata" ["pdata"]=> string(8) "pubdata1" ["subary"]=> object(SubObj)#%d (3) { ["subdata:private"]=> string(11) "subdatadata" ["subpriv:private"]=> string(11) "subprivdata" ["subpdata"]=> string(11) "subpubdata1" } } } OK msgpack-0.5.5/tests/133.phpt0000644000077100007710000000445212110565607015401 0ustar xinchenxinchen--TEST-- unpack of template converter: multiple variable: (array: object) --SKIPIF-- data = "datadata"; $this->subary = new SubObj(); } } class SubObj { private $subdata = null; private $subpriv = "subprivdata"; public $subpdata = null; function __construct() { $this->subdata = "subdatadata"; } } $obj0 = new MyObj(); $obj0->pdata = "pubdata0"; $obj0->subary->subpdata = "subpubdata0"; $obj1 = new MyObj(); $obj1->pdata = "pubdata1"; $obj1->subary->subpdata = "subpubdata1"; $ary = array($obj0, $obj1); $tpl = array(new MyObj()); test("recursive object list /w instance", $ary, $tpl, $ary); --EXPECTF-- array(2) { [0]=> object(MyObj)#%d (4) { [%r"?data"?:("MyObj":)?private"?%r]=> string(8) "datadata" [%r"?priv"?:("MyObj":)?private"?%r]=> string(8) "privdata" ["pdata"]=> string(8) "pubdata0" ["subary"]=> object(SubObj)#%d (3) { [%r"?subdata"?:("SubObj":)?private"?%r]=> string(11) "subdatadata" [%r"?subpriv"?:("SubObj":)?private"?%r]=> string(11) "subprivdata" ["subpdata"]=> string(11) "subpubdata0" } } [1]=> object(MyObj)#%d (4) { [%r"?data"?:("MyObj":)?private"?%r]=> string(8) "datadata" [%r"?priv"?:("MyObj":)?private"?%r]=> string(8) "privdata" ["pdata"]=> string(8) "pubdata1" ["subary"]=> object(SubObj)#%d (3) { [%r"?subdata"?:("SubObj":)?private"?%r]=> string(11) "subdatadata" [%r"?subpriv"?:("SubObj":)?private"?%r]=> string(11) "subprivdata" ["subpdata"]=> string(11) "subpubdata1" } } } OK msgpack-0.5.5/tests/133b.phpt0000644000077100007710000000421712110565607015542 0ustar xinchenxinchen--TEST-- unpack of template converter: multiple variable: (array: object) --SKIPIF-- = 0) { echo "skip tests in PHP 5.1 or older"; } --FILE-- data = "datadata"; $this->subary = new SubObj(); } } class SubObj { private $subdata = null; private $subpriv = "subprivdata"; public $subpdata = null; function __construct() { $this->subdata = "subdatadata"; } } $obj0 = new MyObj(); $obj0->pdata = "pubdata0"; $obj0->subary->subpdata = "subpubdata0"; $obj1 = new MyObj(); $obj1->pdata = "pubdata1"; $obj1->subary->subpdata = "subpubdata1"; $ary = array($obj0, $obj1); $tpl = array(new MyObj()); test("recursive object list /w instance", $ary, $tpl, $ary); --EXPECTF-- array(2) { [0]=> object(MyObj)#%d (4) { ["data:private"]=> string(8) "datadata" ["priv:private"]=> string(8) "privdata" ["pdata"]=> string(8) "pubdata0" ["subary"]=> object(SubObj)#%d (3) { ["subdata:private"]=> string(11) "subdatadata" ["subpriv:private"]=> string(11) "subprivdata" ["subpdata"]=> string(11) "subpubdata0" } } [1]=> object(MyObj)#%d (4) { ["data:private"]=> string(8) "datadata" ["priv:private"]=> string(8) "privdata" ["pdata"]=> string(8) "pubdata1" ["subary"]=> object(SubObj)#%d (3) { ["subdata:private"]=> string(11) "subdatadata" ["subpriv:private"]=> string(11) "subprivdata" ["subpdata"]=> string(11) "subpubdata1" } } } OK msgpack-0.5.5/tests/134.phpt0000644000077100007710000000620212110565607015375 0ustar xinchenxinchen--TEST-- unpack of template converter: multiple class/variable: (array: string) --SKIPIF-- data = "datadata"; $this->subary = array(new SubObj()); } } class SubObj { private $subdata = null; private $subpriv = "subprivdata"; public $subpdata = null; function __construct() { $this->subdata = "subdatadata"; } } $obj0 = new MyObj(); $obj0->pdata = "pubdata0"; $obj0->subary[0]->subpdata = "subpubdata00"; $subobj01 = new SubObj(); $subobj01->subpdata = "subpdata01"; $obj0->subary[1] = $subobj01; $obj1 = new MyObj(); $obj1->pdata = "pubdata1"; $obj1->subary[0]->subpdata = "subpubdata1"; $subobj11 = new SubObj(); $subobj11->subpdata = "subpdata11"; $obj1->subary[1] = $subobj11; $ary = array($obj0, $obj1); $tpl = array("MyObj"); test("recursive object list with object list /w string", $ary, $tpl, $ary); --EXPECTF-- array(2) { [0]=> object(MyObj)#%d (4) { [%r"?data"?:("MyObj":)?private"?%r]=> string(8) "datadata" [%r"?priv"?:("MyObj":)?private"?%r]=> string(8) "privdata" ["pdata"]=> string(8) "pubdata0" ["subary"]=> array(2) { [0]=> object(SubObj)#%d (3) { [%r"?subdata"?:("SubObj":)?private"?%r]=> string(11) "subdatadata" [%r"?subpriv"?:("SubObj":)?private"?%r]=> string(11) "subprivdata" ["subpdata"]=> string(12) "subpubdata00" } [1]=> object(SubObj)#%d (3) { [%r"?subdata"?:("SubObj":)?private"?%r]=> string(11) "subdatadata" [%r"?subpriv"?:("SubObj":)?private"?%r]=> string(11) "subprivdata" ["subpdata"]=> string(10) "subpdata01" } } } [1]=> object(MyObj)#%d (4) { [%r"?data"?:("MyObj":)?private"?%r]=> string(8) "datadata" [%r"?priv"?:("MyObj":)?private"?%r]=> string(8) "privdata" ["pdata"]=> string(8) "pubdata1" ["subary"]=> array(2) { [0]=> object(SubObj)#%d (3) { [%r"?subdata"?:("SubObj":)?private"?%r]=> string(11) "subdatadata" [%r"?subpriv"?:("SubObj":)?private"?%r]=> string(11) "subprivdata" ["subpdata"]=> string(11) "subpubdata1" } [1]=> object(SubObj)#%d (3) { [%r"?subdata"?:("SubObj":)?private"?%r]=> string(11) "subdatadata" [%r"?subpriv"?:("SubObj":)?private"?%r]=> string(11) "subprivdata" ["subpdata"]=> string(10) "subpdata11" } } } } OK msgpack-0.5.5/tests/134b.phpt0000644000077100007710000000562712110565607015551 0ustar xinchenxinchen--TEST-- unpack of template converter: multiple class/variable: (array: string) --SKIPIF-- = 0) { echo "skip tests in PHP 5.1 or older"; } --FILE-- data = "datadata"; $this->subary = array(new SubObj()); } } class SubObj { private $subdata = null; private $subpriv = "subprivdata"; public $subpdata = null; function __construct() { $this->subdata = "subdatadata"; } } $obj0 = new MyObj(); $obj0->pdata = "pubdata0"; $obj0->subary[0]->subpdata = "subpubdata00"; $subobj01 = new SubObj(); $subobj01->subpdata = "subpdata01"; $obj0->subary[1] = $subobj01; $obj1 = new MyObj(); $obj1->pdata = "pubdata1"; $obj1->subary[0]->subpdata = "subpubdata1"; $subobj11 = new SubObj(); $subobj11->subpdata = "subpdata11"; $obj1->subary[1] = $subobj11; $ary = array($obj0, $obj1); $tpl = array("MyObj"); test("recursive object list with object list /w string", $ary, $tpl, $ary); --EXPECTF-- array(2) { [0]=> object(MyObj)#%d (4) { ["data:private"]=> string(8) "datadata" ["priv:private"]=> string(8) "privdata" ["pdata"]=> string(8) "pubdata0" ["subary"]=> array(2) { [0]=> object(SubObj)#%d (3) { ["subdata:private"]=> string(11) "subdatadata" ["subpriv:private"]=> string(11) "subprivdata" ["subpdata"]=> string(12) "subpubdata00" } [1]=> object(SubObj)#%d (3) { ["subdata:private"]=> string(11) "subdatadata" ["subpriv:private"]=> string(11) "subprivdata" ["subpdata"]=> string(10) "subpdata01" } } } [1]=> object(MyObj)#%d (4) { ["data:private"]=> string(8) "datadata" ["priv:private"]=> string(8) "privdata" ["pdata"]=> string(8) "pubdata1" ["subary"]=> array(2) { [0]=> object(SubObj)#%d (3) { ["subdata:private"]=> string(11) "subdatadata" ["subpriv:private"]=> string(11) "subprivdata" ["subpdata"]=> string(11) "subpubdata1" } [1]=> object(SubObj)#%d (3) { ["subdata:private"]=> string(11) "subdatadata" ["subpriv:private"]=> string(11) "subprivdata" ["subpdata"]=> string(10) "subpdata11" } } } } OK msgpack-0.5.5/tests/135.phpt0000644000077100007710000000621012110565607015375 0ustar xinchenxinchen--TEST-- unpack of template converter: multiple class/variable: (array: object) --SKIPIF-- data = "datadata"; $this->subary = array(new SubObj()); } } class SubObj { private $subdata = null; private $subpriv = "subprivdata"; public $subpdata = null; function __construct() { $this->subdata = "subdatadata"; } } $obj0 = new MyObj(); $obj0->pdata = "pubdata0"; $obj0->subary[0]->subpdata = "subpubdata00"; $subobj01 = new SubObj(); $subobj01->subpdata = "subpdata01"; $obj0->subary[1] = $subobj01; $obj1 = new MyObj(); $obj1->pdata = "pubdata1"; $obj1->subary[0]->subpdata = "subpubdata1"; $subobj11 = new SubObj(); $subobj11->subpdata = "subpdata11"; $obj1->subary[1] = $subobj11; $ary = array($obj0, $obj1); $tpl = array(new MyObj()); test("recursive object list with object list /w instance", $ary, $tpl, $ary); --EXPECTF-- array(2) { [0]=> object(MyObj)#%d (4) { [%r"?data"?:("MyObj":)?private"?%r]=> string(8) "datadata" [%r"?priv"?:("MyObj":)?private"?%r]=> string(8) "privdata" ["pdata"]=> string(8) "pubdata0" ["subary"]=> array(2) { [0]=> object(SubObj)#%d (3) { [%r"?subdata"?:("SubObj":)?private"?%r]=> string(11) "subdatadata" [%r"?subpriv"?:("SubObj":)?private"?%r]=> string(11) "subprivdata" ["subpdata"]=> string(12) "subpubdata00" } [1]=> object(SubObj)#%d (3) { [%r"?subdata"?:("SubObj":)?private"?%r]=> string(11) "subdatadata" [%r"?subpriv"?:("SubObj":)?private"?%r]=> string(11) "subprivdata" ["subpdata"]=> string(10) "subpdata01" } } } [1]=> object(MyObj)#%d (4) { [%r"?data"?:("MyObj":)?private"?%r]=> string(8) "datadata" [%r"?priv"?:("MyObj":)?private"?%r]=> string(8) "privdata" ["pdata"]=> string(8) "pubdata1" ["subary"]=> array(2) { [0]=> object(SubObj)#%d (3) { [%r"?subdata"?:("SubObj":)?private"?%r]=> string(11) "subdatadata" [%r"?subpriv"?:("SubObj":)?private"?%r]=> string(11) "subprivdata" ["subpdata"]=> string(11) "subpubdata1" } [1]=> object(SubObj)#%d (3) { [%r"?subdata"?:("SubObj":)?private"?%r]=> string(11) "subdatadata" [%r"?subpriv"?:("SubObj":)?private"?%r]=> string(11) "subprivdata" ["subpdata"]=> string(10) "subpdata11" } } } } OK msgpack-0.5.5/tests/135b.phpt0000644000077100007710000000563512110565607015551 0ustar xinchenxinchen--TEST-- unpack of template converter: multiple class/variable: (array: object) --SKIPIF-- = 0) { echo "skip tests in PHP 5.1 or older"; } --FILE-- data = "datadata"; $this->subary = array(new SubObj()); } } class SubObj { private $subdata = null; private $subpriv = "subprivdata"; public $subpdata = null; function __construct() { $this->subdata = "subdatadata"; } } $obj0 = new MyObj(); $obj0->pdata = "pubdata0"; $obj0->subary[0]->subpdata = "subpubdata00"; $subobj01 = new SubObj(); $subobj01->subpdata = "subpdata01"; $obj0->subary[1] = $subobj01; $obj1 = new MyObj(); $obj1->pdata = "pubdata1"; $obj1->subary[0]->subpdata = "subpubdata1"; $subobj11 = new SubObj(); $subobj11->subpdata = "subpdata11"; $obj1->subary[1] = $subobj11; $ary = array($obj0, $obj1); $tpl = array(new MyObj()); test("recursive object list with object list /w instance", $ary, $tpl, $ary); --EXPECTF-- array(2) { [0]=> object(MyObj)#%d (4) { ["data:private"]=> string(8) "datadata" ["priv:private"]=> string(8) "privdata" ["pdata"]=> string(8) "pubdata0" ["subary"]=> array(2) { [0]=> object(SubObj)#%d (3) { ["subdata:private"]=> string(11) "subdatadata" ["subpriv:private"]=> string(11) "subprivdata" ["subpdata"]=> string(12) "subpubdata00" } [1]=> object(SubObj)#%d (3) { ["subdata:private"]=> string(11) "subdatadata" ["subpriv:private"]=> string(11) "subprivdata" ["subpdata"]=> string(10) "subpdata01" } } } [1]=> object(MyObj)#%d (4) { ["data:private"]=> string(8) "datadata" ["priv:private"]=> string(8) "privdata" ["pdata"]=> string(8) "pubdata1" ["subary"]=> array(2) { [0]=> object(SubObj)#%d (3) { ["subdata:private"]=> string(11) "subdatadata" ["subpriv:private"]=> string(11) "subprivdata" ["subpdata"]=> string(11) "subpubdata1" } [1]=> object(SubObj)#%d (3) { ["subdata:private"]=> string(11) "subdatadata" ["subpriv:private"]=> string(11) "subprivdata" ["subpdata"]=> string(10) "subpdata11" } } } } OK msgpack-0.5.5/tests/136.phpt0000644000077100007710000000653212110565607015405 0ustar xinchenxinchen--TEST-- unpack of template converter: multiple class/variable: (array) --SKIPIF-- data = "datadata"; $this->subary = array(new SubObj()); } } class SubObj { private $subdata = null; private $subpriv = "subprivdata"; public $subpdata = null; function __construct() { $this->subdata = "subdatadata"; } } $arySubObj = array( "subdata" => "subdatadata", "subpriv" => "subprivdata", "subpdata" => null, ); $aryMyObj = array( "data" => "datadata", "priv" => "privdata", "pdata" => null, "subary" => array($arySubObj), ); $obj0 = new MyObj(); $obj0->pdata = "pubdata0"; $obj0->subary[0]->subpdata = "subpubdata00"; $subobj01 = new SubObj(); $subobj01->subpdata = "subpdata01"; $obj0->subary[1] = $subobj01; $obj1 = new MyObj(); $obj1->pdata = "pubdata1"; $obj1->subary[0]->subpdata = "subpubdata1"; $subobj11 = new SubObj(); $subobj11->subpdata = "subpdata11"; $obj1->subary[1] = $subobj11; $ary = array($obj0, $obj1); $tpl = array($aryMyObj); $resary = array($aryMyObj, $aryMyObj); $resary[0]["pdata"] = "pubdata0"; $resary[0]["subary"][] = $arySubObj; $resary[0]["subary"][0]["subpdata"] = "subpubdata00"; $resary[0]["subary"][1]["subpdata"] = "subpdata01"; $resary[1]["subary"][] = $arySubObj; $resary[1]["pdata"] = "pubdata1"; $resary[1]["subary"][0]["subpdata"] = "subpubdata1"; $resary[1]["subary"][1]["subpdata"] = "subpdata11"; test("recursive object list to associative array list", $ary, $tpl, $resary); --EXPECTF-- array(2) { [0]=> array(4) { ["data"]=> string(8) "datadata" ["priv"]=> string(8) "privdata" ["pdata"]=> string(8) "pubdata0" ["subary"]=> array(2) { [0]=> array(3) { ["subdata"]=> string(11) "subdatadata" ["subpriv"]=> string(11) "subprivdata" ["subpdata"]=> string(12) "subpubdata00" } [1]=> array(3) { ["subdata"]=> string(11) "subdatadata" ["subpriv"]=> string(11) "subprivdata" ["subpdata"]=> string(10) "subpdata01" } } } [1]=> array(4) { ["data"]=> string(8) "datadata" ["priv"]=> string(8) "privdata" ["pdata"]=> string(8) "pubdata1" ["subary"]=> array(2) { [0]=> array(3) { ["subdata"]=> string(11) "subdatadata" ["subpriv"]=> string(11) "subprivdata" ["subpdata"]=> string(11) "subpubdata1" } [1]=> array(3) { ["subdata"]=> string(11) "subdatadata" ["subpriv"]=> string(11) "subprivdata" ["subpdata"]=> string(10) "subpdata11" } } } } OK msgpack-0.5.5/tests/136b.phpt0000644000077100007710000000655212110565607015551 0ustar xinchenxinchen--TEST-- unpack of template converter: multiple class/variable: class unpacker (array) --SKIPIF-- = 0) { echo "skip tests in PHP 5.1 or older"; } --FILE-- data = "datadata"; $this->subary = array(new SubObj()); } } class SubObj { private $subdata = null; private $subpriv = "subprivdata"; public $subpdata = null; function __construct() { $this->subdata = "subdatadata"; } } $arySubObj = array( "subdata" => "subdatadata", "subpriv" => "subprivdata", "subpdata" => null, ); $aryMyObj = array( "data" => "datadata", "priv" => "privdata", "pdata" => null, "subary" => array($arySubObj), ); $obj0 = new MyObj(); $obj0->pdata = "pubdata0"; $obj0->subary[0]->subpdata = "subpubdata00"; $subobj01 = new SubObj(); $subobj01->subpdata = "subpdata01"; $obj0->subary[1] = $subobj01; $obj1 = new MyObj(); $obj1->pdata = "pubdata1"; $obj1->subary[0]->subpdata = "subpubdata1"; $subobj11 = new SubObj(); $subobj11->subpdata = "subpdata11"; $obj1->subary[1] = $subobj11; $ary = array($obj0, $obj1); $tpl = array($aryMyObj); $resary = array($aryMyObj, $aryMyObj); $resary[0]["pdata"] = "pubdata0"; $resary[0]["subary"][] = $arySubObj; $resary[0]["subary"][0]["subpdata"] = "subpubdata00"; $resary[0]["subary"][1]["subpdata"] = "subpdata01"; $resary[1]["subary"][] = $arySubObj; $resary[1]["pdata"] = "pubdata1"; $resary[1]["subary"][0]["subpdata"] = "subpubdata1"; $resary[1]["subary"][1]["subpdata"] = "subpdata11"; test("recursive object list to associative array list", $ary, $tpl, $resary); --EXPECTF-- array(2) { [0]=> array(4) { ["data"]=> string(8) "datadata" ["priv"]=> string(8) "privdata" ["pdata"]=> string(8) "pubdata0" ["subary"]=> array(2) { [0]=> array(3) { ["subdata"]=> string(11) "subdatadata" ["subpriv"]=> string(11) "subprivdata" ["subpdata"]=> string(12) "subpubdata00" } [1]=> array(3) { ["subdata"]=> string(11) "subdatadata" ["subpriv"]=> string(11) "subprivdata" ["subpdata"]=> string(10) "subpdata01" } } } [1]=> array(4) { ["data"]=> string(8) "datadata" ["priv"]=> string(8) "privdata" ["pdata"]=> string(8) "pubdata1" ["subary"]=> array(2) { [0]=> array(3) { ["subdata"]=> string(11) "subdatadata" ["subpriv"]=> string(11) "subprivdata" ["subpdata"]=> string(11) "subpubdata1" } [1]=> array(3) { ["subdata"]=> string(11) "subdatadata" ["subpriv"]=> string(11) "subprivdata" ["subpdata"]=> string(10) "subpdata11" } } } } OK msgpack-0.5.5/tests/bug006.phpt0000644000077100007710000000121512110565607016070 0ustar xinchenxinchen--TEST-- Bug #6 (bug with incorrect packing of mixed arrays) --SKIPIF-- 2, 1 => 3); print_r(msgpack_unpack(msgpack_pack($data))); $var = array( 1=> "foo", 2 => "bar"); $var[0] = "dummy"; print_r(msgpack_unpack(msgpack_pack($var))); while ($v = current($var)) { var_dump($v); next($var); } ?> --EXPECTF-- Array ( [key] => 2 [1] => 3 ) Array ( [0] => dummy [1] => foo [2] => bar ) string(3) "foo" string(3) "bar" string(5) "dummy" msgpack-0.5.5/tests/bug011.phpt0000644000077100007710000000043012110565607016062 0ustar xinchenxinchen--TEST-- Bug #011 (Check for segfault with empty array structures) --FILE-- array( ) ); } var_dump( count( msgpack_unpack( msgpack_pack( $items ) ) ) ); ?> --EXPECT-- int(1025) msgpack-0.5.5/tests/bug012.phpt0000644000077100007710000000161412110565607016070 0ustar xinchenxinchen--TEST-- Bug #12 (msgpack_seriallize interfere with php serialize) --SKIPIF-- --EXPECTF-- Array ( [0] => Demo Object ( [storage:ArrayObject:private] => Array ( [0] => stdClass Object ( ) [1] => stdClass Object ( ) ) ) [1] => stdClass Object ( ) [2] => stdClass Object ( ) ) msgpack-0.5.5/LICENSE0000644000077100007710000000274012110565607014037 0ustar xinchenxinchenCopyright (c) 2010, advect All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the advect nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. msgpack-0.5.5/README.md0000644000077100007710000000130612110565607014306 0ustar xinchenxinchen# Msgpack for PHP This extension provide API for communicating with MessagePack serialization. MessagePack is a binary-based efficient object serialization library. It enables to exchange structured objects between many languages like JSON. But unlike JSON, it is very fast and small. ## Requirement - PHP 5.0 + ## Install ### Install from PECL Msgpack is an PECL extension, thus you can simply install it by: ```` pecl install msgpack ```` ### Compile Msgpack from source ```` $/path/to/phpize $./configure $make && make install ```` ### Example ```php 1,1=>2,2=>3); $msg = msgpack_pack($data); $data = msgpack_unpack($msg); ?> ``` # Resources * [msgpack](http://msgpack.org/) msgpack-0.5.5/CREDITS0000644000077100007710000000000712110565607014044 0ustar xinchenxinchenmsgpackmsgpack-0.5.5/ChangeLog0000644000077100007710000000463712110565607014613 0ustar xinchenxinchenmsgpack extension changelog Version 0.5.5 ------------- * Fix ZTS build * Fixed Bug #14 ("Invalid read" reported by valgrind) * Fixed FR #8 (Return on unserialization): Unserializer will return false on error now Version 0.5.4 ------------- * Fixed Bug #12 (msgpack_seriallize interfere with php serialize) * Fixed Bug #11 (unpacking empty array / segmentation fault). Version 0.5.3 ------------- * Fixed Bug #6 (bug with incorrect packing of mixed arrays) Version 0.5.2 ------------- * Support PHP 5.4.x version. Version 0.5.1 ------------- * Fixed include path for version check. (Contributed by duedal) Version 0.5.0 ------------- * Fix ZEND_DECLARE_MODULE_GLOBALS: Moved ZEND_DECLARE_MODULE_GLOBALS from header to source file. Added ZEND_EXTERN_MODULE_GLOBALS in source files to avoid undefined _msgpack_globals message. (Contributed by seporaitis) * Add unpack of template converter: Merge https://github.com/msgpack/msgpack/pull/58 Fixed memory leaks. Fixed older version. Fixed tests scripts. Added msgpack_unpack function was implemented. (Contributed by ivan) Version 0.4.0 ------------- * Fix array pack. * Fix test code. * Add unpack of class object converter. Version 0.3.4 ------------- * Support PHP 5.3.x version on Windows. (note: NAN and Resource is failed) Version 0.3.3 ------------- * Update msgpack header files. * Fix unpack internal processing. Version 0.3.2 ------------- * Version PHP 5 or newer. Version 0.3.1 ------------- * Fix class MessagePackUnpacker. Version 0.3.0 ------------- * Change msgpack_unpack.c (used template) * Add php_only ini option (true / false) * Change class MessagePack and MessagePackUnpacker __construct option. * Add class MessagePack and MessagePackUnpacker setOption method. Version 0.2.1 ------------- * Fix stream deserializer. Version 0.2.0 ------------- * Add stream deserializer / class MessagePackUnpacker interface. * Add alias functions. * Add class MessagePack interface. Version 0.1.5 ------------- * Add msgpack_pack.c * Add msgpack_unpack.c * Update msgpack.c Version 0.1.4 ------------- * Change broken random data. * Support PHP 5.2.x version. Version 0.1.3 ------------- * Fix broken random data. * Change arrays and objects. Version 0.1.2 ------------- * Add Serializable class support. * Fix arrays and objects reference. Version 0.1.1 ------------- * Add session support. Version 0.1.0 ------------- * Initial release. msgpack-0.5.5/EXPERIMENTAL0000644000077100007710000000000012110565607014635 0ustar xinchenxinchenmsgpack-0.5.5/config.m40000644000077100007710000000166612110565607014547 0ustar xinchenxinchendnl config.m4 for extension msgpack dnl Comments in this file start with the string 'dnl'. dnl Remove where necessary. This file will not work dnl without editing. dnl Check PHP version: AC_MSG_CHECKING(PHP version) AC_TRY_COMPILE([#include "$phpincludedir/main/php_version.h"], [ #if PHP_MAJOR_VERSION < 5 #error this extension requires at least PHP version 5 or newer #endif ], [AC_MSG_RESULT(ok)], [AC_MSG_ERROR([need at least PHP 5 or newer])]) dnl If your extension references something external, use with: PHP_ARG_WITH(msgpack, for msgpack support, Make sure that the comment is aligned: [ --with-msgpack Include msgpack support]) if test "$PHP_MSGPACK" != "no"; then PHP_NEW_EXTENSION(msgpack, msgpack.c msgpack_pack.c msgpack_unpack.c msgpack_class.c msgpack_convert.c, $ext_shared) ifdef([PHP_INSTALL_HEADERS], [ PHP_INSTALL_HEADERS([ext/msgpack], [php_msgpack.h]) ], [ PHP_ADD_MAKEFILE_FRAGMENT ]) fi msgpack-0.5.5/config.w320000644000077100007710000000045112110565607014631 0ustar xinchenxinchen// $Id$ // vim:ft=javascript ARG_ENABLE("msgpack", "for msgpack support", "yes"); if (PHP_MSGPACK != "no") { EXTENSION("msgpack", "msgpack.c", PHP_MSGPACK_SHARED, ""); ADD_SOURCES(configure_module_dirname, "msgpack_pack.c msgpack_unpack.c msgpack_class.c msgpack_convert.c", "msgpack"); } msgpack-0.5.5/msgpack.php0000644000077100007710000000076612110565607015176 0ustar xinchenxinchen"; if(!extension_loaded('msgpack')) { dl('msgpack.' . PHP_SHLIB_SUFFIX); } $module = 'msgpack'; $functions = get_extension_funcs($module); echo "Functions available in the test extension:$br\n"; foreach($functions as $func) { echo $func."$br\n"; } echo "$br\n"; $function = $module . '_serialize'; if (extension_loaded($module)) { $str = $function($module); } else { $str = "Module $module is not compiled into PHP"; } echo "$str\n"; ?> msgpack-0.5.5/msgpack.c0000644000077100007710000002102712110565607014622 0ustar xinchenxinchen #ifdef HAVE_CONFIG_H #include "config.h" #endif #include "php.h" #include "php_ini.h" #include "ext/standard/info.h" /* for php_info */ #include "ext/standard/php_incomplete_class.h" /* for incomplete_class */ #include "ext/standard/php_var.h" /* for PHP_VAR_SERIALIZE */ #include "ext/session/php_session.h" /* for php_session_register_serializer */ #include "php_msgpack.h" #include "msgpack_pack.h" #include "msgpack_unpack.h" #include "msgpack_class.h" #include "msgpack_convert.h" #include "msgpack_errors.h" #include "msgpack/version.h" ZEND_DECLARE_MODULE_GLOBALS(msgpack) static ZEND_FUNCTION(msgpack_serialize); static ZEND_FUNCTION(msgpack_unserialize); ZEND_BEGIN_ARG_INFO_EX(arginfo_msgpack_serialize, 0, 0, 1) ZEND_ARG_INFO(0, value) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_msgpack_unserialize, 0, 0, 1) ZEND_ARG_INFO(0, str) ZEND_ARG_INFO(0, object) ZEND_END_ARG_INFO() PHP_INI_BEGIN() STD_PHP_INI_BOOLEAN( "msgpack.error_display", "1", PHP_INI_ALL, OnUpdateBool, error_display, zend_msgpack_globals, msgpack_globals) STD_PHP_INI_BOOLEAN( "msgpack.php_only", "1", PHP_INI_ALL, OnUpdateBool, php_only, zend_msgpack_globals, msgpack_globals) STD_PHP_INI_BOOLEAN( "msgpack.illegal_key_insert", "0", PHP_INI_ALL, OnUpdateBool, illegal_key_insert, zend_msgpack_globals, msgpack_globals) PHP_INI_END() #if HAVE_PHP_SESSION PS_SERIALIZER_FUNCS(msgpack); #endif static zend_function_entry msgpack_functions[] = { ZEND_FE(msgpack_serialize, arginfo_msgpack_serialize) ZEND_FE(msgpack_unserialize, arginfo_msgpack_unserialize) ZEND_FALIAS(msgpack_pack, msgpack_serialize, arginfo_msgpack_serialize) ZEND_FALIAS(msgpack_unpack, msgpack_unserialize, arginfo_msgpack_unserialize) {NULL, NULL, NULL} }; static void msgpack_init_globals(zend_msgpack_globals *msgpack_globals) { TSRMLS_FETCH(); if (PG(display_errors)) { msgpack_globals->error_display = 1; } else { msgpack_globals->error_display = 0; } msgpack_globals->php_only = 1; msgpack_globals->illegal_key_insert = 0; msgpack_globals->serialize.var_hash = NULL; msgpack_globals->serialize.level = 0; } static ZEND_MINIT_FUNCTION(msgpack) { ZEND_INIT_MODULE_GLOBALS(msgpack, msgpack_init_globals, NULL); REGISTER_INI_ENTRIES(); #if HAVE_PHP_SESSION php_session_register_serializer("msgpack", PS_SERIALIZER_ENCODE_NAME(msgpack), PS_SERIALIZER_DECODE_NAME(msgpack)); #endif msgpack_init_class(); #if (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION < 1) REGISTER_LONG_CONSTANT( "MESSAGEPACK_OPT_PHPONLY", MSGPACK_CLASS_OPT_PHPONLY, CONST_CS | CONST_PERSISTENT); #endif return SUCCESS; } static ZEND_MSHUTDOWN_FUNCTION(msgpack) { UNREGISTER_INI_ENTRIES(); return SUCCESS; } static ZEND_MINFO_FUNCTION(msgpack) { php_info_print_table_start(); php_info_print_table_row(2, "MessagePack Support", "enabled"); #if HAVE_PHP_SESSION php_info_print_table_row(2, "Session Support", "enabled" ); #endif php_info_print_table_row(2, "extension Version", MSGPACK_EXTENSION_VERSION); php_info_print_table_row(2, "header Version", MSGPACK_VERSION); php_info_print_table_end(); DISPLAY_INI_ENTRIES(); } zend_module_entry msgpack_module_entry = { #if ZEND_MODULE_API_NO >= 20010901 STANDARD_MODULE_HEADER, #endif "msgpack", msgpack_functions, ZEND_MINIT(msgpack), ZEND_MSHUTDOWN(msgpack), NULL, NULL, ZEND_MINFO(msgpack), #if ZEND_MODULE_API_NO >= 20010901 MSGPACK_EXTENSION_VERSION, #endif STANDARD_MODULE_PROPERTIES }; #ifdef COMPILE_DL_MSGPACK ZEND_GET_MODULE(msgpack) #endif #if HAVE_PHP_SESSION PS_SERIALIZER_ENCODE_FUNC(msgpack) { smart_str buf = {0}; msgpack_serialize_data_t var_hash; msgpack_serialize_var_init(&var_hash); msgpack_serialize_zval(&buf, PS(http_session_vars), var_hash TSRMLS_CC); if (newlen) { *newlen = buf.len; } smart_str_0(&buf); *newstr = buf.c; msgpack_serialize_var_destroy(&var_hash); return SUCCESS; } PS_SERIALIZER_DECODE_FUNC(msgpack) { int ret; HashTable *tmp_hash; HashPosition tmp_hash_pos; char *key_str; ulong key_long; uint key_len; zval *tmp; zval **value; size_t off = 0; msgpack_unpack_t mp; msgpack_unserialize_data_t var_hash; ALLOC_INIT_ZVAL(tmp); template_init(&mp); msgpack_unserialize_var_init(&var_hash); mp.user.retval = (zval *)tmp; mp.user.var_hash = (msgpack_unserialize_data_t *)&var_hash; ret = template_execute(&mp, (char *)val, (size_t)vallen, &off); if (ret == MSGPACK_UNPACK_EXTRA_BYTES || ret == MSGPACK_UNPACK_SUCCESS) { msgpack_unserialize_var_destroy(&var_hash, 0); tmp_hash = HASH_OF(tmp); zend_hash_internal_pointer_reset_ex(tmp_hash, &tmp_hash_pos); while (zend_hash_get_current_data_ex( tmp_hash, (void *)&value, &tmp_hash_pos) == SUCCESS) { ret = zend_hash_get_current_key_ex( tmp_hash, &key_str, &key_len, &key_long, 0, &tmp_hash_pos); switch (ret) { case HASH_KEY_IS_LONG: /* ??? */ break; case HASH_KEY_IS_STRING: php_set_session_var( key_str, key_len - 1, *value, NULL TSRMLS_CC); php_add_session_var(key_str, key_len - 1 TSRMLS_CC); break; } zend_hash_move_forward_ex(tmp_hash, &tmp_hash_pos); } } else { msgpack_unserialize_var_destroy(&var_hash, 1); } zval_ptr_dtor(&tmp); return SUCCESS; } #endif PHP_MSGPACK_API void php_msgpack_serialize(smart_str *buf, zval *val TSRMLS_DC) { msgpack_serialize_data_t var_hash; msgpack_serialize_var_init(&var_hash); msgpack_serialize_zval(buf, val, var_hash TSRMLS_CC); msgpack_serialize_var_destroy(&var_hash); } PHP_MSGPACK_API void php_msgpack_unserialize( zval *return_value, char *str, size_t str_len TSRMLS_DC) { int ret; size_t off = 0; msgpack_unpack_t mp; msgpack_unserialize_data_t var_hash; if (str_len <= 0) { RETURN_NULL(); } template_init(&mp); msgpack_unserialize_var_init(&var_hash); mp.user.retval = (zval *)return_value; mp.user.var_hash = (msgpack_unserialize_data_t *)&var_hash; ret = template_execute(&mp, str, (size_t)str_len, &off); switch (ret) { case MSGPACK_UNPACK_PARSE_ERROR: zval_dtor(return_value); ZVAL_FALSE(return_value); msgpack_unserialize_var_destroy(&var_hash, 1); MSGPACK_WARNING("[msgpack] (%s) Parse error", __FUNCTION__); break; case MSGPACK_UNPACK_CONTINUE: zval_dtor(return_value); ZVAL_FALSE(return_value); msgpack_unserialize_var_destroy(&var_hash, 1); MSGPACK_WARNING( "[msgpack] (%s) Insufficient data for unserializing", __FUNCTION__); break; case MSGPACK_UNPACK_EXTRA_BYTES: case MSGPACK_UNPACK_SUCCESS: msgpack_unserialize_var_destroy(&var_hash, 0); if (off < (size_t)str_len) { MSGPACK_WARNING("[msgpack] (%s) Extra bytes", __FUNCTION__); } break; default: msgpack_unserialize_var_destroy(&var_hash, 0); MSGPACK_WARNING("[msgpack] (%s) Unknown result", __FUNCTION__); break; } } static ZEND_FUNCTION(msgpack_serialize) { zval *parameter; smart_str buf = {0}; if (zend_parse_parameters( ZEND_NUM_ARGS() TSRMLS_CC, "z", ¶meter) == FAILURE) { return; } php_msgpack_serialize(&buf, parameter TSRMLS_CC); ZVAL_STRINGL(return_value, buf.c, buf.len, 1); smart_str_free(&buf); } static ZEND_FUNCTION(msgpack_unserialize) { char *str; int str_len; zval *object = NULL; if (zend_parse_parameters( ZEND_NUM_ARGS() TSRMLS_CC, "s|z", &str, &str_len, &object) == FAILURE) { return; } if (!str_len) { RETURN_NULL(); } if (object == NULL) { php_msgpack_unserialize(return_value, str, str_len TSRMLS_CC); } else { zval *zv; ALLOC_INIT_ZVAL(zv); php_msgpack_unserialize(zv, str, str_len TSRMLS_CC); if (msgpack_convert_template(return_value, object, &zv) != SUCCESS) { RETURN_NULL(); } } } msgpack-0.5.5/msgpack_class.c0000644000077100007710000004342512110565607016015 0ustar xinchenxinchen#include "php.h" #include "php_msgpack.h" #include "msgpack_pack.h" #include "msgpack_unpack.h" #include "msgpack_class.h" #include "msgpack_convert.h" #include "msgpack_errors.h" typedef struct { zend_object object; long php_only; } php_msgpack_base_t; typedef struct { zend_object object; smart_str buffer; zval *retval; long offset; msgpack_unpack_t mp; msgpack_unserialize_data_t var_hash; long php_only; zend_bool finished; int error; } php_msgpack_unpacker_t; #if ZEND_MODULE_API_NO >= 20060613 # define MSGPACK_METHOD_BASE(classname, name) zim_##classname##_##name #else # define MSGPACK_METHOD_BASE(classname, name) zif_##classname##_##name #endif #if ZEND_MODULE_API_NO >= 20090115 # define PUSH_PARAM(arg) zend_vm_stack_push(arg TSRMLS_CC) # define POP_PARAM() (void)zend_vm_stack_pop(TSRMLS_C) # define PUSH_EO_PARAM() # define POP_EO_PARAM() #else # define PUSH_PARAM(arg) zend_ptr_stack_push(&EG(argument_stack), arg) # define POP_PARAM() (void)zend_ptr_stack_pop(&EG(argument_stack)) # define PUSH_EO_PARAM() zend_ptr_stack_push(&EG(argument_stack), NULL) # define POP_EO_PARAM() (void)zend_ptr_stack_pop(&EG(argument_stack)) #endif #if (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION > 0) #define MSGPACK_METHOD_HELPER(classname, name, retval, thisptr, num, param) \ PUSH_PARAM(param); PUSH_PARAM((void*)num); \ PUSH_EO_PARAM(); \ MSGPACK_METHOD_BASE(classname, name)(num, retval, NULL, thisptr, 0 TSRMLS_CC); \ POP_EO_PARAM(); \ POP_PARAM(); POP_PARAM(); #define MSGPACK_METHOD(classname, name, retval, thisptr) \ MSGPACK_METHOD_BASE(classname, name)(0, retval, NULL, thisptr, 0 TSRMLS_CC) #else #define MSGPACK_METHOD_HELPER(classname, name, retval, thisptr, num, param) \ PUSH_PARAM(param); PUSH_PARAM((void*)num); \ PUSH_EO_PARAM(); \ MSGPACK_METHOD_BASE(classname, name)(num, retval, thisptr, 0 TSRMLS_CC); \ POP_EO_PARAM(); \ POP_PARAM(); POP_PARAM(); #define MSGPACK_METHOD(classname, name, retval, thisptr) \ MSGPACK_METHOD_BASE(classname, name)(0, retval, thisptr, 0 TSRMLS_CC) #endif #define MSGPACK_METHOD1(classname, name, retval, thisptr, param1) \ MSGPACK_METHOD_HELPER(classname, name, retval, thisptr, 1, param1); #define MSGPACK_BASE_OBJECT \ php_msgpack_base_t *base; \ base = (php_msgpack_base_t *)zend_object_store_get_object(getThis() TSRMLS_CC); #define MSGPACK_UNPACKER_OBJECT \ php_msgpack_unpacker_t *unpacker; \ unpacker = (php_msgpack_unpacker_t *)zend_object_store_get_object(getThis() TSRMLS_CC); /* MessagePack */ static zend_class_entry *msgpack_ce = NULL; static ZEND_METHOD(msgpack, __construct); static ZEND_METHOD(msgpack, setOption); static ZEND_METHOD(msgpack, pack); static ZEND_METHOD(msgpack, unpack); static ZEND_METHOD(msgpack, unpacker); ZEND_BEGIN_ARG_INFO_EX(arginfo_msgpack_base___construct, 0, 0, 0) ZEND_ARG_INFO(0, opt) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_msgpack_base_setOption, 0, 0, 2) ZEND_ARG_INFO(0, option) ZEND_ARG_INFO(0, value) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_msgpack_base_pack, 0, 0, 1) ZEND_ARG_INFO(0, value) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_msgpack_base_unpack, 0, 0, 1) ZEND_ARG_INFO(0, str) ZEND_ARG_INFO(0, object) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_msgpack_base_unpacker, 0, 0, 0) ZEND_END_ARG_INFO() static zend_function_entry msgpack_base_methods[] = { ZEND_ME(msgpack, __construct, arginfo_msgpack_base___construct, ZEND_ACC_PUBLIC) ZEND_ME(msgpack, setOption, arginfo_msgpack_base_setOption, ZEND_ACC_PUBLIC) ZEND_ME(msgpack, pack, arginfo_msgpack_base_pack, ZEND_ACC_PUBLIC) ZEND_ME(msgpack, unpack, arginfo_msgpack_base_unpack, ZEND_ACC_PUBLIC) ZEND_ME(msgpack, unpacker, arginfo_msgpack_base_unpacker, ZEND_ACC_PUBLIC) {NULL, NULL, NULL} }; /* MessagePackUnpacker */ static zend_class_entry *msgpack_unpacker_ce = NULL; static ZEND_METHOD(msgpack_unpacker, __construct); static ZEND_METHOD(msgpack_unpacker, __destruct); static ZEND_METHOD(msgpack_unpacker, setOption); static ZEND_METHOD(msgpack_unpacker, feed); static ZEND_METHOD(msgpack_unpacker, execute); static ZEND_METHOD(msgpack_unpacker, data); static ZEND_METHOD(msgpack_unpacker, reset); ZEND_BEGIN_ARG_INFO_EX(arginfo_msgpack_unpacker___construct, 0, 0, 0) ZEND_ARG_INFO(0, opt) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_msgpack_unpacker___destruct, 0, 0, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_msgpack_unpacker_setOption, 0, 0, 2) ZEND_ARG_INFO(0, option) ZEND_ARG_INFO(0, value) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_msgpack_unpacker_feed, 0, 0, 1) ZEND_ARG_INFO(0, str) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_msgpack_unpacker_execute, 1, 0, 0) ZEND_ARG_INFO(0, str) ZEND_ARG_INFO(1, offset) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_msgpack_unpacker_data, 0, 0, 0) ZEND_ARG_INFO(0, object) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_msgpack_unpacker_reset, 0, 0, 0) ZEND_END_ARG_INFO() static zend_function_entry msgpack_unpacker_methods[] = { ZEND_ME(msgpack_unpacker, __construct, arginfo_msgpack_unpacker___construct, ZEND_ACC_PUBLIC) ZEND_ME(msgpack_unpacker, __destruct, arginfo_msgpack_unpacker___destruct, ZEND_ACC_PUBLIC) ZEND_ME(msgpack_unpacker, setOption, arginfo_msgpack_unpacker_setOption, ZEND_ACC_PUBLIC) ZEND_ME(msgpack_unpacker, feed, arginfo_msgpack_unpacker_feed, ZEND_ACC_PUBLIC) ZEND_ME(msgpack_unpacker, execute, arginfo_msgpack_unpacker_execute, ZEND_ACC_PUBLIC) ZEND_ME(msgpack_unpacker, data, arginfo_msgpack_unpacker_data, ZEND_ACC_PUBLIC) ZEND_ME(msgpack_unpacker, reset, arginfo_msgpack_unpacker_reset, ZEND_ACC_PUBLIC) {NULL, NULL, NULL} }; static void php_msgpack_base_free(php_msgpack_base_t *base TSRMLS_DC) { #if (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION > 0) zend_object_std_dtor(&base->object TSRMLS_CC); #else if (base->object.properties) { zend_hash_destroy(base->object.properties); FREE_HASHTABLE(base->object.properties); } #endif efree(base); } static zend_object_value php_msgpack_base_new(zend_class_entry *ce TSRMLS_DC) { zend_object_value retval; php_msgpack_base_t *base; #if PHP_API_VERSION < 20100412 zval *tmp; #endif base = emalloc(sizeof(php_msgpack_base_t)); #if (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION > 0) zend_object_std_init(&base->object, ce TSRMLS_CC); #else ALLOC_HASHTABLE(base->object.properties); zend_hash_init(base->object.properties, 0, NULL, ZVAL_PTR_DTOR, 0); base->object.ce = ce; #endif #if PHP_API_VERSION < 20100412 zend_hash_copy( base->object.properties, &ce->default_properties, (copy_ctor_func_t)zval_add_ref, (void *)&tmp, sizeof(zval *)); #else object_properties_init(&base->object, ce); #endif retval.handle = zend_objects_store_put( base, (zend_objects_store_dtor_t)zend_objects_destroy_object, (zend_objects_free_object_storage_t)php_msgpack_base_free, NULL TSRMLS_CC); retval.handlers = zend_get_std_object_handlers(); return retval; } static void php_msgpack_unpacker_free( php_msgpack_unpacker_t *unpacker TSRMLS_DC) { #if (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION > 0) zend_object_std_dtor(&unpacker->object TSRMLS_CC); #else if (unpacker->object.properties) { zend_hash_destroy(unpacker->object.properties); FREE_HASHTABLE(unpacker->object.properties); } #endif efree(unpacker); } static zend_object_value php_msgpack_unpacker_new( zend_class_entry *ce TSRMLS_DC) { zend_object_value retval; php_msgpack_unpacker_t *unpacker; #if PHP_API_VERSION < 20100412 zval *tmp; #endif unpacker = emalloc(sizeof(php_msgpack_unpacker_t)); #if (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION > 0) zend_object_std_init(&unpacker->object, ce TSRMLS_CC); #else ALLOC_HASHTABLE(unpacker->object.properties); zend_hash_init(unpacker->object.properties, 0, NULL, ZVAL_PTR_DTOR, 0); unpacker->object.ce = ce; #endif #if PHP_API_VERSION < 20100412 zend_hash_copy( unpacker->object.properties, &ce->default_properties, (copy_ctor_func_t)zval_add_ref, (void *)&tmp, sizeof(zval *)); #else object_properties_init(&unpacker->object, ce); #endif retval.handle = zend_objects_store_put( unpacker, (zend_objects_store_dtor_t)zend_objects_destroy_object, (zend_objects_free_object_storage_t)php_msgpack_unpacker_free, NULL TSRMLS_CC); retval.handlers = zend_get_std_object_handlers(); return retval; } /* MessagePack */ static ZEND_METHOD(msgpack, __construct) { zend_bool php_only = MSGPACK_G(php_only); MSGPACK_BASE_OBJECT; if (zend_parse_parameters( ZEND_NUM_ARGS() TSRMLS_CC, "|b", &php_only) == FAILURE) { return; } base->php_only = php_only; } static ZEND_METHOD(msgpack, setOption) { long option; zval *value; MSGPACK_BASE_OBJECT; if (zend_parse_parameters( ZEND_NUM_ARGS() TSRMLS_CC, "lz", &option, &value) == FAILURE) { return; } switch (option) { case MSGPACK_CLASS_OPT_PHPONLY: convert_to_boolean(value); base->php_only = Z_BVAL_P(value); break; default: MSGPACK_WARNING("[msgpack] (MessagePack::setOption) " "error setting msgpack option"); RETURN_FALSE; break; } RETURN_TRUE; } static ZEND_METHOD(msgpack, pack) { zval *parameter; smart_str buf = {0}; int php_only = MSGPACK_G(php_only); MSGPACK_BASE_OBJECT; if (zend_parse_parameters( ZEND_NUM_ARGS() TSRMLS_CC, "z", ¶meter) == FAILURE) { return; } MSGPACK_G(php_only) = base->php_only; php_msgpack_serialize(&buf, parameter TSRMLS_CC); MSGPACK_G(php_only) = php_only; ZVAL_STRINGL(return_value, buf.c, buf.len, 1); smart_str_free(&buf); } static ZEND_METHOD(msgpack, unpack) { char *str; int str_len; zval *object = NULL; int php_only = MSGPACK_G(php_only); MSGPACK_BASE_OBJECT; if (zend_parse_parameters( ZEND_NUM_ARGS() TSRMLS_CC, "s|z", &str, &str_len, &object) == FAILURE) { return; } if (!str_len) { RETURN_FALSE; } MSGPACK_G(php_only) = base->php_only; if (object == NULL) { php_msgpack_unserialize(return_value, str, str_len TSRMLS_CC); } else { zval *zv; ALLOC_INIT_ZVAL(zv); php_msgpack_unserialize(zv, str, str_len TSRMLS_CC); if (msgpack_convert_template(return_value, object, &zv) != SUCCESS) { RETURN_FALSE; } } MSGPACK_G(php_only) = php_only; } static ZEND_METHOD(msgpack, unpacker) { zval temp, *opt; MSGPACK_BASE_OBJECT; ALLOC_INIT_ZVAL(opt); ZVAL_BOOL(opt, base->php_only); object_init_ex(return_value, msgpack_unpacker_ce); MSGPACK_METHOD1(msgpack_unpacker, __construct, &temp, return_value, opt); zval_ptr_dtor(&opt); } /* MessagePackUnpacker */ static ZEND_METHOD(msgpack_unpacker, __construct) { zend_bool php_only = MSGPACK_G(php_only); MSGPACK_UNPACKER_OBJECT; if (zend_parse_parameters( ZEND_NUM_ARGS() TSRMLS_CC, "|b", &php_only) == FAILURE) { return; } unpacker->php_only = php_only; unpacker->buffer.c = NULL; unpacker->buffer.len = 0; unpacker->buffer.a = 0; unpacker->retval = NULL; unpacker->offset = 0; unpacker->finished = 0; unpacker->error = 0; template_init(&unpacker->mp); msgpack_unserialize_var_init(&unpacker->var_hash); (&unpacker->mp)->user.var_hash = (msgpack_unserialize_data_t *)&unpacker->var_hash; } static ZEND_METHOD(msgpack_unpacker, __destruct) { MSGPACK_UNPACKER_OBJECT; smart_str_free(&unpacker->buffer); if (unpacker->retval != NULL) { zval_ptr_dtor(&unpacker->retval); } msgpack_unserialize_var_destroy(&unpacker->var_hash, unpacker->error); } static ZEND_METHOD(msgpack_unpacker, setOption) { long option; zval *value; MSGPACK_UNPACKER_OBJECT; if (zend_parse_parameters( ZEND_NUM_ARGS() TSRMLS_CC, "lz", &option, &value) == FAILURE) { return; } switch (option) { case MSGPACK_CLASS_OPT_PHPONLY: convert_to_boolean(value); unpacker->php_only = Z_BVAL_P(value); break; default: MSGPACK_WARNING("[msgpack] (MessagePackUnpacker::setOption) " "error setting msgpack option"); RETURN_FALSE; break; } RETURN_TRUE; } static ZEND_METHOD(msgpack_unpacker, feed) { char *str; int str_len; MSGPACK_UNPACKER_OBJECT; if (zend_parse_parameters( ZEND_NUM_ARGS() TSRMLS_CC, "s", &str, &str_len) == FAILURE) { return; } if (!str_len) { RETURN_FALSE; } smart_str_appendl(&unpacker->buffer, str, str_len); RETURN_TRUE; } static ZEND_METHOD(msgpack_unpacker, execute) { char *str = NULL, *data; long str_len = 0; zval *offset = NULL; int ret; size_t len, off; int error_display = MSGPACK_G(error_display); int php_only = MSGPACK_G(php_only); MSGPACK_UNPACKER_OBJECT; if (zend_parse_parameters( ZEND_NUM_ARGS() TSRMLS_CC, "|sz/", &str, &str_len, &offset) == FAILURE) { return; } if (str != NULL) { data = (char *)str; len = (size_t)str_len; if (offset != NULL) { off = Z_LVAL_P(offset); } else { off = 0; } } else { data = (char *)unpacker->buffer.c; len = unpacker->buffer.len; off = unpacker->offset; } if (unpacker->retval == NULL) { ALLOC_INIT_ZVAL(unpacker->retval); } else if (unpacker->finished) { zval_ptr_dtor(&unpacker->retval); msgpack_unserialize_var_destroy(&unpacker->var_hash, unpacker->error); unpacker->error = 0; ALLOC_INIT_ZVAL(unpacker->retval); template_init(&unpacker->mp); msgpack_unserialize_var_init(&unpacker->var_hash); (&unpacker->mp)->user.var_hash = (msgpack_unserialize_data_t *)&unpacker->var_hash; } (&unpacker->mp)->user.retval = (zval *)unpacker->retval; MSGPACK_G(error_display) = 0; MSGPACK_G(php_only) = unpacker->php_only; ret = template_execute(&unpacker->mp, data, len, &off); MSGPACK_G(error_display) = error_display; MSGPACK_G(php_only) = php_only; if (str != NULL) { if (offset != NULL) { ZVAL_LONG(offset, off); } } else { unpacker->offset = off; } switch (ret) { case MSGPACK_UNPACK_EXTRA_BYTES: case MSGPACK_UNPACK_SUCCESS: unpacker->finished = 1; unpacker->error = 0; RETURN_TRUE; default: unpacker->error = 1; RETURN_FALSE; } } static ZEND_METHOD(msgpack_unpacker, data) { zval *object = NULL; MSGPACK_UNPACKER_OBJECT; if (zend_parse_parameters( ZEND_NUM_ARGS() TSRMLS_CC, "|z", &object) == FAILURE) { return; } if (unpacker->retval != NULL) { if (object == NULL) { ZVAL_ZVAL(return_value, unpacker->retval, 1, 0); } else { zval *zv; ALLOC_INIT_ZVAL(zv); ZVAL_ZVAL(zv, unpacker->retval, 1, 0); if (msgpack_convert_object(return_value, object, &zv) != SUCCESS) { RETURN_NULL(); } } MSGPACK_METHOD(msgpack_unpacker, reset, NULL, getThis()); return; } RETURN_FALSE; } static ZEND_METHOD(msgpack_unpacker, reset) { smart_str buffer = {0}; MSGPACK_UNPACKER_OBJECT; if (unpacker->buffer.len > unpacker->offset) { smart_str_appendl(&buffer, unpacker->buffer.c + unpacker->offset, unpacker->buffer.len - unpacker->offset); } smart_str_free(&unpacker->buffer); unpacker->buffer.c = NULL; unpacker->buffer.len = 0; unpacker->buffer.a = 0; unpacker->offset = 0; unpacker->finished = 0; if (buffer.len > 0) { smart_str_appendl(&unpacker->buffer, buffer.c, buffer.len); } smart_str_free(&buffer); if (unpacker->retval != NULL) { zval_ptr_dtor(&unpacker->retval); unpacker->retval = NULL; } msgpack_unserialize_var_destroy(&unpacker->var_hash, unpacker->error); unpacker->error = 0; template_init(&unpacker->mp); msgpack_unserialize_var_init(&unpacker->var_hash); (&unpacker->mp)->user.var_hash = (msgpack_unserialize_data_t *)&unpacker->var_hash; } void msgpack_init_class() { zend_class_entry ce; TSRMLS_FETCH(); /* base */ INIT_CLASS_ENTRY(ce, "MessagePack", msgpack_base_methods); msgpack_ce = zend_register_internal_class(&ce TSRMLS_CC); msgpack_ce->create_object = php_msgpack_base_new; #if (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION > 0) zend_declare_class_constant_long( msgpack_ce, ZEND_STRS("OPT_PHPONLY") - 1, MSGPACK_CLASS_OPT_PHPONLY TSRMLS_CC); #endif /* unpacker */ INIT_CLASS_ENTRY(ce, "MessagePackUnpacker", msgpack_unpacker_methods); msgpack_unpacker_ce = zend_register_internal_class(&ce TSRMLS_CC); msgpack_unpacker_ce->create_object = php_msgpack_unpacker_new; } msgpack-0.5.5/msgpack_class.h0000644000077100007710000000017612110565607016016 0ustar xinchenxinchen #ifndef MSGPACK_CLASS_H #define MSGPACK_CLASS_H #define MSGPACK_CLASS_OPT_PHPONLY -1001 void msgpack_init_class(); #endif msgpack-0.5.5/msgpack_convert.c0000644000077100007710000006430612110565607016371 0ustar xinchenxinchen #include "php.h" #include "php_msgpack.h" #include "msgpack_convert.h" #include "msgpack_errors.h" #if (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION < 3) # define Z_REFCOUNT_P(pz) ((pz)->refcount) # define Z_SET_ISREF_P(pz) (pz)->is_ref = 1 # define Z_UNSET_ISREF_P(pz) (pz)->is_ref = 0 #endif #define MSGPACK_CONVERT_COPY_ZVAL(_pz, _ppz) \ ALLOC_INIT_ZVAL(_pz); \ *(_pz) = **(_ppz); \ if (PZVAL_IS_REF(*(_ppz))) { \ if (Z_REFCOUNT_P(*(_ppz)) > 0) { \ zval_copy_ctor(_pz); \ } else { \ FREE_ZVAL(*(_ppz)); \ } \ INIT_PZVAL(_pz); \ Z_SET_ISREF_P(_pz); \ } else { \ zval_copy_ctor(_pz); \ INIT_PZVAL(_pz); \ } #define MSGPACK_CONVERT_UPDATE_PROPERTY(_ht, _key, _key_len, _val, _var) \ if (zend_symtable_update( \ _ht, _key, _key_len, &_val, sizeof(_val), NULL) == SUCCESS) { \ zend_hash_add(_var, _key, _key_len, &_val, sizeof(_val), NULL); \ return SUCCESS; \ } inline int msgpack_convert_long_to_properties( HashTable *ht, HashTable **properties, HashPosition *prop_pos, uint key_index, zval *val, HashTable *var) { TSRMLS_FETCH(); if (*properties != NULL) { char *prop_key; uint prop_key_len; ulong prop_key_index; zval **data = NULL; zval *tplval = NULL; zval **dataval = NULL; for (;; zend_hash_move_forward_ex(*properties, prop_pos)) { if (zend_hash_get_current_key_ex( *properties, &prop_key, &prop_key_len, &prop_key_index, 0, prop_pos) == HASH_KEY_IS_STRING) { if (var == NULL || !zend_hash_exists(var, prop_key, prop_key_len)) { if (zend_hash_find( ht, prop_key, prop_key_len, (void **)&data) == SUCCESS) { switch (Z_TYPE_PP(data)) { case IS_ARRAY: { HashTable *dataht; dataht = HASH_OF(val); if (zend_hash_index_find( dataht, prop_key_index, (void **)dataval) != SUCCESS) { MSGPACK_WARNING( "[msgpack] (%s) " "can't get data value by index", __FUNCTION__); return FAILURE; } ALLOC_INIT_ZVAL(tplval); if (msgpack_convert_array( tplval, *data, dataval) == SUCCESS) { zend_hash_move_forward_ex( *properties, prop_pos); return zend_symtable_update( ht, prop_key, prop_key_len, &tplval, sizeof(tplval), NULL); } // TODO: de we need to call dtor? return FAILURE; break; } case IS_OBJECT: { ALLOC_INIT_ZVAL(tplval); if (msgpack_convert_object( tplval, *data, &val) == SUCCESS) { zend_hash_move_forward_ex( *properties, prop_pos); return zend_symtable_update( ht, prop_key, prop_key_len, &tplval, sizeof(tplval), NULL); } // TODO: de we need to call dtor? return FAILURE; break; } default: zend_hash_move_forward_ex(*properties, prop_pos); return zend_symtable_update( ht, prop_key, prop_key_len, &val, sizeof(val), NULL); break; } } } } else { break; } } *properties = NULL; } return zend_hash_index_update(ht, key_index, &val, sizeof(val), NULL); } inline int msgpack_convert_string_to_properties( zval *object, char *key, uint key_len, zval *val, HashTable *var) { zval **data = NULL; HashTable *ht; zend_class_entry *ce; char *prot_name, *priv_name; int prop_name_len; TSRMLS_FETCH(); ht = HASH_OF(object); ce = zend_get_class_entry(object TSRMLS_CC); /* private */ zend_mangle_property_name( &priv_name, &prop_name_len, ce->name, ce->name_length, key, key_len - 1, 1); if (zend_hash_find( ht, priv_name, prop_name_len + 1, (void **)&data) == SUCCESS) { MSGPACK_CONVERT_UPDATE_PROPERTY(ht, priv_name, prop_name_len + 1, val, var); } /* protected */ zend_mangle_property_name( &prot_name, &prop_name_len, "*", 1, key, key_len - 1, 1); if (zend_hash_find( ht, prot_name, prop_name_len + 1, (void **)&data) == SUCCESS) { MSGPACK_CONVERT_UPDATE_PROPERTY(ht, prot_name, prop_name_len + 1, val, var); } /* public */ MSGPACK_CONVERT_UPDATE_PROPERTY(ht, key, key_len, val, var); return FAILURE; } int msgpack_convert_array(zval *return_value, zval *tpl, zval **value) { TSRMLS_FETCH(); if (Z_TYPE_P(tpl) == IS_ARRAY) { char *key; uint key_len; int key_type; ulong key_index; zval **data, **arydata; HashPosition pos, valpos; HashTable *ht, *htval; int num; ht = HASH_OF(tpl); // TODO: maybe need to release memory? array_init(return_value); num = zend_hash_num_elements(ht); if (num <= 0) { MSGPACK_WARNING( "[msgpack] (%s) template array length is 0", __FUNCTION__); zval_ptr_dtor(value); return FAILURE; } /* string */ if (ht->nNumOfElements != ht->nNextFreeElement) { htval = HASH_OF(*value); if (!htval) { MSGPACK_WARNING( "[msgpack] (%s) input data is not array", __FUNCTION__); zval_ptr_dtor(value); return FAILURE; } zend_hash_internal_pointer_reset_ex(ht, &pos); zend_hash_internal_pointer_reset_ex(htval, &valpos); for (;; zend_hash_move_forward_ex(ht, &pos), zend_hash_move_forward_ex(htval, &valpos)) { key_type = zend_hash_get_current_key_ex( ht, &key, &key_len, &key_index, 0, &pos); if (key_type == HASH_KEY_NON_EXISTANT) { break; } if (zend_hash_get_current_data_ex( ht, (void *)&data, &pos) != SUCCESS) { continue; } if (key_type == HASH_KEY_IS_STRING) { int (*convert_function)(zval *, zval *, zval **) = NULL; zval **dataval, *val; switch (Z_TYPE_PP(data)) { case IS_ARRAY: convert_function = msgpack_convert_array; break; case IS_OBJECT: // case IS_STRING: convert_function = msgpack_convert_object; break; default: break; } if (zend_hash_get_current_data_ex( htval, (void *)&dataval, &valpos) != SUCCESS) { MSGPACK_WARNING( "[msgpack] (%s) can't get data", __FUNCTION__); zval_ptr_dtor(value); return FAILURE; } MSGPACK_CONVERT_COPY_ZVAL(val, dataval); if (convert_function) { zval *rv; ALLOC_INIT_ZVAL(rv); if (convert_function(rv, *data, &val) != SUCCESS) { zval_ptr_dtor(&val); return FAILURE; } add_assoc_zval_ex(return_value, key, key_len, rv); } else { add_assoc_zval_ex(return_value, key, key_len, val); } } } zval_ptr_dtor(value); return SUCCESS; } else { /* index */ int (*convert_function)(zval *, zval *, zval **) = NULL; if (Z_TYPE_PP(value) != IS_ARRAY) { MSGPACK_WARNING( "[msgpack] (%s) unserialized data must be array.", __FUNCTION__); zval_ptr_dtor(value); return FAILURE; } zend_hash_internal_pointer_reset_ex(ht, &pos); key_type = zend_hash_get_current_key_ex( ht, &key, &key_len, &key_index, 0, &pos); if (key_type == HASH_KEY_NON_EXISTANT) { MSGPACK_WARNING( "[msgpack] (%s) first element in template array is empty", __FUNCTION__); zval_ptr_dtor(value); return FAILURE; } if (zend_hash_get_current_data_ex( ht, (void *)&data, &pos) != SUCCESS) { MSGPACK_WARNING( "[msgpack] (%s) invalid template: empty array?", __FUNCTION__); zval_ptr_dtor(value); return FAILURE; } switch (Z_TYPE_PP(data)) { case IS_ARRAY: convert_function = msgpack_convert_array; break; case IS_OBJECT: case IS_STRING: convert_function = msgpack_convert_object; break; default: break; } htval = HASH_OF(*value); num = zend_hash_num_elements(htval); if (num <= 0) { MSGPACK_WARNING( "[msgpack] (%s) array length is 0 in unserialized data", __FUNCTION__); zval_ptr_dtor(value); return FAILURE; } zend_hash_internal_pointer_reset_ex(htval, &valpos); for (;; zend_hash_move_forward_ex(htval, &valpos)) { key_type = zend_hash_get_current_key_ex( htval, &key, &key_len, &key_index, 0, &valpos); if (key_type == HASH_KEY_NON_EXISTANT) { break; } if (zend_hash_get_current_data_ex( htval, (void *)&arydata, &valpos) != SUCCESS) { MSGPACK_WARNING( "[msgpack] (%s) can't get next data in indexed array", __FUNCTION__); continue; } switch (key_type) { case HASH_KEY_IS_LONG: { zval *aryval, *rv; ALLOC_INIT_ZVAL(rv); MSGPACK_CONVERT_COPY_ZVAL(aryval, arydata); if (convert_function) { if (convert_function(rv, *data, &aryval) != SUCCESS) { zval_ptr_dtor(&aryval); MSGPACK_WARNING( "[msgpack] (%s) " "convert failure in HASH_KEY_IS_LONG " "in indexed array", __FUNCTION__); zval_ptr_dtor(value); return FAILURE; } add_next_index_zval(return_value, rv); } else { add_next_index_zval(return_value, aryval); } break; } case HASH_KEY_IS_STRING: MSGPACK_WARNING( "[msgpack] (%s) key is string", __FUNCTION__); zval_ptr_dtor(value); return FAILURE; default: MSGPACK_WARNING( "[msgpack] (%s) key is not string nor array", __FUNCTION__); zval_ptr_dtor(value); return FAILURE; } } zval_ptr_dtor(value); return SUCCESS; } } else { // shouldn't reach MSGPACK_WARNING( "[msgpack] (%s) template is not array", __FUNCTION__); zval_ptr_dtor(value); return FAILURE; } // shouldn't reach zval_ptr_dtor(value); return FAILURE; } int msgpack_convert_object(zval *return_value, zval *tpl, zval **value) { zend_class_entry *ce, **pce; TSRMLS_FETCH(); switch (Z_TYPE_P(tpl)) { case IS_STRING: if (zend_lookup_class( Z_STRVAL_P(tpl), Z_STRLEN_P(tpl), &pce TSRMLS_CC) != SUCCESS) { MSGPACK_ERROR("[msgpack] (%s) Class '%s' not found", __FUNCTION__, Z_STRVAL_P(tpl)); return FAILURE; } ce = *pce; break; case IS_OBJECT: ce = zend_get_class_entry(tpl TSRMLS_CC); break; default: MSGPACK_ERROR("[msgpack] (%s) object type is unsupported", __FUNCTION__); return FAILURE; } if (Z_TYPE_PP(value) == IS_OBJECT) { zend_class_entry *vce; vce = zend_get_class_entry(*value TSRMLS_CC); if (strcmp(ce->name, vce->name) == 0) { *return_value = **value; zval_copy_ctor(return_value); zval_ptr_dtor(value); return SUCCESS; } } object_init_ex(return_value, ce); /* Run the constructor if there is one */ if (ce->constructor && (ce->constructor->common.fn_flags & ZEND_ACC_PUBLIC)) { zval *retval_ptr = NULL; zval ***params = NULL; int num_args = 0; zend_fcall_info fci; zend_fcall_info_cache fcc; #if ZEND_MODULE_API_NO >= 20090626 fci.size = sizeof(fci); fci.function_table = EG(function_table); fci.function_name = NULL; fci.symbol_table = NULL; fci.object_ptr = return_value; fci.retval_ptr_ptr = &retval_ptr; fci.param_count = num_args; fci.params = params; fci.no_separation = 1; fcc.initialized = 1; fcc.function_handler = ce->constructor; fcc.calling_scope = EG(scope); fcc.called_scope = Z_OBJCE_P(return_value); fcc.object_ptr = return_value; #else fci.size = sizeof(fci); fci.function_table = EG(function_table); fci.function_name = NULL; fci.symbol_table = NULL; fci.object_pp = &return_value; fci.retval_ptr_ptr = &retval_ptr; fci.param_count = num_args; fci.params = params; fci.no_separation = 1; fcc.initialized = 1; fcc.function_handler = ce->constructor; fcc.calling_scope = EG(scope); fcc.object_pp = &return_value; #endif if (zend_call_function(&fci, &fcc TSRMLS_CC) == FAILURE) { if (params) { efree(params); } if (retval_ptr) { zval_ptr_dtor(&retval_ptr); } MSGPACK_WARNING( "[msgpack] (%s) Invocation of %s's constructor failed", __FUNCTION__, ce->name); return FAILURE; } if (retval_ptr) { zval_ptr_dtor(&retval_ptr); } if (params) { efree(params); } } switch (Z_TYPE_PP(value)) { case IS_ARRAY: { char *key; uint key_len; int key_type; ulong key_index; zval **data; HashPosition pos; HashTable *ht, *ret; HashTable *var = NULL; int num; ht = HASH_OF(*value); ret = HASH_OF(return_value); num = zend_hash_num_elements(ht); if (num <= 0) { zval_ptr_dtor(value); break; } /* string - php_only mode? */ if (ht->nNumOfElements != ht->nNextFreeElement || ht->nNumOfElements != ret->nNumOfElements) { HashTable *properties = NULL; HashPosition prop_pos; ALLOC_HASHTABLE(var); zend_hash_init(var, num, NULL, NULL, 0); zend_hash_internal_pointer_reset_ex(ht, &pos); for (;; zend_hash_move_forward_ex(ht, &pos)) { key_type = zend_hash_get_current_key_ex( ht, &key, &key_len, &key_index, 0, &pos); if (key_type == HASH_KEY_NON_EXISTANT) { break; } if (zend_hash_get_current_data_ex( ht, (void *)&data, &pos) != SUCCESS) { continue; } if (key_type == HASH_KEY_IS_STRING) { zval *val; MSGPACK_CONVERT_COPY_ZVAL(val, data); if (msgpack_convert_string_to_properties( return_value, key, key_len, val, var) != SUCCESS) { zval_ptr_dtor(&val); MSGPACK_WARNING( "[msgpack] (%s) " "illegal offset type, skip this decoding", __FUNCTION__); } } } /* index */ properties = Z_OBJ_HT_P(return_value)->get_properties( return_value TSRMLS_CC); if (HASH_OF(tpl)) { properties = HASH_OF(tpl); } zend_hash_internal_pointer_reset_ex(properties, &prop_pos); zend_hash_internal_pointer_reset_ex(ht, &pos); for (;; zend_hash_move_forward_ex(ht, &pos)) { key_type = zend_hash_get_current_key_ex( ht, &key, &key_len, &key_index, 0, &pos); if (key_type == HASH_KEY_NON_EXISTANT) { break; } if (zend_hash_get_current_data_ex( ht, (void *)&data, &pos) != SUCCESS) { continue; } switch (key_type) { case HASH_KEY_IS_LONG: { zval *val; MSGPACK_CONVERT_COPY_ZVAL(val, data); if (msgpack_convert_long_to_properties( ret, &properties, &prop_pos, key_index, val, var) != SUCCESS) { zval_ptr_dtor(&val); MSGPACK_WARNING( "[msgpack] (%s) " "illegal offset type, skip this decoding", __FUNCTION__); } break; } case HASH_KEY_IS_STRING: break; default: MSGPACK_WARNING( "[msgpack] (%s) key is not string nor array", __FUNCTION__); break; } } zend_hash_destroy(var); FREE_HASHTABLE(var); } else { HashPosition valpos; int (*convert_function)(zval *, zval *, zval **) = NULL; zval **arydata, *aryval; /* index */ zend_hash_internal_pointer_reset_ex(ret, &pos); zend_hash_internal_pointer_reset_ex(ht, &valpos); for (;; zend_hash_move_forward_ex(ret, &pos), zend_hash_move_forward_ex(ht, &valpos)) { key_type = zend_hash_get_current_key_ex( ret, &key, &key_len, &key_index, 0, &pos); if (key_type == HASH_KEY_NON_EXISTANT) { break; } if (zend_hash_get_current_data_ex( ret, (void *)&data, &pos) != SUCCESS) { continue; } switch (Z_TYPE_PP(data)) { case IS_ARRAY: convert_function = msgpack_convert_array; break; case IS_OBJECT: //case IS_STRING: -- may have default values of // class members, so it's not wise to allow convert_function = msgpack_convert_object; break; default: break; } if (zend_hash_get_current_data_ex( ht, (void *)&arydata, &valpos) != SUCCESS) { MSGPACK_WARNING( "[msgpack] (%s) can't get data value by index", __FUNCTION__); return FAILURE; } MSGPACK_CONVERT_COPY_ZVAL(aryval, arydata); if (convert_function) { zval *rv; ALLOC_INIT_ZVAL(rv); if (convert_function(rv, *data, &aryval) != SUCCESS) { zval_ptr_dtor(&aryval); MSGPACK_WARNING( "[msgpack] (%s) " "convert failure in convert_object", __FUNCTION__); return FAILURE; } zend_symtable_update( ret, key, key_len, &rv, sizeof(rv), NULL); } else { zend_symtable_update( ret, key, key_len, &aryval, sizeof(aryval), NULL); } } } zval_ptr_dtor(value); break; } default: { HashTable *properties = NULL; HashPosition prop_pos; properties = Z_OBJ_HT_P(return_value)->get_properties( return_value TSRMLS_CC); zend_hash_internal_pointer_reset_ex(properties, &prop_pos); if (msgpack_convert_long_to_properties( HASH_OF(return_value), &properties, &prop_pos, 0, *value, NULL) != SUCCESS) { MSGPACK_WARNING( "[msgpack] (%s) illegal offset type, skip this decoding", __FUNCTION__); } break; } } return SUCCESS; } int msgpack_convert_template(zval *return_value, zval *tpl, zval **value) { TSRMLS_FETCH(); switch (Z_TYPE_P(tpl)) { case IS_ARRAY: return msgpack_convert_array(return_value, tpl, value); break; case IS_STRING: case IS_OBJECT: return msgpack_convert_object(return_value, tpl, value); break; default: MSGPACK_ERROR("[msgpack] (%s) Template type is unsupported", __FUNCTION__); return FAILURE; } // shouldn't reach return FAILURE; } msgpack-0.5.5/msgpack_convert.h0000644000077100007710000000043512110565607016367 0ustar xinchenxinchen #ifndef MSGPACK_CONVERT_H #define MSGPACK_CONVERT_H int msgpack_convert_object(zval *return_value, zval *object, zval **value); int msgpack_convert_array(zval *return_value, zval *tpl, zval **value); int msgpack_convert_template(zval *return_value, zval *tpl, zval **value); #endif msgpack-0.5.5/msgpack_errors.h0000644000077100007710000000062712110565607016226 0ustar xinchenxinchen #ifndef MSGPACK_ERRORS_H #define MSGPACK_ERRORS_H #define MSGPACK_NOTICE(...) \ if (MSGPACK_G(error_display)) { \ zend_error(E_NOTICE, __VA_ARGS__); \ } #define MSGPACK_WARNING(...) \ if (MSGPACK_G(error_display)) { \ zend_error(E_WARNING, __VA_ARGS__); \ } #define MSGPACK_ERROR(...) zend_error(E_ERROR, __VA_ARGS__) #endif msgpack-0.5.5/msgpack_pack.c0000644000077100007710000004332412110565607015624 0ustar xinchenxinchen #include "php.h" #include "php_ini.h" #include "ext/standard/php_smart_str.h" #include "ext/standard/php_incomplete_class.h" #include "ext/standard/php_var.h" #include "php_msgpack.h" #include "msgpack_pack.h" #include "msgpack_errors.h" #include "msgpack/pack_define.h" #define msgpack_pack_user smart_str* #define msgpack_pack_inline_func(name) \ static inline void msgpack_pack ## name #define msgpack_pack_inline_func_cint(name) \ static inline void msgpack_pack ## name #define msgpack_pack_append_buffer(user, buf, len) \ smart_str_appendl(user, (const void*)buf, len) #include "msgpack/pack_template.h" #if ZEND_MODULE_API_NO < 20090626 # define Z_ISREF_P(pz) PZVAL_IS_REF(pz) #endif inline static int msgpack_check_ht_is_map(zval *array) { int count = zend_hash_num_elements(Z_ARRVAL_P(array)); if (count != (Z_ARRVAL_P(array))->nNextFreeElement) { return 1; } else { int i; HashPosition pos = {0}; zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(array), &pos); for (i = 0; i < count; i++) { if (zend_hash_get_current_key_type_ex(Z_ARRVAL_P(array), &pos) != HASH_KEY_IS_LONG) { return 1; } zend_hash_move_forward_ex(Z_ARRVAL_P(array), &pos); } } return 0; } inline static int msgpack_var_add( HashTable *var_hash, zval *var, void *var_old TSRMLS_DC) { ulong var_no; char id[32], *p; int len; if ((Z_TYPE_P(var) == IS_OBJECT) && Z_OBJ_HT_P(var)->get_class_entry) { p = smart_str_print_long( id + sizeof(id) - 1, (((size_t)Z_OBJCE_P(var) << 5) | ((size_t)Z_OBJCE_P(var) >> (sizeof(long) * 8 - 5))) + (long)Z_OBJ_HANDLE_P(var)); len = id + sizeof(id) - 1 - p; } else if (Z_TYPE_P(var) == IS_ARRAY) { p = smart_str_print_long(id + sizeof(id) - 1, (long)var); len = id + sizeof(id) - 1 - p; } else { return FAILURE; } if (var_old && zend_hash_find(var_hash, p, len, var_old) == SUCCESS) { if (!Z_ISREF_P(var)) { var_no = -1; zend_hash_next_index_insert( var_hash, &var_no, sizeof(var_no), NULL); } return FAILURE; } var_no = zend_hash_num_elements(var_hash) + 1; zend_hash_add(var_hash, p, len, &var_no, sizeof(var_no), NULL); return SUCCESS; } inline static void msgpack_serialize_string( smart_str *buf, char *str, size_t len) { msgpack_pack_raw(buf, len); msgpack_pack_raw_body(buf, str, len); } inline static void msgpack_serialize_class( smart_str *buf, zval *val, zval *retval_ptr, HashTable *var_hash, char *class_name, zend_uint name_len, zend_bool incomplete_class TSRMLS_DC) { int count; HashTable *ht = HASH_OF(retval_ptr); count = zend_hash_num_elements(ht); if (incomplete_class) { --count; } if (count > 0) { char *key; zval **data, **name; ulong key_index; HashPosition pos; int n; zval nval, *nvalp; msgpack_pack_map(buf, count + 1); msgpack_pack_nil(buf); msgpack_serialize_string(buf, class_name, name_len); INIT_ZVAL(nval); ZVAL_NULL(&nval); nvalp = &nval; zend_hash_internal_pointer_reset_ex(ht, &pos); for (;; zend_hash_move_forward_ex(ht, &pos)) { n = zend_hash_get_current_key_ex( ht, &key, NULL, &key_index, 0, &pos); if (n == HASH_KEY_NON_EXISTANT) { break; } if (incomplete_class && strcmp(key, MAGIC_MEMBER) == 0) { continue; } zend_hash_get_current_data_ex(ht, (void **)&name, &pos); if (Z_TYPE_PP(name) != IS_STRING) { MSGPACK_NOTICE( "[msgpack] (%s) __sleep should return an array only " "containing the names of instance-variables to serialize", __FUNCTION__); continue; } if (zend_hash_find( Z_OBJPROP_P(val), Z_STRVAL_PP(name), Z_STRLEN_PP(name) + 1, (void *)&data) == SUCCESS) { msgpack_serialize_string( buf, Z_STRVAL_PP(name), Z_STRLEN_PP(name)); msgpack_serialize_zval(buf, *data, var_hash TSRMLS_CC); } else { zend_class_entry *ce; ce = zend_get_class_entry(val TSRMLS_CC); if (ce) { char *prot_name, *priv_name; int prop_name_length; do { zend_mangle_property_name( &priv_name, &prop_name_length, ce->name, ce->name_length, Z_STRVAL_PP(name), Z_STRLEN_PP(name), ce->type & ZEND_INTERNAL_CLASS); if (zend_hash_find( Z_OBJPROP_P(val), priv_name, prop_name_length + 1, (void *)&data) == SUCCESS) { msgpack_serialize_string( buf, priv_name, prop_name_length); pefree(priv_name, ce->type & ZEND_INTERNAL_CLASS); msgpack_serialize_zval( buf, *data, var_hash TSRMLS_CC); break; } pefree(priv_name, ce->type & ZEND_INTERNAL_CLASS); zend_mangle_property_name( &prot_name, &prop_name_length, "*", 1, Z_STRVAL_PP(name), Z_STRLEN_PP(name), ce->type & ZEND_INTERNAL_CLASS); if (zend_hash_find( Z_OBJPROP_P(val), prot_name, prop_name_length + 1, (void *)&data) == SUCCESS) { msgpack_serialize_string( buf, prot_name, prop_name_length); pefree(prot_name, ce->type & ZEND_INTERNAL_CLASS); msgpack_serialize_zval( buf, *data, var_hash TSRMLS_CC); break; } pefree(prot_name, ce->type & ZEND_INTERNAL_CLASS); MSGPACK_NOTICE( "[msgpack] (%s) \"%s\" returned as member " "variable from __sleep() but does not exist", __FUNCTION__, Z_STRVAL_PP(name)); msgpack_serialize_string( buf, Z_STRVAL_PP(name), Z_STRLEN_PP(name)); msgpack_serialize_zval( buf, nvalp, var_hash TSRMLS_CC); } while (0); } else { msgpack_serialize_string( buf, Z_STRVAL_PP(name), Z_STRLEN_PP(name)); msgpack_serialize_zval(buf, nvalp, var_hash TSRMLS_CC); } } } } } inline static void msgpack_serialize_array( smart_str *buf, zval *val, HashTable *var_hash, zend_bool object, char* class_name, zend_uint name_len, zend_bool incomplete_class TSRMLS_DC) { HashTable *ht; size_t n; zend_bool hash = 1; if (object) { ht = Z_OBJPROP_P(val); } else { ht = HASH_OF(val); } if (ht) { n = zend_hash_num_elements(ht); } else { n = 0; } if (n > 0 && incomplete_class) { --n; } if (object) { if (n == 0) { msgpack_pack_map(buf, n); } else { if (MSGPACK_G(php_only)) { if (Z_ISREF_P(val)) { msgpack_pack_map(buf, n + 2); msgpack_pack_nil(buf); msgpack_pack_long(buf, MSGPACK_SERIALIZE_TYPE_REFERENCE); } else { msgpack_pack_map(buf, n + 1); } msgpack_pack_nil(buf); msgpack_serialize_string(buf, class_name, name_len); } else { msgpack_pack_array(buf, n); hash = 0; } } } else if (n == 0) { hash = 0; msgpack_pack_array(buf, n); } else if (Z_ISREF_P(val) && MSGPACK_G(php_only)) { msgpack_pack_map(buf, n + 1); msgpack_pack_nil(buf); msgpack_pack_long(buf, MSGPACK_SERIALIZE_TYPE_REFERENCE); } else if (!msgpack_check_ht_is_map(val)) { hash = 0; msgpack_pack_array(buf, n); } else { msgpack_pack_map(buf, n); } if (n > 0) { if (object || hash) { char *key; uint key_len; int key_type; ulong key_index; zval **data; HashPosition pos; zend_hash_internal_pointer_reset_ex(ht, &pos); for (;; zend_hash_move_forward_ex(ht, &pos)) { key_type = zend_hash_get_current_key_ex( ht, &key, &key_len, &key_index, 0, &pos); if (key_type == HASH_KEY_NON_EXISTANT) { break; } if (incomplete_class && strcmp(key, MAGIC_MEMBER) == 0) { continue; } if (hash) { switch (key_type) { case HASH_KEY_IS_LONG: msgpack_pack_long(buf, key_index); break; case HASH_KEY_IS_STRING: msgpack_serialize_string(buf, key, key_len - 1); break; default: msgpack_serialize_string(buf, "", sizeof("")); MSGPACK_WARNING( "[msgpack] (%s) key is not string nor array", __FUNCTION__); break; } } if (zend_hash_get_current_data_ex( ht, (void *)&data, &pos) != SUCCESS || !data || data == &val || (Z_TYPE_PP(data) == IS_ARRAY && Z_ARRVAL_PP(data)->nApplyCount > 1)) { msgpack_pack_nil(buf); } else { if (Z_TYPE_PP(data) == IS_ARRAY) { Z_ARRVAL_PP(data)->nApplyCount++; } msgpack_serialize_zval(buf, *data, var_hash TSRMLS_CC); if (Z_TYPE_PP(data) == IS_ARRAY) { Z_ARRVAL_PP(data)->nApplyCount--; } } } } else { zval **data; uint i; for (i = 0; i < n; i++) { if (zend_hash_index_find(ht, i, (void *)&data) != SUCCESS || !data || data == &val || (Z_TYPE_PP(data) == IS_ARRAY && Z_ARRVAL_PP(data)->nApplyCount > 1)) { msgpack_pack_nil(buf); } else { if (Z_TYPE_PP(data) == IS_ARRAY) { Z_ARRVAL_PP(data)->nApplyCount++; } msgpack_serialize_zval(buf, *data, var_hash TSRMLS_CC); if (Z_TYPE_PP(data) == IS_ARRAY) { Z_ARRVAL_PP(data)->nApplyCount--; } } } } } } inline static void msgpack_serialize_object( smart_str *buf, zval *val, HashTable *var_hash, char* class_name, zend_uint name_len, zend_bool incomplete_class TSRMLS_DC) { zval *retval_ptr = NULL; zval fname; int res; zend_class_entry *ce = NULL; if (Z_OBJ_HT_P(val)->get_class_entry) { ce = Z_OBJCE_P(val); } #if (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION > 0) if (ce && ce->serialize != NULL) { unsigned char *serialized_data = NULL; zend_uint serialized_length; if (ce->serialize( val, &serialized_data, &serialized_length, (zend_serialize_data *)var_hash TSRMLS_CC) == SUCCESS && !EG(exception)) { /* has custom handler */ msgpack_pack_map(buf, 2); msgpack_pack_nil(buf); msgpack_pack_long(buf, MSGPACK_SERIALIZE_TYPE_CUSTOM_OBJECT); msgpack_serialize_string(buf, (char *)ce->name, ce->name_length); msgpack_pack_raw(buf, serialized_length); msgpack_pack_raw_body(buf, serialized_data, serialized_length); } else { msgpack_pack_nil(buf); } if (serialized_data) { efree(serialized_data); } return; } #endif if (ce && ce != PHP_IC_ENTRY && zend_hash_exists(&ce->function_table, "__sleep", sizeof("__sleep"))) { INIT_PZVAL(&fname); ZVAL_STRINGL(&fname, "__sleep", sizeof("__sleep") - 1, 0); res = call_user_function_ex(CG(function_table), &val, &fname, &retval_ptr, 0, 0, 1, NULL TSRMLS_CC); if (res == SUCCESS && !EG(exception)) { if (retval_ptr) { if (HASH_OF(retval_ptr)) { msgpack_serialize_class( buf, val, retval_ptr, var_hash, class_name, name_len, incomplete_class TSRMLS_CC); } else { MSGPACK_NOTICE( "[msgpack] (%s) __sleep should return an array only " "containing the names of instance-variables " "to serialize", __FUNCTION__); msgpack_pack_nil(buf); } zval_ptr_dtor(&retval_ptr); } return; } } if (retval_ptr) { zval_ptr_dtor(&retval_ptr); } msgpack_serialize_array( buf, val, var_hash, 1, class_name, name_len, incomplete_class TSRMLS_CC); } void msgpack_serialize_zval( smart_str *buf, zval *val, HashTable *var_hash TSRMLS_DC) { ulong *var_already; if (MSGPACK_G(php_only) && var_hash && msgpack_var_add( var_hash, val, (void *)&var_already TSRMLS_CC) == FAILURE) { if (Z_ISREF_P(val)) { if (Z_TYPE_P(val) == IS_ARRAY) { msgpack_pack_map(buf, 2); msgpack_pack_nil(buf); msgpack_pack_long(buf, MSGPACK_SERIALIZE_TYPE_RECURSIVE); msgpack_pack_long(buf, 0); msgpack_pack_long(buf, *var_already); return; } else if (Z_TYPE_P(val) == IS_OBJECT) { msgpack_pack_map(buf, 2); msgpack_pack_nil(buf); msgpack_pack_long(buf, MSGPACK_SERIALIZE_TYPE_OBJECT_REFERENCE); msgpack_pack_long(buf, 0); msgpack_pack_long(buf, *var_already); return; } } else if (Z_TYPE_P(val) == IS_OBJECT) { msgpack_pack_map(buf, 2); msgpack_pack_nil(buf); msgpack_pack_long(buf, MSGPACK_SERIALIZE_TYPE_OBJECT); msgpack_pack_long(buf, 0); msgpack_pack_long(buf, *var_already); return; } } switch (Z_TYPE_P(val)) { case IS_NULL: msgpack_pack_nil(buf); break; case IS_BOOL: if (Z_BVAL_P(val)) { msgpack_pack_true(buf); } else { msgpack_pack_false(buf); } break; case IS_LONG: msgpack_pack_long(buf, Z_LVAL_P(val)); break; case IS_DOUBLE: { double dbl = Z_DVAL_P(val); msgpack_pack_double(buf, dbl); } break; case IS_STRING: msgpack_serialize_string( buf, Z_STRVAL_P(val), Z_STRLEN_P(val)); break; case IS_ARRAY: msgpack_serialize_array( buf, val, var_hash, 0, NULL, 0, 0 TSRMLS_CC); break; case IS_OBJECT: { PHP_CLASS_ATTRIBUTES; PHP_SET_CLASS_ATTRIBUTES(val); msgpack_serialize_object( buf, val, var_hash, class_name, name_len, incomplete_class TSRMLS_CC); PHP_CLEANUP_CLASS_ATTRIBUTES(); } break; default: MSGPACK_WARNING( "[msgpack] (%s) type is unsupported, encoded as null", __FUNCTION__); msgpack_pack_nil(buf); break; } return; } msgpack-0.5.5/msgpack_pack.h0000644000077100007710000000077012110565607015627 0ustar xinchenxinchen #ifndef MSGPACK_PACK_H #define MSGPACK_PACK_H #include "ext/standard/php_var.h" typedef HashTable* msgpack_serialize_data_t; enum msgpack_serialize_type { MSGPACK_SERIALIZE_TYPE_NONE = 0, MSGPACK_SERIALIZE_TYPE_REFERENCE = 1, MSGPACK_SERIALIZE_TYPE_RECURSIVE, MSGPACK_SERIALIZE_TYPE_CUSTOM_OBJECT, MSGPACK_SERIALIZE_TYPE_OBJECT, MSGPACK_SERIALIZE_TYPE_OBJECT_REFERENCE, }; void msgpack_serialize_zval( smart_str *buf, zval *val, HashTable *var_hash TSRMLS_DC); #endif msgpack-0.5.5/msgpack_unpack.c0000644000077100007710000004741112110565607016170 0ustar xinchenxinchen #include "php.h" #include "php_ini.h" #include "ext/standard/php_incomplete_class.h" #include "php_msgpack.h" #include "msgpack_pack.h" #include "msgpack_unpack.h" #include "msgpack_errors.h" #if (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION < 3) # define Z_ADDREF_PP(ppz) ZVAL_ADDREF(*(ppz)) # define Z_SET_ISREF_PP(ppz) (*(ppz))->is_ref = 1 # define Z_UNSET_ISREF_PP(ppz) (*(ppz))->is_ref = 0 #endif #define VAR_ENTRIES_MAX 1024 typedef struct { zval *data[VAR_ENTRIES_MAX]; long used_slots; void *next; } var_entries; #define MSGPACK_UNSERIALIZE_ALLOC_STACK(_unpack) \ if (_unpack->deps <= 0) { \ *obj = _unpack->retval; \ msgpack_stack_push(_unpack->var_hash, obj, 0); \ } else { \ ALLOC_INIT_ZVAL(*obj); \ msgpack_stack_push(_unpack->var_hash, obj, 1); \ } #define MSGPACK_UNSERIALIZE_ALLOC_VALUE(_unpack) \ if (_unpack->deps <= 0) { \ *obj = _unpack->retval; \ msgpack_var_push(_unpack->var_hash, obj); \ } else { \ ALLOC_INIT_ZVAL(*obj); \ msgpack_var_push(_unpack->var_hash, obj); \ } #define MSGPACK_UNSERIALIZE_FINISH_ITEM(_unpack, _count) \ msgpack_stack_pop(_unpack->var_hash, _count); \ _unpack->stack[_unpack->deps-1]--; \ if (_unpack->stack[_unpack->deps-1] == 0) { \ _unpack->deps--; \ } #define MSGPACK_UNSERIALIZE_FINISH_MAP_ITEM(_unpack, _key, _val) \ zval_ptr_dtor(&_key); \ zval_ptr_dtor(&_val); \ MSGPACK_UNSERIALIZE_FINISH_ITEM(_unpack, 2); inline static void msgpack_var_push( msgpack_unserialize_data_t *var_hashx, zval **rval) { var_entries *var_hash, *prev = NULL; if (!var_hashx) { return; } var_hash = var_hashx->first; while (var_hash && var_hash->used_slots == VAR_ENTRIES_MAX) { prev = var_hash; var_hash = var_hash->next; } if (!var_hash) { var_hash = emalloc(sizeof(var_entries)); var_hash->used_slots = 0; var_hash->next = 0; if (!var_hashx->first) { var_hashx->first = var_hash; } else { prev->next = var_hash; } } var_hash->data[var_hash->used_slots++] = *rval; } inline static int msgpack_var_access( msgpack_unserialize_data_t *var_hashx, long id, zval ***store) { var_entries *var_hash = var_hashx->first; while (id >= VAR_ENTRIES_MAX && var_hash && var_hash->used_slots == VAR_ENTRIES_MAX) { var_hash = var_hash->next; id -= VAR_ENTRIES_MAX; } if (!var_hash) { return !SUCCESS; } if (id < 0 || id >= var_hash->used_slots) { return !SUCCESS; } *store = &var_hash->data[id]; return SUCCESS; } inline static void msgpack_stack_push( msgpack_unserialize_data_t *var_hashx, zval **rval, zend_bool save) { var_entries *var_hash, *prev = NULL; if (!var_hashx) { return; } var_hash = var_hashx->first_dtor; while (var_hash && var_hash->used_slots == VAR_ENTRIES_MAX) { prev = var_hash; var_hash = var_hash->next; } if (!var_hash) { var_hash = emalloc(sizeof(var_entries)); var_hash->used_slots = 0; var_hash->next = 0; if (!var_hashx->first_dtor) { var_hashx->first_dtor = var_hash; } else { prev->next = var_hash; } } if (save) { var_hash->data[var_hash->used_slots++] = *rval; } else { var_hash->data[var_hash->used_slots++] = NULL; } } inline static void msgpack_stack_pop( msgpack_unserialize_data_t *var_hashx, long count) { long i; var_entries *var_hash = var_hashx->first_dtor; while (var_hash && var_hash->used_slots == VAR_ENTRIES_MAX) { var_hash = var_hash->next; } if (!var_hash || count <= 0) { return; } for (i = count; i > 0; i--) { var_hash->used_slots--; if (var_hash->used_slots < 0) { var_hash->used_slots = 0; var_hash->data[var_hash->used_slots] = NULL; break; } else { var_hash->data[var_hash->used_slots] = NULL; } } } inline static zend_class_entry* msgpack_unserialize_class( zval **container, char *class_name, size_t name_len) { zend_class_entry *ce, **pce; zend_bool incomplete_class = 0; zval *user_func, *retval_ptr, **args[1], *arg_func_name; TSRMLS_FETCH(); do { /* Try to find class directly */ if (zend_lookup_class(class_name, name_len, &pce TSRMLS_CC) == SUCCESS) { ce = *pce; break; } /* Check for unserialize callback */ if ((PG(unserialize_callback_func) == NULL) || (PG(unserialize_callback_func)[0] == '\0')) { incomplete_class = 1; ce = PHP_IC_ENTRY; break; } /* Call unserialize callback */ ALLOC_INIT_ZVAL(user_func); ZVAL_STRING(user_func, PG(unserialize_callback_func), 1); args[0] = &arg_func_name; ALLOC_INIT_ZVAL(arg_func_name); ZVAL_STRING(arg_func_name, class_name, 1); if (call_user_function_ex( CG(function_table), NULL, user_func, &retval_ptr, 1, args, 0, NULL TSRMLS_CC) != SUCCESS) { MSGPACK_WARNING("[msgpack] (%s) defined (%s) but not found", __FUNCTION__, class_name); incomplete_class = 1; ce = PHP_IC_ENTRY; zval_ptr_dtor(&user_func); zval_ptr_dtor(&arg_func_name); break; } if (retval_ptr) { zval_ptr_dtor(&retval_ptr); } /* The callback function may have defined the class */ if (zend_lookup_class(class_name, name_len, &pce TSRMLS_CC) == SUCCESS) { ce = *pce; } else { MSGPACK_WARNING("[msgpack] (%s) Function %s() hasn't defined " "the class it was called for", __FUNCTION__, class_name); incomplete_class = 1; ce = PHP_IC_ENTRY; } zval_ptr_dtor(&user_func); zval_ptr_dtor(&arg_func_name); } while(0); if (EG(exception)) { MSGPACK_WARNING("[msgpack] (%s) Exception error", __FUNCTION__); return NULL; } object_init_ex(*container, ce); /* store incomplete class name */ if (incomplete_class) { php_store_class_name(*container, class_name, name_len); } return ce; } void msgpack_serialize_var_init(msgpack_serialize_data_t *var_hash) { HashTable **var_hash_ptr = (HashTable **)var_hash; TSRMLS_FETCH(); if (MSGPACK_G(serialize).level) { *var_hash_ptr = MSGPACK_G(serialize).var_hash; } else { ALLOC_HASHTABLE(*var_hash_ptr); zend_hash_init(*var_hash_ptr, 10, NULL, NULL, 0); MSGPACK_G(serialize).var_hash = *var_hash_ptr; } ++MSGPACK_G(serialize).level; } void msgpack_serialize_var_destroy(msgpack_serialize_data_t *var_hash) { HashTable **var_hash_ptr = (HashTable **)var_hash; TSRMLS_FETCH(); --MSGPACK_G(serialize).level; if (!MSGPACK_G(serialize).level) { zend_hash_destroy(*var_hash_ptr); FREE_HASHTABLE(*var_hash_ptr); } } void msgpack_unserialize_var_init(msgpack_unserialize_data_t *var_hashx) { var_hashx->first = 0; var_hashx->first_dtor = 0; } void msgpack_unserialize_var_destroy( msgpack_unserialize_data_t *var_hashx, zend_bool err) { void *next; long i; var_entries *var_hash = var_hashx->first; while (var_hash) { if (err) { for (i = var_hash->used_slots - 1; i > 0; i--) { if (var_hash->data[i]) { zval_ptr_dtor(&var_hash->data[i]); } } } next = var_hash->next; efree(var_hash); var_hash = next; } var_hash = var_hashx->first_dtor; while (var_hash) { for (i = var_hash->used_slots - 1; i >= 0; i--) { if (var_hash->data[i]) { zval_ptr_dtor(&var_hash->data[i]); } } next = var_hash->next; efree(var_hash); var_hash = next; } } void msgpack_unserialize_init(msgpack_unserialize_data *unpack) { unpack->deps = 0; unpack->type = MSGPACK_SERIALIZE_TYPE_NONE; } int msgpack_unserialize_uint8( msgpack_unserialize_data *unpack, uint8_t data, zval **obj) { MSGPACK_UNSERIALIZE_ALLOC_STACK(unpack); ZVAL_LONG(*obj, data); return 0; } int msgpack_unserialize_uint16( msgpack_unserialize_data *unpack, uint16_t data, zval **obj) { MSGPACK_UNSERIALIZE_ALLOC_STACK(unpack); ZVAL_LONG(*obj, data); return 0; } int msgpack_unserialize_uint32( msgpack_unserialize_data *unpack, uint32_t data, zval **obj) { MSGPACK_UNSERIALIZE_ALLOC_STACK(unpack); ZVAL_LONG(*obj, data); return 0; } int msgpack_unserialize_uint64( msgpack_unserialize_data *unpack, uint64_t data, zval **obj) { MSGPACK_UNSERIALIZE_ALLOC_STACK(unpack); ZVAL_LONG(*obj, data); return 0; } int msgpack_unserialize_int8( msgpack_unserialize_data *unpack, int8_t data, zval **obj) { MSGPACK_UNSERIALIZE_ALLOC_STACK(unpack); ZVAL_LONG(*obj, data); return 0; } int msgpack_unserialize_int16( msgpack_unserialize_data *unpack, int16_t data, zval **obj) { MSGPACK_UNSERIALIZE_ALLOC_STACK(unpack); ZVAL_LONG(*obj, data); return 0; } int msgpack_unserialize_int32( msgpack_unserialize_data *unpack, int32_t data, zval **obj) { MSGPACK_UNSERIALIZE_ALLOC_STACK(unpack); ZVAL_LONG(*obj, data); return 0; } int msgpack_unserialize_int64( msgpack_unserialize_data *unpack, int64_t data, zval **obj) { MSGPACK_UNSERIALIZE_ALLOC_STACK(unpack); ZVAL_LONG(*obj, data); return 0; } int msgpack_unserialize_float( msgpack_unserialize_data *unpack, float data, zval **obj) { MSGPACK_UNSERIALIZE_ALLOC_STACK(unpack); ZVAL_DOUBLE(*obj, data); return 0; } int msgpack_unserialize_double( msgpack_unserialize_data *unpack, double data, zval **obj) { MSGPACK_UNSERIALIZE_ALLOC_STACK(unpack); ZVAL_DOUBLE(*obj, data); return 0; } int msgpack_unserialize_nil(msgpack_unserialize_data *unpack, zval **obj) { MSGPACK_UNSERIALIZE_ALLOC_STACK(unpack); ZVAL_NULL(*obj); return 0; } int msgpack_unserialize_true(msgpack_unserialize_data *unpack, zval **obj) { MSGPACK_UNSERIALIZE_ALLOC_STACK(unpack); ZVAL_BOOL(*obj, 1); return 0; } int msgpack_unserialize_false(msgpack_unserialize_data *unpack, zval **obj) { MSGPACK_UNSERIALIZE_ALLOC_STACK(unpack); ZVAL_BOOL(*obj, 0); return 0; } int msgpack_unserialize_raw( msgpack_unserialize_data *unpack, const char* base, const char* data, unsigned int len, zval **obj) { MSGPACK_UNSERIALIZE_ALLOC_STACK(unpack); if (len == 0) { ZVAL_STRINGL(*obj, "", 0, 1); } else { ZVAL_STRINGL(*obj, (char *)data, len, 1); } return 0; } int msgpack_unserialize_array( msgpack_unserialize_data *unpack, unsigned int count, zval **obj) { MSGPACK_UNSERIALIZE_ALLOC_VALUE(unpack); array_init(*obj); if (count) unpack->stack[unpack->deps++] = count; return 0; } int msgpack_unserialize_array_item( msgpack_unserialize_data *unpack, zval **container, zval *obj) { add_next_index_zval(*container, obj); MSGPACK_UNSERIALIZE_FINISH_ITEM(unpack, 1); return 0; } int msgpack_unserialize_map( msgpack_unserialize_data *unpack, unsigned int count, zval **obj) { TSRMLS_FETCH(); MSGPACK_UNSERIALIZE_ALLOC_VALUE(unpack); if (count) unpack->stack[unpack->deps++] = count; unpack->type = MSGPACK_SERIALIZE_TYPE_NONE; if (count == 0) { if (MSGPACK_G(php_only)) { object_init(*obj); } else { array_init(*obj); } } return 0; } int msgpack_unserialize_map_item( msgpack_unserialize_data *unpack, zval **container, zval *key, zval *val) { long deps; TSRMLS_FETCH(); if (MSGPACK_G(php_only)) { zend_class_entry *ce; if (Z_TYPE_P(key) == IS_NULL) { unpack->type = MSGPACK_SERIALIZE_TYPE_NONE; if (Z_TYPE_P(val) == IS_LONG) { switch (Z_LVAL_P(val)) { case MSGPACK_SERIALIZE_TYPE_REFERENCE: Z_SET_ISREF_PP(container); break; case MSGPACK_SERIALIZE_TYPE_RECURSIVE: unpack->type = MSGPACK_SERIALIZE_TYPE_RECURSIVE; break; case MSGPACK_SERIALIZE_TYPE_CUSTOM_OBJECT: unpack->type = MSGPACK_SERIALIZE_TYPE_CUSTOM_OBJECT; break; case MSGPACK_SERIALIZE_TYPE_OBJECT_REFERENCE: unpack->type = MSGPACK_SERIALIZE_TYPE_OBJECT_REFERENCE; break; case MSGPACK_SERIALIZE_TYPE_OBJECT: unpack->type = MSGPACK_SERIALIZE_TYPE_OBJECT; break; default: break; } } else if (Z_TYPE_P(val) == IS_STRING) { ce = msgpack_unserialize_class( container, Z_STRVAL_P(val), Z_STRLEN_P(val)); if (ce == NULL) { MSGPACK_UNSERIALIZE_FINISH_MAP_ITEM(unpack, key, val); return 0; } } MSGPACK_UNSERIALIZE_FINISH_MAP_ITEM(unpack, key, val); return 0; } else { switch (unpack->type) { case MSGPACK_SERIALIZE_TYPE_CUSTOM_OBJECT: unpack->type = MSGPACK_SERIALIZE_TYPE_NONE; ce = msgpack_unserialize_class( container, Z_STRVAL_P(key), Z_STRLEN_P(key)); if (ce == NULL) { MSGPACK_UNSERIALIZE_FINISH_MAP_ITEM(unpack, key, val); return 0; } #if (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION > 0) /* implementing Serializable */ if (ce->unserialize == NULL) { MSGPACK_WARNING( "[msgpack] (%s) Class %s has no unserializer", __FUNCTION__, ce->name); MSGPACK_UNSERIALIZE_FINISH_MAP_ITEM(unpack, key, val); return 0; } ce->unserialize( container, ce, (const unsigned char *)Z_STRVAL_P(val), Z_STRLEN_P(val) + 1, NULL TSRMLS_CC); #endif MSGPACK_UNSERIALIZE_FINISH_MAP_ITEM(unpack, key, val); return 0; case MSGPACK_SERIALIZE_TYPE_RECURSIVE: case MSGPACK_SERIALIZE_TYPE_OBJECT: case MSGPACK_SERIALIZE_TYPE_OBJECT_REFERENCE: { zval **rval; int type = unpack->type; unpack->type = MSGPACK_SERIALIZE_TYPE_NONE; if (msgpack_var_access( unpack->var_hash, Z_LVAL_P(val) - 1, &rval) != SUCCESS) { MSGPACK_WARNING( "[msgpack] (%s) Invalid references value: %ld", __FUNCTION__, Z_LVAL_P(val) - 1); MSGPACK_UNSERIALIZE_FINISH_MAP_ITEM(unpack, key, val); return 0; } if (container != NULL) { zval_ptr_dtor(container); } *container = *rval; Z_ADDREF_PP(container); if (type == MSGPACK_SERIALIZE_TYPE_OBJECT) { Z_UNSET_ISREF_PP(container); } else if (type == MSGPACK_SERIALIZE_TYPE_OBJECT_REFERENCE) { Z_SET_ISREF_PP(container); } MSGPACK_UNSERIALIZE_FINISH_MAP_ITEM(unpack, key, val); return 0; } } } } if (Z_TYPE_PP(container) != IS_ARRAY && Z_TYPE_PP(container) != IS_OBJECT) { array_init(*container); } switch (Z_TYPE_P(key)) { case IS_LONG: if (zend_hash_index_update( HASH_OF(*container), Z_LVAL_P(key), &val, sizeof(val), NULL) == FAILURE) { zval_ptr_dtor(&val); MSGPACK_WARNING( "[msgpack] (%s) illegal offset type, skip this decoding", __FUNCTION__); } zval_ptr_dtor(&key); break; case IS_STRING: if (zend_symtable_update( HASH_OF(*container), Z_STRVAL_P(key), Z_STRLEN_P(key) + 1, &val, sizeof(val), NULL) == FAILURE) { zval_ptr_dtor(&val); MSGPACK_WARNING( "[msgpack] (%s) illegal offset type, skip this decoding", __FUNCTION__); } zval_ptr_dtor(&key); break; default: MSGPACK_WARNING("[msgpack] (%s) illegal key type", __FUNCTION__); if (MSGPACK_G(illegal_key_insert)) { if (zend_hash_next_index_insert( HASH_OF(*container), &key, sizeof(key), NULL) == FAILURE) { zval_ptr_dtor(&val); } if (zend_hash_next_index_insert( HASH_OF(*container), &val, sizeof(val), NULL) == FAILURE) { zval_ptr_dtor(&val); } } else { convert_to_string(key); if (zend_symtable_update( HASH_OF(*container), Z_STRVAL_P(key), Z_STRLEN_P(key) + 1, &val, sizeof(val), NULL) == FAILURE) { zval_ptr_dtor(&val); } zval_ptr_dtor(&key); } break; } msgpack_stack_pop(unpack->var_hash, 2); deps = unpack->deps - 1; unpack->stack[deps]--; if (unpack->stack[deps] == 0) { unpack->deps--; /* wakeup */ if (MSGPACK_G(php_only) && Z_TYPE_PP(container) == IS_OBJECT && Z_OBJCE_PP(container) != PHP_IC_ENTRY && zend_hash_exists( &Z_OBJCE_PP(container)->function_table, "__wakeup", sizeof("__wakeup"))) { zval f, *h = NULL; INIT_PZVAL(&f); ZVAL_STRINGL(&f, "__wakeup", sizeof("__wakeup") - 1, 0); call_user_function_ex( CG(function_table), container, &f, &h, 0, 0, 1, NULL TSRMLS_CC); if (h) { zval_ptr_dtor(&h); } } } return 0; } msgpack-0.5.5/msgpack_unpack.h0000644000077100007710000001214112110565607016165 0ustar xinchenxinchen #ifndef MSGPACK_UNPACK_H #define MSGPACK_UNPACK_H #include "ext/standard/php_var.h" #define MSGPACK_EMBED_STACK_SIZE 1024 #include "msgpack/unpack_define.h" typedef enum { MSGPACK_UNPACK_SUCCESS = 2, MSGPACK_UNPACK_EXTRA_BYTES = 1, MSGPACK_UNPACK_CONTINUE = 0, MSGPACK_UNPACK_PARSE_ERROR = -1, } msgpack_unpack_return; typedef struct php_unserialize_data msgpack_unserialize_data_t; typedef struct { zval *retval; long deps; msgpack_unserialize_data_t *var_hash; long stack[MSGPACK_EMBED_STACK_SIZE]; int type; } msgpack_unserialize_data; void msgpack_unserialize_var_init(msgpack_unserialize_data_t *var_hashx); void msgpack_unserialize_var_destroy( msgpack_unserialize_data_t *var_hashx, zend_bool err); void msgpack_unserialize_init(msgpack_unserialize_data *unpack); int msgpack_unserialize_uint8( msgpack_unserialize_data *unpack, uint8_t data, zval **obj); int msgpack_unserialize_uint16( msgpack_unserialize_data *unpack, uint16_t data, zval **obj); int msgpack_unserialize_uint32( msgpack_unserialize_data *unpack, uint32_t data, zval **obj); int msgpack_unserialize_uint64( msgpack_unserialize_data *unpack, uint64_t data, zval **obj); int msgpack_unserialize_int8( msgpack_unserialize_data *unpack, int8_t data, zval **obj); int msgpack_unserialize_int16( msgpack_unserialize_data *unpack, int16_t data, zval **obj); int msgpack_unserialize_int32( msgpack_unserialize_data *unpack, int32_t data, zval **obj); int msgpack_unserialize_int64( msgpack_unserialize_data *unpack, int64_t data, zval **obj); int msgpack_unserialize_float( msgpack_unserialize_data *unpack, float data, zval **obj); int msgpack_unserialize_double( msgpack_unserialize_data *unpack, double data, zval **obj); int msgpack_unserialize_nil(msgpack_unserialize_data *unpack, zval **obj); int msgpack_unserialize_true(msgpack_unserialize_data *unpack, zval **obj); int msgpack_unserialize_false(msgpack_unserialize_data *unpack, zval **obj); int msgpack_unserialize_raw( msgpack_unserialize_data *unpack, const char* base, const char* data, unsigned int len, zval **obj); int msgpack_unserialize_array( msgpack_unserialize_data *unpack, unsigned int count, zval **obj); int msgpack_unserialize_array_item( msgpack_unserialize_data *unpack, zval **container, zval *obj); int msgpack_unserialize_map( msgpack_unserialize_data *unpack, unsigned int count, zval **obj); int msgpack_unserialize_map_item( msgpack_unserialize_data *unpack, zval **container, zval *key, zval *val); /* template functions */ #define msgpack_unpack_struct(name) struct template ## name #define msgpack_unpack_func(ret, name) ret template ## name #define msgpack_unpack_callback(name) template_callback ## name #define msgpack_unpack_object zval* #define unpack_user msgpack_unserialize_data #define msgpack_unpack_user msgpack_unserialize_data struct template_context; typedef struct template_context msgpack_unpack_t; static void template_init(msgpack_unpack_t* unpack); static msgpack_unpack_object template_data(msgpack_unpack_t* unpack); static int template_execute( msgpack_unpack_t* unpack, const char* data, size_t len, size_t* off); static inline msgpack_unpack_object template_callback_root(unpack_user* user) { msgpack_unserialize_init(user); return NULL; } #define template_callback_uint8(user, data, obj) \ msgpack_unserialize_uint8(user, data, obj) #define template_callback_uint16(user, data, obj) \ msgpack_unserialize_uint16(user, data, obj) #define template_callback_uint32(user, data, obj) \ msgpack_unserialize_uint32(user, data, obj) #define template_callback_uint64(user, data, obj) \ msgpack_unserialize_uint64(user, data, obj) #define template_callback_int8(user, data, obj) \ msgpack_unserialize_int8(user, data, obj) #define template_callback_int16(user, data, obj) \ msgpack_unserialize_int16(user, data, obj) #define template_callback_int32(user, data, obj) \ msgpack_unserialize_int32(user, data, obj) #define template_callback_int64(user, data, obj) \ msgpack_unserialize_int64(user, data, obj) #define template_callback_float(user, data, obj) \ msgpack_unserialize_float(user, data, obj) #define template_callback_double(user, data, obj) \ msgpack_unserialize_double(user, data, obj) #define template_callback_nil(user, obj) \ msgpack_unserialize_nil(user, obj) #define template_callback_true(user, obj) \ msgpack_unserialize_true(user, obj) #define template_callback_false(user, obj) \ msgpack_unserialize_false(user, obj) #define template_callback_raw(user, base, data, len, obj) \ msgpack_unserialize_raw(user, base, data, len, obj) #define template_callback_array(user, count, obj) \ msgpack_unserialize_array(user, count, obj) #define template_callback_array_item(user, container, obj) \ msgpack_unserialize_array_item(user, container, obj) #define template_callback_map(user, count, obj) \ msgpack_unserialize_map(user, count, obj) #define template_callback_map_item(user, container, key, val) \ msgpack_unserialize_map_item(user, container, key, val) #include "msgpack/unpack_template.h" #endif msgpack-0.5.5/php_msgpack.h0000644000077100007710000000215412110565607015476 0ustar xinchenxinchen#ifndef PHP_MSGPACK_H #define PHP_MSGPACK_H #include "ext/standard/php_smart_str.h" /* for smart_str */ #define MSGPACK_EXTENSION_VERSION "0.5.5" extern zend_module_entry msgpack_module_entry; #define phpext_msgpack_ptr &msgpack_module_entry #ifdef PHP_WIN32 # define PHP_MSGPACK_API __declspec(dllexport) #elif defined(__GNUC__) && __GNUC__ >= 4 # define PHP_MSGPACK_API __attribute__ ((visibility("default"))) #else # define PHP_MSGPACK_API #endif #ifdef ZTS #include "TSRM.h" #endif ZEND_BEGIN_MODULE_GLOBALS(msgpack) zend_bool error_display; zend_bool php_only; zend_bool illegal_key_insert; struct { void *var_hash; unsigned level; } serialize; ZEND_END_MODULE_GLOBALS(msgpack) ZEND_EXTERN_MODULE_GLOBALS(msgpack) #ifdef ZTS #define MSGPACK_G(v) TSRMG(msgpack_globals_id, zend_msgpack_globals *, v) #else #define MSGPACK_G(v) (msgpack_globals.v) #endif PHP_MSGPACK_API void php_msgpack_serialize( smart_str *buf, zval *val TSRMLS_DC); PHP_MSGPACK_API void php_msgpack_unserialize( zval *return_value, char *str, size_t str_len TSRMLS_DC); #endif /* PHP_MSGPACK_H */ msgpack-0.5.5/msgpack/pack_define.h0000644000077100007710000000152512110565607017060 0ustar xinchenxinchen/* * MessagePack unpacking routine template * * Copyright (C) 2008-2010 FURUHASHI Sadayuki * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef MSGPACK_PACK_DEFINE_H__ #define MSGPACK_PACK_DEFINE_H__ #include "msgpack/sysdep.h" #include #include #endif /* msgpack/pack_define.h */ msgpack-0.5.5/msgpack/pack_template.h0000644000077100007710000004302012110565607017435 0ustar xinchenxinchen/* * MessagePack packing routine template * * Copyright (C) 2008-2010 FURUHASHI Sadayuki * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #if defined(__LITTLE_ENDIAN__) #define TAKE8_8(d) ((uint8_t*)&d)[0] #define TAKE8_16(d) ((uint8_t*)&d)[0] #define TAKE8_32(d) ((uint8_t*)&d)[0] #define TAKE8_64(d) ((uint8_t*)&d)[0] #elif defined(__BIG_ENDIAN__) #define TAKE8_8(d) ((uint8_t*)&d)[0] #define TAKE8_16(d) ((uint8_t*)&d)[1] #define TAKE8_32(d) ((uint8_t*)&d)[3] #define TAKE8_64(d) ((uint8_t*)&d)[7] #endif #ifndef msgpack_pack_inline_func #error msgpack_pack_inline_func template is not defined #endif #ifndef msgpack_pack_user #error msgpack_pack_user type is not defined #endif #ifndef msgpack_pack_append_buffer #error msgpack_pack_append_buffer callback is not defined #endif /* * Integer */ #define msgpack_pack_real_uint8(x, d) \ do { \ if(d < (1<<7)) { \ /* fixnum */ \ msgpack_pack_append_buffer(x, &TAKE8_8(d), 1); \ } else { \ /* unsigned 8 */ \ unsigned char buf[2] = {0xcc, TAKE8_8(d)}; \ msgpack_pack_append_buffer(x, buf, 2); \ } \ } while(0) #define msgpack_pack_real_uint16(x, d) \ do { \ if(d < (1<<7)) { \ /* fixnum */ \ msgpack_pack_append_buffer(x, &TAKE8_16(d), 1); \ } else if(d < (1<<8)) { \ /* unsigned 8 */ \ unsigned char buf[2] = {0xcc, TAKE8_16(d)}; \ msgpack_pack_append_buffer(x, buf, 2); \ } else { \ /* unsigned 16 */ \ unsigned char buf[3]; \ buf[0] = 0xcd; _msgpack_store16(&buf[1], (uint16_t)d); \ msgpack_pack_append_buffer(x, buf, 3); \ } \ } while(0) #define msgpack_pack_real_uint32(x, d) \ do { \ if(d < (1<<8)) { \ if(d < (1<<7)) { \ /* fixnum */ \ msgpack_pack_append_buffer(x, &TAKE8_32(d), 1); \ } else { \ /* unsigned 8 */ \ unsigned char buf[2] = {0xcc, TAKE8_32(d)}; \ msgpack_pack_append_buffer(x, buf, 2); \ } \ } else { \ if(d < (1<<16)) { \ /* unsigned 16 */ \ unsigned char buf[3]; \ buf[0] = 0xcd; _msgpack_store16(&buf[1], (uint16_t)d); \ msgpack_pack_append_buffer(x, buf, 3); \ } else { \ /* unsigned 32 */ \ unsigned char buf[5]; \ buf[0] = 0xce; _msgpack_store32(&buf[1], (uint32_t)d); \ msgpack_pack_append_buffer(x, buf, 5); \ } \ } \ } while(0) #define msgpack_pack_real_uint64(x, d) \ do { \ if(d < (1ULL<<8)) { \ if(d < (1ULL<<7)) { \ /* fixnum */ \ msgpack_pack_append_buffer(x, &TAKE8_64(d), 1); \ } else { \ /* unsigned 8 */ \ unsigned char buf[2] = {0xcc, TAKE8_64(d)}; \ msgpack_pack_append_buffer(x, buf, 2); \ } \ } else { \ if(d < (1ULL<<16)) { \ /* unsigned 16 */ \ unsigned char buf[3]; \ buf[0] = 0xcd; _msgpack_store16(&buf[1], (uint16_t)d); \ msgpack_pack_append_buffer(x, buf, 3); \ } else if(d < (1ULL<<32)) { \ /* unsigned 32 */ \ unsigned char buf[5]; \ buf[0] = 0xce; _msgpack_store32(&buf[1], (uint32_t)d); \ msgpack_pack_append_buffer(x, buf, 5); \ } else { \ /* unsigned 64 */ \ unsigned char buf[9]; \ buf[0] = 0xcf; _msgpack_store64(&buf[1], d); \ msgpack_pack_append_buffer(x, buf, 9); \ } \ } \ } while(0) #define msgpack_pack_real_int8(x, d) \ do { \ if(d < -(1<<5)) { \ /* signed 8 */ \ unsigned char buf[2] = {0xd0, TAKE8_8(d)}; \ msgpack_pack_append_buffer(x, buf, 2); \ } else { \ /* fixnum */ \ msgpack_pack_append_buffer(x, &TAKE8_8(d), 1); \ } \ } while(0) #define msgpack_pack_real_int16(x, d) \ do { \ if(d < -(1<<5)) { \ if(d < -(1<<7)) { \ /* signed 16 */ \ unsigned char buf[3]; \ buf[0] = 0xd1; _msgpack_store16(&buf[1], (int16_t)d); \ msgpack_pack_append_buffer(x, buf, 3); \ } else { \ /* signed 8 */ \ unsigned char buf[2] = {0xd0, TAKE8_16(d)}; \ msgpack_pack_append_buffer(x, buf, 2); \ } \ } else if(d < (1<<7)) { \ /* fixnum */ \ msgpack_pack_append_buffer(x, &TAKE8_16(d), 1); \ } else { \ if(d < (1<<8)) { \ /* unsigned 8 */ \ unsigned char buf[2] = {0xcc, TAKE8_16(d)}; \ msgpack_pack_append_buffer(x, buf, 2); \ } else { \ /* unsigned 16 */ \ unsigned char buf[3]; \ buf[0] = 0xcd; _msgpack_store16(&buf[1], (uint16_t)d); \ msgpack_pack_append_buffer(x, buf, 3); \ } \ } \ } while(0) #define msgpack_pack_real_int32(x, d) \ do { \ if(d < -(1<<5)) { \ if(d < -(1<<15)) { \ /* signed 32 */ \ unsigned char buf[5]; \ buf[0] = 0xd2; _msgpack_store32(&buf[1], (int32_t)d); \ msgpack_pack_append_buffer(x, buf, 5); \ } else if(d < -(1<<7)) { \ /* signed 16 */ \ unsigned char buf[3]; \ buf[0] = 0xd1; _msgpack_store16(&buf[1], (int16_t)d); \ msgpack_pack_append_buffer(x, buf, 3); \ } else { \ /* signed 8 */ \ unsigned char buf[2] = {0xd0, TAKE8_32(d)}; \ msgpack_pack_append_buffer(x, buf, 2); \ } \ } else if(d < (1<<7)) { \ /* fixnum */ \ msgpack_pack_append_buffer(x, &TAKE8_32(d), 1); \ } else { \ if(d < (1<<8)) { \ /* unsigned 8 */ \ unsigned char buf[2] = {0xcc, TAKE8_32(d)}; \ msgpack_pack_append_buffer(x, buf, 2); \ } else if(d < (1<<16)) { \ /* unsigned 16 */ \ unsigned char buf[3]; \ buf[0] = 0xcd; _msgpack_store16(&buf[1], (uint16_t)d); \ msgpack_pack_append_buffer(x, buf, 3); \ } else { \ /* unsigned 32 */ \ unsigned char buf[5]; \ buf[0] = 0xce; _msgpack_store32(&buf[1], (uint32_t)d); \ msgpack_pack_append_buffer(x, buf, 5); \ } \ } \ } while(0) #define msgpack_pack_real_int64(x, d) \ do { \ if(d < -(1LL<<5)) { \ if(d < -(1LL<<15)) { \ if(d < -(1LL<<31)) { \ /* signed 64 */ \ unsigned char buf[9]; \ buf[0] = 0xd3; _msgpack_store64(&buf[1], d); \ msgpack_pack_append_buffer(x, buf, 9); \ } else { \ /* signed 32 */ \ unsigned char buf[5]; \ buf[0] = 0xd2; _msgpack_store32(&buf[1], (int32_t)d); \ msgpack_pack_append_buffer(x, buf, 5); \ } \ } else { \ if(d < -(1<<7)) { \ /* signed 16 */ \ unsigned char buf[3]; \ buf[0] = 0xd1; _msgpack_store16(&buf[1], (int16_t)d); \ msgpack_pack_append_buffer(x, buf, 3); \ } else { \ /* signed 8 */ \ unsigned char buf[2] = {0xd0, TAKE8_64(d)}; \ msgpack_pack_append_buffer(x, buf, 2); \ } \ } \ } else if(d < (1<<7)) { \ /* fixnum */ \ msgpack_pack_append_buffer(x, &TAKE8_64(d), 1); \ } else { \ if(d < (1LL<<16)) { \ if(d < (1<<8)) { \ /* unsigned 8 */ \ unsigned char buf[2] = {0xcc, TAKE8_64(d)}; \ msgpack_pack_append_buffer(x, buf, 2); \ } else { \ /* unsigned 16 */ \ unsigned char buf[3]; \ buf[0] = 0xcd; _msgpack_store16(&buf[1], (uint16_t)d); \ msgpack_pack_append_buffer(x, buf, 3); \ } \ } else { \ if(d < (1LL<<32)) { \ /* unsigned 32 */ \ unsigned char buf[5]; \ buf[0] = 0xce; _msgpack_store32(&buf[1], (uint32_t)d); \ msgpack_pack_append_buffer(x, buf, 5); \ } else { \ /* unsigned 64 */ \ unsigned char buf[9]; \ buf[0] = 0xcf; _msgpack_store64(&buf[1], d); \ msgpack_pack_append_buffer(x, buf, 9); \ } \ } \ } \ } while(0) #ifdef msgpack_pack_inline_func_fixint msgpack_pack_inline_func_fixint(_uint8)(msgpack_pack_user x, uint8_t d) { unsigned char buf[2] = {0xcc, TAKE8_8(d)}; msgpack_pack_append_buffer(x, buf, 2); } msgpack_pack_inline_func_fixint(_uint16)(msgpack_pack_user x, uint16_t d) { unsigned char buf[3]; buf[0] = 0xcd; _msgpack_store16(&buf[1], d); msgpack_pack_append_buffer(x, buf, 3); } msgpack_pack_inline_func_fixint(_uint32)(msgpack_pack_user x, uint32_t d) { unsigned char buf[5]; buf[0] = 0xce; _msgpack_store32(&buf[1], d); msgpack_pack_append_buffer(x, buf, 5); } msgpack_pack_inline_func_fixint(_uint64)(msgpack_pack_user x, uint64_t d) { unsigned char buf[9]; buf[0] = 0xcf; _msgpack_store64(&buf[1], d); msgpack_pack_append_buffer(x, buf, 9); } msgpack_pack_inline_func_fixint(_int8)(msgpack_pack_user x, int8_t d) { unsigned char buf[2] = {0xd0, TAKE8_8(d)}; msgpack_pack_append_buffer(x, buf, 2); } msgpack_pack_inline_func_fixint(_int16)(msgpack_pack_user x, int16_t d) { unsigned char buf[3]; buf[0] = 0xd1; _msgpack_store16(&buf[1], d); msgpack_pack_append_buffer(x, buf, 3); } msgpack_pack_inline_func_fixint(_int32)(msgpack_pack_user x, int32_t d) { unsigned char buf[5]; buf[0] = 0xd2; _msgpack_store32(&buf[1], d); msgpack_pack_append_buffer(x, buf, 5); } msgpack_pack_inline_func_fixint(_int64)(msgpack_pack_user x, int64_t d) { unsigned char buf[9]; buf[0] = 0xd3; _msgpack_store64(&buf[1], d); msgpack_pack_append_buffer(x, buf, 9); } #undef msgpack_pack_inline_func_fixint #endif msgpack_pack_inline_func(_uint8)(msgpack_pack_user x, uint8_t d) { msgpack_pack_real_uint8(x, d); } msgpack_pack_inline_func(_uint16)(msgpack_pack_user x, uint16_t d) { msgpack_pack_real_uint16(x, d); } msgpack_pack_inline_func(_uint32)(msgpack_pack_user x, uint32_t d) { msgpack_pack_real_uint32(x, d); } msgpack_pack_inline_func(_uint64)(msgpack_pack_user x, uint64_t d) { msgpack_pack_real_uint64(x, d); } msgpack_pack_inline_func(_int8)(msgpack_pack_user x, int8_t d) { msgpack_pack_real_int8(x, d); } msgpack_pack_inline_func(_int16)(msgpack_pack_user x, int16_t d) { msgpack_pack_real_int16(x, d); } msgpack_pack_inline_func(_int32)(msgpack_pack_user x, int32_t d) { msgpack_pack_real_int32(x, d); } msgpack_pack_inline_func(_int64)(msgpack_pack_user x, int64_t d) { msgpack_pack_real_int64(x, d); } #ifdef msgpack_pack_inline_func_cint msgpack_pack_inline_func_cint(_short)(msgpack_pack_user x, short d) { #if defined(SIZEOF_SHORT) #if SIZEOF_SHORT == 2 msgpack_pack_real_int16(x, d); #elif SIZEOF_SHORT == 4 msgpack_pack_real_int32(x, d); #else msgpack_pack_real_int64(x, d); #endif #elif defined(SHRT_MAX) #if SHRT_MAX == 0x7fff msgpack_pack_real_int16(x, d); #elif SHRT_MAX == 0x7fffffff msgpack_pack_real_int32(x, d); #else msgpack_pack_real_int64(x, d); #endif #else if(sizeof(short) == 2) { msgpack_pack_real_int16(x, d); } else if(sizeof(short) == 4) { msgpack_pack_real_int32(x, d); } else { msgpack_pack_real_int64(x, d); } #endif } msgpack_pack_inline_func_cint(_int)(msgpack_pack_user x, int d) { #if defined(SIZEOF_INT) #if SIZEOF_INT == 2 msgpack_pack_real_int16(x, d); #elif SIZEOF_INT == 4 msgpack_pack_real_int32(x, d); #else msgpack_pack_real_int64(x, d); #endif #elif defined(INT_MAX) #if INT_MAX == 0x7fff msgpack_pack_real_int16(x, d); #elif INT_MAX == 0x7fffffff msgpack_pack_real_int32(x, d); #else msgpack_pack_real_int64(x, d); #endif #else if(sizeof(int) == 2) { msgpack_pack_real_int16(x, d); } else if(sizeof(int) == 4) { msgpack_pack_real_int32(x, d); } else { msgpack_pack_real_int64(x, d); } #endif } msgpack_pack_inline_func_cint(_long)(msgpack_pack_user x, long d) { #if defined(SIZEOF_LONG) #if SIZEOF_LONG == 2 msgpack_pack_real_int16(x, d); #elif SIZEOF_LONG == 4 msgpack_pack_real_int32(x, d); #else msgpack_pack_real_int64(x, d); #endif #elif defined(LONG_MAX) #if LONG_MAX == 0x7fffL msgpack_pack_real_int16(x, d); #elif LONG_MAX == 0x7fffffffL msgpack_pack_real_int32(x, d); #else msgpack_pack_real_int64(x, d); #endif #else if(sizeof(long) == 2) { msgpack_pack_real_int16(x, d); } else if(sizeof(long) == 4) { msgpack_pack_real_int32(x, d); } else { msgpack_pack_real_int64(x, d); } #endif } msgpack_pack_inline_func_cint(_long_long)(msgpack_pack_user x, long long d) { #if defined(SIZEOF_LONG_LONG) #if SIZEOF_LONG_LONG == 2 msgpack_pack_real_int16(x, d); #elif SIZEOF_LONG_LONG == 4 msgpack_pack_real_int32(x, d); #else msgpack_pack_real_int64(x, d); #endif #elif defined(LLONG_MAX) #if LLONG_MAX == 0x7fffL msgpack_pack_real_int16(x, d); #elif LLONG_MAX == 0x7fffffffL msgpack_pack_real_int32(x, d); #else msgpack_pack_real_int64(x, d); #endif #else if(sizeof(long long) == 2) { msgpack_pack_real_int16(x, d); } else if(sizeof(long long) == 4) { msgpack_pack_real_int32(x, d); } else { msgpack_pack_real_int64(x, d); } #endif } msgpack_pack_inline_func_cint(_unsigned_short)(msgpack_pack_user x, unsigned short d) { #if defined(SIZEOF_SHORT) #if SIZEOF_SHORT == 2 msgpack_pack_real_uint16(x, d); #elif SIZEOF_SHORT == 4 msgpack_pack_real_uint32(x, d); #else msgpack_pack_real_uint64(x, d); #endif #elif defined(USHRT_MAX) #if USHRT_MAX == 0xffffU msgpack_pack_real_uint16(x, d); #elif USHRT_MAX == 0xffffffffU msgpack_pack_real_uint32(x, d); #else msgpack_pack_real_uint64(x, d); #endif #else if(sizeof(unsigned short) == 2) { msgpack_pack_real_uint16(x, d); } else if(sizeof(unsigned short) == 4) { msgpack_pack_real_uint32(x, d); } else { msgpack_pack_real_uint64(x, d); } #endif } msgpack_pack_inline_func_cint(_unsigned_int)(msgpack_pack_user x, unsigned int d) { #if defined(SIZEOF_INT) #if SIZEOF_INT == 2 msgpack_pack_real_uint16(x, d); #elif SIZEOF_INT == 4 msgpack_pack_real_uint32(x, d); #else msgpack_pack_real_uint64(x, d); #endif #elif defined(UINT_MAX) #if UINT_MAX == 0xffffU msgpack_pack_real_uint16(x, d); #elif UINT_MAX == 0xffffffffU msgpack_pack_real_uint32(x, d); #else msgpack_pack_real_uint64(x, d); #endif #else if(sizeof(unsigned int) == 2) { msgpack_pack_real_uint16(x, d); } else if(sizeof(unsigned int) == 4) { msgpack_pack_real_uint32(x, d); } else { msgpack_pack_real_uint64(x, d); } #endif } msgpack_pack_inline_func_cint(_unsigned_long)(msgpack_pack_user x, unsigned long d) { #if defined(SIZEOF_LONG) #if SIZEOF_LONG == 2 msgpack_pack_real_uint16(x, d); #elif SIZEOF_LONG == 4 msgpack_pack_real_uint32(x, d); #else msgpack_pack_real_uint64(x, d); #endif #elif defined(ULONG_MAX) #if ULONG_MAX == 0xffffUL msgpack_pack_real_uint16(x, d); #elif ULONG_MAX == 0xffffffffUL msgpack_pack_real_uint32(x, d); #else msgpack_pack_real_uint64(x, d); #endif #else if(sizeof(unsigned long) == 2) { msgpack_pack_real_uint16(x, d); } else if(sizeof(unsigned long) == 4) { msgpack_pack_real_uint32(x, d); } else { msgpack_pack_real_uint64(x, d); } #endif } msgpack_pack_inline_func_cint(_unsigned_long_long)(msgpack_pack_user x, unsigned long long d) { #if defined(SIZEOF_LONG_LONG) #if SIZEOF_LONG_LONG == 2 msgpack_pack_real_uint16(x, d); #elif SIZEOF_LONG_LONG == 4 msgpack_pack_real_uint32(x, d); #else msgpack_pack_real_uint64(x, d); #endif #elif defined(ULLONG_MAX) #if ULLONG_MAX == 0xffffUL msgpack_pack_real_uint16(x, d); #elif ULLONG_MAX == 0xffffffffUL msgpack_pack_real_uint32(x, d); #else msgpack_pack_real_uint64(x, d); #endif #else if(sizeof(unsigned long long) == 2) { msgpack_pack_real_uint16(x, d); } else if(sizeof(unsigned long long) == 4) { msgpack_pack_real_uint32(x, d); } else { msgpack_pack_real_uint64(x, d); } #endif } #undef msgpack_pack_inline_func_cint #endif /* * Float */ msgpack_pack_inline_func(_float)(msgpack_pack_user x, float d) { union { float f; uint32_t i; } mem; unsigned char buf[5]; mem.f = d; buf[0] = 0xca; _msgpack_store32(&buf[1], mem.i); msgpack_pack_append_buffer(x, buf, 5); } msgpack_pack_inline_func(_double)(msgpack_pack_user x, double d) { union { double f; uint64_t i; } mem; unsigned char buf[9]; mem.f = d; buf[0] = 0xcb; _msgpack_store64(&buf[1], mem.i); msgpack_pack_append_buffer(x, buf, 9); } /* * Nil */ msgpack_pack_inline_func(_nil)(msgpack_pack_user x) { static const unsigned char d = 0xc0; msgpack_pack_append_buffer(x, &d, 1); } /* * Boolean */ msgpack_pack_inline_func(_true)(msgpack_pack_user x) { static const unsigned char d = 0xc3; msgpack_pack_append_buffer(x, &d, 1); } msgpack_pack_inline_func(_false)(msgpack_pack_user x) { static const unsigned char d = 0xc2; msgpack_pack_append_buffer(x, &d, 1); } /* * Array */ msgpack_pack_inline_func(_array)(msgpack_pack_user x, unsigned int n) { if(n < 16) { unsigned char d = 0x90 | n; msgpack_pack_append_buffer(x, &d, 1); } else if(n < 65536) { unsigned char buf[3]; buf[0] = 0xdc; _msgpack_store16(&buf[1], (uint16_t)n); msgpack_pack_append_buffer(x, buf, 3); } else { unsigned char buf[5]; buf[0] = 0xdd; _msgpack_store32(&buf[1], (uint32_t)n); msgpack_pack_append_buffer(x, buf, 5); } } /* * Map */ msgpack_pack_inline_func(_map)(msgpack_pack_user x, unsigned int n) { if(n < 16) { unsigned char d = 0x80 | n; msgpack_pack_append_buffer(x, &TAKE8_8(d), 1); } else if(n < 65536) { unsigned char buf[3]; buf[0] = 0xde; _msgpack_store16(&buf[1], (uint16_t)n); msgpack_pack_append_buffer(x, buf, 3); } else { unsigned char buf[5]; buf[0] = 0xdf; _msgpack_store32(&buf[1], (uint32_t)n); msgpack_pack_append_buffer(x, buf, 5); } } /* * Raw */ msgpack_pack_inline_func(_raw)(msgpack_pack_user x, size_t l) { if(l < 32) { unsigned char d = 0xa0 | l; msgpack_pack_append_buffer(x, &TAKE8_8(d), 1); } else if(l < 65536) { unsigned char buf[3]; buf[0] = 0xda; _msgpack_store16(&buf[1], (uint16_t)l); msgpack_pack_append_buffer(x, buf, 3); } else { unsigned char buf[5]; buf[0] = 0xdb; _msgpack_store32(&buf[1], (uint32_t)l); msgpack_pack_append_buffer(x, buf, 5); } } msgpack_pack_inline_func(_raw_body)(msgpack_pack_user x, const void* b, size_t l) { msgpack_pack_append_buffer(x, (const unsigned char*)b, l); } #undef msgpack_pack_inline_func #undef msgpack_pack_user #undef msgpack_pack_append_buffer #undef TAKE8_8 #undef TAKE8_16 #undef TAKE8_32 #undef TAKE8_64 #undef msgpack_pack_real_uint8 #undef msgpack_pack_real_uint16 #undef msgpack_pack_real_uint32 #undef msgpack_pack_real_uint64 #undef msgpack_pack_real_int8 #undef msgpack_pack_real_int16 #undef msgpack_pack_real_int32 #undef msgpack_pack_real_int64 msgpack-0.5.5/msgpack/unpack_define.h0000644000077100007710000000427412110565607017427 0ustar xinchenxinchen/* * MessagePack unpacking routine template * * Copyright (C) 2008-2010 FURUHASHI Sadayuki * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef MSGPACK_UNPACK_DEFINE_H__ #define MSGPACK_UNPACK_DEFINE_H__ #include "msgpack/sysdep.h" #include #include #include #include #ifdef __cplusplus extern "C" { #endif #ifndef MSGPACK_EMBED_STACK_SIZE #define MSGPACK_EMBED_STACK_SIZE 32 #endif typedef enum { CS_HEADER = 0x00, // nil //CS_ = 0x01, //CS_ = 0x02, // false //CS_ = 0x03, // true //CS_ = 0x04, //CS_ = 0x05, //CS_ = 0x06, //CS_ = 0x07, //CS_ = 0x08, //CS_ = 0x09, CS_FLOAT = 0x0a, CS_DOUBLE = 0x0b, CS_UINT_8 = 0x0c, CS_UINT_16 = 0x0d, CS_UINT_32 = 0x0e, CS_UINT_64 = 0x0f, CS_INT_8 = 0x10, CS_INT_16 = 0x11, CS_INT_32 = 0x12, CS_INT_64 = 0x13, //CS_ = 0x14, //CS_ = 0x15, //CS_BIG_INT_16 = 0x16, //CS_BIG_INT_32 = 0x17, //CS_BIG_FLOAT_16 = 0x18, //CS_BIG_FLOAT_32 = 0x19, CS_RAW_16 = 0x1a, CS_RAW_32 = 0x1b, CS_ARRAY_16 = 0x1c, CS_ARRAY_32 = 0x1d, CS_MAP_16 = 0x1e, CS_MAP_32 = 0x1f, //ACS_BIG_INT_VALUE, //ACS_BIG_FLOAT_VALUE, ACS_RAW_VALUE, } msgpack_unpack_state; typedef enum { CT_ARRAY_ITEM, CT_MAP_KEY, CT_MAP_VALUE, } msgpack_container_type; #ifdef __cplusplus } #endif #endif /* msgpack/unpack_define.h */ msgpack-0.5.5/msgpack/unpack_template.h0000644000077100007710000002576712110565607020022 0ustar xinchenxinchen/* * MessagePack unpacking routine template * * Copyright (C) 2008-2010 FURUHASHI Sadayuki * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef msgpack_unpack_func #error msgpack_unpack_func template is not defined #endif #ifndef msgpack_unpack_callback #error msgpack_unpack_callback template is not defined #endif #ifndef msgpack_unpack_struct #error msgpack_unpack_struct template is not defined #endif #ifndef msgpack_unpack_struct_decl #define msgpack_unpack_struct_decl(name) msgpack_unpack_struct(name) #endif #ifndef msgpack_unpack_object #error msgpack_unpack_object type is not defined #endif #ifndef msgpack_unpack_user #error msgpack_unpack_user type is not defined #endif #ifndef USE_CASE_RANGE #if !defined(_MSC_VER) #define USE_CASE_RANGE #endif #endif msgpack_unpack_struct_decl(_stack) { msgpack_unpack_object obj; size_t count; unsigned int ct; msgpack_unpack_object map_key; }; msgpack_unpack_struct_decl(_context) { msgpack_unpack_user user; unsigned int cs; unsigned int trail; unsigned int top; /* msgpack_unpack_struct(_stack)* stack; unsigned int stack_size; msgpack_unpack_struct(_stack) embed_stack[MSGPACK_EMBED_STACK_SIZE]; */ msgpack_unpack_struct(_stack) stack[MSGPACK_EMBED_STACK_SIZE]; }; msgpack_unpack_func(void, _init)(msgpack_unpack_struct(_context)* ctx) { ctx->cs = CS_HEADER; ctx->trail = 0; ctx->top = 0; /* ctx->stack = ctx->embed_stack; ctx->stack_size = MSGPACK_EMBED_STACK_SIZE; */ ctx->stack[0].obj = msgpack_unpack_callback(_root)(&ctx->user); } /* msgpack_unpack_func(void, _destroy)(msgpack_unpack_struct(_context)* ctx) { if(ctx->stack_size != MSGPACK_EMBED_STACK_SIZE) { free(ctx->stack); } } */ msgpack_unpack_func(msgpack_unpack_object, _data)(msgpack_unpack_struct(_context)* ctx) { return (ctx)->stack[0].obj; } msgpack_unpack_func(int, _execute)(msgpack_unpack_struct(_context)* ctx, const char* data, size_t len, size_t* off) { #ifndef _MSC_VER assert(len >= *off); #endif const unsigned char* p = (unsigned char*)data + *off; const unsigned char* const pe = (unsigned char*)data + len; const void* n = NULL; unsigned int trail = ctx->trail; unsigned int cs = ctx->cs; unsigned int top = ctx->top; int ret; msgpack_unpack_struct(_stack)* stack = ctx->stack; /* unsigned int stack_size = ctx->stack_size; */ msgpack_unpack_user* user = &ctx->user; msgpack_unpack_object obj; msgpack_unpack_struct(_stack)* c = NULL; #define push_simple_value(func) \ if(msgpack_unpack_callback(func)(user, &obj) < 0) { goto _failed; } \ goto _push #define push_fixed_value(func, arg) \ if(msgpack_unpack_callback(func)(user, arg, &obj) < 0) { goto _failed; } \ goto _push #define push_variable_value(func, base, pos, len) \ if(msgpack_unpack_callback(func)(user, \ (const char*)base, (const char*)pos, len, &obj) < 0) { goto _failed; } \ goto _push #define again_fixed_trail(_cs, trail_len) \ trail = trail_len; \ cs = _cs; \ goto _fixed_trail_again #define again_fixed_trail_if_zero(_cs, trail_len, ifzero) \ trail = trail_len; \ if(trail == 0) { goto ifzero; } \ cs = _cs; \ goto _fixed_trail_again #define start_container(func, count_, ct_) \ if(top >= MSGPACK_EMBED_STACK_SIZE) { goto _failed; } /* FIXME */ \ if(msgpack_unpack_callback(func)(user, count_, &stack[top].obj) < 0) { goto _failed; } \ if((count_) == 0) { obj = stack[top].obj; goto _push; } \ stack[top].ct = ct_; \ stack[top].count = count_; \ ++top; \ /*printf("container %d count %d stack %d\n",stack[top].obj,count_,top);*/ \ /*printf("stack push %d\n", top);*/ \ /* FIXME \ if(top >= stack_size) { \ if(stack_size == MSGPACK_EMBED_STACK_SIZE) { \ size_t csize = sizeof(msgpack_unpack_struct(_stack)) * MSGPACK_EMBED_STACK_SIZE; \ size_t nsize = csize * 2; \ msgpack_unpack_struct(_stack)* tmp = (msgpack_unpack_struct(_stack)*)malloc(nsize); \ if(tmp == NULL) { goto _failed; } \ memcpy(tmp, ctx->stack, csize); \ ctx->stack = stack = tmp; \ ctx->stack_size = stack_size = MSGPACK_EMBED_STACK_SIZE * 2; \ } else { \ size_t nsize = sizeof(msgpack_unpack_struct(_stack)) * ctx->stack_size * 2; \ msgpack_unpack_struct(_stack)* tmp = (msgpack_unpack_struct(_stack)*)realloc(ctx->stack, nsize); \ if(tmp == NULL) { goto _failed; } \ ctx->stack = stack = tmp; \ ctx->stack_size = stack_size = stack_size * 2; \ } \ } \ */ \ goto _header_again #define NEXT_CS(p) \ ((unsigned int)*p & 0x1f) #ifdef USE_CASE_RANGE #define SWITCH_RANGE_BEGIN switch(*p) { #define SWITCH_RANGE(FROM, TO) case FROM ... TO: #define SWITCH_RANGE_DEFAULT default: #define SWITCH_RANGE_END } #else #define SWITCH_RANGE_BEGIN { if(0) { #define SWITCH_RANGE(FROM, TO) } else if(FROM <= *p && *p <= TO) { #define SWITCH_RANGE_DEFAULT } else { #define SWITCH_RANGE_END } } #endif if(p == pe) { goto _out; } do { switch(cs) { case CS_HEADER: SWITCH_RANGE_BEGIN SWITCH_RANGE(0x00, 0x7f) // Positive Fixnum push_fixed_value(_uint8, *(uint8_t*)p); SWITCH_RANGE(0xe0, 0xff) // Negative Fixnum push_fixed_value(_int8, *(int8_t*)p); SWITCH_RANGE(0xc0, 0xdf) // Variable switch(*p) { case 0xc0: // nil push_simple_value(_nil); //case 0xc1: // string // again_terminal_trail(NEXT_CS(p), p+1); case 0xc2: // false push_simple_value(_false); case 0xc3: // true push_simple_value(_true); //case 0xc4: //case 0xc5: //case 0xc6: //case 0xc7: //case 0xc8: //case 0xc9: case 0xca: // float case 0xcb: // double case 0xcc: // unsigned int 8 case 0xcd: // unsigned int 16 case 0xce: // unsigned int 32 case 0xcf: // unsigned int 64 case 0xd0: // signed int 8 case 0xd1: // signed int 16 case 0xd2: // signed int 32 case 0xd3: // signed int 64 again_fixed_trail(NEXT_CS(p), 1 << (((unsigned int)*p) & 0x03)); //case 0xd4: //case 0xd5: //case 0xd6: // big integer 16 //case 0xd7: // big integer 32 //case 0xd8: // big float 16 //case 0xd9: // big float 32 case 0xda: // raw 16 case 0xdb: // raw 32 case 0xdc: // array 16 case 0xdd: // array 32 case 0xde: // map 16 case 0xdf: // map 32 again_fixed_trail(NEXT_CS(p), 2 << (((unsigned int)*p) & 0x01)); default: goto _failed; } SWITCH_RANGE(0xa0, 0xbf) // FixRaw again_fixed_trail_if_zero(ACS_RAW_VALUE, ((unsigned int)*p & 0x1f), _raw_zero); SWITCH_RANGE(0x90, 0x9f) // FixArray start_container(_array, ((unsigned int)*p) & 0x0f, CT_ARRAY_ITEM); SWITCH_RANGE(0x80, 0x8f) // FixMap start_container(_map, ((unsigned int)*p) & 0x0f, CT_MAP_KEY); SWITCH_RANGE_DEFAULT goto _failed; SWITCH_RANGE_END // end CS_HEADER _fixed_trail_again: ++p; default: if((size_t)(pe - p) < trail) { goto _out; } n = p; p += trail - 1; switch(cs) { //case CS_ //case CS_ case CS_FLOAT: { union { uint32_t i; float f; } mem; mem.i = _msgpack_load32(uint32_t,n); push_fixed_value(_float, mem.f); } case CS_DOUBLE: { union { uint64_t i; double f; } mem; mem.i = _msgpack_load64(uint64_t,n); push_fixed_value(_double, mem.f); } case CS_UINT_8: push_fixed_value(_uint8, *(uint8_t*)n); case CS_UINT_16: push_fixed_value(_uint16, _msgpack_load16(uint16_t,n)); case CS_UINT_32: push_fixed_value(_uint32, _msgpack_load32(uint32_t,n)); case CS_UINT_64: push_fixed_value(_uint64, _msgpack_load64(uint64_t,n)); case CS_INT_8: push_fixed_value(_int8, *(int8_t*)n); case CS_INT_16: push_fixed_value(_int16, _msgpack_load16(int16_t,n)); case CS_INT_32: push_fixed_value(_int32, _msgpack_load32(int32_t,n)); case CS_INT_64: push_fixed_value(_int64, _msgpack_load64(int64_t,n)); //case CS_ //case CS_ //case CS_BIG_INT_16: // again_fixed_trail_if_zero(ACS_BIG_INT_VALUE, _msgpack_load16(uint16_t,n), _big_int_zero); //case CS_BIG_INT_32: // again_fixed_trail_if_zero(ACS_BIG_INT_VALUE, _msgpack_load32(uint32_t,n), _big_int_zero); //case ACS_BIG_INT_VALUE: //_big_int_zero: // // FIXME // push_variable_value(_big_int, data, n, trail); //case CS_BIG_FLOAT_16: // again_fixed_trail_if_zero(ACS_BIG_FLOAT_VALUE, _msgpack_load16(uint16_t,n), _big_float_zero); //case CS_BIG_FLOAT_32: // again_fixed_trail_if_zero(ACS_BIG_FLOAT_VALUE, _msgpack_load32(uint32_t,n), _big_float_zero); //case ACS_BIG_FLOAT_VALUE: //_big_float_zero: // // FIXME // push_variable_value(_big_float, data, n, trail); case CS_RAW_16: again_fixed_trail_if_zero(ACS_RAW_VALUE, _msgpack_load16(uint16_t,n), _raw_zero); case CS_RAW_32: again_fixed_trail_if_zero(ACS_RAW_VALUE, _msgpack_load32(uint32_t,n), _raw_zero); case ACS_RAW_VALUE: _raw_zero: push_variable_value(_raw, data, n, trail); case CS_ARRAY_16: start_container(_array, _msgpack_load16(uint16_t,n), CT_ARRAY_ITEM); case CS_ARRAY_32: /* FIXME security guard */ start_container(_array, _msgpack_load32(uint32_t,n), CT_ARRAY_ITEM); case CS_MAP_16: start_container(_map, _msgpack_load16(uint16_t,n), CT_MAP_KEY); case CS_MAP_32: /* FIXME security guard */ start_container(_map, _msgpack_load32(uint32_t,n), CT_MAP_KEY); default: goto _failed; } } _push: if(top == 0) { goto _finish; } c = &stack[top-1]; switch(c->ct) { case CT_ARRAY_ITEM: if(msgpack_unpack_callback(_array_item)(user, &c->obj, obj) < 0) { goto _failed; } if(--c->count == 0) { obj = c->obj; --top; /*printf("stack pop %d\n", top);*/ goto _push; } goto _header_again; case CT_MAP_KEY: c->map_key = obj; c->ct = CT_MAP_VALUE; goto _header_again; case CT_MAP_VALUE: if(msgpack_unpack_callback(_map_item)(user, &c->obj, c->map_key, obj) < 0) { goto _failed; } if(--c->count == 0) { obj = c->obj; --top; /*printf("stack pop %d\n", top);*/ goto _push; } c->ct = CT_MAP_KEY; goto _header_again; default: goto _failed; } _header_again: cs = CS_HEADER; ++p; } while(p != pe); goto _out; _finish: stack[0].obj = obj; ++p; ret = 1; /*printf("-- finish --\n"); */ goto _end; _failed: /*printf("** FAILED **\n"); */ ret = -1; goto _end; _out: ret = 0; goto _end; _end: ctx->cs = cs; ctx->trail = trail; ctx->top = top; *off = p - (const unsigned char*)data; return ret; } #undef msgpack_unpack_func #undef msgpack_unpack_callback #undef msgpack_unpack_struct #undef msgpack_unpack_object #undef msgpack_unpack_user #undef push_simple_value #undef push_fixed_value #undef push_variable_value #undef again_fixed_trail #undef again_fixed_trail_if_zero #undef start_container #undef NEXT_CS msgpack-0.5.5/msgpack/sysdep.h0000644000077100007710000000665412110565607016147 0ustar xinchenxinchen/* * MessagePack system dependencies * * Copyright (C) 2008-2010 FURUHASHI Sadayuki * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef MSGPACK_SYSDEP_H__ #define MSGPACK_SYSDEP_H__ #include #include #if defined(_MSC_VER) && _MSC_VER < 1600 typedef __int8 int8_t; typedef unsigned __int8 uint8_t; typedef __int16 int16_t; typedef unsigned __int16 uint16_t; typedef __int32 int32_t; typedef unsigned __int32 uint32_t; typedef __int64 int64_t; typedef unsigned __int64 uint64_t; #elif defined(_MSC_VER) // && _MSC_VER >= 1600 #include #else #include #include #endif #ifdef _WIN32 typedef long _msgpack_atomic_counter_t; #define _msgpack_sync_decr_and_fetch(ptr) InterlockedDecrement(ptr) #define _msgpack_sync_incr_and_fetch(ptr) InterlockedIncrement(ptr) #else typedef unsigned int _msgpack_atomic_counter_t; #define _msgpack_sync_decr_and_fetch(ptr) __sync_sub_and_fetch(ptr, 1) #define _msgpack_sync_incr_and_fetch(ptr) __sync_add_and_fetch(ptr, 1) #endif #ifdef _WIN32 #include #ifdef __cplusplus /* numeric_limits::min,max */ #ifdef max #undef max #endif #ifdef min #undef min #endif #endif #else #include /* __BYTE_ORDER */ #endif #if !defined(__LITTLE_ENDIAN__) && !defined(__BIG_ENDIAN__) #if __BYTE_ORDER == __LITTLE_ENDIAN #define __LITTLE_ENDIAN__ #elif __BYTE_ORDER == __BIG_ENDIAN #define __BIG_ENDIAN__ #endif #endif #ifdef __LITTLE_ENDIAN__ #define _msgpack_be16(x) ntohs(x) #define _msgpack_be32(x) ntohl(x) #if defined(_byteswap_uint64) || _MSC_VER >= 1400 # define _msgpack_be64(x) (_byteswap_uint64(x)) #elif defined(bswap_64) # define _msgpack_be64(x) bswap_64(x) #elif defined(__DARWIN_OSSwapInt64) # define _msgpack_be64(x) __DARWIN_OSSwapInt64(x) #else #define _msgpack_be64(x) \ ( ((((uint64_t)x) << 56) & 0xff00000000000000ULL ) | \ ((((uint64_t)x) << 40) & 0x00ff000000000000ULL ) | \ ((((uint64_t)x) << 24) & 0x0000ff0000000000ULL ) | \ ((((uint64_t)x) << 8) & 0x000000ff00000000ULL ) | \ ((((uint64_t)x) >> 8) & 0x00000000ff000000ULL ) | \ ((((uint64_t)x) >> 24) & 0x0000000000ff0000ULL ) | \ ((((uint64_t)x) >> 40) & 0x000000000000ff00ULL ) | \ ((((uint64_t)x) >> 56) & 0x00000000000000ffULL ) ) #endif #else #define _msgpack_be16(x) (x) #define _msgpack_be32(x) (x) #define _msgpack_be64(x) (x) #endif #define _msgpack_store16(to, num) \ do { uint16_t val = _msgpack_be16(num); memcpy(to, &val, 2); } while(0); #define _msgpack_store32(to, num) \ do { uint32_t val = _msgpack_be32(num); memcpy(to, &val, 4); } while(0); #define _msgpack_store64(to, num) \ do { uint64_t val = _msgpack_be64(num); memcpy(to, &val, 8); } while(0); #define _msgpack_load16(cast, from) ((cast)_msgpack_be16(*(uint16_t*)from)) #define _msgpack_load32(cast, from) ((cast)_msgpack_be32(*(uint32_t*)from)) #define _msgpack_load64(cast, from) ((cast)_msgpack_be64(*(uint64_t*)from)) #endif /* msgpack/sysdep.h */ msgpack-0.5.5/msgpack/version.h0000644000077100007710000000202112110565607016305 0ustar xinchenxinchen/* * MessagePack for C version information * * Copyright (C) 2008-2009 FURUHASHI Sadayuki * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef MSGPACK_VERSION_H__ #define MSGPACK_VERSION_H__ #ifdef __cplusplus extern "C" { #endif const char* msgpack_version(void); int msgpack_version_major(void); int msgpack_version_minor(void); #define MSGPACK_VERSION "0.5.4" #define MSGPACK_VERSION_MAJOR 0 #define MSGPACK_VERSION_MINOR 5 #ifdef __cplusplus } #endif #endif /* msgpack/version.h */