kraghuba                Fri Oct  5 19:35:45 2007 UTC

  Modified files:              
    /php-src/ext/standard/tests/strings setlocale_variation1.phpt 
                                        setlocale_variation2.phpt 
                                        setlocale_variation3.phpt 
                                        setlocale_variation4.phpt 
                                        setlocale_variation5.phpt 
                                        setlocale_basic1.phpt 
                                        setlocale_basic2.phpt 
                                        setlocale_basic3.phpt 
                                        setlocale_error.phpt 
  Log:
  New testcases for setlocale() function
  
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/strings/setlocale_variation1.phpt?r1=1.1&r2=1.2&diff_format=u
Index: php-src/ext/standard/tests/strings/setlocale_variation1.phpt
diff -u /dev/null 
php-src/ext/standard/tests/strings/setlocale_variation1.phpt:1.2
--- /dev/null   Fri Oct  5 19:35:45 2007
+++ php-src/ext/standard/tests/strings/setlocale_variation1.phpt        Fri Oct 
 5 19:35:45 2007
@@ -0,0 +1,93 @@
+--TEST--
+Test setlocale() function : usage variations - passing multiple valid/invlaid 
locales as argument
+--SKIPIF--
+<?php
+if (substr(PHP_OS, 0, 3) == 'WIN')
+  die('skip Not valid for windows');
+if(ini_get("unicode.semantics") == "1")
+  die('skip do not run when unicode on');
+?>
+--FILE--
+<?php
+/* Prototype  : string setlocale (int $category , string $locale [,string $..] 
)
+              : string setlocale(int $category , array $locale);
+ * Description: Sets locale information.Returns the new current locale , or 
FALSE
+                if locale functinality is not implemented in this platform.
+ * Source code: ext/standard/string.c
+*/
+
+/* Test the setlocale() when multiple valid/invalid locales are provided as 
argument */
+
+/* Prototype  : array list_system_locales( void )
+   Description: To get the currently installed locle in this platform 
+   Arguments  : Nil
+   Returns    : set of locale as array
+*/
+function list_system_locales() {
+  // start the buffering of next command to internal output buffer
+  ob_start();
+
+  // run the command 'locale -a' to fetch all locales available in the system
+  system('locale -a');
+
+  // get the contents from the internal output buffer
+  $all_locales = ob_get_contents();
+
+  // fflush and end the output buffering to internal output buffer
+  ob_end_clean();
+
+  $system_locales = explode("\n", $all_locales);
+
+  // return all the locale found in the system
+  return $system_locales;
+}
+
+/* Collect existing system locales and get 2 valid locales that can be use to 
+   pass as argument to setlocale(), pass 2 invalid arguments along with two 
valid argumentsss */
+echo "*** Testing setlocale() by passing multiple valid/invalid locales as 
argument ***\n";
+
+//set of currency symbol according to above list of locales
+$currency_symbol = array(
+  "en_US.utf8" => "USD",
+  "ko_KR.utf8" => "KRW",
+  "zh_CN.utf8" => "CNY"
+);
+
+// gather all the locales installed in the system
+$all_system_locales = list_system_locales();
+
+// Now check for three locales that is present in the system and use that as 
argument to setlocale()
+if( in_array("en_US.utf8",$all_system_locales) ||
+    in_array("Ko_KR.utf8",$all_system_locales) ||
+    in_array("zh_CN.utf8",$all_system_locales) ) {
+  echo "-- Testing setlocale() by giving 'category' as LC_ALL & multiple 
locales(en_US.invalid, en_US.utf8, Ko_KR.utf8, KO_KR.invalid, zh_CN.utf8) --\n";
+
+  // call setlocale()
+  $new_locale = setlocale(LC_ALL, "en_US.invalid", "en_US.utf8", "Ko_KR.utf8", 
"KO_KR.invalid", "zh_CN.utf8");
+
+  // dump the name of the new locale set by setlocale()
+  var_dump($new_locale);
+
+  // check that new locale setting is effective
+  // use localeconv() to get the details of currently set locale
+  $locale_info = localeconv();
+  $new_currency = trim($locale_info['int_curr_symbol']);
+
+  echo "Checking currency settings in the new locale, expected: 
".$currency_symbol[$new_locale].", Found: ".$new_currency."\n";
+  echo "Test ";
+  if( trim($currency_symbol[$new_locale]) == $new_currency) {
+    echo "PASSED.\n";
+  } else {
+    echo "FAILED.\n";
+  }
+}
+
+echo "Done\n";
+?>
+--EXPECTF--
+*** Testing setlocale() by passing multiple valid/invalid locales as argument 
***
+-- Testing setlocale() by giving 'category' as LC_ALL & multiple 
locales(en_US.invalid, en_US.utf8, Ko_KR.utf8, KO_KR.invalid, zh_CN.utf8) --
+string(%d) "%s"
+Checking currency settings in the new locale, expected: %s, Found: %s
+Test PASSED.
+Done
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/strings/setlocale_variation2.phpt?r1=1.1&r2=1.2&diff_format=u
Index: php-src/ext/standard/tests/strings/setlocale_variation2.phpt
diff -u /dev/null 
php-src/ext/standard/tests/strings/setlocale_variation2.phpt:1.2
--- /dev/null   Fri Oct  5 19:35:45 2007
+++ php-src/ext/standard/tests/strings/setlocale_variation2.phpt        Fri Oct 
 5 19:35:45 2007
