Search in sources :

Example 1 with TZDBTimeZoneNames

use of android.icu.impl.TZDBTimeZoneNames in project j2objc by google.

the class TimeZoneFormatTest method TestTZDBNamesThreading.

// This is a test case of Ticket#11487.
// Because the problem is reproduced for the very first time,
// the reported problem cannot be reproduced with regular test
// execution. Run this test alone reproduced the problem before
// the fix was merged.
@Test
public void TestTZDBNamesThreading() {
    final TZDBTimeZoneNames names = new TZDBTimeZoneNames(ULocale.ENGLISH);
    final AtomicInteger found = new AtomicInteger();
    List<Thread> threads = new ArrayList<Thread>();
    final int numIteration = 1000;
    try {
        for (int i = 0; i < numIteration; i++) {
            Thread thread = new Thread() {

                @Override
                public void run() {
                    int resultSize = names.find("GMT", 0, EnumSet.allOf(NameType.class)).size();
                    if (resultSize > 0) {
                        found.incrementAndGet();
                    }
                }
            };
            thread.start();
            threads.add(thread);
        }
        for (Thread thread : threads) {
            thread.join();
        }
    } catch (Throwable t) {
        errln(t.toString());
    }
    if (found.intValue() != numIteration) {
        errln("Incorrect count: " + found.toString() + ", expected: " + numIteration);
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ArrayList(java.util.ArrayList) TZDBTimeZoneNames(android.icu.impl.TZDBTimeZoneNames) Test(org.junit.Test)

Example 2 with TZDBTimeZoneNames

use of android.icu.impl.TZDBTimeZoneNames in project j2objc by google.

the class TimeZoneFormatTest method TestGetDisplayNames.

@Test
public void TestGetDisplayNames() {
    long date = System.currentTimeMillis();
    NameType[] types = new NameType[] { NameType.LONG_STANDARD, NameType.LONG_DAYLIGHT, NameType.SHORT_STANDARD, NameType.SHORT_DAYLIGHT };
    Set<String> zones = ZoneMeta.getAvailableIDs(SystemTimeZoneType.ANY, null, null);
    int casesTested = 0;
    Random rnd = new Random(2016);
    for (ULocale uloc : ULocale.getAvailableLocales()) {
        if (rnd.nextDouble() > 0.01) {
            continue;
        }
        for (String zone : zones) {
            if (rnd.nextDouble() > 0.01) {
                continue;
            }
            casesTested++;
            // Test default TimeZoneNames (uses an overridden getDisplayNames)
            {
                TimeZoneNames tznames = TimeZoneNames.getInstance(uloc);
                tznames.loadAllDisplayNames();
                String[] result = new String[types.length];
                tznames.getDisplayNames(zone, types, date, result, 0);
                for (int i = 0; i < types.length; i++) {
                    NameType type = types[i];
                    String expected = result[i];
                    String actual = tznames.getDisplayName(zone, type, date);
                    assertEquals("TimeZoneNames: getDisplayNames() returns different result than getDisplayName()" + " for " + zone + " in locale " + uloc, expected, actual);
                }
                // Coverage for empty call to getDisplayNames
                tznames.getDisplayNames(null, null, 0, null, 0);
            }
            // Test TZDBTimeZoneNames (uses getDisplayNames from abstract class)
            {
                TimeZoneNames tznames = new TZDBTimeZoneNames(uloc);
                tznames.loadAllDisplayNames();
                String[] result = new String[types.length];
                tznames.getDisplayNames(zone, types, date, result, 0);
                for (int i = 0; i < types.length; i++) {
                    NameType type = types[i];
                    String expected = result[i];
                    String actual = tznames.getDisplayName(zone, type, date);
                    assertEquals("TZDBTimeZoneNames: getDisplayNames() returns different result than getDisplayName()" + " for " + zone + " in locale " + uloc, expected, actual);
                }
                // Coverage for empty call to getDisplayNames
                tznames.getDisplayNames(null, null, 0, null, 0);
            }
        }
    }
    assertTrue("No cases were tested", casesTested > 0);
}
Also used : ULocale(android.icu.util.ULocale) Random(java.util.Random) TZDBTimeZoneNames(android.icu.impl.TZDBTimeZoneNames) TimeZoneNames(android.icu.text.TimeZoneNames) NameType(android.icu.text.TimeZoneNames.NameType) TZDBTimeZoneNames(android.icu.impl.TZDBTimeZoneNames) Test(org.junit.Test)

Aggregations

TZDBTimeZoneNames (android.icu.impl.TZDBTimeZoneNames)2 Test (org.junit.Test)2 TimeZoneNames (android.icu.text.TimeZoneNames)1 NameType (android.icu.text.TimeZoneNames.NameType)1 ULocale (android.icu.util.ULocale)1 ArrayList (java.util.ArrayList)1 Random (java.util.Random)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1