php: version 0.3.3

This commit is contained in:
advect 2010-12-27 11:09:14 +09:00
parent 4b36340474
commit 0acf6ec150
76 changed files with 6549 additions and 372 deletions

View file

@ -2,8 +2,10 @@
Check for reference serialization
--SKIPIF--
<?php
if (version_compare(PHP_VERSION, '5.3.2') <= 0) {
echo "skip tests in PHP 5.3.3 or newer";
if ((version_compare(PHP_VERSION, '5.2.13') <= 0) ||
(version_compare(PHP_VERSION, '5.3.0') >= 0 &&
version_compare(PHP_VERSION, '5.3.2') <= 0)) {
echo "skip tests in PHP 5.2.14/5.3.3 or newer";
}
--FILE--
<?php

View file

@ -2,8 +2,10 @@
Check for reference serialization
--SKIPIF--
<?php
if (version_compare(PHP_VERSION, '5.3.3') >= 0) {
echo "skip tests in PHP 5.3.2 or older";
if ((version_compare(PHP_VERSION, '5.3.0') < 0 &&
version_compare(PHP_VERSION, '5.2.14') >= 0) ||
(version_compare(PHP_VERSION, '5.3.3') >= 0)) {
echo "skip tests in PHP 5.2.13/5.3.2 or older";
}
--FILE--
<?php

View file

@ -1,6 +1,10 @@
--TEST--
Object test
--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')) {

52
php/tests/012c.phpt Normal file
View file

@ -0,0 +1,52 @@
--TEST--
Object test
--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);
}
function test($type, $variable, $test) {
$serialized = msgpack_serialize($variable);
$unserialized = msgpack_unserialize($serialized);
echo $type, PHP_EOL;
echo bin2hex($serialized), PHP_EOL;
var_dump($unserialized);
echo $test || $unserialized == $variable ? 'OK' : 'ERROR', PHP_EOL;
}
class Obj {
public $a;
protected $b;
private $c;
function __construct($a, $b, $c) {
$this->a = $a;
$this->b = $b;
$this->c = $c;
}
}
$o = new Obj(1, 2, 3);
test('object', $o, false);
?>
--EXPECTF--
object
84c0a34f626aa16101a4002a006202a6004f626a006303
object(Obj)#%d (3) {
["a"]=>
int(1)
["b:protected"]=>
int(2)
["c:private"]=>
int(3)
}
OK

View file

@ -1,6 +1,10 @@
--TEST--
Check for serialization handler
--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')) {

View file

@ -1,6 +1,10 @@
--TEST--
Check for serialization handler, ini-directive
--SKIPIF--
<?php
if (version_compare(PHP_VERSION, '5.2.0') < 0) {
echo "skip tests in PHP 5.2 or newer";
}
--INI--
session.serialize_handler=msgpack
--FILE--

62
php/tests/015d.phpt Normal file
View file

@ -0,0 +1,62 @@
--TEST--
Check for serialization handler
--SKIPIF--
<?php
if (version_compare(PHP_VERSION, '5.2.0') >= 0) {
echo "skip tests in PHP 5.2 or older";
}
--FILE--
<?php
if(!extension_loaded('msgpack')) {
dl('msgpack.' . PHP_SHLIB_SUFFIX);
}
$output = '';
function open($path, $name) {
return true;
}
function close() {
return true;
}
function read($id) {
global $output;
return pack('H*', '81a3666f6f01');
}
function write($id, $data) {
global $output;
$output .= bin2hex($data). PHP_EOL;
return true;
}
function destroy($id) {
return true;
}
function gc($time) {
return true;
}
ini_set('session.serialize_handler', 'msgpack');
session_set_save_handler('open', 'close', 'read', 'write', 'destroy', 'gc');
session_start();
echo ++$_SESSION['foo'], PHP_EOL;
session_write_close();
echo $output;
var_dump($_SESSION);
?>
--EXPECT--
2
81a3666f6f02
array(1) {
["foo"]=>
int(2)
}

65
php/tests/015e.phpt Normal file
View file

@ -0,0 +1,65 @@
--TEST--
Check for serialization handler, broken
--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);
$output = '';
function open($path, $name) {
return true;
}
function close() {
return true;
}
function read($id) {
global $output;
//broken data
return pack('H*', '81a36');
}
function write($id, $data) {
global $output;
$output .= bin2hex($data). PHP_EOL;
return true;
}
function destroy($id) {
return true;
}
function gc($time) {
return true;
}
ini_set('session.serialize_handler', 'msgpack');
session_set_save_handler('open', 'close', 'read', 'write', 'destroy', 'gc');
session_start();
echo ++$_SESSION['foo'], PHP_EOL;
session_write_close();
echo $output;
var_dump($_SESSION);
?>
--EXPECT--
1
82c001a3666f6f01
array(1) {
["foo"]=>
int(1)
}

65
php/tests/015f.phpt Normal file
View file

@ -0,0 +1,65 @@
--TEST--
Check for serialization handler, broken
--SKIPIF--
<?php
if (version_compare(PHP_VERSION, '5.2.0') >= 0) {
echo "skip tests in PHP 5.2 or older";
}
--FILE--
<?php
if(!extension_loaded('msgpack')) {
dl('msgpack.' . PHP_SHLIB_SUFFIX);
}
error_reporting(0);
$output = '';
function open($path, $name) {
return true;
}
function close() {
return true;
}
function read($id) {
global $output;
//broken data
return pack('H*', '81a36');
}
function write($id, $data) {
global $output;
$output .= bin2hex($data). PHP_EOL;
return true;
}
function destroy($id) {
return true;
}
function gc($time) {
return true;
}
ini_set('session.serialize_handler', 'msgpack');
session_set_save_handler('open', 'close', 'read', 'write', 'destroy', 'gc');
session_start();
echo ++$_SESSION['foo'], PHP_EOL;
session_write_close();
echo $output;
var_dump($_SESSION);
?>
--EXPECT--
1
81a3666f6f01
array(1) {
["foo"]=>
int(1)
}

View file

@ -1,6 +1,10 @@
--TEST--
Object test, __sleep
--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')) {

64
php/tests/016c.phpt Normal file
View file

@ -0,0 +1,64 @@
--TEST--
Object test, __sleep
--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);
}
function test($type, $variable, $test) {
$serialized = msgpack_serialize($variable);
$unserialized = msgpack_unserialize($serialized);
echo $type, PHP_EOL;
echo bin2hex($serialized), PHP_EOL;
var_dump($unserialized);
echo $test || $unserialized == $variable ? 'OK' : 'ERROR', PHP_EOL;
}
class Obj {
public $a;
protected $b;
private $c;
var $d;
function __construct($a, $b, $c, $d) {
$this->a = $a;
$this->b = $b;
$this->c = $c;
$this->d = $d;
}
function __sleep() {
return array('a', 'b', 'c');
}
# function __wakeup() {
# $this->d = $this->a + $this->b + $this->c;
# }
}
$o = new Obj(1, 2, 3, 4);
test('object', $o, true);
?>
--EXPECTF--
object
84c0a34f626aa16101a4002a006202a6004f626a006303
object(Obj)#%d (4) {
["a"]=>
int(1)
["b:protected"]=>
int(2)
["c:private"]=>
int(3)
["d"]=>
NULL
}
OK

View file

@ -1,6 +1,10 @@
--TEST--
Object Serializable interface
--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')) {

View file

@ -1,11 +1,6 @@
--TEST--
Resource
--SKIPIF--
<?php
if (!function_exists("curl_init") && !class_exists("Sqlite3"))) {
echo "skip";
}
?>
--FILE--
<?php
if(!extension_loaded('msgpack')) {
@ -26,11 +21,10 @@ function test($type, $variable, $test) {
if (function_exists('curl_init')) {
$test = 'curl';
$res = curl_init('http://opensource.dynamoid.com');
} else if (class_exists('Sqlite3')) {
$test = 'sqlite';
$sqlite = new Sqlite3();
$res = $sqlite->open('db.txt');
$res = curl_init('http://php.net/');
} else {
$test = 'dir';
$res = opendir('/tmp');
}
test('resource', $res, false);
@ -39,11 +33,8 @@ switch ($test) {
case 'curl':
curl_close($res);
break;
case 'sqlite':
if (isset($sqlite)) {
$sqlite->close();
}
@unlink('db.txt');
default:
closedir($res);
break;
}
?>

View file

@ -2,8 +2,10 @@
Recursive objects
--SKIPIF--
<?php
if (version_compare(PHP_VERSION, '5.3.2') <= 0) {
echo "skip tests in PHP 5.3.3 or newer";
if ((version_compare(PHP_VERSION, '5.2.13') <= 0) ||
(version_compare(PHP_VERSION, '5.3.0') >= 0 &&
version_compare(PHP_VERSION, '5.3.2') <= 0)) {
echo "skip tests in PHP 5.2.14/5.3.3 or newer";
}
--FILE--
<?php

View file

@ -2,8 +2,13 @@
Recursive objects
--SKIPIF--
<?php
if (version_compare(PHP_VERSION, '5.3.3') >= 0) {
echo "skip tests in PHP 5.3.2 or older";
if ((version_compare(PHP_VERSION, '5.3.0') < 0 &&
version_compare(PHP_VERSION, '5.2.14') >= 0) ||
(version_compare(PHP_VERSION, '5.3.3') >= 0)) {
echo "skip tests in PHP 5.2.13/5.3.2 or older";
}
if (version_compare(PHP_VERSION, '5.2.0') < 0) {
echo "skip tests in PHP 5.2 or newer";
}
--FILE--
<?php

170
php/tests/024c.phpt Normal file
View file

@ -0,0 +1,170 @@
--TEST--
Recursive objects
--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);
}
function test($type, $variable, $test) {
$serialized = msgpack_serialize($variable);
$unserialized = msgpack_unserialize($serialized);
echo $type, PHP_EOL;
echo bin2hex($serialized), PHP_EOL;
var_dump($unserialized);
echo $test || $unserialized == $variable ? 'OK' : 'ERROR', PHP_EOL;
}
class Obj {
public $a;
protected $b;
private $c;
function __construct($a, $b, $c) {
$this->a = $a;
$this->b = $b;
$this->c = $c;
}
}
class Obj2 {
public $aa;
protected $bb;
private $cc;
private $obj;
function __construct($a, $b, $c) {
$this->a = $a;
$this->b = $b;
$this->c = $c;
$this->obj = new Obj($a, $b, $c);
}
}
class Obj3 {
private $objs;
function __construct($a, $b, $c) {
$this->objs = array();
for ($i = $a; $i < $c; $i += $b) {
$this->objs[] = new Obj($a, $i, $c);
}
}
}
class Obj4 {
private $a;
private $obj;
function __construct($a) {
$this->a = $a;
}
public function set($obj) {
$this->obj = $obj;
}
}
$o2 = new Obj2(1, 2, 3);
test('objectrec', $o2, false);
$o3 = new Obj3(0, 1, 4);
test('objectrecarr', $o3, false);
$o4 = new Obj4(100);
$o4->set($o4);
test('objectselfrec', $o4, true);
?>
--EXPECTF--
objectrec
88c0a44f626a32a26161c0a5002a006262c0a8004f626a32006363c0a9004f626a32006f626a84c0a34f626aa16101a4002a006202a6004f626a006303a16101a16202a16303
object(Obj2)#%d (7) {
["aa"]=>
NULL
["bb:protected"]=>
NULL
["cc:private"]=>
NULL
["obj:private"]=>
object(Obj)#%d (3) {
["a"]=>
int(1)
["b:protected"]=>
int(2)
["c:private"]=>
int(3)
}
["a"]=>
int(1)
["b"]=>
int(2)
["c"]=>
int(3)
}
OK
objectrecarr
82c0a44f626a33aa004f626a33006f626a73840084c0a34f626aa16100a4002a006200a6004f626a0063040184c0a34f626aa16100a4002a006201a6004f626a0063040284c0a34f626aa16100a4002a006202a6004f626a0063040384c0a34f626aa16100a4002a006203a6004f626a006304
object(Obj3)#%d (1) {
["objs:private"]=>
array(4) {
[0]=>
object(Obj)#%d (3) {
["a"]=>
int(0)
["b:protected"]=>
int(0)
["c:private"]=>
int(4)
}
[1]=>
object(Obj)#%d (3) {
["a"]=>
int(0)
["b:protected"]=>
int(1)
["c:private"]=>
int(4)
}
[2]=>
object(Obj)#%d (3) {
["a"]=>
int(0)
["b:protected"]=>
int(2)
["c:private"]=>
int(4)
}
[3]=>
object(Obj)#%d (3) {
["a"]=>
int(0)
["b:protected"]=>
int(3)
["c:private"]=>
int(4)
}
}
}
OK
objectselfrec
83c0a44f626a34a7004f626a34006164a9004f626a34006f626a82c0020001
object(Obj4)#%d (2) {
["a:private"]=>
int(100)
["obj:private"]=>
object(Obj4)#%d (2) {
["a:private"]=>
int(100)
["obj:private"]=>
*RECURSION*
}
}
OK