@@ -0,0 +1,91 @@
+--TEST--
+Test setlocale() function : usage variations - Setting all available locales 
in the platform
+--SKIPIF--
+<?php
+if (substr(PHP_OS, 0, 3) == 'WIN')
+  die('skip Not valid for windows');
+if(ini_get("unicode.semantics") == "1")
+  die('skip do not run when unicode on');
+?>
+--FILE--
+<?php
+/* Prototype  : string setlocale (int $category , string $locale [,string $..] 
)
+              : string setlocale(int $category , array $locale);  
+ * Description: Sets locale information.Returns the new current locale , or 
FALSE 
+                if locale functinality is not implemented in this platform. 
+ * Source code: ext/standard/string.c
+*/
+
+/* setlocale() to set all available locales in the system and check the 
success count */
+echo "*** Testing setlocale() : usage variations ***\n";
+
+/* Prototype  : array list_system_locales( void )
+ * Description: To get the currently installed locle in this platform 
+ * Arguments  : Nil
+ * Returns    : set of locale as array
+*/
+function list_system_locales() {
+  // start the buffering of next command to internal output buffer
+  ob_start();
+
+  // run the command 'locale -a' to fetch all locales available in the system
+  system('locale -a');
+
+  // get the contents from the internal output buffer
+  $all_locales = ob_get_contents();
+
+  // fflush and end the output buffering to internal output buffer
+  ob_end_clean();
+
+  $system_locales = explode("\n", $all_locales);
+
+  // return all the locale found in the system
+  return $system_locales;
+}
+
+// gather all the locales installed in the system
+$all_system_locales = list_system_locales();
+
+//try different locale names   
+$failure_locale = array();
+$success_count = 0;
+
+echo "-- Test setlocale() with all available locale in the system --\n";
+// gather all locales installed in the system(stored $all_system_locales),
+// try n set each locale using setlocale() and keep track failures, if any
+foreach($all_system_locales as $value){
+  //set locale to $value, if success, count increments
+  if(setlocale(LC_ALL,$value )){
+   $success_count++;
+  }
+  else{
+   //failure values are put in to an array $failure_locale
+   $failure_locale[] = $value;
+  }
+}
+
+echo "No of locales found on the machine = ".count($all_system_locales)."\n";
+echo "No of setlocale() success = ".$success_count."\n";
+echo "Expected no of failures = 0\n";
+echo "Test ";
+// check if there were any failure of setlocale() function earlier, if any 
+// failure then dump the list of failing locales
+if($success_count != count($all_system_locales)){
+  echo "FAILED\n";
+  echo "Names of locale() for which setlocale() failed ...\n";
+  var_dump($failure_locale);
+}
+else{
+  echo "PASSED\n";
+}
+
+echo "Done\n";
+?>
+--EXPECTF--
+*** Testing setlocale() : usage variations ***
+-- Test setlocale() with all available locale in the system --
+No of locales found on the machine = %d
+No of setlocale() success = %d
+Expected no of failures = 0
+Test PASSED
+Done
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/strings/setlocale_variation3.phpt?r1=1.1&r2=1.2&diff_format=u
Index: php-src/ext/standard/tests/strings/setlocale_variation3.phpt
diff -u /dev/null 
php-src/ext/standard/tests/strings/setlocale_variation3.phpt:1.2
--- /dev/null   Fri Oct  5 19:35:45 2007
+++ php-src/ext/standard/tests/strings/setlocale_variation3.phpt        Fri Oct 
 5 19:35:45 2007
