fpassthru_variation.phpt 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. --TEST--
  2. Test fpassthru() function: Variations
  3. --FILE--
  4. <?php
  5. /*
  6. Prototype: int fpassthru ( resource $handle );
  7. Description: Reads to EOF on the given file pointer from the current position
  8. and writes the results to the output buffer.
  9. */
  10. echo "*** Testing fpassthru() function with files ***\n\n";
  11. echo "--- Testing with different offsets ---\n";
  12. $file_name = dirname(__FILE__)."/passthru_variation.tmp";
  13. $file_write = fopen($file_name, "w");
  14. fwrite($file_write, "1234567890abcdefghijklmnopqrstuvwxyz");
  15. fclose($file_write);
  16. $file_read = fopen($file_name, "r");
  17. $offset_arr = array(
  18. /* Positive offsets */
  19. 0,
  20. 1,
  21. 5,
  22. 10,
  23. 20,
  24. 30,
  25. 35,
  26. 36,
  27. 70,
  28. /* Negative offsets, the file pointer should be at the end of file
  29. to get data */
  30. -1,
  31. -5,
  32. -10,
  33. -20,
  34. -35,
  35. -36,
  36. -70
  37. );
  38. for( $i=0; $i<count($offset_arr); $i++ ) {
  39. echo "-- Iteration $i --\n";
  40. if( $offset_arr[$i] >= 0 ) {
  41. fseek($file_read, $offset_arr[$i], SEEK_SET);
  42. var_dump(fpassthru($file_read) );
  43. rewind( $file_read );
  44. }else
  45. {
  46. fseek($file_read, $offset_arr[$i], SEEK_END);
  47. var_dump( fpassthru($file_read) );
  48. rewind( $file_read );
  49. }
  50. }
  51. fclose($file_read); // closing the handle
  52. echo "\n--- Testing with binary mode file ---\n";
  53. /* Opening the file in binary read mode */
  54. $file_read = fopen($file_name, "rb");
  55. fseek($file_read, 12, SEEK_SET);
  56. var_dump(fpassthru($file_read) );
  57. rewind( $file_read );
  58. fclose($file_read);
  59. unlink($file_name);
  60. echo "\n*** Done ***\n";
  61. ?>
  62. --EXPECTF--
  63. *** Testing fpassthru() function with files ***
  64. --- Testing with different offsets ---
  65. -- Iteration 0 --
  66. 1234567890abcdefghijklmnopqrstuvwxyzint(36)
  67. -- Iteration 1 --
  68. 234567890abcdefghijklmnopqrstuvwxyzint(35)
  69. -- Iteration 2 --
  70. 67890abcdefghijklmnopqrstuvwxyzint(31)
  71. -- Iteration 3 --
  72. abcdefghijklmnopqrstuvwxyzint(26)
  73. -- Iteration 4 --
  74. klmnopqrstuvwxyzint(16)
  75. -- Iteration 5 --
  76. uvwxyzint(6)
  77. -- Iteration 6 --
  78. zint(1)
  79. -- Iteration 7 --
  80. int(0)
  81. -- Iteration 8 --
  82. int(0)
  83. -- Iteration 9 --
  84. zint(1)
  85. -- Iteration 10 --
  86. vwxyzint(5)
  87. -- Iteration 11 --
  88. qrstuvwxyzint(10)
  89. -- Iteration 12 --
  90. ghijklmnopqrstuvwxyzint(20)
  91. -- Iteration 13 --
  92. 234567890abcdefghijklmnopqrstuvwxyzint(35)
  93. -- Iteration 14 --
  94. 1234567890abcdefghijklmnopqrstuvwxyzint(36)
  95. -- Iteration 15 --
  96. 1234567890abcdefghijklmnopqrstuvwxyzint(36)
  97. --- Testing with binary mode file ---
  98. cdefghijklmnopqrstuvwxyzint(24)
  99. *** Done ***