View file

@ -1,6 +1,10 @@
--TEST--
Object test, array of objects with __sleep
--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')) {

123
php/tests/025c.phpt Normal file
View file

@ -0,0 +1,123 @@
--TEST--
Object test, array of objects with __sleep
--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);
}
function test($type, $variable, $test) {
$serialized = msgpack_serialize($variable);
$unserialized = msgpack_unserialize($serialized);
var_dump($variable);
var_dump($unserialized);
}
class Obj {
public $a;
protected $b;
private $c;
var $d;
function __construct($a, $b, $c, $d) {
$this->a = $a;
$this->b = $b;
$this->c = $c;
$this->d = $d;
}
function __sleep() {
return array('a', 'b', 'c');
}
# function __wakeup() {
# $this->d = $this->a + $this->b + $this->c;
# }
}
$array = array(
new Obj("aa", "bb", "cc", "dd"),
new Obj("ee", "ff", "gg", "hh"),
new Obj(1, 2, 3, 4),
);
test('array', $array, true);
?>
--EXPECTF--
array(3) {
[0]=>
object(Obj)#1 (4) {
["a"]=>
string(2) "aa"
["b:protected"]=>
string(2) "bb"
["c:private"]=>
string(2) "cc"
["d"]=>
string(2) "dd"
}
[1]=>
object(Obj)#2 (4) {
["a"]=>
string(2) "ee"
["b:protected"]=>
string(2) "ff"
["c:private"]=>
string(2) "gg"
["d"]=>
string(2) "hh"
}
[2]=>
object(Obj)#3 (4) {
["a"]=>
int(1)
["b:protected"]=>
int(2)
["c:private"]=>
int(3)
["d"]=>
int(4)
}
}
array(3) {
[0]=>
object(Obj)#4 (4) {
["a"]=>
string(2) "aa"
["b:protected"]=>
string(2) "bb"
["c:private"]=>
string(2) "cc"
["d"]=>
NULL
}
[1]=>
object(Obj)#5 (4) {
["a"]=>
string(2) "ee"
["b:protected"]=>
string(2) "ff"
["c:private"]=>
string(2) "gg"
["d"]=>
NULL
}
[2]=>
object(Obj)#6 (4) {
["a"]=>
int(1)
["b:protected"]=>
int(2)
["c:private"]=>
int(3)
["d"]=>
NULL
}
}

View file

