Annotation of embedaddon/php/ext/standard/tests/file/fopencookie.phpt, revision 1.1.1.1

1.1       misho       1: --TEST--
                      2: fopencookie detected and working (or cast mechanism works)
                      3: --FILE--
                      4: <?php
                      5: # vim600:syn=php:
                      6: 
                      7: /* This test verifies that the casting mechanism is working correctly.
                      8:  * On systems with fopencookie, a FILE* is created around the user
                      9:  * stream and that is passed back to the ZE to include.
                     10:  * On systems without fopencookie, the stream is fed into a temporary
                     11:  * file, and that temporary file is passed back to the ZE.
                     12:  * The important thing here is really fopencookie; the glibc people
                     13:  * changed the binary interface, so if haven't detected it correctly,
                     14:  * you can expect this test to segfault.
                     15:  *
                     16:  * FIXME: the test really needs something to fseek(3) on the FILE*
                     17:  * used internally for this test to be really effective.
                     18:  */
                     19: 
                     20: class userstream {
                     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: }
                     81: 
                     82: stream_wrapper_register("cookietest", "userstream");
                     83: 
                     84: include("cookietest://foo");
                     85: 
                     86: ?>
                     87: --EXPECT--
                     88: If you can read this, it worked

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>