@@ -0,0 +1,157 @@
+--TEST--
+Test setlocale() function : usage variations - setting system locale = 0
+--SKIPIF--
+<?php
+if (substr(PHP_OS, 0, 3) == 'WIN')
+  die('skip Not valid for windows');
+if(ini_get("unicode.semantics") == "1")
+  die('skip do not run when unicode on');
+?>
+--FILE--
+<?php
+/* Prototype  : string setlocale (int $category , string $locale [,string $..] 
)
+ *            : string setlocale(int $category , array $locale);  
+ * Description: Sets locale information.Returns the new current locale , or 
FALSE
+ *              if locale functinality is not implemented in this platform. 
+ * Source code: ext/standard/string.c
+*/
+
+/* If locale is "0", the locale setting is not affected, only the current 
setting is returned */
+
+echo "*** Testing setlocale() : usage variations - setting system locale = 0 
***\n";
+$locale_info_before = array();
+$locale_info_after = array();
+
+//initially giving the locale
+setlocale(LC_ALL,"en_US.utf8");
+
+echo "Locale info, before setting the locale\n";
+//returns current locale,before executing setlocale().
+$locale_info_before = localeconv();
+
+var_dump($locale_info_before);
+
+//Testing setlocale()  by giving locale = 0
+echo "Setting system locale, category = LC_ALL and locale = 0\n";
+setlocale(LC_ALL, 0);
+
+echo "Locale info, after setting the locale\n";
+//returns current locale,after executing setlocale().
+$locale_info_after = localeconv();
+
+var_dump($locale_info_after);
+
+echo "Checking locale in the system, Expected : no change in the existing 
locale\n";
+echo "Test ";
+if($locale_info_before ==  $locale_info_after){
+  echo "PASSED.";
+} else {
+  echo "FAILED.";
+}
+
+echo "\nDone\n";
+?>
+--EXPECTF--
+*** Testing setlocale() : usage variations - setting system locale = 0 ***
+Locale info, before setting the locale
+array(18) {
+  ["decimal_point"]=>
+  string(1) "."
+  ["thousands_sep"]=>
+  string(1) ","
+  ["int_curr_symbol"]=>
+  string(4) "USD "
+  ["currency_symbol"]=>
+  string(1) "$"
+  ["mon_decimal_point"]=>
+  string(1) "."
+  ["mon_thousands_sep"]=>
+  string(1) ","
+  ["positive_sign"]=>
+  string(0) ""
+  ["negative_sign"]=>
+  string(1) "-"
+  ["int_frac_digits"]=>
+  int(2)
+  ["frac_digits"]=>
+  int(2)
+  ["p_cs_precedes"]=>
+  int(1)
+  ["p_sep_by_space"]=>
+  int(0)
+  ["n_cs_precedes"]=>
+  int(1)
+  ["n_sep_by_space"]=>
+  int(0)
+  ["p_sign_posn"]=>
+  int(1)
+  ["n_sign_posn"]=>
+  int(1)
+  ["grouping"]=>
+  array(2) {
+    [0]=>
+    int(3)
+    [1]=>
+    int(3)
+  }
+  ["mon_grouping"]=>
+  array(2) {
+    [0]=>
+    int(3)
+    [1]=>
+    int(3)
+  }
+}
+Setting system locale, category = LC_ALL and locale = 0
+Locale info, after setting the locale
+array(18) {
+  ["decimal_point"]=>
+  string(1) "."
+  ["thousands_sep"]=>
+  string(1) ","
+  ["int_curr_symbol"]=>
+  string(4) "USD "
+  ["currency_symbol"]=>
+  string(1) "$"
+  ["mon_decimal_point"]=>
+  string(1) "."
+  ["mon_thousands_sep"]=>
+  string(1) ","
+  ["positive_sign"]=>
+  string(0) ""
+  ["negative_sign"]=>
+  string(1) "-"
+  ["int_frac_digits"]=>
+  int(2)
+  ["frac_digits"]=>
+  int(2)
+  ["p_cs_precedes"]=>
+  int(1)
+  ["p_sep_by_space"]=>
+  int(0)
+  ["n_cs_precedes"]=>
+  int(1)
+  ["n_sep_by_space"]=>
+  int(0)
+  ["p_sign_posn"]=>
+  int(1)
+  ["n_sign_posn"]=>
+  int(1)
+  ["grouping"]=>
+  array(2) {
+    [0]=>
+    int(3)
+    [1]=>
+    int(3)
+  }
+  ["mon_grouping"]=>
+  array(2) {
+    [0]=>
+    int(3)
+    [1]=>
+    int(3)
+  }
+}
+Checking locale in the system, Expected : no change in the existing locale
+Test PASSED.
+Done
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/strings/setlocale_variation4.phpt?r1=1.1&r2=1.2&diff_format=u
Index: php-src/ext/standard/tests/strings/setlocale_variation4.phpt
diff -u /dev/null 
php-src/ext/standard/tests/strings/setlocale_variation4.phpt:1.2
--- /dev/null   Fri Oct  5 19:35:45 2007
+++ php-src/ext/standard/tests/strings/setlocale_variation4.phpt        Fri Oct 
 5 19:35:45 2007
