fgets_variation5.phpt 7.5 KB

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