fgets_variation4.phpt 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569
  1. --TEST--
  2. Test fgets() function : usage variations - seek n read
  3. --SKIPIF--
  4. <?php
  5. if (substr(PHP_OS, 0, 3) == 'WIN') {
  6. die('skip Not valid for Windows');
  7. }
  8. ?>
  9. --FILE--
  10. <?php
  11. // include the file.inc for common test functions
  12. include ("file.inc");
  13. $file_modes = array("w+", "w+b", "w+t",
  14. "a+", "a+b", "a+t",
  15. "x+", "x+b", "x+t");
  16. $file_content_types = array("numeric", "text", "text_with_new_line", "alphanumeric");
  17. echo "*** Testing fgets() : usage variations ***\n";
  18. $filename = __DIR__."/fgets_variation4.tmp";
  19. foreach($file_modes as $file_mode) {
  20. echo "\n-- Testing fgets() with file opened using mode $file_mode --\n";
  21. foreach($file_content_types as $file_content_type) {
  22. echo "-- File content type : $file_content_type --\n";
  23. /* create files with $file_content_type */
  24. $file_handle = fopen($filename, $file_mode);
  25. $data = fill_file($file_handle, $file_content_type, 50);
  26. if ( !$file_handle ) {
  27. echo "Error: failed to open file $filename!";
  28. exit();
  29. }
  30. echo "-- fgets() with location set by fseek() with default length --\n";
  31. var_dump( fseek($file_handle, 5, SEEK_SET) );
  32. var_dump( ftell($file_handle) );
  33. var_dump( fgets($file_handle ) );
  34. var_dump( ftell($file_handle) ); // ensure the file pointer position
  35. var_dump( feof($file_handle) ); // ensure if eof set
  36. echo "-- fgets() with location set by fseek() with length = 20 --\n";
  37. var_dump( fseek($file_handle, 25, SEEK_SET) );
  38. var_dump( ftell($file_handle) );
  39. var_dump( fgets($file_handle, 20 ) ); // expected 19 chars
  40. var_dump( ftell($file_handle) ); // ensure the file pointer position
  41. var_dump( feof($file_handle) ); // ensure if eof set
  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. --EXPECT--
  51. *** Testing fgets() : usage variations ***
  52. -- Testing fgets() with file opened using mode w+ --
  53. -- File content type : numeric --
  54. -- fgets() with location set by fseek() with default length --
  55. int(0)
  56. int(5)
  57. string(45) "222222222222222222222222222222222222222222222"
  58. int(50)
  59. bool(true)
  60. -- fgets() with location set by fseek() with length = 20 --
  61. int(0)
  62. int(25)
  63. string(19) "2222222222222222222"
  64. int(44)
  65. bool(false)
  66. -- File content type : text --
  67. -- fgets() with location set by fseek() with default length --
  68. int(0)
  69. int(5)
  70. string(45) "text text text text text text text text text "
  71. int(50)
  72. bool(true)
  73. -- fgets() with location set by fseek() with length = 20 --
  74. int(0)
  75. int(25)
  76. string(19) "text text text text"
  77. int(44)
  78. bool(false)
  79. -- File content type : text_with_new_line --
  80. -- fgets() with location set by fseek() with default length --
  81. int(0)
  82. int(5)
  83. string(13) "line of text
  84. "
  85. int(18)
  86. bool(false)
  87. -- fgets() with location set by fseek() with length = 20 --
  88. int(0)
  89. int(25)
  90. string(11) "ne of text
  91. "
  92. int(36)
  93. bool(false)
  94. -- File content type : alphanumeric --
  95. -- fgets() with location set by fseek() with default length --
  96. int(0)
  97. int(5)
  98. string(45) "ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 "
  99. int(50)
  100. bool(true)
  101. -- fgets() with location set by fseek() with length = 20 --
  102. int(0)
  103. int(25)
  104. string(19) "ab12 ab12 ab12 ab12"
  105. int(44)
  106. bool(false)
  107. -- Testing fgets() with file opened using mode w+b --
  108. -- File content type : numeric --
  109. -- fgets() with location set by fseek() with default length --
  110. int(0)
  111. int(5)
  112. string(45) "222222222222222222222222222222222222222222222"
  113. int(50)
  114. bool(true)
  115. -- fgets() with location set by fseek() with length = 20 --
  116. int(0)
  117. int(25)
  118. string(19) "2222222222222222222"
  119. int(44)
  120. bool(false)
  121. -- File content type : text --
  122. -- fgets() with location set by fseek() with default length --
  123. int(0)
  124. int(5)
  125. string(45) "text text text text text text text text text "
  126. int(50)
  127. bool(true)
  128. -- fgets() with location set by fseek() with length = 20 --
  129. int(0)
  130. int(25)
  131. string(19) "text text text text"
  132. int(44)
  133. bool(false)
  134. -- File content type : text_with_new_line --
  135. -- fgets() with location set by fseek() with default length --
  136. int(0)
  137. int(5)
  138. string(13) "line of text
  139. "
  140. int(18)
  141. bool(false)
  142. -- fgets() with location set by fseek() with length = 20 --
  143. int(0)
  144. int(25)
  145. string(11) "ne of text
  146. "
  147. int(36)
  148. bool(false)
  149. -- File content type : alphanumeric --
  150. -- fgets() with location set by fseek() with default length --
  151. int(0)
  152. int(5)
  153. string(45) "ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 "
  154. int(50)
  155. bool(true)
  156. -- fgets() with location set by fseek() with length = 20 --
  157. int(0)
  158. int(25)
  159. string(19) "ab12 ab12 ab12 ab12"
  160. int(44)
  161. bool(false)
  162. -- Testing fgets() with file opened using mode w+t --
  163. -- File content type : numeric --
  164. -- fgets() with location set by fseek() with default length --
  165. int(0)
  166. int(5)
  167. string(45) "222222222222222222222222222222222222222222222"
  168. int(50)
  169. bool(true)
  170. -- fgets() with location set by fseek() with length = 20 --
  171. int(0)
  172. int(25)
  173. string(19) "2222222222222222222"
  174. int(44)
  175. bool(false)
  176. -- File content type : text --
  177. -- fgets() with location set by fseek() with default length --
  178. int(0)
  179. int(5)
  180. string(45) "text text text text text text text text text "
  181. int(50)
  182. bool(true)
  183. -- fgets() with location set by fseek() with length = 20 --
  184. int(0)
  185. int(25)
  186. string(19) "text text text text"
  187. int(44)
  188. bool(false)
  189. -- File content type : text_with_new_line --
  190. -- fgets() with location set by fseek() with default length --
  191. int(0)
  192. int(5)
  193. string(13) "line of text
  194. "
  195. int(18)
  196. bool(false)
  197. -- fgets() with location set by fseek() with length = 20 --
  198. int(0)
  199. int(25)
  200. string(11) "ne of text
  201. "
  202. int(36)
  203. bool(false)
  204. -- File content type : alphanumeric --
  205. -- fgets() with location set by fseek() with default length --
  206. int(0)
  207. int(5)
  208. string(45) "ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 "
  209. int(50)
  210. bool(true)
  211. -- fgets() with location set by fseek() with length = 20 --
  212. int(0)
  213. int(25)
  214. string(19) "ab12 ab12 ab12 ab12"
  215. int(44)
  216. bool(false)
  217. -- Testing fgets() with file opened using mode a+ --
  218. -- File content type : numeric --
  219. -- fgets() with location set by fseek() with default length --
  220. int(0)
  221. int(5)
  222. string(45) "222222222222222222222222222222222222222222222"
  223. int(50)
  224. bool(true)
  225. -- fgets() with location set by fseek() with length = 20 --
  226. int(0)
  227. int(25)
  228. string(19) "2222222222222222222"
  229. int(44)
  230. bool(false)
  231. -- File content type : text --
  232. -- fgets() with location set by fseek() with default length --
  233. int(0)
  234. int(5)
  235. string(45) "text text text text text text text text text "
  236. int(50)
  237. bool(true)
  238. -- fgets() with location set by fseek() with length = 20 --
  239. int(0)
  240. int(25)
  241. string(19) "text text text text"
  242. int(44)
  243. bool(false)
  244. -- File content type : text_with_new_line --
  245. -- fgets() with location set by fseek() with default length --
  246. int(0)
  247. int(5)
  248. string(13) "line of text
  249. "
  250. int(18)
  251. bool(false)
  252. -- fgets() with location set by fseek() with length = 20 --
  253. int(0)
  254. int(25)
  255. string(11) "ne of text
  256. "
  257. int(36)
  258. bool(false)
  259. -- File content type : alphanumeric --
  260. -- fgets() with location set by fseek() with default length --
  261. int(0)
  262. int(5)
  263. string(45) "ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 "
  264. int(50)
  265. bool(true)
  266. -- fgets() with location set by fseek() with length = 20 --
  267. int(0)
  268. int(25)
  269. string(19) "ab12 ab12 ab12 ab12"
  270. int(44)
  271. bool(false)
  272. -- Testing fgets() with file opened using mode a+b --
  273. -- File content type : numeric --
  274. -- fgets() with location set by fseek() with default length --
  275. int(0)
  276. int(5)
  277. string(45) "222222222222222222222222222222222222222222222"
  278. int(50)
  279. bool(true)
  280. -- fgets() with location set by fseek() with length = 20 --
  281. int(0)
  282. int(25)
  283. string(19) "2222222222222222222"
  284. int(44)
  285. bool(false)
  286. -- File content type : text --
  287. -- fgets() with location set by fseek() with default length --
  288. int(0)
  289. int(5)
  290. string(45) "text text text text text text text text text "
  291. int(50)
  292. bool(true)
  293. -- fgets() with location set by fseek() with length = 20 --
  294. int(0)
  295. int(25)
  296. string(19) "text text text text"
  297. int(44)
  298. bool(false)
  299. -- File content type : text_with_new_line --
  300. -- fgets() with location set by fseek() with default length --
  301. int(0)
  302. int(5)
  303. string(13) "line of text
  304. "
  305. int(18)
  306. bool(false)
  307. -- fgets() with location set by fseek() with length = 20 --
  308. int(0)
  309. int(25)
  310. string(11) "ne of text
  311. "
  312. int(36)
  313. bool(false)
  314. -- File content type : alphanumeric --
  315. -- fgets() with location set by fseek() with default length --
  316. int(0)
  317. int(5)
  318. string(45) "ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 "
  319. int(50)
  320. bool(true)
  321. -- fgets() with location set by fseek() with length = 20 --
  322. int(0)
  323. int(25)
  324. string(19) "ab12 ab12 ab12 ab12"
  325. int(44)
  326. bool(false)
  327. -- Testing fgets() with file opened using mode a+t --
  328. -- File content type : numeric --
  329. -- fgets() with location set by fseek() with default length --
  330. int(0)
  331. int(5)
  332. string(45) "222222222222222222222222222222222222222222222"
  333. int(50)
  334. bool(true)
  335. -- fgets() with location set by fseek() with length = 20 --
  336. int(0)
  337. int(25)
  338. string(19) "2222222222222222222"
  339. int(44)
  340. bool(false)
  341. -- File content type : text --
  342. -- fgets() with location set by fseek() with default length --
  343. int(0)
  344. int(5)
  345. string(45) "text text text text text text text text text "
  346. int(50)
  347. bool(true)
  348. -- fgets() with location set by fseek() with length = 20 --
  349. int(0)
  350. int(25)
  351. string(19) "text text text text"
  352. int(44)
  353. bool(false)
  354. -- File content type : text_with_new_line --
  355. -- fgets() with location set by fseek() with default length --
  356. int(0)
  357. int(5)
  358. string(13) "line of text
  359. "
  360. int(18)
  361. bool(false)
  362. -- fgets() with location set by fseek() with length = 20 --
  363. int(0)
  364. int(25)
  365. string(11) "ne of text
  366. "
  367. int(36)
  368. bool(false)
  369. -- File content type : alphanumeric --
  370. -- fgets() with location set by fseek() with default length --
  371. int(0)
  372. int(5)
  373. string(45) "ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 "
  374. int(50)
  375. bool(true)
  376. -- fgets() with location set by fseek() with length = 20 --
  377. int(0)
  378. int(25)
  379. string(19) "ab12 ab12 ab12 ab12"
  380. int(44)
  381. bool(false)
  382. -- Testing fgets() with file opened using mode x+ --
  383. -- File content type : numeric --
  384. -- fgets() with location set by fseek() with default length --
  385. int(0)
  386. int(5)
  387. string(45) "222222222222222222222222222222222222222222222"
  388. int(50)
  389. bool(true)
  390. -- fgets() with location set by fseek() with length = 20 --
  391. int(0)
  392. int(25)
  393. string(19) "2222222222222222222"
  394. int(44)
  395. bool(false)
  396. -- File content type : text --
  397. -- fgets() with location set by fseek() with default length --
  398. int(0)
  399. int(5)
  400. string(45) "text text text text text text text text text "
  401. int(50)
  402. bool(true)
  403. -- fgets() with location set by fseek() with length = 20 --
  404. int(0)
  405. int(25)
  406. string(19) "text text text text"
  407. int(44)
  408. bool(false)
  409. -- File content type : text_with_new_line --
  410. -- fgets() with location set by fseek() with default length --
  411. int(0)
  412. int(5)
  413. string(13) "line of text
  414. "
  415. int(18)
  416. bool(false)
  417. -- fgets() with location set by fseek() with length = 20 --
  418. int(0)
  419. int(25)
  420. string(11) "ne of text
  421. "
  422. int(36)
  423. bool(false)
  424. -- File content type : alphanumeric --
  425. -- fgets() with location set by fseek() with default length --
  426. int(0)
  427. int(5)
  428. string(45) "ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 "
  429. int(50)
  430. bool(true)
  431. -- fgets() with location set by fseek() with length = 20 --
  432. int(0)
  433. int(25)
  434. string(19) "ab12 ab12 ab12 ab12"
  435. int(44)
  436. bool(false)
  437. -- Testing fgets() with file opened using mode x+b --
  438. -- File content type : numeric --
  439. -- fgets() with location set by fseek() with default length --
  440. int(0)
  441. int(5)
  442. string(45) "222222222222222222222222222222222222222222222"
  443. int(50)
  444. bool(true)
  445. -- fgets() with location set by fseek() with length = 20 --
  446. int(0)
  447. int(25)
  448. string(19) "2222222222222222222"
  449. int(44)
  450. bool(false)
  451. -- File content type : text --
  452. -- fgets() with location set by fseek() with default length --
  453. int(0)
  454. int(5)
  455. string(45) "text text text text text text text text text "
  456. int(50)
  457. bool(true)
  458. -- fgets() with location set by fseek() with length = 20 --
  459. int(0)
  460. int(25)
  461. string(19) "text text text text"
  462. int(44)
  463. bool(false)
  464. -- File content type : text_with_new_line --
  465. -- fgets() with location set by fseek() with default length --
  466. int(0)
  467. int(5)
  468. string(13) "line of text
  469. "
  470. int(18)
  471. bool(false)
  472. -- fgets() with location set by fseek() with length = 20 --
  473. int(0)
  474. int(25)
  475. string(11) "ne of text
  476. "
  477. int(36)
  478. bool(false)
  479. -- File content type : alphanumeric --
  480. -- fgets() with location set by fseek() with default length --
  481. int(0)
  482. int(5)
  483. string(45) "ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 "
  484. int(50)
  485. bool(true)
  486. -- fgets() with location set by fseek() with length = 20 --
  487. int(0)
  488. int(25)
  489. string(19) "ab12 ab12 ab12 ab12"
  490. int(44)
  491. bool(false)
  492. -- Testing fgets() with file opened using mode x+t --
  493. -- File content type : numeric --
  494. -- fgets() with location set by fseek() with default length --
  495. int(0)
  496. int(5)
  497. string(45) "222222222222222222222222222222222222222222222"
  498. int(50)
  499. bool(true)
  500. -- fgets() with location set by fseek() with length = 20 --
  501. int(0)
  502. int(25)
  503. string(19) "2222222222222222222"
  504. int(44)
  505. bool(false)
  506. -- File content type : text --
  507. -- fgets() with location set by fseek() with default length --
  508. int(0)
  509. int(5)
  510. string(45) "text text text text text text text text text "
  511. int(50)
  512. bool(true)
  513. -- fgets() with location set by fseek() with length = 20 --
  514. int(0)
  515. int(25)
  516. string(19) "text text text text"
  517. int(44)
  518. bool(false)
  519. -- File content type : text_with_new_line --
  520. -- fgets() with location set by fseek() with default length --
  521. int(0)
  522. int(5)
  523. string(13) "line of text
  524. "
  525. int(18)
  526. bool(false)
  527. -- fgets() with location set by fseek() with length = 20 --
  528. int(0)
  529. int(25)
  530. string(11) "ne of text
  531. "
  532. int(36)
  533. bool(false)
  534. -- File content type : alphanumeric --
  535. -- fgets() with location set by fseek() with default length --
  536. int(0)
  537. int(5)
  538. string(45) "ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 "
  539. int(50)
  540. bool(true)
  541. -- fgets() with location set by fseek() with length = 20 --
  542. int(0)
  543. int(25)
  544. string(19) "ab12 ab12 ab12 ab12"
  545. int(44)
  546. bool(false)
  547. Done