ICU-12590

X-SVN-Rev: 39279
This commit is contained in:
Norbert Runge 2016-09-19 16:23:26 +00:00
parent a7f9741de4
commit aecdefedd8
5 changed files with 234 additions and 1 deletions

View File

@ -1353,6 +1353,43 @@ public class DateIntervalFormatTest extends com.ibm.icu.dev.test.TestFmwk {
}
}
@Test
public void testGetInstance_String_DateIntervalInfo() {
DateIntervalInfo dateIntervalInfo = new DateIntervalInfo(new ULocale("ca"));
DateIntervalFormat dateIntervalFormat = DateIntervalFormat.getInstance(
DateFormat.YEAR_MONTH, Locale.ENGLISH, dateIntervalInfo);
Calendar from = Calendar.getInstance();
from.set(2000, Calendar.JANUARY, 1, 12, 0);
Calendar to = Calendar.getInstance();
to.set(2001, Calendar.FEBRUARY, 1, 12, 0);
DateInterval interval = new DateInterval(from.getTimeInMillis(), to.getTimeInMillis());
dateIntervalFormat.setTimeZone(from.getTimeZone());
// Month names are default (English), format is Catalan
assertEquals("Wrong date interval",
"January de 2000 February de 2001", dateIntervalFormat.format(interval));
}
@Test
public void testGetInstance_String_Locale_DateIntervalInfo() {
DateIntervalInfo dateIntervalInfo = new DateIntervalInfo(new ULocale("ca"));
DateIntervalFormat dateIntervalFormat = DateIntervalFormat.getInstance(
DateFormat.YEAR_MONTH, Locale.GERMAN, dateIntervalInfo);
Calendar from = Calendar.getInstance();
from.set(2000, Calendar.JANUARY, 1, 12, 0);
Calendar to = Calendar.getInstance();
to.set(2001, Calendar.FEBRUARY, 1, 12, 0);
DateInterval interval = new DateInterval(from.getTimeInMillis(), to.getTimeInMillis());
dateIntervalFormat.setTimeZone(from.getTimeZone());
// Month names are German, format is Catalan
assertEquals("Wrong date interval",
"Januar de 2000 Februar de 2001", dateIntervalFormat.format(interval));
}
@Test(expected = UnsupportedOperationException.class)
public void testParseObject_notSupported() throws ParseException {
DateIntervalFormat.getInstance(DateFormat.YEAR_MONTH).parseObject("");
}
@Test
public void TestTicket9919GetInstance() {
// Creating a DateIntervalFormat with a custom DateIntervalInfo

View File

@ -2979,7 +2979,7 @@ public final class UCharacterTest extends TestFmwk
}
/*
* The following method tests
* The following methods test
* public static String toTitleCase(Locale locale, String str, BreakIterator breakiter)
*/
@Test
@ -3002,6 +3002,19 @@ public final class UCharacterTest extends TestFmwk
// TODO: Tests when "if(titleLimit<index)" is false
// TODO: Tests when "else if((nc=iter.nextCaseMapCP())>=0)" is false
}
@Test
public void testToTitleCase_Locale_String_BreakIterator_I() {
String titleCase = UCharacter.toTitleCase(Locale.forLanguageTag("nl"), "ijsland", null,
UCharacter.FOLD_CASE_DEFAULT);
assertEquals("Wrong title casing", "IJsland", titleCase);
}
@Test
public void testToTitleCase_String_BreakIterator_en() {
String titleCase = UCharacter.toTitleCase(Locale.forLanguageTag("en"), "ijsland", null);
assertEquals("Wrong title casing", "Ijsland", titleCase);
}
/*
* The following method tests
* public static String toUpperCase(ULocale locale, String str)
@ -3554,4 +3567,17 @@ public final class UCharacterTest extends TestFmwk
if(us.isFrozen() != true)
errln("Unicode.isFrozen() was suppose to return true.");
}
/* Tests the methods
* public static String getNameAlias() and
* public static String getCharFromNameAlias()
*/
@Test
public void testNameAliasing() {
int input = '\u01a2';
String alias = UCharacter.getNameAlias(input);
assertEquals("Wrong name alias", "LATIN CAPITAL LETTER GHA", alias);
int output = UCharacter.getCharFromNameAlias(alias);
assertEquals("alias for '" + input + "'", input, output);
}
}

View File

