Annotation of embedaddon/php/ext/intl/tests/ut_common.inc, revision 1.1.1.1
1.1 misho 1: <?php
2: /*
3: * Run unit test in OO- and in procedural mode.
4: * Then compare the outputs.
5: * It they're equal then show one of them.
6: * Otherwise indicate an error.
7: */
8: function ut_run()
9: {
10: // Run unit test in OO mode.
11: $GLOBALS['oo-mode'] = true;
12: $oo_result = ut_main();
13:
14: // Run unit test in procedural mode.
15: $GLOBALS['oo-mode'] = false;
16: $proc_result = ut_main();
17:
18: // Show error if the APIs produce different results.
19: if( $proc_result !== $oo_result )
20: {
21: echo "ERROR: OO- and procedural APIs produce different results!\n";
22: echo "OO API output:\n";
23: echo str_repeat( '=', 78 ) . "\n";
24: echo $oo_result;
25: echo str_repeat( '=', 78 ) . "\n";
26: echo "procedural API output:\n";
27: echo str_repeat( '=', 78 ) . "\n";
28: echo $proc_result;
29: echo str_repeat( '=', 78 ) . "\n";
30: return;
31: }
32:
33: // Else, if the results are equal, show one of them.
34: echo $proc_result;
35: }
36:
37: function dump( $val )
38: {
39: return var_export( $val, true );
40: }
41:
42: /*
43: * Wrappers around Collator methods to run them in either OO- or procedural mode.
44: */
45:
46: function ut_coll_create( $locale )
47: {
48: return $GLOBALS['oo-mode'] ? Collator::create( $locale ) : collator_create( $locale );
49: }
50: function ut_coll_compare( $coll, $str1, $str2 )
51: {
52: return $GLOBALS['oo-mode'] ? $coll->compare( $str1, $str2 ) : collator_compare( $coll, $str1, $str2 );
53: }
54: function ut_coll_sort( $coll, &$arr, $sort_flag = Collator::SORT_REGULAR )
55: {
56: return $GLOBALS['oo-mode'] ? $coll->sort( $arr, $sort_flag ) : collator_sort( $coll, $arr, $sort_flag );
57: }
58: function ut_coll_sort_with_sort_keys( $coll, &$arr )
59: {
60: return $GLOBALS['oo-mode'] ? $coll->sortWithSortKeys( $arr ) : collator_sort_with_sort_keys( $coll, $arr );
61: }
62: function ut_coll_get_sort_key( $coll, $str )
63: {
64: return $GLOBALS['oo-mode'] ? $coll->getSortKey( $str ) : collator_get_sort_key( $coll, $str );
65: }
66: function ut_coll_asort( $coll, &$arr, $sort_flag = Collator::SORT_REGULAR )
67: {
68: return $GLOBALS['oo-mode'] ? $coll->asort( $arr, $sort_flag ) : collator_asort( $coll, $arr, $sort_flag );
69: }
70: function ut_coll_get_locale( $coll, $type )
71: {
72: return $GLOBALS['oo-mode'] ? $coll->getLocale( $type ) : collator_get_locale( $coll, $type );
73: }
74: function ut_coll_get_display_name( $obj_loc, $disp_loc )
75: {
76: return $GLOBALS['oo-mode'] ? Collator::getDisplayName( $obj_loc, $disp_loc ) : collator_get_display_name( $obj_loc, $disp_loc );
77: }
78: function ut_coll_get_available_locales()
79: {
80: return $GLOBALS['oo-mode'] ? Collator::getAvailableLocales() : collator_get_available_locales();
81: }
82: function ut_coll_get_attribute( $coll, $attr )
83: {
84: return $GLOBALS['oo-mode'] ? $coll->getAttribute( $attr ) : collator_get_attribute( $coll, $attr );
85: }
86: function ut_coll_get_strength( $coll )
87: {
88: return $GLOBALS['oo-mode'] ? $coll->getStrength() : collator_get_strength( $coll );
89: }
90: function ut_coll_set_strength( $coll, $strength )
91: {
92: return $GLOBALS['oo-mode'] ? $coll->setStrength( $strength ) : collator_set_strength( $coll, $strength );
93: }
94: function ut_coll_set_attribute( $coll, $attr, $val )
95: {
96: return $GLOBALS['oo-mode'] ? $coll->setAttribute( $attr, $val ) : collator_set_attribute( $coll, $attr, $val );
97: }
98: function ut_coll_get_variable_top( $coll )
99: {
100: return $GLOBALS['oo-mode'] ? $coll->getVariableTop() : collator_get_variable_top( $coll );
101: }
102: function ut_coll_set_variable_top( $coll, $var_top )
103: {
104: return $GLOBALS['oo-mode'] ? $coll->setVariableTop( $var_top ) : collator_set_variable_top( $coll, $var_top );
105: }
106: function ut_coll_restore_variable_top( $coll, $var_top )
107: {
108: return $GLOBALS['oo-mode'] ? $coll->restoreVariableTop( $var_top ) : collator_restore_variable_top( $coll, $var_top );
109: }
110: function ut_coll_get_error_code( $coll )
111: {
112: return $GLOBALS['oo-mode'] ? $coll->getErrorCode() : collator_get_error_code( $coll );
113: }
114: function ut_coll_get_error_message( $coll )
115: {
116: return $GLOBALS['oo-mode'] ? $coll->getErrorMessage() : collator_get_error_message( $coll );
117: }
118: function ut_coll_get_default()
119: {
120: return $GLOBALS['oo-mode'] ? Collator::getDefault() : collator_get_default();
121: }
122: function ut_coll_set_default( $coll )
123: {
124: return $GLOBALS['oo-mode'] ? Collator::setDefault( $coll ) : collator_set_default( $coll );
125: }
126:
127: /*
128: * Wrappers around NumberFormatter methods to run them in either OO- or procedural mode.
129: */
130:
131: // FIXME: incomplete list
132:
133: function ut_nfmt_create( $locale, $style, $pattern = null )
134: {
135: return $GLOBALS['oo-mode'] ? new NumberFormatter( $locale, $style, $pattern ) : numfmt_create( $locale, $style, $pattern );
136: }
137: function ut_nfmt_format( $fmt, $number, $type = null )
138: {
139: return $GLOBALS['oo-mode'] ? $fmt->format( $number, $type ) : numfmt_format( $fmt, $number, $type );
140: }
141: function ut_nfmt_parse( $fmt, $string, $type = NumberFormatter::TYPE_DOUBLE, &$position = null )
142: {
143: if(is_null($position)) {
144: return $GLOBALS['oo-mode'] ? $fmt->parse( $string, $type ) : numfmt_parse( $fmt, $string, $type );
145: } else {
146: return $GLOBALS['oo-mode'] ? $fmt->parse( $string, $type, $position ) : numfmt_parse( $fmt, $string, $type, $position );
147: }
148: }
149: function ut_nfmt_format_currency( $fmt, $number, $currency )
150: {
151: return $GLOBALS['oo-mode'] ? $fmt->formatCurrency( $number, $currency ) : numfmt_format_currency( $fmt, $number, $currency );
152: }
153: function ut_nfmt_parse_currency( $fmt, $string, &$currency, &$position = null )
154: {
155: if(is_null($position)) {
156: return $GLOBALS['oo-mode'] ? $fmt->parseCurrency( $string, $currency ) : numfmt_parse_currency( $fmt, $string, $currency );
157: } else {
158: return $GLOBALS['oo-mode'] ? $fmt->parseCurrency( $string, $currency, $position ) : numfmt_parse_currency( $fmt, $string, $currency, $position );
159: }
160: }
161: function ut_nfmt_set_attribute( $fmt, $attribute, $value )
162: {
163: return $GLOBALS['oo-mode'] ? $fmt->setAttribute( $attribute, $value ) : numfmt_set_attribute( $fmt, $attribute, $value );
164: }
165: function ut_nfmt_set_text_attribute( $fmt, $attribute, $value )
166: {
167: return $GLOBALS['oo-mode'] ? $fmt->setTextAttribute( $attribute, $value ) : numfmt_set_text_attribute( $fmt, $attribute, $value );
168: }
169: function ut_nfmt_set_symbol( $fmt, $attribute, $value )
170: {
171: return $GLOBALS['oo-mode'] ? $fmt->setSymbol( $attribute, $value ) : numfmt_set_symbol( $fmt, $attribute, $value );
172: }
173: function ut_nfmt_set_pattern( $fmt, $pattern )
174: {
175: return $GLOBALS['oo-mode'] ? $fmt->setPattern( $pattern ) : numfmt_set_pattern( $fmt, $pattern );
176: }
177: function ut_nfmt_get_attribute( $fmt, $attribute )
178: {
179: return $GLOBALS['oo-mode'] ? $fmt->getAttribute( $attribute ) : numfmt_get_attribute( $fmt, $attribute );
180: }
181: function ut_nfmt_get_text_attribute( $fmt, $attribute )
182: {
183: return $GLOBALS['oo-mode'] ? $fmt->getTextAttribute( $attribute ) : numfmt_get_text_attribute( $fmt, $attribute );
184: }
185: function ut_nfmt_get_symbol( $fmt, $attribute )
186: {
187: return $GLOBALS['oo-mode'] ? $fmt->getSymbol( $attribute ) : numfmt_get_symbol( $fmt, $attribute );
188: }
189: function ut_nfmt_get_pattern( $fmt )
190: {
191: return $GLOBALS['oo-mode'] ? $fmt->getPattern() : numfmt_get_pattern( $fmt );
192: }
193: function ut_nfmt_get_locale( $fmt, $type = 0 )
194: {
195: return $GLOBALS['oo-mode'] ? $fmt->getLocale( $type ) : numfmt_get_locale( $fmt, $type );
196: }
197: function ut_nfmt_get_error_code( $fmt )
198: {
199: return $GLOBALS['oo-mode'] ? $fmt->getErrorCode() : numfmt_get_error_code( $fmt );
200: }
201: function ut_nfmt_get_error_message( $fmt )
202: {
203: return $GLOBALS['oo-mode'] ? $fmt->getErrorMessage() : numfmt_get_error_message( $fmt );
204: }
205:
206: function ut_norm_normalize( $str, $form )
207: {
208: return $GLOBALS['oo-mode'] ? Normalizer::normalize( $str, $form ) : normalizer_normalize( $str, $form );
209: }
210: function ut_norm_is_normalized( $str, $form )
211: {
212: return $GLOBALS['oo-mode'] ? Normalizer::isNormalized( $str, $form ) : normalizer_is_normalized( $str, $form );
213: }
214:
215: /*
216: * Wrappers around Collator methods to run them in either OO- or procedural mode.
217: */
218:
219: function ut_loc_get_default( )
220: {
221: return $GLOBALS['oo-mode'] ? Locale::getDefault( ) : locale_get_default();
222: }
223: function ut_loc_set_default( $locale )
224: {
225: return $GLOBALS['oo-mode'] ? Locale::setDefault( $locale ) : locale_set_default( $locale );
226: }
227: function ut_loc_get_primary_language( $locale )
228: {
229: return $GLOBALS['oo-mode'] ? Locale::getPrimaryLanguage( $locale ) : locale_get_primary_language( $locale );
230: }
231: function ut_loc_get_script( $locale )
232: {
233: return $GLOBALS['oo-mode'] ? Locale::getScript( $locale ) : locale_get_script( $locale );
234: }
235: function ut_loc_get_region( $locale )
236: {
237: return $GLOBALS['oo-mode'] ? Locale::getRegion( $locale ) : locale_get_region( $locale );
238: }
239: function ut_loc_get_keywords( $locale )
240: {
241: return $GLOBALS['oo-mode'] ? Locale::getKeywords( $locale ) : locale_get_keywords( $locale );
242: }
243: function ut_loc_get_display_name( $locale , $dispLocale )
244: {
245: return $GLOBALS['oo-mode'] ? Locale::getDisplayName( $locale , $dispLocale ) : locale_get_display_name( $locale , $dispLocale );
246: }
247: function ut_loc_get_display_language( $locale , $dispLocale )
248: {
249: return $GLOBALS['oo-mode'] ? Locale::getDisplayLanguage( $locale , $dispLocale ) : locale_get_display_language( $locale , $dispLocale );
250: }
251: function ut_loc_get_display_script( $locale , $dispLocale )
252: {
253: return $GLOBALS['oo-mode'] ? Locale::getDisplayScript( $locale , $dispLocale ) : locale_get_display_script( $locale , $dispLocale );
254: }
255: function ut_loc_get_display_region( $locale, $dispLocale )
256: {
257: return $GLOBALS['oo-mode'] ? Locale::getDisplayRegion( $locale, $dispLocale ) : locale_get_display_region( $locale, $dispLocale );
258: }
259: function ut_loc_get_display_variant( $locale , $dispLocale )
260: {
261: return $GLOBALS['oo-mode'] ? Locale::getDisplayVariant( $locale , $dispLocale ) : locale_get_display_variant( $locale, $dispLocale );
262: }
263: function ut_loc_locale_compose( $loc_parts_arr )
264: {
265: return $GLOBALS['oo-mode'] ? Locale::composeLocale( $loc_parts_arr ) : locale_compose( $loc_parts_arr );
266: }
267: function ut_loc_locale_parse( $locale )
268: {
269: return $GLOBALS['oo-mode'] ? Locale::parseLocale( $locale ) : locale_parse($locale );
270: }
271: function ut_loc_locale_get_all_variants( $locale )
272: {
273: return $GLOBALS['oo-mode'] ? Locale::getAllVariants( $locale ) : locale_get_all_variants( $locale );
274: }
275: function ut_loc_locale_filter_matches( $lang_tag,$loc_range ,$isCanonical)
276: {
277: return $GLOBALS['oo-mode'] ? Locale::filterMatches( $lang_tag,$loc_range ,$isCanonical) : locale_filter_matches( $lang_tag,$loc_range ,$isCanonical);
278: }
279: function ut_loc_canonicalize( $locale )
280: {
281: return $GLOBALS['oo-mode'] ? Locale::canonicalize( $locale ) : locale_canonicalize( $locale );
282: }
283: function ut_loc_locale_lookup( $lang_tag_arr,$loc_range,$isCanonical,$default_loc)
284: {
285: return $GLOBALS['oo-mode'] ? Locale::lookup( $lang_tag_arr,$loc_range,$isCanonical,$default_loc ) : locale_lookup( $lang_tag_arr,$loc_range,$isCanonical,$default_loc );
286: }
287: function ut_loc_accept_http($http) {
288: return $GLOBALS['oo-mode'] ? Locale::acceptFromHttp($http):locale_accept_from_http($http);
289: }
290: /* MessageFormatter functions */
291: function ut_msgfmt_create( $locale, $pattern)
292: {
293: return $GLOBALS['oo-mode'] ? MessageFormatter::create( $locale, $pattern ) : msgfmt_create( $locale, $pattern );
294: }
295: function ut_msgfmt_format( $fmt, $args )
296: {
297: return $GLOBALS['oo-mode'] ? $fmt->format( $args ) : msgfmt_format( $fmt, $args);
298: }
299: function ut_msgfmt_parse( $fmt, $string)
300: {
301: return $GLOBALS['oo-mode'] ? $fmt->parse( $string) : msgfmt_parse( $fmt, $string);
302: }
303: function ut_msgfmt_format_message( $locale, $pattern, $args )
304: {
305: return $GLOBALS['oo-mode'] ? MessageFormatter::formatMessage( $locale, $pattern, $args ) : msgfmt_format_message( $locale, $pattern, $args );
306: }
307: function ut_msgfmt_parse_message( $locale, $pattern, $string )
308: {
309: return $GLOBALS['oo-mode'] ? MessageFormatter::parseMessage( $locale, $pattern, $string ) : msgfmt_parse_message( $locale, $pattern, $string );
310: }
311: function ut_msgfmt_set_pattern( $fmt, $pattern )
312: {
313: return $GLOBALS['oo-mode'] ? $fmt->setPattern( $pattern ) : msgfmt_set_pattern( $fmt, $pattern );
314: }
315: function ut_msgfmt_get_pattern( $fmt )
316: {
317: return $GLOBALS['oo-mode'] ? $fmt->getPattern() : msgfmt_get_pattern( $fmt );
318: }
319: function ut_msgfmt_get_locale( $fmt )
320: {
321: return $GLOBALS['oo-mode'] ? $fmt->getLocale( ) : msgfmt_get_locale( $fmt );
322: }
323: function ut_msgfmt_get_error_code( $fmt )
324: {
325: return $GLOBALS['oo-mode'] ? $fmt->getErrorCode() : msgfmt_get_error_code( $fmt );
326: }
327: function ut_msgfmt_get_error_message( $fmt )
328: {
329: return $GLOBALS['oo-mode'] ? $fmt->getErrorMessage() : msgfmt_get_error_message( $fmt );
330: }
331: /* IntlDateFormatter functions */
332: function ut_datefmt_create( $locale, $datetype, $timetype, $timezone = null, $calendar = null ,$pattern = null)
333: {
334: return $GLOBALS['oo-mode'] ? datefmt_create( $locale, $datetype, $timetype, $timezone, $calendar ,$pattern ) : datefmt_create( $locale, $datetype, $timetype, $timezone, $calendar ,$pattern);
335: }
336: function ut_datefmt_get_datetype( $fmt )
337: {
338: return $GLOBALS['oo-mode'] ? $fmt->getDateType( ) : datefmt_get_datetype( $fmt );
339: }
340: function ut_datefmt_get_timetype( $fmt )
341: {
342: return $GLOBALS['oo-mode'] ? $fmt->getTimeType( ) : datefmt_get_timetype( $fmt );
343: }
344: function ut_datefmt_get_calendar( $fmt )
345: {
346: return $GLOBALS['oo-mode'] ? $fmt->getCalendar( ) : datefmt_get_calendar( $fmt );
347: }
348: function ut_datefmt_set_calendar( $fmt ,$calendar )
349: {
350: return $GLOBALS['oo-mode'] ? $fmt->setCalendar( $calendar ) : datefmt_set_calendar( $fmt , $calendar );
351: }
352: function ut_datefmt_get_timezone_id( $fmt )
353: {
354: return $GLOBALS['oo-mode'] ? $fmt->getTimeZoneId( ) : datefmt_get_timezone_id( $fmt );
355: }
356: function ut_datefmt_set_timezone_id( $fmt ,$timezone_id )
357: {
358: return $GLOBALS['oo-mode'] ? $fmt->setTimeZoneId( $timezone_id ) : datefmt_set_timezone_id( $fmt ,$timezone_id);
359: }
360: function ut_datefmt_get_pattern( $fmt )
361: {
362: return $GLOBALS['oo-mode'] ? $fmt->getPattern() : datefmt_get_pattern( $fmt );
363: }
364: function ut_datefmt_set_pattern( $fmt , $pattern )
365: {
366: return $GLOBALS['oo-mode'] ? $fmt->setPattern( $pattern ) : datefmt_set_pattern( $fmt , $pattern);
367: }
368: function ut_datefmt_get_locale( $fmt ,$type=ULOC_ACTUAL_LOCALE)
369: {
370: return $GLOBALS['oo-mode'] ? $fmt->getLocale($type ) : datefmt_get_locale( $fmt ,$type);
371: }
372: function ut_datefmt_is_lenient( $fmt )
373: {
374: return $GLOBALS['oo-mode'] ? $fmt->isLenient() : datefmt_is_lenient( $fmt );
375: }
376: function ut_datefmt_set_lenient( $fmt , $lenient )
377: {
378: return $GLOBALS['oo-mode'] ? $fmt->setLenient( $lenient ) : datefmt_set_lenient( $fmt , $lenient);
379: }
380: function ut_datefmt_format( $fmt , $value )
381: {
382: return $GLOBALS['oo-mode'] ? $fmt->format( $value ) : datefmt_format( $fmt , $value);
383: }
384: function ut_datefmt_parse( $fmt , $value , &$parse_pos=0 )
385: {
386: return $GLOBALS['oo-mode'] ? $fmt->parse( $value ,$parse_pos ) : datefmt_parse( $fmt , $value,$parse_pos);
387: }
388: function ut_datefmt_localtime( $fmt , $value , &$parse_pos=0 )
389: {
390: return $GLOBALS['oo-mode'] ? $fmt->localtime( $value , $parse_pos ) : datefmt_localtime( $fmt , $value , $parse_pos );
391: }
392:
393: function ut_resourcebundle_create( $locale, $bundle, $fallback=true )
394: {
395: return $GLOBALS['oo-mode'] ? new ResourceBundle($locale, $bundle, $fallback): resourcebundle_create($locale, $bundle, $fallback);
396: }
397: function ut_resourcebundle_count($bundle )
398: {
399: return $GLOBALS['oo-mode'] ? $bundle->count():resourcebundle_count($bundle);
400: }
401: function ut_resourcebundle_locales($bundle )
402: {
403: return $GLOBALS['oo-mode'] ? ResourceBundle::getLocales($bundle):resourcebundle_locales($bundle);
404: }
405: function ut_resourcebundle_get($bundle, $idx )
406: {
407: return $GLOBALS['oo-mode'] ? $bundle->get($idx):resourcebundle_get($bundle, $idx);
408: }
409: function ut_resourcebundle_get_error_code($bundle )
410: {
411: return $GLOBALS['oo-mode'] ? $bundle->getErrorCode():resourcebundle_get_error_code($bundle);
412: }
413: function ut_resourcebundle_get_error_message($bundle )
414: {
415: return $GLOBALS['oo-mode'] ? $bundle->getErrorMessage():resourcebundle_get_error_message($bundle);
416: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>