@@ -0,0 +1,155 @@
+--TEST--
+Test setlocale() function : usage variations - setting system locale as null
+--SKIPIF--
+<?php
+if (substr(PHP_OS, 0, 3) == 'WIN')
+  die('skip Not valid for windows');
+if(ini_get("unicode.semantics") == "1")
+  die('skip do not run when unicode on');
+?>
+--ENV--
+LC_ALL=en_US.utf8;
+--FILE--
+<?php
+/* Prototype  : string setlocale (int $category , string $locale [,string $..] 
)
+ *            : string setlocale(int $category , array $locale);  
+ * Description: Sets locale information.Returns the new current locale , or 
FALSE
+ *              if locale functinality is not implemented in this platform. 
+ * Source code: ext/standard/string.c
+*/
+
+/*If locale is NULL, the locale names will be set from the values of 
environment variables with the same names as the above ENV settings */
+
+echo "*** Testing setlocale() : usage variations - Setting system locale = 
null ***\n";
+
+//initially setting the locale
+setlocale(LC_ALL,"en_AU.utf8");
+
+echo "Locale info, before setting the locale\n";
+//returns current locale,before executing setlocale() .
+$locale_info_before = localeconv();
+var_dump($locale_info_before);
+
+//Testing setlocale()  by giving locale = null
+echo "Setting system locale, category = LC_ALL and locale = null\n";
+setlocale(LC_ALL, null);
+
+echo "Locale info, after setting the locale\n";
+//Returns Current locale,after executing setlocale().
+$locale_info_after = localeconv();
+var_dump($locale_info_after);
+
+echo "Checking new locale in the system, Expected : the locale names will be 
set from the values of environment variables\n";
+echo "Test ";
+if($locale_info_before != $locale_info_after){
+  echo "PASSED.";
+} else {
+  echo "FAILED.";
+}
+
+echo "\nDone\n";
+?>
+--EXPECTF--
+*** Testing setlocale() : usage variations - Setting system locale = null ***
+Locale info, before setting the locale
+array(18) {
+  ["decimal_point"]=>
+  string(1) "."
+  ["thousands_sep"]=>
+  string(1) ","
+  ["int_curr_symbol"]=>
+  string(4) "AUD "
+  ["currency_symbol"]=>
+  string(1) "$"
+  ["mon_decimal_point"]=>
+  string(1) "."
+  ["mon_thousands_sep"]=>
+  string(1) ","
+  ["positive_sign"]=>
+  string(0) ""
+  ["negative_sign"]=>
+  string(1) "-"
+  ["int_frac_digits"]=>
+  int(2)
+  ["frac_digits"]=>
+  int(2)
+  ["p_cs_precedes"]=>
+  int(1)
+  ["p_sep_by_space"]=>
+  int(0)
+  ["n_cs_precedes"]=>
+  int(1)
+  ["n_sep_by_space"]=>
+  int(0)
+  ["p_sign_posn"]=>
+  int(1)
+  ["n_sign_posn"]=>
+  int(1)
+  ["grouping"]=>
+  array(2) {
+    [0]=>
+    int(3)
+    [1]=>
+    int(3)
+  }
+  ["mon_grouping"]=>
+  array(2) {
+    [0]=>
+    int(3)
+    [1]=>
+    int(3)
+  }
+}
+Setting system locale, category = LC_ALL and locale = null
+Locale info, after setting the locale
+array(18) {
+  ["decimal_point"]=>
+  string(1) "."
+  ["thousands_sep"]=>
+  string(1) ","
+  ["int_curr_symbol"]=>
+  string(4) "USD "
+  ["currency_symbol"]=>
+  string(1) "$"
+  ["mon_decimal_point"]=>
+  string(1) "."
+  ["mon_thousands_sep"]=>
+  string(1) ","
+  ["positive_sign"]=>
+  string(0) ""
+  ["negative_sign"]=>
+  string(1) "-"
+  ["int_frac_digits"]=>
+  int(2)
+  ["frac_digits"]=>
+  int(2)
+  ["p_cs_precedes"]=>
+  int(1)
+  ["p_sep_by_space"]=>
+  int(0)
+  ["n_cs_precedes"]=>
+  int(1)
+  ["n_sep_by_space"]=>
+  int(0)
+  ["p_sign_posn"]=>
+  int(1)
+  ["n_sign_posn"]=>
+  int(1)
+  ["grouping"]=>
+  array(2) {
+    [0]=>
+    int(3)
+    [1]=>
+    int(3)
+  }
+  ["mon_grouping"]=>
+  array(2) {
+    [0]=>
+    int(3)
+    [1]=>
+    int(3)
+  }
+}
+Checking new locale in the system, Expected : the locale names will be set 
from the values of environment variables
+Test PASSED.
+Done
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/strings/setlocale_variation5.phpt?r1=1.1&r2=1.2&diff_format=u
Index: php-src/ext/standard/tests/strings/setlocale_variation5.phpt
diff -u /dev/null 
php-src/ext/standard/tests/strings/setlocale_variation5.phpt:1.2
--- /dev/null   Fri Oct  5 19:35:45 2007
+++ php-src/ext/standard/tests/strings/setlocale_variation5.phpt        Fri Oct 
 5 19:35:45 2007
