Annotation of embedaddon/php/ext/standard/tests/file/userstreams_005.phpt, revision 1.1.1.1
1.1 misho 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:
34: $fd = fopen("test://foo","r");
35: $fd2 = fopen("test2://foo","r");
36: $fd3 = fopen("test3://foo","r");
37:
38: test("stream_truncate not implemented", $fd2, 0);
39: test("stream_truncate size 0", $fd, 0);
40: test("stream_truncate size 10", $fd, 10);
41: test("stream_truncate negative size", $fd, -1);
42: test("stream_truncate bad return", $fd3, 0);
43: --EXPECTF--
44: bool(true)
45: bool(true)
46: bool(true)
47: ------ stream_truncate not implemented: -------
48:
49: Warning: ftruncate(): Can't truncate this stream! in %s on line %d
50: bool(false)
51: ------ stream_truncate size 0: -------
52: truncation with new_size=0
53: bool(true)
54: ------ stream_truncate size 10: -------
55: truncation with new_size=10
56: bool(true)
57: ------ stream_truncate negative size: -------
58: bool(false)
59: ------ stream_truncate bad return: -------
60: truncation with new_size=0
61:
62: Warning: ftruncate(): test_wrapper_bad::stream_truncate did not return a boolean! in %s on line %d
63: bool(false)
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>