@ -3,8 +3,10 @@ Cyclic array test
--INI--
--SKIPIF--
<?php
if (version_compare(PHP_VERSION, '5.3.2') <= 0) {
echo "skip tests in PHP 5.3.3 or newer";
if ((version_compare(PHP_VERSION, '5.2.13') <= 0) ||
(version_compare(PHP_VERSION, '5.3.0') >= 0 &&
version_compare(PHP_VERSION, '5.3.2') <= 0)) {
echo "skip tests in PHP 5.2.14/5.3.3 or newer";
}
--FILE--
<?php
@ -43,7 +45,7 @@ var_dump($k);
?>
--EXPECT--
array
82a16182a162a163a164a165a16683c001a16182a162a163a164a165a16682c0020005
82a16182a162a163a164a165a16683c001a16182a162a163a164a165a16682c0020003
array(2) {
["a"]=>
array(2) {

View file

@ -3,8 +3,13 @@ Cyclic array test
--INI--
--SKIPIF--
<?php
if (version_compare(PHP_VERSION, '5.3.3') >= 0) {
echo "skip tests in PHP 5.3.2 or older";
if ((version_compare(PHP_VERSION, '5.3.0') < 0 &&
version_compare(PHP_VERSION, '5.2.14') >= 0) ||
(version_compare(PHP_VERSION, '5.3.3') >= 0)) {
echo "skip tests in PHP 5.2.13/5.3.2 or older";
}
if (version_compare(PHP_VERSION, '5.1.0') < 0) {
echo "skip tests in PHP 5.1 or newer";
}
--FILE--
<?php
@ -43,7 +48,7 @@ var_dump($k);
?>
--EXPECT--
array
82a16182a162a163a164a165a16683c001a16182a162a163a164a165a16682c0020005
82a16182a162a163a164a165a16683c001a16182a162a163a164a165a16682c0020003
array(2) {
["a"]=>
array(2) {

147
php/tests/026d.phpt Normal file
View file

@ -0,0 +1,147 @@
--TEST--
Cyclic array test
--INI--
--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) {
$serialized = msgpack_serialize($variable);
$unserialized = msgpack_unserialize($serialized);
echo $type, PHP_EOL;
echo bin2hex($serialized), PHP_EOL;
var_dump($unserialized);
echo $test || $unserialized == $variable ? 'OK' : 'ERROR', PHP_EOL;
}
$a = array(
'a' => array(
'b' => 'c',
'd' => 'e'
),
);
$a['f'] = &$a;
test('array', $a, true);
$a = array("foo" => &$b);
$b = array(1, 2, $a);
var_dump($a);
var_dump($k = msgpack_unserialize(msgpack_serialize($a)));
$k["foo"][1] = "b";
var_dump($k);
?>
--EXPECT--
array
82a16182a162a163a164a165a16682a16182a162a163a164a165a16682a16182a162a163a164a165a166c0
array(2) {
["a"]=>
array(2) {
["b"]=>
string(1) "c"
["d"]=>
string(1) "e"
}
["f"]=>
array(2) {
["a"]=>
array(2) {
["b"]=>
string(1) "c"
["d"]=>
string(1) "e"
}
["f"]=>
array(2) {
["a"]=>
array(2) {
["b"]=>
string(1) "c"
["d"]=>
string(1) "e"
}
["f"]=>
NULL
}
}
}
OK
array(1) {
["foo"]=>
&array(3) {
[0]=>
int(1)
[1]=>
int(2)
[2]=>
array(1) {
["foo"]=>
&array(3) {
[0]=>
int(1)
[1]=>
int(2)
[2]=>
*RECURSION*
}
}
}
}
array(1) {
["foo"]=>
&array(3) {
[0]=>
int(1)
[1]=>
int(2)
[2]=>
array(1) {
["foo"]=>
&array(3) {
[0]=>
int(1)
[1]=>
int(2)
[2]=>
array(1) {
["foo"]=>
*RECURSION*
}
}
}
}
}
array(1) {
["foo"]=>
&array(3) {
[0]=>
int(1)
[1]=>
string(1) "b"
[2]=>
array(1) {
["foo"]=>
&array(3) {
[0]=>
int(1)
[1]=>
string(1) "b"
[2]=>
array(1) {
["foo"]=>
*RECURSION*
}
}
}
}
}

View file

@ -1,6 +1,10 @@
--TEST--
Check for serialization handler
--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')) {

77
php/tests/027d.phpt Normal file
View file

@ -0,0 +1,77 @@
--TEST--
Check for serialization handler
--SKIPIF--
<?php
if (version_compare(PHP_VERSION, '5.2.0') >= 0) {
echo "skip tests in PHP 5.2 or older";
}
--FILE--
<?php
if(!extension_loaded('msgpack')) {
dl('msgpack.' . PHP_SHLIB_SUFFIX);
}
$output = '';
function open($path, $name) {
return true;
}
function close() {
return true;
}
function read($id) {
global $output;
$output .= "read" . PHP_EOL;
return pack('H*', '81a3666f6f01');
}
function write($id, $data) {
global $output;
$output .= "wrote: ";
$output .= bin2hex($data). PHP_EOL;
return true;
}
function destroy($id) {
return true;
}
function gc($time) {
return true;
}
class Foo {
}
class Bar {
}
ini_set('session.serialize_handler', 'msgpack');
session_set_save_handler('open', 'close', 'read', 'write', 'destroy', 'gc');
$db_object = new Foo();
$session_object = new Bar();
$v = session_start();
var_dump($v);
$_SESSION['test'] = "foobar";
session_write_close();
echo $output;
var_dump($_SESSION);
?>
--EXPECT--
bool(true)
read
wrote: 82a3666f6f01a474657374a6666f6f626172
array(2) {
["foo"]=>
int(1)
["test"]=>
string(6) "foobar"
}

View file

@ -2,8 +2,10 @@
Serialize object into session, full set
--SKIPIF--
<?php
if (version_compare(PHP_VERSION, '5.3.2') <= 0) {
echo "skip tests in PHP 5.3.3 or newer";
if ((version_compare(PHP_VERSION, '5.2.13') <= 0) ||
(version_compare(PHP_VERSION, '5.3.0') >= 0 &&
version_compare(PHP_VERSION, '5.3.2') <= 0)) {
echo "skip tests in PHP 5.2.14/5.3.3 or newer";
}
--FILE--
<?php
@ -100,7 +102,7 @@ var_dump($_SESSION);
?>
--EXPECTF--
read
write: 84c001a36f6c6484c0a3466f6fa700466f6f00643184c0a3426172a2643182c0020002a70042617200643282c0020002a5002a00643382c0020002a5002a00643282c0020003a2643382c0020003a474657374a6666f6f626172a36e657784c0a3426172a2643184c0a3466f6fa700466f6f00643182c002000aa5002a00643282c002000aa2643382c002000aa70042617200643282c002000ba5002a00643382c002000b
write: 84c001a36f6c6484c0a3466f6fa700466f6f00643184c0a3426172a2643182c0020002a70042617200643282c0020002a5002a00643382c0020002a5002a00643282c0020003a2643382c0020003a474657374a6666f6f626172a36e657784c0a3426172a2643184c0a3466f6fa700466f6f00643182c0020009a5002a00643282c0020009a2643382c0020009a70042617200643282c002000aa5002a00643382c002000a
array(3) {
["old"]=>
object(Foo)#3 (3) {

View file

@ -2,8 +2,13 @@
Serialize object into session, full set
--SKIPIF--
<?php
if (version_compare(PHP_VERSION, '5.3.3') >= 0) {
echo "skip tests in PHP 5.3.2 or older";
if ((version_compare(PHP_VERSION, '5.3.0') < 0 &&
version_compare(PHP_VERSION, '5.2.14') >= 0) ||
(version_compare(PHP_VERSION, '5.3.3') >= 0)) {
echo "skip tests in PHP 5.2.13/5.3.2 or older";
}
if (version_compare(PHP_VERSION, '5.2.0') < 0) {
echo "skip tests in PHP 5.2 or newer";
}
--FILE--
<?php
@ -100,7 +105,7 @@ var_dump($_SESSION);
?>
--EXPECTF--
read
write: 84c001a36f6c6484c0a3466f6fa700466f6f00643184c0a3426172a2643182c0020002a70042617200643282c0020002a5002a00643382c0020002a5002a00643282c0020003a2643382c0020003a474657374a6666f6f626172a36e657784c0a3426172a2643184c0a3466f6fa700466f6f00643182c002000aa5002a00643282c002000aa2643382c002000aa70042617200643282c002000ba5002a00643382c002000b
write: 84c001a36f6c6484c0a3466f6fa700466f6f00643184c0a3426172a2643182c0020002a70042617200643282c0020002a5002a00643382c0020002a5002a00643282c0020003a2643382c0020003a474657374a6666f6f626172a36e657784c0a3426172a2643184c0a3466f6fa700466f6f00643182c0020009a5002a00643282c0020009a2643382c0020009a70042617200643282c002000aa5002a00643382c002000a
array(3) {
["old"]=>
object(Foo)#3 (3) {

672
php/tests/028c.phpt Normal file
View file

@ -0,0 +1,672 @@
--TEST--
Serialize object into session, full set
--SKIPIF--
<?php
if (version_compare(PHP_VERSION, '5.1.0') < 0 ||
version_compare(PHP_VERSION, '5.2.0') >= 0) {
echo "skip tests in PHP 5.1";
}
--FILE--
<?php
if(!extension_loaded('msgpack')) {
dl('msgpack.' . PHP_SHLIB_SUFFIX);
}
class Foo {
private static $s1 = array();
protected static $s2 = array();
public static $s3 = array();
private $d1;
protected $d2;
public $d3;
public function __construct($foo) {
$this->d1 = $foo;
$this->d2 = $foo;
$this->d3 = $foo;
}
}
class Bar {
private static $s1 = array();
protected static $s2 = array();
public static $s3 = array();
public $d1;
private $d2;
protected $d3;
public function __construct() {
}
public function set($foo) {
$this->d1 = $foo;
$this->d2 = $foo;
$this->d3 = $foo;
}
}
$output = '';
function open($path, $name) {
return true;
}
function close() {
return true;
}
function read($id) {
global $output;
$output .= "read" . PHP_EOL;
$a = new Bar();
$b = new Foo($a);
$a->set($b);
$session = array('old' => $b);
return msgpack_serialize($session);
}
function write($id, $data) {
global $output;
$output .= "write: ";
$output .= bin2hex($data) . PHP_EOL;
return true;
}
function destroy($id) {
return true;
}
function gc($time) {
return true;
}
ini_set('session.serialize_handler', 'msgpack');
session_set_save_handler('open', 'close', 'read', 'write', 'destroy', 'gc');
session_start();
$_SESSION['test'] = "foobar";
$a = new Bar();
$b = new Foo($a);
$a->set($b);
$_SESSION['new'] = $a;
session_write_close();
echo $output;
var_dump($_SESSION);
?>
--EXPECTF--
read
write: 83a36f6c6484c0a3466f6fa700466f6f00643184c0a3426172a2643182c0020002a70042617200643282c0020002a5002a00643382c0020002a5002a00643282c0020003a2643382c0020003a474657374a6666f6f626172a36e657784c0a3426172a2643184c0a3466f6fa700466f6f00643182c0020009a5002a00643282c0020009a2643382c0020009a70042617200643282c002000aa5002a00643382c002000a
array(3) {
["old"]=>
object(Foo)#3 (3) {
["d1:private"]=>
object(Bar)#4 (3) {
["d1"]=>
object(Foo)#3 (3) {
["d1:private"]=>
object(Bar)#4 (3) {
["d1"]=>
*RECURSION*
["d2:private"]=>
*RECURSION*
["d3:protected"]=>
*RECURSION*
}
["d2:protected"]=>
object(Bar)#4 (3) {
["d1"]=>
*RECURSION*
["d2:private"]=>
*RECURSION*
["d3:protected"]=>
*RECURSION*
}
["d3"]=>
object(Bar)#4 (3) {
["d1"]=>
*RECURSION*
["d2:private"]=>
*RECURSION*
["d3:protected"]=>
*RECURSION*
}
}
["d2:private"]=>
object(Foo)#3 (3) {
["d1:private"]=>
object(Bar)#4 (3) {
["d1"]=>
*RECURSION*
["d2:private"]=>
*RECURSION*
["d3:protected"]=>
*RECURSION*
}
["d2:protected"]=>
object(Bar)#4 (3) {
["d1"]=>
*RECURSION*
["d2:private"]=>
*RECURSION*
["d3:protected"]=>
*RECURSION*
}
["d3"]=>
object(Bar)#4 (3) {
["d1"]=>
*RECURSION*
["d2:private"]=>
*RECURSION*
["d3:protected"]=>
*RECURSION*
}
}
["d3:protected"]=>
object(Foo)#3 (3) {
["d1:private"]=>
object(Bar)#4 (3) {
["d1"]=>
*RECURSION*
["d2:private"]=>
*RECURSION*
["d3:protected"]=>
*RECURSION*
}
["d2:protected"]=>
object(Bar)#4 (3) {
["d1"]=>
*RECURSION*
["d2:private"]=>
*RECURSION*
["d3:protected"]=>
*RECURSION*
}
["d3"]=>
object(Bar)#4 (3) {
["d1"]=>
*RECURSION*
["d2:private"]=>
*RECURSION*
["d3:protected"]=>
*RECURSION*
}
}
}
["d2:protected"]=>
object(Bar)#4 (3) {
["d1"]=>
object(Foo)#3 (3) {
["d1:private"]=>
object(Bar)#4 (3) {
["d1"]=>
*RECURSION*
["d2:private"]=>
*RECURSION*
["d3:protected"]=>
*RECURSION*
}
["d2:protected"]=>
object(Bar)#4 (3) {
["d1"]=>
*RECURSION*
["d2:private"]=>
*RECURSION*
["d3:protected"]=>
*RECURSION*
}
["d3"]=>
object(Bar)#4 (3) {
["d1"]=>
*RECURSION*
["d2:private"]=>
*RECURSION*
["d3:protected"]=>
*RECURSION*
}
}
["d2:private"]=>
object(Foo)#3 (3) {
["d1:private"]=>
object(Bar)#4 (3) {
["d1"]=>
*RECURSION*
["d2:private"]=>
*RECURSION*
["d3:protected"]=>
*RECURSION*
}
["d2:protected"]=>
object(Bar)#4 (3) {
["d1"]=>
*RECURSION*
["d2:private"]=>
*RECURSION*
["d3:protected"]=>
*RECURSION*
}
["d3"]=>
object(Bar)#4 (3) {
["d1"]=>
*RECURSION*
["d2:private"]=>
*RECURSION*
["d3:protected"]=>
*RECURSION*
}
}
["d3:protected"]=>
object(Foo)#3 (3) {
["d1:private"]=>
object(Bar)#4 (3) {
["d1"]=>
*RECURSION*
["d2:private"]=>
*RECURSION*
["d3:protected"]=>
*RECURSION*
}
["d2:protected"]=>
object(Bar)#4 (3) {
["d1"]=>
*RECURSION*
["d2:private"]=>
*RECURSION*
["d3:protected"]=>
*RECURSION*
}
["d3"]=>
object(Bar)#4 (3) {
["d1"]=>
*RECURSION*
["d2:private"]=>
*RECURSION*
["d3:protected"]=>
*RECURSION*
}
}
}
["d3"]=>
object(Bar)#4 (3) {
["d1"]=>
object(Foo)#3 (3) {
["d1:private"]=>
object(Bar)#4 (3) {
["d1"]=>
*RECURSION*
["d2:private"]=>
*RECURSION*
["d3:protected"]=>
*RECURSION*
}
["d2:protected"]=>
object(Bar)#4 (3) {
["d1"]=>
*RECURSION*
["d2:private"]=>
*RECURSION*
["d3:protected"]=>
*RECURSION*
}
["d3"]=>
object(Bar)#4 (3) {
["d1"]=>
*RECURSION*
["d2:private"]=>
*RECURSION*
["d3:protected"]=>
*RECURSION*
}
}
["d2:private"]=>
object(Foo)#3 (3) {
["d1:private"]=>
object(Bar)#4 (3) {
["d1"]=>
*RECURSION*
["d2:private"]=>
*RECURSION*
["d3:protected"]=>
*RECURSION*
}
["d2:protected"]=>
object(Bar)#4 (3) {
["d1"]=>
*RECURSION*
["d2:private"]=>
*RECURSION*
["d3:protected"]=>
*RECURSION*
}
["d3"]=>
object(Bar)#4 (3) {
["d1"]=>
*RECURSION*
["d2:private"]=>
*RECURSION*
["d3:protected"]=>
*RECURSION*
}
}
["d3:protected"]=>
object(Foo)#3 (3) {
["d1:private"]=>
object(Bar)#4 (3) {
["d1"]=>
*RECURSION*
["d2:private"]=>
*RECURSION*
["d3:protected"]=>
*RECURSION*
}
["d2:protected"]=>
object(Bar)#4 (3) {
["d1"]=>
*RECURSION*
["d2:private"]=>
*RECURSION*
["d3:protected"]=>
*RECURSION*
}
["d3"]=>
object(Bar)#4 (3) {
["d1"]=>
*RECURSION*
["d2:private"]=>
*RECURSION*
["d3:protected"]=>
*RECURSION*
}
}
}
}
["test"]=>
string(6) "foobar"
["new"]=>
object(Bar)#5 (3) {
["d1"]=>
object(Foo)#6 (3) {
["d1:private"]=>
object(Bar)#5 (3) {
["d1"]=>
object(Foo)#6 (3) {
["d1:private"]=>
*RECURSION*
["d2:protected"]=>
*RECURSION*
["d3"]=>
*RECURSION*
}
["d2:private"]=>
object(Foo)#6 (3) {
["d1:private"]=>
*RECURSION*
["d2:protected"]=>
*RECURSION*
["d3"]=>
*RECURSION*
}
["d3:protected"]=>
object(Foo)#6 (3) {
["d1:private"]=>
*RECURSION*
["d2:protected"]=>
*RECURSION*
["d3"]=>
*RECURSION*
}
}
["d2:protected"]=>
object(Bar)#5 (3) {
["d1"]=>
object(Foo)#6 (3) {
["d1:private"]=>
*RECURSION*
["d2:protected"]=>
*RECURSION*
["d3"]=>
*RECURSION*
}
["d2:private"]=>
object(Foo)#6 (3) {
["d1:private"]=>
*RECURSION*
["d2:protected"]=>
*RECURSION*
["d3"]=>
*RECURSION*
}
["d3:protected"]=>
object(Foo)#6 (3) {
["d1:private"]=>
*RECURSION*
["d2:protected"]=>
*RECURSION*
["d3"]=>
*RECURSION*
}
}
["d3"]=>
object(Bar)#5 (3) {
["d1"]=>
object(Foo)#6 (3) {
["d1:private"]=>
*RECURSION*
["d2:protected"]=>
*RECURSION*
["d3"]=>
*RECURSION*
}
["d2:private"]=>
object(Foo)#6 (3) {
["d1:private"]=>
*RECURSION*
["d2:protected"]=>
*RECURSION*
["d3"]=>
*RECURSION*
}
["d3:protected"]=>
object(Foo)#6 (3) {
["d1:private"]=>
*RECURSION*
["d2:protected"]=>
*RECURSION*
["d3"]=>
*RECURSION*
}
}
}
["d2:private"]=>
object(Foo)#6 (3) {
["d1:private"]=>
object(Bar)#5 (3) {
["d1"]=>
object(Foo)#6 (3) {
["d1:private"]=>
*RECURSION*
["d2:protected"]=>
*RECURSION*
["d3"]=>
*RECURSION*
}
["d2:private"]=>
object(Foo)#6 (3) {
["d1:private"]=>
*RECURSION*
["d2:protected"]=>
*RECURSION*
["d3"]=>
*RECURSION*
}
["d3:protected"]=>
object(Foo)#6 (3) {
["d1:private"]=>
*RECURSION*
["d2:protected"]=>
*RECURSION*
["d3"]=>
*RECURSION*
}
}
["d2:protected"]=>
object(Bar)#5 (3) {
["d1"]=>
object(Foo)#6 (3) {
["d1:private"]=>
*RECURSION*
["d2:protected"]=>
*RECURSION*
["d3"]=>
*RECURSION*
}
["d2:private"]=>
object(Foo)#6 (3) {
["d1:private"]=>
*RECURSION*
["d2:protected"]=>
*RECURSION*
["d3"]=>
*RECURSION*
}
["d3:protected"]=>
object(Foo)#6 (3) {
["d1:private"]=>
*RECURSION*
["d2:protected"]=>
*RECURSION*
["d3"]=>
*RECURSION*
}
}
["d3"]=>
object(Bar)#5 (3) {
["d1"]=>
object(Foo)#6 (3) {
["d1:private"]=>
*RECURSION*
["d2:protected"]=>
*RECURSION*
["d3"]=>
*RECURSION*
}
["d2:private"]=>
object(Foo)#6 (3) {
["d1:private"]=>
*RECURSION*
["d2:protected"]=>
*RECURSION*
["d3"]=>
*RECURSION*
}
["d3:protected"]=>
object(Foo)#6 (3) {
["d1:private"]=>
*RECURSION*
["d2:protected"]=>
*RECURSION*
["d3"]=>
*RECURSION*
}
}
}
["d3:protected"]=>
object(Foo)#6 (3) {
["d1:private"]=>
object(Bar)#5 (3) {
["d1"]=>
object(Foo)#6 (3) {
["d1:private"]=>
*RECURSION*
["d2:protected"]=>
*RECURSION*
["d3"]=>
*RECURSION*
}
["d2:private"]=>
object(Foo)#6 (3) {
["d1:private"]=>
*RECURSION*
["d2:protected"]=>
*RECURSION*
["d3"]=>
*RECURSION*
}
["d3:protected"]=>
object(Foo)#6 (3) {
["d1:private"]=>
*RECURSION*
["d2:protected"]=>
*RECURSION*
["d3"]=>
*RECURSION*
}
}
["d2:protected"]=>
object(Bar)#5 (3) {
["d1"]=>
object(Foo)#6 (3) {
["d1:private"]=>
*RECURSION*
["d2:protected"]=>
*RECURSION*
["d3"]=>
*RECURSION*
}
["d2:private"]=>
object(Foo)#6 (3) {
["d1:private"]=>
*RECURSION*
["d2:protected"]=>
*RECURSION*
["d3"]=>
*RECURSION*
}
["d3:protected"]=>
object(Foo)#6 (3) {
["d1:private"]=>
*RECURSION*
["d2:protected"]=>
*RECURSION*
["d3"]=>
*RECURSION*
}
}
["d3"]=>
object(Bar)#5 (3) {
["d1"]=>
object(Foo)#6 (3) {
["d1:private"]=>
*RECURSION*
["d2:protected"]=>
*RECURSION*
["d3"]=>
*RECURSION*
}
["d2:private"]=>
object(Foo)#6 (3) {
["d1:private"]=>
*RECURSION*
["d2:protected"]=>
*RECURSION*
["d3"]=>
*RECURSION*
}
["d3:protected"]=>
object(Foo)#6 (3) {
["d1:private"]=>
*RECURSION*
["d2:protected"]=>
*RECURSION*
["d3"]=>
*RECURSION*
}
}
}
}
}