@ -13,6 +13,7 @@ import java.text.ParsePosition;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
@ -2705,4 +2706,37 @@ public class UnicodeSetTest extends TestFmwk {
++i;
}
}
@Test
public void testAddAll_CharacterSequences() {
UnicodeSet unicodeSet = new UnicodeSet();
unicodeSet.addAll("a", "b");
assertEquals("Wrong UnicodeSet pattern", "[ab]", unicodeSet.toPattern(true));
unicodeSet.addAll("b", "x");
assertEquals("Wrong UnicodeSet pattern", "[abx]", unicodeSet.toPattern(true));
unicodeSet.addAll(new CharSequence[]{new StringBuilder("foo"), new StringBuffer("bar")});
assertEquals("Wrong UnicodeSet pattern", "[abx{bar}{foo}]", unicodeSet.toPattern(true));
}
@Test
public void testCompareTo() {
Set<String> test_set = Collections.emptySet();
assertEquals("UnicodeSet not empty", 0, UnicodeSet.EMPTY.compareTo(test_set));
assertEquals("UnicodeSet comparison wrong",
0, UnicodeSet.fromAll("a").compareTo(Collections.singleton("a")));
// Longer is bigger
assertTrue("UnicodeSet is empty",
UnicodeSet.ALL_CODE_POINTS.compareTo(test_set) > 0);
assertTrue("UnicodeSet not empty",
UnicodeSet.EMPTY.compareTo(Collections.singleton("a")) < 0);
// Equal length compares on first difference.
assertTrue("UnicodeSet comparison wrong",
UnicodeSet.fromAll("a").compareTo(Collections.singleton("b")) < 0);
assertTrue("UnicodeSet comparison wrong",
UnicodeSet.fromAll("ab").compareTo(Arrays.asList("a", "c")) < 0);
assertTrue("UnicodeSet comparison wrong",
UnicodeSet.fromAll("b").compareTo(Collections.singleton("a")) > 0);
}
}

View File

