Annotation of embedaddon/php/ext/standard/tests/file/tempnam_variation3-win32.phpt, revision 1.1.1.2

1.1       misho       1: --TEST--
                      2: Test tempnam() function: usage variations - obscure prefixes
                      3: --SKIPIF--
                      4: <?php
                      5: if(substr(PHP_OS, 0, 3) != "WIN")
                      6:        die("skip run only on Windows");
                      7: ?>
                      8: --FILE--
                      9: <?php
                     10: /* Prototype:  string tempnam ( string $dir, string $prefix );
                     11:    Description: Create file with unique file name.
                     12: */
                     13: 
                     14: /* Passing invalid/non-existing args for $prefix */
                     15: 
                     16: echo "*** Testing tempnam() with obscure prefixes ***\n";
                     17: $file_path = dirname(__FILE__)."/tempnamVar3";
                     18: if (!mkdir($file_path)) {
                     19:        echo "Failed, cannot create temp dir $filepath\n";
                     20:        exit(1);
                     21: }
                     22: 
                     23: $file_path = realpath($file_path);
                     24: 
                     25: /* An array of prefixes */ 
                     26: $names_arr = array(
                     27:        /* Valid args (casting)*/ 
                     28:        -1,
                     29:        TRUE,
                     30:        FALSE,
                     31:        NULL,
                     32:        "",
                     33:        " ",
                     34:        "\0",
1.1.1.2 ! misho      35:        /* Invalid args */ 
1.1       misho      36:        array(),
                     37: 
                     38:        /* Valid args*/ 
                     39:        /* prefix with path separator of a non existing directory*/
                     40:        "/no/such/file/dir", 
                     41:        "php/php"
                     42: );
                     43: 
                     44: $res_arr = array(
                     45:        /* Invalid args */ 
                     46:        true,
                     47:        true,
                     48:        true,
                     49:        true,
                     50:        true,
                     51:        true,
                     52:        true,
                     53:        false,
                     54: 
                     55:        /* prefix with path separator of a non existing directory*/
                     56:        true, 
                     57:        true
                     58: );
                     59: 
                     60: for( $i=0; $i<count($names_arr); $i++ ) {
                     61:        echo "-- Iteration $i --\n";
                     62:        $file_name = tempnam($file_path, $names_arr[$i]);
                     63: 
                     64:        /* creating the files in existing dir */
                     65:        if (file_exists($file_name) && !$res_arr[$i]) {
                     66:                echo "Failed\n";
                     67:        }
                     68:        if ($res_arr[$i]) {
                     69:                $file_dir = dirname($file_name);
                     70:                if (realpath($file_dir) == $file_path || realpath($file_dir . "\\") == $file_path) {
                     71:                        echo "OK\n";
                     72:                } else {
                     73:                        echo "Failed, not created in the correct directory " . realpath($file_dir) . ' vs ' . $file_path ."\n";
                     74:                }
                     75:                
                     76:                if (!is_writable($file_name)) {
                     77:                        printf("%o\n", fileperms($file_name) );
                     78: 
                     79:                }
                     80:        } else {
                     81:                echo "OK\n";
                     82:        }
                     83:        @unlink($file_name);
                     84: }
                     85: 
                     86: rmdir($file_path);
                     87: echo "\n*** Done. ***\n";
                     88: ?>
                     89: --EXPECTF--
                     90: *** Testing tempnam() with obscure prefixes ***
                     91: -- Iteration 0 --
                     92: OK
                     93: -- Iteration 1 --
                     94: OK
                     95: -- Iteration 2 --
                     96: OK
                     97: -- Iteration 3 --
                     98: OK
                     99: -- Iteration 4 --
                    100: OK
                    101: -- Iteration 5 --
                    102: Failed, not created in the correct directory %s vs %s
                    103: 0
                    104: -- Iteration 6 --
1.1.1.2 ! misho     105: OK
1.1       misho     106: -- Iteration 7 --
                    107: 
                    108: Warning: tempnam() expects parameter 2 to be string, array given in %s\ext\standard\tests\file\tempnam_variation3-win32.php on line %d
                    109: OK
                    110: -- Iteration 8 --
                    111: OK
                    112: -- Iteration 9 --
                    113: OK
                    114: 
                    115: *** Done. ***

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>