1--TEST--
2User-space streams: stream_set_option()
3--FILE--
4<?php
5class test_wrapper_base {
6    public $context;
7    public $return_value;
8    public $expected_option;
9    public $expected_value;
10    function stream_open($path, $mode, $openedpath) {
11        return true;
12    }
13    function stream_eof() {
14        return false;
15    }
16}
17class test_wrapper extends test_wrapper_base {
18    function stream_set_option($option, $value, $ptrparam) {
19        echo "value:\n";
20        var_dump($value);
21        echo "ptrparam:\n";
22        var_dump($ptrparam);
23        echo "\$option === $option === " . $this->expected_option . ":\n";
24        var_dump($option === $this->expected_option);
25        echo "\$value === $value === " . $this->expected_value. ":\n";
26        var_dump($value === $this->expected_value);
27        return $this->return_value;
28    }
29}
30
31function test($name, $fd, $return_value, $func, $args, $expected_option, $expected_value) {
32    echo "\n------ $name: -------\n";
33    $data = stream_get_meta_data($fd);
34    $data['wrapper_data']->return_value = $return_value;
35    $data['wrapper_data']->expected_option = $expected_option;
36    $data['wrapper_data']->expected_value = $expected_value;
37    var_dump(call_user_func_array($func, $args));
38}
39
40var_dump(stream_wrapper_register('test', 'test_wrapper'));
41var_dump(stream_wrapper_register('test2', 'test_wrapper_base'));
42
43$fd = fopen("test://foo","r");
44$fd2 = fopen("test2://foo","r");
45
46test("stream_set_blocking - 1", $fd, true, "stream_set_blocking", array($fd,0), STREAM_OPTION_BLOCKING, 0);
47test("stream_set_blocking - 2", $fd, false, "stream_set_blocking", array($fd,1), STREAM_OPTION_BLOCKING, 1);
48test("stream_set_blocking - 3", $fd, "foo", "stream_set_blocking", array($fd,0), STREAM_OPTION_BLOCKING, 0);
49test("stream_set_blocking - 4", $fd2, true, "stream_set_blocking", array($fd2,1), STREAM_OPTION_BLOCKING, 1);
50
51test("stream_set_write_buffer - 1", $fd, true, "stream_set_write_buffer", array($fd,0), STREAM_OPTION_WRITE_BUFFER, STREAM_BUFFER_NONE);
52test("stream_set_write_buffer - 2", $fd, true, "stream_set_write_buffer", array($fd,4096), STREAM_OPTION_WRITE_BUFFER, STREAM_BUFFER_FULL);
53test("stream_set_write_buffer - 3", $fd, false, "stream_set_write_buffer", array($fd,8192), STREAM_OPTION_WRITE_BUFFER, STREAM_BUFFER_FULL);
54
55test("stream_set_timeout - 1", $fd, true, "stream_set_timeout", array($fd,10,11), STREAM_OPTION_READ_TIMEOUT, 10);
56test("stream_set_timeout - 2", $fd, false, "stream_set_timeout", array($fd,11,12), STREAM_OPTION_READ_TIMEOUT, 11);
57
58?>
59--EXPECTF--
60bool(true)
61bool(true)
62
63------ stream_set_blocking - 1: -------
64value:
65int(0)
66ptrparam:
67NULL
68$option === 1 === 1:
69bool(true)
70$value === 0 === 0:
71bool(true)
72bool(true)
73
74------ stream_set_blocking - 2: -------
75value:
76int(1)
77ptrparam:
78NULL
79$option === 1 === 1:
80bool(true)
81$value === 1 === 1:
82bool(true)
83bool(false)
84
85------ stream_set_blocking - 3: -------
86value:
87int(0)
88ptrparam:
89NULL
90$option === 1 === 1:
91bool(true)
92$value === 0 === 0:
93bool(true)
94bool(true)
95
96------ stream_set_blocking - 4: -------
97
98Warning: stream_set_blocking(): test_wrapper_base::stream_set_option is not implemented! in %s
99bool(false)
100
101------ stream_set_write_buffer - 1: -------
102value:
103int(0)
104ptrparam:
105int(%d)
106$option === 3 === 3:
107bool(true)
108$value === 0 === 0:
109bool(true)
110int(0)
111
112------ stream_set_write_buffer - 2: -------
113value:
114int(2)
115ptrparam:
116int(4096)
117$option === 3 === 3:
118bool(true)
119$value === 2 === 2:
120bool(true)
121int(0)
122
123------ stream_set_write_buffer - 3: -------
124value:
125int(2)
126ptrparam:
127int(8192)
128$option === 3 === 3:
129bool(true)
130$value === 2 === 2:
131bool(true)
132int(-1)
133
134------ stream_set_timeout - 1: -------
135value:
136int(10)
137ptrparam:
138int(11)
139$option === 4 === 4:
140bool(true)
141$value === 10 === 10:
142bool(true)
143bool(true)
144
145------ stream_set_timeout - 2: -------
146value:
147int(11)
148ptrparam:
149int(12)
150$option === 4 === 4:
151bool(true)
152$value === 11 === 11:
153bool(true)
154bool(false)
155