1--TEST--
2fopencookie detected and working (or cast mechanism works)
3--FILE--
4<?php
5
6/* This test verifies that the casting mechanism is working correctly.
7 * On systems with fopencookie, a FILE* is created around the user
8 * stream and that is passed back to the ZE to include.
9 * On systems without fopencookie, the stream is fed into a temporary
10 * file, and that temporary file is passed back to the ZE.
11 * The important thing here is really fopencookie; the glibc people
12 * changed the binary interface, so if haven't detected it correctly,
13 * you can expect this test to segfault.
14 *
15 * FIXME: the test really needs something to fseek(3) on the FILE*
16 * used internally for this test to be really effective.
17 */
18
19class userstream {
20    public $context;
21    public $position = 0;
22    public $data = "If you can read this, it worked";
23
24    function stream_open($path, $mode, $options, &$opened_path)
25    {
26        return true;
27    }
28
29    function stream_read($count)
30    {
31        $ret = substr($this->data, $this->position, $count);
32        $this->position += strlen($ret);
33        return $ret;
34    }
35
36    function stream_tell()
37    {
38        return $this->position;
39    }
40
41    function stream_eof()
42    {
43        return $this->position >= strlen($this->data);
44    }
45
46    function stream_seek($offset, $whence)
47    {
48        switch($whence) {
49            case SEEK_SET:
50                if ($offset < strlen($this->data) && $offset >= 0) {
51                    $this->position = $offset;
52                    return true;
53                } else {
54                    return false;
55                }
56                break;
57            case SEEK_CUR:
58                if ($offset >= 0) {
59                    $this->position += $offset;
60                    return true;
61                } else {
62                    return false;
63                }
64                break;
65            case SEEK_END:
66                if (strlen($this->data) + $offset >= 0) {
67                    $this->position = strlen($this->data) + $offset;
68                    return true;
69                } else {
70                    return false;
71                }
72                break;
73            default:
74                return false;
75        }
76    }
77    function stream_stat() {
78        return array('size' => strlen($this->data));
79    }
80    function stream_set_option($option, $arg1, $arg2) {
81        return false;
82    }
83}
84
85stream_wrapper_register("cookietest", "userstream");
86
87include("cookietest://foo");
88
89?>
90--EXPECT--
91If you can read this, it worked
92