]> granicus.if.org Git - php/commitdiff
New testcases for strncasecmp()
authorRaghubansh Kumar <kraghuba@php.net>
Fri, 14 Sep 2007 19:02:07 +0000 (19:02 +0000)
committerRaghubansh Kumar <kraghuba@php.net>
Fri, 14 Sep 2007 19:02:07 +0000 (19:02 +0000)
14 files changed:
ext/standard/tests/strings/stripos_basic.phpt [new file with mode: 0644]
ext/standard/tests/strings/strncasecmp_basic.phpt [new file with mode: 0644]
ext/standard/tests/strings/strncasecmp_error.phpt [new file with mode: 0644]
ext/standard/tests/strings/strncasecmp_variation1.phpt [new file with mode: 0644]
ext/standard/tests/strings/strncasecmp_variation10.phpt [new file with mode: 0644]
ext/standard/tests/strings/strncasecmp_variation11.phpt [new file with mode: 0644]
ext/standard/tests/strings/strncasecmp_variation2.phpt [new file with mode: 0644]
ext/standard/tests/strings/strncasecmp_variation3.phpt [new file with mode: 0644]
ext/standard/tests/strings/strncasecmp_variation4.phpt [new file with mode: 0644]
ext/standard/tests/strings/strncasecmp_variation5.phpt [new file with mode: 0644]
ext/standard/tests/strings/strncasecmp_variation6.phpt [new file with mode: 0644]
ext/standard/tests/strings/strncasecmp_variation7.phpt [new file with mode: 0644]
ext/standard/tests/strings/strncasecmp_variation8.phpt [new file with mode: 0644]
ext/standard/tests/strings/strncasecmp_variation9.phpt [new file with mode: 0644]

