copy_variation2-win32.phpt 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. --TEST--
  2. Test copy() function: usage variations - destination file names(special chars)
  3. --SKIPIF--
  4. <?php
  5. if(substr(PHP_OS, 0, 3) != "WIN")
  6. die("skip only run on Windows");
  7. ?>
  8. --FILE--
  9. <?php
  10. /* Prototype: bool copy ( string $source, string $dest );
  11. Description: Makes a copy of the file source to dest.
  12. Returns TRUE on success or FALSE on failure.
  13. */
  14. /* Test copy() function: In creation of destination file names containing special characters
  15. and checking the existence and size of destination files
  16. */
  17. echo "*** Test copy() function: destination file names containing special characters ***\n";
  18. $file_path = dirname(__FILE__);
  19. $src_file_name = $file_path."/copy_variation2.tmp";
  20. $file_handle = fopen($src_file_name, "w");
  21. fwrite( $file_handle, str_repeat(b"Hello2World...\n", 100) );
  22. fclose($file_handle);
  23. /* array of destination file names */
  24. $dest_files = array(
  25. /* File names containing special(non-alpha numeric) characters */
  26. "_copy_variation2.tmp",
  27. "@copy_variation2.tmp",
  28. "#copy_variation2.tmp",
  29. "+copy_variation2.tmp",
  30. "?copy_variation2.tmp",
  31. ">copy_variation2.tmp",
  32. "!copy_variation2.tmp",
  33. "&copy_variation2.tmp",
  34. "(copy_variation2.tmp",
  35. ":copy_variation2.tmp",
  36. ";copy_variation2.tmp",
  37. "=copy_variation2.tmp",
  38. "[copy_variation2.tmp",
  39. "^copy_variation2.tmp",
  40. "{copy_variation2.tmp",
  41. "|copy_variation2.tmp",
  42. "~copy_variation2.tmp",
  43. "\$copy_variation2.tmp"
  44. );
  45. echo "Size of the source file before copy operation => ";
  46. var_dump( filesize("$src_file_name") );
  47. clearstatcache();
  48. echo "\n--- Now applying copy() on source file to create copies ---";
  49. $count = 1;
  50. foreach($dest_files as $dest_file) {
  51. echo "\n-- Iteration $count --\n";
  52. $dest_file_name = $file_path."/$dest_file";
  53. echo "Copy operation => ";
  54. var_dump( copy($src_file_name, $dest_file_name) );
  55. echo "Existence of destination file => ";
  56. var_dump( file_exists($dest_file_name) );
  57. if( file_exists($dest_file_name) ) {
  58. echo "Destination file name => ";
  59. print($dest_file_name);
  60. echo "\n";
  61. echo "Size of source file => ";
  62. var_dump( filesize($src_file_name) );
  63. clearstatcache();
  64. echo "Size of destination file => ";
  65. var_dump( filesize($dest_file_name) );
  66. clearstatcache();
  67. unlink($dest_file_name);
  68. }
  69. $count++;
  70. }
  71. echo "*** Done ***\n";
  72. ?>
  73. --CLEAN--
  74. <?php
  75. unlink(dirname(__FILE__)."/copy_variation2.tmp");
  76. ?>
  77. --EXPECTF--
  78. *** Test copy() function: destination file names containing special characters ***
  79. Size of the source file before copy operation => int(1500)
  80. --- Now applying copy() on source file to create copies ---
  81. -- Iteration 1 --
  82. Copy operation => bool(true)
  83. Existence of destination file => bool(true)
  84. Destination file name => %s/_copy_variation2.tmp
  85. Size of source file => int(1500)
  86. Size of destination file => int(1500)
  87. -- Iteration 2 --
  88. Copy operation => bool(true)
  89. Existence of destination file => bool(true)
  90. Destination file name => %s/@copy_variation2.tmp
  91. Size of source file => int(1500)
  92. Size of destination file => int(1500)
  93. -- Iteration 3 --
  94. Copy operation => bool(true)
  95. Existence of destination file => bool(true)
  96. Destination file name => %s/#copy_variation2.tmp
  97. Size of source file => int(1500)
  98. Size of destination file => int(1500)
  99. -- Iteration 4 --
  100. Copy operation => bool(true)
  101. Existence of destination file => bool(true)
  102. Destination file name => %s/+copy_variation2.tmp
  103. Size of source file => int(1500)
  104. Size of destination file => int(1500)
  105. -- Iteration 5 --
  106. Copy operation =>
  107. Warning: copy(%s): %s
  108. bool(false)
  109. Existence of destination file => bool(false)
  110. -- Iteration 6 --
  111. Copy operation =>
  112. Warning: copy(%s): %s
  113. bool(false)
  114. Existence of destination file => bool(false)
  115. -- Iteration 7 --
  116. Copy operation => bool(true)
  117. Existence of destination file => bool(true)
  118. Destination file name => %s/!copy_variation2.tmp
  119. Size of source file => int(1500)
  120. Size of destination file => int(1500)
  121. -- Iteration 8 --
  122. Copy operation => bool(true)
  123. Existence of destination file => bool(true)
  124. Destination file name => %s/&copy_variation2.tmp
  125. Size of source file => int(1500)
  126. Size of destination file => int(1500)
  127. -- Iteration 9 --
  128. Copy operation => bool(true)
  129. Existence of destination file => bool(true)
  130. Destination file name => %s/(copy_variation2.tmp
  131. Size of source file => int(1500)
  132. Size of destination file => int(1500)
  133. -- Iteration 10 --
  134. Copy operation =>
  135. Warning: copy(%s): %s
  136. bool(false)
  137. Existence of destination file => bool(false)
  138. -- Iteration 11 --
  139. Copy operation => bool(true)
  140. Existence of destination file => bool(true)
  141. Destination file name => %s/;copy_variation2.tmp
  142. Size of source file => int(1500)
  143. Size of destination file => int(1500)
  144. -- Iteration 12 --
  145. Copy operation => bool(true)
  146. Existence of destination file => bool(true)
  147. Destination file name => %s/=copy_variation2.tmp
  148. Size of source file => int(1500)
  149. Size of destination file => int(1500)
  150. -- Iteration 13 --
  151. Copy operation => bool(true)
  152. Existence of destination file => bool(true)
  153. Destination file name => %s/[copy_variation2.tmp
  154. Size of source file => int(1500)
  155. Size of destination file => int(1500)
  156. -- Iteration 14 --
  157. Copy operation => bool(true)
  158. Existence of destination file => bool(true)
  159. Destination file name => %s/^copy_variation2.tmp
  160. Size of source file => int(1500)
  161. Size of destination file => int(1500)
  162. -- Iteration 15 --
  163. Copy operation => bool(true)
  164. Existence of destination file => bool(true)
  165. Destination file name => %s/{copy_variation2.tmp
  166. Size of source file => int(1500)
  167. Size of destination file => int(1500)
  168. -- Iteration 16 --
  169. Copy operation =>
  170. Warning: copy(%s): %s
  171. bool(false)
  172. Existence of destination file => bool(false)
  173. -- Iteration 17 --
  174. Copy operation => bool(true)
  175. Existence of destination file => bool(true)
  176. Destination file name => %s/~copy_variation2.tmp
  177. Size of source file => int(1500)
  178. Size of destination file => int(1500)
  179. -- Iteration 18 --
  180. Copy operation => bool(true)
  181. Existence of destination file => bool(true)
  182. Destination file name => %s/$copy_variation2.tmp
  183. Size of source file => int(1500)
  184. Size of destination file => int(1500)
  185. *** Done ***