fflush_variation2.phpt 8.7 KB

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