Annotation of embedaddon/php/ext/standard/tests/file/userstreams_002.phpt, revision 1.1.1.1
1.1 misho 1: --TEST--
2: User-space streams: stream_cast()
3: --FILE--
4: <?php
5: class test_wrapper_base {
6: public $return_value;
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_cast($castas) {
16: return $this->return_value;
17: }
18: }
19: function test($name, $fd, $return_value) {
20: echo "\n------ $name: -------\n";
21: $data = stream_get_meta_data($fd);
22: $data['wrapper_data']->return_value = $return_value;
23: $r = array($fd);
24: $w = $e = null;
25: var_dump(stream_select($r, $w, $e, 0) !== false);
26: }
27:
28: var_dump(stream_wrapper_register('test', 'test_wrapper'));
29: var_dump(stream_wrapper_register('test2', 'test_wrapper_base'));
30:
31: $fd = fopen("test://foo","r");
32: $fd2 = fopen("test2://foo","r");
33:
34: test("valid stream", $fd, STDIN);
35: test("stream_cast not implemented", $fd2, null);
36: test("return value is false", $fd, false);
37: test("return value not a stream resource", $fd, "foo");
38: test("return value is stream itself", $fd, $fd);
39: test("return value cannot be casted", $fd, $fd2);
40:
41: ?>
42: --EXPECTF--
43: bool(true)
44: bool(true)
45:
46: ------ valid stream: -------
47: bool(true)
48:
49: ------ stream_cast not implemented: -------
50:
51: Warning: stream_select(): test_wrapper_base::stream_cast is not implemented! in %s
52:
53: Warning: stream_select(): cannot represent a stream of type user-space as a select()able descriptor in %s
54:
55: Warning: stream_select(): No stream arrays were passed in %s
56: bool(false)
57:
58: ------ return value is false: -------
59:
60: Warning: stream_select(): cannot represent a stream of type user-space as a select()able descriptor in %s
61:
62: Warning: stream_select(): No stream arrays were passed in %s
63: bool(false)
64:
65: ------ return value not a stream resource: -------
66:
67: Warning: stream_select(): supplied argument is not a valid stream resource in %s
68:
69: Warning: stream_select(): test_wrapper::stream_cast must return a stream resource in %s
70:
71: Warning: stream_select(): cannot represent a stream of type user-space as a select()able descriptor in %s
72:
73: Warning: stream_select(): No stream arrays were passed in %s
74: bool(false)
75:
76: ------ return value is stream itself: -------
77:
78: Warning: stream_select(): test_wrapper::stream_cast must not return itself in %s
79:
80: Warning: stream_select(): cannot represent a stream of type user-space as a select()able descriptor in %s
81:
82: Warning: stream_select(): No stream arrays were passed in %s
83: bool(false)
84:
85: ------ return value cannot be casted: -------
86:
87: Warning: stream_select(): test_wrapper_base::stream_cast is not implemented! in %s
88:
89: Warning: stream_select(): cannot represent a stream of type user-space as a select()able descriptor in %s
90:
91: Warning: stream_select(): cannot represent a stream of type user-space as a select()able descriptor in %s
92:
93: Warning: stream_select(): No stream arrays were passed in %s
94: bool(false)
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>