userstreams_005.phpt 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. --TEST--
  2. User-space streams: stream_truncate()
  3. --FILE--
  4. <?php
  5. class test_wrapper_base {
  6. public $mode;
  7. function stream_open($path, $mode, $openedpath) {
  8. return true;
  9. }
  10. function stream_eof() {
  11. return false;
  12. }
  13. }
  14. class test_wrapper extends test_wrapper_base {
  15. function stream_truncate($new_size) {
  16. echo "truncation with new_size=$new_size\n";
  17. return true;
  18. }
  19. }
  20. class test_wrapper_bad extends test_wrapper_base {
  21. function stream_truncate($new_size) {
  22. echo "truncation with new_size=$new_size\n";
  23. return "kkk";
  24. }
  25. }
  26. function test($name, $fd, $dest_size) {
  27. echo "------ $name: -------\n";
  28. var_dump(ftruncate($fd, $dest_size));
  29. }
  30. var_dump(stream_wrapper_register('test', 'test_wrapper'));
  31. var_dump(stream_wrapper_register('test2', 'test_wrapper_base'));
  32. var_dump(stream_wrapper_register('test3', 'test_wrapper_bad'));
  33. $fd = fopen("test://foo","r");
  34. $fd2 = fopen("test2://foo","r");
  35. $fd3 = fopen("test3://foo","r");
  36. test("stream_truncate not implemented", $fd2, 0);
  37. test("stream_truncate size 0", $fd, 0);
  38. test("stream_truncate size 10", $fd, 10);
  39. test("stream_truncate negative size", $fd, -1);
  40. test("stream_truncate bad return", $fd3, 0);
  41. --EXPECTF--
  42. bool(true)
  43. bool(true)
  44. bool(true)
  45. ------ stream_truncate not implemented: -------
  46. Warning: ftruncate(): Can't truncate this stream! in %s on line %d
  47. bool(false)
  48. ------ stream_truncate size 0: -------
  49. truncation with new_size=0
  50. bool(true)
  51. ------ stream_truncate size 10: -------
  52. truncation with new_size=10
  53. bool(true)
  54. ------ stream_truncate negative size: -------
  55. bool(false)
  56. ------ stream_truncate bad return: -------
  57. truncation with new_size=0
  58. Warning: ftruncate(): test_wrapper_bad::stream_truncate did not return a boolean! in %s on line %d
  59. bool(false)