fgets_variation6-win32.phpt 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372
  1. --TEST--
  2. Test fgets() function : usage variations - read when file pointer at EOF
  3. --SKIPIF--
  4. <?php
  5. if (substr(PHP_OS, 0, 3) != 'WIN') {
  6. die('skip only valid for Windows');
  7. }
  8. ?>
  9. --FILE--
  10. <?php
  11. /*
  12. Prototype: string fgets ( resource $handle [, int $length] );
  13. Description: Gets a line from file pointer
  14. */
  15. // include the file.inc for common test funcitons
  16. include ("file.inc");
  17. $file_modes = array("w+", "w+b", "w+t",
  18. "a+", "a+b", "a+t",
  19. "x+", "x+b", "x+t");
  20. $file_content_types = array("numeric", "text", "text_with_new_line", "alphanumeric");
  21. echo "*** Testing fgets() : usage variations ***\n";
  22. $filename = dirname(__FILE__)."/fgets_variation4.tmp";
  23. foreach($file_modes as $file_mode) {
  24. echo "\n-- Testing fgets() with file opened using mode $file_mode --\n";
  25. foreach($file_content_types as $file_content_type) {
  26. echo "-- File content type : $file_content_type --\n";
  27. /* create files with $file_content_type */
  28. $file_handle = fopen($filename, $file_mode);
  29. $data = fill_file($file_handle, $file_content_type, 50);
  30. if ( !$file_handle ) {
  31. echo "Error: failed to open file $filename!";
  32. exit();
  33. }
  34. echo "-- fgets() with file pointer pointing at EOF --\n";
  35. // seek to end of the file and try fgets()
  36. var_dump( fseek($file_handle, 0, SEEK_END) ); // set file pointer to eof
  37. var_dump( ftell($file_handle) ); // ensure that file pointer is at eof
  38. var_dump( feof($file_handle) ); // expected false
  39. var_dump( fgets($file_handle) ); // try n read a line, none expected
  40. var_dump( ftell($file_handle) ); // file pointer position
  41. var_dump( feof($file_handle) ); // ensure thta file pointer is at eof
  42. //close file
  43. fclose($file_handle);
  44. // delete file
  45. delete_file($filename);
  46. } // file_content_type loop
  47. } // file_mode loop
  48. echo "Done\n";
  49. ?>
  50. --EXPECTF--
  51. *** Testing fgets() : usage variations ***
  52. -- Testing fgets() with file opened using mode w+ --
  53. -- File content type : numeric --
  54. -- fgets() with file pointer pointing at EOF --
  55. int(0)
  56. int(50)
  57. bool(false)
  58. bool(false)
  59. int(50)
  60. bool(true)
  61. -- File content type : text --
  62. -- fgets() with file pointer pointing at EOF --
  63. int(0)
  64. int(50)
  65. bool(false)
  66. bool(false)
  67. int(50)
  68. bool(true)
  69. -- File content type : text_with_new_line --
  70. -- fgets() with file pointer pointing at EOF --
  71. int(0)
  72. int(50)
  73. bool(false)
  74. bool(false)
  75. int(50)
  76. bool(true)
  77. -- File content type : alphanumeric --
  78. -- fgets() with file pointer pointing at EOF --
  79. int(0)
  80. int(50)
  81. bool(false)
  82. bool(false)
  83. int(50)
  84. bool(true)
  85. -- Testing fgets() with file opened using mode w+b --
  86. -- File content type : numeric --
  87. -- fgets() with file pointer pointing at EOF --
  88. int(0)
  89. int(50)
  90. bool(false)
  91. bool(false)
  92. int(50)
  93. bool(true)
  94. -- File content type : text --
  95. -- fgets() with file pointer pointing at EOF --
  96. int(0)
  97. int(50)
  98. bool(false)
  99. bool(false)
  100. int(50)
  101. bool(true)
  102. -- File content type : text_with_new_line --
  103. -- fgets() with file pointer pointing at EOF --
  104. int(0)
  105. int(50)
  106. bool(false)
  107. bool(false)
  108. int(50)
  109. bool(true)
  110. -- File content type : alphanumeric --
  111. -- fgets() with file pointer pointing at EOF --
  112. int(0)
  113. int(50)
  114. bool(false)
  115. bool(false)
  116. int(50)
  117. bool(true)
  118. -- Testing fgets() with file opened using mode w+t --
  119. -- File content type : numeric --
  120. -- fgets() with file pointer pointing at EOF --
  121. int(0)
  122. int(50)
  123. bool(false)
  124. bool(false)
  125. int(50)
  126. bool(true)
  127. -- File content type : text --
  128. -- fgets() with file pointer pointing at EOF --
  129. int(0)
  130. int(50)
  131. bool(false)
  132. bool(false)
  133. int(50)
  134. bool(true)
  135. -- File content type : text_with_new_line --
  136. -- fgets() with file pointer pointing at EOF --
  137. int(0)
  138. int(55)
  139. bool(false)
  140. bool(false)
  141. int(55)
  142. bool(true)
  143. -- File content type : alphanumeric --
  144. -- fgets() with file pointer pointing at EOF --
  145. int(0)
  146. int(50)
  147. bool(false)
  148. bool(false)
  149. int(50)
  150. bool(true)
  151. -- Testing fgets() with file opened using mode a+ --
  152. -- File content type : numeric --
  153. -- fgets() with file pointer pointing at EOF --
  154. int(0)
  155. int(50)
  156. bool(false)
  157. bool(false)
  158. int(50)
  159. bool(true)
  160. -- File content type : text --
  161. -- fgets() with file pointer pointing at EOF --
  162. int(0)
  163. int(50)
  164. bool(false)
  165. bool(false)
  166. int(50)
  167. bool(true)
  168. -- File content type : text_with_new_line --
  169. -- fgets() with file pointer pointing at EOF --
  170. int(0)
  171. int(50)
  172. bool(false)
  173. bool(false)
  174. int(50)
  175. bool(true)
  176. -- File content type : alphanumeric --
  177. -- fgets() with file pointer pointing at EOF --
  178. int(0)
  179. int(50)
  180. bool(false)
  181. bool(false)
  182. int(50)
  183. bool(true)
  184. -- Testing fgets() with file opened using mode a+b --
  185. -- File content type : numeric --
  186. -- fgets() with file pointer pointing at EOF --
  187. int(0)
  188. int(50)
  189. bool(false)
  190. bool(false)
  191. int(50)
  192. bool(true)
  193. -- File content type : text --
  194. -- fgets() with file pointer pointing at EOF --
  195. int(0)
  196. int(50)
  197. bool(false)
  198. bool(false)
  199. int(50)
  200. bool(true)
  201. -- File content type : text_with_new_line --
  202. -- fgets() with file pointer pointing at EOF --
  203. int(0)
  204. int(50)
  205. bool(false)
  206. bool(false)
  207. int(50)
  208. bool(true)
  209. -- File content type : alphanumeric --
  210. -- fgets() with file pointer pointing at EOF --
  211. int(0)
  212. int(50)
  213. bool(false)
  214. bool(false)
  215. int(50)
  216. bool(true)
  217. -- Testing fgets() with file opened using mode a+t --
  218. -- File content type : numeric --
  219. -- fgets() with file pointer pointing at EOF --
  220. int(0)
  221. int(50)
  222. bool(false)
  223. bool(false)
  224. int(50)
  225. bool(true)
  226. -- File content type : text --
  227. -- fgets() with file pointer pointing at EOF --
  228. int(0)
  229. int(50)
  230. bool(false)
  231. bool(false)
  232. int(50)
  233. bool(true)
  234. -- File content type : text_with_new_line --
  235. -- fgets() with file pointer pointing at EOF --
  236. int(0)
  237. int(55)
  238. bool(false)
  239. bool(false)
  240. int(55)
  241. bool(true)
  242. -- File content type : alphanumeric --
  243. -- fgets() with file pointer pointing at EOF --
  244. int(0)
  245. int(50)
  246. bool(false)
  247. bool(false)
  248. int(50)
  249. bool(true)
  250. -- Testing fgets() with file opened using mode x+ --
  251. -- File content type : numeric --
  252. -- fgets() with file pointer pointing at EOF --
  253. int(0)
  254. int(50)
  255. bool(false)
  256. bool(false)
  257. int(50)
  258. bool(true)
  259. -- File content type : text --
  260. -- fgets() with file pointer pointing at EOF --
  261. int(0)
  262. int(50)
  263. bool(false)
  264. bool(false)
  265. int(50)
  266. bool(true)
  267. -- File content type : text_with_new_line --
  268. -- fgets() with file pointer pointing at EOF --
  269. int(0)
  270. int(50)
  271. bool(false)
  272. bool(false)
  273. int(50)
  274. bool(true)
  275. -- File content type : alphanumeric --
  276. -- fgets() with file pointer pointing at EOF --
  277. int(0)
  278. int(50)
  279. bool(false)
  280. bool(false)
  281. int(50)
  282. bool(true)
  283. -- Testing fgets() with file opened using mode x+b --
  284. -- File content type : numeric --
  285. -- fgets() with file pointer pointing at EOF --
  286. int(0)
  287. int(50)
  288. bool(false)
  289. bool(false)
  290. int(50)
  291. bool(true)
  292. -- File content type : text --
  293. -- fgets() with file pointer pointing at EOF --
  294. int(0)
  295. int(50)
  296. bool(false)
  297. bool(false)
  298. int(50)
  299. bool(true)
  300. -- File content type : text_with_new_line --
  301. -- fgets() with file pointer pointing at EOF --
  302. int(0)
  303. int(50)
  304. bool(false)
  305. bool(false)
  306. int(50)
  307. bool(true)
  308. -- File content type : alphanumeric --
  309. -- fgets() with file pointer pointing at EOF --
  310. int(0)
  311. int(50)
  312. bool(false)
  313. bool(false)
  314. int(50)
  315. bool(true)
  316. -- Testing fgets() with file opened using mode x+t --
  317. -- File content type : numeric --
  318. -- fgets() with file pointer pointing at EOF --
  319. int(0)
  320. int(50)
  321. bool(false)
  322. bool(false)
  323. int(50)
  324. bool(true)
  325. -- File content type : text --
  326. -- fgets() with file pointer pointing at EOF --
  327. int(0)
  328. int(50)
  329. bool(false)
  330. bool(false)
  331. int(50)
  332. bool(true)
  333. -- File content type : text_with_new_line --
  334. -- fgets() with file pointer pointing at EOF --
  335. int(0)
  336. int(55)
  337. bool(false)
  338. bool(false)
  339. int(55)
  340. bool(true)
  341. -- File content type : alphanumeric --
  342. -- fgets() with file pointer pointing at EOF --
  343. int(0)
  344. int(50)
  345. bool(false)
  346. bool(false)
  347. int(50)
  348. bool(true)
  349. Done