]> granicus.if.org Git - php/commitdiff
- fix test, rewrite it (same cases are tested), CS, simplify, be verbose on error...
authorPierre Joye <pajoye@php.net>
Sat, 30 Jan 2010 17:06:06 +0000 (17:06 +0000)
committerPierre Joye <pajoye@php.net>
Sat, 30 Jan 2010 17:06:06 +0000 (17:06 +0000)
ext/standard/tests/file/tempnam_variation3-win32.phpt

index ec7718f970cb94e761847b971980ed95658cd139..00f5e1c0e9b68653c9c4857f7bf21978242f45c2 100644 (file)
@@ -15,106 +15,100 @@ if(substr(PHP_OS, 0, 3) != "WIN")
 
 echo "*** Testing tempnam() with obscure prefixes ***\n";
 $file_path = dirname(__FILE__)."/tempnamVar3";
-mkdir($file_path);
+if (!mkdir($file_path)) {
+       echo "Failed, cannot create temp dir $filepath\n";
+       exit(1);
+}
+
+$file_path = realpath($file_path);
 
 /* An array of prefixes */ 
 $names_arr = array(
-  /* Invalid args */ 
-  -1,
-  TRUE,
-  FALSE,
-  NULL,
-  "",
-  " ",
-  "\0",
-  array(),
+       /* Valid args (casting)*/ 
+       -1,
+       TRUE,
+       FALSE,
+       NULL,
+       "",
+       " ",
+       "\0",
+       /* Invalid args */ 
+       array(),
+
+       /* Valid args*/ 
+       /* prefix with path separator of a non existing directory*/
+       "/no/such/file/dir", 
+       "php/php"
+);
 
-  /* prefix with path separator of a non existing directory*/
-  "/no/such/file/dir", 
-  "php/php"
+$res_arr = array(
+       /* Invalid args */ 
+       true,
+       true,
+       true,
+       true,
+       true,
+       true,
+       true,
+       false,
 
+       /* prefix with path separator of a non existing directory*/
+       true, 
+       true
 );
 
 for( $i=0; $i<count($names_arr); $i++ ) {
-  echo "-- Iteration $i --\n";
-  $file_name = tempnam("$file_path", $names_arr[$i]);
+       echo "-- Iteration $i --\n";
+       $file_name = tempnam($file_path, $names_arr[$i]);
 
-  /* creating the files in existing dir */
-  if( file_exists($file_name) ) {
-    echo "File name is => ";
-    print($file_name);
-    echo "\n";
+       /* creating the files in existing dir */
+       if (file_exists($file_name) && !$res_arr[$i]) {
+               echo "Failed\n";
+       }
+       if ($res_arr[$i]) {
+               $file_dir = dirname($file_name);
+               if (realpath($file_dir) == $file_path || realpath($file_dir . "\\") == $file_path) {
+                       echo "OK\n";
+               } else {
+                       echo "Failed, not created in the correct directory" . realpath($file_dir) . ' vs ' . $file_path ."\n";
+               }
+               
+               if (!is_writable($file_name)) {
+                       printf("%o\n", fileperms($file_name) );
 
-    echo "File permissions are => ";
-    printf("%o", fileperms($file_name) );
-    echo "\n";
-    
-    echo "File created in => ";
-    $file_dir = dirname($file_name);
-    if (realpath($file_dir) == realpath(sys_get_temp_dir()) || realpath($file_dir."\\") == realpath(sys_get_temp_dir())) {
-       echo "temp dir\n";
-    }
-    else if (realpath($file_dir) == realpath($file_path) || realpath($file_dir."\\") == realpath($file_path)) {    
-       echo "directory specified\n";
-    }
-    else {
-       echo "unknown location\n";
-    }         
-  }
-  else {
-    echo "-- File is not created --\n";
-  }
-
-  unlink($file_name);
+               }
+       } else {
+               echo "OK\n";
+       }
+       @unlink($file_name);
 }
 
 rmdir($file_path);
-echo "\n*** Done ***\n";
+echo "\n*** Done. ***\n";
 ?>
 --EXPECTF--
 *** Testing tempnam() with obscure prefixes ***
 -- Iteration 0 --
-File name is => %s\%s
-File permissions are => 100666
-File created in => directory specified
+OK
 -- Iteration 1 --
-File name is => %s\%s
-File permissions are => 100666
-File created in => directory specified
+OK
 -- Iteration 2 --
-File name is => %s\%s
-File permissions are => 100666
-File created in => directory specified
+OK
 -- Iteration 3 --
-File name is => %s\%s
-File permissions are => 100666
-File created in => directory specified
+OK
 -- Iteration 4 --
-File name is => %s\%s
-File permissions are => 100666
-File created in => directory specified
+OK
 -- Iteration 5 --
-File name is => %s\%s
-File permissions are => 100666
-File created in => directory specified
+OK
 -- Iteration 6 --
-File name is => %s\%s
-File permissions are => 100666
-File created in => directory specified
+OK
 -- Iteration 7 --
 
-Warning: tempnam() expects parameter 2 to be string, array given in %s on line %d
--- File is not created --
-
-Warning: unlink(): No such file or directory in %s on line %d
+Warning: tempnam() expects parameter 2 to be string, array given in %s\ext\standard\tests\file\tempnam_variation3-win32.php on line %d
+OK
 -- Iteration 8 --
-File name is => %s\di%s
-File permissions are => 100666
-File created in => directory specified
+OK
 -- Iteration 9 --
-File name is => %s\ph%s
-File permissions are => 100666
-File created in => directory specified
-
-*** Done ***
+OK
 
+*** Done. ***