Return to touch_variation5.phpt CVS log | Up to [ELWIX - Embedded LightWeight unIX -] / embedaddon / php / ext / standard / tests / file |
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.. Not 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: mkdir($workDir); 22: $cwd = getcwd(); 23: 24: $paths = array( 25: // relative 26: $workDir.'/'.$subDirOrFile, 27: './'.$workDir.'/'.$subDirOrFile, 28: $workDir.'/../'.$workDir.'/'.$subDirOrFile, 29: 30: // relative bad path 31: $workDir.'/../BADDIR/'.$subDirOrFile, 32: 'BADDIR/'.$subDirOrFile, 33: 34: //absolute 35: $cwd.'/'.$workDir.'/'.$subDirOrFile, 36: $cwd.'/./'.$workDir.'/'.$subDirOrFile, 37: $cwd.'/'.$workDir.'/../'.$workDir.'/'.$subDirOrFile, 38: 39: //absolute bad path 40: $cwd.'/BADDIR/'.$subDirOrFile, 41: 42: //trailing separators 43: $workDir.'/'.$subDirOrFile.'/', 44: $cwd.'/'.$workDir.'/'.$subDirOrFile.'/', 45: 46: // multiple separators 47: $workDir.'//'.$subDirOrFile, 48: $cwd.'//'.$workDir.'//'.$subDirOrFile, 49: 50: ); 51: 52: echo "*** Testing touch() : variation ***\n"; 53: 54: echo "\n*** testing nonexisting paths ***\n"; 55: test_nonexisting($paths); 56: 57: echo "\n*** testing existing files ***\n"; 58: test_existing($paths, false); 59: 60: echo "\n*** testing existing directories ***\n"; 61: test_existing($paths, true); 62: 63: 64: rmdir($workDir); 65: 66: 67: 68: function test_nonexisting($paths) { 69: foreach($paths as $path) { 70: echo "--- testing $path ---\n"; 71: 72: if (is_dir($path) || is_file($path)) { 73: echo "FAILED: $path - exists\n"; 74: } 75: else { 76: $res = touch($path); 77: if ($res === true) { 78: // something was created 79: if (file_exists($path)) { 80: // something found 81: if (is_dir($path)) { 82: echo "FAILED: $path - unexpected directory\n"; 83: } 84: else { 85: echo "PASSED: $path - created\n"; 86: unlink($path); 87: } 88: } 89: else { 90: // nothing found 91: echo "FAILED: $path - touch returned true, nothing there\n"; 92: } 93: } 94: else { 95: // nothing created 96: if (file_exists($path)) { 97: //something found 98: echo "FAILED: $path - touch returned false, something there\n"; 99: if (is_dir($path)) { 100: rmdir($path); 101: } 102: else { 103: unlink($path); 104: } 105: } 106: } 107: } 108: } 109: } 110: 111: function test_existing($paths, $are_dirs) { 112: foreach($paths as $path) { 113: if ($are_dirs) { 114: $res = @mkdir($path); 115: if ($res == true) { 116: test_path($path); 117: rmdir($path); 118: } 119: } 120: else { 121: $h = @fopen($path,"w"); 122: if ($h !== false) { 123: fclose($h); 124: test_path($path); 125: unlink($path); 126: } 127: } 128: } 129: } 130: 131: 132: function test_path($path) { 133: echo "--- testing $path ---\n"; 134: $org_atime = get_atime($path); 135: clearstatcache(); 136: $res = touch($path,0,0); 137: $next_atime = get_atime($path); 138: if ($next_atime == $org_atime) { 139: echo "FAILED: $path - access time not changed\n"; 140: } 141: else { 142: echo "PASSED: $path - touched\n"; 143: } 144: } 145: 146: function get_atime($path) { 147: $temp = stat($path); 148: return $temp['atime']; 149: } 150: 151: 152: ?> 153: ===DONE=== 154: --EXPECTF-- 155: *** Testing touch() : variation *** 156: 157: *** testing nonexisting paths *** 158: --- testing touchVar5.tmp/aSubDirOrFile --- 159: PASSED: touchVar5.tmp/aSubDirOrFile - created 160: --- testing ./touchVar5.tmp/aSubDirOrFile --- 161: PASSED: ./touchVar5.tmp/aSubDirOrFile - created 162: --- testing touchVar5.tmp/../touchVar5.tmp/aSubDirOrFile --- 163: PASSED: touchVar5.tmp/../touchVar5.tmp/aSubDirOrFile - created 164: --- testing touchVar5.tmp/../BADDIR/aSubDirOrFile --- 165: 166: Warning: touch(): Unable to create file touchVar5.tmp/../BADDIR/aSubDirOrFile because %s in %s on line %d 167: --- testing BADDIR/aSubDirOrFile --- 168: 169: Warning: touch(): Unable to create file BADDIR/aSubDirOrFile because %s in %s on line %d 170: --- testing /%s/touchVar5.tmp/aSubDirOrFile --- 171: PASSED: /%s/touchVar5.tmp/aSubDirOrFile - created 172: --- testing /%s/./touchVar5.tmp/aSubDirOrFile --- 173: PASSED: /%s/./touchVar5.tmp/aSubDirOrFile - created 174: --- testing /%s/touchVar5.tmp/../touchVar5.tmp/aSubDirOrFile --- 175: PASSED: /%s/touchVar5.tmp/../touchVar5.tmp/aSubDirOrFile - created 176: --- testing /%s/BADDIR/aSubDirOrFile --- 177: 178: Warning: touch(): Unable to create file /%s/BADDIR/aSubDirOrFile because %s in %s on line %d 179: --- testing touchVar5.tmp/aSubDirOrFile/ --- 180: 181: Warning: touch(): Unable to create file touchVar5.tmp/aSubDirOrFile/ because %s in %s on line %d 182: --- testing /%s/touchVar5.tmp/aSubDirOrFile/ --- 183: 184: Warning: touch(): Unable to create file /%s/touchVar5.tmp/aSubDirOrFile/ because %s in %s on line %d 185: --- testing touchVar5.tmp//aSubDirOrFile --- 186: PASSED: touchVar5.tmp//aSubDirOrFile - created 187: --- testing /%s//touchVar5.tmp//aSubDirOrFile --- 188: PASSED: /%s//touchVar5.tmp//aSubDirOrFile - created 189: 190: *** testing existing files *** 191: --- testing touchVar5.tmp/aSubDirOrFile --- 192: PASSED: touchVar5.tmp/aSubDirOrFile - touched 193: --- testing ./touchVar5.tmp/aSubDirOrFile --- 194: PASSED: ./touchVar5.tmp/aSubDirOrFile - touched 195: --- testing touchVar5.tmp/../touchVar5.tmp/aSubDirOrFile --- 196: PASSED: touchVar5.tmp/../touchVar5.tmp/aSubDirOrFile - touched 197: --- testing /%s/touchVar5.tmp/aSubDirOrFile --- 198: PASSED: /%s/touchVar5.tmp/aSubDirOrFile - touched 199: --- testing /%s/./touchVar5.tmp/aSubDirOrFile --- 200: PASSED: /%s/./touchVar5.tmp/aSubDirOrFile - touched 201: --- testing /%s/touchVar5.tmp/../touchVar5.tmp/aSubDirOrFile --- 202: PASSED: /%s/touchVar5.tmp/../touchVar5.tmp/aSubDirOrFile - touched 203: --- testing touchVar5.tmp//aSubDirOrFile --- 204: PASSED: touchVar5.tmp//aSubDirOrFile - touched 205: --- testing /%s//touchVar5.tmp//aSubDirOrFile --- 206: PASSED: /%s//touchVar5.tmp//aSubDirOrFile - touched 207: 208: *** testing existing directories *** 209: --- testing touchVar5.tmp/aSubDirOrFile --- 210: PASSED: touchVar5.tmp/aSubDirOrFile - touched 211: --- testing ./touchVar5.tmp/aSubDirOrFile --- 212: PASSED: ./touchVar5.tmp/aSubDirOrFile - touched 213: --- testing touchVar5.tmp/../touchVar5.tmp/aSubDirOrFile --- 214: PASSED: touchVar5.tmp/../touchVar5.tmp/aSubDirOrFile - touched 215: --- testing /%s/touchVar5.tmp/aSubDirOrFile --- 216: PASSED: /%s/touchVar5.tmp/aSubDirOrFile - touched 217: --- testing /%s/./touchVar5.tmp/aSubDirOrFile --- 218: PASSED: /%s/./touchVar5.tmp/aSubDirOrFile - touched 219: --- testing /%s/touchVar5.tmp/../touchVar5.tmp/aSubDirOrFile --- 220: PASSED: /%s/touchVar5.tmp/../touchVar5.tmp/aSubDirOrFile - touched 221: --- testing touchVar5.tmp/aSubDirOrFile/ --- 222: PASSED: touchVar5.tmp/aSubDirOrFile/ - touched 223: --- testing /%s/touchVar5.tmp/aSubDirOrFile/ --- 224: PASSED: /%s/touchVar5.tmp/aSubDirOrFile/ - touched 225: --- testing touchVar5.tmp//aSubDirOrFile --- 226: PASSED: touchVar5.tmp//aSubDirOrFile - touched 227: --- testing /%s//touchVar5.tmp//aSubDirOrFile --- 228: PASSED: /%s//touchVar5.tmp//aSubDirOrFile - touched 229: ===DONE=== 230: