fwrite_variation3-win32.phpt 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371
  1. --TEST--
  2. Test fwrite() function : usage variations - a, ab, at, a+, a+b & a+t mode
  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 : a,ab,at,a+,a+b,a+
  16. File having content of type numeric, text,text_with_new_line & alphanumeric
  17. */
  18. $file_modes = array("a","ab","at","a+","a+b","a+t");
  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 temp file and fill it content of type $file_content_type
  26. $filename = __DIR__."/fwrite_variation3.tmp"; // this is name of the file
  27. create_files ( __DIR__, 1, $file_content_type, 0755, 1, "w", "fwrite_variation", 3);
  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. // append the data to the file, starting from current position of the file pointer
  38. var_dump( ftell($file_handle) ); // expected: 1024
  39. var_dump( fwrite($file_handle,$data_to_be_written,400) );
  40. var_dump( ftell($file_handle) ); // expected: 1024 + 400
  41. var_dump( feof($file_handle) ); // expected : true
  42. /*overwrite data in middle of the file*/
  43. fseek($file_handle, SEEK_SET, (1024 + 400)/2 );
  44. var_dump( ftell($file_handle)); // expected: (1024 + 400)/2
  45. var_dump( fwrite($file_handle, $data_to_be_written, 200) );
  46. var_dump( ftell($file_handle) );
  47. var_dump( feof($file_handle) ); //Expecting bool(false)
  48. /* check the filesize and display file content */
  49. // close the file, get the size and content of the file.
  50. var_dump( fclose($file_handle) );
  51. clearstatcache();//clears file status cache
  52. var_dump( filesize($filename) );
  53. var_dump(md5(file_get_contents($filename)));
  54. // delete the file created
  55. delete_file($filename); // delete file with name fwrite_variation3.tmp
  56. } // end of inner foreach loop
  57. } // end of outer foreach loop
  58. echo "Done\n";
  59. ?>
  60. --EXPECT--
  61. *** Testing fwrite() various operations ***
  62. -- Testing fwrite() with file having content of type numeric --
  63. -- Opening file in a --
  64. int(0)
  65. int(400)
  66. int(400)
  67. bool(false)
  68. int(400)
  69. int(200)
  70. int(600)
  71. bool(false)
  72. bool(true)
  73. int(1624)
  74. string(32) "59ce5bf03b69069d00d6354bdc969ff6"
  75. -- Opening file in ab --
  76. int(0)
  77. int(400)
  78. int(400)
  79. bool(false)
  80. int(400)
  81. int(200)
  82. int(600)
  83. bool(false)
  84. bool(true)
  85. int(1624)
  86. string(32) "59ce5bf03b69069d00d6354bdc969ff6"
  87. -- Opening file in at --
  88. int(0)
  89. int(400)
  90. int(400)
  91. bool(false)
  92. int(400)
  93. int(200)
  94. int(600)
  95. bool(false)
  96. bool(true)
  97. int(1624)
  98. string(32) "59ce5bf03b69069d00d6354bdc969ff6"
  99. -- Opening file in a+ --
  100. int(0)
  101. int(400)
  102. int(400)
  103. bool(false)
  104. int(400)
  105. int(200)
  106. int(600)
  107. bool(false)
  108. bool(true)
  109. int(1624)
  110. string(32) "59ce5bf03b69069d00d6354bdc969ff6"
  111. -- Opening file in a+b --
  112. int(0)
  113. int(400)
  114. int(400)
  115. bool(false)
  116. int(400)
  117. int(200)
  118. int(600)
  119. bool(false)
  120. bool(true)
  121. int(1624)
  122. string(32) "59ce5bf03b69069d00d6354bdc969ff6"
  123. -- Opening file in a+t --
  124. int(0)
  125. int(400)
  126. int(400)
  127. bool(false)
  128. int(400)
  129. int(200)
  130. int(600)
  131. bool(false)
  132. bool(true)
  133. int(1624)
  134. string(32) "59ce5bf03b69069d00d6354bdc969ff6"
  135. -- Testing fwrite() with file having content of type text --
  136. -- Opening file in a --
  137. int(0)
  138. int(400)
  139. int(400)
  140. bool(false)
  141. int(400)
  142. int(200)
  143. int(600)
  144. bool(false)
  145. bool(true)
  146. int(1624)
  147. string(32) "dbd9dffd809d82e299bc1e5c55087f3b"
  148. -- Opening file in ab --
  149. int(0)
  150. int(400)
  151. int(400)
  152. bool(false)
  153. int(400)
  154. int(200)
  155. int(600)
  156. bool(false)
  157. bool(true)
  158. int(1624)
  159. string(32) "dbd9dffd809d82e299bc1e5c55087f3b"
  160. -- Opening file in at --
  161. int(0)
  162. int(400)
  163. int(400)
  164. bool(false)
  165. int(400)
  166. int(200)
  167. int(600)
  168. bool(false)
  169. bool(true)
  170. int(1624)
  171. string(32) "dbd9dffd809d82e299bc1e5c55087f3b"
  172. -- Opening file in a+ --
  173. int(0)
  174. int(400)
  175. int(400)
  176. bool(false)
  177. int(400)
  178. int(200)
  179. int(600)
  180. bool(false)
  181. bool(true)
  182. int(1624)
  183. string(32) "dbd9dffd809d82e299bc1e5c55087f3b"
  184. -- Opening file in a+b --
  185. int(0)
  186. int(400)
  187. int(400)
  188. bool(false)
  189. int(400)
  190. int(200)
  191. int(600)
  192. bool(false)
  193. bool(true)
  194. int(1624)
  195. string(32) "dbd9dffd809d82e299bc1e5c55087f3b"
  196. -- Opening file in a+t --
  197. int(0)
  198. int(400)
  199. int(400)
  200. bool(false)
  201. int(400)
  202. int(200)
  203. int(600)
  204. bool(false)
  205. bool(true)
  206. int(1624)
  207. string(32) "dbd9dffd809d82e299bc1e5c55087f3b"
  208. -- Testing fwrite() with file having content of type text_with_new_line --
  209. -- Opening file in a --
  210. int(0)
  211. int(400)
  212. int(400)
  213. bool(false)
  214. int(400)
  215. int(200)
  216. int(600)
  217. bool(false)
  218. bool(true)
  219. int(1624)
  220. string(32) "3f0a483fe8a2f405677844e0b1af6cf4"
  221. -- Opening file in ab --
  222. int(0)
  223. int(400)
  224. int(400)
  225. bool(false)
  226. int(400)
  227. int(200)
  228. int(600)
  229. bool(false)
  230. bool(true)
  231. int(1624)
  232. string(32) "3f0a483fe8a2f405677844e0b1af6cf4"
  233. -- Opening file in at --
  234. int(0)
  235. int(400)
  236. int(400)
  237. bool(false)
  238. int(400)
  239. int(200)
  240. int(600)
  241. bool(false)
  242. bool(true)
  243. int(1690)
  244. string(32) "656648355b64df6fded53b12fb355ab8"
  245. -- Opening file in a+ --
  246. int(0)
  247. int(400)
  248. int(400)
  249. bool(false)
  250. int(400)
  251. int(200)
  252. int(600)
  253. bool(false)
  254. bool(true)
  255. int(1624)
  256. string(32) "3f0a483fe8a2f405677844e0b1af6cf4"
  257. -- Opening file in a+b --
  258. int(0)
  259. int(400)
  260. int(400)
  261. bool(false)
  262. int(400)
  263. int(200)
  264. int(600)
  265. bool(false)
  266. bool(true)
  267. int(1624)
  268. string(32) "3f0a483fe8a2f405677844e0b1af6cf4"
  269. -- Opening file in a+t --
  270. int(0)
  271. int(400)
  272. int(400)
  273. bool(false)
  274. int(400)
  275. int(200)
  276. int(600)
  277. bool(false)
  278. bool(true)
  279. int(1690)
  280. string(32) "656648355b64df6fded53b12fb355ab8"
  281. -- Testing fwrite() with file having content of type alphanumeric --
  282. -- Opening file in a --
  283. int(0)
  284. int(400)
  285. int(400)
  286. bool(false)
  287. int(400)
  288. int(200)
  289. int(600)
  290. bool(false)
  291. bool(true)
  292. int(1624)
  293. string(32) "ea0c0bfa0b10aa8e614fd33ffe295cb9"
  294. -- Opening file in ab --
  295. int(0)
  296. int(400)
  297. int(400)
  298. bool(false)
  299. int(400)
  300. int(200)
  301. int(600)
  302. bool(false)
  303. bool(true)
  304. int(1624)
  305. string(32) "ea0c0bfa0b10aa8e614fd33ffe295cb9"
  306. -- Opening file in at --
  307. int(0)
  308. int(400)
  309. int(400)
  310. bool(false)
  311. int(400)
  312. int(200)
  313. int(600)
  314. bool(false)
  315. bool(true)
  316. int(1624)
  317. string(32) "ea0c0bfa0b10aa8e614fd33ffe295cb9"
  318. -- Opening file in a+ --
  319. int(0)
  320. int(400)
  321. int(400)
  322. bool(false)
  323. int(400)
  324. int(200)
  325. int(600)
  326. bool(false)
  327. bool(true)
  328. int(1624)
  329. string(32) "ea0c0bfa0b10aa8e614fd33ffe295cb9"
  330. -- Opening file in a+b --
  331. int(0)
  332. int(400)
  333. int(400)
  334. bool(false)
  335. int(400)
  336. int(200)
  337. int(600)
  338. bool(false)
  339. bool(true)
  340. int(1624)
  341. string(32) "ea0c0bfa0b10aa8e614fd33ffe295cb9"
  342. -- Opening file in a+t --
  343. int(0)
  344. int(400)
  345. int(400)
  346. bool(false)
  347. int(400)
  348. int(200)
  349. int(600)
  350. bool(false)
  351. bool(true)
  352. int(1624)
  353. string(32) "ea0c0bfa0b10aa8e614fd33ffe295cb9"
  354. Done