Annotation of embedaddon/php/ext/standard/tests/file/touch_variation6-win32.phpt, revision 1.1.1.1

1.1       misho       1: --TEST--
                      2: Test touch() function : variation: various valid and invalid paths 
                      3: --CREDITS--
                      4: Dave Kelsey <d_kelsey@uk.ibm.com>
                      5: --SKIPIF--
                      6: <?php
                      7: if (substr(PHP_OS, 0, 3) != 'WIN') {
                      8:     die('skip.. only for Windows');
                      9: }
                     10: ?>
                     11: --FILE--
                     12: <?php
                     13: /* Prototype  : bool touch(string filename [, int time [, int atime]])
                     14:  * Description: Set modification time of file 
                     15:  * Source code: ext/standard/filestat.c
                     16:  * Alias to functions: 
                     17:  */
                     18: 
                     19: $workDir = "touchVar5.tmp";
                     20: $subDirOrFile = "aSubDirOrFile";
                     21: chdir(__DIR__);
                     22: mkdir($workDir);
                     23: $cwd = getcwd();
                     24: 
                     25: $unixifiedDirOrFile = '/'.substr(str_replace('\\','/',$cwd).'/'.$workDir.'/'.$subDirOrFile, 3);
                     26: 
                     27: $paths = array(
                     28:                         // relative
                     29:              $workDir.'\\'.$subDirOrFile,
                     30:              '.\\'.$workDir.'\\'.$subDirOrFile,
                     31:              $workDir.'\\..\\'.$workDir.'\\'.$subDirOrFile,
                     32:              
                     33:              // relative bad path (note p8 msgs differ)
                     34:              $workDir.'\\..\\BADDIR\\'.$subDirOrFile,
                     35:              'BADDIR\\'.$subDirOrFile,
                     36:              
                     37:              //absolute
                     38:              $cwd.'\\'.$workDir.'\\'.$subDirOrFile,
                     39:              $cwd.'\\.\\'.$workDir.'\\'.$subDirOrFile,
                     40:              $cwd.'\\'.$workDir.'\\..\\'.$workDir.'\\'.$subDirOrFile,
                     41: 
                     42:              //absolute bad path (note p8 msgs differ)             
                     43:              $cwd.'\\BADDIR\\'.$subDirOrFile,
                     44:              
                     45:              //trailing separators
                     46:              $workDir.'\\'.$subDirOrFile.'\\',
                     47:              $cwd.'\\'.$workDir.'\\'.$subDirOrFile.'\\',
                     48:              
                     49:              // multiple separators
                     50:              $workDir.'\\\\'.$subDirOrFile,
                     51:              $cwd.'\\\\'.$workDir.'\\\\'.$subDirOrFile,
                     52:              
                     53:              // Unixified Dir Or File
                     54:              $unixifiedDirOrFile,                         
                     55:              
                     56:              );
                     57:              
                     58: echo "*** Testing touch() : variation ***\n";
                     59: 
                     60: echo "\n*** testing nonexisting paths ***\n";      
                     61: test_nonexisting($paths);
                     62: 
                     63: echo "\n*** testing existing files ***\n";      
                     64: test_existing($paths, false);
                     65: 
                     66: echo "\n*** testing existing directories ***\n";      
                     67: test_existing($paths, true);
                     68: 
                     69: 
                     70: rmdir($workDir);
                     71: 
                     72: 
                     73: 
                     74: function test_nonexisting($paths) {
                     75:        foreach($paths as $path) {
                     76:           echo "--- testing $path ---\n";
                     77:           
                     78:           if (is_dir($path) || is_file($path)) {
                     79:              echo "FAILED: $path - exists\n";
                     80:           }
                     81:           else {
                     82:              $res = touch($path);
                     83:              if ($res === true) {
                     84:                 // something was created
                     85:                 if (file_exists($path)) {
                     86:                      // something found
                     87:                              if (is_dir($path)) {
                     88:                                 echo "FAILED: $path - unexpected directory\n";
                     89:                              }
                     90:                              else {
                     91:                                 echo "PASSED: $path - created\n";
                     92:                                 unlink($path);
                     93:                              }
                     94:                 }
                     95:                 else {
                     96:                    // nothing found
                     97:                    echo "FAILED: $path - touch returned true, nothing there\n";
                     98:                 }
                     99:              }
                    100:              else {
                    101:                 // nothing created
                    102:                 if (file_exists($path)) {
                    103:                      //something found
                    104:                      echo "FAILED: $path - touch returned false, something there\n";
                    105:                      if (is_dir($path)) {
                    106:                         rmdir($path);
                    107:                              }
                    108:                              else {
                    109:                                 unlink($path);
                    110:                              }
                    111:                 }
                    112:              }
                    113:           }
                    114:        }
                    115: }
                    116: 
                    117: function test_existing($paths, $are_dirs) {
                    118:        foreach($paths as $path) {
                    119:           if ($are_dirs) {
                    120:              $res = @mkdir($path);
                    121:              if ($res == true) {
                    122:              test_path($path);
                    123:              rmdir($path);
                    124:           }       
                    125:           }
                    126:           else {
                    127:              $h = @fopen($path,"w");
                    128:              if ($h !== false) {
                    129:                 fclose($h);
                    130:              test_path($path);
                    131:              unlink($path);
                    132:           }       
                    133:           }
                    134:        }
                    135: }
                    136:           
                    137:        
                    138: function test_path($path) {
                    139:    echo "--- testing $path ---\n";
                    140:    $org_atime = get_atime($path);
                    141:    clearstatcache();
                    142:    $res = touch($path,0,0);
                    143:    $next_atime = get_atime($path);
                    144:    if ($next_atime == $org_atime) {
                    145:       echo "FAILED: $path - access time not changed\n";
                    146:    }
                    147:    else {
                    148:       echo "PASSED: $path - touched\n";
                    149:    }
                    150: }
                    151: 
                    152: function get_atime($path) {
                    153:    $temp = stat($path);
                    154:    return $temp['atime'];
                    155: }
                    156: 
                    157: 
                    158: ?>
                    159: ===DONE===
                    160: --EXPECTF--
                    161: *** Testing touch() : variation ***
                    162: 
                    163: *** testing nonexisting paths ***
                    164: --- testing touchVar5.tmp\aSubDirOrFile ---
                    165: PASSED: touchVar5.tmp\aSubDirOrFile - created
                    166: --- testing .\touchVar5.tmp\aSubDirOrFile ---
                    167: PASSED: .\touchVar5.tmp\aSubDirOrFile - created
                    168: --- testing touchVar5.tmp\..\touchVar5.tmp\aSubDirOrFile ---
                    169: PASSED: touchVar5.tmp\..\touchVar5.tmp\aSubDirOrFile - created
                    170: --- testing touchVar5.tmp\..\BADDIR\aSubDirOrFile ---
                    171: 
                    172: Warning: touch(): Unable to create file touchVar5.tmp\..\BADDIR\aSubDirOrFile because %s in %s on line %d
                    173: --- testing BADDIR\aSubDirOrFile ---
                    174: 
                    175: Warning: touch(): Unable to create file BADDIR\aSubDirOrFile because %s in %s on line %d
                    176: --- testing %s\touchVar5.tmp\aSubDirOrFile ---
                    177: PASSED: %s\touchVar5.tmp\aSubDirOrFile - created
                    178: --- testing %s\.\touchVar5.tmp\aSubDirOrFile ---
                    179: PASSED: %s\.\touchVar5.tmp\aSubDirOrFile - created
                    180: --- testing %s\touchVar5.tmp\..\touchVar5.tmp\aSubDirOrFile ---
                    181: PASSED: %s\touchVar5.tmp\..\touchVar5.tmp\aSubDirOrFile - created
                    182: --- testing %s\BADDIR\aSubDirOrFile ---
                    183: 
                    184: Warning: touch(): Unable to create file %s\BADDIR\aSubDirOrFile because %s in %s on line %d
                    185: --- testing touchVar5.tmp\aSubDirOrFile\ ---
                    186: 
                    187: Warning: touch(): Unable to create file touchVar5.tmp\aSubDirOrFile\ because Invalid argument in %s on line %d
                    188: --- testing %s\touchVar5.tmp\aSubDirOrFile\ ---
                    189: 
                    190: Warning: touch(): Unable to create file %s\touchVar5.tmp\aSubDirOrFile\ because Invalid argument in %s on line %d
                    191: --- testing touchVar5.tmp\\aSubDirOrFile ---
                    192: PASSED: touchVar5.tmp\\aSubDirOrFile - created
                    193: --- testing %s\\touchVar5.tmp\\aSubDirOrFile ---
                    194: PASSED: %s\\touchVar5.tmp\\aSubDirOrFile - created
                    195: --- testing /%s/touchVar5.tmp/aSubDirOrFile ---
                    196: PASSED: /%s/touchVar5.tmp/aSubDirOrFile - created
                    197: 
                    198: *** testing existing files ***
                    199: --- testing touchVar5.tmp\aSubDirOrFile ---
                    200: PASSED: touchVar5.tmp\aSubDirOrFile - touched
                    201: --- testing .\touchVar5.tmp\aSubDirOrFile ---
                    202: PASSED: .\touchVar5.tmp\aSubDirOrFile - touched
                    203: --- testing touchVar5.tmp\..\touchVar5.tmp\aSubDirOrFile ---
                    204: PASSED: touchVar5.tmp\..\touchVar5.tmp\aSubDirOrFile - touched
                    205: --- testing %s\touchVar5.tmp\aSubDirOrFile ---
                    206: PASSED: %s\touchVar5.tmp\aSubDirOrFile - touched
                    207: --- testing %s\.\touchVar5.tmp\aSubDirOrFile ---
                    208: PASSED: %s\.\touchVar5.tmp\aSubDirOrFile - touched
                    209: --- testing %s\touchVar5.tmp\..\touchVar5.tmp\aSubDirOrFile ---
                    210: PASSED: %s\touchVar5.tmp\..\touchVar5.tmp\aSubDirOrFile - touched
                    211: --- testing touchVar5.tmp\\aSubDirOrFile ---
                    212: PASSED: touchVar5.tmp\\aSubDirOrFile - touched
                    213: --- testing %s\\touchVar5.tmp\\aSubDirOrFile ---
                    214: PASSED: %s\\touchVar5.tmp\\aSubDirOrFile - touched
                    215: --- testing /%s/touchVar5.tmp/aSubDirOrFile ---
                    216: PASSED: /%s/touchVar5.tmp/aSubDirOrFile - touched
                    217: 
                    218: *** testing existing directories ***
                    219: --- testing touchVar5.tmp\aSubDirOrFile ---
                    220: PASSED: touchVar5.tmp\aSubDirOrFile - touched
                    221: --- testing .\touchVar5.tmp\aSubDirOrFile ---
                    222: PASSED: .\touchVar5.tmp\aSubDirOrFile - touched
                    223: --- testing touchVar5.tmp\..\touchVar5.tmp\aSubDirOrFile ---
                    224: PASSED: touchVar5.tmp\..\touchVar5.tmp\aSubDirOrFile - touched
                    225: --- testing %s\touchVar5.tmp\aSubDirOrFile ---
                    226: PASSED: %s\touchVar5.tmp\aSubDirOrFile - touched
                    227: --- testing %s\.\touchVar5.tmp\aSubDirOrFile ---
                    228: PASSED: %s\.\touchVar5.tmp\aSubDirOrFile - touched
                    229: --- testing %s\touchVar5.tmp\..\touchVar5.tmp\aSubDirOrFile ---
                    230: PASSED: %s\touchVar5.tmp\..\touchVar5.tmp\aSubDirOrFile - touched
                    231: --- testing touchVar5.tmp\aSubDirOrFile\ ---
                    232: PASSED: touchVar5.tmp\aSubDirOrFile\ - touched
                    233: --- testing %s\touchVar5.tmp\aSubDirOrFile\ ---
                    234: PASSED: %s\touchVar5.tmp\aSubDirOrFile\ - touched
                    235: --- testing touchVar5.tmp\\aSubDirOrFile ---
                    236: PASSED: touchVar5.tmp\\aSubDirOrFile - touched
                    237: --- testing %s\\touchVar5.tmp\\aSubDirOrFile ---
                    238: PASSED: %s\\touchVar5.tmp\\aSubDirOrFile - touched
                    239: --- testing /%s/touchVar5.tmp/aSubDirOrFile ---
                    240: PASSED: /%s/touchVar5.tmp/aSubDirOrFile - touched
                    241: ===DONE===
                    242: 

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