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 */ 8function 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 37function 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 46function ut_coll_create( $locale ) 47{ 48 return $GLOBALS['oo-mode'] ? Collator::create( $locale ) : collator_create( $locale ); 49} 50function ut_coll_compare( $coll, $str1, $str2 ) 51{ 52 return $GLOBALS['oo-mode'] ? $coll->compare( $str1, $str2 ) : collator_compare( $coll, $str1, $str2 ); 53} 54function 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} 58function 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} 62function ut_coll_get_sort_key( $coll, $str ) 63{ 64 return $GLOBALS['oo-mode'] ? $coll->getSortKey( $str ) : collator_get_sort_key( $coll, $str ); 65} 66function 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} 70function ut_coll_get_locale( $coll, $type ) 71{ 72 return $GLOBALS['oo-mode'] ? $coll->getLocale( $type ) : collator_get_locale( $coll, $type ); 73} 74function 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} 78function ut_coll_get_available_locales() 79{ 80 return $GLOBALS['oo-mode'] ? Collator::getAvailableLocales() : collator_get_available_locales(); 81} 82function ut_coll_get_attribute( $coll, $attr ) 83{ 84 return $GLOBALS['oo-mode'] ? $coll->getAttribute( $attr ) : collator_get_attribute( $coll, $attr ); 85} 86function ut_coll_get_strength( $coll ) 87{ 88 return $GLOBALS['oo-mode'] ? $coll->getStrength() : collator_get_strength( $coll ); 89} 90function ut_coll_set_strength( $coll, $strength ) 91{ 92 return $GLOBALS['oo-mode'] ? $coll->setStrength( $strength ) : collator_set_strength( $coll, $strength ); 93} 94function ut_coll_set_attribute( $coll, $attr, $val ) 95{ 96 return $GLOBALS['oo-mode'] ? $coll->setAttribute( $attr, $val ) : collator_set_attribute( $coll, $attr, $val ); 97} 98function ut_coll_get_variable_top( $coll ) 99{ 100 return $GLOBALS['oo-mode'] ? $coll->getVariableTop() : collator_get_variable_top( $coll ); 101} 102function 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} 106function 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} 110function ut_coll_get_error_code( $coll ) 111{ 112 return $GLOBALS['oo-mode'] ? $coll->getErrorCode() : collator_get_error_code( $coll ); 113} 114function ut_coll_get_error_message( $coll ) 115{ 116 return $GLOBALS['oo-mode'] ? $coll->getErrorMessage() : collator_get_error_message( $coll ); 117} 118function ut_coll_get_default() 119{ 120 return $GLOBALS['oo-mode'] ? Collator::getDefault() : collator_get_default(); 121} 122function 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 133function ut_nfmt_create( $locale, $style, $pattern = null ) 134{ 135 return $GLOBALS['oo-mode'] ? new NumberFormatter( $locale, $style, $pattern ) : numfmt_create( $locale, $style, $pattern ); 136} 137function ut_nfmt_format( $fmt, $number, $type = null ) 138{ 139 return $GLOBALS['oo-mode'] ? $fmt->format( $number, $type ) : numfmt_format( $fmt, $number, $type ); 140} 141function 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} 149function ut_nfmt_format_currency( $fmt, $number, $currency ) 150{ 151 return $GLOBALS['oo-mode'] ? $fmt->formatCurrency( $number, $currency ) : numfmt_format_currency( $fmt, $number, $currency ); 152} 153function 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} 161function ut_nfmt_set_attribute( $fmt, $attribute, $value ) 162{ 163 return $GLOBALS['oo-mode'] ? $fmt->setAttribute( $attribute, $value ) : numfmt_set_attribute( $fmt, $attribute, $value ); 164} 165function 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} 169function ut_nfmt_set_symbol( $fmt, $attribute, $value ) 170{ 171 return $GLOBALS['oo-mode'] ? $fmt->setSymbol( $attribute, $value ) : numfmt_set_symbol( $fmt, $attribute, $value ); 172} 173function ut_nfmt_set_pattern( $fmt, $pattern ) 174{ 175 return $GLOBALS['oo-mode'] ? $fmt->setPattern( $pattern ) : numfmt_set_pattern( $fmt, $pattern ); 176} 177function ut_nfmt_get_attribute( $fmt, $attribute ) 178{ 179 return $GLOBALS['oo-mode'] ? $fmt->getAttribute( $attribute ) : numfmt_get_attribute( $fmt, $attribute ); 180} 181function ut_nfmt_get_text_attribute( $fmt, $attribute ) 182{ 183 return $GLOBALS['oo-mode'] ? $fmt->getTextAttribute( $attribute ) : numfmt_get_text_attribute( $fmt, $attribute ); 184} 185function ut_nfmt_get_symbol( $fmt, $attribute ) 186{ 187 return $GLOBALS['oo-mode'] ? $fmt->getSymbol( $attribute ) : numfmt_get_symbol( $fmt, $attribute ); 188} 189function ut_nfmt_get_pattern( $fmt ) 190{ 191 return $GLOBALS['oo-mode'] ? $fmt->getPattern() : numfmt_get_pattern( $fmt ); 192} 193function ut_nfmt_get_locale( $fmt, $type = 0 ) 194{ 195 return $GLOBALS['oo-mode'] ? $fmt->getLocale( $type ) : numfmt_get_locale( $fmt, $type ); 196} 197function ut_nfmt_get_error_code( $fmt ) 198{ 199 return $GLOBALS['oo-mode'] ? $fmt->getErrorCode() : numfmt_get_error_code( $fmt ); 200} 201function ut_nfmt_get_error_message( $fmt ) 202{ 203 return $GLOBALS['oo-mode'] ? $fmt->getErrorMessage() : numfmt_get_error_message( $fmt ); 204} 205 206function ut_norm_normalize( $str, $form ) 207{ 208 return $GLOBALS['oo-mode'] ? Normalizer::normalize( $str, $form ) : normalizer_normalize( $str, $form ); 209} 210function 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 219function ut_loc_get_default( ) 220{ 221 return $GLOBALS['oo-mode'] ? Locale::getDefault( ) : locale_get_default(); 222} 223function ut_loc_set_default( $locale ) 224{ 225 return $GLOBALS['oo-mode'] ? Locale::setDefault( $locale ) : locale_set_default( $locale ); 226} 227function ut_loc_get_primary_language( $locale ) 228{ 229 return $GLOBALS['oo-mode'] ? Locale::getPrimaryLanguage( $locale ) : locale_get_primary_language( $locale ); 230} 231function ut_loc_get_script( $locale ) 232{ 233 return $GLOBALS['oo-mode'] ? Locale::getScript( $locale ) : locale_get_script( $locale ); 234} 235function ut_loc_get_region( $locale ) 236{ 237 return $GLOBALS['oo-mode'] ? Locale::getRegion( $locale ) : locale_get_region( $locale ); 238} 239function ut_loc_get_keywords( $locale ) 240{ 241 return $GLOBALS['oo-mode'] ? Locale::getKeywords( $locale ) : locale_get_keywords( $locale ); 242} 243function ut_loc_get_display_name( $locale , $dispLocale ) 244{ 245 return $GLOBALS['oo-mode'] ? Locale::getDisplayName( $locale , $dispLocale ) : locale_get_display_name( $locale , $dispLocale ); 246} 247function ut_loc_get_display_language( $locale , $dispLocale ) 248{ 249 return $GLOBALS['oo-mode'] ? Locale::getDisplayLanguage( $locale , $dispLocale ) : locale_get_display_language( $locale , $dispLocale ); 250} 251function ut_loc_get_display_script( $locale , $dispLocale ) 252{ 253 return $GLOBALS['oo-mode'] ? Locale::getDisplayScript( $locale , $dispLocale ) : locale_get_display_script( $locale , $dispLocale ); 254} 255function ut_loc_get_display_region( $locale, $dispLocale ) 256{ 257 return $GLOBALS['oo-mode'] ? Locale::getDisplayRegion( $locale, $dispLocale ) : locale_get_display_region( $locale, $dispLocale ); 258} 259function ut_loc_get_display_variant( $locale , $dispLocale ) 260{ 261 return $GLOBALS['oo-mode'] ? Locale::getDisplayVariant( $locale , $dispLocale ) : locale_get_display_variant( $locale, $dispLocale ); 262} 263function ut_loc_locale_compose( $loc_parts_arr ) 264{ 265 return $GLOBALS['oo-mode'] ? Locale::composeLocale( $loc_parts_arr ) : locale_compose( $loc_parts_arr ); 266} 267function ut_loc_locale_parse( $locale ) 268{ 269 return $GLOBALS['oo-mode'] ? Locale::parseLocale( $locale ) : locale_parse($locale ); 270} 271function ut_loc_locale_get_all_variants( $locale ) 272{ 273 return $GLOBALS['oo-mode'] ? Locale::getAllVariants( $locale ) : locale_get_all_variants( $locale ); 274} 275function 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} 279function ut_loc_canonicalize( $locale ) 280{ 281 return $GLOBALS['oo-mode'] ? Locale::canonicalize( $locale ) : locale_canonicalize( $locale ); 282} 283function 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} 287function ut_loc_accept_http($http) { 288 return $GLOBALS['oo-mode'] ? Locale::acceptFromHttp($http):locale_accept_from_http($http); 289} 290/* MessageFormatter functions */ 291function ut_msgfmt_create( $locale, $pattern) 292{ 293 return $GLOBALS['oo-mode'] ? MessageFormatter::create( $locale, $pattern ) : msgfmt_create( $locale, $pattern ); 294} 295function ut_msgfmt_format( $fmt, $args ) 296{ 297 return $GLOBALS['oo-mode'] ? $fmt->format( $args ) : msgfmt_format( $fmt, $args); 298} 299function ut_msgfmt_parse( $fmt, $string) 300{ 301 return $GLOBALS['oo-mode'] ? $fmt->parse( $string) : msgfmt_parse( $fmt, $string); 302} 303function 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} 307function 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} 311function ut_msgfmt_set_pattern( $fmt, $pattern ) 312{ 313 return $GLOBALS['oo-mode'] ? $fmt->setPattern( $pattern ) : msgfmt_set_pattern( $fmt, $pattern ); 314} 315function ut_msgfmt_get_pattern( $fmt ) 316{ 317 return $GLOBALS['oo-mode'] ? $fmt->getPattern() : msgfmt_get_pattern( $fmt ); 318} 319function ut_msgfmt_get_locale( $fmt ) 320{ 321 return $GLOBALS['oo-mode'] ? $fmt->getLocale( ) : msgfmt_get_locale( $fmt ); 322} 323function ut_msgfmt_get_error_code( $fmt ) 324{ 325 return $GLOBALS['oo-mode'] ? $fmt->getErrorCode() : msgfmt_get_error_code( $fmt ); 326} 327function ut_msgfmt_get_error_message( $fmt ) 328{ 329 return $GLOBALS['oo-mode'] ? $fmt->getErrorMessage() : msgfmt_get_error_message( $fmt ); 330} 331/* IntlDateFormatter functions */ 332function 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} 336function ut_datefmt_get_datetype( $fmt ) 337{ 338 return $GLOBALS['oo-mode'] ? $fmt->getDateType( ) : datefmt_get_datetype( $fmt ); 339} 340function ut_datefmt_get_timetype( $fmt ) 341{ 342 return $GLOBALS['oo-mode'] ? $fmt->getTimeType( ) : datefmt_get_timetype( $fmt ); 343} 344function ut_datefmt_get_calendar( $fmt ) 345{ 346 return $GLOBALS['oo-mode'] ? $fmt->getCalendar( ) : datefmt_get_calendar( $fmt ); 347} 348function ut_datefmt_set_calendar( $fmt ,$calendar ) 349{ 350 return $GLOBALS['oo-mode'] ? $fmt->setCalendar( $calendar ) : datefmt_set_calendar( $fmt , $calendar ); 351} 352function ut_datefmt_get_timezone_id( $fmt ) 353{ 354 return $GLOBALS['oo-mode'] ? $fmt->getTimeZoneId( ) : datefmt_get_timezone_id( $fmt ); 355} 356function 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} 360function ut_datefmt_get_pattern( $fmt ) 361{ 362 return $GLOBALS['oo-mode'] ? $fmt->getPattern() : datefmt_get_pattern( $fmt ); 363} 364function ut_datefmt_set_pattern( $fmt , $pattern ) 365{ 366 return $GLOBALS['oo-mode'] ? $fmt->setPattern( $pattern ) : datefmt_set_pattern( $fmt , $pattern); 367} 368function ut_datefmt_get_locale( $fmt ,$type=ULOC_ACTUAL_LOCALE) 369{ 370 return $GLOBALS['oo-mode'] ? $fmt->getLocale($type ) : datefmt_get_locale( $fmt ,$type); 371} 372function ut_datefmt_is_lenient( $fmt ) 373{ 374 return $GLOBALS['oo-mode'] ? $fmt->isLenient() : datefmt_is_lenient( $fmt ); 375} 376function ut_datefmt_set_lenient( $fmt , $lenient ) 377{ 378 return $GLOBALS['oo-mode'] ? $fmt->setLenient( $lenient ) : datefmt_set_lenient( $fmt , $lenient); 379} 380function ut_datefmt_format( $fmt , $value ) 381{ 382 return $GLOBALS['oo-mode'] ? $fmt->format( $value ) : datefmt_format( $fmt , $value); 383} 384function 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} 388function 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 393function ut_resourcebundle_create( $locale, $bundle, $fallback=true ) 394{ 395 return $GLOBALS['oo-mode'] ? new ResourceBundle($locale, $bundle, $fallback): resourcebundle_create($locale, $bundle, $fallback); 396} 397function ut_resourcebundle_count($bundle ) 398{ 399 return $GLOBALS['oo-mode'] ? $bundle->count():resourcebundle_count($bundle); 400} 401function ut_resourcebundle_locales($bundle ) 402{ 403 return $GLOBALS['oo-mode'] ? ResourceBundle::getLocales($bundle):resourcebundle_locales($bundle); 404} 405function ut_resourcebundle_get($bundle, $idx ) 406{ 407 return $GLOBALS['oo-mode'] ? $bundle->get($idx):resourcebundle_get($bundle, $idx); 408} 409function ut_resourcebundle_get_error_code($bundle ) 410{ 411 return $GLOBALS['oo-mode'] ? $bundle->getErrorCode():resourcebundle_get_error_code($bundle); 412} 413function ut_resourcebundle_get_error_message($bundle ) 414{ 415 return $GLOBALS['oo-mode'] ? $bundle->getErrorMessage():resourcebundle_get_error_message($bundle); 416} 417