Skip to content
This repository has been archived by the owner on May 27, 2022. It is now read-only.

Commit

Permalink
Fix cyclicreference check outputs.
Browse files Browse the repository at this point in the history
  • Loading branch information
tricky committed Jan 2, 2011
1 parent 39c0b36 commit a7a0e2d
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 127 deletions.
55 changes: 13 additions & 42 deletions tests/009.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,32 @@ if(!extension_loaded('igbinary')) {
--FILE--
<?php

function test($type, $variable, $test) {
function test($type, $variable, $test = true) {
$serialized = igbinary_serialize($variable);
$unserialized = igbinary_unserialize($serialized);

echo $type, "\n";
echo substr(bin2hex($serialized), 8), "\n";
echo $test || $unserialized == $variable ? 'OK' : 'ERROR';
echo "\n";
echo !$test || $unserialized == $variable ? 'OK' : 'ERROR', "\n";

$dump_exp = print_r($variable, true);
$dump_act = print_r($unserialized, true);

if ($dump_act !== $dump_exp) {
echo "But var dump differs:\n", $dump_act, "\n", $dump_exp, "\n";
}
}

$a = array('foo');

test('array($a, $a)', array($a, $a), false);
test('array(&$a, &$a)', array(&$a, &$a), false);
test('array($a, $a)', array($a, $a), true);
test('array(&$a, &$a)', array(&$a, &$a), true);

$a = array(null);
$b = array(&$a);
$a[0] = &$b;

test('cyclic', $a, true);

var_dump($a);
var_dump(igbinary_unserialize(igbinary_serialize($a)));
test('cyclic $a = array(&array(&$a))', $a, false);

--EXPECT--
array($a, $a)
Expand All @@ -41,38 +44,6 @@ OK
array(&$a, &$a)
1402060025140106001103666f6f0601250101
OK
cyclic
cyclic $a = array(&array(&$a))
1401060025140106002514010600250101
OK
array(1) {
[0]=>
&array(1) {
[0]=>
&array(1) {
[0]=>
&array(1) {
[0]=>
&array(1) {
[0]=>
*RECURSION*
}
}
}
}
}
array(1) {
[0]=>
&array(1) {
[0]=>
&array(1) {
[0]=>
&array(1) {
[0]=>
&array(1) {
[0]=>
*RECURSION*
}
}
}
}
}
109 changes: 24 additions & 85 deletions tests/026.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ function test($type, $variable, $test) {

echo $type, "\n";
echo substr(bin2hex($serialized), 8), "\n";
echo $test || $unserialized == $variable ? 'OK' : 'ERROR';
echo "\n";
echo !$test || $unserialized == $variable ? 'OK' : 'ERROR', "\n";
}

$a = array(
Expand All @@ -29,96 +28,36 @@ $a = array(

$a['f'] = &$a;

test('array', $a, true);
test('array', $a, false);

$a = array("foo" => &$b);
$b = array(1, 2, $a);
var_dump($a);
//var_dump(unserialize(serialize($a)));
var_dump($k = igbinary_unserialize(igbinary_serialize($a)));

$k["foo"][1] = "b";
var_dump($k);
$exp = $a;
$act = igbinary_unserialize(igbinary_serialize($a));

$dump_exp = print_r($exp, true);
$dump_act = print_r($act, true);

if ($dump_act !== $dump_exp) {
echo "Var dump differs:\n", $dump_act, "\n", $dump_exp, "\n";
} else {
echo "Var dump OK\n";
}

$act['foo'][1] = 'test value';
$exp['foo'][1] = 'test value';
if ($act['foo'][1] !== $act['foo'][2]['foo'][1]) {
echo "Recursive elements differ:\n";
var_dump($act);
var_dump($act['foo']);
var_dump($exp);
var_dump($exp['foo']);
}

/*
* you can add regression tests for your extension here
*
* the output of your test code has to be equal to the
* text in the --EXPECT-- section below for the tests
* to pass, differences between the output and the
* expected text are interpreted as failure
*
* see php5/README.TESTING for further information on
* writing regression tests
*/
?>
--EXPECT--
array
140211016114021101621101631101641101651101662514020e0001010e05250102
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]=>
*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*
}
}
}
}
}
Var dump OK

0 comments on commit a7a0e2d

Please sign in to comment.