wharmby         Sat Jan 24 12:47:36 2009 UTC

  Modified files:              
    /php-src/ext/standard/tests/general_functions       getrusage_basic.phpt 
                                                        
get_extension_funcs_basic.phpt 
                                                        
getrusage_variation1.phpt 
                                                        getrusage_error.phpt 
                                                        
get_extension_funcs_variation.phpt 
                                                        
get_extension_funcs_error.phpt 
  Log:
  New get_extension_funcs() and getrusage() tests. Tested on Windows, Linux and 
Linux 64 bit
  
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/general_functions/getrusage_basic.phpt?r1=1.1&r2=1.2&diff_format=u
Index: php-src/ext/standard/tests/general_functions/getrusage_basic.phpt
diff -u /dev/null 
php-src/ext/standard/tests/general_functions/getrusage_basic.phpt:1.2
--- /dev/null   Sat Jan 24 12:47:36 2009
+++ php-src/ext/standard/tests/general_functions/getrusage_basic.phpt   Sat Jan 
24 12:47:36 2009
@@ -0,0 +1,33 @@
+--TEST--
+Test getrusage() function: basic test
+--SKIPIF--
+<?php
+if( substr(PHP_OS, 0, 3) == "WIN" )
+  die("skip.. Do not run on Windows");
+?>
+--FILE--
+<?php
+/* Prototype  :  array getrusage  ([ int $who  ] )
+ * Description: Gets the current resource usages
+ * Source code: ext/standard/microtime.c
+ * Alias to functions: 
+ */
+
+echo "Simple testcase for getrusage() function\n";
+
+$dat = getrusage();
+
+if (!is_array($dat)) {
+       echo "TEST FAILED : getrusage shoudl return an array\n";
+}      
+
+// echo the fields which are common to all platforms 
+echo "User time used (seconds) " . $dat["ru_utime.tv_sec"] . "\n";
+echo "User time used (microseconds) " . $dat["ru_utime.tv_usec"] . "\n"; 
+?>
+===DONE===
+--EXPECTF--
+Simple testcase for getrusage() function
+User time used (seconds) %d
+User time used (microseconds) %d
+===DONE===
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/general_functions/get_extension_funcs_basic.phpt?r1=1.1&r2=1.2&diff_format=u
Index: 
php-src/ext/standard/tests/general_functions/get_extension_funcs_basic.phpt
diff -u /dev/null 
php-src/ext/standard/tests/general_functions/get_extension_funcs_basic.phpt:1.2
--- /dev/null   Sat Jan 24 12:47:36 2009
+++ php-src/ext/standard/tests/general_functions/get_extension_funcs_basic.phpt 
Sat Jan 24 12:47:36 2009
@@ -0,0 +1,23 @@
+--TEST--
+Test get_extension_funcs() function: basic test
+--FILE--
+<?php
+/* Prototype  : array get_extension_funcs  ( string $module_name  )
+ * Description: Returns an array with the names of the functions of a module.
+ * Source code: Zend/zend_builtin_functions.c
+ * Alias to functions: 
+ */
+
+echo "Simple testcase for get_extension_funcs() function\n";
+
+$result = get_extension_funcs("standard");
+var_dump(gettype($result));
+var_dump(in_array("cos", $result));
+
+?>
+===DONE===
+--EXPECTF--
+Simple testcase for get_extension_funcs() function
+unicode(5) "array"
+bool(true)
+===DONE===
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/general_functions/getrusage_variation1.phpt?r1=1.1&r2=1.2&diff_format=u
Index: php-src/ext/standard/tests/general_functions/getrusage_variation1.phpt
diff -u /dev/null 
php-src/ext/standard/tests/general_functions/getrusage_variation1.phpt:1.2
--- /dev/null   Sat Jan 24 12:47:36 2009
+++ php-src/ext/standard/tests/general_functions/getrusage_variation1.phpt      
Sat Jan 24 12:47:36 2009
@@ -0,0 +1,142 @@
+--TEST--
+Test getrusage() function : usage variation - diff data types as $who arg
+--SKIPIF--
+<?php
+if( substr(PHP_OS, 0, 3) == "WIN" )
+  die("skip.. Do not run on Windows");
+?>
+--FILE--
+<?php
+/* Prototype  :  array getrusage  ([ int $who  ] )
+ * Description: Gets the current resource usages
+ * Source code: ext/standard/microtime.c
+ * Alias to functions: 
+ */
+
+
+/*
+ * Pass different data types as $who argument to test behaviour of getrusage()
+ */
+
+echo "*** Testing getrusage() : usage variations ***\n";
+
+//get an unset variable
+$unset_var = 10;
+unset ($unset_var);
+
+
+// unexpected values to be passed to $stream_id argument
+$inputs = array(
+
+       // int data
+/*1*/  0,
+       1,
+       12345,
+       -2345,
+
+       // float data
+/*5*/  10.5,
+       -10.5,
+       12.3456789000e10,
+       12.3456789000E-10,
+       .5,
+
+       // null data
+/*10*/ NULL,
+       null,
+
+       // boolean data
+/*12*/ true,
+       false,
+       TRUE,
+       FALSE,
+       
+       // string data
+/*16*/ "0",
+       '1',
+       "1232456",
+       "1.23E4",
+       
+       // undefined data
+/*20*/ @$undefined_var,
+
+       // unset data
+/*21*/ @$unset_var,
+);
+
+// loop through each element of $inputs to check the behavior of getrusage()
+$iterator = 1;
+foreach($inputs as $input) {
+  echo "\n-- Iteration $iterator --\n";
+  $res = getrusage($input);
+  echo "User time used (microseconds) " . $res["ru_utime.tv_usec"] . "\n";
+  $iterator++;
+}
+?>
+===DONE===
+--EXPECTF--
+*** Testing getrusage() : usage variations ***
+
+-- Iteration 1 --
+User time used (microseconds) %d
+
+-- Iteration 2 --
+User time used (microseconds) %d
+
+-- Iteration 3 --
+User time used (microseconds) %d
+
+-- Iteration 4 --
+User time used (microseconds) %d
+
+-- Iteration 5 --
+User time used (microseconds) %d
+
+-- Iteration 6 --
+User time used (microseconds) %d
+
+-- Iteration 7 --
+User time used (microseconds) %d
+
+-- Iteration 8 --
+User time used (microseconds) %d
+
+-- Iteration 9 --
+User time used (microseconds) %d
+
+-- Iteration 10 --
+User time used (microseconds) %d
+
+-- Iteration 11 --
+User time used (microseconds) %d
+
+-- Iteration 12 --
+User time used (microseconds) %d
+
+-- Iteration 13 --
+User time used (microseconds) %d
+
+-- Iteration 14 --
+User time used (microseconds) %d
+
+-- Iteration 15 --
+User time used (microseconds) %d
+
+-- Iteration 16 --
+User time used (microseconds) %d
+
+-- Iteration 17 --
+User time used (microseconds) %d
+
+-- Iteration 18 --
+User time used (microseconds) %d
+
+-- Iteration 19 --
+User time used (microseconds) %d
+
+-- Iteration 20 --
+User time used (microseconds) %d
+
+-- Iteration 21 --
+User time used (microseconds) %d
+===DONE===
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/general_functions/getrusage_error.phpt?r1=1.1&r2=1.2&diff_format=u
Index: php-src/ext/standard/tests/general_functions/getrusage_error.phpt
diff -u /dev/null 
php-src/ext/standard/tests/general_functions/getrusage_error.phpt:1.2
--- /dev/null   Sat Jan 24 12:47:36 2009
+++ php-src/ext/standard/tests/general_functions/getrusage_error.phpt   Sat Jan 
24 12:47:36 2009
@@ -0,0 +1,73 @@
+--TEST--
+Test getrusage() function : error conditions - incorrect number of args
+--SKIPIF--
+<?php
+if( substr(PHP_OS, 0, 3) == "WIN" )
+  die("skip.. Do not run on Windows");
+?>
+--FILE--
+<?php
+/* Prototype  :  array getrusage  ([ int $who  ] )
+ * Description: Gets the current resource usages
+ * Source code: ext/standard/microtime.c
+ * Alias to functions: 
+ */
+
+/*
+ * Pass an incorrect number of arguments to getrusage() to test behaviour
+ */
+
+echo "*** Testing getrusage() : error conditions ***\n";
+
+echo "\n-- Testing getrusage() function with more than expected no. of 
arguments --\n";
+$extra_arg = 10;
+$dat = getrusage(1, $extra_arg);
+
+echo "\n-- Testing getrusage() function with invalid argument - non-numeric 
STRING--\n";
+$string_arg = "foo";
+$dat = getrusage($string_arg);
+
+echo "\n-- Testing getrusage() function with invalid argument - ARRAY--\n";
+$array_arg = array(1,2,3);
+$dat = getrusage($array_arg);
+
+echo "\n-- Testing getrusage() function with invalid argument - OBJECT --\n";
+class classA 
+{
+  function __toString() {
+    return "ClassAObject";
+  }
+}
+$obj_arg = new classA();
+$dat = getrusage($obj_arg);
+
+echo "\n-- Testing getrusage() function with invalid argument - RESOURCE --\n";
+$file_handle=fopen(__FILE__, "r");
+$dat = getrusage($file_handle);
+fclose($file_handle);
+
+?>
+===DONE===
+--EXPECTF--
+*** Testing getrusage() : error conditions ***
+
+-- Testing getrusage() function with more than expected no. of arguments --
+
+Warning: getrusage() expects at most 1 parameter, 2 given in %s on line %d
+
+-- Testing getrusage() function with invalid argument - non-numeric STRING--
+
+Warning: getrusage() expects parameter 1 to be long, Unicode string given in 
%s on line %d
+
+-- Testing getrusage() function with invalid argument - ARRAY--
+
+Warning: getrusage() expects parameter 1 to be long, array given in %s on line 
%d
+
+-- Testing getrusage() function with invalid argument - OBJECT --
+
+Warning: getrusage() expects parameter 1 to be long, object given in %s on 
line %d
+
+-- Testing getrusage() function with invalid argument - RESOURCE --
+
+Warning: getrusage() expects parameter 1 to be long, resource given in %s on 
line %d
+===DONE===
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/general_functions/get_extension_funcs_variation.phpt?r1=1.1&r2=1.2&diff_format=u
Index: 
php-src/ext/standard/tests/general_functions/get_extension_funcs_variation.phpt
diff -u /dev/null 
php-src/ext/standard/tests/general_functions/get_extension_funcs_variation.phpt:1.2
--- /dev/null   Sat Jan 24 12:47:36 2009
+++ 
php-src/ext/standard/tests/general_functions/get_extension_funcs_variation.phpt 
    Sat Jan 24 12:47:36 2009
