Annotation of embedaddon/php/ext/standard/tests/strings/sha1_file.phpt, revision 1.1.1.2
1.1 misho 1: --TEST--
2: Test sha1_file() function with ASCII output and raw binary output. Based on ext/standard/tests/strings/md5_file.phpt
3: --FILE--
4: <?php
5:
6: /* Prototype: string sha1_file( string filename[, bool raw_output] )
7: * Description: Calculate the sha1 hash of a file
8: */
9:
10: echo "*** Testing sha1_file() : basic functionality ***\n";
11:
12: /* Creating an empty file */
13: if (($handle = fopen( "EmptyFile.txt", "w+")) == FALSE)
14: return false;
15:
16: /* Creating a data file */
17: if (($handle2 = fopen( "DataFile.txt", "w+")) == FALSE)
18: return false;
19:
20: /* Writing into file */
21: $filename = "DataFile.txt";
22: $content = b"Add this to the file\n";
23: if (is_writable($filename)) {
24: if (fwrite($handle2, $content) === FALSE) {
25: echo "Cannot write to file ($filename)";
26: exit;
27: }
28: }
29:
30: // close the files
31: fclose($handle);
32: fclose($handle2);
33:
34: /* Testing error conditions */
35: echo "\n*** Testing for error conditions ***\n";
36:
37: echo "\n-- No filename --\n";
38: var_dump( sha1_file("") );
39:
40: echo "\n-- invalid filename --\n";
1.1.1.2 ! misho 41: var_dump( sha1_file("rewncwYcn89q") );
1.1 misho 42:
43: echo "\n-- Scalar value as filename --\n";
44: var_dump( sha1_file(12) );
45:
46: echo "\n-- NULL as filename --\n";
47: var_dump( sha1_file(NULL) );
48:
49: echo "\n-- Zero arguments --\n";
50: var_dump ( sha1_file() );
51:
52: echo "\n-- More than valid number of arguments ( valid is 2) --\n";
53: var_dump ( sha1_file("EmptyFile.txt", true, NULL) );
54:
55: echo "\n-- Hexadecimal Output for Empty file as Argument --\n";
56: var_dump( sha1_file("EmptyFile.txt") );
57:
58: echo "\n-- Raw Binary Output for Empty file as Argument --\n";
59: var_dump( bin2hex(sha1_file("EmptyFile.txt", true)));
60:
61: echo "\n-- Hexadecimal Output for a valid file with some contents --\n";
62: var_dump( sha1_file("DataFile.txt") );
63:
64: echo "\n-- Raw Binary Output for a valid file with some contents --\n";
65: var_dump ( bin2hex(sha1_file("DataFile.txt", true)));
66:
67: // remove temp files
68: unlink("DataFile.txt");
69: unlink("EmptyFile.txt");
70:
71: ?>
72: ===DONE===
73: --EXPECTF--
74: *** Testing sha1_file() : basic functionality ***
75:
76: *** Testing for error conditions ***
77:
78: -- No filename --
79:
80: Warning: sha1_file(): Filename cannot be empty in %s on line %d
81: bool(false)
82:
83: -- invalid filename --
84:
1.1.1.2 ! misho 85: Warning: sha1_file(rewncwYcn89q): failed to open stream: No such file or directory in %s on line %d
1.1 misho 86: bool(false)
87:
88: -- Scalar value as filename --
89:
90: Warning: sha1_file(12): failed to open stream: No such file or directory in %s on line %d
91: bool(false)
92:
93: -- NULL as filename --
94:
95: Warning: sha1_file(): Filename cannot be empty in %s on line %d
96: bool(false)
97:
98: -- Zero arguments --
99:
100: Warning: sha1_file() expects at least 1 parameter, 0 given in %s on line %d
101: NULL
102:
103: -- More than valid number of arguments ( valid is 2) --
104:
105: Warning: sha1_file() expects at most 2 parameters, 3 given in %s on line %d
106: NULL
107:
108: -- Hexadecimal Output for Empty file as Argument --
109: string(40) "da39a3ee5e6b4b0d3255bfef95601890afd80709"
110:
111: -- Raw Binary Output for Empty file as Argument --
112: string(40) "da39a3ee5e6b4b0d3255bfef95601890afd80709"
113:
114: -- Hexadecimal Output for a valid file with some contents --
115: string(40) "d16a568ab98233deff7ec8b1668eb4b3d9e53fee"
116:
117: -- Raw Binary Output for a valid file with some contents --
118: string(40) "d16a568ab98233deff7ec8b1668eb4b3d9e53fee"
119: ===DONE===
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>