fgets_variation5.phpt 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  1. --TEST--
  2. Test fgets() function : usage variations - read beyond filesize
  3. --FILE--
  4. <?php
  5. // include the file.inc for common test functions
  6. include ("file.inc");
  7. $file_modes = array("w+", "w+b", "w+t",
  8. "a+", "a+b", "a+t",
  9. "x+", "x+b", "x+t");
  10. $file_content_types = array("numeric", "text", "text_with_new_line", "alphanumeric");
  11. echo "*** Testing fgets() : usage variations ***\n";
  12. $filename = __DIR__."/fgets_variation5.tmp";
  13. foreach($file_modes as $file_mode) {
  14. echo "\n-- Testing fgets() with file opened using mode $file_mode --\n";
  15. foreach($file_content_types as $file_content_type) {
  16. echo "-- File content type : $file_content_type --\n";
  17. /* create files with $file_content_type */
  18. $file_handle = fopen($filename, $file_mode);
  19. $data = fill_file($file_handle, $file_content_type, 50);
  20. if ( !$file_handle ) {
  21. echo "Error: failed to open file $filename!";
  22. exit();
  23. }
  24. /* read with length beyond file size */
  25. echo "-- fgets() with length > filesize --\n";
  26. rewind($file_handle);
  27. var_dump( ftell($file_handle) );
  28. var_dump( fgets($file_handle, 50 + 23) ); // expected: 50
  29. var_dump( ftell($file_handle) ); // ensure the file pointer position
  30. var_dump( feof($file_handle) ); // ensure if eof set
  31. //close file
  32. fclose($file_handle);
  33. // delete file
  34. delete_file($filename);
  35. } // file_content_type loop
  36. } // file_mode loop
  37. echo "Done\n";
  38. ?>
  39. --EXPECT--
  40. *** Testing fgets() : usage variations ***
  41. -- Testing fgets() with file opened using mode w+ --
  42. -- File content type : numeric --
  43. -- fgets() with length > filesize --
  44. int(0)
  45. string(50) "22222222222222222222222222222222222222222222222222"
  46. int(50)
  47. bool(true)
  48. -- File content type : text --
  49. -- fgets() with length > filesize --
  50. int(0)
  51. string(50) "text text text text text text text text text text "
  52. int(50)
  53. bool(true)
  54. -- File content type : text_with_new_line --
  55. -- fgets() with length > filesize --
  56. int(0)
  57. string(5) "line
  58. "
  59. int(5)
  60. bool(false)
  61. -- File content type : alphanumeric --
  62. -- fgets() with length > filesize --
  63. int(0)
  64. string(50) "ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 "
  65. int(50)
  66. bool(true)
  67. -- Testing fgets() with file opened using mode w+b --
  68. -- File content type : numeric --
  69. -- fgets() with length > filesize --
  70. int(0)
  71. string(50) "22222222222222222222222222222222222222222222222222"
  72. int(50)
  73. bool(true)
  74. -- File content type : text --
  75. -- fgets() with length > filesize --
  76. int(0)
  77. string(50) "text text text text text text text text text text "
  78. int(50)
  79. bool(true)
  80. -- File content type : text_with_new_line --
  81. -- fgets() with length > filesize --
  82. int(0)
  83. string(5) "line
  84. "
  85. int(5)
  86. bool(false)
  87. -- File content type : alphanumeric --
  88. -- fgets() with length > filesize --
  89. int(0)
  90. string(50) "ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 "
  91. int(50)
  92. bool(true)
  93. -- Testing fgets() with file opened using mode w+t --
  94. -- File content type : numeric --
  95. -- fgets() with length > filesize --
  96. int(0)
  97. string(50) "22222222222222222222222222222222222222222222222222"
  98. int(50)
  99. bool(true)
  100. -- File content type : text --
  101. -- fgets() with length > filesize --
  102. int(0)
  103. string(50) "text text text text text text text text text text "
  104. int(50)
  105. bool(true)
  106. -- File content type : text_with_new_line --
  107. -- fgets() with length > filesize --
  108. int(0)
  109. string(5) "line
  110. "
  111. int(5)
  112. bool(false)
  113. -- File content type : alphanumeric --
  114. -- fgets() with length > filesize --
  115. int(0)
  116. string(50) "ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 "
  117. int(50)
  118. bool(true)
  119. -- Testing fgets() with file opened using mode a+ --
  120. -- File content type : numeric --
  121. -- fgets() with length > filesize --
  122. int(0)
  123. string(50) "22222222222222222222222222222222222222222222222222"
  124. int(50)
  125. bool(true)
  126. -- File content type : text --
  127. -- fgets() with length > filesize --
  128. int(0)
  129. string(50) "text text text text text text text text text text "
  130. int(50)
  131. bool(true)
  132. -- File content type : text_with_new_line --
  133. -- fgets() with length > filesize --
  134. int(0)
  135. string(5) "line
  136. "
  137. int(5)
  138. bool(false)
  139. -- File content type : alphanumeric --
  140. -- fgets() with length > filesize --
  141. int(0)
  142. string(50) "ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 "
  143. int(50)
  144. bool(true)
  145. -- Testing fgets() with file opened using mode a+b --
  146. -- File content type : numeric --
  147. -- fgets() with length > filesize --
  148. int(0)
  149. string(50) "22222222222222222222222222222222222222222222222222"
  150. int(50)
  151. bool(true)
  152. -- File content type : text --
  153. -- fgets() with length > filesize --
  154. int(0)
  155. string(50) "text text text text text text text text text text "
  156. int(50)
  157. bool(true)
  158. -- File content type : text_with_new_line --
  159. -- fgets() with length > filesize --
  160. int(0)
  161. string(5) "line
  162. "
  163. int(5)
  164. bool(false)
  165. -- File content type : alphanumeric --
  166. -- fgets() with length > filesize --
  167. int(0)
  168. string(50) "ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 "
  169. int(50)
  170. bool(true)
  171. -- Testing fgets() with file opened using mode a+t --
  172. -- File content type : numeric --
  173. -- fgets() with length > filesize --
  174. int(0)
  175. string(50) "22222222222222222222222222222222222222222222222222"
  176. int(50)
  177. bool(true)
  178. -- File content type : text --
  179. -- fgets() with length > filesize --
  180. int(0)
  181. string(50) "text text text text text text text text text text "
  182. int(50)
  183. bool(true)
  184. -- File content type : text_with_new_line --
  185. -- fgets() with length > filesize --
  186. int(0)
  187. string(5) "line
  188. "
  189. int(5)
  190. bool(false)
  191. -- File content type : alphanumeric --
  192. -- fgets() with length > filesize --
  193. int(0)
  194. string(50) "ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 "
  195. int(50)
  196. bool(true)
  197. -- Testing fgets() with file opened using mode x+ --
  198. -- File content type : numeric --
  199. -- fgets() with length > filesize --
  200. int(0)
  201. string(50) "22222222222222222222222222222222222222222222222222"
  202. int(50)
  203. bool(true)
  204. -- File content type : text --
  205. -- fgets() with length > filesize --
  206. int(0)
  207. string(50) "text text text text text text text text text text "
  208. int(50)
  209. bool(true)
  210. -- File content type : text_with_new_line --
  211. -- fgets() with length > filesize --
  212. int(0)
  213. string(5) "line
  214. "
  215. int(5)
  216. bool(false)
  217. -- File content type : alphanumeric --
  218. -- fgets() with length > filesize --
  219. int(0)
  220. string(50) "ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 "
  221. int(50)
  222. bool(true)
  223. -- Testing fgets() with file opened using mode x+b --
  224. -- File content type : numeric --
  225. -- fgets() with length > filesize --
  226. int(0)
  227. string(50) "22222222222222222222222222222222222222222222222222"
  228. int(50)
  229. bool(true)
  230. -- File content type : text --
  231. -- fgets() with length > filesize --
  232. int(0)
  233. string(50) "text text text text text text text text text text "
  234. int(50)
  235. bool(true)
  236. -- File content type : text_with_new_line --
  237. -- fgets() with length > filesize --
  238. int(0)
  239. string(5) "line
  240. "
  241. int(5)
  242. bool(false)
  243. -- File content type : alphanumeric --
  244. -- fgets() with length > filesize --
  245. int(0)
  246. string(50) "ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 "
  247. int(50)
  248. bool(true)
  249. -- Testing fgets() with file opened using mode x+t --
  250. -- File content type : numeric --
  251. -- fgets() with length > filesize --
  252. int(0)
  253. string(50) "22222222222222222222222222222222222222222222222222"
  254. int(50)
  255. bool(true)
  256. -- File content type : text --
  257. -- fgets() with length > filesize --
  258. int(0)
  259. string(50) "text text text text text text text text text text "
  260. int(50)
  261. bool(true)
  262. -- File content type : text_with_new_line --
  263. -- fgets() with length > filesize --
  264. int(0)
  265. string(5) "line
  266. "
  267. int(5)
  268. bool(false)
  269. -- File content type : alphanumeric --
  270. -- fgets() with length > filesize --
  271. int(0)
  272. string(50) "ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 "
  273. int(50)
  274. bool(true)
  275. Done