2000-01-15 02:00:06 +00:00
/********************************************************************
2003-12-03 00:25:25 +00:00
* COPYRIGHT :
2007-03-06 01:15:14 +00:00
* Copyright ( c ) 1997 - 2007 , International Business Machines Corporation and
2000-01-15 02:00:06 +00:00
* others . All Rights Reserved .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1999-08-16 21:50:52 +00:00
# include "loctest.h"
1999-12-28 23:57:50 +00:00
# include "unicode/decimfmt.h"
2003-06-25 00:04:49 +00:00
# include "unicode/ucurr.h"
1999-12-28 23:57:50 +00:00
# include "unicode/smpdtfmt.h"
2004-01-23 18:05:46 +00:00
# include "unicode/dtfmtsym.h"
# include "unicode/brkiter.h"
# include "unicode/coll.h"
# include "cstring.h"
2006-06-26 19:01:38 +00:00
# include <stdio.h>
1999-08-16 21:50:52 +00:00
2006-10-01 06:45:25 +00:00
static const char * const rawData [ 33 ] [ 8 ] = {
2000-04-15 21:28:17 +00:00
// language code
2004-01-08 00:56:21 +00:00
{ " en " , " fr " , " ca " , " el " , " no " , " it " , " xx " , " zh " } ,
// script code
{ " " , " " , " " , " " , " " , " " , " " , " Hans " } ,
2000-04-15 21:28:17 +00:00
// country code
2004-01-08 00:56:21 +00:00
{ " US " , " FR " , " ES " , " GR " , " NO " , " " , " YY " , " CN " } ,
2000-04-15 21:28:17 +00:00
// variant code
2004-01-08 00:56:21 +00:00
{ " " , " " , " " , " " , " NY " , " " , " " , " " } ,
2000-04-15 21:28:17 +00:00
// full name
2004-01-08 00:56:21 +00:00
{ " en_US " , " fr_FR " , " ca_ES " , " el_GR " , " no_NO_NY " , " it " , " xx_YY " , " zh_Hans_CN " } ,
2000-04-15 21:28:17 +00:00
// ISO-3 language
2004-01-08 00:56:21 +00:00
{ " eng " , " fra " , " cat " , " ell " , " nor " , " ita " , " " , " zho " } ,
2000-04-15 21:28:17 +00:00
// ISO-3 country
2004-01-08 00:56:21 +00:00
{ " USA " , " FRA " , " ESP " , " GRC " , " NOR " , " " , " " , " CHN " } ,
2003-07-26 00:07:49 +00:00
// LCID
2004-01-08 00:56:21 +00:00
{ " 409 " , " 40c " , " 403 " , " 408 " , " 814 " , " 10 " , " 0 " , " 804 " } ,
2000-04-15 21:28:17 +00:00
// display langage (English)
2004-01-08 00:56:21 +00:00
{ " English " , " French " , " Catalan " , " Greek " , " Norwegian " , " Italian " , " xx " , " Chinese " } ,
// display script (English)
{ " " , " " , " " , " " , " " , " " , " " , " Simplified Han " } ,
2000-04-15 21:28:17 +00:00
// display country (English)
2004-01-08 00:56:21 +00:00
{ " United States " , " France " , " Spain " , " Greece " , " Norway " , " " , " YY " , " China " } ,
2000-04-15 21:28:17 +00:00
// display variant (English)
2004-01-08 00:56:21 +00:00
{ " " , " " , " " , " " , " NY " , " " , " " , " " } ,
2000-04-15 21:28:17 +00:00
// display name (English)
// Updated no_NO_NY English display name for new pattern-based algorithm
// (part of Euro support).
2004-01-08 00:56:21 +00:00
{ " English (United States) " , " French (France) " , " Catalan (Spain) " , " Greek (Greece) " , " Norwegian (Norway, NY) " , " Italian " , " xx (YY) " , " Chinese (Simplified Han, China) " } ,
2000-04-15 21:28:17 +00:00
// display langage (French)
2004-01-08 00:56:21 +00:00
{ " anglais " , " fran \\ u00E7ais " , " catalan " , " grec " , " norv \\ u00E9gien " , " italien " , " xx " , " chinois " } ,
// display script (French)
2006-06-26 22:41:29 +00:00
{ " " , " " , " " , " " , " " , " " , " " , " id \\ u00E9ogrammes han (variante simplifi \\ u00E9e) " } ,
2000-04-15 21:28:17 +00:00
// display country (French)
2004-01-08 00:56:21 +00:00
{ " \\ u00C9tats-Unis " , " France " , " Espagne " , " Gr \\ u00E8ce " , " Norv \\ u00E8ge " , " " , " YY " , " Chine " } ,
2000-04-15 21:28:17 +00:00
// display variant (French)
2004-01-08 00:56:21 +00:00
{ " " , " " , " " , " " , " NY " , " " , " " , " " } ,
2000-04-15 21:28:17 +00:00
// display name (French)
2004-11-12 01:11:27 +00:00
//{ "anglais (Etats-Unis)", "francais (France)", "catalan (Espagne)", "grec (Grece)", "norvegien (Norvege,Nynorsk)", "italien", "xx (YY)" },
2006-06-26 22:41:29 +00:00
{ " anglais ( \\ u00C9tats-Unis) " , " fran \\ u00E7ais (France) " , " catalan (Espagne) " , " grec (Gr \\ u00E8ce) " , " norv \\ u00E9gien (Norv \\ u00E8ge, NY) " , " italien " , " xx (YY) " , " chinois (id \\ u00E9ogrammes han (variante simplifi \\ u00E9e), Chine) " } , // STILL not right
2003-07-26 00:07:49 +00:00
2003-10-01 21:13:37 +00:00
/* display language (Catalan) */
2004-01-08 00:56:21 +00:00
{ " angl \\ u00E8s " , " franc \\ u00E8s " , " catal \\ u00E0 " , " grec " , " noruec " , " itali \\ u00E0 " , " " , " xin \\ u00E9s " } ,
/* display script (Catalan) */
{ " " , " " , " " , " " , " " , " " , " " , " Hans " } ,
2003-10-01 21:13:37 +00:00
/* display country (Catalan) */
2004-01-08 00:56:21 +00:00
{ " Estats Units " , " Fran \\ u00E7a " , " Espanya " , " Gr \\ u00E8cia " , " Noruega " , " " , " " , " Xina " } ,
2003-10-01 21:13:37 +00:00
/* display variant (Catalan) */
2004-01-08 00:56:21 +00:00
{ " " , " " , " " , " " , " NY " , " " , " " } ,
2003-10-01 21:13:37 +00:00
/* display name (Catalan) */
2004-01-08 00:56:21 +00:00
{ " angl \\ u00E8s (Estats Units) " , " franc \\ u00E8s (Fran \\ u00E7a) " , " catal \\ u00E0 (Espanya) " , " grec (Gr \\ u00E8cia) " , " noruec (Noruega, NY) " , " itali \\ u00E0 " , " " , " xin \\ u00E9s (Hans, Xina) " } ,
2000-04-15 21:28:17 +00:00
// display langage (Greek)[actual values listed below]
2007-06-22 23:57:38 +00:00
{ " \\ u0391 \\ u03b3 \\ u03b3 \\ u03bb \\ u03b9 \\ u03ba \\ u03ac " ,
" \\ u0393 \\ u03b1 \\ u03bb \\ u03bb \\ u03b9 \\ u03ba \\ u03ac " ,
" \\ u039a \\ u03b1 \\ u03c4 \\ u03b1 \\ u03bb \\ u03b1 \\ u03bd \\ u03b9 \\ u03ba \\ u03ac " ,
" \\ u0395 \\ u03bb \\ u03bb \\ u03b7 \\ u03bd \\ u03b9 \\ u03ba \\ u03ac " ,
" \\ u039d \\ u03bf \\ u03c1 \\ u03b2 \\ u03b7 \\ u03b3 \\ u03b9 \\ u03ba \\ u03ac " ,
" \\ u0399 \\ u03c4 \\ u03b1 \\ u03bb \\ u03b9 \\ u03ba \\ u03ac " ,
2003-07-26 00:07:49 +00:00
" " ,
2007-06-22 23:57:38 +00:00
" \\ u039A \\ u03B9 \\ u03BD \\ u03B5 \\ u03B6 \\ u03B9 \\ u03BA \\ u03AC "
2003-07-26 00:07:49 +00:00
} ,
2004-01-08 00:56:21 +00:00
// display script (Greek)
2007-06-22 23:57:38 +00:00
{ " " , " " , " " , " " , " " , " " , " " , " \\ u039a \\ u03b9 \\ u03bd \\ u03b5 \\ u03b6 \\ u03b9 \\ u03ba \\ u03cc \\ u0391 \\ u03c0 \\ u03bb \\ u03bf \\ u03c0 \\ u03bf \\ u03b9 \\ u03b7 \\ u03bc \\ u03ad \\ u03bd \\ u03bf " } ,
2000-04-15 21:28:17 +00:00
// display country (Greek)[actual values listed below]
2003-07-26 00:07:49 +00:00
{ " \\ u0397 \\ u03BD \\ u03C9 \\ u03BC \\ u03AD \\ u03BD \\ u03B5 \\ u03C2 \\ u03A0 \\ u03BF \\ u03BB \\ u03B9 \\ u03C4 \\ u03B5 \\ u03AF \\ u03B5 \\ u03C2 " ,
" \\ u0393 \\ u03b1 \\ u03bb \\ u03bb \\ u03af \\ u03b1 " ,
" \\ u0399 \\ u03c3 \\ u03c0 \\ u03b1 \\ u03bd \\ u03af \\ u03b1 " ,
" \\ u0395 \\ u03bb \\ u03bb \\ u03ac \\ u03b4 \\ u03b1 " ,
" \\ u039d \\ u03bf \\ u03c1 \\ u03b2 \\ u03b7 \\ u03b3 \\ u03af \\ u03b1 " ,
" " ,
2004-01-08 00:56:21 +00:00
" " ,
" \\ u039A \\ u03AF \\ u03BD \\ u03B1 "
2003-07-26 00:07:49 +00:00
} ,
2000-04-15 21:28:17 +00:00
// display variant (Greek)
2004-01-08 00:56:21 +00:00
{ " " , " " , " " , " " , " NY " , " " , " " } ,
2000-04-15 21:28:17 +00:00
// display name (Greek)[actual values listed below]
2007-06-22 23:57:38 +00:00
{ " \\ u0391 \\ u03b3 \\ u03b3 \\ u03bb \\ u03b9 \\ u03ba \\ u03ac ( \\ u0397 \\ u03BD \\ u03C9 \\ u03BC \\ u03AD \\ u03BD \\ u03B5 \\ u03C2 \\ u03A0 \\ u03BF \\ u03BB \\ u03B9 \\ u03C4 \\ u03B5 \\ u03AF \\ u03B5 \\ u03C2) " ,
" \\ u0393 \\ u03b1 \\ u03bb \\ u03bb \\ u03b9 \\ u03ba \\ u03ac ( \\ u0393 \\ u03b1 \\ u03bb \\ u03bb \\ u03af \\ u03b1) " ,
" \\ u039a \\ u03b1 \\ u03c4 \\ u03b1 \\ u03bb \\ u03b1 \\ u03bd \\ u03b9 \\ u03ba \\ u03ac ( \\ u0399 \\ u03c3 \\ u03c0 \\ u03b1 \\ u03bd \\ u03af \\ u03b1) " ,
" \\ u0395 \\ u03bb \\ u03bb \\ u03b7 \\ u03bd \\ u03b9 \\ u03ba \\ u03ac ( \\ u0395 \\ u03bb \\ u03bb \\ u03ac \\ u03b4 \\ u03b1) " ,
" \\ u039d \\ u03bf \\ u03c1 \\ u03b2 \\ u03b7 \\ u03b3 \\ u03b9 \\ u03ba \\ u03ac ( \\ u039d \\ u03bf \\ u03c1 \\ u03b2 \\ u03b7 \\ u03b3 \\ u03af \\ u03b1, NY) " ,
" \\ u0399 \\ u03c4 \\ u03b1 \\ u03bb \\ u03b9 \\ u03ba \\ u03ac " ,
2003-07-26 00:07:49 +00:00
" " ,
2007-06-22 23:57:38 +00:00
" \\ u039A \\ u03B9 \\ u03BD \\ u03B5 \\ u03B6 \\ u03B9 \\ u03BA \\ u03AC ( \\ u039a \\ u03b9 \\ u03bd \\ u03b5 \\ u03b6 \\ u03b9 \\ u03ba \\ u03cc \\ u0391 \\ u03c0 \\ u03bb \\ u03bf \\ u03c0 \\ u03bf \\ u03b9 \\ u03b7 \\ u03bc \\ u03ad \\ u03bd \\ u03bf, \\ u039A \\ u03AF \\ u03BD \\ u03B1) "
2003-07-26 00:07:49 +00:00
} ,
2000-04-15 21:28:17 +00:00
// display langage (<root>)
2004-01-08 00:56:21 +00:00
{ " English " , " French " , " Catalan " , " Greek " , " Norwegian " , " Italian " , " xx " , " " } ,
// display script (<root>)
{ " " , " " , " " , " " , " " , " " , " " , " " } ,
2000-04-15 21:28:17 +00:00
// display country (<root>)
2004-01-08 00:56:21 +00:00
{ " United States " , " France " , " Spain " , " Greece " , " Norway " , " " , " YY " , " " } ,
2000-04-15 21:28:17 +00:00
// display variant (<root>)
2004-01-08 00:56:21 +00:00
{ " " , " " , " " , " " , " Nynorsk " , " " , " " , " " } ,
2000-04-15 21:28:17 +00:00
// display name (<root>)
2003-07-26 00:07:49 +00:00
//{ "English (United States)", "French (France)", "Catalan (Spain)", "Greek (Greece)", "Norwegian (Norway,Nynorsk)", "Italian", "xx (YY)" },
2004-01-08 00:56:21 +00:00
{ " English (United States) " , " French (France) " , " Catalan (Spain) " , " Greek (Greece) " , " Norwegian (Norway,NY) " , " Italian " , " xx (YY) " , " " }
2000-04-15 21:28:17 +00:00
} ;
2006-07-06 01:50:03 +00:00
1999-08-16 21:50:52 +00:00
/*
Usage :
2006-07-06 01:50:03 +00:00
test_assert ( Test ( should be TRUE ) )
1999-08-16 21:50:52 +00:00
Example :
2006-07-06 01:50:03 +00:00
test_assert ( i = = 3 ) ;
1999-08-16 21:50:52 +00:00
2006-07-06 01:50:03 +00:00
the macro is ugly but makes the tests pretty .
1999-08-16 21:50:52 +00:00
*/
2006-07-06 01:50:03 +00:00
# define test_assert(test) \
1999-08-16 21:50:52 +00:00
{ \
2006-07-06 01:50:03 +00:00
if ( ! ( test ) ) \
errln ( " FAIL: " # test " was not true. In " __FILE__ " on line %d " , __LINE__ ) ; \
1999-08-16 21:50:52 +00:00
else \
2006-07-06 01:50:03 +00:00
logln ( " PASS: asserted " # test ) ; \
1999-08-16 21:50:52 +00:00
}
/*
Usage :
test_assert_print ( Test ( should be TRUE ) , printable )
Example :
test_assert ( i = = 3 , toString ( i ) ) ;
the macro is ugly but makes the tests pretty .
*/
# define test_assert_print(test,print) \
{ \
if ( ! ( test ) ) \
2006-07-06 01:50:03 +00:00
errln ( " FAIL: " # test " was not true. " + UnicodeString ( print ) ) ; \
1999-08-16 21:50:52 +00:00
else \
2006-07-06 01:50:03 +00:00
logln ( " PASS: asserted " # test " -> " + UnicodeString ( print ) ) ; \
1999-08-16 21:50:52 +00:00
}
2006-07-06 01:50:03 +00:00
# define test_dumpLocale(l) { logln(#l " = " + UnicodeString(l.getName(), "")); }
1999-08-16 21:50:52 +00:00
LocaleTest : : LocaleTest ( )
2001-10-04 16:36:32 +00:00
: dataTable ( NULL )
1999-08-16 21:50:52 +00:00
{
setUpDataTable ( ) ;
}
LocaleTest : : ~ LocaleTest ( )
{
2001-10-04 16:36:32 +00:00
if ( dataTable ! = 0 ) {
2004-01-08 00:56:21 +00:00
for ( int32_t i = 0 ; i < 33 ; i + + ) {
2001-10-04 16:36:32 +00:00
delete [ ] dataTable [ i ] ;
}
delete [ ] dataTable ;
dataTable = 0 ;
}
1999-08-16 21:50:52 +00:00
}
2000-08-23 19:11:16 +00:00
void LocaleTest : : runIndexedTest ( int32_t index , UBool exec , const char * & name , char * /*par*/ )
1999-08-16 21:50:52 +00:00
{
switch ( index ) {
2004-01-23 18:05:46 +00:00
TESTCASE ( 0 , TestBasicGetters ) ;
TESTCASE ( 1 , TestSimpleResourceInfo ) ;
TESTCASE ( 2 , TestDisplayNames ) ;
TESTCASE ( 3 , TestSimpleObjectStuff ) ;
TESTCASE ( 4 , TestPOSIXParsing ) ;
TESTCASE ( 5 , TestGetAvailableLocales ) ;
TESTCASE ( 6 , TestDataDirectory ) ;
TESTCASE ( 7 , TestISO3Fallback ) ;
TESTCASE ( 8 , TestGetLangsAndCountries ) ;
TESTCASE ( 9 , TestSimpleDisplayNames ) ;
TESTCASE ( 10 , TestUninstalledISO3Names ) ;
TESTCASE ( 11 , TestAtypicalLocales ) ;
2002-09-21 00:43:14 +00:00
# if !UCONFIG_NO_FORMATTING
2004-01-23 18:05:46 +00:00
TESTCASE ( 12 , TestThaiCurrencyFormat ) ;
TESTCASE ( 13 , TestEuroSupport ) ;
2002-09-21 00:43:14 +00:00
# endif
2004-01-23 18:05:46 +00:00
TESTCASE ( 14 , TestToString ) ;
2002-09-21 00:43:14 +00:00
# if !UCONFIG_NO_FORMATTING
2004-01-23 18:05:46 +00:00
TESTCASE ( 15 , Test4139940 ) ;
TESTCASE ( 16 , Test4143951 ) ;
2002-09-21 00:43:14 +00:00
# endif
2004-01-23 18:05:46 +00:00
TESTCASE ( 17 , Test4147315 ) ;
TESTCASE ( 18 , Test4147317 ) ;
TESTCASE ( 19 , Test4147552 ) ;
TESTCASE ( 20 , TestVariantParsing ) ;
2002-09-21 00:43:14 +00:00
# if !UCONFIG_NO_FORMATTING
2004-01-23 18:05:46 +00:00
TESTCASE ( 21 , Test4105828 ) ;
2002-09-21 00:43:14 +00:00
# endif
2004-01-23 18:05:46 +00:00
TESTCASE ( 22 , TestSetIsBogus ) ;
TESTCASE ( 23 , TestParallelAPIValues ) ;
TESTCASE ( 24 , TestKeywordVariants ) ;
TESTCASE ( 25 , TestKeywordVariantParsing ) ;
TESTCASE ( 26 , TestGetBaseName ) ;
TESTCASE ( 27 , TestGetLocale ) ;
2004-03-07 07:13:42 +00:00
TESTCASE ( 28 , TestVariantWithOutCountry ) ;
2004-05-18 20:07:33 +00:00
TESTCASE ( 29 , TestCanonicalization ) ;
2003-10-15 05:32:40 +00:00
2002-09-21 00:43:14 +00:00
// keep the last index in sync with the condition in default:
1999-08-16 21:50:52 +00:00
2002-09-21 00:43:14 +00:00
default :
2004-03-07 07:13:42 +00:00
if ( index < = 28 ) { // keep this in sync with the last index!
2004-01-23 18:05:46 +00:00
name = " (test omitted by !UCONFIG_NO_FORMATTING) " ;
2002-09-21 00:43:14 +00:00
} else {
name = " " ;
}
break ; //needed to end loop
1999-08-16 21:50:52 +00:00
}
}
void LocaleTest : : TestBasicGetters ( ) {
UnicodeString temp ;
int32_t i ;
for ( i = 0 ; i < = MAX_LOCALES ; i + + ) {
2004-01-08 00:56:21 +00:00
Locale testLocale ( " " ) ;
if ( rawData [ SCRIPT ] [ i ] & & rawData [ SCRIPT ] [ i ] [ 0 ] ! = 0 ) {
testLocale = Locale ( rawData [ LANG ] [ i ] , rawData [ SCRIPT ] [ i ] , rawData [ CTRY ] [ i ] , rawData [ VAR ] [ i ] ) ;
}
else {
testLocale = Locale ( rawData [ LANG ] [ i ] , rawData [ CTRY ] [ i ] , rawData [ VAR ] [ i ] ) ;
}
2000-04-15 21:28:17 +00:00
logln ( " Testing " + ( UnicodeString ) testLocale . getName ( ) + " ... " ) ;
1999-08-16 21:50:52 +00:00
2000-04-15 21:28:17 +00:00
if ( ( temp = testLocale . getLanguage ( ) ) ! = ( dataTable [ LANG ] [ i ] ) )
1999-08-16 21:50:52 +00:00
errln ( " Language code mismatch: " + temp + " versus "
+ dataTable [ LANG ] [ i ] ) ;
2004-01-08 00:56:21 +00:00
if ( ( temp = testLocale . getScript ( ) ) ! = ( dataTable [ SCRIPT ] [ i ] ) )
errln ( " Script code mismatch: " + temp + " versus "
+ dataTable [ SCRIPT ] [ i ] ) ;
2000-04-15 21:28:17 +00:00
if ( ( temp = testLocale . getCountry ( ) ) ! = ( dataTable [ CTRY ] [ i ] ) )
1999-08-16 21:50:52 +00:00
errln ( " Country code mismatch: " + temp + " versus "
+ dataTable [ CTRY ] [ i ] ) ;
2000-04-15 21:28:17 +00:00
if ( ( temp = testLocale . getVariant ( ) ) ! = ( dataTable [ VAR ] [ i ] ) )
1999-08-16 21:50:52 +00:00
errln ( " Variant code mismatch: " + temp + " versus "
+ dataTable [ VAR ] [ i ] ) ;
2000-04-15 21:28:17 +00:00
if ( ( temp = testLocale . getName ( ) ) ! = ( dataTable [ NAME ] [ i ] ) )
1999-08-16 21:50:52 +00:00
errln ( " Locale name mismatch: " + temp + " versus "
+ dataTable [ NAME ] [ i ] ) ;
}
logln ( " Same thing without variant codes... " ) ;
for ( i = 0 ; i < = MAX_LOCALES ; i + + ) {
2004-01-08 00:56:21 +00:00
Locale testLocale ( " " ) ;
if ( rawData [ SCRIPT ] [ i ] & & rawData [ SCRIPT ] [ i ] [ 0 ] ! = 0 ) {
testLocale = Locale ( rawData [ LANG ] [ i ] , rawData [ SCRIPT ] [ i ] , rawData [ CTRY ] [ i ] ) ;
}
else {
testLocale = Locale ( rawData [ LANG ] [ i ] , rawData [ CTRY ] [ i ] ) ;
}
2000-04-15 21:28:17 +00:00
logln ( " Testing " + ( temp = testLocale . getName ( ) ) + " ... " ) ;
1999-08-16 21:50:52 +00:00
2000-04-15 21:28:17 +00:00
if ( ( temp = testLocale . getLanguage ( ) ) ! = ( dataTable [ LANG ] [ i ] ) )
2004-01-08 21:14:31 +00:00
errln ( " Language code mismatch: " + temp + " versus "
1999-08-16 21:50:52 +00:00
+ dataTable [ LANG ] [ i ] ) ;
2004-01-08 00:56:21 +00:00
if ( ( temp = testLocale . getScript ( ) ) ! = ( dataTable [ SCRIPT ] [ i ] ) )
2004-01-08 21:14:31 +00:00
errln ( " Script code mismatch: " + temp + " versus "
2004-01-08 00:56:21 +00:00
+ dataTable [ SCRIPT ] [ i ] ) ;
2000-04-15 21:28:17 +00:00
if ( ( temp = testLocale . getCountry ( ) ) ! = ( dataTable [ CTRY ] [ i ] ) )
2004-01-08 21:14:31 +00:00
errln ( " Country code mismatch: " + temp + " versus "
1999-08-16 21:50:52 +00:00
+ dataTable [ CTRY ] [ i ] ) ;
2000-04-15 21:28:17 +00:00
if ( testLocale . getVariant ( ) [ 0 ] ! = 0 )
2004-01-08 21:14:31 +00:00
errln ( " Variant code mismatch: something versus \" \" " ) ;
1999-08-16 21:50:52 +00:00
}
2002-03-26 23:18:57 +00:00
2001-03-15 07:09:09 +00:00
logln ( " Testing long language names and getters " ) ;
2004-01-08 21:14:31 +00:00
Locale test8 = Locale : : createFromName ( " x-klingon-latn-zx.utf32be@special " ) ;
2001-03-15 07:09:09 +00:00
temp = test8 . getLanguage ( ) ;
if ( temp ! = UnicodeString ( " x-klingon " ) )
2004-01-08 21:14:31 +00:00
errln ( " Language code mismatch: " + temp + " versus \" x-klingon \" " ) ;
temp = test8 . getScript ( ) ;
if ( temp ! = UnicodeString ( " Latn " ) )
errln ( " Script code mismatch: " + temp + " versus \" Latn \" " ) ;
2001-03-15 07:09:09 +00:00
temp = test8 . getCountry ( ) ;
if ( temp ! = UnicodeString ( " ZX " ) )
2004-01-08 21:14:31 +00:00
errln ( " Country code mismatch: " + temp + " versus \" ZX \" " ) ;
2001-03-15 07:09:09 +00:00
temp = test8 . getVariant ( ) ;
2004-05-14 22:45:27 +00:00
//if (temp != UnicodeString("SPECIAL") )
// errln("Variant code mismatch: " + temp + " versus \"SPECIAL\"");
// As of 3.0, the "@special" will *not* be parsed by uloc_getName()
if ( temp ! = UnicodeString ( " " ) )
errln ( " Variant code mismatch: " + temp + " versus \" \" " ) ;
2001-03-15 07:09:09 +00:00
2001-08-18 00:15:44 +00:00
if ( Locale : : getDefault ( ) ! = Locale : : createFromName ( NULL ) )
2004-01-08 00:56:21 +00:00
errln ( " Locale::getDefault() == Locale::createFromName(NULL) " ) ;
2001-03-15 07:09:09 +00:00
2000-08-02 21:00:23 +00:00
/*----------*/
1999-08-16 21:50:52 +00:00
// NOTE: There used to be a special test for locale names that had language or
// country codes that were longer than two letters. The new version of Locale
// doesn't support anything that isn't an officially recognized language or
// country code, so we no longer support this feature.
2003-05-14 00:42:21 +00:00
Locale bogusLang ( " THISISABOGUSLANGUAGE " ) ; // Jitterbug 2864: language code too long
if ( ! bogusLang . isBogus ( ) ) {
errln ( " Locale( \" THISISABOGUSLANGUAGE \" ).isBogus()==FALSE " ) ;
}
bogusLang = Locale ( " eo " ) ;
if ( bogusLang . isBogus ( ) | |
strcmp ( bogusLang . getLanguage ( ) , " eo " ) ! = 0 | |
* bogusLang . getCountry ( ) ! = 0 | |
* bogusLang . getVariant ( ) ! = 0 | |
strcmp ( bogusLang . getName ( ) , " eo " ) ! = 0
) {
errln ( " assignment to bogus Locale does not unbogus it or sets bad data " ) ;
}
2003-11-05 02:06:36 +00:00
Locale a ( " eo_DE@currency=DEM " ) ;
Locale * pb = a . clone ( ) ;
if ( pb = = & a | | * pb ! = a ) {
errln ( " Locale.clone() failed " ) ;
}
delete pb ;
1999-08-16 21:50:52 +00:00
}
2002-03-26 23:18:57 +00:00
void LocaleTest : : TestParallelAPIValues ( ) {
logln ( " Test synchronization between C and C++ API " ) ;
if ( strcmp ( Locale : : getChinese ( ) . getName ( ) , ULOC_CHINESE ) ! = 0 ) {
errln ( " Differences for ULOC_CHINESE Locale " ) ;
}
if ( strcmp ( Locale : : getEnglish ( ) . getName ( ) , ULOC_ENGLISH ) ! = 0 ) {
errln ( " Differences for ULOC_ENGLISH Locale " ) ;
}
if ( strcmp ( Locale : : getFrench ( ) . getName ( ) , ULOC_FRENCH ) ! = 0 ) {
errln ( " Differences for ULOC_FRENCH Locale " ) ;
}
if ( strcmp ( Locale : : getGerman ( ) . getName ( ) , ULOC_GERMAN ) ! = 0 ) {
errln ( " Differences for ULOC_GERMAN Locale " ) ;
}
if ( strcmp ( Locale : : getItalian ( ) . getName ( ) , ULOC_ITALIAN ) ! = 0 ) {
errln ( " Differences for ULOC_ITALIAN Locale " ) ;
}
if ( strcmp ( Locale : : getJapanese ( ) . getName ( ) , ULOC_JAPANESE ) ! = 0 ) {
errln ( " Differences for ULOC_JAPANESE Locale " ) ;
}
if ( strcmp ( Locale : : getKorean ( ) . getName ( ) , ULOC_KOREAN ) ! = 0 ) {
errln ( " Differences for ULOC_KOREAN Locale " ) ;
}
if ( strcmp ( Locale : : getSimplifiedChinese ( ) . getName ( ) , ULOC_SIMPLIFIED_CHINESE ) ! = 0 ) {
errln ( " Differences for ULOC_SIMPLIFIED_CHINESE Locale " ) ;
}
if ( strcmp ( Locale : : getTraditionalChinese ( ) . getName ( ) , ULOC_TRADITIONAL_CHINESE ) ! = 0 ) {
errln ( " Differences for ULOC_TRADITIONAL_CHINESE Locale " ) ;
}
if ( strcmp ( Locale : : getCanada ( ) . getName ( ) , ULOC_CANADA ) ! = 0 ) {
errln ( " Differences for ULOC_CANADA Locale " ) ;
}
if ( strcmp ( Locale : : getCanadaFrench ( ) . getName ( ) , ULOC_CANADA_FRENCH ) ! = 0 ) {
errln ( " Differences for ULOC_CANADA_FRENCH Locale " ) ;
}
if ( strcmp ( Locale : : getChina ( ) . getName ( ) , ULOC_CHINA ) ! = 0 ) {
errln ( " Differences for ULOC_CHINA Locale " ) ;
}
if ( strcmp ( Locale : : getPRC ( ) . getName ( ) , ULOC_PRC ) ! = 0 ) {
errln ( " Differences for ULOC_PRC Locale " ) ;
}
if ( strcmp ( Locale : : getFrance ( ) . getName ( ) , ULOC_FRANCE ) ! = 0 ) {
errln ( " Differences for ULOC_FRANCE Locale " ) ;
}
if ( strcmp ( Locale : : getGermany ( ) . getName ( ) , ULOC_GERMANY ) ! = 0 ) {
errln ( " Differences for ULOC_GERMANY Locale " ) ;
}
if ( strcmp ( Locale : : getItaly ( ) . getName ( ) , ULOC_ITALY ) ! = 0 ) {
errln ( " Differences for ULOC_ITALY Locale " ) ;
}
if ( strcmp ( Locale : : getJapan ( ) . getName ( ) , ULOC_JAPAN ) ! = 0 ) {
errln ( " Differences for ULOC_JAPAN Locale " ) ;
}
if ( strcmp ( Locale : : getKorea ( ) . getName ( ) , ULOC_KOREA ) ! = 0 ) {
errln ( " Differences for ULOC_KOREA Locale " ) ;
}
if ( strcmp ( Locale : : getTaiwan ( ) . getName ( ) , ULOC_TAIWAN ) ! = 0 ) {
errln ( " Differences for ULOC_TAIWAN Locale " ) ;
}
if ( strcmp ( Locale : : getUK ( ) . getName ( ) , ULOC_UK ) ! = 0 ) {
errln ( " Differences for ULOC_UK Locale " ) ;
}
if ( strcmp ( Locale : : getUS ( ) . getName ( ) , ULOC_US ) ! = 0 ) {
errln ( " Differences for ULOC_US Locale " ) ;
}
}
1999-08-16 21:50:52 +00:00
void LocaleTest : : TestSimpleResourceInfo ( ) {
2004-01-08 00:56:21 +00:00
UnicodeString temp ;
char temp2 [ 20 ] ;
UErrorCode err = U_ZERO_ERROR ;
int32_t i = 0 ;
for ( i = 0 ; i < = MAX_LOCALES ; i + + ) {
Locale testLocale ( rawData [ LANG ] [ i ] , rawData [ CTRY ] [ i ] , rawData [ VAR ] [ i ] ) ;
logln ( " Testing " + ( temp = testLocale . getName ( ) ) + " ... " ) ;
if ( ( temp = testLocale . getISO3Language ( ) ) ! = ( dataTable [ LANG3 ] [ i ] ) )
errln ( " ISO-3 language code mismatch: " + temp
+ " versus " + dataTable [ LANG3 ] [ i ] ) ;
if ( ( temp = testLocale . getISO3Country ( ) ) ! = ( dataTable [ CTRY3 ] [ i ] ) )
errln ( " ISO-3 country code mismatch: " + temp
+ " versus " + dataTable [ CTRY3 ] [ i ] ) ;
2004-05-30 09:58:45 +00:00
sprintf ( temp2 , " %x " , ( int ) testLocale . getLCID ( ) ) ;
2004-01-08 00:56:21 +00:00
if ( UnicodeString ( temp2 ) ! = dataTable [ LCID ] [ i ] )
errln ( ( UnicodeString ) " LCID mismatch: " + temp2 + " versus "
+ dataTable [ LCID ] [ i ] ) ;
if ( U_FAILURE ( err ) )
{
errln ( ( UnicodeString ) " Some error on number " + i + u_errorName ( err ) ) ;
}
err = U_ZERO_ERROR ;
}
Locale locale ( " en " ) ;
if ( strcmp ( locale . getName ( ) , " en " ) ! = 0 | |
strcmp ( locale . getLanguage ( ) , " en " ) ! = 0 ) {
errln ( " construction of Locale(en) failed \n " ) ;
}
/*-----*/
2000-08-02 21:00:23 +00:00
1999-08-16 21:50:52 +00:00
}
2003-04-25 22:56:51 +00:00
/*
* Jitterbug 2439 - - markus 20030425
*
* The lookup of display names must not fall back through the default
* locale because that yields useless results .
*/
2003-12-03 00:25:25 +00:00
void
LocaleTest : : TestDisplayNames ( )
1999-08-16 21:50:52 +00:00
{
Locale english ( " en " , " US " ) ;
Locale french ( " fr " , " FR " ) ;
2003-07-26 00:07:49 +00:00
Locale croatian ( " ca " , " ES " ) ;
1999-08-16 21:50:52 +00:00
Locale greek ( " el " , " GR " ) ;
logln ( " In locale = en_US... " ) ;
2003-04-25 22:56:51 +00:00
doTestDisplayNames ( english , DLANG_EN ) ;
1999-08-16 21:50:52 +00:00
logln ( " In locale = fr_FR... " ) ;
2003-04-25 22:56:51 +00:00
doTestDisplayNames ( french , DLANG_FR ) ;
2003-07-26 00:07:49 +00:00
logln ( " In locale = ca_ES... " ) ;
doTestDisplayNames ( croatian , DLANG_CA ) ;
1999-08-16 21:50:52 +00:00
logln ( " In locale = el_GR... " ) ;
2003-04-25 22:56:51 +00:00
doTestDisplayNames ( greek , DLANG_EL ) ;
1999-08-16 21:50:52 +00:00
2003-04-25 22:56:51 +00:00
UnicodeString s ;
2006-11-07 17:14:12 +00:00
UErrorCode status = U_ZERO_ERROR ;
DecimalFormatSymbols symb ( status ) ;
/* Check to see if ICU supports this locale */
if ( symb . getLocale ( ULOC_VALID_LOCALE , status ) ! = Locale ( " root " ) ) {
/* test that the default locale has a display name for its own language */
Locale ( ) . getDisplayLanguage ( Locale ( ) , s ) ;
if ( s . length ( ) < = 3 & & s . charAt ( 0 ) < = 0x7f ) {
/* check <=3 to reject getting the language code as a display name */
errln ( " unable to get a display string for the language of the default locale \n " ) ;
}
2003-05-10 23:03:43 +00:00
2006-11-07 17:14:12 +00:00
/*
* API coverage improvements : call
* Locale : : getDisplayLanguage ( UnicodeString & ) and
* Locale : : getDisplayCountry ( UnicodeString & )
*/
s . remove ( ) ;
Locale ( ) . getDisplayLanguage ( s ) ;
if ( s . length ( ) < = 3 & & s . charAt ( 0 ) < = 0x7f ) {
errln ( " unable to get a display string for the language of the default locale [2] \n " ) ;
}
}
else {
logln ( " Default locale %s is unsupported by ICU \n " , Locale ( ) . getName ( ) ) ;
2003-05-10 23:03:43 +00:00
}
s . remove ( ) ;
french . getDisplayCountry ( s ) ;
if ( s . isEmpty ( ) ) {
errln ( " unable to get any default-locale display string for the country of fr_FR \n " ) ;
}
2004-12-21 20:19:39 +00:00
s . remove ( ) ;
Locale ( " zh " , " Hant " ) . getDisplayScript ( s ) ;
if ( s . isEmpty ( ) ) {
errln ( " unable to get any default-locale display string for the country of zh_Hant \n " ) ;
}
1999-08-16 21:50:52 +00:00
}
void LocaleTest : : TestSimpleObjectStuff ( ) {
Locale test1 ( " aa " , " AA " ) ;
Locale test2 ( " aa " , " AA " ) ;
Locale test3 ( test1 ) ;
Locale test4 ( " zz " , " ZZ " ) ;
2003-12-03 00:25:25 +00:00
Locale test5 ( " aa " , " AA " , " " ) ;
Locale test6 ( " aa " , " AA " , " ANTARES " ) ;
2001-02-17 13:34:42 +00:00
Locale test7 ( " aa " , " AA " , " JUPITER " ) ;
2004-05-14 22:45:27 +00:00
Locale test8 = Locale : : createFromName ( " aa-aa-jupiTER " ) ; // was "aa-aa.utf8@jupiter" but in 3.0 getName won't normalize that
1999-08-16 21:50:52 +00:00
// now list them all for debugging usage.
test_dumpLocale ( test1 ) ;
test_dumpLocale ( test2 ) ;
test_dumpLocale ( test3 ) ;
test_dumpLocale ( test4 ) ;
test_dumpLocale ( test5 ) ;
test_dumpLocale ( test6 ) ;
2001-02-17 13:34:42 +00:00
test_dumpLocale ( test7 ) ;
test_dumpLocale ( test8 ) ;
1999-08-16 21:50:52 +00:00
// Make sure things compare to themselves!
test_assert ( test1 = = test1 ) ;
test_assert ( test2 = = test2 ) ;
test_assert ( test3 = = test3 ) ;
test_assert ( test4 = = test4 ) ;
test_assert ( test5 = = test5 ) ;
test_assert ( test6 = = test6 ) ;
test_assert ( test7 = = test7 ) ;
2001-02-17 13:34:42 +00:00
test_assert ( test8 = = test8 ) ;
1999-08-16 21:50:52 +00:00
// make sure things are not equal to themselves.
test_assert ( ! ( test1 ! = test1 ) ) ;
test_assert ( ! ( test2 ! = test2 ) ) ;
test_assert ( ! ( test3 ! = test3 ) ) ;
test_assert ( ! ( test4 ! = test4 ) ) ;
test_assert ( ! ( test5 ! = test5 ) ) ;
test_assert ( ! ( test6 ! = test6 ) ) ;
test_assert ( ! ( test7 ! = test7 ) ) ;
2001-02-17 13:34:42 +00:00
test_assert ( ! ( test8 ! = test8 ) ) ;
1999-08-16 21:50:52 +00:00
// make sure things that are equal to each other don't show up as unequal.
test_assert ( ! ( test1 ! = test2 ) ) ;
test_assert ( ! ( test2 ! = test1 ) ) ;
test_assert ( ! ( test1 ! = test3 ) ) ;
test_assert ( ! ( test2 ! = test3 ) ) ;
test_assert ( test5 = = test1 ) ;
test_assert ( test6 ! = test2 ) ;
test_assert ( test6 ! = test5 ) ;
test_assert ( test6 ! = test7 ) ;
// test for things that shouldn't compare equal.
test_assert ( ! ( test1 = = test4 ) ) ;
test_assert ( ! ( test2 = = test4 ) ) ;
test_assert ( ! ( test3 = = test4 ) ) ;
2001-02-17 13:34:42 +00:00
test_assert ( test7 = = test8 ) ;
1999-08-16 21:50:52 +00:00
// test for hash codes to be the same.
int32_t hash1 = test1 . hashCode ( ) ;
int32_t hash2 = test2 . hashCode ( ) ;
int32_t hash3 = test3 . hashCode ( ) ;
test_assert ( hash1 = = hash2 ) ;
test_assert ( hash1 = = hash3 ) ;
test_assert ( hash2 = = hash3 ) ;
// test that the assignment operator works.
test4 = test1 ;
logln ( " test4=test1; " ) ;
test_dumpLocale ( test4 ) ;
test_assert ( test4 = = test4 ) ;
test_assert ( ! ( test1 ! = test4 ) ) ;
test_assert ( ! ( test2 ! = test4 ) ) ;
test_assert ( ! ( test3 ! = test4 ) ) ;
test_assert ( test1 = = test4 ) ;
test_assert ( test4 = = test1 ) ;
2003-12-03 00:25:25 +00:00
1999-08-16 21:50:52 +00:00
// test assignments with a variant
logln ( " test7 = test6 " ) ;
test7 = test6 ;
test_dumpLocale ( test7 ) ;
test_assert ( test7 = = test7 ) ;
test_assert ( test7 = = test6 ) ;
test_assert ( test7 ! = test5 ) ;
logln ( " test6 = test1 " ) ;
test6 = test1 ;
test_dumpLocale ( test6 ) ;
test_assert ( test6 ! = test7 ) ;
test_assert ( test6 = = test1 ) ;
test_assert ( test6 = = test6 ) ;
}
// A class which exposes constructors that are implemented in terms of the POSIX parsing code.
class POSIXLocale : public Locale
{
public :
POSIXLocale ( const UnicodeString & l )
: Locale ( )
{
2000-04-15 21:28:17 +00:00
char * ch ;
2001-03-06 23:55:33 +00:00
ch = new char [ l . length ( ) + 1 ] ;
2000-04-15 21:28:17 +00:00
ch [ l . extract ( 0 , 0x7fffffff , ch , " " ) ] = 0 ;
setFromPOSIXID ( ch ) ;
delete [ ] ch ;
1999-08-16 21:50:52 +00:00
}
POSIXLocale ( const char * l )
: Locale ( )
{
setFromPOSIXID ( l ) ;
}
} ;
void LocaleTest : : TestPOSIXParsing ( )
{
POSIXLocale test1 ( " ab_AB " ) ;
POSIXLocale test2 ( UnicodeString ( " ab_AB " ) ) ;
Locale test3 ( " ab " , " AB " ) ;
POSIXLocale test4 ( " ab_AB_Antares " ) ;
POSIXLocale test5 ( UnicodeString ( " ab_AB_Antares " ) ) ;
2003-12-03 00:25:25 +00:00
Locale test6 ( " ab " , " AB " , " Antares " ) ;
1999-08-16 21:50:52 +00:00
test_dumpLocale ( test1 ) ;
test_dumpLocale ( test2 ) ;
test_dumpLocale ( test3 ) ;
test_dumpLocale ( test4 ) ;
test_dumpLocale ( test5 ) ;
test_dumpLocale ( test6 ) ;
test_assert ( test1 = = test1 ) ;
test_assert ( test1 = = test2 ) ;
test_assert ( test2 = = test3 ) ;
test_assert ( test3 = = test1 ) ;
test_assert ( test4 = = test5 ) ;
test_assert ( test5 = = test6 ) ;
test_assert ( test6 = = test4 ) ;
test_assert ( test1 ! = test4 ) ;
test_assert ( test5 ! = test3 ) ;
test_assert ( test5 ! = test2 ) ;
int32_t hash1 = test1 . hashCode ( ) ;
int32_t hash2 = test2 . hashCode ( ) ;
int32_t hash3 = test3 . hashCode ( ) ;
test_assert ( hash1 = = hash2 ) ;
test_assert ( hash2 = = hash3 ) ;
test_assert ( hash3 = = hash1 ) ;
}
void LocaleTest : : TestGetAvailableLocales ( )
{
int32_t locCount = 0 ;
const Locale * locList = Locale : : getAvailableLocales ( locCount ) ;
if ( locCount = = 0 )
errln ( " getAvailableLocales() returned an empty list! " ) ;
else {
logln ( UnicodeString ( " Number of locales returned = " ) + locCount ) ;
UnicodeString temp ;
for ( int32_t i = 0 ; i < locCount ; + + i )
2000-04-15 21:28:17 +00:00
logln ( locList [ i ] . getName ( ) ) ;
1999-08-16 21:50:52 +00:00
}
// I have no idea how to test this function...
}
// This test isn't applicable anymore - getISO3Language is
// independent of the data directory
void LocaleTest : : TestDataDirectory ( )
{
/*
char oldDirectory [ 80 ] ;
const char * temp ;
1999-10-07 00:07:53 +00:00
UErrorCode err = U_ZERO_ERROR ;
1999-08-16 21:50:52 +00:00
UnicodeString testValue ;
temp = Locale : : getDataDirectory ( ) ;
strcpy ( oldDirectory , temp ) ;
logln ( UnicodeString ( " oldDirectory = " ) + oldDirectory ) ;
Locale test ( Locale : : US ) ;
test . getISO3Language ( testValue ) ;
logln ( " first fetch of language retrieved " + testValue ) ;
if ( testValue ! = " eng " )
errln ( " Initial check of ISO3 language failed: expected \" eng \" , got \" " + testValue + " \" " ) ;
{
char * path ;
path = IntlTest : : getTestDirectory ( ) ;
Locale : : setDataDirectory ( path ) ;
}
test . getISO3Language ( testValue ) ;
logln ( " second fetch of language retrieved " + testValue ) ;
if ( testValue ! = " xxx " )
errln ( " setDataDirectory() failed: expected \" xxx \" , got \" " + testValue + " \" " ) ;
2003-12-03 00:25:25 +00:00
1999-08-16 21:50:52 +00:00
Locale : : setDataDirectory ( oldDirectory ) ;
test . getISO3Language ( testValue ) ;
logln ( " third fetch of language retrieved " + testValue ) ;
if ( testValue ! = " eng " )
errln ( " get/setDataDirectory() failed: expected \" eng \" , got \" " + testValue + " \" " ) ;
*/
}
//===========================================================
2003-04-25 22:56:51 +00:00
void LocaleTest : : doTestDisplayNames ( Locale & displayLocale , int32_t compareIndex ) {
1999-08-16 21:50:52 +00:00
UnicodeString temp ;
2003-12-03 00:25:25 +00:00
1999-08-16 21:50:52 +00:00
for ( int32_t i = 0 ; i < = MAX_LOCALES ; i + + ) {
2004-01-08 00:56:21 +00:00
Locale testLocale ( " " ) ;
if ( rawData [ SCRIPT ] [ i ] & & rawData [ SCRIPT ] [ i ] [ 0 ] ! = 0 ) {
testLocale = Locale ( rawData [ LANG ] [ i ] , rawData [ SCRIPT ] [ i ] , rawData [ CTRY ] [ i ] , rawData [ VAR ] [ i ] ) ;
}
else {
testLocale = Locale ( rawData [ LANG ] [ i ] , rawData [ CTRY ] [ i ] , rawData [ VAR ] [ i ] ) ;
}
2000-04-15 21:28:17 +00:00
logln ( " Testing " + ( temp = testLocale . getName ( ) ) + " ... " ) ;
1999-08-16 21:50:52 +00:00
UnicodeString testLang ;
2004-01-08 00:56:21 +00:00
UnicodeString testScript ;
1999-08-16 21:50:52 +00:00
UnicodeString testCtry ;
UnicodeString testVar ;
UnicodeString testName ;
2003-04-25 22:56:51 +00:00
testLocale . getDisplayLanguage ( displayLocale , testLang ) ;
2004-01-08 00:56:21 +00:00
testLocale . getDisplayScript ( displayLocale , testScript ) ;
2003-04-25 22:56:51 +00:00
testLocale . getDisplayCountry ( displayLocale , testCtry ) ;
testLocale . getDisplayVariant ( displayLocale , testVar ) ;
testLocale . getDisplayName ( displayLocale , testName ) ;
1999-08-16 21:50:52 +00:00
UnicodeString expectedLang ;
2004-01-08 00:56:21 +00:00
UnicodeString expectedScript ;
1999-08-16 21:50:52 +00:00
UnicodeString expectedCtry ;
UnicodeString expectedVar ;
UnicodeString expectedName ;
expectedLang = dataTable [ compareIndex ] [ i ] ;
1999-12-08 02:11:04 +00:00
if ( expectedLang . length ( ) = = 0 )
1999-08-16 21:50:52 +00:00
expectedLang = dataTable [ DLANG_EN ] [ i ] ;
2004-01-08 00:56:21 +00:00
expectedScript = dataTable [ compareIndex + 1 ] [ i ] ;
if ( expectedScript . length ( ) = = 0 )
expectedScript = dataTable [ DSCRIPT_EN ] [ i ] ;
expectedCtry = dataTable [ compareIndex + 2 ] [ i ] ;
1999-12-08 02:11:04 +00:00
if ( expectedCtry . length ( ) = = 0 )
1999-08-16 21:50:52 +00:00
expectedCtry = dataTable [ DCTRY_EN ] [ i ] ;
2004-01-08 00:56:21 +00:00
expectedVar = dataTable [ compareIndex + 3 ] [ i ] ;
1999-12-08 02:11:04 +00:00
if ( expectedVar . length ( ) = = 0 )
1999-08-16 21:50:52 +00:00
expectedVar = dataTable [ DVAR_EN ] [ i ] ;
2004-01-08 00:56:21 +00:00
expectedName = dataTable [ compareIndex + 4 ] [ i ] ;
1999-12-08 02:11:04 +00:00
if ( expectedName . length ( ) = = 0 )
1999-08-16 21:50:52 +00:00
expectedName = dataTable [ DNAME_EN ] [ i ] ;
if ( testLang ! = expectedLang )
2003-07-26 00:07:49 +00:00
errln ( " Display language ( " + UnicodeString ( displayLocale . getName ( ) ) + " ) of ( " + UnicodeString ( testLocale . getName ( ) ) + " ) got " + testLang + " expected " + expectedLang ) ;
2004-01-08 00:56:21 +00:00
if ( testScript ! = expectedScript )
errln ( " Display script ( " + UnicodeString ( displayLocale . getName ( ) ) + " ) of ( " + UnicodeString ( testLocale . getName ( ) ) + " ) got " + testScript + " expected " + expectedScript ) ;
1999-08-16 21:50:52 +00:00
if ( testCtry ! = expectedCtry )
2003-07-26 00:07:49 +00:00
errln ( " Display country ( " + UnicodeString ( displayLocale . getName ( ) ) + " ) of ( " + UnicodeString ( testLocale . getName ( ) ) + " ) got " + testCtry + " expected " + expectedCtry ) ;
1999-08-16 21:50:52 +00:00
if ( testVar ! = expectedVar )
2003-07-26 00:07:49 +00:00
errln ( " Display variant ( " + UnicodeString ( displayLocale . getName ( ) ) + " ) of ( " + UnicodeString ( testLocale . getName ( ) ) + " ) got " + testVar + " expected " + expectedVar ) ;
1999-08-16 21:50:52 +00:00
if ( testName ! = expectedName )
2003-07-26 00:07:49 +00:00
errln ( " Display name ( " + UnicodeString ( displayLocale . getName ( ) ) + " ) of ( " + UnicodeString ( testLocale . getName ( ) ) + " ) got " + testName + " expected " + expectedName ) ;
1999-08-16 21:50:52 +00:00
}
}
//---------------------------------------------------
// table of valid data
//---------------------------------------------------
2003-12-03 00:25:25 +00:00
1999-08-16 21:50:52 +00:00
void LocaleTest : : setUpDataTable ( )
{
if ( dataTable = = 0 ) {
2004-01-08 00:56:21 +00:00
dataTable = new UnicodeString * [ 33 ] ;
1999-08-16 21:50:52 +00:00
2004-01-08 00:56:21 +00:00
for ( int32_t i = 0 ; i < 33 ; i + + ) {
dataTable [ i ] = new UnicodeString [ 8 ] ;
for ( int32_t j = 0 ; j < 8 ; j + + ) {
2000-03-22 23:17:42 +00:00
dataTable [ i ] [ j ] = CharsToUnicodeString ( rawData [ i ] [ j ] ) ;
}
1999-08-16 21:50:52 +00:00
}
}
}
// ====================
/**
* @ bug 4011756 4011380
*/
2003-12-03 00:25:25 +00:00
void
LocaleTest : : TestISO3Fallback ( )
1999-08-16 21:50:52 +00:00
{
Locale test ( " xx " , " YY " ) ;
2000-04-15 21:28:17 +00:00
const char * result ;
1999-08-16 21:50:52 +00:00
2000-04-15 21:28:17 +00:00
result = test . getISO3Language ( ) ;
2003-12-03 00:25:25 +00:00
// Conform to C API usage
2000-04-15 21:28:17 +00:00
if ( ! result | | ( result [ 0 ] ! = 0 ) )
errln ( " getISO3Language() on xx_YY returned " + UnicodeString ( result ) + " instead of \" \" " ) ;
result = test . getISO3Country ( ) ;
if ( ! result | | ( result [ 0 ] ! = 0 ) )
errln ( " getISO3Country() on xx_YY returned " + UnicodeString ( result ) + " instead of \" \" " ) ;
1999-08-16 21:50:52 +00:00
}
/**
* @ bug 4106155 4118587
*/
2003-12-03 00:25:25 +00:00
void
LocaleTest : : TestGetLangsAndCountries ( )
1999-08-16 21:50:52 +00:00
{
// It didn't seem right to just do an exhaustive test of everything here, so I check
// for the following things:
// 1) Does each list have the right total number of entries?
// 2) Does each list contain certain language and country codes we think are important
// (the G7 countries, plus a couple others)?
// 3) Does each list have every entry formatted correctly? (i.e., two characters,
// all lower case for the language codes, all upper case for the country codes)
// 4) Is each list in sorted order?
int32_t testCount = 0 ;
2000-04-15 21:28:17 +00:00
const char * const * test = Locale : : getISOLanguages ( ) ;
2003-12-03 00:25:25 +00:00
const char spotCheck1 [ ] [ 4 ] = { " en " , " es " , " fr " , " de " , " it " ,
" ja " , " ko " , " zh " , " th " , " he " ,
1999-08-16 21:50:52 +00:00
" id " , " iu " , " ug " , " yi " , " za " } ;
int32_t i ;
2003-12-03 00:25:25 +00:00
2000-04-15 21:28:17 +00:00
for ( testCount = 0 ; test [ testCount ] ; testCount + + )
;
1999-08-16 21:50:52 +00:00
2004-07-18 20:49:33 +00:00
/* TODO: Change this test to be more like the cloctst version? */
2006-11-07 08:40:47 +00:00
if ( testCount ! = 487 )
errln ( " Expected getISOLanguages() to return 487 languages; it returned %d " , testCount ) ;
1999-08-16 21:50:52 +00:00
else {
for ( i = 0 ; i < 15 ; i + + ) {
int32_t j ;
for ( j = 0 ; j < testCount ; j + + )
2000-04-15 21:28:17 +00:00
if ( uprv_strcmp ( test [ j ] , spotCheck1 [ i ] ) = = 0 )
1999-08-16 21:50:52 +00:00
break ;
2000-04-15 21:28:17 +00:00
if ( j = = testCount | | ( uprv_strcmp ( test [ j ] , spotCheck1 [ i ] ) ! = 0 ) )
errln ( " Couldn't find " + ( UnicodeString ) spotCheck1 [ i ] + " in language list. " ) ;
1999-08-16 21:50:52 +00:00
}
}
for ( i = 0 ; i < testCount ; i + + ) {
2000-04-15 21:28:17 +00:00
UnicodeString testee ( test [ i ] , " " ) ;
UnicodeString lc ( test [ i ] , " " ) ;
if ( testee ! = lc . toLower ( ) )
errln ( lc + " is not all lower case. " ) ;
2001-10-14 00:24:34 +00:00
if ( ( testee . length ( ) ! = 2 ) & & ( testee . length ( ) ! = 3 ) )
errln ( testee + " is not two or three characters long. " ) ;
2000-04-15 21:28:17 +00:00
if ( i > 0 & & testee . compare ( test [ i - 1 ] ) < = 0 )
errln ( testee + " appears in an out-of-order position in the list. " ) ;
1999-08-16 21:50:52 +00:00
}
2000-04-15 21:28:17 +00:00
test = Locale : : getISOCountries ( ) ;
2003-12-03 00:25:25 +00:00
UnicodeString spotCheck2 [ ] = { " US " , " CA " , " GB " , " FR " , " DE " ,
" IT " , " JP " , " KR " , " CN " , " TW " ,
1999-08-16 21:50:52 +00:00
" TH " } ;
int32_t spot2Len = 11 ;
2000-04-15 21:28:17 +00:00
for ( testCount = 0 ; test [ testCount ] ; testCount + + )
;
1999-08-16 21:50:52 +00:00
2006-06-23 16:31:07 +00:00
if ( testCount ! = 244 ) {
errln ( " Expected getISOCountries to return 240 countries; it returned %d " , testCount ) ;
} else {
1999-08-16 21:50:52 +00:00
for ( i = 0 ; i < spot2Len ; i + + ) {
int32_t j ;
for ( j = 0 ; j < testCount ; j + + )
2000-04-15 21:28:17 +00:00
{
UnicodeString testee ( test [ j ] , " " ) ;
if ( testee = = spotCheck2 [ i ] )
1999-08-16 21:50:52 +00:00
break ;
2000-04-15 21:28:17 +00:00
}
UnicodeString testee ( test [ j ] , " " ) ;
if ( j = = testCount | | testee ! = spotCheck2 [ i ] )
1999-08-16 21:50:52 +00:00
errln ( " Couldn't find " + spotCheck2 [ i ] + " in country list. " ) ;
}
}
2006-06-23 16:31:07 +00:00
for ( i = 0 ; i < testCount ; i + + ) {
2000-04-15 21:28:17 +00:00
UnicodeString testee ( test [ i ] , " " ) ;
UnicodeString uc ( test [ i ] , " " ) ;
if ( testee ! = uc . toUpper ( ) )
errln ( testee + " is not all upper case. " ) ;
if ( testee . length ( ) ! = 2 )
errln ( testee + " is not two characters long. " ) ;
if ( i > 0 & & testee . compare ( test [ i - 1 ] ) < = 0 )
errln ( testee + " appears in an out-of-order position in the list. " ) ;
1999-08-16 21:50:52 +00:00
}
}
/**
* @ bug 4118587
*/
2003-12-03 00:25:25 +00:00
void
LocaleTest : : TestSimpleDisplayNames ( )
1999-08-16 21:50:52 +00:00
{
// This test is different from TestDisplayNames because TestDisplayNames checks
// fallback behavior, combination of language and country names to form locale
// names, and other stuff like that. This test just checks specific language
// and country codes to make sure we have the correct names for them.
2000-04-15 21:28:17 +00:00
char languageCodes [ ] [ 4 ] = { " he " , " id " , " iu " , " ug " , " yi " , " za " } ;
2003-07-29 16:32:43 +00:00
UnicodeString languageNames [ ] = { " Hebrew " , " Indonesian " , " Inuktitut " , " Uighur " , " Yiddish " ,
1999-08-16 21:50:52 +00:00
" Zhuang " } ;
for ( int32_t i = 0 ; i < 6 ; i + + ) {
UnicodeString test ;
Locale l ( languageCodes [ i ] , " " , " " ) ;
2002-08-21 00:16:30 +00:00
l . getDisplayLanguage ( Locale : : getUS ( ) , test ) ;
1999-08-16 21:50:52 +00:00
if ( test ! = languageNames [ i ] )
2000-04-15 21:28:17 +00:00
errln ( " Got wrong display name for " + UnicodeString ( languageCodes [ i ] ) + " : Expected \" " +
1999-08-16 21:50:52 +00:00
languageNames [ i ] + " \" , got \" " + test + " \" . " ) ;
}
}
/**
* @ bug 4118595
*/
2003-12-03 00:25:25 +00:00
void
LocaleTest : : TestUninstalledISO3Names ( )
1999-08-16 21:50:52 +00:00
{
// This test checks to make sure getISO3Language and getISO3Country work right
// even for locales that are not installed.
2003-12-03 00:25:25 +00:00
const char iso2Languages [ ] [ 4 ] = { " am " , " ba " , " fy " , " mr " , " rn " ,
1999-08-16 21:50:52 +00:00
" ss " , " tw " , " zu " } ;
2003-12-03 00:25:25 +00:00
const char iso3Languages [ ] [ 5 ] = { " amh " , " bak " , " fry " , " mar " , " run " ,
1999-08-16 21:50:52 +00:00
" ssw " , " twi " , " zul " } ;
int32_t i ;
for ( i = 0 ; i < 8 ; i + + ) {
2000-04-15 21:28:17 +00:00
UErrorCode err = U_ZERO_ERROR ;
UnicodeString test ;
1999-08-16 21:50:52 +00:00
Locale l ( iso2Languages [ i ] , " " , " " ) ;
2000-04-15 21:28:17 +00:00
test = l . getISO3Language ( ) ;
if ( ( test ! = iso3Languages [ i ] ) | | U_FAILURE ( err ) )
errln ( " Got wrong ISO3 code for " + UnicodeString ( iso2Languages [ i ] ) + " : Expected \" " +
iso3Languages [ i ] + " \" , got \" " + test + " \" . " + UnicodeString ( u_errorName ( err ) ) ) ;
1999-08-16 21:50:52 +00:00
}
2003-12-03 00:25:25 +00:00
char iso2Countries [ ] [ 4 ] = { " AF " , " BW " , " KZ " , " MO " , " MN " ,
1999-08-16 21:50:52 +00:00
" SB " , " TC " , " ZW " } ;
2003-12-03 00:25:25 +00:00
char iso3Countries [ ] [ 4 ] = { " AFG " , " BWA " , " KAZ " , " MAC " , " MNG " ,
1999-08-16 21:50:52 +00:00
" SLB " , " TCA " , " ZWE " } ;
for ( i = 0 ; i < 8 ; i + + ) {
2000-04-15 21:28:17 +00:00
UErrorCode err = U_ZERO_ERROR ;
1999-08-16 21:50:52 +00:00
Locale l ( " " , iso2Countries [ i ] , " " ) ;
2000-04-15 21:28:17 +00:00
UnicodeString test ( l . getISO3Country ( ) , " " ) ;
1999-08-16 21:50:52 +00:00
if ( test ! = iso3Countries [ i ] )
2000-04-15 21:28:17 +00:00
errln ( " Got wrong ISO3 code for " + UnicodeString ( iso2Countries [ i ] ) + " : Expected \" " +
UnicodeString ( iso3Countries [ i ] ) + " \" , got \" " + test + " \" . " + u_errorName ( err ) ) ;
1999-08-16 21:50:52 +00:00
}
}
/**
* @ bug 4092475
* I could not reproduce this bug . I ' m pretty convinced it was fixed with the
* big locale - data reorg of 10 / 28 / 97. The lookup logic for language and country
* display names was also changed at that time in that check - in . - - rtg 3 / 20 / 98
*/
2003-12-03 00:25:25 +00:00
void
LocaleTest : : TestAtypicalLocales ( )
1999-08-16 21:50:52 +00:00
{
Locale localesToTest [ ] = { Locale ( " de " , " CA " ) ,
Locale ( " ja " , " ZA " ) ,
Locale ( " ru " , " MX " ) ,
Locale ( " en " , " FR " ) ,
Locale ( " es " , " DE " ) ,
Locale ( " " , " HR " ) ,
Locale ( " " , " SE " ) ,
Locale ( " " , " DO " ) ,
Locale ( " " , " BE " ) } ;
UnicodeString englishDisplayNames [ ] = { " German (Canada) " ,
" Japanese (South Africa) " ,
" Russian (Mexico) " ,
" English (France) " ,
" Spanish (Germany) " ,
" Croatia " ,
" Sweden " ,
" Dominican Republic " ,
" Belgium " } ;
UnicodeString frenchDisplayNames [ ] = { " allemand (Canada) " ,
2000-10-30 21:05:32 +00:00
" japonais (Afrique du Sud) " ,
" russe (Mexique) " ,
1999-08-16 21:50:52 +00:00
" anglais (France) " ,
" espagnol (Allemagne) " ,
2000-10-30 21:05:32 +00:00
" Croatie " ,
2000-03-22 23:17:42 +00:00
CharsToUnicodeString ( " Su \\ u00E8de " ) ,
2007-06-28 20:59:10 +00:00
CharsToUnicodeString ( " R \\ u00E9publique dominicaine " ) ,
1999-08-16 21:50:52 +00:00
" Belgique " } ;
2000-11-20 18:48:05 +00:00
UnicodeString spanishDisplayNames [ ] = {
CharsToUnicodeString ( " alem \\ u00E1n (Canad \\ u00E1) " ) ,
2000-11-22 17:51:54 +00:00
CharsToUnicodeString ( " japon \\ u00E9s (Sud \\ u00E1frica) " ) ,
2000-11-20 18:48:05 +00:00
CharsToUnicodeString ( " ruso (M \\ u00E9xico) " ) ,
CharsToUnicodeString ( " ingl \\ u00E9s (Francia) " ) ,
CharsToUnicodeString ( " espa \\ u00F1ol (Alemania) " ) ,
2000-11-22 17:51:54 +00:00
" Croacia " ,
2000-11-20 18:48:05 +00:00
" Suecia " ,
CharsToUnicodeString ( " Rep \\ u00FAblica Dominicana " ) ,
CharsToUnicodeString ( " B \\ u00E9lgica " ) } ;
2003-09-27 01:09:40 +00:00
// De-Anglicizing root required the change from
// English display names to ISO Codes - ram 2003/09/26
2005-06-01 01:23:19 +00:00
UnicodeString invDisplayNames [ ] = { " German (Canada) " ,
" Japanese (South Africa) " ,
" Russian (Mexico) " ,
" English (France) " ,
" Spanish (Germany) " ,
" Croatia " ,
" Sweden " ,
" Dominican Republic " ,
" Belgium " } ;
2003-12-03 00:25:25 +00:00
1999-08-16 21:50:52 +00:00
int32_t i ;
1999-10-07 00:07:53 +00:00
UErrorCode status = U_ZERO_ERROR ;
2004-12-22 19:28:42 +00:00
Locale saveLocale ;
2002-03-26 23:18:57 +00:00
Locale : : setDefault ( Locale : : getUS ( ) , status ) ;
1999-08-16 21:50:52 +00:00
for ( i = 0 ; i < 9 ; + + i ) {
UnicodeString name ;
2002-03-26 23:18:57 +00:00
localesToTest [ i ] . getDisplayName ( Locale : : getUS ( ) , name ) ;
1999-08-16 21:50:52 +00:00
logln ( name ) ;
if ( name ! = englishDisplayNames [ i ] )
{
errln ( " Lookup in English failed: expected \" " + englishDisplayNames [ i ]
+ " \" , got \" " + name + " \" " ) ;
2000-04-15 21:28:17 +00:00
logln ( " Locale name was-> " + ( name = localesToTest [ i ] . getName ( ) ) ) ;
1999-08-16 21:50:52 +00:00
}
}
for ( i = 0 ; i < 9 ; i + + ) {
UnicodeString name ;
localesToTest [ i ] . getDisplayName ( Locale ( " es " , " ES " ) , name ) ;
logln ( name ) ;
if ( name ! = spanishDisplayNames [ i ] )
errln ( " Lookup in Spanish failed: expected \" " + spanishDisplayNames [ i ]
+ " \" , got \" " + name + " \" " ) ;
}
for ( i = 0 ; i < 9 ; i + + ) {
UnicodeString name ;
2002-03-26 23:18:57 +00:00
localesToTest [ i ] . getDisplayName ( Locale : : getFrance ( ) , name ) ;
1999-08-16 21:50:52 +00:00
logln ( name ) ;
if ( name ! = frenchDisplayNames [ i ] )
errln ( " Lookup in French failed: expected \" " + frenchDisplayNames [ i ]
+ " \" , got \" " + name + " \" " ) ;
}
2000-11-20 18:48:05 +00:00
for ( i = 0 ; i < 9 ; i + + ) {
UnicodeString name ;
2005-06-01 01:23:19 +00:00
localesToTest [ i ] . getDisplayName ( Locale ( " inv " , " IN " ) , name ) ;
2003-11-11 23:49:33 +00:00
logln ( name + " Locale fallback to be, and data fallback to root " ) ;
2005-06-01 01:23:19 +00:00
if ( name ! = invDisplayNames [ i ] )
errln ( " Lookup in INV failed: expected \" " + prettify ( invDisplayNames [ i ] )
+ " \" , got \" " + prettify ( name ) + " \" " ) ;
localesToTest [ i ] . getDisplayName ( Locale ( " inv " , " BD " ) , name ) ;
2000-11-20 18:48:05 +00:00
logln ( name + " Data fallback to root " ) ;
2005-06-01 01:23:19 +00:00
if ( name ! = invDisplayNames [ i ] )
errln ( " Lookup in INV failed: expected \" " + prettify ( invDisplayNames [ i ] )
+ " \" , got \" " + prettify ( name ) + " \" " ) ;
2000-11-20 18:48:05 +00:00
}
2004-12-22 19:28:42 +00:00
Locale : : setDefault ( saveLocale , status ) ;
1999-08-16 21:50:52 +00:00
}
2002-09-21 00:43:14 +00:00
# if !UCONFIG_NO_FORMATTING
1999-08-16 21:50:52 +00:00
/**
* @ bug 4135752
* This would be better tested by the LocaleDataTest . Will move it when I
* get the LocaleDataTest working again .
*/
2003-12-03 00:25:25 +00:00
void
LocaleTest : : TestThaiCurrencyFormat ( )
1999-08-16 21:50:52 +00:00
{
1999-10-07 00:07:53 +00:00
UErrorCode status = U_ZERO_ERROR ;
1999-08-16 21:50:52 +00:00
DecimalFormat * thaiCurrency = ( DecimalFormat * ) NumberFormat : : createCurrencyInstance (
Locale ( " th " , " TH " ) , status ) ;
UChar posPrefix = 0x0e3f ;
UnicodeString temp ;
2000-02-16 22:38:38 +00:00
if ( U_FAILURE ( status ) | | ! thaiCurrency )
{
errln ( " Couldn't get th_TH currency -> " + UnicodeString ( u_errorName ( status ) ) ) ;
return ;
}
1999-08-16 21:50:52 +00:00
if ( thaiCurrency - > getPositivePrefix ( temp ) ! = UnicodeString ( & posPrefix , 1 , 1 ) )
errln ( " Thai currency prefix wrong: expected 0x0e3f, got \" " +
thaiCurrency - > getPositivePrefix ( temp ) + " \" " ) ;
if ( thaiCurrency - > getPositiveSuffix ( temp ) ! = " " )
errln ( " Thai currency suffix wrong: expected \" \" , got \" " +
thaiCurrency - > getPositiveSuffix ( temp ) + " \" " ) ;
delete thaiCurrency ;
}
/**
* @ bug 4122371
* Confirm that Euro support works . This test is pretty rudimentary ; all it does
* is check that any locales with the EURO variant format a number using the
* Euro currency symbol .
*
* ASSUME : All locales encode the Euro character " \u20AC " .
* If this is changed to use the single - character Euro symbol , this
* test must be updated .
*
*/
2003-12-03 00:25:25 +00:00
void
LocaleTest : : TestEuroSupport ( )
1999-08-16 21:50:52 +00:00
{
UChar euro = 0x20ac ;
const UnicodeString EURO_CURRENCY ( & euro , 1 , 1 ) ; // Look for this UnicodeString in formatted Euro currency
2001-10-30 01:54:24 +00:00
const char * localeArr [ ] = {
" ca_ES " ,
" de_AT " ,
" de_DE " ,
" de_LU " ,
" el_GR " ,
" en_BE " ,
" en_IE " ,
2003-06-25 00:04:49 +00:00
" en_GB_EURO " ,
" en_US_EURO " ,
2001-10-30 01:54:24 +00:00
" es_ES " ,
" eu_ES " ,
" fi_FI " ,
" fr_BE " ,
" fr_FR " ,
" fr_LU " ,
" ga_IE " ,
" gl_ES " ,
" it_IT " ,
" nl_BE " ,
" nl_NL " ,
" pt_PT " ,
2001-10-30 18:08:41 +00:00
NULL
2001-10-30 01:54:24 +00:00
} ;
const char * * locales = localeArr ;
1999-08-16 21:50:52 +00:00
1999-10-07 00:07:53 +00:00
UErrorCode status = U_ZERO_ERROR ;
1999-08-16 21:50:52 +00:00
UnicodeString temp ;
2001-10-30 18:08:41 +00:00
for ( ; * locales ! = NULL ; locales + + ) {
2001-10-30 01:54:24 +00:00
Locale loc ( * locales ) ;
1999-08-16 21:50:52 +00:00
UnicodeString temp ;
2003-06-25 00:04:49 +00:00
NumberFormat * nf = NumberFormat : : createCurrencyInstance ( loc , status ) ;
UnicodeString pos ;
2005-04-05 20:12:22 +00:00
2005-04-06 00:38:48 +00:00
if ( U_FAILURE ( status ) ) {
dataerrln ( " Error calling NumberFormat::createCurrencyInstance(%s) " , * locales ) ;
continue ;
}
2005-04-05 20:12:22 +00:00
2003-06-25 00:04:49 +00:00
nf - > format ( 271828.182845 , pos ) ;
UnicodeString neg ;
nf - > format ( - 271828.182845 , neg ) ;
if ( pos . indexOf ( EURO_CURRENCY ) > = 0 & &
neg . indexOf ( EURO_CURRENCY ) > = 0 ) {
logln ( " Ok: " + ( temp = loc . getName ( ) ) +
" : " + pos + " / " + neg ) ;
}
else {
errln ( " Fail: " + ( temp = loc . getName ( ) ) +
" formats without " + EURO_CURRENCY +
" : " + pos + " / " + neg +
" \n *** THIS FAILURE MAY ONLY MEAN THAT LOCALE DATA HAS CHANGED *** " ) ;
}
2003-12-03 00:25:25 +00:00
2003-06-25 00:04:49 +00:00
delete nf ;
}
UnicodeString dollarStr ( " USD " , " " ) , euroStr ( " EUR " , " " ) , genericStr ( ( UChar ) 0x00a4 ) , resultStr ;
2003-11-13 23:24:45 +00:00
UChar tmp [ 4 ] ;
2003-06-25 00:04:49 +00:00
status = U_ZERO_ERROR ;
2003-11-13 23:24:45 +00:00
ucurr_forLocale ( " en_US " , tmp , 4 , & status ) ;
resultStr . setTo ( tmp ) ;
2003-06-25 00:04:49 +00:00
if ( dollarStr ! = resultStr ) {
errln ( " Fail: en_US didn't return USD " ) ;
}
2003-11-13 23:24:45 +00:00
ucurr_forLocale ( " en_US_EURO " , tmp , 4 , & status ) ;
resultStr . setTo ( tmp ) ;
2003-06-25 00:04:49 +00:00
if ( euroStr ! = resultStr ) {
errln ( " Fail: en_US_EURO didn't return EUR " ) ;
}
2003-11-13 23:24:45 +00:00
ucurr_forLocale ( " en_GB_EURO " , tmp , 4 , & status ) ;
resultStr . setTo ( tmp ) ;
2003-06-25 00:04:49 +00:00
if ( euroStr ! = resultStr ) {
errln ( " Fail: en_GB_EURO didn't return EUR " ) ;
}
2003-11-13 23:24:45 +00:00
ucurr_forLocale ( " en_US_PREEURO " , tmp , 4 , & status ) ;
resultStr . setTo ( tmp ) ;
2003-06-25 00:04:49 +00:00
if ( dollarStr ! = resultStr ) {
errln ( " Fail: en_US_PREEURO didn't fallback to en_US " ) ;
}
2003-11-13 23:24:45 +00:00
ucurr_forLocale ( " en_US_Q " , tmp , 4 , & status ) ;
resultStr . setTo ( tmp ) ;
2003-06-25 00:04:49 +00:00
if ( dollarStr ! = resultStr ) {
errln ( " Fail: en_US_Q didn't fallback to en_US " ) ;
}
2003-11-13 23:24:45 +00:00
int32_t invalidLen = ucurr_forLocale ( " en_QQ " , tmp , 4 , & status ) ;
if ( invalidLen | | U_SUCCESS ( status ) ) {
2003-06-25 00:04:49 +00:00
errln ( " Fail: en_QQ didn't return NULL " ) ;
1999-08-16 21:50:52 +00:00
}
}
2002-09-21 00:43:14 +00:00
# endif
1999-08-16 21:50:52 +00:00
/**
* @ bug 4139504
* toString ( ) doesn ' t work with language_VARIANT .
*/
2003-12-03 00:25:25 +00:00
void
1999-08-16 21:50:52 +00:00
LocaleTest : : TestToString ( ) {
Locale DATA [ ] = {
Locale ( " xx " , " " , " " ) ,
Locale ( " " , " YY " , " " ) ,
Locale ( " " , " " , " ZZ " ) ,
Locale ( " xx " , " YY " , " " ) ,
Locale ( " xx " , " " , " ZZ " ) ,
Locale ( " " , " YY " , " ZZ " ) ,
Locale ( " xx " , " YY " , " ZZ " ) ,
} ;
2000-04-15 21:28:17 +00:00
const char DATA_S [ ] [ 20 ] = {
1999-08-16 21:50:52 +00:00
" xx " ,
" _YY " ,
" __ZZ " ,
" xx_YY " ,
" xx__ZZ " ,
" _YY_ZZ " ,
" xx_YY_ZZ " ,
} ;
2003-12-03 00:25:25 +00:00
1999-08-16 21:50:52 +00:00
for ( int32_t i = 0 ; i < 7 ; + + i ) {
2000-04-15 21:28:17 +00:00
const char * name ;
name = DATA [ i ] . getName ( ) ;
if ( strcmp ( name , DATA_S [ i ] ) ! = 0 )
{
errln ( " Fail: Locale.getName(), got: " + UnicodeString ( name ) + " , expected: " + DATA_S [ i ] ) ;
1999-08-16 21:50:52 +00:00
}
else
2000-04-15 21:28:17 +00:00
logln ( " Pass: Locale.getName(), got: " + UnicodeString ( name ) ) ;
1999-08-16 21:50:52 +00:00
}
}
2002-09-21 00:43:14 +00:00
# if !UCONFIG_NO_FORMATTING
1999-08-16 21:50:52 +00:00
/**
* @ bug 4139940
* Couldn ' t reproduce this bug - - probably was fixed earlier .
*
* ORIGINAL BUG REPORT :
2003-12-03 00:25:25 +00:00
* - - basically , hungarian for monday shouldn ' t have an \ u00f4
* ( o circumflex ) in it instead it should be an o with 2 inclined
1999-08-16 21:50:52 +00:00
* ( right ) lines over it . .
*
* You may wonder - - why do all this - - why not just add a line to
* LocaleData ? Well , I could see by inspection that the locale file had the
* right character in it , so I wanted to check the rest of the pipeline - - a
* very remote possibility , but I wanted to be sure . The other possibility
* is that something is wrong with the font mapping subsystem , but we can ' t
* test that here .
*/
2003-12-03 00:25:25 +00:00
void
LocaleTest : : Test4139940 ( )
1999-08-16 21:50:52 +00:00
{
2003-12-03 00:25:25 +00:00
Locale mylocale ( " hu " , " " , " " ) ;
1999-08-16 21:50:52 +00:00
UDate mydate = date ( 98 , 3 , 13 ) ; // A Monday
1999-10-07 00:07:53 +00:00
UErrorCode status = U_ZERO_ERROR ;
1999-08-16 21:50:52 +00:00
SimpleDateFormat df_full ( " EEEE " , mylocale , status ) ;
2005-05-19 20:28:20 +00:00
if ( U_FAILURE ( status ) ) {
errln ( UnicodeString ( " Could not create SimpleDateFormat object for locale hu. Error: " ) + UnicodeString ( u_errorName ( status ) ) ) ;
return ;
}
1999-08-16 21:50:52 +00:00
UnicodeString str ;
FieldPosition pos ( FieldPosition : : DONT_CARE ) ;
df_full . format ( mydate , str , pos ) ;
// Make sure that o circumflex (\u00F4) is NOT there, and
// o double acute (\u0151) IS.
UChar ocf = 0x00f4 ;
UChar oda = 0x0151 ;
2003-10-26 10:20:40 +00:00
if ( str . indexOf ( oda ) < 0 | | str . indexOf ( ocf ) > = 0 ) {
errln ( " Fail: Monday in Hungarian is wrong - oda's index is %d and ocf's is %d " ,
str . indexOf ( oda ) , str . indexOf ( ocf ) ) ;
logln ( UnicodeString ( " String is: " ) + str ) ;
}
1999-08-16 21:50:52 +00:00
}
UDate
LocaleTest : : date ( int32_t y , int32_t m , int32_t d , int32_t hr , int32_t min , int32_t sec )
{
1999-10-07 00:07:53 +00:00
UErrorCode status = U_ZERO_ERROR ;
1999-08-16 21:50:52 +00:00
Calendar * cal = Calendar : : createInstance ( status ) ;
2003-12-03 00:25:25 +00:00
if ( cal = = 0 )
1999-08-16 21:50:52 +00:00
return 0.0 ;
cal - > clear ( ) ;
cal - > set ( 1900 + y , m , d , hr , min , sec ) ; // Add 1900 to follow java.util.Date protocol
UDate dt = cal - > getTime ( status ) ;
1999-10-18 22:48:32 +00:00
if ( U_FAILURE ( status ) )
1999-08-16 21:50:52 +00:00
return 0.0 ;
2003-12-03 00:25:25 +00:00
1999-08-16 21:50:52 +00:00
delete cal ;
return dt ;
}
/**
* @ bug 4143951
* Russian first day of week should be Monday . Confirmed .
*/
2003-12-03 00:25:25 +00:00
void
LocaleTest : : Test4143951 ( )
1999-08-16 21:50:52 +00:00
{
1999-10-07 00:07:53 +00:00
UErrorCode status = U_ZERO_ERROR ;
1999-08-16 21:50:52 +00:00
Calendar * cal = Calendar : : createInstance ( Locale ( " ru " , " " , " " ) , status ) ;
2003-06-04 23:56:49 +00:00
if ( U_SUCCESS ( status ) ) {
if ( cal - > getFirstDayOfWeek ( status ) ! = UCAL_MONDAY ) {
errln ( " Fail: First day of week in Russia should be Monday " ) ;
}
1999-08-16 21:50:52 +00:00
}
delete cal ;
}
2002-09-21 00:43:14 +00:00
# endif
1999-08-16 21:50:52 +00:00
/**
* @ bug 4147315
* java . util . Locale . getISO3Country ( ) works wrong for non ISO - 3166 codes .
* Should throw an exception for unknown locales
*/
2003-12-03 00:25:25 +00:00
void
LocaleTest : : Test4147315 ( )
1999-08-16 21:50:52 +00:00
{
2000-04-15 21:28:17 +00:00
UnicodeString temp ;
1999-08-16 21:50:52 +00:00
// Try with codes that are the wrong length but happen to match text
// at a valid offset in the mapping table
Locale locale ( " aaa " , " CCC " ) ;
2003-12-03 00:25:25 +00:00
2000-04-15 21:28:17 +00:00
const char * result = locale . getISO3Country ( ) ;
1999-08-16 21:50:52 +00:00
2000-04-15 21:28:17 +00:00
// Change to conform to C api usage
if ( ( result = = NULL ) | | ( result [ 0 ] ! = 0 ) )
2003-12-03 00:25:25 +00:00
errln ( " ERROR: getISO3Country() returns: " + UnicodeString ( result , " " ) +
2000-04-15 21:28:17 +00:00
" for locale ' " + ( temp = locale . getName ( ) ) + " ' rather than exception " ) ;
1999-08-16 21:50:52 +00:00
}
/**
* @ bug 4147317
* java . util . Locale . getISO3Language ( ) works wrong for non ISO - 3166 codes .
* Should throw an exception for unknown locales
*/
2003-12-03 00:25:25 +00:00
void
LocaleTest : : Test4147317 ( )
1999-08-16 21:50:52 +00:00
{
2000-04-15 21:28:17 +00:00
UnicodeString temp ;
1999-08-16 21:50:52 +00:00
// Try with codes that are the wrong length but happen to match text
// at a valid offset in the mapping table
Locale locale ( " aaa " , " CCC " ) ;
2003-12-03 00:25:25 +00:00
2000-04-15 21:28:17 +00:00
const char * result = locale . getISO3Language ( ) ;
1999-08-16 21:50:52 +00:00
2000-04-15 21:28:17 +00:00
// Change to conform to C api usage
if ( ( result = = NULL ) | | ( result [ 0 ] ! = 0 ) )
2003-12-03 00:25:25 +00:00
errln ( " ERROR: getISO3Language() returns: " + UnicodeString ( result , " " ) +
2000-04-15 21:28:17 +00:00
" for locale ' " + ( temp = locale . getName ( ) ) + " ' rather than exception " ) ;
1999-08-16 21:50:52 +00:00
}
/*
* @ bug 4147552
*/
2003-12-03 00:25:25 +00:00
void
LocaleTest : : Test4147552 ( )
1999-08-16 21:50:52 +00:00
{
2003-12-03 00:25:25 +00:00
Locale locales [ ] = { Locale ( " no " , " NO " ) ,
1999-08-16 21:50:52 +00:00
Locale ( " no " , " NO " , " B " ) ,
2003-12-03 00:25:25 +00:00
Locale ( " no " , " NO " , " NY " )
1999-08-16 21:50:52 +00:00
} ;
2003-12-03 00:25:25 +00:00
2003-10-03 17:40:03 +00:00
UnicodeString edn ( " Norwegian (Norway, B) " ) ;
2003-12-03 00:25:25 +00:00
UnicodeString englishDisplayNames [ ] = {
1999-08-16 21:50:52 +00:00
" Norwegian (Norway) " ,
edn ,
// "Norwegian (Norway,B)",
2003-12-03 00:25:25 +00:00
//"Norwegian (Norway,NY)"
2003-12-09 23:19:32 +00:00
" Norwegian (Norway, NY) "
1999-08-16 21:50:52 +00:00
} ;
2003-10-03 17:40:03 +00:00
UnicodeString ndn ( " norsk (Norge, B " ) ;
2003-12-03 00:25:25 +00:00
UnicodeString norwegianDisplayNames [ ] = {
2003-10-03 17:40:03 +00:00
" norsk (Norge) " ,
2003-12-03 00:25:25 +00:00
" norsk (Norge, B) " ,
//ndn,
" norsk (Noreg, NY) "
//"Norsk (Noreg, Nynorsk)"
1999-08-16 21:50:52 +00:00
} ;
2004-12-22 19:28:42 +00:00
UErrorCode status = U_ZERO_ERROR ;
1999-08-16 21:50:52 +00:00
2004-12-22 19:28:42 +00:00
Locale saveLocale ;
Locale : : setDefault ( Locale : : getEnglish ( ) , status ) ;
1999-08-16 21:50:52 +00:00
for ( int32_t i = 0 ; i < 3 ; + + i ) {
Locale loc = locales [ i ] ;
UnicodeString temp ;
if ( loc . getDisplayName ( temp ) ! = englishDisplayNames [ i ] )
errln ( " English display-name mismatch: expected " +
englishDisplayNames [ i ] + " , got " + loc . getDisplayName ( temp ) ) ;
if ( loc . getDisplayName ( loc , temp ) ! = norwegianDisplayNames [ i ] )
errln ( " Norwegian display-name mismatch: expected " +
norwegianDisplayNames [ i ] + " , got " +
loc . getDisplayName ( loc , temp ) ) ;
}
2004-12-22 19:28:42 +00:00
Locale : : setDefault ( saveLocale , status ) ;
1999-08-16 21:50:52 +00:00
}
void
LocaleTest : : TestVariantParsing ( )
{
Locale en_US_custom ( " en " , " US " , " De Anza_Cupertino_California_United States_Earth " ) ;
UnicodeString dispName ( " English (United States, DE ANZA_CUPERTINO_CALIFORNIA_UNITED STATES_EARTH) " ) ;
UnicodeString dispVar ( " DE ANZA_CUPERTINO_CALIFORNIA_UNITED STATES_EARTH " ) ;
2003-12-03 00:25:25 +00:00
1999-08-16 21:50:52 +00:00
UnicodeString got ;
2003-12-03 00:25:25 +00:00
2002-03-26 23:18:57 +00:00
en_US_custom . getDisplayVariant ( Locale : : getUS ( ) , got ) ;
1999-08-16 21:50:52 +00:00
if ( got ! = dispVar ) {
errln ( " FAIL: getDisplayVariant() " ) ;
errln ( " Wanted: " + dispVar ) ;
errln ( " Got : " + got ) ;
}
2002-03-26 23:18:57 +00:00
en_US_custom . getDisplayName ( Locale : : getUS ( ) , got ) ;
1999-08-16 21:50:52 +00:00
if ( got ! = dispName ) {
errln ( " FAIL: getDisplayName() " ) ;
errln ( " Wanted: " + dispName ) ;
errln ( " Got : " + got ) ;
}
Locale shortVariant ( " fr " , " FR " , " foo " ) ;
shortVariant . getDisplayVariant ( got ) ;
2003-12-03 00:25:25 +00:00
1999-08-16 21:50:52 +00:00
if ( got ! = " FOO " ) {
errln ( " FAIL: getDisplayVariant() " ) ;
errln ( " Wanted: foo " ) ;
errln ( " Got : " + got ) ;
}
Locale bogusVariant ( " fr " , " FR " , " _foo " ) ;
bogusVariant . getDisplayVariant ( got ) ;
2003-12-03 00:25:25 +00:00
1999-08-16 21:50:52 +00:00
if ( got ! = " FOO " ) {
errln ( " FAIL: getDisplayVariant() " ) ;
errln ( " Wanted: foo " ) ;
errln ( " Got : " + got ) ;
}
Locale bogusVariant2 ( " fr " , " FR " , " foo_ " ) ;
bogusVariant2 . getDisplayVariant ( got ) ;
2003-12-03 00:25:25 +00:00
1999-08-16 21:50:52 +00:00
if ( got ! = " FOO " ) {
errln ( " FAIL: getDisplayVariant() " ) ;
errln ( " Wanted: foo " ) ;
errln ( " Got : " + got ) ;
}
Locale bogusVariant3 ( " fr " , " FR " , " _foo_ " ) ;
bogusVariant3 . getDisplayVariant ( got ) ;
2003-12-03 00:25:25 +00:00
1999-08-16 21:50:52 +00:00
if ( got ! = " FOO " ) {
errln ( " FAIL: getDisplayVariant() " ) ;
errln ( " Wanted: foo " ) ;
errln ( " Got : " + got ) ;
}
}
2002-09-21 00:43:14 +00:00
# if !UCONFIG_NO_FORMATTING
1999-08-16 21:50:52 +00:00
/**
* @ bug 4105828
* Currency symbol in zh is wrong . We will test this at the NumberFormat
* end to test the whole pipe .
*/
2003-12-03 00:25:25 +00:00
void
LocaleTest : : Test4105828 ( )
1999-08-16 21:50:52 +00:00
{
2002-03-26 23:18:57 +00:00
Locale LOC [ ] = { Locale : : getChinese ( ) , Locale ( " zh " , " CN " , " " ) ,
1999-08-16 21:50:52 +00:00
Locale ( " zh " , " TW " , " " ) , Locale ( " zh " , " HK " , " " ) } ;
1999-10-07 00:07:53 +00:00
UErrorCode status = U_ZERO_ERROR ;
1999-08-16 21:50:52 +00:00
for ( int32_t i = 0 ; i < 4 ; + + i ) {
NumberFormat * fmt = NumberFormat : : createPercentInstance ( LOC [ i ] , status ) ;
1999-10-18 22:48:32 +00:00
if ( U_FAILURE ( status ) ) {
1999-08-16 21:50:52 +00:00
errln ( " Couldn't create NumberFormat " ) ;
return ;
}
UnicodeString result ;
FieldPosition pos ( 0 ) ;
fmt - > format ( ( int32_t ) 1 , result , pos ) ;
UnicodeString temp ;
if ( result ! = " 100% " ) {
errln ( UnicodeString ( " Percent for " ) + LOC [ i ] . getDisplayName ( temp ) + " should be 100%, got " + result ) ;
}
delete fmt ;
}
}
2002-02-28 21:32:28 +00:00
2002-09-21 00:43:14 +00:00
# endif
2002-02-28 21:32:28 +00:00
// Tests setBogus and isBogus APIs for Locale
// Jitterbug 1735
void
LocaleTest : : TestSetIsBogus ( ) {
2003-12-03 00:25:25 +00:00
Locale l ( " en_US " ) ;
l . setToBogus ( ) ;
if ( l . isBogus ( ) ! = TRUE ) {
errln ( " After setting bogus, didn't return TRUE " ) ;
}
l = " en_US " ; // This should reset bogus
if ( l . isBogus ( ) ! = FALSE ) {
errln ( " After resetting bogus, didn't return FALSE " ) ;
}
2002-03-01 03:47:13 +00:00
}
2003-10-15 05:32:40 +00:00
2003-12-03 00:25:25 +00:00
void
2003-10-15 05:32:40 +00:00
LocaleTest : : TestKeywordVariants ( void ) {
2006-10-01 06:45:25 +00:00
static const struct {
2003-12-03 00:25:25 +00:00
const char * localeID ;
const char * expectedLocaleID ;
2004-05-14 22:45:27 +00:00
//const char *expectedLocaleIDNoKeywords;
//const char *expectedCanonicalID;
2003-12-03 00:25:25 +00:00
const char * expectedKeywords [ 10 ] ;
int32_t numKeywords ;
UErrorCode expectedStatus ;
} testCases [ ] = {
2004-05-14 22:45:27 +00:00
{
" de_DE@ currency = euro; C o ll A t i o n = Phonebook ; C alen dar = buddhist " ,
" de_DE@calendar=buddhist;collation=Phonebook;currency=euro " ,
//"de_DE",
//"de_DE@calendar=buddhist;collation=Phonebook;currency=euro",
{ " calendar " , " collation " , " currency " } ,
3 ,
U_ZERO_ERROR
2003-12-03 00:25:25 +00:00
} ,
2004-05-14 22:45:27 +00:00
{
" de_DE@euro " ,
" de_DE@euro " ,
//"de_DE",
//"de_DE@currency=EUR",
{ " " , " " , " " , " " , " " , " " , " " } ,
0 ,
U_INVALID_FORMAT_ERROR /* must have '=' after '@' */
}
2003-12-03 00:25:25 +00:00
} ;
UErrorCode status = U_ZERO_ERROR ;
2003-10-15 05:32:40 +00:00
2003-12-03 00:25:25 +00:00
int32_t i = 0 , j = 0 ;
const char * result = NULL ;
StringEnumeration * keywords ;
int32_t keyCount = 0 ;
const char * keyword = NULL ;
const UnicodeString * keywordString ;
int32_t keywordLen = 0 ;
for ( i = 0 ; i < ( int32_t ) ( sizeof ( testCases ) / sizeof ( testCases [ 0 ] ) ) ; i + + ) {
status = U_ZERO_ERROR ;
Locale l ( testCases [ i ] . localeID ) ;
keywords = l . createKeywords ( status ) ;
if ( status ! = testCases [ i ] . expectedStatus ) {
err ( " Expected to get status %s. Got %s instead \n " ,
u_errorName ( testCases [ i ] . expectedStatus ) , u_errorName ( status ) ) ;
}
status = U_ZERO_ERROR ;
if ( keywords ) {
if ( ( keyCount = keywords - > count ( status ) ) ! = testCases [ i ] . numKeywords ) {
err ( " Expected to get %i keywords, got %i \n " , testCases [ i ] . numKeywords , keyCount ) ;
2003-11-06 23:25:00 +00:00
}
2003-12-03 00:25:25 +00:00
if ( keyCount ) {
for ( j = 0 ; ; ) {
if ( ( j & 1 ) = = 0 ) {
if ( ( keyword = keywords - > next ( & keywordLen , status ) ) = = NULL ) {
break ;
}
if ( strcmp ( keyword , testCases [ i ] . expectedKeywords [ j ] ) ! = 0 ) {
err ( " Expected to get keyword value %s, got %s \n " , testCases [ i ] . expectedKeywords [ j ] , keyword ) ;
}
} else {
if ( ( keywordString = keywords - > snext ( status ) ) = = NULL ) {
break ;
}
if ( * keywordString ! = UnicodeString ( testCases [ i ] . expectedKeywords [ j ] , " " ) ) {
err ( " Expected to get keyword UnicodeString %s, got %s \n " , testCases [ i ] . expectedKeywords [ j ] , keyword ) ;
}
}
j + + ;
if ( j = = keyCount / 2 ) {
// replace keywords with a clone of itself
StringEnumeration * k2 = keywords - > clone ( ) ;
if ( k2 = = NULL | | keyCount ! = k2 - > count ( status ) ) {
errln ( " KeywordEnumeration.clone() failed " ) ;
} else {
delete keywords ;
keywords = k2 ;
}
}
}
2004-12-22 06:36:14 +00:00
keywords - > reset ( status ) ; // Make sure that reset works.
for ( j = 0 ; ; ) {
if ( ( keyword = keywords - > next ( & keywordLen , status ) ) = = NULL ) {
break ;
}
if ( strcmp ( keyword , testCases [ i ] . expectedKeywords [ j ] ) ! = 0 ) {
err ( " Expected to get keyword value %s, got %s \n " , testCases [ i ] . expectedKeywords [ j ] , keyword ) ;
}
j + + ;
}
2003-11-05 02:06:36 +00:00
}
2003-12-03 00:25:25 +00:00
delete keywords ;
}
result = l . getName ( ) ;
if ( uprv_strcmp ( testCases [ i ] . expectedLocaleID , result ) ! = 0 ) {
err ( " Expected to get \" %s \" from \" %s \" . Got \" %s \" instead \n " ,
testCases [ i ] . expectedLocaleID , testCases [ i ] . localeID , result ) ;
2003-10-15 05:32:40 +00:00
}
2003-12-03 00:25:25 +00:00
}
2003-10-15 05:32:40 +00:00
}
2003-12-03 00:25:25 +00:00
void
2003-10-15 05:32:40 +00:00
LocaleTest : : TestKeywordVariantParsing ( void ) {
2006-10-01 06:45:25 +00:00
static const struct {
2003-12-03 00:25:25 +00:00
const char * localeID ;
const char * keyword ;
const char * expectedValue ;
} testCases [ ] = {
2004-05-14 22:45:27 +00:00
{ " de_DE@ C o ll A t i o n = Phonebook " , " collation " , " Phonebook " } ,
2003-12-03 00:25:25 +00:00
{ " de_DE " , " collation " , " " } ,
{ " de_DE@collation= PHONEBOOK " , " collation " , " PHONEBOOK " } ,
2004-05-14 22:45:27 +00:00
{ " de_DE@ currency = euro ; CoLLaTion = PHONEBOOk " , " collation " , " PHONEBOOk " } ,
2003-12-03 00:25:25 +00:00
} ;
2003-10-15 05:32:40 +00:00
2003-12-03 00:25:25 +00:00
UErrorCode status = U_ZERO_ERROR ;
2003-10-15 05:32:40 +00:00
2003-12-03 00:25:25 +00:00
int32_t i = 0 ;
int32_t resultLen = 0 ;
char buffer [ 256 ] ;
for ( i = 0 ; i < ( int32_t ) ( sizeof ( testCases ) / sizeof ( testCases [ 0 ] ) ) ; i + + ) {
* buffer = 0 ;
Locale l ( testCases [ i ] . localeID ) ;
resultLen = l . getKeywordValue ( testCases [ i ] . keyword , buffer , 256 , status ) ;
if ( uprv_strcmp ( testCases [ i ] . expectedValue , buffer ) ! = 0 ) {
err ( " Expected to extract \" %s \" from \" %s \" for keyword \" %s \" . Got \" %s \" instead \n " ,
testCases [ i ] . expectedValue , testCases [ i ] . localeID , testCases [ i ] . keyword , buffer ) ;
}
2003-10-15 05:32:40 +00:00
}
}
2003-12-03 00:25:25 +00:00
2004-01-09 08:08:26 +00:00
void
LocaleTest : : TestGetBaseName ( void ) {
2006-10-01 06:45:25 +00:00
static const struct {
2004-01-09 08:08:26 +00:00
const char * localeID ;
const char * baseName ;
} testCases [ ] = {
{ " de_DE@ C o ll A t i o n = Phonebook " , " de_DE " } ,
{ " de@currency = euro; CoLLaTion = PHONEBOOk " , " de " } ,
{ " ja@calendar = buddhist " , " ja " }
} ;
2004-01-13 00:09:55 +00:00
int32_t i = 0 ;
2004-01-09 08:08:26 +00:00
2004-01-13 00:09:55 +00:00
for ( i = 0 ; i < ( int32_t ) ( sizeof ( testCases ) / sizeof ( testCases [ 0 ] ) ) ; i + + ) {
2004-01-09 08:08:26 +00:00
Locale loc ( testCases [ i ] . localeID ) ;
if ( strcmp ( testCases [ i ] . baseName , loc . getBaseName ( ) ) ) {
errln ( " For locale \" %s \" expected baseName \" %s \" , but got \" %s \" " ,
testCases [ i ] . localeID , testCases [ i ] . baseName , loc . getBaseName ( ) ) ;
return ;
}
}
}
2004-01-13 00:09:55 +00:00
2004-01-23 18:05:46 +00:00
/**
* Compare two locale IDs . If they are equal , return 0. If ` string '
* starts with ` prefix ' plus an additional element , that is , string = =
* prefix + ' _ ' + x , then return 1. Otherwise return a value < 0.
*/
static UBool _loccmp ( const char * string , const char * prefix ) {
2004-11-05 17:21:42 +00:00
int32_t slen = ( int32_t ) strlen ( string ) ,
plen = ( int32_t ) strlen ( prefix ) ;
2004-01-23 18:05:46 +00:00
int32_t c = uprv_strncmp ( string , prefix , plen ) ;
/* 'root' is "less than" everything */
if ( uprv_strcmp ( prefix , " root " ) = = 0 ) {
return ( uprv_strcmp ( string , " root " ) = = 0 ) ? 0 : 1 ;
}
if ( c ) return - 1 ; /* mismatch */
if ( slen = = plen ) return 0 ;
if ( string [ plen ] = = ' _ ' ) return 1 ;
return - 2 ; /* false match, e.g. "en_USX" cmp "en_US" */
}
/**
* Check the relationship between requested locales , and report problems .
* The caller specifies the expected relationships between requested
* and valid ( expReqValid ) and between valid and actual ( expValidActual ) .
* Possible values are :
* " gt " strictly greater than , e . g . , en_US > en
* " ge " greater or equal , e . g . , en > = en
* " eq " equal , e . g . , en = = en
*/
void LocaleTest : : _checklocs ( const char * label ,
const char * req ,
const Locale & validLoc ,
const Locale & actualLoc ,
const char * expReqValid ,
const char * expValidActual ) {
const char * valid = validLoc . getName ( ) ;
const char * actual = actualLoc . getName ( ) ;
int32_t reqValid = _loccmp ( req , valid ) ;
int32_t validActual = _loccmp ( valid , actual ) ;
if ( ( ( 0 = = uprv_strcmp ( expReqValid , " gt " ) & & reqValid > 0 ) | |
( 0 = = uprv_strcmp ( expReqValid , " ge " ) & & reqValid > = 0 ) | |
( 0 = = uprv_strcmp ( expReqValid , " eq " ) & & reqValid = = 0 ) ) & &
( ( 0 = = uprv_strcmp ( expValidActual , " gt " ) & & validActual > 0 ) | |
( 0 = = uprv_strcmp ( expValidActual , " ge " ) & & validActual > = 0 ) | |
( 0 = = uprv_strcmp ( expValidActual , " eq " ) & & validActual = = 0 ) ) ) {
logln ( " %s; req=%s, valid=%s, actual=%s " ,
label , req , valid , actual ) ;
} else {
2004-05-18 01:51:31 +00:00
errln ( " FAIL: %s; req=%s, valid=%s, actual=%s. Require (R %s V) and (V %s A) " ,
label , req , valid , actual ,
expReqValid , expValidActual ) ;
2004-01-23 18:05:46 +00:00
}
}
2004-03-07 07:13:42 +00:00
void LocaleTest : : TestGetLocale ( void ) {
2004-07-18 02:02:06 +00:00
# if !UCONFIG_NO_SERVICE
2004-01-23 18:05:46 +00:00
UErrorCode ec = U_ZERO_ERROR ;
const char * req ;
Locale valid , actual , reqLoc ;
// Calendar
2004-01-26 21:58:16 +00:00
# if !UCONFIG_NO_FORMATTING
2004-01-23 18:05:46 +00:00
req = " en_US_BROOKLYN " ;
Calendar * cal = Calendar : : createInstance ( Locale : : createFromName ( req ) , ec ) ;
if ( U_FAILURE ( ec ) ) {
errln ( " FAIL: Calendar::createInstance failed " ) ;
} else {
valid = cal - > getLocale ( ULOC_VALID_LOCALE , ec ) ;
actual = cal - > getLocale ( ULOC_ACTUAL_LOCALE , ec ) ;
if ( U_FAILURE ( ec ) ) {
errln ( " FAIL: Calendar::getLocale() failed " ) ;
} else {
_checklocs ( " Calendar " , req , valid , actual ) ;
}
2004-12-28 20:31:49 +00:00
/* Make sure that it fails correctly */
ec = U_FILE_ACCESS_ERROR ;
if ( cal - > getLocale ( ULOC_VALID_LOCALE , ec ) . getName ( ) [ 0 ] ! = 0 ) {
errln ( " FAIL: Calendar::getLocale() failed to fail correctly. It should have returned \" \" " ) ;
}
ec = U_ZERO_ERROR ;
2004-01-23 18:05:46 +00:00
}
delete cal ;
2004-01-26 21:58:16 +00:00
# endif
2004-01-23 18:05:46 +00:00
// DecimalFormat, DecimalFormatSymbols
2004-01-26 21:58:16 +00:00
# if !UCONFIG_NO_FORMATTING
2004-01-23 18:05:46 +00:00
req = " fr_FR_NICE " ;
DecimalFormat * dec = ( DecimalFormat * )
2005-07-05 18:39:00 +00:00
NumberFormat : : createInstance ( Locale : : createFromName ( req ) , ec ) ;
2004-01-23 18:05:46 +00:00
if ( U_FAILURE ( ec ) ) {
errln ( " FAIL: NumberFormat::createInstance failed " ) ;
} else {
2006-07-06 01:50:03 +00:00
if ( dec - > getDynamicClassID ( ) ! = DecimalFormat : : getStaticClassID ( ) ) {
errln ( " FAIL: NumberFormat::createInstance does not return a DecimalFormat " ) ;
return ;
}
2004-01-23 18:05:46 +00:00
valid = dec - > getLocale ( ULOC_VALID_LOCALE , ec ) ;
actual = dec - > getLocale ( ULOC_ACTUAL_LOCALE , ec ) ;
if ( U_FAILURE ( ec ) ) {
errln ( " FAIL: DecimalFormat::getLocale() failed " ) ;
} else {
_checklocs ( " DecimalFormat " , req , valid , actual ) ;
}
const DecimalFormatSymbols * sym = dec - > getDecimalFormatSymbols ( ) ;
2006-07-06 01:50:03 +00:00
if ( sym = = NULL ) {
errln ( " FAIL: getDecimalFormatSymbols returned NULL " ) ;
return ;
}
2004-01-23 18:05:46 +00:00
valid = sym - > getLocale ( ULOC_VALID_LOCALE , ec ) ;
actual = sym - > getLocale ( ULOC_ACTUAL_LOCALE , ec ) ;
if ( U_FAILURE ( ec ) ) {
errln ( " FAIL: DecimalFormatSymbols::getLocale() failed " ) ;
} else {
_checklocs ( " DecimalFormatSymbols " , req , valid , actual ) ;
}
}
delete dec ;
2004-01-26 21:58:16 +00:00
# endif
2004-01-23 18:05:46 +00:00
// DateFormat, DateFormatSymbols
2004-01-26 21:58:16 +00:00
# if !UCONFIG_NO_FORMATTING
2004-01-23 18:05:46 +00:00
req = " de_CH_LUCERNE " ;
SimpleDateFormat * dat = ( SimpleDateFormat * )
DateFormat : : createDateInstance ( DateFormat : : kDefault ,
Locale : : createFromName ( req ) ) ;
2005-07-05 18:39:00 +00:00
if ( dat = = 0 ) {
dataerrln ( " Error calling DateFormat::createDateInstance() " ) ;
2004-01-23 18:05:46 +00:00
} else {
2006-07-06 01:50:03 +00:00
if ( dat - > getDynamicClassID ( ) ! = SimpleDateFormat : : getStaticClassID ( ) ) {
errln ( " FAIL: NumberFormat::createInstance does not return a DecimalFormat " ) ;
return ;
}
2005-07-05 18:39:00 +00:00
valid = dat - > getLocale ( ULOC_VALID_LOCALE , ec ) ;
actual = dat - > getLocale ( ULOC_ACTUAL_LOCALE , ec ) ;
if ( U_FAILURE ( ec ) ) {
errln ( " FAIL: SimpleDateFormat::getLocale() failed " ) ;
} else {
_checklocs ( " SimpleDateFormat " , req , valid , actual ) ;
}
2004-01-23 18:05:46 +00:00
2005-07-05 18:39:00 +00:00
const DateFormatSymbols * sym = dat - > getDateFormatSymbols ( ) ;
2006-07-06 01:50:03 +00:00
if ( sym = = NULL ) {
errln ( " FAIL: getDateFormatSymbols returned NULL " ) ;
return ;
}
2005-07-05 18:39:00 +00:00
valid = sym - > getLocale ( ULOC_VALID_LOCALE , ec ) ;
actual = sym - > getLocale ( ULOC_ACTUAL_LOCALE , ec ) ;
if ( U_FAILURE ( ec ) ) {
errln ( " FAIL: DateFormatSymbols::getLocale() failed " ) ;
} else {
_checklocs ( " DateFormatSymbols " , req , valid , actual ) ;
}
}
2004-01-23 18:05:46 +00:00
delete dat ;
2004-01-26 21:58:16 +00:00
# endif
2004-01-23 18:05:46 +00:00
// BreakIterator
2004-01-26 21:58:16 +00:00
# if !UCONFIG_NO_BREAK_ITERATION
2004-01-23 18:05:46 +00:00
req = " es_ES_BARCELONA " ;
reqLoc = Locale : : createFromName ( req ) ;
BreakIterator * brk = BreakIterator : : createWordInstance ( reqLoc , ec ) ;
if ( U_FAILURE ( ec ) ) {
errln ( " FAIL: BreakIterator::createWordInstance failed " ) ;
} else {
valid = brk - > getLocale ( ULOC_VALID_LOCALE , ec ) ;
actual = brk - > getLocale ( ULOC_ACTUAL_LOCALE , ec ) ;
if ( U_FAILURE ( ec ) ) {
errln ( " FAIL: BreakIterator::getLocale() failed " ) ;
} else {
_checklocs ( " BreakIterator " , req , valid , actual ) ;
}
// After registering something, the behavior should be different
URegistryKey key = BreakIterator : : registerInstance ( brk , reqLoc , UBRK_WORD , ec ) ;
brk = 0 ; // registerInstance adopts
if ( U_FAILURE ( ec ) ) {
errln ( " FAIL: BreakIterator::registerInstance() failed " ) ;
} else {
brk = BreakIterator : : createWordInstance ( reqLoc , ec ) ;
if ( U_FAILURE ( ec ) ) {
errln ( " FAIL: BreakIterator::createWordInstance failed " ) ;
} else {
valid = brk - > getLocale ( ULOC_VALID_LOCALE , ec ) ;
actual = brk - > getLocale ( ULOC_ACTUAL_LOCALE , ec ) ;
if ( U_FAILURE ( ec ) ) {
errln ( " FAIL: BreakIterator::getLocale() failed " ) ;
} else {
// N.B.: now expect valid==actual==req
_checklocs ( " BreakIterator(registered) " ,
req , valid , actual , " eq " , " eq " ) ;
}
}
// No matter what, unregister
BreakIterator : : unregister ( key , ec ) ;
if ( U_FAILURE ( ec ) ) {
errln ( " FAIL: BreakIterator::unregister() failed " ) ;
}
delete brk ;
brk = 0 ;
}
// After unregistering, should behave normally again
brk = BreakIterator : : createWordInstance ( reqLoc , ec ) ;
if ( U_FAILURE ( ec ) ) {
errln ( " FAIL: BreakIterator::createWordInstance failed " ) ;
} else {
valid = brk - > getLocale ( ULOC_VALID_LOCALE , ec ) ;
actual = brk - > getLocale ( ULOC_ACTUAL_LOCALE , ec ) ;
if ( U_FAILURE ( ec ) ) {
errln ( " FAIL: BreakIterator::getLocale() failed " ) ;
} else {
_checklocs ( " BreakIterator(unregistered) " , req , valid , actual ) ;
}
}
}
delete brk ;
2004-01-26 21:58:16 +00:00
# endif
2004-01-23 18:05:46 +00:00
// Collator
2004-01-26 21:58:16 +00:00
# if !UCONFIG_NO_COLLATION
2004-01-23 18:05:46 +00:00
req = " hi_IN_BHOPAL " ;
reqLoc = Locale : : createFromName ( req ) ;
Collator * coll = Collator : : createInstance ( reqLoc , ec ) ;
if ( U_FAILURE ( ec ) ) {
errln ( " FAIL: Collator::createInstance failed " ) ;
} else {
valid = coll - > getLocale ( ULOC_VALID_LOCALE , ec ) ;
actual = coll - > getLocale ( ULOC_ACTUAL_LOCALE , ec ) ;
if ( U_FAILURE ( ec ) ) {
errln ( " FAIL: Collator::getLocale() failed " ) ;
} else {
_checklocs ( " Collator " , req , valid , actual ) ;
}
// After registering something, the behavior should be different
URegistryKey key = Collator : : registerInstance ( coll , reqLoc , ec ) ;
coll = 0 ; // registerInstance adopts
if ( U_FAILURE ( ec ) ) {
errln ( " FAIL: Collator::registerInstance() failed " ) ;
} else {
coll = Collator : : createInstance ( reqLoc , ec ) ;
if ( U_FAILURE ( ec ) ) {
errln ( " FAIL: Collator::createWordInstance failed " ) ;
} else {
valid = coll - > getLocale ( ULOC_VALID_LOCALE , ec ) ;
actual = coll - > getLocale ( ULOC_ACTUAL_LOCALE , ec ) ;
if ( U_FAILURE ( ec ) ) {
errln ( " FAIL: Collator::getLocale() failed " ) ;
} else {
// N.B.: now expect valid==actual==req
_checklocs ( " Collator(registered) " ,
req , valid , actual , " eq " , " eq " ) ;
}
}
// No matter what, unregister
Collator : : unregister ( key , ec ) ;
if ( U_FAILURE ( ec ) ) {
errln ( " FAIL: Collator::unregister() failed " ) ;
}
delete coll ;
coll = 0 ;
}
// After unregistering, should behave normally again
coll = Collator : : createInstance ( reqLoc , ec ) ;
if ( U_FAILURE ( ec ) ) {
errln ( " FAIL: Collator::createInstance failed " ) ;
} else {
valid = coll - > getLocale ( ULOC_VALID_LOCALE , ec ) ;
actual = coll - > getLocale ( ULOC_ACTUAL_LOCALE , ec ) ;
if ( U_FAILURE ( ec ) ) {
errln ( " FAIL: Collator::getLocale() failed " ) ;
} else {
_checklocs ( " Collator(unregistered) " , req , valid , actual ) ;
}
}
}
delete coll ;
2004-01-26 21:58:16 +00:00
# endif
2004-07-18 02:02:06 +00:00
# endif
2004-01-23 18:05:46 +00:00
}
2004-03-07 07:13:42 +00:00
void LocaleTest : : TestVariantWithOutCountry ( void ) {
Locale loc ( " en " , " " , " POSIX " ) ;
if ( 0 ! = strcmp ( loc . getVariant ( ) , " POSIX " ) ) {
errln ( " FAIL: en__POSIX didn't get parsed correctly " ) ;
}
Locale loc2 ( " en " , " " , " FOUR " ) ;
if ( 0 ! = strcmp ( loc2 . getVariant ( ) , " FOUR " ) ) {
errln ( " FAIL: en__FOUR didn't get parsed correctly " ) ;
}
Locale loc3 ( " en " , " Latn " , " " , " FOUR " ) ;
if ( 0 ! = strcmp ( loc3 . getVariant ( ) , " FOUR " ) ) {
errln ( " FAIL: en_Latn__FOUR didn't get parsed correctly " ) ;
}
Locale loc4 ( " " , " Latn " , " " , " FOUR " ) ;
if ( 0 ! = strcmp ( loc4 . getVariant ( ) , " FOUR " ) ) {
errln ( " FAIL: _Latn__FOUR didn't get parsed correctly " ) ;
}
Locale loc5 ( " " , " Latn " , " US " , " FOUR " ) ;
if ( 0 ! = strcmp ( loc5 . getVariant ( ) , " FOUR " ) ) {
errln ( " FAIL: _Latn_US_FOUR didn't get parsed correctly " ) ;
}
}
2004-05-18 20:07:33 +00:00
static Locale _canonicalize ( int32_t selector , /* 0==createFromName, 1==createCanonical, 2==Locale ct */
const char * localeID ) {
switch ( selector ) {
case 0 :
return Locale : : createFromName ( localeID ) ;
case 1 :
return Locale : : createCanonical ( localeID ) ;
case 2 :
return Locale ( localeID ) ;
default :
return Locale ( " " ) ;
}
}
void LocaleTest : : TestCanonicalization ( void )
{
2006-10-01 06:45:25 +00:00
static const struct {
2004-05-18 20:07:33 +00:00
const char * localeID ; /* input */
const char * getNameID ; /* expected getName() result */
const char * canonicalID ; /* expected canonicalize() result */
} testCases [ ] = {
2004-05-19 23:09:12 +00:00
{ " ca_ES_PREEURO-with-extra-stuff-that really doesn't make any sense-unless-you're trying to increase code coverage " ,
" ca_ES_PREEURO_WITH_EXTRA_STUFF_THAT REALLY DOESN'T MAKE ANY SENSE_UNLESS_YOU'RE TRYING TO INCREASE CODE COVERAGE " ,
" ca_ES_PREEURO_WITH_EXTRA_STUFF_THAT REALLY DOESN'T MAKE ANY SENSE_UNLESS_YOU'RE TRYING TO INCREASE CODE COVERAGE " } ,
2004-05-18 20:07:33 +00:00
{ " ca_ES_PREEURO " , " ca_ES_PREEURO " , " ca_ES@currency=ESP " } ,
{ " de_AT_PREEURO " , " de_AT_PREEURO " , " de_AT@currency=ATS " } ,
{ " de_DE_PREEURO " , " de_DE_PREEURO " , " de_DE@currency=DEM " } ,
2004-06-03 17:44:02 +00:00
{ " de_LU_PREEURO " , " de_LU_PREEURO " , " de_LU@currency=LUF " } ,
2004-05-18 20:07:33 +00:00
{ " el_GR_PREEURO " , " el_GR_PREEURO " , " el_GR@currency=GRD " } ,
{ " en_BE_PREEURO " , " en_BE_PREEURO " , " en_BE@currency=BEF " } ,
{ " en_IE_PREEURO " , " en_IE_PREEURO " , " en_IE@currency=IEP " } ,
{ " es_ES_PREEURO " , " es_ES_PREEURO " , " es_ES@currency=ESP " } ,
{ " eu_ES_PREEURO " , " eu_ES_PREEURO " , " eu_ES@currency=ESP " } ,
{ " fi_FI_PREEURO " , " fi_FI_PREEURO " , " fi_FI@currency=FIM " } ,
{ " fr_BE_PREEURO " , " fr_BE_PREEURO " , " fr_BE@currency=BEF " } ,
{ " fr_FR_PREEURO " , " fr_FR_PREEURO " , " fr_FR@currency=FRF " } ,
{ " fr_LU_PREEURO " , " fr_LU_PREEURO " , " fr_LU@currency=LUF " } ,
{ " ga_IE_PREEURO " , " ga_IE_PREEURO " , " ga_IE@currency=IEP " } ,
{ " gl_ES_PREEURO " , " gl_ES_PREEURO " , " gl_ES@currency=ESP " } ,
{ " it_IT_PREEURO " , " it_IT_PREEURO " , " it_IT@currency=ITL " } ,
{ " nl_BE_PREEURO " , " nl_BE_PREEURO " , " nl_BE@currency=BEF " } ,
{ " nl_NL_PREEURO " , " nl_NL_PREEURO " , " nl_NL@currency=NLG " } ,
{ " pt_PT_PREEURO " , " pt_PT_PREEURO " , " pt_PT@currency=PTE " } ,
{ " de__PHONEBOOK " , " de__PHONEBOOK " , " de@collation=phonebook " } ,
{ " en_GB_EURO " , " en_GB_EURO " , " en_GB@currency=EUR " } ,
{ " en_GB@EURO " , " en_GB@EURO " , " en_GB@currency=EUR " } , /* POSIX ID */
{ " es__TRADITIONAL " , " es__TRADITIONAL " , " es@collation=traditional " } ,
{ " hi__DIRECT " , " hi__DIRECT " , " hi@collation=direct " } ,
{ " ja_JP_TRADITIONAL " , " ja_JP_TRADITIONAL " , " ja_JP@calendar=japanese " } ,
{ " th_TH_TRADITIONAL " , " th_TH_TRADITIONAL " , " th_TH@calendar=buddhist " } ,
2005-03-22 01:38:18 +00:00
{ " zh_TW_STROKE " , " zh_TW_STROKE " , " zh_Hant_TW@collation=stroke " } ,
2004-05-18 20:07:33 +00:00
{ " zh__PINYIN " , " zh__PINYIN " , " zh@collation=pinyin " } ,
{ " zh@collation=pinyin " , " zh@collation=pinyin " , " zh@collation=pinyin " } ,
{ " zh_CN@collation=pinyin " , " zh_CN@collation=pinyin " , " zh_CN@collation=pinyin " } ,
{ " zh_CN_CA@collation=pinyin " , " zh_CN_CA@collation=pinyin " , " zh_CN_CA@collation=pinyin " } ,
{ " en_US_POSIX " , " en_US_POSIX " , " en_US_POSIX " } ,
{ " hy_AM_REVISED " , " hy_AM_REVISED " , " hy_AM_REVISED " } ,
{ " no_NO_NY " , " no_NO_NY " , " no_NO_NY " /* not: "nn_NO" [alan ICU3.0] */ } ,
{ " no@ny " , " no@ny " , " no__NY " /* not: "nn" [alan ICU3.0] */ } , /* POSIX ID */
{ " no-no.utf32@B " , " no_NO.utf32@B " , " no_NO_B " /* not: "nb_NO_B" [alan ICU3.0] */ } , /* POSIX ID */
{ " qz-qz@Euro " , " qz_QZ@Euro " , " qz_QZ@currency=EUR " } , /* qz-qz uses private use iso codes */
// NOTE: uloc_getName() works on en-BOONT, but Locale() parser considers it BOGUS
// TODO: unify this behavior
{ " en-BOONT " , " BOGUS " , " en__BOONT " } , /* registered name */
{ " de-1901 " , " de_1901 " , " de__1901 " } , /* registered name */
{ " de-1906 " , " de_1906 " , " de__1906 " } , /* registered name */
2005-09-23 21:00:41 +00:00
{ " sr-SP-Cyrl " , " sr_SP_CYRL " , " sr_Cyrl_CS " } , /* .NET name */
{ " sr-SP-Latn " , " sr_SP_LATN " , " sr_Latn_CS " } , /* .NET name */
{ " sr_YU_CYRILLIC " , " sr_YU_CYRILLIC " , " sr_Cyrl_CS " } , /* Linux name */
2004-05-18 20:07:33 +00:00
{ " uz-UZ-Cyrl " , " uz_UZ_CYRL " , " uz_Cyrl_UZ " } , /* .NET name */
{ " uz-UZ-Latn " , " uz_UZ_LATN " , " uz_Latn_UZ " } , /* .NET name */
{ " zh-CHS " , " zh_CHS " , " zh_Hans " } , /* .NET name */
2005-03-22 01:38:18 +00:00
{ " zh-CHT " , " zh_CHT " , " zh_Hant " } , /* .NET name This may change back to zh_Hant */
2004-05-18 20:07:33 +00:00
/* posix behavior that used to be performed by getName */
{ " mr.utf8 " , " mr.utf8 " , " mr " } ,
{ " de-tv.koi8r " , " de_TV.koi8r " , " de_TV " } ,
{ " x-piglatin_ML.MBE " , " x-piglatin_ML.MBE " , " x-piglatin_ML " } ,
{ " i-cherokee_US.utf7 " , " i-cherokee_US.utf7 " , " i-cherokee_US " } ,
{ " x-filfli_MT_FILFLA.gb-18030 " , " x-filfli_MT_FILFLA.gb-18030 " , " x-filfli_MT_FILFLA " } ,
{ " no-no-ny.utf8@B " , " no_NO_NY.utf8@B " , " no_NO_NY_B " /* not: "nn_NO" [alan ICU3.0] */ } , /* @ ignored unless variant is empty */
/* fleshing out canonicalization */
/* trim space and sort keywords, ';' is separator so not present at end in canonical form */
{ " en_Hant_IL_VALLEY_GIRL@ currency = EUR; calendar = Japanese ; " , " en_Hant_IL_VALLEY_GIRL@calendar=Japanese;currency=EUR " , " en_Hant_IL_VALLEY_GIRL@calendar=Japanese;currency=EUR " } ,
/* already-canonical ids are not changed */
{ " en_Hant_IL_VALLEY_GIRL@calendar=Japanese;currency=EUR " , " en_Hant_IL_VALLEY_GIRL@calendar=Japanese;currency=EUR " , " en_Hant_IL_VALLEY_GIRL@calendar=Japanese;currency=EUR " } ,
/* PRE_EURO and EURO conversions don't affect other keywords */
{ " es_ES_PREEURO@CALendar=Japanese " , " es_ES_PREEURO@calendar=Japanese " , " es_ES@calendar=Japanese;currency=ESP " } ,
{ " es_ES_EURO@SHOUT=zipeedeedoodah " , " es_ES_EURO@shout=zipeedeedoodah " , " es_ES@currency=EUR;shout=zipeedeedoodah " } ,
/* currency keyword overrides PRE_EURO and EURO currency */
{ " es_ES_PREEURO@currency=EUR " , " es_ES_PREEURO@currency=EUR " , " es_ES@currency=EUR " } ,
{ " es_ES_EURO@currency=ESP " , " es_ES_EURO@currency=ESP " , " es_ES@currency=ESP " } ,
/* norwegian is just too weird, if we handle things in their full generality */
{ " no-Hant-GB_NY@currency=$$$ " , " no_Hant_GB_NY@currency=$$$ " , " no_Hant_GB_NY@currency=$$$ " /* not: "nn_Hant_GB@currency=$$$" [alan ICU3.0] */ } ,
/* test cases reflecting internal resource bundle usage */
{ " root@kw=foo " , " root@kw=foo " , " root@kw=foo " } ,
2004-05-19 23:09:12 +00:00
{ " @calendar=gregorian " , " @calendar=gregorian " , " @calendar=gregorian " } ,
{ " ja_JP@calendar=Japanese " , " ja_JP@calendar=Japanese " , " ja_JP@calendar=Japanese " }
2004-05-18 20:07:33 +00:00
} ;
2004-05-19 23:09:12 +00:00
static const char * label [ ] = { " createFromName " , " createCanonical " , " Locale " } ;
2004-05-18 20:07:33 +00:00
int32_t i , j ;
2004-05-30 09:58:45 +00:00
for ( i = 0 ; i < ( int ) ( sizeof ( testCases ) / sizeof ( testCases [ 0 ] ) ) ; i + + ) {
2004-05-18 20:07:33 +00:00
for ( j = 0 ; j < 3 ; + + j ) {
const char * expected = ( j = = 1 ) ? testCases [ i ] . canonicalID : testCases [ i ] . getNameID ;
Locale loc = _canonicalize ( j , testCases [ i ] . localeID ) ;
const char * getName = loc . isBogus ( ) ? " BOGUS " : loc . getName ( ) ;
if ( uprv_strcmp ( expected , getName ) ! = 0 ) {
errln ( " FAIL: %s(%s).getName() => \" %s \" , expected \" %s \" " ,
label [ j ] , testCases [ i ] . localeID , getName , expected ) ;
} else {
logln ( " Ok: %s(%s) => \" %s \" " ,
label [ j ] , testCases [ i ] . localeID , getName ) ;
}
}
}
}