touch_variation5-win32.phpt 7.2 KB

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