summaryrefslogtreecommitdiff
path: root/tests/func
diff options
context:
space:
mode:
authorLorry Tar Creator <lorry-tar-importer@baserock.org>2013-03-14 05:42:27 +0000
committer <>2013-04-03 16:25:08 +0000
commitc4dd7a1a684490673e25aaf4fabec5df138854c4 (patch)
tree4d57c44caae4480efff02b90b9be86f44bf25409 /tests/func
downloadphp2-master.tar.gz
Imported from /home/lorry/working-area/delta_php2/php-5.4.13.tar.bz2.HEADphp-5.4.13master
Diffstat (limited to 'tests/func')
-rw-r--r--tests/func/001.phpt6
-rw-r--r--tests/func/002.phpt21
-rw-r--r--tests/func/003.phpt291
-rw-r--r--tests/func/004.phpt65
-rw-r--r--tests/func/005.phpt19
-rw-r--r--tests/func/005a.phpt32
-rw-r--r--tests/func/006.phpt26
-rw-r--r--tests/func/007.phpt22
-rw-r--r--tests/func/008.phpt16
-rw-r--r--tests/func/009.phpt16
-rw-r--r--tests/func/010.phpt77
-rw-r--r--tests/func/ini_alter.phpt19
12 files changed, 610 insertions, 0 deletions
diff --git a/tests/func/001.phpt b/tests/func/001.phpt
new file mode 100644
index 0000000..d080406
--- /dev/null
+++ b/tests/func/001.phpt
@@ -0,0 +1,6 @@
+--TEST--
+Strlen() function test
+--FILE--
+<?php echo strlen("abcdef")?>
+--EXPECT--
+6
diff --git a/tests/func/002.phpt b/tests/func/002.phpt
new file mode 100644
index 0000000..cb35f92
--- /dev/null
+++ b/tests/func/002.phpt
@@ -0,0 +1,21 @@
+--TEST--
+Static variables in functions
+--FILE--
+<?php
+function blah()
+{
+ static $hey=0,$yo=0;
+
+ echo "hey=".$hey++.", ",$yo--."\n";
+}
+
+blah();
+blah();
+blah();
+if (isset($hey) || isset($yo)) {
+ echo "Local variables became global :(\n";
+}
+--EXPECT--
+hey=0, 0
+hey=1, -1
+hey=2, -2
diff --git a/tests/func/003.phpt b/tests/func/003.phpt
new file mode 100644
index 0000000..d603784
--- /dev/null
+++ b/tests/func/003.phpt
@@ -0,0 +1,291 @@
+--TEST--
+General function test
+--FILE--
+<?php
+
+function a()
+{
+ echo "hey\n";
+}
+
+function b($i)
+{
+ echo "$i\n";
+}
+
+
+function c($i,$j)
+{
+ echo "Counting from $i to $j\n";
+ for ($k=$i; $k<=$j; $k++) {
+ echo "$k\n";
+ }
+}
+
+
+
+a();
+b("blah");
+a();
+b("blah","blah");
+c(7,14);
+
+a();
+
+
+function factorial($n)
+{
+ if ($n==0 || $n==1) {
+ return 1;
+ } else {
+ return factorial($n-1)*$n;
+ }
+}
+
+
+function factorial2($start, $n)
+{
+ if ($n<=$start) {
+ return $start;
+ } else {
+ return factorial2($start,$n-1)*$n;
+ }
+}
+
+
+for ($k=0; $k<10; $k++) {
+ for ($i=0; $i<=10; $i++) {
+ $n=factorial($i);
+ echo "factorial($i) = $n\n";
+ }
+}
+
+
+echo "and now, from a function...\n";
+
+function call_fact()
+{
+ echo "(it should break at 5...)\n";
+ for ($i=0; $i<=10; $i++) {
+ if ($i == 5) break;
+ $n=factorial($i);
+ echo "factorial($i) = $n\n";
+ }
+}
+
+function return4() { return 4; }
+function return7() { return 7; }
+
+for ($k=0; $k<10; $k++) {
+ call_fact();
+}
+
+echo "------\n";
+$result = factorial(factorial(3));
+echo "$result\n";
+
+$result=factorial2(return4(),return7());
+echo "$result\n";
+
+function andi($i, $j)
+{
+ for ($k=$i ; $k<=$j ; $k++) {
+ if ($k >5) continue;
+ echo "$k\n";
+ }
+}
+
+andi (3,10);
+--EXPECT--
+hey
+blah
+hey
+blah
+Counting from 7 to 14
+7
+8
+9
+10
+11
+12
+13
+14
+hey
+factorial(0) = 1
+factorial(1) = 1
+factorial(2) = 2
+factorial(3) = 6
+factorial(4) = 24
+factorial(5) = 120
+factorial(6) = 720
+factorial(7) = 5040
+factorial(8) = 40320
+factorial(9) = 362880
+factorial(10) = 3628800
+factorial(0) = 1
+factorial(1) = 1
+factorial(2) = 2
+factorial(3) = 6
+factorial(4) = 24
+factorial(5) = 120
+factorial(6) = 720
+factorial(7) = 5040
+factorial(8) = 40320
+factorial(9) = 362880
+factorial(10) = 3628800
+factorial(0) = 1
+factorial(1) = 1
+factorial(2) = 2
+factorial(3) = 6
+factorial(4) = 24
+factorial(5) = 120
+factorial(6) = 720
+factorial(7) = 5040
+factorial(8) = 40320
+factorial(9) = 362880
+factorial(10) = 3628800
+factorial(0) = 1
+factorial(1) = 1
+factorial(2) = 2
+factorial(3) = 6
+factorial(4) = 24
+factorial(5) = 120
+factorial(6) = 720
+factorial(7) = 5040
+factorial(8) = 40320
+factorial(9) = 362880
+factorial(10) = 3628800
+factorial(0) = 1
+factorial(1) = 1
+factorial(2) = 2
+factorial(3) = 6
+factorial(4) = 24
+factorial(5) = 120
+factorial(6) = 720
+factorial(7) = 5040
+factorial(8) = 40320
+factorial(9) = 362880
+factorial(10) = 3628800
+factorial(0) = 1
+factorial(1) = 1
+factorial(2) = 2
+factorial(3) = 6
+factorial(4) = 24
+factorial(5) = 120
+factorial(6) = 720
+factorial(7) = 5040
+factorial(8) = 40320
+factorial(9) = 362880
+factorial(10) = 3628800
+factorial(0) = 1
+factorial(1) = 1
+factorial(2) = 2
+factorial(3) = 6
+factorial(4) = 24
+factorial(5) = 120
+factorial(6) = 720
+factorial(7) = 5040
+factorial(8) = 40320
+factorial(9) = 362880
+factorial(10) = 3628800
+factorial(0) = 1
+factorial(1) = 1
+factorial(2) = 2
+factorial(3) = 6
+factorial(4) = 24
+factorial(5) = 120
+factorial(6) = 720
+factorial(7) = 5040
+factorial(8) = 40320
+factorial(9) = 362880
+factorial(10) = 3628800
+factorial(0) = 1
+factorial(1) = 1
+factorial(2) = 2
+factorial(3) = 6
+factorial(4) = 24
+factorial(5) = 120
+factorial(6) = 720
+factorial(7) = 5040
+factorial(8) = 40320
+factorial(9) = 362880
+factorial(10) = 3628800
+factorial(0) = 1
+factorial(1) = 1
+factorial(2) = 2
+factorial(3) = 6
+factorial(4) = 24
+factorial(5) = 120
+factorial(6) = 720
+factorial(7) = 5040
+factorial(8) = 40320
+factorial(9) = 362880
+factorial(10) = 3628800
+and now, from a function...
+(it should break at 5...)
+factorial(0) = 1
+factorial(1) = 1
+factorial(2) = 2
+factorial(3) = 6
+factorial(4) = 24
+(it should break at 5...)
+factorial(0) = 1
+factorial(1) = 1
+factorial(2) = 2
+factorial(3) = 6
+factorial(4) = 24
+(it should break at 5...)
+factorial(0) = 1
+factorial(1) = 1
+factorial(2) = 2
+factorial(3) = 6
+factorial(4) = 24
+(it should break at 5...)
+factorial(0) = 1
+factorial(1) = 1
+factorial(2) = 2
+factorial(3) = 6
+factorial(4) = 24
+(it should break at 5...)
+factorial(0) = 1
+factorial(1) = 1
+factorial(2) = 2
+factorial(3) = 6
+factorial(4) = 24
+(it should break at 5...)
+factorial(0) = 1
+factorial(1) = 1
+factorial(2) = 2
+factorial(3) = 6
+factorial(4) = 24
+(it should break at 5...)
+factorial(0) = 1
+factorial(1) = 1
+factorial(2) = 2
+factorial(3) = 6
+factorial(4) = 24
+(it should break at 5...)
+factorial(0) = 1
+factorial(1) = 1
+factorial(2) = 2
+factorial(3) = 6
+factorial(4) = 24
+(it should break at 5...)
+factorial(0) = 1
+factorial(1) = 1
+factorial(2) = 2
+factorial(3) = 6
+factorial(4) = 24
+(it should break at 5...)
+factorial(0) = 1
+factorial(1) = 1
+factorial(2) = 2
+factorial(3) = 6
+factorial(4) = 24
+------
+720
+840
+3
+4
+5
+
diff --git a/tests/func/004.phpt b/tests/func/004.phpt
new file mode 100644
index 0000000..1434297
--- /dev/null
+++ b/tests/func/004.phpt
@@ -0,0 +1,65 @@
+--TEST--
+General function test
+--FILE--
+<?php
+
+echo "Before function declaration...\n";
+
+function print_something_multiple_times($something,$times)
+{
+ echo "----\nIn function, printing the string \"$something\" $times times\n";
+ for ($i=0; $i<$times; $i++) {
+ echo "$i) $something\n";
+ }
+ echo "Done with function...\n-----\n";
+}
+
+function some_other_function()
+{
+ echo "This is some other function, to ensure more than just one function works fine...\n";
+}
+
+
+echo "After function declaration...\n";
+
+echo "Calling function for the first time...\n";
+print_something_multiple_times("This works!",10);
+echo "Returned from function call...\n";
+
+echo "Calling the function for the second time...\n";
+print_something_multiple_times("This like, really works and stuff...",3);
+echo "Returned from function call...\n";
+
+some_other_function();
+
+?>
+--EXPECT--
+
+Before function declaration...
+After function declaration...
+Calling function for the first time...
+----
+In function, printing the string "This works!" 10 times
+0) This works!
+1) This works!
+2) This works!
+3) This works!
+4) This works!
+5) This works!
+6) This works!
+7) This works!
+8) This works!
+9) This works!
+Done with function...
+-----
+Returned from function call...
+Calling the function for the second time...
+----
+In function, printing the string "This like, really works and stuff..." 3 times
+0) This like, really works and stuff...
+1) This like, really works and stuff...
+2) This like, really works and stuff...
+Done with function...
+-----
+Returned from function call...
+This is some other function, to ensure more than just one function works fine...
diff --git a/tests/func/005.phpt b/tests/func/005.phpt
new file mode 100644
index 0000000..c4215fe
--- /dev/null
+++ b/tests/func/005.phpt
@@ -0,0 +1,19 @@
+--TEST--
+Testing register_shutdown_function()
+--FILE--
+<?php
+
+function foo()
+{
+ print "foo";
+}
+
+register_shutdown_function("foo");
+
+print "foo() will be called on shutdown...\n";
+
+?>
+--EXPECT--
+foo() will be called on shutdown...
+foo
+
diff --git a/tests/func/005a.phpt b/tests/func/005a.phpt
new file mode 100644
index 0000000..3c2bcb1
--- /dev/null
+++ b/tests/func/005a.phpt
@@ -0,0 +1,32 @@
+--TEST--
+Testing register_shutdown_function() with timeout. (Bug: #21513)
+--SKIPIF--
+<?php
+if (getenv("SKIP_SLOW_TESTS")) die("skip slow test");
+?>
+--FILE--
+<?php
+
+ini_set('display_errors', 0);
+
+echo "Start\n";
+
+function boo()
+{
+ echo "Shutdown\n";
+}
+
+register_shutdown_function("boo");
+
+/* not necessary, just to show the error sooner */
+set_time_limit(1);
+
+/* infinite loop to simulate long processing */
+for (;;) {}
+
+echo "End\n";
+
+?>
+--EXPECT--
+Start
+Shutdown
diff --git a/tests/func/006.phpt b/tests/func/006.phpt
new file mode 100644
index 0000000..077b6f8
--- /dev/null
+++ b/tests/func/006.phpt
@@ -0,0 +1,26 @@
+--TEST--
+Output buffering tests
+--INI--
+output_buffering=0
+output_handler=
+zlib.output_compression=0
+zlib.output_handler=
+--FILE--
+<?php
+ob_start();
+echo ob_get_level();
+echo 'A';
+ ob_start();
+ echo ob_get_level();
+ echo 'B';
+ $b = ob_get_contents();
+ ob_end_clean();
+$a = ob_get_contents();
+ob_end_clean();
+
+var_dump( $b ); // 2B
+var_dump( $a ); // 1A
+?>
+--EXPECT--
+string(2) "2B"
+string(2) "1A"
diff --git a/tests/func/007.phpt b/tests/func/007.phpt
new file mode 100644
index 0000000..73aae2e
--- /dev/null
+++ b/tests/func/007.phpt
@@ -0,0 +1,22 @@
+--TEST--
+INI functions test
+--FILE--
+<?php
+
+$ini1 = ini_get('include_path');
+ini_set('include_path','ini_set_works');
+echo ini_get('include_path')."\n";
+ini_restore('include_path');
+$ini2 = ini_get('include_path');
+
+if ($ini1 !== $ini2) {
+ echo "ini_restore() does not work.\n";
+}
+else {
+ echo "ini_restore_works\n";
+}
+
+?>
+--EXPECT--
+ini_set_works
+ini_restore_works
diff --git a/tests/func/008.phpt b/tests/func/008.phpt
new file mode 100644
index 0000000..48098e1
--- /dev/null
+++ b/tests/func/008.phpt
@@ -0,0 +1,16 @@
+--TEST--
+Test for buffering in core functions with implicit flush off
+--INI--
+implicit_flush=0
+--FILE--
+<?php
+$res = var_export("foo1");
+echo "\n";
+$res = var_export("foo2", TRUE);
+echo "\n";
+echo $res."\n";
+?>
+--EXPECT--
+'foo1'
+
+'foo2'
diff --git a/tests/func/009.phpt b/tests/func/009.phpt
new file mode 100644
index 0000000..05b40e8
--- /dev/null
+++ b/tests/func/009.phpt
@@ -0,0 +1,16 @@
+--TEST--
+Test for buffering in core functions with implicit flush on
+--INI--
+implicit_flush=1
+--FILE--
+<?php
+$res = var_export("foo1");
+echo "\n";
+$res = var_export("foo2", TRUE);
+echo "\n";
+echo $res."\n";
+?>
+--EXPECT--
+'foo1'
+
+'foo2'
diff --git a/tests/func/010.phpt b/tests/func/010.phpt
new file mode 100644
index 0000000..f970283
--- /dev/null
+++ b/tests/func/010.phpt
@@ -0,0 +1,77 @@
+--TEST--
+function with many parameters
+--SKIPIF--
+<?php
+if (getenv("SKIP_SLOW_TESTS")) die("skip slow test");
+?>
+--FILE--
+<?php
+
+// the stack size + some random constant
+$boundary = 64*1024;
+$limit = $boundary+42;
+
+
+function test($a,$b)
+{
+ var_dump($a === $b);
+ test2($a,$b);
+}
+
+function test2($a, $b)
+{
+ if ($a !== $b) {
+ var_dump("something went wrong: $a !== $b");
+ }
+}
+
+
+// generate the function
+$str = "<?php\nfunction x(";
+
+for($i=0; $i < $limit; ++$i) {
+ $str .= '$v'.dechex($i).($i===($limit-1) ? '' : ',');
+}
+
+$str .= ') {
+ test($v42, \'42\');
+ test(\'4000\', $v4000);
+ test2($v300, \'300\');
+ test($v0, \'0\'); // first
+ test($v'.dechex($limit-1).", '".dechex($limit-1).'\'); // last
+ test($v'.dechex($boundary).", '".dechex($boundary).'\'); //boundary
+ test($v'.dechex($boundary+1).", '".dechex($boundary+1).'\'); //boundary+1
+ test($v'.dechex($boundary-1).", '".dechex($boundary-1).'\'); //boundary-1
+}';
+
+// generate the function call
+$str .= "\n\nx(";
+
+for($i=0; $i< $limit; ++$i) {
+ $str .= "'".dechex($i)."'".($i===($limit-1) ? '' : ',');
+}
+
+$str .= ");\n";
+
+$filename = dirname(__FILE__).'/010-file.php';
+file_put_contents(dirname(__FILE__).'/010-file.php', $str);
+unset($str);
+
+include($filename);
+
+echo "Done\n";
+
+?>
+--CLEAN--
+<?php
+@unlink(dirname(__FILE__).'/010-file.php');
+?>
+--EXPECT--
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+Done
diff --git a/tests/func/ini_alter.phpt b/tests/func/ini_alter.phpt
new file mode 100644
index 0000000..111e826
--- /dev/null
+++ b/tests/func/ini_alter.phpt
@@ -0,0 +1,19 @@
+--TEST--
+ini_alter() check
+--CREDITS--
+Sebastian Schürmann
+sebs@php.net
+Testfest 2009 Munich
+--FILE--
+<?php
+ini_alter('error_reporting', 1);
+$var = ini_get('error_reporting');
+var_dump($var);
+ini_alter('error_reporting', 0);
+$var = ini_get('error_reporting');
+var_dump($var);
+?>
+--EXPECT--
+string(1) "1"
+string(1) "0"
+