diff --git a/ext/standard/tests/strings/stripos_basic.phpt b/ext/standard/tests/strings/stripos_basic.phpt
new file mode 100644 (file)
index 0000000..8bc44e7
--- /dev/null
@@ -0,0 +1,27 @@
+--TEST--
+Test stripos() function : basic functionality 
+--FILE--
+<?php
+/* Prototype  : int stripos ( string $haystack, string $needle [, int $offset] );
+ * Description: Find position of first occurrence of a case-insensitive string
+ * Source code: ext/standard/string.c
+*/
+
+/* Test stripos() function by providing all the parameters */
+
+echo "*** Test stripos() : basic functionality ***\n";
+/* Initialize all required variables */
+$haystack = 'string';
+$needle = 'ring';
+$offset = 3;
+/* Calling stripos() with default arguments */
+var_dump( stripos($haystack, $needle) );
+/* Calling stripos() with all arguments */
+var_dump( stripos($haystack, $needle, $offset) );
+echo "*** Done ***\n";
+?>
+--EXPECTF--
+*** Test stripos() : basic functionality ***
+int(2)
+bool(false)
+*** Done ***
diff --git a/ext/standard/tests/strings/strncasecmp_basic.phpt b/ext/standard/tests/strings/strncasecmp_basic.phpt
new file mode 100644 (file)
index 0000000..34a1b08
--- /dev/null
@@ -0,0 +1,46 @@
+--TEST--
+Test strncasecmp() function : basic functionality 
+--FILE--
+<?php
+/* Prototype  : int strncasecmp ( string $str1, string $str2, int $len );
+ * Description: Binary safe case-insensitive string comparison of the first n characters
+ * Source code: Zend/zend_builtin_functions.c
+*/
+
+echo "*** Testing strncasecmp() function: basic functionality ***\n";
+
+echo "-- Testing strncasecmp() with single quoted string --\n";
+var_dump( strncasecmp('Hello', 'Hello', 5) );  //expected: int(0)
+var_dump( strncasecmp('Hello', 'Hi', 5) );  //expected: value < 0
+var_dump( strncasecmp('Hi', 'Hello', 5) );  //expected: value > 0
+
+echo "-- Testing strncasecmp() with double quoted string --\n";
+var_dump( strncasecmp("Hello", "Hello", 5) );  //expected: int(0)
+var_dump( strncasecmp("Hello", "Hi", 5) );  //expected: value < 0
+var_dump( strncasecmp("Hi", "Hello", 5) );  //expected: value > 0
+
+echo "-- Testing strncasecmp() with here-doc string --\n";
+$str = <<<HEREDOC
+Hello
+HEREDOC;
+var_dump( strncasecmp($str, "Hello", 5) );  //expected: int(0)
+var_dump( strncasecmp($str, "Hi", 5) );  //expected: value < 0
+var_dump( strncasecmp("Hi", $str, 5) );  //expected: value > 0
+
+echo "*** Done ***";
+?>
+--EXPECTREGEX--
+\*\*\* Testing strncasecmp\(\) function: basic functionality \*\*\*
+-- Testing strncasecmp\(\) with single quoted string --
+int\(0\)
+int\(-[1-9][0-9]*\)
+int\([1-9][0-9]*\)
+-- Testing strncasecmp\(\) with double quoted string --
+int\(0\)
+int\(-[1-9][0-9]*\)
+int\([1-9][0-9]*\)
+-- Testing strncasecmp\(\) with here-doc string --
+int\(0\)
+int\(-[1-9][0-9]*\)
+int\([1-9][0-9]*\)
+\*\*\* Done \*\*\*
diff --git a/ext/standard/tests/strings/strncasecmp_error.phpt b/ext/standard/tests/strings/strncasecmp_error.phpt
new file mode 100644 (file)
index 0000000..7282ea9
--- /dev/null
@@ -0,0 +1,52 @@
+--TEST--
+Test strncasecmp() function : error conditions 
+--FILE--
+<?php
+/* Prototype  : int strncasecmp ( string $str1, string $str2, int $len );
+ * Description: Binary safe case-insensitive string comparison of the first n characters
+ * Source code: Zend/zend_builtin_functions.c
+*/
+
+echo "*** Testing strncasecmp() function: error conditions ***\n";
+$str1 = 'string_val';
+$str2 = 'string_val';
+$len = 10;
+$extra_arg = 10;
+
+echo "\n-- Testing strncasecmp() function with Zero arguments --";
+var_dump( strncasecmp() );
+
+echo "\n-- Testing strncasecmp() function with less than expected number of arguments --";
+var_dump( strncasecmp($str1) );
+var_dump( strncasecmp($str1, $str2) );
+
+echo "\n-- Testing strncasecmp() function with more than expected number of arguments --";
+var_dump( strncasecmp($str1, $str2, $len, $extra_arg) );
+
+echo "\n-- Testing strncasecmp() function with invalid argument --";
+$len = -10;
+var_dump( strncasecmp($str1, $str2, $len) );
+echo "*** Done ***\n";
+?>
+--EXPECTF--
+*** Testing strncasecmp() function: error conditions ***
+
+-- Testing strncasecmp() function with Zero arguments --
+Warning: Wrong parameter count for strncasecmp() in %s on line %d
+NULL
+
+-- Testing strncasecmp() function with less than expected number of arguments --
+Warning: Wrong parameter count for strncasecmp() in %s on line %d
+NULL
+
+Warning: Wrong parameter count for strncasecmp() in %s on line %d
+NULL
+
+-- Testing strncasecmp() function with more than expected number of arguments --
+Warning: Wrong parameter count for strncasecmp() in %s on line %d
+NULL
+
+-- Testing strncasecmp() function with invalid argument --
+Warning: Length must be greater than or equal to 0 in %s on line %d
+bool(false)
+*** Done ***
diff --git a/ext/standard/tests/strings/strncasecmp_variation1.phpt b/ext/standard/tests/strings/strncasecmp_variation1.phpt
new file mode 100644 (file)
index 0000000..bcc6ad3
--- /dev/null
@@ -0,0 +1,135 @@
+--TEST--
+Test strncasecmp() function: usage variations - case-sensitivity
+--FILE--
+<?php
+/* Prototype  : int strncasecmp ( string $str1, string $str2, int $len );
+ * Description: Binary safe case-insensitive string comparison of the first n characters
+ * Source code: Zend/zend_builtin_functions.c
+*/
+
+/* Test strncasecmp() function with upper-case and lower-case alphabets as inputs for 'str1' and 'str2' */
+
+echo "*** Test strncasecmp() function: with alphabets ***\n";
+echo "-- Passing upper-case letters for 'str1' --\n";
+for($ASCII = 65; $ASCII <= 90; $ASCII++) {
+  var_dump( strncasecmp( chr($ASCII), chr($ASCII), 1 ) );  //comparing uppercase letter with corresponding uppercase letter; exp: int(0)
+  var_dump( strncasecmp( chr($ASCII), chr($ASCII + 32), 1 ) );  //comparing uppercase letter with corresponding lowercase letter; exp: int(0)
+}
+
+echo "\n-- Passing lower-case letters for 'str1' --\n";
+for($ASCII = 97; $ASCII <= 122; $ASCII++) {
+  var_dump( strncasecmp( chr($ASCII), chr($ASCII), 1 ) );  //comparing lowercase letter with corresponding lowercase letter; exp: int(0)
+  var_dump( strncasecmp( chr($ASCII), chr($ASCII - 32), 1 ) );  //comparing lowercase letter with corresponding uppercase letter; exp: int(0)
+}
+echo "*** Done ***\n";
+?>
+--EXPECTF--
+*** Test strncasecmp() function: with alphabets ***
+-- Passing upper-case letters for 'str1' --
+int(0)
+int(0)
+int(0)
+int(0)
+int(0)
+int(0)
+int(0)
+int(0)
+int(0)
+int(0)
+int(0)
+int(0)
+int(0)
+int(0)
+int(0)
+int(0)
+int(0)
+int(0)
+int(0)
+int(0)
+int(0)
+int(0)
+int(0)
+int(0)
+int(0)
+int(0)
+int(0)
+int(0)
+int(0)
+int(0)
+int(0)
+int(0)
+int(0)
+int(0)
+int(0)
+int(0)
+int(0)
+int(0)
+int(0)
+int(0)
+int(0)
+int(0)
+int(0)
+int(0)
+int(0)
+int(0)
+int(0)
+int(0)
+int(0)
+int(0)
+int(0)
+int(0)
+
+-- Passing lower-case letters for 'str1' --
+int(0)
+int(0)
+int(0)
+int(0)
+int(0)
+int(0)
+int(0)
+int(0)
+int(0)
+int(0)
+int(0)
+int(0)
+int(0)
+int(0)
+int(0)
+int(0)
+int(0)
+int(0)
+int(0)
+int(0)
+int(0)
+int(0)
+int(0)
+int(0)
+int(0)
+int(0)
+int(0)
+int(0)
+int(0)
+int(0)
+int(0)
+int(0)
+int(0)
+int(0)
+int(0)
+int(0)
+int(0)
+int(0)
+int(0)
+int(0)
+int(0)
+int(0)
+int(0)
+int(0)
+int(0)
+int(0)
+int(0)
+int(0)
+int(0)
+int(0)
+int(0)
+int(0)
+*** Done ***
diff --git a/ext/standard/tests/strings/strncasecmp_variation10.phpt b/ext/standard/tests/strings/strncasecmp_variation10.phpt
new file mode 100644 (file)
index 0000000..e06b2b2
--- /dev/null
@@ -0,0 +1,184 @@
+--TEST--
+Test strncasecmp() function : usage variations - unexpected values for 'str1'
+--FILE--
+<?php
+/* Prototype  : int strncasecmp ( string $str1, string $str2, int $len );
+ * Description: Binary safe case-insensitive string comparison of the first n characters
+ * Source code: Zend/zend_builtin_functions.c
+*/
+
+/* Test strncasecmp() function with the unexpected inputs for 'str1' */
+
+echo "*** Testing strncasecmp() function: with unexpected values for 'str1' ***\n";
+/* get an unset variable */
+$unset_var = 'string_val';
+unset($unset_var);
+
+/* get resource handle */
+$file_handle = fopen(__FILE__, "r");
+
+/* declaring a class */
+class sample  {
+  public function __toString() {
+  return "object";
+  }
+}
+
+
+/* array with different values */
+$values =  array (
+  /* integer values */
+  0,
+  1,
+  12345,
+  -2345,
+  /* float values */
+  10.5,
+  -10.5,
+  10.5e10,
+  10.6E-10,
+  .5,
+
+  /* hexadecimal values */
+  0x12,
+  -0x12,
+  
+  /* octal values */
+  012,
+  -012,
+  01.2,
+
+  /* array values */
+  array(),
+  array(0),
+  array(1),
+  array(1, 2),
+  array('color' => 'red', 'item' => 'pen'),
+
+  /* boolean values */
+  true,
+  false,
+  TRUE,
+  FALSE,
+
+  /* nulls */
+  NULL,
+  null,
+
+  /* empty string */
+  "",
+  '',
+
+  /* undefined variable */
+  @$undefined_var,
+
+  /* unset variable */
+  @$unset_var,
+
+  /* resource */
+  $file_handle,  
+
+  /* object */
+  new sample()
+);
+
+/* loop through each element of the array and check the working of strncasecmp() */
+$counter = 1;
+for($index = 0; $index < count($values); $index ++) {
+  echo "-- Iteration $counter --\n";
+  $str1 = $values[$index];
+  $len = strlen($values[$index]) + 1;
+  var_dump( strncasecmp($str1, "string", $len) );
+  $counter ++;
+}
+
+fclose($file_handle);  //closing the file handle
+
+echo "*** Done ***\n";
+?>
+--EXPECTF--
+*** Testing strncasecmp() function: with unexpected values for 'str1' ***
+-- Iteration 1 --
+int(-%d)
+-- Iteration 2 --
+int(-%d)
+-- Iteration 3 --
+int(-%d)
+-- Iteration 4 --
+int(-%d)
+-- Iteration 5 --
+int(-%d)
+-- Iteration 6 --
+int(-%d)
+-- Iteration 7 --
+int(-%d)
+-- Iteration 8 --
+int(-%d)
+-- Iteration 9 --
+int(-%d)
+-- Iteration 10 --
+int(-%d)
+-- Iteration 11 --
+int(-%d)
+-- Iteration 12 --
+int(-%d)
+-- Iteration 13 --
+int(-%d)
+-- Iteration 14 --
+int(-%d)
+-- Iteration 15 --
+
+Notice: Array to string conversion in %s on line 88
+
+Notice: Array to string conversion in %s on line 89
+int(-%d)
+-- Iteration 16 --
+
+Notice: Array to string conversion in %s on line 88
+
+Notice: Array to string conversion in %s on line 89
+int(-%d)
+-- Iteration 17 --
+
+Notice: Array to string conversion in %s on line 88
+
+Notice: Array to string conversion in %s on line 89
+int(-%d)
+-- Iteration 18 --
+
+Notice: Array to string conversion in %s on line 88
+
+Notice: Array to string conversion in %s on line 89
+int(-%d)
+-- Iteration 19 --
+
+Notice: Array to string conversion in %s on line 88
+
+Notice: Array to string conversion in %s on line 89
+int(-%d)
+-- Iteration 20 --
+int(-%d)
+-- Iteration 21 --
+int(-%d)
+-- Iteration 22 --
+int(-%d)
+-- Iteration 23 --
+int(-%d)
+-- Iteration 24 --
+int(-%d)
+-- Iteration 25 --
+int(-%d)
+-- Iteration 26 --
+int(-%d)
+-- Iteration 27 --
+int(-%d)
+-- Iteration 28 --
+int(-%d)
+-- Iteration 29 --
+int(-%d)
+-- Iteration 30 --
+int(-%d)
+-- Iteration 31 --
+int(-%d)
+*** Done ***
diff --git a/ext/standard/tests/strings/strncasecmp_variation11.phpt b/ext/standard/tests/strings/strncasecmp_variation11.phpt
new file mode 100644 (file)
index 0000000..f756c6c
--- /dev/null
@@ -0,0 +1,185 @@
+--TEST--
+Test strncasecmp() function : usage variations - unexpected values for 'str2'
+--FILE--
+<?php
+/* Prototype  : int strncasecmp ( string $str1, string $str2, int $len );
+ * Description: Binary safe case-insensitive string comparison of the first n characters
+ * Source code: Zend/zend_builtin_functions.c
+*/
+
+/* Test strncasecmp() function with the unexpected inputs for 'str2' */
+
+echo "*** Testing strncasecmp() function: with unexpected values for 'str2' ***\n";
+/* get an unset variable */
+$unset_var = 'string_val';
+unset($unset_var);
+
+/* get resource handle */
+$file_handle = fopen(__FILE__, "r");
+
+/* declaring a class */
+class sample  {
+  public function __toString() {
+  return "object";
+  }
+}
+
+
+/* array with different values */
+$values =  array (
+  /* integer values */
+  0,
+  1,
+  12345,
+  -2345,
+  /* float values */
+  10.5,
+  -10.5,
+  10.5e10,
+  10.6E-10,
+  .5,
+
+  /* hexadecimal values */
+  0x12,
+  -0x12,
+  
+  /* octal values */
+  012,
+  -012,
+  01.2,
+
+  /* array values */
+  array(),
+  array(0),
+  array(1),
+  array(1, 2),
+  array('color' => 'red', 'item' => 'pen'),
+
+  /* boolean values */
+  true,
+  false,
+  TRUE,
+  FALSE,
+
+  /* nulls */
+  NULL,
+  null,
+
+  /* empty string */
+  "",
+  '',
+
+  /* undefined variable */
+  @$undefined_var,
+
+  /* unset variable */
+  @$unset_var,
+
+  /* resource */
+  $file_handle,  
+
+  /* object */
+  new sample()
+);
+
+/* loop through each element of the array and check the working of strncasecmp() */
+$counter = 1;
+for($index = 0; $index < count($values); $index ++) {
+  echo "-- Iteration $counter --\n";
+  $str1 = $values[$index];
+  $str2 = $values[$index];
+  $len = strlen($values[$index]) + 1;
+  var_dump( strncasecmp("string", $str2, $len) );
+  $counter ++;
+}
+
+fclose($file_handle);  //closing the file handle
+
+echo "*** Done ***\n";
+?>
+--EXPECTF--
+*** Testing strncasecmp() function: with unexpected values for 'str2' ***
+-- Iteration 1 --
+int(%d)
+-- Iteration 2 --
+int(%d)
+-- Iteration 3 --
+int(%d)
+-- Iteration 4 --
+int(%d)
+-- Iteration 5 --
+int(%d)
+-- Iteration 6 --
+int(%d)
+-- Iteration 7 --
+int(%d)
+-- Iteration 8 --
+int(%d)
+-- Iteration 9 --
+int(%d)
+-- Iteration 10 --
+int(%d)
+-- Iteration 11 --
+int(%d)
+-- Iteration 12 --
+int(%d)
+-- Iteration 13 --
+int(%d)
+-- Iteration 14 --
+int(%d)
+-- Iteration 15 --
+
+Notice: Array to string conversion in %s on line %d
+
+Notice: Array to string conversion in %s on line %d
+int(%d)
+-- Iteration 16 --
+
+Notice: Array to string conversion in %s on line %d
+
+Notice: Array to string conversion in %s on line %d
+int(%d)
+-- Iteration 17 --
+
+Notice: Array to string conversion in %s on line %d
+
+Notice: Array to string conversion in %s on line %d
+int(%d)
+-- Iteration 18 --
+
+Notice: Array to string conversion in %s on line %d
+
+Notice: Array to string conversion in %s on line %d
+int(%d)
+-- Iteration 19 --
+
+Notice: Array to string conversion in %s on line %d
+
+Notice: Array to string conversion in %s on line %d
+int(%d)
+-- Iteration 20 --
+int(%d)
+-- Iteration 21 --
+int(%d)
+-- Iteration 22 --
+int(%d)
+-- Iteration 23 --
+int(%d)
+-- Iteration 24 --
+int(%d)
+-- Iteration 25 --
+int(%d)
+-- Iteration 26 --
+int(%d)
+-- Iteration 27 --
+int(%d)
+-- Iteration 28 --
+int(%d)
+-- Iteration 29 --
+int(%d)
+-- Iteration 30 --
+int(%d)
+-- Iteration 31 --
+int(%d)
+*** Done ***
diff --git a/ext/standard/tests/strings/strncasecmp_variation2.phpt b/ext/standard/tests/strings/strncasecmp_variation2.phpt
new file mode 100644 (file)
index 0000000..a6f8c1e
--- /dev/null
@@ -0,0 +1,63 @@
+--TEST--
+Test strncasecmp() function: usage variations - double quoted strings
+--FILE--
+<?php
+/* Prototype  : int strncasecmp ( string $str1, string $str2, int $len );
+ * Description: Binary safe case-insensitive string comparison of the first n characters
+ * Source code: Zend/zend_builtin_functions.c
+*/
+
+/* Test strncasecmp() function with various double quoted strings for 'str1', 'str2' */
+
+echo "*** Test strncasecmp() function: with double quoted strings ***\n";
+$strings = array(
+  "Hello, World",
+  "hello, world",
+  "HELLO, WORLD",
+  "Hello, World\n",
+  "Hello".chr(0)."World"
+);
+/* loop through to compare each string with the other string */
+$count = 1;
+for($index1 = 0; $index1 < count($strings); $index1++) {
+  echo "-- Iteration $count --\n";
+  for($index2 = 0; $index2 < count($strings); $index2++) {
+    var_dump( strncasecmp( $strings[$index1], $strings[$index2], (strlen($strings[$index1]) + 1) ) );
+  }
+  $count ++;
+}
+echo "*** Done ***\n";
+?>
+--EXPECTREGEX--
+\*\*\* Test strncasecmp\(\) function: with double quoted strings \*\*\*
+-- Iteration 1 --
+int\(0\)
+int\(0\)
+int\(0\)
+int\(-[1-9][0-9]*\)
+int\([1-9][0-9]*\)
+-- Iteration 2 --
+int\(0\)
+int\(0\)
+int\(0\)
+int\(-[1-9][0-9]*\)
+int\([1-9][0-9]*\)
+-- Iteration 3 --
+int\(0\)
+int\(0\)
+int\(0\)
+int\(-[1-9][0-9]*\)
+int\([1-9][0-9]*\)
+-- Iteration 4 --
+int\([1-9][0-9]*\)
+int\([1-9][0-9]*\)
+int\([1-9][0-9]*\)
+int\(0\)
+int\([1-9][0-9]*\)
+-- Iteration 5 --
+int\(-[1-9][0-9]*\)
+int\(-[1-9][0-9]*\)
+int\(-[1-9][0-9]*\)
+int\(-[1-9][0-9]*\)
+int\(0\)
+\*\*\* Done \*\*\*
diff --git a/ext/standard/tests/strings/strncasecmp_variation3.phpt b/ext/standard/tests/strings/strncasecmp_variation3.phpt
new file mode 100644 (file)
index 0000000..8409260
--- /dev/null
@@ -0,0 +1,39 @@
+--TEST--
+Test strncasecmp() function: usage variations - various lengths
+--FILE--
+<?php
+/* Prototype  : int strncasecmp ( string $str1, string $str2, int $len );
+ * Description: Binary safe case-insensitive string comparison of the first n characters
+ * Source code: Zend/zend_builtin_functions.c
+*/
+
+/* Test strncasecmp() with various lengths */
+
+echo "*** Test strncasecmp() function: with different lengths ***\n";
+/* definitions of required variables */
+$str1 = "Hello, World\n";
+$str2 = "Hello, world\n";
+
+/* loop through to compare the strings, for various length values */
+for($len = strlen($str1); $len >= 0; $len--) {
+  var_dump( strncasecmp($str1, $str2, $len) );
+}
+echo "*** Done ***\n";
+?>
+--EXPECTF--    
+*** Test strncasecmp() function: with different lengths ***
+int(0)
+int(0)
+int(0)
+int(0)
+int(0)
+int(0)
+int(0)
+int(0)
+int(0)
+int(0)
+int(0)
+int(0)
+int(0)
+int(0)
+*** Done ***
diff --git a/ext/standard/tests/strings/strncasecmp_variation4.phpt b/ext/standard/tests/strings/strncasecmp_variation4.phpt
new file mode 100644 (file)
index 0000000..3f73aa3
--- /dev/null
@@ -0,0 +1,195 @@
+--TEST--
+Test strncasecmp() function : usage variations - unexpected values for 'str1' & 'str2'
+--FILE--
+<?php
+/* Prototype  : int strncasecmp ( string $str1, string $str2, int $len );
+ * Description: Binary safe case-insensitive string comparison of the first n characters
+ * Source code: Zend/zend_builtin_functions.c
+*/
+
+/* Test strncasecmp() function with the unexpected inputs for 'str1' and 'str2' */
+
+echo "*** Testing strncasecmp() function: with unexpected values for 'str1' and 'str2' ***\n";
+/* get an unset variable */
+$unset_var = 'string_val';
+unset($unset_var);
+
+/* get resource handle */
+$file_handle = fopen(__FILE__, "r");
+
+/* declaring a class */
+class sample  {
+  public function __toString() {
+  return "object";
+  }
+}
+
+
+/* array with different values */
+$values =  array (
+  /* integer values */
+  0,
+  1,
+  12345,
+  -2345,
+  /* float values */
+  10.5,
+  -10.5,
+  10.5e10,
+  10.6E-10,
+  .5,
+
+  /* hexadecimal values */
+  0x12,
+  -0x12,
+  
+  /* octal values */
+  012,
+  -012,
+  01.2,
+
+  /* array values */
+  array(),
+  array(0),
+  array(1),
+  array(1, 2),
+  array('color' => 'red', 'item' => 'pen'),
+
+  /* boolean values */
+  true,
+  false,
+  TRUE,
+  FALSE,
+
+  /* nulls */
+  NULL,
+  null,
+
+  /* empty string */
+  "",
+  '',
+
+  /* undefined variable */
+  @$undefined_var,
+
+  /* unset variable */
+  @$unset_var,
+
+  /* resource */
+  $file_handle,  
+
+  /* object */
+  new sample()
+);
+
+/* loop through each element of the array and check the working of strncasecmp() */
+$counter = 1;
+for($index = 0; $index < count($values); $index ++) {
+  echo "-- Iteration $counter --\n";
+  $str1 = $values[$index];
+  $str2 = $values[$index];
+  $len = strlen($values[$index]) + 1;
+  var_dump( strncasecmp($str1, $str2, $len) );
+  $counter ++;
+}
+
+fclose($file_handle);  //closing the file handle
+
+echo "*** Done ***\n";
+?>
+--EXPECTF--
+*** Testing strncasecmp() function: with unexpected values for 'str1' and 'str2' ***
+-- Iteration 1 --
+int(0)
+-- Iteration 2 --
+int(0)
+-- Iteration 3 --
+int(0)
+-- Iteration 4 --
+int(0)
+-- Iteration 5 --
+int(0)
+-- Iteration 6 --
+int(0)
+-- Iteration 7 --
+int(0)
+-- Iteration 8 --
+int(0)
+-- Iteration 9 --
+int(0)
+-- Iteration 10 --
+int(0)
+-- Iteration 11 --
+int(0)
+-- Iteration 12 --
+int(0)
+-- Iteration 13 --
+int(0)
+-- Iteration 14 --
+int(0)
+-- Iteration 15 --
+
+Notice: Array to string conversion in %s on line %d
+
+Notice: Array to string conversion in %s on line %d
+
+Notice: Array to string conversion in %s on line %d
+int(0)
+-- Iteration 16 --
+
+Notice: Array to string conversion in %s on line %d
+
+Notice: Array to string conversion in %s on line %d
+
+Notice: Array to string conversion in %s on line %d
+int(0)
+-- Iteration 17 --
+
+Notice: Array to string conversion in %s on line %d
+
+Notice: Array to string conversion in %s on line %d
+
+Notice: Array to string conversion in %s on line %d
+int(0)
+-- Iteration 18 --
+
+Notice: Array to string conversion in %s on line %d
+
+Notice: Array to string conversion in %s on line %d
+
+Notice: Array to string conversion in %s on line %d
+int(0)
+-- Iteration 19 --
+
+Notice: Array to string conversion in %s on line %d
+
+Notice: Array to string conversion in %s on line %d
+
+Notice: Array to string conversion in %s on line %d
+int(0)
+-- Iteration 20 --
+int(0)
+-- Iteration 21 --
+int(0)
+-- Iteration 22 --
+int(0)
+-- Iteration 23 --
+int(0)
+-- Iteration 24 --
+int(0)
+-- Iteration 25 --
+int(0)
+-- Iteration 26 --
+int(0)
+-- Iteration 27 --
+int(0)
+-- Iteration 28 --
+int(0)
+-- Iteration 29 --
+int(0)
+-- Iteration 30 --
+int(0)
+-- Iteration 31 --
+int(0)
+*** Done ***
diff --git a/ext/standard/tests/strings/strncasecmp_variation5.phpt b/ext/standard/tests/strings/strncasecmp_variation5.phpt
new file mode 100644 (file)
index 0000000..4a9fa89
--- /dev/null
@@ -0,0 +1,147 @@
+--TEST--
+Test strncasecmp() function : usage variations - unexpected values for 'len'
+--FILE--
+<?php
+/* Prototype  : int strncasecmp ( string $str1, string $str2, int $len );
+ * Description: Binary safe case-insensitive string comparison of the first n characters
+ * Source code: Zend/zend_builtin_functions.c
+*/
+
+/* Test strncasecmp() function with the unexpected values, and giving the same strings for 'str1' and 'str2' */
+
+echo "*** Test strncasecmp() function: unexpected values for 'len' ***\n";
+
+/* definition of required variables */
+$str1 = "Hello, World\n";
+$str2 = "Hello, World\n";
+
+/* get an unset variable */
+$unset_var = 'string_val';
+unset($unset_var);
+
+/* get resource handle */
+$file_handle = fopen(__FILE__, "r");
+
+/* declaring a class */
+class sample  {
+  public function __toString() {
+  return "object";
+  }
+}
+
+
+/* array with different values */
+$lengths =  array (
+
+  /* float values */
+  10.5,
+  10.5e10,
+  10.6E-10,
+  .5,
+
+  /* hexadecimal values */
+  0x12,
+
+  /* octal values */
+  012,
+  01.2,
+
+  /* array values */
+  array(),
+  array(0),
+  array(1),
+  array(1, 2),
+  array('color' => 'red', 'item' => 'pen'),
+
+  /* boolean values */
+  true,
+  false,
+  TRUE,
+  FALSE,
+
+  /* nulls */
+  NULL,
+  null,
+
+  /* empty string */
+  "",
+  '',
+
+  /* undefined variable */
+  @$undefined_var,
+
+  /* unset variable */
+  @$unset_var,
+
+  /* resource */
+  $file_handle,
+
+  /* object */
+  new sample()
+);
+
+/* loop through each element of the array and check the working of strncasecmp() */
+$counter = 1;
+for($index = 0; $index < count($lengths); $index ++) {
+  $len = $lengths[$index];
+  echo "-- Iteration $counter --\n";
+  var_dump( strncasecmp($str1, $str2, $len) );
+  $counter ++;
+}
+fclose($file_handle);
+
+echo "*** Done ***\n";
+?>
+--EXPECTF--
+*** Test strncasecmp() function: unexpected values for 'len' ***
+-- Iteration 1 --
+int(0)
+-- Iteration 2 --
+int(0)
+-- Iteration 3 --
+int(0)
+-- Iteration 4 --
+int(0)
+-- Iteration 5 --
+int(0)
+-- Iteration 6 --
+int(0)
+-- Iteration 7 --
+int(0)
+-- Iteration 8 --
+int(0)
+-- Iteration 9 --
+int(0)
+-- Iteration 10 --
+int(0)
+-- Iteration 11 --
+int(0)
+-- Iteration 12 --
+int(0)
+-- Iteration 13 --
+int(0)
+-- Iteration 14 --
+int(0)
+-- Iteration 15 --
+int(0)
+-- Iteration 16 --
+int(0)
+-- Iteration 17 --
+int(0)
+-- Iteration 18 --
+int(0)
+-- Iteration 19 --
+int(0)
+-- Iteration 20 --
+int(0)
+-- Iteration 21 --
+int(0)
+-- Iteration 22 --
+int(0)
+-- Iteration 23 --
+int(0)
+-- Iteration 24 --
+
+Notice: Object of class sample could not be converted to int in %s on line %d
+int(0)
+*** Done ***
diff --git a/ext/standard/tests/strings/strncasecmp_variation6.phpt b/ext/standard/tests/strings/strncasecmp_variation6.phpt
new file mode 100644 (file)
index 0000000..765032b
--- /dev/null
@@ -0,0 +1,810 @@
+--TEST--
+Test strncasecmp() function : usage variations - binary safe - all ASCII chars
+--FILE--
+<?php
+/* Prototype  : int strncasecmp ( string $str1, string $str2, int $len );
+ * Description: Binary safe case-insensitive string comparison of the first n characters
+ * Source code: Zend/zend_builtin_functions.c
+*/
+
+/* Test strncasecmp() function with binary values passed to 'str1' & 'str2' */
+
+echo "*** Test strncasecmp() function: with binary inputs ***\n";
+
+/* A binary function should work with all 256 characters that a character(8-bit) can take */
+echo "\n-- Checking with all 256 characters given, in binary format --\n";
+/* loop through to get all 256 character's equivelent binary value, and check working of strncasecmp() */
+$count = 1;
+for($ASCII = 0; $ASCII <= 255; $ASCII++) {
+  $str1 = decbin($ASCII);  //ASCII value in binary form
+  $str2 = decbin( ord( chr($ASCII) ) );  //Getting equivelent ASCII value for the character in binary form
+  echo "-- Iteration $count --\n";
+  var_dump( strncasecmp($str1, $str2, 8) );  //comparing all the 8-bits; expected: int(0)
+  var_dump( strncasecmp($str1, $str2, 4) );  //comparing only 4-bits; expected: int(0)
+  $count++;
+}
+
+echo "\n-- Checking with out of character's range, given in binary format --\n";
+$str1 = decbin(256);
+$str2 = decbin( ord( chr(256) ));
+var_dump( strncasecmp($str1, $str2, 8) );  //comparing all the 8-bits; expected: int(1)
+
+echo "\n*** Done ***\n";
+?>
+--EXPECTF--
+*** Test strncasecmp() function: with binary inputs ***
+
+-- Checking with all 256 characters given, in binary format --
+-- Iteration 1 --
+int(0)
+int(0)
+-- Iteration 2 --
+int(0)
+int(0)
+-- Iteration 3 --
+int(0)
+int(0)
+-- Iteration 4 --
+int(0)
+int(0)
+-- Iteration 5 --
+int(0)
+int(0)
+-- Iteration 6 --
+int(0)
+int(0)
+-- Iteration 7 --
+int(0)
+int(0)
+-- Iteration 8 --
+int(0)
+int(0)
+-- Iteration 9 --
+int(0)
+int(0)
+-- Iteration 10 --
+int(0)
+int(0)
+-- Iteration 11 --
+int(0)
+int(0)
+-- Iteration 12 --
+int(0)
+int(0)
+-- Iteration 13 --
+int(0)
+int(0)
+-- Iteration 14 --
+int(0)
+int(0)
+-- Iteration 15 --
+int(0)
+int(0)
+-- Iteration 16 --
+int(0)
+int(0)
+-- Iteration 17 --
+int(0)
+int(0)
+-- Iteration 18 --
+int(0)
+int(0)
+-- Iteration 19 --
+int(0)
+int(0)
+-- Iteration 20 --
+int(0)
+int(0)
+-- Iteration 21 --
+int(0)
+int(0)
+-- Iteration 22 --
+int(0)
+int(0)
+-- Iteration 23 --
+int(0)
+int(0)
+-- Iteration 24 --
+int(0)
+int(0)
+-- Iteration 25 --
+int(0)
+int(0)
+-- Iteration 26 --
+int(0)
+int(0)
+-- Iteration 27 --
+int(0)
+int(0)
+-- Iteration 28 --
+int(0)
+int(0)
+-- Iteration 29 --
+int(0)
+int(0)
+-- Iteration 30 --
+int(0)
+int(0)
+-- Iteration 31 --
+int(0)
+int(0)
+-- Iteration 32 --
+int(0)
+int(0)
+-- Iteration 33 --
+int(0)
+int(0)
+-- Iteration 34 --
+int(0)
+int(0)
+-- Iteration 35 --
+int(0)
+int(0)
+-- Iteration 36 --
+int(0)
+int(0)
+-- Iteration 37 --
+int(0)
+int(0)
+-- Iteration 38 --
+int(0)
+int(0)
+-- Iteration 39 --
+int(0)
+int(0)
+-- Iteration 40 --
+int(0)
+int(0)
+-- Iteration 41 --
+int(0)
+int(0)
+-- Iteration 42 --
+int(0)
+int(0)
+-- Iteration 43 --
+int(0)
+int(0)
+-- Iteration 44 --
+int(0)
+int(0)
+-- Iteration 45 --
+int(0)
+int(0)
+-- Iteration 46 --
+int(0)
+int(0)
+-- Iteration 47 --
+int(0)
+int(0)
+-- Iteration 48 --
+int(0)
+int(0)
+-- Iteration 49 --
+int(0)
+int(0)
+-- Iteration 50 --
+int(0)
+int(0)
+-- Iteration 51 --
+int(0)
+int(0)
+-- Iteration 52 --
+int(0)
+int(0)
+-- Iteration 53 --
+int(0)
+int(0)
+-- Iteration 54 --
+int(0)
+int(0)
+-- Iteration 55 --
+int(0)
+int(0)
+-- Iteration 56 --
+int(0)
+int(0)
+-- Iteration 57 --
+int(0)
+int(0)
+-- Iteration 58 --
+int(0)
+int(0)
+-- Iteration 59 --
+int(0)
+int(0)
+-- Iteration 60 --
+int(0)
+int(0)
+-- Iteration 61 --
+int(0)
+int(0)
+-- Iteration 62 --
+int(0)
+int(0)
+-- Iteration 63 --
+int(0)
+int(0)
+-- Iteration 64 --
+int(0)
+int(0)
+-- Iteration 65 --
+int(0)
+int(0)
+-- Iteration 66 --
+int(0)
+int(0)
+-- Iteration 67 --
+int(0)
+int(0)
+-- Iteration 68 --
+int(0)
+int(0)
+-- Iteration 69 --
+int(0)
+int(0)
+-- Iteration 70 --
+int(0)
+int(0)
+-- Iteration 71 --
+int(0)
+int(0)
+-- Iteration 72 --
+int(0)
+int(0)
+-- Iteration 73 --
+int(0)
+int(0)
+-- Iteration 74 --
+int(0)
+int(0)
+-- Iteration 75 --
+int(0)
+int(0)
+-- Iteration 76 --
+int(0)
+int(0)
+-- Iteration 77 --
+int(0)
+int(0)
+-- Iteration 78 --
+int(0)
+int(0)
+-- Iteration 79 --
+int(0)
+int(0)
+-- Iteration 80 --
+int(0)
+int(0)
+-- Iteration 81 --
+int(0)
+int(0)
+-- Iteration 82 --
+int(0)
+int(0)
+-- Iteration 83 --
+int(0)
+int(0)
+-- Iteration 84 --
+int(0)
+int(0)
+-- Iteration 85 --
+int(0)
+int(0)
+-- Iteration 86 --
+int(0)
+int(0)
+-- Iteration 87 --
+int(0)
+int(0)
+-- Iteration 88 --
+int(0)
+int(0)
+-- Iteration 89 --
+int(0)
+int(0)
+-- Iteration 90 --
+int(0)
+int(0)
+-- Iteration 91 --
+int(0)
+int(0)
+-- Iteration 92 --
+int(0)
+int(0)
+-- Iteration 93 --
+int(0)
+int(0)
+-- Iteration 94 --
+int(0)
+int(0)
+-- Iteration 95 --
+int(0)
+int(0)
+-- Iteration 96 --
+int(0)
+int(0)
+-- Iteration 97 --
+int(0)
+int(0)
+-- Iteration 98 --
+int(0)
+int(0)
+-- Iteration 99 --
+int(0)
+int(0)
+-- Iteration 100 --
+int(0)
+int(0)
+-- Iteration 101 --
+int(0)
+int(0)
+-- Iteration 102 --
+int(0)
+int(0)
+-- Iteration 103 --
+int(0)
+int(0)
+-- Iteration 104 --
+int(0)
+int(0)
+-- Iteration 105 --
+int(0)
+int(0)
+-- Iteration 106 --
+int(0)
+int(0)
+-- Iteration 107 --
+int(0)
+int(0)
+-- Iteration 108 --
+int(0)
+int(0)
+-- Iteration 109 --
+int(0)
+int(0)
+-- Iteration 110 --
+int(0)
+int(0)
+-- Iteration 111 --
+int(0)
+int(0)
+-- Iteration 112 --
+int(0)
+int(0)
+-- Iteration 113 --
+int(0)
+int(0)
+-- Iteration 114 --
+int(0)
+int(0)
+-- Iteration 115 --
+int(0)
+int(0)
+-- Iteration 116 --
+int(0)
+int(0)
+-- Iteration 117 --
+int(0)
+int(0)
+-- Iteration 118 --
+int(0)
+int(0)
+-- Iteration 119 --
+int(0)
+int(0)
+-- Iteration 120 --
+int(0)
+int(0)
+-- Iteration 121 --
+int(0)
+int(0)
+-- Iteration 122 --
+int(0)
+int(0)
+-- Iteration 123 --
+int(0)
+int(0)
+-- Iteration 124 --
+int(0)
+int(0)
+-- Iteration 125 --
+int(0)
+int(0)
+-- Iteration 126 --
+int(0)
+int(0)
+-- Iteration 127 --
+int(0)
+int(0)
+-- Iteration 128 --
+int(0)
+int(0)
+-- Iteration 129 --
+int(0)
+int(0)
+-- Iteration 130 --
+int(0)
+int(0)
+-- Iteration 131 --
+int(0)
+int(0)
+-- Iteration 132 --
+int(0)
+int(0)
+-- Iteration 133 --
+int(0)
+int(0)
+-- Iteration 134 --
+int(0)
+int(0)
+-- Iteration 135 --
+int(0)
+int(0)
+-- Iteration 136 --
+int(0)
+int(0)
+-- Iteration 137 --
+int(0)
+int(0)
+-- Iteration 138 --
+int(0)
+int(0)
+-- Iteration 139 --
+int(0)
+int(0)
+-- Iteration 140 --
+int(0)
+int(0)
+-- Iteration 141 --
+int(0)
+int(0)
+-- Iteration 142 --
+int(0)
+int(0)
+-- Iteration 143 --
+int(0)
+int(0)
+-- Iteration 144 --
+int(0)
+int(0)
+-- Iteration 145 --
+int(0)
+int(0)
+-- Iteration 146 --
+int(0)
+int(0)
+-- Iteration 147 --
+int(0)
+int(0)
+-- Iteration 148 --
+int(0)
+int(0)
+-- Iteration 149 --
+int(0)
+int(0)
+-- Iteration 150 --
+int(0)
+int(0)
+-- Iteration 151 --
+int(0)
+int(0)
+-- Iteration 152 --
+int(0)
+int(0)
+-- Iteration 153 --
+int(0)
+int(0)
+-- Iteration 154 --
+int(0)
+int(0)
+-- Iteration 155 --
+int(0)
+int(0)
+-- Iteration 156 --
+int(0)
+int(0)
+-- Iteration 157 --
+int(0)
+int(0)
+-- Iteration 158 --
+int(0)
+int(0)
+-- Iteration 159 --
+int(0)
+int(0)
+-- Iteration 160 --
+int(0)
+int(0)
+-- Iteration 161 --
+int(0)
+int(0)
+-- Iteration 162 --
+int(0)
+int(0)
+-- Iteration 163 --
+int(0)
+int(0)
+-- Iteration 164 --
+int(0)
+int(0)
+-- Iteration 165 --
+int(0)
+int(0)
+-- Iteration 166 --
+int(0)
+int(0)
+-- Iteration 167 --
+int(0)
+int(0)
+-- Iteration 168 --
+int(0)
+int(0)
+-- Iteration 169 --
+int(0)
+int(0)
+-- Iteration 170 --
+int(0)
+int(0)
+-- Iteration 171 --
+int(0)
+int(0)
+-- Iteration 172 --
+int(0)
+int(0)
+-- Iteration 173 --
+int(0)
+int(0)
+-- Iteration 174 --
+int(0)
+int(0)
+-- Iteration 175 --
+int(0)
+int(0)
+-- Iteration 176 --
+int(0)
+int(0)
+-- Iteration 177 --
+int(0)
+int(0)
+-- Iteration 178 --
+int(0)
+int(0)
+-- Iteration 179 --
+int(0)
+int(0)
+-- Iteration 180 --
+int(0)
+int(0)
+-- Iteration 181 --
+int(0)
+int(0)
+-- Iteration 182 --
+int(0)
+int(0)
+-- Iteration 183 --
+int(0)
+int(0)
+-- Iteration 184 --
+int(0)
+int(0)
+-- Iteration 185 --
+int(0)
+int(0)
+-- Iteration 186 --
+int(0)
+int(0)
+-- Iteration 187 --
+int(0)
+int(0)
+-- Iteration 188 --
+int(0)
+int(0)
+-- Iteration 189 --
+int(0)
+int(0)
+-- Iteration 190 --
+int(0)
+int(0)
+-- Iteration 191 --
+int(0)
+int(0)
+-- Iteration 192 --
+int(0)
+int(0)
+-- Iteration 193 --
+int(0)
+int(0)
+-- Iteration 194 --
+int(0)
+int(0)
+-- Iteration 195 --
+int(0)
+int(0)
+-- Iteration 196 --
+int(0)
+int(0)
+-- Iteration 197 --
+int(0)
+int(0)
+-- Iteration 198 --
+int(0)
+int(0)
+-- Iteration 199 --
+int(0)
+int(0)
+-- Iteration 200 --
+int(0)
+int(0)
+-- Iteration 201 --
+int(0)
+int(0)
+-- Iteration 202 --
+int(0)
+int(0)
+-- Iteration 203 --
+int(0)
+int(0)
+-- Iteration 204 --
+int(0)
+int(0)
+-- Iteration 205 --
+int(0)
+int(0)
+-- Iteration 206 --
+int(0)
+int(0)
+-- Iteration 207 --
+int(0)
+int(0)
+-- Iteration 208 --
+int(0)
+int(0)
+-- Iteration 209 --
+int(0)
+int(0)
+-- Iteration 210 --
+int(0)
+int(0)
+-- Iteration 211 --
+int(0)
+int(0)
+-- Iteration 212 --
+int(0)
+int(0)
+-- Iteration 213 --
+int(0)
+int(0)
+-- Iteration 214 --
+int(0)
+int(0)
+-- Iteration 215 --
+int(0)
+int(0)
+-- Iteration 216 --
+int(0)
+int(0)
+-- Iteration 217 --
+int(0)
+int(0)
+-- Iteration 218 --
+int(0)
+int(0)
+-- Iteration 219 --
+int(0)
+int(0)
+-- Iteration 220 --
+int(0)
+int(0)
+-- Iteration 221 --
+int(0)
+int(0)
+-- Iteration 222 --
+int(0)
+int(0)
+-- Iteration 223 --
+int(0)
+int(0)
+-- Iteration 224 --
+int(0)
+int(0)
+-- Iteration 225 --
+int(0)
+int(0)
+-- Iteration 226 --
+int(0)
+int(0)
+-- Iteration 227 --
+int(0)
+int(0)
+-- Iteration 228 --
+int(0)
+int(0)
+-- Iteration 229 --
+int(0)
+int(0)
+-- Iteration 230 --
+int(0)
+int(0)
+-- Iteration 231 --
+int(0)
+int(0)
+-- Iteration 232 --
+int(0)
+int(0)
+-- Iteration 233 --
+int(0)
+int(0)
+-- Iteration 234 --
+int(0)
+int(0)
+-- Iteration 235 --
+int(0)
+int(0)
+-- Iteration 236 --
+int(0)
+int(0)
+-- Iteration 237 --
+int(0)
+int(0)
+-- Iteration 238 --
+int(0)
+int(0)
+-- Iteration 239 --
+int(0)
+int(0)
+-- Iteration 240 --
+int(0)
+int(0)
+-- Iteration 241 --
+int(0)
+int(0)
+-- Iteration 242 --
+int(0)
+int(0)
+-- Iteration 243 --
+int(0)
+int(0)
+-- Iteration 244 --
+int(0)
+int(0)
+-- Iteration 245 --
+int(0)
+int(0)
+-- Iteration 246 --
+int(0)
+int(0)
+-- Iteration 247 --
+int(0)
+int(0)
+-- Iteration 248 --
+int(0)
+int(0)
+-- Iteration 249 --
+int(0)
+int(0)
+-- Iteration 250 --
+int(0)
+int(0)
+-- Iteration 251 --
+int(0)
+int(0)
+-- Iteration 252 --
+int(0)
+int(0)
+-- Iteration 253 --
+int(0)
+int(0)
+-- Iteration 254 --
+int(0)
+int(0)
+-- Iteration 255 --
+int(0)
+int(0)
+-- Iteration 256 --
+int(0)
+int(0)
+
+-- Checking with out of character's range, given in binary format --
+int(1)
+
+*** Done ***
diff --git a/ext/standard/tests/strings/strncasecmp_variation7.phpt b/ext/standard/tests/strings/strncasecmp_variation7.phpt
new file mode 100644 (file)
index 0000000..e22fad7
--- /dev/null
@@ -0,0 +1,27 @@
+--TEST--
+Test strncasecmp() function : usage variations - binary safe
+--FILE--
+<?php
+/* Prototype  : int strncasecmp ( string $str1, string $str2, int $len );
+ * Description: Binary safe case-insensitive string comparison of the first n characters
+ * Source code: Zend/zend_builtin_functions.c
+*/
+
+/* Test strncasecmp() function with null terminated strings and binary values passed to 'str1' & 'str2' */
+
+echo "*** Test strncasecmp() function: with null terminated strings and binary inputs ***\n";
+
+/* A binary function should not expect a null terminated string, and it should treat input as a raw stream of data */
+$str1 = "Hello\0world";
+$str2 = "Hello\0";
+$str3 = "Hello,".chr(0)."world";
+var_dump( strncasecmp($str1, $str2, 12) );
+var_dump( strncasecmp($str3, "Hello,world", 12) );
+
+echo "*** Done ***\n";
+?>
+--EXPECTF--
+*** Test strncasecmp() function: with null terminated strings and binary inputs ***
+int(5)
+int(-119)
+*** Done ***
diff --git a/ext/standard/tests/strings/strncasecmp_variation8.phpt b/ext/standard/tests/strings/strncasecmp_variation8.phpt
new file mode 100644 (file)
index 0000000..6011a7b
--- /dev/null
@@ -0,0 +1,52 @@
+--TEST--
+Test strncasecmp() function: usage variations - single quoted strings
+--FILE--
+<?php
+/* Prototype  : int strncasecmp ( string $str1, string $str2, int $len ); 
+ * Description: Binary safe case-insensitive string comparison of the first n characters
+ * Source code: Zend/zend_builtin_functions.c
+*/
+
+/* Test strncasecmp() function with various single quoted strings for 'str1', 'str2' */
+
+echo "*** Test strncasecmp() function: with single quoted strings ***\n";
+$strings = array(
+  'Hello, World',
+  'hello, world',
+  'HELLO, WORLD',
+  'Hello, World\n'
+);
+/* loop through to compare each string with the other string */
+$count = 1;
+for($index1 = 0; $index1 < count($strings); $index1++) {
+  echo "-- Iteration $count --\n";
+  for($index2 = 0; $index2 < count($strings); $index2++) {
+    var_dump( strncasecmp( $strings[$index1], $strings[$index2], (strlen($strings[$index1]) + 1) ) );
+  }
+  $count ++;
+}
+echo "*** Done ***\n";
+?>
+--EXPECTREGEX--
+\*\*\* Test strncasecmp\(\) function: with single quoted strings \*\*\*
+-- Iteration 1 --
+int\(0\)
+int\(0\)
+int\(0\)
+int\(-[1-9][0-9]*\)
+-- Iteration 2 --
+int\(0\)
+int\(0\)
+int\(0\)
+int\(-[1-9][0-9]*\)
+-- Iteration 3 --
+int\(0\)
+int\(0\)
+int\(0\)
+int\(-[1-9][0-9]*\)
+-- Iteration 4 --
+int\([1-9][0-9]*\)
+int\([1-9][0-9]*\)
+int\([1-9][0-9]*\)
+int\(0\)
+\*\*\* Done \*\*\*
diff --git a/ext/standard/tests/strings/strncasecmp_variation9.phpt b/ext/standard/tests/strings/strncasecmp_variation9.phpt
new file mode 100644 (file)
index 0000000..0d71303
--- /dev/null
@@ -0,0 +1,92 @@
+--TEST--
+Test strncasecmp() function: usage variations - heredoc strings
+--FILE--
+<?php
+/* Prototype  : int strncasecmp ( string $str1, string $str2, int $len );
+ * Description: Binary safe case-insensitive string comparison of the first n characters
+ * Source code: Zend/zend_builtin_functions.c
+*/
+
+/* Test strncasecmp() function with here-doc strings for 'str1', 'str2' */
+
+echo "*** Test strncasecmp() function: with here-doc strings ***\n";
+
+/* multi line heredoc string */
+$multi_line_str = <<<EOD
+Example of string
+spanning multiple lines
+using heredoc syntax.
+EOD;
+
+/* identifier name contains underscore */
+$identifier_str1 = <<<identifier_str1
+Example of heredoc
+string, whose identifier
+having underscore("_") 
+& numeric value.
+identifier_str1;
+
+/* identifier name starts with underscore */
+$identifier_str2 = <<<_identifier_str2
+Hello, World
+hello, world
+_identifier_str2;
+
+/* string containing control character */
+$control_char_str = <<<EOD
+Hello, World\n
+Hello\0World
+EOD;
+
+/* heredoc string with quote chars & slash */
+$quote_char_string = <<<EOD
+it's bright,but i cann't see it.
+"things in double quote"
+'things in single quote'
+this\line is /with\slashs
+EOD;
+
+/* heredoc string with blank line */
+$blank_line = <<<EOD
+
+EOD;
+
+/* empty heredoc string */
+$empty_string = <<<EOD
+EOD;
+
+$strings = array(
+  $multi_line_str,
+  $identifier_str1,
+  $identifier_str2,
+  $control_char_str,
+  $quote_char_string,
+  $blank_line,
+  $empty_string
+);
+/* loop through to compare the strings */
+$index2 = count($strings);
+for($index1 = 0; $index1 < count($strings); $index1++) {
+  $index2--;
+  var_dump( strncasecmp( $strings[$index1], $strings[$index1], strlen($strings[$index1]) ) );
+  var_dump( strncasecmp( $strings[$index1], $strings[$index2], strlen($strings[$index1]) ) );
+}
+echo "*** Done ***\n";
+?>
+--EXPECTF--
+*** Test strncasecmp() function: with here-doc strings ***
+int(0)
+int(63)
+int(0)
+int(84)
+int(0)
+int(-1)
+int(0)
+int(0)
+int(0)
+int(1)
+int(0)
+int(0)
+int(0)
+int(0)
+*** Done ***