671
php/tests/028d.phpt Normal file
View file

@ -0,0 +1,671 @@
--TEST--
Serialize object into session, full set
--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);
}
class Foo {
private static $s1 = array();
protected static $s2 = array();
public static $s3 = array();
private $d1;
protected $d2;
public $d3;
public function __construct($foo) {
$this->d1 = $foo;
$this->d2 = $foo;
$this->d3 = $foo;
}
}
class Bar {
private static $s1 = array();
protected static $s2 = array();
public static $s3 = array();
public $d1;
private $d2;
protected $d3;
public function __construct() {
}
public function set($foo) {
$this->d1 = $foo;
$this->d2 = $foo;
$this->d3 = $foo;
}
}
$output = '';
function open($path, $name) {
return true;
}
function close() {
return true;
}
function read($id) {
global $output;
$output .= "read" . PHP_EOL;
$a = new Bar();
$b = new Foo($a);
$a->set($b);
$session = array('old' => $b);
return msgpack_serialize($session);
}
function write($id, $data) {
global $output;
$output .= "write: ";
$output .= bin2hex($data) . PHP_EOL;
return true;
}
function destroy($id) {
return true;
}
function gc($time) {
return true;
}
ini_set('session.serialize_handler', 'msgpack');
session_set_save_handler('open', 'close', 'read', 'write', 'destroy', 'gc');
session_start();
$_SESSION['test'] = "foobar";
$a = new Bar();
$b = new Foo($a);
$a->set($b);
$_SESSION['new'] = $a;
session_write_close();
echo $output;
var_dump($_SESSION);
?>
--EXPECTF--
read
write: 83a36f6c6484c0a3466f6fa700466f6f00643184c0a3426172a2643182c0020002a70042617200643282c0020002a5002a00643382c0020002a5002a00643282c0020003a2643382c0020003a474657374a6666f6f626172a36e657784c0a3426172a2643184c0a3466f6fa700466f6f00643182c0020009a5002a00643282c0020009a2643382c0020009a70042617200643282c002000aa5002a00643382c002000a
array(3) {
["old"]=>
object(Foo)#3 (3) {
["d1:private"]=>
object(Bar)#4 (3) {
["d1"]=>
object(Foo)#3 (3) {
["d1:private"]=>
object(Bar)#4 (3) {
["d1"]=>
*RECURSION*
["d2:private"]=>
*RECURSION*
["d3:protected"]=>
*RECURSION*
}
["d2:protected"]=>
object(Bar)#4 (3) {
["d1"]=>
*RECURSION*
["d2:private"]=>
*RECURSION*
["d3:protected"]=>
*RECURSION*
}
["d3"]=>
object(Bar)#4 (3) {
["d1"]=>
*RECURSION*
["d2:private"]=>
*RECURSION*
["d3:protected"]=>
*RECURSION*
}
}
["d2:private"]=>
object(Foo)#3 (3) {
["d1:private"]=>
object(Bar)#4 (3) {
["d1"]=>
*RECURSION*
["d2:private"]=>
*RECURSION*
["d3:protected"]=>
*RECURSION*
}
["d2:protected"]=>
object(Bar)#4 (3) {
["d1"]=>
*RECURSION*
["d2:private"]=>
*RECURSION*
["d3:protected"]=>
*RECURSION*
}
["d3"]=>
object(Bar)#4 (3) {
["d1"]=>
*RECURSION*
["d2:private"]=>
*RECURSION*
["d3:protected"]=>
*RECURSION*
}
}
["d3:protected"]=>
object(Foo)#3 (3) {
["d1:private"]=>
object(Bar)#4 (3) {
["d1"]=>
*RECURSION*
["d2:private"]=>
*RECURSION*
["d3:protected"]=>
*RECURSION*
}
["d2:protected"]=>
object(Bar)#4 (3) {
["d1"]=>
*RECURSION*
["d2:private"]=>
*RECURSION*
["d3:protected"]=>
*RECURSION*
}
["d3"]=>
object(Bar)#4 (3) {
["d1"]=>
*RECURSION*
["d2:private"]=>
*RECURSION*
["d3:protected"]=>
*RECURSION*
}
}
}
["d2:protected"]=>
object(Bar)#4 (3) {
["d1"]=>
object(Foo)#3 (3) {
["d1:private"]=>
object(Bar)#4 (3) {
["d1"]=>
*RECURSION*
["d2:private"]=>
*RECURSION*
["d3:protected"]=>
*RECURSION*
}
["d2:protected"]=>
object(Bar)#4 (3) {
["d1"]=>
*RECURSION*
["d2:private"]=>
*RECURSION*
["d3:protected"]=>
*RECURSION*
}
["d3"]=>
object(Bar)#4 (3) {
["d1"]=>
*RECURSION*
["d2:private"]=>
*RECURSION*
["d3:protected"]=>
*RECURSION*
}
}
["d2:private"]=>
object(Foo)#3 (3) {
["d1:private"]=>
object(Bar)#4 (3) {
["d1"]=>
*RECURSION*
["d2:private"]=>
*RECURSION*
["d3:protected"]=>
*RECURSION*
}
["d2:protected"]=>
object(Bar)#4 (3) {
["d1"]=>
*RECURSION*
["d2:private"]=>
*RECURSION*
["d3:protected"]=>
*RECURSION*
}
["d3"]=>
object(Bar)#4 (3) {
["d1"]=>
*RECURSION*
["d2:private"]=>
*RECURSION*
["d3:protected"]=>
*RECURSION*
}
}
["d3:protected"]=>
object(Foo)#3 (3) {
["d1:private"]=>
object(Bar)#4 (3) {
["d1"]=>
*RECURSION*
["d2:private"]=>
*RECURSION*
["d3:protected"]=>
*RECURSION*
}
["d2:protected"]=>
object(Bar)#4 (3) {
["d1"]=>
*RECURSION*
["d2:private"]=>
*RECURSION*
["d3:protected"]=>
*RECURSION*
}
["d3"]=>
object(Bar)#4 (3) {
["d1"]=>
*RECURSION*
["d2:private"]=>
*RECURSION*
["d3:protected"]=>
*RECURSION*
}
}
}
["d3"]=>
object(Bar)#4 (3) {
["d1"]=>
object(Foo)#3 (3) {
["d1:private"]=>
object(Bar)#4 (3) {
["d1"]=>
*RECURSION*
["d2:private"]=>
*RECURSION*
["d3:protected"]=>
*RECURSION*
}
["d2:protected"]=>
object(Bar)#4 (3) {
["d1"]=>
*RECURSION*
["d2:private"]=>
*RECURSION*
["d3:protected"]=>
*RECURSION*
}
["d3"]=>
object(Bar)#4 (3) {
["d1"]=>
*RECURSION*
["d2:private"]=>
*RECURSION*
["d3:protected"]=>
*RECURSION*
}
}
["d2:private"]=>
object(Foo)#3 (3) {
["d1:private"]=>
object(Bar)#4 (3) {
["d1"]=>
*RECURSION*
["d2:private"]=>
*RECURSION*
["d3:protected"]=>
*RECURSION*
}
["d2:protected"]=>
object(Bar)#4 (3) {
["d1"]=>
*RECURSION*
["d2:private"]=>
*RECURSION*
["d3:protected"]=>
*RECURSION*
}
["d3"]=>
object(Bar)#4 (3) {
["d1"]=>
*RECURSION*
["d2:private"]=>
*RECURSION*
["d3:protected"]=>
*RECURSION*
}
}
["d3:protected"]=>
object(Foo)#3 (3) {
["d1:private"]=>
object(Bar)#4 (3) {
["d1"]=>
*RECURSION*
["d2:private"]=>
*RECURSION*
["d3:protected"]=>
*RECURSION*
}
["d2:protected"]=>
object(Bar)#4 (3) {
["d1"]=>
*RECURSION*
["d2:private"]=>
*RECURSION*
["d3:protected"]=>
*RECURSION*
}
["d3"]=>
object(Bar)#4 (3) {
["d1"]=>
*RECURSION*
["d2:private"]=>
*RECURSION*
["d3:protected"]=>
*RECURSION*
}
}
}
}
["test"]=>
string(6) "foobar"
["new"]=>
object(Bar)#5 (3) {
["d1"]=>
object(Foo)#6 (3) {
["d1:private"]=>
object(Bar)#5 (3) {
["d1"]=>
object(Foo)#6 (3) {
["d1:private"]=>
*RECURSION*
["d2:protected"]=>
*RECURSION*
["d3"]=>
*RECURSION*
}
["d2:private"]=>
object(Foo)#6 (3) {
["d1:private"]=>
*RECURSION*
["d2:protected"]=>
*RECURSION*
["d3"]=>
*RECURSION*
}
["d3:protected"]=>
object(Foo)#6 (3) {
["d1:private"]=>
*RECURSION*
["d2:protected"]=>
*RECURSION*
["d3"]=>
*RECURSION*
}
}
["d2:protected"]=>
object(Bar)#5 (3) {
["d1"]=>
object(Foo)#6 (3) {
["d1:private"]=>
*RECURSION*
["d2:protected"]=>
*RECURSION*
["d3"]=>
*RECURSION*
}
["d2:private"]=>
object(Foo)#6 (3) {
["d1:private"]=>
*RECURSION*
["d2:protected"]=>
*RECURSION*
["d3"]=>
*RECURSION*
}
["d3:protected"]=>
object(Foo)#6 (3) {
["d1:private"]=>
*RECURSION*
["d2:protected"]=>
*RECURSION*
["d3"]=>
*RECURSION*
}
}
["d3"]=>
object(Bar)#5 (3) {
["d1"]=>
object(Foo)#6 (3) {
["d1:private"]=>
*RECURSION*
["d2:protected"]=>
*RECURSION*
["d3"]=>
*RECURSION*
}
["d2:private"]=>
object(Foo)#6 (3) {
["d1:private"]=>
*RECURSION*
["d2:protected"]=>
*RECURSION*
["d3"]=>
*RECURSION*
}
["d3:protected"]=>
object(Foo)#6 (3) {
["d1:private"]=>
*RECURSION*
["d2:protected"]=>
*RECURSION*
["d3"]=>
*RECURSION*
}
}
}
["d2:private"]=>
object(Foo)#6 (3) {
["d1:private"]=>
object(Bar)#5 (3) {
["d1"]=>
object(Foo)#6 (3) {
["d1:private"]=>
*RECURSION*
["d2:protected"]=>
*RECURSION*
["d3"]=>
*RECURSION*
}
["d2:private"]=>
object(Foo)#6 (3) {
["d1:private"]=>
*RECURSION*
["d2:protected"]=>
*RECURSION*
["d3"]=>
*RECURSION*
}
["d3:protected"]=>
object(Foo)#6 (3) {
["d1:private"]=>
*RECURSION*
["d2:protected"]=>
*RECURSION*
["d3"]=>
*RECURSION*
}
}
["d2:protected"]=>
object(Bar)#5 (3) {
["d1"]=>
object(Foo)#6 (3) {
["d1:private"]=>
*RECURSION*
["d2:protected"]=>
*RECURSION*
["d3"]=>
*RECURSION*
}
["d2:private"]=>
object(Foo)#6 (3) {
["d1:private"]=>
*RECURSION*
["d2:protected"]=>
*RECURSION*
["d3"]=>
*RECURSION*
}
["d3:protected"]=>
object(Foo)#6 (3) {
["d1:private"]=>
*RECURSION*
["d2:protected"]=>
*RECURSION*
["d3"]=>
*RECURSION*
}
}
["d3"]=>
object(Bar)#5 (3) {
["d1"]=>
object(Foo)#6 (3) {
["d1:private"]=>
*RECURSION*
["d2:protected"]=>
*RECURSION*
["d3"]=>
*RECURSION*
}
["d2:private"]=>
object(Foo)#6 (3) {
["d1:private"]=>
*RECURSION*
["d2:protected"]=>
*RECURSION*
["d3"]=>
*RECURSION*
}
["d3:protected"]=>
object(Foo)#6 (3) {
["d1:private"]=>
*RECURSION*
["d2:protected"]=>
*RECURSION*
["d3"]=>
*RECURSION*
}
}
}
["d3:protected"]=>
object(Foo)#6 (3) {
["d1:private"]=>
object(Bar)#5 (3) {
["d1"]=>
object(Foo)#6 (3) {
["d1:private"]=>
*RECURSION*
["d2:protected"]=>
*RECURSION*
["d3"]=>
*RECURSION*
}
["d2:private"]=>
object(Foo)#6 (3) {
["d1:private"]=>
*RECURSION*
["d2:protected"]=>
*RECURSION*
["d3"]=>
*RECURSION*
}
["d3:protected"]=>
object(Foo)#6 (3) {
["d1:private"]=>
*RECURSION*
["d2:protected"]=>
*RECURSION*
["d3"]=>
*RECURSION*
}
}
["d2:protected"]=>
object(Bar)#5 (3) {
["d1"]=>
object(Foo)#6 (3) {
["d1:private"]=>
*RECURSION*
["d2:protected"]=>
*RECURSION*
["d3"]=>
*RECURSION*
}
["d2:private"]=>
object(Foo)#6 (3) {
["d1:private"]=>
*RECURSION*
["d2:protected"]=>
*RECURSION*
["d3"]=>
*RECURSION*
}
["d3:protected"]=>
object(Foo)#6 (3) {
["d1:private"]=>
*RECURSION*
["d2:protected"]=>
*RECURSION*
["d3"]=>
*RECURSION*
}
}
["d3"]=>
object(Bar)#5 (3) {
["d1"]=>
object(Foo)#6 (3) {
["d1:private"]=>
*RECURSION*
["d2:protected"]=>
*RECURSION*
["d3"]=>
*RECURSION*
}
["d2:private"]=>
object(Foo)#6 (3) {
["d1:private"]=>
*RECURSION*
["d2:protected"]=>
*RECURSION*
["d3"]=>
*RECURSION*
}
["d3:protected"]=>
object(Foo)#6 (3) {
["d1:private"]=>
*RECURSION*
["d2:protected"]=>
*RECURSION*
["d3"]=>
*RECURSION*
}
}
}
}
}

