fgets_variation4-win32.phpt 13 KB

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