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

1.1       misho       1: --TEST--
                      2: Test fseek() function : variation functionality beyond file boundaries 
                      3: --CREDITS--
                      4: Dave Kelsey <d_kelsey@uk.ibm.com>
                      5: --FILE--
                      6: <?php
                      7: /* Prototype  : proto int fseek(resource fp, int offset [, int whence])
                      8:  * Description: Seek on a file pointer 
                      9:  * Source code: ext/standard/file.c
                     10:  * Alias to functions: gzseek
                     11:  */
                     12: 
                     13: echo "*** Testing fseek() : variation - beyond file boundaries ***\n";
                     14: 
                     15: $outputfile = __FILE__.".tmp";
                     16: 
                     17: $h = fopen($outputfile, "wb+");
                     18: for ($i = 1; $i < 10; $i++) {
                     19:    fwrite($h, chr(0x30 + $i));
                     20: }
                     21: 
                     22: echo "--- fseek beyond start of file ---\n";
                     23: var_dump(fseek($h, -4, SEEK_SET));
                     24: echo "after -4 seek: ".bin2hex(fread($h,1))."\n";
                     25: var_dump(fseek($h, -1, SEEK_CUR));
                     26: echo "after seek back 1: ".bin2hex(fread($h,1))."\n";
                     27: var_dump(fseek($h, -20, SEEK_CUR));
                     28: echo "after seek back 20: ".bin2hex(fread($h,1))."\n";
                     29: 
                     30: echo "--- fseek beyond end of file ---\n";
                     31: var_dump(fseek($h, 16, SEEK_SET));
                     32: fwrite($h, b"end");
                     33: fseek($h ,0, SEEK_SET);
                     34: $data = fread($h, 4096);
                     35: echo bin2hex($data)."\n";
                     36: 
                     37: fclose($h);
                     38: unlink($outputfile);
                     39: 
                     40: echo "Done";
                     41: ?>
                     42: --EXPECTF--
                     43: *** Testing fseek() : variation - beyond file boundaries ***
                     44: --- fseek beyond start of file ---
                     45: int(-1)
                     46: after -4 seek: 
                     47: int(0)
                     48: after seek back 1: 39
                     49: int(-1)
                     50: after seek back 20: 
                     51: --- fseek beyond end of file ---
                     52: int(0)
                     53: 31323334353637383900000000000000656e64
                     54: Done

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