Annotation of embedaddon/php/ext/standard/tests/strings/strncasecmp_variation5.phpt, revision 1.1.1.1

1.1       misho       1: --TEST--
                      2: Test strncasecmp() function : usage variations - unexpected values for 'len'
                      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 values, and giving the same strings for 'str1' and 'str2' */
                     11: 
                     12: echo "*** Test strncasecmp() function: unexpected values for 'len' ***\n";
                     13: 
                     14: /* definition of required variables */
                     15: $str1 = "Hello, World\n";
                     16: $str2 = "Hello, World\n";
                     17: 
                     18: /* get an unset variable */
                     19: $unset_var = 'string_val';
                     20: unset($unset_var);
                     21: 
                     22: /* get resource handle */
                     23: $file_handle = fopen(__FILE__, "r");
                     24: 
                     25: /* declaring a class */
                     26: class sample  {
                     27:   public function __toString() {
                     28:   return "object";
                     29:   }
                     30: }
                     31: 
                     32: 
                     33: /* array with different values */
                     34: $lengths =  array (
                     35: 
                     36:   /* float values */
                     37:   10.5,
                     38:   10.5e10,
                     39:   10.6E-10,
                     40:   .5,
                     41: 
                     42:   /* hexadecimal values */
                     43:   0x12,
                     44: 
                     45:   /* octal values */
                     46:   012,
                     47:   01.2,
                     48: 
                     49:   /* array values */
                     50:   array(),
                     51:   array(0),
                     52:   array(1),
                     53:   array(1, 2),
                     54:   array('color' => 'red', 'item' => 'pen'),
                     55: 
                     56:   /* boolean values */
                     57:   true,
                     58:   false,
                     59:   TRUE,
                     60:   FALSE,
                     61: 
                     62:   /* nulls */
                     63:   NULL,
                     64:   null,
                     65: 
                     66:   /* empty string */
                     67:   "",
                     68:   '',
                     69: 
                     70:   /* undefined variable */
                     71:   @$undefined_var,
                     72: 
                     73:   /* unset variable */
                     74:   @$unset_var,
                     75: 
                     76:   /* resource */
                     77:   $file_handle,
                     78: 
                     79:   /* object */
                     80:   new sample()
                     81: );
                     82: 
                     83: /* loop through each element of the array and check the working of strncasecmp() */
                     84: $counter = 1;
                     85: for($index = 0; $index < count($lengths); $index ++) {
                     86:   $len = $lengths[$index];
                     87:   echo "-- Iteration $counter --\n";
                     88:   var_dump( strncasecmp($str1, $str2, $len) );
                     89:   $counter ++;
                     90: }
                     91: fclose($file_handle);
                     92: 
                     93: echo "*** Done ***\n";
                     94: ?>
                     95: --EXPECTF--
                     96: *** Test strncasecmp() function: unexpected values for 'len' ***
                     97: -- Iteration 1 --
                     98: int(0)
                     99: -- Iteration 2 --
                    100: int(0)
                    101: -- Iteration 3 --
                    102: int(0)
                    103: -- Iteration 4 --
                    104: int(0)
                    105: -- Iteration 5 --
                    106: int(0)
                    107: -- Iteration 6 --
                    108: int(0)
                    109: -- Iteration 7 --
                    110: int(0)
                    111: -- Iteration 8 --
                    112: 
                    113: Warning: strncasecmp() expects parameter 3 to be long, array given in %s on line %d
                    114: NULL
                    115: -- Iteration 9 --
                    116: 
                    117: Warning: strncasecmp() expects parameter 3 to be long, array given in %s on line %d
                    118: NULL
                    119: -- Iteration 10 --
                    120: 
                    121: Warning: strncasecmp() expects parameter 3 to be long, array given in %s on line %d
                    122: NULL
                    123: -- Iteration 11 --
                    124: 
                    125: Warning: strncasecmp() expects parameter 3 to be long, array given in %s on line %d
                    126: NULL
                    127: -- Iteration 12 --
                    128: 
                    129: Warning: strncasecmp() expects parameter 3 to be long, array given in %s on line %d
                    130: NULL
                    131: -- Iteration 13 --
                    132: int(0)
                    133: -- Iteration 14 --
                    134: int(0)
                    135: -- Iteration 15 --
                    136: int(0)
                    137: -- Iteration 16 --
                    138: int(0)
                    139: -- Iteration 17 --
                    140: int(0)
                    141: -- Iteration 18 --
                    142: int(0)
                    143: -- Iteration 19 --
                    144: 
                    145: Warning: strncasecmp() expects parameter 3 to be long, string given in %s on line %d
                    146: NULL
                    147: -- Iteration 20 --
                    148: 
                    149: Warning: strncasecmp() expects parameter 3 to be long, string given in %s on line %d
                    150: NULL
                    151: -- Iteration 21 --
                    152: int(0)
                    153: -- Iteration 22 --
                    154: int(0)
                    155: -- Iteration 23 --
                    156: 
                    157: Warning: strncasecmp() expects parameter 3 to be long, resource given in %s on line %d
                    158: NULL
                    159: -- Iteration 24 --
                    160: 
                    161: Warning: strncasecmp() expects parameter 3 to be long, object given in %s on line %d
                    162: NULL
                    163: *** Done ***

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