zoe Mon Jul 6 21:02:48 2009 UTC
Added files:
/phpruntests/QA/tests/lang 015.inc 023-1.inc bug38579.inc inc.inc
inc_throw.inc 016.inc 023-2.inc
/phpruntests/QA/tests/security open_basedir.inc
/phpruntests/QA/tests/output ob_011.out ob_011.php ob_011.exp
ob_011.diff
/phpruntests/QA/tests quicktester.inc
Modified files:
/phpruntests/QA/tests/lang bug24054.phpt
Log:
building test suite
http://cvs.php.net/viewvc.cgi/phpruntests/QA/tests/lang/bug24054.phpt?r1=1.1&r2=1.2&diff_format=u
Index: phpruntests/QA/tests/lang/bug24054.phpt
diff -u phpruntests/QA/tests/lang/bug24054.phpt:1.1
phpruntests/QA/tests/lang/bug24054.phpt:1.2
--- phpruntests/QA/tests/lang/bug24054.phpt:1.1 Mon Jul 6 20:04:53 2009
+++ phpruntests/QA/tests/lang/bug24054.phpt Mon Jul 6 21:02:47 2009
@@ -1,7 +1,7 @@
--TEST--
Bug #24054 (Assignment operator *= broken)
--FILE--
-<?php // $Id: bug24054.phpt,v 1.1 2009/07/06 20:04:53 zoe Exp $
+<?php // $Id: bug24054.phpt,v 1.2 2009/07/06 21:02:47 zoe Exp $
define('LONG_MAX', is_int(5000000000)? 9223372036854775807 : 0x7FFFFFFF);
define('LONG_MIN', -LONG_MAX - 1);
http://cvs.php.net/viewvc.cgi/phpruntests/QA/tests/lang/015.inc?view=markup&rev=1.1
Index: phpruntests/QA/tests/lang/015.inc
+++ phpruntests/QA/tests/lang/015.inc
<?php
echo "Hello";
?>
http://cvs.php.net/viewvc.cgi/phpruntests/QA/tests/lang/023-1.inc?view=markup&rev=1.1
Index: phpruntests/QA/tests/lang/023-1.inc
+++ phpruntests/QA/tests/lang/023-1.inc
<html>
<head>
<?php
/* the point of this file is to intensively test various aspects of
* the parser. right now, each test focuses in one aspect only
* (e.g. variable aliasing, arithemtic operator, various control
* structures), while trying to combine code from other parts of the
* parser as well.
*/
?>
*** Testing assignments and variable aliasing: ***<br>
<?php
/* This test tests assignments to variables using other variables as
variable-names */
$a = "b";
$$a = "test";
$$$a = "blah";
${$$$a}["associative arrays work too"] = "this is nifty";
?>
This should read "blah": <?php echo "$test<br>\n"; ?>
This should read "this is nifty": <?php echo $blah[$test="associative arrays
work too"]."<br>\n"; ?>
*************************************************<br>
*** Testing integer operators ***<br>
<?php
/* test just about any operator possible on $i and $j (ints) */
$i = 5;
$j = 3;
?>
Correct result - 8: <?php echo $i+$j; ?><br>
Correct result - 8: <?php echo $i+$j; ?><br>
Correct result - 2: <?php echo $i-$j; ?><br>
Correct result - -2: <?php echo $j-$i; ?><br>
Correct result - 15: <?php echo $i*$j; ?><br>
Correct result - 15: <?php echo $j*$i; ?><br>
Correct result - 2: <?php echo $i%$j; ?><br>
Correct result - 3: <?php echo $j%$i; ?><br>
*********************************<br>
*** Testing real operators ***<br>
<?php
/* test just about any operator possible on $i and $j (floats) */
$i = 5.0;
$j = 3.0;
?>
Correct result - 8: <?php echo $i+$j; ?><br>
Correct result - 8: <?php echo $i+$j; ?><br>
Correct result - 2: <?php echo $i-$j; ?><br>
Correct result - -2: <?php echo $j-$i; ?><br>
Correct result - 15: <?php echo $i*$j; ?><br>
Correct result - 15: <?php echo $j*$i; ?><br>
Correct result - 2: <?php echo $i%$j; ?><br>
Correct result - 3: <?php echo $j%$i; ?><br>
*********************************<br>
*** Testing if/elseif/else control ***<br>
<?php
/* sick if/elseif/else test by Andi :) */
$a = 5;
if ($a == "4") {
echo "This "." does "." not "." work<br>\n";
} elseif ($a == "5") {
echo "This "." works<br>\n";
$a = 6;
if ("andi" == ($test = "andi")) {
echo "this_still_works<br>\n";
} elseif (1) {
echo "should_not_print<br>\n";
} else {
echo "should_not_print<br>\n";
}
if (44 == 43) {
echo "should_not_print<br>\n";
} else {
echo "should_print<br>\n";
}
} elseif ($a == 6) {
echo "this "."broken<br>\n";
if (0) {
echo "this_should_not_print<br>\n";
} else {
echo "TestingDanglingElse_This_Should_not_print<br>\n";
}
} else {
echo "This "."does "." not"." work<br>\n";
}
?>
*** Seriously nested if's test ***<br>
** spelling correction by kluzz **
<?php
/* yet another sick if/elseif/else test by Zeev */
$i=$j=0;
echo "Only two lines of text should follow:<br>\n";
if (0) { /* this code is not supposed to be executed */
echo "hmm, this shouldn't be displayed #1<br>\n";
$j++;
if (1) {
$i
+=
$j;
if (0) {
$j = ++$i;
if (1) {
$j *= $i;
echo "damn, this shouldn't be displayed<br>\n";
} else {
$j /= $i;
++$j;
echo "this shouldn't be displayed either<br>\n";
}
} elseif (1) {
$i++; $j++;
echo "this isn't supposed to be displayed<br>\n";
}
} elseif (0) {
$i++;
echo "this definitely shouldn't be displayed<br>\n";
} else {
--$j;
echo "and this too shouldn't be displayed<br>\n";
while ($j>0) {
$j--;
}
}
} elseif (2-2) { /* as long as 2-2==0, this isn't supposed to be executed
either */
$i = ++$j;
echo "hmm, this shouldn't be displayed #2<br>\n";
if (1) {
$j = ++$i;
if (0) {
$j = $i*2+$j*($i++);
if (1) {
$i++;
echo "damn, this shouldn't be displayed<br>\n";
} else {
$j++;
echo "this shouldn't be displayed either<br>\n";
}
} else if (1) {
++$j;
echo "this isn't supposed to be displayed<br>\n";
}
} elseif (0) {
$j++;
echo "this definitely shouldn't be displayed<br>\n";
} else {
$i++;
echo "and this too shouldn't be displayed<br>\n";
}
} else {
$j=$i++; /* this should set $i to 1, but shouldn't change $j (it's assigned
$i's previous values, zero) */
echo "this should be displayed. should be: \$i=1, \$j=0. is: \$i=$i,
\$j=$j<br>\n";
if (1) {
$j += ++$i; /* ++$i --> $i==2, $j += 2 --> $j==2 */
if (0) {
$j += 40;
if (1) {
$i += 50;
echo "damn, this shouldn't be displayed<br>\n";
} else {
$j += 20;
echo "this shouldn't be displayed either<br>\n";
}
} else if (1) {
$j *= $i; /* $j *= 2 --> $j == 4 */
echo "this is supposed to be displayed. should be: \$i=2, \$j=4. is:
\$i=$i, \$j=$j<br>\n";
echo "3 loop iterations should follow:<br>\n";
while ($i<=$j) {
echo $i++." $j<br>\n";
}
}
} elseif (0) {
echo "this definitely shouldn't be displayed<br>\n";
} else {
echo "and this too shouldn't be displayed<br>\n";
}
echo "**********************************<br>\n";
}
?>
*** C-style else-if's ***<br>
<?php
/* looks like without we even tried, C-style else-if structure works fine! */
if ($a=0) {
echo "This shouldn't be displayed<br>\n";
} else if ($a++) {
echo "This shouldn't be displayed either<br>\n";
} else if (--$a) {
echo "No, this neither<br>\n";
} else if (++$a) {
echo "This should be displayed<br>\n";
} else {
echo "This shouldn't be displayed at all<br>\n";
}
?>
*************************<br>
*** WHILE tests ***<br>
<?php
$i=0;
$j=20;
while ($i<(2*$j)) {
if ($i>$j) {
echo "$i is greater than $j<br>\n";
} else if ($i==$j) {
echo "$i equals $j<br>\n";
} else {
echo "$i is smaller than $j<br>\n";
}
$i++;
}
?>
*******************<br>
*** Nested WHILEs ***<br>
<?php
$arr_len=3;
$i=0;
while ($i<$arr_len) {
$j=0;
while ($j<$arr_len) {
$k=0;
while ($k<$arr_len) {
${"test$i$j"}[$k] = $i+$j+$k;
$k++;
}
$j++;
}
$i++;
}
echo "Each array variable should be equal to the sum of its indices:<br>\n";
$i=0;
while ($i<$arr_len) {
$j=0;
while ($j<$arr_len) {
$k=0;
while ($k<$arr_len) {
echo "\${test$i$j}[$k] = ".${"test$i$j"}[$k]."<br>\n";
$k++;
}
$j++;
}
$i++;
}
?>
*********************<br>
*** hash test... ***<br>
<?php
/*
$i=0;
while ($i<10000) {
$arr[$i]=$i;
$i++;
}
$i=0;
while ($i<10000) {
echo $arr[$i++]."<br>\n";
}
*/
echo "commented out...";
?>
**************************<br>
*** Hash resizing test ***<br>
<?php
$i = 10;
$a = 'b';
while ($i > 0) {
$a = $a . 'a';
echo "$a<br>\n";
$resize[$a] = $i;
$i--;
}
$i = 10;
$a = 'b';
while ($i > 0) {
$a = $a . 'a';
echo "$a<br>\n";
echo $resize[$a]."<br>\n";
$i--;
}
?>
**************************<br>
*** break/continue test ***<br>
<?php
$i=0;
echo "\$i should go from 0 to 2<br>\n";
while ($i<5) {
if ($i>2) {
break;
}
$j=0;
echo "\$j should go from 3 to 4, and \$q should go from 3 to 4<br>\n";
while ($j<5) {
if ($j<=2) {
$j++;
continue;
}
echo " \$j=$j<br>\n";
for ($q=0; $q<=10; $q++) {
if ($q<3) {
continue;
}
if ($q>4) {
break;
}
echo " \$q=$q<br>\n";
}
$j++;
}
$j=0;
echo "\$j should go from 0 to 2<br>\n";
while ($j<5) {
if ($j>2) {
$k=0;
echo "\$k should go from 0 to 2<br>\n";
while ($k<5) {
if ($k>2) {
break 2;
}
echo " \$k=$k<br>\n";
$k++;
}
}
echo " \$j=$j<br>\n";
$j++;
}
echo "\$i=$i<br>\n";
$i++;
}
?>
***********************<br>
*** Nested file include test ***<br>
<?php include("023-2.inc"); ?>
********************************<br>
<?php
{
echo "Tests completed.<br>\n"; # testing some PHP style comment...
}
?>
http://cvs.php.net/viewvc.cgi/phpruntests/QA/tests/lang/bug38579.inc?view=markup&rev=1.1
Index: phpruntests/QA/tests/lang/bug38579.inc
+++ phpruntests/QA/tests/lang/bug38579.inc
<?php
echo "ok\n";
?>
http://cvs.php.net/viewvc.cgi/phpruntests/QA/tests/lang/inc.inc?view=markup&rev=1.1
Index: phpruntests/QA/tests/lang/inc.inc
+++ phpruntests/QA/tests/lang/inc.inc
<?php
echo "Included!\n";
?>
http://cvs.php.net/viewvc.cgi/phpruntests/QA/tests/lang/inc_throw.inc?view=markup&rev=1.1
Index: phpruntests/QA/tests/lang/inc_throw.inc
+++ phpruntests/QA/tests/lang/inc_throw.inc
<?php
throw new Exception();
?>
http://cvs.php.net/viewvc.cgi/phpruntests/QA/tests/lang/016.inc?view=markup&rev=1.1
Index: phpruntests/QA/tests/lang/016.inc
+++ phpruntests/QA/tests/lang/016.inc
<?php
function MyFunc ($a) {
echo $a;
}
?>
http://cvs.php.net/viewvc.cgi/phpruntests/QA/tests/lang/023-2.inc?view=markup&rev=1.1
Index: phpruntests/QA/tests/lang/023-2.inc
+++ phpruntests/QA/tests/lang/023-2.inc
<html>
This is Finish.phtml. This file is supposed to be included
from regression_test.phtml. This is normal HTML.
<?php echo "and this is PHP code, 2+2=".(2+2).""; ?>
</html>
http://cvs.php.net/viewvc.cgi/phpruntests/QA/tests/security/open_basedir.inc?view=markup&rev=1.1
Index: phpruntests/QA/tests/security/open_basedir.inc
+++ phpruntests/QA/tests/security/open_basedir.inc
<?php
// This file contains helper functions for testing open_basedir configuration
// Care must be taken with where the directories are created because different
// SAPIs set the working directory differently. So simply creating a directory
// relative to the current working directory like this: mkdir("blah") might
// actually create it in several different places depending on the SAPI..!
//
// Note also depending on the version of php being tested, so the open_basedir
// configuration may or may not be changeable from a script (PHP_INI_SYSTEM).
//
// For this reason we set the open_basedir to . (current directory) and then
// move around to various directories for testing using chdir(). This is NOT
// recommended for production use as . bypasses all semblence of security..!
//
// Although safe mode has been removed in php 6.0, open_basedir is still valid.
// See http://www.php.net/features.safe-mode for more information
function recursive_delete_directory($directory) {
// Remove any trailing slash first
if (substr($directory, -1) == '/') {
$directory = substr($directory, 0, -1);
}
// Make sure the directory is valid
if (is_dir($directory) == FALSE) {
return FALSE;
}
// Check we can access the directory
if (is_readable($directory) == FALSE) {
return FALSE;
}
$handle = opendir($directory);
// Scan through the directory contents
while (FALSE !== ($item = readdir($handle))) {
if ($item != '.') {
if ($item != '..') {
$path = ($directory.'/'.$item);
if (is_dir($path) == TRUE) {
recursive_delete_directory($path);
} else {
@chmod($path, 0777);
unlink($path);
}
}
}
}
closedir($handle);
@chmod($directory, 0777);
rmdir($directory);
return TRUE;
}
function create_directories() {
delete_directories();
$directory = getcwd();
var_dump(mkdir($directory."/test"));
var_dump(mkdir($directory."/test/ok"));
var_dump(mkdir($directory."/test/bad"));
file_put_contents($directory."/test/ok/ok.txt", "Hello World!");
file_put_contents($directory."/test/bad/bad.txt", "Hello World!");
}
function delete_directories() {
$directory = (getcwd()."/test");
recursive_delete_directory($directory);
}
function test_open_basedir_error($function) {
global $savedDirectory;
var_dump($function("../bad"));
var_dump($function("../bad/bad.txt"));
var_dump($function(".."));
var_dump($function("../"));
var_dump($function("/"));
var_dump($function("../bad/."));
$directory = $savedDirectory;
var_dump($function($directory."/test/bad/bad.txt"));
var_dump($function($directory."/test/bad/../bad/bad.txt"));
}
function test_open_basedir_before($function, $change = TRUE) {
global $savedDirectory;
echo "*** Testing open_basedir configuration [$function] ***\n";
$directory = getcwd();
$savedDirectory = $directory;
var_dump(chdir($directory));
create_directories();
// Optionally change directory
if ($change == TRUE) {
var_dump(chdir($directory."/test/ok"));
}
}
// Delete directories using a --CLEAN-- section!
function test_open_basedir_after($function) {
echo "*** Finished testing open_basedir configuration [$function] ***\n";
}
// This is used by functions that return an array on success
function test_open_basedir_array($function) {
global $savedDirectory;
test_open_basedir_before($function);
test_open_basedir_error($function);
var_dump(is_array($function("./../.")));
var_dump(is_array($function("../ok")));
var_dump(is_array($function("ok.txt")));
var_dump(is_array($function("../ok/ok.txt")));
$directory = $savedDirectory;
var_dump(is_array($function($directory."/test/ok/ok.txt")));
var_dump(is_array($function($directory."/test/ok/../ok/ok.txt")));
test_open_basedir_after($function);
}
function test_open_basedir($function) {
global $savedDirectory;
test_open_basedir_before($function);
test_open_basedir_error($function);
var_dump($function("./../."));
var_dump($function("../ok"));
var_dump($function("ok.txt"));
var_dump($function("../ok/ok.txt"));
$directory = $savedDirectory;
var_dump($function($directory."/test/ok/ok.txt"));
var_dump($function($directory."/test/ok/../ok/ok.txt"));
test_open_basedir_after($function);
}
?>
http://cvs.php.net/viewvc.cgi/phpruntests/QA/tests/output/ob_011.out?view=markup&rev=1.1
Index: phpruntests/QA/tests/output/ob_011.out
+++ phpruntests/QA/tests/output/ob_011.out
http://cvs.php.net/viewvc.cgi/phpruntests/QA/tests/output/ob_011.php?view=markup&rev=1.1
Index: phpruntests/QA/tests/output/ob_011.php
+++ phpruntests/QA/tests/output/ob_011.php
<?php
function obh($s)
{
return ob_get_flush();
}
ob_start("obh");
echo "foo\n";
?>
http://cvs.php.net/viewvc.cgi/phpruntests/QA/tests/output/ob_011.exp?view=markup&rev=1.1
Index: phpruntests/QA/tests/output/ob_011.exp
+++ phpruntests/QA/tests/output/ob_011.exp
Fatal error: ob_get_flush(): Cannot use output buffering in output buffering
display handlers in %sob_011.php on line %d
http://cvs.php.net/viewvc.cgi/phpruntests/QA/tests/output/ob_011.diff?view=markup&rev=1.1
Index: phpruntests/QA/tests/output/ob_011.diff
+++ phpruntests/QA/tests/output/ob_011.diff
001+
001- Fatal error: ob_get_flush(): Cannot use output buffering in output
buffering display handlers in %sob_011.php on line %d
http://cvs.php.net/viewvc.cgi/phpruntests/QA/tests/quicktester.inc?view=markup&rev=1.1
Index: phpruntests/QA/tests/quicktester.inc
+++ phpruntests/QA/tests/quicktester.inc
<?php
/*
Helper for simple tests to check return-value. Usage:
$tests = <<<TESTS
expected_return_value === expression
2 === 1+1
4 === 2*2
FALSE === @ fopen('non_existent_file')
TESTS;
include( 'tests/quicktester.inc' );
Expect: OK
Remember to NOT put a trailing ; after a line!
*/
error_reporting(E_ALL);
$tests = explode("\n",$tests);
$success = TRUE;
foreach ($tests as $n=>$test)
{
// ignore empty lines
if (!$test) continue;
// warn for trailing ;
if (substr(trim($test), -1, 1) === ';') {
echo "WARNING: trailing ';' found in test ".($n+1)."\n";
exit;
}
// try for operators
$operators = array('===', '~==');
$operator = NULL;
foreach ($operators as $a_operator) {
if (strpos($test, $a_operator)!== FALSE) {
$operator = $a_operator;
list($left,$right) = explode($operator, $test);
break;
}
}
if (!$operator) {
echo "WARNING: unknown operator in '$test' (1)\n";
exit;
}
$left = eval("return ($left );");
$right = eval("return ($right);");
switch (@$operator) {
case '===': // exact match
$result = $left === $right;
break;
case '~==': // may differ after 12th significant number
if ( !is_float($left ) && !is_int($left )
|| !is_float($right) && !is_int($right)) {
$result = FALSE;
break;
}
$result = abs(($left-$right) / $left) < 1e-12;
break;
default:
echo "WARNING: unknown operator in '$test' (2)\n";
exit;
}
$success = $success && $result;
if (!$result) {
echo "\nAssert failed:\n";
echo "$test\n";
echo "Left: ";var_dump($left );
echo "Right: ";var_dump($right);
}
}
if ($success) echo "OK";
--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php