1--TEST--
2User-space streams: stream_truncate()
3--FILE--
4<?php
5class 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}
14class 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}
20class 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}
26function test($name, $fd, $dest_size) {
27	echo "------ $name: -------\n";
28	var_dump(ftruncate($fd, $dest_size));
29}
30var_dump(stream_wrapper_register('test', 'test_wrapper'));
31var_dump(stream_wrapper_register('test2', 'test_wrapper_base'));
32var_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
38test("stream_truncate not implemented", $fd2, 0);
39test("stream_truncate size 0", $fd, 0);
40test("stream_truncate size 10", $fd, 10);
41test("stream_truncate negative size", $fd, -1);
42test("stream_truncate bad return", $fd3, 0);
43--EXPECTF--
44bool(true)
45bool(true)
46bool(true)
47------ stream_truncate not implemented: -------
48
49Warning: ftruncate(): Can't truncate this stream! in %s on line %d
50bool(false)
51------ stream_truncate size 0: -------
52truncation with new_size=0
53bool(true)
54------ stream_truncate size 10: -------
55truncation with new_size=10
56bool(true)
57------ stream_truncate negative size: -------
58
59Warning: ftruncate(): Negative size is not supported in %s on line %d
60bool(false)
61------ stream_truncate bad return: -------
62truncation with new_size=0
63
64Warning: ftruncate(): test_wrapper_bad::stream_truncate did not return a boolean! in %s on line %d
65bool(false)
66