2010-01-14 02:23:46 +00:00
/*********************************************************************
* COPYRIGHT :
2014-03-02 00:44:35 +00:00
* Copyright ( c ) 2010 - 2014 , International Business Machines Corporation and
2010-01-14 02:23:46 +00:00
* others . All Rights Reserved .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
# include "locnmtst.h"
2010-02-24 22:29:08 +00:00
# include "cstring.h"
2010-01-14 02:23:46 +00:00
/*
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 ) ) \
errln ( " FAIL: " # test " was not true. In " __FILE__ " on line %d " , __LINE__ ) ; \
else \
logln ( " PASS: asserted " # 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: " # test " was not true. " + UnicodeString ( print ) ) ; \
else \
logln ( " PASS: asserted " # test " -> " + UnicodeString ( print ) ) ; \
}
# define test_assert_equal(target,value) \
{ \
if ( UnicodeString ( target ) ! = ( value ) ) { \
logln ( " unexpected value ' " + ( value ) + " ' " ) ; \
2010-02-24 16:17:03 +00:00
dataerrln ( " FAIL: " # target " == " # value " was not true. In " __FILE__ " on line %d " , __LINE__ ) ; \
2010-01-14 02:23:46 +00:00
} else { \
2012-10-09 12:45:54 +00:00
logln ( " PASS: asserted " # target " == " # value ) ; \
2010-01-14 02:23:46 +00:00
} \
}
# define test_dumpLocale(l) { logln(#l " = " + UnicodeString(l.getName(), "")); }
LocaleDisplayNamesTest : : LocaleDisplayNamesTest ( ) {
}
LocaleDisplayNamesTest : : ~ LocaleDisplayNamesTest ( ) {
}
void LocaleDisplayNamesTest : : runIndexedTest ( int32_t index , UBool exec , const char * & name ,
2012-10-09 12:45:54 +00:00
char * /*par*/ ) {
2010-01-14 02:23:46 +00:00
switch ( index ) {
# if !UCONFIG_NO_FORMATTING
TESTCASE ( 0 , TestCreate ) ;
TESTCASE ( 1 , TestCreateDialect ) ;
2012-10-09 12:45:54 +00:00
TESTCASE ( 2 , TestWithKeywordsAndEverything ) ;
TESTCASE ( 3 , TestUldnOpen ) ;
TESTCASE ( 4 , TestUldnOpenDialect ) ;
TESTCASE ( 5 , TestUldnWithKeywordsAndEverything ) ;
TESTCASE ( 6 , TestUldnComponents ) ;
TESTCASE ( 7 , TestRootEtc ) ;
2014-12-10 09:00:53 +00:00
TESTCASE ( 8 , TestCurrencyKeyword ) ;
TESTCASE ( 9 , TestUnknownCurrencyKeyword ) ;
TESTCASE ( 10 , TestUntranslatedKeywords ) ;
TESTCASE ( 11 , TestPrivateUse ) ;
TESTCASE ( 12 , TestUldnDisplayContext ) ;
2010-01-14 02:23:46 +00:00
# endif
default :
2012-10-09 12:45:54 +00:00
name = " " ;
break ;
2010-01-14 02:23:46 +00:00
}
}
2010-01-26 00:55:35 +00:00
# if !UCONFIG_NO_FORMATTING
2010-01-14 02:23:46 +00:00
void LocaleDisplayNamesTest : : TestCreate ( ) {
UnicodeString temp ;
LocaleDisplayNames * ldn = LocaleDisplayNames : : createInstance ( Locale : : getGermany ( ) ) ;
ldn - > localeDisplayName ( " de_DE " , temp ) ;
delete ldn ;
test_assert_equal ( " Deutsch (Deutschland) " , temp ) ;
}
void LocaleDisplayNamesTest : : TestCreateDialect ( ) {
UnicodeString temp ;
LocaleDisplayNames * ldn = LocaleDisplayNames : : createInstance ( Locale : : getUS ( ) , ULDN_DIALECT_NAMES ) ;
ldn - > localeDisplayName ( " en_GB " , temp ) ;
delete ldn ;
test_assert_equal ( " British English " , temp ) ;
}
void LocaleDisplayNamesTest : : TestWithKeywordsAndEverything ( ) {
UnicodeString temp ;
LocaleDisplayNames * ldn = LocaleDisplayNames : : createInstance ( Locale : : getUS ( ) ) ;
const char * locname = " en_Hant_US_VALLEY@calendar=gregorian;collation=phonebook " ;
2011-03-12 14:57:18 +00:00
const char * target = " English (Traditional, United States, VALLEY, "
2012-02-14 00:42:04 +00:00
" Gregorian Calendar, Phonebook Sort Order) " ;
ldn - > localeDisplayName ( locname , temp ) ;
delete ldn ;
test_assert_equal ( target , temp ) ;
}
2014-12-10 09:00:53 +00:00
void LocaleDisplayNamesTest : : TestCurrencyKeyword ( ) {
UnicodeString temp ;
LocaleDisplayNames * ldn = LocaleDisplayNames : : createInstance ( Locale : : getUS ( ) ) ;
const char * locname = " ja@currency=JPY " ;
const char * target = " Japanese (Japanese Yen) " ;
ldn - > localeDisplayName ( locname , temp ) ;
delete ldn ;
test_assert_equal ( target , temp ) ;
}
void LocaleDisplayNamesTest : : TestUnknownCurrencyKeyword ( ) {
2012-02-14 00:42:04 +00:00
UnicodeString temp ;
LocaleDisplayNames * ldn = LocaleDisplayNames : : createInstance ( Locale : : getUS ( ) ) ;
const char * locname = " de@currency=XYZ " ;
const char * target = " German (Currency: XYZ) " ;
ldn - > localeDisplayName ( locname , temp ) ;
delete ldn ;
test_assert_equal ( target , temp ) ;
}
void LocaleDisplayNamesTest : : TestUntranslatedKeywords ( ) {
UnicodeString temp ;
LocaleDisplayNames * ldn = LocaleDisplayNames : : createInstance ( Locale : : getUS ( ) ) ;
const char * locname = " de@foo=bar " ;
const char * target = " German (foo=bar) " ;
ldn - > localeDisplayName ( locname , temp ) ;
delete ldn ;
test_assert_equal ( target , temp ) ;
}
void LocaleDisplayNamesTest : : TestPrivateUse ( ) {
UnicodeString temp ;
LocaleDisplayNames * ldn = LocaleDisplayNames : : createInstance ( Locale : : getUS ( ) ) ;
const char * locname = " de@x=foobar " ;
const char * target = " German (Private-Use: foobar) " ;
2010-01-14 02:23:46 +00:00
ldn - > localeDisplayName ( locname , temp ) ;
delete ldn ;
test_assert_equal ( target , temp ) ;
}
2010-01-15 02:35:02 +00:00
void LocaleDisplayNamesTest : : TestUldnOpen ( ) {
UErrorCode status = U_ZERO_ERROR ;
const int32_t kMaxResultSize = 150 ; // long enough
UChar result [ 150 ] ;
ULocaleDisplayNames * ldn = uldn_open ( Locale : : getGermany ( ) . getName ( ) , ULDN_STANDARD_NAMES , & status ) ;
int32_t len = uldn_localeDisplayName ( ldn , " de_DE " , result , kMaxResultSize , & status ) ;
uldn_close ( ldn ) ;
test_assert ( U_SUCCESS ( status ) ) ;
UnicodeString str ( result , len , kMaxResultSize ) ;
test_assert_equal ( " Deutsch (Deutschland) " , str ) ;
2010-02-24 22:29:08 +00:00
// make sure that NULL gives us the default locale as usual
ldn = uldn_open ( NULL , ULDN_STANDARD_NAMES , & status ) ;
const char * locale = uldn_getLocale ( ldn ) ;
if ( 0 ! = uprv_strcmp ( uloc_getDefault ( ) , locale ) ) {
errln ( " uldn_getLocale(uldn_open(NULL))=%s != default locale %s \n " , locale , uloc_getDefault ( ) ) ;
}
uldn_close ( ldn ) ;
test_assert ( U_SUCCESS ( status ) ) ;
2010-01-15 02:35:02 +00:00
}
void LocaleDisplayNamesTest : : TestUldnOpenDialect ( ) {
UErrorCode status = U_ZERO_ERROR ;
const int32_t kMaxResultSize = 150 ; // long enough
UChar result [ 150 ] ;
ULocaleDisplayNames * ldn = uldn_open ( Locale : : getUS ( ) . getName ( ) , ULDN_DIALECT_NAMES , & status ) ;
int32_t len = uldn_localeDisplayName ( ldn , " en_GB " , result , kMaxResultSize , & status ) ;
uldn_close ( ldn ) ;
test_assert ( U_SUCCESS ( status ) ) ;
UnicodeString str ( result , len , kMaxResultSize ) ;
test_assert_equal ( " British English " , str ) ;
}
void LocaleDisplayNamesTest : : TestUldnWithKeywordsAndEverything ( ) {
UErrorCode status = U_ZERO_ERROR ;
const int32_t kMaxResultSize = 150 ; // long enough
UChar result [ 150 ] ;
const char * locname = " en_Hant_US_VALLEY@calendar=gregorian;collation=phonebook " ;
2011-03-12 14:57:18 +00:00
const char * target = " English (Traditional, United States, VALLEY, "
2012-02-14 00:42:04 +00:00
" Gregorian Calendar, Phonebook Sort Order) " ;
2010-01-15 02:35:02 +00:00
ULocaleDisplayNames * ldn = uldn_open ( Locale : : getUS ( ) . getName ( ) , ULDN_STANDARD_NAMES , & status ) ;
int32_t len = uldn_localeDisplayName ( ldn , locname , result , kMaxResultSize , & status ) ;
uldn_close ( ldn ) ;
test_assert ( U_SUCCESS ( status ) ) ;
UnicodeString str ( result , len , kMaxResultSize ) ;
test_assert_equal ( target , str ) ;
}
void LocaleDisplayNamesTest : : TestUldnComponents ( ) {
UErrorCode status = U_ZERO_ERROR ;
const int32_t kMaxResultSize = 150 ; // long enough
UChar result [ 150 ] ;
ULocaleDisplayNames * ldn = uldn_open ( Locale : : getGermany ( ) . getName ( ) , ULDN_STANDARD_NAMES , & status ) ;
test_assert ( U_SUCCESS ( status ) ) ;
if ( U_FAILURE ( status ) ) {
return ;
}
// "en_Hant_US_PRE_EURO@calendar=gregorian";
{
int32_t len = uldn_languageDisplayName ( ldn , " en " , result , kMaxResultSize , & status ) ;
UnicodeString str ( result , len , kMaxResultSize ) ;
test_assert_equal ( " Englisch " , str ) ;
}
{
int32_t len = uldn_scriptDisplayName ( ldn , " Hant " , result , kMaxResultSize , & status ) ;
UnicodeString str ( result , len , kMaxResultSize ) ;
2011-05-05 18:12:27 +00:00
test_assert_equal ( " Traditionell " , str ) ;
2010-01-15 02:35:02 +00:00
}
{
int32_t len = uldn_scriptCodeDisplayName ( ldn , USCRIPT_TRADITIONAL_HAN , result , kMaxResultSize ,
2012-10-09 12:45:54 +00:00
& status ) ;
2010-01-15 02:35:02 +00:00
UnicodeString str ( result , len , kMaxResultSize ) ;
2011-05-05 18:12:27 +00:00
test_assert_equal ( " Traditionell " , str ) ;
2010-01-15 02:35:02 +00:00
}
{
int32_t len = uldn_regionDisplayName ( ldn , " US " , result , kMaxResultSize , & status ) ;
UnicodeString str ( result , len , kMaxResultSize ) ;
test_assert_equal ( " Vereinigte Staaten " , str ) ;
}
{
int32_t len = uldn_variantDisplayName ( ldn , " PRE_EURO " , result , kMaxResultSize , & status ) ;
UnicodeString str ( result , len , kMaxResultSize ) ;
test_assert_equal ( " PRE_EURO " , str ) ;
}
{
int32_t len = uldn_keyDisplayName ( ldn , " calendar " , result , kMaxResultSize , & status ) ;
UnicodeString str ( result , len , kMaxResultSize ) ;
test_assert_equal ( " Kalender " , str ) ;
}
{
int32_t len = uldn_keyValueDisplayName ( ldn , " calendar " , " gregorian " , result ,
2012-10-09 12:45:54 +00:00
kMaxResultSize , & status ) ;
2010-01-15 02:35:02 +00:00
UnicodeString str ( result , len , kMaxResultSize ) ;
test_assert_equal ( " Gregorianischer Kalender " , str ) ;
}
uldn_close ( ldn ) ;
}
2010-01-21 02:45:53 +00:00
2012-10-09 12:45:54 +00:00
typedef struct {
const char * displayLocale ;
UDisplayContext dialectHandling ;
UDisplayContext capitalization ;
2014-09-05 04:54:53 +00:00
UDisplayContext displayLength ;
2012-10-09 12:45:54 +00:00
const char * localeToBeNamed ;
const UChar * result ;
} LocNameDispContextItem ;
static char en [ ] = " en " ;
2014-09-05 04:54:53 +00:00
static char en_GB [ ] = " en_GB " ;
2012-10-09 12:45:54 +00:00
static UChar daFor_en [ ] = { 0x65 , 0x6E , 0x67 , 0x65 , 0x6C , 0x73 , 0x6B , 0 } ; //"engelsk"
2014-09-05 04:54:53 +00:00
static UChar daFor_en_GB [ ] = { 0x65 , 0x6E , 0x67 , 0x65 , 0x6C , 0x73 , 0x6B , 0x20 , 0x28 , 0x53 , 0x74 , 0x6F , 0x72 , 0x62 , 0x72 , 0x69 , 0x74 , 0x61 , 0x6E , 0x6E , 0x69 , 0x65 , 0x6E , 0x29 , 0 } ; //"engelsk (Storbritannien)"
static UChar daFor_en_GB_S [ ] = { 0x65 , 0x6E , 0x67 , 0x65 , 0x6C , 0x73 , 0x6B , 0x20 , 0x28 , 0x55 , 0x4B , 0x29 , 0 } ; //"engelsk (UK)"
static UChar daFor_en_GB_D [ ] = { 0x62 , 0x72 , 0x69 , 0x74 , 0x69 , 0x73 , 0x6B , 0x20 , 0x65 , 0x6E , 0x67 , 0x65 , 0x6C , 0x73 , 0x6B , 0 } ; //"britisk engelsk"
static UChar esFor_en [ ] = { 0x69 , 0x6E , 0x67 , 0x6C , 0xE9 , 0x73 , 0 } ; //"ingles" with acute on the e
2014-09-10 13:59:41 +00:00
static UChar esFor_en_GB [ ] = { 0x69 , 0x6E , 0x67 , 0x6C , 0xE9 , 0x73 , 0x20 , 0x28 , 0x52 , 0x65 , 0x69 , 0x6E , 0x6F , 0x20 , 0x55 , 0x6E , 0x69 , 0x64 , 0x6F , 0x29 , 0 } ; //"ingles (Reino Unido)" ...
2014-09-05 04:54:53 +00:00
static UChar esFor_en_GB_S [ ] = { 0x69 , 0x6E , 0x67 , 0x6C , 0xE9 , 0x73 , 0x20 , 0x28 , 0x52 , 0x55 , 0x29 , 0 } ; //"ingles (RU)" ...
static UChar esFor_en_GB_D [ ] = { 0x69 , 0x6E , 0x67 , 0x6C , 0xE9 , 0x73 , 0x20 , 0x62 , 0x72 , 0x69 , 0x74 , 0xE1 , 0x6E , 0x69 , 0x63 , 0x6F , 0 } ; //"ingles britanico" with acute on the e, a
2012-10-18 19:51:28 +00:00
# if !UCONFIG_NO_BREAK_ITERATION
static UChar daFor_en_T [ ] = { 0x45 , 0x6E , 0x67 , 0x65 , 0x6C , 0x73 , 0x6B , 0 } ; //"Engelsk"
2014-09-05 04:54:53 +00:00
static UChar daFor_en_GB_T [ ] = { 0x45 , 0x6E , 0x67 , 0x65 , 0x6C , 0x73 , 0x6B , 0x20 , 0x28 , 0x53 , 0x74 , 0x6F , 0x72 , 0x62 , 0x72 , 0x69 , 0x74 , 0x61 , 0x6E , 0x6E , 0x69 , 0x65 , 0x6E , 0x29 , 0 } ; //"Engelsk (Storbritannien)"
static UChar daFor_en_GB_ST [ ] = { 0x45 , 0x6E , 0x67 , 0x65 , 0x6C , 0x73 , 0x6B , 0x20 , 0x28 , 0x55 , 0x4B , 0x29 , 0 } ; //"Engelsk (UK)"
static UChar daFor_en_GB_DT [ ] = { 0x42 , 0x72 , 0x69 , 0x74 , 0x69 , 0x73 , 0x6B , 0x20 , 0x65 , 0x6E , 0x67 , 0x65 , 0x6C , 0x73 , 0x6B , 0 } ; //"Britisk engelsk"
static UChar esFor_en_T [ ] = { 0x49 , 0x6E , 0x67 , 0x6C , 0xE9 , 0x73 , 0 } ; //"Ingles" with acute on the e
static UChar esFor_en_GB_T [ ] = { 0x49 , 0x6E , 0x67 , 0x6C , 0xE9 , 0x73 , 0x20 , 0x28 , 0x52 , 0x65 , 0x69 , 0x6E , 0x6F , 0x20 , 0x55 , 0x6E , 0x69 , 0x64 , 0x6F , 0x29 , 0 } ; //"Ingles (Reino Unido)" ...
static UChar esFor_en_GB_ST [ ] = { 0x49 , 0x6E , 0x67 , 0x6C , 0xE9 , 0x73 , 0x20 , 0x28 , 0x52 , 0x55 , 0x29 , 0 } ; //"Ingles (RU)" ...
static UChar esFor_en_GB_DT [ ] = { 0x49 , 0x6E , 0x67 , 0x6C , 0xE9 , 0x73 , 0x20 , 0x62 , 0x72 , 0x69 , 0x74 , 0xE1 , 0x6E , 0x69 , 0x63 , 0x6F , 0 } ; //"Ingles britanico" with acute on the e, a
2012-10-18 19:51:28 +00:00
# endif /* #if !UCONFIG_NO_BREAK_ITERATION */
2012-10-09 12:45:54 +00:00
static const LocNameDispContextItem ctxtItems [ ] = {
2014-09-05 04:54:53 +00:00
{ " da " , UDISPCTX_STANDARD_NAMES , UDISPCTX_CAPITALIZATION_FOR_MIDDLE_OF_SENTENCE , UDISPCTX_LENGTH_FULL , en , daFor_en } ,
{ " da " , UDISPCTX_STANDARD_NAMES , UDISPCTX_CAPITALIZATION_FOR_MIDDLE_OF_SENTENCE , UDISPCTX_LENGTH_FULL , en_GB , daFor_en_GB } ,
{ " da " , UDISPCTX_STANDARD_NAMES , UDISPCTX_CAPITALIZATION_FOR_MIDDLE_OF_SENTENCE , UDISPCTX_LENGTH_SHORT , en_GB , daFor_en_GB_S } ,
{ " da " , UDISPCTX_DIALECT_NAMES , UDISPCTX_CAPITALIZATION_FOR_MIDDLE_OF_SENTENCE , UDISPCTX_LENGTH_FULL , en_GB , daFor_en_GB_D } ,
{ " es " , UDISPCTX_STANDARD_NAMES , UDISPCTX_CAPITALIZATION_FOR_MIDDLE_OF_SENTENCE , UDISPCTX_LENGTH_FULL , en , esFor_en } ,
{ " es " , UDISPCTX_STANDARD_NAMES , UDISPCTX_CAPITALIZATION_FOR_MIDDLE_OF_SENTENCE , UDISPCTX_LENGTH_FULL , en_GB , esFor_en_GB } ,
{ " es " , UDISPCTX_STANDARD_NAMES , UDISPCTX_CAPITALIZATION_FOR_MIDDLE_OF_SENTENCE , UDISPCTX_LENGTH_SHORT , en_GB , esFor_en_GB_S } ,
{ " es " , UDISPCTX_DIALECT_NAMES , UDISPCTX_CAPITALIZATION_FOR_MIDDLE_OF_SENTENCE , UDISPCTX_LENGTH_FULL , en_GB , esFor_en_GB_D } ,
2012-10-18 19:51:28 +00:00
# if !UCONFIG_NO_BREAK_ITERATION
2014-09-05 04:54:53 +00:00
{ " da " , UDISPCTX_STANDARD_NAMES , UDISPCTX_CAPITALIZATION_FOR_BEGINNING_OF_SENTENCE , UDISPCTX_LENGTH_FULL , en , daFor_en_T } ,
{ " da " , UDISPCTX_STANDARD_NAMES , UDISPCTX_CAPITALIZATION_FOR_BEGINNING_OF_SENTENCE , UDISPCTX_LENGTH_FULL , en_GB , daFor_en_GB_T } ,
{ " da " , UDISPCTX_STANDARD_NAMES , UDISPCTX_CAPITALIZATION_FOR_BEGINNING_OF_SENTENCE , UDISPCTX_LENGTH_SHORT , en_GB , daFor_en_GB_ST } ,
{ " da " , UDISPCTX_DIALECT_NAMES , UDISPCTX_CAPITALIZATION_FOR_BEGINNING_OF_SENTENCE , UDISPCTX_LENGTH_FULL , en_GB , daFor_en_GB_DT } ,
{ " es " , UDISPCTX_STANDARD_NAMES , UDISPCTX_CAPITALIZATION_FOR_BEGINNING_OF_SENTENCE , UDISPCTX_LENGTH_FULL , en , esFor_en_T } ,
{ " es " , UDISPCTX_STANDARD_NAMES , UDISPCTX_CAPITALIZATION_FOR_BEGINNING_OF_SENTENCE , UDISPCTX_LENGTH_FULL , en_GB , esFor_en_GB_T } ,
{ " es " , UDISPCTX_STANDARD_NAMES , UDISPCTX_CAPITALIZATION_FOR_BEGINNING_OF_SENTENCE , UDISPCTX_LENGTH_SHORT , en_GB , esFor_en_GB_ST } ,
{ " es " , UDISPCTX_DIALECT_NAMES , UDISPCTX_CAPITALIZATION_FOR_BEGINNING_OF_SENTENCE , UDISPCTX_LENGTH_FULL , en_GB , esFor_en_GB_DT } ,
{ " da " , UDISPCTX_STANDARD_NAMES , UDISPCTX_CAPITALIZATION_FOR_UI_LIST_OR_MENU , UDISPCTX_LENGTH_FULL , en , daFor_en_T } ,
{ " da " , UDISPCTX_STANDARD_NAMES , UDISPCTX_CAPITALIZATION_FOR_UI_LIST_OR_MENU , UDISPCTX_LENGTH_FULL , en_GB , daFor_en_GB_T } ,
{ " da " , UDISPCTX_STANDARD_NAMES , UDISPCTX_CAPITALIZATION_FOR_UI_LIST_OR_MENU , UDISPCTX_LENGTH_SHORT , en_GB , daFor_en_GB_ST } ,
{ " da " , UDISPCTX_DIALECT_NAMES , UDISPCTX_CAPITALIZATION_FOR_UI_LIST_OR_MENU , UDISPCTX_LENGTH_FULL , en_GB , daFor_en_GB_DT } ,
{ " es " , UDISPCTX_STANDARD_NAMES , UDISPCTX_CAPITALIZATION_FOR_UI_LIST_OR_MENU , UDISPCTX_LENGTH_FULL , en , esFor_en_T } ,
{ " es " , UDISPCTX_STANDARD_NAMES , UDISPCTX_CAPITALIZATION_FOR_UI_LIST_OR_MENU , UDISPCTX_LENGTH_FULL , en_GB , esFor_en_GB_T } ,
{ " es " , UDISPCTX_STANDARD_NAMES , UDISPCTX_CAPITALIZATION_FOR_UI_LIST_OR_MENU , UDISPCTX_LENGTH_SHORT , en_GB , esFor_en_GB_ST } ,
{ " es " , UDISPCTX_DIALECT_NAMES , UDISPCTX_CAPITALIZATION_FOR_UI_LIST_OR_MENU , UDISPCTX_LENGTH_FULL , en_GB , esFor_en_GB_DT } ,
{ " da " , UDISPCTX_STANDARD_NAMES , UDISPCTX_CAPITALIZATION_FOR_STANDALONE , UDISPCTX_LENGTH_FULL , en , daFor_en } ,
{ " da " , UDISPCTX_STANDARD_NAMES , UDISPCTX_CAPITALIZATION_FOR_STANDALONE , UDISPCTX_LENGTH_FULL , en_GB , daFor_en_GB } ,
{ " da " , UDISPCTX_STANDARD_NAMES , UDISPCTX_CAPITALIZATION_FOR_STANDALONE , UDISPCTX_LENGTH_SHORT , en_GB , daFor_en_GB_S } ,
{ " da " , UDISPCTX_DIALECT_NAMES , UDISPCTX_CAPITALIZATION_FOR_STANDALONE , UDISPCTX_LENGTH_FULL , en_GB , daFor_en_GB_D } ,
{ " es " , UDISPCTX_STANDARD_NAMES , UDISPCTX_CAPITALIZATION_FOR_STANDALONE , UDISPCTX_LENGTH_FULL , en , esFor_en_T } ,
{ " es " , UDISPCTX_STANDARD_NAMES , UDISPCTX_CAPITALIZATION_FOR_STANDALONE , UDISPCTX_LENGTH_FULL , en_GB , esFor_en_GB_T } ,
{ " es " , UDISPCTX_STANDARD_NAMES , UDISPCTX_CAPITALIZATION_FOR_STANDALONE , UDISPCTX_LENGTH_SHORT , en_GB , esFor_en_GB_ST } ,
{ " es " , UDISPCTX_DIALECT_NAMES , UDISPCTX_CAPITALIZATION_FOR_STANDALONE , UDISPCTX_LENGTH_FULL , en_GB , esFor_en_GB_DT } ,
2012-10-18 19:51:28 +00:00
# endif /* #if !UCONFIG_NO_BREAK_ITERATION */
2014-09-05 04:54:53 +00:00
{ NULL , ( UDisplayContext ) 0 , ( UDisplayContext ) 0 , ( UDisplayContext ) 0 , NULL , NULL }
2012-10-09 12:45:54 +00:00
} ;
void LocaleDisplayNamesTest : : TestUldnDisplayContext ( ) {
const LocNameDispContextItem * ctxtItemPtr ;
for ( ctxtItemPtr = ctxtItems ; ctxtItemPtr - > displayLocale ! = NULL ; ctxtItemPtr + + ) {
2014-09-05 04:54:53 +00:00
UDisplayContext contexts [ 3 ] = { ctxtItemPtr - > dialectHandling , ctxtItemPtr - > capitalization , ctxtItemPtr - > displayLength } ;
2012-10-09 12:45:54 +00:00
UErrorCode status = U_ZERO_ERROR ;
2014-09-05 04:54:53 +00:00
ULocaleDisplayNames * uldn = uldn_openForContext ( ctxtItemPtr - > displayLocale , contexts , 3 , & status ) ;
2012-10-09 12:45:54 +00:00
if ( U_FAILURE ( status ) ) {
errln ( UnicodeString ( " FAIL: uldn_openForContext failed for locale " ) + ctxtItemPtr - > displayLocale +
2014-09-05 04:54:53 +00:00
" , dialectHandling " + ctxtItemPtr - > dialectHandling +
" , capitalization " + ctxtItemPtr - > capitalization +
" , displayLength " + ctxtItemPtr - > displayLength ) ;
2012-10-09 12:45:54 +00:00
} else {
UDisplayContext dialectHandling = uldn_getContext ( uldn , UDISPCTX_TYPE_DIALECT_HANDLING , & status ) ;
UDisplayContext capitalization = uldn_getContext ( uldn , UDISPCTX_TYPE_CAPITALIZATION , & status ) ;
2014-09-05 04:54:53 +00:00
UDisplayContext displayLength = uldn_getContext ( uldn , UDISPCTX_TYPE_DISPLAY_LENGTH , & status ) ;
2012-10-09 12:45:54 +00:00
if ( U_FAILURE ( status ) ) {
errln ( UnicodeString ( " FAIL: uldn_getContext status " ) + ( int ) status ) ;
2014-09-05 04:54:53 +00:00
} else if ( dialectHandling ! = ctxtItemPtr - > dialectHandling | |
capitalization ! = ctxtItemPtr - > capitalization | |
displayLength ! = ctxtItemPtr - > displayLength ) {
errln ( " FAIL: uldn_getContext retrieved incorrect dialectHandling, capitalization, or displayLength " ) ;
2012-10-09 12:45:54 +00:00
} else {
UChar nameBuf [ ULOC_FULLNAME_CAPACITY ] ;
int32_t len = uldn_localeDisplayName ( uldn , ctxtItemPtr - > localeToBeNamed , nameBuf , ULOC_FULLNAME_CAPACITY , & status ) ;
if ( U_FAILURE ( status ) ) {
2012-10-19 20:09:53 +00:00
dataerrln ( UnicodeString ( " FAIL: uldn_localeDisplayName status: " ) + u_errorName ( status ) ) ;
2012-10-09 12:45:54 +00:00
} else if ( u_strcmp ( ctxtItemPtr - > result , nameBuf ) ! = 0 ) {
UnicodeString exp ( ctxtItemPtr - > result , u_strlen ( ctxtItemPtr - > result ) ) ;
UnicodeString got ( nameBuf , len ) ;
2012-10-19 20:09:53 +00:00
dataerrln ( UnicodeString ( " FAIL: uldn_localeDisplayName, capitalization " ) + ctxtItemPtr - > capitalization +
" , expected " + exp + " , got " + got ) ;
2012-10-09 12:45:54 +00:00
}
}
2012-10-16 16:01:17 +00:00
uldn_close ( uldn ) ;
2012-10-09 12:45:54 +00:00
}
}
}
2010-01-21 02:45:53 +00:00
void LocaleDisplayNamesTest : : TestRootEtc ( ) {
UnicodeString temp ;
LocaleDisplayNames * ldn = LocaleDisplayNames : : createInstance ( Locale : : getUS ( ) ) ;
const char * locname = " @collation=phonebook " ;
2012-02-14 00:42:04 +00:00
const char * target = " Root (Phonebook Sort Order) " ;
2010-01-21 02:45:53 +00:00
ldn - > localeDisplayName ( locname , temp ) ;
test_assert_equal ( target , temp ) ;
ldn - > languageDisplayName ( " root " , temp ) ;
test_assert_equal ( " root " , temp ) ;
ldn - > languageDisplayName ( " en_GB " , temp ) ;
test_assert_equal ( " en_GB " , temp ) ;
delete ldn ;
}
2010-01-26 00:55:35 +00:00
# endif /* UCONFIG_NO_FORMATTING */