From: Raghubansh Kumar Date: Fri, 5 Oct 2007 19:35:45 +0000 (+0000) Subject: New testcases for setlocale() function X-Git-Tag: RELEASE_2_0_0a1~1650 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=dd24301ac60015625cbebef27d6ef9b248c69110;p=php New testcases for setlocale() function --- diff --git a/ext/standard/tests/strings/setlocale_basic1.phpt b/ext/standard/tests/strings/setlocale_basic1.phpt new file mode 100644 index 0000000000..b55741c465 --- /dev/null +++ b/ext/standard/tests/strings/setlocale_basic1.phpt @@ -0,0 +1,123 @@ +--TEST-- +Test setlocale() function : basic functionality - setting system locale to a specific +--SKIPIF-- + +--FILE-- + "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 diff --git a/ext/standard/tests/strings/setlocale_basic2.phpt b/ext/standard/tests/strings/setlocale_basic2.phpt new file mode 100644 index 0000000000..4b05cc9412 --- /dev/null +++ b/ext/standard/tests/strings/setlocale_basic2.phpt @@ -0,0 +1,127 @@ +--TEST-- +Test setlocale() function : basic functionality - set locale using an array +--SKIPIF-- + +--FILE-- + "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 diff --git a/ext/standard/tests/strings/setlocale_basic3.phpt b/ext/standard/tests/strings/setlocale_basic3.phpt new file mode 100644 index 0000000000..dc13134522 --- /dev/null +++ b/ext/standard/tests/strings/setlocale_basic3.phpt @@ -0,0 +1,93 @@ +--TEST-- +Test setlocale() function : basic functionality - passing multiple locales as argument +--SKIPIF-- + +--FILE-- + "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 diff --git a/ext/standard/tests/strings/setlocale_error.phpt b/ext/standard/tests/strings/setlocale_error.phpt new file mode 100644 index 0000000000..161dce0e15 --- /dev/null +++ b/ext/standard/tests/strings/setlocale_error.phpt @@ -0,0 +1,69 @@ +--TEST-- +Test setlocale() function : error conditions +--SKIPIF-- + +--FILE-- + +--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 diff --git a/ext/standard/tests/strings/setlocale_variation1.phpt b/ext/standard/tests/strings/setlocale_variation1.phpt new file mode 100644 index 0000000000..ee886bc4a1 --- /dev/null +++ b/ext/standard/tests/strings/setlocale_variation1.phpt @@ -0,0 +1,93 @@ +--TEST-- +Test setlocale() function : usage variations - passing multiple valid/invlaid locales as argument +--SKIPIF-- + +--FILE-- + "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 diff --git a/ext/standard/tests/strings/setlocale_variation2.phpt b/ext/standard/tests/strings/setlocale_variation2.phpt new file mode 100644 index 0000000000..e3f874a92f --- /dev/null +++ b/ext/standard/tests/strings/setlocale_variation2.phpt @@ -0,0 +1,91 @@ +--TEST-- +Test setlocale() function : usage variations - Setting all available locales in the platform +--SKIPIF-- + +--FILE-- + +--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 diff --git a/ext/standard/tests/strings/setlocale_variation3.phpt b/ext/standard/tests/strings/setlocale_variation3.phpt new file mode 100644 index 0000000000..070044fcec --- /dev/null +++ b/ext/standard/tests/strings/setlocale_variation3.phpt @@ -0,0 +1,157 @@ +--TEST-- +Test setlocale() function : usage variations - setting system locale = 0 +--SKIPIF-- + +--FILE-- + +--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 diff --git a/ext/standard/tests/strings/setlocale_variation4.phpt b/ext/standard/tests/strings/setlocale_variation4.phpt new file mode 100644 index 0000000000..41dffa4320 --- /dev/null +++ b/ext/standard/tests/strings/setlocale_variation4.phpt @@ -0,0 +1,155 @@ +--TEST-- +Test setlocale() function : usage variations - setting system locale as null +--SKIPIF-- + +--ENV-- +LC_ALL=en_US.utf8; +--FILE-- + +--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 diff --git a/ext/standard/tests/strings/setlocale_variation5.phpt b/ext/standard/tests/strings/setlocale_variation5.phpt new file mode 100644 index 0000000000..88c0690056 --- /dev/null +++ b/ext/standard/tests/strings/setlocale_variation5.phpt @@ -0,0 +1,159 @@ +--TEST-- +Test setlocale() function : usage variations - Setting system locale as empty string +--SKIPIF-- + +--ENV-- +LC_ALL=en_US.utf8; +--FILE-- + +--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