Annotation of embedaddon/php/ext/standard/tests/file/feof_basic.phpt, revision 1.1.1.1
1.1 misho 1: --TEST--
2: Test feof() function : basic functionality
3: --CREDITS--
4: Dave Kelsey <d_kelsey@uk.ibm.com>
5: --FILE--
6: <?php
7: /* Prototype : proto bool feof(resource fp)
8: * Description: Test for end-of-file on a file pointer
9: * Source code: ext/standard/file.c
10: * Alias to functions: gzeof
11: */
12:
13: echo "*** Testing feof() : basic functionality ***\n";
14: $tmpFile1 = __FILE__.".tmp1";
15: $h = fopen($tmpFile1, 'wb');
16: $count = 10;
17: for ($i = 1; $i <= $count; $i++) {
18: fwrite($h, "some data $i\n");
19: }
20: fclose($h);
21:
22: echo "\n*** testing reading complete file using feof to stop ***\n";
23: $h = fopen($tmpFile1, 'rb');
24:
25: //feof is not set to true until you try to read past the end of file.
26: //so fgets will be called even if we are at the end of the file on
27: //last time to set the eof flag but it will fail to read.
28: $lastline = "";
29: while (!feof($h)) {
30: $previousLine = $lastline;
31: $lastline = fgets($h);
32: }
33: echo $previousLine;
34: var_dump($lastline); // this should be false
35: fclose($h);
36:
37: $tmpFile2 = __FILE__.".tmp2";
38: $h = fopen($tmpFile2, 'wb+');
39: $count = 10;
40: echo "*** writing $count lines, testing feof ***\n";
41: for ($i = 1; $i <=$count; $i++) {
42: fwrite($h, "some data $i\n");
43: var_dump(feof($h));
44: }
45:
46: echo "*** testing feof on unclosed file after a read ***\n";
47:
48: fread($h, 100);
49: var_dump(feof($h));
50:
51: $eofPointer = ftell($h);
52:
53: echo "*** testing feof after a seek to near the beginning ***\n";
54: fseek($h, 20, SEEK_SET);
55: var_dump(feof($h));
56:
57: echo "*** testing feof after a seek to end ***\n";
58: fseek($h, $eofPointer, SEEK_SET);
59: var_dump(feof($h));
60:
61: echo "*** testing feof after a seek passed the end ***\n";
62: fseek($h, $eofPointer + 1000, SEEK_SET);
63: var_dump(feof($h));
64:
65: echo "*** closing file, testing eof ***\n";
66: fclose($h);
67: feof($h);
68: unlink($tmpFile1);
69: unlink($tmpFile2);
70:
71: echo "Done";
72: ?>
73: --EXPECTF--
74: *** Testing feof() : basic functionality ***
75:
76: *** testing reading complete file using feof to stop ***
77: some data 10
78: bool(false)
79: *** writing 10 lines, testing feof ***
80: bool(false)
81: bool(false)
82: bool(false)
83: bool(false)
84: bool(false)
85: bool(false)
86: bool(false)
87: bool(false)
88: bool(false)
89: bool(false)
90: *** testing feof on unclosed file after a read ***
91: bool(true)
92: *** testing feof after a seek to near the beginning ***
93: bool(false)
94: *** testing feof after a seek to end ***
95: bool(false)
96: *** testing feof after a seek passed the end ***
97: bool(false)
98: *** closing file, testing eof ***
99:
100: Warning: feof(): %d is not a valid stream resource in %s on line %d
101: Done
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>