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

Commit

Permalink
Merge commit 'tricky/master'
Browse files Browse the repository at this point in the history
* commit 'tricky/master':
  Fixup against NaN
  Add 0 and -0
  Also skip test if mcrypt is not available.
  Closures cannot be serialized.
  Add test for double Inf, -Inf, and NaN.
  Another rm check
  • Loading branch information
phadej committed Mar 15, 2010
2 parents 9d788b5 + 86d850c commit ca73a35
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 1 deletion.
2 changes: 1 addition & 1 deletion tests/035.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Profiling perf test.
--SKIPIF--
<?php
if (!extension_loaded("igbinary")) {
if (!extension_loaded("igbinary") || !extension_loaded("mcrypt")) {
print "skip";
}
if (!isset($_ENV['TEST_PERFORMANCE']) || !$_ENV['TEST_PERFORMANCE']) {
Expand Down
48 changes: 48 additions & 0 deletions tests/041.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
--TEST--
Check for double NaN, Inf, -Inf, 0, and -0
--FILE--
<?php
function test($type, $variable) {
$serialized = igbinary_serialize($variable);
$unserialized = igbinary_unserialize($serialized);

echo $type, ":\n";
var_dump($variable);
var_dump($unserialized);

echo substr(bin2hex($serialized), 8), "\n";
echo "\n";
}

test('double NaN', NAN);
test('double Inf', INF);
test('double -Inf', -INF);
test('double 0.0', 0.0);
test('double -0.0', -0.0);

--EXPECTF--
double NaN:
float(NAN)
float(NAN)
%r0c[7f]ff0*[^0]0*%r

double Inf:
float(INF)
float(INF)
0c7ff0000000000000

double -Inf:
float(-INF)
float(-INF)
0cfff0000000000000

double 0.0:
float(0)
float(0)
0c0000000000000000

double -0.0:
float(0)
float(0)
0c0000000000000000

41 changes: 41 additions & 0 deletions tests/042.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
--TEST--
Closure
--SKIPIF--
<?php
if(!extension_loaded('igbinary')) {
echo "skip no igbinary";
}

if (version_compare(PHP_VERSION, '5.3.0') < 0) {
echo "skip closures only for PHP 5.3.0+";
}
--FILE--
<?php

$closure = function ($x) {
return $x + 1;
};

class Foo implements Serializable {
public function serialize() {
echo "Should not be run.\n";
}

public function unserialize($str) {
echo "Should not be run.\n";
}
}

$array = array($closure, new Foo());

try {
$ser = igbinary_serialize($array);
echo "Serialized closure.\n";
$unser = igbinary_unserialize($ser);
echo "Unserialized closure.\n";
var_dump($unser);
} catch (Exception $e) {
echo "Got exception.\n";
}
--EXPECT--
Got exception.

0 comments on commit ca73a35

Please sign in to comment.