2000-01-15 02:00:06 +00:00
/********************************************************************
* COPYRIGHT :
2001-03-21 20:09:56 +00:00
* Copyright ( c ) 1997 - 2001 , 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"
# include <stdio.h>
# include <string.h>
2000-04-15 21:28:17 +00:00
# include <cstring.h>
1999-08-16 21:50:52 +00:00
1999-12-28 23:57:50 +00:00
# include "unicode/decimfmt.h"
//#include "unicode/datefmt.h"
# include "unicode/smpdtfmt.h"
1999-08-16 21:50:52 +00:00
2000-08-14 21:42:36 +00:00
const char * rawData [ 27 ] [ 7 ] = {
2000-04-15 21:28:17 +00:00
// language code
{ " en " , " fr " , " hr " , " el " , " no " , " it " , " xx " } ,
// country code
{ " US " , " FR " , " HR " , " GR " , " NO " , " " , " YY " } ,
// variant code
{ " " , " " , " " , " " , " NY " , " " , " " } ,
// full name
{ " en_US " , " fr_FR " , " hr_HR " , " el_GR " , " no_NO_NY " , " it " , " xx_YY " } ,
// ISO-3 language
{ " eng " , " fra " , " hrv " , " ell " , " nor " , " ita " , " " } ,
// ISO-3 country
{ " USA " , " FRA " , " HRV " , " GRC " , " NOR " , " " , " " } ,
// LCID (not currently public)
{ " 409 " , " 40c " , " 41a " , " 408 " , " 814 " , " " , " " } ,
// display langage (English)
{ " English " , " French " , " Croatian " , " Greek " , " Norwegian " , " Italian " , " xx " } ,
// display country (English)
{ " United States " , " France " , " Croatia " , " Greece " , " Norway " , " " , " YY " } ,
// display variant (English)
{ " " , " " , " " , " " , " Nynorsk " , " " , " " } ,
//{ "", "", "", "", "NY", "", ""},
// display name (English)
// Updated no_NO_NY English display name for new pattern-based algorithm
// (part of Euro support).
{ " English (United States) " , " French (France) " , " Croatian (Croatia) " , " Greek (Greece) " , " Norwegian (Norway, Nynorsk) " , " Italian " , " xx (YY) " } ,
//{ "English (United States)", "French (France)", "Croatian (Croatia)", "Greek (Greece)", "Norwegian (Norway,NY)", "Italian", "xx (YY)" },
// display langage (French)
2000-10-30 21:05:32 +00:00
{ " anglais " , " fran \\ u00E7ais " , " croate " , " grec " , " norv \\ u00E9gien " , " italien " , " xx " } ,
2000-04-15 21:28:17 +00:00
// display country (French)
2000-10-30 21:05:32 +00:00
{ " \\ u00C9tats-Unis " , " France " , " Croatie " , " Gr \\ u00E8ce " , " Norv \\ u00E8ge " , " " , " YY " } ,
2000-04-15 21:28:17 +00:00
// display variant (French)
{ " " , " " , " " , " " , " Nynorsk " , " " , " " } ,
// display name (French)
2000-10-30 21:05:32 +00:00
//{ "anglais (<28> tats-Unis)", "fran<61> ais (France)", "croate (Croatie)", "grec (Gr<47> ce)", "norv<72> gien (Norv<72> ge,Nynorsk)", "italien", "xx (YY)" },
{ " anglais ( \\ u00C9tats-Unis) " , " fran \\ u00E7ais (France) " , " croate (Croatie) " , " grec (Gr \\ u00E8ce) " , " norv \\ u00E9gien (Norv \\ u00E8ge, Nynorsk) " , " italien " , " xx (YY) " } , // STILL not right
2000-04-15 21:28:17 +00:00
// display langage (Croatian)
{ " " , " " , " hrvatski " , " " , " " , " " , " xx " } ,
// display country (Croatian)
{ " " , " " , " Hrvatska " , " " , " " , " " , " YY " } ,
// display variant (Croatian)
{ " " , " " , " " , " " , " " , " " , " " } ,
// display name (Croatian)
{ " " , " " , " hrvatski (Hrvatska) " , " " , " " , " " , " xx (YY) " } ,
// display langage (Greek)[actual values listed below]
{ " " , " " , " " , " " , " " , " " , " " } ,
// display country (Greek)[actual values listed below]
{ " " , " " , " " , " " , " " , " " , " " } ,
// display variant (Greek)
{ " " , " " , " " , " " , " " , " " , " " } ,
// display name (Greek)[actual values listed below]
{ " " , " " , " " , " " , " " , " " , " " } ,
// display langage (<root>)
{ " English " , " French " , " Croatian " , " Greek " , " Norwegian " , " Italian " , " xx " } ,
// display country (<root>)
{ " United States " , " France " , " Croatia " , " Greece " , " Norway " , " " , " YY " } ,
// display variant (<root>)
{ " " , " " , " " , " " , " Nynorsk " , " " , " " } ,
// display name (<root>)
//{ "English (United States)", "French (France)", "Croatian (Croatia)", "Greek (Greece)", "Norwegian (Norway,Nynorsk)", "Italian", "xx (YY)" },
{ " English (United States) " , " French (France) " , " Croatian (Croatia) " , " Greek (Greece) " , " Norwegian (Norway,NY) " , " Italian " , " xx (YY) " }
} ;
1999-08-16 21:50:52 +00:00
// * test macros
/*
Usage :
test_compare ( Function to be performed ,
Test of the function ,
expected result of the test ,
printable result
)
Example :
test_compare ( i = 3 , i , 3 , someNumberFormatter ( i ) ) ;
test_compare ( 0 , 1 + 1 , 2 , someNumberFormatter ( 1 + 1 ) ) ;
Note that in the second example the expression is 0 , because the fcn produces it ' s own result .
Macro is ugly but makes the tests pretty .
*/
# define test_compare(expression,test,expected,printableResult) \
{ \
expression ; \
\
if ( ( test ) ! = ( expected ) ) \
errln ( " FAIL: " + UnicodeString ( # expression ) + " ; -> " + printableResult + " \n " + \
" ( " + UnicodeString ( # test ) + " != " + UnicodeString ( # expected ) + " ) " ) ; \
else \
logln ( UnicodeString ( # expression ) + " -> " + printableResult + " ( " + UnicodeString ( # test ) + " ) " ) ; \
}
/*
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 ) ) \
errln ( " FAIL: " + UnicodeString ( # test ) + " was not true. " + " -> " + UnicodeString ( print ) ) ; \
else \
logln ( " PASS: asserted " + UnicodeString ( # test ) + " -> " + UnicodeString ( print ) ) ; \
}
2000-04-15 21:28:17 +00:00
# define test_dumpLocale(l) { UnicodeString s(l.getName(),""); logln(#l + UnicodeString(" = ") + s); }
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 ) {
for ( int32_t i = 0 ; i < 27 ; i + + ) {
delete [ ] dataTable [ i ] ;
}
delete [ ] dataTable ;
dataTable = 0 ;
}
1999-08-16 21:50:52 +00:00
}
# define CASE(id,test) case id: name = #test; if (exec) { logln(#test "---"); logln((UnicodeString)""); test(); } break;
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
{
if ( exec ) logln ( " TestSuite LocaleTest: " ) ;
switch ( index ) {
case 0 : name = " TestBasicGetters " ; if ( exec ) TestBasicGetters ( ) ; break ;
case 1 : name = " TestSimpleResourceInfo " ; if ( exec ) TestSimpleResourceInfo ( ) ; break ;
case 2 : name = " TestDisplayNames " ; if ( exec ) TestDisplayNames ( ) ; break ;
case 3 : name = " TestSimpleObjectStuff " ; if ( exec ) TestSimpleObjectStuff ( ) ; break ;
case 4 : name = " TestPOSIXParsing " ; if ( exec ) TestPOSIXParsing ( ) ; break ;
case 5 : name = " TestGetAvailableLocales " ; if ( exec ) TestGetAvailableLocales ( ) ; break ;
case 6 : name = " TestDataDirectory " ; if ( exec ) TestDataDirectory ( ) ; break ;
CASE ( 7 , TestISO3Fallback )
CASE ( 8 , TestGetLangsAndCountries )
CASE ( 9 , Test4126880 )
CASE ( 10 , TestBug4135316 )
CASE ( 11 , TestSimpleDisplayNames )
CASE ( 12 , TestUninstalledISO3Names )
1999-12-28 21:31:55 +00:00
CASE ( 13 , TestAtypicalLocales )
CASE ( 14 , TestThaiCurrencyFormat )
CASE ( 15 , TestEuroSupport )
CASE ( 16 , TestToString )
CASE ( 17 , Test4139940 )
CASE ( 18 , Test4143951 )
CASE ( 19 , Test4147315 )
CASE ( 20 , Test4147317 )
CASE ( 21 , Test4147552 )
CASE ( 22 , TestVariantParsing )
CASE ( 23 , Test4105828 )
1999-08-16 21:50:52 +00:00
default : name = " " ; break ; //needed to end loop
}
}
void LocaleTest : : TestBasicGetters ( ) {
UnicodeString temp ;
int32_t i ;
for ( i = 0 ; i < = MAX_LOCALES ; i + + ) {
2000-04-15 21:28:17 +00:00
Locale testLocale ( rawData [ LANG ] [ i ] , rawData [ CTRY ] [ i ] , rawData [ VAR ] [ i ] ) ;
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 ] ) ;
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 + + ) {
2000-04-15 21:28:17 +00:00
Locale testLocale ( rawData [ LANG ] [ i ] , rawData [ CTRY ] [ i ] ) ;
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 ] ) )
1999-08-16 21:50:52 +00:00
errln ( " Language code mismatch: " + temp + " versus "
+ dataTable [ LANG ] [ 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 ( testLocale . getVariant ( ) [ 0 ] ! = 0 )
errln ( " Variant code mismatch: something versus \" \" " ) ;
1999-08-16 21:50:52 +00:00
}
2000-08-02 21:00:23 +00:00
/*tests for the depracted API*/
2001-03-06 02:04:14 +00:00
# ifdef ICU_LOCID_USE_DEPRECATES
2000-08-02 21:00:23 +00:00
for ( i = 0 ; i < = MAX_LOCALES ; i + + ) {
Locale testLocale ( ( UnicodeString ) rawData [ LANG ] [ i ] , ( UnicodeString ) rawData [ CTRY ] [ i ] , ( UnicodeString ) rawData [ VAR ] [ i ] ) ;
logln ( " Testing " + ( UnicodeString ) testLocale . getName ( ) + " ... " ) ;
1999-08-16 21:50:52 +00:00
2000-08-02 21:00:23 +00:00
if ( testLocale . getLanguage ( temp ) ! = ( UnicodeString ) ( dataTable [ LANG ] [ i ] ) )
errln ( " Language code mismatch: " + temp + " versus "
+ dataTable [ LANG ] [ i ] ) ;
if ( testLocale . getCountry ( temp ) ! = ( UnicodeString ) ( dataTable [ CTRY ] [ i ] ) )
errln ( " Country code mismatch: " + temp + " versus "
+ dataTable [ CTRY ] [ i ] ) ;
if ( testLocale . getVariant ( temp ) ! = ( UnicodeString ) ( dataTable [ VAR ] [ i ] ) )
errln ( " Variant code mismatch: " + temp + " versus "
+ dataTable [ VAR ] [ i ] ) ;
if ( testLocale . getName ( temp ) ! = ( UnicodeString ) ( dataTable [ NAME ] [ i ] ) )
errln ( " Locale name mismatch: " + temp + " versus "
+ dataTable [ NAME ] [ i ] ) ;
}
logln ( " Same thing without variant codes... " ) ;
for ( i = 0 ; i < = MAX_LOCALES ; i + + ) {
Locale testLocale ( ( UnicodeString ) rawData [ LANG ] [ i ] , ( UnicodeString ) rawData [ CTRY ] [ i ] ) ;
logln ( " Testing " + ( testLocale . getName ( temp ) ) + " ... " ) ;
1999-08-16 21:50:52 +00:00
2000-08-02 21:00:23 +00:00
if ( testLocale . getLanguage ( temp ) ! = ( UnicodeString ) ( dataTable [ LANG ] [ i ] ) )
errln ( " Language code mismatch: " + temp + " versus "
+ dataTable [ LANG ] [ i ] ) ;
if ( testLocale . getCountry ( temp ) ! = ( UnicodeString ) ( dataTable [ CTRY ] [ i ] ) )
errln ( " Country code mismatch: " + temp + " versus "
+ dataTable [ CTRY ] [ i ] ) ;
if ( testLocale . getVariant ( temp ) . length ( ) ! = 0 )
errln ( " Variant code mismatch: something versus \" \" " ) ;
}
2001-03-15 07:09:09 +00:00
2001-03-06 02:04:14 +00:00
# endif
2001-03-15 07:09:09 +00:00
logln ( " Testing long language names and getters " ) ;
Locale test8 = Locale : : createFromName ( " x-klingon-zx.utf32be@special " ) ;
temp = test8 . getLanguage ( ) ;
if ( temp ! = UnicodeString ( " x-klingon " ) )
errln ( " Language code mismatch: " + temp + " versus \" x-klingon \" " ) ;
temp = test8 . getCountry ( ) ;
if ( temp ! = UnicodeString ( " ZX " ) )
errln ( " Country code mismatch: " + temp + " versus \" ZX \" " ) ;
temp = test8 . getVariant ( ) ;
if ( temp ! = UnicodeString ( " SPECIAL " ) )
errln ( " Variant code mismatch: " + temp + " versus \" SPECIAL \" " ) ;
2001-08-18 00:15:44 +00:00
if ( Locale : : getDefault ( ) ! = Locale : : createFromName ( NULL ) )
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.
}
void LocaleTest : : TestSimpleResourceInfo ( ) {
UnicodeString temp ;
char temp2 [ 20 ] ;
2000-04-15 21:28:17 +00:00
UErrorCode err = U_ZERO_ERROR ;
2000-08-03 19:17:22 +00:00
int32_t i = 0 ;
for ( i = 0 ; i < = MAX_LOCALES ; i + + ) {
2000-04-15 21:28:17 +00:00
Locale testLocale ( rawData [ LANG ] [ i ] , rawData [ CTRY ] [ i ] , rawData [ VAR ] [ i ] ) ;
logln ( " Testing " + ( temp = testLocale . getName ( ) ) + " ... " ) ;
1999-08-16 21:50:52 +00:00
2000-04-15 21:28:17 +00:00
if ( ( temp = testLocale . getISO3Language ( ) ) ! = ( dataTable [ LANG3 ] [ i ] ) )
1999-08-16 21:50:52 +00:00
errln ( " ISO-3 language code mismatch: " + temp
+ " versus " + dataTable [ LANG3 ] [ i ] ) ;
2000-04-15 21:28:17 +00:00
if ( ( temp = testLocale . getISO3Country ( ) ) ! = ( dataTable [ CTRY3 ] [ i ] ) )
1999-08-16 21:50:52 +00:00
errln ( " ISO-3 country code mismatch: " + temp
+ " versus " + dataTable [ CTRY3 ] [ i ] ) ;
sprintf ( temp2 , " %x " , testLocale . getLCID ( ) ) ;
if ( UnicodeString ( temp2 ) ! = dataTable [ LCID ] [ i ] )
2000-12-19 21:48:58 +00:00
errln ( ( UnicodeString ) " LCID mismatch: " + temp2 + " versus "
1999-08-16 21:50:52 +00:00
+ dataTable [ LCID ] [ i ] ) ;
2000-04-15 21:28:17 +00:00
if ( U_FAILURE ( err ) )
{
errln ( ( UnicodeString ) " Some error on number " + i + u_errorName ( err ) ) ;
}
err = U_ZERO_ERROR ;
1999-08-16 21:50:52 +00:00
}
2000-08-02 21:00:23 +00:00
/*tests for the deprecated API*/
2001-03-06 02:04:14 +00:00
# ifdef ICU_LOCID_USE_DEPRECATES
2000-08-02 21:00:23 +00:00
for ( i = 0 ; i < = MAX_LOCALES ; i + + ) {
Locale testLocale ( ( UnicodeString ) rawData [ LANG ] [ i ] , ( UnicodeString ) rawData [ CTRY ] [ i ] , ( UnicodeString ) rawData [ VAR ] [ i ] ) ;
logln ( " Testing " + ( testLocale . getName ( temp ) ) + " ... " ) ;
if ( testLocale . getISO3Language ( temp , err ) ! = ( UnicodeString ) ( dataTable [ LANG3 ] [ i ] ) )
errln ( " ISO-3 language code mismatch: " + temp
+ " versus " + dataTable [ LANG3 ] [ i ] ) ;
if ( testLocale . getISO3Country ( temp , err ) ! = ( UnicodeString ) ( dataTable [ CTRY3 ] [ i ] ) )
errln ( " ISO-3 country code mismatch: " + temp
+ " versus " + dataTable [ CTRY3 ] [ i ] ) ;
if ( U_FAILURE ( err ) )
{
errln ( ( UnicodeString ) " Some error on number " + i + u_errorName ( err ) ) ;
}
err = U_ZERO_ERROR ;
}
2001-03-06 02:04:14 +00:00
# endif
2000-08-02 21:00:23 +00:00
2001-03-06 02:04:14 +00:00
Locale locale ( " en " ) ;
if ( strcmp ( locale . getName ( ) , " en " ) ! = 0 | |
strcmp ( locale . getLanguage ( ) , " en " ) ! = 0 ) {
2000-08-02 21:00:23 +00:00
errln ( " construction of Locale(en) failed \n " ) ;
}
/*-----*/
1999-08-16 21:50:52 +00:00
}
void
LocaleTest : : TestDisplayNames ( )
{
Locale saveDefault = Locale : : getDefault ( ) ;
Locale empty ( " " , " " ) ;
Locale english ( " en " , " US " ) ;
Locale french ( " fr " , " FR " ) ;
Locale croatian ( " hr " , " HR " ) ;
Locale greek ( " el " , " GR " ) ;
1999-10-07 00:07:53 +00:00
UErrorCode err = U_ZERO_ERROR ;
1999-08-16 21:50:52 +00:00
Locale : : setDefault ( english , err ) ;
1999-10-18 22:48:32 +00:00
if ( U_FAILURE ( err ) ) {
1999-08-16 21:50:52 +00:00
errln ( " Locale::setDefault returned error code " + ( int ) err ) ;
return ;
}
logln ( " With default = en_US... " ) ;
logln ( " In default locale... " ) ;
doTestDisplayNames ( empty , DLANG_EN , FALSE ) ;
logln ( " In locale = en_US... " ) ;
doTestDisplayNames ( english , DLANG_EN , FALSE ) ;
logln ( " In locale = fr_FR... " ) ;
doTestDisplayNames ( french , DLANG_FR , FALSE ) ;
logln ( " In locale = hr_HR... " ) ;
doTestDisplayNames ( croatian , DLANG_HR , FALSE ) ;
logln ( " In locale = el_GR... " ) ;
doTestDisplayNames ( greek , DLANG_EL , FALSE ) ;
Locale : : setDefault ( french , err ) ;
1999-10-18 22:48:32 +00:00
if ( U_FAILURE ( err ) ) {
1999-08-16 21:50:52 +00:00
errln ( " Locale::setDefault returned error code " + ( int ) err ) ;
return ;
}
logln ( " With default = fr_FR... " ) ;
logln ( " In default locale... " ) ;
doTestDisplayNames ( empty , DLANG_FR , TRUE ) ;
logln ( " In locale = en_US... " ) ;
doTestDisplayNames ( english , DLANG_EN , TRUE ) ;
logln ( " In locale = fr_FR... " ) ;
doTestDisplayNames ( french , DLANG_FR , TRUE ) ;
logln ( " In locale = hr_HR... " ) ;
doTestDisplayNames ( croatian , DLANG_HR , TRUE ) ;
logln ( " In locale = el_GR... " ) ;
doTestDisplayNames ( greek , DLANG_EL , TRUE ) ;
Locale : : setDefault ( saveDefault , err ) ;
1999-10-18 22:48:32 +00:00
if ( U_FAILURE ( err ) ) {
1999-08-16 21:50:52 +00:00
errln ( " Locale::setDefault returned error code " + ( int ) err ) ;
return ;
}
}
/*
Usage :
test_assert ( Test ( should be TRUE ) )
Example :
test_assert ( i = = 3 ) ;
the macro is ugly but makes the tests pretty .
*/
# define test_assert(test) \
{ \
if ( ! ( test ) ) \
2000-04-15 21:28:17 +00:00
errln ( " FAIL: " + UnicodeString ( # test ) + " was not true. " + UnicodeString ( __FILE__ " line " ) + __LINE__ ) ; \
1999-08-16 21:50:52 +00:00
else \
logln ( " PASS: asserted " + UnicodeString ( # test ) ) ; \
}
void LocaleTest : : TestSimpleObjectStuff ( ) {
Locale test1 ( " aa " , " AA " ) ;
Locale test2 ( " aa " , " AA " ) ;
Locale test3 ( test1 ) ;
Locale test4 ( " zz " , " ZZ " ) ;
Locale test5 ( " aa " , " AA " , " " ) ;
2001-02-17 13:34:42 +00:00
Locale test6 ( " aa " , " AA " , " ANTARES " ) ;
Locale test7 ( " aa " , " AA " , " JUPITER " ) ;
Locale test8 = Locale : : createFromName ( " aa-aa.utf8@jupiter " ) ;
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 ) ;
// 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 " ) ) ;
Locale test6 ( " ab " , " AB " , " Antares " ) ;
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 + " \" " ) ;
Locale : : setDataDirectory ( oldDirectory ) ;
test . getISO3Language ( testValue ) ;
logln ( " third fetch of language retrieved " + testValue ) ;
if ( testValue ! = " eng " )
errln ( " get/setDataDirectory() failed: expected \" eng \" , got \" " + testValue + " \" " ) ;
*/
}
//===========================================================
void LocaleTest : : doTestDisplayNames ( Locale & inLocale ,
int32_t compareIndex ,
2000-05-18 22:08:39 +00:00
UBool defaultIsFrench ) {
1999-08-16 21:50:52 +00:00
UnicodeString temp ;
2000-04-15 21:28:17 +00:00
if ( defaultIsFrench & & ( temp = Locale : : getDefault ( ) . getLanguage ( ) ) ! = " fr " )
1999-08-16 21:50:52 +00:00
errln ( " Default locale should be French, but it's really " + temp ) ;
2000-04-15 21:28:17 +00:00
else if ( ! defaultIsFrench & & ( temp = Locale : : getDefault ( ) . getLanguage ( ) ) ! = " en " )
1999-08-16 21:50:52 +00:00
errln ( " Default locale should be English, but it's really " + temp ) ;
for ( int32_t i = 0 ; i < = MAX_LOCALES ; i + + ) {
2000-04-15 21:28:17 +00:00
Locale testLocale ( rawData [ LANG ] [ i ] , rawData [ CTRY ] [ i ] , rawData [ VAR ] [ i ] ) ;
logln ( " Testing " + ( temp = testLocale . getName ( ) ) + " ... " ) ;
1999-08-16 21:50:52 +00:00
UnicodeString testLang ;
UnicodeString testCtry ;
UnicodeString testVar ;
UnicodeString testName ;
if ( inLocale = = Locale ( " " , " " , " " ) ) {
testLocale . getDisplayLanguage ( testLang ) ;
testLocale . getDisplayCountry ( testCtry ) ;
testLocale . getDisplayVariant ( testVar ) ;
testLocale . getDisplayName ( testName ) ;
}
else {
testLocale . getDisplayLanguage ( inLocale , testLang ) ;
testLocale . getDisplayCountry ( inLocale , testCtry ) ;
testLocale . getDisplayVariant ( inLocale , testVar ) ;
testLocale . getDisplayName ( inLocale , testName ) ;
}
UnicodeString expectedLang ;
UnicodeString expectedCtry ;
UnicodeString expectedVar ;
UnicodeString expectedName ;
expectedLang = dataTable [ compareIndex ] [ i ] ;
1999-12-08 02:11:04 +00:00
if ( expectedLang . length ( ) = = 0 & & defaultIsFrench )
1999-08-16 21:50:52 +00:00
expectedLang = dataTable [ DLANG_FR ] [ 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 ] ;
expectedCtry = dataTable [ compareIndex + 1 ] [ i ] ;
2000-10-30 21:05:32 +00:00
if ( ( expectedCtry . length ( ) = = 0 ) & & defaultIsFrench )
1999-08-16 21:50:52 +00:00
expectedCtry = dataTable [ DCTRY_FR ] [ 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 ] ;
expectedVar = dataTable [ compareIndex + 2 ] [ i ] ;
1999-12-08 02:11:04 +00:00
if ( expectedVar . length ( ) = = 0 & & defaultIsFrench )
1999-08-16 21:50:52 +00:00
expectedVar = dataTable [ DVAR_FR ] [ 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 ] ;
expectedName = dataTable [ compareIndex + 3 ] [ i ] ;
1999-12-08 02:11:04 +00:00
if ( expectedName . length ( ) = = 0 & & defaultIsFrench )
1999-08-16 21:50:52 +00:00
expectedName = dataTable [ DNAME_FR ] [ 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 )
2000-10-30 21:05:32 +00:00
errln ( " Display language ( " + UnicodeString ( inLocale . getName ( ) ) + " ) mismatch: " + testLang + " versus " + expectedLang ) ;
1999-08-16 21:50:52 +00:00
if ( testCtry ! = expectedCtry )
2000-10-30 21:05:32 +00:00
errln ( " Display country ( " + UnicodeString ( inLocale . getName ( ) ) + " ) mismatch: " + testCtry + " versus " + expectedCtry + ( defaultIsFrench ? UnicodeString ( " French " ) : UnicodeString ( " _ " ) ) ) ;
1999-08-16 21:50:52 +00:00
if ( testVar ! = expectedVar )
2000-10-30 21:05:32 +00:00
errln ( " Display variant ( " + UnicodeString ( inLocale . getName ( ) ) + " ) mismatch: " + testVar + " versus " + expectedVar ) ;
1999-08-16 21:50:52 +00:00
if ( testName ! = expectedName )
2000-10-30 21:05:32 +00:00
errln ( " Display name ( " + UnicodeString ( inLocale . getName ( ) ) + " ) mismatch: " + testName + " versus " + expectedName ) ;
1999-08-16 21:50:52 +00:00
}
}
//---------------------------------------------------
// table of valid data
//---------------------------------------------------
UChar greekDisplayLanguage [ ] = { 0x03b5 , 0x03bb , 0x03bb , 0x03b7 , 0x03bd , 0x03b9 , 0x03ba , 0x03ac , 0 } ;
UChar greekDisplayCountry [ ] = { 0x0395 , 0x03bb , 0x03bb , 0x03ac , 0x03b4 , 0x03b1 , 0 } ;
UChar greekDisplayName [ ] = { 0x03b5 , 0x03bb , 0x03bb , 0x03b7 , 0x03bd , 0x03b9 , 0x03ba ,
2000-03-22 23:17:42 +00:00
0x03ac , 0x20 , 0x28 , 0x0395 , 0x03bb , 0x03bb , 0x03ac , 0x03b4 , 0x03b1 , 0x29 , 0 } ;
1999-08-16 21:50:52 +00:00
void LocaleTest : : setUpDataTable ( )
{
if ( dataTable = = 0 ) {
dataTable = new UnicodeString * [ 27 ] ;
for ( int32_t i = 0 ; i < 27 ; i + + ) {
dataTable [ i ] = new UnicodeString [ 7 ] ;
2000-03-22 23:17:42 +00:00
for ( int32_t j = 0 ; j < 7 ; j + + ) {
dataTable [ i ] [ j ] = CharsToUnicodeString ( rawData [ i ] [ j ] ) ;
}
1999-08-16 21:50:52 +00:00
}
dataTable [ DLANG_EL ] [ GREEK ] = greekDisplayLanguage ;
dataTable [ DCTRY_EL ] [ GREEK ] = greekDisplayCountry ;
dataTable [ DNAME_EL ] [ GREEK ] = greekDisplayName ;
}
}
// ====================
/**
* @ bug 4011756 4011380
*/
void
LocaleTest : : TestISO3Fallback ( )
{
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 ( ) ;
// Conform to C API usage
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
*/
void
LocaleTest : : TestGetLangsAndCountries ( )
{
// 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 ( ) ;
const char spotCheck1 [ ] [ 4 ] = { " en " , " es " , " fr " , " de " , " it " ,
1999-08-16 21:50:52 +00:00
" ja " , " ko " , " zh " , " th " , " he " ,
" id " , " iu " , " ug " , " yi " , " za " } ;
int32_t i ;
2000-04-15 21:28:17 +00:00
for ( testCount = 0 ; test [ testCount ] ; testCount + + )
;
1999-08-16 21:50:52 +00:00
2001-10-14 00:24:34 +00:00
if ( testCount ! = 437 )
errln ( " Expected getISOLanguages() to return 437 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 ( ) ;
1999-08-16 21:50:52 +00:00
UnicodeString spotCheck2 [ ] = { " US " , " CA " , " GB " , " FR " , " DE " ,
" IT " , " JP " , " KR " , " CN " , " TW " ,
" 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
if ( testCount ! = 239 )
errln ( " Expected getISOLanguages to return 238 languages; it returned " + testCount ) ;
else {
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. " ) ;
}
}
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 4126880
*/
// since this returns const UnicodeString* in C++, is this test applicable?
void
LocaleTest : : Test4126880 ( )
{
2001-03-06 02:04:14 +00:00
# ifdef ICU_LOCID_USE_DEPRECATES
2000-08-02 21:00:23 +00:00
1999-08-16 21:50:52 +00:00
const UnicodeString * test ;
2000-08-02 21:00:23 +00:00
int32_t testCount = 0 ;
1999-08-16 21:50:52 +00:00
2000-08-02 21:00:23 +00:00
/*test = Locale::getISOCountries(testCount);
1999-08-16 21:50:52 +00:00
test [ 0 ] = " SUCKER!!! " ;
test = Locale : : getISOCountries ( testCount ) ;
if ( test [ 0 ] = = " SUCKER!!! " )
errln ( " Changed internal country code list! " ) ;
test = Locale : : getISOLanguages ( testCount ) ;
test [ 0 ] = " HAHAHAHA!!! " ;
test = Locale : : getISOLanguages ( testCount ) ;
if ( test [ 0 ] = = " HAHAHAHA!!! " ) // Fixed typo
errln ( " Changes internal language code list! " ) ;
2000-08-02 21:00:23 +00:00
*/
/*tests for deprecated API*/
test = Locale : : getISOCountries ( testCount ) ;
if ( testCount ! = 239 ) {
errln ( ( UnicodeString ) " There is an error in getISOCountries " + testCount ) ;
}
test = Locale : : getISOLanguages ( testCount ) ;
2001-10-14 00:24:34 +00:00
if ( testCount ! = 437 ) {
2000-08-02 21:00:23 +00:00
errln ( ( UnicodeString ) " There is an error in getISOLanguages " + testCount ) ;
}
2001-03-06 02:04:14 +00:00
/*----------*/
# else
logln ( " Skipping Test4126880 for deprecated API " ) ;
# endif
1999-08-16 21:50:52 +00:00
}
/**
* @ bug 4135316
*/
// not applicable in C++ - const Locale*
void
LocaleTest : : TestBug4135316 ( )
{
/*
Locale [ ] locales1 = Locale . getAvailableLocales ( ) ;
Locale [ ] locales2 = Locale . getAvailableLocales ( ) ;
if ( locales1 = = locales2 )
errln ( " Locale.getAvailableLocales() doesn't clone its internal storage! " ) ;
*/
}
/**
* @ bug 4107953
*/
/*
test commented out pending API - change approval
public void TestGetLanguagesForCountry ( ) {
UnicodeString [ ] languages = Locale . getLanguagesForCountry ( " US " ) ;
if ( ! searchStringArrayFor ( " en " , languages ) )
errln ( " Didn't get en as a language for US " ) ;
languages = Locale . getLanguagesForCountry ( " FR " ) ;
if ( ! searchStringArrayFor ( " fr " , languages ) )
errln ( " Didn't get fr as a language for FR " ) ;
languages = Locale . getLanguagesForCountry ( " CH " ) ;
if ( ! searchStringArrayFor ( " fr " , languages ) )
errln ( " Didn't get fr as a language for CH " ) ;
if ( ! searchStringArrayFor ( " it " , languages ) )
errln ( " Didn't get it as a language for CH " ) ;
if ( ! searchStringArrayFor ( " de " , languages ) )
errln ( " Didn't get de as a language for CH " ) ;
languages = Locale . getLanguagesForCountry ( " JP " ) ;
if ( ! searchStringArrayFor ( " ja " , languages ) )
errln ( " Didn't get ja as a language for JP " ) ;
}
*/
/*
2000-05-18 22:08:39 +00:00
private UBool searchStringArrayFor ( UnicodeString s , UnicodeString [ ] array ) {
1999-08-16 21:50:52 +00:00
for ( int32_t i = 0 ; i < array . length ; i + + )
if ( s . equals ( array [ i ] ) )
return TRUE ;
return FALSE ;
}
*/
/**
* @ bug 4110613
*/
// not applicable in C++
/*
void
LocaleTest : : TestSerialization ( ) throws ClassNotFoundException , OptionalDataException ,
IOException , StreamCorruptedException
{
ObjectOutputStream ostream ;
ByteArrayOutputStream obstream ;
byte [ ] bytes = null ;
obstream = new ByteArrayOutputStream ( ) ;
ostream = new ObjectOutputStream ( obstream ) ;
Locale test1 = new Locale ( " zh " , " TW " , " " ) ;
int32_t dummy = test1 . hashCode ( ) ; // fill in the cached hash-code value
ostream . writeObject ( test1 ) ;
bytes = obstream . toByteArray ( ) ;
ObjectInputStream istream = new ObjectInputStream ( new ByteArrayInputStream ( bytes ) ) ;
Locale test2 = ( Locale ) ( istream . readObject ( ) ) ;
if ( ! test1 . equals ( test2 ) | | test1 . hashCode ( ) ! = test2 . hashCode ( ) )
errln ( " Locale failed to deserialize correctly. " ) ;
}
*/
/**
* @ bug 4118587
*/
void
LocaleTest : : TestSimpleDisplayNames ( )
{
// 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 " } ;
1999-08-16 21:50:52 +00:00
UnicodeString languageNames [ ] = { " Hebrew " , " Indonesian " , " Inukitut " , " Uighur " , " Yiddish " ,
" Zhuang " } ;
for ( int32_t i = 0 ; i < 6 ; i + + ) {
UnicodeString test ;
Locale l ( languageCodes [ i ] , " " , " " ) ;
l . getDisplayLanguage ( Locale : : US , test ) ;
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
*/
void
LocaleTest : : TestUninstalledISO3Names ( )
{
// This test checks to make sure getISO3Language and getISO3Country work right
// even for locales that are not installed.
2000-04-15 21:28:17 +00:00
const char iso2Languages [ ] [ 4 ] = { " am " , " ba " , " fy " , " mr " , " rn " ,
1999-08-16 21:50:52 +00:00
" ss " , " tw " , " zu " } ;
2000-04-15 21:28:17 +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
}
2000-04-15 21:28:17 +00:00
char iso2Countries [ ] [ 4 ] = { " AF " , " BW " , " KZ " , " MO " , " MN " ,
1999-08-16 21:50:52 +00:00
" SB " , " TC " , " ZW " } ;
2000-04-15 21:28:17 +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
*/
void
LocaleTest : : TestAtypicalLocales ( )
{
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 " ) ,
2000-10-30 21:05:32 +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 " ) } ;
UnicodeString arabicDisplayNames [ ] = { " German (Canada) " ,
1999-08-16 21:50:52 +00:00
" Japanese (South Africa) " ,
2000-11-20 18:48:05 +00:00
" Russian (Mexico) " ,
1999-08-16 21:50:52 +00:00
" English (France) " ,
2000-11-20 18:48:05 +00:00
" Spanish (Germany) " ,
1999-08-16 21:50:52 +00:00
" Croatia " ,
" Sweden " ,
2000-11-20 18:48:05 +00:00
" Dominican Republic " ,
1999-08-16 21:50:52 +00:00
" Belgium " } ;
2000-11-20 18:48:05 +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 ;
1999-08-16 21:50:52 +00:00
Locale : : setDefault ( Locale : : US , status ) ;
for ( i = 0 ; i < 9 ; + + i ) {
UnicodeString name ;
localesToTest [ i ] . getDisplayName ( Locale : : US , name ) ;
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 ;
localesToTest [ i ] . getDisplayName ( Locale : : FRANCE , name ) ;
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 ;
localesToTest [ i ] . getDisplayName ( Locale ( " ar " , " ES " ) , name ) ;
logln ( name + " Locale fallback to ar, and data fallback to root " ) ;
if ( name ! = arabicDisplayNames [ i ] )
errln ( " Lookup in Arabic failed: expected \" " + arabicDisplayNames [ i ]
+ " \" , got \" " + name + " \" " ) ;
localesToTest [ i ] . getDisplayName ( Locale ( " ar " , " EG " ) , name ) ;
logln ( name + " Data fallback to root " ) ;
if ( name ! = arabicDisplayNames [ i ] )
errln ( " Lookup in Arabic failed: expected \" " + arabicDisplayNames [ i ]
+ " \" , got \" " + name + " \" " ) ;
}
1999-08-16 21:50:52 +00:00
}
/**
* @ bug 4126371
*/
// not applicable in C++, setDefault() takes a reference
void
LocaleTest : : TestNullDefault ( )
{
/*
// why on earth anyone would ever try to do this is beyond me, but we should
// definitely make sure we don't let them
2000-05-18 22:08:39 +00:00
UBool gotException = FALSE ;
1999-08-16 21:50:52 +00:00
try {
Locale . setDefault ( null ) ;
}
catch ( NullPointerException e ) {
// all other exception types propagate through here back to the test harness
gotException = TRUE ;
}
if ( Locale . getDefault ( ) = = null )
errln ( " Locale.getDefault() allowed us to set default to NULL! " ) ;
if ( ! gotException )
errln ( " Trying to set default locale to NULL didn't throw exception! " ) ;
*/
}
/**
* @ bug 4135752
* This would be better tested by the LocaleDataTest . Will move it when I
* get the LocaleDataTest working again .
*/
void
LocaleTest : : TestThaiCurrencyFormat ( )
{
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 .
*
* DON ' T ASSUME : Any specific countries support the Euro . Instead ,
* iterate through all locales .
*/
void
LocaleTest : : TestEuroSupport ( )
{
const UnicodeString EURO_VARIANT ( " EURO " ) ;
UChar euro = 0x20ac ;
const UnicodeString EURO_CURRENCY ( & euro , 1 , 1 ) ; // Look for this UnicodeString in formatted Euro currency
1999-10-07 00:07:53 +00:00
UErrorCode status = U_ZERO_ERROR ;
1999-08-16 21:50:52 +00:00
UnicodeString temp ;
int32_t locCount = 0 ;
const Locale * locales = NumberFormat : : getAvailableLocales ( locCount ) ;
for ( int32_t i = 0 ; i < locCount ; + + i ) {
Locale loc = locales [ i ] ;
UnicodeString temp ;
2000-04-15 21:28:17 +00:00
if ( ( temp = loc . getVariant ( ) ) . indexOf ( EURO_VARIANT ) > = 0 ) {
1999-08-16 21:50:52 +00:00
NumberFormat * nf = NumberFormat : : createCurrencyInstance ( loc , status ) ;
UnicodeString pos ;
nf - > format ( 271828.182845 , pos ) ;
UnicodeString neg ;
nf - > format ( - 271828.182845 , neg ) ;
if ( pos . indexOf ( EURO_CURRENCY ) > = 0 & &
neg . indexOf ( EURO_CURRENCY ) > = 0 ) {
2000-04-15 21:28:17 +00:00
logln ( " Ok: " + ( temp = loc . getName ( ) ) +
1999-08-16 21:50:52 +00:00
" : " + pos + " / " + neg ) ;
}
else {
2000-04-15 21:28:17 +00:00
errln ( " Fail: " + ( temp = loc . getName ( ) ) +
1999-08-16 21:50:52 +00:00
" formats without " + EURO_CURRENCY +
" : " + pos + " / " + neg +
" \n *** THIS FAILURE MAY ONLY MEAN THAT LOCALE DATA HAS CHANGED *** " ) ;
}
delete nf ;
}
}
}
/**
* @ bug 4139504
* toString ( ) doesn ' t work with language_VARIANT .
*/
void
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 " ,
} ;
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
}
}
/**
* @ bug 4139940
* Couldn ' t reproduce this bug - - probably was fixed earlier .
*
* ORIGINAL BUG REPORT :
* - - basically , hungarian for monday shouldn ' t have an \ u00f4
* ( o circumflex ) in it instead it should be an o with 2 inclined
* ( 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 .
*/
void
LocaleTest : : Test4139940 ( )
{
Locale mylocale ( " hu " , " " , " " ) ;
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 ) ;
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 ;
if ( str . indexOf ( oda ) < 0 | | str . indexOf ( ocf ) > = 0 )
errln ( " Fail: Monday in Hungarian is wrong " ) ;
}
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 ) ;
if ( cal = = 0 )
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 ;
delete cal ;
return dt ;
}
/**
* @ bug 4143951
* Russian first day of week should be Monday . Confirmed .
*/
void
LocaleTest : : Test4143951 ( )
{
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 ) ;
if ( cal - > getFirstDayOfWeek ( ) ! = Calendar : : MONDAY ) {
errln ( " Fail: First day of week in Russia should be Monday " ) ;
}
delete cal ;
}
/**
* @ bug 4147315
* java . util . Locale . getISO3Country ( ) works wrong for non ISO - 3166 codes .
* Should throw an exception for unknown locales
*/
void
LocaleTest : : Test4147315 ( )
{
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 " ) ;
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 ) )
errln ( " ERROR: getISO3Country() returns: " + UnicodeString ( result , " " ) +
" 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
*/
void
LocaleTest : : Test4147317 ( )
{
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 " ) ;
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 ) )
errln ( " ERROR: getISO3Language() returns: " + UnicodeString ( result , " " ) +
" for locale ' " + ( temp = locale . getName ( ) ) + " ' rather than exception " ) ;
1999-08-16 21:50:52 +00:00
}
/*
* @ bug 4147552
*/
void
LocaleTest : : Test4147552 ( )
{
Locale locales [ ] = { Locale ( " no " , " NO " ) ,
Locale ( " no " , " NO " , " B " ) ,
Locale ( " no " , " NO " , " NY " )
} ;
UnicodeString edn ( " Norwegian (Norway, Bokm " ) ;
2000-04-03 23:53:59 +00:00
edn + = ( UChar32 ) 0x00e5 ;
1999-08-16 21:50:52 +00:00
edn + = " l) " ;
UnicodeString englishDisplayNames [ ] = {
" Norwegian (Norway) " ,
edn ,
// "Norwegian (Norway,B)",
//"Norwegian (Norway,NY)"
" Norwegian (Norway, Nynorsk) "
} ;
UnicodeString ndn ( " norsk (Norge, Bokm " ) ;
2000-04-03 23:53:59 +00:00
ndn + = ( UChar32 ) 0x00e5 ;
1999-08-16 21:50:52 +00:00
ndn + = " l) " ;
UnicodeString norwegianDisplayNames [ ] = {
" norsk (Norge) " ,
//"norsk (Norge,B)",
ndn ,
//"norsk (Norge,NY)"
2000-12-19 21:48:58 +00:00
" norsk (Noreg, Nynorsk) "
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 ) ) ;
}
}
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 " ) ;
UnicodeString got ;
en_US_custom . getDisplayVariant ( Locale : : US , got ) ;
if ( got ! = dispVar ) {
errln ( " FAIL: getDisplayVariant() " ) ;
errln ( " Wanted: " + dispVar ) ;
errln ( " Got : " + got ) ;
}
en_US_custom . getDisplayName ( Locale : : US , got ) ;
if ( got ! = dispName ) {
errln ( " FAIL: getDisplayName() " ) ;
errln ( " Wanted: " + dispName ) ;
errln ( " Got : " + got ) ;
}
Locale shortVariant ( " fr " , " FR " , " foo " ) ;
shortVariant . getDisplayVariant ( got ) ;
if ( got ! = " FOO " ) {
errln ( " FAIL: getDisplayVariant() " ) ;
errln ( " Wanted: foo " ) ;
errln ( " Got : " + got ) ;
}
Locale bogusVariant ( " fr " , " FR " , " _foo " ) ;
bogusVariant . getDisplayVariant ( got ) ;
if ( got ! = " FOO " ) {
errln ( " FAIL: getDisplayVariant() " ) ;
errln ( " Wanted: foo " ) ;
errln ( " Got : " + got ) ;
}
Locale bogusVariant2 ( " fr " , " FR " , " foo_ " ) ;
bogusVariant2 . getDisplayVariant ( got ) ;
if ( got ! = " FOO " ) {
errln ( " FAIL: getDisplayVariant() " ) ;
errln ( " Wanted: foo " ) ;
errln ( " Got : " + got ) ;
}
Locale bogusVariant3 ( " fr " , " FR " , " _foo_ " ) ;
bogusVariant3 . getDisplayVariant ( got ) ;
if ( got ! = " FOO " ) {
errln ( " FAIL: getDisplayVariant() " ) ;
errln ( " Wanted: foo " ) ;
errln ( " Got : " + got ) ;
}
}
/**
* @ bug 4105828
* Currency symbol in zh is wrong . We will test this at the NumberFormat
* end to test the whole pipe .
*/
void
LocaleTest : : Test4105828 ( )
{
Locale LOC [ ] = { Locale : : CHINESE , Locale ( " zh " , " CN " , " " ) ,
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 ;
}
}