userstreams_002.phpt 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. var_dump(stream_wrapper_register('test', 'test_wrapper'));
  28. var_dump(stream_wrapper_register('test2', 'test_wrapper_base'));
  29. $fd = fopen("test://foo","r");
  30. $fd2 = fopen("test2://foo","r");
  31. test("valid stream", $fd, STDIN);
  32. test("stream_cast not implemented", $fd2, null);
  33. test("return value is false", $fd, false);
  34. test("return value not a stream resource", $fd, "foo");
  35. test("return value is stream itself", $fd, $fd);
  36. test("return value cannot be casted", $fd, $fd2);
  37. ?>
  38. --EXPECTF--
  39. bool(true)
  40. bool(true)
  41. ------ valid stream: -------
  42. bool(true)
  43. ------ stream_cast not implemented: -------
  44. Warning: stream_select(): test_wrapper_base::stream_cast is not implemented! in %s
  45. Warning: stream_select(): cannot represent a stream of type user-space as a select()able descriptor in %s
  46. Warning: stream_select(): No stream arrays were passed in %s
  47. bool(false)
  48. ------ return value is false: -------
  49. Warning: stream_select(): cannot represent a stream of type user-space as a select()able descriptor in %s
  50. Warning: stream_select(): No stream arrays were passed in %s
  51. bool(false)
  52. ------ return value not a stream resource: -------
  53. Warning: stream_select(): supplied argument is not a valid stream resource in %s
  54. Warning: stream_select(): test_wrapper::stream_cast must return a stream resource in %s
  55. Warning: stream_select(): cannot represent a stream of type user-space as a select()able descriptor in %s
  56. Warning: stream_select(): No stream arrays were passed in %s
  57. bool(false)
  58. ------ return value is stream itself: -------
  59. Warning: stream_select(): test_wrapper::stream_cast must not return itself in %s
  60. Warning: stream_select(): cannot represent a stream of type user-space as a select()able descriptor in %s
  61. Warning: stream_select(): No stream arrays were passed in %s
  62. bool(false)
  63. ------ return value cannot be casted: -------
  64. Warning: stream_select(): test_wrapper_base::stream_cast is not implemented! in %s
  65. Warning: stream_select(): cannot represent a stream of type user-space as a select()able descriptor in %s
  66. Warning: stream_select(): cannot represent a stream of type user-space as a select()able descriptor in %s
  67. Warning: stream_select(): No stream arrays were passed in %s
  68. bool(false)