Return to strncasecmp_variation10.phpt CVS log | Up to [ELWIX - Embedded LightWeight unIX -] / embedaddon / php / ext / standard / tests / strings |
1.1 misho 1: --TEST-- 2: Test strncasecmp() function : usage variations - unexpected values for 'str1' 3: --FILE-- 4: <?php 5: /* Prototype : int strncasecmp ( string $str1, string $str2, int $len ); 6: * Description: Binary safe case-insensitive string comparison of the first n characters 7: * Source code: Zend/zend_builtin_functions.c 8: */ 9: 10: /* Test strncasecmp() function with the unexpected inputs for 'str1' */ 11: 12: echo "*** Testing strncasecmp() function: with unexpected values for 'str1' ***\n"; 13: /* get an unset variable */ 14: $unset_var = 'string_val'; 15: unset($unset_var); 16: 17: /* get resource handle */ 18: $file_handle = fopen(__FILE__, "r"); 19: 20: /* declaring a class */ 21: class sample { 22: public function __toString() { 23: return "object"; 24: } 25: } 26: 27: 28: /* array with different values */ 29: $values = array ( 30: /* integer values */ 31: 0, 32: 1, 33: 12345, 34: -2345, 35: 36: /* float values */ 37: 10.5, 38: -10.5, 39: 10.5e10, 40: 10.6E-10, 41: .5, 42: 43: /* hexadecimal values */ 44: 0x12, 45: -0x12, 46: 47: /* octal values */ 48: 012, 49: -012, 50: 01.2, 51: 52: /* array values */ 53: array(), 54: array(0), 55: array(1), 56: array(1, 2), 57: array('color' => 'red', 'item' => 'pen'), 58: 59: /* boolean values */ 60: true, 61: false, 62: TRUE, 63: FALSE, 64: 65: /* nulls */ 66: NULL, 67: null, 68: 69: /* empty string */ 70: "", 71: '', 72: 73: /* undefined variable */ 74: @$undefined_var, 75: 76: /* unset variable */ 77: @$unset_var, 78: 79: /* resource */ 80: $file_handle, 81: 82: /* object */ 83: new sample() 84: ); 85: 86: /* loop through each element of the array and check the working of strncasecmp() */ 87: $counter = 1; 88: for($index = 0; $index < count($values); $index ++) { 89: echo "-- Iteration $counter --\n"; 90: $str1 = $values[$index]; 91: $len = strlen($values[$index]) + 1; 92: var_dump( strncasecmp($str1, "string", $len) ); 93: $counter ++; 94: } 95: 96: fclose($file_handle); //closing the file handle 97: 98: echo "*** Done ***\n"; 99: ?> 100: --EXPECTF-- 101: *** Testing strncasecmp() function: with unexpected values for 'str1' *** 102: -- Iteration 1 -- 103: int(-%d) 104: -- Iteration 2 -- 105: int(-%d) 106: -- Iteration 3 -- 107: int(-%d) 108: -- Iteration 4 -- 109: int(-%d) 110: -- Iteration 5 -- 111: int(-%d) 112: -- Iteration 6 -- 113: int(-%d) 114: -- Iteration 7 -- 115: int(-%d) 116: -- Iteration 8 -- 117: int(-%d) 118: -- Iteration 9 -- 119: int(-%d) 120: -- Iteration 10 -- 121: int(-%d) 122: -- Iteration 11 -- 123: int(-%d) 124: -- Iteration 12 -- 125: int(-%d) 126: -- Iteration 13 -- 127: int(-%d) 128: -- Iteration 14 -- 129: int(-%d) 130: -- Iteration 15 -- 131: 132: Warning: strlen() expects parameter 1 to be string, array given in %s on line 88 133: 134: Warning: strncasecmp() expects parameter 1 to be string, array given in %s on line 89 135: NULL 136: -- Iteration 16 -- 137: 138: Warning: strlen() expects parameter 1 to be string, array given in %s on line 88 139: 140: Warning: strncasecmp() expects parameter 1 to be string, array given in %s on line 89 141: NULL 142: -- Iteration 17 -- 143: 144: Warning: strlen() expects parameter 1 to be string, array given in %s on line 88 145: 146: Warning: strncasecmp() expects parameter 1 to be string, array given in %s on line 89 147: NULL 148: -- Iteration 18 -- 149: 150: Warning: strlen() expects parameter 1 to be string, array given in %s on line 88 151: 152: Warning: strncasecmp() expects parameter 1 to be string, array given in %s on line 89 153: NULL 154: -- Iteration 19 -- 155: 156: Warning: strlen() expects parameter 1 to be string, array given in %s on line 88 157: 158: Warning: strncasecmp() expects parameter 1 to be string, array given in %s on line 89 159: NULL 160: -- Iteration 20 -- 161: int(-%d) 162: -- Iteration 21 -- 163: int(-%d) 164: -- Iteration 22 -- 165: int(-%d) 166: -- Iteration 23 -- 167: int(-%d) 168: -- Iteration 24 -- 169: int(-%d) 170: -- Iteration 25 -- 171: int(-%d) 172: -- Iteration 26 -- 173: int(-%d) 174: -- Iteration 27 -- 175: int(-%d) 176: -- Iteration 28 -- 177: int(-%d) 178: -- Iteration 29 -- 179: int(-%d) 180: -- Iteration 30 -- 181: 182: Warning: strlen() expects parameter 1 to be string, resource given in %s on line 88 183: 184: Warning: strncasecmp() expects parameter 1 to be string, resource given in %s on line 89 185: NULL 186: -- Iteration 31 -- 187: int(-%d) 188: *** Done ***