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