View file

@ -1,6 +1,10 @@
--TEST--
Object Serializable interface throws exceptions
--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')) {

View file

@ -1,5 +1,5 @@
--TEST--
b0rked random data test
broken random data test
--SKIPIF--
--FILE--
<?php

44
php/tests/040b.phpt Normal file
View file

@ -0,0 +1,44 @@
--TEST--
broken random data test : MessagePack class
--SKIPIF--
--FILE--
<?php
if(!extension_loaded('msgpack')) {
dl('msgpack.' . PHP_SHLIB_SUFFIX);
}
error_reporting(E_ERROR | E_PARSE);
function test() {
$serialized = msgpack_serialize(null);
$serialized = substr($serialized, 0, -1);
$length = mt_rand(1, 255);
for ($i = 0; $i < $length; ++$i) {
$serialized .= chr(mt_rand(0, 255));
}
// if returned null everything is OK
$msgpack = new MessagePack();
if (($unserialized = $msgpack->unpack($serialized)) === null) {
return true;
}
// whole data is read?
if ($serialized !== msgpack_serialize($unserialized)) {
return true;
}
echo bin2hex($serialized), "\n";
var_dump($unserialized);
return false;
}
mt_srand(0x4c05b583);
for ($i = 0; $i < 100; ++$i) {
if (!test()) break;
}
?>
--EXPECT--

53
php/tests/040c.phpt Normal file
View file

@ -0,0 +1,53 @@
--TEST--
broken random data test : MessagePackUnpacker::feed
--SKIPIF--
--FILE--
<?php
if(!extension_loaded('msgpack')) {
dl('msgpack.' . PHP_SHLIB_SUFFIX);
}
error_reporting(E_ERROR | E_PARSE);
function test() {
$serialized = msgpack_serialize(null);
$serialized = substr($serialized, 0, -1);
$length = mt_rand(1, 255);
for ($i = 0; $i < $length; ++$i) {
$serialized .= chr(mt_rand(0, 255));
}
// if returned null everything is OK
$unpacker = new MessagePackUnpacker();
$unpacker->feed($serialized);
if ($unpacker->execute())
{
if (($unserialized = $unpacker->data()) === null) {
return true;
}
$unpacker->reset();
}
else
{
return true;
}
// whole data is read?
if ($serialized !== msgpack_serialize($unserialized)) {
return true;
}
echo bin2hex($serialized), "\n";
var_dump($unserialized);
return false;
}
mt_srand(0x4c05b583);
for ($i = 0; $i < 100; ++$i) {
if (!test()) break;
}
?>
--EXPECT--

52
php/tests/040d.phpt Normal file
View file

@ -0,0 +1,52 @@
--TEST--
broken random data test : MessagePackUnpacker::execute
--SKIPIF--
--FILE--
<?php
if(!extension_loaded('msgpack')) {
dl('msgpack.' . PHP_SHLIB_SUFFIX);
}
error_reporting(E_ERROR | E_PARSE);
function test() {
$serialized = msgpack_serialize(null);
$serialized = substr($serialized, 0, -1);
$length = mt_rand(1, 255);
for ($i = 0; $i < $length; ++$i) {
$serialized .= chr(mt_rand(0, 255));
}
// if returned null everything is OK
$unpacker = new MessagePackUnpacker();
if ($unpacker->execute($serialized, $offset))
{
if (($unserialized = $unpacker->data()) === null) {
return true;
}
$unpacker->reset();
}
else
{
return true;
}
// whole data is read?
if ($serialized !== msgpack_serialize($unserialized)) {
return true;
}
echo bin2hex($serialized), "\n";
var_dump($unserialized);
return false;
}
mt_srand(0x4c05b583);
for ($i = 0; $i < 100; ++$i) {
if (!test()) break;
}
?>
--EXPECT--

View file

@ -2,8 +2,10 @@
Check for buffered streaming unserialization
--SKIPIF--
<?php
if (version_compare(PHP_VERSION, '5.3.2') <= 0) {
echo "skip tests in PHP 5.3.3 or newer";
if ((version_compare(PHP_VERSION, '5.2.13') <= 0) ||
(version_compare(PHP_VERSION, '5.3.0') >= 0 &&
version_compare(PHP_VERSION, '5.3.2') <= 0)) {
echo "skip tests in PHP 5.2.14/5.3.3 or newer";
}
--FILE--
<?php

View file

@ -2,8 +2,13 @@
Check for buffered streaming unserialization
--SKIPIF--
<?php
if (version_compare(PHP_VERSION, '5.3.3') >= 0) {
echo "skip tests in PHP 5.3.2 or older";
if ((version_compare(PHP_VERSION, '5.3.0') < 0 &&
version_compare(PHP_VERSION, '5.2.14') >= 0) ||
(version_compare(PHP_VERSION, '5.3.3') >= 0)) {
echo "skip tests in PHP 5.2.13/5.3.2 or older";
}
if (version_compare(PHP_VERSION, '5.2.0') < 0) {
echo "skip tests in PHP 5.2 or newer";
}
--FILE--
<?php

319
php/tests/060c.phpt Normal file
View file

@ -0,0 +1,319 @@
--TEST--
Check for buffered streaming unserialization
--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);
}
function test($type, $variable, $test = null) {
$serialized = msgpack_serialize($variable);
$unpacker = new MessagePackUnpacker();
$length = strlen($serialized);
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;
}
if (!is_bool($test))
{
echo $unserialized === $variable ? 'OK' : 'ERROR', PHP_EOL;
}
else
{
echo $test || $unserialized == $variable ? 'OK' : 'ERROR', PHP_EOL;
}
}
test('null', null);
test('bool: true', true);
test('bool: false', false);
test('zero: 0', 0);
test('small: 1', 1);
test('small: -1', -1);
test('medium: 1000', 1000);
test('medium: -1000', -1000);
test('large: 100000', 100000);
test('large: -100000', -100000);
test('double: 123.456', 123.456);
test('empty: ""', "");
test('string: "foobar"', "foobar");
test('array', array(), false);
test('array(1, 2, 3)', array(1, 2, 3), false);
test('array(array(1, 2, 3), arr...', array(array(1, 2, 3), array(4, 5, 6), array(7, 8, 9)), false);
test('array("foo", "foo", "foo")', array("foo", "foo", "foo"), false);
test('array("one" => 1, "two" => 2))', array("one" => 1, "two" => 2), false);
test('array("kek" => "lol", "lol" => "kek")', array("kek" => "lol", "lol" => "kek"), false);
test('array("" => "empty")', array("" => "empty"), false);
$a = array('foo');
test('array($a, $a)', array($a, $a), false);
test('array(&$a, &$a)', array(&$a, &$a), false);
$a = array(null);
$b = array(&$a);
$a[0] = &$b;
test('cyclic', $a, true);
$a = array(
'a' => array(
'b' => 'c',
'd' => 'e'
),
'f' => array(
'g' => 'h'
)
);
test('array', $a, false);
class Obj {
public $a;
protected $b;
private $c;
function __construct($a, $b, $c) {
$this->a = $a;
$this->b = $b;
$this->c = $c;
}
}
test('object', new Obj(1, 2, 3), false);
test('object', array(new Obj(1, 2, 3), new Obj(4, 5, 6)), false);
$o = new Obj(1, 2, 3);
test('object', array(&$o, &$o), false);
--EXPECTF--
NULL
OK
bool(true)
OK
bool(false)
OK
int(0)
OK
int(1)
OK
int(-1)
OK
int(1000)
OK
int(-1000)
OK
int(100000)
OK
int(-100000)
OK
float(123.456)
OK
string(0) ""
OK
string(6) "foobar"
OK
array(0) {
}
OK
array(3) {
[0]=>
int(1)
[1]=>
int(2)
[2]=>
int(3)
}
OK
array(3) {
[0]=>
array(3) {
[0]=>
int(1)
[1]=>
int(2)
[2]=>
int(3)
}
[1]=>
array(3) {
[0]=>
int(4)
[1]=>
int(5)
[2]=>
int(6)
}
[2]=>
array(3) {
[0]=>
int(7)
[1]=>
int(8)
[2]=>
int(9)
}
}
OK
array(3) {
[0]=>
string(3) "foo"
[1]=>
string(3) "foo"
[2]=>
string(3) "foo"
}
OK
array(2) {
["one"]=>
int(1)
["two"]=>
int(2)
}
OK
array(2) {
["kek"]=>
string(3) "lol"
["lol"]=>
string(3) "kek"
}
OK
array(1) {
[""]=>
string(5) "empty"
}
OK
array(2) {
[0]=>
array(1) {
[0]=>
string(3) "foo"
}
[1]=>
array(1) {
[0]=>
string(3) "foo"
}
}
OK
array(2) {
[0]=>
&array(1) {
[0]=>
string(3) "foo"
}
[1]=>
&array(1) {
[0]=>
string(3) "foo"
}
}
OK
array(1) {
[0]=>
&array(1) {
[0]=>
&array(1) {
[0]=>
&array(1) {
[0]=>
&array(1) {
[0]=>
*RECURSION*
}
}
}
}
}
OK
array(2) {
["a"]=>
array(2) {
["b"]=>
string(1) "c"
["d"]=>
string(1) "e"
}
["f"]=>
array(1) {
["g"]=>
string(1) "h"
}
}
OK
object(Obj)#%d (3) {
["a"]=>
int(1)
["b:protected"]=>
int(2)
["c:private"]=>
int(3)
}
OK
array(2) {
[0]=>
object(Obj)#%d (3) {
["a"]=>
int(1)
["b:protected"]=>
int(2)
["c:private"]=>
int(3)
}
[1]=>
object(Obj)#%d (3) {
["a"]=>
int(4)
["b:protected"]=>
int(5)
["c:private"]=>
int(6)
}
}
OK
array(2) {
[0]=>
&object(Obj)#%d (3) {
["a"]=>
int(1)
["b:protected"]=>
int(2)
["c:private"]=>
int(3)
}
[1]=>
&object(Obj)#%d (3) {
["a"]=>
int(1)
["b:protected"]=>
int(2)
["c:private"]=>
int(3)
}
}
OK

