diff options
author | andy wharmby <wharmby@php.net> | 2009-06-15 12:14:55 +0000 |
---|---|---|
committer | andy wharmby <wharmby@php.net> | 2009-06-15 12:14:55 +0000 |
commit | 4a110443df241e79dd86039036bbab2b0d8d0335 (patch) | |
tree | 04c8bf79a103a7bd4f1ee34d901bb3a140cd9f73 /ext/posix | |
parent | e52e1fab4ce44e3bfda096eeb146c3d1fa0d8a96 (diff) | |
download | php-git-4a110443df241e79dd86039036bbab2b0d8d0335.tar.gz |
New POSIX extension tests from Berlin UG TestFest 2009.
Diffstat (limited to 'ext/posix')
-rw-r--r-- | ext/posix/tests/posix_access.phpt | 51 | ||||
-rw-r--r-- | ext/posix/tests/posix_access_error_modes.phpt | 45 | ||||
-rw-r--r-- | ext/posix/tests/posix_access_error_wrongparams.phpt | 43 | ||||
-rw-r--r-- | ext/posix/tests/posix_access_safemode.phpt | 24 | ||||
-rw-r--r-- | ext/posix/tests/posix_ctermid.phpt | 26 | ||||
-rw-r--r-- | ext/posix/tests/posix_getgrgid.phpt | 45 | ||||
-rw-r--r-- | ext/posix/tests/posix_getgrgid_macosx.phpt | 23 | ||||
-rw-r--r-- | ext/posix/tests/posix_getgrgid_wrongparams.phpt | 28 | ||||
-rw-r--r-- | ext/posix/tests/posix_getsid.phpt | 28 | ||||
-rw-r--r-- | ext/posix/tests/posix_getsid_error.phpt | 28 | ||||
-rw-r--r-- | ext/posix/tests/posix_mkfifo_safemode.phpt | 44 | ||||
-rw-r--r-- | ext/posix/tests/posix_mkfifo_wrongparams.phpt | 21 | ||||
-rw-r--r-- | ext/posix/tests/posix_times.phpt | 33 | ||||
-rw-r--r-- | ext/posix/tests/posix_ttyname.phpt | 26 | ||||
-rw-r--r-- | ext/posix/tests/posix_ttyname_error_wrongparams.phpt | 37 | ||||
-rw-r--r-- | ext/posix/tests/posix_uname.phpt | 33 |
16 files changed, 535 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..a427f8a192 --- /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-- +PHP Warning: Directive 'safe_mode' is deprecated in PHP 5.3 and greater in %s on line %d +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..bfe366f819 --- /dev/null +++ b/ext/posix/tests/posix_access_error_modes.phpt @@ -0,0 +1,45 @@ +--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-- +PHP Warning: Directive 'safe_mode' is deprecated in PHP 5.3 and greater in Unknown on line %d +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..04f933545d --- /dev/null +++ b/ext/posix/tests/posix_access_error_wrongparams.phpt @@ -0,0 +1,43 @@ +--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-- +PHP Warning: Directive 'safe_mode' is deprecated in PHP 5.3 and greater in Unknown on line 0 + +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..6055c8074d --- /dev/null +++ b/ext/posix/tests/posix_access_safemode.phpt @@ -0,0 +1,24 @@ +--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-- +PHP Warning: Directive 'safe_mode' is deprecated in PHP 5.3 and greater in %s on line %d +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..4cbcc6878b --- /dev/null +++ b/ext/posix/tests/posix_mkfifo_safemode.phpt @@ -0,0 +1,44 @@ +--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-- +PHP Warning: Directive 'safe_mode' is deprecated in PHP 5.3 and greater in %s on line %d + +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=== |