summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorandy wharmby <wharmby@php.net>2009-06-15 12:14:59 +0000
committerandy wharmby <wharmby@php.net>2009-06-15 12:14:59 +0000
commit04961ad0c0fe3d7e4b668bbe7493206c03a70d1d (patch)
tree5ecdb8476a8e8167a8045543a6d29acd1f207944
parent7012611307105fd82ec694b8c76f973743049ad5 (diff)
downloadphp-git-04961ad0c0fe3d7e4b668bbe7493206c03a70d1d.tar.gz
New POSIX extension tests from Berlin UG TestFest 2009.
-rw-r--r--ext/posix/tests/posix_access.phpt51
-rw-r--r--ext/posix/tests/posix_access_error_modes.phpt44
-rw-r--r--ext/posix/tests/posix_access_error_wrongparams.phpt42
-rw-r--r--ext/posix/tests/posix_access_safemode.phpt23
-rw-r--r--ext/posix/tests/posix_ctermid.phpt26
-rw-r--r--ext/posix/tests/posix_getgrgid.phpt45
-rw-r--r--ext/posix/tests/posix_getgrgid_macosx.phpt23
-rw-r--r--ext/posix/tests/posix_getgrgid_wrongparams.phpt28
-rw-r--r--ext/posix/tests/posix_getsid.phpt28
-rw-r--r--ext/posix/tests/posix_getsid_error.phpt28
-rw-r--r--ext/posix/tests/posix_mkfifo_safemode.phpt43
-rw-r--r--ext/posix/tests/posix_mkfifo_wrongparams.phpt21
-rw-r--r--ext/posix/tests/posix_times.phpt33
-rw-r--r--ext/posix/tests/posix_ttyname.phpt26
-rw-r--r--ext/posix/tests/posix_ttyname_error_wrongparams.phpt37
-rw-r--r--ext/posix/tests/posix_uname.phpt33
16 files changed, 531 insertions, 0 deletions
diff --git a/ext/posix/tests/posix_access.phpt b/ext/posix/tests/posix_access.phpt
new file mode 100644
index 0000000000..7082924b6e
--- /dev/null
+++ b/ext/posix/tests/posix_access.phpt
@@ -0,0 +1,51 @@
+--TEST--
+Test posix_access() function test
+--DESCRIPTION--
+checks for existence, read-access, write-access, execute-access
+--CREDITS--
+Moritz Neuhaeuser, info@xcompile.net
+PHP Testfest Berlin 2009-05-10
+--SKIPIF--
+<?php
+if (!extension_loaded('posix')) {
+ die('SKIP The posix extension is not loaded.');
+}
+
+if (posix_geteuid() == 0) {
+ die('SKIP Cannot run test as root.');
+}
+?>
+--INI--
+safe_mode = 1
+--FILE--
+<?php
+$filename = dirname(__FILE__) . '/foo.test';
+$fp = fopen($filename,"w");
+fwrite($fp,"foo");
+fclose($fp);
+
+chmod ($filename, 0000);
+var_dump(posix_access($filename, POSIX_F_OK));
+
+chmod ($filename, 0400);
+var_dump(posix_access($filename, POSIX_R_OK));
+
+chmod ($filename, 0600);
+var_dump(posix_access($filename, POSIX_W_OK));
+
+chmod ($filename, 0700);
+var_dump(posix_access($filename, POSIX_X_OK));
+?>
+===DONE===
+--CLEAN--
+<?php
+$filename = dirname(__FILE__) . '/foo.test';
+chmod ($filename, 0700);
+unlink($filename);
+?>
+--EXPECTF--
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+===DONE===
diff --git a/ext/posix/tests/posix_access_error_modes.phpt b/ext/posix/tests/posix_access_error_modes.phpt
new file mode 100644
index 0000000000..6e0d5dce82
--- /dev/null
+++ b/ext/posix/tests/posix_access_error_modes.phpt
@@ -0,0 +1,44 @@
+--TEST--
+Test posix_access() function test error conditions
+--DESCRIPTION--
+checks if posix_access() failes for wrong permissions
+--CREDITS--
+Moritz Neuhaeuser, info@xcompile.net
+PHP Testfest Berlin 2009-05-10
+--SKIPIF--
+<?php
+if (!extension_loaded('posix')) {
+ die('SKIP The posix extension is not loaded.');
+}
+if (posix_geteuid() == 0) {
+ die('SKIP Cannot run test as root.');
+}
+?>
+--INI--
+safe_mode = 1
+--FILE--
+<?php
+$filename = dirname(__FILE__) . '/foo.test';
+var_dump(posix_access($filename, POSIX_F_OK));
+$fp = fopen($filename,"w");
+fwrite($fp,"foo");
+fclose($fp);
+
+chmod ($filename, 0000);
+var_dump(posix_access($filename, POSIX_R_OK));
+var_dump(posix_access($filename, POSIX_W_OK));
+var_dump(posix_access($filename, POSIX_X_OK));
+?>
+===DONE===
+--CLEAN--
+<?php
+$filename = dirname(__FILE__) . '/foo.test';
+chmod ($filename, 0700);
+unlink($filename);
+?>
+--EXPECTF--
+bool(false)
+bool(false)
+bool(false)
+bool(false)
+===DONE===
diff --git a/ext/posix/tests/posix_access_error_wrongparams.phpt b/ext/posix/tests/posix_access_error_wrongparams.phpt
new file mode 100644
index 0000000000..56a2a65475
--- /dev/null
+++ b/ext/posix/tests/posix_access_error_wrongparams.phpt
@@ -0,0 +1,42 @@
+--TEST--
+Test posix_access() function : parameter validation
+--DESCRIPTION--
+cases: no params, wrong param1, wrong param2, null directory, wrong directory,
+--CREDITS--
+Moritz Neuhaeuser, info@xcompile.net
+PHP Testfest Berlin 2009-05-10
+--SKIPIF--
+<?php
+if (!extension_loaded('posix')) {
+ die('SKIP The posix extension is not loaded.');
+}
+if (posix_geteuid() == 0) {
+ die('SKIP Cannot run test as root.');
+}
+?>
+--INI--
+safe_mode = 1
+--FILE--
+<?php
+
+var_dump( posix_access() );
+var_dump( posix_access(array()) );
+var_dump( posix_access('foo',array()) );
+var_dump( posix_access(null) );
+
+var_dump(posix_access('./foobar'));
+?>
+===DONE===
+--EXPECTF--
+
+Warning: posix_access() expects at least 1 parameter, 0 given in %s on line %d
+bool(false)
+
+Warning: posix_access() expects parameter 1 to be string, array given in %s on line %d
+bool(false)
+
+Warning: posix_access() expects parameter 2 to be long, array given in %s on line %d
+bool(false)
+bool(false)
+bool(false)
+===DONE===
diff --git a/ext/posix/tests/posix_access_safemode.phpt b/ext/posix/tests/posix_access_safemode.phpt
new file mode 100644
index 0000000000..51baf186d2
--- /dev/null
+++ b/ext/posix/tests/posix_access_safemode.phpt
@@ -0,0 +1,23 @@
+--TEST--
+Test posix_access() with safe_mode enabled.
+--CREDITS--
+Till Klampaeckel, till@php.net
+TestFest Berlin 2009
+--SKIPIF--
+<?php
+if (!extension_loaded('posix')) {
+ die('SKIP The posix extension is not loaded.');
+}
+if (posix_geteuid() == 0) {
+ die('SKIP Cannot run test as root.');
+}
+--INI--
+safe_mode = 1
+--FILE--
+<?php
+var_dump(posix_access('/tmp', POSIX_W_OK));
+?>
+===DONE===
+--EXPECTF--
+bool(false)
+===DONE===
diff --git a/ext/posix/tests/posix_ctermid.phpt b/ext/posix/tests/posix_ctermid.phpt
new file mode 100644
index 0000000000..f77da00aab
--- /dev/null
+++ b/ext/posix/tests/posix_ctermid.phpt
@@ -0,0 +1,26 @@
+--TEST--
+Test posix_ctermid()
+--DESCRIPTION--
+Gets path name of controlling terminal.
+Source code: ext/posix/posix.c
+--CREDITS--
+Falko Menge, mail at falko-menge dot de
+PHP Testfest Berlin 2009-05-10
+--SKIPIF--
+<?php
+ if (!extension_loaded('posix')) {
+ die('SKIP - POSIX extension not available');
+ }
+ // needed because of #ifdef HAVE_CTERMID in posix.c
+ if (!function_exists('posix_ctermid')) {
+ die('SKIP - Fuction posix_ctermid() not available');
+ }
+?>
+--FILE--
+<?php
+ var_dump(posix_ctermid());
+?>
+===DONE===
+--EXPECTF--
+string(%d) "%s"
+===DONE===
diff --git a/ext/posix/tests/posix_getgrgid.phpt b/ext/posix/tests/posix_getgrgid.phpt
new file mode 100644
index 0000000000..0209d09732
--- /dev/null
+++ b/ext/posix/tests/posix_getgrgid.phpt
@@ -0,0 +1,45 @@
+--TEST--
+Test posix_getgrgid().
+--CREDITS--
+Till Klampaeckel, till@php.net
+TestFest Berlin 2009
+--SKIPIF--
+<?php
+if (!extension_loaded('posix')) {
+ die('SKIP The posix extension is not loaded.');
+}
+?>
+--FILE--
+<?php
+$grp = posix_getgrgid(0);
+if (!isset($grp['name'])) {
+ die('Array index "name" does not exist.');
+}
+if (!isset($grp['passwd'])) {
+ die('Array index "passwd" does not exist.');
+}
+if (!isset($grp['members'])) {
+ die('Array index "members" does not exist.');
+} elseif (!is_array($grp['members'])) {
+ die('Array index "members" must be an array.');
+} else {
+ if (count($grp['members']) > 0) {
+ foreach ($grp['members'] as $idx => $username) {
+ if (!is_int($idx)) {
+ die('Index in members Array is not an int.');
+ }
+ if (!is_string($username)) {
+ die('Username in members Array is not of type string.');
+ }
+ }
+ }
+}
+if (!isset($grp['gid'])) {
+ die('Array index "gid" does not exist.');
+}
+var_dump($grp['gid']);
+?>
+===DONE===
+--EXPECT--
+int(0)
+===DONE===
diff --git a/ext/posix/tests/posix_getgrgid_macosx.phpt b/ext/posix/tests/posix_getgrgid_macosx.phpt
new file mode 100644
index 0000000000..f9e6cc1d53
--- /dev/null
+++ b/ext/posix/tests/posix_getgrgid_macosx.phpt
@@ -0,0 +1,23 @@
+--TEST--
+Test return values of posix_getgrgid() on MacOSX.
+--CREDITS--
+Till Klampaeckel, till@php.net
+TestFest Berlin 2009
+--SKIPIF--
+<?php
+if (!extension_loaded('posix')) {
+ die('SKIP The posix extension is not loaded.');
+}
+if (strtolower(PHP_OS) != 'darwin') {
+ die('SKIP This test requires MacOSX/Darwin.');
+}
+?>
+--FILE--
+<?php
+$grp = posix_getgrgid(-1);
+var_dump($grp['name']);
+?>
+===DONE===
+--EXPECT--
+string(7) "nogroup"
+===DONE===
diff --git a/ext/posix/tests/posix_getgrgid_wrongparams.phpt b/ext/posix/tests/posix_getgrgid_wrongparams.phpt
new file mode 100644
index 0000000000..d1ff77d193
--- /dev/null
+++ b/ext/posix/tests/posix_getgrgid_wrongparams.phpt
@@ -0,0 +1,28 @@
+--TEST--
+Test parameters on posix_getgrgid().
+--CREDITS--
+Till Klampaeckel, till@php.net
+TestFest Berlin 2009
+--SKIPIF--
+<?php
+if (!extension_loaded('posix')) {
+ die('SKIP The posix extension is not loaded.');
+}
+if (strtolower(PHP_OS) == 'darwin') {
+ die('SKIP This test doesn\'t run on MacOSX/Darwin.');
+}
+--FILE--
+<?php
+$gid = PHP_INT_MAX; // obscene high gid
+var_dump(posix_getgrgid($gid));
+var_dump(posix_getgrgid(-1));
+var_dump(posix_getgrgid());
+?>
+===DONE===
+--EXPECTF--
+bool(false)
+bool(false)
+
+Warning: posix_getgrgid() expects exactly 1 parameter, 0 given in %s on line %d
+bool(false)
+===DONE===
diff --git a/ext/posix/tests/posix_getsid.phpt b/ext/posix/tests/posix_getsid.phpt
new file mode 100644
index 0000000000..62ed3c9ebd
--- /dev/null
+++ b/ext/posix/tests/posix_getsid.phpt
@@ -0,0 +1,28 @@
+--TEST--
+Test posix_getsid() function test
+--DESCRIPTION--
+Get the current session id of a process pid (POSIX.1, 4.2.1)
+Source code: ext/posix/posix.c
+--CREDITS--
+Moritz Neuhaeuser, info@xcompile.net
+PHP Testfest Berlin 2009-05-10
+--SKIPIF--
+<?php
+ if(!extension_loaded("posix")) print "SKIP - POSIX extension not loaded";
+?>
+--FILE--
+<?php
+echo "*** Testing posix_getsid() : function test ***\n";
+
+$pid = posix_getpid();
+echo "\n-- Testing posix_getsid() function with current process pid --\n";
+var_dump( is_long(posix_getsid($pid)) );
+
+?>
+===DONE===
+--EXPECTF--
+*** Testing posix_getsid() : function test ***
+
+-- Testing posix_getsid() function with current process pid --
+bool(true)
+===DONE===
diff --git a/ext/posix/tests/posix_getsid_error.phpt b/ext/posix/tests/posix_getsid_error.phpt
new file mode 100644
index 0000000000..445bc5a876
--- /dev/null
+++ b/ext/posix/tests/posix_getsid_error.phpt
@@ -0,0 +1,28 @@
+--TEST--
+Test posix_getsid() function : error conditions
+--DESCRIPTION--
+cases: no params, wrong param, wrong param range
+--CREDITS--
+Moritz Neuhaeuser, info@xcompile.net
+PHP Testfest Berlin 2009-05-10
+--SKIPIF--
+<?php
+ if(!extension_loaded("posix")) {
+ die("SKIP - POSIX extension not loaded");
+ }
+?>
+--FILE--
+<?php
+var_dump( posix_getsid() );
+var_dump( posix_getsid(array()) );
+var_dump( posix_getsid(-1) );
+?>
+===DONE===
+--EXPECTF--
+Warning: posix_getsid() expects exactly 1 parameter, 0 given in %s on line %d
+bool(false)
+
+Warning: posix_getsid() expects parameter 1 to be long, array given in %s on line %d
+bool(false)
+bool(false)
+===DONE===
diff --git a/ext/posix/tests/posix_mkfifo_safemode.phpt b/ext/posix/tests/posix_mkfifo_safemode.phpt
new file mode 100644
index 0000000000..6a928f8bc8
--- /dev/null
+++ b/ext/posix/tests/posix_mkfifo_safemode.phpt
@@ -0,0 +1,43 @@
+--TEST--
+Test posix_mkfifo() with safe_mode.
+--DESCRIPTION--
+The test attempts to enable safe_mode, catches all the relevant E_WARNING's and tries to create a fifo in /tmp.
+
+The first attempt (writing to /tmp) should effectively fail because /tmp is owned by root.
+
+The second attempt (writing to a local created file) works.
+--CREDITS--
+Till Klampaeckel, till@php.net
+TestFest Berlin 2009
+--SKIPIF--
+<?php
+if (!extension_loaded('posix')) {
+ die('SKIP The posix extension is not loaded.');
+}
+if (posix_geteuid() == 0) {
+ die('SKIP Cannot run test as root.');
+}
+?>
+--INI--
+safe_mode = 1
+--FILE--
+<?php
+var_dump(posix_mkfifo('/tmp/foobar', 0644));
+
+$dir = dirname(__FILE__) . '/foo';
+mkdir ($dir);
+var_dump(posix_mkfifo($dir . '/bar', 0644));
+?>
+===DONE===
+--CLEAN--
+<?php
+$dir = dirname(__FILE__) . '/foo';
+unlink($dir . '/bar');
+rmdir($dir);
+?>
+--EXPECTF--
+
+Warning: posix_mkfifo(): SAFE MODE Restriction in effect. The script whose uid is %d is not allowed to access /tmp owned by uid %d in %s on line %d
+bool(false)
+bool(true)
+===DONE===
diff --git a/ext/posix/tests/posix_mkfifo_wrongparams.phpt b/ext/posix/tests/posix_mkfifo_wrongparams.phpt
new file mode 100644
index 0000000000..0d4df7b6e6
--- /dev/null
+++ b/ext/posix/tests/posix_mkfifo_wrongparams.phpt
@@ -0,0 +1,21 @@
+--TEST--
+Test parameter validation in posix_mkfifo().
+--CREDITS--
+Till Klampaeckel, till@php.net
+TestFest Berlin 2009
+--SKIPIF--
+<?php
+if (!extension_loaded('posix')) {
+ die('SKIP The posix extension is not loaded.');
+}
+?>
+--FILE--
+<?php
+posix_mkfifo(null);
+var_dump(posix_mkfifo(null, 0644));
+?>
+===DONE===
+--EXPECTF--
+Warning: posix_mkfifo() expects exactly 2 parameters, 1 given in %s on line %d
+bool(false)
+===DONE===
diff --git a/ext/posix/tests/posix_times.phpt b/ext/posix/tests/posix_times.phpt
new file mode 100644
index 0000000000..6ad3407ccb
--- /dev/null
+++ b/ext/posix/tests/posix_times.phpt
@@ -0,0 +1,33 @@
+--TEST--
+Test posix_times()
+--DESCRIPTION--
+Gets information about the current CPU usage.
+Source code: ext/posix/posix.c
+--CREDITS--
+Falko Menge, mail at falko-menge dot de
+PHP Testfest Berlin 2009-05-10
+--SKIPIF--
+<?php
+ if (!extension_loaded('posix')) {
+ die('SKIP - POSIX extension not available');
+ }
+?>
+--FILE--
+<?php
+ var_dump(posix_times());
+?>
+===DONE===
+--EXPECTF--
+array(5) {
+ ["ticks"]=>
+ int(%i)
+ ["utime"]=>
+ int(%d)
+ ["stime"]=>
+ int(%d)
+ ["cutime"]=>
+ int(%d)
+ ["cstime"]=>
+ int(%d)
+}
+===DONE===
diff --git a/ext/posix/tests/posix_ttyname.phpt b/ext/posix/tests/posix_ttyname.phpt
new file mode 100644
index 0000000000..76dff4e4c0
--- /dev/null
+++ b/ext/posix/tests/posix_ttyname.phpt
@@ -0,0 +1,26 @@
+--TEST--
+Test posix_ttyname()
+--DESCRIPTION--
+Gets the absolute path to the current terminal device that is open on a given file descriptor.
+Source code: ext/posix/posix.c
+--CREDITS--
+Falko Menge, mail at falko-menge dot de
+PHP Testfest Berlin 2009-05-10
+--SKIPIF--
+<?php
+ if (!extension_loaded('posix')) {
+ die('SKIP - POSIX extension not available');
+ }
+?>
+--FILE--
+<?php
+ var_dump(posix_ttyname(STDIN));
+ var_dump(posix_ttyname(STDERR));
+ var_dump(posix_ttyname(STDOUT));
+?>
+===DONE===
+--EXPECTF--
+bool(false)
+bool(false)
+bool(false)
+===DONE===
diff --git a/ext/posix/tests/posix_ttyname_error_wrongparams.phpt b/ext/posix/tests/posix_ttyname_error_wrongparams.phpt
new file mode 100644
index 0000000000..daa487f853
--- /dev/null
+++ b/ext/posix/tests/posix_ttyname_error_wrongparams.phpt
@@ -0,0 +1,37 @@
+--TEST--
+Test posix_ttyname() with wrong parameters
+--DESCRIPTION--
+Gets the absolute path to the current terminal device that is open on a given file descriptor.
+Source code: ext/posix/posix.c
+--CREDITS--
+Falko Menge, mail at falko-menge dot de
+PHP Testfest Berlin 2009-05-10
+--SKIPIF--
+<?php
+ if (!extension_loaded('posix')) {
+ die('SKIP - POSIX extension not available');
+ }
+ if (!extension_loaded('gd')) {
+ die('SKIP - GD extension not available');
+ }
+ if (!function_exists('imagecreate')) {
+ die('SKIP - Function imagecreate() not available');
+ }
+?>
+--FILE--
+<?php
+ var_dump(posix_ttyname()); // param missing
+ var_dump(posix_ttyname(0)); // param not a ressource
+ var_dump(posix_ttyname(imagecreate(1, 1))); // wrong resource type
+?>
+===DONE===
+--EXPECTF--
+Warning: posix_ttyname() expects exactly 1 parameter, 0 given in %s on line %d
+bool(false)
+bool(false)
+
+Warning: posix_ttyname(): supplied resource is not a valid stream resource in %s on line %s
+
+Warning: posix_ttyname(): expects argument 1 to be a valid stream resource in %s on line %d
+bool(false)
+===DONE===
diff --git a/ext/posix/tests/posix_uname.phpt b/ext/posix/tests/posix_uname.phpt
new file mode 100644
index 0000000000..12c4baec16
--- /dev/null
+++ b/ext/posix/tests/posix_uname.phpt
@@ -0,0 +1,33 @@
+--TEST--
+Test posix_uname()
+--DESCRIPTION--
+Gets information about the system.
+Source code: ext/posix/posix.c
+--CREDITS--
+Falko Menge, mail at falko-menge dot de
+PHP Testfest Berlin 2009-05-10
+--SKIPIF--
+<?php
+ if (!extension_loaded('posix')) {
+ die('SKIP - POSIX extension not available');
+ }
+?>
+--FILE--
+<?php
+ var_dump(posix_uname());
+?>
+===DONE===
+--EXPECTF--
+array(5) {
+ ["sysname"]=>
+ string(%d) "%s"
+ ["nodename"]=>
+ string(%d) "%s"
+ ["release"]=>
+ string(%d) "%s"
+ ["version"]=>
+ string(%d) "%s"
+ ["machine"]=>
+ string(%d) "%s"
+}
+===DONE===