@@ -0,0 +1,137 @@
+--TEST--
+Test get_extension_funcs() function : error conditions 
+--FILE--
+<?php
+/* Prototype  : array get_extension_funcs  ( string $module_name  )
+ * Description: Returns an array with the names of the functions of a module.
+ * Source code: Zend/zend_builtin_functions.c
+ * Alias to functions: 
+ */
+
+echo "*** Testing get_extension_funcs() function: with unexpected inputs for 
'module_name' argument ***\n";
+
+//get an unset variable
+$unset_var = 'string_val';
+unset($unset_var);
+
+//defining a class
+class sample  {
+  public function __toString() {
+    return "sample object";
+  } 
+}
+
+//getting the resource
+$file_handle = fopen(__FILE__, "r");
+
+// array with different values for $str
+$inputs =  array (
+
+  // integer values
+  0,
+  1,
+  255,
+  256,
+  PHP_INT_MAX,
+  -PHP_INT_MAX,
+
+  // float values
+  10.5,
+  -20.5,
+  10.1234567e10,
+
+  // array values
+  array(),
+  array(0),
+  array(1, 2),
+
+  // boolean values
+  true,
+  false,
+  TRUE,
+  FALSE,
+
+  // null values
+  NULL,
+  null,
+
+  // objects
+  new sample(),
+
+  // resource
+  $file_handle,
+
+  // undefined variable
+  @$undefined_var,
+
+  // unset variable
+  @$unset_var
+);
+
+// loop through with each element of the $inputs array to test 
get_extension_funcs() function
+$count = 1;
+foreach($inputs as $input) {
+  echo "-- Iteration $count --\n";
+  var_dump( get_extension_funcs($input) );
+  $count ++;
+}
+
+fclose($file_handle);  //closing the file handle
+
+?>
+===DONE===
+--EXPECTF--
+*** Testing get_extension_funcs() function: with unexpected inputs for 
'module_name' argument ***
+-- Iteration 1 --
+bool(false)
+-- Iteration 2 --
+bool(false)
+-- Iteration 3 --
+bool(false)
+-- Iteration 4 --
+bool(false)
+-- Iteration 5 --
+bool(false)
+-- Iteration 6 --
+bool(false)
+-- Iteration 7 --
+bool(false)
+-- Iteration 8 --
+bool(false)
+-- Iteration 9 --
+bool(false)
+-- Iteration 10 --
+
+Warning: get_extension_funcs() expects parameter 1 to be string (Unicode or 
binary), array given in %s on line %d
+NULL
+-- Iteration 11 --
+
+Warning: get_extension_funcs() expects parameter 1 to be string (Unicode or 
binary), array given in %s on line %d
+NULL
+-- Iteration 12 --
+
+Warning: get_extension_funcs() expects parameter 1 to be string (Unicode or 
binary), array given in %s on line %d
+NULL
+-- Iteration 13 --
+bool(false)
+-- Iteration 14 --
+bool(false)
+-- Iteration 15 --
+bool(false)
+-- Iteration 16 --
+bool(false)
+-- Iteration 17 --
+bool(false)
+-- Iteration 18 --
+bool(false)
+-- Iteration 19 --
+bool(false)
+-- Iteration 20 --
+
+Warning: get_extension_funcs() expects parameter 1 to be string (Unicode or 
binary), resource given in %s on line %d
+NULL
+-- Iteration 21 --
+bool(false)
+-- Iteration 22 --
+bool(false)
+===DONE===
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/general_functions/get_extension_funcs_error.phpt?r1=1.1&r2=1.2&diff_format=u
Index: 
php-src/ext/standard/tests/general_functions/get_extension_funcs_error.phpt
diff -u /dev/null 
php-src/ext/standard/tests/general_functions/get_extension_funcs_error.phpt:1.2
--- /dev/null   Sat Jan 24 12:47:36 2009
+++ php-src/ext/standard/tests/general_functions/get_extension_funcs_error.phpt 
Sat Jan 24 12:47:36 2009
@@ -0,0 +1,40 @@
+--TEST--
+Test get_extension_funcs() function : error conditions 
+--FILE--
+<?php
+/* Prototype  : array get_extension_funcs  ( string $module_name  )
+ * Description: Returns an array with the names of the functions of a module.
+ * Source code: Zend/zend_builtin_functions.c
+ * Alias to functions: 
+ */
+
+echo "*** Testing get_extension_funcs() : error conditions ***\n";
+
+echo "\n-- Too few arguments --\n";
+var_dump(get_extension_funcs());
+
+$extra_arg = 1;
+echo "\n-- Too many arguments --\n";
+var_dump(get_extension_funcs("standard", $extra_arg));
+
+echo "\n-- Invalid extension name --\n";
+var_dump(get_extension_funcs("foo"));
+
+?>
+===DONE===
+--EXPECTF--
+*** Testing get_extension_funcs() : error conditions ***
+
+-- Too few arguments --
+
+Warning: get_extension_funcs() expects exactly 1 parameter, 0 given in %s on 
line %d
+NULL
+
+-- Too many arguments --
+
+Warning: get_extension_funcs() expects exactly 1 parameter, 2 given in %s on 
line %d
+NULL
+
+-- Invalid extension name --
+bool(false)
+===DONE===

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to