fgetc_basic.phpt 11 KB

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