ftruncate_variation7-win32.phpt 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458
  1. --TEST--
  2. Test ftruncate() function : usage variations - truncate when file pointer at EOF
  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. /* truncate the file when file pointer is positioned at end of the file */
  12. // include common file related test functions
  13. include ("file.inc");
  14. echo "*** Testing ftruncate() : usage variations ***\n";
  15. /* test ftruncate with file opened in different modes */
  16. $file_modes = array("r", "rb", "rt", "r+", "r+b", "r+t",
  17. "w", "wb", "wt", "w+", "w+b", "w+t",
  18. "x", "xb", "xt", "x+", "x+b", "x+t",
  19. "a", "ab", "at", "a+", "a+b", "a+t");
  20. $file_content_types = array("numeric","text_with_new_line");
  21. foreach($file_content_types as $file_content_type) {
  22. echo "\n-- Testing ftruncate() with file having data of type ". $file_content_type ." --\n";
  23. for($mode_counter = 0; $mode_counter < count($file_modes); $mode_counter++) {
  24. echo "-- Testing ftruncate() with file opening using $file_modes[$mode_counter] mode --\n";
  25. // create 1 file with some contents
  26. $filename = __DIR__."/ftruncate_variation7.tmp";
  27. if( strstr($file_modes[$mode_counter], "x") || strstr($file_modes[$mode_counter], "w") ) {
  28. // fopen the file using the $file_modes
  29. $file_handle = fopen($filename, $file_modes[$mode_counter]);
  30. fill_file($file_handle, $file_content_type, 1024);
  31. } else {
  32. create_files ( __DIR__, 1, $file_content_type, 0755, 1, "w", "ftruncate_variation", 7);
  33. // fopen the file using the $file_modes
  34. $file_handle = fopen($filename, $file_modes[$mode_counter]);
  35. }
  36. if (!$file_handle) {
  37. echo "Error: failed to open file $filename!\n";
  38. exit();
  39. }
  40. rewind($file_handle); // file pointer to 0
  41. echo "-- Testing ftruncate(): File pointer at the end --\n";
  42. /* try to truncate it to while file pointer at the end */
  43. fseek($file_handle, 0, SEEK_END);
  44. $new_size = 200;
  45. var_dump( filesize($filename) ); // current filesize
  46. var_dump( ftell($file_handle) );
  47. var_dump( ftruncate($file_handle, $new_size) ); // truncate it
  48. var_dump( ftell($file_handle) );
  49. var_dump( feof($file_handle) );
  50. fclose($file_handle);
  51. clearstatcache(); // clear previous size value in cache
  52. var_dump( filesize($filename) );
  53. //delete all files created
  54. delete_file($filename);
  55. }//end of inner for loop
  56. }//end of outer foreach loop
  57. echo "Done\n";
  58. ?>
  59. --EXPECT--
  60. *** Testing ftruncate() : usage variations ***
  61. -- Testing ftruncate() with file having data of type numeric --
  62. -- Testing ftruncate() with file opening using r mode --
  63. -- Testing ftruncate(): File pointer at the end --
  64. int(1024)
  65. int(1024)
  66. bool(false)
  67. int(1024)
  68. bool(false)
  69. int(1024)
  70. -- Testing ftruncate() with file opening using rb mode --
  71. -- Testing ftruncate(): File pointer at the end --
  72. int(1024)
  73. int(1024)
  74. bool(false)
  75. int(1024)
  76. bool(false)
  77. int(1024)
  78. -- Testing ftruncate() with file opening using rt mode --
  79. -- Testing ftruncate(): File pointer at the end --
  80. int(1024)
  81. int(1024)
  82. bool(false)
  83. int(1024)
  84. bool(false)
  85. int(1024)
  86. -- Testing ftruncate() with file opening using r+ mode --
  87. -- Testing ftruncate(): File pointer at the end --
  88. int(1024)
  89. int(1024)
  90. bool(true)
  91. int(1024)
  92. bool(false)
  93. int(200)
  94. -- Testing ftruncate() with file opening using r+b mode --
  95. -- Testing ftruncate(): File pointer at the end --
  96. int(1024)
  97. int(1024)
  98. bool(true)
  99. int(1024)
  100. bool(false)
  101. int(200)
  102. -- Testing ftruncate() with file opening using r+t mode --
  103. -- Testing ftruncate(): File pointer at the end --
  104. int(1024)
  105. int(1024)
  106. bool(true)
  107. int(1024)
  108. bool(false)
  109. int(200)
  110. -- Testing ftruncate() with file opening using w mode --
  111. -- Testing ftruncate(): File pointer at the end --
  112. int(1024)
  113. int(1024)
  114. bool(true)
  115. int(1024)
  116. bool(false)
  117. int(200)
  118. -- Testing ftruncate() with file opening using wb mode --
  119. -- Testing ftruncate(): File pointer at the end --
  120. int(1024)
  121. int(1024)
  122. bool(true)
  123. int(1024)
  124. bool(false)
  125. int(200)
  126. -- Testing ftruncate() with file opening using wt mode --
  127. -- Testing ftruncate(): File pointer at the end --
  128. int(1024)
  129. int(1024)
  130. bool(true)
  131. int(1024)
  132. bool(false)
  133. int(200)
  134. -- Testing ftruncate() with file opening using w+ mode --
  135. -- Testing ftruncate(): File pointer at the end --
  136. int(1024)
  137. int(1024)
  138. bool(true)
  139. int(1024)
  140. bool(false)
  141. int(200)
  142. -- Testing ftruncate() with file opening using w+b mode --
  143. -- Testing ftruncate(): File pointer at the end --
  144. int(1024)
  145. int(1024)
  146. bool(true)
  147. int(1024)
  148. bool(false)
  149. int(200)
  150. -- Testing ftruncate() with file opening using w+t mode --
  151. -- Testing ftruncate(): File pointer at the end --
  152. int(1024)
  153. int(1024)
  154. bool(true)
  155. int(1024)
  156. bool(false)
  157. int(200)
  158. -- Testing ftruncate() with file opening using x mode --
  159. -- Testing ftruncate(): File pointer at the end --
  160. int(1024)
  161. int(1024)
  162. bool(true)
  163. int(1024)
  164. bool(false)
  165. int(200)
  166. -- Testing ftruncate() with file opening using xb mode --
  167. -- Testing ftruncate(): File pointer at the end --
  168. int(1024)
  169. int(1024)
  170. bool(true)
  171. int(1024)
  172. bool(false)
  173. int(200)
  174. -- Testing ftruncate() with file opening using xt mode --
  175. -- Testing ftruncate(): File pointer at the end --
  176. int(1024)
  177. int(1024)
  178. bool(true)
  179. int(1024)
  180. bool(false)
  181. int(200)
  182. -- Testing ftruncate() with file opening using x+ mode --
  183. -- Testing ftruncate(): File pointer at the end --
  184. int(1024)
  185. int(1024)
  186. bool(true)
  187. int(1024)
  188. bool(false)
  189. int(200)
  190. -- Testing ftruncate() with file opening using x+b mode --
  191. -- Testing ftruncate(): File pointer at the end --
  192. int(1024)
  193. int(1024)
  194. bool(true)
  195. int(1024)
  196. bool(false)
  197. int(200)
  198. -- Testing ftruncate() with file opening using x+t mode --
  199. -- Testing ftruncate(): File pointer at the end --
  200. int(1024)
  201. int(1024)
  202. bool(true)
  203. int(1024)
  204. bool(false)
  205. int(200)
  206. -- Testing ftruncate() with file opening using a mode --
  207. -- Testing ftruncate(): File pointer at the end --
  208. int(1024)
  209. int(1024)
  210. bool(true)
  211. int(1024)
  212. bool(false)
  213. int(200)
  214. -- Testing ftruncate() with file opening using ab mode --
  215. -- Testing ftruncate(): File pointer at the end --
  216. int(1024)
  217. int(1024)
  218. bool(true)
  219. int(1024)
  220. bool(false)
  221. int(200)
  222. -- Testing ftruncate() with file opening using at mode --
  223. -- Testing ftruncate(): File pointer at the end --
  224. int(1024)
  225. int(1024)
  226. bool(true)
  227. int(1024)
  228. bool(false)
  229. int(200)
  230. -- Testing ftruncate() with file opening using a+ mode --
  231. -- Testing ftruncate(): File pointer at the end --
  232. int(1024)
  233. int(1024)
  234. bool(true)
  235. int(1024)
  236. bool(false)
  237. int(200)
  238. -- Testing ftruncate() with file opening using a+b mode --
  239. -- Testing ftruncate(): File pointer at the end --
  240. int(1024)
  241. int(1024)
  242. bool(true)
  243. int(1024)
  244. bool(false)
  245. int(200)
  246. -- Testing ftruncate() with file opening using a+t mode --
  247. -- Testing ftruncate(): File pointer at the end --
  248. int(1024)
  249. int(1024)
  250. bool(true)
  251. int(1024)
  252. bool(false)
  253. int(200)
  254. -- Testing ftruncate() with file having data of type text_with_new_line --
  255. -- Testing ftruncate() with file opening using r mode --
  256. -- Testing ftruncate(): File pointer at the end --
  257. int(1024)
  258. int(1024)
  259. bool(false)
  260. int(1024)
  261. bool(false)
  262. int(1024)
  263. -- Testing ftruncate() with file opening using rb mode --
  264. -- Testing ftruncate(): File pointer at the end --
  265. int(1024)
  266. int(1024)
  267. bool(false)
  268. int(1024)
  269. bool(false)
  270. int(1024)
  271. -- Testing ftruncate() with file opening using rt mode --
  272. -- Testing ftruncate(): File pointer at the end --
  273. int(1024)
  274. int(1024)
  275. bool(false)
  276. int(1024)
  277. bool(false)
  278. int(1024)
  279. -- Testing ftruncate() with file opening using r+ mode --
  280. -- Testing ftruncate(): File pointer at the end --
  281. int(1024)
  282. int(1024)
  283. bool(true)
  284. int(1024)
  285. bool(false)
  286. int(200)
  287. -- Testing ftruncate() with file opening using r+b mode --
  288. -- Testing ftruncate(): File pointer at the end --
  289. int(1024)
  290. int(1024)
  291. bool(true)
  292. int(1024)
  293. bool(false)
  294. int(200)
  295. -- Testing ftruncate() with file opening using r+t mode --
  296. -- Testing ftruncate(): File pointer at the end --
  297. int(1024)
  298. int(1024)
  299. bool(true)
  300. int(1024)
  301. bool(false)
  302. int(200)
  303. -- Testing ftruncate() with file opening using w mode --
  304. -- Testing ftruncate(): File pointer at the end --
  305. int(1024)
  306. int(1024)
  307. bool(true)
  308. int(1024)
  309. bool(false)
  310. int(200)
  311. -- Testing ftruncate() with file opening using wb mode --
  312. -- Testing ftruncate(): File pointer at the end --
  313. int(1024)
  314. int(1024)
  315. bool(true)
  316. int(1024)
  317. bool(false)
  318. int(200)
  319. -- Testing ftruncate() with file opening using wt mode --
  320. -- Testing ftruncate(): File pointer at the end --
  321. int(1137)
  322. int(1137)
  323. bool(true)
  324. int(1137)
  325. bool(false)
  326. int(200)
  327. -- Testing ftruncate() with file opening using w+ mode --
  328. -- Testing ftruncate(): File pointer at the end --
  329. int(1024)
  330. int(1024)
  331. bool(true)
  332. int(1024)
  333. bool(false)
  334. int(200)
  335. -- Testing ftruncate() with file opening using w+b mode --
  336. -- Testing ftruncate(): File pointer at the end --
  337. int(1024)
  338. int(1024)
  339. bool(true)
  340. int(1024)
  341. bool(false)
  342. int(200)
  343. -- Testing ftruncate() with file opening using w+t mode --
  344. -- Testing ftruncate(): File pointer at the end --
  345. int(1137)
  346. int(1137)
  347. bool(true)
  348. int(1137)
  349. bool(false)
  350. int(200)
  351. -- Testing ftruncate() with file opening using x mode --
  352. -- Testing ftruncate(): File pointer at the end --
  353. int(1024)
  354. int(1024)
  355. bool(true)
  356. int(1024)
  357. bool(false)
  358. int(200)
  359. -- Testing ftruncate() with file opening using xb mode --
  360. -- Testing ftruncate(): File pointer at the end --
  361. int(1024)
  362. int(1024)
  363. bool(true)
  364. int(1024)
  365. bool(false)
  366. int(200)
  367. -- Testing ftruncate() with file opening using xt mode --
  368. -- Testing ftruncate(): File pointer at the end --
  369. int(1137)
  370. int(1137)
  371. bool(true)
  372. int(1137)
  373. bool(false)
  374. int(200)
  375. -- Testing ftruncate() with file opening using x+ mode --
  376. -- Testing ftruncate(): File pointer at the end --
  377. int(1024)
  378. int(1024)
  379. bool(true)
  380. int(1024)
  381. bool(false)
  382. int(200)
  383. -- Testing ftruncate() with file opening using x+b mode --
  384. -- Testing ftruncate(): File pointer at the end --
  385. int(1024)
  386. int(1024)
  387. bool(true)
  388. int(1024)
  389. bool(false)
  390. int(200)
  391. -- Testing ftruncate() with file opening using x+t mode --
  392. -- Testing ftruncate(): File pointer at the end --
  393. int(1137)
  394. int(1137)
  395. bool(true)
  396. int(1137)
  397. bool(false)
  398. int(200)
  399. -- Testing ftruncate() with file opening using a mode --
  400. -- Testing ftruncate(): File pointer at the end --
  401. int(1024)
  402. int(1024)
  403. bool(true)
  404. int(1024)
  405. bool(false)
  406. int(200)
  407. -- Testing ftruncate() with file opening using ab mode --
  408. -- Testing ftruncate(): File pointer at the end --
  409. int(1024)
  410. int(1024)
  411. bool(true)
  412. int(1024)
  413. bool(false)
  414. int(200)
  415. -- Testing ftruncate() with file opening using at mode --
  416. -- Testing ftruncate(): File pointer at the end --
  417. int(1024)
  418. int(1024)
  419. bool(true)
  420. int(1024)
  421. bool(false)
  422. int(200)
  423. -- Testing ftruncate() with file opening using a+ mode --
  424. -- Testing ftruncate(): File pointer at the end --
  425. int(1024)
  426. int(1024)
  427. bool(true)
  428. int(1024)
  429. bool(false)
  430. int(200)
  431. -- Testing ftruncate() with file opening using a+b mode --
  432. -- Testing ftruncate(): File pointer at the end --
  433. int(1024)
  434. int(1024)
  435. bool(true)
  436. int(1024)
  437. bool(false)
  438. int(200)
  439. -- Testing ftruncate() with file opening using a+t mode --
  440. -- Testing ftruncate(): File pointer at the end --
  441. int(1024)
  442. int(1024)
  443. bool(true)
  444. int(1024)
  445. bool(false)
  446. int(200)
  447. Done