From 1914dbf81df1dc0b8b83cc9210d5e1ed9bba37a6 Mon Sep 17 00:00:00 2001 From: GCL Shanghai Date: Fri, 29 Oct 2004 16:30:35 +0000 Subject: [PATCH] ICU-4094 Add API/Method Coverage tests for ICU4J X-SVN-Rev: 16675 --- .../dev/test/format/TestMessageFormat.java | 116 ++++++++++++ .../ibm/icu/dev/test/util/ULocaleTest.java | 170 ++++++++++++++++++ 2 files changed, 286 insertions(+) diff --git a/icu4j/src/com/ibm/icu/dev/test/format/TestMessageFormat.java b/icu4j/src/com/ibm/icu/dev/test/format/TestMessageFormat.java index 8240c0c44c4..89a136ac51a 100644 --- a/icu4j/src/com/ibm/icu/dev/test/format/TestMessageFormat.java +++ b/icu4j/src/com/ibm/icu/dev/test/format/TestMessageFormat.java @@ -21,6 +21,9 @@ import java.util.Locale; import com.ibm.icu.text.DecimalFormat; import com.ibm.icu.text.MessageFormat; import com.ibm.icu.text.NumberFormat; +import com.ibm.icu.text.DateFormat; +import com.ibm.icu.text.UFormat; +import com.ibm.icu.util.ULocale; public class TestMessageFormat extends com.ibm.icu.dev.test.TestFmwk { @@ -367,6 +370,31 @@ public class TestMessageFormat extends com.ibm.icu.dev.test.TestFmwk { } } + public void TestHashCode() + { + ULocale save = ULocale.getDefault(); + ULocale.setDefault(ULocale.US); + + MessageFormat x = new MessageFormat("There are {0} files on {1}"); + MessageFormat z = new MessageFormat("There are {0} files on {1}"); + MessageFormat y = null; + y = (MessageFormat)x.clone(); + if (x.hashCode() != y.hashCode()) + errln("FAIL: identical objects have different hashcodes"); + if (x.hashCode() != z.hashCode()) + errln("FAIL: identical objects have different hashcodes"); + + y.setLocale(ULocale.FRENCH); + if (x.hashCode() == y.hashCode()) + errln("FAIL: different objects have same hashcodes. Locale ignored"); + + z.applyPattern("There are {0} files on {1} the disk"); + if (x.hashCode() == z.hashCode()) + errln("FAIL: different objects have same hashcodes. Pattern ignored"); + + ULocale.setDefault(save); + } + public void TestSetLocale() { Object arguments[] = { @@ -414,6 +442,22 @@ public class TestMessageFormat extends com.ibm.icu.dev.test.TestFmwk { result, pos); assertEquals("format", compareStrGer, result.toString()); + + //Cover getULocale() + logln("Testing set/get ULocale ..."); + msg.setLocale(ULocale.ENGLISH); + assertEquals("getULocale", ULocale.ENGLISH, msg.getULocale()); + + msg.setLocale(ULocale.GERMAN); + assertEquals("getULocale", ULocale.GERMAN, msg.getULocale()); + + msg.applyPattern(formatStr); + result.setLength(0); + result = msg.format( + arguments, + result, + pos); + assertEquals("format", compareStrGer, result.toString()); } public void TestFormat() @@ -791,4 +835,76 @@ public class TestMessageFormat extends com.ibm.icu.dev.test.TestFmwk { } } } + + public void TestSetGetFormats() + { + Object arguments[] = { + new Double(456.83), + new Date(871068000000L), + "deposit" + }; + + StringBuffer result = new StringBuffer(); + + String formatStr = "At