fwrite_variation1-win32-mb.phpt 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. --TEST--
  2. Test fwrite() function : usage variations - r, rb & rt modes
  3. --SKIPIF--
  4. <?php
  5. if( substr(PHP_OS, 0, 3) != 'WIN' ) {
  6. die('skip...Not valid for Linux');
  7. }
  8. ?>
  9. --FILE--
  10. <?php
  11. echo "*** Testing fwrite() various operations ***\n";
  12. // include the file.inc for Function: function delete_file($filename)
  13. include ("file.inc");
  14. /*
  15. Test fwrite with file opened in mode : r,rb,rt
  16. File having content of type numeric, text,text_with_new_line & alphanumeric
  17. */
  18. $file_modes = array("r","rb","rt");
  19. $file_content_types = array("numeric","text","text_with_new_line","alphanumeric");
  20. foreach($file_content_types as $file_content_type) {
  21. echo "\n-- Testing fwrite() with file having content of type ". $file_content_type ." --\n";
  22. /* open the file using $files_modes and perform fwrite() on it */
  23. foreach($file_modes as $file_mode) {
  24. echo "-- Opening file in $file_mode --\n";
  25. // create the temp file with content of type $file_content_type
  26. $filename = __DIR__."/fwrite_variation1私はガラスを食べられます1.tmp"; // this is name of the file
  27. create_files ( __DIR__, 1, $file_content_type, 0755, 1, "w", "fwrite_variation1私はガラスを食べられます");
  28. $file_handle = fopen($filename, $file_mode);
  29. if(!$file_handle) {
  30. echo "Error: failed to fopen() file: $filename!";
  31. exit();
  32. }
  33. $data_to_be_written="";
  34. fill_buffer($data_to_be_written,$file_content_type,1024); //get the data of size 1024
  35. /* Write the data into the file, verify it by checking the file pointer position, eof position,
  36. filesize & by displaying the content */
  37. var_dump( ftell($file_handle) ); // expected: 0
  38. var_dump( fwrite($file_handle, $data_to_be_written ));
  39. var_dump( ftell($file_handle) ); // expected: 0
  40. var_dump( feof($file_handle) ); // expected: false
  41. // move the file pointer to end of the file and try fwrite()
  42. fseek($file_handle, SEEK_END, 0);
  43. var_dump( ftell($file_handle) ); // expecting 1024
  44. var_dump( fwrite($file_handle, $data_to_be_written) ); // fwrite to fail
  45. var_dump( ftell($file_handle) ); //check that file pointer points at eof, expected: 1024
  46. var_dump( feof($file_handle) ); // ensure that feof() points to eof, expected: true
  47. // ensure that file content/size didn't change.
  48. var_dump( fclose($file_handle) );
  49. clearstatcache();//clears file status cache
  50. var_dump( filesize($filename) ); // expected: 1024
  51. var_dump(md5(file_get_contents($filename))); // hash the output
  52. delete_file($filename); // delete file with name fwrite_variation1.tmp
  53. } // end of inner foreach loop
  54. } // end of outer foreach loop
  55. echo "Done\n";
  56. ?>
  57. --EXPECTF--
  58. *** Testing fwrite() various operations ***
  59. -- Testing fwrite() with file having content of type numeric --
  60. -- Opening file in r --
  61. int(0)
  62. Notice: fwrite(): Write of 1024 bytes failed with errno=9 Bad file descriptor in %s on line %d
  63. bool(false)
  64. int(0)
  65. bool(false)
  66. int(2)
  67. Notice: fwrite(): Write of 1024 bytes failed with errno=9 Bad file descriptor in %s on line %d
  68. bool(false)
  69. int(2)
  70. bool(false)
  71. bool(true)
  72. int(1024)
  73. string(32) "950b7457d1deb6332f2fc5d42f3129d6"
  74. -- Opening file in rb --
  75. int(0)
  76. Notice: fwrite(): Write of 1024 bytes failed with errno=9 Bad file descriptor in %s on line %d
  77. bool(false)
  78. int(0)
  79. bool(false)
  80. int(2)
  81. Notice: fwrite(): Write of 1024 bytes failed with errno=9 Bad file descriptor in %s on line %d
  82. bool(false)
  83. int(2)
  84. bool(false)
  85. bool(true)
  86. int(1024)
  87. string(32) "950b7457d1deb6332f2fc5d42f3129d6"
  88. -- Opening file in rt --
  89. int(0)
  90. Notice: fwrite(): Write of 1024 bytes failed with errno=9 Bad file descriptor in %s on line %d
  91. bool(false)
  92. int(0)
  93. bool(false)
  94. int(2)
  95. Notice: fwrite(): Write of 1024 bytes failed with errno=9 Bad file descriptor in %s on line %d
  96. bool(false)
  97. int(2)
  98. bool(false)
  99. bool(true)
  100. int(1024)
  101. string(32) "950b7457d1deb6332f2fc5d42f3129d6"
  102. -- Testing fwrite() with file having content of type text --
  103. -- Opening file in r --
  104. int(0)
  105. Notice: fwrite(): Write of 1024 bytes failed with errno=9 Bad file descriptor in %s on line %d
  106. bool(false)
  107. int(0)
  108. bool(false)
  109. int(2)
  110. Notice: fwrite(): Write of 1024 bytes failed with errno=9 Bad file descriptor in %s on line %d
  111. bool(false)
  112. int(2)
  113. bool(false)
  114. bool(true)
  115. int(1024)
  116. string(32) "e486000c4c8452774f746a27658d87fa"
  117. -- Opening file in rb --
  118. int(0)
  119. Notice: fwrite(): Write of 1024 bytes failed with errno=9 Bad file descriptor in %s on line %d
  120. bool(false)
  121. int(0)
  122. bool(false)
  123. int(2)
  124. Notice: fwrite(): Write of 1024 bytes failed with errno=9 Bad file descriptor in %s on line %d
  125. bool(false)
  126. int(2)
  127. bool(false)
  128. bool(true)
  129. int(1024)
  130. string(32) "e486000c4c8452774f746a27658d87fa"
  131. -- Opening file in rt --
  132. int(0)
  133. Notice: fwrite(): Write of 1024 bytes failed with errno=9 Bad file descriptor in %s on line %d
  134. bool(false)
  135. int(0)
  136. bool(false)
  137. int(2)
  138. Notice: fwrite(): Write of 1024 bytes failed with errno=9 Bad file descriptor in %s on line %d
  139. bool(false)
  140. int(2)
  141. bool(false)
  142. bool(true)
  143. int(1024)
  144. string(32) "e486000c4c8452774f746a27658d87fa"
  145. -- Testing fwrite() with file having content of type text_with_new_line --
  146. -- Opening file in r --
  147. int(0)
  148. Notice: fwrite(): Write of 1024 bytes failed with errno=9 Bad file descriptor in %s on line %d
  149. bool(false)
  150. int(0)
  151. bool(false)
  152. int(2)
  153. Notice: fwrite(): Write of 1024 bytes failed with errno=9 Bad file descriptor in %s on line %d
  154. bool(false)
  155. int(2)
  156. bool(false)
  157. bool(true)
  158. int(1024)
  159. string(32) "b09c8026a64a88d36d4c2f17983964bb"
  160. -- Opening file in rb --
  161. int(0)
  162. Notice: fwrite(): Write of 1024 bytes failed with errno=9 Bad file descriptor in %s on line %d
  163. bool(false)
  164. int(0)
  165. bool(false)
  166. int(2)
  167. Notice: fwrite(): Write of 1024 bytes failed with errno=9 Bad file descriptor in %s on line %d
  168. bool(false)
  169. int(2)
  170. bool(false)
  171. bool(true)
  172. int(1024)
  173. string(32) "b09c8026a64a88d36d4c2f17983964bb"
  174. -- Opening file in rt --
  175. int(0)
  176. Notice: fwrite(): Write of 1024 bytes failed with errno=9 Bad file descriptor in %s on line %d
  177. bool(false)
  178. int(0)
  179. bool(false)
  180. int(2)
  181. Notice: fwrite(): Write of 1024 bytes failed with errno=9 Bad file descriptor in %s on line %d
  182. bool(false)
  183. int(2)
  184. bool(false)
  185. bool(true)
  186. int(1024)
  187. string(32) "b09c8026a64a88d36d4c2f17983964bb"
  188. -- Testing fwrite() with file having content of type alphanumeric --
  189. -- Opening file in r --
  190. int(0)
  191. Notice: fwrite(): Write of 1024 bytes failed with errno=9 Bad file descriptor in %s on line %d
  192. bool(false)
  193. int(0)
  194. bool(false)
  195. int(2)
  196. Notice: fwrite(): Write of 1024 bytes failed with errno=9 Bad file descriptor in %s on line %d
  197. bool(false)
  198. int(2)
  199. bool(false)
  200. bool(true)
  201. int(1024)
  202. string(32) "3fabd48d8eaa65c14e0d93d6880c560c"
  203. -- Opening file in rb --
  204. int(0)
  205. Notice: fwrite(): Write of 1024 bytes failed with errno=9 Bad file descriptor in %s on line %d
  206. bool(false)
  207. int(0)
  208. bool(false)
  209. int(2)
  210. Notice: fwrite(): Write of 1024 bytes failed with errno=9 Bad file descriptor in %s on line %d
  211. bool(false)
  212. int(2)
  213. bool(false)
  214. bool(true)
  215. int(1024)
  216. string(32) "3fabd48d8eaa65c14e0d93d6880c560c"
  217. -- Opening file in rt --
  218. int(0)
  219. Notice: fwrite(): Write of 1024 bytes failed with errno=9 Bad file descriptor in %s on line %d
  220. bool(false)
  221. int(0)
  222. bool(false)
  223. int(2)
  224. Notice: fwrite(): Write of 1024 bytes failed with errno=9 Bad file descriptor in %s on line %d
  225. bool(false)
  226. int(2)
  227. bool(false)
  228. bool(true)
  229. int(1024)
  230. string(32) "3fabd48d8eaa65c14e0d93d6880c560c"
  231. Done