fflush_variation2.phpt 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443
  1. --TEST--
  2. Test fflush() function: usage variations - links as resource
  3. --SKIPIF--
  4. <?php
  5. if( substr(PHP_OS, 0, 3) == 'WIN')
  6. die("skip Links not valid on Windows");
  7. ?>
  8. --FILE--
  9. <?php
  10. /* Prototype: bool fflush ( resource $handle );
  11. Description: Flushes the output to a file
  12. */
  13. /* test fflush() with handle to symbollic link */
  14. $file_path = dirname(__FILE__);
  15. require $file_path.'/file.inc';
  16. echo "*** Testing fflush(): with soft links to files opened in diff modes ***\n";
  17. $file_types = array("empty", "numeric", "text", "text_with_new_line", "alphanumeric");
  18. $file_modes = array("w", "wb", "wt", "w+", "w+b", "w+t",
  19. "a", "ab", "at", "a+","a+b", "a+t");
  20. $file_name = "$file_path/fflush_variation2.tmp";
  21. $symlink_name = "$file_path/symlnk_fflush_variation2.tmp";
  22. $count = 1;
  23. foreach( $file_types as $type ) {
  24. echo "-- Iteration $count with file containing $type data --\n";
  25. foreach( $file_modes as $mode ) {
  26. echo "-- link opened in $mode mode --\n";
  27. //creating the file
  28. $file_handle = fopen($file_name, "w");
  29. if($file_handle == false)
  30. exit("Error:failed to open file $file_name");
  31. //fill the file with some data if mode is append mode
  32. if( substr($mode, 0, 1) == "a" )
  33. fill_file($file_handle, $type, 10);
  34. //close the file
  35. fclose($file_handle);
  36. // creating the sym link
  37. var_dump( symlink($file_name, $symlink_name) );
  38. $file_handle = fopen($symlink_name, $mode);
  39. if($file_handle == false)
  40. exit("Error:failed to open link $symlink_name");
  41. // filling data into the file
  42. var_dump( fill_file($file_handle, $type, 50) );
  43. var_dump( fflush($file_handle) );
  44. fclose($file_handle);
  45. // reading the data from the file
  46. var_dump( readfile($symlink_name) );
  47. unlink($symlink_name);
  48. unlink($file_name);
  49. }
  50. $count++;
  51. }
  52. echo "\n*** Done ***";
  53. ?>
  54. --EXPECTF--
  55. *** Testing fflush(): with soft links to files opened in diff modes ***
  56. -- Iteration 1 with file containing empty data --
  57. -- link opened in w mode --
  58. bool(true)
  59. bool(true)
  60. bool(true)
  61. int(0)
  62. -- link opened in wb mode --
  63. bool(true)
  64. bool(true)
  65. bool(true)
  66. int(0)
  67. -- link opened in wt mode --
  68. bool(true)
  69. bool(true)
  70. bool(true)
  71. int(0)
  72. -- link opened in w+ mode --
  73. bool(true)
  74. bool(true)
  75. bool(true)
  76. int(0)
  77. -- link opened in w+b mode --
  78. bool(true)
  79. bool(true)
  80. bool(true)
  81. int(0)
  82. -- link opened in w+t mode --
  83. bool(true)
  84. bool(true)
  85. bool(true)
  86. int(0)
  87. -- link opened in a mode --
  88. bool(true)
  89. bool(true)
  90. bool(true)
  91. int(0)
  92. -- link opened in ab mode --
  93. bool(true)
  94. bool(true)
  95. bool(true)
  96. int(0)
  97. -- link opened in at mode --
  98. bool(true)
  99. bool(true)
  100. bool(true)
  101. int(0)
  102. -- link opened in a+ mode --
  103. bool(true)
  104. bool(true)
  105. bool(true)
  106. int(0)
  107. -- link opened in a+b mode --
  108. bool(true)
  109. bool(true)
  110. bool(true)
  111. int(0)
  112. -- link opened in a+t mode --
  113. bool(true)
  114. bool(true)
  115. bool(true)
  116. int(0)
  117. -- Iteration 2 with file containing numeric data --
  118. -- link opened in w mode --
  119. bool(true)
  120. bool(true)
  121. bool(true)
  122. 22222222222222222222222222222222222222222222222222int(50)
  123. -- link opened in wb mode --
  124. bool(true)
  125. bool(true)
  126. bool(true)
  127. 22222222222222222222222222222222222222222222222222int(50)
  128. -- link opened in wt mode --
  129. bool(true)
  130. bool(true)
  131. bool(true)
  132. 22222222222222222222222222222222222222222222222222int(50)
  133. -- link opened in w+ mode --
  134. bool(true)
  135. bool(true)
  136. bool(true)
  137. 22222222222222222222222222222222222222222222222222int(50)
  138. -- link opened in w+b mode --
  139. bool(true)
  140. bool(true)
  141. bool(true)
  142. 22222222222222222222222222222222222222222222222222int(50)
  143. -- link opened in w+t mode --
  144. bool(true)
  145. bool(true)
  146. bool(true)
  147. 22222222222222222222222222222222222222222222222222int(50)
  148. -- link opened in a mode --
  149. bool(true)
  150. bool(true)
  151. bool(true)
  152. 222222222222222222222222222222222222222222222222222222222222int(60)
  153. -- link opened in ab mode --
  154. bool(true)
  155. bool(true)
  156. bool(true)
  157. 222222222222222222222222222222222222222222222222222222222222int(60)
  158. -- link opened in at mode --
  159. bool(true)
  160. bool(true)
  161. bool(true)
  162. 222222222222222222222222222222222222222222222222222222222222int(60)
  163. -- link opened in a+ mode --
  164. bool(true)
  165. bool(true)
  166. bool(true)
  167. 222222222222222222222222222222222222222222222222222222222222int(60)
  168. -- link opened in a+b mode --
  169. bool(true)
  170. bool(true)
  171. bool(true)
  172. 222222222222222222222222222222222222222222222222222222222222int(60)
  173. -- link opened in a+t mode --
  174. bool(true)
  175. bool(true)
  176. bool(true)
  177. 222222222222222222222222222222222222222222222222222222222222int(60)
  178. -- Iteration 3 with file containing text data --
  179. -- link opened in w mode --
  180. bool(true)
  181. bool(true)
  182. bool(true)
  183. text text text text text text text text text text int(50)
  184. -- link opened in wb mode --
  185. bool(true)
  186. bool(true)
  187. bool(true)
  188. text text text text text text text text text text int(50)
  189. -- link opened in wt mode --
  190. bool(true)
  191. bool(true)
  192. bool(true)
  193. text text text text text text text text text text int(50)
  194. -- link opened in w+ mode --
  195. bool(true)
  196. bool(true)
  197. bool(true)
  198. text text text text text text text text text text int(50)
  199. -- link opened in w+b mode --
  200. bool(true)
  201. bool(true)
  202. bool(true)
  203. text text text text text text text text text text int(50)
  204. -- link opened in w+t mode --
  205. bool(true)
  206. bool(true)
  207. bool(true)
  208. text text text text text text text text text text int(50)
  209. -- link opened in a mode --
  210. bool(true)
  211. bool(true)
  212. bool(true)
  213. text text text text text text text text text text text text int(60)
  214. -- link opened in ab mode --
  215. bool(true)
  216. bool(true)
  217. bool(true)
  218. text text text text text text text text text text text text int(60)
  219. -- link opened in at mode --
  220. bool(true)
  221. bool(true)
  222. bool(true)
  223. text text text text text text text text text text text text int(60)
  224. -- link opened in a+ mode --
  225. bool(true)
  226. bool(true)
  227. bool(true)
  228. text text text text text text text text text text text text int(60)
  229. -- link opened in a+b mode --
  230. bool(true)
  231. bool(true)
  232. bool(true)
  233. text text text text text text text text text text text text int(60)
  234. -- link opened in a+t mode --
  235. bool(true)
  236. bool(true)
  237. bool(true)
  238. text text text text text text text text text text text text int(60)
  239. -- Iteration 4 with file containing text_with_new_line data --
  240. -- link opened in w mode --
  241. bool(true)
  242. bool(true)
  243. bool(true)
  244. line
  245. line of text
  246. line
  247. line of text
  248. line
  249. line of tint(50)
  250. -- link opened in wb mode --
  251. bool(true)
  252. bool(true)
  253. bool(true)
  254. line
  255. line of text
  256. line
  257. line of text
  258. line
  259. line of tint(50)
  260. -- link opened in wt mode --
  261. bool(true)
  262. bool(true)
  263. bool(true)
  264. line
  265. line of text
  266. line
  267. line of text
  268. line
  269. line of tint(50)
  270. -- link opened in w+ mode --
  271. bool(true)
  272. bool(true)
  273. bool(true)
  274. line
  275. line of text
  276. line
  277. line of text
  278. line
  279. line of tint(50)
  280. -- link opened in w+b mode --
  281. bool(true)
  282. bool(true)
  283. bool(true)
  284. line
  285. line of text
  286. line
  287. line of text
  288. line
  289. line of tint(50)
  290. -- link opened in w+t mode --
  291. bool(true)
  292. bool(true)
  293. bool(true)
  294. line
  295. line of text
  296. line
  297. line of text
  298. line
  299. line of tint(50)
  300. -- link opened in a mode --
  301. bool(true)
  302. bool(true)
  303. bool(true)
  304. line
  305. line line
  306. line of text
  307. line
  308. line of text
  309. line
  310. line of tint(60)
  311. -- link opened in ab mode --
  312. bool(true)
  313. bool(true)
  314. bool(true)
  315. line
  316. line line
  317. line of text
  318. line
  319. line of text
  320. line
  321. line of tint(60)
  322. -- link opened in at mode --
  323. bool(true)
  324. bool(true)
  325. bool(true)
  326. line
  327. line line
  328. line of text
  329. line
  330. line of text
  331. line
  332. line of tint(60)
  333. -- link opened in a+ mode --
  334. bool(true)
  335. bool(true)
  336. bool(true)
  337. line
  338. line line
  339. line of text
  340. line
  341. line of text
  342. line
  343. line of tint(60)
  344. -- link opened in a+b mode --
  345. bool(true)
  346. bool(true)
  347. bool(true)
  348. line
  349. line line
  350. line of text
  351. line
  352. line of text
  353. line
  354. line of tint(60)
  355. -- link opened in a+t mode --
  356. bool(true)
  357. bool(true)
  358. bool(true)
  359. line
  360. line line
  361. line of text
  362. line
  363. line of text
  364. line
  365. line of tint(60)
  366. -- Iteration 5 with file containing alphanumeric data --
  367. -- link opened in w mode --
  368. bool(true)
  369. bool(true)
  370. bool(true)
  371. ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 int(50)
  372. -- link opened in wb mode --
  373. bool(true)
  374. bool(true)
  375. bool(true)
  376. ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 int(50)
  377. -- link opened in wt mode --
  378. bool(true)
  379. bool(true)
  380. bool(true)
  381. ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 int(50)
  382. -- link opened in w+ mode --
  383. bool(true)
  384. bool(true)
  385. bool(true)
  386. ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 int(50)
  387. -- link opened in w+b mode --
  388. bool(true)
  389. bool(true)
  390. bool(true)
  391. ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 int(50)
  392. -- link opened in w+t mode --
  393. bool(true)
  394. bool(true)
  395. bool(true)
  396. ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 int(50)
  397. -- link opened in a mode --
  398. bool(true)
  399. bool(true)
  400. bool(true)
  401. ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 int(60)
  402. -- link opened in ab mode --
  403. bool(true)
  404. bool(true)
  405. bool(true)
  406. ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 int(60)
  407. -- link opened in at mode --
  408. bool(true)
  409. bool(true)
  410. bool(true)
  411. ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 int(60)
  412. -- link opened in a+ mode --
  413. bool(true)
  414. bool(true)
  415. bool(true)
  416. ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 int(60)
  417. -- link opened in a+b mode --
  418. bool(true)
  419. bool(true)
  420. bool(true)
  421. ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 int(60)
  422. -- link opened in a+t mode --
  423. bool(true)
  424. bool(true)
  425. bool(true)
  426. ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 int(60)
  427. *** Done ***