touch_variation6-win32.phpt 7.7 KB

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