fopencookie.phpt 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. --TEST--
  2. fopencookie detected and working (or cast mechanism works)
  3. --FILE--
  4. <?php
  5. # vim600:syn=php:
  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. class userstream {
  19. public $position = 0;
  20. public $data = "If you can read this, it worked";
  21. function stream_open($path, $mode, $options, &$opened_path)
  22. {
  23. return true;
  24. }
  25. function stream_read($count)
  26. {
  27. $ret = substr($this->data, $this->position, $count);
  28. $this->position += strlen($ret);
  29. return $ret;
  30. }
  31. function stream_tell()
  32. {
  33. return $this->position;
  34. }
  35. function stream_eof()
  36. {
  37. return $this->position >= strlen($this->data);
  38. }
  39. function stream_seek($offset, $whence)
  40. {
  41. switch($whence) {
  42. case SEEK_SET:
  43. if ($offset < strlen($this->data) && $offset >= 0) {
  44. $this->position = $offset;
  45. return true;
  46. } else {
  47. return false;
  48. }
  49. break;
  50. case SEEK_CUR:
  51. if ($offset >= 0) {
  52. $this->position += $offset;
  53. return true;
  54. } else {
  55. return false;
  56. }
  57. break;
  58. case SEEK_END:
  59. if (strlen($this->data) + $offset >= 0) {
  60. $this->position = strlen($this->data) + $offset;
  61. return true;
  62. } else {
  63. return false;
  64. }
  65. break;
  66. default:
  67. return false;
  68. }
  69. }
  70. function stream_stat() {
  71. return array('size' => strlen($this->data));
  72. }
  73. }
  74. stream_wrapper_register("cookietest", "userstream");
  75. include("cookietest://foo");
  76. ?>
  77. --EXPECT--
  78. If you can read this, it worked