View file

@ -2,8 +2,10 @@
Check for unbuffered streaming unserialization
--SKIPIF--
<?php
if (version_compare(PHP_VERSION, '5.3.2') <= 0) {
echo "skip tests in PHP 5.3.3 or newer";
if ((version_compare(PHP_VERSION, '5.2.13') <= 0) ||
(version_compare(PHP_VERSION, '5.3.0') >= 0 &&
version_compare(PHP_VERSION, '5.3.2') <= 0)) {
echo "skip tests in PHP 5.2.14/5.3.3 or newer";
}
--FILE--
<?php

View file

@ -2,8 +2,13 @@
Check for unbuffered streaming unserialization
--SKIPIF--
<?php
if (version_compare(PHP_VERSION, '5.3.3') >= 0) {
echo "skip tests in PHP 5.3.2 or older";
if ((version_compare(PHP_VERSION, '5.3.0') < 0 &&
version_compare(PHP_VERSION, '5.2.14') >= 0) ||
(version_compare(PHP_VERSION, '5.3.3') >= 0)) {
echo "skip tests in PHP 5.2.13/5.3.2 or older";
}
if (version_compare(PHP_VERSION, '5.2.0') < 0) {
echo "skip tests in PHP 5.2 or newer";
}
--FILE--
<?php

324
php/tests/061c.phpt Normal file
View file

@ -0,0 +1,324 @@
--TEST--
Check for unbuffered streaming unserialization
--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);
}
function test($type, $variable, $test = null) {
$serialized = msgpack_serialize($variable);
$unpacker = new MessagePackUnpacker();
$length = strlen($serialized);
$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), false);
test('object', array(new Obj(1, 2, 3), new Obj(4, 5, 6)), false);
$o = new Obj(1, 2, 3);
test('object', array(&$o, &$o), false);
--EXPECTF--
NULL
OK
bool(true)
OK
bool(false)
OK
int(0)
OK
int(1)
OK
int(-1)
OK
int(1000)
OK
int(-1000)
OK
int(100000)
OK
int(-100000)
OK
float(123.456)
OK
string(0) ""
OK
string(6) "foobar"
OK
array(0) {
}
OK
array(3) {
[0]=>
int(1)
[1]=>
int(2)
[2]=>
int(3)
}
OK
array(3) {
[0]=>
array(3) {
[0]=>
int(1)
[1]=>
int(2)
[2]=>
int(3)
}
[1]=>
array(3) {
[0]=>
int(4)
[1]=>
int(5)
[2]=>
int(6)
}
[2]=>
array(3) {
[0]=>
int(7)
[1]=>
int(8)
[2]=>
int(9)
}
}
OK
array(3) {
[0]=>
string(3) "foo"
[1]=>
string(3) "foo"
[2]=>
string(3) "foo"
}
OK
array(2) {
["one"]=>
int(1)
["two"]=>
int(2)
}
OK
array(2) {
["kek"]=>
string(3) "lol"
["lol"]=>
string(3) "kek"
}
OK
array(1) {
[""]=>
string(5) "empty"
}
OK
array(2) {
[0]=>
array(1) {
[0]=>
string(3) "foo"
}
[1]=>
array(1) {
[0]=>
string(3) "foo"
}
}
OK
array(2) {
[0]=>
&array(1) {
[0]=>
string(3) "foo"
}
[1]=>
&array(1) {
[0]=>
string(3) "foo"
}
}
OK
array(1) {
[0]=>
&array(1) {
[0]=>
&array(1) {
[0]=>
&array(1) {
[0]=>
&array(1) {
[0]=>
*RECURSION*
}
}
}
}
}
OK
array(2) {
["a"]=>
array(2) {
["b"]=>
string(1) "c"
["d"]=>
string(1) "e"
}
["f"]=>
array(1) {
["g"]=>
string(1) "h"
}
}
OK
object(Obj)#%d (3) {
["a"]=>
int(1)
["b:protected"]=>
int(2)
["c:private"]=>
int(3)
}
OK
array(2) {
[0]=>
object(Obj)#%d (3) {
["a"]=>
int(1)
["b:protected"]=>
int(2)
["c:private"]=>
int(3)
}
[1]=>
object(Obj)#%d (3) {
["a"]=>
int(4)
["b:protected"]=>
int(5)
["c:private"]=>
int(6)
}
}
OK
array(2) {
[0]=>
&object(Obj)#%d (3) {
["a"]=>
int(1)
["b:protected"]=>
int(2)
["c:private"]=>
int(3)
}
[1]=>
&object(Obj)#%d (3) {
["a"]=>
int(1)
["b:protected"]=>
int(2)
["c:private"]=>
int(3)
}
}
OK

View file

@ -2,8 +2,10 @@
Check for buffered streaming unserialization (single)
--SKIPIF--
<?php
if (version_compare(PHP_VERSION, '5.3.2') <= 0) {
echo "skip tests in PHP 5.3.3 or newer";
if ((version_compare(PHP_VERSION, '5.2.13') <= 0) ||
(version_compare(PHP_VERSION, '5.3.0') >= 0 &&
version_compare(PHP_VERSION, '5.3.2') <= 0)) {
echo "skip tests in PHP 5.2.14/5.3.3 or newer";
}
--FILE--
<?php

View file

@ -2,8 +2,13 @@
Check for buffered streaming unserialization (single)
--SKIPIF--
<?php
if (version_compare(PHP_VERSION, '5.3.3') >= 0) {
echo "skip tests in PHP 5.3.2 or older";
if ((version_compare(PHP_VERSION, '5.3.0') < 0 &&
version_compare(PHP_VERSION, '5.2.14') >= 0) ||
(version_compare(PHP_VERSION, '5.3.3') >= 0)) {
echo "skip tests in PHP 5.2.13/5.3.2 or older";
}
if (version_compare(PHP_VERSION, '5.2.0') < 0) {
echo "skip tests in PHP 5.2 or newer";
}
--FILE--
<?php

321
php/tests/064c.phpt Normal file
View file

@ -0,0 +1,321 @@
--TEST--
Check for buffered streaming unserialization (single)
--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);
}
$unpacker = new MessagePackUnpacker();
function test($type, $variable, $test = null) {
$serialized = msgpack_serialize($variable);
global $unpacker;
$length = strlen($serialized);
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;
}
if (!is_bool($test))
{
echo $unserialized === $variable ? 'OK' : 'ERROR', PHP_EOL;
}
else
{
echo $test || $unserialized == $variable ? 'OK' : 'ERROR', PHP_EOL;
}
}
test('null', null);
test('bool: true', true);
test('bool: false', false);
test('zero: 0', 0);
test('small: 1', 1);
test('small: -1', -1);
test('medium: 1000', 1000);
test('medium: -1000', -1000);
test('large: 100000', 100000);
test('large: -100000', -100000);
test('double: 123.456', 123.456);
test('empty: ""', "");
test('string: "foobar"', "foobar");
test('array', array(), false);
test('array(1, 2, 3)', array(1, 2, 3), false);
test('array(array(1, 2, 3), arr...', array(array(1, 2, 3), array(4, 5, 6), array(7, 8, 9)), false);
test('array("foo", "foo", "foo")', array("foo", "foo", "foo"), false);
test('array("one" => 1, "two" => 2))', array("one" => 1, "two" => 2), false);
test('array("kek" => "lol", "lol" => "kek")', array("kek" => "lol", "lol" => "kek"), false);
test('array("" => "empty")', array("" => "empty"), false);
$a = array('foo');
test('array($a, $a)', array($a, $a), false);
test('array(&$a, &$a)', array(&$a, &$a), false);
$a = array(null);
$b = array(&$a);
$a[0] = &$b;
test('cyclic', $a, true);
$a = array(
'a' => array(
'b' => 'c',
'd' => 'e'
),
'f' => array(
'g' => 'h'
)
);
test('array', $a, false);
class Obj {
public $a;
protected $b;
private $c;
function __construct($a, $b, $c) {
$this->a = $a;
$this->b = $b;
$this->c = $c;
}
}
test('object', new Obj(1, 2, 3), false);
test('object', array(new Obj(1, 2, 3), new Obj(4, 5, 6)), false);
$o = new Obj(1, 2, 3);
test('object', array(&$o, &$o), false);
--EXPECTF--
NULL
OK
bool(true)
OK
bool(false)
OK
int(0)
OK
int(1)
OK
int(-1)
OK
int(1000)
OK
int(-1000)
OK
int(100000)
OK
int(-100000)
OK
float(123.456)
OK
string(0) ""
OK
string(6) "foobar"
OK
array(0) {
}
OK
array(3) {
[0]=>
int(1)
[1]=>
int(2)
[2]=>
int(3)
}
OK
array(3) {
[0]=>
array(3) {
[0]=>
int(1)
[1]=>
int(2)
[2]=>
int(3)
}
[1]=>
array(3) {
[0]=>
int(4)
[1]=>
int(5)
[2]=>
int(6)
}
[2]=>
array(3) {
[0]=>
int(7)
[1]=>
int(8)
[2]=>
int(9)
}
}
OK
array(3) {
[0]=>
string(3) "foo"
[1]=>
string(3) "foo"
[2]=>
string(3) "foo"
}
OK
array(2) {
["one"]=>
int(1)
["two"]=>
int(2)
}
OK
array(2) {
["kek"]=>
string(3) "lol"
["lol"]=>
string(3) "kek"
}
OK
array(1) {
[""]=>
string(5) "empty"
}
OK
array(2) {
[0]=>
array(1) {
[0]=>
string(3) "foo"
}
[1]=>
array(1) {
[0]=>
string(3) "foo"
}
}
OK
array(2) {
[0]=>
&array(1) {
[0]=>
string(3) "foo"
}
[1]=>
&array(1) {
[0]=>
string(3) "foo"
}
}
OK
array(1) {
[0]=>
&array(1) {
[0]=>
&array(1) {
[0]=>
&array(1) {
[0]=>
&array(1) {
[0]=>
*RECURSION*
}
}
}
}
}
OK
array(2) {
["a"]=>
array(2) {
["b"]=>
string(1) "c"
["d"]=>
string(1) "e"
}
["f"]=>
array(1) {
["g"]=>
string(1) "h"
}
}
OK
object(Obj)#%d (3) {
["a"]=>
int(1)
["b:protected"]=>
int(2)
["c:private"]=>
int(3)
}
OK
array(2) {
[0]=>
object(Obj)#%d (3) {
["a"]=>
int(1)
["b:protected"]=>
int(2)
["c:private"]=>
int(3)
}
[1]=>
object(Obj)#%d (3) {
["a"]=>
int(4)
["b:protected"]=>
int(5)
["c:private"]=>
int(6)
}
}
OK
array(2) {
[0]=>
&object(Obj)#%d (3) {
["a"]=>
int(1)
["b:protected"]=>
int(2)
["c:private"]=>
int(3)
}
[1]=>
&object(Obj)#%d (3) {
["a"]=>
int(1)
["b:protected"]=>
int(2)
["c:private"]=>
int(3)
}
}
OK

