ftruncate_variation1-win32-mb.phpt 10 KB

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