Annotation of embedaddon/php/ext/standard/tests/strings/setlocale_variation2.phpt, revision 1.1.1.2
1.1 misho 1: --TEST--
2: Test setlocale() function : usage variations - Setting all available locales in the platform
3: --SKIPIF--
4: <?php
5: if (substr(PHP_OS, 0, 3) == 'WIN') {
6: die('skip Not valid for windows');
7: }
8: ?>
9: --FILE--
10: <?php
11: /* Prototype : string setlocale (int $category , string $locale [,string $..] )
12: : string setlocale(int $category , array $locale);
13: * Description: Sets locale information.Returns the new current locale , or FALSE
1.1.1.2 ! misho 14: if locale functionality is not implemented in this platform.
1.1 misho 15: * Source code: ext/standard/string.c
16: */
17:
18: /* setlocale() to set all available locales in the system and check the success count */
19: echo "*** Testing setlocale() : usage variations ***\n";
20:
21: function good_locale($locale) {
22: return $locale !== 'tt_RU@iqtelif.UTF-8';
23: }
24:
25: /* Prototype : array list_system_locales( void )
26: * Description: To get the currently installed locle in this platform
27: * Arguments : Nil
28: * Returns : set of locale as array
29: */
30: function list_system_locales() {
31: // start the buffering of next command to internal output buffer
32: ob_start();
33:
34: // run the command 'locale -a' to fetch all locales available in the system
35: system('locale -a');
36:
37: // get the contents from the internal output buffer
38: $all_locales = ob_get_contents();
39:
40: // fflush and end the output buffering to internal output buffer
41: ob_end_clean();
42:
43: $system_locales = explode("\n", $all_locales);
44:
45: // return all the locale found in the system, except for broken one
46: return array_filter($system_locales, 'good_locale');
47: }
48:
49: // gather all the locales installed in the system
50: $all_system_locales = list_system_locales();
51:
52: //try different locale names
53: $failure_locale = array();
54: $success_count = 0;
55:
56: echo "-- Test setlocale() with all available locale in the system --\n";
57: // gather all locales installed in the system(stored $all_system_locales),
58: // try n set each locale using setlocale() and keep track failures, if any
59: foreach($all_system_locales as $value){
60: //set locale to $value, if success, count increments
61: if(setlocale(LC_ALL,$value )){
62: $success_count++;
63: }
64: else{
65: //failure values are put in to an array $failure_locale
66: $failure_locale[] = $value;
67: }
68: }
69:
70: echo "No of locales found on the machine = ".count($all_system_locales)."\n";
71: echo "No of setlocale() success = ".$success_count."\n";
72: echo "Expected no of failures = 0\n";
73: echo "Test ";
74: // check if there were any failure of setlocale() function earlier, if any
75: // failure then dump the list of failing locales
76: if($success_count != count($all_system_locales)){
77: echo "FAILED\n";
78: echo "Names of locale() for which setlocale() failed ...\n";
79: var_dump($failure_locale);
80: }
81: else{
82: echo "PASSED\n";
83: }
84:
85: echo "Done\n";
86: ?>
87: --EXPECTF--
88: *** Testing setlocale() : usage variations ***
89: -- Test setlocale() with all available locale in the system --
90: No of locales found on the machine = %d
91: No of setlocale() success = %d
92: Expected no of failures = 0
93: Test PASSED
94: Done
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>