View file

@ -2,8 +2,10 @@
Check for unbuffered streaming unserialization (single)
--SKIPIF--
<?php
if (version_compare(PHP_VERSION, '5.3.2') <= 0) {
echo "skip tests in PHP 5.3.3 or newer";
if ((version_compare(PHP_VERSION, '5.2.13') <= 0) ||
(version_compare(PHP_VERSION, '5.3.0') >= 0 &&
version_compare(PHP_VERSION, '5.3.2') <= 0)) {
echo "skip tests in PHP 5.2.14/5.3.3 or newer";
}
--FILE--
<?php

View file

@ -2,8 +2,13 @@
Check for unbuffered streaming unserialization (single)
--SKIPIF--
<?php
if (version_compare(PHP_VERSION, '5.3.3') >= 0) {
echo "skip tests in PHP 5.3.2 or older";
if ((version_compare(PHP_VERSION, '5.3.0') < 0 &&
version_compare(PHP_VERSION, '5.2.14') >= 0) ||
(version_compare(PHP_VERSION, '5.3.3') >= 0)) {
echo "skip tests in PHP 5.2.13/5.3.2 or older";
}
if (version_compare(PHP_VERSION, '5.2.0') < 0) {
echo "skip tests in PHP 5.2 or newer";
}
--FILE--
<?php

326
php/tests/065c.phpt Normal file
View file

@ -0,0 +1,326 @@
--TEST--
Check for unbuffered streaming unserialization (single)
--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);
}
$unpacker = new MessagePackUnpacker();
function test($type, $variable, $test = null) {
$serialized = msgpack_serialize($variable);
global $unpacker;
$length = strlen($serialized);
$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), false);
test('object', array(new Obj(1, 2, 3), new Obj(4, 5, 6)), false);
$o = new Obj(1, 2, 3);
test('object', array(&$o, &$o), false);
--EXPECTF--
NULL
OK
bool(true)
OK
bool(false)
OK
int(0)
OK
int(1)
OK
int(-1)
OK
int(1000)
OK
int(-1000)
OK
int(100000)
OK
int(-100000)
OK
float(123.456)
OK
string(0) ""
OK
string(6) "foobar"
OK
array(0) {
}
OK
array(3) {
[0]=>
int(1)
[1]=>
int(2)
[2]=>
int(3)
}
OK
array(3) {
[0]=>
array(3) {
[0]=>
int(1)
[1]=>
int(2)
[2]=>
int(3)
}
[1]=>
array(3) {
[0]=>
int(4)
[1]=>
int(5)
[2]=>
int(6)
}
[2]=>
array(3) {
[0]=>
int(7)
[1]=>
int(8)
[2]=>
int(9)
}
}
OK
array(3) {
[0]=>
string(3) "foo"
[1]=>
string(3) "foo"
[2]=>
string(3) "foo"
}
OK
array(2) {
["one"]=>
int(1)
["two"]=>
int(2)
}
OK
array(2) {
["kek"]=>
string(3) "lol"
["lol"]=>
string(3) "kek"
}
OK
array(1) {
[""]=>
string(5) "empty"
}
OK
array(2) {
[0]=>
array(1) {
[0]=>
string(3) "foo"
}
[1]=>
array(1) {
[0]=>
string(3) "foo"
}
}
OK
array(2) {
[0]=>
&array(1) {
[0]=>
string(3) "foo"
}
[1]=>
&array(1) {
[0]=>
string(3) "foo"
}
}
OK
array(1) {
[0]=>
&array(1) {
[0]=>
&array(1) {
[0]=>
&array(1) {
[0]=>
&array(1) {
[0]=>
*RECURSION*
}
}
}
}
}
OK
array(2) {
["a"]=>
array(2) {
["b"]=>
string(1) "c"
["d"]=>
string(1) "e"
}
["f"]=>
array(1) {
["g"]=>
string(1) "h"
}
}
OK
object(Obj)#%d (3) {
["a"]=>
int(1)
["b:protected"]=>
int(2)
["c:private"]=>
int(3)
}
OK
array(2) {
[0]=>
object(Obj)#%d (3) {
["a"]=>
int(1)
["b:protected"]=>
int(2)
["c:private"]=>
int(3)
}
[1]=>
object(Obj)#%d (3) {
["a"]=>
int(4)
["b:protected"]=>
int(5)
["c:private"]=>
int(6)
}
}
OK
array(2) {
[0]=>
&object(Obj)#%d (3) {
["a"]=>
int(1)
["b:protected"]=>
int(2)
["c:private"]=>
int(3)
}
[1]=>
&object(Obj)#%d (3) {
["a"]=>
int(1)
["b:protected"]=>
int(2)
["c:private"]=>
int(3)
}
}
OK

View file

@ -2,8 +2,10 @@
Check for alias functions
--SKIPIF--
<?php
if (version_compare(PHP_VERSION, '5.3.2') <= 0) {
echo "skip tests in PHP 5.3.3 or newer";
if ((version_compare(PHP_VERSION, '5.2.13') <= 0) ||
(version_compare(PHP_VERSION, '5.3.0') >= 0 &&
version_compare(PHP_VERSION, '5.3.2') <= 0)) {
echo "skip tests in PHP 5.2.14/5.3.3 or newer";
}
--FILE--
<?php

View file

@ -2,8 +2,13 @@
Check for alias functions
--SKIPIF--
<?php
if (version_compare(PHP_VERSION, '5.3.3') >= 0) {
echo "skip tests in PHP 5.3.2 or older";
if ((version_compare(PHP_VERSION, '5.3.0') < 0 &&
version_compare(PHP_VERSION, '5.2.14') >= 0) ||
(version_compare(PHP_VERSION, '5.3.3') >= 0)) {
echo "skip tests in PHP 5.2.13/5.3.2 or older";
}
if (version_compare(PHP_VERSION, '5.2.0') < 0) {
echo "skip tests in PHP 5.2 or newer";
}
--FILE--
<?php

303
php/tests/070c.phpt Normal file
View file

@ -0,0 +1,303 @@
--TEST--
Check for alias functions
--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);
}
function test($type, $variable, $test = null) {
$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), false);
test('object', array(new Obj(1, 2, 3), new Obj(4, 5, 6)), false);
$o = new Obj(1, 2, 3);
test('object', array(&$o, &$o), false);
--EXPECTF--
NULL
OK
bool(true)
OK
bool(false)
OK
int(0)
OK
int(1)
OK
int(-1)
OK
int(1000)
OK
int(-1000)
OK
int(100000)
OK
int(-100000)
OK
float(123.456)
OK
string(0) ""
OK
string(6) "foobar"
OK
array(0) {
}
OK
array(3) {
[0]=>
int(1)
[1]=>
int(2)
[2]=>
int(3)
}
OK
array(3) {
[0]=>
array(3) {
[0]=>
int(1)
[1]=>
int(2)
[2]=>
int(3)
}
[1]=>
array(3) {
[0]=>
int(4)
[1]=>
int(5)
[2]=>
int(6)
}
[2]=>
array(3) {
[0]=>
int(7)
[1]=>
int(8)
[2]=>
int(9)
}
}
OK
array(3) {
[0]=>
string(3) "foo"
[1]=>
string(3) "foo"
[2]=>
string(3) "foo"
}
OK
array(2) {
["one"]=>
int(1)
["two"]=>
int(2)
}
OK
array(2) {
["kek"]=>
string(3) "lol"
["lol"]=>
string(3) "kek"
}
OK
array(1) {
[""]=>
string(5) "empty"
}
OK
array(2) {
[0]=>
array(1) {
[0]=>
string(3) "foo"
}
[1]=>
array(1) {
[0]=>
string(3) "foo"
}
}
OK
array(2) {
[0]=>
&array(1) {
[0]=>
string(3) "foo"
}
[1]=>
&array(1) {
[0]=>
string(3) "foo"
}
}
OK
array(1) {
[0]=>
&array(1) {
[0]=>
&array(1) {
[0]=>
&array(1) {
[0]=>
&array(1) {
[0]=>
*RECURSION*
}
}
}
}
}
OK
array(2) {
["a"]=>
array(2) {
["b"]=>
string(1) "c"
["d"]=>
string(1) "e"
}
["f"]=>
array(1) {
["g"]=>
string(1) "h"
}
}
OK
object(Obj)#%d (3) {
["a"]=>
int(1)
["b:protected"]=>
int(2)
["c:private"]=>
int(3)
}
OK
array(2) {
[0]=>
object(Obj)#%d (3) {
["a"]=>
int(1)
["b:protected"]=>
int(2)
["c:private"]=>
int(3)
}
[1]=>
object(Obj)#%d (3) {
["a"]=>
int(4)
["b:protected"]=>
int(5)
["c:private"]=>
int(6)
}
}
OK
array(2) {
[0]=>
&object(Obj)#%d (3) {
["a"]=>
int(1)
["b:protected"]=>
int(2)
["c:private"]=>
int(3)
}
[1]=>
&object(Obj)#%d (3) {
["a"]=>
int(1)
["b:protected"]=>
int(2)
["c:private"]=>
int(3)
}
}
OK

View file

@ -2,8 +2,10 @@
Check for class methods
--SKIPIF--
<?php
if (version_compare(PHP_VERSION, '5.3.2') <= 0) {
echo "skip tests in PHP 5.3.3 or newer";
if ((version_compare(PHP_VERSION, '5.2.13') <= 0) ||
(version_compare(PHP_VERSION, '5.3.0') >= 0 &&
version_compare(PHP_VERSION, '5.3.2') <= 0)) {
echo "skip tests in PHP 5.2.14/5.3.3 or newer";
}
--FILE--
<?php

View file

@ -2,8 +2,13 @@
Check for class methods
--SKIPIF--
<?php
if (version_compare(PHP_VERSION, '5.3.3') >= 0) {
echo "skip tests in PHP 5.3.2 or older";
if ((version_compare(PHP_VERSION, '5.3.0') < 0 &&
version_compare(PHP_VERSION, '5.2.14') >= 0) ||
(version_compare(PHP_VERSION, '5.3.3') >= 0)) {
echo "skip tests in PHP 5.2.13/5.3.2 or older";
}
if (version_compare(PHP_VERSION, '5.2.0') < 0) {
echo "skip tests in PHP 5.2 or newer";
}
--FILE--
<?php

305
php/tests/071c.phpt Normal file
View file

@ -0,0 +1,305 @@
--TEST--
Check for class methods
--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);
}
function test($type, $variable, $test = null) {
$msgpack = new MessagePack();
$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), false);
test('object', array(new Obj(1, 2, 3), new Obj(4, 5, 6)), false);
$o = new Obj(1, 2, 3);
test('object', array(&$o, &$o), false);
--EXPECTF--
NULL
OK
bool(true)
OK
bool(false)
OK
int(0)
OK
int(1)
OK
int(-1)
OK
int(1000)
OK
int(-1000)
OK
int(100000)
OK
int(-100000)
OK
float(123.456)
OK
string(0) ""
OK
string(6) "foobar"
OK
array(0) {
}
OK
array(3) {
[0]=>
int(1)
[1]=>
int(2)
[2]=>
int(3)
}
OK
array(3) {
[0]=>
array(3) {
[0]=>
int(1)
[1]=>
int(2)
[2]=>
int(3)
}
[1]=>
array(3) {
[0]=>
int(4)
[1]=>
int(5)
[2]=>
int(6)
}
[2]=>
array(3) {
[0]=>
int(7)
[1]=>
int(8)
[2]=>
int(9)
}
}
OK
array(3) {
[0]=>
string(3) "foo"
[1]=>
string(3) "foo"
[2]=>
string(3) "foo"
}
OK
array(2) {
["one"]=>
int(1)
["two"]=>
int(2)
}
OK
array(2) {
["kek"]=>
string(3) "lol"
["lol"]=>
string(3) "kek"
}
OK
array(1) {
[""]=>
string(5) "empty"
}
OK
array(2) {
[0]=>
array(1) {
[0]=>
string(3) "foo"
}
[1]=>
array(1) {
[0]=>
string(3) "foo"
}
}
OK
array(2) {
[0]=>
&array(1) {
[0]=>
string(3) "foo"
}
[1]=>
&array(1) {
[0]=>
string(3) "foo"
}
}
OK
array(1) {
[0]=>
&array(1) {
[0]=>
&array(1) {
[0]=>
&array(1) {
[0]=>
&array(1) {
[0]=>
*RECURSION*
}
}
}
}
}
OK
array(2) {
["a"]=>
array(2) {
["b"]=>
string(1) "c"
["d"]=>
string(1) "e"
}
["f"]=>
array(1) {
["g"]=>
string(1) "h"
}
}
OK
object(Obj)#%d (3) {
["a"]=>
int(1)
["b:protected"]=>
int(2)
["c:private"]=>
int(3)
}
OK
array(2) {
[0]=>
object(Obj)#%d (3) {
["a"]=>
int(1)
["b:protected"]=>
int(2)
["c:private"]=>
int(3)
}
[1]=>
object(Obj)#%d (3) {
["a"]=>
int(4)
["b:protected"]=>
int(5)
["c:private"]=>
int(6)
}
}
OK
array(2) {
[0]=>
&object(Obj)#%d (3) {
["a"]=>
int(1)
["b:protected"]=>
int(2)
["c:private"]=>
int(3)
}
[1]=>
&object(Obj)#%d (3) {
["a"]=>
int(1)
["b:protected"]=>
int(2)
["c:private"]=>
int(3)
}
}
OK