@@ -0,0 +1,159 @@
+--TEST--
+Test setlocale() function : usage variations - Setting system locale as empty 
string
+--SKIPIF--
+<?php
+if (substr(PHP_OS, 0, 3) == 'WIN')
+  die('skip Not valid for windows');
+if(ini_get("unicode.semantics") == "1")
+  die('skip do not run when unicode on');
+?>
+--ENV--
+LC_ALL=en_US.utf8;
+--FILE--
+<?php
+/* Prototype  : string setlocale (int $category , string $locale [,string $..] 
)
+ *            : string setlocale(int $category , array $locale);  
+ * Description: Sets locale information.Returns the new current locale , or 
FALSE 
+ *              if locale functinality is not implemented in this platform. 
+ * Source code: ext/standard/string.c
+*/
+
+/* If locale is empty string "", the locale names will be set from the values 
of environment variables with the same names as from ENV */
+
+echo "*** Testing setlocale() : usage variations - setting system locale = 
\"\" ***\n";
+
+//initially setting the locale
+setlocale(LC_ALL,'en_AU.utf8');
+
+echo "Locale info, before setting the locale\n";
+
+//returns current locale,before executing setlocale() .
+$locale_info_before = localeconv();
+
+var_dump($locale_info_before);
+
+//Testing setlocale()  by giving locale = null
+echo "Setting system locale, category = LC_ALL and locale = \"\"\n";
+setlocale(LC_ALL, "");
+
+echo "Locale info, after setting the locale\n";
+
+//Returns Current locale,after executing setlocale().
+$locale_info_after = localeconv();
+
+var_dump($locale_info_after);
+
+echo "Checking new locale in the system, Expected : the locale names will be 
set from the values of environment variables\n";
+echo "Test ";
+if($locale_info_before != $locale_info_after){
+  echo "PASSED.";
+} else {
+  echo "FAILED.";
+}
+
+echo "\nDone\n";
+?>
+--EXPECTF--
+*** Testing setlocale() : usage variations - setting system locale = "" ***
+Locale info, before setting the locale
+array(18) {
+  ["decimal_point"]=>
+  string(1) "."
+  ["thousands_sep"]=>
+  string(1) ","
+  ["int_curr_symbol"]=>
+  string(4) "AUD "
+  ["currency_symbol"]=>
+  string(1) "$"
+  ["mon_decimal_point"]=>
+  string(1) "."
+  ["mon_thousands_sep"]=>
+  string(1) ","
+  ["positive_sign"]=>
+  string(0) ""
+  ["negative_sign"]=>
+  string(1) "-"
+  ["int_frac_digits"]=>
+  int(2)
+  ["frac_digits"]=>
+  int(2)
+  ["p_cs_precedes"]=>
+  int(1)
+  ["p_sep_by_space"]=>
+  int(0)
+  ["n_cs_precedes"]=>
+  int(1)
+  ["n_sep_by_space"]=>
+  int(0)
+  ["p_sign_posn"]=>
+  int(1)
+  ["n_sign_posn"]=>
+  int(1)
+  ["grouping"]=>
+  array(2) {
+    [0]=>
+    int(3)
+    [1]=>
+    int(3)
+  }
+  ["mon_grouping"]=>
+  array(2) {
+    [0]=>
+    int(3)
+    [1]=>
+    int(3)
+  }
+}
+Setting system locale, category = LC_ALL and locale = ""
+Locale info, after setting the locale
+array(18) {
+  ["decimal_point"]=>
+  string(1) "."
+  ["thousands_sep"]=>
+  string(1) ","
+  ["int_curr_symbol"]=>
+  string(4) "USD "
+  ["currency_symbol"]=>
+  string(1) "$"
+  ["mon_decimal_point"]=>
+  string(1) "."
+  ["mon_thousands_sep"]=>
+  string(1) ","
+  ["positive_sign"]=>
+  string(0) ""
+  ["negative_sign"]=>
+  string(1) "-"
+  ["int_frac_digits"]=>
+  int(2)
+  ["frac_digits"]=>
+  int(2)
+  ["p_cs_precedes"]=>
+  int(1)
+  ["p_sep_by_space"]=>
+  int(0)
+  ["n_cs_precedes"]=>
+  int(1)
+  ["n_sep_by_space"]=>
+  int(0)
+  ["p_sign_posn"]=>
+  int(1)
+  ["n_sign_posn"]=>
+  int(1)
+  ["grouping"]=>
+  array(2) {
+    [0]=>
+    int(3)
+    [1]=>
+    int(3)
+  }
+  ["mon_grouping"]=>
+  array(2) {
+    [0]=>
+    int(3)
+    [1]=>
+    int(3)
+  }
+}
+Checking new locale in the system, Expected : the locale names will be set 
from the values of environment variables
+Test PASSED.
+Done
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/strings/setlocale_basic1.phpt?r1=1.1&r2=1.2&diff_format=u
Index: php-src/ext/standard/tests/strings/setlocale_basic1.phpt
diff -u /dev/null php-src/ext/standard/tests/strings/setlocale_basic1.phpt:1.2
--- /dev/null   Fri Oct  5 19:35:45 2007
+++ php-src/ext/standard/tests/strings/setlocale_basic1.phpt    Fri Oct  5 
19:35:45 2007
@@ -0,0 +1,123 @@
+--TEST--
+Test setlocale() function : basic functionality - setting system locale to a 
specific   
+--SKIPIF--
+<?php
+if (substr(PHP_OS, 0, 3) == 'WIN') 
+  die('skip Not valid for windows');
+
+if( ini_get("unicode.semantics") == "1")
+  die('skip do not run when unicode on');
+?>
+--FILE--
+<?php
+/* Prototype  : string setlocale (int $category , string $locale [,string $..] 
)
+              : string setlocale(int $category , array $locale);  
+ * Description: Sets locale information.Returns the new current locale , 
+ *              or FALSE if locale functinality is not implemented in this 
platform. 
+ * Source code: ext/standard/string.c
+*/
+
+/* test setlocale by specifying a specific locale as input */
+
+/* Prototype  : array list_system_locales( void )
+   Description: To get the currently installed locle in this platform 
+   Arguments  : Nil
+   Returns    : set of locale as array
+*/
+function list_system_locales() {
+  // start the buffering of next command to internal output buffer
+  ob_start();
+
+  // run the command 'locale -a' to fetch all locales available in the system
+  system('locale -a');
+
+  // get the contents from the internal output buffer
+  $all_locales = ob_get_contents();
+
+  // fflush and end the output buffering to internal output buffer
+  ob_end_clean();
+
+  $system_locales = explode("\n", $all_locales);
+
+  // return all the locale found in the system
+  return $system_locales;
+}
+
+/* Collect existing system locales and set one among them,
+   Check the currency settings in the new locale  */
+echo "*** Testing setlocale() : basic functionality - set to a specific locale 
***\n";
+
+//set of locales to be used
+$common_locales = array(
+  "english_US"=> "en_US.utf8gfd", 
+  "english_AU" => "en_AU.utf8hgg", 
+  "korean_KR" => "ko_KR.utf8", 
+  "Chinese_zh" => "zh_CN.utf8",
+  "germen_DE" => "de_DE.utf8",
+  "spanish_es" => "es_EC.utf8",
+  "french_FR" => "fr_FR.utf8",
+  "japanees_JP" => "ja_JP.utf8",
+  "greek_GR" => "el_GR.utf8",
+  "dutch_NL" => "nl_NL.utf8"
+);
+
+//set of currency symbol according to above list of locales
+$currency_symbol = array(
+  "en_US.utf8" => "USD",
+  "en_AU.utf8" => "AUD",
+  "ko_KR.utf8" => "KRW",
+  "zh_CN.utf8" => "CNY",
+  "de_DE.utf8" => "EUR",
+  "es_EC.utf8" => "USD",
+  "fr_FR.utf8" => "EUR",
+  "ja_JP.utf8" => "JPY",
+  "el_GR.utf8" => "EUR",
+  "nl_NL.utf8" =>"EUR"
+);
+
+// gather all the locales installed in the system
+$all_system_locales = list_system_locales();
+
+// set the system locale to a locale, choose the right locale by 
+// finding a common locale in commonly used locale stored in 
+// $common_locales & locales that are available in the system, stored 
+// in $all_system_locales. 
+echo "Setting system locale(LC_ALL) to ";
+foreach($common_locales as $value) {
+  // check if a commonly used locale is installed in the system 
+  if(in_array($value, $all_system_locales)){
+    echo "$value\n"; // print, this is found
+    // set the found locale as current locale
+    var_dump(setlocale(LC_ALL, $value ));
+    // stop here 
+    break;
+  }
+  else{
+    // continue to check if next commonly locale is installed in the system
+    continue;
+  }
+}
+
+// check that new locale setting is effective
+// use localeconv() to get the details of currently set locale
+$locale_info = localeconv();
+
+//checking currency settings in the new locale to see if the setlocale() was 
effective
+$new_currency = trim($locale_info['int_curr_symbol']);
+echo "Checking currency settings in the new locale, expected: 
".$currency_symbol[$value].", Found: ".$new_currency."\n";
+echo "Test ";
+if(trim($currency_symbol[$value]) == $new_currency){
+  echo "PASSED.";
+} else {
+  echo "FAILED.";
+}
+
+echo "\nDone\n";
+?>
+--EXPECTF--
+*** Testing setlocale() : basic functionality - set to a specific locale ***
+Setting system locale(LC_ALL) to %s
+string(%d) %s
+Checking currency settings in the new locale, expected: %s, Found: %s
+Test PASSED.
+Done
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/strings/setlocale_basic2.phpt?r1=1.1&r2=1.2&diff_format=u
Index: php-src/ext/standard/tests/strings/setlocale_basic2.phpt
diff -u /dev/null php-src/ext/standard/tests/strings/setlocale_basic2.phpt:1.2
--- /dev/null   Fri Oct  5 19:35:45 2007
+++ php-src/ext/standard/tests/strings/setlocale_basic2.phpt    Fri Oct  5 
19:35:45 2007
@@ -0,0 +1,127 @@
+--TEST--
+Test setlocale() function : basic functionality - set locale using an array
+--SKIPIF--
+<?php
+if (substr(PHP_OS, 0, 3) == 'WIN')
+  die('skip Not valid for windows');
+if(ini_get("unicode.semantics") == "1")
+  die('skip do not run when unicode on');
+?>
+--FILE--
+<?php
+/* Prototype  : string setlocale (int $category , string $locale [,string $..] 
)
+              : string setlocale(int $category , array $locale);  
+ * Description: Sets locale information.Returns the new current locale , or 
FALSE
+                if locale  functinality is not implemented in this platform. 
+ * Source code: ext/standard/string.c
+*/
+
+/* Test the setlocale() when an array is provided as input containing list of 
locales */
+
+/* Prototype  : array list_system_locales( void )
+ * Description: To get the currently installed locle in this platform 
+ * Arguments  : Nil
+ * Returns    : set of locale as array
+*/
+function list_system_locales() {
+  // start the buffering of next command to internal output buffer
+  ob_start();
+
+  // run the command 'locale -a' to fetch all locales available in the system
+  system('locale -a');
+
+  // get the contents from the internal output buffer
+  $all_locales = ob_get_contents();
+
+  // fflush and end the output buffering to internal output buffer
+  ob_end_clean();
+
+  $system_locales = explode("\n", $all_locales);
+
+  // return all the locale found in the system
+  return $system_locales;
+}
+
+/* Collect existing system locales and prepare a list of locales that can be 
used as 
+   input to setlocale() */
+
+echo "*** Testing setlocale() with an array containing list of locales ***\n";
+
+//set of locales to be used
+$common_locales = array(
+  "english_US"=> "en_US.utf8", 
+  "english_AU" => "en_AU.utf8", 
+  "korean_KR" => "ko_KR.utf8", 
+  "Chinese_zh" => "zh_CN.utf8",
+  "germen_DE" => "de_DE.utf8",
+  "spanish_es" => "es_EC.utf8",
+  "french_FR" => "fr_FR.utf8",
+  "japanees_JP" => "ja_JP.utf8",
+  "greek_GR" => "el_GR.utf8",
+  "dutch_NL" => "nl_NL.utf8"
+);
+
+//set of currency symbol according to above list of locales
+$currency_symbol = array(
+  "en_US.utf8" => "USD",
+  "en_AU.utf8" => "AUD",
+  "ko_KR.utf8" => "KRW",
+  "zh_CN.utf8" => "CNY",
+  "de_DE.utf8" => "EUR",
+  "es_EC.utf8" => "USD",
+  "fr_FR.utf8" => "EUR",
+  "ja_JP.utf8" => "JPY",
+  "el_GR.utf8" => "EUR",
+  "nl_NL.utf8" =>"EUR"
+);
+
+// gather all the locales installed in the system
+$all_system_locales = list_system_locales();
+
+// prepare the list of locales based on list of locales found in the system
+// and those known to this script ( as stored $common_locales) which can be
+// given as input to setlocale(), later verify the new locale setting by
+// checking the currency setting of the system(use localconv())
+$list_of_locales = array();
+foreach($common_locales as $value) {
+  if( in_array($value, $all_system_locales) ) {
+    $list_of_locales[] = $value;
+  }
+}
+
+// Now $list_of_locales array contains the locales that can be passed to 
+// setlocale() function.
+echo "-- Testing setlocale() : 'category' argument as LC_ALL & 'locale' 
argument as an array --\n";
+if ( count($list_of_locales) > 0 ) {
+  // set locale to $list_of_locales
+  $new_locale = setlocale(LC_ALL, $list_of_locales);
+
+  // dump the current locale
+  var_dump($new_locale);
+
+  // check that new locale setting is effective
+  // use localeconv() to get the details of currently set locale
+  $locale_info = localeconv();
+  $new_currency = trim($locale_info['int_curr_symbol']);
+
+  echo "Checking currency settings in the new locale, expected: 
".$currency_symbol[$new_locale].", Found: ".$new_currency."\n";
+  echo "Test ";
+
+  if(trim($currency_symbol[$new_locale]) == $new_currency){
+    echo "PASSED.\n";
+  } else { 
+    echo "FAILED.\n";
+  }
+} else {
+  echo "Test FAILED.\n";
+}
+
+echo "Done\n";
+?>
+--EXPECTF--
+*** Testing setlocale() with an array containing list of locales ***
+-- Testing setlocale() : 'category' argument as LC_ALL & 'locale' argument as 
an array --
+string(%d) "%s"
+Checking currency settings in the new locale, expected: %s, Found: %s
+Test PASSED.
+Done
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/strings/setlocale_basic3.phpt?r1=1.1&r2=1.2&diff_format=u
Index: php-src/ext/standard/tests/strings/setlocale_basic3.phpt
diff -u /dev/null php-src/ext/standard/tests/strings/setlocale_basic3.phpt:1.2
--- /dev/null   Fri Oct  5 19:35:45 2007
+++ php-src/ext/standard/tests/strings/setlocale_basic3.phpt    Fri Oct  5 
19:35:45 2007
@@ -0,0 +1,93 @@
+--TEST--
+Test setlocale() function : basic functionality - passing multiple locales as 
argument
+--SKIPIF--
+<?php
+if (substr(PHP_OS, 0, 3) == 'WIN')
+  die('skip Not valid for windows');
+if(ini_get("unicode.semantics") == "1")
+  die('skip do not run when unicode on');
+?>
+--FILE--
+<?php
+/* Prototype  : string setlocale (int $category , string $locale [,string $..] 
)
+              : string setlocale(int $category , array $locale);
+ * Description: Sets locale information.Returns the new current locale , or 
FALSE
+                if locale functinality is not implemented in this platform.
+ * Source code: ext/standard/string.c
+*/
+
+/* Test the setlocale() when multiple locales are provided as argument */
+
+/* Prototype  : array list_system_locales( void )
+   Description: To get the currently installed locle in this platform 
+   Arguments  : Nil
+   Returns    : set of locale as array
+*/
+function list_system_locales() {
+  // start the buffering of next command to internal output buffer
+  ob_start();
+
+  // run the command 'locale -a' to fetch all locales available in the system
+  system('locale -a');
+
+  // get the contents from the internal output buffer
+  $all_locales = ob_get_contents();
+
+  // fflush and end the output buffering to internal output buffer
+  ob_end_clean();
+
+  $system_locales = explode("\n", $all_locales);
+
+  // return all the locale found in the system
+  return $system_locales;
+}
+
+/* Collect existing system locales and get three locales that can be use to 
+   pass as argument to setlocale() */
+echo "*** Testing setlocale() by passing multiple locales as argument ***\n";
+
+//set of currency symbol according to above list of locales
+$currency_symbol = array(
+  "en_US.utf8" => "USD",
+  "ko_KR.utf8" => "KRW",
+  "zh_CN.utf8" => "CNY",
+);
+
+// gather all the locales installed in the system
+$all_system_locales = list_system_locales();
+
+// Now check for three locales that is present in the system and use that as 
argument to setlocale()
+if( in_array("en_US.utf8",$all_system_locales) ||
+    in_array("Ko_KR.utf8",$all_system_locales) ||
+    in_array("zh_CN.utf8",$all_system_locales) ) {
+  echo "-- Testing setlocale() by giving 'category' as LC_ALL & multiple 
locales(en_US.utf8, Ko_KR.utf8, zh_CN.utf8) --\n";
+
+  // call setlocale()
+  $new_locale = setlocale(LC_ALL, "en_US.utf8", "Ko_KR.utf8", "zh_CN.utf8");
+
+  // dump the name of the new locale set by setlocale()
+  var_dump($new_locale);
+
+  // check that new locale setting is effective
+  // use localeconv() to get the details of currently set locale
+  $locale_info = localeconv();
+  $new_currency = trim($locale_info['int_curr_symbol']);
+
+  echo "Checking currency settings in the new locale, expected: 
".$currency_symbol[$new_locale].", Found: ".$new_currency."\n";
+  echo "Test ";
+  if( trim($currency_symbol[$new_locale]) == $new_currency) {
+    echo "PASSED.\n";
+  } else {
+    echo "FAILED.\n";
+  }
+}
+
+echo "Done\n";
+?>
+--EXPECTF--
+*** Testing setlocale() by passing multiple locales as argument ***
+-- Testing setlocale() by giving 'category' as LC_ALL & multiple 
locales(en_US.utf8, Ko_KR.utf8, zh_CN.utf8) --
+string(%d) "%s"
+Checking currency settings in the new locale, expected: %s, Found: %s
+Test PASSED.
+Done
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/strings/setlocale_error.phpt?r1=1.1&r2=1.2&diff_format=u
Index: php-src/ext/standard/tests/strings/setlocale_error.phpt
diff -u /dev/null php-src/ext/standard/tests/strings/setlocale_error.phpt:1.2
--- /dev/null   Fri Oct  5 19:35:45 2007
+++ php-src/ext/standard/tests/strings/setlocale_error.phpt     Fri Oct  5 
19:35:45 2007
@@ -0,0 +1,69 @@
+--TEST--
+Test setlocale() function : error conditions
+--SKIPIF--
+<?php
+if (substr(PHP_OS, 0, 3) == 'WIN')
+  die('skip Not valid for windows');
+if(ini_get("unicode.semantics") == "1")
+  die('skip do not run when unicode on');
+?>
+--FILE--
+<?php
+/* Prototype  : string setlocale (int $category , string $locale [,string $..] 
)
+              : string setlocale(int $category , array $locale);  
+ * Description: Sets locale information.Returns the new current locale , or 
FALSE if locale functinality is not implemented in this platform. 
+ * Source code: ext/standard/string.c
+*/
+
+echo "*** Testing setlocale() : error conditions ***\n";
+
+// Zero argument
+echo "\n-- Testing setlocale() function with Zero arguments --";
+var_dump( setlocale());
+
+// One argument
+echo "\n-- Testing setlocale() function with One argument, 'category' = LC_ALL 
--";
+var_dump( setlocale(LC_ALL) );
+
+echo "\n-- Testing setlocale() function with invalid locale array, 'category' 
= LC_ALL --\n";
+//Invalid array of locales
+$invalid_locales = array("en_US.invalid", "en_AU.invalid", "ko_KR.invalid");
+var_dump( setlocale(LC_ALL,$invalid_locales) );
+
+echo "\n-- Testing setlocale() function with invalid multiple locales, 
'category' = LC_ALL --\n";
+//Invalid array of locales
+var_dump( setlocale(LC_ALL,"en_US.invalid", "en_AU.invalid", "ko_KR.invalid") 
);
+
+echo "\n-- Testing setlocale() function with invalid category --\n";
+//invalid $category
+$invalid_category = "TEST";
+var_dump( setlocale($invalid_category,"en_US.utf8") );
+ 
+echo "\nDone";
+?>
+--EXPECTF--
+
+*** Testing setlocale() : error conditions ***
+
+-- Testing setlocale() function with Zero arguments --
+Warning: Wrong parameter count for setlocale() in %s on line %d
+NULL
+
+-- Testing setlocale() function with One argument, 'category' = LC_ALL --
+Warning: Wrong parameter count for setlocale() in %s on line %d
+NULL
+
+-- Testing setlocale() function with invalid locale array, 'category' = LC_ALL 
--
+bool(false)
+
+-- Testing setlocale() function with invalid multiple locales, 'category' = 
LC_ALL --
+bool(false)
+
+-- Testing setlocale() function with invalid category --
+
+Warning: setlocale(): Passing locale category name as string is deprecated. 
Use the LC_* -constants instead in %s on line %d
+
+Warning: setlocale(): Invalid locale category name TEST, must be one of 
LC_ALL, LC_COLLATE, LC_CTYPE, LC_MONETARY, LC_NUMERIC, or LC_TIME in %s on line 
%d
+bool(false)
+
+Done

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to