@ -200,6 +200,19 @@ public class CurrencyTest extends TestFmwk {
// TODO add more tests later
}
@Test
public void testGetName_Locale_Int_String_BooleanArray() {
Currency currency = Currency.getInstance(ULocale.CHINA);
boolean[] isChoiceFormat = new boolean[1];
int nameStyle = Currency.LONG_NAME;
String pluralCount = "";
String ulocaleName =
currency.getName(ULocale.CANADA, nameStyle, pluralCount, isChoiceFormat);
assertEquals("currency name mismatch", "Chinese Yuan", ulocaleName);
String localeName = currency.getName(Locale.CANADA, nameStyle, pluralCount, isChoiceFormat);
assertEquals("currency name mismatch", ulocaleName, localeName);
}
@Test
public void TestCoverage() {
Currency usd = Currency.getInstance("USD");
@ -781,4 +794,30 @@ public class CurrencyTest extends TestFmwk {
public void TestCurrencyInfoCtor() {
new CurrencyMetaInfo.CurrencyInfo("region", "code", 0, 0, 1);
}
/**
* Test cases for rounding and fractions.
*/
@Test
public void testGetDefaultFractionDigits_CurrencyUsage() {
Currency currency = Currency.getInstance(ULocale.CHINA);
int cashFractionDigits = currency.getDefaultFractionDigits(Currency.CurrencyUsage.CASH);
assertEquals("number of digits in fraction incorrect", 2, cashFractionDigits);
}
@Test
public void testGetRoundingIncrement() {
Currency currency = Currency.getInstance(ULocale.JAPAN);
// It appears as though this always returns 0 irrespective of the currency.
double roundingIncrement = currency.getRoundingIncrement();
assertEquals("Rounding increment not zero", 0.0, roundingIncrement, 0.0);
}
@Test
public void testGetRoundingIncrement_CurrencyUsage() {
Currency currency = Currency.getInstance(ULocale.JAPAN);
// It appears as though this always returns 0 irrespective of the currency or usage.
double roundingIncrement = currency.getRoundingIncrement(Currency.CurrencyUsage.CASH);
// TODO: replace the JUnit import with TestFmwk assertEquals.
assertEquals("Rounding increment not zero", 0.0, roundingIncrement, 0.0);
}
}

View File

@ -8,6 +8,7 @@
*/
package com.ibm.icu.dev.test.localespi;
import java.util.Collections;
import java.util.HashSet;
import java.util.Locale;
import java.util.Set;
@ -154,4 +155,100 @@ public class TimeZoneNameTest extends TestFmwk {
}
}
}
@Test
public void testGetInstance_Locale() {
TimeZoneNames uLocaleInstance = TimeZoneNames.getInstance(ULocale.CANADA);
TimeZoneNames localeInstance = TimeZoneNames.getInstance(Locale.CANADA);
Set<String> uLocaleAvailableIds = uLocaleInstance.getAvailableMetaZoneIDs();
Set<String> localeAvailableIds = localeInstance.getAvailableMetaZoneIDs();
assertEquals("Available ids", uLocaleAvailableIds, localeAvailableIds);
for (String availableId : uLocaleAvailableIds) {
long date = 1458385200000L;
TimeZoneNames.NameType nameType = TimeZoneNames.NameType.SHORT_GENERIC;
String uLocaleName = uLocaleInstance.getDisplayName(availableId, nameType, date);
String localeName = localeInstance.getDisplayName(availableId, nameType, date);
assertEquals("Id: " + availableId, uLocaleName, localeName);
}
}
@Test
public void testGetAvailableMetaZoneIDs() {
TimeZoneNames japaneseNames = TimeZoneNames.getInstance(ULocale.JAPANESE);
Set<String> allJapan = japaneseNames.getAvailableMetaZoneIDs();
TimeZoneNames tzdbNames = TimeZoneNames.getTZDBInstance(ULocale.CHINESE);
Set<String> tzdbAll = tzdbNames.getAvailableMetaZoneIDs();
// The data is the same in the current implementation.
assertEquals("MetaZone IDs different between locales", allJapan, tzdbAll);
// Make sure that there is something.
assertTrue("count of zone ids is less than 100", allJapan.size() >= 180);
}
@Test
public void testGetAvailableMetaZoneIDs_String() {
TimeZoneNames japaneseNames = TimeZoneNames.getInstance(ULocale.JAPANESE);
assertEquals("Timezone name mismatch", Collections.singleton("America_Pacific"),
japaneseNames.getAvailableMetaZoneIDs("America/Los_Angeles"));
TimeZoneNames tzdbNames = TimeZoneNames.getTZDBInstance(ULocale.CHINESE);
assertEquals("Timezone name mismatch", Collections.singleton("Taipei"),
tzdbNames.getAvailableMetaZoneIDs("Asia/Taipei"));
}
@Test
public void testGetMetaZoneDisplayName() {
TimeZoneNames usNames = TimeZoneNames.getInstance(ULocale.US);
String europeanCentralName = usNames.getMetaZoneDisplayName("Europe_Central",
TimeZoneNames.NameType.LONG_STANDARD);
assertEquals("Timezone name mismatch", "Central European Standard Time",
europeanCentralName);
TimeZoneNames tzdbNames = TimeZoneNames.getTZDBInstance(ULocale.CHINESE);
String americaPacificName = tzdbNames.getMetaZoneDisplayName("America_Pacific",
TimeZoneNames.NameType.SHORT_DAYLIGHT);
assertEquals("Timezone name mismatch", "PDT", americaPacificName);
}
@Test
public void testGetMetaZoneID() {
TimeZoneNames usNames = TimeZoneNames.getInstance(ULocale.US);
String europeanCentralName = usNames.getMetaZoneID("Europe/Paris", 0);
assertEquals("Timezone name mismatch", "Europe_Central", europeanCentralName);
TimeZoneNames tzdbNames = TimeZoneNames.getTZDBInstance(ULocale.KOREAN);
String seoulName = tzdbNames.getMetaZoneID("Asia/Seoul", 0);
assertEquals("Timezone name mismatch", "Korea", seoulName);
// Now try Jan 1st 1945 GMT
seoulName = tzdbNames.getMetaZoneID("Asia/Seoul", -786240000000L);
assertNull("Timezone name mismatch", seoulName);
}
@Test
public void testGetTimeZoneDisplayName() {
TimeZoneNames frenchNames = TimeZoneNames.getInstance(ULocale.FRENCH);
String dublinName = frenchNames.getTimeZoneDisplayName("Europe/Dublin",
TimeZoneNames.NameType.LONG_DAYLIGHT);
assertEquals("Timezone name mismatch", "heure dété irlandaise", dublinName);
String dublinLocation = frenchNames.getTimeZoneDisplayName("Europe/Dublin",
TimeZoneNames.NameType.EXEMPLAR_LOCATION);
assertEquals("Timezone name mismatch", "Dublin", dublinLocation);
// All the names returned by this are null.
TimeZoneNames tzdbNames = TimeZoneNames.getTZDBInstance(ULocale.KOREAN);
for (String tzId : TimeZone.getAvailableIDs()) {
for (TimeZoneNames.NameType nameType : TimeZoneNames.NameType.values()) {
String name = tzdbNames.getTimeZoneDisplayName(tzId, nameType);
assertNull("TZ:" + tzId + ", NameType: " + nameType + ", value: " + name, name);
}
}
}
}