php: added unpack of class object converter

This commit is contained in:
advect 2011-01-16 17:35:10 +09:00
parent fe26df5355
commit 5debbd2be8
86 changed files with 14795 additions and 1451 deletions

View file

@ -28,7 +28,7 @@ array(0) {
}
OK
array(1, 2, 3)
83000101020203
93010203
array(3) {
[0]=>
int(1)
@ -39,7 +39,7 @@ array(3) {
}
OK
array(array(1, 2, 3), arr...
83008300010102020301830004010502060283000701080209
93930102039304050693070809
array(3) {
[0]=>
array(3) {

View file

@ -24,7 +24,7 @@ test('array("" => "empty")', array("" => "empty"));
?>
--EXPECT--
array("foo", "foo", "foo")
8300a3666f6f01a3666f6f02a3666f6f
93a3666f6fa3666f6fa3666f6f
array(3) {
[0]=>
string(3) "foo"

View file

@ -39,7 +39,7 @@ var_dump(msgpack_unserialize(msgpack_serialize($a)));
--EXPECT--
array($a, $a)
82008100a3666f6f018100a3666f6f
9291a3666f6f91a3666f6f
array(2) {
[0]=>
array(1) {
@ -54,7 +54,7 @@ array(2) {
}
OK
array(&$a, &$a)
820082c00100a3666f6f0182c0020002
9282c00100a3666f6f82c0020002
array(2) {
[0]=>
&array(1) {
@ -69,7 +69,7 @@ array(2) {
}
OK
cyclic
810082c0010082c0010082c0020002
9182c0010082c0010082c0020002
array(1) {
[0]=>
&array(1) {

View file

@ -39,7 +39,7 @@ var_dump(msgpack_unserialize(msgpack_serialize($a)));
--EXPECT--
array($a, $a)
82008100a3666f6f018100a3666f6f
9291a3666f6f91a3666f6f
array(2) {
[0]=>
array(1) {
@ -54,7 +54,7 @@ array(2) {
}
OK
array(&$a, &$a)
820082c00100a3666f6f0182c0020002
9282c00100a3666f6f82c0020002
array(2) {
[0]=>
&array(1) {
@ -69,7 +69,7 @@ array(2) {
}
OK
cyclic
810082c0010082c0010082c0020002
9182c0010082c0010082c0020002
array(1) {
[0]=>
&array(1) {

View file

@ -34,7 +34,7 @@ test('object', $o, false);
?>
--EXPECTF--
object
820083c0a34f626aa16101a162020183c0a34f626aa16103a16204
9283c0a34f626aa16101a1620283c0a34f626aa16103a16204
array(2) {
[0]=>
object(Obj)#%d (2) {

View file

@ -34,7 +34,7 @@ test('object', $a, false);
?>
--EXPECTF--
object
820084c001c0a34f626aa16101a162020182c0020002
9284c001c0a34f626aa16101a1620282c0050002
array(2) {
[0]=>
&object(Obj)#%d (2) {

View file

@ -113,7 +113,7 @@ object(Obj2)#%d (7) {
}
OK
objectrecarr
82c0a44f626a33aa004f626a33006f626a73840084c0a34f626aa16100a4002a006200a6004f626a0063040184c0a34f626aa16100a4002a006201a6004f626a0063040284c0a34f626aa16100a4002a006202a6004f626a0063040384c0a34f626aa16100a4002a006203a6004f626a006304
82c0a44f626a33aa004f626a33006f626a739484c0a34f626aa16100a4002a006200a6004f626a00630484c0a34f626aa16100a4002a006201a6004f626a00630484c0a34f626aa16100a4002a006202a6004f626a00630484c0a34f626aa16100a4002a006203a6004f626a006304
object(Obj3)#%d (1) {
[%r"?objs"?:("Obj3":)?private"?%r]=>
array(4) {
@ -157,7 +157,7 @@ object(Obj3)#%d (1) {
}
OK
objectselfrec
83c0a44f626a34a7004f626a34006164a9004f626a34006f626a82c0020001
83c0a44f626a34a7004f626a34006164a9004f626a34006f626a82c0040001
object(Obj4)#%d (2) {
[%r"?a"?:("Obj4":)?private"?%r]=>
int(100)

View file

@ -116,7 +116,7 @@ object(Obj2)#%d (7) {
}
OK
objectrecarr
82c0a44f626a33aa004f626a33006f626a73840084c0a34f626aa16100a4002a006200a6004f626a0063040184c0a34f626aa16100a4002a006201a6004f626a0063040284c0a34f626aa16100a4002a006202a6004f626a0063040384c0a34f626aa16100a4002a006203a6004f626a006304
82c0a44f626a33aa004f626a33006f626a739484c0a34f626aa16100a4002a006200a6004f626a00630484c0a34f626aa16100a4002a006201a6004f626a00630484c0a34f626aa16100a4002a006202a6004f626a00630484c0a34f626aa16100a4002a006203a6004f626a006304
object(Obj3)#%d (1) {
[%r"?objs"?:("Obj3":)?private"?%r]=>
array(4) {
@ -160,7 +160,7 @@ object(Obj3)#%d (1) {
}
OK
objectselfrec
83c0a44f626a34a7004f626a34006164a9004f626a34006f626a82c0020001
83c0a44f626a34a7004f626a34006164a9004f626a34006f626a82c0040001
object(Obj4)#%d (2) {
[%r"?a"?:("Obj4":)?private"?%r]=>
int(100)

View file

@ -111,7 +111,7 @@ object(Obj2)#%d (7) {
}
OK
objectrecarr
82c0a44f626a33aa004f626a33006f626a73840084c0a34f626aa16100a4002a006200a6004f626a0063040184c0a34f626aa16100a4002a006201a6004f626a0063040284c0a34f626aa16100a4002a006202a6004f626a0063040384c0a34f626aa16100a4002a006203a6004f626a006304
82c0a44f626a33aa004f626a33006f626a739484c0a34f626aa16100a4002a006200a6004f626a00630484c0a34f626aa16100a4002a006201a6004f626a00630484c0a34f626aa16100a4002a006202a6004f626a00630484c0a34f626aa16100a4002a006203a6004f626a006304
object(Obj3)#%d (1) {
["objs:private"]=>
array(4) {
@ -155,7 +155,7 @@ object(Obj3)#%d (1) {
}
OK
objectselfrec
83c0a44f626a34a7004f626a34006164a9004f626a34006f626a82c0020001
83c0a44f626a34a7004f626a34006164a9004f626a34006f626a82c0040001
object(Obj4)#%d (2) {
["a:private"]=>
int(100)

View file

@ -102,7 +102,7 @@ var_dump($_SESSION);
?>
--EXPECTF--
read
write: 84c001a36f6c6484c0a3466f6fa700466f6f00643184c0a3426172a2643182c0020002a70042617200643282c0020002a5002a00643382c0020002a5002a00643282c0020003a2643382c0020003a474657374a6666f6f626172a36e657784c0a3426172a2643184c0a3466f6fa700466f6f00643182c0020009a5002a00643282c0020009a2643382c0020009a70042617200643282c002000aa5002a00643382c002000a
write: 84c001a36f6c6484c0a3466f6fa700466f6f00643184c0a3426172a2643182c0040002a70042617200643282c0040002a5002a00643382c0040002a5002a00643282c0040003a2643382c0040003a474657374a6666f6f626172a36e657784c0a3426172a2643184c0a3466f6fa700466f6f00643182c0040009a5002a00643282c0040009a2643382c0040009a70042617200643282c004000aa5002a00643382c004000a
array(3) {
["old"]=>
object(Foo)#3 (3) {

View file

@ -105,7 +105,7 @@ var_dump($_SESSION);
?>
--EXPECTF--
read
write: 84c001a36f6c6484c0a3466f6fa700466f6f00643184c0a3426172a2643182c0020002a70042617200643282c0020002a5002a00643382c0020002a5002a00643282c0020003a2643382c0020003a474657374a6666f6f626172a36e657784c0a3426172a2643184c0a3466f6fa700466f6f00643182c0020009a5002a00643282c0020009a2643382c0020009a70042617200643282c002000aa5002a00643382c002000a
write: 84c001a36f6c6484c0a3466f6fa700466f6f00643184c0a3426172a2643182c0040002a70042617200643282c0040002a5002a00643382c0040002a5002a00643282c0040003a2643382c0040003a474657374a6666f6f626172a36e657784c0a3426172a2643184c0a3466f6fa700466f6f00643182c0040009a5002a00643282c0040009a2643382c0040009a70042617200643282c004000aa5002a00643382c004000a
array(3) {
["old"]=>
object(Foo)#3 (3) {

View file

@ -101,7 +101,7 @@ var_dump($_SESSION);
?>
--EXPECTF--
read
write: 83a36f6c6484c0a3466f6fa700466f6f00643184c0a3426172a2643182c0020002a70042617200643282c0020002a5002a00643382c0020002a5002a00643282c0020003a2643382c0020003a474657374a6666f6f626172a36e657784c0a3426172a2643184c0a3466f6fa700466f6f00643182c0020009a5002a00643282c0020009a2643382c0020009a70042617200643282c002000aa5002a00643382c002000a
write: 83a36f6c6484c0a3466f6fa700466f6f00643184c0a3426172a2643182c0040002a70042617200643282c0040002a5002a00643382c0040002a5002a00643282c0040003a2643382c0040003a474657374a6666f6f626172a36e657784c0a3426172a2643184c0a3466f6fa700466f6f00643182c0040009a5002a00643282c0040009a2643382c0040009a70042617200643282c004000aa5002a00643382c004000a
array(3) {
["old"]=>
object(Foo)#3 (3) {

View file

@ -100,7 +100,7 @@ var_dump($_SESSION);
?>
--EXPECTF--
read
write: 83a36f6c6484c0a3466f6fa700466f6f00643184c0a3426172a2643182c0020002a70042617200643282c0020002a5002a00643382c0020002a5002a00643282c0020003a2643382c0020003a474657374a6666f6f626172a36e657784c0a3426172a2643184c0a3466f6fa700466f6f00643182c0020009a5002a00643282c0020009a2643382c0020009a70042617200643282c002000aa5002a00643382c002000a
write: 83a36f6c6484c0a3466f6fa700466f6f00643184c0a3426172a2643182c0040002a70042617200643282c0040002a5002a00643382c0040002a5002a00643282c0040003a2643382c0040003a474657374a6666f6f626172a36e657784c0a3426172a2643184c0a3466f6fa700466f6f00643182c0040009a5002a00643282c0040009a2643382c0040009a70042617200643282c004000aa5002a00643382c004000a
array(3) {
["old"]=>
object(Foo)#3 (3) {

View file

@ -52,8 +52,8 @@ function test($type, $variable, $test = null) {
test('null', null);
test('boo:l true', true);
test('bool: true', false);
test('bool: true', true);
test('bool: false', false);
test('zero: 0', 0);
test('small: 1', 1);
@ -68,9 +68,9 @@ test('double: 123.456', 123.456);
test('empty: ""', "");
test('string: "foobar"', "foobar");
test('empty: array', array(), false);
test('empty: array(1, 2, 3)', array(1, 2, 3), false);
test('empty: array(array(1, 2, 3), arr...', array(array(1, 2, 3), array(4, 5, 6), array(7, 8, 9)), false);
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);

View file

@ -55,8 +55,8 @@ function test($type, $variable, $test = null) {
test('null', null);
test('boo:l true', true);
test('bool: true', false);
test('bool: true', true);
test('bool: false', false);
test('zero: 0', 0);
test('small: 1', 1);
@ -71,9 +71,9 @@ test('double: 123.456', 123.456);
test('empty: ""', "");
test('string: "foobar"', "foobar");
test('empty: array', array(), false);
test('empty: array(1, 2, 3)', array(1, 2, 3), false);
test('empty: array(array(1, 2, 3), arr...', array(array(1, 2, 3), array(4, 5, 6), array(7, 8, 9)), false);
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);

View file

@ -50,8 +50,8 @@ function test($type, $variable, $test = null) {
test('null', null);
test('boo:l true', true);
test('bool: true', false);
test('bool: true', true);
test('bool: false', false);
test('zero: 0', 0);
test('small: 1', 1);
@ -66,9 +66,9 @@ test('double: 123.456', 123.456);
test('empty: ""', "");
test('string: "foobar"', "foobar");
test('empty: array', array(), false);
test('empty: array(1, 2, 3)', array(1, 2, 3), false);
test('empty: array(array(1, 2, 3), arr...', array(array(1, 2, 3), array(4, 5, 6), array(7, 8, 9)), false);
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);

View file

@ -54,8 +54,8 @@ function test($type, $variable, $test = null) {
test('null', null);
test('boo:l true', true);
test('bool: true', false);
test('bool: true', true);
test('bool: false', false);
test('zero: 0', 0);
test('small: 1', 1);
@ -70,9 +70,9 @@ test('double: 123.456', 123.456);
test('empty: ""', "");
test('string: "foobar"', "foobar");
test('empty: array', array(), false);
test('empty: array(1, 2, 3)', array(1, 2, 3), false);
test('empty: array(array(1, 2, 3), arr...', array(array(1, 2, 3), array(4, 5, 6), array(7, 8, 9)), false);
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);

View file

@ -57,8 +57,8 @@ function test($type, $variable, $test = null) {
test('null', null);
test('boo:l true', true);
test('bool: true', false);
test('bool: true', true);
test('bool: false', false);
test('zero: 0', 0);
test('small: 1', 1);
@ -73,9 +73,9 @@ test('double: 123.456', 123.456);
test('empty: ""', "");
test('string: "foobar"', "foobar");
test('empty: array', array(), false);
test('empty: array(1, 2, 3)', array(1, 2, 3), false);
test('empty: array(array(1, 2, 3), arr...', array(array(1, 2, 3), array(4, 5, 6), array(7, 8, 9)), false);
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);

View file

@ -52,8 +52,8 @@ function test($type, $variable, $test = null) {
test('null', null);
test('boo:l true', true);
test('bool: true', false);
test('bool: true', true);
test('bool: false', false);
test('zero: 0', 0);
test('small: 1', 1);
@ -68,9 +68,9 @@ test('double: 123.456', 123.456);
test('empty: ""', "");
test('string: "foobar"', "foobar");
test('empty: array', array(), false);
test('empty: array(1, 2, 3)', array(1, 2, 3), false);
test('empty: array(array(1, 2, 3), arr...', array(array(1, 2, 3), array(4, 5, 6), array(7, 8, 9)), false);
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);

View file

@ -31,8 +31,8 @@ function test($type, $variable, $test = null) {
test('null', null);
test('boo:l true', true);
test('bool: true', false);
test('bool: true', true);
test('bool: false', false);
test('zero: 0', 0);
test('small: 1', 1);
@ -47,9 +47,9 @@ test('double: 123.456', 123.456);
test('empty: ""', "");
test('string: "foobar"', "foobar");
test('empty: array', array(), false);
test('empty: array(1, 2, 3)', array(1, 2, 3), false);
test('empty: array(array(1, 2, 3), arr...', array(array(1, 2, 3), array(4, 5, 6), array(7, 8, 9)), false);
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);

View file

@ -34,8 +34,8 @@ function test($type, $variable, $test = null) {
test('null', null);
test('boo:l true', true);
test('bool: true', false);
test('bool: true', true);
test('bool: false', false);
test('zero: 0', 0);
test('small: 1', 1);
@ -50,9 +50,9 @@ test('double: 123.456', 123.456);
test('empty: ""', "");
test('string: "foobar"', "foobar");
test('empty: array', array(), false);
test('empty: array(1, 2, 3)', array(1, 2, 3), false);
test('empty: array(array(1, 2, 3), arr...', array(array(1, 2, 3), array(4, 5, 6), array(7, 8, 9)), false);
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);

View file

@ -29,8 +29,8 @@ function test($type, $variable, $test = null) {
test('null', null);
test('boo:l true', true);
test('bool: true', false);
test('bool: true', true);
test('bool: false', false);
test('zero: 0', 0);
test('small: 1', 1);
@ -45,9 +45,9 @@ test('double: 123.456', 123.456);
test('empty: ""', "");
test('string: "foobar"', "foobar");
test('empty: array', array(), false);
test('empty: array(1, 2, 3)', array(1, 2, 3), false);
test('empty: array(array(1, 2, 3), arr...', array(array(1, 2, 3), array(4, 5, 6), array(7, 8, 9)), false);
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);

View file

@ -33,8 +33,8 @@ function test($type, $variable, $test = null) {
test('null', null);
test('boo:l true', true);
test('bool: true', false);
test('bool: true', true);
test('bool: false', false);
test('zero: 0', 0);
test('small: 1', 1);
@ -49,9 +49,9 @@ test('double: 123.456', 123.456);
test('empty: ""', "");
test('string: "foobar"', "foobar");
test('empty: array', array(), false);
test('empty: array(1, 2, 3)', array(1, 2, 3), false);
test('empty: array(array(1, 2, 3), arr...', array(array(1, 2, 3), array(4, 5, 6), array(7, 8, 9)), false);
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);

View file

@ -36,8 +36,8 @@ function test($type, $variable, $test = null) {
test('null', null);
test('boo:l true', true);
test('bool: true', false);
test('bool: true', true);
test('bool: false', false);
test('zero: 0', 0);
test('small: 1', 1);
@ -52,9 +52,9 @@ test('double: 123.456', 123.456);
test('empty: ""', "");
test('string: "foobar"', "foobar");
test('empty: array', array(), false);
test('empty: array(1, 2, 3)', array(1, 2, 3), false);
test('empty: array(array(1, 2, 3), arr...', array(array(1, 2, 3), array(4, 5, 6), array(7, 8, 9)), false);
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);

View file

@ -31,8 +31,8 @@ function test($type, $variable, $test = null) {
test('null', null);
test('boo:l true', true);
test('bool: true', false);
test('bool: true', true);
test('bool: false', false);
test('zero: 0', 0);
test('small: 1', 1);
@ -47,9 +47,9 @@ test('double: 123.456', 123.456);
test('empty: ""', "");
test('string: "foobar"', "foobar");
test('empty: array', array(), false);
test('empty: array(1, 2, 3)', array(1, 2, 3), false);
test('empty: array(array(1, 2, 3), arr...', array(array(1, 2, 3), array(4, 5, 6), array(7, 8, 9)), false);
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);

View file

@ -73,8 +73,8 @@ function test($type, $variable, $test = null) {
test('null', null);
test('boo:l true', true);
test('bool: true', false);
test('bool: true', true);
test('bool: false', false);
test('zero: 0', 0);
test('small: 1', 1);
@ -89,9 +89,9 @@ test('double: 123.456', 123.456);
test('empty: ""', "");
test('string: "foobar"', "foobar");
test('empty: array', array(), false);
test('empty: array(1, 2, 3)', array(1, 2, 3), false);
test('empty: array(array(1, 2, 3), arr...', array(array(1, 2, 3), array(4, 5, 6), array(7, 8, 9)), false);
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);

View file

@ -76,8 +76,8 @@ function test($type, $variable, $test = null) {
test('null', null);
test('boo:l true', true);
test('bool: true', false);
test('bool: true', true);
test('bool: false', false);
test('zero: 0', 0);
test('small: 1', 1);
@ -92,9 +92,9 @@ test('double: 123.456', 123.456);
test('empty: ""', "");
test('string: "foobar"', "foobar");
test('empty: array', array(), false);
test('empty: array(1, 2, 3)', array(1, 2, 3), false);
test('empty: array(array(1, 2, 3), arr...', array(array(1, 2, 3), array(4, 5, 6), array(7, 8, 9)), false);
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);

View file

@ -71,8 +71,8 @@ function test($type, $variable, $test = null) {
test('null', null);
test('boo:l true', true);
test('bool: true', false);
test('bool: true', true);
test('bool: false', false);
test('zero: 0', 0);
test('small: 1', 1);
@ -87,9 +87,9 @@ test('double: 123.456', 123.456);
test('empty: ""', "");
test('string: "foobar"', "foobar");
test('empty: array', array(), false);
test('empty: array(1, 2, 3)', array(1, 2, 3), false);
test('empty: array(array(1, 2, 3), arr...', array(array(1, 2, 3), array(4, 5, 6), array(7, 8, 9)), false);
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);

View file

@ -74,8 +74,8 @@ function test($type, $variable, $test = null) {
test('null', null);
test('boo:l true', true);
test('bool: true', false);
test('bool: true', true);
test('bool: false', false);
test('zero: 0', 0);
test('small: 1', 1);
@ -90,9 +90,9 @@ test('double: 123.456', 123.456);
test('empty: ""', "");
test('string: "foobar"', "foobar");
test('empty: array', array(), false);
test('empty: array(1, 2, 3)', array(1, 2, 3), false);
test('empty: array(array(1, 2, 3), arr...', array(array(1, 2, 3), array(4, 5, 6), array(7, 8, 9)), false);
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);

View file

@ -77,8 +77,8 @@ function test($type, $variable, $test = null) {
test('null', null);
test('boo:l true', true);
test('bool: true', false);
test('bool: true', true);
test('bool: false', false);
test('zero: 0', 0);
test('small: 1', 1);
@ -93,9 +93,9 @@ test('double: 123.456', 123.456);
test('empty: ""', "");
test('string: "foobar"', "foobar");
test('empty: array', array(), false);
test('empty: array(1, 2, 3)', array(1, 2, 3), false);
test('empty: array(array(1, 2, 3), arr...', array(array(1, 2, 3), array(4, 5, 6), array(7, 8, 9)), false);
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);

View file

@ -72,8 +72,8 @@ function test($type, $variable, $test = null) {
test('null', null);
test('boo:l true', true);
test('bool: true', false);
test('bool: true', true);
test('bool: false', false);
test('zero: 0', 0);
test('small: 1', 1);
@ -88,9 +88,9 @@ test('double: 123.456', 123.456);
test('empty: ""', "");
test('string: "foobar"', "foobar");
test('empty: array', array(), false);
test('empty: array(1, 2, 3)', array(1, 2, 3), false);
test('empty: array(array(1, 2, 3), arr...', array(array(1, 2, 3), array(4, 5, 6), array(7, 8, 9)), false);
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);

View file

@ -27,8 +27,8 @@ function test($type, $variable, $test = null) {
test('null', null);
test('boo:l true', true);
test('bool: true', false);
test('bool: true', true);
test('bool: false', false);
test('zero: 0', 0);
test('small: 1', 1);
@ -43,9 +43,9 @@ test('double: 123.456', 123.456);
test('empty: ""', "");
test('string: "foobar"', "foobar");
test('empty: array', array(), false);
test('empty: array(1, 2, 3)', array(1, 2, 3), false);
test('empty: array(array(1, 2, 3), arr...', array(array(1, 2, 3), array(4, 5, 6), array(7, 8, 9)), false);
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);

View file

@ -29,8 +29,8 @@ function test($type, $variable, $test = null) {
test('null', null);
test('boo:l true', true);
test('bool: true', false);
test('bool: true', true);
test('bool: false', false);
test('zero: 0', 0);
test('small: 1', 1);
@ -45,9 +45,9 @@ test('double: 123.456', 123.456);
test('empty: ""', "");
test('string: "foobar"', "foobar");
test('empty: array', array(), false);
test('empty: array(1, 2, 3)', array(1, 2, 3), false);
test('empty: array(array(1, 2, 3), arr...', array(array(1, 2, 3), array(4, 5, 6), array(7, 8, 9)), false);
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);

View file

@ -72,8 +72,8 @@ function test($type, $variable, $test = null)
test('null', null);
test('boo:l true', true);
test('bool: true', false);
test('bool: true', true);
test('bool: false', false);
test('zero: 0', 0);
test('small: 1', 1);
@ -88,9 +88,9 @@ test('double: 123.456', 123.456);
test('empty: ""', "");
test('string: "foobar"', "foobar");
test('empty: array', array(), false);
test('empty: array(1, 2, 3)', array(1, 2, 3), false);
test('empty: array(array(1, 2, 3), arr...', array(array(1, 2, 3), array(4, 5, 6), array(7, 8, 9)), false);
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);

View file

@ -73,8 +73,8 @@ function test($type, $variable, $test = null)
test('null', null);
test('boo:l true', true);
test('bool: true', false);
test('bool: true', true);
test('bool: false', false);
test('zero: 0', 0);
test('small: 1', 1);
@ -89,9 +89,9 @@ test('double: 123.456', 123.456);
test('empty: ""', "");
test('string: "foobar"', "foobar");
test('empty: array', array(), false);
test('empty: array(1, 2, 3)', array(1, 2, 3), false);
test('empty: array(array(1, 2, 3), arr...', array(array(1, 2, 3), array(4, 5, 6), array(7, 8, 9)), false);
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);

View file

@ -27,8 +27,8 @@ function test($type, $variable, $test = null) {
test('null', null);
test('boo:l true', true);
test('bool: true', false);
test('bool: true', true);
test('bool: false', false);
test('zero: 0', 0);
test('small: 1', 1);
@ -43,9 +43,9 @@ test('double: 123.456', 123.456);
test('empty: ""', "");
test('string: "foobar"', "foobar");
test('empty: array', array(), false);
test('empty: array(1, 2, 3)', array(1, 2, 3), false);
test('empty: array(array(1, 2, 3), arr...', array(array(1, 2, 3), array(4, 5, 6), array(7, 8, 9)), false);
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);

View file

@ -70,8 +70,8 @@ function test($type, $variable, $test = null)
test('null', null);
test('boo:l true', true);
test('bool: true', false);
test('bool: true', true);
test('bool: false', false);
test('zero: 0', 0);
test('small: 1', 1);
@ -86,9 +86,9 @@ test('double: 123.456', 123.456);
test('empty: ""', "");
test('string: "foobar"', "foobar");
test('empty: array', array(), false);
test('empty: array(1, 2, 3)', array(1, 2, 3), false);
test('empty: array(array(1, 2, 3), arr...', array(array(1, 2, 3), array(4, 5, 6), array(7, 8, 9)), false);
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);

View file

@ -71,8 +71,8 @@ function test($type, $variable, $test = null)
test('null', null);
test('boo:l true', true);
test('bool: true', false);
test('bool: true', true);
test('bool: false', false);
test('zero: 0', 0);
test('small: 1', 1);
@ -87,9 +87,9 @@ test('double: 123.456', 123.456);
test('empty: ""', "");
test('string: "foobar"', "foobar");
test('empty: array', array(), false);
test('empty: array(1, 2, 3)', array(1, 2, 3), false);
test('empty: array(array(1, 2, 3), arr...', array(array(1, 2, 3), array(4, 5, 6), array(7, 8, 9)), false);
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);

View file

@ -1,10 +1,6 @@
--TEST--
disabled php only for class methods (set option)
--SKIPIF--
<?php
if (version_compare(PHP_VERSION, '5.1.0') < 0) {
echo "skip tests in PHP 5.1 or newer";
}
--FILE--
<?php
if(!extension_loaded('msgpack')) {
@ -13,7 +9,14 @@ if(!extension_loaded('msgpack')) {
function test($type, $variable, $test = null) {
$msgpack = new MessagePack();
$msgpack->setOption(MessagePack::OPT_PHPONLY, false);
if (version_compare(PHP_VERSION, '5.1.0') < 0)
{
$msgpack->setOption(MESSAGEPACK_OPT_PHPONLY, false);
}
else
{
$msgpack->setOption(MessagePack::OPT_PHPONLY, false);
}
$serialized = $msgpack->pack($variable);
$unserialized = $msgpack->unpack($serialized);
@ -32,8 +35,8 @@ function test($type, $variable, $test = null) {
test('null', null);
test('boo:l true', true);
test('bool: true', false);
test('bool: true', true);
test('bool: false', false);
test('zero: 0', 0);
test('small: 1', 1);
@ -48,9 +51,9 @@ test('double: 123.456', 123.456);
test('empty: ""', "");
test('string: "foobar"', "foobar");
test('empty: array', array(), false);
test('empty: array(1, 2, 3)', array(1, 2, 3), false);
test('empty: array(array(1, 2, 3), arr...', array(array(1, 2, 3), array(4, 5, 6), array(7, 8, 9)), false);
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);

View file

@ -1,306 +0,0 @@
--TEST--
disabled php only for class methods (set option)
--SKIPIF--
<?php
if (version_compare(PHP_VERSION, '5.1.0') >= 0) {
echo "skip tests in PHP 5.0 or older";
}
--FILE--
<?php
if(!extension_loaded('msgpack')) {
dl('msgpack.' . PHP_SHLIB_SUFFIX);
}
function test($type, $variable, $test = null) {
$msgpack = new MessagePack();
$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('boo:l true', true);
test('bool: true', 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('empty: array', array(), false);
test('empty: array(1, 2, 3)', array(1, 2, 3), false);
test('empty: 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

View file

@ -1,10 +1,6 @@
--TEST--
disabled php only for class methods unpacker (set option)
--SKIPIF--
<?php
if (version_compare(PHP_VERSION, '5.1.0') < 0) {
echo "skip tests in PHP 5.1 or newer";
}
--FILE--
<?php
if(!extension_loaded('msgpack')) {
@ -14,7 +10,14 @@ if(!extension_loaded('msgpack')) {
function test($type, $variable, $test = null)
{
$msgpack = new MessagePack();
$msgpack->setOption(MessagePack::OPT_PHPONLY, false);
if (version_compare(PHP_VERSION, '5.1.0') < 0)
{
$msgpack->setOption(MESSAGEPACK_OPT_PHPONLY, false);
}
else
{
$msgpack->setOption(MessagePack::OPT_PHPONLY, false);
}
$serialized = $msgpack->pack($variable);
$unpacker = $msgpack->unpacker();
@ -75,8 +78,8 @@ function test($type, $variable, $test = null)
test('null', null);
test('boo:l true', true);
test('bool: true', false);
test('bool: true', true);
test('bool: false', false);
test('zero: 0', 0);
test('small: 1', 1);
@ -91,9 +94,9 @@ test('double: 123.456', 123.456);
test('empty: ""', "");
test('string: "foobar"', "foobar");
test('empty: array', array(), false);
test('empty: array(1, 2, 3)', array(1, 2, 3), false);
test('empty: array(array(1, 2, 3), arr...', array(array(1, 2, 3), array(4, 5, 6), array(7, 8, 9)), false);
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);

View file

@ -1,349 +0,0 @@
--TEST--
disabled php only for class methods unpacker (set option)
--SKIPIF--
<?php
if (version_compare(PHP_VERSION, '5.1.0') >= 0) {
echo "skip tests in PHP 5.1.0 or older";
}
--FILE--
<?php
if(!extension_loaded('msgpack')) {
dl('msgpack.' . PHP_SHLIB_SUFFIX);
}
function test($type, $variable, $test = null)
{
$msgpack = new MessagePack();
$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('boo:l true', true);
test('bool: true', 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('empty: array', array(), false);
test('empty: array(1, 2, 3)', array(1, 2, 3), false);
test('empty: 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

View file

@ -14,12 +14,26 @@ if(!extension_loaded('msgpack')) {
function test($type, $variable, $test = null)
{
$msgpack = new MessagePack();
$msgpack->setOption(MessagePack::OPT_PHPONLY, false);
if (version_compare(PHP_VERSION, '5.1.0') < 0)
{
$msgpack->setOption(MESSAGEPACK_OPT_PHPONLY, false);
}
else
{
$msgpack->setOption(MessagePack::OPT_PHPONLY, false);
}
$serialized = $msgpack->pack($variable);
$unpacker = new MessagePackUnpacker();
$unpacker->setOption(MessagePack::OPT_PHPONLY, false);
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);
@ -77,8 +91,8 @@ function test($type, $variable, $test = null)
test('null', null);
test('boo:l true', true);
test('bool: true', false);
test('bool: true', true);
test('bool: false', false);
test('zero: 0', 0);
test('small: 1', 1);
@ -93,9 +107,9 @@ test('double: 123.456', 123.456);
test('empty: ""', "");
test('string: "foobar"', "foobar");
test('empty: array', array(), false);
test('empty: array(1, 2, 3)', array(1, 2, 3), false);
test('empty: array(array(1, 2, 3), arr...', array(array(1, 2, 3), array(4, 5, 6), array(7, 8, 9)), false);
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);

View file

@ -1,351 +0,0 @@
--TEST--
disabled php only for class unpacker (set option)
--SKIPIF--
<?php
if (version_compare(PHP_VERSION, '5.1.0') >= 0) {
echo "skip tests in PHP 5.0 or older";
}
--FILE--
<?php
if(!extension_loaded('msgpack')) {
dl('msgpack.' . PHP_SHLIB_SUFFIX);
}
function test($type, $variable, $test = null)
{
$msgpack = new MessagePack();
$msgpack->setOption(MESSAGEPACK_OPT_PHPONLY, false);
$serialized = $msgpack->pack($variable);
$unpacker = new MessagePackUnpacker();
$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('boo:l true', true);
test('bool: true', 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('empty: array', array(), false);
test('empty: array(1, 2, 3)', array(1, 2, 3), false);
test('empty: 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

575
php/tests/090.phpt Normal file
View file

@ -0,0 +1,575 @@
--TEST--
unpack of object converter (string)
--SKIPIF--
<?php
if (version_compare(PHP_VERSION, '5.2.0') < 0) {
echo "skip tests in PHP 5.2 or newer";
}
--FILE--
<?php
if(!extension_loaded('msgpack'))
{
dl('msgpack.' . PHP_SHLIB_SUFFIX);
}
error_reporting(0);
function test($type, $variable, $object, $result = null)
{
$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));
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

563
php/tests/090b.phpt Normal file
View file

@ -0,0 +1,563 @@
--TEST--
unpack of object converter (string)
--SKIPIF--
<?php
if (version_compare(PHP_VERSION, '5.2.0') >= 0) {
echo "skip tests in PHP 5.1 or older";
}
--FILE--
<?php
if(!extension_loaded('msgpack'))
{
dl('msgpack.' . PHP_SHLIB_SUFFIX);
}
error_reporting(0);
function test($type, $variable, $object, $result = null)
{
$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));
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

577
php/tests/091.phpt Normal file
View file

@ -0,0 +1,577 @@
--TEST--
unpack of object converter (object)
--SKIPIF--
<?php
if (version_compare(PHP_VERSION, '5.2.0') < 0) {
echo "skip tests in PHP 5.2 or newer";
}
--FILE--
<?php
if(!extension_loaded('msgpack'))
{
dl('msgpack.' . PHP_SHLIB_SUFFIX);
}
error_reporting(0);
function test($type, $variable, $object, $result = null)
{
$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;
}
}
}
}
$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

563
php/tests/091b.phpt Normal file
View file

@ -0,0 +1,563 @@
--TEST--
unpack of object converter (object)
--SKIPIF--
<?php
if (version_compare(PHP_VERSION, '5.2.0') >= 0) {
echo "skip tests in PHP 5.1 or older";
}
--FILE--
<?php
if(!extension_loaded('msgpack'))
{
dl('msgpack.' . PHP_SHLIB_SUFFIX);
}
error_reporting(0);
function test($type, $variable, $object, $result = null)
{
$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, 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

442
php/tests/092.phpt Normal file
View file

@ -0,0 +1,442 @@
--TEST--
unpack of object converter (string: php_only=0)
--SKIPIF--
<?php
if (version_compare(PHP_VERSION, '5.2.0') < 0) {
echo "skip tests in PHP 5.2 or newer";
}
--FILE--
<?php
if(!extension_loaded('msgpack'))
{
dl('msgpack.' . PHP_SHLIB_SUFFIX);
}
error_reporting(0);
ini_set('msgpack.php_only', 0);
function test($type, $variable, $object, $result = null)
{
$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

430
php/tests/092b.phpt Normal file
View file

@ -0,0 +1,430 @@
--TEST--
unpack of object converter (string: php_only=0)
--SKIPIF--
<?php
if (version_compare(PHP_VERSION, '5.2.0') >= 0) {
echo "skip tests in PHP 5.1 or older";
}
--FILE--
<?php
if(!extension_loaded('msgpack'))
{
dl('msgpack.' . PHP_SHLIB_SUFFIX);
}
error_reporting(0);
ini_set('msgpack.php_only', 0);
function test($type, $variable, $object, $result = null)
{
$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

444
php/tests/093.phpt Normal file
View file

@ -0,0 +1,444 @@
--TEST--
unpack of object converter (object: php_only=0)
--SKIPIF--
<?php
if (version_compare(PHP_VERSION, '5.2.0') < 0) {
echo "skip tests in PHP 5.2 or newer";
}
--FILE--
<?php
if(!extension_loaded('msgpack'))
{
dl('msgpack.' . PHP_SHLIB_SUFFIX);
}
error_reporting(0);
ini_set('msgpack.php_only', 0);
function test($type, $variable, $object, $result = null)
{
$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;
}
}
}
}
$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

430
php/tests/093b.phpt Normal file
View file

@ -0,0 +1,430 @@
--TEST--
unpack of object converter (object: php_only=0)
--SKIPIF--
<?php
if (version_compare(PHP_VERSION, '5.2.0') >= 0) {
echo "skip tests in PHP 5.1 or older";
}
--FILE--
<?php
if(!extension_loaded('msgpack'))
{
dl('msgpack.' . PHP_SHLIB_SUFFIX);
}
error_reporting(0);
ini_set('msgpack.php_only', 0);
function test($type, $variable, $object, $result = null)
{
$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, 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

578
php/tests/094.phpt Normal file
View file

@ -0,0 +1,578 @@
--TEST--
unpack of object converter : class unpack (string)
--SKIPIF--
<?php
if (version_compare(PHP_VERSION, '5.2.0') < 0) {
echo "skip tests in PHP 5.2 or newer";
}
--FILE--
<?php
if(!extension_loaded('msgpack'))
{
dl('msgpack.' . PHP_SHLIB_SUFFIX);
}
error_reporting(0);
function test($type, $variable, $object, $result = null)
{
$msgpack = new MessagePack();
$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));
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

566
php/tests/094b.phpt Normal file
View file

@ -0,0 +1,566 @@
--TEST--
unpack of object converter : class unpack (string)
--SKIPIF--
<?php
if (version_compare(PHP_VERSION, '5.2.0') >= 0) {
echo "skip tests in PHP 5.1 or older";
}
--FILE--
<?php
if(!extension_loaded('msgpack'))
{
dl('msgpack.' . PHP_SHLIB_SUFFIX);
}
error_reporting(0);
function test($type, $variable, $object, $result = null)
{
$msgpack = new MessagePack();
$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));
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

580
php/tests/095.phpt Normal file
View file

@ -0,0 +1,580 @@
--TEST--
unpack of object converter : class unpack (object)
--SKIPIF--
<?php
if (version_compare(PHP_VERSION, '5.2.0') < 0) {
echo "skip tests in PHP 5.2 or newer";
}
--FILE--
<?php
if(!extension_loaded('msgpack'))
{
dl('msgpack.' . PHP_SHLIB_SUFFIX);
}
error_reporting(0);
function test($type, $variable, $object, $result = null)
{
$msgpack = new MessagePack();
$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;
}
}
}
}
$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

566
php/tests/095b.phpt Normal file
View file

@ -0,0 +1,566 @@
--TEST--
unpack of object converter : class unpack (object)
--SKIPIF--
<?php
if (version_compare(PHP_VERSION, '5.2.0') >= 0) {
echo "skip tests in PHP 5.1 or older";
}
--FILE--
<?php
if(!extension_loaded('msgpack'))
{
dl('msgpack.' . PHP_SHLIB_SUFFIX);
}
error_reporting(0);
function test($type, $variable, $object, $result = null)
{
$msgpack = new MessagePack();
$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, 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

445
php/tests/096.phpt Normal file
View file

@ -0,0 +1,445 @@
--TEST--
unpack of object converter : class unpack (string: php_only=0)
--SKIPIF--
<?php
if (version_compare(PHP_VERSION, '5.2.0') < 0) {
echo "skip tests in PHP 5.2 or newer";
}
--FILE--
<?php
if(!extension_loaded('msgpack'))
{
dl('msgpack.' . PHP_SHLIB_SUFFIX);
}
error_reporting(0);
ini_set('msgpack.php_only', 0);
function test($type, $variable, $object, $result = null)
{
$msgpack = new MessagePack();
$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

433
php/tests/096b.phpt Normal file
View file

@ -0,0 +1,433 @@
--TEST--
unpack of object converter : class unpack (string: php_only=0)
--SKIPIF--
<?php
if (version_compare(PHP_VERSION, '5.2.0') >= 0) {
echo "skip tests in PHP 5.1 or older";
}
--FILE--
<?php
if(!extension_loaded('msgpack'))
{
dl('msgpack.' . PHP_SHLIB_SUFFIX);
}
error_reporting(0);
ini_set('msgpack.php_only', 0);
function test($type, $variable, $object, $result = null)
{
$msgpack = new MessagePack();
$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

447
php/tests/097.phpt Normal file
View file

@ -0,0 +1,447 @@
--TEST--
unpack of object converter : class unpack (object: php_only=0)
--SKIPIF--
<?php
if (version_compare(PHP_VERSION, '5.2.0') < 0) {
echo "skip tests in PHP 5.2 or newer";
}
--FILE--
<?php
if(!extension_loaded('msgpack'))
{
dl('msgpack.' . PHP_SHLIB_SUFFIX);
}
error_reporting(0);
ini_set('msgpack.php_only', 0);
function test($type, $variable, $object, $result = null)
{
$msgpack = new MessagePack();
$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;
}
}
}
}
$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

433
php/tests/097b.phpt Normal file
View file

@ -0,0 +1,433 @@
--TEST--
unpack of object converter : class unpack (object: php_only=0)
--SKIPIF--
<?php
if (version_compare(PHP_VERSION, '5.2.0') >= 0) {
echo "skip tests in PHP 5.1 or older";
}
--FILE--
<?php
if(!extension_loaded('msgpack'))
{
dl('msgpack.' . PHP_SHLIB_SUFFIX);
}
error_reporting(0);
ini_set('msgpack.php_only', 0);
function test($type, $variable, $object, $result = null)
{
$msgpack = new MessagePack();
$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, 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

445
php/tests/098.phpt Normal file
View file

@ -0,0 +1,445 @@
--TEST--
unpack of object converter: class unpack (string: OPT_PHPONLY=false)
--SKIPIF--
<?php
if (version_compare(PHP_VERSION, '5.2.0') < 0) {
echo "skip tests in PHP 5.2 or newer";
}
--FILE--
<?php
if(!extension_loaded('msgpack'))
{
dl('msgpack.' . PHP_SHLIB_SUFFIX);
}
error_reporting(0);
function test($type, $variable, $object, $result = null)
{
$msgpack = new MessagePack();
$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("" => "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

440
php/tests/098b.phpt Normal file
View file

@ -0,0 +1,440 @@
--TEST--
unpack of object converter: class unpack (string: OPT_PHPONLY=false)
--SKIPIF--
<?php
if (version_compare(PHP_VERSION, '5.2.0') >= 0) {
echo "skip tests in PHP 5.1 or older";
}
--FILE--
<?php
if(!extension_loaded('msgpack'))
{
dl('msgpack.' . PHP_SHLIB_SUFFIX);
}
error_reporting(0);
function test($type, $variable, $object, $result = null)
{
$msgpack = new MessagePack();
if (version_compare(PHP_VERSION, '5.1.0') <= 0)
{
$msgpack->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

584
php/tests/099.phpt Normal file
View file

@ -0,0 +1,584 @@
--TEST--
unpack of object converter : class unpacker (string)
--SKIPIF--
<?php
if (version_compare(PHP_VERSION, '5.2.0') < 0) {
echo "skip tests in PHP 5.2 or newer";
}
--FILE--
<?php
if(!extension_loaded('msgpack'))
{
dl('msgpack.' . PHP_SHLIB_SUFFIX);
}
error_reporting(0);
function test($type, $variable, $object, $result = null)
{
$msgpack = new MessagePack();
$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));
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

572
php/tests/099b.phpt Normal file
View file

@ -0,0 +1,572 @@
--TEST--
unpack of object converter : class unpacker (string)
--SKIPIF--
<?php
if (version_compare(PHP_VERSION, '5.2.0') >= 0) {
echo "skip tests in PHP 5.1 or older";
}
--FILE--
<?php
if(!extension_loaded('msgpack'))
{
dl('msgpack.' . PHP_SHLIB_SUFFIX);
}
error_reporting(0);
function test($type, $variable, $object, $result = null)
{
$msgpack = new MessagePack();
$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));
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

586
php/tests/100.phpt Normal file
View file

@ -0,0 +1,586 @@
--TEST--
unpack of object converter : class unpacker (object)
--SKIPIF--
<?php
if (version_compare(PHP_VERSION, '5.2.0') < 0) {
echo "skip tests in PHP 5.2 or newer";
}
--FILE--
<?php
if(!extension_loaded('msgpack'))
{
dl('msgpack.' . PHP_SHLIB_SUFFIX);
}
error_reporting(0);
function test($type, $variable, $object, $result = null)
{
$msgpack = new MessagePack();
$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;
}
}
}
}
$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

572
php/tests/100b.phpt Normal file
View file

@ -0,0 +1,572 @@
--TEST--
unpack of object converter : class unpacker (object)
--SKIPIF--
<?php
if (version_compare(PHP_VERSION, '5.2.0') >= 0) {
echo "skip tests in PHP 5.1 or older";
}
--FILE--
<?php
if(!extension_loaded('msgpack'))
{
dl('msgpack.' . PHP_SHLIB_SUFFIX);
}
error_reporting(0);
function test($type, $variable, $object, $result = null)
{
$msgpack = new MessagePack();
$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, 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

451
php/tests/101.phpt Normal file
View file

@ -0,0 +1,451 @@
--TEST--
unpack of object converter : class unpacker (string: php_only=0)
--SKIPIF--
<?php
if (version_compare(PHP_VERSION, '5.2.0') < 0) {
echo "skip tests in PHP 5.2 or newer";
}
--FILE--
<?php
if(!extension_loaded('msgpack'))
{
dl('msgpack.' . PHP_SHLIB_SUFFIX);
}
error_reporting(0);
ini_set('msgpack.php_only', 0);
function test($type, $variable, $object, $result = null)
{
$msgpack = new MessagePack();
$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

439
php/tests/101b.phpt Normal file
View file

@ -0,0 +1,439 @@
--TEST--
unpack of object converter : class unpack (string: php_only=0)
--SKIPIF--
<?php
if (version_compare(PHP_VERSION, '5.2.0') >= 0) {
echo "skip tests in PHP 5.1 or older";
}
--FILE--
<?php
if(!extension_loaded('msgpack'))
{
dl('msgpack.' . PHP_SHLIB_SUFFIX);
}
error_reporting(0);
ini_set('msgpack.php_only', 0);
function test($type, $variable, $object, $result = null)
{
$msgpack = new MessagePack();
$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

453
php/tests/102.phpt Normal file
View file

@ -0,0 +1,453 @@
--TEST--
unpack of object converter : class unpacker (object: php_only=0)
--SKIPIF--
<?php
if (version_compare(PHP_VERSION, '5.2.0') < 0) {
echo "skip tests in PHP 5.2 or newer";
}
--FILE--
<?php
if(!extension_loaded('msgpack'))
{
dl('msgpack.' . PHP_SHLIB_SUFFIX);
}
error_reporting(0);
ini_set('msgpack.php_only', 0);
function test($type, $variable, $object, $result = null)
{
$msgpack = new MessagePack();
$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;
}
}
}
}
$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

439
php/tests/102b.phpt Normal file
View file

@ -0,0 +1,439 @@
--TEST--
unpack of object converter : class unpacker (object: php_only=0)
--SKIPIF--
<?php
if (version_compare(PHP_VERSION, '5.2.0') >= 0) {
echo "skip tests in PHP 5.1 or older";
}
--FILE--
<?php
if(!extension_loaded('msgpack'))
{
dl('msgpack.' . PHP_SHLIB_SUFFIX);
}
error_reporting(0);
ini_set('msgpack.php_only', 0);
function test($type, $variable, $object, $result = null)
{
$msgpack = new MessagePack();
$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, 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

451
php/tests/103.phpt Normal file
View file

@ -0,0 +1,451 @@
--TEST--
unpack of object converter: class unpacker (string: OPT_PHPONLY=false)
--SKIPIF--
<?php
if (version_compare(PHP_VERSION, '5.2.0') < 0) {
echo "skip tests in PHP 5.2 or newer";
}
--FILE--
<?php
if(!extension_loaded('msgpack'))
{
dl('msgpack.' . PHP_SHLIB_SUFFIX);
}
error_reporting(0);
function test($type, $variable, $object, $result = null)
{
$msgpack = new MessagePack();
$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("" => "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

446
php/tests/103b.phpt Normal file
View file

@ -0,0 +1,446 @@
--TEST--
unpack of object converter: class unpacker (string: OPT_PHPONLY=false)
--SKIPIF--
<?php
if (version_compare(PHP_VERSION, '5.2.0') >= 0) {
echo "skip tests in PHP 5.1 or older";
}
--FILE--
<?php
if(!extension_loaded('msgpack'))
{
dl('msgpack.' . PHP_SHLIB_SUFFIX);
}
error_reporting(0);
function test($type, $variable, $object, $result = null)
{
$msgpack = new MessagePack();
if (version_compare(PHP_VERSION, '5.1.0') <= 0)
{
$msgpack->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