OLD | NEW |
1 /******************************************************************** | 1 /******************************************************************** |
2 * COPYRIGHT: | 2 * COPYRIGHT: |
3 * Copyright (c) 1997-2015, International Business Machines Corporation and | 3 * Copyright (c) 1997-2015, International Business Machines Corporation and |
4 * others. All Rights Reserved. | 4 * others. All Rights Reserved. |
5 ********************************************************************/ | 5 ********************************************************************/ |
6 | 6 |
7 #include "loctest.h" | 7 #include "loctest.h" |
8 #include "unicode/decimfmt.h" | 8 #include "unicode/decimfmt.h" |
9 #include "unicode/ucurr.h" | 9 #include "unicode/ucurr.h" |
10 #include "unicode/smpdtfmt.h" | 10 #include "unicode/smpdtfmt.h" |
11 #include "unicode/dtfmtsym.h" | 11 #include "unicode/dtfmtsym.h" |
12 #include "unicode/brkiter.h" | 12 #include "unicode/brkiter.h" |
13 #include "unicode/coll.h" | 13 #include "unicode/coll.h" |
14 #include "cstring.h" | 14 #include "cstring.h" |
15 #include <stdio.h> | 15 #include <stdio.h> |
16 #include <string.h> | 16 #include <string.h> |
17 #include "putilimp.h" | 17 #include "putilimp.h" |
18 #include "unicode/ustring.h" | 18 #include "unicode/ustring.h" |
| 19 #include "hash.h" |
19 | 20 |
20 static const char* const rawData[33][8] = { | 21 static const char* const rawData[33][8] = { |
21 | 22 |
22 // language code | 23 // language code |
23 { "en", "fr", "ca", "el", "no", "it", "xx", "zh" }, | 24 { "en", "fr", "ca", "el", "no", "it", "xx", "zh" }, |
24 // script code | 25 // script code |
25 { "", "", "", "", "", "", "", "Hans" }, | 26 { "", "", "", "", "", "", "", "Hans" }, |
26 // country code | 27 // country code |
27 { "US", "FR", "ES", "GR", "NO", "", "YY", "CN" }, | 28 { "US", "FR", "ES", "GR", "NO", "", "YY", "CN" }, |
28 // variant code | 29 // variant code |
(...skipping 824 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
853 const char spotCheck1[ ][4] = { "en", "es", "fr", "de", "it", | 854 const char spotCheck1[ ][4] = { "en", "es", "fr", "de", "it", |
854 "ja", "ko", "zh", "th", "he", | 855 "ja", "ko", "zh", "th", "he", |
855 "id", "iu", "ug", "yi", "za" }; | 856 "id", "iu", "ug", "yi", "za" }; |
856 | 857 |
857 int32_t i; | 858 int32_t i; |
858 | 859 |
859 for(testCount = 0;test[testCount];testCount++) | 860 for(testCount = 0;test[testCount];testCount++) |
860 ; | 861 ; |
861 | 862 |
862 /* TODO: Change this test to be more like the cloctst version? */ | 863 /* TODO: Change this test to be more like the cloctst version? */ |
863 if (testCount != 560) | 864 if (testCount != 593) |
864 errln("Expected getISOLanguages() to return 560 languages; it returned %
d", testCount); | 865 errln("Expected getISOLanguages() to return 593 languages; it returned %
d", testCount); |
865 else { | 866 else { |
866 for (i = 0; i < 15; i++) { | 867 for (i = 0; i < 15; i++) { |
867 int32_t j; | 868 int32_t j; |
868 for (j = 0; j < testCount; j++) | 869 for (j = 0; j < testCount; j++) |
869 if (uprv_strcmp(test[j],spotCheck1[i])== 0) | 870 if (uprv_strcmp(test[j],spotCheck1[i])== 0) |
870 break; | 871 break; |
871 if (j == testCount || (uprv_strcmp(test[j],spotCheck1[i])!=0)) | 872 if (j == testCount || (uprv_strcmp(test[j],spotCheck1[i])!=0)) |
872 errln("Couldn't find " + (UnicodeString)spotCheck1[i] + " in lan
guage list."); | 873 errln("Couldn't find " + (UnicodeString)spotCheck1[i] + " in lan
guage list."); |
873 } | 874 } |
874 } | 875 } |
(...skipping 960 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1835 label, req, valid, actual); | 1836 label, req, valid, actual); |
1836 } else { | 1837 } else { |
1837 dataerrln("FAIL: %s; req=%s, valid=%s, actual=%s. Require (R %s V) and
(V %s A)", | 1838 dataerrln("FAIL: %s; req=%s, valid=%s, actual=%s. Require (R %s V) and
(V %s A)", |
1838 label, req, valid, actual, | 1839 label, req, valid, actual, |
1839 expReqValid, expValidActual); | 1840 expReqValid, expValidActual); |
1840 } | 1841 } |
1841 } | 1842 } |
1842 | 1843 |
1843 void LocaleTest::TestGetLocale(void) { | 1844 void LocaleTest::TestGetLocale(void) { |
1844 #if !UCONFIG_NO_SERVICE | 1845 #if !UCONFIG_NO_SERVICE |
1845 UErrorCode ec = U_ZERO_ERROR; | |
1846 const char *req; | 1846 const char *req; |
1847 Locale valid, actual, reqLoc; | 1847 Locale valid, actual, reqLoc; |
1848 | 1848 |
1849 // Calendar | 1849 // Calendar |
1850 #if !UCONFIG_NO_FORMATTING | 1850 #if !UCONFIG_NO_FORMATTING |
1851 req = "en_US_BROOKLYN"; | 1851 { |
1852 Calendar* cal = Calendar::createInstance(Locale::createFromName(req), ec); | 1852 UErrorCode ec = U_ZERO_ERROR; // give each resource type its own error
code |
1853 if (U_FAILURE(ec)) { | 1853 req = "en_US_BROOKLYN"; |
1854 dataerrln("FAIL: Calendar::createInstance failed - %s", u_errorName(ec))
; | 1854 Calendar* cal = Calendar::createInstance(Locale::createFromName(req), ec
); |
1855 } else { | |
1856 valid = cal->getLocale(ULOC_VALID_LOCALE, ec); | |
1857 actual = cal->getLocale(ULOC_ACTUAL_LOCALE, ec); | |
1858 if (U_FAILURE(ec)) { | 1855 if (U_FAILURE(ec)) { |
1859 errln("FAIL: Calendar::getLocale() failed"); | 1856 dataerrln("FAIL: Calendar::createInstance failed - %s", u_errorName(
ec)); |
1860 } else { | 1857 } else { |
1861 _checklocs("Calendar", req, valid, actual); | 1858 valid = cal->getLocale(ULOC_VALID_LOCALE, ec); |
| 1859 actual = cal->getLocale(ULOC_ACTUAL_LOCALE, ec); |
| 1860 if (U_FAILURE(ec)) { |
| 1861 errln("FAIL: Calendar::getLocale() failed"); |
| 1862 } else { |
| 1863 _checklocs("Calendar", req, valid, actual); |
| 1864 } |
| 1865 /* Make sure that it fails correctly */ |
| 1866 ec = U_FILE_ACCESS_ERROR; |
| 1867 if (cal->getLocale(ULOC_VALID_LOCALE, ec).getName()[0] != 0) { |
| 1868 errln("FAIL: Calendar::getLocale() failed to fail correctly. It
should have returned \"\""); |
| 1869 } |
| 1870 ec = U_ZERO_ERROR; |
1862 } | 1871 } |
1863 /* Make sure that it fails correctly */ | 1872 delete cal; |
1864 ec = U_FILE_ACCESS_ERROR; | |
1865 if (cal->getLocale(ULOC_VALID_LOCALE, ec).getName()[0] != 0) { | |
1866 errln("FAIL: Calendar::getLocale() failed to fail correctly. It shou
ld have returned \"\""); | |
1867 } | |
1868 ec = U_ZERO_ERROR; | |
1869 } | 1873 } |
1870 delete cal; | |
1871 #endif | 1874 #endif |
1872 | 1875 |
1873 // DecimalFormat, DecimalFormatSymbols | 1876 // DecimalFormat, DecimalFormatSymbols |
1874 #if !UCONFIG_NO_FORMATTING | 1877 #if !UCONFIG_NO_FORMATTING |
1875 req = "fr_FR_NICE"; | 1878 { |
1876 NumberFormat* nf = NumberFormat::createInstance(Locale::createFromName(req),
ec); | 1879 UErrorCode ec = U_ZERO_ERROR; // give each resource type its own error
code |
1877 if (U_FAILURE(ec)) { | 1880 req = "fr_FR_NICE"; |
1878 dataerrln("FAIL: NumberFormat::createInstance failed - %s", u_errorName(
ec)); | 1881 NumberFormat* nf = NumberFormat::createInstance(Locale::createFromName(r
eq), ec); |
1879 } else { | 1882 if (U_FAILURE(ec)) { |
1880 DecimalFormat* dec = dynamic_cast<DecimalFormat*>(nf); | 1883 dataerrln("FAIL: NumberFormat::createInstance failed - %s", u_errorN
ame(ec)); |
1881 if (dec == NULL) { | 1884 } else { |
1882 errln("FAIL: NumberFormat::createInstance does not return a DecimalF
ormat"); | 1885 DecimalFormat* dec = dynamic_cast<DecimalFormat*>(nf); |
1883 return; | 1886 if (dec == NULL) { |
| 1887 errln("FAIL: NumberFormat::createInstance does not return a Deci
malFormat"); |
| 1888 return; |
| 1889 } |
| 1890 valid = dec->getLocale(ULOC_VALID_LOCALE, ec); |
| 1891 actual = dec->getLocale(ULOC_ACTUAL_LOCALE, ec); |
| 1892 if (U_FAILURE(ec)) { |
| 1893 errln("FAIL: DecimalFormat::getLocale() failed"); |
| 1894 } else { |
| 1895 _checklocs("DecimalFormat", req, valid, actual); |
| 1896 } |
| 1897 |
| 1898 const DecimalFormatSymbols* sym = dec->getDecimalFormatSymbols(); |
| 1899 if (sym == NULL) { |
| 1900 errln("FAIL: getDecimalFormatSymbols returned NULL"); |
| 1901 return; |
| 1902 } |
| 1903 valid = sym->getLocale(ULOC_VALID_LOCALE, ec); |
| 1904 actual = sym->getLocale(ULOC_ACTUAL_LOCALE, ec); |
| 1905 if (U_FAILURE(ec)) { |
| 1906 errln("FAIL: DecimalFormatSymbols::getLocale() failed"); |
| 1907 } else { |
| 1908 _checklocs("DecimalFormatSymbols", req, valid, actual); |
| 1909 } |
1884 } | 1910 } |
1885 valid = dec->getLocale(ULOC_VALID_LOCALE, ec); | 1911 delete nf; |
1886 actual = dec->getLocale(ULOC_ACTUAL_LOCALE, ec); | |
1887 if (U_FAILURE(ec)) { | |
1888 errln("FAIL: DecimalFormat::getLocale() failed"); | |
1889 } else { | |
1890 _checklocs("DecimalFormat", req, valid, actual); | |
1891 } | |
1892 | |
1893 const DecimalFormatSymbols* sym = dec->getDecimalFormatSymbols(); | |
1894 if (sym == NULL) { | |
1895 errln("FAIL: getDecimalFormatSymbols returned NULL"); | |
1896 return; | |
1897 } | |
1898 valid = sym->getLocale(ULOC_VALID_LOCALE, ec); | |
1899 actual = sym->getLocale(ULOC_ACTUAL_LOCALE, ec); | |
1900 if (U_FAILURE(ec)) { | |
1901 errln("FAIL: DecimalFormatSymbols::getLocale() failed"); | |
1902 } else { | |
1903 _checklocs("DecimalFormatSymbols", req, valid, actual); | |
1904 } | |
1905 } | 1912 } |
1906 delete nf; | |
1907 #endif | 1913 #endif |
1908 | 1914 |
1909 // DateFormat, DateFormatSymbols | 1915 // DateFormat, DateFormatSymbols |
1910 #if !UCONFIG_NO_FORMATTING | 1916 #if !UCONFIG_NO_FORMATTING |
1911 req = "de_CH_LUCERNE"; | 1917 { |
1912 DateFormat* df = | 1918 UErrorCode ec = U_ZERO_ERROR; // give each resource type its own error
code |
1913 DateFormat::createDateInstance(DateFormat::kDefault, | 1919 req = "de_CH_LUCERNE"; |
1914 Locale::createFromName(req)); | 1920 DateFormat* df = |
1915 if (df == 0){ | 1921 DateFormat::createDateInstance(DateFormat::kDefault, |
1916 dataerrln("Error calling DateFormat::createDateInstance()"); | 1922 Locale::createFromName(req)); |
1917 } else { | 1923 if (df == 0){ |
1918 SimpleDateFormat* dat = dynamic_cast<SimpleDateFormat*>(df); | 1924 dataerrln("Error calling DateFormat::createDateInstance()"); |
1919 if (dat == NULL) { | 1925 } else { |
1920 errln("FAIL: DateFormat::createInstance does not return a SimpleDate
Format"); | 1926 SimpleDateFormat* dat = dynamic_cast<SimpleDateFormat*>(df); |
1921 return; | 1927 if (dat == NULL) { |
| 1928 errln("FAIL: DateFormat::createInstance does not return a Simple
DateFormat"); |
| 1929 return; |
| 1930 } |
| 1931 valid = dat->getLocale(ULOC_VALID_LOCALE, ec); |
| 1932 actual = dat->getLocale(ULOC_ACTUAL_LOCALE, ec); |
| 1933 if (U_FAILURE(ec)) { |
| 1934 errln("FAIL: SimpleDateFormat::getLocale() failed"); |
| 1935 } else { |
| 1936 _checklocs("SimpleDateFormat", req, valid, actual); |
| 1937 } |
| 1938 |
| 1939 const DateFormatSymbols* sym = dat->getDateFormatSymbols(); |
| 1940 if (sym == NULL) { |
| 1941 errln("FAIL: getDateFormatSymbols returned NULL"); |
| 1942 return; |
| 1943 } |
| 1944 valid = sym->getLocale(ULOC_VALID_LOCALE, ec); |
| 1945 actual = sym->getLocale(ULOC_ACTUAL_LOCALE, ec); |
| 1946 if (U_FAILURE(ec)) { |
| 1947 errln("FAIL: DateFormatSymbols::getLocale() failed"); |
| 1948 } else { |
| 1949 _checklocs("DateFormatSymbols", req, valid, actual); |
| 1950 } |
1922 } | 1951 } |
1923 valid = dat->getLocale(ULOC_VALID_LOCALE, ec); | 1952 delete df; |
1924 actual = dat->getLocale(ULOC_ACTUAL_LOCALE, ec); | |
1925 if (U_FAILURE(ec)) { | |
1926 errln("FAIL: SimpleDateFormat::getLocale() failed"); | |
1927 } else { | |
1928 _checklocs("SimpleDateFormat", req, valid, actual); | |
1929 } | |
1930 | |
1931 const DateFormatSymbols* sym = dat->getDateFormatSymbols(); | |
1932 if (sym == NULL) { | |
1933 errln("FAIL: getDateFormatSymbols returned NULL"); | |
1934 return; | |
1935 } | |
1936 valid = sym->getLocale(ULOC_VALID_LOCALE, ec); | |
1937 actual = sym->getLocale(ULOC_ACTUAL_LOCALE, ec); | |
1938 if (U_FAILURE(ec)) { | |
1939 errln("FAIL: DateFormatSymbols::getLocale() failed"); | |
1940 } else { | |
1941 _checklocs("DateFormatSymbols", req, valid, actual); | |
1942 } | |
1943 } | 1953 } |
1944 delete df; | |
1945 #endif | 1954 #endif |
1946 | 1955 |
1947 // BreakIterator | 1956 // BreakIterator |
1948 #if !UCONFIG_NO_BREAK_ITERATION | 1957 #if !UCONFIG_NO_BREAK_ITERATION |
1949 req = "es_ES_BARCELONA"; | 1958 { |
1950 reqLoc = Locale::createFromName(req); | 1959 UErrorCode ec = U_ZERO_ERROR; // give each resource type its own error
code |
1951 BreakIterator* brk = BreakIterator::createWordInstance(reqLoc, ec); | 1960 req = "es_ES_BARCELONA"; |
1952 if (U_FAILURE(ec)) { | 1961 reqLoc = Locale::createFromName(req); |
1953 dataerrln("FAIL: BreakIterator::createWordInstance failed - %s", u_error
Name(ec)); | 1962 BreakIterator* brk = BreakIterator::createWordInstance(reqLoc, ec); |
1954 } else { | |
1955 valid = brk->getLocale(ULOC_VALID_LOCALE, ec); | |
1956 actual = brk->getLocale(ULOC_ACTUAL_LOCALE, ec); | |
1957 if (U_FAILURE(ec)) { | 1963 if (U_FAILURE(ec)) { |
1958 errln("FAIL: BreakIterator::getLocale() failed"); | 1964 dataerrln("FAIL: BreakIterator::createWordInstance failed - %s", u_e
rrorName(ec)); |
1959 } else { | 1965 } else { |
1960 _checklocs("BreakIterator", req, valid, actual); | 1966 valid = brk->getLocale(ULOC_VALID_LOCALE, ec); |
1961 } | 1967 actual = brk->getLocale(ULOC_ACTUAL_LOCALE, ec); |
| 1968 if (U_FAILURE(ec)) { |
| 1969 errln("FAIL: BreakIterator::getLocale() failed"); |
| 1970 } else { |
| 1971 _checklocs("BreakIterator", req, valid, actual); |
| 1972 } |
1962 | 1973 |
1963 // After registering something, the behavior should be different | 1974 // After registering something, the behavior should be different |
1964 URegistryKey key = BreakIterator::registerInstance(brk, reqLoc, UBRK_WOR
D, ec); | 1975 URegistryKey key = BreakIterator::registerInstance(brk, reqLoc, UBRK
_WORD, ec); |
1965 brk = 0; // registerInstance adopts | 1976 brk = 0; // registerInstance adopts |
1966 if (U_FAILURE(ec)) { | 1977 if (U_FAILURE(ec)) { |
1967 errln("FAIL: BreakIterator::registerInstance() failed"); | 1978 errln("FAIL: BreakIterator::registerInstance() failed"); |
1968 } else { | 1979 } else { |
| 1980 brk = BreakIterator::createWordInstance(reqLoc, ec); |
| 1981 if (U_FAILURE(ec)) { |
| 1982 errln("FAIL: BreakIterator::createWordInstance failed"); |
| 1983 } else { |
| 1984 valid = brk->getLocale(ULOC_VALID_LOCALE, ec); |
| 1985 actual = brk->getLocale(ULOC_ACTUAL_LOCALE, ec); |
| 1986 if (U_FAILURE(ec)) { |
| 1987 errln("FAIL: BreakIterator::getLocale() failed"); |
| 1988 } else { |
| 1989 // N.B.: now expect valid==actual==req |
| 1990 _checklocs("BreakIterator(registered)", |
| 1991 req, valid, actual, "eq", "eq"); |
| 1992 } |
| 1993 } |
| 1994 // No matter what, unregister |
| 1995 BreakIterator::unregister(key, ec); |
| 1996 if (U_FAILURE(ec)) { |
| 1997 errln("FAIL: BreakIterator::unregister() failed"); |
| 1998 } |
| 1999 delete brk; |
| 2000 brk = 0; |
| 2001 } |
| 2002 |
| 2003 // After unregistering, should behave normally again |
1969 brk = BreakIterator::createWordInstance(reqLoc, ec); | 2004 brk = BreakIterator::createWordInstance(reqLoc, ec); |
1970 if (U_FAILURE(ec)) { | 2005 if (U_FAILURE(ec)) { |
1971 errln("FAIL: BreakIterator::createWordInstance failed"); | 2006 errln("FAIL: BreakIterator::createWordInstance failed"); |
1972 } else { | 2007 } else { |
1973 valid = brk->getLocale(ULOC_VALID_LOCALE, ec); | 2008 valid = brk->getLocale(ULOC_VALID_LOCALE, ec); |
1974 actual = brk->getLocale(ULOC_ACTUAL_LOCALE, ec); | 2009 actual = brk->getLocale(ULOC_ACTUAL_LOCALE, ec); |
1975 if (U_FAILURE(ec)) { | 2010 if (U_FAILURE(ec)) { |
1976 errln("FAIL: BreakIterator::getLocale() failed"); | 2011 errln("FAIL: BreakIterator::getLocale() failed"); |
1977 } else { | 2012 } else { |
1978 // N.B.: now expect valid==actual==req | 2013 _checklocs("BreakIterator(unregistered)", req, valid, actual
); |
1979 _checklocs("BreakIterator(registered)", | |
1980 req, valid, actual, "eq", "eq"); | |
1981 } | 2014 } |
1982 } | 2015 } |
1983 // No matter what, unregister | |
1984 BreakIterator::unregister(key, ec); | |
1985 if (U_FAILURE(ec)) { | |
1986 errln("FAIL: BreakIterator::unregister() failed"); | |
1987 } | |
1988 delete brk; | |
1989 brk = 0; | |
1990 } | 2016 } |
1991 | 2017 delete brk; |
1992 // After unregistering, should behave normally again | |
1993 brk = BreakIterator::createWordInstance(reqLoc, ec); | |
1994 if (U_FAILURE(ec)) { | |
1995 errln("FAIL: BreakIterator::createWordInstance failed"); | |
1996 } else { | |
1997 valid = brk->getLocale(ULOC_VALID_LOCALE, ec); | |
1998 actual = brk->getLocale(ULOC_ACTUAL_LOCALE, ec); | |
1999 if (U_FAILURE(ec)) { | |
2000 errln("FAIL: BreakIterator::getLocale() failed"); | |
2001 } else { | |
2002 _checklocs("BreakIterator(unregistered)", req, valid, actual); | |
2003 } | |
2004 } | |
2005 } | 2018 } |
2006 delete brk; | |
2007 #endif | 2019 #endif |
2008 | 2020 |
2009 // Collator | 2021 // Collator |
2010 #if !UCONFIG_NO_COLLATION | 2022 #if !UCONFIG_NO_COLLATION |
2011 req = "hi_IN_BHOPAL"; | 2023 { |
2012 reqLoc = Locale::createFromName(req); | 2024 UErrorCode ec = U_ZERO_ERROR; // give each resource type its own error
code |
2013 Collator* coll = Collator::createInstance(reqLoc, ec); | 2025 |
2014 if (U_FAILURE(ec)) { | 2026 checkRegisteredCollators(NULL); // Don't expect any extras |
2015 dataerrln("FAIL: Collator::createInstance failed - %s", u_errorName(ec))
; | 2027 |
2016 } else { | 2028 req = "hi_IN_BHOPAL"; |
2017 valid = coll->getLocale(ULOC_VALID_LOCALE, ec); | 2029 reqLoc = Locale::createFromName(req); |
2018 actual = coll->getLocale(ULOC_ACTUAL_LOCALE, ec); | 2030 Collator* coll = Collator::createInstance(reqLoc, ec); |
2019 if (U_FAILURE(ec)) { | 2031 if (U_FAILURE(ec)) { |
2020 errln("FAIL: Collator::getLocale() failed"); | 2032 dataerrln("FAIL: Collator::createInstance failed - %s", u_errorName(
ec)); |
2021 } else { | 2033 } else { |
2022 _checklocs("Collator", req, valid, actual); | 2034 valid = coll->getLocale(ULOC_VALID_LOCALE, ec); |
2023 } | 2035 actual = coll->getLocale(ULOC_ACTUAL_LOCALE, ec); |
| 2036 if (U_FAILURE(ec)) { |
| 2037 errln("FAIL: Collator::getLocale() failed"); |
| 2038 } else { |
| 2039 _checklocs("Collator", req, valid, actual); |
| 2040 } |
2024 | 2041 |
2025 // After registering something, the behavior should be different | 2042 // After registering something, the behavior should be different |
2026 URegistryKey key = Collator::registerInstance(coll, reqLoc, ec); | 2043 URegistryKey key = Collator::registerInstance(coll, reqLoc, ec); |
2027 coll = 0; // registerInstance adopts | 2044 coll = 0; // registerInstance adopts |
2028 if (U_FAILURE(ec)) { | 2045 if (U_FAILURE(ec)) { |
2029 errln("FAIL: Collator::registerInstance() failed"); | 2046 errln("FAIL: Collator::registerInstance() failed"); |
2030 } else { | 2047 } else { |
| 2048 coll = Collator::createInstance(reqLoc, ec); |
| 2049 if (U_FAILURE(ec)) { |
| 2050 errln("FAIL: Collator::createWordInstance failed"); |
| 2051 } else { |
| 2052 valid = coll->getLocale(ULOC_VALID_LOCALE, ec); |
| 2053 actual = coll->getLocale(ULOC_ACTUAL_LOCALE, ec); |
| 2054 if (U_FAILURE(ec)) { |
| 2055 errln("FAIL: Collator::getLocale() failed"); |
| 2056 } else { |
| 2057 // N.B.: now expect valid==actual==req |
| 2058 _checklocs("Collator(registered)", |
| 2059 req, valid, actual, "eq", "eq"); |
| 2060 } |
| 2061 } |
| 2062 checkRegisteredCollators(req); // include hi_IN_BHOPAL |
| 2063 |
| 2064 // No matter what, unregister |
| 2065 Collator::unregister(key, ec); |
| 2066 if (U_FAILURE(ec)) { |
| 2067 errln("FAIL: Collator::unregister() failed"); |
| 2068 } |
| 2069 delete coll; |
| 2070 coll = 0; |
| 2071 } |
| 2072 |
| 2073 // After unregistering, should behave normally again |
2031 coll = Collator::createInstance(reqLoc, ec); | 2074 coll = Collator::createInstance(reqLoc, ec); |
2032 if (U_FAILURE(ec)) { | 2075 if (U_FAILURE(ec)) { |
2033 errln("FAIL: Collator::createWordInstance failed"); | 2076 errln("FAIL: Collator::createInstance failed"); |
2034 } else { | 2077 } else { |
2035 valid = coll->getLocale(ULOC_VALID_LOCALE, ec); | 2078 valid = coll->getLocale(ULOC_VALID_LOCALE, ec); |
2036 actual = coll->getLocale(ULOC_ACTUAL_LOCALE, ec); | 2079 actual = coll->getLocale(ULOC_ACTUAL_LOCALE, ec); |
2037 if (U_FAILURE(ec)) { | 2080 if (U_FAILURE(ec)) { |
2038 errln("FAIL: Collator::getLocale() failed"); | 2081 errln("FAIL: Collator::getLocale() failed"); |
2039 } else { | 2082 } else { |
2040 // N.B.: now expect valid==actual==req | 2083 _checklocs("Collator(unregistered)", req, valid, actual); |
2041 _checklocs("Collator(registered)", | |
2042 req, valid, actual, "eq", "eq"); | |
2043 } | 2084 } |
2044 } | 2085 } |
2045 // No matter what, unregister | |
2046 Collator::unregister(key, ec); | |
2047 if (U_FAILURE(ec)) { | |
2048 errln("FAIL: Collator::unregister() failed"); | |
2049 } | |
2050 delete coll; | |
2051 coll = 0; | |
2052 } | 2086 } |
| 2087 delete coll; |
2053 | 2088 |
2054 // After unregistering, should behave normally again | 2089 checkRegisteredCollators(NULL); // extra should be gone again |
2055 coll = Collator::createInstance(reqLoc, ec); | |
2056 if (U_FAILURE(ec)) { | |
2057 errln("FAIL: Collator::createInstance failed"); | |
2058 } else { | |
2059 valid = coll->getLocale(ULOC_VALID_LOCALE, ec); | |
2060 actual = coll->getLocale(ULOC_ACTUAL_LOCALE, ec); | |
2061 if (U_FAILURE(ec)) { | |
2062 errln("FAIL: Collator::getLocale() failed"); | |
2063 } else { | |
2064 _checklocs("Collator(unregistered)", req, valid, actual); | |
2065 } | |
2066 } | |
2067 } | 2090 } |
2068 delete coll; | |
2069 #endif | 2091 #endif |
2070 #endif | 2092 #endif |
2071 } | 2093 } |
2072 | 2094 |
| 2095 #if !UCONFIG_NO_COLLATION |
| 2096 /** |
| 2097 * Compare Collator::getAvailableLocales(int) [ "old", returning an array ] |
| 2098 * with Collator::getAvailableLocales() [ "new", returning a StringEnumera
tion ] |
| 2099 * These should be identical (check their API docs) EXCEPT that |
| 2100 * if expectExtra is non-NULL, it will be in the "new" array but not "old". |
| 2101 * Does not return any status but calls errln on error. |
| 2102 * @param expectExtra an extra locale, will be in "new" but not "old". Or NULL. |
| 2103 */ |
| 2104 void LocaleTest::checkRegisteredCollators(const char *expectExtra) { |
| 2105 UErrorCode status = U_ZERO_ERROR; |
| 2106 int32_t count1=0,count2=0; |
| 2107 Hashtable oldHash(status); |
| 2108 Hashtable newHash(status); |
| 2109 TEST_ASSERT_STATUS(status); |
| 2110 |
| 2111 UnicodeString expectStr(expectExtra?expectExtra:"n/a", ""); |
| 2112 |
| 2113 // the 'old' list (non enumeration) |
| 2114 const Locale* oldList = Collator::getAvailableLocales(count1); |
| 2115 if(oldList == NULL) { |
| 2116 dataerrln("Error: Collator::getAvailableLocales(count) returned NULL"); |
| 2117 return; |
| 2118 } |
| 2119 |
| 2120 // the 'new' list (enumeration) |
| 2121 LocalPointer<StringEnumeration> newEnum(Collator::getAvailableLocales()); |
| 2122 if(newEnum.isNull()) { |
| 2123 errln("Error: collator::getAvailableLocales() returned NULL"); |
| 2124 return; |
| 2125 } |
| 2126 |
| 2127 // OK. Let's add all of the OLD |
| 2128 // then check for any in the NEW not in OLD |
| 2129 // then check for any in OLD not in NEW. |
| 2130 |
| 2131 // 1. add all of OLD |
| 2132 for(int32_t i=0;i<count1;i++) { |
| 2133 const UnicodeString key(oldList[i].getName(), ""); |
| 2134 int32_t oldI = oldHash.puti(key, 1, status); |
| 2135 if( oldI == 1 ){ |
| 2136 errln("Error: duplicate key %s in Collator::getAvailableLocales(coun
t) list.\n", |
| 2137 oldList[i].getName()); |
| 2138 return; |
| 2139 } |
| 2140 if(expectExtra != NULL && !strcmp(expectExtra, oldList[i].getName())) { |
| 2141 errln("Inexplicably, Collator::getAvailableCollators(count) had regi
stered collator %s. This shouldn't happen, so I am going to consider it an error
.\n", expectExtra); |
| 2142 } |
| 2143 } |
| 2144 |
| 2145 // 2. add all of NEW |
| 2146 const UnicodeString *locStr; |
| 2147 UBool foundExpected = FALSE; |
| 2148 while((locStr = newEnum->snext(status)) && U_SUCCESS(status)) { |
| 2149 count2++; |
| 2150 |
| 2151 if(expectExtra != NULL && expectStr == *locStr) { |
| 2152 foundExpected = TRUE; |
| 2153 logln(UnicodeString("Found expected registered collator: ","") + exp
ectStr); |
| 2154 } |
| 2155 (void)foundExpected; // Hush unused variable compiler warning. |
| 2156 |
| 2157 if( oldHash.geti(*locStr) == 0 ) { |
| 2158 if(expectExtra != NULL && expectStr==*locStr) { |
| 2159 logln(UnicodeString("As expected, Collator::getAvailableLocales(
count) is missing registered collator ") + expectStr); |
| 2160 } else { |
| 2161 errln(UnicodeString("Error: Collator::getAvailableLocales(count)
is missing: ","") |
| 2162 + *locStr); |
| 2163 } |
| 2164 } |
| 2165 newHash.puti(*locStr, 1, status); |
| 2166 } |
| 2167 |
| 2168 // 3. check all of OLD again |
| 2169 for(int32_t i=0;i<count1;i++) { |
| 2170 const UnicodeString key(oldList[i].getName(), ""); |
| 2171 int32_t newI = newHash.geti(key); |
| 2172 if(newI == 0) { |
| 2173 errln(UnicodeString("Error: Collator::getAvailableLocales() is missi
ng: ","") |
| 2174 + key); |
| 2175 } |
| 2176 } |
| 2177 |
| 2178 int32_t expectCount2 = count1; |
| 2179 if(expectExtra != NULL) { |
| 2180 expectCount2 ++; // if an extra item registered, bump the expect count |
| 2181 } |
| 2182 |
| 2183 assertEquals("Collator::getAvail() count", expectCount2, count2); |
| 2184 } |
| 2185 #endif |
| 2186 |
| 2187 |
| 2188 |
2073 void LocaleTest::TestVariantWithOutCountry(void) { | 2189 void LocaleTest::TestVariantWithOutCountry(void) { |
2074 Locale loc("en","","POSIX"); | 2190 Locale loc("en","","POSIX"); |
2075 if (0 != strcmp(loc.getVariant(), "POSIX")) { | 2191 if (0 != strcmp(loc.getVariant(), "POSIX")) { |
2076 errln("FAIL: en__POSIX didn't get parsed correctly - name is %s - expect
ed %s got %s", loc.getName(), "POSIX", loc.getVariant()); | 2192 errln("FAIL: en__POSIX didn't get parsed correctly - name is %s - expect
ed %s got %s", loc.getName(), "POSIX", loc.getVariant()); |
2077 } | 2193 } |
2078 Locale loc2("en","","FOUR"); | 2194 Locale loc2("en","","FOUR"); |
2079 if (0 != strcmp(loc2.getVariant(), "FOUR")) { | 2195 if (0 != strcmp(loc2.getVariant(), "FOUR")) { |
2080 errln("FAIL: en__FOUR didn't get parsed correctly - name is %s - expecte
d %s got %s", loc2.getName(), "FOUR", loc2.getVariant()); | 2196 errln("FAIL: en__FOUR didn't get parsed correctly - name is %s - expecte
d %s got %s", loc2.getName(), "FOUR", loc2.getVariant()); |
2081 } | 2197 } |
2082 Locale loc3("en","Latn","","FOUR"); | 2198 Locale loc3("en","Latn","","FOUR"); |
(...skipping 489 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2572 const Locale *localeList = Locale::getAvailableLocales(numLocales); | 2688 const Locale *localeList = Locale::getAvailableLocales(numLocales); |
2573 for (int localeIndex = 0; localeIndex < numLocales; localeIndex++) { | 2689 for (int localeIndex = 0; localeIndex < numLocales; localeIndex++) { |
2574 const Locale &loc = localeList[localeIndex]; | 2690 const Locale &loc = localeList[localeIndex]; |
2575 if (strncmp(loc.getName(), loc.getBaseName(), strlen(loc.getBaseName()))
) { | 2691 if (strncmp(loc.getName(), loc.getBaseName(), strlen(loc.getBaseName()))
) { |
2576 errln("%s:%d loc.getName=\"%s\"; loc.getBaseName=\"%s\"", | 2692 errln("%s:%d loc.getName=\"%s\"; loc.getBaseName=\"%s\"", |
2577 __FILE__, __LINE__, loc.getName(), loc.getBaseName()); | 2693 __FILE__, __LINE__, loc.getName(), loc.getBaseName()); |
2578 break; | 2694 break; |
2579 } | 2695 } |
2580 } | 2696 } |
2581 } | 2697 } |
OLD | NEW |