View file

@ -2,8 +2,10 @@
Check for class methods unpacker
--SKIPIF--
<?php
if (version_compare(PHP_VERSION, '5.3.2') <= 0) {
echo "skip tests in PHP 5.3.3 or newer";
if ((version_compare(PHP_VERSION, '5.2.13') <= 0) ||
(version_compare(PHP_VERSION, '5.3.0') >= 0 &&
version_compare(PHP_VERSION, '5.3.2') <= 0)) {
echo "skip tests in PHP 5.2.14/5.3.3 or newer";
}
--FILE--
<?php

View file

@ -2,8 +2,13 @@
Check for class methods unpacker
--SKIPIF--
<?php
if (version_compare(PHP_VERSION, '5.3.3') >= 0) {
echo "skip tests in PHP 5.3.2 or older";
if ((version_compare(PHP_VERSION, '5.3.0') < 0 &&
version_compare(PHP_VERSION, '5.2.14') >= 0) ||
(version_compare(PHP_VERSION, '5.3.3') >= 0)) {
echo "skip tests in PHP 5.2.13/5.3.2 or older";
}
if (version_compare(PHP_VERSION, '5.2.0') < 0) {
echo "skip tests in PHP 5.2 or newer";
}
--FILE--
<?php

345
php/tests/072c.phpt Normal file
View file

@ -0,0 +1,345 @@
--TEST--
Check for class methods unpacker
--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);
}
function test($type, $variable, $test = null) {
$msgpack = new MessagePack();
$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), false);
test('object', array(new Obj(1, 2, 3), new Obj(4, 5, 6)), false);
$o = new Obj(1, 2, 3);
test('object', array(&$o, &$o), false);
--EXPECTF--
NULL
OK
bool(true)
OK
bool(false)
OK
int(0)
OK
int(1)
OK
int(-1)
OK
int(1000)
OK
int(-1000)
OK
int(100000)
OK
int(-100000)
OK
float(123.456)
OK
string(0) ""
OK
string(6) "foobar"
OK
array(0) {
}
OK
array(3) {
[0]=>
int(1)
[1]=>
int(2)
[2]=>
int(3)
}
OK
array(3) {
[0]=>
array(3) {
[0]=>
int(1)
[1]=>
int(2)
[2]=>
int(3)
}
[1]=>
array(3) {
[0]=>
int(4)
[1]=>
int(5)
[2]=>
int(6)
}
[2]=>
array(3) {
[0]=>
int(7)
[1]=>
int(8)
[2]=>
int(9)
}
}
OK
array(3) {
[0]=>
string(3) "foo"
[1]=>
string(3) "foo"
[2]=>
string(3) "foo"
}
OK
array(2) {
["one"]=>
int(1)
["two"]=>
int(2)
}
OK
array(2) {
["kek"]=>
string(3) "lol"
["lol"]=>
string(3) "kek"
}
OK
array(1) {
[""]=>
string(5) "empty"
}
OK
array(2) {
[0]=>
array(1) {
[0]=>
string(3) "foo"
}
[1]=>
array(1) {
[0]=>
string(3) "foo"
}
}
OK
array(2) {
[0]=>
&array(1) {
[0]=>
string(3) "foo"
}
[1]=>
&array(1) {
[0]=>
string(3) "foo"
}
}
OK
array(1) {
[0]=>
&array(1) {
[0]=>
&array(1) {
[0]=>
&array(1) {
[0]=>
&array(1) {
[0]=>
*RECURSION*
}
}
}
}
}
OK
array(2) {
["a"]=>
array(2) {
["b"]=>
string(1) "c"
["d"]=>
string(1) "e"
}
["f"]=>
array(1) {
["g"]=>
string(1) "h"
}
}
OK
object(Obj)#%d (3) {
["a"]=>
int(1)
["b:protected"]=>
int(2)
["c:private"]=>
int(3)
}
OK
array(2) {
[0]=>
object(Obj)#%d (3) {
["a"]=>
int(1)
["b:protected"]=>
int(2)
["c:private"]=>
int(3)
}
[1]=>
object(Obj)#%d (3) {
["a"]=>
int(4)
["b:protected"]=>
int(5)
["c:private"]=>
int(6)
}
}
OK
array(2) {
[0]=>
&object(Obj)#%d (3) {
["a"]=>
int(1)
["b:protected"]=>
int(2)
["c:private"]=>
int(3)
}
[1]=>
&object(Obj)#%d (3) {
["a"]=>
int(1)
["b:protected"]=>
int(2)
["c:private"]=>
int(3)
}
}
OK

View file

@ -2,8 +2,10 @@
Check for class unpacker
--SKIPIF--
<?php
if (version_compare(PHP_VERSION, '5.3.2') <= 0) {
echo "skip tests in PHP 5.3.3 or newer";
if ((version_compare(PHP_VERSION, '5.2.13') <= 0) ||
(version_compare(PHP_VERSION, '5.3.0') >= 0 &&
version_compare(PHP_VERSION, '5.3.2') <= 0)) {
echo "skip tests in PHP 5.2.14/5.3.3 or newer";
}
--FILE--
<?php

View file

@ -2,8 +2,13 @@
Check for class unpacker
--SKIPIF--
<?php
if (version_compare(PHP_VERSION, '5.3.3') >= 0) {
echo "skip tests in PHP 5.3.2 or older";
if ((version_compare(PHP_VERSION, '5.3.0') < 0 &&
version_compare(PHP_VERSION, '5.2.14') >= 0) ||
(version_compare(PHP_VERSION, '5.3.3') >= 0)) {
echo "skip tests in PHP 5.2.13/5.3.2 or older";
}
if (version_compare(PHP_VERSION, '5.2.0') < 0) {
echo "skip tests in PHP 5.2 or newer";
}
--FILE--
<?php

346
php/tests/073c.phpt Normal file
View file

@ -0,0 +1,346 @@
--TEST--
Check for class unpacker
--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);
}
function test($type, $variable, $test = null) {
$msgpack = new MessagePack();
$serialized = $msgpack->pack($variable);
$unpacker = new MessagePackUnpacker();
$length = strlen($serialized);
if (rand(0, 1))
{
for ($i = 0; $i < $length;) {
$len = rand(1, 10);
$str = substr($serialized, $i, $len);
$unpacker->feed($str);
if ($unpacker->execute())
{
$unserialized = $unpacker->data();
var_dump($unserialized);
$unpacker->reset();
}
$i += $len;
}
}
else
{
$str = "";
$offset = 0;
for ($i = 0; $i < $length;) {
$len = rand(1, 10);
$str .= substr($serialized, $i, $len);
if ($unpacker->execute($str, $offset))
{
$unserialized = $unpacker->data();
var_dump($unserialized);
$unpacker->reset();
$str = "";
$offset = 0;
}
$i += $len;
}
}
if (!is_bool($test))
{
echo $unserialized === $variable ? 'OK' : 'ERROR', PHP_EOL;
}
else
{
echo $test || $unserialized == $variable ? 'OK' : 'ERROR', PHP_EOL;
}
}
test('null', null);
test('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), false);
test('object', array(new Obj(1, 2, 3), new Obj(4, 5, 6)), false);
$o = new Obj(1, 2, 3);
test('object', array(&$o, &$o), false);
--EXPECTF--
NULL
OK
bool(true)
OK
bool(false)
OK
int(0)
OK
int(1)
OK
int(-1)
OK
int(1000)
OK
int(-1000)
OK
int(100000)
OK
int(-100000)
OK
float(123.456)
OK
string(0) ""
OK
string(6) "foobar"
OK
array(0) {
}
OK
array(3) {
[0]=>
int(1)
[1]=>
int(2)
[2]=>
int(3)
}
OK
array(3) {
[0]=>
array(3) {
[0]=>
int(1)
[1]=>
int(2)
[2]=>
int(3)
}
[1]=>
array(3) {
[0]=>
int(4)
[1]=>
int(5)
[2]=>
int(6)
}
[2]=>
array(3) {
[0]=>
int(7)
[1]=>
int(8)
[2]=>
int(9)
}
}
OK
array(3) {
[0]=>
string(3) "foo"
[1]=>
string(3) "foo"
[2]=>
string(3) "foo"
}
OK
array(2) {
["one"]=>
int(1)
["two"]=>
int(2)
}
OK
array(2) {
["kek"]=>
string(3) "lol"
["lol"]=>
string(3) "kek"
}
OK
array(1) {
[""]=>
string(5) "empty"
}
OK
array(2) {
[0]=>
array(1) {
[0]=>
string(3) "foo"
}
[1]=>
array(1) {
[0]=>
string(3) "foo"
}
}
OK
array(2) {
[0]=>
&array(1) {
[0]=>
string(3) "foo"
}
[1]=>
&array(1) {
[0]=>
string(3) "foo"
}
}
OK
array(1) {
[0]=>
&array(1) {
[0]=>
&array(1) {
[0]=>
&array(1) {
[0]=>
&array(1) {
[0]=>
*RECURSION*
}
}
}
}
}
OK
array(2) {
["a"]=>
array(2) {
["b"]=>
string(1) "c"
["d"]=>
string(1) "e"
}
["f"]=>
array(1) {
["g"]=>
string(1) "h"
}
}
OK
object(Obj)#%d (3) {
["a"]=>
int(1)
["b:protected"]=>
int(2)
["c:private"]=>
int(3)
}
OK
array(2) {
[0]=>
object(Obj)#%d (3) {
["a"]=>
int(1)
["b:protected"]=>
int(2)
["c:private"]=>
int(3)
}
[1]=>
object(Obj)#%d (3) {
["a"]=>
int(4)
["b:protected"]=>
int(5)
["c:private"]=>
int(6)
}
}
OK
array(2) {
[0]=>
&object(Obj)#%d (3) {
["a"]=>
int(1)
["b:protected"]=>
int(2)
["c:private"]=>
int(3)
}
[1]=>
&object(Obj)#%d (3) {
["a"]=>
int(1)
["b:protected"]=>
int(2)
["c:private"]=>
int(3)
}
}
OK

View file

@ -1,6 +1,10 @@
--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')) {

306
php/tests/087d.phpt Normal file
View file

@ -0,0 +1,306 @@
--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,6 +1,10 @@
--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')) {

349
php/tests/088d.phpt Normal file
View file

@ -0,0 +1,349 @@
--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

@ -1,6 +1,10 @@
--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.1 or newer";
}
--FILE--
<?php
if(!extension_loaded('msgpack')) {

351
php/tests/089d.phpt Normal file
View file

@ -0,0 +1,351 @@
--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