parent
3c89f98296
commit
a54b04118d
18 changed files with 831 additions and 10 deletions
@ -0,0 +1,5 @@ |
||||
<?php |
||||
$cache = []; |
||||
$key = 'hello'; |
||||
$hello = @$cache[$key]; |
||||
var_dump($hello); |
||||
@ -0,0 +1,146 @@ |
||||
--TEST-- |
||||
File type functions |
||||
--SKIPIF-- |
||||
<?php |
||||
if (substr(PHP_OS, 0, 3) == 'WIN') { |
||||
die('skip not for Windows'); |
||||
} |
||||
if (getenv("SKIP_SLOW_TESTS")) die("skip slow test"); |
||||
?> |
||||
--FILE-- |
||||
<?php |
||||
chdir(__DIR__); |
||||
@unlink('test.file'); |
||||
@unlink('test.link'); |
||||
if (file_exists('test.file')) { |
||||
echo "test.file exists\n"; |
||||
} else { |
||||
echo "test.file does not exist\n"; |
||||
} |
||||
fclose (fopen('test.file', 'w')); |
||||
chmod ('test.file', 0744); |
||||
if (file_exists('test.file')) { |
||||
echo "test.file exists\n"; |
||||
} else { |
||||
echo "test.file does not exist\n"; |
||||
} |
||||
sleep (2); |
||||
symlink('test.file','test.link'); |
||||
if (file_exists('test.link')) { |
||||
echo "test.link exists\n"; |
||||
} else { |
||||
echo "test.link does not exist\n"; |
||||
} |
||||
if (is_link('test.file')) { |
||||
echo "test.file is a symlink\n"; |
||||
} else { |
||||
echo "test.file is not a symlink\n"; |
||||
} |
||||
if (is_link('test.link')) { |
||||
echo "test.link is a symlink\n"; |
||||
} else { |
||||
echo "test.link is not a symlink\n"; |
||||
} |
||||
if (file_exists('test.file')) { |
||||
echo "test.file exists\n"; |
||||
} else { |
||||
echo "test.file does not exist\n"; |
||||
} |
||||
$s = stat ('test.file'); |
||||
$ls = lstat ('test.file'); |
||||
for ($i = 0; $i <= 12; $i++) { |
||||
if ($ls[$i] != $s[$i]) { |
||||
echo "test.file lstat and stat differ at element $i\n"; |
||||
} |
||||
} |
||||
$s = stat ('test.link'); |
||||
$ls = lstat ('test.link'); |
||||
for ($i = 0; $i <= 11; $i++) { |
||||
if ($ls[$i] != $s[$i]) { |
||||
if ($i != 6 && $i != 10 && $i != 11) echo "test.link lstat and stat differ at element $i\n"; |
||||
} |
||||
} |
||||
echo "test.file is " . filetype('test.file') . "\n"; |
||||
echo "test.link is " . filetype('test.link') . "\n"; |
||||
printf ("test.file permissions are 0%o\n", 0777 & fileperms('test.file')); |
||||
echo "test.file size is " . filesize('test.file') . "\n"; |
||||
if (is_writeable('test.file')) { |
||||
echo "test.file is writeable\n"; |
||||
} else { |
||||
echo "test.file is not writeable\n"; |
||||
} |
||||
if (is_readable('test.file')) { |
||||
echo "test.file is readable\n"; |
||||
} else { |
||||
echo "test.file is not readable\n"; |
||||
} |
||||
if (is_executable('test.file')) { |
||||
echo "test.file is executable\n"; |
||||
} else { |
||||
echo "test.file is not executable\n"; |
||||
} |
||||
if (is_file('test.file')) { |
||||
echo "test.file is a regular file\n"; |
||||
} else { |
||||
echo "test.file is not a regular file\n"; |
||||
} |
||||
if (is_file('test.link')) { |
||||
echo "test.link is a regular file\n"; |
||||
} else { |
||||
echo "test.link is not a regular file\n"; |
||||
} |
||||
if (is_dir('test.link')) { |
||||
echo "test.link is a directory\n"; |
||||
} else { |
||||
echo "test.link is not a directory\n"; |
||||
} |
||||
if (is_dir('../file')) { |
||||
echo "../file is a directory\n"; |
||||
} else { |
||||
echo "../file is not a directory\n"; |
||||
} |
||||
if (is_dir('test.file')) { |
||||
echo "test.file is a directory\n"; |
||||
} else { |
||||
echo "test.file is not a directory\n"; |
||||
} |
||||
unlink('test.file'); |
||||
unlink('test.link'); |
||||
if (file_exists('test.file')) { |
||||
echo "test.file exists (cached)\n"; |
||||
} else { |
||||
echo "test.file does not exist\n"; |
||||
} |
||||
clearstatcache(); |
||||
if (file_exists('test.file')) { |
||||
echo "test.file exists\n"; |
||||
} else { |
||||
echo "test.file does not exist\n"; |
||||
} |
||||
?> |
||||
--EXPECT-- |
||||
test.file does not exist |
||||
test.file exists |
||||
test.link exists |
||||
test.file is not a symlink |
||||
test.link is a symlink |
||||
test.file exists |
||||
test.link lstat and stat differ at element 1 |
||||
test.link lstat and stat differ at element 2 |
||||
test.link lstat and stat differ at element 7 |
||||
test.link lstat and stat differ at element 8 |
||||
test.link lstat and stat differ at element 9 |
||||
test.file is file |
||||
test.link is link |
||||
test.file permissions are 0744 |
||||
test.file size is 0 |
||||
test.file is writeable |
||||
test.file is readable |
||||
test.file is executable |
||||
test.file is a regular file |
||||
test.link is a regular file |
||||
test.link is not a directory |
||||
../file is a directory |
||||
test.file is not a directory |
||||
test.file does not exist |
||||
test.file does not exist |
||||
@ -0,0 +1,52 @@ |
||||
--TEST-- |
||||
File/Stream functions |
||||
--FILE-- |
||||
<?php |
||||
|
||||
$data = <<<EOD |
||||
blah blah blah blah blah blah blah |
||||
blah blah blah blah blah blah blah |
||||
blah blah blah blah blah blah blah |
||||
blah blah blah blah blah blah blah |
||||
blah blah blah blah blah blah blah |
||||
blah blah blah blah blah blah blah |
||||
blah blah blah blah blah blah blah |
||||
blah blah blah blah blah blah blah |
||||
blah blah blah blah blah blah blah |
||||
blah blah blah blah blah blah blah |
||||
blah blah blah blah blah blah blah |
||||
blah blah blah blah blah blah blah |
||||
blah blah blah blah blah blah blah |
||||
blah blah blah blah blah blah blah |
||||
blah blah blah blah blah blah blah |
||||
blah blah blah blah blah blah blah |
||||
EOD; |
||||
|
||||
$name = tempnam(__DIR__, "php"); |
||||
$fp = fopen($name, "w"); |
||||
fwrite($fp, $data); |
||||
fclose($fp); |
||||
|
||||
//readfile($name); |
||||
echo file_get_contents($name); |
||||
|
||||
unlink($name); |
||||
|
||||
?> |
||||
--EXPECT-- |
||||
blah blah blah blah blah blah blah |
||||
blah blah blah blah blah blah blah |
||||
blah blah blah blah blah blah blah |
||||
blah blah blah blah blah blah blah |
||||
blah blah blah blah blah blah blah |
||||
blah blah blah blah blah blah blah |
||||
blah blah blah blah blah blah blah |
||||
blah blah blah blah blah blah blah |
||||
blah blah blah blah blah blah blah |
||||
blah blah blah blah blah blah blah |
||||
blah blah blah blah blah blah blah |
||||
blah blah blah blah blah blah blah |
||||
blah blah blah blah blah blah blah |
||||
blah blah blah blah blah blah blah |
||||
blah blah blah blah blah blah blah |
||||
blah blah blah blah blah blah blah |
||||
@ -0,0 +1,41 @@ |
||||
--TEST-- |
||||
is_*() and file_exists() return values are boolean. |
||||
--FILE-- |
||||
<?php |
||||
|
||||
$funcs = array( |
||||
'is_writable', |
||||
'is_readable', |
||||
'is_executable', |
||||
'is_file', |
||||
'file_exists', |
||||
); |
||||
|
||||
$filename=""; |
||||
|
||||
foreach ($funcs as $test) { |
||||
$bb = $test($filename); |
||||
echo gettype($bb)."\n"; |
||||
clearstatcache(); |
||||
} |
||||
|
||||
$filename="run-tests.php"; |
||||
|
||||
foreach ($funcs as $test) { |
||||
$bb = $test($filename); |
||||
echo gettype($bb)."\n"; |
||||
clearstatcache(); |
||||
} |
||||
|
||||
?> |
||||
--EXPECT-- |
||||
boolean |
||||
boolean |
||||
boolean |
||||
boolean |
||||
boolean |
||||
boolean |
||||
boolean |
||||
boolean |
||||
boolean |
||||
boolean |
||||
@ -0,0 +1,61 @@ |
||||
--TEST-- |
||||
file_put_contents() test |
||||
--FILE-- |
||||
<?php |
||||
chdir(__DIR__); |
||||
for ($i = 1; $i < 6; $i++) { |
||||
@unlink("./TEST{$i}"); |
||||
} |
||||
|
||||
echo "String Test: "; |
||||
echo file_put_contents("TEST1", file_get_contents(__FILE__)) !== FALSE ? 'OK' : 'FAIL'; |
||||
echo "\n"; |
||||
|
||||
$old_int = $int = rand(); |
||||
$ret = file_put_contents("TEST2", $int); |
||||
echo "Integer Test: "; |
||||
if ($int === $old_int && $ret !== FALSE && md5($int) == md5_file("TEST2")) { |
||||
echo 'OK'; |
||||
} else { |
||||
echo 'FAIL'; |
||||
} |
||||
echo "\n"; |
||||
|
||||
$old_int = $int = time() / 1000; |
||||
$ret = file_put_contents("TEST3", $int); |
||||
echo "Float Test: "; |
||||
if ($int === $old_int && $ret !== FALSE && md5($int) == md5_file("TEST3")) { |
||||
echo 'OK'; |
||||
} else { |
||||
echo 'FAIL'; |
||||
} |
||||
echo "\n"; |
||||
|
||||
$ret = file_put_contents("TEST4", __FILE__); |
||||
echo "Bool Test: "; |
||||
if ($ret !== FALSE && md5(__FILE__) == md5_file("TEST4")) { |
||||
echo 'OK'; |
||||
} else { |
||||
echo 'FAIL'; |
||||
} |
||||
echo "\n"; |
||||
|
||||
$ret = @file_put_contents("TEST5", $_SERVER); |
||||
echo "Array Test: "; |
||||
if ($ret !== FALSE && @md5(@implode('', $_SERVER)) == md5_file("TEST5")) { |
||||
echo 'OK'; |
||||
} else { |
||||
echo 'FAIL'; |
||||
} |
||||
echo "\n"; |
||||
|
||||
for ($i = 1; $i < 6; $i++) { |
||||
@unlink("./TEST{$i}"); |
||||
} |
||||
?> |
||||
--EXPECT-- |
||||
String Test: OK |
||||
Integer Test: OK |
||||
Float Test: OK |
||||
Bool Test: OK |
||||
Array Test: OK |
||||
@ -0,0 +1,37 @@ |
||||
--TEST-- |
||||
Test fileatime(), filemtime(), filectime() & touch() functions : basic functionality |
||||
--FILE-- |
||||
<?php |
||||
|
||||
echo "*** Testing the basic functionality with file ***\n"; |
||||
print( @date('Y:M:D:H:i:s', fileatime(__FILE__)) )."\n"; |
||||
print( @date('Y:M:D:H:i:s', filemtime(__FILE__)) )."\n"; |
||||
print( @date('Y:M:D:H:i:s', filectime(__FILE__)) )."\n"; |
||||
print( @date('Y:M:D:H:i:s', touch(__DIR__."/005_basic.tmp")) )."\n"; |
||||
|
||||
echo "*** Testing the basic functionality with dir ***\n"; |
||||
print( @date('Y:M:D:H:i:s', fileatime(".")) )."\n"; |
||||
print( @date('Y:M:D:H:i:s', filemtime(".")) )."\n"; |
||||
print( @date('Y:M:D:H:i:s', filectime(".")) )."\n"; |
||||
print( @date('Y:M:D:H:i:s', touch(__DIR__."/005_basic")) )."\n"; |
||||
|
||||
echo "\n*** Done ***\n"; |
||||
?> |
||||
--CLEAN-- |
||||
<?php |
||||
unlink(__DIR__."/005_basic.tmp"); |
||||
unlink(__DIR__."/005_basic"); |
||||
?> |
||||
--EXPECTF-- |
||||
*** Testing the basic functionality with file *** |
||||
%d:%s:%s:%d:%d:%d |
||||
%d:%s:%s:%d:%d:%d |
||||
%d:%s:%s:%d:%d:%d |
||||
%d:%s:%s:%d:%d:%d |
||||
*** Testing the basic functionality with dir *** |
||||
%d:%s:%s:%d:%d:%d |
||||
%d:%s:%s:%d:%d:%d |
||||
%d:%s:%s:%d:%d:%d |
||||
%d:%s:%s:%d:%d:%d |
||||
|
||||
*** Done *** |
||||
@ -0,0 +1,33 @@ |
||||
--TEST-- |
||||
Test fileatime(), filemtime(), filectime() & touch() functions : error conditions |
||||
--FILE-- |
||||
<?php |
||||
|
||||
echo "*** Testing error conditions ***\n"; |
||||
|
||||
echo "\n-- Testing with Non-existing files --"; |
||||
/* Both invalid arguments */ |
||||
var_dump( fileatime("/no/such/file/or/dir") ); |
||||
var_dump( filemtime("/no/such/file/or/dir") ); |
||||
var_dump( filectime("/no/such/file/or/dir") ); |
||||
var_dump( touch("/no/such/file/or/dir", 10) ); |
||||
|
||||
echo "\nDone"; |
||||
?> |
||||
--EXPECTF-- |
||||
*** Testing error conditions *** |
||||
|
||||
-- Testing with Non-existing files -- |
||||
Warning: %s: stat failed for /no/such/file/or/dir in %s on line %d |
||||
bool(false) |
||||
|
||||
Warning: %s: stat failed for /no/such/file/or/dir in %s on line %d |
||||
bool(false) |
||||
|
||||
Warning: %s: stat failed for /no/such/file/or/dir in %s on line %d |
||||
bool(false) |
||||
|
||||
Warning: %s: Unable to create file /no/such/file/or/dir because No such file or directory in %s on line %d |
||||
bool(false) |
||||
|
||||
Done |
||||
@ -0,0 +1,32 @@ |
||||
--TEST-- |
||||
stream_filter_register() and invalid arguments |
||||
--FILE-- |
||||
<?php |
||||
try { |
||||
stream_filter_register("", ""); |
||||
} catch (ValueError $exception) { |
||||
echo $exception->getMessage() . "\n"; |
||||
} |
||||
|
||||
try { |
||||
stream_filter_register("test", ""); |
||||
} catch (ValueError $exception) { |
||||
echo $exception->getMessage() . "\n"; |
||||
} |
||||
|
||||
try { |
||||
stream_filter_register("", "test"); |
||||
} catch (ValueError $exception) { |
||||
echo $exception->getMessage() . "\n"; |
||||
} |
||||
|
||||
var_dump(stream_filter_register("------", "nonexistentclass")); |
||||
|
||||
echo "Done\n"; |
||||
?> |
||||
--EXPECT-- |
||||
stream_filter_register(): Argument #1 ($filter_name) must be a non-empty string |
||||
stream_filter_register(): Argument #2 ($class) must be a non-empty string |
||||
stream_filter_register(): Argument #1 ($filter_name) must be a non-empty string |
||||
bool(true) |
||||
Done |
||||
@ -0,0 +1,45 @@ |
||||
--TEST-- |
||||
basic stream filter tests |
||||
--FILE-- |
||||
<?php |
||||
function filter_test($names) |
||||
{ |
||||
global $text; |
||||
$fp = tmpfile(); |
||||
fwrite($fp, $text); |
||||
rewind($fp); |
||||
foreach ($names as $name) { |
||||
echo "filter: $name\n"; |
||||
var_dump(stream_filter_prepend($fp, $name)); |
||||
} |
||||
var_dump(fgets($fp)); |
||||
fclose($fp); |
||||
} |
||||
|
||||
function main() { |
||||
global $text; |
||||
$text = "Hello There!"; |
||||
$filters = array("string.rot13", "string.toupper", "string.tolower"); |
||||
|
||||
foreach ($filters as $filter) { |
||||
filter_test(array($filter)); |
||||
} |
||||
|
||||
filter_test(array($filters[0], $filters[1])); |
||||
} |
||||
?> |
||||
--EXPECTF-- |
||||
filter: string.rot13 |
||||
resource(%d) of type (stream filter) |
||||
string(12) "Uryyb Gurer!" |
||||
filter: string.toupper |
||||
resource(%d) of type (stream filter) |
||||
string(12) "HELLO THERE!" |
||||
filter: string.tolower |
||||
resource(%d) of type (stream filter) |
||||
string(12) "hello there!" |
||||
filter: string.rot13 |
||||
resource(%d) of type (stream filter) |
||||
filter: string.toupper |
||||
resource(%d) of type (stream filter) |
||||
string(12) "URYYB GURER!" |
||||
@ -0,0 +1,129 @@ |
||||
--TEST-- |
||||
convert stream filter tests |
||||
--FILE-- |
||||
<?php |
||||
function test_roundtrip($data, $encode, $decode, $opts = null, $is_binary = false) { |
||||
echo "Filter: $encode\n"; |
||||
|
||||
$fp = tmpfile(); |
||||
fwrite($fp, $data); |
||||
rewind($fp); |
||||
|
||||
if ($opts === null) { |
||||
stream_filter_prepend($fp, $encode, STREAM_FILTER_READ); |
||||
} else { |
||||
stream_filter_prepend($fp, $encode, STREAM_FILTER_READ, $opts); |
||||
} |
||||
$encoded = stream_get_contents($fp); |
||||
fclose($fp); |
||||
|
||||
if ($is_binary) { |
||||
echo "Original (hex): " . bin2hex($data) . "\n"; |
||||
echo "Encoded: $encoded\n"; |
||||
} else { |
||||
echo "Original: $data\n"; |
||||
echo "Encoded: $encoded\n"; |
||||
} |
||||
|
||||
$fp2 = tmpfile(); |
||||
fwrite($fp2, $encoded); |
||||
rewind($fp2); |
||||
|
||||
if ($opts === null) { |
||||
stream_filter_prepend($fp2, $decode, STREAM_FILTER_READ); |
||||
} else { |
||||
stream_filter_prepend($fp2, $decode, STREAM_FILTER_READ, $opts); |
||||
} |
||||
$decoded = stream_get_contents($fp2); |
||||
fclose($fp2); |
||||
|
||||
if ($is_binary) { |
||||
echo "Decoded (hex): " . bin2hex($decoded) . "\n"; |
||||
} else { |
||||
echo "Decoded: $decoded\n"; |
||||
} |
||||
var_dump($data === $decoded); |
||||
echo "\n"; |
||||
} |
||||
|
||||
function main() { |
||||
$text = "Hello World!"; |
||||
$binary = "ABC\xFF"; |
||||
test_roundtrip($text, "convert.base64-encode", "convert.base64-decode"); |
||||
test_roundtrip($binary, "convert.base64-encode", "convert.base64-decode", null, true); |
||||
test_roundtrip("", "convert.base64-encode", "convert.base64-decode"); |
||||
test_roundtrip("A", "convert.base64-encode", "convert.base64-decode"); |
||||
|
||||
test_roundtrip($text, "convert.quoted-printable-encode", "convert.quoted-printable-decode"); |
||||
test_roundtrip("Line1\r\nLine2", "convert.quoted-printable-encode", "convert.quoted-printable-decode"); |
||||
|
||||
$opts = array('line-length' => 20, 'line-break-chars' => "\n"); |
||||
test_roundtrip("Long text that will be wrapped", "convert.base64-encode", "convert.base64-decode", $opts); |
||||
|
||||
$opts2 = array('binary' => true); |
||||
test_roundtrip("Text\t\r\n", "convert.quoted-printable-encode", "convert.quoted-printable-decode", $opts2); |
||||
|
||||
$fp = tmpfile(); |
||||
fwrite($fp, "Test"); |
||||
rewind($fp); |
||||
stream_filter_prepend($fp, 'convert.base64-encode', STREAM_FILTER_READ); |
||||
$result = stream_get_contents($fp); |
||||
fclose($fp); |
||||
var_dump($result === base64_encode("Test")); |
||||
} |
||||
?> |
||||
--EXPECTF-- |
||||
Filter: convert.base64-encode |
||||
Original: Hello World! |
||||
Encoded: SGVsbG8gV29ybGQh |
||||
Decoded: Hello World! |
||||
bool(true) |
||||
|
||||
Filter: convert.base64-encode |
||||
Original (hex): 414243ff |
||||
Encoded: QUJD/w== |
||||
Decoded (hex): 414243ff |
||||
bool(true) |
||||
|
||||
Filter: convert.base64-encode |
||||
Original: |
||||
Encoded: |
||||
Decoded: |
||||
bool(true) |
||||
|
||||
Filter: convert.base64-encode |
||||
Original: A |
||||
Encoded: QQ== |
||||
Decoded: A |
||||
bool(true) |
||||
|
||||
Filter: convert.quoted-printable-encode |
||||
Original: Hello World! |
||||
Encoded: Hello World! |
||||
Decoded: Hello World! |
||||
bool(true) |
||||
|
||||
Filter: convert.quoted-printable-encode |
||||
Original: Line1 |
||||
Line2 |
||||
Encoded: Line1=0D=0ALine2 |
||||
Decoded: Line1 |
||||
Line2 |
||||
bool(true) |
||||
|
||||
Filter: convert.base64-encode |
||||
Original: Long text that will be wrapped |
||||
Encoded: TG9uZyB0ZXh0IHRoYXQg |
||||
d2lsbCBiZSB3cmFwcGVk |
||||
Decoded: Long text that will be wrapped |
||||
bool(true) |
||||
|
||||
Filter: convert.quoted-printable-encode |
||||
Original: Text |
||||
|
||||
Encoded: Text=09=0D=0A |
||||
Decoded: Text |
||||
|
||||
bool(true) |
||||
|
||||
bool(true) |
||||
@ -0,0 +1,67 @@ |
||||
--TEST-- |
||||
sprintf() function |
||||
--FILE-- |
||||
<?php |
||||
|
||||
$agent = sprintf("%.5s", "James Bond, 007"); |
||||
|
||||
echo("sprintf string truncate test: "); |
||||
if ($agent == "James") { |
||||
echo("passed\n"); |
||||
} else { |
||||
echo("failed!\n"); |
||||
} |
||||
|
||||
echo("sprintf padding and align test: "); |
||||
$test = sprintf("abc%04d %-20s%c", 20, "fisketur", 33); |
||||
if ($test == "abc0020 fisketur !") { |
||||
echo("passed\n"); |
||||
} else { |
||||
echo("failed!\n"); |
||||
} |
||||
|
||||
echo("sprintf octal and hex test: "); |
||||
$test = sprintf("%4o %4x %4X %0"."8x", 128, 1024, 49151, 3457925); |
||||
if ($test == " 200 400 BFFF 0034c385") { |
||||
echo("passed\n"); |
||||
} else { |
||||
echo("failed!\n"); |
||||
} |
||||
|
||||
echo("sprintf octal binary test: "); |
||||
$test = sprintf("%b", 3457925); |
||||
if ($test == "1101001100001110000101") { |
||||
echo("passed\n"); |
||||
} else { |
||||
echo("failed!\n"); |
||||
} |
||||
|
||||
echo("sprintf float test: "); |
||||
$test = sprintf("%0"."06.2f", 10000/3.0); |
||||
if ($test == "003333.33") { |
||||
echo("passed\n"); |
||||
} else { |
||||
echo("failed!\n"); |
||||
} |
||||
|
||||
echo sprintf("%.2f\n", "99.00"); |
||||
echo sprintf("%.2f\n", 99.00); |
||||
|
||||
echo sprintf("%e\n", 1.234E-18); |
||||
echo sprintf("%e\n", 1.234E+18); |
||||
echo sprintf("%e\n", 9843243.12); |
||||
echo sprintf("%e\n", -9843243.12); |
||||
|
||||
?> |
||||
--EXPECT-- |
||||
sprintf string truncate test: passed |
||||
sprintf padding and align test: passed |
||||
sprintf octal and hex test: passed |
||||
sprintf octal binary test: passed |
||||
sprintf float test: passed |
||||
99.00 |
||||
99.00 |
||||
1.234000e-18 |
||||
1.234000e+18 |
||||
9.843243e+6 |
||||
-9.843243e+6 |
||||
@ -0,0 +1,11 @@ |
||||
--TEST-- |
||||
quoted_printable_decode() function test |
||||
--FILE-- |
||||
<?php echo quoted_printable_decode("=FAwow-factor=C1=d0=D5=DD=C5=CE=CE=D9=C5=0A= |
||||
=20=D4=cf=D2=C7=CF=D7=D9=C5= |
||||
=20= |
||||
=D0= |
||||
=D2=CF=C5=CB=D4=D9"); ?> |
||||
--EXPECT-- |
||||
úwow-factorÁÐÕÝÅÎÎÙÅ |
||||
ÔÏÒÇÏ×ÙÅ ÐÒÏÅËÔÙ |
||||
@ -0,0 +1,59 @@ |
||||
--TEST-- |
||||
levenshtein() function test |
||||
--FILE-- |
||||
<?php |
||||
|
||||
function test_me($title,$expect,$text1,$text2,$cost1=0,$cost2=0,$cost3=0) { |
||||
|
||||
if($cost1==0) |
||||
$result=levenshtein($text1,$text2); |
||||
else |
||||
$result=levenshtein($text1,$text2,$cost1,$cost2,$cost3); |
||||
|
||||
if($result==$expect) return 0; |
||||
|
||||
echo "$title: result is $result instead of $expect "; |
||||
echo "for '$text1'/'$text2' "; |
||||
if($cost1) echo "($cost1:$cost2:$cost3)"; |
||||
echo "\n"; |
||||
|
||||
return 1; |
||||
} |
||||
|
||||
function main() { |
||||
$n=0; |
||||
|
||||
$n += test_me("equal" , 0, "12345", "12345"); |
||||
$n += test_me("1st empty" , 3, "", "xzy"); |
||||
$n += test_me("2nd empty" , 3, "xzy", ""); |
||||
$n += test_me("both empty" , 0, "", ""); |
||||
$n += test_me("1 char" , 1, "1", "2"); |
||||
$n += test_me("2 char swap", 2, "12", "21"); |
||||
|
||||
$n += test_me("inexpensive delete", 2, "2121", "11", 2, 1, 1); |
||||
$n += test_me("expensive delete" , 10, "2121", "11", 2, 1, 5); |
||||
$n += test_me("inexpensive insert", 2, "11", "2121", 1, 1, 1); |
||||
$n += test_me("expensive insert" , 10, "11", "2121", 5, 1, 1); |
||||
|
||||
$n += test_me("expensive replace" , 3, "111", "121", 2, 3, 2); |
||||
$n += test_me("very expensive replace", 4, "111", "121", 2, 9, 2); |
||||
|
||||
$n += test_me("bug #7368", 2, "13458", "12345"); |
||||
$n += test_me("bug #7368", 2, "1345", "1234"); |
||||
|
||||
$n += test_me("bug #6562", 1, "debugg", "debug"); |
||||
$n += test_me("bug #6562", 1, "ddebug", "debug"); |
||||
$n += test_me("bug #6562", 2, "debbbug", "debug"); |
||||
$n += test_me("bug #6562", 1, "debugging", "debuging"); |
||||
|
||||
$n += test_me("bug #16473", 2, "a", "bc"); |
||||
$n += test_me("bug #16473", 2, "xa", "xbc"); |
||||
$n += test_me("bug #16473", 2, "xax", "xbcx"); |
||||
$n += test_me("bug #16473", 2, "ax", "bcx"); |
||||
|
||||
|
||||
echo ($n==0)?"all passed\n":"$n failed\n"; |
||||
} |
||||
?> |
||||
--EXPECT-- |
||||
all passed |
||||
@ -0,0 +1,26 @@ |
||||
--TEST-- |
||||
MD5 / Base64 |
||||
--FILE-- |
||||
<?php |
||||
function test($str) { |
||||
$res = md5(base64_decode(base64_encode($str)))."\n"; |
||||
return $res; |
||||
} |
||||
function main() { |
||||
echo test(""); |
||||
echo test("a"); |
||||
echo test("abc"); |
||||
echo test("message digest"); |
||||
echo test("abcdefghijklmnopqrstuvwxyz"); |
||||
echo test("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"); |
||||
echo test("12345678901234567890123456789012345678901234567890123456789012345678901234567890"); |
||||
} |
||||
?> |
||||
--EXPECT-- |
||||
d41d8cd98f00b204e9800998ecf8427e |
||||
0cc175b9c0f1b6a831c399e269772661 |
||||
900150983cd24fb0d6963f7d28e17f72 |
||||
f96b697d7cb7938d525a2f31aaf161d0 |
||||
c3fcd3d76192e4007dfb496cca67e13b |
||||
d174ab98d277d9f5a5611c2c9f419d9f |
||||
57edf4a22be3c955ac49da2e2107b67a |
||||
@ -0,0 +1,43 @@ |
||||
--TEST-- |
||||
var_dump float test |
||||
--FILE-- |
||||
<?php |
||||
// this checks f,g,G conversion for snprintf/spprintf |
||||
var_dump(array(ini_get('precision'), |
||||
.012, |
||||
-.012, |
||||
.12, |
||||
-.12, |
||||
1.2,-1.2,12.,-12.,0.000123,.0000123,123456789012.0,1234567890123.0,12345678901234567890.0)); |
||||
?> |
||||
--EXPECT-- |
||||
array(14) { |
||||
[0]=> |
||||
string(2) "17" |
||||
[1]=> |
||||
float(0.012) |
||||
[2]=> |
||||
float(-0.012) |
||||
[3]=> |
||||
float(0.12) |
||||
[4]=> |
||||
float(-0.12) |
||||
[5]=> |
||||
float(1.2) |
||||
[6]=> |
||||
float(-1.2) |
||||
[7]=> |
||||
float(12) |
||||
[8]=> |
||||
float(-12) |
||||
[9]=> |
||||
float(0.000123) |
||||
[10]=> |
||||
float(1.23E-5) |
||||
[11]=> |
||||
float(123456789012) |
||||
[12]=> |
||||
float(1234567890123) |
||||
[13]=> |
||||
float(1.2345678901234567E+19) |
||||
} |
||||
@ -0,0 +1,26 @@ |
||||
--TEST-- |
||||
SHA1 |
||||
--FILE-- |
||||
<?php |
||||
function test($str) { |
||||
$res = sha1($str)."\n"; |
||||
return $res; |
||||
} |
||||
function main() { |
||||
echo test(""); |
||||
echo test("a"); |
||||
echo test("abc"); |
||||
echo test("message digest"); |
||||
echo test("abcdefghijklmnopqrstuvwxyz"); |
||||
echo test("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"); |
||||
echo test("12345678901234567890123456789012345678901234567890123456789012345678901234567890"); |
||||
} |
||||
?> |
||||
--EXPECT-- |
||||
da39a3ee5e6b4b0d3255bfef95601890afd80709 |
||||
86f7e437faa5a7fce15d1ddcb9eaeaea377667b8 |
||||
a9993e364706816aba3e25717850c26c9cd0d89d |
||||
c12252ceda8be8994d5fa0290a47231c1d16aae3 |
||||
32d10c7b8cf96570ca04ce37f2a19d84240d3a89 |
||||
761c457bf73b14d27e9e9265c46f4b4dda11f940 |
||||
50abf5706a150990a08b2c5ea40fa0e585554732 |
||||
Loading…
Reference in new issue