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

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

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