1ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/******************************************************************** 2ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * COPYRIGHT: 3ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * Copyright (c) 2005-2006, International Business Machines Corporation and 4ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * others. All Rights Reserved. 5ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ********************************************************************/ 6ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 7ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "aliastst.h" 8ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/calendar.h" 9ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/smpdtfmt.h" 10ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/datefmt.h" 11ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/unistr.h" 12ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/coll.h" 13ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/resbund.h" 14ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include <stdio.h> 15ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include <string.h> 16ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include <stdlib.h> 17ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 18ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruconst char* _LOCALE_ALIAS[][2] = { 19ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {"in", "id"}, 20ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {"in_ID", "id_ID"}, 21ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {"iw", "he"}, 22ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {"iw_IL", "he_IL"}, 23ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {"ji", "yi"}, 24ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {"en_BU", "en_MM"}, 25ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {"en_DY", "en_BJ"}, 26ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {"en_HV", "en_BF"}, 27ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {"en_NH", "en_VU"}, 28ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {"en_RH", "en_ZW"}, 29ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {"en_TP", "en_TL"}, 30ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {"en_ZR", "en_CD"} 31ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}; 32ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 33ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruconst int _LOCALE_NUMBER = 12; 34ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 35ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid LocaleAliasTest::runIndexedTest( int32_t index, UBool exec, const char* &name, char* /*par*/ ){ 36ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru switch (index) { 37ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru TESTCASE(0, TestCalendar); 38ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru TESTCASE(1, TestDateFormat); 39ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru TESTCASE(2, TestCollation); 40ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru TESTCASE(3, TestULocale); 41ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru TESTCASE(4, TestUResourceBundle); 42ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru TESTCASE(5, TestDisplayName); 43ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru // keep the last index in sync with the condition in default: 44ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 45ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru default: 46ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (index <= 5) { // keep this in sync with the last index! 47ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru name = "(test omitted by !UCONFIG_NO_FORMATTING)"; 48ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } else { 49ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru name = ""; 50ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 51ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru break; //needed to end loop 52ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 53ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 54ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 55ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid LocaleAliasTest::TestCalendar() { 56ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#if !UCONFIG_NO_FORMATTING 57ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UErrorCode status = U_ZERO_ERROR; 58ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru for (int i=0; i<_LOCALE_NUMBER; i++) { 59ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru Locale oldLoc(_LOCALE_ALIAS[i][0]); 60ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru Locale newLoc(_LOCALE_ALIAS[i][1]); 61ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(!isLocaleAvailable(_LOCALE_ALIAS[i][1])){ 62ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru logln(UnicodeString(newLoc.getName())+" is not available. Skipping!"); 63ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru continue; 64ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 65ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru logln("\nold locale:%s new locale:%s",oldLoc.getName(),newLoc.getName()); 66ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru Calendar* c1 = Calendar::createInstance(oldLoc, status); 67ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru Calendar* c2 = Calendar::createInstance(newLoc, status); 68ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 69ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru //Test function "getLocale(ULocale.VALID_LOCALE)" 70ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const char* l1 = c1->getLocaleID(ULOC_VALID_LOCALE, status); 71ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const char* l2 = c2->getLocaleID(ULOC_VALID_LOCALE, status); 72ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (strcmp(newLoc.getName(), l1)!=0) { 73ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru errln("CalendarTest: newLoc!=l1: newLoc= "+UnicodeString(newLoc.getName()) +" l1= "+UnicodeString(l1)); 74ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 75ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (strcmp(l1, l2)!=0) { 76ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru errln("CalendarTest: l1!=l2: l1= "+UnicodeString(l1) +" l2= "+UnicodeString(l2)); 77ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 78ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(!(c1==c2)){ 79ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru errln("CalendarTest: c1!=c2. newLoc= "+UnicodeString(newLoc.getName()) +" oldLoc= "+UnicodeString(oldLoc.getName())); 80ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 81ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru logln("Calendar(getLocale) old:"+UnicodeString(l1)+" new:"+UnicodeString(l2)); 82ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru delete c1; 83ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru delete c2; 84ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 85ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#endif 86ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 87ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid LocaleAliasTest::TestDateFormat() { 88ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#if !UCONFIG_NO_FORMATTING 89ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UErrorCode status = U_ZERO_ERROR; 90ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru for (int i=0; i<_LOCALE_NUMBER; i++) { 91ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru Locale oldLoc(_LOCALE_ALIAS[i][0]); 92ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru Locale newLoc(_LOCALE_ALIAS[i][1]); 93ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(!isLocaleAvailable(_LOCALE_ALIAS[i][1])){ 94ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru logln(UnicodeString(newLoc.getName())+" is not available. Skipping!"); 95ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru continue; 96ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 97ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru logln("\nold locale:%s new locale:%s",oldLoc.getName(),newLoc.getName()); 98ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 99ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru DateFormat* df1 = DateFormat::createDateInstance(DateFormat::FULL, oldLoc); 100ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru DateFormat* df2 = DateFormat::createDateInstance(DateFormat::FULL, newLoc); 101ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 102ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru //Test function "getLocale" 103ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const char* l1 = df1->getLocaleID(ULOC_VALID_LOCALE, status); 104ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const char* l2 = df2->getLocaleID(ULOC_VALID_LOCALE, status); 105ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (strcmp(newLoc.getName(), l1)!=0) { 106ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru errln("CalendarTest: newLoc!=l1: newLoc= "+UnicodeString(newLoc.getName()) +" l1= "+UnicodeString(l1)); 107ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 108ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (strcmp(l1, l2)!=0) { 109ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru errln("TestDateFormat: l1!=l2: l1= "+UnicodeString(l1) +" l2= "+UnicodeString(l2)); 110ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 111ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(!(df1==df2)){ 112ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru errln("TestDateFormat: c1!=c2. newLoc= "+UnicodeString(newLoc.getName()) +" oldLoc= "+UnicodeString(oldLoc.getName())); 113ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 114ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru logln("DateFormat(getLocale) old:%s new:%s",l1,l2); 115ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 116ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru delete df1; 117ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru delete df2; 118ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 119ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#endif 120ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 121ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid LocaleAliasTest::TestCollation() { 122ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#if !UCONFIG_NO_COLLATION 123ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UErrorCode status = U_ZERO_ERROR; 124ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru for (int i=0; i<_LOCALE_NUMBER; i++) { 125ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru Locale oldLoc(_LOCALE_ALIAS[i][0]); 126ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru Locale newLoc(_LOCALE_ALIAS[i][1]); 127ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(!isLocaleAvailable(_LOCALE_ALIAS[i][1])){ 128ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru logln(UnicodeString(newLoc.getName())+" is not available. Skipping!"); 129ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru continue; 130ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 131ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru logln("\nold locale:%s new locale:%s",oldLoc.getName(),newLoc.getName()); 132ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 133ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru Collator* c1 = Collator::createInstance(oldLoc, status); 134ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru Collator* c2 = Collator::createInstance(newLoc, status); 135ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 136ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru Locale l1 = c1->getLocale(ULOC_VALID_LOCALE, status); 137ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru Locale l2 = c2->getLocale(ULOC_VALID_LOCALE, status); 138ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 139ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (strcmp(newLoc.getName(), l1.getName())!=0) { 140ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru errln("CalendarTest: newLoc!=l1: newLoc= "+UnicodeString(newLoc.getName()) +" l1= "+UnicodeString(l1.getName())); 141ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 142ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (strcmp(l1.getName(), l2.getName())!=0) { 143ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru errln("CollationTest: l1!=l2: l1= "+UnicodeString(l1.getName()) +" l2= "+UnicodeString(l2.getName())); 144ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 145ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(!(c1==c2)){ 146ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru errln("CollationTest: c1!=c2. newLoc= "+UnicodeString(newLoc.getName()) +" oldLoc= "+UnicodeString(oldLoc.getName())); 147ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 148ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru logln("Collator(getLocale) old:%s new:%s", l1.getName(), l2.getName()); 149ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru delete c1; 150ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru delete c2; 151ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 152ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#endif 153ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 154ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid LocaleAliasTest::TestULocale() { 155ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru for (int i=0; i<_LOCALE_NUMBER; i++) { 156ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru Locale oldLoc(_LOCALE_ALIAS[i][0]); 157ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru Locale newLoc(_LOCALE_ALIAS[i][1]); 158ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(!isLocaleAvailable(_LOCALE_ALIAS[i][1])){ 159ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru logln(UnicodeString(newLoc.getName())+" is not available. Skipping!"); 160ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru continue; 161ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 162ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru logln("\nold locale:%s new locale:%s",oldLoc.getName(),newLoc.getName()); 163ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 164ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UnicodeString name1, name2; 165ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru oldLoc.getDisplayName(name1); 166ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru newLoc.getDisplayName(name2); 167ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (name1!=name2) { 168ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru errln("DisplayNames are not equal. newLoc= "+UnicodeString(newLoc.getName()) +" oldLoc= "+UnicodeString(oldLoc.getName())); 169ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 170ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log("ULocale(getDisplayName) old:"); 171ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log(name1); 172ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log(" new:"); 173ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru logln(name2); 174ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 175ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 176ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruLocaleAliasTest::LocaleAliasTest(){ 177ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UErrorCode status = U_ZERO_ERROR; 178ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru resIndex = ures_open(NULL,"res_index", &status); 179ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_FAILURE(status)){ 180ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru errln("Could not open res_index.res. Exiting. Error: %s\n", u_errorName(status)); 181ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru resIndex=NULL; 182ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 183ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru defLocale = Locale::getDefault(); 184ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru Locale::setDefault(Locale::getUS(), status); 185ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 186ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruLocaleAliasTest::~LocaleAliasTest(){ 187ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* reset the default locale */ 188ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UErrorCode status = U_ZERO_ERROR; 189ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru Locale::setDefault(defLocale, status); 190ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ures_close(resIndex); 191ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_FAILURE(status)){ 192ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru errln("Could not reset the default locale. Exiting. Error: %s\n", u_errorName(status)); 193ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 194ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 195ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruUBool LocaleAliasTest::isLocaleAvailable(const char* loc){ 196ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(resIndex==NULL){ 197ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return FALSE; 198ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 199ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UErrorCode status = U_ZERO_ERROR; 200ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t len = 0; 201ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ures_getStringByKey(resIndex, loc,&len, &status); 202ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_FAILURE(status)){ 203ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return FALSE; 204ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 205ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return TRUE; 206ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 207ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid LocaleAliasTest::TestDisplayName() { 208ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t availableNum =0; 209ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const Locale* available = Locale::getAvailableLocales(availableNum); 210ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru for (int i=0; i<_LOCALE_NUMBER; i++) { 211ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru Locale oldLoc(_LOCALE_ALIAS[i][0]); 212ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru Locale newLoc(_LOCALE_ALIAS[i][1]); 213ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(!isLocaleAvailable(_LOCALE_ALIAS[i][1])){ 214ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru logln(UnicodeString(newLoc.getName())+" is not available. Skipping!"); 215ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru continue; 216ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 217ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru for(int j=0; j<availableNum; j++){ 218ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UnicodeString dipLocName = UnicodeString(available[j].getName()); 219ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const UnicodeString oldCountry = oldLoc.getDisplayCountry(dipLocName); 220ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const UnicodeString newCountry = newLoc.getDisplayCountry(dipLocName); 221ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const UnicodeString oldLang = oldLoc.getDisplayLanguage(dipLocName); 222ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const UnicodeString newLang = newLoc.getDisplayLanguage(dipLocName); 223ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 224ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru // is there display name for the current country ID 225ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(newCountry != newLoc.getCountry()){ 226ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(oldCountry!=newCountry){ 227ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru errln("getCountry() failed for "+ UnicodeString(oldLoc.getName()) +" oldCountry= "+ prettify(oldCountry) +" newCountry = "+prettify(newCountry)+ " in display locale "+ UnicodeString(available[j].getName())); 228ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 229ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 230ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru //there is a display name for the current lang ID 231ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(newLang != newLoc.getLanguage()){ 232ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(oldLang != newLang){ 233ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru errln("getLanguage() failed for " + UnicodeString(oldLoc.getName()) + " oldLang = "+ prettify(oldLang) +" newLang = "+prettify(newLang)+ " in display locale "+UnicodeString(available[j].getName())); 234ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 235ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 236ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 237ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 238ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 239ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid LocaleAliasTest::TestUResourceBundle() { 240ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 241ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UErrorCode status = U_ZERO_ERROR; 242ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru for (int i=0; i<_LOCALE_NUMBER; i++) { 243ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru Locale oldLoc(_LOCALE_ALIAS[i][0]); 244ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru Locale newLoc(_LOCALE_ALIAS[i][1]); 245ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(!isLocaleAvailable(_LOCALE_ALIAS[i][1])){ 246ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru logln(UnicodeString(newLoc.getName())+" is not available. Skipping!"); 247ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru continue; 248ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 249ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru logln("\nold locale:%s new locale:%s",oldLoc.getName(),newLoc.getName()); 250ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 251ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ResourceBundle* rb1 = NULL; 252ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ResourceBundle* rb2 = NULL; 253ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 254ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const char* testdatapath=loadTestData(status); 255ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 256ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UnicodeString us1("NULL"); 257ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UnicodeString us2("NULL"); 258ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru rb1 = new ResourceBundle(testdatapath, oldLoc, status); 259ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (U_FAILURE(U_ZERO_ERROR)) { 260ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 261ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } else { 262ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru us1 = rb1->getStringEx("locale", status); 263ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 264ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru rb2 = new ResourceBundle(testdatapath, newLoc, status); 265ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (U_FAILURE(U_ZERO_ERROR)){ 266ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 267ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } else { 268ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru us2 = rb2->getStringEx("locale", status); 269ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 270ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UnicodeString uNewLoc(newLoc.getName()); 271ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (us1.compare(uNewLoc)!=0 || us1.compare(us2)!=0 || status!=U_ZERO_ERROR) { 272ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 273ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 274ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log("UResourceBundle(getStringEx) old:"); 275ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log(us1); 276ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log(" new:"); 277ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru logln(us2); 278ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 279ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (rb1!=NULL) { 280ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru delete rb1; 281ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 282ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (rb2!=NULL) { 283ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru delete rb2; 284ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 285ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 286ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 287ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 288