summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--CleanSpec.mk1
-rw-r--r--JavaLibrary.mk75
-rw-r--r--NativeCode.mk44
-rw-r--r--crypto/src/main/java/org/conscrypt/NativeCrypto.java9
-rw-r--r--crypto/src/main/native/org_conscrypt_NativeCrypto.cpp25
-rw-r--r--dalvik/src/main/java/dalvik/system/VMDebug.java5
-rw-r--r--expectations/brokentests.txt40
-rw-r--r--expectations/knownfailures.txt19
-rw-r--r--harmony-tests/src/test/java/org/apache/harmony/tests/java/text/BidiTest.java77
-rw-r--r--harmony-tests/src/test/java/org/apache/harmony/tests/java/text/CollationElementIteratorTest.java346
-rw-r--r--harmony-tests/src/test/java/org/apache/harmony/tests/java/text/DateFormatSymbolsTest.java75
-rw-r--r--harmony-tests/src/test/java/org/apache/harmony/tests/java/text/DecimalFormatSymbolsTest.java44
-rw-r--r--harmony-tests/src/test/java/org/apache/harmony/tests/java/text/DecimalFormatTest.java1089
-rw-r--r--harmony-tests/src/test/java/org/apache/harmony/tests/java/text/FieldPositionTest.java87
-rw-r--r--harmony-tests/src/test/java/org/apache/harmony/tests/java/text/MessageFormatTest.java922
-rw-r--r--harmony-tests/src/test/java/org/apache/harmony/tests/java/text/NumberFormatTest.java16
-rw-r--r--harmony-tests/src/test/java/org/apache/harmony/tests/java/text/RuleBasedCollatorTest.java474
-rw-r--r--harmony-tests/src/test/java/org/apache/harmony/tests/java/text/SimpleDateFormatTest.java173
-rw-r--r--harmony-tests/src/test/java/org/apache/harmony/tests/java/text/Support_DecimalFormat.java483
-rw-r--r--harmony-tests/src/test/java/org/apache/harmony/tests/java/text/Support_Format.java228
-rw-r--r--harmony-tests/src/test/java/org/apache/harmony/tests/java/text/Support_MessageFormat.java82
-rw-r--r--harmony-tests/src/test/java/org/apache/harmony/tests/java/text/Support_SimpleDateFormat.java454
-rw-r--r--luni/src/main/java/java/text/Bidi.java49
-rw-r--r--luni/src/main/java/java/text/DateFormatSymbols.java2
-rw-r--r--luni/src/main/java/java/text/DecimalFormat.java133
-rw-r--r--luni/src/main/java/java/text/FieldPosition.java244
-rw-r--r--luni/src/main/java/java/text/NumberFormat.java30
-rw-r--r--luni/src/main/java/java/text/SimpleDateFormat.java24
-rw-r--r--luni/src/main/java/java/util/concurrent/ConcurrentHashMap.java2
-rw-r--r--luni/src/main/java/libcore/icu/DateIntervalFormat.java51
-rw-r--r--luni/src/main/java/libcore/icu/LocaleData.java6
-rw-r--r--luni/src/main/java/libcore/icu/NativeDecimalFormat.java176
-rw-r--r--luni/src/main/native/IcuUtilities.h1
-rw-r--r--luni/src/main/native/Register.cpp1
-rw-r--r--luni/src/main/native/libcore_icu_ICU.cpp36
-rw-r--r--luni/src/main/native/libcore_icu_NativeDecimalFormat.cpp72
-rw-r--r--luni/src/test/java/libcore/icu/DateIntervalFormatTest.java231
-rw-r--r--luni/src/test/java/libcore/java/text/OldBidiTest.java22
-rw-r--r--luni/src/test/java/libcore/java/text/OldCollationElementIteratorTest.java52
-rw-r--r--luni/src/test/java/libcore/java/text/OldDecimalFormatTest.java1007
-rw-r--r--luni/src/test/java/libcore/java/text/OldFieldPositionTest.java79
-rw-r--r--luni/src/test/java/libcore/java/text/OldMessageFormatTest.java463
-rw-r--r--luni/src/test/java/libcore/java/text/OldSimpleDateFormatTest.java251
-rw-r--r--luni/src/test/java/libcore/javax/net/ssl/SSLSessionTest.java4
-rw-r--r--luni/src/test/java/libcore/javax/net/ssl/SSLSocketTest.java2
-rw-r--r--support/src/test/java/libcore/java/lang/ref/FinalizationTester.java (renamed from luni/src/test/java/libcore/java/lang/ref/FinalizationTester.java)0
46 files changed, 3039 insertions, 4667 deletions
diff --git a/CleanSpec.mk b/CleanSpec.mk
index 4cde928..992b0dc 100644
--- a/CleanSpec.mk
+++ b/CleanSpec.mk
@@ -46,6 +46,7 @@
#$(call add-clean-step, rm -rf $(PRODUCT_OUT)/data/*)
#$(call add-clean-step, rm -rf $(OUT)/obj/SHARED_LIBRARIES/libdvm*)
$(call add-clean-step, rm -rf $(OUT)/system/framework/conscrypt-nojarjar.jar)
+$(call add-clean-step, rm -rf $(OUT)/system/framework/conscrypt-nojarjar.jar)
# ************************************************
# NEWER CLEAN STEPS MUST BE AT THE END OF THE LIST
# ************************************************
diff --git a/JavaLibrary.mk b/JavaLibrary.mk
index 78c9d13..d3ce43b 100644
--- a/JavaLibrary.mk
+++ b/JavaLibrary.mk
@@ -50,7 +50,7 @@ $(shell cd $(LOCAL_PATH) && ls -d */src/$(1)/{java,resources} 2> /dev/null)
endef
# The Java files and their associated resources.
-core_src_files := $(call all-main-java-files-under,dalvik dex dom json luni support xml)
+core_src_files := $(call all-main-java-files-under,dalvik dex dom json luni xml)
core_src_files += $(call all-main-java-files-under,libdvm)
core_resource_dirs := $(call all-core-resource-dirs,main)
test_resource_dirs := $(call all-core-resource-dirs,test)
@@ -100,6 +100,7 @@ LOCAL_JAVACFLAGS := $(local_javac_flags)
LOCAL_JARJAR_RULES := $(LOCAL_PATH)/crypto/jarjar-rules.txt
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE := conscrypt
+LOCAL_REQUIRED_MODULES := libjavacrypto
LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/JavaLibrary.mk
include $(BUILD_JAVA_LIBRARY)
@@ -118,19 +119,48 @@ include $(BUILD_STATIC_JAVA_LIBRARY)
ifeq ($(LIBCORE_SKIP_TESTS),)
# Make the core-tests library.
include $(CLEAR_VARS)
-LOCAL_SRC_FILES := $(call all-test-java-files-under,crypto dalvik dom harmony-tests json luni support xml)
+LOCAL_SRC_FILES := $(call all-test-java-files-under,dalvik dom harmony-tests json luni xml)
LOCAL_JAVA_RESOURCE_DIRS := $(test_resource_dirs)
LOCAL_NO_STANDARD_LIBRARIES := true
LOCAL_JAVA_LIBRARIES := bouncycastle core core-junit okhttp
-LOCAL_STATIC_JAVA_LIBRARIES := sqlite-jdbc mockwebserver nist-pkix-tests conscrypt-nojarjar okhttp-tests
+LOCAL_STATIC_JAVA_LIBRARIES := core-tests-support sqlite-jdbc mockwebserver nist-pkix-tests okhttp-tests
LOCAL_JAVACFLAGS := $(local_javac_flags)
-LOCAL_JARJAR_RULES := $(LOCAL_PATH)/crypto/jarjar-rules.txt
LOCAL_MODULE := core-tests
LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/JavaLibrary.mk
include $(BUILD_STATIC_JAVA_LIBRARY)
endif
ifeq ($(LIBCORE_SKIP_TESTS),)
+# Make the core-tests-support library.
+include $(CLEAR_VARS)
+LOCAL_SRC_FILES := $(call all-test-java-files-under,support)
+LOCAL_JAVA_RESOURCE_DIRS := $(test_resource_dirs)
+LOCAL_NO_STANDARD_LIBRARIES := true
+LOCAL_JAVA_LIBRARIES := bouncycastle core core-junit
+LOCAL_JAVACFLAGS := $(local_javac_flags)
+LOCAL_MODULE := core-tests-support
+LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/JavaLibrary.mk
+include $(BUILD_STATIC_JAVA_LIBRARY)
+endif
+
+ifeq ($(LIBCORE_SKIP_TESTS),)
+# Make the conscrypt-tests library.
+include $(CLEAR_VARS)
+LOCAL_SRC_FILES := $(call all-test-java-files-under,crypto)
+LOCAL_JAVA_RESOURCE_DIRS := $(test_resource_dirs)
+LOCAL_NO_STANDARD_LIBRARIES := true
+LOCAL_JAVA_LIBRARIES := bouncycastle core core-junit
+LOCAL_STATIC_JAVA_LIBRARIES := core-tests-support conscrypt-nojarjar
+LOCAL_JAVACFLAGS := $(local_javac_flags)
+LOCAL_MODULE_TAGS := optional
+LOCAL_MODULE := conscrypt-tests
+LOCAL_REQUIRED_MODULES := libjavacrypto
+LOCAL_JARJAR_RULES := $(LOCAL_PATH)/crypto/jarjar-rules.txt
+LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/JavaLibrary.mk
+include $(BUILD_STATIC_JAVA_LIBRARY)
+endif
+
+ifeq ($(LIBCORE_SKIP_TESTS),)
# Make the jsr166-tests library.
include $(CLEAR_VARS)
LOCAL_SRC_FILES := $(call all-test-java-files-under, jsr166-tests)
@@ -200,6 +230,7 @@ ifeq ($(WITH_HOST_DALVIK),true)
LOCAL_BUILD_HOST_DEX := true
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE := conscrypt-hostdex
+ LOCAL_REQUIRED_MODULES := libjavacrypto
LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/JavaLibrary.mk
include $(BUILD_HOST_JAVA_LIBRARY)
@@ -218,19 +249,49 @@ ifeq ($(WITH_HOST_DALVIK),true)
# Make the core-tests library.
ifeq ($(LIBCORE_SKIP_TESTS),)
include $(CLEAR_VARS)
- LOCAL_SRC_FILES := $(call all-test-java-files-under,crypto dalvik dom json luni support xml)
+ LOCAL_SRC_FILES := $(call all-test-java-files-under,dalvik dom json luni xml)
LOCAL_JAVA_RESOURCE_DIRS := $(test_resource_dirs)
LOCAL_NO_STANDARD_LIBRARIES := true
- LOCAL_JAVA_LIBRARIES := bouncycastle-hostdex core-hostdex conscrypt-hostdex-nojarjar core-junit-hostdex okhttp-hostdex
+ LOCAL_JAVA_LIBRARIES := bouncycastle-hostdex core-hostdex core-junit-hostdex core-tests-support-hostdex okhttp-hostdex
LOCAL_STATIC_JAVA_LIBRARIES := sqlite-jdbc-host mockwebserver-host nist-pkix-tests-host
LOCAL_JAVACFLAGS := $(local_javac_flags)
- LOCAL_JARJAR_RULES := $(LOCAL_PATH)/crypto/jarjar-rules.txt
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE := core-tests-hostdex
LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/JavaLibrary.mk
LOCAL_BUILD_HOST_DEX := true
include $(BUILD_HOST_JAVA_LIBRARY)
endif
+
+ # Make the core-tests-support library.
+ ifeq ($(LIBCORE_SKIP_TESTS),)
+ include $(CLEAR_VARS)
+ LOCAL_SRC_FILES := $(call all-test-java-files-under,support)
+ LOCAL_JAVA_RESOURCE_DIRS := $(test_resource_dirs)
+ LOCAL_NO_STANDARD_LIBRARIES := true
+ LOCAL_JAVA_LIBRARIES := bouncycastle-hostdex core-hostdex core-junit-hostdex
+ LOCAL_JAVACFLAGS := $(local_javac_flags)
+ LOCAL_MODULE_TAGS := optional
+ LOCAL_MODULE := core-tests-support-hostdex
+ LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/JavaLibrary.mk
+ LOCAL_BUILD_HOST_DEX := true
+ include $(BUILD_HOST_JAVA_LIBRARY)
+ endif
+
+ # Make the conscrypt-tests library.
+ ifeq ($(LIBCORE_SKIP_TESTS),)
+ include $(CLEAR_VARS)
+ LOCAL_SRC_FILES := $(call all-test-java-files-under,crypto)
+ LOCAL_JAVA_RESOURCE_DIRS := $(test_resource_dirs)
+ LOCAL_NO_STANDARD_LIBRARIES := true
+ LOCAL_JAVA_LIBRARIES := bouncycastle-hostdex core-hostdex core-junit-hostdex core-tests-support-hostdex conscrypt-hostdex-nojarjar
+ LOCAL_JAVACFLAGS := $(local_javac_flags)
+ LOCAL_MODULE_TAGS := optional
+ LOCAL_MODULE := conscrypt-tests-hostdex
+ LOCAL_REQUIRED_MODULES := libjavacrypto
+ LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/JavaLibrary.mk
+ LOCAL_BUILD_HOST_DEX := true
+ include $(BUILD_HOST_JAVA_LIBRARY)
+ endif
endif
#
diff --git a/NativeCode.mk b/NativeCode.mk
index 52ab6d7..42319dc 100644
--- a/NativeCode.mk
+++ b/NativeCode.mk
@@ -59,7 +59,7 @@ core_src_files :=
# Include the sub.mk files.
$(foreach dir, \
- crypto/src/main/native dalvik/src/main/native luni/src/main/native, \
+ dalvik/src/main/native luni/src/main/native, \
$(eval $(call include-core-native-dir,$(dir))))
# Extract out the allowed LOCAL_* variables.
@@ -67,7 +67,6 @@ core_c_includes := libcore/include $(LOCAL_C_INCLUDES)
core_shared_libraries := $(LOCAL_SHARED_LIBRARIES)
core_static_libraries := $(LOCAL_STATIC_LIBRARIES)
core_cflags := -Wall -Wextra -Werror
-core_cflags += -DJNI_JARJAR_PREFIX="com/android/"
core_cppflags += -std=gnu++11
core_test_files := \
@@ -82,7 +81,7 @@ LOCAL_CFLAGS += $(core_cflags)
LOCAL_CPPFLAGS += $(core_cppflags)
LOCAL_SRC_FILES += $(core_src_files)
LOCAL_C_INCLUDES += $(core_c_includes)
-LOCAL_SHARED_LIBRARIES += $(core_shared_libraries) libexpat libicuuc libicui18n libssl libcrypto libz libnativehelper
+LOCAL_SHARED_LIBRARIES += $(core_shared_libraries) libcrypto libexpat libicuuc libicui18n libnativehelper libz
LOCAL_STATIC_LIBRARIES += $(core_static_libraries)
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE := libjavacore
@@ -90,6 +89,23 @@ LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/NativeCode.mk
include external/stlport/libstlport.mk
include $(BUILD_SHARED_LIBRARY)
+# Platform conscrypt crypto library
+include $(CLEAR_VARS)
+LOCAL_CFLAGS += $(core_cflags)
+LOCAL_CFLAGS += -DJNI_JARJAR_PREFIX="com/android/"
+LOCAL_CPPFLAGS += $(core_cppflags)
+LOCAL_SRC_FILES := \
+ crypto/src/main/native/org_conscrypt_NativeCrypto.cpp \
+ luni/src/main/native/AsynchronousSocketCloseMonitor.cpp
+LOCAL_C_INCLUDES += $(core_c_includes) \
+ libcore/luni/src/main/native
+LOCAL_SHARED_LIBRARIES += $(core_shared_libraries) libcrypto libssl libnativehelper libz
+LOCAL_STATIC_LIBRARIES += $(core_static_libraries)
+LOCAL_MODULE_TAGS := optional
+LOCAL_MODULE := libjavacrypto
+LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/NativeCode.mk
+include external/stlport/libstlport.mk
+include $(BUILD_SHARED_LIBRARY)
# Test JNI library.
ifeq ($(LIBCORE_SKIP_TESTS),)
@@ -123,7 +139,24 @@ ifeq ($(WITH_HOST_DALVIK),true)
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE := libjavacore
LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/NativeCode.mk
- LOCAL_SHARED_LIBRARIES += $(core_shared_libraries) libexpat-host libicuuc-host libicui18n-host libssl-host libcrypto-host libz-host
+ LOCAL_SHARED_LIBRARIES += $(core_shared_libraries) libexpat-host libicuuc-host libicui18n-host libcrypto-host libz-host
+ LOCAL_STATIC_LIBRARIES += $(core_static_libraries)
+ include $(BUILD_HOST_SHARED_LIBRARY)
+
+ # Conscrypt native library for host
+ include $(CLEAR_VARS)
+ LOCAL_SRC_FILES += \
+ crypto/src/main/native/org_conscrypt_NativeCrypto.cpp \
+ luni/src/main/native/AsynchronousSocketCloseMonitor.cpp
+ LOCAL_C_INCLUDES += $(core_c_includes) \
+ libcore/luni/src/main/native
+ LOCAL_CPPFLAGS += $(core_cppflags)
+ LOCAL_LDLIBS += -lpthread
+ LOCAL_MODULE_TAGS := optional
+ LOCAL_MODULE := libjavacrypto
+ LOCAL_CFLAGS += -DJNI_JARJAR_PREFIX="com/android/"
+ LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/NativeCode.mk
+ LOCAL_SHARED_LIBRARIES += $(core_shared_libraries) libssl-host libcrypto-host
LOCAL_STATIC_LIBRARIES += $(core_static_libraries)
include $(BUILD_HOST_SHARED_LIBRARY)
@@ -132,7 +165,8 @@ ifeq ($(WITH_HOST_DALVIK),true)
LOCAL_SRC_FILES += \
crypto/src/main/native/org_conscrypt_NativeCrypto.cpp \
luni/src/main/native/AsynchronousSocketCloseMonitor.cpp
- LOCAL_C_INCLUDES += $(core_c_includes)
+ LOCAL_C_INCLUDES += $(core_c_includes) \
+ libcore/luni/src/main/native
LOCAL_CPPFLAGS += $(core_cppflags)
LOCAL_LDLIBS += -lpthread
LOCAL_MODULE_TAGS := optional
diff --git a/crypto/src/main/java/org/conscrypt/NativeCrypto.java b/crypto/src/main/java/org/conscrypt/NativeCrypto.java
index 9094935..86c99d8 100644
--- a/crypto/src/main/java/org/conscrypt/NativeCrypto.java
+++ b/crypto/src/main/java/org/conscrypt/NativeCrypto.java
@@ -46,11 +46,12 @@ public final class NativeCrypto {
// --- OpenSSL library initialization --------------------------------------
static {
/*
- * If we're compiled as part of Android, we don't need to explicitly
- * call loadLibrary. Detect this by looking for the jarjar'd package
- * name.
+ * If we're compiled as part of Android, should use a different JNI
+ * library name. Detect this by looking for the jarjar'd package name.
*/
- if (!"com.android.org.conscrypt".equals(NativeCrypto.class.getPackage().getName())) {
+ if ("com.android.org.conscrypt".equals(NativeCrypto.class.getPackage().getName())) {
+ System.loadLibrary("javacrypto");
+ } else {
System.loadLibrary("conscrypt_jni");
}
diff --git a/crypto/src/main/native/org_conscrypt_NativeCrypto.cpp b/crypto/src/main/native/org_conscrypt_NativeCrypto.cpp
index 5dc6037..bde5b35 100644
--- a/crypto/src/main/native/org_conscrypt_NativeCrypto.cpp
+++ b/crypto/src/main/native/org_conscrypt_NativeCrypto.cpp
@@ -8178,8 +8178,6 @@ static void initialize_conscrypt(JNIEnv* env) {
outputStream_flushMethod = env->GetMethodID(outputStreamClass, "flush", "()V");
}
-#if defined(CONSCRYPT_UNBUNDLED)
-
static jclass findClass(JNIEnv* env, const char* name) {
ScopedLocalRef<jclass> localClass(env, env->FindClass(name));
jclass result = reinterpret_cast<jclass>(env->NewGlobalRef(localClass.get()));
@@ -8191,7 +8189,7 @@ static jclass findClass(JNIEnv* env, const char* name) {
}
// Use JNI_OnLoad for when we're standalone
-int JNI_OnLoad(JavaVM *vm, void* reserved) {
+int JNI_OnLoad(JavaVM *vm, void*) {
JNI_TRACE("JNI_OnLoad NativeCrypto");
gJavaVM = vm;
@@ -8213,24 +8211,3 @@ int JNI_OnLoad(JavaVM *vm, void* reserved) {
initialize_conscrypt(env);
return JNI_VERSION_1_6;
}
-
-#else
-
-// Use this when built into Android
-void register_org_conscrypt_NativeCrypto(JNIEnv* env) {
- JNI_TRACE("register_org_conscrypt_NativeCrypto");
-
- byteArrayClass = JniConstants::byteArrayClass;
- calendarClass = JniConstants::calendarClass;
- inputStreamClass = JniConstants::inputStreamClass;
- integerClass = JniConstants::integerClass;
- objectClass = JniConstants::objectClass;
- objectArrayClass = JniConstants::objectArrayClass;
- outputStreamClass = JniConstants::outputStreamClass;
- stringClass = JniConstants::stringClass;
-
- env->GetJavaVM(&gJavaVM);
- initialize_conscrypt(env);
-}
-
-#endif // defined(CONSCRYPT_UNBUNDLED)
diff --git a/dalvik/src/main/java/dalvik/system/VMDebug.java b/dalvik/src/main/java/dalvik/system/VMDebug.java
index 18111f9..5d59838 100644
--- a/dalvik/src/main/java/dalvik/system/VMDebug.java
+++ b/dalvik/src/main/java/dalvik/system/VMDebug.java
@@ -198,9 +198,10 @@ public final class VMDebug {
private static native void startMethodTracingFilename(String traceFileName, int bufferSize, int flags);
/**
- * Determine whether method tracing is currently active.
+ * Determine whether method tracing is currently active and what type is
+ * active.
*/
- public static native boolean isMethodTracingActive();
+ public static native int getMethodTracingMode();
/**
* Stops method tracing.
diff --git a/expectations/brokentests.txt b/expectations/brokentests.txt
index 24813dd..2d028b0 100644
--- a/expectations/brokentests.txt
+++ b/expectations/brokentests.txt
@@ -543,21 +543,14 @@
substring: "GMT-07:00"
},
{
- description: "This test fails because on Android, RuleBasedCollators default to
- CANONICAL_DECOMPOSITION, not NO_DECOMPOSITION.",
- result: EXEC_FAILED,
- name: "org.apache.harmony.text.tests.java.text.RuleBasedCollatorTest#testEqualsObject",
- substring: "expected:<0> but was:<1>"
-},
-{
- description: "These Harmony tests are enforcing a buggy behaviour in TreeMap, presumably to be bug-compatible
+ description: "These Harmony tests are enforcing a buggy behavior in TreeMap, presumably to be bug-compatible
with the RI. Our implementation is more conservative and throws on the bogus inputs.",
result: EXEC_FAILED,
name: "org.apache.harmony.luni.tests.java.util.TreeMapExtendTest#test_AscendingSubMapKeySet_headSet",
substring: "java.lang.IllegalArgumentException: 100 not in range (100..109]"
},
{
- description: "These Harmony tests are enforcing a buggy behaviour in TreeMap, presumably to be bug-compatible
+ description: "These Harmony tests are enforcing a buggy behavior in TreeMap, presumably to be bug-compatible
with the RI. Our implementation is more conservative and throws on the bogus inputs.",
result: EXEC_FAILED,
names: [
@@ -567,7 +560,7 @@
substring: "java.lang.IllegalArgumentException: null not in range [100..109)"
},
{
- description: "These Harmony tests are enforcing a buggy behaviour in TreeMap, presumably to be bug-compatible
+ description: "These Harmony tests are enforcing a buggy behavior in TreeMap, presumably to be bug-compatible
with the RI. Our implementation is more conservative and throws on the bogus inputs.",
result: EXEC_FAILED,
names: [
@@ -757,24 +750,6 @@
substring: "junit.framework.AssertionFailedError: expected:<3> but was:<2>"
},
{
- description: "ICU doesn't provide localized pattern characters, and these tests assume the locale they're using has them.",
- result: EXEC_FAILED,
- name: "org.apache.harmony.text.tests.java.text.SimpleDateFormatTest#test_applyLocalizedPatternLjava_lang_String",
- substring: "java.lang.IllegalArgumentException: Invalid pattern character 'u' in 'GuMtkHmsSEDFwWahKz'"
-},
-{
- description: "ICU doesn't provide localized pattern characters, and these tests assume the locale they're using has them.",
- result: EXEC_FAILED,
- name: "org.apache.harmony.text.tests.java.text.SimpleDateFormatTest#test_toLocalizedPattern",
- substring: "junit.framework.AssertionFailedError: Wrong pattern: GyMdkHmsSEDFwWahKz"
-},
-{
- description: "ICU doesn't provide localized pattern characters, and these tests assume the locale they're using has them.",
- result: EXEC_FAILED,
- name: "org.apache.harmony.text.tests.java.text.DateFormatSymbolsTest#test_getLocalPatternChars",
- substring: "junit.framework.ComparisonFailure: Returned incorrect pattern string expected:<...YeugAZvcLQqV> but was:<...Z>"
-},
-{
description: "we don't support the CharsetProvider spi, so we don't have \"mockCharset00\".",
result: EXEC_FAILED,
name: "tests.api.java.nio.charset.CharsetTest#test_availableCharsets",
@@ -838,15 +813,6 @@
name: "org.apache.harmony.luni.tests.internal.nls.MessagesTest"
},
{
- description: "These test implementation details we don't share.",
- result: EXEC_FAILED,
- names: [
- "org.apache.harmony.text.tests.java.text.BreakIteratorTest#test_getInt",
- "org.apache.harmony.text.tests.java.text.BreakIteratorTest#test_getLong",
- "org.apache.harmony.text.tests.java.text.BreakIteratorTest#test_getShort"
- ]
-},
-{
description: "These format specifiers are documented to not take flags, but the RI accepts and ignores them.",
result: EXEC_FAILED,
name: "org.apache.harmony.luni.tests.java.util.FormatterTest#test_formatLjava_lang_String$Ljava_lang_Object_LineSeparator",
diff --git a/expectations/knownfailures.txt b/expectations/knownfailures.txt
index 9f67048..5391954 100644
--- a/expectations/knownfailures.txt
+++ b/expectations/knownfailures.txt
@@ -159,25 +159,6 @@
bug: 3056792
},
{
- description: "DecimalFormat.formatToCharacterIterator() is failing tests",
- names: [
- "libcore.java.text.OldDecimalFormatTest#test_formatToCharacterIterator",
- "org.apache.harmony.text.tests.java.text.DecimalFormatTest#test_formatToCharacterIteratorLjava_lang_Object",
- "org.apache.harmony.text.tests.java.text.DecimalFormatTest#test_formatToCharacterIteratorLjava_lang_Object__ArithmeticException"
- ],
- bug: 3056865
-},
-{
- description: "DecimalFormat.parse returns wrong type with multiplier: expected Long but was Double",
- name: "libcore.java.text.OldDecimalFormatTest#test_parseLjava_lang_StringLjava_text_ParsePosition",
- bug: 3057080
-},
-{
- description: "DecimalFormat FieldPosition not updated with correct begin and end indices",
- name: "libcore.java.text.OldDecimalFormatTest#test_formatDLjava_lang_StringBufferLjava_text_FieldPosition",
- bug: 3057090
-},
-{
description: "DecimalFormat is limited to 127 digits",
name: "libcore.java.text.DecimalFormatTest#test_setMaximumIntegerDigits",
bug: 2400429
diff --git a/harmony-tests/src/test/java/org/apache/harmony/tests/java/text/BidiTest.java b/harmony-tests/src/test/java/org/apache/harmony/tests/java/text/BidiTest.java
index 70dbce3..52a29a2 100644
--- a/harmony-tests/src/test/java/org/apache/harmony/tests/java/text/BidiTest.java
+++ b/harmony-tests/src/test/java/org/apache/harmony/tests/java/text/BidiTest.java
@@ -1,13 +1,13 @@
-/*
+/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -17,7 +17,7 @@
package org.apache.harmony.tests.java.text;
-import java.text.AttributedString;
+import java.text.AttributedString;
import java.text.Bidi;
import java.util.Arrays;
@@ -107,39 +107,39 @@ public class BidiTest extends TestCase {
//regression for HARMONY-1031
try {
bd = new Bidi(new char[] { 't','t','t'}, -1, new byte[] { 2, 2 }, 1, 1, 1);
- fail("should be IAE");
+ fail("should be IAE");
} catch (IllegalArgumentException e) {
// expected
}
-
+
try {
bd = new Bidi(new char[] { 't','t','t'}, 1, new byte[] { 2, 2 }, -1, 1, 1);
- fail("should be IAE");
+ fail("should be IAE");
} catch (IllegalArgumentException e) {
// expected
}
-
+
try {
bd = new Bidi(new char[] { 't','t','t'}, 1, new byte[] { 2, 2 }, 1, -1, 1);
- fail("should be IAE");
+ fail("should be IAE");
} catch (IllegalArgumentException e) {
// expected
}
try {
bd = new Bidi(new char[] {}, 5, new byte[] { 2, 2, 2, 2, 2, 2 }, 8, Integer.MAX_VALUE, 5);
- fail("should be IAE");
+ fail("should be IAE");
} catch (IllegalArgumentException e) {
// expected
}
try {
bd = new Bidi(null, 5, null, 8, Integer.MAX_VALUE, 5);
- fail("should be IAE");
+ fail("should be IAE");
} catch (IllegalArgumentException e) {
// expected
}
-
+
bd = new Bidi(new char[] {'o'}, 0, new byte[] { 2, 2}, 2, 0, 2 );
}
@@ -700,7 +700,7 @@ public class BidiTest extends TestCase {
} catch (IllegalArgumentException e) {
// expected
}
-
+
assertFalse(Bidi.requiresBidi("".toCharArray(), 0, 0));
assertFalse(Bidi.requiresBidi("aaa".toCharArray(), 1, 1));
assertFalse(Bidi.requiresBidi("aaa".toCharArray(), 0, 2));
@@ -807,28 +807,28 @@ public class BidiTest extends TestCase {
Bidi bidi = new Bidi("str", 1);
try {
bidi.createLineBidi(-1, 1);
- fail("Expected IAE");
+ fail("Expected IAE");
} catch (IllegalArgumentException e) {
// Expected
}
-
+
try {
bidi.createLineBidi(1, -1);
- fail("Expected IAE");
+ fail("Expected IAE");
} catch (IllegalArgumentException e) {
// Expected
}
-
+
try {
bidi.createLineBidi(-1, -1);
- fail("Expected IAE");
+ fail("Expected IAE");
} catch (IllegalArgumentException e) {
// Expected
}
try {
bidi.createLineBidi(2, 1);
- fail("Expected IAE");
+ fail("Expected IAE");
} catch (IllegalArgumentException e) {
// Expected
}
@@ -841,12 +841,12 @@ public class BidiTest extends TestCase {
try {
bidi.createLineBidi(2, 4);
- fail("Expected IAE");
+ fail("Expected IAE");
} catch (IllegalArgumentException e) {
// Expected
}
}
-
+
public void testIncompatibleLineAlgorithm() {
// ICU treat a new line as in the same run, however RI does not
bd = new Bidi("aaaaa".toCharArray(), 0,
@@ -929,7 +929,7 @@ public class BidiTest extends TestCase {
} catch (NullPointerException e) {
// expected
}
-
+
try {
Bidi.reorderVisually(new byte[] { 2, 1, 3, 0 }, 1, s, 0, -1);
fail("should throw IAE");
@@ -938,22 +938,22 @@ public class BidiTest extends TestCase {
}
}
-
+
public void testGetRuns() {
//Regression test for Harmony-1028
-
+
String LTR = "\u0061\u0062";
String RTL = "\u05DC\u05DD";
String newLine = "\n";
String defText = LTR + newLine + RTL + LTR + RTL;
-
+
int[][] expectedRuns = {
{0, 3},
{3, 5},
{5, 7},
{7, 9},
};
-
+
Bidi bi = new Bidi(defText, 0);
final int count = bi.getRunCount();
for (int i = 0; i < count; i++) {
@@ -961,29 +961,4 @@ public class BidiTest extends TestCase {
assertEquals(expectedRuns[i][1], bi.getRunLimit(i));
}
}
- public void testGetRunLimit() {
- bd = new Bidi("text", Bidi.DIRECTION_LEFT_TO_RIGHT);
- try {
- assertTrue(4 == bd.getRunLimit(-1));
- } catch (IllegalArgumentException e) {
- // Expected for illegal run limit
- return;
- }
-
- fail("Expected IllegalArgumentException to be thrown for invalid run limit");
- }
-
- public void testBidiConstructor_Iterator() {
- AttributedString paragraph = new AttributedString("text");
- bd = new Bidi(paragraph.getIterator());
- try {
- assertTrue(4 == bd.getRunLimit(1));
- } catch (IllegalArgumentException e) {
- // Expected for illegal run limit
- return;
- }
-
- fail("Expected IllegalArgumentException to be thrown for invalid run limit");
- }
-
}
diff --git a/harmony-tests/src/test/java/org/apache/harmony/tests/java/text/CollationElementIteratorTest.java b/harmony-tests/src/test/java/org/apache/harmony/tests/java/text/CollationElementIteratorTest.java
index 2330cd8..dc0f4b7 100644
--- a/harmony-tests/src/test/java/org/apache/harmony/tests/java/text/CollationElementIteratorTest.java
+++ b/harmony-tests/src/test/java/org/apache/harmony/tests/java/text/CollationElementIteratorTest.java
@@ -1,13 +1,13 @@
-/*
+/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -27,178 +27,178 @@ import junit.framework.TestCase;
/**
* Test CollationElementIterator
- *
+ *
* Only test normal condition.
- *
+ *
*/
public class CollationElementIteratorTest extends TestCase {
- private RuleBasedCollator coll;
-
- protected void setUp() {
- coll = (RuleBasedCollator) Collator.getInstance(Locale.US);
- }
-
- public void testGetOffset() {
- String text = "abc";
- CollationElementIterator iterator = coll
- .getCollationElementIterator(text);
- int[] offsets = { 0, 1, 2, 3 };
- int offset = iterator.getOffset();
- int i = 0;
- assertEquals(offsets[i++], offset);
- while (offset != text.length()) {
- iterator.next();
- offset = iterator.getOffset();
- assertEquals(offsets[i++], offset);
- }
- }
-
- public void testNext() {
- String text = "abc";
- CollationElementIterator iterator = coll
- .getCollationElementIterator(text);
- int[] orders = new int[text.length()];
- int order = iterator.next();
- int i = 0;
- while (order != CollationElementIterator.NULLORDER) {
- orders[i++] = order;
- order = iterator.next();
- }
-
- int offset = iterator.getOffset();
- assertEquals(text.length(), offset);
- order = iterator.previous();
-
- while (order != CollationElementIterator.NULLORDER) {
- assertEquals(orders[--i], order);
- order = iterator.previous();
- }
-
- assertEquals(0, iterator.getOffset());
- }
-
- public void testReset() {
- String text = "abc";
- CollationElementIterator iterator = coll
- .getCollationElementIterator(text);
- int[] orders = new int[text.length()];
- int order = iterator.next();
- int i = 0;
- while (order != CollationElementIterator.NULLORDER) {
- orders[i++] = order;
- order = iterator.next();
- }
-
- int offset = iterator.getOffset();
- assertEquals(text.length(), offset);
-
- iterator.reset();
- assertEquals(0, iterator.getOffset());
- }
-
- public void testGetMaxExpansion() {
- String text = "cha";
- RuleBasedCollator rbColl = (RuleBasedCollator) Collator
- .getInstance(new Locale("es", "", "TRADITIONAL"));
- CollationElementIterator iterator = rbColl
- .getCollationElementIterator(text);
- int order = iterator.next();
- while (order != CollationElementIterator.NULLORDER) {
- assertEquals(1, iterator.getMaxExpansion(order));
- order = iterator.next();
- }
-
- }
-
- public void testPrimaryOrder() {
- RuleBasedCollator rbColl = (RuleBasedCollator) Collator
- .getInstance(new Locale("de", "DE"));
- String text = "\u00e6";
- CollationElementIterator iterator = rbColl
- .getCollationElementIterator(text);
- int order = iterator.next();
- int pOrder = CollationElementIterator.primaryOrder(order);
- CollationElementIterator iterator2 = rbColl
- .getCollationElementIterator("ae");
- int order2 = iterator2.next();
- int pOrder2 = CollationElementIterator.primaryOrder(order2);
- assertEquals(pOrder, pOrder2);
- }
-
- public void testSecondaryOrder() {
- RuleBasedCollator rbColl = (RuleBasedCollator) Collator
- .getInstance(new Locale("fr", "FR"));
- String text = "a\u00e0";
- CollationElementIterator iterator = rbColl
- .getCollationElementIterator(text);
- int order = iterator.next();
- int sOrder1 = CollationElementIterator.secondaryOrder(order);
-
- order = iterator.next();
- int sOrder2 = CollationElementIterator.secondaryOrder(order);
-
- assertEquals(sOrder1, sOrder2);
- }
-
- public void testTertiaryOrder() {
- RuleBasedCollator rbColl = (RuleBasedCollator) Collator
- .getInstance(new Locale("fr", "FR"));
- String text = "abAB";
- CollationElementIterator iterator = rbColl
- .getCollationElementIterator(text);
- int order = iterator.next();
- int tOrder1 = CollationElementIterator.tertiaryOrder(order);
- order = iterator.next();
- int tOrder2 = CollationElementIterator.tertiaryOrder(order);
- assertEquals(tOrder1, tOrder2);
-
- order = iterator.next();
- tOrder1 = CollationElementIterator.tertiaryOrder(order);
- order = iterator.next();
- tOrder2 = CollationElementIterator.tertiaryOrder(order);
- assertEquals(tOrder1, tOrder2);
- }
-
- public void testSetOffset() {
- RuleBasedCollator rbColl = (RuleBasedCollator) Collator
- .getInstance(new Locale("es", "", "TRADITIONAL"));
- String text = "cha";
- CollationElementIterator iterator = rbColl
- .getCollationElementIterator(text);
- iterator.setOffset(1);
- assertEquals(0, iterator.getOffset());
- }
-
- /*
- * Class under test for void setText(java.lang.String)
- */
- public void testSetTextString() {
- RuleBasedCollator rbColl = (RuleBasedCollator) Collator
- .getInstance(new Locale("es", "", "TRADITIONAL"));
- String text = "caa";
- CollationElementIterator iterator = rbColl
- .getCollationElementIterator(text);
- iterator.setOffset(1);
- assertEquals(1, iterator.getOffset());
- iterator.setText("cha");
- iterator.setOffset(1);
- assertEquals(0, iterator.getOffset());
- }
-
- /*
- * Class under test for void setText(java.text.CharacterIterator)
- */
- public void testSetTextCharacterIterator() {
- RuleBasedCollator rbColl = (RuleBasedCollator) Collator
- .getInstance(new Locale("es", "", "TRADITIONAL"));
- String text = "caa";
- CollationElementIterator iterator = rbColl
- .getCollationElementIterator(text);
- iterator.setOffset(1);
- assertEquals(1, iterator.getOffset());
- iterator.setText(new StringCharacterIterator("cha"));
- iterator.setOffset(1);
- assertEquals(0, iterator.getOffset());
- }
+ private RuleBasedCollator coll;
+
+ protected void setUp() {
+ coll = (RuleBasedCollator) Collator.getInstance(Locale.US);
+ }
+
+ public void testGetOffset() {
+ String text = "abc";
+ CollationElementIterator iterator = coll.getCollationElementIterator(text);
+ int[] offsets = { 0, 1, 2, 3 };
+ int offset = iterator.getOffset();
+ int i = 0;
+ assertEquals(offsets[i++], offset);
+ while (offset != text.length()) {
+ iterator.next();
+ offset = iterator.getOffset();
+ assertEquals(offsets[i++], offset);
+ }
+ }
+
+ public void testNext() {
+ String text = "abc";
+ CollationElementIterator iterator = coll.getCollationElementIterator(text);
+ int[] orders = new int[text.length()];
+ int order = iterator.next();
+ int i = 0;
+ while (order != CollationElementIterator.NULLORDER) {
+ orders[i++] = order;
+ order = iterator.next();
+ }
+
+ int offset = iterator.getOffset();
+ assertEquals(text.length(), offset);
+ order = iterator.previous();
+
+ while (order != CollationElementIterator.NULLORDER) {
+ assertEquals(orders[--i], order);
+ order = iterator.previous();
+ }
+
+ assertEquals(0, iterator.getOffset());
+ }
+
+ public void testPrevious() {
+ RuleBasedCollator coll = (RuleBasedCollator) Collator.getInstance(Locale.US);
+ String text = "abc";
+ CollationElementIterator iterator = coll
+ .getCollationElementIterator(text);
+ int[] orders = new int[text.length()];
+ int order = iterator.next();
+ int i = 0;
+ while (order != CollationElementIterator.NULLORDER) {
+ orders[i++] = order;
+ order = iterator.next();
+ }
+
+ int offset = iterator.getOffset();
+ assertEquals(text.length(), offset);
+ order = iterator.previous();
+
+ while (order != CollationElementIterator.NULLORDER) {
+ assertEquals(orders[--i], order);
+ order = iterator.previous();
+ }
+
+ assertEquals(0, iterator.getOffset());
+ }
+
+ public void testReset() {
+ String text = "abc";
+ CollationElementIterator iterator = coll.getCollationElementIterator(text);
+ int[] orders = new int[text.length()];
+ int order = iterator.next();
+ int i = 0;
+ while (order != CollationElementIterator.NULLORDER) {
+ orders[i++] = order;
+ order = iterator.next();
+ }
+
+ int offset = iterator.getOffset();
+ assertEquals(text.length(), offset);
+
+ iterator.reset();
+ assertEquals(0, iterator.getOffset());
+ }
+
+ public void testGetMaxExpansion() {
+ String text = "cha";
+ RuleBasedCollator rbColl = (RuleBasedCollator) Collator.getInstance(new Locale("es", "", "TRADITIONAL"));
+ CollationElementIterator iterator = rbColl.getCollationElementIterator(text);
+ int order = iterator.next();
+ while (order != CollationElementIterator.NULLORDER) {
+ assertEquals(1, iterator.getMaxExpansion(order));
+ order = iterator.next();
+ }
+ }
+
+ public void testPrimaryOrder() {
+ RuleBasedCollator rbColl = (RuleBasedCollator) Collator.getInstance(new Locale("de", "DE"));
+ String text = "\u00e6";
+ CollationElementIterator iterator = rbColl.getCollationElementIterator(text);
+ int order = iterator.next();
+ int pOrder = CollationElementIterator.primaryOrder(order);
+ CollationElementIterator iterator2 = rbColl.getCollationElementIterator("ae");
+ int order2 = iterator2.next();
+ int pOrder2 = CollationElementIterator.primaryOrder(order2);
+ assertEquals(pOrder, pOrder2);
+ }
+
+ public void testSecondaryOrder() {
+ RuleBasedCollator rbColl = (RuleBasedCollator) Collator.getInstance(new Locale("fr", "FR"));
+ String text = "a\u00e0";
+ CollationElementIterator iterator = rbColl.getCollationElementIterator(text);
+ int order = iterator.next();
+ int sOrder1 = CollationElementIterator.secondaryOrder(order);
+
+ order = iterator.next();
+ int sOrder2 = CollationElementIterator.secondaryOrder(order);
+
+ assertEquals(sOrder1, sOrder2);
+ }
+
+ public void testTertiaryOrder() {
+ RuleBasedCollator rbColl = (RuleBasedCollator) Collator.getInstance(new Locale("fr", "FR"));
+ String text = "abAB";
+ CollationElementIterator iterator = rbColl.getCollationElementIterator(text);
+ int order = iterator.next();
+ int tOrder1 = CollationElementIterator.tertiaryOrder(order);
+ order = iterator.next();
+ int tOrder2 = CollationElementIterator.tertiaryOrder(order);
+ assertEquals(tOrder1, tOrder2);
+
+ order = iterator.next();
+ tOrder1 = CollationElementIterator.tertiaryOrder(order);
+ order = iterator.next();
+ tOrder2 = CollationElementIterator.tertiaryOrder(order);
+ assertEquals(tOrder1, tOrder2);
+ }
+
+ public void testSetOffset() {
+ RuleBasedCollator rbColl = (RuleBasedCollator) Collator.getInstance(new Locale("es", "", "TRADITIONAL"));
+ String text = "cha";
+ CollationElementIterator iterator = rbColl.getCollationElementIterator(text);
+ iterator.setOffset(1);
+ assertEquals(1, iterator.getOffset());
+ }
+
+ public void testSetTextString() {
+ RuleBasedCollator rbColl = (RuleBasedCollator) Collator.getInstance(new Locale("es", "", "TRADITIONAL"));
+ String text = "caa";
+ CollationElementIterator iterator = rbColl.getCollationElementIterator(text);
+ iterator.setOffset(1);
+ assertEquals(1, iterator.getOffset());
+ iterator.setText("cha");
+ iterator.setOffset(1);
+ assertEquals(1, iterator.getOffset());
+ }
+
+ public void testSetTextCharacterIterator() {
+ RuleBasedCollator rbColl = (RuleBasedCollator) Collator.getInstance(new Locale("es", "", "TRADITIONAL"));
+ String text = "caa";
+ CollationElementIterator iterator = rbColl.getCollationElementIterator(text);
+ iterator.setOffset(1);
+ assertEquals(1, iterator.getOffset());
+ iterator.setText(new StringCharacterIterator("cha"));
+ iterator.setOffset(1);
+ assertEquals(1, iterator.getOffset());
+ }
}
diff --git a/harmony-tests/src/test/java/org/apache/harmony/tests/java/text/DateFormatSymbolsTest.java b/harmony-tests/src/test/java/org/apache/harmony/tests/java/text/DateFormatSymbolsTest.java
index 34dc1c2..9fe3681 100644
--- a/harmony-tests/src/test/java/org/apache/harmony/tests/java/text/DateFormatSymbolsTest.java
+++ b/harmony-tests/src/test/java/org/apache/harmony/tests/java/text/DateFormatSymbolsTest.java
@@ -1,13 +1,13 @@
-/*
+/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -73,45 +73,22 @@ public class DateFormatSymbolsTest extends junit.framework.TestCase {
assertEquals(new DateFormatSymbols(), DateFormatSymbols.getInstance());
assertEquals(new DateFormatSymbols(Locale.getDefault()),
DateFormatSymbols.getInstance());
-
+
assertNotSame(DateFormatSymbols.getInstance(), DateFormatSymbols.getInstance());
}
public void test_getInstanceLjava_util_Locale() {
try {
DateFormatSymbols.getInstance(null);
- fail("Should throw NullPointerException");
- } catch (NullPointerException e) {
- // expected
- }
-
- assertEquals(new DateFormatSymbols(Locale.GERMANY), DateFormatSymbols
- .getInstance(Locale.GERMANY));
-
- Locale locale = new Locale("not exist language", "not exist country");
- DateFormatSymbols symbols = DateFormatSymbols.getInstance(locale);
- assertNotNull(symbols);
- assertEquals(DateFormatSymbols.getInstance(), symbols);
- }
-
- /**
- * @tests java.text.DateFormatSymbols#getInstance(Locale)
- */
- public void test_getInstanceLjava_util_Locale_no_provider() {
- try {
- DateFormatSymbols.getInstance(null);
- fail("Should throw NullPointerException");
- } catch (NullPointerException e) {
- // expected
+ fail();
+ } catch (NullPointerException expected) {
}
- assertEquals(new DateFormatSymbols(Locale.GERMANY), DateFormatSymbols
- .getInstance(Locale.GERMANY));
+ assertEquals(new DateFormatSymbols(Locale.GERMANY), DateFormatSymbols.getInstance(Locale.GERMANY));
Locale locale = new Locale("not exist language", "not exist country");
DateFormatSymbols symbols = DateFormatSymbols.getInstance(locale);
assertNotNull(symbols);
- assertEquals(DateFormatSymbols.getInstance(), symbols);
}
/**
@@ -165,19 +142,6 @@ public class DateFormatSymbolsTest extends junit.framework.TestCase {
}
/**
- * @tests java.text.DateFormatSymbols#getLocalPatternChars()
- */
- public void test_getLocalPatternChars() {
- // Test for method java.lang.String
- // java.text.DateFormatSymbols.getLocalPatternChars()
- String retVal = dfs.getLocalPatternChars();
-
- String val = "GyMdkHmsSEDFwWahKzYeugAZvcLQqV";
-
- assertEquals("Returned incorrect pattern string", val, retVal);
- }
-
- /**
* @tests java.text.DateFormatSymbols#getMonths()
*/
public void test_getMonths() {
@@ -241,7 +205,7 @@ public class DateFormatSymbolsTest extends junit.framework.TestCase {
public void test_getZoneStrings() {
// Test for method java.lang.String [][]
// java.text.DateFormatSymbols.getZoneStrings()
- String[][] val = { { "XX", "XX", "XX", "XX", "XX" },
+ String[][] val = { { "XX", "XX", "XX", "XX", "XX" },
{ "YY", "YY", "YY", "YY", "YY" } };
dfs.setZoneStrings(val);
String[][] retVal = dfs.getZoneStrings();
@@ -261,7 +225,7 @@ public class DateFormatSymbolsTest extends junit.framework.TestCase {
int hc2 = dfs.hashCode();
assertTrue("hashCode() returned inconsistent number : " + hc1 + " - " + hc2, hc1 == hc2);
- assertTrue("hashCode() returns different values for equal() objects",
+ assertTrue("hashCode() returns different values for equal() objects",
dfs.hashCode() == dfs.clone().hashCode());
}
@@ -295,23 +259,16 @@ public class DateFormatSymbolsTest extends junit.framework.TestCase {
assertTrue("Failed to set strings", retVal[i].equals(val[i]));
}
- /**
- * @tests java.text.DateFormatSymbols#setLocalPatternChars(java.lang.String)
- */
public void test_setLocalPatternCharsLjava_lang_String() {
- // Test for method void
- // java.text.DateFormatSymbols.setLocalPatternChars(java.lang.String)
- dfs.setLocalPatternChars("GyMZZkHmsSEHHFwWahKz");
- String retVal = dfs.getLocalPatternChars();
- String val = "GyMZZkHmsSEHHFwWahKz";
- assertTrue("Returned incorrect pattern string", retVal.equals(val));
-
+ String patternChars = "GyMZZkHmsSEHHFwWahKz";
+ dfs.setLocalPatternChars(patternChars);
+ assertEquals(patternChars, dfs.getLocalPatternChars());
+
try {
// Regression for HARMONY-466
new DateFormatSymbols().setLocalPatternChars(null);
- fail("NullPointerException expected");
- } catch (NullPointerException e) {
- // expected
+ fail();
+ } catch (NullPointerException expected) {
}
}
@@ -401,7 +358,7 @@ public class DateFormatSymbolsTest extends junit.framework.TestCase {
/**
* @tests java.text.DateFormatSymbols#setZoneStrings(java.lang.String[][])
- *
+ *
* Tests setting zone strings to invalid values
* Regression for HARMONY-6337
*/
diff --git a/harmony-tests/src/test/java/org/apache/harmony/tests/java/text/DecimalFormatSymbolsTest.java b/harmony-tests/src/test/java/org/apache/harmony/tests/java/text/DecimalFormatSymbolsTest.java
index ef9d489..14c2e2e 100644
--- a/harmony-tests/src/test/java/org/apache/harmony/tests/java/text/DecimalFormatSymbolsTest.java
+++ b/harmony-tests/src/test/java/org/apache/harmony/tests/java/text/DecimalFormatSymbolsTest.java
@@ -1,13 +1,13 @@
-/*
+/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -82,48 +82,22 @@ public class DecimalFormatSymbolsTest extends TestCase {
assertEquals(new DecimalFormatSymbols(), DecimalFormatSymbols.getInstance());
assertEquals(new DecimalFormatSymbols(Locale.getDefault()),
DecimalFormatSymbols.getInstance());
-
+
assertNotSame(DecimalFormatSymbols.getInstance(), DecimalFormatSymbols.getInstance());
}
- /**
- * @tests java.text.DecimalFormatSymbols#getInstance(Locale)
- */
public void test_getInstanceLjava_util_Locale() {
try {
DecimalFormatSymbols.getInstance(null);
- fail("Should throw NullPointerException");
- } catch (NullPointerException e) {
- // expected
+ fail();
+ } catch (NullPointerException expected) {
}
- assertEquals(new DecimalFormatSymbols(Locale.GERMANY), DecimalFormatSymbols
- .getInstance(Locale.GERMANY));
+ assertEquals(new DecimalFormatSymbols(Locale.GERMANY), DecimalFormatSymbols.getInstance(Locale.GERMANY));
Locale locale = new Locale("not exist language", "not exist country");
DecimalFormatSymbols symbols = DecimalFormatSymbols.getInstance(locale);
assertNotNull(symbols);
- assertEquals(DecimalFormatSymbols.getInstance(), symbols);
- }
-
- /**
- * @tests java.text.DecimalFormatSymbols#getInstance(Locale)
- */
- public void test_getInstanceLjava_util_Locale_no_provider() {
- try {
- DecimalFormatSymbols.getInstance(null);
- fail("Should throw NullPointerException");
- } catch (NullPointerException e) {
- // expected
- }
-
- assertEquals(new DecimalFormatSymbols(Locale.GERMANY), DecimalFormatSymbols
- .getInstance(Locale.GERMANY));
-
- Locale locale = new Locale("not exist language", "not exist country");
- DecimalFormatSymbols symbols = DecimalFormatSymbols.getInstance(locale);
- assertNotNull(symbols);
- assertEquals(DecimalFormatSymbols.getInstance(), symbols);
}
/**
@@ -522,7 +496,7 @@ public class DecimalFormatSymbolsTest extends TestCase {
}
assertDecimalFormatSymbolsRIFrance(dfs);
}
-
+
static void assertDecimalFormatSymbolsRIFrance(DecimalFormatSymbols dfs) {
// Values based on Java 1.5 RI DecimalFormatSymbols for Locale.FRANCE
/*
@@ -567,7 +541,7 @@ public class DecimalFormatSymbolsTest extends TestCase {
symbols.setNaN("NaN");
SerializationTest.verifyGolden(this, symbols);
}
-
+
/**
* @tests serialization/deserialization compatibility.
*/
diff --git a/harmony-tests/src/test/java/org/apache/harmony/tests/java/text/DecimalFormatTest.java b/harmony-tests/src/test/java/org/apache/harmony/tests/java/text/DecimalFormatTest.java
index c0b2c96..2e3761a 100644
--- a/harmony-tests/src/test/java/org/apache/harmony/tests/java/text/DecimalFormatTest.java
+++ b/harmony-tests/src/test/java/org/apache/harmony/tests/java/text/DecimalFormatTest.java
@@ -1,13 +1,13 @@
-/*
+/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -38,33 +38,55 @@ import org.apache.harmony.testframework.serialization.SerializationTest;
public class DecimalFormatTest extends TestCase {
+ // https://code.google.com/p/android/issues/detail?id=59600
+ public void test_empty_NaN() throws Exception {
+ DecimalFormatSymbols dfs = new DecimalFormatSymbols();
+ dfs.setNaN("");
+ DecimalFormat df = new DecimalFormat();
+ df.setDecimalFormatSymbols(dfs);
+ df.format(Double.NaN);
+ }
+
public void testAttributedCharacterIterator() throws Exception {
// Regression for http://issues.apache.org/jira/browse/HARMONY-333
AttributedCharacterIterator iterator = new DecimalFormat().formatToCharacterIterator(new Integer(1));
assertNotNull(iterator);
assertFalse("attributes should exist", iterator.getAttributes().isEmpty());
- }
-
- /*
- * Test the getter and setter of parseBigDecimal and parseIntegerOnly and
- * test the default value of them.
- */
- public void test_isParseBigDecimalLjava_lang_Boolean_isParseIntegerOnlyLjava_lang_Boolean() {
-
- // parseBigDecimal default to false
- DecimalFormat form = (DecimalFormat) DecimalFormat.getInstance(Locale.US);
- assertFalse(form.isParseBigDecimal());
- form.setParseBigDecimal(true);
- assertTrue(form.isParseBigDecimal());
- form.setParseBigDecimal(false);
- assertFalse(form.isParseBigDecimal());
+ }
- // parseIntegerOnly default to false
- assertFalse(form.isParseIntegerOnly());
+ public void test_isParseBigDecimalLjava_lang_Boolean_isParseIntegerOnlyLjava_lang_Boolean() throws Exception {
+ // parseBigDecimal default to false
+ DecimalFormat form = (DecimalFormat) DecimalFormat.getInstance(Locale.US);
+ assertFalse(form.isParseBigDecimal());
+ form.setParseBigDecimal(true);
+ assertTrue(form.isParseBigDecimal());
+
+ Number result = form.parse("123.123");
+ assertEquals(new BigDecimal("123.123"), result);
+
+ form.setParseBigDecimal(false);
+ assertFalse(form.isParseBigDecimal());
+
+ result = form.parse("123.123");
+ assertFalse(result instanceof BigDecimal);
}
- // Test the type of the returned object
+ public void test_isParseIntegerOnly() throws Exception {
+ DecimalFormat format = new DecimalFormat();
+ assertFalse("Default value of isParseIntegerOnly is true", format.isParseIntegerOnly());
+
+ format.setParseIntegerOnly(true);
+ assertTrue(format.isParseIntegerOnly());
+ Number result = format.parse("123.123");
+ assertEquals(new Long("123"), result);
+ format.setParseIntegerOnly(false);
+ assertFalse(format.isParseIntegerOnly());
+ result = format.parse("123.123");
+ assertEquals(new Double("123.123"), result);
+ }
+
+ // Test the type of the returned object
public void test_parseLjava_lang_String_Ljava_text_ParsePosition() {
DecimalFormat form = (DecimalFormat) DecimalFormat.getInstance(Locale.US);
Number number = form.parse("23.1", new ParsePosition(0));
@@ -83,9 +105,8 @@ public class DecimalFormatTest extends TestCase {
assertTrue(number instanceof BigDecimal);
assertEquals(new BigDecimal("23.1"), number);
- // When parseIntegerOnly set to true, all float numbers will be parsed
- // into Long.
- // With the exception that, the value is out of the bound of Long or
+ // When parseIntegerOnly set to true, all numbers will be parsed
+ // into Long unless the value is out of the bound of Long or
// some special values such as NaN or Infinity.
form = (DecimalFormat) DecimalFormat.getInstance(Locale.US);
@@ -101,9 +122,16 @@ public class DecimalFormatTest extends TestCase {
assertTrue(number instanceof Long);
assertTrue(new Long(0).equals(number));
- number = form.parse("-9,223,372,036,854,775,8080.00",
- new ParsePosition(0));
- assertTrue(number instanceof Double);
+ // The last integers representable by long.
+ number = form.parse("9223372036854775807.00", new ParsePosition(0));
+ assertEquals(Long.class, number.getClass());
+ number = form.parse("9223372036854775808.00", new ParsePosition(0));
+ assertEquals(Double.class, number.getClass());
+ // The first integers that need to be represented by double.
+ number = form.parse("-9223372036854775808.00", new ParsePosition(0));
+ assertEquals(Long.class, number.getClass());
+ number = form.parse("-9223372036854775809.00", new ParsePosition(0));
+ assertEquals(Double.class, number.getClass());
// Even if parseIntegerOnly is set to true, NaN will be parsed to Double
@@ -135,8 +163,7 @@ public class DecimalFormatTest extends TestCase {
number = form.parse("23.0", new ParsePosition(0));
assertTrue(number instanceof BigDecimal);
- number = form.parse("-9,223,372,036,854,775,8080.00",
- new ParsePosition(0));
+ number = form.parse("-92,233,720,368,547,758,080.00", new ParsePosition(0));
assertFalse(number instanceof BigInteger);
assertTrue(number instanceof BigDecimal);
@@ -278,7 +305,7 @@ public class DecimalFormatTest extends TestCase {
assertTrue(number instanceof Double);
assertEquals("9.223372036854776E18", number.toString());
- number = form.parse("-9,223,372,036,854,775,8080.00",
+ number = form.parse("-92,233,720,368,547,758,080.00",
new ParsePosition(0));
assertTrue(number instanceof Double);
assertEquals("-9.223372036854776E19", number.toString());
@@ -296,8 +323,7 @@ public class DecimalFormatTest extends TestCase {
assertEquals(9.223372036854776E18, number.doubleValue(), 0);
- number = form.parse("-9,223,372,036,854,775,8080.00",
- new ParsePosition(0));
+ number = form.parse("-92,233,720,368,547,758,080.00", new ParsePosition(0));
assertTrue(number instanceof BigDecimal);
assertEquals(-9.223372036854776E19, number.doubleValue(), 0);
@@ -332,6 +358,24 @@ public class DecimalFormatTest extends TestCase {
}
}
+ public void test_parseLjava_lang_String_Ljava_text_ParsePosition_2() {
+ DecimalFormat form = (DecimalFormat) DecimalFormat.getInstance(Locale.US);
+ form.setParseIntegerOnly(true);
+ form.setParseBigDecimal(true);
+
+ final String doubleMax2 = "359,538,626,972,463,141,629,054,847,463,408,"
+ + "713,596,141,135,051,689,993,197,834,953,606,314,521,560,057,077,"
+ + "521,179,117,265,533,756,343,080,917,907,028,764,928,468,642,653,"
+ + "778,928,365,536,935,093,407,075,033,972,099,821,153,102,564,152,"
+ + "490,980,180,778,657,888,151,737,016,910,267,884,609,166,473,806,"
+ + "445,896,331,617,118,664,246,696,549,595,652,408,289,446,337,476,"
+ + "354,361,838,599,762,500,808,052,368,249,716,736";
+ Number number = form.parse(doubleMax2, new ParsePosition(0));
+ assertTrue(number instanceof BigDecimal);
+ BigDecimal result = (BigDecimal)number;
+ assertEquals(new BigDecimal(Double.MAX_VALUE).add(new BigDecimal(Double.MAX_VALUE)), result);
+ }
+
public void test_getMaximumFractionDigits() {
NumberFormat nform = DecimalFormat.getInstance(Locale.US);
DecimalFormat form = (DecimalFormat) nform;
@@ -483,17 +527,9 @@ public class DecimalFormatTest extends TestCase {
}
try {
- form.format(new Double(1.4), null, null);
- fail("Should throw NPE");
- } catch (NullPointerException e) {
- // expected
- }
-
- try {
- form.format(new Object(), null, null);
- fail("Should throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- // expected
+ form.format(new Object(), new StringBuffer(), new FieldPosition(0));
+ fail();
+ } catch (IllegalArgumentException expected) {
}
FieldPosition pos;
@@ -696,38 +732,136 @@ public class DecimalFormatTest extends TestCase {
assertEquals(format, cloned);
}
- public void test_setPositivePrefixLjava_lang_String() {
- DecimalFormat format = new DecimalFormat();
- assertEquals("", format.getPositivePrefix());
+ public void test_getNegativePrefix() {
+ DecimalFormat df = new DecimalFormat();
+ df.setNegativePrefix("--");
+ assertTrue("Incorrect negative prefix", df.getNegativePrefix().equals("--"));
}
- public void test_setPositiveSuffixLjava_lang_String() {
- DecimalFormat format = new DecimalFormat();
- assertEquals("", format.getPositiveSuffix());
+ public void test_getNegativeSuffix() {
+ DecimalFormat df = new DecimalFormat();
+ df.setNegativeSuffix("&");
+ assertTrue("Incorrect negative suffix", df.getNegativeSuffix().equals("&"));
}
- public void test_setNegativePrefixLjava_lang_String() {
- DecimalFormat format = new DecimalFormat();
- assertEquals("-", format.getNegativePrefix());
+ public void test_getPositivePrefix() {
+ DecimalFormat df = new DecimalFormat();
+ df.setPositivePrefix("++");
+ assertTrue("Incorrect positive prefix", df.getPositivePrefix().equals("++"));
}
- public void test_setNegativeSuffixLjava_lang_String() {
- DecimalFormat format = new DecimalFormat();
- assertEquals("", format.getNegativeSuffix());
+ public void test_getPositiveSuffix() {
+ DecimalFormat df = new DecimalFormat();
+ df.setPositiveSuffix("%");
+ assertTrue("Incorrect positive prefix", df.getPositiveSuffix().equals("%"));
+ }
+
+ public void test_setPositivePrefixLjava_lang_String() throws Exception {
+ DecimalFormat format = new DecimalFormat();
+ assertEquals("", format.getPositivePrefix());
+
+ format.setPositivePrefix("PosPrf");
+ assertEquals("PosPrf", format.getPositivePrefix());
+ assertTrue(format.parse("PosPrf123.45").doubleValue() == 123.45);
+
+ format.setPositivePrefix("");
+ assertEquals("", format.getPositivePrefix());
+
+ format.setPositivePrefix(null);
+ assertNull(format.getPositivePrefix());
+ }
+
+ public void test_setPositiveSuffixLjava_lang_String() throws Exception {
+ DecimalFormat format = new DecimalFormat();
+ assertEquals("", format.getPositiveSuffix());
+
+ format.setPositiveSuffix("PosSfx");
+ assertEquals("PosSfx", format.getPositiveSuffix());
+ assertTrue(format.parse("123.45PosSfx").doubleValue() == 123.45);
+
+ format.setPositiveSuffix("");
+ assertEquals("", format.getPositiveSuffix());
+
+ format.setPositiveSuffix(null);
+ assertNull(format.getPositiveSuffix());
+ }
+
+ public void test_setNegativePrefixLjava_lang_String() throws Exception {
+ DecimalFormat format = new DecimalFormat();
+ assertEquals("-", format.getNegativePrefix());
+
+ format.setNegativePrefix("NegPrf");
+ assertEquals("NegPrf", format.getNegativePrefix());
+ assertTrue(format.parse("NegPrf123.45").doubleValue() == -123.45);
+ format.setNegativePrefix("");
+ assertEquals("", format.getNegativePrefix());
+
+ format.setNegativePrefix(null);
+ assertNull(format.getNegativePrefix());
+ }
+
+ public void test_setNegativeSuffixLjava_lang_String() throws Exception {
+ DecimalFormat format = new DecimalFormat();
+ assertEquals("", format.getNegativeSuffix());
+
+ format.setNegativeSuffix("NegSfx");
+ assertEquals("NegSfx", format.getNegativeSuffix());
+ assertTrue(format.parse("123.45NegPfx").doubleValue() == 123.45);
+
+ format.setNegativeSuffix("");
+ assertEquals("", format.getNegativeSuffix());
+
+ format.setNegativeSuffix(null);
+ assertNull(format.getNegativeSuffix());
}
public void test_setGroupingUse() {
- DecimalFormat format = new DecimalFormat();
- StringBuffer buf = new StringBuffer();
- format.setGroupingUsed(false);
- format.format(new Long(1970), buf, new FieldPosition(0));
- assertEquals("1970", buf.toString());
- assertFalse(format.isGroupingUsed());
+ DecimalFormat format = new DecimalFormat();
+
+ StringBuffer buf = new StringBuffer();
+ format.setGroupingUsed(false);
+ format.format(new Long(1970), buf, new FieldPosition(0));
+ assertEquals("1970", buf.toString());
+ assertFalse(format.isGroupingUsed());
+ format.format(new Long(1970), buf, new FieldPosition(0));
+ assertEquals("19701970", buf.toString());
+ assertFalse(format.isGroupingUsed());
+
+ format.setGroupingUsed(true);
+ format.format(new Long(1970), buf, new FieldPosition(0));
+ assertEquals("197019701,970", buf.toString());
+ assertTrue(format.isGroupingUsed());
+ }
+
+ public void test_isGroupingUsed() {
+ assertFalse(new DecimalFormat("####.##").isGroupingUsed());
+ assertFalse(new DecimalFormat("######.######").isGroupingUsed());
+ assertFalse(new DecimalFormat("000000.000000").isGroupingUsed());
+ assertFalse(new DecimalFormat("######.000000").isGroupingUsed());
+ assertFalse(new DecimalFormat("000000.######").isGroupingUsed());
+ assertFalse(new DecimalFormat(" ###.###").isGroupingUsed());
+ assertFalse(new DecimalFormat("$#####.######").isGroupingUsed());
+ assertFalse(new DecimalFormat("$$####.######").isGroupingUsed());
+
+ assertTrue(new DecimalFormat("###,####").isGroupingUsed());
+ }
+
+ public void test_Constructor() {
+ // Test for method java.text.DecimalFormat()
+ // the constructor form that specifies a pattern is equal to the form
+ // constructed with no pattern and applying that pattern using the
+ // applyPattern call
+ DecimalFormat format1 = new DecimalFormat();
+ format1.applyPattern("'$'1000.0000");
+ DecimalFormat format2 = new DecimalFormat();
+ format2.applyPattern("'$'1000.0000");
+ assertTrue("Constructed format did not match applied format object", format2.equals(format1));
+ DecimalFormat format3 = new DecimalFormat("'$'1000.0000");
+ assertTrue("Constructed format did not match applied format object", format3.equals(format1));
+ DecimalFormat format4 = new DecimalFormat("'$'8000.0000");
+ assertTrue("Constructed format did not match applied format object", !format4.equals(format1));
}
- /**
- * @tests java.text.DecimalFormat#DecimalFormat(java.lang.String)
- */
public void test_ConstructorLjava_lang_String() {
// Test for method java.text.DecimalFormat(java.lang.String)
// the constructor form that specifies a pattern is equal to the form
@@ -736,13 +870,75 @@ public class DecimalFormatTest extends TestCase {
DecimalFormat format = new DecimalFormat("'$'0000.0000");
DecimalFormat format1 = new DecimalFormat();
format1.applyPattern("'$'0000.0000");
- assertTrue("Constructed format did not match applied format object",
- format.equals(format1));
+ assertTrue("Constructed format did not match applied format object", format.equals(format1));
+
+ new DecimalFormat("####.##");
+ new DecimalFormat("######.######");
+ new DecimalFormat("000000.000000");
+ new DecimalFormat("######.000000");
+ new DecimalFormat("000000.######");
+ new DecimalFormat(" ###.###");
+ new DecimalFormat("$#####.######");
+ new DecimalFormat("$$####.######");
+ new DecimalFormat("%#,##,###,####");
+ new DecimalFormat("#,##0.00;(#,##0.00)");
+
+ try {
+ new DecimalFormat(null);
+ fail();
+ } catch (NullPointerException expected) {
+ }
+
+ try {
+ new DecimalFormat("%#,##,###,####'");
+ fail();
+ } catch (IllegalArgumentException expected) {
+ }
+
+ try {
+ new DecimalFormat("#.##0.00");
+ fail();
+ } catch (IllegalArgumentException expected) {
+ }
+ }
+
+ public void test_ConstructorLjava_lang_StringLjava_text_DecimalFormatSymbols() {
+ // case 1: Try to construct object using correct pattern and format
+ // symbols.
+ DecimalFormatSymbols dfs = new DecimalFormatSymbols(Locale.CANADA);
+ DecimalFormat format1 = new DecimalFormat("'$'1000.0000", dfs);
+ DecimalFormat format2 = new DecimalFormat();
+ format2.applyPattern("'$'1000.0000");
+ format2.setDecimalFormatSymbols(dfs);
+ assertTrue("Constructed format did not match applied format object", format2.equals(format1));
+ assertTrue("Constructed format did not match applied format object",
+ !format1.equals(new DecimalFormat("'$'1000.0000", new DecimalFormatSymbols(Locale.CHINA))));
+
+ // case 2: Try to construct object using null arguments.
+ try {
+ new DecimalFormat("'$'1000.0000", (DecimalFormatSymbols) null);
+ fail();
+ } catch (NullPointerException expected) {
+ }
+ try {
+ new DecimalFormat(null, new DecimalFormatSymbols());
+ fail();
+ } catch (NullPointerException expected) {
+ }
+ try {
+ new DecimalFormat(null, (DecimalFormatSymbols) null);
+ fail();
+ } catch (NullPointerException expected) {
+ }
+
+ // case 3: Try to construct object using incorrect pattern.
+ try {
+ new DecimalFormat("$'", new DecimalFormatSymbols());
+ fail();
+ } catch (IllegalArgumentException expected) {
+ }
}
- /**
- * @tests java.text.DecimalFormat#applyPattern(java.lang.String)
- */
public void test_applyPatternLjava_lang_String() {
DecimalFormat format = new DecimalFormat("#.#");
assertEquals("Wrong pattern 1", "#0.#", format.toPattern());
@@ -752,6 +948,7 @@ public class DecimalFormatTest extends TestCase {
assertEquals("Wrong pattern 3", "#", format.toPattern());
format = new DecimalFormat(".#");
assertEquals("Wrong pattern 4", "#.0", format.toPattern());
+
// Regression for HARMONY-6485
format = new DecimalFormat();
format.setMinimumIntegerDigits(0);
@@ -762,16 +959,116 @@ public class DecimalFormatTest extends TestCase {
assertEquals("Minimum fraction digits not set", 1, format.getMinimumFractionDigits());
assertEquals("Maximum fraction digits not set", 2, format.getMaximumFractionDigits());
+ try {
+ format.applyPattern(null);
+ fail();
+ } catch (NullPointerException expected) {
+ }
+
+ try {
+ format.applyPattern("%#,##,###,####'");
+ fail();
+ } catch (IllegalArgumentException expected) {
+ }
+
+ try {
+ format.applyPattern("#.##0.00");
+ fail();
+ } catch (IllegalArgumentException expected) {
+ }
+ }
+
+ // AndroidOnly: icu supports 2 grouping sizes
+ public void test_applyPatternLjava_lang_String2() {
+ DecimalFormat decFormat = new DecimalFormat("#.#");
+ String[] patterns = {
+ "####.##", "######.######", "000000.000000",
+ "######.000000", "000000.######", " ###.###", "$#####.######",
+ "$$####.######", "%#,##,###,####", "#,##0.00;(#,##0.00)",
+ "##.##-E"
+ };
+
+ String[] expResult = {
+ "#0.##", "#0.######", "#000000.000000",
+ "#.000000", "#000000.######", " #0.###", "$#0.######",
+ "$$#0.######",
+ "%#,###,####", // icu only. icu supports two grouping sizes
+ "#,##0.00;(#,##0.00)",
+ "#0.##-'E'" // icu only. E in the suffix does not need to be quoted. This is done automatically.
+ };
+
+ for (int i = 0; i < patterns.length; i++) {
+ decFormat.applyPattern(patterns[i]);
+ String result = decFormat.toPattern();
+ assertEquals("Failed to apply following pattern: " + patterns[i] +
+ "\n expected: " + expResult[i] +
+ "\n returned: " + result, expResult[i], result);
+ }
+ }
+
+ public void test_applyLocalizedPatternLjava_lang_String() throws Exception {
+ DecimalFormat format = new DecimalFormat();
+
+ // case 1: Try to apply correct variants of pattern.
+ format.applyLocalizedPattern("#.#");
+ assertEquals("Wrong pattern 1", "#0.#", format.toLocalizedPattern());
+ format.applyLocalizedPattern("#.");
+ assertEquals("Wrong pattern 2", "#0.", format.toLocalizedPattern());
+ format.applyLocalizedPattern("#");
+ assertEquals("Wrong pattern 3", "#", format.toLocalizedPattern());
+ format.applyLocalizedPattern(".#");
+ assertEquals("Wrong pattern 4", "#.0", format.toLocalizedPattern());
+
+ // case 2: Try to apply malformed patten.
+ try {
+ format.applyLocalizedPattern("'#,#:#0.0#;(#)");
+ fail();
+ } catch (IllegalArgumentException expected) {
+ }
+
+ // case 3: Try to apply null pattern.
+ try {
+ format.applyLocalizedPattern((String) null);
+ fail();
+ } catch (NullPointerException expected) {
+ }
+ }
+
+ public void test_toPattern() {
+ DecimalFormat format = new DecimalFormat();
+ format.applyPattern("#.#");
+ assertEquals("Wrong pattern 1", "#0.#", format.toPattern());
+ format.applyPattern("#.");
+ assertEquals("Wrong pattern 2", "#0.", format.toPattern());
+ format.applyPattern("#");
+ assertEquals("Wrong pattern 3", "#", format.toPattern());
+ format.applyPattern(".#");
+ assertEquals("Wrong pattern 4", "#.0", format.toPattern());
+ }
+
+ public void test_toLocalizedPattern() {
+ DecimalFormat format = new DecimalFormat();
+ format.setDecimalFormatSymbols(new DecimalFormatSymbols(Locale.US));
+ format.applyLocalizedPattern("#.#");
+ assertEquals("Wrong pattern 1", "#0.#", format.toLocalizedPattern());
+ format.applyLocalizedPattern("#.");
+ assertEquals("Wrong pattern 2", "#0.", format.toLocalizedPattern());
+ format.applyLocalizedPattern("#");
+ assertEquals("Wrong pattern 3", "#", format.toLocalizedPattern());
+ format.applyLocalizedPattern(".#");
+ assertEquals("Wrong pattern 4", "#.0", format.toLocalizedPattern());
+ }
+
+ public void test_hashCode() {
+ DecimalFormat df1 = new DecimalFormat();
+ DecimalFormat df2 = (DecimalFormat) df1.clone();
+ assertTrue("Hash codes of equals object are not equal", df2.hashCode() == df1.hashCode());
}
- /**
- * @tests java.text.DecimalFormat#clone()
- */
public void test_clone() {
DecimalFormat format = (DecimalFormat) DecimalFormat.getInstance(Locale.US);
DecimalFormat cloned = (DecimalFormat) format.clone();
- assertEquals(cloned.getDecimalFormatSymbols(), format
- .getDecimalFormatSymbols());
+ assertEquals(cloned.getDecimalFormatSymbols(), format.getDecimalFormatSymbols());
format = new DecimalFormat("'$'0000.0000");
DecimalFormat format1 = (DecimalFormat) (format.clone());
@@ -780,8 +1077,7 @@ public class DecimalFormatTest extends TestCase {
// change the content of the clone and make sure it's not equal anymore
// verifies that it's data is now distinct from the original
format1.applyPattern("'$'0000.####");
- assertTrue("Object's changed clone should not be equal!", !format
- .equals(format1));
+ assertTrue("Object's changed clone should not be equal!", !format.equals(format1));
}
private void compare(String testName, String format, String expected) {
@@ -789,27 +1085,119 @@ public class DecimalFormatTest extends TestCase {
format.equals(expected));
}
- private boolean compare(int count, String format, String expected) {
- boolean result = format.equals(expected);
- if (!result)
- System.out.println("Failure test: " + count + " got: " + format
- + " expected: " + expected);
- return result;
+ // icu4c and the RI disagree about these patterns, and I'm not yet sure which is correct.
+ public void test_formatDLjava_lang_StringBufferLjava_text_FieldPosition_problem_cases() {
+ final DecimalFormatSymbols dfs = new DecimalFormatSymbols(Locale.US);
+ DecimalFormat df;
+
+ df = new DecimalFormat("##0.0E0", dfs);
+ compare("##0.0E0: 123.0", df.format(123.0), "123E0");
+ compare("##0.0E0: 1234.0", df.format(1234.0), "1.234E3");
+ compare("##0.0E0: 12346.0", df.format(12346.0), "12.35E3");
+
+ df = new DecimalFormat("#00.0##E0", dfs);
+ compare("#00.0##E0: 0.1", df.format(0.1), ".100E0");
+ compare("#00.0##E0: 0.12", df.format(0.12), ".120E0");
+ compare("#00.0##E0: 0.123", df.format(0.123), ".123E0");
+ compare("#00.0##E0: 0.1234", df.format(0.1234), ".1234E0");
+ compare("#00.0##E0: 0.1234567", df.format(0.1234567), ".123457E0");
+ compare("#00.0##E0: 0.01", df.format(0.01), "10.0E-3");
+ compare("#00.0##E0: 0.012", df.format(0.012), "12.0E-3");
+ compare("#00.0##E0: 0.0123", df.format(0.0123), "12.3E-3");
+ compare("#00.0##E0: 0.01234", df.format(0.01234), "12.34E-3");
+ compare("#00.0##E0: 0.01234567", df.format(0.01234567), "12.3457E-3");
+ compare("#00.0##E0: 0.001", df.format(0.001), "1.00E-3");
+ compare("#00.0##E0: 0.0012", df.format(0.0012), "1.20E-3");
+ compare("#00.0##E0: 0.00123", df.format(0.00123), "1.23E-3");
+ compare("#00.0##E0: 0.001234", df.format(0.001234), "1.234E-3");
+ compare("#00.0##E0: 0.001234567", df.format(0.001234567), "1.23457E-3");
+ compare("#00.0##E0: 0.0001", df.format(0.0001), "100E-6");
+ compare("#00.0##E0: 0.00012", df.format(0.00012), "120E-6");
+ compare("#00.0##E0: 0.000123", df.format(0.000123), "123E-6");
+ compare("#00.0##E0: 0.0001234", df.format(0.0001234), "123.4E-6");
+ compare("#00.0##E0: 0.0001234567", df.format(0.0001234567), "123.457E-6");
+
+ compare("#00.0##E0: 0.0", df.format(0.0), "0.00E0");
+ compare("#00.0##E0: 1.0", df.format(1.0), "1.00E0");
+ compare("#00.0##E0: 12.0", df.format(12.0), "12.0E0");
+ compare("#00.0##E0: 123.0", df.format(123.0), "123E0");
+ compare("#00.0##E0: 1234.0", df.format(1234.0), "1.234E3");
+ compare("#00.0##E0: 12345.0", df.format(12345.0), "12.345E3");
+ compare("#00.0##E0: 123456.0", df.format(123456.0), "123.456E3");
+ compare("#00.0##E0: 1234567.0", df.format(1234567.0), "1.23457E6");
+ compare("#00.0##E0: 12345678.0", df.format(12345678.0), "12.3457E6");
+ compare("#00.0##E0: 99999999.0", df.format(99999999.0), "100E6");
+
+ df = new DecimalFormat("#.0E0", dfs);
+ compare("#.0E0: 0.0", df.format(0.0), ".0E0");
+ compare("#.0E0: 1.0", df.format(1.0), ".1E1");
+ compare("#.0E0: 12.0", df.format(12.0), ".12E2");
+ compare("#.0E0: 123.0", df.format(123.0), ".12E3");
+ compare("#.0E0: 1234.0", df.format(1234.0), ".12E4");
+ compare("#.0E0: 9999.0", df.format(9999.0), ".1E5");
+
+ df = new DecimalFormat("0.E0", dfs);
+ compare("0.E0: 0.0", df.format(0.0), "0.E0");
+ compare("0.E0: 1.0", df.format(1.0), "1.E0");
+ compare("0.E0: 12.0", df.format(12.0), "1.E1");
+ compare("0.E0: 123.0", df.format(123.0), "1.E2");
+ compare("0.E0: 1234.0", df.format(1234.0), "1.E3");
+ compare("0.E0: 9999.0", df.format(9999.0), "1.E4");
+
+ df = new DecimalFormat("##0.00#E0", dfs);
+ compare("##0.00#E0: 0.1", df.format(0.1), ".100E0");
+ compare("##0.00#E0: 0.1234567", df.format(0.1234567), ".123457E0");
+ compare("##0.00#E0: 0.9999999", df.format(0.9999999), "1.00E0");
+ compare("##0.00#E0: 0.01", df.format(0.01), "10.0E-3");
+ compare("##0.00#E0: 0.01234567", df.format(0.01234567), "12.3457E-3");
+ compare("##0.00#E0: 0.09999999", df.format(0.09999999), ".100E0");
+ compare("##0.00#E0: 0.001", df.format(0.001), "1.00E-3");
+ compare("##0.00#E0: 0.001234567", df.format(0.001234567), "1.23457E-3");
+ compare("##0.00#E0: 0.009999999", df.format(0.009999999), "10.0E-3");
+ compare("##0.00#E0: 0.0001", df.format(0.0001), "100E-6");
+ compare("##0.00#E0: 0.0001234567", df.format(0.0001234567), "123.457E-6");
+ compare("##0.00#E0: 0.0009999999", df.format(0.0009999999), "1.00E-3");
+
+ df = new DecimalFormat("###0.00#E0", dfs);
+ compare("###0.00#E0: 0.1", df.format(0.1), ".100E0");
+ compare("###0.00#E0: 0.12345678", df.format(0.12345678), ".1234568E0");
+ compare("###0.00#E0: 0.99999999", df.format(0.99999999), "1.00E0");
+ compare("###0.00#E0: 0.01", df.format(0.01), "100E-4");
+ compare("###0.00#E0: 0.012345678", df.format(0.012345678), "123.4568E-4");
+ compare("###0.00#E0: 0.099999999", df.format(0.099999999), ".100E0");
+ compare("###0.00#E0: 0.001", df.format(0.001), "10.0E-4");
+ compare("###0.00#E0: 0.0012345678", df.format(0.0012345678), "12.34568E-4");
+ compare("###0.00#E0: 0.0099999999", df.format(0.0099999999), "100E-4");
+ compare("###0.00#E0: 0.0001", df.format(0.0001), "1.00E-4");
+ compare("###0.00#E0: 0.00012345678", df.format(0.00012345678), "1.234568E-4");
+ compare("###0.00#E0: 0.00099999999", df.format(0.00099999999), "10.0E-4");
+ compare("###0.00#E0: 0.00001", df.format(0.00001), "1000E-8");
+ compare("###0.00#E0: 0.000012345678", df.format(0.000012345678), "1234.568E-8");
+ compare("###0.00#E0: 0.000099999999", df.format(0.000099999999), "1.00E-4");
+
+ df = new DecimalFormat("###0.0#E0", dfs);
+ compare("###0.0#E0: 0.1", df.format(0.1), ".10E0");
+ compare("###0.0#E0: 0.1234567", df.format(0.1234567), ".123457E0");
+ compare("###0.0#E0: 0.9999999", df.format(0.9999999), "1.0E0");
+ compare("###0.0#E0: 0.01", df.format(0.01), "100E-4");
+ compare("###0.0#E0: 0.01234567", df.format(0.01234567), "123.457E-4");
+ compare("###0.0#E0: 0.09999999", df.format(0.09999999), ".10E0");
+ compare("###0.0#E0: 0.001", df.format(0.001), "10E-4");
+ compare("###0.0#E0: 0.001234567", df.format(0.001234567), "12.3457E-4");
+ compare("###0.0#E0: 0.009999999", df.format(0.009999999), "100E-4");
+ compare("###0.0#E0: 0.0001", df.format(0.0001), "1.0E-4");
+ compare("###0.0#E0: 0.0001234567", df.format(0.0001234567), "1.23457E-4");
+ compare("###0.0#E0: 0.0009999999", df.format(0.0009999999), "10E-4");
+ compare("###0.0#E0: 0.00001", df.format(0.00001), "1000E-8");
+ compare("###0.0#E0: 0.00001234567", df.format(0.00001234567), "1234.57E-8");
+ compare("###0.0#E0: 0.00009999999", df.format(0.00009999999), "1.0E-4");
}
- /**
- * @tests java.text.DecimalFormat#format(double, java.lang.StringBuffer,
- * java.text.FieldPosition)
- */
- //FIXME This test fails on Harmony ClassLibrary
public void test_formatDLjava_lang_StringBufferLjava_text_FieldPosition() {
new Support_DecimalFormat(
"test_formatDLjava_lang_StringBufferLjava_text_FieldPosition")
.t_format_with_FieldPosition();
- int failCount = 0;
- BitSet failures = new BitSet();
-
final DecimalFormatSymbols dfs = new DecimalFormatSymbols(Locale.US);
DecimalFormat df = new DecimalFormat("00.0#E0", dfs);
@@ -831,7 +1219,6 @@ public class DecimalFormatTest extends TestCase {
compare("00.0#E0: 0.1234", df.format(0.1234), "12.34E-2");
compare("00.0#E0: 0.12346", df.format(0.12346), "12.35E-2");
compare("00.0#E0: 0.99999", df.format(0.99999), "10.0E-1");
- compare("00.0#E0: -0.0", df.format(-0.0), "-00.0E0");
compare("00.0#E0: -1.0", df.format(-1.0), "-10.0E-1");
compare("00.0#E0: -12.0", df.format(-12.0), "-12.0E0");
compare("00.0#E0: -123.0", df.format(-123.0), "-12.3E1");
@@ -840,67 +1227,13 @@ public class DecimalFormatTest extends TestCase {
compare("00.0#E0: -99999.0", df.format(-99999.0), "-10.0E4");
df = new DecimalFormat("##0.0E0", dfs);
- compare("##0.0E0: -0.0", df.format(-0.0), "-0.0E0");
compare("##0.0E0: 0.0", df.format(0.0), "0.0E0");
compare("##0.0E0: 1.0", df.format(1.0), "1.0E0");
compare("##0.0E0: 12.0", df.format(12.0), "12E0");
- compare("##0.0E0: 123.0", df.format(123.0), "123E0");
- compare("##0.0E0: 1234.0", df.format(1234.0), "1.234E3");
- compare("##0.0E0: 12346.0", df.format(12346.0), "12.35E3");
- // Fails in JDK 1.2.2
- if (!compare(failCount, df.format(99999.0), "100E3"))
- failures.set(failCount);
- failCount++;
+ compare("##0.0E0: 99999.0", df.format(99999.0), "100E3");
compare("##0.0E0: 999999.0", df.format(999999.0), "1.0E6");
- df = new DecimalFormat("#00.0##E0", dfs);
- compare("#00.0##E0: 0.1", df.format(0.1), ".100E0");
- compare("#00.0##E0: 0.12", df.format(0.12), ".120E0");
- compare("#00.0##E0: 0.123", df.format(0.123), ".123E0");
- compare("#00.0##E0: 0.1234", df.format(0.1234), ".1234E0");
- compare("#00.0##E0: 0.1234567", df.format(0.1234567), ".123457E0");
- compare("#00.0##E0: 0.01", df.format(0.01), "10.0E-3");
- compare("#00.0##E0: 0.012", df.format(0.012), "12.0E-3");
- compare("#00.0##E0: 0.0123", df.format(0.0123), "12.3E-3");
- compare("#00.0##E0: 0.01234", df.format(0.01234), "12.34E-3");
- compare("#00.0##E0: 0.01234567", df.format(0.01234567), "12.3457E-3");
- compare("#00.0##E0: 0.001", df.format(0.001), "1.00E-3");
- compare("#00.0##E0: 0.0012", df.format(0.0012), "1.20E-3");
- compare("#00.0##E0: 0.00123", df.format(0.00123), "1.23E-3");
- compare("#00.0##E0: 0.001234", df.format(0.001234), "1.234E-3");
- compare("#00.0##E0: 0.001234567", df.format(0.001234567), "1.23457E-3");
- compare("#00.0##E0: 0.0001", df.format(0.0001), "100E-6");
- compare("#00.0##E0: 0.00012", df.format(0.00012), "120E-6");
- compare("#00.0##E0: 0.000123", df.format(0.000123), "123E-6");
- compare("#00.0##E0: 0.0001234", df.format(0.0001234), "123.4E-6");
- compare("#00.0##E0: 0.0001234567", df.format(0.0001234567),
- "123.457E-6");
-
- // Fails in JDK 1.2.2
- if (!compare(failCount, df.format(0.0), "0.00E0"))
- failures.set(failCount);
- failCount++;
- compare("#00.0##E0: 1.0", df.format(1.0), "1.00E0");
- compare("#00.0##E0: 12.0", df.format(12.0), "12.0E0");
- compare("#00.0##E0: 123.0", df.format(123.0), "123E0");
- compare("#00.0##E0: 1234.0", df.format(1234.0), "1.234E3");
- compare("#00.0##E0: 12345.0", df.format(12345.0), "12.345E3");
- compare("#00.0##E0: 123456.0", df.format(123456.0), "123.456E3");
- compare("#00.0##E0: 1234567.0", df.format(1234567.0), "1.23457E6");
- compare("#00.0##E0: 12345678.0", df.format(12345678.0), "12.3457E6");
- compare("#00.0##E0: 99999999.0", df.format(99999999.0), "100E6");
-
- df = new DecimalFormat("#.0E0", dfs);
- compare("#.0E0: -0.0", df.format(-0.0), "-.0E0");
- compare("#.0E0: 0.0", df.format(0.0), ".0E0");
- compare("#.0E0: 1.0", df.format(1.0), ".1E1");
- compare("#.0E0: 12.0", df.format(12.0), ".12E2");
- compare("#.0E0: 123.0", df.format(123.0), ".12E3");
- compare("#.0E0: 1234.0", df.format(1234.0), ".12E4");
- compare("#.0E0: 9999.0", df.format(9999.0), ".1E5");
-
df = new DecimalFormat("0.#E0", dfs);
- compare("0.#E0: -0.0", df.format(-0.0), "-0E0");
compare("0.#E0: 0.0", df.format(0.0), "0E0");
compare("0.#E0: 1.0", df.format(1.0), "1E0");
compare("0.#E0: 12.0", df.format(12.0), "1.2E1");
@@ -909,7 +1242,6 @@ public class DecimalFormatTest extends TestCase {
compare("0.#E0: 9999.0", df.format(9999.0), "1E4");
df = new DecimalFormat(".0E0", dfs);
- compare(".0E0: -0.0", df.format(-0.0), "-.0E0");
compare(".0E0: 0.0", df.format(0.0), ".0E0");
compare(".0E0: 1.0", df.format(1.0), ".1E1");
compare(".0E0: 12.0", df.format(12.0), ".1E2");
@@ -917,99 +1249,6 @@ public class DecimalFormatTest extends TestCase {
compare(".0E0: 1234.0", df.format(1234.0), ".1E4");
compare(".0E0: 9999.0", df.format(9999.0), ".1E5");
- df = new DecimalFormat("0.E0", dfs);
- // Fails in JDK 1.2.2
- if (!compare(failCount, df.format(0.0), "0.E0"))
- failures.set(failCount);
- failCount++;
- if (!compare(failCount, df.format(1.0), "1.E0"))
- failures.set(failCount);
- failCount++;
- if (!compare(failCount, df.format(12.0), "1.E1"))
- failures.set(failCount);
- failCount++;
- if (!compare(failCount, df.format(123.0), "1.E2"))
- failures.set(failCount);
- failCount++;
- if (!compare(failCount, df.format(1234.0), "1.E3"))
- failures.set(failCount);
- failCount++;
- if (!compare(failCount, df.format(9999.0), "1.E4"))
- failures.set(failCount);
- failCount++;
-
- df = new DecimalFormat("##0.00#E0", dfs);
- compare("##0.00#E0: 0.1", df.format(0.1), ".100E0");
- compare("##0.00#E0: 0.1234567", df.format(0.1234567), ".123457E0");
- compare("##0.00#E0: 0.9999999", df.format(0.9999999), "1.00E0");
- compare("##0.00#E0: 0.01", df.format(0.01), "10.0E-3");
- compare("##0.00#E0: 0.01234567", df.format(0.01234567), "12.3457E-3");
- compare("##0.00#E0: 0.09999999", df.format(0.09999999), ".100E0");
- compare("##0.00#E0: 0.001", df.format(0.001), "1.00E-3");
- compare("##0.00#E0: 0.001234567", df.format(0.001234567), "1.23457E-3");
- compare("##0.00#E0: 0.009999999", df.format(0.009999999), "10.0E-3");
- compare("##0.00#E0: 0.0001", df.format(0.0001), "100E-6");
- compare("##0.00#E0: 0.0001234567", df.format(0.0001234567),
- "123.457E-6");
- compare("##0.00#E0: 0.0009999999", df.format(0.0009999999), "1.00E-3");
-
- df = new DecimalFormat("###0.00#E0", dfs);
- compare("###0.00#E0: 0.1", df.format(0.1), ".100E0");
- compare("###0.00#E0: 0.12345678", df.format(0.12345678), ".1234568E0");
- compare("###0.00#E0: 0.99999999", df.format(0.99999999), "1.00E0");
- compare("###0.00#E0: 0.01", df.format(0.01), "100E-4");
- compare("###0.00#E0: 0.012345678", df.format(0.012345678),
- "123.4568E-4");
- compare("###0.00#E0: 0.099999999", df.format(0.099999999), ".100E0");
- compare("###0.00#E0: 0.001", df.format(0.001), "10.0E-4");
- compare("###0.00#E0: 0.0012345678", df.format(0.0012345678),
- "12.34568E-4");
- compare("###0.00#E0: 0.0099999999", df.format(0.0099999999), "100E-4");
- compare("###0.00#E0: 0.0001", df.format(0.0001), "1.00E-4");
- compare("###0.00#E0: 0.00012345678", df.format(0.00012345678),
- "1.234568E-4");
- compare("###0.00#E0: 0.00099999999", df.format(0.00099999999),
- "10.0E-4");
- // Fails in JDK 1.2.2
- if (!compare(failCount, df.format(0.00001), "1000E-8"))
- failures.set(failCount);
- failCount++;
- compare("###0.00#E0: 0.000012345678", df.format(0.000012345678),
- "1234.568E-8");
- compare("###0.00#E0: 0.000099999999", df.format(0.000099999999),
- "1.00E-4");
-
- df = new DecimalFormat("###0.0#E0", dfs);
- compare("###0.0#E0: 0.1", df.format(0.1), ".10E0");
- compare("###0.0#E0: 0.1234567", df.format(0.1234567), ".123457E0");
- compare("###0.0#E0: 0.9999999", df.format(0.9999999), "1.0E0");
- // Fails in JDK 1.2.2
- if (!compare(failCount, df.format(0.01), "100E-4"))
- failures.set(failCount);
- failCount++;
- compare("###0.0#E0: 0.01234567", df.format(0.01234567), "123.457E-4");
- compare("###0.0#E0: 0.09999999", df.format(0.09999999), ".10E0");
- compare("###0.0#E0: 0.001", df.format(0.001), "10E-4");
- compare("###0.0#E0: 0.001234567", df.format(0.001234567), "12.3457E-4");
- // Fails in JDK 1.2.2
- if (!compare(failCount, df.format(0.009999999), "100E-4"))
- failures.set(failCount);
- failCount++;
- compare("###0.0#E0: 0.0001", df.format(0.0001), "1.0E-4");
- compare("###0.0#E0: 0.0001234567", df.format(0.0001234567),
- "1.23457E-4");
- compare("###0.0#E0: 0.0009999999", df.format(0.0009999999), "10E-4");
- // Fails in JDK 1.2.2
- if (!compare(failCount, df.format(0.00001), "1000E-8"))
- failures.set(failCount);
- failCount++;
- compare("###0.0#E0: 0.00001234567", df.format(0.00001234567),
- "1234.57E-8");
- compare("###0.0#E0: 0.00009999999", df.format(0.00009999999), "1.0E-4");
-
- assertTrue("Failed " + failures + " of " + failCount,
- failures.length() == 0);
-
String formatString = "##0.#";
df = new DecimalFormat(formatString, dfs);
df.setMinimumFractionDigits(30);
@@ -1030,15 +1269,26 @@ public class DecimalFormatTest extends TestCase {
compare(formatString + ": -1", df.format(-1.0), "-1");
}
- /**
- * @tests java.text.DecimalFormat#format(long, java.lang.StringBuffer,
- * java.text.FieldPosition)
- */
- //FIXME This test fails on Harmony ClassLibrary
- public void test_formatJLjava_lang_StringBufferLjava_text_FieldPosition() {
- int failCount = 0;
- BitSet failures = new BitSet();
+ public void test_format_minus_zero() throws Exception {
+ final DecimalFormatSymbols dfs = new DecimalFormatSymbols(Locale.US);
+ DecimalFormat df = new DecimalFormat("00.0#E0", dfs);
+ compare("00.0#E0: -0.0", df.format(-0.0), "-00.0E0");
+
+ df = new DecimalFormat("##0.0E0", dfs);
+ compare("##0.0E0: -0.0", df.format(-0.0), "-0.0E0");
+
+ df = new DecimalFormat("#.0E0", dfs);
+ compare("#.0E0: -0.0", df.format(-0.0), "-.0E0");
+
+ df = new DecimalFormat("0.#E0", dfs);
+ compare("0.#E0: -0.0", df.format(-0.0), "-0E0");
+
+ df = new DecimalFormat(".0E0", dfs);
+ compare(".0E0: -0.0", df.format(-0.0), "-.0E0");
+ }
+
+ public void test_formatJLjava_lang_StringBufferLjava_text_FieldPosition() {
final DecimalFormatSymbols dfs = new DecimalFormatSymbols(Locale.US);
DecimalFormat df = new DecimalFormat("00.0#E0", dfs);
@@ -1063,17 +1313,11 @@ public class DecimalFormatTest extends TestCase {
assertEquals("##0.0E0: 123", "123E0", df.format(123));
assertEquals("##0.0E0: 1234", "1.234E3", df.format(1234));
assertEquals("##0.0E0: 12346", "12.35E3", df.format(12346));
- // Fails in JDK 1.2.2
- if (!df.format(99999).equals("100E3"))
- failures.set(failCount);
- failCount++;
+ assertEquals("##0.0E0: 99999", "100E3", df.format(99999));
assertEquals("##0.0E0: 999999", "1.0E6", df.format(999999));
df = new DecimalFormat("#00.0##E0", dfs);
- // Fails in JDK 1.2.2
- if (!df.format(0).equals("0.00E0"))
- failures.set(failCount);
- failCount++;
+ assertEquals("#00.0##E0: 0", "0.00E0", df.format(0));
assertEquals("#00.0##E0: 1", "1.00E0", df.format(1));
assertEquals("#00.0##E0: 12", "12.0E0", df.format(12));
assertEquals("#00.0##E0: 123", "123E0", df.format(123));
@@ -1099,15 +1343,8 @@ public class DecimalFormatTest extends TestCase {
assertEquals("0.#E0: 123", "1.2E2", df.format(123));
assertEquals("0.#E0: 1234", "1.2E3", df.format(1234));
assertEquals("0.#E0: 9999", "1E4", df.format(9999));
-
- assertTrue("Failed " + failures + " of " + failCount,
- failures.length() == 0);
}
- /**
- * @tests java.text.DecimalFormat#formatToCharacterIterator(java.lang.Object)
- */
- //FIXME This test fails on Harmony ClassLibrary
public void test_formatToCharacterIteratorLjava_lang_Object() {
try {
@@ -1123,12 +1360,8 @@ public class DecimalFormatTest extends TestCase {
.t_formatToCharacterIterator();
}
- /**
- * @tests java.text.DecimalFormat#format(double)
- */
public void test_formatD() {
- DecimalFormat format = (DecimalFormat) NumberFormat
- .getInstance(Locale.ENGLISH);
+ DecimalFormat format = (DecimalFormat) NumberFormat.getInstance(Locale.ENGLISH);
format.setGroupingUsed(false);
format.setMaximumFractionDigits(400);
for (int i = 0; i < 309; i++) {
@@ -1148,44 +1381,59 @@ public class DecimalFormatTest extends TestCase {
String result = format.format(d);
assertEquals(i + ") e:" + tval + " r:" + result, tval, result);
}
- assertEquals("999999999999999", format.format(999999999999999.));
- assertEquals("1", "999999999999999.9", format.format(999999999999999.9));
- assertEquals("2", "99999999999999.98", format.format(99999999999999.99));
- assertEquals("3", "9999999999999.998", format.format(9999999999999.999));
- assertEquals("4", "999999999999.9999", format.format(999999999999.9999));
- assertEquals("5", "99999999999.99998", format.format(99999999999.99999));
- assertEquals("6", "9999999999.999998", format.format(9999999999.999999));
- assertEquals("7", "999999999.9999999", format.format(999999999.9999999));
- assertEquals("8", "99999999.99999999", format.format(99999999.99999999));
- assertEquals("9", "9999999.999999998", format.format(9999999.999999999));
- assertEquals("10", "99999.99999999999", format
- .format(99999.99999999999));
- assertEquals("11", "9999.999999999998", format
- .format(9999.999999999999));
- assertEquals("12", "999.9999999999999", format
- .format(999.9999999999999));
- assertEquals("13", "99.99999999999999", format
- .format(99.99999999999999));
- assertEquals("14", "9.999999999999998", format
- .format(9.999999999999999));
- assertEquals("15", "0.9999999999999999", format
- .format(.9999999999999999));
- }
-
- /**
- * @tests java.text.DecimalFormat#getDecimalFormatSymbols()
- */
+ }
+
+ public void test_formatD_2() {
+ DecimalFormat format = (DecimalFormat) NumberFormat.getInstance(Locale.ENGLISH);
+ format.setGroupingUsed(false);
+ format.setMaximumFractionDigits(400);
+
+ assertEquals("999999999999999", format.format(999999999999999.));
+ assertEquals("999999999999999.9", format.format(999999999999999.9));
+ assertEquals("99999999999999.98", format.format(99999999999999.99));
+ assertEquals("9999999999999.998", format.format(9999999999999.999));
+ assertEquals("999999999999.9999", format.format(999999999999.9999));
+ assertEquals("99999999999.99998", format.format(99999999999.99999));
+ assertEquals("9999999999.999998", format.format(9999999999.999999));
+ assertEquals("999999999.9999999", format.format(999999999.9999999));
+ assertEquals("99999999.99999999", format.format(99999999.99999999));
+ assertEquals("9999999.999999998", format.format(9999999.999999999));
+ assertEquals("99999.99999999999", format.format(99999.99999999999));
+ assertEquals("9999.999999999998", format.format(9999.999999999999));
+ assertEquals("999.9999999999999", format.format(999.9999999999999));
+ assertEquals("99.99999999999999", format.format(99.99999999999999));
+ assertEquals("9.999999999999998", format.format(9.999999999999999));
+ assertEquals("0.9999999999999999", format.format(.9999999999999999));
+ }
+
+ public void test_formatD_3() {
+ DecimalFormat format = (DecimalFormat) NumberFormat.getInstance(Locale.ENGLISH);
+ format.setGroupingUsed(false);
+ format.setMaximumFractionDigits(400);
+
+ assertEquals("123456789012345", format.format(123456789012345.));
+ assertEquals("1", "12345678901234.5", format.format(12345678901234.5));
+ assertEquals("2", "1234567890123.25", format.format(1234567890123.25));
+ assertEquals("3", "999999999999.375", format.format(999999999999.375));
+ assertEquals("4", "99999999999.0625", format.format(99999999999.0625));
+ assertEquals("5", "9999999999.03125", format.format(9999999999.03125));
+ assertEquals("6", "999999999.015625", format.format(999999999.015625));
+ assertEquals("7", "99999999.0078125", format.format(99999999.0078125));
+ assertEquals("8", "9999999.00390625", format.format(9999999.00390625));
+ assertEquals("9", "999999.001953125", format.format(999999.001953125));
+ assertEquals("10", "9999.00048828125", format.format(9999.00048828125));
+ assertEquals("11", "999.000244140625", format.format(999.000244140625));
+ assertEquals("12", "99.0001220703125", format.format(99.0001220703125));
+ assertEquals("13", "9.00006103515625", format.format(9.00006103515625));
+ assertEquals("14", "0.000030517578125", format.format(0.000030517578125));
+ }
+
public void test_getDecimalFormatSymbols() {
- DecimalFormat df = (DecimalFormat) NumberFormat
- .getInstance(Locale.ENGLISH);
+ DecimalFormat df = (DecimalFormat) NumberFormat.getInstance(Locale.ENGLISH);
DecimalFormatSymbols dfs = df.getDecimalFormatSymbols();
assertTrue("Identical symbols", dfs != df.getDecimalFormatSymbols());
}
- /**
- * @tests java.text.DecimalFormat#getCurrency()
- */
- //FIXME This test fails on Harmony ClassLibrary
public void test_getCurrency() {
Currency currK = Currency.getInstance("KRW");
Currency currX = Currency.getInstance("XXX");
@@ -1216,7 +1464,7 @@ public class DecimalFormatTest extends TestCase {
df = (DecimalFormat) NumberFormat.getCurrencyInstance(new Locale("QWERTY"));
assertTrue("Test5: Returned incorrect currency",
df.getCurrency() == currX);
-
+
// JDK fails these tests since it doesn't have the PREEURO variant
// df = (DecimalFormat)NumberFormat.getCurrencyInstance(new Locale("fr",
// "FR","PREEURO"));
@@ -1224,9 +1472,6 @@ public class DecimalFormatTest extends TestCase {
// currF);
}
- /**
- * @tests java.text.DecimalFormat#getGroupingSize()
- */
public void test_getGroupingSize() {
DecimalFormat df = new DecimalFormat("###0.##");
assertEquals("Wrong unset size", 0, df.getGroupingSize());
@@ -1236,9 +1481,6 @@ public class DecimalFormatTest extends TestCase {
assertEquals("Wrong multiple set size", 4, df.getGroupingSize());
}
- /**
- * @tests java.text.DecimalFormat#getMultiplier()
- */
public void test_getMultiplier() {
final int defaultMultiplier = 1;
NumberFormat nform = DecimalFormat.getInstance(Locale.US);
@@ -1253,9 +1495,6 @@ public class DecimalFormatTest extends TestCase {
assertEquals("Wrong mille multiplier", 1000, df.getMultiplier());
}
- /**
- * @tests java.text.DecimalFormat#isDecimalSeparatorAlwaysShown()
- */
public void test_isDecimalSeparatorAlwaysShown() {
DecimalFormat df = new DecimalFormat("###0.##");
assertTrue("Wrong unset value", !df.isDecimalSeparatorAlwaysShown());
@@ -1265,11 +1504,6 @@ public class DecimalFormatTest extends TestCase {
assertTrue("Wrong set value", df.isDecimalSeparatorAlwaysShown());
}
- /**
- * @tests java.text.DecimalFormat#parse(java.lang.String,
- * java.text.ParsePosition)
- */
- //FIXME This test fails on Harmony ClassLibrary
public void test_parseLjava_lang_StringLjava_text_ParsePosition() {
DecimalFormat format = (DecimalFormat) NumberFormat
.getNumberInstance(Locale.ENGLISH);
@@ -1335,34 +1569,28 @@ public class DecimalFormatTest extends TestCase {
.getClass() == Double.class);
assertTrue("Wrong result for overflow e: " + result, result
.doubleValue() == 9223372036854775809d);
+ }
- // test parse with multipliers
- format.setMultiplier(100);
- result = format.parse("9223372036854775807", new ParsePosition(0));
- assertTrue("Wrong result type multiplier 100: " + result, result
- .getClass() == Long.class);
- assertTrue("Wrong result for multiplier 100: " + result, result
- .longValue() == 92233720368547758L);
-
- format.setMultiplier(1000);
- result = format.parse("9223372036854775807", new ParsePosition(0));
- assertTrue("Wrong result type multiplier 1000: " + result, result
- .getClass() == Long.class);
- assertTrue("Wrong result for multiplier 1000: " + result, result
- .longValue() == 9223372036854776L);
-
- format.setMultiplier(10000);
- result = format.parse("9223372036854775807", new ParsePosition(0));
- assertTrue("Wrong result type multiplier 10000: " + result, result
- .getClass() == Double.class);
- assertTrue("Wrong result for multiplier 10000: " + result, result
- .doubleValue() == 922337203685477.5807d);
+ public void test_parse_with_multiplier() {
+ DecimalFormat format = (DecimalFormat) NumberFormat.getNumberInstance(Locale.ENGLISH);
+ Number result;
+
+ format.setMultiplier(100);
+ result = format.parse("9223372036854775807", new ParsePosition(0));
+ assertEquals("Wrong result type multiplier 100: " + result, Double.class, result.getClass());
+ assertEquals("Wrong result for multiplier 100: " + result, 92233720368547758.07d, result.doubleValue());
+ format.setMultiplier(1000);
+ result = format.parse("9223372036854775807", new ParsePosition(0));
+ assertEquals("Wrong result type multiplier 1000: " + result, Double.class, result.getClass());
+ assertEquals("Wrong result for multiplier 1000: " + result, 9223372036854775.807d, result.doubleValue());
+
+ format.setMultiplier(10000);
+ result = format.parse("9223372036854775807", new ParsePosition(0));
+ assertEquals("Wrong result type multiplier 10000: " + result, Double.class, result.getClass());
+ assertEquals("Wrong result for multiplier 10000: " + result, 922337203685477.5807d, result.doubleValue());
}
- /**
- * @tests java.text.DecimalFormat#setDecimalFormatSymbols(java.text.DecimalFormatSymbols)
- */
public void test_setDecimalFormatSymbolsLjava_text_DecimalFormatSymbols() {
DecimalFormat df = new DecimalFormat("###0.##");
DecimalFormatSymbols dfs = new DecimalFormatSymbols();
@@ -1381,9 +1609,6 @@ public class DecimalFormatTest extends TestCase {
assertNotSame(symbols, symbolsOut);
}
- /**
- * @tests java.text.DecimalFormat#setDecimalSeparatorAlwaysShown(boolean)
- */
public void test_setDecimalSeparatorAlwaysShownZ() {
DecimalFormat df = new DecimalFormat("###0.##",
new DecimalFormatSymbols(Locale.US));
@@ -1393,9 +1618,6 @@ public class DecimalFormatTest extends TestCase {
assertEquals("Wrong set result", "7.", df.format(7));
}
- /**
- * @tests java.text.DecimalFormat#setCurrency(java.util.Currency)
- */
public void test_setCurrencyLjava_util_Currency() {
Locale locale = Locale.CANADA;
DecimalFormat df = ((DecimalFormat) NumberFormat
@@ -1419,9 +1641,6 @@ public class DecimalFormatTest extends TestCase {
.getInternationalCurrencySymbol()));
}
- /**
- * @tests java.text.DecimalFormat#setGroupingSize(int)
- */
public void test_setGroupingSizeI() {
DecimalFormat df = new DecimalFormat("###0.##",
new DecimalFormatSymbols(Locale.ENGLISH));
@@ -1432,9 +1651,6 @@ public class DecimalFormatTest extends TestCase {
assertTrue("Invalid format:" + result, result.equals("1,23"));
}
- /**
- * @tests java.text.DecimalFormat#setMaximumFractionDigits(int)
- */
public void test_setMaximumFractionDigitsI() {
DecimalFormat df = new DecimalFormat("###0.##",
new DecimalFormatSymbols(Locale.US));
@@ -1446,9 +1662,6 @@ public class DecimalFormatTest extends TestCase {
assertEquals("Incorrect fraction", "456.0000", df.format(456));
}
- /**
- * @tests java.text.DecimalFormat#setMaximumIntegerDigits(int)
- */
public void test_setMaximumIntegerDigitsI() {
DecimalFormat df = new DecimalFormat("###0.##");
df.setMaximumIntegerDigits(2);
@@ -1459,9 +1672,6 @@ public class DecimalFormatTest extends TestCase {
assertEquals("Incorrect integer", "0026", df.format(26));
}
- /**
- * @tests java.text.DecimalFormat#setMinimumFractionDigits(int)
- */
public void test_setMinimumFractionDigitsI() {
DecimalFormat df = new DecimalFormat("###0.##",
new DecimalFormatSymbols(Locale.US));
@@ -1473,9 +1683,6 @@ public class DecimalFormatTest extends TestCase {
assertEquals("Incorrect fraction", "456.00", df.format(456));
}
- /**
- * @tests java.text.DecimalFormat#setMinimumIntegerDigits(int)
- */
public void test_setMinimumIntegerDigitsI() {
DecimalFormat df = new DecimalFormat("###0.##",
new DecimalFormatSymbols(Locale.US));
@@ -1487,33 +1694,22 @@ public class DecimalFormatTest extends TestCase {
assertEquals("Incorrect integer", "00.7", df.format(0.7));
}
- /**
- * @tests java.text.DecimalFormat#setMultiplier(int)
- */
- //FIXME This test fails on Harmony ClassLibrary
public void test_setMultiplierI() {
DecimalFormat df = new DecimalFormat("###0.##");
df.setMultiplier(10);
assertEquals("Wrong multiplier", 10, df.getMultiplier());
assertEquals("Wrong format", "50", df.format(5));
- assertEquals("Wrong parse", 5, df.parse("50", new ParsePosition(0))
- .intValue());
-
+ assertEquals("Wrong parse", 5, df.parse("50", new ParsePosition(0)).intValue());
+
// regression test for HARMONY-879
df.setMultiplier(-1);
assertEquals("Wrong multiplier for negative value", -1, df.getMultiplier());
}
- /**
- * @tests serialization/deserialization compatibility.
- */
public void testSerializationSelf() throws Exception {
SerializationTest.verifySelf(new DecimalFormat());
}
- /**
- * @tests serialization compatibility with RI
- */
public void test_serializationHarmonyRICompatible() throws Exception {
NumberFormat nf = NumberFormat.getInstance(Locale.FRANCE);
@@ -1569,9 +1765,6 @@ public class DecimalFormatTest extends TestCase {
}
- /**
- * Test whether DecimalFormat can parse Positive infinity correctly
- */
public void testParseInfinityBigDecimalFalse() {
// Regression test for HARMONY-106
DecimalFormat format = (DecimalFormat) DecimalFormat.getInstance();
@@ -1582,9 +1775,6 @@ public class DecimalFormatTest extends TestCase {
assertTrue(Double.isInfinite(number.doubleValue()));
}
- /**
- * Test whether DecimalFormat can parse Negative infinity correctly
- */
public void testParseMinusInfinityBigDecimalFalse() {
// Regression test for HARMONY-106
DecimalFormat format = (DecimalFormat) DecimalFormat.getInstance();
@@ -1594,20 +1784,111 @@ public class DecimalFormatTest extends TestCase {
assertTrue(number instanceof Double);
assertTrue(Double.isInfinite(number.doubleValue()));
}
-
- /**
- * Test if setDecimalFormatSymbols method wont throw NullPointerException
- * when it is called with null parameter.
- */
+
public void testSetDecimalFormatSymbolsAsNull(){
- // Regression for HARMONY-1070
+ // Regression for HARMONY-1070
DecimalFormat format = (DecimalFormat)DecimalFormat.getInstance();
- format.setDecimalFormatSymbols(null);
+ format.setDecimalFormatSymbols(null);
}
-
- /**
- * @tests java.text.DecimalFormat#formatToCharacterIterator(java.lang.Object)
- */
+
+ public void test_formatToCharacterIterator() throws Exception {
+ AttributedCharacterIterator iterator;
+ int[] runStarts;
+ int[] runLimits;
+ String result;
+ char current;
+
+ // BigInteger.
+ iterator = new DecimalFormat().formatToCharacterIterator(new BigInteger("123456789"));
+ runStarts = new int[] {0, 0, 0, 3, 4, 4, 4, 7, 8, 8, 8};
+ runLimits = new int[] {3, 3, 3, 4, 7, 7, 7, 8, 11, 11, 11};
+ result = "123,456,789";
+ current = iterator.current();
+ for (int i = 0; i < runStarts.length; i++) {
+ assertEquals("wrong start @" + i, runStarts[i], iterator.getRunStart());
+ assertEquals("wrong limit @" + i, runLimits[i], iterator.getRunLimit());
+ assertEquals("wrong char @" + i, result.charAt(i), current);
+ current = iterator.next();
+ }
+ assertEquals(0, iterator.getBeginIndex());
+ assertEquals(11, iterator.getEndIndex());
+
+ // For BigDecimal with multiplier test.
+ DecimalFormat df = new DecimalFormat();
+ df.setMultiplier(10);
+ iterator = df.formatToCharacterIterator(new BigDecimal("12345678901234567890"));
+ result = "123,456,789,012,345,678,900";
+ current = iterator.current();
+ for (int i = 0; i < result.length(); i++) {
+ assertEquals("wrong char @" + i, result.charAt(i), current);
+ current = iterator.next();
+ }
+
+ // For BigDecimal with multiplier test.
+ df = new DecimalFormat();
+ df.setMultiplier(-1);
+ df.setMaximumFractionDigits(20);
+ iterator = df.formatToCharacterIterator(new BigDecimal("1.23456789012345678901"));
+ result = "-1.23456789012345678901";
+ current = iterator.current();
+ for (int i = 0; i < result.length(); i++) {
+ assertEquals("wrong char @" + i, result.charAt(i), current);
+ current = iterator.next();
+ }
+
+ iterator = new DecimalFormat().formatToCharacterIterator(new BigDecimal("1.23456789E301"));
+ runStarts = new int[] {0, 0, 2, 3, 3, 3, 6, 7, 7, 7, 10, 11, 11, 11, 14};
+ runLimits = new int[] {2, 2, 3, 6, 6, 6, 7, 10, 10, 10, 11, 14, 14, 14, 15};
+ result = "12,345,678,900,"; // 000,000,000,000....
+ current = iterator.current();
+ for (int i = 0; i < runStarts.length; i++) {
+ assertEquals("wrong start @" + i, runStarts[i], iterator.getRunStart());
+ assertEquals("wrong limit @" + i, runLimits[i], iterator.getRunLimit());
+ assertEquals("wrong char @" + i, result.charAt(i), current);
+ current = iterator.next();
+ }
+ assertEquals(0, iterator.getBeginIndex());
+ assertEquals(402, iterator.getEndIndex());
+
+ iterator = new DecimalFormat().formatToCharacterIterator(new BigDecimal("1.2345678E4"));
+ runStarts = new int[] {0, 0, 2, 3, 3, 3, 6, 7, 7, 7};
+ runLimits = new int[] {2, 2, 3, 6, 6, 6, 7, 10, 10, 10};
+ result = "12,345.678";
+ current = iterator.current();
+ for (int i = 0; i < runStarts.length; i++) {
+ assertEquals("wrong start @" + i, runStarts[i], iterator.getRunStart());
+ assertEquals("wrong limit @" + i, runLimits[i], iterator.getRunLimit());
+ assertEquals("wrong char @" + i, result.charAt(i), current);
+ current = iterator.next();
+ }
+ assertEquals(0, iterator.getBeginIndex());
+ assertEquals(10, iterator.getEndIndex());
+ }
+
+ public void test_formatToCharacterIterator_very_large() throws Exception {
+ AttributedCharacterIterator iterator;
+ int[] runStarts;
+ int[] runLimits;
+ String result;
+ char current;
+
+ Number number = new BigDecimal("1.23456789E1234");
+ assertEquals("1.23456789E+1234", number.toString());
+ iterator = new DecimalFormat().formatToCharacterIterator(number);
+ runStarts = new int[] {0, 0, 2, 3, 3, 3, 6, 7, 7, 7, 10, 11, 11, 11, 14};
+ runLimits = new int[] {2, 2, 3, 6, 6, 6, 7, 10, 10, 10, 11, 14, 14, 14, 15};
+ result = "12,345,678,900,"; // 000,000,000,000....
+ current = iterator.current();
+ for (int i = 0; i < runStarts.length; i++) {
+ assertEquals("wrong start @" + i, runStarts[i], iterator.getRunStart());
+ assertEquals("wrong limit @" + i, runLimits[i], iterator.getRunLimit());
+ assertEquals("wrong char @" + i, result.charAt(i), current);
+ current = iterator.next();
+ }
+ assertEquals(0, iterator.getBeginIndex());
+ assertEquals(1646, iterator.getEndIndex());
+ }
+
public void test_formatToCharacterIteratorLjava_lang_Object__ArithmeticException() {
DecimalFormat decimalFormat = (DecimalFormat) DecimalFormat
.getInstance(Locale.US);
@@ -1622,10 +1903,6 @@ public class DecimalFormatTest extends TestCase {
}
}
- /**
- * @tests java.text.DecimalFormat#format(double, java.lang.StringBuffer,
- * java.text.FieldPosition)
- */
public void test_formatDLjava_lang_StringBufferLjava_text_FieldPosition_ArithmeticException() {
DecimalFormat decimalFormat = (DecimalFormat) DecimalFormat
.getInstance(Locale.US);
@@ -1642,10 +1919,6 @@ public class DecimalFormatTest extends TestCase {
}
}
- /**
- * @tests java.text.DecimalFormat#format(long, java.lang.StringBuffer,
- * java.text.FieldPosition)
- */
public void test_formatJLjava_lang_StringBufferLjava_text_FieldPosition_ArithmeticException() {
final DecimalFormatSymbols dfs = new DecimalFormatSymbols(Locale.US);
@@ -1662,15 +1935,12 @@ public class DecimalFormatTest extends TestCase {
}
}
- /**
- * @tests java.text.DecimalFormat#getRoundingMode()
- */
public void test_GetRoundingMode() {
// get the default RoundingMode of this DecimalFormat
DecimalFormat decimalFormat = (DecimalFormat) DecimalFormat
.getInstance(Locale.US);
-
+
// the default RoundingMode is HALF_EVEN
assertEquals("Incorrect default RoundingMode", decimalFormat.getRoundingMode(), RoundingMode.HALF_EVEN);
@@ -1681,10 +1951,7 @@ public class DecimalFormatTest extends TestCase {
}
- /**
- * @tests java.text.DecimalFormat#setRoundingMode(java.math.RoundingMode)
- */
- public void test_SetRoudingMode_Ljava_math_RoundingMode() {
+ public void test_SetRoundingMode_Ljava_math_RoundingMode() {
DecimalFormat decimalFormat = (DecimalFormat) DecimalFormat
.getInstance(Locale.US);
// ignore the fraction part of a given value
@@ -1776,11 +2043,9 @@ public class DecimalFormatTest extends TestCase {
assertEquals("Incorrect RoundingMode behavior: RoundingMode.HALF_UP",
"0", result);
- // the following assertion will fail on RI implementation, since the
- // implementation of ICU and RI are not identical.
result = decimalFormat.format(-0.2);
assertEquals("Incorrect RoundingMode behavior: RoundingMode.HALF_UP",
- "0", result);
+ "-0", result);
// set RoundingMode.UP of this DecimalFormat and test its
// behavior
@@ -1804,7 +2069,7 @@ public class DecimalFormatTest extends TestCase {
// set RoundingMode.UNNECESSARY of this DecimalFormat and test its
// behavior
decimalFormat.setRoundingMode(RoundingMode.UNNECESSARY);
-
+
try {
// when rounding is needed but RoundingMode is set to RoundingMode.UNNECESSARY, throw ArithmeticException
result = decimalFormat.format(5.5);
@@ -2038,7 +2303,7 @@ public class DecimalFormatTest extends TestCase {
result = decimalFormat.format(-0.2);
assertEquals("Incorrect RoundingMode behavior: RoundingMode.HALF_UP",
- "0", result);
+ "-0", result);
// set RoundingMode.UP of this DecimalFormat and test its
// behavior
diff --git a/harmony-tests/src/test/java/org/apache/harmony/tests/java/text/FieldPositionTest.java b/harmony-tests/src/test/java/org/apache/harmony/tests/java/text/FieldPositionTest.java
index 066ad2d..8fdc334 100644
--- a/harmony-tests/src/test/java/org/apache/harmony/tests/java/text/FieldPositionTest.java
+++ b/harmony-tests/src/test/java/org/apache/harmony/tests/java/text/FieldPositionTest.java
@@ -1,13 +1,13 @@
-/*
+/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -157,45 +157,58 @@ public class FieldPositionTest extends junit.framework.TestCase {
fpos2.getFieldAttribute());
}
- /**
- * @tests java.text.FieldPosition#hashCode()
- */
public void test_hashCode() {
- // Test for method int java.text.FieldPosition.hashCode()
- FieldPosition fpos = new FieldPosition(1);
- fpos.setBeginIndex(5);
- fpos.setEndIndex(110);
- fpos.hashCode();
-
- FieldPosition fpos2 = new FieldPosition(
- DateFormat.Field.DAY_OF_WEEK_IN_MONTH);
- fpos2.setBeginIndex(5);
- fpos2.setEndIndex(110);
- fpos2.hashCode();
+ // Test for method int java.text.FieldPosition.hashCode()
+ FieldPosition fpos1 = new FieldPosition(1);
+ FieldPosition fpos2 = new FieldPosition(1);
+ assertTrue("test 1: hash codes are not equal for equal objects.",
+ fpos1.hashCode() == fpos2.hashCode());
+ fpos1.setBeginIndex(5);
+ fpos1.setEndIndex(110);
+ assertTrue("test 2: hash codes are equal for non equal objects.",
+ fpos1.hashCode() != fpos2.hashCode());
+ fpos2.setBeginIndex(5);
+ fpos2.setEndIndex(110);
+ assertTrue("test 3: hash codes are not equal for equal objects.",
+ fpos1.hashCode() == fpos2.hashCode());
+
+ FieldPosition fpos3 = new FieldPosition(
+ DateFormat.Field.DAY_OF_WEEK_IN_MONTH);
+
+ assertTrue("test 4: hash codes are equal for non equal objects.",
+ fpos2.hashCode() != fpos3.hashCode());
}
- /**
- * @tests java.text.FieldPosition#setBeginIndex(int)
- */
public void test_setBeginIndexI() {
- // Test for method void java.text.FieldPosition.setBeginIndex(int)
- FieldPosition fpos = new FieldPosition(1);
- fpos.setBeginIndex(2);
- fpos.setEndIndex(3);
- assertEquals("beginIndex should have been set to 2",
- 2, fpos.getBeginIndex());
+ FieldPosition fpos = new FieldPosition(1);
+ fpos.setBeginIndex(2);
+ fpos.setEndIndex(3);
+ assertEquals("beginIndex should have been set to 2", 2, fpos
+ .getBeginIndex());
+
+ fpos.setBeginIndex(Integer.MAX_VALUE);
+ assertEquals("beginIndex should have been set to Integer.MAX_VALUE",
+ Integer.MAX_VALUE, fpos.getBeginIndex());
+
+ fpos.setBeginIndex(-1);
+ assertEquals("beginIndex should have been set to -1",
+ -1, fpos.getBeginIndex());
}
- /**
- * @tests java.text.FieldPosition#setEndIndex(int)
- */
public void test_setEndIndexI() {
- // Test for method void java.text.FieldPosition.setEndIndex(int)
- FieldPosition fpos = new FieldPosition(1);
- fpos.setEndIndex(3);
- fpos.setBeginIndex(2);
- assertEquals("EndIndex should have been set to 3",
- 3, fpos.getEndIndex());
+ FieldPosition fpos = new FieldPosition(1);
+ fpos.setEndIndex(3);
+ fpos.setBeginIndex(2);
+ assertEquals("EndIndex should have been set to 3", 3, fpos
+ .getEndIndex());
+
+ fpos.setEndIndex(Integer.MAX_VALUE);
+ assertEquals("endIndex should have been set to Integer.MAX_VALUE",
+ Integer.MAX_VALUE, fpos.getEndIndex());
+
+ fpos.setEndIndex(-1);
+ assertEquals("endIndex should have been set to -1",
+ -1, fpos.getEndIndex());
}
/**
@@ -208,7 +221,7 @@ public class FieldPositionTest extends junit.framework.TestCase {
fpos.setEndIndex(3);
assertEquals(
"ToString returned the wrong value:",
- "java.text.FieldPosition[attribute=null, field=1, beginIndex=2, endIndex=3]",
+ "java.text.FieldPosition[attribute=null,field=1,beginIndex=2,endIndex=3]",
fpos.toString());
FieldPosition fpos2 = new FieldPosition(DateFormat.Field.ERA);
@@ -216,7 +229,7 @@ public class FieldPositionTest extends junit.framework.TestCase {
fpos2.setEndIndex(5);
assertEquals("ToString returned the wrong value:",
"java.text.FieldPosition[attribute=" + DateFormat.Field.ERA
- + ", field=-1, beginIndex=4, endIndex=5]", fpos2
+ + ",field=-1,beginIndex=4,endIndex=5]", fpos2
.toString());
}
diff --git a/harmony-tests/src/test/java/org/apache/harmony/tests/java/text/MessageFormatTest.java b/harmony-tests/src/test/java/org/apache/harmony/tests/java/text/MessageFormatTest.java
index 1b5b6a8..28538e7 100644
--- a/harmony-tests/src/test/java/org/apache/harmony/tests/java/text/MessageFormatTest.java
+++ b/harmony-tests/src/test/java/org/apache/harmony/tests/java/text/MessageFormatTest.java
@@ -1,13 +1,13 @@
-/*
+/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -24,6 +24,8 @@ import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.text.ChoiceFormat;
import java.text.DateFormat;
+import java.text.DecimalFormat;
+import java.text.DecimalFormatSymbols;
import java.text.FieldPosition;
import java.text.Format;
import java.text.MessageFormat;
@@ -41,132 +43,347 @@ import junit.framework.TestCase;
public class MessageFormatTest extends TestCase {
- private MessageFormat format1, format2, format3;
+ private MessageFormat format1, format2, format3;
+
+ private Locale defaultLocale;
+
+ private void checkSerialization(MessageFormat format) {
+ try {
+ ByteArrayOutputStream ba = new ByteArrayOutputStream();
+ ObjectOutputStream out = new ObjectOutputStream(ba);
+ out.writeObject(format);
+ out.close();
+ ObjectInputStream in = new ObjectInputStream(
+ new ByteArrayInputStream(ba.toByteArray()));
+ MessageFormat read = (MessageFormat) in.readObject();
+ assertTrue("Not equal: " + format.toPattern(), format.equals(read));
+ } catch (IOException e) {
+ fail("Format: " + format.toPattern()
+ + " caused IOException: " + e);
+ } catch (ClassNotFoundException e) {
+ fail("Format: " + format.toPattern()
+ + " caused ClassNotFoundException: " + e);
+ }
+ }
- private Locale defaultLocale;
-
- private void checkSerialization(MessageFormat format) {
- try {
- ByteArrayOutputStream ba = new ByteArrayOutputStream();
- ObjectOutputStream out = new ObjectOutputStream(ba);
- out.writeObject(format);
- out.close();
- ObjectInputStream in = new ObjectInputStream(
- new ByteArrayInputStream(ba.toByteArray()));
- MessageFormat read = (MessageFormat) in.readObject();
- assertTrue("Not equal: " + format.toPattern(), format.equals(read));
- } catch (IOException e) {
- fail("Format: " + format.toPattern()
- + " caused IOException: " + e);
- } catch (ClassNotFoundException e) {
- fail("Format: " + format.toPattern()
- + " caused ClassNotFoundException: " + e);
- }
+ public void test_formatToCharacterIteratorLjava_lang_Object() {
+ new Support_MessageFormat("test_formatToCharacterIteratorLjava_lang_Object").t_formatToCharacterIterator();
+
+ try {
+ new MessageFormat("{1, number}").formatToCharacterIterator(null);
+ fail();
+ } catch (NullPointerException expected) {
}
- /**
- * @tests java.text.MessageFormat#MessageFormat(java.lang.String,
- * java.util.Locale)
- */
- public void test_ConstructorLjava_lang_StringLjava_util_Locale() {
- // Test for method java.text.MessageFormat(java.lang.String,
- // java.util.Locale)
- Locale mk = new Locale("mk", "MK");
- MessageFormat format = new MessageFormat(
- "Date: {0,date} Currency: {1, number, currency} Integer: {2, number, integer}",
- mk);
-
- assertTrue("Wrong locale1", format.getLocale().equals(mk));
- assertTrue("Wrong locale2", format.getFormats()[0].equals(DateFormat
- .getDateInstance(DateFormat.DEFAULT, mk)));
- assertTrue("Wrong locale3", format.getFormats()[1].equals(NumberFormat
- .getCurrencyInstance(mk)));
- assertTrue("Wrong locale4", format.getFormats()[2].equals(NumberFormat
- .getIntegerInstance(mk)));
- }
-
- /**
- * @tests java.text.MessageFormat#MessageFormat(java.lang.String)
- */
- public void test_ConstructorLjava_lang_String() {
- // Test for method java.text.MessageFormat(java.lang.String)
- MessageFormat format = new MessageFormat(
- "abc {4,time} def {3,date} ghi {2,number} jkl {1,choice,0#low|1#high} mnop {0}");
- assertTrue("Not a MessageFormat",
- format.getClass() == MessageFormat.class);
- Format[] formats = format.getFormats();
- assertNotNull("null formats", formats);
- assertTrue("Wrong format count: " + formats.length, formats.length >= 5);
- assertTrue("Wrong time format", formats[0].equals(DateFormat
- .getTimeInstance()));
- assertTrue("Wrong date format", formats[1].equals(DateFormat
- .getDateInstance()));
- assertTrue("Wrong number format", formats[2].equals(NumberFormat
- .getInstance()));
- assertTrue("Wrong choice format", formats[3].equals(new ChoiceFormat(
- "0.0#low|1.0#high")));
- assertNull("Wrong string format", formats[4]);
+ try {
+ new MessageFormat("{0, time}").formatToCharacterIterator(new Object[]{""});
+ fail();
+ } catch (IllegalArgumentException expected) {
+ }
+ }
+
+
+ public void test_getLocale() throws Exception {
+ Locale[] l = {
+ Locale.FRANCE,
+ Locale.KOREA,
+ new Locale("FR", "fr"), // Deliberately backwards.
+ new Locale("mk"),
+ new Locale("mk", "MK"),
+ Locale.US,
+ new Locale("#ru", "@31230") // Deliberately nonsense.
+ };
+
+ String pattern = "getLocale test {0,number,#,####}";
+
+ for (int i = 0; i < 0; i++) {
+ MessageFormat mf = new MessageFormat(pattern, l[i]);
+ Locale result = mf.getLocale();
+ assertEquals(l[i], result);
+ assertEquals(l[i].getLanguage(), result.getLanguage());
+ assertEquals(l[i].getCountry(), result.getCountry());
+ }
- Date date = new Date();
- FieldPosition pos = new FieldPosition(-1);
- StringBuffer buffer = new StringBuffer();
- format.format(new Object[] { "123", new Double(1.6), new Double(7.2),
- date, date }, buffer, pos);
- String result = buffer.toString();
- buffer.setLength(0);
- buffer.append("abc ");
- buffer.append(DateFormat.getTimeInstance().format(date));
- buffer.append(" def ");
- buffer.append(DateFormat.getDateInstance().format(date));
- buffer.append(" ghi ");
- buffer.append(NumberFormat.getInstance().format(new Double(7.2)));
- buffer.append(" jkl high mnop 123");
- assertTrue("Wrong answer:\n" + result + "\n" + buffer, result
- .equals(buffer.toString()));
-
- assertEquals("Simple string", "Test message", new MessageFormat("Test message").format(
- new Object[0]));
-
- result = new MessageFormat("Don't").format(new Object[0]);
- assertTrue("Should not throw IllegalArgumentException: " + result,
- "Dont".equals(result));
+ MessageFormat mf = new MessageFormat(pattern);
+ mf.setLocale(null);
+ Locale result = mf.getLocale();
+ assertEquals(null, result);
+ }
+
+ public void test_setFormatILjava_text_Format() throws Exception {
+ // case 1: Compare getFormats() results after calls to setFormat()
+ MessageFormat f1 = (MessageFormat) format1.clone();
+ f1.setFormat(0, DateFormat.getTimeInstance());
+ f1.setFormat(1, DateFormat.getTimeInstance());
+ f1.setFormat(2, NumberFormat.getInstance());
+ f1.setFormat(3, new ChoiceFormat("0#off|1#on"));
+ f1.setFormat(4, new ChoiceFormat("1#few|2#ok|3#a lot"));
+ f1.setFormat(5, DateFormat.getTimeInstance());
+
+ Format[] formats = f1.getFormats();
+ formats = f1.getFormats();
+
+ Format[] correctFormats = new Format[] {
+ DateFormat.getTimeInstance(),
+ DateFormat.getTimeInstance(),
+ NumberFormat.getInstance(),
+ new ChoiceFormat("0#off|1#on"),
+ new ChoiceFormat("1#few|2#ok|3#a lot"),
+ DateFormat.getTimeInstance()
+ };
+
+ assertEquals(correctFormats.length, formats.length);
+ for (int i = 0; i < correctFormats.length; i++) {
+ assertEquals("Test1B:wrong format for pattern index " + i + ":", correctFormats[i], formats[i]);
+ }
- try {
- new MessageFormat("Invalid {1,foobar} format descriptor!");
- fail("Expected test_ConstructorLjava_lang_String to throw IAE.");
- } catch (IllegalArgumentException ex) {
- // expected
- }
+ // case 2: Try to setFormat using incorrect index
+ try {
+ f1.setFormat(-1, DateFormat.getDateInstance());
+ fail();
+ } catch (ArrayIndexOutOfBoundsException expected) {
+ }
+ try {
+ f1.setFormat(f1.getFormats().length, DateFormat.getDateInstance());
+ fail();
+ } catch (ArrayIndexOutOfBoundsException expected) {
+ }
+ }
+
+ public void test_parseObjectLjava_lang_StringLjavajava_text_ParsePosition() throws Exception {
+ MessageFormat mf = new MessageFormat("{0,number,#.##}, {0,number,#.#}");
+ // case 1: Try to parse correct data string.
+ Object[] objs = { new Double(3.1415) };
+ String result = mf.format(objs);
+ // result now equals "3.14, 3.1"
+ Object[] res = null;
+ ParsePosition pp = new ParsePosition(0);
+ int parseIndex = pp.getIndex();
+ res = (Object[]) mf.parseObject(result, pp);
+ assertTrue("Parse operation return null", res != null);
+ assertTrue("parse operation return array with incorrect length", 1 == res.length);
+ assertTrue("ParseIndex is incorrect", pp.getIndex() != parseIndex);
+ assertTrue("Result object is incorrect", new Double(3.1).equals(res[0]));
+
+ // case 2: Try to parse partially correct data string.
+ pp.setIndex(0);
+ char[] cur = result.toCharArray();
+ cur[cur.length / 2] = 'Z';
+ String partialCorrect = new String(cur);
+ res = (Object[]) mf.parseObject(partialCorrect, pp);
+ assertTrue("Parse operation return null", res == null);
+ assertTrue("ParseIndex is incorrect", pp.getIndex() == 0);
+ assertTrue("ParseErrorIndex is incorrect", pp.getErrorIndex() == cur.length / 2);
+
+ // case 3: Try to use argument ParsePosition as null.
+ try {
+ mf.parseObject(result, null);
+ fail();
+ } catch (NullPointerException expected) {
+ }
+ }
+
+ public void test_parseLjava_lang_String() throws ParseException {
+ String pattern = "A {3, number, currency} B {2, time} C {0, number, percent} D {4} E {1,choice,0#off|1#on} F {0, date}";
+ MessageFormat mf = new MessageFormat(pattern);
+ String sToParse = "A $12,345.00 B 9:56:07 AM C 3,200% D 1/15/70 9:56 AM E on F Jan 1, 1970";
+ Object[] result = mf.parse(sToParse);
+
+ assertTrue("No result: " + result.length, result.length == 5);
+ assertTrue("Object 0 is not date", result[0] instanceof Date);
+ assertEquals("Object 1 is not stringr", result[1].toString(), "1.0");
+ assertTrue("Object 2 is not date", result[2] instanceof Date);
+ assertEquals("Object 3 is not number", result[3].toString(), "12345");
+ assertEquals("Object 4 is not string", result[4].toString(), "1/15/70 9:56 AM");
+
+ sToParse = "xxdate is Feb 28, 1999";
+ try {
+ result = format1.parse(sToParse);
+ fail();
+ } catch (java.text.ParseException expected) {
+ }
- try {
- new MessageFormat(
- "Invalid {1,date,invalid-spec} format descriptor!");
- } catch (IllegalArgumentException ex) {
- // expected
- }
+ sToParse = "vm=Test, @3 4 6, 3 ";
+ mf = new MessageFormat("vm={0},{1},{2}");
+ result = mf.parse(sToParse);
+ assertTrue("No result: " + result.length, result.length == 3);
+ assertEquals("Object 0 is not string", result[0].toString(), "Test");
+ assertEquals("Object 1 is not string", result[1].toString(), " @3 4 6");
+ assertEquals("Object 2 is not string", result[2].toString(), " 3 ");
+
+ try {
+ result = mf.parse(null);
+ fail();
+ } catch (java.text.ParseException expected) {
+ }
+ }
+
+ public void test_setFormats$Ljava_text_Format() throws Exception {
+ MessageFormat f1 = (MessageFormat) format1.clone();
+
+ // case 1: Test with repeating formats and max argument index < max
+ // offset
+ // compare getFormats() results after calls to setFormats(Format[])
+ Format[] correctFormats = new Format[] {
+ DateFormat.getTimeInstance(),
+ new ChoiceFormat("0#off|1#on"),
+ DateFormat.getTimeInstance(),
+ NumberFormat.getCurrencyInstance(),
+ new ChoiceFormat("1#few|2#ok|3#a lot")
+ };
+
+ f1.setFormats(correctFormats);
+ Format[] formats = f1.getFormats();
+
+ assertTrue("Test1A:Returned wrong number of formats:", correctFormats.length <= formats.length);
+ for (int i = 0; i < correctFormats.length; i++) {
+ assertEquals("Test1B:wrong format for argument index " + i + ":", correctFormats[i], formats[i]);
+ }
- checkSerialization(new MessageFormat(""));
- checkSerialization(new MessageFormat("noargs"));
- checkSerialization(new MessageFormat("{0}"));
- checkSerialization(new MessageFormat("a{0}"));
- checkSerialization(new MessageFormat("{0}b"));
- checkSerialization(new MessageFormat("a{0}b"));
-
- // Regression for HARMONY-65
- try {
- new MessageFormat("{0,number,integer");
- fail("Assert 0: Failed to detect unmatched brackets.");
- } catch (IllegalArgumentException e) {
- // expected
- }
+ // case 2: Try to pass null argument to setFormats().
+ try {
+ f1.setFormats(null);
+ fail();
+ } catch (NullPointerException expected) {
+ }
+ }
+
+ public void test_formatLjava_lang_StringLjava_lang_Object() {
+ TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
+ int iCurrency = 123;
+ int iInteger = Integer.MIN_VALUE;
+
+ Date date = new Date(12345678);
+ Object[] args = { date, iCurrency, iInteger };
+ String resStr = "Date: Jan 1, 1970 Currency: $" + iCurrency + ".00 Integer: -2,147,483,648";
+ String pattern = "Date: {0,date} Currency: {1, number, currency} Integer: {2, number, integer}";
+ String sFormat = MessageFormat.format(pattern, (Object[]) args);
+ assertEquals(
+ "format(String, Object[]) with valid parameters returns incorrect string: case 1",
+ sFormat, resStr);
+
+ pattern = "abc {4, number, integer} def {3,date} ghi {2,number} jkl {1,choice,0#low|1#high} mnop {0}";
+ resStr = "abc -2,147,483,648 def Jan 1, 1970 ghi -2,147,483,648 jkl high mnop -2,147,483,648";
+ Object[] args_ = { iInteger, 1, iInteger, date, iInteger };
+ sFormat = MessageFormat.format(pattern, args_);
+ assertEquals(
+ "format(String, Object[]) with valid parameters returns incorrect string: case 1",
+ sFormat, resStr);
+
+ try {
+ args = null;
+ MessageFormat.format(null, args);
+ fail();
+ } catch (Exception expected) {
+ }
+
+ try {
+ MessageFormat.format("Invalid {1,foobar} format descriptor!", new Object[] {iInteger} );
+ fail();
+ } catch (IllegalArgumentException expected) {
+ }
+
+ try {
+ MessageFormat.format("Invalid {1,date,invalid-spec} format descriptor!", new Object[]{""});
+ fail();
+ } catch (IllegalArgumentException expected) {
}
- /**
- * @tests java.text.MessageFormat#applyPattern(java.lang.String)
- */
+ try {
+ MessageFormat.format("{0,number,integer", new Object[] {iInteger});
+ fail();
+ } catch (IllegalArgumentException expected) {
+ }
+
+ try {
+ MessageFormat.format("Valid {1, date} format {0, number} descriptor!", new Object[]{ "" } );
+ fail();
+ } catch (IllegalArgumentException expected) {
+ }
+ }
+
+ public void test_ConstructorLjava_lang_StringLjava_util_Locale() {
+ Locale mk = new Locale("mk", "MK");
+ MessageFormat format = new MessageFormat("Date: {0,date} Currency: {1, number, currency} Integer: {2, number, integer}", mk);
+ assertEquals(format.getLocale(), mk);
+ assertEquals(format.getFormats()[0], DateFormat.getDateInstance(DateFormat.DEFAULT, mk));
+ assertEquals(format.getFormats()[1], NumberFormat.getCurrencyInstance(mk));
+ assertEquals(format.getFormats()[2], NumberFormat.getIntegerInstance(mk));
+ }
+
+ public void test_ConstructorLjava_lang_String() {
+ MessageFormat format = new MessageFormat(
+ "abc {4,time} def {3,date} ghi {2,number} jkl {1,choice,0#low|1#high} mnop {0}");
+ assertTrue("Not a MessageFormat",
+ format.getClass() == MessageFormat.class);
+ Format[] formats = format.getFormats();
+ assertNotNull("null formats", formats);
+ assertTrue("Wrong format count: " + formats.length, formats.length >= 5);
+ assertTrue("Wrong time format", formats[0].equals(DateFormat
+ .getTimeInstance()));
+ assertTrue("Wrong date format", formats[1].equals(DateFormat
+ .getDateInstance()));
+ assertTrue("Wrong number format", formats[2].equals(NumberFormat
+ .getInstance()));
+ assertTrue("Wrong choice format", formats[3].equals(new ChoiceFormat(
+ "0.0#low|1.0#high")));
+ assertNull("Wrong string format", formats[4]);
+
+ Date date = new Date();
+ FieldPosition pos = new FieldPosition(-1);
+ StringBuffer buffer = new StringBuffer();
+ format.format(new Object[] { "123", new Double(1.6), new Double(7.2),
+ date, date }, buffer, pos);
+ String result = buffer.toString();
+ buffer.setLength(0);
+ buffer.append("abc ");
+ buffer.append(DateFormat.getTimeInstance().format(date));
+ buffer.append(" def ");
+ buffer.append(DateFormat.getDateInstance().format(date));
+ buffer.append(" ghi ");
+ buffer.append(NumberFormat.getInstance().format(new Double(7.2)));
+ buffer.append(" jkl high mnop 123");
+ assertTrue("Wrong answer:\n" + result + "\n" + buffer, result
+ .equals(buffer.toString()));
+
+ assertEquals("Simple string", "Test message", new MessageFormat("Test message").format(
+ new Object[0]));
+
+ result = new MessageFormat("Don't").format(new Object[0]);
+ assertTrue("Should not throw IllegalArgumentException: " + result,
+ "Dont".equals(result));
+
+ try {
+ new MessageFormat("Invalid {1,foobar} format descriptor!");
+ fail("Expected test_ConstructorLjava_lang_String to throw IAE.");
+ } catch (IllegalArgumentException ex) {
+ // expected
+ }
+
+ try {
+ new MessageFormat(
+ "Invalid {1,date,invalid-spec} format descriptor!");
+ } catch (IllegalArgumentException ex) {
+ // expected
+ }
+
+ checkSerialization(new MessageFormat(""));
+ checkSerialization(new MessageFormat("noargs"));
+ checkSerialization(new MessageFormat("{0}"));
+ checkSerialization(new MessageFormat("a{0}"));
+ checkSerialization(new MessageFormat("{0}b"));
+ checkSerialization(new MessageFormat("a{0}b"));
+
+ // Regression for HARMONY-65
+ try {
+ new MessageFormat("{0,number,integer");
+ fail("Assert 0: Failed to detect unmatched brackets.");
+ } catch (IllegalArgumentException e) {
+ // expected
+ }
+ }
+
public void test_applyPatternLjava_lang_String() {
- // Test for method void
- // java.text.MessageFormat.applyPattern(java.lang.String)
MessageFormat format = new MessageFormat("test");
format.applyPattern("xx {0}");
assertEquals("Invalid number", "xx 46", format.format(
@@ -191,17 +408,17 @@ public class MessageFormatTest extends TestCase {
format.applyPattern("{0,Time, Short\n}");
assertTrue("Wrong short time format", format.getFormats()[0]
.equals(DateFormat.getTimeInstance(DateFormat.SHORT)));
- assertEquals("Wrong short time pattern",
+ assertEquals("Wrong short time pattern",
"{0,time,short}", format.toPattern());
format.applyPattern("{0,TIME,\nmedium }");
assertTrue("Wrong medium time format", format.getFormats()[0]
.equals(DateFormat.getTimeInstance(DateFormat.MEDIUM)));
- assertEquals("Wrong medium time pattern",
+ assertEquals("Wrong medium time pattern",
"{0,time}", format.toPattern());
format.applyPattern("{0,time,LONG}");
assertTrue("Wrong long time format", format.getFormats()[0]
.equals(DateFormat.getTimeInstance(DateFormat.LONG)));
- assertEquals("Wrong long time pattern",
+ assertEquals("Wrong long time pattern",
"{0,time,long}", format.toPattern());
format.setLocale(Locale.FRENCH); // use French since English has the
// same LONG and FULL time patterns
@@ -209,7 +426,7 @@ public class MessageFormatTest extends TestCase {
assertTrue("Wrong full time format", format.getFormats()[0]
.equals(DateFormat.getTimeInstance(DateFormat.FULL,
Locale.FRENCH)));
- assertEquals("Wrong full time pattern",
+ assertEquals("Wrong full time pattern",
"{0,time,full}", format.toPattern());
format.setLocale(Locale.getDefault());
@@ -220,69 +437,69 @@ public class MessageFormatTest extends TestCase {
format.applyPattern("{0, date, short}");
assertTrue("Wrong short date format", format.getFormats()[0]
.equals(DateFormat.getDateInstance(DateFormat.SHORT)));
- assertEquals("Wrong short date pattern",
+ assertEquals("Wrong short date pattern",
"{0,date,short}", format.toPattern());
format.applyPattern("{0, date, medium}");
assertTrue("Wrong medium date format", format.getFormats()[0]
.equals(DateFormat.getDateInstance(DateFormat.MEDIUM)));
- assertEquals("Wrong medium date pattern",
+ assertEquals("Wrong medium date pattern",
"{0,date}", format.toPattern());
format.applyPattern("{0, date, long}");
assertTrue("Wrong long date format", format.getFormats()[0]
.equals(DateFormat.getDateInstance(DateFormat.LONG)));
- assertEquals("Wrong long date pattern",
+ assertEquals("Wrong long date pattern",
"{0,date,long}", format.toPattern());
format.applyPattern("{0, date, full}");
assertTrue("Wrong full date format", format.getFormats()[0]
.equals(DateFormat.getDateInstance(DateFormat.FULL)));
- assertEquals("Wrong full date pattern",
+ assertEquals("Wrong full date pattern",
"{0,date,full}", format.toPattern());
format.applyPattern("{0, date, MMM d {hh:mm:ss}}");
assertEquals("Wrong time/date format", " MMM d {hh:mm:ss}", ((SimpleDateFormat) (format
.getFormats()[0])).toPattern());
- assertEquals("Wrong time/date pattern",
+ assertEquals("Wrong time/date pattern",
"{0,date, MMM d {hh:mm:ss}}", format.toPattern());
format.applyPattern("{0, number}");
assertTrue("Wrong number format", format.getFormats()[0]
.equals(NumberFormat.getNumberInstance()));
- assertEquals("Wrong number pattern",
+ assertEquals("Wrong number pattern",
"{0,number}", format.toPattern());
format.applyPattern("{0, number, currency}");
assertTrue("Wrong currency number format", format.getFormats()[0]
.equals(NumberFormat.getCurrencyInstance()));
- assertEquals("Wrong currency number pattern",
+ assertEquals("Wrong currency number pattern",
"{0,number,currency}", format.toPattern());
format.applyPattern("{0, number, percent}");
assertTrue("Wrong percent number format", format.getFormats()[0]
.equals(NumberFormat.getPercentInstance()));
- assertEquals("Wrong percent number pattern",
+ assertEquals("Wrong percent number pattern",
"{0,number,percent}", format.toPattern());
format.applyPattern("{0, number, integer}");
- NumberFormat nf = NumberFormat.getInstance();
- nf.setMaximumFractionDigits(0);
- nf.setParseIntegerOnly(true);
- assertTrue("Wrong integer number format", format.getFormats()[0]
- .equals(nf));
- assertEquals("Wrong integer number pattern",
- "{0,number,integer}", format.toPattern());
+
+ DecimalFormat expectedNumberFormat = (DecimalFormat) NumberFormat.getIntegerInstance();
+ DecimalFormat actualNumberFormat = (DecimalFormat) format.getFormats()[0];
+ assertEquals(expectedNumberFormat.getDecimalFormatSymbols(), actualNumberFormat.getDecimalFormatSymbols());
+ assertEquals(expectedNumberFormat.isParseIntegerOnly(), actualNumberFormat.isParseIntegerOnly());
+ assertEquals("Wrong integer number pattern", "{0,number,integer}", format.toPattern());
+ assertEquals(expectedNumberFormat, format.getFormats()[0]);
format.applyPattern("{0, number, {'#'}##0.0E0}");
/*
- * TODO validate these assertions
- * String actual = ((DecimalFormat)(format.getFormats()[0])).toPattern();
- * assertEquals("Wrong pattern number format", "' {#}'##0.0E0", actual);
+ * TODO validate these assertions
+ * String actual = ((DecimalFormat)(format.getFormats()[0])).toPattern();
+ * assertEquals("Wrong pattern number format", "' {#}'##0.0E0", actual);
* assertEquals("Wrong pattern number pattern", "{0,number,' {#}'##0.0E0}", format.toPattern());
- *
+ *
*/
format.applyPattern("{0, choice,0#no|1#one|2#{1,number}}");
assertEquals("Wrong choice format",
-
+
"0.0#no|1.0#one|2.0#{1,number}", ((ChoiceFormat) format.getFormats()[0]).toPattern());
- assertEquals("Wrong choice pattern",
+ assertEquals("Wrong choice pattern",
"{0,choice,0.0#no|1.0#one|2.0#{1,number}}", format.toPattern());
assertEquals("Wrong formatted choice", "3.6", format.format(
new Object[] { new Integer(2), new Float(3.6) }));
@@ -292,7 +509,7 @@ public class MessageFormatTest extends TestCase {
fail("Expected IllegalArgumentException for invalid pattern");
} catch (IllegalArgumentException e) {
}
-
+
// Regression for HARMONY-65
MessageFormat mf = new MessageFormat("{0,number,integer}");
String badpattern = "{0,number,#";
@@ -304,15 +521,11 @@ public class MessageFormatTest extends TestCase {
}
}
- /**
- * @tests java.text.MessageFormat#clone()
- */
public void test_clone() {
- // Test for method java.lang.Object java.text.MessageFormat.clone()
MessageFormat format = new MessageFormat("'{'choice'}'{0}");
MessageFormat clone = (MessageFormat) format.clone();
assertTrue("Clone not equal", format.equals(clone));
- assertEquals("Wrong answer",
+ assertEquals("Wrong answer",
"{choice}{0}", format.format(new Object[] {}));
clone.setFormat(0, DateFormat.getInstance());
assertTrue("Clone shares format data", !format.equals(clone));
@@ -322,12 +535,7 @@ public class MessageFormatTest extends TestCase {
assertTrue("Clone shares format data", !format.equals(clone));
}
- /**
- * @tests java.text.MessageFormat#equals(java.lang.Object)
- */
public void test_equalsLjava_lang_Object() {
- // Test for method boolean
- // java.text.MessageFormat.equals(java.lang.Object)
MessageFormat format1 = new MessageFormat("{0}");
MessageFormat format2 = new MessageFormat("{1}");
assertTrue("Should not be equal", !format1.equals(format2));
@@ -339,109 +547,100 @@ public class MessageFormatTest extends TestCase {
assertTrue("Should be equal2", format1.equals(format2));
}
- /**
- * @tests java.text.MessageFormat#hashCode()
- */
- public void test_hashCode() {
- // Test for method
- // int java.text.MessageFormat.hashCode()
- assertEquals("Should be equal", 3648, new MessageFormat("rr", null).hashCode());
- }
-
- /**
- * @tests java.text.MessageFormat#formatToCharacterIterator(java.lang.Object)
- */
- //FIXME This test fails on Harmony ClassLibrary
- public void failing_test_formatToCharacterIteratorLjava_lang_Object() {
- // Test for method formatToCharacterIterator(java.lang.Object)
- new Support_MessageFormat("test_formatToCharacterIteratorLjava_lang_Object").t_formatToCharacterIterator();
- }
-
- /**
- * @tests java.text.MessageFormat#format(java.lang.Object[],
- * java.lang.StringBuffer, java.text.FieldPosition)
- */
- public void test_format$Ljava_lang_ObjectLjava_lang_StringBufferLjava_text_FieldPosition() {
- // Test for method java.lang.StringBuffer
- // java.text.MessageFormat.format(java.lang.Object [],
- // java.lang.StringBuffer, java.text.FieldPosition)
- MessageFormat format = new MessageFormat("{1,number,integer}");
- StringBuffer buffer = new StringBuffer();
- format.format(new Object[] { "0", new Double(53.863) }, buffer,
- new FieldPosition(0));
- assertEquals("Wrong result", "54", buffer.toString());
- format
- .applyPattern("{0,choice,0#zero|1#one '{1,choice,2#two {2,time}}'}");
- Date date = new Date();
- String expected = "one two "
- + DateFormat.getTimeInstance().format(date);
- String result = format.format(new Object[] { new Double(1.6),
- new Integer(3), date });
- assertTrue("Choice not recursive:\n" + expected + "\n" + result,
- expected.equals(result));
- }
-
- /**
- * @tests java.text.MessageFormat#format(java.lang.Object,
- * java.lang.StringBuffer, java.text.FieldPosition)
- */
- public void test_formatLjava_lang_ObjectLjava_lang_StringBufferLjava_text_FieldPosition() {
- // Test for method java.lang.StringBuffer
- // java.text.MessageFormat.format(java.lang.Object,
- // java.lang.StringBuffer, java.text.FieldPosition)
- new Support_MessageFormat(
- "test_formatLjava_lang_ObjectLjava_lang_StringBufferLjava_text_FieldPosition")
- .t_format_with_FieldPosition();
- }
-
- /**
- * @tests java.text.MessageFormat#getFormats()
- */
- public void test_getFormats() {
- // Test for method java.text.Format []
- // java.text.MessageFormat.getFormats()
-
- // test with repeating formats and max argument index < max offset
- Format[] formats = format1.getFormats();
- Format[] correctFormats = new Format[] {
- NumberFormat.getCurrencyInstance(),
- DateFormat.getTimeInstance(),
- NumberFormat.getPercentInstance(), null,
- new ChoiceFormat("0#off|1#on"), DateFormat.getDateInstance(), };
-
- assertEquals("Test1:Returned wrong number of formats:",
- correctFormats.length, formats.length);
- for (int i = 0; i < correctFormats.length; i++) {
- assertEquals("Test1:wrong format for pattern index " + i + ":",
- correctFormats[i], formats[i]);
- }
-
- // test with max argument index > max offset
- formats = format2.getFormats();
- correctFormats = new Format[] { NumberFormat.getCurrencyInstance(),
- DateFormat.getTimeInstance(),
- NumberFormat.getPercentInstance(), null,
- new ChoiceFormat("0#off|1#on"), DateFormat.getDateInstance() };
+ public void test_hashCode() {
+ assertEquals("Should be equal", 3648, new MessageFormat("rr", null).hashCode());
+ }
+
+ public void test_format$Ljava_lang_ObjectLjava_lang_StringBufferLjava_text_FieldPosition() {
+ MessageFormat format = new MessageFormat("{1,number,integer}");
+ StringBuffer buffer = new StringBuffer();
+ format.format(new Object[] { "0", new Double(53.863) }, buffer,
+ new FieldPosition(0));
+ assertEquals("Wrong result", "54", buffer.toString());
+
+ format.format(new Object[] { "0", new Double(53.863) }, buffer,
+ new FieldPosition(MessageFormat.Field.ARGUMENT));
+ assertEquals("Wrong result", "5454", buffer.toString());
+
+ buffer = new StringBuffer();
+ format.applyPattern("{0,choice,0#zero|1#one '{1,choice,2#two {2,time}}'}");
+ Date date = new Date();
+ String expectedText = "one two " + DateFormat.getTimeInstance().format(date);
+ format.format(new Object[] { new Double(1.6), new Integer(3), date }, buffer, new FieldPosition(MessageFormat.Field.ARGUMENT));
+ assertEquals("Choice not recursive:\n" + expectedText + "\n" + buffer, expectedText, buffer.toString());
+
+ StringBuffer str = format.format(new Object[] { new Double(0.6),
+ new Integer(3)}, buffer, null);
+ assertEquals(expectedText + "zero", str.toString());
+ assertEquals(expectedText + "zero", buffer.toString());
+
+ try {
+ format.format(new Object[] { "0", new Double(1), "" }, buffer,
+ new FieldPosition(MessageFormat.Field.ARGUMENT));
+ fail();
+ } catch (IllegalArgumentException expected) {
+ }
- assertEquals("Test2:Returned wrong number of formats:",
- correctFormats.length, formats.length);
- for (int i = 0; i < correctFormats.length; i++) {
- assertEquals("Test2:wrong format for pattern index " + i + ":",
- correctFormats[i], formats[i]);
- }
+ try {
+ format.format(new Object[] { "", new Integer(3)}, buffer,
+ new FieldPosition(MessageFormat.Field.ARGUMENT));
+ fail();
+ } catch (IllegalArgumentException expected) {
+ }
+ }
+
+ public void test_formatLjava_lang_ObjectLjava_lang_StringBufferLjava_text_FieldPosition() {
+ new Support_MessageFormat(
+ "test_formatLjava_lang_ObjectLjava_lang_StringBufferLjava_text_FieldPosition")
+ .t_format_with_FieldPosition();
+
+ String pattern = "On {4,date} at {3,time}, he ate {2,number, integer} hamburger{2,choice,1#|1<s}.";
+ MessageFormat format = new MessageFormat(pattern, Locale.US);
+ Object[] objects = new Object[] { "", new Integer(3), 8, ""};
+ try {
+ format.format(objects, new StringBuffer(), new FieldPosition(DateFormat.Field.AM_PM));
+ fail();
+ } catch (IllegalArgumentException expected) {
+ }
+ }
+
+ public void test_getFormats() {
+ // test with repeating formats and max argument index < max offset
+ Format[] formats = format1.getFormats();
+ Format[] correctFormats = new Format[] {
+ NumberFormat.getCurrencyInstance(),
+ DateFormat.getTimeInstance(),
+ NumberFormat.getPercentInstance(), null,
+ new ChoiceFormat("0#off|1#on"), DateFormat.getDateInstance(), };
+
+ assertEquals("Test1:Returned wrong number of formats:",
+ correctFormats.length, formats.length);
+ for (int i = 0; i < correctFormats.length; i++) {
+ assertEquals("Test1:wrong format for pattern index " + i + ":",
+ correctFormats[i], formats[i]);
+ }
- // test with argument number being zero
- formats = format3.getFormats();
- assertEquals("Test3: Returned wrong number of formats:", 0,
- formats.length);
+ // test with max argument index > max offset
+ formats = format2.getFormats();
+ correctFormats = new Format[] { NumberFormat.getCurrencyInstance(),
+ DateFormat.getTimeInstance(),
+ NumberFormat.getPercentInstance(), null,
+ new ChoiceFormat("0#off|1#on"), DateFormat.getDateInstance() };
+
+ assertEquals("Test2:Returned wrong number of formats:",
+ correctFormats.length, formats.length);
+ for (int i = 0; i < correctFormats.length; i++) {
+ assertEquals("Test2:wrong format for pattern index " + i + ":",
+ correctFormats[i], formats[i]);
}
- /**
- * @tests java.text.MessageFormat#getFormatsByArgumentIndex()
- */
- public void test_getFormatsByArgumentIndex() {
- // Test for method java.text.Format [] test_getFormatsByArgumentIndex()
+ // test with argument number being zero
+ formats = format3.getFormats();
+ assertEquals("Test3: Returned wrong number of formats:", 0,
+ formats.length);
+ }
+ public void test_getFormatsByArgumentIndex() {
// test with repeating formats and max argument index < max offset
Format[] formats = format1.getFormatsByArgumentIndex();
Format[] correctFormats = new Format[] { DateFormat.getDateInstance(),
@@ -475,10 +674,6 @@ public class MessageFormatTest extends TestCase {
formats.length);
}
- /**
- * @tests java.text.MessageFormat#setFormatByArgumentIndex(int,
- * java.text.Format)
- */
public void test_setFormatByArgumentIndexILjava_text_Format() {
// test for method setFormatByArgumentIndex(int, Format)
MessageFormat f1 = (MessageFormat) format1.clone();
@@ -556,11 +751,7 @@ public class MessageFormatTest extends TestCase {
formats.length);
}
- /**
- * @tests java.text.MessageFormat#setFormatsByArgumentIndex(java.text.Format[])
- */
public void test_setFormatsByArgumentIndex$Ljava_text_Format() {
- // test for method setFormatByArgumentIndex(Format[])
MessageFormat f1 = (MessageFormat) format1.clone();
// test with repeating formats and max argument index < max offset
@@ -643,10 +834,6 @@ public class MessageFormatTest extends TestCase {
}
- /**
- * @tests java.text.MessageFormat#parse(java.lang.String,
- * java.text.ParsePosition)
- */
public void test_parseLjava_lang_StringLjava_text_ParsePosition() {
MessageFormat format = new MessageFormat("date is {0,date,MMM d, yyyy}");
ParsePosition pos = new ParsePosition(2);
@@ -665,115 +852,102 @@ public class MessageFormatTest extends TestCase {
mf = new MessageFormat("{0}; {0}; {0}");
String parse = "a; b; c";
result = mf.parse(parse, new ParsePosition(0));
- assertEquals("Wrong variable result", "c", result[0]);
-
- mf = new MessageFormat("before {0}, after {1,number}");
- parse = "before you, after 42";
- pos.setIndex(0);
- pos.setErrorIndex(8);
- result = mf.parse(parse, pos);
- assertEquals(2, result.length);
- }
-
- /**
- * @tests java.text.MessageFormat#setLocale(java.util.Locale)
- */
- public void test_setLocaleLjava_util_Locale() {
- // Test for method void
- // java.text.MessageFormat.setLocale(java.util.Locale)
- MessageFormat format = new MessageFormat("date {0,date}");
- format.setLocale(Locale.CHINA);
- assertEquals("Wrong locale1", Locale.CHINA, format.getLocale());
- format.applyPattern("{1,date}");
- assertEquals("Wrong locale3", DateFormat.getDateInstance(DateFormat.DEFAULT,
- Locale.CHINA), format.getFormats()[0]);
- }
-
- /**
- * @tests java.text.MessageFormat#toPattern()
- */
- public void test_toPattern() {
- // Test for method java.lang.String java.text.MessageFormat.toPattern()
- String pattern = "[{0}]";
- MessageFormat mf = new MessageFormat(pattern);
- assertTrue("Wrong pattern", mf.toPattern().equals(pattern));
-
- // Regression for HARMONY-59
- new MessageFormat("CHOICE {1,choice}").toPattern();
- }
-
- /**
- * Sets up the fixture, for example, open a network connection. This method
- * is called before a test is executed.
- */
- protected void setUp() {
- defaultLocale = Locale.getDefault();
- Locale.setDefault(Locale.US);
-
- // test with repeating formats and max argument index < max offset
- String pattern = "A {3, number, currency} B {2, time} C {0, number, percent} D {4} E {1,choice,0#off|1#on} F {0, date}";
- format1 = new MessageFormat(pattern);
+ assertEquals("Wrong variable result", "c", result[0]);
- // test with max argument index > max offset
- pattern = "A {3, number, currency} B {8, time} C {0, number, percent} D {6} E {1,choice,0#off|1#on} F {0, date}";
- format2 = new MessageFormat(pattern);
+ mf = new MessageFormat("before {0}, after {1,number}");
+ parse = "before you, after 42";
+ pos.setIndex(0);
+ pos.setErrorIndex(8);
+ result = mf.parse(parse, pos);
+ assertEquals(2, result.length);
- // test with argument number being zero
- pattern = "A B C D E F";
- format3 = new MessageFormat(pattern);
- }
-
- /**
- * Tears down the fixture, for example, close a network connection. This
- * method is called after a test is executed.
- */
- protected void tearDown() {
- Locale.setDefault(defaultLocale);
- }
-
- /**
- * @tests java.text.MessageFormat(java.util.Locale)
- */
- public void test_ConstructorLjava_util_Locale() {
- // Regression for HARMONY-65
- try {
- new MessageFormat("{0,number,integer", Locale.US);
- fail("Assert 0: Failed to detect unmatched brackets.");
- } catch (IllegalArgumentException e) {
- // expected
- }
- }
-
- /**
- * @tests java.text.MessageFormat#parse(java.lang.String)
- */
- public void test_parse() throws ParseException {
- // Regression for HARMONY-63
- MessageFormat mf = new MessageFormat("{0,number,#,####}", Locale.US);
- Object[] res = mf.parse("1,00,00");
- assertEquals("Assert 0: incorrect size of parsed data ", 1, res.length);
- assertEquals("Assert 1: parsed value incorrectly", new Long(10000), (Long)res[0]);
- }
-
- public void test_format_Object() {
- // Regression for HARMONY-1875
- Locale.setDefault(Locale.CANADA);
- TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
- String pat="text here {0, date, yyyyyyyyy } and here";
- String etalon="text here 000002007 and here";
- MessageFormat obj = new MessageFormat(pat);
- assertEquals(etalon, obj.format(new Object[]{new Date(1198141737640L)}));
-
- assertEquals("{0}", MessageFormat.format("{0}", (Object[])null));
- assertEquals("nullABC", MessageFormat.format("{0}{1}", new String[]{null, "ABC"}));
- }
-
- public void testHARMONY5323() {
- Object []messageArgs = new Object[11];
- for (int i = 0; i < messageArgs.length; i++)
- messageArgs[i] = "dumb"+i;
-
- String res = MessageFormat.format("bgcolor=\"{10}\"", messageArgs);
- assertEquals(res, "bgcolor=\"dumb10\"");
- }
+ try {
+ mf.parse(parse, null);
+ fail();
+ } catch (NullPointerException expected) {
+ }
+
+ // This should _not_ throw.
+ mf.parse(null, pos);
+ }
+
+ public void test_setLocaleLjava_util_Locale() {
+ MessageFormat format = new MessageFormat("date {0,date}");
+ format.setLocale(Locale.CHINA);
+ assertEquals("Wrong locale1", Locale.CHINA, format.getLocale());
+ format.applyPattern("{1,date}");
+ assertEquals("Wrong locale3", DateFormat.getDateInstance(DateFormat.DEFAULT,
+ Locale.CHINA), format.getFormats()[0]);
+ }
+
+ public void test_toPattern() {
+ String pattern = "[{0}]";
+ MessageFormat mf = new MessageFormat(pattern);
+ assertTrue("Wrong pattern", mf.toPattern().equals(pattern));
+
+ // Regression for HARMONY-59
+ new MessageFormat("CHOICE {1,choice}").toPattern();
+ }
+
+ protected void setUp() {
+ defaultLocale = Locale.getDefault();
+ Locale.setDefault(Locale.US);
+
+ // test with repeating formats and max argument index < max offset
+ String pattern = "A {3, number, currency} B {2, time} C {0, number, percent} D {4} E {1,choice,0#off|1#on} F {0, date}";
+ format1 = new MessageFormat(pattern);
+
+ // test with max argument index > max offset
+ pattern = "A {3, number, currency} B {8, time} C {0, number, percent} D {6} E {1,choice,0#off|1#on} F {0, date}";
+ format2 = new MessageFormat(pattern);
+
+ // test with argument number being zero
+ pattern = "A B C D E F";
+ format3 = new MessageFormat(pattern);
+ }
+
+ protected void tearDown() {
+ Locale.setDefault(defaultLocale);
+ }
+
+ public void test_ConstructorLjava_util_Locale() {
+ // Regression for HARMONY-65
+ try {
+ new MessageFormat("{0,number,integer", Locale.US);
+ fail("Assert 0: Failed to detect unmatched brackets.");
+ } catch (IllegalArgumentException e) {
+ // expected
+ }
+ }
+
+ public void test_parse() throws ParseException {
+ // Regression for HARMONY-63
+ MessageFormat mf = new MessageFormat("{0,number,#,##}", Locale.US);
+ Object[] res = mf.parse("1,00,00");
+ assertEquals("Assert 0: incorrect size of parsed data ", 1, res.length);
+ assertEquals("Assert 1: parsed value incorrectly", new Long(10000), (Long)res[0]);
+ }
+
+ public void test_format_Object() {
+ // Regression for HARMONY-1875
+ Locale.setDefault(Locale.CANADA);
+ TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
+ String pat="text here {0, date, yyyyyyyyy } and here";
+ String etalon="text here 000002007 and here";
+ MessageFormat obj = new MessageFormat(pat);
+ assertEquals(etalon, obj.format(new Object[]{new Date(1198141737640L)}));
+
+ assertEquals("{0}", MessageFormat.format("{0}", (Object[])null));
+ assertEquals("nullABC", MessageFormat.format("{0}{1}", new String[]{null, "ABC"}));
+ }
+
+ public void testHARMONY5323() {
+ Object[] messageArgs = new Object[11];
+ for (int i = 0; i < messageArgs.length; i++) {
+ messageArgs[i] = "example" + i;
+ }
+
+ String res = MessageFormat.format("bgcolor=\"{10}\"", messageArgs);
+ assertEquals(res, "bgcolor=\"example10\"");
+ }
}
diff --git a/harmony-tests/src/test/java/org/apache/harmony/tests/java/text/NumberFormatTest.java b/harmony-tests/src/test/java/org/apache/harmony/tests/java/text/NumberFormatTest.java
index 5de73c2..cb7ac4b 100644
--- a/harmony-tests/src/test/java/org/apache/harmony/tests/java/text/NumberFormatTest.java
+++ b/harmony-tests/src/test/java/org/apache/harmony/tests/java/text/NumberFormatTest.java
@@ -1,13 +1,13 @@
-/*
+/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -174,7 +174,7 @@ public class NumberFormatTest extends junit.framework.TestCase {
format = (DecimalFormat) NumberFormat.getIntegerInstance(arLocale);
assertEquals(
"Test7: NumberFormat.getIntegerInstance(new Locale(\"ar\", \"AE\")).toPattern() returned wrong pattern",
- "#,##0;#,##0-", format.toPattern());
+ "#0;#0-", format.toPattern());
assertEquals(
"Test8: NumberFormat.getIntegerInstance(new Locale(\"ar\", \"AE\")).format(-35.76) returned wrong value",
"\u0666-", format.format(-6));
@@ -249,7 +249,7 @@ public class NumberFormatTest extends junit.framework.TestCase {
public void test_parseObjectLjava_lang_StringLjava_text_ParsePosition() {
// regression test for HARMONY-1003
assertNull(NumberFormat.getInstance().parseObject("0", new ParsePosition(-1)));
-
+
// Regression for HARMONY-1685
try {
NumberFormat.getInstance().parseObject("test", null);
@@ -258,13 +258,13 @@ public class NumberFormatTest extends junit.framework.TestCase {
//expected
}
}
-
+
protected void setUp() {
}
protected void tearDown() {
}
-
+
public void test_setRoundingMode_NullRoundingMode() {
try {
// Create a subclass ChoiceFormat which doesn't support
@@ -291,5 +291,5 @@ public class NumberFormatTest extends junit.framework.TestCase {
// expected
}
}
-
+
}
diff --git a/harmony-tests/src/test/java/org/apache/harmony/tests/java/text/RuleBasedCollatorTest.java b/harmony-tests/src/test/java/org/apache/harmony/tests/java/text/RuleBasedCollatorTest.java
index a9f4c57..3e8f28d 100644
--- a/harmony-tests/src/test/java/org/apache/harmony/tests/java/text/RuleBasedCollatorTest.java
+++ b/harmony-tests/src/test/java/org/apache/harmony/tests/java/text/RuleBasedCollatorTest.java
@@ -5,9 +5,9 @@
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
@@ -30,280 +30,234 @@ import junit.framework.TestCase;
public class RuleBasedCollatorTest extends TestCase {
- public void test_getCollationKeyLjava_lang_String() {
- // Regression test for HARMONY-28
- String source = null;
- RuleBasedCollator rbc = null;
- try {
- String Simple = "< a< b< c< d";
- rbc = new RuleBasedCollator(Simple);
- } catch (ParseException e) {
- fail("Assert 0: Unexpected format exception " + e);
- }
- CollationKey ck = rbc.getCollationKey(source);
- assertNull("Assert 1: getCollationKey (null) does not return null", ck);
- }
-
- public void testHashCode() throws ParseException {
- {
- String rule = "< a < b < c < d";
- RuleBasedCollator coll = new RuleBasedCollator(rule);
- assertEquals(rule.hashCode(), coll.hashCode());
- }
-
- {
- String rule = "< a < b < c < d < e";
- RuleBasedCollator coll = new RuleBasedCollator(rule);
- assertEquals(rule.hashCode(), coll.hashCode());
- }
-
- }
-
- public void testClone() throws ParseException {
- RuleBasedCollator coll = (RuleBasedCollator) Collator
- .getInstance(Locale.US);
- RuleBasedCollator clone = (RuleBasedCollator) coll.clone();
- assertNotSame(coll, clone);
- assertEquals(coll.getRules(), clone.getRules());
- assertEquals(coll.getDecomposition(), clone.getDecomposition());
- assertEquals(coll.getStrength(), clone.getStrength());
+ public void test_getCollationKeyLjava_lang_String() throws Exception {
+ // Regression test for HARMONY-28
+ String source = null;
+ String Simple = "< a< b< c< d";
+ RuleBasedCollator rbc = new RuleBasedCollator(Simple);
+ CollationKey ck = rbc.getCollationKey(source);
+ assertNull("Assert 1: getCollationKey (null) does not return null", ck);
+ }
+
+ public void testHashCode() throws ParseException {
+ {
+ String rule = "< a < b < c < d";
+ RuleBasedCollator coll = new RuleBasedCollator(rule);
+ assertEquals(rule.hashCode(), coll.hashCode());
}
- /*
- * Class under test for boolean equals(java.lang.Object)
- */
- public void testEqualsObject() throws ParseException {
- String rule = "< a < b < c < d < e";
- RuleBasedCollator coll = new RuleBasedCollator(rule);
-
- assertEquals(Collator.TERTIARY, coll.getStrength());
- assertEquals(Collator.NO_DECOMPOSITION, coll.getDecomposition());
- RuleBasedCollator other = new RuleBasedCollator(rule);
- assertTrue(coll.equals(other));
-
- coll.setStrength(Collator.PRIMARY);
- assertFalse(coll.equals(other));
-
- coll.setStrength(Collator.TERTIARY);
- coll.setDecomposition(Collator.CANONICAL_DECOMPOSITION);
- assertFalse(coll.equals(other));
+ {
+ String rule = "< a < b < c < d < e";
+ RuleBasedCollator coll = new RuleBasedCollator(rule);
+ assertEquals(rule.hashCode(), coll.hashCode());
}
-
- /*
- * Class under test for int compare(java.lang.String, java.lang.String)
- */
- public void testCompareStringString() throws ParseException {
- String rule = "< c < b < a";
- RuleBasedCollator coll = new RuleBasedCollator(rule);
- assertEquals(-1, coll.compare("c", "a"));
- }
-
- public void testGetCollationKey() {
- RuleBasedCollator coll = (RuleBasedCollator) Collator
- .getInstance(Locale.GERMAN);
- String source = "abc";
- CollationKey key1 = coll.getCollationKey(source);
- assertEquals(source, key1.getSourceString());
- String source2 = "abb";
- CollationKey key2 = coll.getCollationKey(source2);
- assertEquals(source2, key2.getSourceString());
- assertTrue(key1.compareTo(key2) > 0);
- assertTrue(coll.compare(source, source2) > 0);
-
- }
-
- public void testGetRules() throws ParseException {
- String rule = "< a = b < c";
- RuleBasedCollator coll = new RuleBasedCollator(rule);
- assertEquals(rule, coll.getRules());
+ }
+
+ public void testClone() throws ParseException {
+ RuleBasedCollator coll = (RuleBasedCollator) Collator.getInstance(Locale.US);
+ RuleBasedCollator clone = (RuleBasedCollator) coll.clone();
+ assertNotSame(coll, clone);
+ assertEquals(coll.getRules(), clone.getRules());
+ assertEquals(coll.getDecomposition(), clone.getDecomposition());
+ assertEquals(coll.getStrength(), clone.getStrength());
+ }
+
+ public void testEqualsObject() throws ParseException {
+ String rule = "< a < b < c < d < e";
+ RuleBasedCollator coll = new RuleBasedCollator(rule);
+
+ assertEquals(Collator.TERTIARY, coll.getStrength());
+ assertEquals(Collator.NO_DECOMPOSITION, coll.getDecomposition());
+ RuleBasedCollator other = new RuleBasedCollator(rule);
+ assertTrue(coll.equals(other));
+
+ coll.setStrength(Collator.PRIMARY);
+ assertFalse(coll.equals(other));
+
+ coll.setStrength(Collator.TERTIARY);
+ coll.setDecomposition(Collator.CANONICAL_DECOMPOSITION);
+ assertFalse(coll.equals(other));
+ }
+
+ public void testCompareStringString() throws ParseException {
+ String rule = "< c < b < a";
+ RuleBasedCollator coll = new RuleBasedCollator(rule);
+ assertEquals(-1, coll.compare("c", "a"));
+ }
+
+ public void testGetCollationKey() {
+ RuleBasedCollator coll = (RuleBasedCollator) Collator.getInstance(Locale.GERMAN);
+ String source = "abc";
+ CollationKey key1 = coll.getCollationKey(source);
+ assertEquals(source, key1.getSourceString());
+ String source2 = "abb";
+ CollationKey key2 = coll.getCollationKey(source2);
+ assertEquals(source2, key2.getSourceString());
+ assertTrue(key1.compareTo(key2) > 0);
+ assertTrue(coll.compare(source, source2) > 0);
+ }
+
+ public void testGetRules() throws ParseException {
+ String rule = "< a = b < c";
+ RuleBasedCollator coll = new RuleBasedCollator(rule);
+ assertEquals(rule, coll.getRules());
+ }
+
+ public void testGetCollationElementIteratorString() throws Exception {
+ {
+ Locale locale = new Locale("es", "", "TRADITIONAL");
+ RuleBasedCollator coll = (RuleBasedCollator) Collator.getInstance(locale);
+ String source = "cha";
+ CollationElementIterator iterator = coll.getCollationElementIterator(source);
+ int[] e_offset = { 0, 2, 3 };
+ int offset = iterator.getOffset();
+ int i = 0;
+ assertEquals(e_offset[i++], offset);
+ while (offset != source.length()) {
+ iterator.next();
+ offset = iterator.getOffset();
+ assertEquals(e_offset[i++], offset);
+ }
+ assertEquals(CollationElementIterator.NULLORDER, iterator.next());
}
- /*
- * Class under test for java.text.CollationElementIterator
- * getCollationElementIterator(java.lang.String)
- */
- public void testGetCollationElementIteratorString() throws Exception {
- {
- Locale locale = new Locale("es", "", "TRADITIONAL");
- RuleBasedCollator coll = (RuleBasedCollator) Collator
- .getInstance(locale);
- String source = "cha";
- CollationElementIterator iterator = coll
- .getCollationElementIterator(source);
- int[] e_offset = { 0, 2 ,3};
- int offset = iterator.getOffset();
- int i = 0;
- assertEquals(e_offset[i++], offset);
- while (offset != source.length()) {
- iterator.next();
- offset = iterator.getOffset();
- assertEquals(e_offset[i++], offset);
- }
- }
-
- {
- Locale locale = new Locale("de", "DE");
- RuleBasedCollator coll = (RuleBasedCollator) Collator
- .getInstance(locale);
- String source = "\u00E6b";
- CollationElementIterator iterator = coll
- .getCollationElementIterator(source);
- int[] e_offset = { 0, 1, 1, 2 };
- int offset = iterator.getOffset();
- int i = 0;
- assertEquals(e_offset[i++], offset);
- while (offset != source.length()) {
- iterator.next();
- offset = iterator.getOffset();
- assertEquals(e_offset[i++], offset);
- }
- }
- //Regression for HARMONY-1352
- try {
- new RuleBasedCollator("< a< b< c< d").getCollationElementIterator((String)null);
- fail("NullPointerException expected");
- } catch (NullPointerException e) {
- //expected
- }
+ {
+ Locale locale = new Locale("de", "DE");
+ RuleBasedCollator coll = (RuleBasedCollator) Collator.getInstance(locale);
+ String source = "\u00fcb";
+ CollationElementIterator iterator = coll.getCollationElementIterator(source);
+ int[] e_offset = { 0, 1, 1, 2 };
+ int offset = iterator.getOffset();
+ int i = 0;
+ assertEquals(e_offset[i++], offset);
+ while (offset != source.length()) {
+ iterator.next();
+ offset = iterator.getOffset();
+ assertEquals(e_offset[i++], offset);
+ }
+ assertEquals(CollationElementIterator.NULLORDER, iterator.next());
}
-
- /*
- * Class under test for java.text.CollationElementIterator
- * getCollationElementIterator(java.text.CharacterIterator)
- */
- public void testGetCollationElementIteratorCharacterIterator() throws Exception {
- {
- Locale locale = new Locale("es", "", "TRADITIONAL");
- RuleBasedCollator coll = (RuleBasedCollator) Collator
- .getInstance(locale);
- String text = "cha";
- StringCharacterIterator source = new StringCharacterIterator(text);
- CollationElementIterator iterator = coll
- .getCollationElementIterator(source);
- int[] e_offset = { 0, 2, 3 };
- int offset = iterator.getOffset();
- int i = 0;
- assertEquals(e_offset[i++], offset);
- while (offset != text.length()) {
- iterator.next();
- offset = iterator.getOffset();
- // System.out.println(offset);
- assertEquals(e_offset[i++], offset);
- }
- }
-
- {
- Locale locale = new Locale("de", "DE");
- RuleBasedCollator coll = (RuleBasedCollator) Collator
- .getInstance(locale);
- String text = "\u00E6b";
- StringCharacterIterator source = new StringCharacterIterator(text);
- CollationElementIterator iterator = coll
- .getCollationElementIterator(source);
- int[] e_offset = { 0, 1, 1, 2 };
- int offset = iterator.getOffset();
- int i = 0;
- assertEquals(e_offset[i++], offset);
- while (offset != text.length()) {
- iterator.next();
- offset = iterator.getOffset();
- assertEquals(e_offset[i++], offset);
- }
- }
- //Regression for HARMONY-1352
- try {
- new RuleBasedCollator("< a< b< c< d").getCollationElementIterator((CharacterIterator)null);
- fail("NullPointerException expected");
- } catch (NullPointerException e) {
- //expected
- }
+ //Regression for HARMONY-1352
+ try {
+ new RuleBasedCollator("< a< b< c< d").getCollationElementIterator((String)null);
+ fail();
+ } catch (NullPointerException expected) {
}
-
- public void testStrength() {
- RuleBasedCollator coll = (RuleBasedCollator) Collator
- .getInstance(Locale.US);
- for (int i = 0; i < 4; i++) {
- coll.setStrength(i);
- assertEquals(i, coll.getStrength());
- }
-
+ }
+
+ public void testGetCollationElementIteratorCharacterIterator() throws Exception {
+ {
+ Locale locale = new Locale("es", "", "TRADITIONAL");
+ RuleBasedCollator coll = (RuleBasedCollator) Collator.getInstance(locale);
+ String text = "cha";
+ StringCharacterIterator source = new StringCharacterIterator(text);
+ CollationElementIterator iterator = coll.getCollationElementIterator(source);
+ int[] e_offset = { 0, 2, 3 };
+ int offset = iterator.getOffset();
+ int i = 0;
+ assertEquals(e_offset[i++], offset);
+ while (offset != text.length()) {
+ iterator.next();
+ offset = iterator.getOffset();
+ // System.out.println(offset);
+ assertEquals(e_offset[i++], offset);
+ }
+ assertEquals(CollationElementIterator.NULLORDER, iterator.next());
}
- public void testDecomposition() {
- RuleBasedCollator coll = (RuleBasedCollator) Collator
- .getInstance(Locale.US);
- for (int i = 0; i < 2; i++) {
- coll.setDecomposition(i);
- assertEquals(i, coll.getDecomposition());
- }
+ {
+ Locale locale = new Locale("de", "DE");
+ RuleBasedCollator coll = (RuleBasedCollator) Collator.getInstance(locale);
+ String text = "\u00fcb";
+ StringCharacterIterator source = new StringCharacterIterator(text);
+ CollationElementIterator iterator = coll.getCollationElementIterator(source);
+ int[] e_offset = { 0, 1, 1, 2 };
+ int offset = iterator.getOffset();
+ int i = 0;
+ assertEquals(e_offset[i++], offset);
+ while (offset != text.length()) {
+ iterator.next();
+ offset = iterator.getOffset();
+ assertEquals(e_offset[i++], offset);
+ }
+ assertEquals(CollationElementIterator.NULLORDER, iterator.next());
}
-
- public void testCollator_GetInstance() {
- Collator coll = Collator.getInstance();
- Object obj1 = "a";
- Object obj2 = "b";
- assertEquals(-1, coll.compare(obj1, obj2));
-
- Collator.getInstance();
- assertFalse(coll.equals("A", "\uFF21"));
+ //Regression for HARMONY-1352
+ try {
+ new RuleBasedCollator("< a< b< c< d").getCollationElementIterator((CharacterIterator)null);
+ fail();
+ } catch (NullPointerException expected) {
}
+ }
- public void testGetAvailableLocales() {
- // Locale[] locales = Collator.getAvailableLocales();
- // for (int i = 0; i < locales.length; i++) {
- // Locale locale = locales[i];
- // }
+ public void testStrength() {
+ RuleBasedCollator coll = (RuleBasedCollator) Collator.getInstance(Locale.US);
+ for (int i = 0; i < 4; i++) {
+ coll.setStrength(i);
+ assertEquals(i, coll.getStrength());
}
+ }
- // Test CollationKey
- public void testCollationKey() {
- Collator coll = Collator.getInstance(Locale.US);
- String text = "abc";
- CollationKey key = coll.getCollationKey(text);
- key.hashCode();
-
- CollationKey key2 = coll.getCollationKey("abc");
-
- assertEquals(0, key.compareTo(key2));
+ public void testDecomposition() {
+ RuleBasedCollator coll = (RuleBasedCollator) Collator.getInstance(Locale.US);
+ for (int i = 0; i < 2; i++) {
+ coll.setDecomposition(i);
+ assertEquals(i, coll.getDecomposition());
}
-
- /**
- * @tests java.text.RuleBasedCollator.RuleBasedCollator(java.lang.String)
- */
- public void testNullPointerException() throws Exception {
- //Regression for HARMONY-241
- try {
- new RuleBasedCollator(null);
- fail("Constructor RuleBasedCollator(null) "
- + "should throw NullPointerException");
- } catch (NullPointerException e) {}
+ }
+
+ public void testCollator_GetInstance() {
+ Collator coll = Collator.getInstance();
+ Object obj1 = "a";
+ Object obj2 = "b";
+ assertEquals(-1, coll.compare(obj1, obj2));
+
+ Collator.getInstance();
+ assertFalse(coll.equals("A", "\uFF21"));
+ }
+
+ public void testGetAvailableLocales() {
+ assertTrue(Collator.getAvailableLocales().length > 0);
+ }
+
+ // Test CollationKey
+ public void testCollationKey() {
+ Collator coll = Collator.getInstance(Locale.US);
+ String text = "abc";
+ CollationKey key = coll.getCollationKey(text);
+ key.hashCode();
+
+ CollationKey key2 = coll.getCollationKey("abc");
+
+ assertEquals(0, key.compareTo(key2));
+ }
+
+ public void testNullPointerException() throws Exception {
+ //Regression for HARMONY-241
+ try {
+ new RuleBasedCollator(null);
+ fail();
+ } catch (NullPointerException expected) {
}
-
- /**
- * @tests java.text.RuleBasedCollator.compare(java.lang.String, java.lang.String)
- */
- public void testCompareNull() throws Exception {
- //Regression for HARMONY-836
- try {
- new RuleBasedCollator("< a").compare(null, null);
- fail("RuleBasedCollator.compare(null, null) "
- + "should throw NullPointerException");
- } catch (NullPointerException e) {}
+ }
+
+ public void testCompareNull() throws Exception {
+ //Regression for HARMONY-836
+ try {
+ new RuleBasedCollator("< a").compare(null, null);
+ fail();
+ } catch (NullPointerException expected) {
}
-
- /**
- * @tests java.text.RuleBasedCollator.RuleBasedCollator(java.lang.String)
- */
- public void testEmptyStringException() {
- //Regression for HARMONY-241
- try {
- new RuleBasedCollator("");
- fail("Constructor RuleBasedCollator(\"\") "
- + "should throw ParseException");
- } catch (ParseException e) {
- assertEquals("java.text.ParseException", e.getClass().getName());
- assertEquals(0, e.getErrorOffset());
- }
+ }
+
+ public void testEmptyStringException() {
+ //Regression for HARMONY-241
+ try {
+ new RuleBasedCollator("");
+ fail();
+ } catch (ParseException e) {
+ assertEquals("java.text.ParseException", e.getClass().getName());
+ assertEquals(0, e.getErrorOffset());
}
-
+ }
}
diff --git a/harmony-tests/src/test/java/org/apache/harmony/tests/java/text/SimpleDateFormatTest.java b/harmony-tests/src/test/java/org/apache/harmony/tests/java/text/SimpleDateFormatTest.java
index 1c932b5..91fb2cf 100644
--- a/harmony-tests/src/test/java/org/apache/harmony/tests/java/text/SimpleDateFormatTest.java
+++ b/harmony-tests/src/test/java/org/apache/harmony/tests/java/text/SimpleDateFormatTest.java
@@ -1,13 +1,13 @@
-/*
+/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -140,7 +140,7 @@ public class SimpleDateFormatTest extends junit.framework.TestCase {
fail("Expected test_ConstructorLjava_lang_String to throw IAE.");
} catch (IllegalArgumentException ex) {
// expected
- }
+ }
// Null string value
try {
@@ -148,7 +148,7 @@ public class SimpleDateFormatTest extends junit.framework.TestCase {
fail("Expected test_ConstructorLjava_lang_String to throw NPE.");
} catch (NullPointerException ex) {
// expected
- }
+ }
}
/**
@@ -185,47 +185,30 @@ public class SimpleDateFormatTest extends junit.framework.TestCase {
f2.format(new Date()).getClass() == String.class);
}
- /**
- * @tests java.text.SimpleDateFormat#applyLocalizedPattern(java.lang.String)
- */
public void test_applyLocalizedPatternLjava_lang_String() {
- // Test for method void
- // java.text.SimpleDateFormat.applyLocalizedPattern(java.lang.String)
SimpleDateFormat f2 = new SimpleDateFormat("y", new Locale("de", "CH"));
- f2.applyLocalizedPattern("GuMtkHmsSEDFwWahKz");
- String pattern = f2.toPattern();
-// assertTrue("Wrong pattern: " + pattern, pattern
-// .equals("GyMdkHmsSEDFwWahKz"));
-
- // test the new "Z" pattern char
- f2 = new SimpleDateFormat("y", new Locale("de", "CH"));
- f2.applyLocalizedPattern("G u M t Z");
- pattern = f2.toPattern();
-// assertTrue("Wrong pattern: " + pattern, pattern.equals("G y M d Z"));
+ String pattern = "GyMdkHmsSEDFwWahKzZLc";
+ f2.applyLocalizedPattern(pattern);
+ assertEquals(pattern, f2.toPattern());
+ assertEquals(pattern, f2.toLocalizedPattern());
// test invalid patterns
-// try {
-// f2.applyLocalizedPattern("b");
-// fail("Expected IllegalArgumentException for pattern with invalid pattern letter: b");
-// } catch (IllegalArgumentException e) {
-// }
-
-// try {
-// f2.applyLocalizedPattern("y");
-// fail("Expected IllegalArgumentException for pattern with invalid pattern letter: y");
-// } catch (IllegalArgumentException e) {
-// }
+ try {
+ f2.applyLocalizedPattern("b");
+ fail();
+ } catch (IllegalArgumentException expected) {
+ }
try {
- f2.applyLocalizedPattern("a '");
- fail("Expected IllegalArgumentException for pattern with unterminated quote: a '");
- } catch (IllegalArgumentException e) {
+ f2.applyLocalizedPattern("a '"); // Unterminated quote.
+ fail();
+ } catch (IllegalArgumentException expected) {
}
try {
f2.applyLocalizedPattern(null);
- fail("Expected NullPointerException for null pattern");
- } catch (NullPointerException e) {
+ fail();
+ } catch (NullPointerException expected) {
}
}
@@ -303,19 +286,14 @@ public class SimpleDateFormatTest extends junit.framework.TestCase {
assertEquals(df, new SimpleDateFormat());
}
- /**
- * @tests java.text.SimpleDateFormat#formatToCharacterIterator(java.lang.Object)
- */
public void test_formatToCharacterIteratorLjava_lang_Object() {
-
try {
// Regression for HARMONY-466
new SimpleDateFormat().formatToCharacterIterator(null);
- fail("NullPointerException expected");
- } catch (NullPointerException e) {
- // expected
+ fail();
+ } catch (NullPointerException expected) {
}
-
+
// Test for method formatToCharacterIterator(java.lang.Object)
new Support_SimpleDateFormat(
"test_formatToCharacterIteratorLjava_lang_Object")
@@ -345,7 +323,7 @@ public class SimpleDateFormatTest extends junit.framework.TestCase {
test.test(" G", new GregorianCalendar(-1999, Calendar.JUNE, 2), " BC",
DateFormat.ERA_FIELD);
- test.test(" y", cal, " 99", DateFormat.YEAR_FIELD);
+ test.test(" y", cal, " 1999", DateFormat.YEAR_FIELD);
test.test(" yy", cal, " 99", DateFormat.YEAR_FIELD);
test.test(" yy", new GregorianCalendar(2001, Calendar.JUNE, 2), " 01",
DateFormat.YEAR_FIELD);
@@ -363,8 +341,7 @@ public class SimpleDateFormatTest extends junit.framework.TestCase {
test.test(" MM", cal, " 06", DateFormat.MONTH_FIELD);
test.test(" MMM", cal, " Jun", DateFormat.MONTH_FIELD);
test.test(" MMMM", cal, " June", DateFormat.MONTH_FIELD);
- // It is an ICU defect.
- //test.test(" MMMMM", cal, " June", DateFormat.MONTH_FIELD);
+ test.test(" MMMMM", cal, " J", DateFormat.MONTH_FIELD);
test.test(" d", cal, " 2", DateFormat.DATE_FIELD);
test.test(" d", new GregorianCalendar(1999, Calendar.NOVEMBER, 12),
@@ -414,8 +391,7 @@ public class SimpleDateFormatTest extends junit.framework.TestCase {
test.test(" EE", cal, " Wed", DateFormat.DAY_OF_WEEK_FIELD);
test.test(" EEE", cal, " Wed", DateFormat.DAY_OF_WEEK_FIELD);
test.test(" EEEE", cal, " Wednesday", DateFormat.DAY_OF_WEEK_FIELD);
- // ICU defect
- //test.test(" EEEEE", cal, " Wednesday", DateFormat.DAY_OF_WEEK_FIELD);
+ test.test(" EEEEE", cal, " W", DateFormat.DAY_OF_WEEK_FIELD);
test.test(" D", cal, " 153", DateFormat.DAY_OF_YEAR_FIELD);
test.test(" DD", cal, " 153", DateFormat.DAY_OF_YEAR_FIELD);
@@ -432,8 +408,8 @@ public class SimpleDateFormatTest extends junit.framework.TestCase {
test.test(" wwww", cal, " 0023", DateFormat.WEEK_OF_YEAR_FIELD);
test.test(" W", cal, " 1", DateFormat.WEEK_OF_MONTH_FIELD);
- test.test(" W", new GregorianCalendar(1999, Calendar.NOVEMBER, 14),
- " 2", DateFormat.WEEK_OF_MONTH_FIELD);
+// test.test(" W", new GregorianCalendar(1999, Calendar.NOVEMBER, 14),
+// " 2", DateFormat.WEEK_OF_MONTH_FIELD);
test.test(" WW", cal, " 01", DateFormat.WEEK_OF_MONTH_FIELD);
test.test(" WWWW", cal, " 0001", DateFormat.WEEK_OF_MONTH_FIELD);
@@ -470,22 +446,17 @@ public class SimpleDateFormatTest extends junit.framework.TestCase {
test.test(" z", temp2, " GMT-05:00", DateFormat.TIMEZONE_FIELD);
test.test(" zz", cal, " GMT-05:00", DateFormat.TIMEZONE_FIELD);
test.test(" zzz", cal, " GMT-05:00", DateFormat.TIMEZONE_FIELD);
- test.test(" zzzz", cal, " GMT-05:00",
- DateFormat.TIMEZONE_FIELD);
- test.test(" zzzz", temp2, " GMT-05:00",
- DateFormat.TIMEZONE_FIELD);
- test.test(" zzzzz", cal, " GMT-05:00",
- DateFormat.TIMEZONE_FIELD);
+ test.test(" zzzz", cal, " GMT-05:00", DateFormat.TIMEZONE_FIELD);
+ test.test(" zzzz", temp2, " GMT-05:00", DateFormat.TIMEZONE_FIELD);
+ test.test(" zzzzz", cal, " GMT-05:00", DateFormat.TIMEZONE_FIELD);
format.setTimeZone(new SimpleTimeZone(60000, "ONE MINUTE"));
- test.test(" z", cal, " GMT+00:00", DateFormat.TIMEZONE_FIELD);
- test.test(" zzzz", cal, " GMT+00:00", DateFormat.TIMEZONE_FIELD);
+ test.test(" z", cal, " GMT+00:01", DateFormat.TIMEZONE_FIELD);
+ test.test(" zzzz", cal, " GMT+00:01", DateFormat.TIMEZONE_FIELD);
format.setTimeZone(new SimpleTimeZone(5400000, "ONE HOUR, THIRTY"));
- test.test(" z", cal, " GMT+00:00", DateFormat.TIMEZONE_FIELD);
- format
- .setTimeZone(new SimpleTimeZone(-5400000,
- "NEG ONE HOUR, THIRTY"));
- test.test(" z", cal, " GMT+00:00", DateFormat.TIMEZONE_FIELD);
+ test.test(" z", cal, " GMT+01:30", DateFormat.TIMEZONE_FIELD);
+ format.setTimeZone(new SimpleTimeZone(-5400000, "NEG ONE HOUR, THIRTY"));
+ test.test(" z", cal, " GMT-01:30", DateFormat.TIMEZONE_FIELD);
format.applyPattern("'Mkz''':.@5");
assertEquals("Wrong output", "Mkz':.@5", format.format(new Date()));
@@ -496,50 +467,41 @@ public class SimpleDateFormatTest extends junit.framework.TestCase {
SimpleDateFormat dateFormat = new SimpleDateFormat();
try {
dateFormat.format(null, new StringBuffer(), new FieldPosition(1));
- fail("Expected test to throw NPE.");
- } catch (NullPointerException ex) {
- // expected
- }
+ fail();
+ } catch (NullPointerException expected) {
+ }
}
- /**
- * @tests java.text.SimpleDateFormat#format(java.util.Date)
- */
public void test_timeZoneFormatting() {
// tests specific to formatting of timezones
- Date summerDate = new GregorianCalendar(1999, Calendar.JUNE, 2, 15, 3,
- 6).getTime();
- Date winterDate = new GregorianCalendar(1999, Calendar.JANUARY, 12)
- .getTime();
+ Date summerDate = new GregorianCalendar(1999, Calendar.JUNE, 2, 15, 3, 6).getTime();
+ Date winterDate = new GregorianCalendar(1999, Calendar.JANUARY, 12).getTime();
TestFormat test = new TestFormat(
"test_formatLjava_util_DateLjava_lang_StringBufferLjava_text_FieldPosition");
- test.verifyFormatTimezone("PST", "PDT, Pacific Daylight Time",
- "-0700, GMT-07:00", summerDate);
- test.verifyFormatTimezone("PST", "PST, Pacific Standard Time",
- "-0800, GMT-08:00", winterDate);
+ test.verifyFormatTimezone("America/Los_Angeles", "PDT, Pacific Daylight Time", "-0700, GMT-07:00", summerDate);
+ test.verifyFormatTimezone("America/Los_Angeles", "PST, Pacific Standard Time", "-0800, GMT-08:00", winterDate);
+
+ test.verifyFormatTimezone("GMT-7", "GMT-07:00, GMT-07:00", "-0700, GMT-07:00", summerDate);
+ test.verifyFormatTimezone("GMT-7", "GMT-07:00, GMT-07:00", "-0700, GMT-07:00", winterDate);
+
+ test.verifyFormatTimezone("GMT+14", "GMT+14:00, GMT+14:00", "+1400, GMT+14:00", summerDate);
+ test.verifyFormatTimezone("GMT+14", "GMT+14:00, GMT+14:00", "+1400, GMT+14:00", winterDate);
- test.verifyFormatTimezone("GMT-7", "GMT-07:00, GMT-07:00",
- "-0700, GMT-07:00", summerDate);
- test.verifyFormatTimezone("GMT-7", "GMT-07:00, GMT-07:00",
- "-0700, GMT-07:00", winterDate);
+ // this fails on the RI!
+ test.verifyFormatTimezone("America/Detroit", "EDT, Eastern Daylight Time", "-0400, GMT-04:00", summerDate);
+ test.verifyFormatTimezone("America/Detroit", "EST, Eastern Standard Time", "-0500, GMT-05:00", winterDate);
// Pacific/Kiritimati is one of the timezones supported only in mJava
- test.verifyFormatTimezone("Pacific/Kiritimati", "GMT+14:00, Line Islands Time",
- "+1400, GMT+14:00", summerDate);
- test.verifyFormatTimezone("Pacific/Kiritimati", "GMT+14:00, Line Islands Time",
- "+1400, GMT+14:00", winterDate);
-
- test.verifyFormatTimezone("EST", "GMT-05:00, GMT-05:00",
- "-0500, GMT-05:00", summerDate);
- test.verifyFormatTimezone("EST", "GMT-05:00, GMT-05:00",
- "-0500, GMT-05:00", winterDate);
-
- test.verifyFormatTimezone("GMT+14", "GMT+14:00, GMT+14:00",
- "+1400, GMT+14:00", summerDate);
- test.verifyFormatTimezone("GMT+14", "GMT+14:00, GMT+14:00",
- "+1400, GMT+14:00", winterDate);
+ test.verifyFormatTimezone("Pacific/Kiritimati", "GMT+14:00, Line Islands Time", "+1400, GMT+14:00", summerDate);
+ test.verifyFormatTimezone("Pacific/Kiritimati", "GMT+14:00, Line Islands Time", "+1400, GMT+14:00", winterDate);
+
+ test.verifyFormatTimezone("EST", "GMT-05:00, GMT-05:00", "-0500, GMT-05:00", summerDate);
+ test.verifyFormatTimezone("EST", "GMT-05:00, GMT-05:00", "-0500, GMT-05:00", winterDate);
+
+ test.verifyFormatTimezone("GMT+14", "GMT+14:00, GMT+14:00", "+1400, GMT+14:00", summerDate);
+ test.verifyFormatTimezone("GMT+14", "GMT+14:00, GMT+14:00", "+1400, GMT+14:00", winterDate);
}
/**
@@ -823,22 +785,9 @@ public class SimpleDateFormatTest extends junit.framework.TestCase {
symbols));
}
- /**
- * @tests java.text.SimpleDateFormat#toLocalizedPattern()
- */
public void test_toLocalizedPattern() {
- // Test for method java.lang.String
- // java.text.SimpleDateFormat.toLocalizedPattern()
- SimpleDateFormat f2 = new SimpleDateFormat("GyMdkHmsSEDFwWahKz",
- new Locale("de", "CH"));
- String pattern = f2.toLocalizedPattern();
- assertTrue("Wrong pattern: " + pattern, pattern
- .equals("GuMtkHmsSEDFwWahKz"));
-
- // test the new "Z" pattern char
- f2 = new SimpleDateFormat("G y M d Z", new Locale("de", "CH"));
- pattern = f2.toLocalizedPattern();
- assertTrue("Wrong pattern: " + pattern, pattern.equals("G u M t Z"));
+ SimpleDateFormat f2 = new SimpleDateFormat("GyMdkHmsSEDFwWahKzZLc", new Locale("de", "CH"));
+ assertEquals(f2.toPattern(), f2.toLocalizedPattern());
}
/**
diff --git a/harmony-tests/src/test/java/org/apache/harmony/tests/java/text/Support_DecimalFormat.java b/harmony-tests/src/test/java/org/apache/harmony/tests/java/text/Support_DecimalFormat.java
index 052aa7b..9a55bc3 100644
--- a/harmony-tests/src/test/java/org/apache/harmony/tests/java/text/Support_DecimalFormat.java
+++ b/harmony-tests/src/test/java/org/apache/harmony/tests/java/text/Support_DecimalFormat.java
@@ -1,13 +1,13 @@
-/*
+/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -22,266 +22,223 @@ import java.text.NumberFormat;
import java.util.Locale;
import java.util.Vector;
-
public class Support_DecimalFormat extends Support_Format {
- public Support_DecimalFormat(String p1) {
- super(p1);
- }
-
- @Override
- public void runTest() {
- t_formatToCharacterIterator();
- t_format_with_FieldPosition();
- }
-
- public static void main(String[] args) {
- new Support_DecimalFormat("").runTest();
- }
-
- public void t_format_with_FieldPosition() {
- DecimalFormat format = (DecimalFormat) NumberFormat
- .getCurrencyInstance(Locale.US);
- Number number = new Double(10000000.76);
- String text = "$10,000,000.76";
-
- t_FormatWithField(0, format, number, text, NumberFormat.Field.CURRENCY,
- 0, 1);
- t_FormatWithField(1, format, number, text, NumberFormat.Field.INTEGER,
- 1, 11);
- t_FormatWithField(2, format, number, text,
- NumberFormat.Field.GROUPING_SEPARATOR, 3, 4);
- t_FormatWithField(3, format, number, text,
- NumberFormat.Field.DECIMAL_SEPARATOR, 11, 12);
- t_FormatWithField(4, format, number, text, NumberFormat.Field.FRACTION,
- 12, 14);
-
- // test fields that are not included in the formatted text
- t_FormatWithField(5, format, number, text, NumberFormat.Field.SIGN, 0,
- 0);
- t_FormatWithField(6, format, number, text, NumberFormat.Field.EXPONENT,
- 0, 0);
- t_FormatWithField(7, format, number, text,
- NumberFormat.Field.EXPONENT_SIGN, 0, 0);
- t_FormatWithField(8, format, number, text,
- NumberFormat.Field.EXPONENT_SYMBOL, 0, 0);
- t_FormatWithField(9, format, number, text, NumberFormat.Field.PERCENT,
- 0, 0);
- t_FormatWithField(10, format, number, text,
- NumberFormat.Field.PERMILLE, 0, 0);
-
- // test Exponential
- format = new DecimalFormat("000000000.0#E0");
- text = "100000007.6E-1";
- t_FormatWithField(11, format, number, text, NumberFormat.Field.INTEGER,
- 0, 9);
- t_FormatWithField(12, format, number, text,
- NumberFormat.Field.DECIMAL_SEPARATOR, 9, 10);
- t_FormatWithField(13, format, number, text,
- NumberFormat.Field.FRACTION, 10, 11);
- t_FormatWithField(14, format, number, text,
- NumberFormat.Field.EXPONENT_SYMBOL, 11, 12);
- t_FormatWithField(15, format, number, text,
- NumberFormat.Field.EXPONENT_SIGN, 12, 13);
- t_FormatWithField(16, format, number, text,
- NumberFormat.Field.EXPONENT, 13, 14);
-
- // test fields that are not included in the formatted text
- t_FormatWithField(17, format, number, text,
- NumberFormat.Field.GROUPING_SEPARATOR, 0, 0);
- t_FormatWithField(18, format, number, text, NumberFormat.Field.SIGN, 0,
- 0);
- t_FormatWithField(19, format, number, text,
- NumberFormat.Field.CURRENCY, 0, 0);
- t_FormatWithField(20, format, number, text, NumberFormat.Field.PERCENT,
- 0, 0);
- t_FormatWithField(21, format, number, text,
- NumberFormat.Field.PERMILLE, 0, 0);
-
- // test currency instance with TR Locale
- number = new Double(350.76);
- format = (DecimalFormat) NumberFormat.getCurrencyInstance(new Locale(
- "tr", "TR"));
- text = "351 TL";
- t_FormatWithField(22, format, number, text, NumberFormat.Field.INTEGER,
- 0, 3);
- t_FormatWithField(23, format, number, text,
- NumberFormat.Field.CURRENCY, 4, 6);
-
- // test fields that are not included in the formatted text
- t_FormatWithField(25, format, number, text,
- NumberFormat.Field.GROUPING_SEPARATOR, 0, 0);
- t_FormatWithField(26, format, number, text,
- NumberFormat.Field.DECIMAL_SEPARATOR, 0, 0);
- t_FormatWithField(27, format, number, text, NumberFormat.Field.SIGN, 0,
- 0);
- t_FormatWithField(28, format, number, text,
- NumberFormat.Field.EXPONENT, 0, 0);
- t_FormatWithField(29, format, number, text,
- NumberFormat.Field.EXPONENT_SIGN, 0, 0);
- t_FormatWithField(30, format, number, text,
- NumberFormat.Field.EXPONENT_SYMBOL, 0, 0);
- t_FormatWithField(31, format, number, text, NumberFormat.Field.PERCENT,
- 0, 0);
- t_FormatWithField(32, format, number, text,
- NumberFormat.Field.PERMILLE, 0, 0);
-
- }
-
- public void t_formatToCharacterIterator() {
-
- Number number = new Double(350.76);
- Number negativeNumber = new Double(-350.76);
-
- Locale us = Locale.US;
- Locale tr = new Locale("tr", "TR");
-
- // test number instance
- t_Format(1, number, NumberFormat.getNumberInstance(us),
- getNumberVectorUS());
-
- // test integer instance
- // testFormat(2, number, NumberFormat.getIntegerInstance(us),
- // getPercentVectorUS());
-
- // test percent instance
- t_Format(3, number, NumberFormat.getPercentInstance(us),
- getPercentVectorUS());
-
- // test permille pattern
- DecimalFormat format = new DecimalFormat("###0.##\u2030");
- t_Format(4, number, format, getPermilleVector());
-
- // test exponential pattern with positive exponent
- format = new DecimalFormat("00.0#E0");
- t_Format(5, number, format, getPositiveExponentVector());
-
- // test exponential pattern with negative exponent
- format = new DecimalFormat("0000.0#E0");
- t_Format(6, number, format, getNegativeExponentVector());
-
- // test currency instance with US Locale
- t_Format(7, number, NumberFormat.getCurrencyInstance(us),
- getPositiveCurrencyVectorUS());
-
- // test negative currency instance with US Locale
- t_Format(8, negativeNumber, NumberFormat.getCurrencyInstance(us),
- getNegativeCurrencyVectorUS());
-
- // test currency instance with TR Locale
- t_Format(9, number, NumberFormat.getCurrencyInstance(tr),
- getPositiveCurrencyVectorTR());
-
- // test negative currency instance with TR Locale
- t_Format(10, negativeNumber, NumberFormat.getCurrencyInstance(tr),
- getNegativeCurrencyVectorTR());
-
- // test multiple grouping seperators
- number = new Long(100300400);
- t_Format(11, number, NumberFormat.getNumberInstance(us),
- getNumberVector2US());
-
- // test 0
- number = new Long(0);
- t_Format(12, number, NumberFormat.getNumberInstance(us),
- getZeroVector());
- }
-
- private static Vector<FieldContainer> getNumberVectorUS() {
- Vector<FieldContainer> v = new Vector<FieldContainer>();
- v.add(new FieldContainer(0, 3, NumberFormat.Field.INTEGER));
- v.add(new FieldContainer(3, 4, NumberFormat.Field.DECIMAL_SEPARATOR));
- v.add(new FieldContainer(4, 6, NumberFormat.Field.FRACTION));
- return v;
- }
-
- private static Vector<FieldContainer> getPositiveCurrencyVectorTR() {
- Vector<FieldContainer> v = new Vector<FieldContainer>();
- v.add(new FieldContainer(0, 3, NumberFormat.Field.INTEGER));
- v.add(new FieldContainer(4, 6, NumberFormat.Field.CURRENCY));
- return v;
- }
-
- private static Vector<FieldContainer> getNegativeCurrencyVectorTR() {
- Vector<FieldContainer> v = new Vector<FieldContainer>();
- v.add(new FieldContainer(0, 1, NumberFormat.Field.SIGN));
- v.add(new FieldContainer(1, 4, NumberFormat.Field.INTEGER));
- v.add(new FieldContainer(5, 7, NumberFormat.Field.CURRENCY));
- return v;
- }
-
- private static Vector<FieldContainer> getPositiveCurrencyVectorUS() {
- Vector<FieldContainer> v = new Vector<FieldContainer>();
- v.add(new FieldContainer(0, 1, NumberFormat.Field.CURRENCY));
- v.add(new FieldContainer(1, 4, NumberFormat.Field.INTEGER));
- v.add(new FieldContainer(4, 5, NumberFormat.Field.DECIMAL_SEPARATOR));
- v.add(new FieldContainer(5, 7, NumberFormat.Field.FRACTION));
- return v;
- }
-
- private static Vector<FieldContainer> getNegativeCurrencyVectorUS() {
- Vector<FieldContainer> v = new Vector<FieldContainer>();
- v.add(new FieldContainer(1, 2, NumberFormat.Field.CURRENCY));
- v.add(new FieldContainer(2, 5, NumberFormat.Field.INTEGER));
- v.add(new FieldContainer(5, 6, NumberFormat.Field.DECIMAL_SEPARATOR));
- v.add(new FieldContainer(6, 8, NumberFormat.Field.FRACTION));
- return v;
- }
-
- private static Vector<FieldContainer> getPercentVectorUS() {
- Vector<FieldContainer> v = new Vector<FieldContainer>();
- v.add(new FieldContainer(0, 2, NumberFormat.Field.INTEGER));
- v.add(new FieldContainer(2, 3, NumberFormat.Field.INTEGER));
- v.add(new FieldContainer(2, 3, NumberFormat.Field.GROUPING_SEPARATOR));
- v.add(new FieldContainer(3, 6, NumberFormat.Field.INTEGER));
- v.add(new FieldContainer(6, 7, NumberFormat.Field.PERCENT));
- return v;
- }
-
- private static Vector<FieldContainer> getPermilleVector() {
- Vector<FieldContainer> v = new Vector<FieldContainer>();
- v.add(new FieldContainer(0, 6, NumberFormat.Field.INTEGER));
- v.add(new FieldContainer(6, 7, NumberFormat.Field.PERMILLE));
- return v;
- }
-
- private static Vector<FieldContainer> getNegativeExponentVector() {
- Vector<FieldContainer> v = new Vector<FieldContainer>();
- v.add(new FieldContainer(0, 4, NumberFormat.Field.INTEGER));
- v.add(new FieldContainer(4, 5, NumberFormat.Field.DECIMAL_SEPARATOR));
- v.add(new FieldContainer(5, 6, NumberFormat.Field.FRACTION));
- v.add(new FieldContainer(6, 7, NumberFormat.Field.EXPONENT_SYMBOL));
- v.add(new FieldContainer(7, 8, NumberFormat.Field.EXPONENT_SIGN));
- v.add(new FieldContainer(8, 9, NumberFormat.Field.EXPONENT));
- return v;
- }
-
- private static Vector<FieldContainer> getPositiveExponentVector() {
- Vector<FieldContainer> v = new Vector<FieldContainer>();
- v.add(new FieldContainer(0, 2, NumberFormat.Field.INTEGER));
- v.add(new FieldContainer(2, 3, NumberFormat.Field.DECIMAL_SEPARATOR));
- v.add(new FieldContainer(3, 5, NumberFormat.Field.FRACTION));
- v.add(new FieldContainer(5, 6, NumberFormat.Field.EXPONENT_SYMBOL));
- v.add(new FieldContainer(6, 7, NumberFormat.Field.EXPONENT));
- return v;
- }
-
- private static Vector<FieldContainer> getNumberVector2US() {
- Vector<FieldContainer> v = new Vector<FieldContainer>();
- v.add(new FieldContainer(0, 3, NumberFormat.Field.INTEGER));
- v.add(new FieldContainer(3, 4, NumberFormat.Field.GROUPING_SEPARATOR));
- v.add(new FieldContainer(3, 4, NumberFormat.Field.INTEGER));
- v.add(new FieldContainer(4, 7, NumberFormat.Field.INTEGER));
- v.add(new FieldContainer(7, 8, NumberFormat.Field.GROUPING_SEPARATOR));
- v.add(new FieldContainer(7, 8, NumberFormat.Field.INTEGER));
- v.add(new FieldContainer(8, 11, NumberFormat.Field.INTEGER));
- return v;
- }
-
- private static Vector<FieldContainer> getZeroVector() {
- Vector<FieldContainer> v = new Vector<FieldContainer>();
- v.add(new FieldContainer(0, 1, NumberFormat.Field.INTEGER));
- return v;
- }
-
+ public Support_DecimalFormat(String p1) {
+ super(p1);
+ }
+
+ @Override public void runTest() {
+ t_formatToCharacterIterator();
+ t_format_with_FieldPosition();
+ }
+
+ public static void main(String[] args) {
+ new Support_DecimalFormat("").runTest();
+ }
+
+ public void t_format_with_FieldPosition() {
+ DecimalFormat format = (DecimalFormat) NumberFormat.getCurrencyInstance(Locale.US);
+ Number number = new Double(10000000.76);
+ String text = "$10,000,000.76";
+
+ t_FormatWithField(0, format, number, text, NumberFormat.Field.CURRENCY, 0, 1);
+ t_FormatWithField(1, format, number, text, NumberFormat.Field.INTEGER, 1, 11);
+ t_FormatWithField(2, format, number, text, NumberFormat.Field.GROUPING_SEPARATOR, 3, 4);
+ t_FormatWithField(3, format, number, text, NumberFormat.Field.DECIMAL_SEPARATOR, 11, 12);
+ t_FormatWithField(4, format, number, text, NumberFormat.Field.FRACTION, 12, 14);
+
+ // test fields that are not included in the formatted text
+ t_FormatWithField(5, format, number, text, NumberFormat.Field.SIGN, 0, 0);
+ t_FormatWithField(6, format, number, text, NumberFormat.Field.EXPONENT, 0, 0);
+ t_FormatWithField(7, format, number, text, NumberFormat.Field.EXPONENT_SIGN, 0, 0);
+ t_FormatWithField(8, format, number, text, NumberFormat.Field.EXPONENT_SYMBOL, 0, 0);
+ t_FormatWithField(9, format, number, text, NumberFormat.Field.PERCENT, 0, 0);
+ t_FormatWithField(10, format, number, text, NumberFormat.Field.PERMILLE, 0, 0);
+
+ // test Exponential
+ format = new DecimalFormat("000000000.0#E0");
+ text = "100000007.6E-1";
+ t_FormatWithField(11, format, number, text, NumberFormat.Field.INTEGER, 0, 9);
+ t_FormatWithField(12, format, number, text, NumberFormat.Field.DECIMAL_SEPARATOR, 9, 10);
+ t_FormatWithField(13, format, number, text, NumberFormat.Field.FRACTION, 10, 11);
+ t_FormatWithField(14, format, number, text, NumberFormat.Field.EXPONENT_SYMBOL, 11, 12);
+ t_FormatWithField(15, format, number, text, NumberFormat.Field.EXPONENT_SIGN, 12, 13);
+ t_FormatWithField(16, format, number, text, NumberFormat.Field.EXPONENT, 13, 14);
+
+ // test fields that are not included in the formatted text
+ t_FormatWithField(17, format, number, text, NumberFormat.Field.GROUPING_SEPARATOR, 0, 0);
+ t_FormatWithField(18, format, number, text, NumberFormat.Field.SIGN, 0, 0);
+ t_FormatWithField(19, format, number, text, NumberFormat.Field.CURRENCY, 0, 0);
+ t_FormatWithField(20, format, number, text, NumberFormat.Field.PERCENT, 0, 0);
+ t_FormatWithField(21, format, number, text, NumberFormat.Field.PERMILLE, 0, 0);
+
+ // test currency instance with TR Locale
+ number = new Double(350.76);
+ format = (DecimalFormat) NumberFormat.getCurrencyInstance(new Locale("tr", "TR"));
+ text = "350,76" + "\u00a0" + "TL";
+ t_FormatWithField(22, format, number, text, NumberFormat.Field.INTEGER, 0, 3);
+ t_FormatWithField(22, format, number, text, NumberFormat.Field.DECIMAL_SEPARATOR, 3, 4);
+ t_FormatWithField(22, format, number, text, NumberFormat.Field.FRACTION, 4, 6);
+ t_FormatWithField(23, format, number, text, NumberFormat.Field.CURRENCY, 7, 9);
+
+ // test fields that are not included in the formatted text
+ t_FormatWithField(25, format, number, text, NumberFormat.Field.GROUPING_SEPARATOR, 0, 0);
+ t_FormatWithField(27, format, number, text, NumberFormat.Field.SIGN, 0, 0);
+ t_FormatWithField(28, format, number, text, NumberFormat.Field.EXPONENT, 0, 0);
+ t_FormatWithField(29, format, number, text, NumberFormat.Field.EXPONENT_SIGN, 0, 0);
+ t_FormatWithField(30, format, number, text, NumberFormat.Field.EXPONENT_SYMBOL, 0, 0);
+ t_FormatWithField(31, format, number, text, NumberFormat.Field.PERCENT, 0, 0);
+ t_FormatWithField(32, format, number, text, NumberFormat.Field.PERMILLE, 0, 0);
+ }
+
+ public void t_formatToCharacterIterator() {
+ Number number = new Double(350.76);
+ Number negativeNumber = new Double(-350.76);
+
+ Locale us = Locale.US;
+ Locale tr = new Locale("tr", "TR");
+
+ // test number instance
+ t_Format(1, number, NumberFormat.getNumberInstance(us), getNumberVectorUS());
+
+ // test integer instance
+ // testFormat(2, number, NumberFormat.getIntegerInstance(us),
+ // getPercentVectorUS());
+
+ // test percent instance
+ t_Format(3, number, NumberFormat.getPercentInstance(us), getPercentVectorUS());
+
+ // test permille pattern
+ DecimalFormat format = new DecimalFormat("###0.##\u2030");
+ t_Format(4, number, format, getPermilleVector());
+
+ // test exponential pattern with positive exponent
+ format = new DecimalFormat("00.0#E0");
+ t_Format(5, number, format, getPositiveExponentVector());
+
+ // test exponential pattern with negative exponent
+ format = new DecimalFormat("0000.0#E0");
+ t_Format(6, number, format, getNegativeExponentVector());
+
+ // test currency instance with US Locale
+ t_Format(7, number, NumberFormat.getCurrencyInstance(us), getPositiveCurrencyVectorUS());
+
+ // test negative currency instance with US Locale
+ t_Format(8, negativeNumber, NumberFormat.getCurrencyInstance(us), getNegativeCurrencyVectorUS());
+
+ // test currency instance with TR Locale
+ t_Format(9, number, NumberFormat.getCurrencyInstance(tr), getPositiveCurrencyVectorTR());
+
+ // test negative currency instance with TR Locale
+ t_Format(10, negativeNumber, NumberFormat.getCurrencyInstance(tr), getNegativeCurrencyVectorTR());
+
+ // test multiple grouping separators
+ number = new Long(100300400);
+ t_Format(11, number, NumberFormat.getNumberInstance(us), getNumberVector2US());
+
+ // test 0
+ number = new Long(0);
+ t_Format(12, number, NumberFormat.getNumberInstance(us), getZeroVector());
+ }
+
+ private static Vector<FieldContainer> getNumberVectorUS() {
+ Vector<FieldContainer> v = new Vector<FieldContainer>();
+ v.add(new FieldContainer(0, 3, NumberFormat.Field.INTEGER));
+ v.add(new FieldContainer(3, 4, NumberFormat.Field.DECIMAL_SEPARATOR));
+ v.add(new FieldContainer(4, 6, NumberFormat.Field.FRACTION));
+ return v;
+ }
+
+ private static Vector<FieldContainer> getPositiveCurrencyVectorTR() {
+ Vector<FieldContainer> v = new Vector<FieldContainer>();
+ v.add(new FieldContainer(0, 3, NumberFormat.Field.INTEGER));
+ v.add(new FieldContainer(3, 4, NumberFormat.Field.DECIMAL_SEPARATOR));
+ v.add(new FieldContainer(4, 6, NumberFormat.Field.FRACTION));
+ v.add(new FieldContainer(7, 9, NumberFormat.Field.CURRENCY));
+ return v;
+ }
+
+ private static Vector<FieldContainer> getNegativeCurrencyVectorTR() {
+ Vector<FieldContainer> v = new Vector<FieldContainer>();
+ v.add(new FieldContainer(1, 4, NumberFormat.Field.INTEGER));
+ v.add(new FieldContainer(4, 5, NumberFormat.Field.DECIMAL_SEPARATOR));
+ v.add(new FieldContainer(5, 7, NumberFormat.Field.FRACTION));
+ v.add(new FieldContainer(8, 10, NumberFormat.Field.CURRENCY));
+ return v;
+ }
+
+ private static Vector<FieldContainer> getPositiveCurrencyVectorUS() {
+ Vector<FieldContainer> v = new Vector<FieldContainer>();
+ v.add(new FieldContainer(0, 1, NumberFormat.Field.CURRENCY));
+ v.add(new FieldContainer(1, 4, NumberFormat.Field.INTEGER));
+ v.add(new FieldContainer(4, 5, NumberFormat.Field.DECIMAL_SEPARATOR));
+ v.add(new FieldContainer(5, 7, NumberFormat.Field.FRACTION));
+ return v;
+ }
+
+ private static Vector<FieldContainer> getNegativeCurrencyVectorUS() {
+ Vector<FieldContainer> v = new Vector<FieldContainer>();
+ v.add(new FieldContainer(1, 2, NumberFormat.Field.CURRENCY));
+ v.add(new FieldContainer(2, 5, NumberFormat.Field.INTEGER));
+ v.add(new FieldContainer(5, 6, NumberFormat.Field.DECIMAL_SEPARATOR));
+ v.add(new FieldContainer(6, 8, NumberFormat.Field.FRACTION));
+ return v;
+ }
+
+ private static Vector<FieldContainer> getPercentVectorUS() {
+ Vector<FieldContainer> v = new Vector<FieldContainer>();
+ v.add(new FieldContainer(0, 2, NumberFormat.Field.INTEGER));
+ v.add(new FieldContainer(2, 3, NumberFormat.Field.INTEGER));
+ v.add(new FieldContainer(2, 3, NumberFormat.Field.GROUPING_SEPARATOR));
+ v.add(new FieldContainer(3, 6, NumberFormat.Field.INTEGER));
+ v.add(new FieldContainer(6, 7, NumberFormat.Field.PERCENT));
+ return v;
+ }
+
+ private static Vector<FieldContainer> getPermilleVector() {
+ Vector<FieldContainer> v = new Vector<FieldContainer>();
+ v.add(new FieldContainer(0, 6, NumberFormat.Field.INTEGER));
+ v.add(new FieldContainer(6, 7, NumberFormat.Field.PERMILLE));
+ return v;
+ }
+
+ private static Vector<FieldContainer> getNegativeExponentVector() {
+ Vector<FieldContainer> v = new Vector<FieldContainer>();
+ v.add(new FieldContainer(0, 4, NumberFormat.Field.INTEGER));
+ v.add(new FieldContainer(4, 5, NumberFormat.Field.DECIMAL_SEPARATOR));
+ v.add(new FieldContainer(5, 6, NumberFormat.Field.FRACTION));
+ v.add(new FieldContainer(6, 7, NumberFormat.Field.EXPONENT_SYMBOL));
+ v.add(new FieldContainer(7, 8, NumberFormat.Field.EXPONENT_SIGN));
+ v.add(new FieldContainer(8, 9, NumberFormat.Field.EXPONENT));
+ return v;
+ }
+
+ private static Vector<FieldContainer> getPositiveExponentVector() {
+ Vector<FieldContainer> v = new Vector<FieldContainer>();
+ v.add(new FieldContainer(0, 2, NumberFormat.Field.INTEGER));
+ v.add(new FieldContainer(2, 3, NumberFormat.Field.DECIMAL_SEPARATOR));
+ v.add(new FieldContainer(3, 5, NumberFormat.Field.FRACTION));
+ v.add(new FieldContainer(5, 6, NumberFormat.Field.EXPONENT_SYMBOL));
+ v.add(new FieldContainer(6, 7, NumberFormat.Field.EXPONENT));
+ return v;
+ }
+
+ private static Vector<FieldContainer> getNumberVector2US() {
+ Vector<FieldContainer> v = new Vector<FieldContainer>();
+ v.add(new FieldContainer(0, 3, NumberFormat.Field.INTEGER));
+ v.add(new FieldContainer(3, 4, NumberFormat.Field.GROUPING_SEPARATOR));
+ v.add(new FieldContainer(3, 4, NumberFormat.Field.INTEGER));
+ v.add(new FieldContainer(4, 7, NumberFormat.Field.INTEGER));
+ v.add(new FieldContainer(7, 8, NumberFormat.Field.GROUPING_SEPARATOR));
+ v.add(new FieldContainer(7, 8, NumberFormat.Field.INTEGER));
+ v.add(new FieldContainer(8, 11, NumberFormat.Field.INTEGER));
+ return v;
+ }
+
+ private static Vector<FieldContainer> getZeroVector() {
+ Vector<FieldContainer> v = new Vector<FieldContainer>();
+ v.add(new FieldContainer(0, 1, NumberFormat.Field.INTEGER));
+ return v;
+ }
}
diff --git a/harmony-tests/src/test/java/org/apache/harmony/tests/java/text/Support_Format.java b/harmony-tests/src/test/java/org/apache/harmony/tests/java/text/Support_Format.java
index 98c2f10..493e27e 100644
--- a/harmony-tests/src/test/java/org/apache/harmony/tests/java/text/Support_Format.java
+++ b/harmony-tests/src/test/java/org/apache/harmony/tests/java/text/Support_Format.java
@@ -1,13 +1,13 @@
-/*
+/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -21,123 +21,119 @@ import java.text.AttributedCharacterIterator;
import java.text.FieldPosition;
import java.text.Format;
import java.text.AttributedCharacterIterator.Attribute;
+import java.util.Collections;
import java.util.Iterator;
import java.util.Vector;
import junit.framework.TestCase;
public class Support_Format extends TestCase {
- protected String text;
-
- public Support_Format(String p1) {
- super(p1);
- }
-
- protected void t_FormatWithField(int count, Format format, Object object,
- String text, Format.Field field, int begin, int end) {
- StringBuffer buffer = new StringBuffer();
- FieldPosition pos = new FieldPosition(field);
- format.format(object, buffer, pos);
-
- // System.out.println(buffer);
- // System.out.println(pos);
-
- if (text == null) {
- assertEquals("Test " + count + ": incorrect formatted text",
- this.text, buffer.toString());
- } else {
- assertEquals("Test " + count + ": incorrect formatted text", text,
- buffer.toString());
- }
-
- assertEquals("Test " + count + ": incorrect begin index for field "
- + field, begin, pos.getBeginIndex());
- assertEquals("Test " + count + ": incorrect end index for field "
- + field, end, pos.getEndIndex());
- }
-
- protected void t_Format(int count, Object object, Format format,
- Vector<FieldContainer> expectedResults) {
- // System.out.println(format.format(object));
- Vector<FieldContainer> results = findFields(format.formatToCharacterIterator(object));
- assertTrue("Test " + count
- + ": Format returned incorrect CharacterIterator for "
- + format.format(object), compare(results, expectedResults));
- }
-
- /**
- * compares two vectors regardless of the order of their elements
- */
- protected static boolean compare(Vector<FieldContainer> vector1, Vector<FieldContainer> vector2) {
- return vector1.size() == vector2.size() && vector1.containsAll(vector2);
- }
-
- /**
- * finds attributes with regards to char index in this
- * AttributedCharacterIterator, and puts them in a vector
- *
- * @param iterator
- * @return a vector, each entry in this vector are of type FieldContainer ,
- * which stores start and end indexes and an attribute this range
- * has
- */
- protected static Vector<FieldContainer> findFields(AttributedCharacterIterator iterator) {
- Vector<FieldContainer> result = new Vector<FieldContainer>();
- while (iterator.getIndex() != iterator.getEndIndex()) {
- int start = iterator.getRunStart();
- int end = iterator.getRunLimit();
-
- Iterator<Attribute> it = iterator.getAttributes().keySet().iterator();
- while (it.hasNext()) {
- AttributedCharacterIterator.Attribute attribute = it.next();
- Object value = iterator.getAttribute(attribute);
- result.add(new FieldContainer(start, end, attribute, value));
- // System.out.println(start + " " + end + ": " + attribute + ",
- // " + value );
- // System.out.println("v.add(new FieldContainer(" + start +"," +
- // end +"," + attribute+ "," + value+ "));");
- }
- iterator.setIndex(end);
- }
- return result;
- }
-
- protected static class FieldContainer {
- int start, end;
-
- AttributedCharacterIterator.Attribute attribute;
-
- Object value;
-
- // called from support_decimalformat and support_simpledateformat tests
- public FieldContainer(int start, int end,
- AttributedCharacterIterator.Attribute attribute) {
- this(start, end, attribute, attribute);
- }
-
- // called from support_messageformat tests
- public FieldContainer(int start, int end, Attribute attribute, int value) {
- this(start, end, attribute, new Integer(value));
- }
-
- // called from support_messageformat tests
- public FieldContainer(int start, int end, Attribute attribute,
- Object value) {
- this.start = start;
- this.end = end;
- this.attribute = attribute;
- this.value = value;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (!(obj instanceof FieldContainer)) {
- return false;
- }
-
- FieldContainer fc = (FieldContainer) obj;
- return (start == fc.start && end == fc.end
- && attribute == fc.attribute && value.equals(fc.value));
- }
- }
+ protected String text;
+
+ public Support_Format(String p1) {
+ super(p1);
+ }
+
+ protected void t_FormatWithField(int count, Format format, Object object,
+ String text, Format.Field field, int begin, int end) {
+ StringBuffer buffer = new StringBuffer();
+ FieldPosition pos = new FieldPosition(field);
+ format.format(object, buffer, pos);
+
+ // System.out.println(buffer);
+ // System.out.println(pos);
+
+ if (text == null) {
+ assertEquals("Test " + count + ": incorrect formatted text", this.text, buffer.toString());
+ } else {
+ assertEquals(text, buffer.toString());
+ }
+
+ if (begin != pos.getBeginIndex() || end != pos.getEndIndex()) {
+ assertEquals(field + " " + begin + ".." + end,
+ pos.getFieldAttribute() + " " + pos.getBeginIndex() + ".." + pos.getEndIndex());
+ }
+ }
+
+ protected void t_Format(int count, Object object, Format format, Vector<FieldContainer> expectedResults) {
+ Vector<FieldContainer> results = findFields(format.formatToCharacterIterator(object));
+ assertEquals("size mismatch\n" +
+ format.format(object) + "\n" +
+ "expectedResults=" + expectedResults + "\n" +
+ " results=" + results, expectedResults.size(), results.size());
+ for (int i = 0; i < results.size(); ++i) {
+ if (!results.contains(expectedResults.get(i))) {
+ fail("didn't find expected result " + expectedResults.get(i) + "\n" +
+ "expectedResults=" + expectedResults + "\n" +
+ " results=" + results);
+ }
+ }
+ }
+
+ /**
+ * finds attributes with regards to char index in this
+ * AttributedCharacterIterator, and puts them in a vector
+ *
+ * @param iterator
+ * @return a vector, each entry in this vector are of type FieldContainer,
+ * which stores start and end indexes and an attribute this range has
+ */
+ protected static Vector<FieldContainer> findFields(AttributedCharacterIterator iterator) {
+ Vector<FieldContainer> result = new Vector<FieldContainer>();
+ while (iterator.getIndex() != iterator.getEndIndex()) {
+ int start = iterator.getRunStart();
+ int end = iterator.getRunLimit();
+
+ Iterator<Attribute> it = iterator.getAttributes().keySet().iterator();
+ while (it.hasNext()) {
+ AttributedCharacterIterator.Attribute attribute = it.next();
+ Object value = iterator.getAttribute(attribute);
+ result.add(new FieldContainer(start, end, attribute, value));
+ // System.out.println(start + " " + end + ": " + attribute + ",
+ // " + value );
+ // System.out.println("v.add(new FieldContainer(" + start +"," +
+ // end +"," + attribute+ "," + value+ "));");
+ }
+ iterator.setIndex(end);
+ }
+ return result;
+ }
+
+ static class FieldContainer {
+ final int start;
+ final int end;
+ final Attribute attribute;
+ final Object value;
+
+ // called from Support_DecimalFormat and Support_SimpleDateFormat tests
+ public FieldContainer(int start, int end, Attribute attribute) {
+ this(start, end, attribute, attribute);
+ }
+
+ // called from Support_MessageFormat tests
+ public FieldContainer(int start, int end, Attribute attribute, int value) {
+ this(start, end, attribute, new Integer(value));
+ }
+
+ // called from Support_MessageFormat tests
+ public FieldContainer(int start, int end, Attribute attribute, Object value) {
+ this.start = start;
+ this.end = end;
+ this.attribute = attribute;
+ this.value = value;
+ }
+
+ @Override public boolean equals(Object obj) {
+ if (!(obj instanceof FieldContainer)) {
+ return false;
+ }
+
+ FieldContainer fc = (FieldContainer) obj;
+ return (start == fc.start && end == fc.end && attribute == fc.attribute && value.equals(fc.value));
+ }
+
+ @Override public String toString() {
+ return "FC[" + start + ".." + end + ",attribute=" + attribute + ",value=" + value + "]";
+ }
+ }
}
diff --git a/harmony-tests/src/test/java/org/apache/harmony/tests/java/text/Support_MessageFormat.java b/harmony-tests/src/test/java/org/apache/harmony/tests/java/text/Support_MessageFormat.java
index a07e602..8003b88 100644
--- a/harmony-tests/src/test/java/org/apache/harmony/tests/java/text/Support_MessageFormat.java
+++ b/harmony-tests/src/test/java/org/apache/harmony/tests/java/text/Support_MessageFormat.java
@@ -1,13 +1,13 @@
-/*
+/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -45,7 +45,7 @@ public class Support_MessageFormat extends Support_Format {
public void t_format_with_FieldPosition() {
- String pattern = "On {4,date} at {3,time}, he ate {2,number, integer} hamburger{2,choice,1#|1<s} and drank {1, number} litres of coke. That was {0,choice,1#just enough|1<more than enough} food!";
+ String pattern = "On {4,date} at {3,time}, he ate {2,number, integer} hamburger{2,choice,1#|1<s} and drank {1, number} liters of coke. That was {0,choice,1#just enough|1<more than enough} food!";
MessageFormat format = new MessageFormat(pattern, Locale.US);
Date date = new GregorianCalendar(2005, 1, 28, 14, 20, 16).getTime();
@@ -53,7 +53,7 @@ public class Support_MessageFormat extends Support_Format {
Object[] objects = new Object[] { hamburgers, new Double(3.5),
hamburgers, date, date };
- super.text = "On Feb 28, 2005 at 2:20:16 PM, he ate 8 hamburgers and drank 3.5 litres of coke. That was more than enough food!";
+ super.text = "On Feb 28, 2005 at 2:20:16 PM, he ate 8 hamburgers and drank 3.5 liters of coke. That was more than enough food!";
// test with MessageFormat.Field.ARGUMENT
t_FormatWithField(1, format, objects, null, Field.ARGUMENT, 3, 15);
@@ -71,50 +71,48 @@ public class Support_MessageFormat extends Support_Format {
}
public void t_formatToCharacterIterator() {
-
- String pattern = "On {4,date} at {3,time}, he ate {2,number, integer} hamburger{2,choice,1#|1<s} and drank {1, number} litres of coke. That was {0,choice,1#just enough|1<more than enough} food!";
+ String pattern = "On {4,date} at {3,time}, he ate {2,number, integer} hamburger{2,choice,1#|1<s} and drank {1, number} liters of coke. That was {0,choice,1#just enough|1<more than enough} food!";
MessageFormat format = new MessageFormat(pattern, Locale.US);
Date date = new GregorianCalendar(2005, 1, 28, 14, 20, 16).getTime();
Integer hamburgers = new Integer(8);
- Object[] objects = new Object[] { hamburgers, new Double(3.5),
- hamburgers, date, date };
+ Object[] objects = new Object[] { hamburgers, new Double(3.5), hamburgers, date, date };
t_Format(1, objects, format, getMessageVector1());
}
- private Vector<FieldContainer> getMessageVector1() {
- Vector<FieldContainer> v = new Vector<FieldContainer>();
- v.add(new FieldContainer(3, 6, Field.ARGUMENT, 4));
- v.add(new FieldContainer(3, 6, DateFormat.Field.MONTH));
- v.add(new FieldContainer(6, 7, Field.ARGUMENT, 4));
- v.add(new FieldContainer(7, 9, Field.ARGUMENT, 4));
- v.add(new FieldContainer(7, 9, DateFormat.Field.DAY_OF_MONTH));
- v.add(new FieldContainer(9, 11, Field.ARGUMENT, 4));
- v.add(new FieldContainer(11, 15, Field.ARGUMENT, 4));
- v.add(new FieldContainer(11, 15, DateFormat.Field.YEAR));
- v.add(new FieldContainer(19, 20, Field.ARGUMENT, 3));
- v.add(new FieldContainer(19, 20, DateFormat.Field.HOUR1));
- v.add(new FieldContainer(20, 21, Field.ARGUMENT, 3));
- v.add(new FieldContainer(21, 23, Field.ARGUMENT, 3));
- v.add(new FieldContainer(21, 23, DateFormat.Field.MINUTE));
- v.add(new FieldContainer(23, 24, Field.ARGUMENT, 3));
- v.add(new FieldContainer(24, 26, Field.ARGUMENT, 3));
- v.add(new FieldContainer(24, 26, DateFormat.Field.SECOND));
- v.add(new FieldContainer(26, 27, Field.ARGUMENT, 3));
- v.add(new FieldContainer(27, 29, Field.ARGUMENT, 3));
- v.add(new FieldContainer(27, 29, DateFormat.Field.AM_PM));
- v.add(new FieldContainer(38, 39, Field.ARGUMENT, 2));
- v.add(new FieldContainer(38, 39, NumberFormat.Field.INTEGER));
- v.add(new FieldContainer(49, 50, Field.ARGUMENT, 2));
- v.add(new FieldContainer(61, 62, Field.ARGUMENT, 1));
- v.add(new FieldContainer(61, 62, NumberFormat.Field.INTEGER));
- v.add(new FieldContainer(62, 63, Field.ARGUMENT, 1));
- v.add(new FieldContainer(62, 63, NumberFormat.Field.DECIMAL_SEPARATOR));
- v.add(new FieldContainer(63, 64, Field.ARGUMENT, 1));
- v.add(new FieldContainer(63, 64, NumberFormat.Field.FRACTION));
- v.add(new FieldContainer(90, 106, Field.ARGUMENT, 0));
- return v;
- }
+ private Vector<FieldContainer> getMessageVector1() {
+ Vector<FieldContainer> v = new Vector<FieldContainer>();
+ v.add(new FieldContainer(3, 6, DateFormat.Field.MONTH));
+ v.add(new FieldContainer(3, 6, Field.ARGUMENT, 4));
+ v.add(new FieldContainer(6, 7, Field.ARGUMENT, 4));
+ v.add(new FieldContainer(7, 9, DateFormat.Field.DAY_OF_MONTH));
+ v.add(new FieldContainer(7, 9, Field.ARGUMENT, 4));
+ v.add(new FieldContainer(9, 11, Field.ARGUMENT, 4));
+ v.add(new FieldContainer(11, 15, DateFormat.Field.YEAR));
+ v.add(new FieldContainer(11, 15, Field.ARGUMENT, 4));
+ v.add(new FieldContainer(19, 20, DateFormat.Field.HOUR1));
+ v.add(new FieldContainer(19, 20, Field.ARGUMENT, 3));
+ v.add(new FieldContainer(20, 21, Field.ARGUMENT, 3));
+ v.add(new FieldContainer(21, 23, DateFormat.Field.MINUTE));
+ v.add(new FieldContainer(21, 23, Field.ARGUMENT, 3));
+ v.add(new FieldContainer(23, 24, Field.ARGUMENT, 3));
+ v.add(new FieldContainer(24, 26, DateFormat.Field.SECOND));
+ v.add(new FieldContainer(24, 26, Field.ARGUMENT, 3));
+ v.add(new FieldContainer(26, 27, Field.ARGUMENT, 3));
+ v.add(new FieldContainer(27, 29, DateFormat.Field.AM_PM));
+ v.add(new FieldContainer(27, 29, Field.ARGUMENT, 3));
+ v.add(new FieldContainer(38, 39, NumberFormat.Field.INTEGER));
+ v.add(new FieldContainer(38, 39, Field.ARGUMENT, 2));
+ v.add(new FieldContainer(49, 50, Field.ARGUMENT, 2));
+ v.add(new FieldContainer(61, 62, NumberFormat.Field.INTEGER));
+ v.add(new FieldContainer(61, 62, Field.ARGUMENT, 1));
+ v.add(new FieldContainer(62, 63, NumberFormat.Field.DECIMAL_SEPARATOR));
+ v.add(new FieldContainer(62, 63, Field.ARGUMENT, 1));
+ v.add(new FieldContainer(63, 64, NumberFormat.Field.FRACTION));
+ v.add(new FieldContainer(63, 64, Field.ARGUMENT, 1));
+ v.add(new FieldContainer(90, 106, Field.ARGUMENT, 0));
+ return v;
+ }
}
diff --git a/harmony-tests/src/test/java/org/apache/harmony/tests/java/text/Support_SimpleDateFormat.java b/harmony-tests/src/test/java/org/apache/harmony/tests/java/text/Support_SimpleDateFormat.java
index 00306bd..d050e83 100644
--- a/harmony-tests/src/test/java/org/apache/harmony/tests/java/text/Support_SimpleDateFormat.java
+++ b/harmony-tests/src/test/java/org/apache/harmony/tests/java/text/Support_SimpleDateFormat.java
@@ -30,237 +30,229 @@ import java.util.Vector;
import org.apache.harmony.tests.java.text.Support_Format.FieldContainer;
-
public class Support_SimpleDateFormat extends Support_Format {
- public Support_SimpleDateFormat(String p1) {
- super(p1);
- }
-
- @Override
- public void runTest() {
- t_formatToCharacterIterator();
- t_format_with_FieldPosition();
- }
-
- public static void main(String[] args) {
- new Support_SimpleDateFormat("").runTest();
- }
-
- public void t_format_with_FieldPosition() {
- TimeZone tz = TimeZone.getTimeZone("EST");
- Calendar cal = new GregorianCalendar(tz);
- cal.set(1999, Calendar.SEPTEMBER, 13, 17, 19, 01);
- cal.set(Calendar.MILLISECOND, 0);
- Date date = cal.getTime();
- SimpleDateFormat format = (SimpleDateFormat) DateFormat
- .getDateInstance(DateFormat.DEFAULT, Locale.US);
- format.setTimeZone(tz);
-
- // test with all pattern chars, and multiple occurances
- format
- .applyPattern("G GGGG y yy yyyy M MM MMM MMMM d dd ddd k kk kkk H HH HHH h hh hhh m mmm s ss sss S SS SSS EE EEEE D DD DDD F FF w www W WWW a aaa K KKK z zzzz Z ZZZZ");
-
- StringBuffer textbuffer = new StringBuffer(
- "AD Anno Domini 99 99 1999 9 09 Sep September 13 13 013 17 17 017 17 17 017 5 05");
- textbuffer
- .append(" 005 19 019 1 01 001 0 00 000 Mon Monday 256 256 256 2 02 38 038 3 003 PM");
- textbuffer.append(" PM 5 005 GMT-05:00 GMT-05:00 -0500 GMT-05:00");
-
- // to avoid passing the huge Stringbuffer each time.
- super.text = textbuffer.toString();
-
- // test if field positions are set correctly for these fields occuring
- // multiple times.
- t_FormatWithField(0, format, date, null, Field.ERA, 0, 2);
- t_FormatWithField(1, format, date, null, Field.YEAR, 15, 17);
- t_FormatWithField(2, format, date, null, Field.MONTH, 26, 27);
- t_FormatWithField(3, format, date, null, Field.DAY_OF_MONTH, 45, 47);
- t_FormatWithField(4, format, date, null, Field.HOUR_OF_DAY1, 55, 57);
- t_FormatWithField(5, format, date, null, Field.HOUR_OF_DAY0, 65, 67);
- t_FormatWithField(6, format, date, null, Field.HOUR1, 75, 76);
- t_FormatWithField(7, format, date, null, Field.MINUTE, 84, 86);
- t_FormatWithField(8, format, date, null, Field.SECOND, 91, 92);
- t_FormatWithField(9, format, date, null, Field.MILLISECOND, 100, 101);
- t_FormatWithField(10, format, date, null, Field.DAY_OF_WEEK, 109, 112);
- t_FormatWithField(11, format, date, null, Field.DAY_OF_YEAR, 120, 123);
- t_FormatWithField(12, format, date, null, Field.DAY_OF_WEEK_IN_MONTH,
- 132, 133);
- t_FormatWithField(13, format, date, null, Field.WEEK_OF_YEAR, 137, 139);
- t_FormatWithField(14, format, date, null, Field.WEEK_OF_MONTH, 144, 145);
- t_FormatWithField(15, format, date, null, Field.AM_PM, 150, 152);
- t_FormatWithField(16, format, date, null, Field.HOUR0, 158, 159);
- t_FormatWithField(17, format, date, null, Field.TIME_ZONE, 164, 173);
-
- // test fields that are not included in the formatted text
- t_FormatWithField(18, format, date, null,
- NumberFormat.Field.EXPONENT_SIGN, 0, 0);
-
- // test with simple example
- format.applyPattern("h:m z");
-
- super.text = "5:19 GMT-05:00";
- t_FormatWithField(21, format, date, null, Field.HOUR1, 0, 1);
- t_FormatWithField(22, format, date, null, Field.MINUTE, 2, 4);
- t_FormatWithField(23, format, date, null, Field.TIME_ZONE, 5, 14);
-
- // test fields that are not included in the formatted text
-
- t_FormatWithField(24, format, date, null, Field.ERA, 0, 0);
- t_FormatWithField(25, format, date, null, Field.YEAR, 0, 0);
- t_FormatWithField(26, format, date, null, Field.MONTH, 0, 0);
- t_FormatWithField(27, format, date, null, Field.DAY_OF_MONTH, 0, 0);
- t_FormatWithField(28, format, date, null, Field.HOUR_OF_DAY1, 0, 0);
- t_FormatWithField(29, format, date, null, Field.HOUR_OF_DAY0, 0, 0);
- t_FormatWithField(30, format, date, null, Field.SECOND, 0, 0);
- t_FormatWithField(31, format, date, null, Field.MILLISECOND, 0, 0);
- t_FormatWithField(32, format, date, null, Field.DAY_OF_WEEK, 0, 0);
- t_FormatWithField(33, format, date, null, Field.DAY_OF_YEAR, 0, 0);
- t_FormatWithField(34, format, date, null, Field.DAY_OF_WEEK_IN_MONTH,
- 0, 0);
- t_FormatWithField(35, format, date, null, Field.WEEK_OF_YEAR, 0, 0);
- t_FormatWithField(36, format, date, null, Field.WEEK_OF_MONTH, 0, 0);
- t_FormatWithField(37, format, date, null, Field.AM_PM, 0, 0);
- t_FormatWithField(38, format, date, null, Field.HOUR0, 0, 0);
-
- t_FormatWithField(39, format, date, null, NumberFormat.Field.EXPONENT,
- 0, 0);
-
- // test with simple example with pattern char Z
- format.applyPattern("h:m Z z");
- super.text = "5:19 -0500 GMT-05:00";
- t_FormatWithField(40, format, date, null, Field.HOUR1, 0, 1);
- t_FormatWithField(41, format, date, null, Field.MINUTE, 2, 4);
- t_FormatWithField(42, format, date, null, Field.TIME_ZONE, 5, 10);
- }
-
- public void t_formatToCharacterIterator() {
- TimeZone tz = TimeZone.getTimeZone("EST");
- Calendar cal = new GregorianCalendar(tz);
- cal.set(1999, Calendar.SEPTEMBER, 13, 17, 19, 01);
- cal.set(Calendar.MILLISECOND, 0);
- Date date = cal.getTime();
- SimpleDateFormat format = (SimpleDateFormat) DateFormat
- .getDateInstance(DateFormat.DEFAULT, Locale.US);
- format.setTimeZone(tz);
-
- format.applyPattern("yyyyMMddHHmmss");
- t_Format(1, date, format, getDateVector1());
-
- format.applyPattern("w W dd MMMM yyyy EEEE");
- t_Format(2, date, format, getDateVector2());
-
- format.applyPattern("h:m z");
- t_Format(3, date, format, getDateVector3());
-
- format.applyPattern("h:m Z");
- t_Format(5, date, format, getDateVector5());
-
- // with all pattern chars, and multiple occurances
- format
- .applyPattern("G GGGG y yy yyyy M MM MMM MMMM d dd ddd k kk kkk H HH HHH h hh hhh m mmm s ss sss S SS SSS EE EEEE D DD DDD F FF w www W WWW a aaa K KKK z zzzz Z ZZZZ");
- t_Format(4, date, format, getDateVector4());
- }
-
- private Vector<FieldContainer> getDateVector1() {
- // "19990913171901"
- Vector<FieldContainer> v = new Vector<FieldContainer>();
- v.add(new FieldContainer(0, 4, Field.YEAR));
- v.add(new FieldContainer(4, 6, Field.MONTH));
- v.add(new FieldContainer(6, 8, Field.DAY_OF_MONTH));
- v.add(new FieldContainer(8, 10, Field.HOUR_OF_DAY0));
- v.add(new FieldContainer(10, 12, Field.MINUTE));
- v.add(new FieldContainer(12, 14, Field.SECOND));
- return v;
- }
-
- private Vector<FieldContainer> getDateVector2() {
- // "12 3 5 March 2002 Monday"
- Vector<FieldContainer> v = new Vector<FieldContainer>();
- v.add(new FieldContainer(0, 2, Field.WEEK_OF_YEAR));
- v.add(new FieldContainer(3, 4, Field.WEEK_OF_MONTH));
- v.add(new FieldContainer(5, 7, Field.DAY_OF_MONTH));
- v.add(new FieldContainer(8, 17, Field.MONTH));
- v.add(new FieldContainer(18, 22, Field.YEAR));
- v.add(new FieldContainer(23, 29, Field.DAY_OF_WEEK));
- return v;
- }
-
- private Vector<FieldContainer> getDateVector3() {
- // "5:19 EDT"
- Vector<FieldContainer> v = new Vector<FieldContainer>();
- v.add(new FieldContainer(0, 1, Field.HOUR1));
- v.add(new FieldContainer(2, 4, Field.MINUTE));
- v.add(new FieldContainer(5, 14, Field.TIME_ZONE));
- return v;
- }
-
- private Vector<FieldContainer> getDateVector5() {
- // "5:19 -0400"
- Vector<FieldContainer> v = new Vector<FieldContainer>();
- v.add(new FieldContainer(0, 1, Field.HOUR1));
- v.add(new FieldContainer(2, 4, Field.MINUTE));
- v.add(new FieldContainer(5, 10, Field.TIME_ZONE));
- return v;
- }
-
- private Vector<FieldContainer> getDateVector4() {
- Vector<FieldContainer> v = new Vector<FieldContainer>();
-
- // "AD AD 99 99 1999 9 09 Sep September 13 13 013 17 17 017 17 17 017 5
- // 05
- // 005 19 019 1 01 001 0 00 000 Mon Monday 256 256 256 2 02 38 038 3 003
- // PM
- // PM 5 005 EDT Eastern Daylight Time -0400 -0400"
- v.add(new FieldContainer(0, 2, Field.ERA));
- v.add(new FieldContainer(3, 5, Field.ERA));
- v.add(new FieldContainer(6, 8, Field.YEAR));
- v.add(new FieldContainer(9, 11, Field.YEAR));
- v.add(new FieldContainer(12, 16, Field.YEAR));
- v.add(new FieldContainer(17, 18, Field.MONTH));
- v.add(new FieldContainer(19, 21, Field.MONTH));
- v.add(new FieldContainer(22, 25, Field.MONTH));
- v.add(new FieldContainer(26, 35, Field.MONTH));
- v.add(new FieldContainer(36, 38, Field.DAY_OF_MONTH));
- v.add(new FieldContainer(39, 41, Field.DAY_OF_MONTH));
- v.add(new FieldContainer(42, 45, Field.DAY_OF_MONTH));
- v.add(new FieldContainer(46, 48, Field.HOUR_OF_DAY1));
- v.add(new FieldContainer(49, 51, Field.HOUR_OF_DAY1));
- v.add(new FieldContainer(52, 55, Field.HOUR_OF_DAY1));
- v.add(new FieldContainer(56, 58, Field.HOUR_OF_DAY0));
- v.add(new FieldContainer(59, 61, Field.HOUR_OF_DAY0));
- v.add(new FieldContainer(62, 65, Field.HOUR_OF_DAY0));
- v.add(new FieldContainer(66, 67, Field.HOUR1));
- v.add(new FieldContainer(68, 70, Field.HOUR1));
- v.add(new FieldContainer(71, 74, Field.HOUR1));
- v.add(new FieldContainer(75, 77, Field.MINUTE));
- v.add(new FieldContainer(78, 81, Field.MINUTE));
- v.add(new FieldContainer(82, 83, Field.SECOND));
- v.add(new FieldContainer(84, 86, Field.SECOND));
- v.add(new FieldContainer(87, 90, Field.SECOND));
- v.add(new FieldContainer(91, 92, Field.MILLISECOND));
- v.add(new FieldContainer(93, 95, Field.MILLISECOND));
- v.add(new FieldContainer(96, 99, Field.MILLISECOND));
- v.add(new FieldContainer(100, 103, Field.DAY_OF_WEEK));
- v.add(new FieldContainer(104, 110, Field.DAY_OF_WEEK));
- v.add(new FieldContainer(111, 114, Field.DAY_OF_YEAR));
- v.add(new FieldContainer(115, 118, Field.DAY_OF_YEAR));
- v.add(new FieldContainer(119, 122, Field.DAY_OF_YEAR));
- v.add(new FieldContainer(123, 124, Field.DAY_OF_WEEK_IN_MONTH));
- v.add(new FieldContainer(125, 127, Field.DAY_OF_WEEK_IN_MONTH));
- v.add(new FieldContainer(128, 130, Field.WEEK_OF_YEAR));
- v.add(new FieldContainer(131, 134, Field.WEEK_OF_YEAR));
- v.add(new FieldContainer(135, 136, Field.WEEK_OF_MONTH));
- v.add(new FieldContainer(137, 140, Field.WEEK_OF_MONTH));
- v.add(new FieldContainer(141, 143, Field.AM_PM));
- v.add(new FieldContainer(145, 147, Field.AM_PM));
- v.add(new FieldContainer(149, 150, Field.HOUR0));
- v.add(new FieldContainer(151, 154, Field.HOUR0));
- v.add(new FieldContainer(155, 164, Field.TIME_ZONE));
- v.add(new FieldContainer(165, 174, Field.TIME_ZONE));
- v.add(new FieldContainer(175, 180, Field.TIME_ZONE));
- v.add(new FieldContainer(181, 186, Field.TIME_ZONE));
- return v;
- }
-
+ public Support_SimpleDateFormat(String p1) {
+ super(p1);
+ }
+
+ @Override public void runTest() {
+ t_formatToCharacterIterator();
+ t_format_with_FieldPosition();
+ }
+
+ public static void main(String[] args) {
+ new Support_SimpleDateFormat("").runTest();
+ }
+
+ public void t_format_with_FieldPosition() {
+ TimeZone tz = TimeZone.getTimeZone("EST");
+ Calendar cal = new GregorianCalendar(tz);
+ cal.set(1999, Calendar.SEPTEMBER, 13, 17, 19, 01);
+ cal.set(Calendar.MILLISECOND, 0);
+ Date date = cal.getTime();
+ SimpleDateFormat format = (SimpleDateFormat) DateFormat.getDateInstance(DateFormat.DEFAULT, Locale.US);
+ format.setTimeZone(tz);
+
+ // test with all pattern chars, and multiple occurences
+ format.applyPattern("G GGGG y yy yyyy M MM MMM MMMM d dd ddd " +
+ "k kk kkk H HH HHH h hh hhh m mmm s ss sss S SS SSS EE EEEE " +
+ "D DD DDD F FF w www W WWW " +
+ "a aaa K KKK z zzzz Z ZZZZ");
+
+ StringBuffer textBuffer = new StringBuffer();
+ // Really, GGGG should be "Anno Domini", but the RI doesn't support that and no one cares.
+ textBuffer.append("AD AD 1999 99 1999 9 09 Sep September 13 13 013 ");
+ textBuffer.append("17 17 017 17 17 017 5 05 005 19 019 1 01 001 0 00 000 Mon Monday ");
+ textBuffer.append("256 256 256 2 02 38 038 3 003 ");
+ textBuffer.append("PM PM 5 005 GMT-05:00 GMT-05:00 -0500 GMT-05:00");
+
+ // to avoid passing the huge StringBuffer each time.
+ super.text = textBuffer.toString();
+
+ // test if field positions are set correctly for these fields occurring
+ // multiple times.
+ t_FormatWithField(0, format, date, null, Field.ERA, 0, 2);
+ t_FormatWithField(1, format, date, null, Field.YEAR, 6, 10);
+ t_FormatWithField(2, format, date, null, Field.MONTH, 19, 20);
+ t_FormatWithField(3, format, date, null, Field.DAY_OF_MONTH, 38, 40);
+ t_FormatWithField(4, format, date, null, Field.HOUR_OF_DAY1, 48, 50);
+ t_FormatWithField(5, format, date, null, Field.HOUR_OF_DAY0, 58, 60);
+ t_FormatWithField(6, format, date, null, Field.HOUR1, 68, 69);
+ t_FormatWithField(7, format, date, null, Field.MINUTE, 77, 79);
+ t_FormatWithField(8, format, date, null, Field.SECOND, 84, 85);
+ t_FormatWithField(9, format, date, null, Field.MILLISECOND, 93, 94);
+ t_FormatWithField(10, format, date, null, Field.DAY_OF_WEEK, 102, 105);
+ t_FormatWithField(11, format, date, null, Field.DAY_OF_YEAR, 113, 116);
+ t_FormatWithField(12, format, date, null, Field.DAY_OF_WEEK_IN_MONTH, 125, 126);
+ t_FormatWithField(13, format, date, null, Field.WEEK_OF_YEAR, 130, 132);
+ t_FormatWithField(14, format, date, null, Field.WEEK_OF_MONTH, 137, 138);
+ t_FormatWithField(15, format, date, null, Field.AM_PM, 143, 145);
+ t_FormatWithField(16, format, date, null, Field.HOUR0, 151, 152);
+ t_FormatWithField(17, format, date, null, Field.TIME_ZONE, 157, 166);
+
+ // test fields that are not included in the formatted text
+ t_FormatWithField(18, format, date, null, NumberFormat.Field.EXPONENT_SIGN, 0, 0);
+
+ // test with simple example
+ format.applyPattern("h:m z");
+
+ super.text = "5:19 GMT-05:00";
+ t_FormatWithField(21, format, date, null, Field.HOUR1, 0, 1);
+ t_FormatWithField(22, format, date, null, Field.MINUTE, 2, 4);
+ t_FormatWithField(23, format, date, null, Field.TIME_ZONE, 5, 14);
+
+ // test fields that are not included in the formatted text
+ t_FormatWithField(24, format, date, null, Field.ERA, 0, 0);
+ t_FormatWithField(25, format, date, null, Field.YEAR, 0, 0);
+ t_FormatWithField(26, format, date, null, Field.MONTH, 0, 0);
+ t_FormatWithField(27, format, date, null, Field.DAY_OF_MONTH, 0, 0);
+ t_FormatWithField(28, format, date, null, Field.HOUR_OF_DAY1, 0, 0);
+ t_FormatWithField(29, format, date, null, Field.HOUR_OF_DAY0, 0, 0);
+ t_FormatWithField(30, format, date, null, Field.SECOND, 0, 0);
+ t_FormatWithField(31, format, date, null, Field.MILLISECOND, 0, 0);
+ t_FormatWithField(32, format, date, null, Field.DAY_OF_WEEK, 0, 0);
+ t_FormatWithField(33, format, date, null, Field.DAY_OF_YEAR, 0, 0);
+ t_FormatWithField(34, format, date, null, Field.DAY_OF_WEEK_IN_MONTH, 0, 0);
+ t_FormatWithField(35, format, date, null, Field.WEEK_OF_YEAR, 0, 0);
+ t_FormatWithField(36, format, date, null, Field.WEEK_OF_MONTH, 0, 0);
+ t_FormatWithField(37, format, date, null, Field.AM_PM, 0, 0);
+ t_FormatWithField(38, format, date, null, Field.HOUR0, 0, 0);
+
+ t_FormatWithField(39, format, date, null, NumberFormat.Field.EXPONENT, 0, 0);
+
+ // test with simple example with pattern char Z
+ format.applyPattern("h:m Z z");
+ super.text = "5:19 -0500 GMT-05:00";
+ t_FormatWithField(40, format, date, null, Field.HOUR1, 0, 1);
+ t_FormatWithField(41, format, date, null, Field.MINUTE, 2, 4);
+ t_FormatWithField(42, format, date, null, Field.TIME_ZONE, 5, 10);
+ }
+
+ public void t_formatToCharacterIterator() {
+ TimeZone tz = TimeZone.getTimeZone("EST");
+ Calendar cal = new GregorianCalendar(tz);
+ cal.set(1999, Calendar.SEPTEMBER, 13, 17, 19, 01);
+ cal.set(Calendar.MILLISECOND, 0);
+ Date date = cal.getTime();
+ SimpleDateFormat format = (SimpleDateFormat) DateFormat.getDateInstance(DateFormat.DEFAULT, Locale.US);
+ format.setTimeZone(tz);
+
+ format.applyPattern("yyyyMMddHHmmss");
+ t_Format(1, date, format, getDateVector1());
+
+ format.applyPattern("w W dd MMMM yyyy EEEE");
+ t_Format(2, date, format, getDateVector2());
+
+ format.applyPattern("h:m z");
+ t_Format(3, date, format, getDateVector3());
+
+ format.applyPattern("h:m Z");
+ t_Format(5, date, format, getDateVector5());
+
+ // with all pattern chars, and multiple occurences
+ format.applyPattern("G GGGG y yy yyyy M MM MMM MMMM d dd ddd k kk kkk H HH HHH h hh hhh m mmm s ss sss S SS SSS EE EEEE D DD DDD F FF w www W WWW a aaa K KKK z zzzz Z ZZZZ");
+ t_Format(4, date, format, getDateVector4());
+ }
+
+ private Vector<FieldContainer> getDateVector1() {
+ // "19990913171901"
+ Vector<FieldContainer> v = new Vector<FieldContainer>();
+ v.add(new FieldContainer(0, 4, Field.YEAR));
+ v.add(new FieldContainer(4, 6, Field.MONTH));
+ v.add(new FieldContainer(6, 8, Field.DAY_OF_MONTH));
+ v.add(new FieldContainer(8, 10, Field.HOUR_OF_DAY0));
+ v.add(new FieldContainer(10, 12, Field.MINUTE));
+ v.add(new FieldContainer(12, 14, Field.SECOND));
+ return v;
+ }
+
+ private Vector<FieldContainer> getDateVector2() {
+ // "12 3 5 March 2002 Monday"
+ Vector<FieldContainer> v = new Vector<FieldContainer>();
+ v.add(new FieldContainer(0, 2, Field.WEEK_OF_YEAR));
+ v.add(new FieldContainer(3, 4, Field.WEEK_OF_MONTH));
+ v.add(new FieldContainer(5, 7, Field.DAY_OF_MONTH));
+ v.add(new FieldContainer(8, 17, Field.MONTH));
+ v.add(new FieldContainer(18, 22, Field.YEAR));
+ v.add(new FieldContainer(23, 29, Field.DAY_OF_WEEK));
+ return v;
+ }
+
+ private Vector<FieldContainer> getDateVector3() {
+ // "5:19 EDT"
+ Vector<FieldContainer> v = new Vector<FieldContainer>();
+ v.add(new FieldContainer(0, 1, Field.HOUR1));
+ v.add(new FieldContainer(2, 4, Field.MINUTE));
+ v.add(new FieldContainer(5, 14, Field.TIME_ZONE));
+ return v;
+ }
+
+ private Vector<FieldContainer> getDateVector5() {
+ // "5:19 -0400"
+ Vector<FieldContainer> v = new Vector<FieldContainer>();
+ v.add(new FieldContainer(0, 1, Field.HOUR1));
+ v.add(new FieldContainer(2, 4, Field.MINUTE));
+ v.add(new FieldContainer(5, 10, Field.TIME_ZONE));
+ return v;
+ }
+
+ private Vector<FieldContainer> getDateVector4() {
+ Vector<FieldContainer> v = new Vector<FieldContainer>();
+
+ // "AD AD 1999 99 1999 9 09 Sep September 13 13 013 17 17 017 17 17 017 5
+ // 05
+ // 005 19 019 1 01 001 0 00 000 Mon Monday 256 256 256 2 02 38 038 3 003
+ // PM
+ // PM 5 005 EDT Eastern Daylight Time -0400 -0400"
+ v.add(new FieldContainer(0, 2, Field.ERA));
+ v.add(new FieldContainer(3, 5, Field.ERA));
+ v.add(new FieldContainer(6, 10, Field.YEAR));
+ v.add(new FieldContainer(11, 13, Field.YEAR));
+ v.add(new FieldContainer(14, 18, Field.YEAR));
+ v.add(new FieldContainer(19, 20, Field.MONTH));
+ v.add(new FieldContainer(21, 23, Field.MONTH));
+ v.add(new FieldContainer(24, 27, Field.MONTH));
+ v.add(new FieldContainer(28, 37, Field.MONTH));
+ v.add(new FieldContainer(38, 40, Field.DAY_OF_MONTH));
+ v.add(new FieldContainer(41, 43, Field.DAY_OF_MONTH));
+ v.add(new FieldContainer(44, 47, Field.DAY_OF_MONTH));
+ v.add(new FieldContainer(48, 50, Field.HOUR_OF_DAY1));
+ v.add(new FieldContainer(51, 53, Field.HOUR_OF_DAY1));
+ v.add(new FieldContainer(54, 57, Field.HOUR_OF_DAY1));
+ v.add(new FieldContainer(58, 60, Field.HOUR_OF_DAY0));
+ v.add(new FieldContainer(61, 63, Field.HOUR_OF_DAY0));
+ v.add(new FieldContainer(64, 67, Field.HOUR_OF_DAY0));
+ v.add(new FieldContainer(68, 69, Field.HOUR1));
+ v.add(new FieldContainer(70, 72, Field.HOUR1));
+ v.add(new FieldContainer(73, 76, Field.HOUR1));
+ v.add(new FieldContainer(77, 79, Field.MINUTE));
+ v.add(new FieldContainer(80, 83, Field.MINUTE));
+ v.add(new FieldContainer(84, 85, Field.SECOND));
+ v.add(new FieldContainer(86, 88, Field.SECOND));
+ v.add(new FieldContainer(89, 92, Field.SECOND));
+ v.add(new FieldContainer(93, 94, Field.MILLISECOND));
+ v.add(new FieldContainer(95, 97, Field.MILLISECOND));
+ v.add(new FieldContainer(98, 101, Field.MILLISECOND));
+ v.add(new FieldContainer(102, 105, Field.DAY_OF_WEEK));
+ v.add(new FieldContainer(106, 112, Field.DAY_OF_WEEK));
+ v.add(new FieldContainer(113, 116, Field.DAY_OF_YEAR));
+ v.add(new FieldContainer(117, 120, Field.DAY_OF_YEAR));
+ v.add(new FieldContainer(121, 124, Field.DAY_OF_YEAR));
+ v.add(new FieldContainer(125, 126, Field.DAY_OF_WEEK_IN_MONTH));
+ v.add(new FieldContainer(127, 129, Field.DAY_OF_WEEK_IN_MONTH));
+ v.add(new FieldContainer(130, 132, Field.WEEK_OF_YEAR));
+ v.add(new FieldContainer(133, 136, Field.WEEK_OF_YEAR));
+ v.add(new FieldContainer(137, 138, Field.WEEK_OF_MONTH));
+ v.add(new FieldContainer(139, 142, Field.WEEK_OF_MONTH));
+ v.add(new FieldContainer(143, 145, Field.AM_PM));
+ v.add(new FieldContainer(147, 149, Field.AM_PM));
+ v.add(new FieldContainer(151, 152, Field.HOUR0));
+ v.add(new FieldContainer(153, 156, Field.HOUR0));
+ v.add(new FieldContainer(157, 166, Field.TIME_ZONE));
+ v.add(new FieldContainer(167, 176, Field.TIME_ZONE));
+ v.add(new FieldContainer(177, 182, Field.TIME_ZONE));
+ v.add(new FieldContainer(183, 192, Field.TIME_ZONE));
+ return v;
+ }
}
diff --git a/luni/src/main/java/java/text/Bidi.java b/luni/src/main/java/java/text/Bidi.java
index e4b30e6..d73ea4a 100644
--- a/luni/src/main/java/java/text/Bidi.java
+++ b/luni/src/main/java/java/text/Bidi.java
@@ -421,28 +421,20 @@ public final class Bidi {
/**
* Returns the base level.
- *
- * @return the base level.
*/
public int getBaseLevel() {
return baseLevel;
}
/**
- * Returns the length of the text in the {@code Bidi} object.
- *
- * @return the length.
+ * Returns the length of the text.
*/
public int getLength() {
return length;
}
/**
- * Returns the level of a specified character.
- *
- * @param offset
- * the offset of the character.
- * @return the level.
+ * Returns the level of the given character.
*/
public int getLevelAt(int offset) {
try {
@@ -453,74 +445,51 @@ public final class Bidi {
}
/**
- * Returns the number of runs in the bidirectional text.
- *
- * @return the number of runs, at least 1.
+ * Returns the number of runs in the text, at least 1.
*/
public int getRunCount() {
return unidirectional ? 1 : runs.length;
}
/**
- * Returns the level of the specified run.
- *
- * @param run
- * the index of the run.
- * @return the level of the run.
+ * Returns the level of the given run.
*/
public int getRunLevel(int run) {
return unidirectional ? baseLevel : runs[run].getLevel();
}
/**
- * Returns the limit offset of the specified run.
- *
- * @param run
- * the index of the run.
- * @return the limit offset of the run.
+ * Returns the limit offset of the given run.
*/
public int getRunLimit(int run) {
return unidirectional ? length : runs[run].getLimit();
}
/**
- * Returns the start offset of the specified run.
- *
- * @param run
- * the index of the run.
- * @return the start offset of the run.
+ * Returns the start offset of the given run.
*/
public int getRunStart(int run) {
return unidirectional ? 0 : runs[run].getStart();
}
/**
- * Indicates whether the text is from left to right, that is, both the base
+ * Returns true if the text is from left to right, that is, both the base
* direction and the text direction is from left to right.
- *
- * @return {@code true} if the text is from left to right; {@code false}
- * otherwise.
*/
public boolean isLeftToRight() {
return direction == UBiDiDirection_UBIDI_LTR;
}
/**
- * Indicates whether the text direction is mixed.
- *
- * @return {@code true} if the text direction is mixed; {@code false}
- * otherwise.
+ * Returns true if the text direction is mixed.
*/
public boolean isMixed() {
return direction == UBiDiDirection_UBIDI_MIXED;
}
/**
- * Indicates whether the text is from right to left, that is, both the base
+ * Returns true if the text is from right to left, that is, both the base
* direction and the text direction is from right to left.
- *
- * @return {@code true} if the text is from right to left; {@code false}
- * otherwise.
*/
public boolean isRightToLeft() {
return direction == UBiDiDirection_UBIDI_RTL;
diff --git a/luni/src/main/java/java/text/DateFormatSymbols.java b/luni/src/main/java/java/text/DateFormatSymbols.java
index e75b82c..0d33d75 100644
--- a/luni/src/main/java/java/text/DateFormatSymbols.java
+++ b/luni/src/main/java/java/text/DateFormatSymbols.java
@@ -251,8 +251,6 @@ public class DateFormatSymbols implements Serializable, Cloneable {
/**
* Returns the pattern characters used by {@link SimpleDateFormat} to
* specify date and time fields.
- *
- * @return a string containing the pattern characters.
*/
public String getLocalPatternChars() {
return localPatternChars;
diff --git a/luni/src/main/java/java/text/DecimalFormat.java b/luni/src/main/java/java/text/DecimalFormat.java
index 948bec1..f9f282a 100644
--- a/luni/src/main/java/java/text/DecimalFormat.java
+++ b/luni/src/main/java/java/text/DecimalFormat.java
@@ -574,6 +574,7 @@ public class DecimalFormat extends NumberFormat {
*/
public void applyLocalizedPattern(String pattern) {
ndf.applyLocalizedPattern(pattern);
+ updateFieldsFromNative();
}
/**
@@ -587,6 +588,14 @@ public class DecimalFormat extends NumberFormat {
*/
public void applyPattern(String pattern) {
ndf.applyPattern(pattern);
+ updateFieldsFromNative();
+ }
+
+ private void updateFieldsFromNative() {
+ maximumIntegerDigits = ndf.getMaximumIntegerDigits();
+ minimumIntegerDigits = ndf.getMinimumIntegerDigits();
+ maximumFractionDigits = ndf.getMaximumFractionDigits();
+ minimumFractionDigits = ndf.getMinimumFractionDigits();
}
/**
@@ -644,6 +653,9 @@ public class DecimalFormat extends NumberFormat {
if (object == null) {
throw new NullPointerException("object == null");
}
+ if (roundingMode == RoundingMode.UNNECESSARY && (object instanceof Float || object instanceof Double)) {
+ checkRoundingUnnecessary(((Number) object).doubleValue());
+ }
return ndf.formatToCharacterIterator(object);
}
@@ -656,23 +668,30 @@ public class DecimalFormat extends NumberFormat {
}
}
+ private void checkRoundingUnnecessary(Object value) {
+ // ICU4C doesn't support this rounding mode, so we have to fake it.
+ // This implementation reduces code duplication, but adds boxing
+ // overhead and sends you all the way back through. But since we
+ // have to format your string multiple times in this mode, you're already
+ // screwed performance-wise.
+ try {
+ setRoundingMode(RoundingMode.UP);
+ String upResult = format(value, new StringBuffer(), new FieldPosition(0)).toString();
+ setRoundingMode(RoundingMode.DOWN);
+ String downResult = format(value, new StringBuffer(), new FieldPosition(0)).toString();
+ if (!upResult.equals(downResult)) {
+ throw new ArithmeticException("rounding mode UNNECESSARY but rounding required");
+ }
+ } finally {
+ setRoundingMode(RoundingMode.UNNECESSARY);
+ }
+ }
+
@Override
public StringBuffer format(double value, StringBuffer buffer, FieldPosition position) {
checkBufferAndFieldPosition(buffer, position);
- // All float/double/Float/Double formatting ends up here...
if (roundingMode == RoundingMode.UNNECESSARY) {
- // ICU4C doesn't support this rounding mode, so we have to fake it.
- try {
- setRoundingMode(RoundingMode.UP);
- String upResult = format(value, new StringBuffer(), new FieldPosition(0)).toString();
- setRoundingMode(RoundingMode.DOWN);
- String downResult = format(value, new StringBuffer(), new FieldPosition(0)).toString();
- if (!upResult.equals(downResult)) {
- throw new ArithmeticException("rounding mode UNNECESSARY but rounding required");
- }
- } finally {
- setRoundingMode(RoundingMode.UNNECESSARY);
- }
+ checkRoundingUnnecessary(value);
}
buffer.append(ndf.formatDouble(value, position));
return buffer;
@@ -681,6 +700,9 @@ public class DecimalFormat extends NumberFormat {
@Override
public StringBuffer format(long value, StringBuffer buffer, FieldPosition position) {
checkBufferAndFieldPosition(buffer, position);
+ if (roundingMode == RoundingMode.UNNECESSARY) {
+ checkRoundingUnnecessary(value);
+ }
buffer.append(ndf.formatLong(value, position));
return buffer;
}
@@ -735,16 +757,6 @@ public class DecimalFormat extends NumberFormat {
}
/**
- * Returns the multiplier which is applied to the number before formatting
- * or after parsing.
- *
- * @return the multiplier.
- */
- public int getMultiplier() {
- return ndf.getMultiplier();
- }
-
- /**
* Returns the prefix which is formatted or parsed before a negative number.
*
* @return the negative prefix.
@@ -826,16 +838,10 @@ public class DecimalFormat extends NumberFormat {
// In this implementation, NativeDecimalFormat is wrapped to
// fulfill most of the format and parse feature. And this method is
// delegated to the wrapped instance of NativeDecimalFormat.
+ super.setParseIntegerOnly(value);
ndf.setParseIntegerOnly(value);
}
- /**
- * Indicates whether parsing with this decimal format will only
- * return numbers of type {@code java.lang.Integer}.
- *
- * @return {@code true} if this {@code DecimalFormat}'s parse method only
- * returns {@code java.lang.Integer}; {@code false} otherwise.
- */
@Override
public boolean isParseIntegerOnly() {
return ndf.isParseIntegerOnly();
@@ -898,9 +904,6 @@ public class DecimalFormat extends NumberFormat {
/**
* Sets the {@code DecimalFormatSymbols} used by this decimal format.
- *
- * @param value
- * the {@code DecimalFormatSymbols} to set.
*/
public void setDecimalFormatSymbols(DecimalFormatSymbols value) {
if (value != null) {
@@ -913,10 +916,6 @@ public class DecimalFormat extends NumberFormat {
/**
* Sets the currency used by this decimal format. The min and max fraction
* digits remain the same.
- *
- * @param currency
- * the currency this {@code DecimalFormat} should use.
- * @see DecimalFormatSymbols#setCurrency(Currency)
*/
@Override
public void setCurrency(Currency currency) {
@@ -925,12 +924,8 @@ public class DecimalFormat extends NumberFormat {
}
/**
- * Sets whether the decimal separator is shown when there are no fractional
+ * Sets whether the decimal separator is shown even when there are no fractional
* digits.
- *
- * @param value
- * {@code true} if the decimal separator should always be
- * formatted; {@code false} otherwise.
*/
public void setDecimalSeparatorAlwaysShown(boolean value) {
ndf.setDecimalSeparatorAlwaysShown(value);
@@ -940,20 +935,14 @@ public class DecimalFormat extends NumberFormat {
* Sets the number of digits grouped together by the grouping separator.
* This only allows to set the primary grouping size; the secondary grouping
* size can only be set with a pattern.
- *
- * @param value
- * the number of digits grouped together.
*/
public void setGroupingSize(int value) {
ndf.setGroupingSize(value);
}
/**
- * Sets whether or not grouping will be used in this format. Grouping
- * affects both parsing and formatting.
- *
- * @param value
- * {@code true} if grouping is used; {@code false} otherwise.
+ * Sets whether or not digit grouping will be used in this format. Grouping
+ * affects both formatting and parsing.
*/
@Override
public void setGroupingUsed(boolean value) {
@@ -961,9 +950,8 @@ public class DecimalFormat extends NumberFormat {
}
/**
- * Indicates whether grouping will be used in this format.
- *
- * @return {@code true} if grouping is used; {@code false} otherwise.
+ * Returns true if digit grouping is used in this format. Grouping affects both
+ * formatting and parsing.
*/
@Override
public boolean isGroupingUsed() {
@@ -974,8 +962,6 @@ public class DecimalFormat extends NumberFormat {
* Sets the maximum number of digits after the decimal point.
* If the value passed is negative then it is replaced by 0.
* Regardless of this setting, no more than 340 digits will be used.
- *
- * @param value the maximum number of fraction digits.
*/
@Override
public void setMaximumFractionDigits(int value) {
@@ -989,8 +975,6 @@ public class DecimalFormat extends NumberFormat {
* Sets the maximum number of digits before the decimal point.
* If the value passed is negative then it is replaced by 0.
* Regardless of this setting, no more than 309 digits will be used.
- *
- * @param value the maximum number of integer digits.
*/
@Override
public void setMaximumIntegerDigits(int value) {
@@ -1002,8 +986,6 @@ public class DecimalFormat extends NumberFormat {
* Sets the minimum number of digits after the decimal point.
* If the value passed is negative then it is replaced by 0.
* Regardless of this setting, no more than 340 digits will be used.
- *
- * @param value the minimum number of fraction digits.
*/
@Override
public void setMinimumFractionDigits(int value) {
@@ -1015,8 +997,6 @@ public class DecimalFormat extends NumberFormat {
* Sets the minimum number of digits before the decimal point.
* If the value passed is negative then it is replaced by 0.
* Regardless of this setting, no more than 309 digits will be used.
- *
- * @param value the minimum number of integer digits.
*/
@Override
public void setMinimumIntegerDigits(int value) {
@@ -1025,11 +1005,20 @@ public class DecimalFormat extends NumberFormat {
}
/**
+ * Returns the multiplier which is applied to the number before formatting
+ * or after parsing. The multiplier is meant for tasks like parsing percentages.
+ * For example, given a multiplier of 100, 1.23 would be formatted as "123" and
+ * "123" would be parsed as 1.23.
+ */
+ public int getMultiplier() {
+ return ndf.getMultiplier();
+ }
+
+ /**
* Sets the multiplier which is applied to the number before formatting or
- * after parsing.
- *
- * @param value
- * the multiplier.
+ * after parsing. The multiplier meant for tasks like parsing percentages.
+ * For example, given a multiplier of 100, 1.23 would be formatted as "123" and
+ * "123" would be parsed as 1.23.
*/
public void setMultiplier(int value) {
ndf.setMultiplier(value);
@@ -1037,9 +1026,6 @@ public class DecimalFormat extends NumberFormat {
/**
* Sets the prefix which is formatted or parsed before a negative number.
- *
- * @param value
- * the negative prefix.
*/
public void setNegativePrefix(String value) {
ndf.setNegativePrefix(value);
@@ -1047,9 +1033,6 @@ public class DecimalFormat extends NumberFormat {
/**
* Sets the suffix which is formatted or parsed after a negative number.
- *
- * @param value
- * the negative suffix.
*/
public void setNegativeSuffix(String value) {
ndf.setNegativeSuffix(value);
@@ -1057,9 +1040,6 @@ public class DecimalFormat extends NumberFormat {
/**
* Sets the prefix which is formatted or parsed before a positive number.
- *
- * @param value
- * the positive prefix.
*/
public void setPositivePrefix(String value) {
ndf.setPositivePrefix(value);
@@ -1067,9 +1047,6 @@ public class DecimalFormat extends NumberFormat {
/**
* Sets the suffix which is formatted or parsed after a positive number.
- *
- * @param value
- * the positive suffix.
*/
public void setPositiveSuffix(String value) {
ndf.setPositiveSuffix(value);
@@ -1244,4 +1221,6 @@ public class DecimalFormat extends NumberFormat {
ndf.setRoundingMode(roundingMode, roundingIncrement);
}
}
+
+ public String toString() { return ndf.toString(); }
}
diff --git a/luni/src/main/java/java/text/FieldPosition.java b/luni/src/main/java/java/text/FieldPosition.java
index d5bccc7..c26ba33 100644
--- a/luni/src/main/java/java/text/FieldPosition.java
+++ b/luni/src/main/java/java/text/FieldPosition.java
@@ -21,152 +21,114 @@ package java.text;
* Identifies fields in formatted strings. If a {@code FieldPosition} is passed
* to the format method with such a parameter, then the indices will be set to
* the start and end indices of the field in the formatted string.
- * <p>
- * A {@code FieldPosition} can be created by using the integer constants in the
+ *
+ * <p>A {@code FieldPosition} can be created by using the integer constants in the
* various format classes (for example {@code NumberFormat.INTEGER_FIELD}) or
* one of the fields of type {@code Format.Field}.
- * <p>
- * If more than one field information is needed, the method
+ *
+ * <p>If more than one field position is needed, the method
* {@link NumberFormat#formatToCharacterIterator(Object)} should be used.
*/
public class FieldPosition {
- private int myField, beginIndex, endIndex;
-
- private Format.Field myAttribute;
-
- /**
- * Constructs a new {@code FieldPosition} for the specified field.
- *
- * @param field
- * the field to identify.
- */
- public FieldPosition(int field) {
- myField = field;
- }
-
- /**
- * Constructs a new {@code FieldPosition} for the specified {@code Field}
- * attribute.
- *
- * @param attribute
- * the field attribute to identify.
- */
- public FieldPosition(Format.Field attribute) {
- myAttribute = attribute;
- myField = -1;
- }
-
- /**
- * Constructs a new {@code FieldPosition} for the specified {@code Field}
- * attribute and field id.
- *
- * @param attribute
- * the field attribute to identify.
- * @param field
- * the field to identify.
- */
- public FieldPosition(Format.Field attribute, int field) {
- myAttribute = attribute;
- myField = field;
- }
-
- void clear() {
- beginIndex = endIndex = 0;
- }
-
- /**
- * Compares the specified object to this field position and indicates if
- * they are equal. In order to be equal, {@code object} must be an instance
- * of {@code FieldPosition} with the same field, begin index and end index.
- *
- * @param object
- * the object to compare with this object.
- * @return {@code true} if the specified object is equal to this field
- * position; {@code false} otherwise.
- * @see #hashCode
- */
- @Override
- public boolean equals(Object object) {
- if (!(object instanceof FieldPosition)) {
- return false;
- }
- FieldPosition pos = (FieldPosition) object;
- return myField == pos.myField && myAttribute == pos.myAttribute
- && beginIndex == pos.beginIndex && endIndex == pos.endIndex;
- }
-
- /**
- * Returns the index of the beginning of the field.
- *
- * @return the first index of the field.
- */
- public int getBeginIndex() {
- return beginIndex;
- }
-
- /**
- * Returns the index one past the end of the field.
- *
- * @return one past the index of the last character in the field.
- */
- public int getEndIndex() {
- return endIndex;
- }
-
- /**
- * Returns the field which is being identified.
- *
- * @return the field constant.
- */
- public int getField() {
- return myField;
- }
-
- /**
- * Returns the attribute which is being identified.
- *
- * @return the field.
- */
- public Format.Field getFieldAttribute() {
- return myAttribute;
- }
-
- @Override
- public int hashCode() {
- int attributeHash = (myAttribute == null) ? 0 : myAttribute.hashCode();
- return attributeHash + myField * 10 + beginIndex * 100 + endIndex;
- }
-
- /**
- * Sets the index of the beginning of the field.
- *
- * @param index
- * the index of the first character in the field.
- */
- public void setBeginIndex(int index) {
- beginIndex = index;
- }
-
- /**
- * Sets the index of the end of the field.
- *
- * @param index
- * one past the index of the last character in the field.
- */
- public void setEndIndex(int index) {
- endIndex = index;
- }
-
- /**
- * Returns the string representation of this field position.
- *
- * @return the string representation of this field position.
- */
- @Override
- public String toString() {
- return getClass().getName() + "[attribute=" + myAttribute + ", field="
- + myField + ", beginIndex=" + beginIndex + ", endIndex="
- + endIndex + "]";
+ private int field;
+ private int beginIndex;
+ private int endIndex;
+ private Format.Field attribute;
+
+ /**
+ * Constructs a new {@code FieldPosition} for the given field id.
+ */
+ public FieldPosition(int field) {
+ this.field = field;
+ }
+
+ /**
+ * Constructs a new {@code FieldPosition} for the given {@code Field} attribute.
+ */
+ public FieldPosition(Format.Field attribute) {
+ this.attribute = attribute;
+ this.field = -1;
+ }
+
+ /**
+ * Constructs a new {@code FieldPosition} for the given {@code Field} attribute and field id.
+ */
+ public FieldPosition(Format.Field attribute, int field) {
+ this.attribute = attribute;
+ this.field = field;
+ }
+
+ /**
+ * Compares the given object to this field position and indicates if
+ * they are equal. In order to be equal, {@code object} must be an instance
+ * of {@code FieldPosition} with the same field, begin index and end index.
+ */
+ @Override public boolean equals(Object object) {
+ if (!(object instanceof FieldPosition)) {
+ return false;
}
+ FieldPosition pos = (FieldPosition) object;
+ return field == pos.field && this.attribute == pos.attribute &&
+ beginIndex == pos.beginIndex && endIndex == pos.endIndex;
+ }
+
+ /**
+ * Returns the index of the beginning of the field.
+ */
+ public int getBeginIndex() {
+ return beginIndex;
+ }
+
+ /**
+ * Returns the index one past the end of the field.
+ */
+ public int getEndIndex() {
+ return endIndex;
+ }
+
+ /**
+ * Returns the field which is being identified.
+ */
+ public int getField() {
+ return field;
+ }
+
+ /**
+ * Returns the attribute which is being identified.
+ */
+ public Format.Field getFieldAttribute() {
+ return attribute;
+ }
+
+ @Override public int hashCode() {
+ int attributeHash = (attribute == null) ? 0 : attribute.hashCode();
+ return attributeHash + field * 10 + beginIndex * 100 + endIndex;
+ }
+
+ /**
+ * Sets the index of the beginning of the field.
+ */
+ public void setBeginIndex(int index) {
+ beginIndex = index;
+ }
+
+ /**
+ * Sets the index of the end of the field.
+ */
+ public void setEndIndex(int index) {
+ endIndex = index;
+ }
+
+ /**
+ * Returns the string representation of this field position.
+ */
+ @Override public String toString() {
+ return getClass().getName() + "[" +
+ "attribute=" + attribute +
+ ",field=" + field +
+ ",beginIndex=" + beginIndex +
+ ",endIndex=" + endIndex +
+ "]";
+ }
}
diff --git a/luni/src/main/java/java/text/NumberFormat.java b/luni/src/main/java/java/text/NumberFormat.java
index 36fdd0f..5879191 100644
--- a/luni/src/main/java/java/text/NumberFormat.java
+++ b/luni/src/main/java/java/text/NumberFormat.java
@@ -155,8 +155,10 @@ public abstract class NumberFormat extends Format {
private boolean groupingUsed = true, parseIntegerOnly = false;
- private int maximumIntegerDigits = 40, minimumIntegerDigits = 1,
- maximumFractionDigits = 3, minimumFractionDigits = 0;
+ int maximumIntegerDigits = 40;
+ int minimumIntegerDigits = 1;
+ int maximumFractionDigits = 3;
+ int minimumFractionDigits = 0;
/**
* Used by subclasses. This was public in Java 5.
@@ -208,8 +210,7 @@ public abstract class NumberFormat extends Format {
* @return the formatted string.
*/
public final String format(double value) {
- return format(value, new StringBuffer(), new FieldPosition(0))
- .toString();
+ return format(value, new StringBuffer(), new FieldPosition(0)).toString();
}
/**
@@ -241,8 +242,7 @@ public abstract class NumberFormat extends Format {
* @return the formatted string.
*/
public final String format(long value) {
- return format(value, new StringBuffer(), new FieldPosition(0))
- .toString();
+ return format(value, new StringBuffer(), new FieldPosition(0)).toString();
}
/**
@@ -301,7 +301,11 @@ public abstract class NumberFormat extends Format {
double dv = ((Number) object).doubleValue();
return format(dv, buffer, field);
}
- throw new IllegalArgumentException("Bad class: " + object.getClass());
+ if (object == null) {
+ throw new IllegalArgumentException("Can't format null object");
+ } else {
+ throw new IllegalArgumentException("Bad class: " + object.getClass());
+ }
}
/**
@@ -514,11 +518,8 @@ public abstract class NumberFormat extends Format {
}
/**
- * Indicates whether this number format only parses integer numbers. Parsing
+ * Returns true if this number format only parses integer numbers. Parsing
* stops if a decimal separator is encountered.
- *
- * @return {@code true} if this number format only parses integers,
- * {@code false} if if parsese integers as well as fractions.
*/
public boolean isParseIntegerOnly() {
return parseIntegerOnly;
@@ -742,10 +743,6 @@ public abstract class NumberFormat extends Format {
* The instances of this inner class are used as attribute keys and values
* in {@code AttributedCharacterIterator} that the
* {@link NumberFormat#formatToCharacterIterator(Object)} method returns.
- * <p>
- * There is no public constructor in this class, the only instances are the
- * constants defined here.
- * <p>
*/
public static class Field extends Format.Field {
@@ -809,9 +806,6 @@ public abstract class NumberFormat extends Format {
/**
* Constructs a new instance of {@code NumberFormat.Field} with the
* given field name.
- *
- * @param fieldName
- * the field name.
*/
protected Field(String fieldName) {
super(fieldName);
diff --git a/luni/src/main/java/java/text/SimpleDateFormat.java b/luni/src/main/java/java/text/SimpleDateFormat.java
index ea90bbb..d369970 100644
--- a/luni/src/main/java/java/text/SimpleDateFormat.java
+++ b/luni/src/main/java/java/text/SimpleDateFormat.java
@@ -517,7 +517,8 @@ public class SimpleDateFormat extends DateFormat {
int next, last = -1, count = 0;
calendar.setTime(date);
if (field != null) {
- field.clear();
+ field.setBeginIndex(0);
+ field.setEndIndex(0);
}
final int patternLength = pattern.length();
@@ -623,8 +624,7 @@ public class SimpleDateFormat extends DateFormat {
break;
case MILLISECOND_FIELD:
dateFormatField = Field.MILLISECOND;
- int value = calendar.get(Calendar.MILLISECOND);
- appendNumber(buffer, count, value);
+ appendMilliseconds(buffer, count, calendar.get(Calendar.MILLISECOND));
break;
case STAND_ALONE_DAY_OF_WEEK_FIELD:
dateFormatField = Field.DAY_OF_WEEK;
@@ -776,6 +776,24 @@ public class SimpleDateFormat extends DateFormat {
appendNumber(buffer, 2, (offset % 3600000) / 60000);
}
+ private void appendMilliseconds(StringBuffer buffer, int count, int value) {
+ // Unlike other fields, milliseconds are truncated by count. So 361 formatted SS is "36".
+ numberFormat.setMinimumIntegerDigits((count > 3) ? 3 : count);
+ numberFormat.setMaximumIntegerDigits(10);
+ // We need to left-justify.
+ if (count == 1) {
+ value /= 100;
+ } else if (count == 2) {
+ value /= 10;
+ }
+ FieldPosition p = new FieldPosition(0);
+ numberFormat.format(Integer.valueOf(value), buffer, p);
+ if (count > 3) {
+ numberFormat.setMinimumIntegerDigits(count - 3);
+ numberFormat.format(Integer.valueOf(0), buffer, p);
+ }
+ }
+
private void appendNumber(StringBuffer buffer, int count, int value) {
// TODO: we could avoid using the NumberFormat in most cases for a significant speedup.
// The only problem is that we expose the NumberFormat to third-party code, so we'd have
diff --git a/luni/src/main/java/java/util/concurrent/ConcurrentHashMap.java b/luni/src/main/java/java/util/concurrent/ConcurrentHashMap.java
index 515cc38..ea3b1e9 100644
--- a/luni/src/main/java/java/util/concurrent/ConcurrentHashMap.java
+++ b/luni/src/main/java/java/util/concurrent/ConcurrentHashMap.java
@@ -2002,7 +2002,7 @@ public class ConcurrentHashMap<K,V> extends java.util.AbstractMap<K,V>
return;
}
}
- else if ((s | WAITER) == 0) {
+ else if ((s & WAITER) == 0) {
if (U.compareAndSwapInt(this, LOCKSTATE, s, s | WAITER)) {
waiting = true;
waiter = Thread.currentThread();
diff --git a/luni/src/main/java/libcore/icu/DateIntervalFormat.java b/luni/src/main/java/libcore/icu/DateIntervalFormat.java
index a3e1e5e..274cce7 100644
--- a/luni/src/main/java/libcore/icu/DateIntervalFormat.java
+++ b/luni/src/main/java/libcore/icu/DateIntervalFormat.java
@@ -42,6 +42,9 @@ public final class DateIntervalFormat {
public static final int FORMAT_NUMERIC_DATE = 0x20000;
public static final int FORMAT_ABBREV_ALL = 0x80000;
+ private static final int DAY_IN_MS = 24 * 60 * 60 * 1000;
+ private static final int EPOCH_JULIAN_DAY = 2440588;
+
// TODO: check whether icu4c's DateIntervalFormat is expensive enough to warrant a native peer.
private DateIntervalFormat() {
}
@@ -58,11 +61,6 @@ public final class DateIntervalFormat {
// This is our slightly more sensible internal API. (A truly sane replacement would take a
// skeleton instead of int flags.)
public static String formatDateRange(Locale locale, TimeZone tz, long startMs, long endMs, int flags) {
- String skeleton = toSkeleton(tz, startMs, endMs, flags);
- return formatDateInterval(skeleton, locale.toString(), tz.getID(), startMs, endMs);
- }
-
- private static String toSkeleton(TimeZone tz, long startMs, long endMs, int flags) {
Calendar startCalendar = Calendar.getInstance(tz);
startCalendar.setTimeInMillis(startMs);
@@ -74,6 +72,23 @@ public final class DateIntervalFormat {
endCalendar.setTimeInMillis(endMs);
}
+ boolean endsAtMidnight = isMidnight(endCalendar);
+
+ // If we're not showing the time or the start and end times are on the same day, and the
+ // end time is midnight, fudge the end date so we don't count the day that's about to start.
+ // This is not the behavior of icu4c's DateIntervalFormat, but it's the historical behavior
+ // of Android's DateUtils.formatDateRange.
+ if (startMs != endMs && endsAtMidnight &&
+ ((flags & FORMAT_SHOW_TIME) == 0 || julianDay(startCalendar) == julianDay(endCalendar))) {
+ endCalendar.roll(Calendar.DAY_OF_MONTH, false);
+ endMs -= DAY_IN_MS;
+ }
+
+ String skeleton = toSkeleton(startCalendar, endCalendar, flags);
+ return formatDateInterval(skeleton, locale.toString(), tz.getID(), startMs, endMs);
+ }
+
+ private static String toSkeleton(Calendar startCalendar, Calendar endCalendar, int flags) {
if ((flags & FORMAT_ABBREV_ALL) != 0) {
flags |= FORMAT_ABBREV_MONTH | FORMAT_ABBREV_TIME | FORMAT_ABBREV_WEEKDAY;
}
@@ -96,8 +111,18 @@ public final class DateIntervalFormat {
} else if ((flags & FORMAT_12HOUR) != 0) {
timePart = "h";
}
- if ((flags & FORMAT_ABBREV_TIME) == 0 || !onTheHour(startCalendar) || !onTheHour(endCalendar)) {
- timePart = timePart + "m";
+
+ // If we've not been asked to abbreviate times, or we're using the 24-hour clock (where it
+ // never makes sense to leave out the minutes), include minutes. This gets us times like
+ // "4 PM" while avoiding times like "16" (for "16:00").
+ if ((flags & FORMAT_ABBREV_TIME) == 0 || (flags & FORMAT_24HOUR) != 0) {
+ timePart += "m";
+ } else {
+ // Otherwise, we're abbreviating a 12-hour time, and should only show the minutes
+ // if they're not both "00".
+ if (!(onTheHour(startCalendar) && onTheHour(endCalendar))) {
+ timePart = timePart + "m";
+ }
}
if (fallOnDifferentDates(startCalendar, endCalendar)) {
@@ -132,6 +157,13 @@ public final class DateIntervalFormat {
return builder.toString();
}
+ private static boolean isMidnight(Calendar c) {
+ return c.get(Calendar.HOUR_OF_DAY) == 0 &&
+ c.get(Calendar.MINUTE) == 0 &&
+ c.get(Calendar.SECOND) == 0 &&
+ c.get(Calendar.MILLISECOND) == 0;
+ }
+
private static boolean onTheHour(Calendar c) {
return c.get(Calendar.MINUTE) == 0 && c.get(Calendar.SECOND) == 0;
}
@@ -146,5 +178,10 @@ public final class DateIntervalFormat {
return c1.get(Calendar.MONTH) == c2.get(Calendar.MONTH);
}
+ private static int julianDay(Calendar c) {
+ long utcMs = c.get(Calendar.MILLISECOND) + c.get(Calendar.ZONE_OFFSET);
+ return (int) (utcMs / DAY_IN_MS) + EPOCH_JULIAN_DAY;
+ }
+
private static native String formatDateInterval(String skeleton, String localeName, String timeZoneName, long fromDate, long toDate);
}
diff --git a/luni/src/main/java/libcore/icu/LocaleData.java b/luni/src/main/java/libcore/icu/LocaleData.java
index a6d700f..2a0573f 100644
--- a/luni/src/main/java/libcore/icu/LocaleData.java
+++ b/luni/src/main/java/libcore/icu/LocaleData.java
@@ -174,6 +174,12 @@ public final class LocaleData {
if (!ICU.initLocaleDataImpl(locale.toString(), localeData)) {
throw new AssertionError("couldn't initialize LocaleData for locale " + locale);
}
+
+ // Get the "h:mm a" and "HH:mm" 12- and 24-hour time format strings.
+ localeData.timeFormat12 = ICU.getBestDateTimePattern("hm", locale.toString());
+ localeData.timeFormat24 = ICU.getBestDateTimePattern("Hm", locale.toString());
+
+ // Fix up a couple of patterns.
if (localeData.fullTimeFormat != null) {
// There are some full time format patterns in ICU that use the pattern character 'v'.
// Java doesn't accept this, so we replace it with 'z' which has about the same result
diff --git a/luni/src/main/java/libcore/icu/NativeDecimalFormat.java b/luni/src/main/java/libcore/icu/NativeDecimalFormat.java
index 0e9ffc4..fbb3d10 100644
--- a/luni/src/main/java/libcore/icu/NativeDecimalFormat.java
+++ b/luni/src/main/java/libcore/icu/NativeDecimalFormat.java
@@ -27,7 +27,6 @@ import java.text.Format;
import java.text.NumberFormat;
import java.text.ParsePosition;
import java.util.Currency;
-import java.util.NoSuchElementException;
public final class NativeDecimalFormat implements Cloneable {
/**
@@ -92,6 +91,47 @@ public final class NativeDecimalFormat implements Cloneable {
private static final int UNUM_PUBLIC_RULESETS = 7;
/**
+ * A table for translating between NumberFormat.Field instances
+ * and icu4c UNUM_x_FIELD constants.
+ */
+ private static final Format.Field[] ICU4C_FIELD_IDS = {
+ // The old java field values were 0 for integer and 1 for fraction.
+ // The new java field attributes are all objects. ICU assigns the values
+ // starting from 0 in the following order; note that integer and
+ // fraction positions match the old field values.
+ NumberFormat.Field.INTEGER, // 0 UNUM_INTEGER_FIELD
+ NumberFormat.Field.FRACTION, // 1 UNUM_FRACTION_FIELD
+ NumberFormat.Field.DECIMAL_SEPARATOR, // 2 UNUM_DECIMAL_SEPARATOR_FIELD
+ NumberFormat.Field.EXPONENT_SYMBOL, // 3 UNUM_EXPONENT_SYMBOL_FIELD
+ NumberFormat.Field.EXPONENT_SIGN, // 4 UNUM_EXPONENT_SIGN_FIELD
+ NumberFormat.Field.EXPONENT, // 5 UNUM_EXPONENT_FIELD
+ NumberFormat.Field.GROUPING_SEPARATOR, // 6 UNUM_GROUPING_SEPARATOR_FIELD
+ NumberFormat.Field.CURRENCY, // 7 UNUM_CURRENCY_FIELD
+ NumberFormat.Field.PERCENT, // 8 UNUM_PERCENT_FIELD
+ NumberFormat.Field.PERMILLE, // 9 UNUM_PERMILL_FIELD
+ NumberFormat.Field.SIGN, // 10 UNUM_SIGN_FIELD
+ };
+
+ private static int translateFieldId(FieldPosition fp) {
+ int id = fp.getField();
+ if (id < -1 || id > 1) {
+ id = -1;
+ }
+ if (id == -1) {
+ Format.Field attr = fp.getFieldAttribute();
+ if (attr != null) {
+ for (int i = 0; i < ICU4C_FIELD_IDS.length; ++i) {
+ if (ICU4C_FIELD_IDS[i].equals(attr)) {
+ id = i;
+ break;
+ }
+ }
+ }
+ }
+ return id;
+ }
+
+ /**
* The address of the ICU DecimalFormat* on the native heap.
*/
private long address;
@@ -111,13 +151,6 @@ public final class NativeDecimalFormat implements Cloneable {
private transient boolean parseBigDecimal;
- /**
- * Cache the BigDecimal form of the multiplier. This is null until we've
- * formatted a BigDecimal (with a multiplier that is not 1), or the user has
- * explicitly called {@link #setMultiplier(int)} with any multiplier.
- */
- private BigDecimal multiplierBigDecimal = null;
-
public NativeDecimalFormat(String pattern, DecimalFormatSymbols dfs) {
try {
this.address = open(pattern, dfs.getCurrencySymbol(),
@@ -211,6 +244,23 @@ public final class NativeDecimalFormat implements Cloneable {
obj.isGroupingUsed() == this.isGroupingUsed();
}
+ public String toString() {
+ return getClass().getName() + "[\"" + toPattern() + "\"" +
+ ",isDecimalSeparatorAlwaysShown=" + isDecimalSeparatorAlwaysShown() +
+ ",groupingSize=" + getGroupingSize() +
+ ",multiplier=" + getMultiplier() +
+ ",negativePrefix=" + getNegativePrefix() +
+ ",negativeSuffix=" + getNegativeSuffix() +
+ ",positivePrefix=" + getPositivePrefix() +
+ ",positiveSuffix=" + getPositiveSuffix() +
+ ",maxIntegerDigits=" + getMaximumIntegerDigits() +
+ ",maxFractionDigits=" + getMaximumFractionDigits() +
+ ",minIntegerDigits=" + getMinimumIntegerDigits() +
+ ",minFractionDigits=" + getMinimumFractionDigits() +
+ ",grouping=" + isGroupingUsed() +
+ "]";
+ }
+
/**
* Copies the DecimalFormatSymbols settings into our native peer in bulk.
*/
@@ -233,8 +283,8 @@ public final class NativeDecimalFormat implements Cloneable {
public char[] formatBigDecimal(BigDecimal value, FieldPosition field) {
FieldPositionIterator fpi = FieldPositionIterator.forFieldPosition(field);
char[] result = formatDigitList(this.address, value.toString(), fpi);
- if (fpi != null) {
- FieldPositionIterator.setFieldPosition(fpi, field);
+ if (fpi != null && field != null) {
+ updateFieldPosition(field, fpi);
}
return result;
}
@@ -242,8 +292,8 @@ public final class NativeDecimalFormat implements Cloneable {
public char[] formatBigInteger(BigInteger value, FieldPosition field) {
FieldPositionIterator fpi = FieldPositionIterator.forFieldPosition(field);
char[] result = formatDigitList(this.address, value.toString(10), fpi);
- if (fpi != null) {
- FieldPositionIterator.setFieldPosition(fpi, field);
+ if (fpi != null && field != null) {
+ updateFieldPosition(field, fpi);
}
return result;
}
@@ -251,8 +301,8 @@ public final class NativeDecimalFormat implements Cloneable {
public char[] formatLong(long value, FieldPosition field) {
FieldPositionIterator fpi = FieldPositionIterator.forFieldPosition(field);
char[] result = formatLong(this.address, value, fpi);
- if (fpi != null) {
- FieldPositionIterator.setFieldPosition(fpi, field);
+ if (fpi != null && field != null) {
+ updateFieldPosition(field, fpi);
}
return result;
}
@@ -260,12 +310,25 @@ public final class NativeDecimalFormat implements Cloneable {
public char[] formatDouble(double value, FieldPosition field) {
FieldPositionIterator fpi = FieldPositionIterator.forFieldPosition(field);
char[] result = formatDouble(this.address, value, fpi);
- if (fpi != null) {
- FieldPositionIterator.setFieldPosition(fpi, field);
+ if (fpi != null && field != null) {
+ updateFieldPosition(field, fpi);
}
return result;
}
+ private static void updateFieldPosition(FieldPosition fp, FieldPositionIterator fpi) {
+ int field = translateFieldId(fp);
+ if (field != -1) {
+ while (fpi.next()) {
+ if (fpi.fieldId() == field) {
+ fp.setBeginIndex(fpi.start());
+ fp.setEndIndex(fpi.limit());
+ return;
+ }
+ }
+ }
+ }
+
public void applyLocalizedPattern(String pattern) {
applyPattern(this.address, true, pattern);
lastPattern = null;
@@ -440,8 +503,6 @@ public final class NativeDecimalFormat implements Cloneable {
public void setMultiplier(int value) {
setAttribute(this.address, UNUM_MULTIPLIER, value);
- // Update the cached BigDecimal for multiplier.
- multiplierBigDecimal = BigDecimal.valueOf(value);
}
public void setNegativePrefix(String value) {
@@ -515,104 +576,33 @@ public final class NativeDecimalFormat implements Cloneable {
}
public static FieldPositionIterator forFieldPosition(FieldPosition fp) {
- if (fp != null && fp.getField() != -1) {
- return new FieldPositionIterator();
- }
- return null;
- }
-
- private static int getNativeFieldPositionId(FieldPosition fp) {
- // NOTE: -1, 0, and 1 were the only valid original java field values
- // for NumberFormat. They take precedence. This assumes any other
- // value is a mistake and the actual value is in the attribute.
- // Clients can construct FieldPosition combining any attribute with any field
- // value, which is just wrong, but there you go.
-
- int id = fp.getField();
- if (id < -1 || id > 1) {
- id = -1;
- }
- if (id == -1) {
- Format.Field attr = fp.getFieldAttribute();
- if (attr != null) {
- for (int i = 0; i < fields.length; ++i) {
- if (fields[i].equals(attr)) {
- id = i;
- break;
- }
- }
- }
- }
- return id;
- }
-
- private static void setFieldPosition(FieldPositionIterator fpi, FieldPosition fp) {
- if (fpi != null && fp != null) {
- int field = getNativeFieldPositionId(fp);
- if (field != -1) {
- while (fpi.next()) {
- if (fpi.fieldId() == field) {
- fp.setBeginIndex(fpi.start());
- fp.setEndIndex(fpi.limit());
- break;
- }
- }
- }
- }
+ return (fp != null) ? new FieldPositionIterator() : null;
}
public boolean next() {
- // if pos == data.length, we've already returned false once
- if (data == null || pos == data.length) {
- throw new NoSuchElementException();
+ if (data == null) {
+ return false;
}
pos += 3;
return pos < data.length;
}
- private void checkValid() {
- if (data == null || pos < 0 || pos == data.length) {
- throw new NoSuchElementException();
- }
- }
-
public int fieldId() {
return data[pos];
}
public Format.Field field() {
- checkValid();
- return fields[data[pos]];
+ return ICU4C_FIELD_IDS[data[pos]];
}
public int start() {
- checkValid();
return data[pos + 1];
}
public int limit() {
- checkValid();
return data[pos + 2];
}
- private static Format.Field fields[] = {
- // The old java field values were 0 for integer and 1 for fraction.
- // The new java field attributes are all objects. ICU assigns the values
- // starting from 0 in the following order; note that integer and
- // fraction positions match the old field values.
- NumberFormat.Field.INTEGER,
- NumberFormat.Field.FRACTION,
- NumberFormat.Field.DECIMAL_SEPARATOR,
- NumberFormat.Field.EXPONENT_SYMBOL,
- NumberFormat.Field.EXPONENT_SIGN,
- NumberFormat.Field.EXPONENT,
- NumberFormat.Field.GROUPING_SEPARATOR,
- NumberFormat.Field.CURRENCY,
- NumberFormat.Field.PERCENT,
- NumberFormat.Field.PERMILLE,
- NumberFormat.Field.SIGN,
- };
-
// called by native
private void setData(int[] data) {
this.data = data;
diff --git a/luni/src/main/native/IcuUtilities.h b/luni/src/main/native/IcuUtilities.h
index cff1e0d..ffcfcda 100644
--- a/luni/src/main/native/IcuUtilities.h
+++ b/luni/src/main/native/IcuUtilities.h
@@ -17,6 +17,7 @@
#ifndef ICU_UTILITIES_H_included
#define ICU_UTILITIES_H_included
+#undef U_HAVE_STD_STRING
#define U_HAVE_STD_STRING 1 // For UnicodeString::toUTF8String(std::string&).
#include "jni.h"
diff --git a/luni/src/main/native/Register.cpp b/luni/src/main/native/Register.cpp
index 54aecef..240e45b 100644
--- a/luni/src/main/native/Register.cpp
+++ b/luni/src/main/native/Register.cpp
@@ -73,7 +73,6 @@ int JNI_OnLoad(JavaVM* vm, void*) {
REGISTER(register_libcore_net_RawSocket);
REGISTER(register_org_apache_harmony_dalvik_NativeTestTarget);
REGISTER(register_org_apache_harmony_xml_ExpatParser);
- REGISTER(register_org_conscrypt_NativeCrypto);
REGISTER(register_sun_misc_Unsafe);
#undef REGISTER
return JNI_VERSION_1_6;
diff --git a/luni/src/main/native/libcore_icu_ICU.cpp b/luni/src/main/native/libcore_icu_ICU.cpp
index ad86e14..34d5803 100644
--- a/luni/src/main/native/libcore_icu_ICU.cpp
+++ b/luni/src/main/native/libcore_icu_ICU.cpp
@@ -439,28 +439,6 @@ static bool getDateTimePatterns(JNIEnv* env, jobject localeData, const char* loc
return true;
}
-static bool getTimeFormats12And24(JNIEnv* env, jobject localeData, Locale& locale) {
- UErrorCode status = U_ZERO_ERROR;
- DateTimePatternGenerator* generator = DateTimePatternGenerator::createInstance(locale, status);
- if (U_FAILURE(status)) {
- return false;
- }
-
- UnicodeString pattern_Hm(generator->getBestPattern(UnicodeString("Hm", 2, US_INV), status));
- if (U_FAILURE(status)) {
- return false;
- }
-
- UnicodeString pattern_hm(generator->getBestPattern(UnicodeString("hm", 2, US_INV), status));
- if (U_FAILURE(status)) {
- return false;
- }
-
- setStringField(env, localeData, "timeFormat12", pattern_hm);
- setStringField(env, localeData, "timeFormat24", pattern_Hm);
- return true;
-}
-
static bool getYesterdayTodayAndTomorrow(JNIEnv* env, jobject localeData, const char* locale_name) {
UErrorCode status = U_ZERO_ERROR;
ScopedResourceBundle root(ures_open(NULL, locale_name, &status));
@@ -512,13 +490,6 @@ static jboolean ICU_initLocaleDataImpl(JNIEnv* env, jclass, jstring javaLocaleNa
return JNI_FALSE;
}
- // Get the "h:mm a" and "HH:mm" 12- and 24-hour time format strings.
- Locale locale = getLocale(env, javaLocaleName);
- if (!getTimeFormats12And24(env, localeData, locale)) {
- ALOGE("Couldn't find ICU 12- and 24-hour time formats for %s", localeName.c_str());
- return JNI_FALSE;
- }
-
// Get the "Yesterday", "Today", and "Tomorrow" strings.
bool foundYesterdayTodayAndTomorrow = false;
for (LocaleNameIterator it(localeName.c_str(), status); it.HasNext(); it.Up()) {
@@ -533,6 +504,7 @@ static jboolean ICU_initLocaleDataImpl(JNIEnv* env, jclass, jstring javaLocaleNa
}
status = U_ZERO_ERROR;
+ Locale locale = getLocale(env, javaLocaleName);
UniquePtr<Calendar> cal(Calendar::createInstance(locale, status));
if (U_FAILURE(status)) {
return JNI_FALSE;
@@ -627,7 +599,7 @@ static jstring ICU_toLowerCase(JNIEnv* env, jclass, jstring javaString, jstring
}
UnicodeString& s(scopedString.unicodeString());
UnicodeString original(s);
- s.toLower(Locale::createFromName(ScopedUtfChars(env, localeName).c_str()));
+ s.toLower(getLocale(env, localeName));
return s == original ? javaString : env->NewString(s.getBuffer(), s.length());
}
@@ -638,7 +610,7 @@ static jstring ICU_toUpperCase(JNIEnv* env, jclass, jstring javaString, jstring
}
UnicodeString& s(scopedString.unicodeString());
UnicodeString original(s);
- s.toUpper(Locale::createFromName(ScopedUtfChars(env, localeName).c_str()));
+ s.toUpper(getLocale(env, localeName));
return s == original ? javaString : env->NewString(s.getBuffer(), s.length());
}
@@ -676,7 +648,7 @@ static jobject ICU_getAvailableCurrencyCodes(JNIEnv* env, jclass) {
static jstring ICU_getBestDateTimePattern(JNIEnv* env, jclass, jstring javaSkeleton, jstring javaLocaleName) {
Locale locale = getLocale(env, javaLocaleName);
UErrorCode status = U_ZERO_ERROR;
- DateTimePatternGenerator* generator = DateTimePatternGenerator::createInstance(locale, status);
+ UniquePtr<DateTimePatternGenerator> generator(DateTimePatternGenerator::createInstance(locale, status));
if (maybeThrowIcuException(env, "DateTimePatternGenerator::createInstance", status)) {
return NULL;
}
diff --git a/luni/src/main/native/libcore_icu_NativeDecimalFormat.cpp b/luni/src/main/native/libcore_icu_NativeDecimalFormat.cpp
index 88e6780..af1d8fe 100644
--- a/luni/src/main/native/libcore_icu_NativeDecimalFormat.cpp
+++ b/luni/src/main/native/libcore_icu_NativeDecimalFormat.cpp
@@ -16,25 +16,28 @@
#define LOG_TAG "NativeDecimalFormat"
+#include <stdlib.h>
+#include <string.h>
+
+#include <vector>
+
+#include "cutils/log.h"
+#include "digitlst.h"
#include "IcuUtilities.h"
-#include "JNIHelp.h"
#include "JniConstants.h"
#include "JniException.h"
+#include "JNIHelp.h"
#include "ScopedJavaUnicodeString.h"
#include "ScopedPrimitiveArray.h"
#include "ScopedStringChars.h"
#include "ScopedUtfChars.h"
-#include "UniquePtr.h"
-#include "cutils/log.h"
-#include "digitlst.h"
#include "unicode/decimfmt.h"
#include "unicode/fmtable.h"
#include "unicode/numfmt.h"
#include "unicode/unum.h"
#include "unicode/ustring.h"
+#include "UniquePtr.h"
#include "valueOf.h"
-#include <stdlib.h>
-#include <string.h>
static DecimalFormat* toDecimalFormat(jlong addr) {
return reinterpret_cast<DecimalFormat*>(static_cast<uintptr_t>(addr));
@@ -216,56 +219,69 @@ static jstring NativeDecimalFormat_toPatternImpl(JNIEnv* env, jclass, jlong addr
return env->NewString(pattern.getBuffer(), pattern.length());
}
-static jcharArray formatResult(JNIEnv* env, const UnicodeString &str, FieldPositionIterator* fpi, jobject fpIter) {
+static jcharArray formatResult(JNIEnv* env, const UnicodeString& s, FieldPositionIterator* fpi, jobject javaFieldPositionIterator) {
static jmethodID gFPI_setData = env->GetMethodID(JniConstants::fieldPositionIteratorClass, "setData", "([I)V");
if (fpi != NULL) {
- int len = fpi->getData(NULL, 0);
- jintArray data = NULL;
- if (len) {
- data = env->NewIntArray(len);
- ScopedIntArrayRW ints(env, data);
+ std::vector<int32_t> data;
+ FieldPosition fp;
+ while (fpi->next(fp)) {
+ data.push_back(fp.getField());
+ data.push_back(fp.getBeginIndex());
+ data.push_back(fp.getEndIndex());
+ }
+
+ jintArray javaData = NULL;
+ if (!data.empty()) {
+ javaData = env->NewIntArray(data.size());
+ if (javaData == NULL) {
+ return NULL;
+ }
+ ScopedIntArrayRW ints(env, javaData);
if (ints.get() == NULL) {
return NULL;
}
- fpi->getData(ints.get(), len);
+ memcpy(ints.get(), &data[0], data.size() * sizeof(int32_t));
}
- env->CallVoidMethod(fpIter, gFPI_setData, data);
+ env->CallVoidMethod(javaFieldPositionIterator, gFPI_setData, javaData);
}
- jcharArray result = env->NewCharArray(str.length());
+ jcharArray result = env->NewCharArray(s.length());
if (result != NULL) {
- env->SetCharArrayRegion(result, 0, str.length(), str.getBuffer());
+ env->SetCharArrayRegion(result, 0, s.length(), s.getBuffer());
}
return result;
}
template <typename T>
-static jcharArray format(JNIEnv* env, jlong addr, jobject fpIter, T val) {
+static jcharArray format(JNIEnv* env, jlong addr, jobject javaFieldPositionIterator, T value) {
UErrorCode status = U_ZERO_ERROR;
- UnicodeString str;
+ UnicodeString s;
DecimalFormat* fmt = toDecimalFormat(addr);
- FieldPositionIterator fpi;
- FieldPositionIterator* pfpi = fpIter ? &fpi : NULL;
- fmt->format(val, str, pfpi, status);
- return formatResult(env, str, pfpi, fpIter);
+ FieldPositionIterator nativeFieldPositionIterator;
+ FieldPositionIterator* fpi = javaFieldPositionIterator ? &nativeFieldPositionIterator : NULL;
+ fmt->format(value, s, fpi, status);
+ if (maybeThrowIcuException(env, "DecimalFormat::format", status)) {
+ return NULL;
+ }
+ return formatResult(env, s, fpi, javaFieldPositionIterator);
}
-static jcharArray NativeDecimalFormat_formatLong(JNIEnv* env, jclass, jlong addr, jlong value, jobject fpIter) {
- return format(env, addr, fpIter, value);
+static jcharArray NativeDecimalFormat_formatLong(JNIEnv* env, jclass, jlong addr, jlong value, jobject javaFieldPositionIterator) {
+ return format<int64_t>(env, addr, javaFieldPositionIterator, value);
}
-static jcharArray NativeDecimalFormat_formatDouble(JNIEnv* env, jclass, jlong addr, jdouble value, jobject fpIter) {
- return format(env, addr, fpIter, value);
+static jcharArray NativeDecimalFormat_formatDouble(JNIEnv* env, jclass, jlong addr, jdouble value, jobject javaFieldPositionIterator) {
+ return format<double>(env, addr, javaFieldPositionIterator, value);
}
-static jcharArray NativeDecimalFormat_formatDigitList(JNIEnv* env, jclass, jlong addr, jstring value, jobject fpIter) {
+static jcharArray NativeDecimalFormat_formatDigitList(JNIEnv* env, jclass, jlong addr, jstring value, jobject javaFieldPositionIterator) {
ScopedUtfChars chars(env, value);
if (chars.c_str() == NULL) {
return NULL;
}
StringPiece sp(chars.c_str());
- return format(env, addr, fpIter, sp);
+ return format(env, addr, javaFieldPositionIterator, sp);
}
static jobject newBigDecimal(JNIEnv* env, const char* value, jsize len) {
diff --git a/luni/src/test/java/libcore/icu/DateIntervalFormatTest.java b/luni/src/test/java/libcore/icu/DateIntervalFormatTest.java
index 8de3407..00ffc0e 100644
--- a/luni/src/test/java/libcore/icu/DateIntervalFormatTest.java
+++ b/luni/src/test/java/libcore/icu/DateIntervalFormatTest.java
@@ -26,11 +26,11 @@ import java.util.TimeZone;
import static libcore.icu.DateIntervalFormat.*;
public class DateIntervalFormatTest extends junit.framework.TestCase {
- private static final long MINUTE_DURATION = 60 * 1000;
- private static final long HOUR_DURATION = 60 * MINUTE_DURATION;
- private static final long DAY_DURATION = 24 * HOUR_DURATION;
- private static final long MONTH_DURATION = 31 * DAY_DURATION;
- private static final long YEAR_DURATION = 12 * MONTH_DURATION;
+ private static final long MINUTE = 60 * 1000;
+ private static final long HOUR = 60 * MINUTE;
+ private static final long DAY = 24 * HOUR;
+ private static final long MONTH = 31 * DAY;
+ private static final long YEAR = 12 * MONTH;
public void test_formatDateInterval() throws Exception {
Date date = new Date(109, 0, 19, 3, 30, 15);
@@ -53,12 +53,12 @@ public class DateIntervalFormatTest extends junit.framework.TestCase {
TimeZone tz = TimeZone.getTimeZone("America/Los_Angeles");
- assertEquals("Monday", formatDateRange(en_US, tz, fixedTime, fixedTime + HOUR_DURATION, FORMAT_SHOW_WEEKDAY));
- assertEquals("January 19", formatDateRange(en_US, tz, timeWithCurrentYear, timeWithCurrentYear + HOUR_DURATION, FORMAT_SHOW_DATE));
+ assertEquals("Monday", formatDateRange(en_US, tz, fixedTime, fixedTime + HOUR, FORMAT_SHOW_WEEKDAY));
+ assertEquals("January 19", formatDateRange(en_US, tz, timeWithCurrentYear, timeWithCurrentYear + HOUR, FORMAT_SHOW_DATE));
assertEquals("3:30 AM", formatDateRange(en_US, tz, fixedTime, fixedTime, FORMAT_SHOW_TIME));
- assertEquals("January 19, 2009", formatDateRange(en_US, tz, fixedTime, fixedTime + HOUR_DURATION, FORMAT_SHOW_YEAR));
- assertEquals("January 19", formatDateRange(en_US, tz, timeWithCurrentYear, timeWithCurrentYear + HOUR_DURATION, 0 /*FORMAT_NO_YEAR*/));
- assertEquals("January", formatDateRange(en_US, tz, timeWithCurrentYear, timeWithCurrentYear + HOUR_DURATION, FORMAT_NO_MONTH_DAY));
+ assertEquals("January 19, 2009", formatDateRange(en_US, tz, fixedTime, fixedTime + HOUR, FORMAT_SHOW_YEAR));
+ assertEquals("January 19", formatDateRange(en_US, tz, timeWithCurrentYear, timeWithCurrentYear + HOUR, 0 /*FORMAT_NO_YEAR*/));
+ assertEquals("January", formatDateRange(en_US, tz, timeWithCurrentYear, timeWithCurrentYear + HOUR, FORMAT_NO_MONTH_DAY));
assertEquals("3:30 AM", formatDateRange(en_US, tz, fixedTime, fixedTime, FORMAT_12HOUR | FORMAT_SHOW_TIME));
assertEquals("03:30", formatDateRange(en_US, tz, fixedTime, fixedTime, FORMAT_24HOUR | FORMAT_SHOW_TIME));
assertEquals("3:30 AM", formatDateRange(en_US, tz, fixedTime, fixedTime, FORMAT_12HOUR /*| FORMAT_CAP_AMPM*/ | FORMAT_SHOW_TIME));
@@ -68,97 +68,97 @@ public class DateIntervalFormatTest extends junit.framework.TestCase {
assertEquals("12:00 AM", formatDateRange(en_US, tz, fixedTime - midnightDuration, fixedTime - midnightDuration, FORMAT_12HOUR | FORMAT_SHOW_TIME /*| FORMAT_NO_MIDNIGHT*/));
assertEquals("3:30 AM", formatDateRange(en_US, tz, fixedTime, fixedTime, FORMAT_SHOW_TIME | FORMAT_UTC));
assertEquals("3 AM", formatDateRange(en_US, tz, fixedTime - integralDuration, fixedTime - integralDuration, FORMAT_SHOW_TIME | FORMAT_ABBREV_TIME));
- assertEquals("Mon", formatDateRange(en_US, tz, fixedTime, fixedTime + HOUR_DURATION, FORMAT_SHOW_WEEKDAY | FORMAT_ABBREV_WEEKDAY));
- assertEquals("Jan 19", formatDateRange(en_US, tz, timeWithCurrentYear, timeWithCurrentYear + HOUR_DURATION, FORMAT_SHOW_DATE | FORMAT_ABBREV_MONTH));
- assertEquals("Jan 19", formatDateRange(en_US, tz, timeWithCurrentYear, timeWithCurrentYear + HOUR_DURATION, FORMAT_SHOW_DATE | FORMAT_ABBREV_ALL));
-
- assertEquals("1/19/2009", formatDateRange(en_US, tz, fixedTime, fixedTime + 3 * HOUR_DURATION, FORMAT_SHOW_YEAR | FORMAT_NUMERIC_DATE));
- assertEquals("1/19/2009 – 1/22/2009", formatDateRange(en_US, tz, fixedTime, fixedTime + 3 * DAY_DURATION, FORMAT_SHOW_YEAR | FORMAT_NUMERIC_DATE));
- assertEquals("1/19/2009 – 4/22/2009", formatDateRange(en_US, tz, fixedTime, fixedTime + 3 * MONTH_DURATION, FORMAT_SHOW_YEAR | FORMAT_NUMERIC_DATE));
- assertEquals("1/19/2009 – 2/9/2012", formatDateRange(en_US, tz, fixedTime, fixedTime + 3 * YEAR_DURATION, FORMAT_SHOW_YEAR | FORMAT_NUMERIC_DATE));
-
- assertEquals("19.1.2009", formatDateRange(de_DE, tz, fixedTime, fixedTime + HOUR_DURATION, FORMAT_SHOW_YEAR | FORMAT_NUMERIC_DATE));
- assertEquals("19.01.2009 - 22.01.2009", formatDateRange(de_DE, tz, fixedTime, fixedTime + 3 * DAY_DURATION, FORMAT_SHOW_YEAR | FORMAT_NUMERIC_DATE));
- assertEquals("19.01.2009 - 22.04.2009", formatDateRange(de_DE, tz, fixedTime, fixedTime + 3 * MONTH_DURATION, FORMAT_SHOW_YEAR | FORMAT_NUMERIC_DATE));
- assertEquals("19.01.2009 - 09.02.2012", formatDateRange(de_DE, tz, fixedTime, fixedTime + 3 * YEAR_DURATION, FORMAT_SHOW_YEAR | FORMAT_NUMERIC_DATE));
-
- assertEquals("1/19/2009", formatDateRange(es_US, tz, fixedTime, fixedTime + HOUR_DURATION, FORMAT_SHOW_YEAR | FORMAT_NUMERIC_DATE));
- assertEquals("19/1/2009 – 22/1/2009", formatDateRange(es_US, tz, fixedTime, fixedTime + 3 * DAY_DURATION, FORMAT_SHOW_YEAR | FORMAT_NUMERIC_DATE));
- assertEquals("19/1/2009 – 22/4/2009", formatDateRange(es_US, tz, fixedTime, fixedTime + 3 * MONTH_DURATION, FORMAT_SHOW_YEAR | FORMAT_NUMERIC_DATE));
- assertEquals("19/1/2009 – 9/2/2012", formatDateRange(es_US, tz, fixedTime, fixedTime + 3 * YEAR_DURATION, FORMAT_SHOW_YEAR | FORMAT_NUMERIC_DATE));
-
- assertEquals("19/1/2009", formatDateRange(es_ES, tz, fixedTime, fixedTime + HOUR_DURATION, FORMAT_SHOW_YEAR | FORMAT_NUMERIC_DATE));
- assertEquals("19/1/2009 – 22/1/2009", formatDateRange(es_ES, tz, fixedTime, fixedTime + 3 * DAY_DURATION, FORMAT_SHOW_YEAR | FORMAT_NUMERIC_DATE));
- assertEquals("19/1/2009 – 22/4/2009", formatDateRange(es_ES, tz, fixedTime, fixedTime + 3 * MONTH_DURATION, FORMAT_SHOW_YEAR | FORMAT_NUMERIC_DATE));
- assertEquals("19/1/2009 – 9/2/2012", formatDateRange(es_ES, tz, fixedTime, fixedTime + 3 * YEAR_DURATION, FORMAT_SHOW_YEAR | FORMAT_NUMERIC_DATE));
+ assertEquals("Mon", formatDateRange(en_US, tz, fixedTime, fixedTime + HOUR, FORMAT_SHOW_WEEKDAY | FORMAT_ABBREV_WEEKDAY));
+ assertEquals("Jan 19", formatDateRange(en_US, tz, timeWithCurrentYear, timeWithCurrentYear + HOUR, FORMAT_SHOW_DATE | FORMAT_ABBREV_MONTH));
+ assertEquals("Jan 19", formatDateRange(en_US, tz, timeWithCurrentYear, timeWithCurrentYear + HOUR, FORMAT_SHOW_DATE | FORMAT_ABBREV_ALL));
+
+ assertEquals("1/19/2009", formatDateRange(en_US, tz, fixedTime, fixedTime + 3 * HOUR, FORMAT_SHOW_YEAR | FORMAT_NUMERIC_DATE));
+ assertEquals("1/19/2009 – 1/22/2009", formatDateRange(en_US, tz, fixedTime, fixedTime + 3 * DAY, FORMAT_SHOW_YEAR | FORMAT_NUMERIC_DATE));
+ assertEquals("1/19/2009 – 4/22/2009", formatDateRange(en_US, tz, fixedTime, fixedTime + 3 * MONTH, FORMAT_SHOW_YEAR | FORMAT_NUMERIC_DATE));
+ assertEquals("1/19/2009 – 2/9/2012", formatDateRange(en_US, tz, fixedTime, fixedTime + 3 * YEAR, FORMAT_SHOW_YEAR | FORMAT_NUMERIC_DATE));
+
+ assertEquals("19.1.2009", formatDateRange(de_DE, tz, fixedTime, fixedTime + HOUR, FORMAT_SHOW_YEAR | FORMAT_NUMERIC_DATE));
+ assertEquals("19.01.2009 - 22.01.2009", formatDateRange(de_DE, tz, fixedTime, fixedTime + 3 * DAY, FORMAT_SHOW_YEAR | FORMAT_NUMERIC_DATE));
+ assertEquals("19.01.2009 - 22.04.2009", formatDateRange(de_DE, tz, fixedTime, fixedTime + 3 * MONTH, FORMAT_SHOW_YEAR | FORMAT_NUMERIC_DATE));
+ assertEquals("19.01.2009 - 09.02.2012", formatDateRange(de_DE, tz, fixedTime, fixedTime + 3 * YEAR, FORMAT_SHOW_YEAR | FORMAT_NUMERIC_DATE));
+
+ assertEquals("1/19/2009", formatDateRange(es_US, tz, fixedTime, fixedTime + HOUR, FORMAT_SHOW_YEAR | FORMAT_NUMERIC_DATE));
+ assertEquals("19/1/2009 – 22/1/2009", formatDateRange(es_US, tz, fixedTime, fixedTime + 3 * DAY, FORMAT_SHOW_YEAR | FORMAT_NUMERIC_DATE));
+ assertEquals("19/1/2009 – 22/4/2009", formatDateRange(es_US, tz, fixedTime, fixedTime + 3 * MONTH, FORMAT_SHOW_YEAR | FORMAT_NUMERIC_DATE));
+ assertEquals("19/1/2009 – 9/2/2012", formatDateRange(es_US, tz, fixedTime, fixedTime + 3 * YEAR, FORMAT_SHOW_YEAR | FORMAT_NUMERIC_DATE));
+
+ assertEquals("19/1/2009", formatDateRange(es_ES, tz, fixedTime, fixedTime + HOUR, FORMAT_SHOW_YEAR | FORMAT_NUMERIC_DATE));
+ assertEquals("19/1/2009 – 22/1/2009", formatDateRange(es_ES, tz, fixedTime, fixedTime + 3 * DAY, FORMAT_SHOW_YEAR | FORMAT_NUMERIC_DATE));
+ assertEquals("19/1/2009 – 22/4/2009", formatDateRange(es_ES, tz, fixedTime, fixedTime + 3 * MONTH, FORMAT_SHOW_YEAR | FORMAT_NUMERIC_DATE));
+ assertEquals("19/1/2009 – 9/2/2012", formatDateRange(es_ES, tz, fixedTime, fixedTime + 3 * YEAR, FORMAT_SHOW_YEAR | FORMAT_NUMERIC_DATE));
// These are some random other test cases I came up with.
- assertEquals("January 19–22", formatDateRange(en_US, tz, fixedTime, fixedTime + 3 * DAY_DURATION, 0));
- assertEquals("Jan 19–22", formatDateRange(en_US, tz, fixedTime, fixedTime + 3 * DAY_DURATION, FORMAT_SHOW_DATE | FORMAT_ABBREV_ALL));
- assertEquals("Mon, Jan 19 – Thu, Jan 22", formatDateRange(en_US, tz, fixedTime, fixedTime + 3 * DAY_DURATION, FORMAT_SHOW_WEEKDAY | FORMAT_ABBREV_ALL));
- assertEquals("Monday, January 19 – Thursday, January 22", formatDateRange(en_US, tz, fixedTime, fixedTime + 3 * DAY_DURATION, FORMAT_SHOW_WEEKDAY));
+ assertEquals("January 19–22", formatDateRange(en_US, tz, fixedTime, fixedTime + 3 * DAY, 0));
+ assertEquals("Jan 19–22", formatDateRange(en_US, tz, fixedTime, fixedTime + 3 * DAY, FORMAT_SHOW_DATE | FORMAT_ABBREV_ALL));
+ assertEquals("Mon, Jan 19 – Thu, Jan 22", formatDateRange(en_US, tz, fixedTime, fixedTime + 3 * DAY, FORMAT_SHOW_WEEKDAY | FORMAT_ABBREV_ALL));
+ assertEquals("Monday, January 19 – Thursday, January 22", formatDateRange(en_US, tz, fixedTime, fixedTime + 3 * DAY, FORMAT_SHOW_WEEKDAY));
- assertEquals("January 19 – April 22", formatDateRange(en_US, tz, fixedTime, fixedTime + 3 * MONTH_DURATION, 0));
- assertEquals("Jan 19 – Apr 22", formatDateRange(en_US, tz, fixedTime, fixedTime + 3 * MONTH_DURATION, FORMAT_SHOW_DATE | FORMAT_ABBREV_ALL));
- assertEquals("Mon, Jan 19 – Wed, Apr 22", formatDateRange(en_US, tz, fixedTime, fixedTime + 3 * MONTH_DURATION, FORMAT_SHOW_WEEKDAY | FORMAT_ABBREV_ALL));
- assertEquals("January–April", formatDateRange(en_US, tz, fixedTime, fixedTime + 3 * MONTH_DURATION, FORMAT_NO_MONTH_DAY));
+ assertEquals("January 19 – April 22", formatDateRange(en_US, tz, fixedTime, fixedTime + 3 * MONTH, 0));
+ assertEquals("Jan 19 – Apr 22", formatDateRange(en_US, tz, fixedTime, fixedTime + 3 * MONTH, FORMAT_SHOW_DATE | FORMAT_ABBREV_ALL));
+ assertEquals("Mon, Jan 19 – Wed, Apr 22", formatDateRange(en_US, tz, fixedTime, fixedTime + 3 * MONTH, FORMAT_SHOW_WEEKDAY | FORMAT_ABBREV_ALL));
+ assertEquals("January–April", formatDateRange(en_US, tz, fixedTime, fixedTime + 3 * MONTH, FORMAT_NO_MONTH_DAY));
- assertEquals("Jan 19, 2009 – Feb 9, 2012", formatDateRange(en_US, tz, fixedTime, fixedTime + 3 * YEAR_DURATION, FORMAT_SHOW_DATE | FORMAT_ABBREV_ALL));
- assertEquals("Jan 2009 – Feb 2012", formatDateRange(en_US, tz, fixedTime, fixedTime + 3 * YEAR_DURATION, FORMAT_NO_MONTH_DAY | FORMAT_ABBREV_ALL));
- assertEquals("January 19, 2009 – February 9, 2012", formatDateRange(en_US, tz, fixedTime, fixedTime + 3 * YEAR_DURATION, 0));
- assertEquals("Monday, January 19, 2009 – Thursday, February 9, 2012", formatDateRange(en_US, tz, fixedTime, fixedTime + 3 * YEAR_DURATION, FORMAT_SHOW_WEEKDAY));
+ assertEquals("Jan 19, 2009 – Feb 9, 2012", formatDateRange(en_US, tz, fixedTime, fixedTime + 3 * YEAR, FORMAT_SHOW_DATE | FORMAT_ABBREV_ALL));
+ assertEquals("Jan 2009 – Feb 2012", formatDateRange(en_US, tz, fixedTime, fixedTime + 3 * YEAR, FORMAT_NO_MONTH_DAY | FORMAT_ABBREV_ALL));
+ assertEquals("January 19, 2009 – February 9, 2012", formatDateRange(en_US, tz, fixedTime, fixedTime + 3 * YEAR, 0));
+ assertEquals("Monday, January 19, 2009 – Thursday, February 9, 2012", formatDateRange(en_US, tz, fixedTime, fixedTime + 3 * YEAR, FORMAT_SHOW_WEEKDAY));
// The same tests but for de_DE.
- assertEquals("19.-22. Januar", formatDateRange(de_DE, tz, fixedTime, fixedTime + 3 * DAY_DURATION, 0));
- assertEquals("19.-22. Jan.", formatDateRange(de_DE, tz, fixedTime, fixedTime + 3 * DAY_DURATION, FORMAT_SHOW_DATE | FORMAT_ABBREV_ALL));
- assertEquals("Mo., 19. - Do., 22. Jan.", formatDateRange(de_DE, tz, fixedTime, fixedTime + 3 * DAY_DURATION, FORMAT_SHOW_WEEKDAY | FORMAT_ABBREV_ALL));
- assertEquals("Montag, 19. - Donnerstag, 22. Januar", formatDateRange(de_DE, tz, fixedTime, fixedTime + 3 * DAY_DURATION, FORMAT_SHOW_WEEKDAY));
+ assertEquals("19.-22. Januar", formatDateRange(de_DE, tz, fixedTime, fixedTime + 3 * DAY, 0));
+ assertEquals("19.-22. Jan.", formatDateRange(de_DE, tz, fixedTime, fixedTime + 3 * DAY, FORMAT_SHOW_DATE | FORMAT_ABBREV_ALL));
+ assertEquals("Mo., 19. - Do., 22. Jan.", formatDateRange(de_DE, tz, fixedTime, fixedTime + 3 * DAY, FORMAT_SHOW_WEEKDAY | FORMAT_ABBREV_ALL));
+ assertEquals("Montag, 19. - Donnerstag, 22. Januar", formatDateRange(de_DE, tz, fixedTime, fixedTime + 3 * DAY, FORMAT_SHOW_WEEKDAY));
- assertEquals("19. Januar - 22. April", formatDateRange(de_DE, tz, fixedTime, fixedTime + 3 * MONTH_DURATION, 0));
- assertEquals("19. Jan. - 22. Apr.", formatDateRange(de_DE, tz, fixedTime, fixedTime + 3 * MONTH_DURATION, FORMAT_SHOW_DATE | FORMAT_ABBREV_ALL));
- assertEquals("Mo., 19. Jan. - Mi., 22. Apr.", formatDateRange(de_DE, tz, fixedTime, fixedTime + 3 * MONTH_DURATION, FORMAT_SHOW_WEEKDAY | FORMAT_ABBREV_ALL));
- assertEquals("Januar-April", formatDateRange(de_DE, tz, fixedTime, fixedTime + 3 * MONTH_DURATION, FORMAT_NO_MONTH_DAY));
+ assertEquals("19. Januar - 22. April", formatDateRange(de_DE, tz, fixedTime, fixedTime + 3 * MONTH, 0));
+ assertEquals("19. Jan. - 22. Apr.", formatDateRange(de_DE, tz, fixedTime, fixedTime + 3 * MONTH, FORMAT_SHOW_DATE | FORMAT_ABBREV_ALL));
+ assertEquals("Mo., 19. Jan. - Mi., 22. Apr.", formatDateRange(de_DE, tz, fixedTime, fixedTime + 3 * MONTH, FORMAT_SHOW_WEEKDAY | FORMAT_ABBREV_ALL));
+ assertEquals("Januar-April", formatDateRange(de_DE, tz, fixedTime, fixedTime + 3 * MONTH, FORMAT_NO_MONTH_DAY));
- assertEquals("19. Jan. 2009 - 9. Feb. 2012", formatDateRange(de_DE, tz, fixedTime, fixedTime + 3 * YEAR_DURATION, FORMAT_SHOW_DATE | FORMAT_ABBREV_ALL));
- assertEquals("Jan. 2009 - Feb. 2012", formatDateRange(de_DE, tz, fixedTime, fixedTime + 3 * YEAR_DURATION, FORMAT_NO_MONTH_DAY | FORMAT_ABBREV_ALL));
- assertEquals("19. Januar 2009 - 9. Februar 2012", formatDateRange(de_DE, tz, fixedTime, fixedTime + 3 * YEAR_DURATION, 0));
- assertEquals("Montag, 19. Januar 2009 - Donnerstag, 9. Februar 2012", formatDateRange(de_DE, tz, fixedTime, fixedTime + 3 * YEAR_DURATION, FORMAT_SHOW_WEEKDAY));
+ assertEquals("19. Jan. 2009 - 9. Feb. 2012", formatDateRange(de_DE, tz, fixedTime, fixedTime + 3 * YEAR, FORMAT_SHOW_DATE | FORMAT_ABBREV_ALL));
+ assertEquals("Jan. 2009 - Feb. 2012", formatDateRange(de_DE, tz, fixedTime, fixedTime + 3 * YEAR, FORMAT_NO_MONTH_DAY | FORMAT_ABBREV_ALL));
+ assertEquals("19. Januar 2009 - 9. Februar 2012", formatDateRange(de_DE, tz, fixedTime, fixedTime + 3 * YEAR, 0));
+ assertEquals("Montag, 19. Januar 2009 - Donnerstag, 9. Februar 2012", formatDateRange(de_DE, tz, fixedTime, fixedTime + 3 * YEAR, FORMAT_SHOW_WEEKDAY));
// The same tests but for es_US.
- assertEquals("19–22 enero", formatDateRange(es_US, tz, fixedTime, fixedTime + 3 * DAY_DURATION, 0));
- assertEquals("19–22 ene", formatDateRange(es_US, tz, fixedTime, fixedTime + 3 * DAY_DURATION, FORMAT_SHOW_DATE | FORMAT_ABBREV_ALL));
- assertEquals("lun 19 ene – jue 22 ene", formatDateRange(es_US, tz, fixedTime, fixedTime + 3 * DAY_DURATION, FORMAT_SHOW_WEEKDAY | FORMAT_ABBREV_ALL));
- assertEquals("lunes 19 enero – jueves 22 enero", formatDateRange(es_US, tz, fixedTime, fixedTime + 3 * DAY_DURATION, FORMAT_SHOW_WEEKDAY));
+ assertEquals("19–22 enero", formatDateRange(es_US, tz, fixedTime, fixedTime + 3 * DAY, 0));
+ assertEquals("19–22 ene", formatDateRange(es_US, tz, fixedTime, fixedTime + 3 * DAY, FORMAT_SHOW_DATE | FORMAT_ABBREV_ALL));
+ assertEquals("lun 19 ene – jue 22 ene", formatDateRange(es_US, tz, fixedTime, fixedTime + 3 * DAY, FORMAT_SHOW_WEEKDAY | FORMAT_ABBREV_ALL));
+ assertEquals("lunes 19 enero – jueves 22 enero", formatDateRange(es_US, tz, fixedTime, fixedTime + 3 * DAY, FORMAT_SHOW_WEEKDAY));
- assertEquals("19 enero – 22 abril", formatDateRange(es_US, tz, fixedTime, fixedTime + 3 * MONTH_DURATION, 0));
- assertEquals("19 ene – 22 abr", formatDateRange(es_US, tz, fixedTime, fixedTime + 3 * MONTH_DURATION, FORMAT_SHOW_DATE | FORMAT_ABBREV_ALL));
- assertEquals("lun 19 ene – mié 22 abr", formatDateRange(es_US, tz, fixedTime, fixedTime + 3 * MONTH_DURATION, FORMAT_SHOW_WEEKDAY | FORMAT_ABBREV_ALL));
- assertEquals("enero–abril", formatDateRange(es_US, tz, fixedTime, fixedTime + 3 * MONTH_DURATION, FORMAT_NO_MONTH_DAY));
+ assertEquals("19 enero – 22 abril", formatDateRange(es_US, tz, fixedTime, fixedTime + 3 * MONTH, 0));
+ assertEquals("19 ene – 22 abr", formatDateRange(es_US, tz, fixedTime, fixedTime + 3 * MONTH, FORMAT_SHOW_DATE | FORMAT_ABBREV_ALL));
+ assertEquals("lun 19 ene – mié 22 abr", formatDateRange(es_US, tz, fixedTime, fixedTime + 3 * MONTH, FORMAT_SHOW_WEEKDAY | FORMAT_ABBREV_ALL));
+ assertEquals("enero–abril", formatDateRange(es_US, tz, fixedTime, fixedTime + 3 * MONTH, FORMAT_NO_MONTH_DAY));
- assertEquals("19 ene 2009 – 9 feb 2012", formatDateRange(es_US, tz, fixedTime, fixedTime + 3 * YEAR_DURATION, FORMAT_SHOW_DATE | FORMAT_ABBREV_ALL));
- assertEquals("ene 2009 – feb 2012", formatDateRange(es_US, tz, fixedTime, fixedTime + 3 * YEAR_DURATION, FORMAT_NO_MONTH_DAY | FORMAT_ABBREV_ALL));
- assertEquals("19 enero 2009 – 9 febrero 2012", formatDateRange(es_US, tz, fixedTime, fixedTime + 3 * YEAR_DURATION, 0));
- assertEquals("lunes 19 enero 2009 – jueves 9 febrero 2012", formatDateRange(es_US, tz, fixedTime, fixedTime + 3 * YEAR_DURATION, FORMAT_SHOW_WEEKDAY));
+ assertEquals("19 ene 2009 – 9 feb 2012", formatDateRange(es_US, tz, fixedTime, fixedTime + 3 * YEAR, FORMAT_SHOW_DATE | FORMAT_ABBREV_ALL));
+ assertEquals("ene 2009 – feb 2012", formatDateRange(es_US, tz, fixedTime, fixedTime + 3 * YEAR, FORMAT_NO_MONTH_DAY | FORMAT_ABBREV_ALL));
+ assertEquals("19 enero 2009 – 9 febrero 2012", formatDateRange(es_US, tz, fixedTime, fixedTime + 3 * YEAR, 0));
+ assertEquals("lunes 19 enero 2009 – jueves 9 febrero 2012", formatDateRange(es_US, tz, fixedTime, fixedTime + 3 * YEAR, FORMAT_SHOW_WEEKDAY));
// The same tests but for es_ES.
- assertEquals("19–22 enero", formatDateRange(es_ES, tz, fixedTime, fixedTime + 3 * DAY_DURATION, 0));
- assertEquals("19–22 ene", formatDateRange(es_ES, tz, fixedTime, fixedTime + 3 * DAY_DURATION, FORMAT_SHOW_DATE | FORMAT_ABBREV_ALL));
- assertEquals("lun 19 ene – jue 22 ene", formatDateRange(es_ES, tz, fixedTime, fixedTime + 3 * DAY_DURATION, FORMAT_SHOW_WEEKDAY | FORMAT_ABBREV_ALL));
- assertEquals("lunes 19 enero – jueves 22 enero", formatDateRange(es_ES, tz, fixedTime, fixedTime + 3 * DAY_DURATION, FORMAT_SHOW_WEEKDAY));
+ assertEquals("19–22 enero", formatDateRange(es_ES, tz, fixedTime, fixedTime + 3 * DAY, 0));
+ assertEquals("19–22 ene", formatDateRange(es_ES, tz, fixedTime, fixedTime + 3 * DAY, FORMAT_SHOW_DATE | FORMAT_ABBREV_ALL));
+ assertEquals("lun 19 ene – jue 22 ene", formatDateRange(es_ES, tz, fixedTime, fixedTime + 3 * DAY, FORMAT_SHOW_WEEKDAY | FORMAT_ABBREV_ALL));
+ assertEquals("lunes 19 enero – jueves 22 enero", formatDateRange(es_ES, tz, fixedTime, fixedTime + 3 * DAY, FORMAT_SHOW_WEEKDAY));
- assertEquals("19 enero – 22 abril", formatDateRange(es_ES, tz, fixedTime, fixedTime + 3 * MONTH_DURATION, 0));
- assertEquals("19 ene – 22 abr", formatDateRange(es_ES, tz, fixedTime, fixedTime + 3 * MONTH_DURATION, FORMAT_SHOW_DATE | FORMAT_ABBREV_ALL));
- assertEquals("lun 19 ene – mié 22 abr", formatDateRange(es_ES, tz, fixedTime, fixedTime + 3 * MONTH_DURATION, FORMAT_SHOW_WEEKDAY | FORMAT_ABBREV_ALL));
- assertEquals("enero–abril", formatDateRange(es_ES, tz, fixedTime, fixedTime + 3 * MONTH_DURATION, FORMAT_NO_MONTH_DAY));
+ assertEquals("19 enero – 22 abril", formatDateRange(es_ES, tz, fixedTime, fixedTime + 3 * MONTH, 0));
+ assertEquals("19 ene – 22 abr", formatDateRange(es_ES, tz, fixedTime, fixedTime + 3 * MONTH, FORMAT_SHOW_DATE | FORMAT_ABBREV_ALL));
+ assertEquals("lun 19 ene – mié 22 abr", formatDateRange(es_ES, tz, fixedTime, fixedTime + 3 * MONTH, FORMAT_SHOW_WEEKDAY | FORMAT_ABBREV_ALL));
+ assertEquals("enero–abril", formatDateRange(es_ES, tz, fixedTime, fixedTime + 3 * MONTH, FORMAT_NO_MONTH_DAY));
- assertEquals("19 ene 2009 – 9 feb 2012", formatDateRange(es_ES, tz, fixedTime, fixedTime + 3 * YEAR_DURATION, FORMAT_SHOW_DATE | FORMAT_ABBREV_ALL));
- assertEquals("ene 2009 – feb 2012", formatDateRange(es_ES, tz, fixedTime, fixedTime + 3 * YEAR_DURATION, FORMAT_NO_MONTH_DAY | FORMAT_ABBREV_ALL));
- assertEquals("19 enero 2009 – 9 febrero 2012", formatDateRange(es_ES, tz, fixedTime, fixedTime + 3 * YEAR_DURATION, 0));
- assertEquals("lunes 19 enero 2009 – jueves 9 febrero 2012", formatDateRange(es_ES, tz, fixedTime, fixedTime + 3 * YEAR_DURATION, FORMAT_SHOW_WEEKDAY));
+ assertEquals("19 ene 2009 – 9 feb 2012", formatDateRange(es_ES, tz, fixedTime, fixedTime + 3 * YEAR, FORMAT_SHOW_DATE | FORMAT_ABBREV_ALL));
+ assertEquals("ene 2009 – feb 2012", formatDateRange(es_ES, tz, fixedTime, fixedTime + 3 * YEAR, FORMAT_NO_MONTH_DAY | FORMAT_ABBREV_ALL));
+ assertEquals("19 enero 2009 – 9 febrero 2012", formatDateRange(es_ES, tz, fixedTime, fixedTime + 3 * YEAR, 0));
+ assertEquals("lunes 19 enero 2009 – jueves 9 febrero 2012", formatDateRange(es_ES, tz, fixedTime, fixedTime + 3 * YEAR, FORMAT_SHOW_WEEKDAY));
}
public void test8862241() throws Exception {
@@ -172,8 +172,73 @@ public class DateIntervalFormatTest extends junit.framework.TestCase {
public void test10089890() throws Exception {
// Test that we actually take the time zone into account.
// The Unix epoch is UTC, so 0 is 1970-01-01T00:00Z...
- assertEquals("Jan 1–2", formatDateRange(0, 24*60*60 * 1000L, FORMAT_SHOW_DATE | FORMAT_ABBREV_ALL, "Europe/London"));
+ assertEquals("Jan 1–2", formatDateRange(0, DAY, FORMAT_SHOW_DATE | FORMAT_ABBREV_ALL, "Europe/London"));
// But MTV is hours behind, so 0 was still the afternoon of the previous day...
- assertEquals("Dec 31, 1969 – Jan 1, 1970", formatDateRange(0, 24*60*60 * 1000L, FORMAT_SHOW_DATE | FORMAT_ABBREV_ALL, "America/Los_Angeles"));
+ assertEquals("Dec 31, 1969 – Jan 1, 1970", formatDateRange(0, DAY, FORMAT_SHOW_DATE | FORMAT_ABBREV_ALL, "America/Los_Angeles"));
+ }
+
+ public void test10318326() throws Exception {
+ long midnight = 0;
+ long teaTime = 16 * HOUR;
+
+ int time12 = FORMAT_12HOUR | FORMAT_SHOW_TIME;
+ int time24 = FORMAT_24HOUR | FORMAT_SHOW_TIME;
+ int abbr12 = time12 | FORMAT_ABBREV_ALL;
+ int abbr24 = time24 | FORMAT_ABBREV_ALL;
+
+ Locale l = Locale.US;
+ TimeZone utc = TimeZone.getTimeZone("UTC");
+
+ // Full length on-the-hour times.
+ assertEquals("00:00", formatDateRange(l, utc, midnight, midnight, time24));
+ assertEquals("12:00 AM", formatDateRange(l, utc, midnight, midnight, time12));
+ assertEquals("16:00", formatDateRange(l, utc, teaTime, teaTime, time24));
+ assertEquals("4:00 PM", formatDateRange(l, utc, teaTime, teaTime, time12));
+
+ // Abbreviated on-the-hour times.
+ assertEquals("00:00", formatDateRange(l, utc, midnight, midnight, abbr24));
+ assertEquals("12 AM", formatDateRange(l, utc, midnight, midnight, abbr12));
+ assertEquals("16:00", formatDateRange(l, utc, teaTime, teaTime, abbr24));
+ assertEquals("4 PM", formatDateRange(l, utc, teaTime, teaTime, abbr12));
+
+ // Abbreviated on-the-hour ranges.
+ assertEquals("00:00–16:00", formatDateRange(l, utc, midnight, teaTime, abbr24));
+ assertEquals("12 AM – 4 PM", formatDateRange(l, utc, midnight, teaTime, abbr12));
+
+ // Abbreviated mixed ranges.
+ assertEquals("00:00–16:01", formatDateRange(l, utc, midnight, teaTime + MINUTE, abbr24));
+ assertEquals("12:00 AM – 4:01 PM", formatDateRange(l, utc, midnight, teaTime + MINUTE, abbr12));
+ }
+
+ public void test10560853_when_time_not_displayed() throws Exception {
+ Locale l = Locale.US;
+ TimeZone utc = TimeZone.getTimeZone("UTC");
+
+ long midnight = 0;
+ long midnightNext = 1 * DAY;
+
+ int flags = FORMAT_SHOW_DATE | FORMAT_SHOW_WEEKDAY;
+
+ // An all-day event runs until 0 milliseconds into the next day, but is formatted as if it's
+ // just the first day.
+ assertEquals("Thursday, January 1", formatDateRange(l, utc, midnight, midnightNext, flags));
+
+ // Run one millisecond over, though, and you're into the next day.
+ long nextMorning = 1 * DAY + 1;
+ assertEquals("Thursday, January 1 – Friday, January 2", formatDateRange(l, utc, midnight, nextMorning, flags));
+
+ // But the same reasoning applies for that day.
+ long nextMidnight = 2 * DAY;
+ assertEquals("Thursday, January 1 – Friday, January 2", formatDateRange(l, utc, midnight, nextMidnight, flags));
+ }
+
+ public void test10560853_for_single_day_events() throws Exception {
+ Locale l = Locale.US;
+ TimeZone utc = TimeZone.getTimeZone("UTC");
+
+ int flags = FORMAT_SHOW_TIME | FORMAT_24HOUR | FORMAT_SHOW_DATE;
+
+ assertEquals("January 1, 22:00–00:00", formatDateRange(l, utc, 22 * HOUR, 24 * HOUR, flags));
+ assertEquals("January 1, 22:00 – January 2, 00:30", formatDateRange(l, utc, 22 * HOUR, 24 * HOUR + 30 * MINUTE, flags));
}
}
diff --git a/luni/src/test/java/libcore/java/text/OldBidiTest.java b/luni/src/test/java/libcore/java/text/OldBidiTest.java
index 2e5fd21..45fe258 100644
--- a/luni/src/test/java/libcore/java/text/OldBidiTest.java
+++ b/luni/src/test/java/libcore/java/text/OldBidiTest.java
@@ -22,11 +22,9 @@ import junit.framework.TestCase;
public class OldBidiTest extends TestCase {
- Bidi bd;
-
public void testToString() {
try {
- bd = new Bidi("bidi", 173);
+ Bidi bd = new Bidi("bidi", 173);
assertNotNull("Bidi representation is null", bd.toString());
} catch (Exception e) {
fail("Unexpected exception " + e.toString());
@@ -41,7 +39,7 @@ public class OldBidiTest extends TestCase {
}
public void testGetRunLevelLInt() {
- bd = new Bidi("text", Bidi.DIRECTION_LEFT_TO_RIGHT);
+ Bidi bd = new Bidi("text", Bidi.DIRECTION_LEFT_TO_RIGHT);
try {
assertEquals(0, bd.getRunLevel(0));
assertEquals(0, bd.getRunLevel(bd.getRunCount()));
@@ -65,25 +63,11 @@ public class OldBidiTest extends TestCase {
}
public void testGetRunStart() {
- bd = new Bidi(new char[] { 's', 's', 's' }, 0, new byte[] { (byte) -7,
+ Bidi bd = new Bidi(new char[] { 's', 's', 's' }, 0, new byte[] { (byte) -7,
(byte) -2, (byte) 3 }, 0, 3,
Bidi.DIRECTION_DEFAULT_LEFT_TO_RIGHT);
assertEquals(0, bd.getRunStart(0));
assertEquals(1, bd.getRunStart(1));
assertEquals(2, bd.getRunStart(2));
-
- String LTR = "\u0061\u0062";
- String RTL = "\u05DC\u05DD";
- String newLine = "\n";
- String defText = LTR + newLine + RTL + LTR + RTL;
-
- int[][] expectedRuns = { { 0, 3 }, { 3, 5 }, { 5, 7 }, { 7, 9 }, };
-
- Bidi bi = new Bidi(defText, 0);
-
- final int count = bi.getRunCount();
- for (int i = 0; i < count; i++) {
- assertEquals(expectedRuns[i][0], bi.getRunStart(i));
- }
}
}
diff --git a/luni/src/test/java/libcore/java/text/OldCollationElementIteratorTest.java b/luni/src/test/java/libcore/java/text/OldCollationElementIteratorTest.java
deleted file mode 100644
index 9e98a56..0000000
--- a/luni/src/test/java/libcore/java/text/OldCollationElementIteratorTest.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package libcore.java.text;
-
-import java.text.CollationElementIterator;
-import java.text.Collator;
-import java.text.RuleBasedCollator;
-import java.util.Locale;
-import junit.framework.TestCase;
-
-public class OldCollationElementIteratorTest extends TestCase {
-
- public void testPrevious() {
- RuleBasedCollator coll = (RuleBasedCollator) Collator.getInstance(Locale.US);
- String text = "abc";
- CollationElementIterator iterator = coll
- .getCollationElementIterator(text);
- int[] orders = new int[text.length()];
- int order = iterator.next();
- int i = 0;
- while (order != CollationElementIterator.NULLORDER) {
- orders[i++] = order;
- order = iterator.next();
- }
-
- int offset = iterator.getOffset();
- assertEquals(text.length(), offset);
- order = iterator.previous();
-
- while (order != CollationElementIterator.NULLORDER) {
- assertEquals(orders[--i], order);
- order = iterator.previous();
- }
-
- assertEquals(0, iterator.getOffset());
- }
-}
diff --git a/luni/src/test/java/libcore/java/text/OldDecimalFormatTest.java b/luni/src/test/java/libcore/java/text/OldDecimalFormatTest.java
deleted file mode 100644
index f3e016e..0000000
--- a/luni/src/test/java/libcore/java/text/OldDecimalFormatTest.java
+++ /dev/null
@@ -1,1007 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package libcore.java.text;
-
-import java.math.BigDecimal;
-import java.math.BigInteger;
-import java.text.AttributedCharacterIterator;
-import java.text.DecimalFormat;
-import java.text.DecimalFormatSymbols;
-import java.text.FieldPosition;
-import java.text.NumberFormat;
-import java.text.ParseException;
-import java.text.ParsePosition;
-import java.util.BitSet;
-import java.util.Locale;
-import junit.framework.TestCase;
-import tests.support.Support_DecimalFormat;
-
-public class OldDecimalFormatTest extends TestCase {
-
- public void test_formatToCharacterIterator() throws Exception {
- AttributedCharacterIterator iterator;
- int[] runStarts;
- int[] runLimits;
- String result;
- char current;
-
- // For BigDecimal with multiplier test.
- DecimalFormat df = new DecimalFormat();
- df.setMultiplier(10);
- iterator = df.formatToCharacterIterator(new BigDecimal("12345678901234567890"));
- result = "123,456,789,012,345,678,900";
- current = iterator.current();
- for (int i = 0; i < result.length(); i++) {
- assertEquals("wrong char @" + i, result.charAt(i), current);
- current = iterator.next();
- }
-
- // For BigDecimal with multiplier test.
- df = new DecimalFormat();
- df.setMultiplier(-1);
- df.setMaximumFractionDigits(20);
- iterator = df.formatToCharacterIterator(new BigDecimal("1.23456789012345678901"));
- result = "-1.23456789012345678901";
- current = iterator.current();
- for (int i = 0; i < result.length(); i++) {
- assertEquals("wrong char @" + i, result.charAt(i), current);
- current = iterator.next();
- }
-
- iterator = new DecimalFormat()
- .formatToCharacterIterator(new BigDecimal("1.23456789E1234"));
- runStarts = new int[] {0, 0, 2, 3, 3, 3, 6, 7, 7, 7, 10, 11, 11, 11, 14};
- runLimits = new int[] {2, 2, 3, 6, 6, 6, 7, 10, 10, 10, 11, 14, 14, 14, 15};
- result = "12,345,678,900,"; // 000,000,000,000....
- current = iterator.current();
- for (int i = 0; i < runStarts.length; i++) {
- assertEquals("wrong start @" + i, runStarts[i], iterator.getRunStart());
- assertEquals("wrong limit @" + i, runLimits[i], iterator.getRunLimit());
- assertEquals("wrong char @" + i, result.charAt(i), current);
- current = iterator.next();
- }
- assertEquals(0, iterator.getBeginIndex());
- assertEquals(1646, iterator.getEndIndex());
-
- iterator = new DecimalFormat()
- .formatToCharacterIterator(new BigDecimal("1.23456789E301"));
- runStarts = new int[] {0, 0, 2, 3, 3, 3, 6, 7, 7, 7, 10, 11, 11, 11, 14};
- runLimits = new int[] {2, 2, 3, 6, 6, 6, 7, 10, 10, 10, 11, 14, 14, 14, 15};
- result = "12,345,678,900,"; // 000,000,000,000....
- current = iterator.current();
- for (int i = 0; i < runStarts.length; i++) {
- assertEquals("wrong start @" + i, runStarts[i], iterator.getRunStart());
- assertEquals("wrong limit @" + i, runLimits[i], iterator.getRunLimit());
- assertEquals("wrong char @" + i, result.charAt(i), current);
- current = iterator.next();
- }
- assertEquals(0, iterator.getBeginIndex());
- assertEquals(402, iterator.getEndIndex());
-
- iterator = new DecimalFormat()
- .formatToCharacterIterator(new BigDecimal("1.2345678E4"));
- runStarts = new int[] {0, 0, 2, 3, 3, 3, 6, 7, 7, 7};
- runLimits = new int[] {2, 2, 3, 6, 6, 6, 7, 10, 10, 10};
- result = "12,345.678";
- current = iterator.current();
- for (int i = 0; i < runStarts.length; i++) {
- assertEquals("wrong start @" + i, runStarts[i], iterator.getRunStart());
- assertEquals("wrong limit @" + i, runLimits[i], iterator.getRunLimit());
- assertEquals("wrong char @" + i, result.charAt(i), current);
- current = iterator.next();
- }
- assertEquals(0, iterator.getBeginIndex());
- assertEquals(10, iterator.getEndIndex());
-
- iterator = new DecimalFormat()
- .formatToCharacterIterator(new BigInteger("123456789"));
- runStarts = new int[] {0, 0, 0, 3, 4, 4, 4, 7, 8, 8, 8};
- runLimits = new int[] {3, 3, 3, 4, 7, 7, 7, 8, 11, 11, 11};
- result = "123,456,789";
- current = iterator.current();
- for (int i = 0; i < runStarts.length; i++) {
- assertEquals("wrong start @" + i, runStarts[i], iterator.getRunStart());
- assertEquals("wrong limit @" + i, runLimits[i], iterator.getRunLimit());
- assertEquals("wrong char @" + i, result.charAt(i), current);
- current = iterator.next();
- }
- assertEquals(0, iterator.getBeginIndex());
- assertEquals(11, iterator.getEndIndex());
- }
-
- /*
- * Test the getter and setter of parseBigDecimal and parseIntegerOnly and
- * test the default value of them.
- */
- public void test_isParseBigDecimalLjava_lang_Boolean_isParseIntegerOnlyLjava_lang_Boolean() {
-
- // parseBigDecimal default to false
- DecimalFormat form = (DecimalFormat) DecimalFormat
- .getInstance(Locale.US);
- assertFalse(form.isParseBigDecimal());
- form.setParseBigDecimal(true);
- assertTrue(form.isParseBigDecimal());
-
- try {
- Number result = form.parse("123.123");
- assertEquals(new BigDecimal("123.123"), result);
- } catch (ParseException e) {
- fail("ParseException was thrown.");
- }
-
- form.setParseBigDecimal(false);
- assertFalse(form.isParseBigDecimal());
-
- try {
- Number result = form.parse("123.123");
- assertFalse(result instanceof BigDecimal);
- } catch (ParseException e) {
- fail("ParseException was thrown.");
- }
-
- // parseIntegerOnly default to false
- assertFalse(form.isParseIntegerOnly());
- }
-
- public void test_isParseIntegerOnly() {
-
- DecimalFormat format = new DecimalFormat();
- assertFalse("Default value of isParseIntegerOnly is true",
- format.isParseIntegerOnly());
-
- format.setParseIntegerOnly(true);
- assertTrue(format.isParseIntegerOnly());
- try {
- Number result = format.parse("123.123");
- assertEquals(new Long("123"), result);
- } catch (ParseException e) {
- fail("ParseException was thrown.");
- }
-
- format.setParseIntegerOnly(false);
- assertFalse(format.isParseIntegerOnly());
- try {
- Number result = format.parse("123.123");
- assertEquals(new Double("123.123"), result);
- } catch (ParseException e) {
- fail("ParseException was thrown.");
- }
- }
-
- public void test_isGroupingUsed() {
- String [] patterns = {"####.##", "######.######", "000000.000000",
- "######.000000", "000000.######", " ###.###", "$#####.######",
- "$$####.######"};
-
- for(String pattern:patterns) {
- DecimalFormat format = new DecimalFormat(pattern);
- assertFalse(format.isGroupingUsed());
- }
-
- DecimalFormat format = new DecimalFormat("###,####");
- assertTrue(format.isGroupingUsed());
- }
-
- // Test the type of the returned object
- public void test_parseLjava_lang_String_Ljava_text_ParsePosition() {
- DecimalFormat form = (DecimalFormat) DecimalFormat.getInstance(Locale.US);
- form.setParseIntegerOnly(true);
- form.setParseBigDecimal(true);
-
- final String doubleMax2 = "359,538,626,972,463,141,629,054,847,463,408,"
- + "713,596,141,135,051,689,993,197,834,953,606,314,521,560,057,077,"
- + "521,179,117,265,533,756,343,080,917,907,028,764,928,468,642,653,"
- + "778,928,365,536,935,093,407,075,033,972,099,821,153,102,564,152,"
- + "490,980,180,778,657,888,151,737,016,910,267,884,609,166,473,806,"
- + "445,896,331,617,118,664,246,696,549,595,652,408,289,446,337,476,"
- + "354,361,838,599,762,500,808,052,368,249,716,736";
- Number number = form.parse(doubleMax2, new ParsePosition(0));
- assertTrue(number instanceof BigDecimal);
- BigDecimal result = (BigDecimal)number;
- assertEquals(new BigDecimal(Double.MAX_VALUE).add(new BigDecimal(
- Double.MAX_VALUE)), result);
- }
-
- // AndroidOnly: Difference to RI
- public void test_getMaximumIntegerDigits_AndroidOnly() {
- final int maxIntDigit = 309;
-
- // When use default locale, in this case zh_CN
- // the returned instance of NumberFormat is a DecimalFormat
- DecimalFormat form = new DecimalFormat("00.###E0");
- NumberFormat nform = DecimalFormat.getInstance(Locale.US);
- nform = DecimalFormat.getInstance(Locale.US);
- form = null;
- if (nform instanceof DecimalFormat) {
- form = (DecimalFormat) nform;
- }
- // getMaximumIntegerDigits from NumberFormat default to 309
- // getMaximumIntegerDigits from DecimalFormat default to 309
- // the following 2 assertions will fail on RI implementation, since the
- // implementation of ICU and RI are not identical. RI does not give
- // DecimalFormat an initial bound about its maximumIntegerDigits
- // (default to Integer.MAX_VALUE: 2147483647 )
- assertEquals(maxIntDigit, nform.getMaximumIntegerDigits());
- assertEquals(maxIntDigit, form.getMaximumIntegerDigits());
- }
-
- // AndroidOnly: second 0 needs to be quoted in icu.
- // (quoting special characters in prefix and suffix necessary)
- public void test_getMaximumIntegerDigits2() {
- // regression test for HARMONY-878
- assertTrue(new DecimalFormat("0\t'0'").getMaximumIntegerDigits() > 0);
- }
-
- public void test_setPositivePrefixLjava_lang_String() {
- DecimalFormat format = new DecimalFormat();
- assertEquals("", format.getPositivePrefix());
-
- format.setPositivePrefix("PosPrf");
- assertEquals("PosPrf", format.getPositivePrefix());
- try {
- assertTrue(format.parse("PosPrf123.45").doubleValue() == 123.45);
- } catch(java.text.ParseException pe) {
- fail("ParseException was thrown.");
- }
-
- format.setPositivePrefix("");
- assertEquals("", format.getPositivePrefix());
-
- format.setPositivePrefix(null);
- assertNull(format.getPositivePrefix());
- }
- public void test_setPositiveSuffixLjava_lang_String() {
- DecimalFormat format = new DecimalFormat();
- assertEquals("", format.getPositiveSuffix());
-
- format.setPositiveSuffix("PosSfx");
- assertEquals("PosSfx", format.getPositiveSuffix());
- try {
- assertTrue(format.parse("123.45PosSfx").doubleValue() == 123.45);
- } catch(java.text.ParseException pe) {
- fail("ParseException was thrown.");
- }
-
- format.setPositiveSuffix("");
- assertEquals("", format.getPositiveSuffix());
-
- format.setPositiveSuffix(null);
- assertNull(format.getPositiveSuffix());
- }
- public void test_setNegativePrefixLjava_lang_String() {
- DecimalFormat format = new DecimalFormat();
- assertEquals("-", format.getNegativePrefix());
-
- format.setNegativePrefix("NegPrf");
- assertEquals("NegPrf", format.getNegativePrefix());
- try {
- assertTrue(format.parse("NegPrf123.45").doubleValue() == -123.45);
- } catch(java.text.ParseException pe) {
- fail("ParseException was thrown.");
- }
- format.setNegativePrefix("");
- assertEquals("", format.getNegativePrefix());
-
- format.setNegativePrefix(null);
- assertNull(format.getNegativePrefix());
- }
- public void test_setNegativeSuffixLjava_lang_String() {
- DecimalFormat format = new DecimalFormat();
- assertEquals("", format.getNegativeSuffix());
-
- format.setNegativeSuffix("NegSfx");
- assertEquals("NegSfx", format.getNegativeSuffix());
- try {
- assertTrue(format.parse("123.45NegPfx").doubleValue() == 123.45);
- } catch(java.text.ParseException pe) {
- fail("ParseException was thrown.");
- }
-
- format.setNegativeSuffix("");
- assertEquals("", format.getNegativeSuffix());
-
- format.setNegativeSuffix(null);
- assertNull(format.getNegativeSuffix());
- }
-
- public void test_toLocalizedPattern() {
- DecimalFormat format = new DecimalFormat();
- format.setDecimalFormatSymbols(new DecimalFormatSymbols(Locale.US));
- try {
- format.applyLocalizedPattern("#.#");
- assertEquals("Wrong pattern 1", "#0.#", format.toLocalizedPattern());
- format.applyLocalizedPattern("#.");
- assertEquals("Wrong pattern 2", "#0.", format.toLocalizedPattern());
- format.applyLocalizedPattern("#");
- assertEquals("Wrong pattern 3", "#", format.toLocalizedPattern());
- format.applyLocalizedPattern(".#");
- assertEquals("Wrong pattern 4", "#.0", format.toLocalizedPattern());
- } catch (Exception e) {
- fail("Unexpected exception " + e.toString());
- }
- }
-
- public void test_toPattern() {
- DecimalFormat format = new DecimalFormat();
- try {
- format.applyPattern("#.#");
- assertEquals("Wrong pattern 1", "#0.#", format.toPattern());
- format.applyPattern("#.");
- assertEquals("Wrong pattern 2", "#0.", format.toPattern());
- format.applyPattern("#");
- assertEquals("Wrong pattern 3", "#", format.toPattern());
- format.applyPattern(".#");
- assertEquals("Wrong pattern 4", "#.0", format.toPattern());
- } catch (Exception e) {
- fail("Unexpected exception " + e.toString());
- }
- }
- public void test_setGroupingUse() {
- DecimalFormat format = new DecimalFormat();
-
- StringBuffer buf = new StringBuffer();
- format.setGroupingUsed(false);
- format.format(new Long(1970), buf, new FieldPosition(0));
- assertEquals("1970", buf.toString());
- assertFalse(format.isGroupingUsed());
- format.format(new Long(1970), buf, new FieldPosition(0));
- assertEquals("19701970", buf.toString());
- assertFalse(format.isGroupingUsed());
-
- format.setGroupingUsed(true);
- format.format(new Long(1970), buf, new FieldPosition(0));
- assertEquals("197019701,970", buf.toString());
- assertTrue(format.isGroupingUsed());
- }
-
- public void test_Constructor() {
- // Test for method java.text.DecimalFormat()
- // the constructor form that specifies a pattern is equal to the form
- // constructed with no pattern and applying that pattern using the
- // applyPattern call
- try {
- DecimalFormat format1 = new DecimalFormat();
- format1.applyPattern("'$'1000.0000");
- DecimalFormat format2 = new DecimalFormat();
- format2.applyPattern("'$'1000.0000");
- assertTrue(
- "Constructed format did not match applied format object",
- format2.equals(format1));
- DecimalFormat format3 = new DecimalFormat("'$'1000.0000");
- assertTrue(
- "Constructed format did not match applied format object",
- format3.equals(format1));
- DecimalFormat format4 = new DecimalFormat("'$'8000.0000");
- assertTrue(
- "Constructed format did not match applied format object",
- !format4.equals(format1));
- } catch (Exception e) {
- fail("Unexpected exception " + e.toString());
- }
- }
-
- public void test_ConstructorLjava_lang_String() {
- // Test for method java.text.DecimalFormat(java.lang.String)
- // the constructor form that specifies a pattern is equal to the form
- // constructed with no pattern and applying that pattern using the
- // applyPattern call
- DecimalFormat format = new DecimalFormat("'$'0000.0000");
- DecimalFormat format1 = new DecimalFormat();
- format1.applyPattern("'$'0000.0000");
- assertTrue("Constructed format did not match applied format object",
- format.equals(format1));
-
- String [] patterns = {"####.##", "######.######", "000000.000000",
- "######.000000", "000000.######", " ###.###", "$#####.######",
- "$$####.######", "%#,##,###,####", "#,##0.00;(#,##0.00)"};
-
- for(String str:patterns) {
- new DecimalFormat(str);
- }
-
- try {
- new DecimalFormat(null);
- fail("NullPointerException wasn't thrown.");
- } catch(NullPointerException npe){
- //expected
- }
-
- String [] incPatterns = {"%#,##,###,####'", "#.##0.00"};
- for(String str:incPatterns) {
- try {
- new DecimalFormat(str);
- fail("IllegalArgumentException wasn't thrown for pattern: " + str);
- } catch(IllegalArgumentException iae){
- //expected
- }
- }
- }
-
- /**
- * Case 1: Try to construct object using correct pattern and fromat symbols.
- * Case 2: Try to construct object using null arguments.
- * Case 3: Try to construct object using incorrect pattern.
- */
- public void test_ConstructorLjava_lang_StringLjava_text_DecimalFormatSymbols() {
- try {
- // case 1: Try to construct object using correct pattern and fromat
- // symbols.
- DecimalFormatSymbols dfs = new DecimalFormatSymbols(Locale.CANADA);
- DecimalFormat format1 = new DecimalFormat("'$'1000.0000", dfs);
- DecimalFormat format2 = new DecimalFormat();
- format2.applyPattern("'$'1000.0000");
- format2.setDecimalFormatSymbols(dfs);
- assertTrue(
- "Constructed format did not match applied format object",
- format2.equals(format1));
- assertTrue(
- "Constructed format did not match applied format object",
- !format1.equals(new DecimalFormat("'$'1000.0000",
- new DecimalFormatSymbols(Locale.CHINA))));
-
- // case 2: Try to construct object using null arguments.
- try {
- new DecimalFormat("'$'1000.0000", (DecimalFormatSymbols) null);
- fail("Expected NullPointerException was not thrown");
- } catch (NullPointerException e) {
- // expected
- }
- try {
- new DecimalFormat(null, new DecimalFormatSymbols());
- fail("Expected NullPointerException was not thrown");
- } catch (NullPointerException e) {
- // expected
- }
- try {
- new DecimalFormat(null, (DecimalFormatSymbols) null);
- fail("Expected NullPointerException was not thrown");
- } catch (NullPointerException e) {
- // expected
- }
-
- // case 3: Try to construct object using incorrect pattern.
- try {
- new DecimalFormat("$'", new DecimalFormatSymbols());
- fail("Expected IllegalArgumentException was not thrown");
- } catch (IllegalArgumentException e) {
- // expected
- }
- } catch (Exception e) {
- fail("Unexpected exception " + e.toString());
- }
- }
-
- /**
- * Case 1: Try to apply correct variants of pattern.
- * Case 2: Try to apply malformed patten. Case 3: Try to apply null pattern.
- */
- public void test_applyLocalizedPatternLjava_lang_String() {
- DecimalFormat format = new DecimalFormat();
- try {
- // case 1: Try to apply correct variants of pattern.
- format.applyLocalizedPattern("#.#");
- assertEquals("Wrong pattern 1", "#0.#", format.toLocalizedPattern());
- format.applyLocalizedPattern("#.");
- assertEquals("Wrong pattern 2", "#0.", format.toLocalizedPattern());
- format.applyLocalizedPattern("#");
- assertEquals("Wrong pattern 3", "#", format.toLocalizedPattern());
- format.applyLocalizedPattern(".#");
- assertEquals("Wrong pattern 4", "#.0", format.toLocalizedPattern());
-
- // case 2: Try to apply malformed patten.
- try {
- format.applyLocalizedPattern("'#,#:#0.0#;(#)");
- fail("Expected IllegalArgumentException was not thrown");
- } catch (IllegalArgumentException e) {
- // expected
- }
-
- // case 3: Try to apply null patern.
- try {
- format.applyLocalizedPattern((String) null);
- fail("Expected NullPointerException was not thrown");
- } catch (NullPointerException e) {
- // expected
- }
- } catch (Exception e) {
- fail("Unexpected exception " + e.toString());
- }
- }
-
- public void test_applyPatternLjava_lang_String() {
- DecimalFormat format = new DecimalFormat("#.#");
- assertEquals("Wrong pattern 1", "#0.#", format.toPattern());
- format = new DecimalFormat("#.");
- assertEquals("Wrong pattern 2", "#0.", format.toPattern());
- format = new DecimalFormat("#");
- assertEquals("Wrong pattern 3", "#", format.toPattern());
- format = new DecimalFormat(".#");
- assertEquals("Wrong pattern 4", "#.0", format.toPattern());
-
- DecimalFormat decFormat = new DecimalFormat("#.#");
-
- try {
- decFormat.applyPattern(null);
- fail("NullPointerException was not thrown.");
- } catch(NullPointerException npe) {
- //expected
- }
-
- String [] incPatterns = {"%#,##,###,####'", "#.##0.00"};
- for(String str:incPatterns) {
- try {
- decFormat.applyPattern(str);
- fail("IllegalArgumentException was not thrown for pattern: " +
- str);
- } catch(IllegalArgumentException iae) {
- //expected
- }
- }
- }
-
- // AndroidOnly: icu supports 2 grouping sizes
- public void test_applyPatternLjava_lang_String2() {
- DecimalFormat decFormat = new DecimalFormat("#.#");
- String [] patterns = {"####.##", "######.######", "000000.000000",
- "######.000000", "000000.######", " ###.###", "$#####.######",
- "$$####.######", "%#,##,###,####", "#,##0.00;(#,##0.00)",
- "##.##-E"};
-
- String [] expResult = {"#0.##", "#0.######", "#000000.000000",
- "#.000000", "#000000.######", " #0.###", "$#0.######",
- "$$#0.######",
- "%#,###,####", // icu only. icu supports two grouping sizes
- "#,##0.00;(#,##0.00)",
- "#0.##-'E'"}; // icu only. E in the suffix does not need to be
- // quoted. This is done automatically.
-
- for (int i = 0; i < patterns.length; i++) {
- decFormat.applyPattern(patterns[i]);
- String result = decFormat.toPattern();
- assertEquals("Failed to apply following pattern: " + patterns[i] +
- " expected: " + expResult[i] + " returned: " + result,
- expResult[i], result);
- }
- }
-
- public void test_clone() {
- DecimalFormat format = (DecimalFormat) DecimalFormat
- .getInstance(Locale.US);
- DecimalFormat cloned = (DecimalFormat) format.clone();
- assertEquals(cloned.getDecimalFormatSymbols(), format
- .getDecimalFormatSymbols());
-
- format = new DecimalFormat("'$'0000.0000");
- DecimalFormat format1 = (DecimalFormat) (format.clone());
- // make sure the objects are equal
- assertTrue("Object's clone isn't equal!", format.equals(format1));
- // change the content of the clone and make sure it's not equal anymore
- // verifies that it's data is now distinct from the original
- format1.applyPattern("'$'0000.####");
- assertTrue("Object's changed clone should not be equal!", !format
- .equals(format1));
- }
-
- private void compare(String testName, String format, String expected) {
- assertTrue(testName + " got: " + format + " expected: " + expected,
- format.equals(expected));
- }
-
- private boolean compare(int count, String format, String expected) {
- boolean result = format.equals(expected);
- if (!result)
- System.out.println("Failure test: " + count + " got: " + format
- + " expected: " + expected);
- return result;
- }
-
- public void test_formatDLjava_lang_StringBufferLjava_text_FieldPosition() {
- new Support_DecimalFormat(
- "test_formatDLjava_lang_StringBufferLjava_text_FieldPosition")
- .t_format_with_FieldPosition();
-
- int failCount = 0;
- BitSet failures = new BitSet();
-
- final DecimalFormatSymbols dfs = new DecimalFormatSymbols(Locale.US);
-
- DecimalFormat df = new DecimalFormat("00.0#E0", dfs);
- compare("00.0#E0: 0.0", df.format(0.0), "00.0E0");
- compare("00.0#E0: 1.0", df.format(1.0), "10.0E-1");
- compare("00.0#E0: 12.0", df.format(12.0), "12.0E0");
- compare("00.0#E0: 123.0", df.format(123.0), "12.3E1");
- compare("00.0#E0: 1234.0", df.format(1234.0), "12.34E2");
- compare("00.0#E0: 12346.0", df.format(12346.0), "12.35E3");
- compare("00.0#E0: 99999.0", df.format(99999.0), "10.0E4");
- compare("00.0#E0: 1.2", df.format(1.2), "12.0E-1");
- compare("00.0#E0: 12.3", df.format(12.3), "12.3E0");
- compare("00.0#E0: 123.4", df.format(123.4), "12.34E1");
- compare("00.0#E0: 1234.6", df.format(1234.6), "12.35E2");
- compare("00.0#E0: 9999.9", df.format(9999.9), "10.0E3");
- compare("00.0#E0: 0.1", df.format(0.1), "10.0E-2");
- compare("00.0#E0: 0.12", df.format(0.12), "12.0E-2");
- compare("00.0#E0: 0.123", df.format(0.123), "12.3E-2");
- compare("00.0#E0: 0.1234", df.format(0.1234), "12.34E-2");
- compare("00.0#E0: 0.12346", df.format(0.12346), "12.35E-2");
- compare("00.0#E0: 0.99999", df.format(0.99999), "10.0E-1");
- compare("00.0#E0: -0.0", df.format(-0.0), "-00.0E0");
- compare("00.0#E0: -1.0", df.format(-1.0), "-10.0E-1");
- compare("00.0#E0: -12.0", df.format(-12.0), "-12.0E0");
- compare("00.0#E0: -123.0", df.format(-123.0), "-12.3E1");
- compare("00.0#E0: -1234.0", df.format(-1234.0), "-12.34E2");
- compare("00.0#E0: -12346.0", df.format(-12346.0), "-12.35E3");
- compare("00.0#E0: -99999.0", df.format(-99999.0), "-10.0E4");
-
- df = new DecimalFormat("##0.0E0", dfs);
- compare("##0.0E0: -0.0", df.format(-0.0), "-0.0E0");
- compare("##0.0E0: 0.0", df.format(0.0), "0.0E0");
- compare("##0.0E0: 1.0", df.format(1.0), "1.0E0");
- compare("##0.0E0: 12.0", df.format(12.0), "12E0");
- compare("##0.0E0: 123.0", df.format(123.0), "123E0"); // Android fails, here!
- compare("##0.0E0: 1234.0", df.format(1234.0), "1.234E3");
- compare("##0.0E0: 12346.0", df.format(12346.0), "12.35E3");
- // Fails in JDK 1.2.2
- if (!compare(failCount, df.format(99999.0), "100E3"))
- failures.set(failCount);
- failCount++;
- compare("##0.0E0: 999999.0", df.format(999999.0), "1.0E6");
-
- df = new DecimalFormat("#00.0##E0", dfs);
- compare("#00.0##E0: 0.1", df.format(0.1), "100E-3");
- compare("#00.0##E0: 0.12", df.format(0.12), "120E-3");
- compare("#00.0##E0: 0.123", df.format(0.123), "123E-3");
- compare("#00.0##E0: 0.1234", df.format(0.1234), "123.4E-3");
- compare("#00.0##E0: 0.1234567", df.format(0.1234567), "123.457E-3");
- compare("#00.0##E0: 0.01", df.format(0.01), "10.0E-3");
- compare("#00.0##E0: 0.012", df.format(0.012), "12.0E-3");
- compare("#00.0##E0: 0.0123", df.format(0.0123), "12.3E-3");
- compare("#00.0##E0: 0.01234", df.format(0.01234), "12.34E-3");
- compare("#00.0##E0: 0.01234567", df.format(0.01234567), "12.3457E-3");
- compare("#00.0##E0: 0.001", df.format(0.001), "1.00E-3");
- compare("#00.0##E0: 0.0012", df.format(0.0012), "1.20E-3");
- compare("#00.0##E0: 0.00123", df.format(0.00123), "1.23E-3");
- compare("#00.0##E0: 0.001234", df.format(0.001234), "1.234E-3");
- compare("#00.0##E0: 0.001234567", df.format(0.001234567), "1.23457E-3");
- compare("#00.0##E0: 0.0001", df.format(0.0001), "100E-6");
- compare("#00.0##E0: 0.00012", df.format(0.00012), "120E-6");
- compare("#00.0##E0: 0.000123", df.format(0.000123), "123E-6");
- compare("#00.0##E0: 0.0001234", df.format(0.0001234), "123.4E-6");
- compare("#00.0##E0: 0.0001234567", df.format(0.0001234567),
- "123.457E-6");
-
- // Fails in JDK 1.2.2
- if (!compare(failCount, df.format(0.0), "0.00E0"))
- failures.set(failCount);
- failCount++;
- compare("#00.0##E0: 1.0", df.format(1.0), "1.00E0");
- compare("#00.0##E0: 12.0", df.format(12.0), "12.0E0");
- compare("#00.0##E0: 123.0", df.format(123.0), "123E0");
- compare("#00.0##E0: 1234.0", df.format(1234.0), "1.234E3");
- compare("#00.0##E0: 12345.0", df.format(12345.0), "12.345E3");
- compare("#00.0##E0: 123456.0", df.format(123456.0), "123.456E3");
- compare("#00.0##E0: 1234567.0", df.format(1234567.0), "1.23457E6");
- compare("#00.0##E0: 12345678.0", df.format(12345678.0), "12.3457E6");
- compare("#00.0##E0: 99999999.0", df.format(99999999.0), "100E6");
-
- df = new DecimalFormat("#.0E0", dfs);
- compare("#.0E0: -0.0", df.format(-0.0), "-.0E0");
- compare("#.0E0: 0.0", df.format(0.0), ".0E0");
- compare("#.0E0: 1.0", df.format(1.0), ".1E1");
- compare("#.0E0: 12.0", df.format(12.0), ".12E2");
- compare("#.0E0: 123.0", df.format(123.0), ".12E3");
- compare("#.0E0: 1234.0", df.format(1234.0), ".12E4");
- compare("#.0E0: 9999.0", df.format(9999.0), ".1E5");
-
- df = new DecimalFormat("0.#E0", dfs);
- compare("0.#E0: -0.0", df.format(-0.0), "-0E0");
- compare("0.#E0: 0.0", df.format(0.0), "0E0");
- compare("0.#E0: 1.0", df.format(1.0), "1E0");
- compare("0.#E0: 12.0", df.format(12.0), "1.2E1");
- compare("0.#E0: 123.0", df.format(123.0), "1.2E2");
- compare("0.#E0: 1234.0", df.format(1234.0), "1.2E3");
- compare("0.#E0: 9999.0", df.format(9999.0), "1E4");
-
- df = new DecimalFormat(".0E0", dfs);
- compare(".0E0: -0.0", df.format(-0.0), "-.0E0");
- compare(".0E0: 0.0", df.format(0.0), ".0E0");
- compare(".0E0: 1.0", df.format(1.0), ".1E1");
- compare(".0E0: 12.0", df.format(12.0), ".1E2");
- compare(".0E0: 123.0", df.format(123.0), ".1E3");
- compare(".0E0: 1234.0", df.format(1234.0), ".1E4");
- compare(".0E0: 9999.0", df.format(9999.0), ".1E5");
-
- df = new DecimalFormat("0.E0", dfs);
- // Fails in JDK 1.2.2
- if (!compare(failCount, df.format(0.0), "0.E0"))
- failures.set(failCount);
- failCount++;
- if (!compare(failCount, df.format(1.0), "1.E0"))
- failures.set(failCount);
- failCount++;
- if (!compare(failCount, df.format(12.0), "1.E1"))
- failures.set(failCount);
- failCount++;
- if (!compare(failCount, df.format(123.0), "1.E2"))
- failures.set(failCount);
- failCount++;
- if (!compare(failCount, df.format(1234.0), "1.E3"))
- failures.set(failCount);
- failCount++;
- if (!compare(failCount, df.format(9999.0), "1.E4"))
- failures.set(failCount);
- failCount++;
-
- df = new DecimalFormat("##0.00#E0", dfs);
- compare("##0.00#E0: 0.1", df.format(0.1), "100E-3");
- compare("##0.00#E0: 0.1234567", df.format(0.1234567), "123.457E-3");
- compare("##0.00#E0: 0.9999999", df.format(0.9999999), "1.00E0");
- compare("##0.00#E0: 0.01", df.format(0.01), "10.0E-3");
- compare("##0.00#E0: 0.01234567", df.format(0.01234567), "12.3457E-3");
- compare("##0.00#E0: 0.09999999", df.format(0.09999999), "100E-3");
- compare("##0.00#E0: 0.001", df.format(0.001), "1.00E-3");
- compare("##0.00#E0: 0.001234567", df.format(0.001234567), "1.23457E-3");
- compare("##0.00#E0: 0.009999999", df.format(0.009999999), "10.0E-3");
- compare("##0.00#E0: 0.0001", df.format(0.0001), "100E-6");
- compare("##0.00#E0: 0.0001234567", df.format(0.0001234567),
- "123.457E-6");
- compare("##0.00#E0: 0.0009999999", df.format(0.0009999999), "1.00E-3");
-
- df = new DecimalFormat("###0.00#E0", dfs);
- compare("###0.00#E0: 0.1", df.format(0.1), "1000E-4");
- compare("###0.00#E0: 0.12345678", df.format(0.12345678), "1234.568E-4");
- compare("###0.00#E0: 0.99999999", df.format(0.99999999), "1.00E0");
- compare("###0.00#E0: 0.01", df.format(0.01), "100E-4");
- compare("###0.00#E0: 0.012345678", df.format(0.012345678),
- "123.4568E-4");
- compare("###0.00#E0: 0.099999999", df.format(0.099999999), "1000E-4");
- compare("###0.00#E0: 0.001", df.format(0.001), "10.0E-4");
- compare("###0.00#E0: 0.0012345678", df.format(0.0012345678),
- "12.34568E-4");
- compare("###0.00#E0: 0.0099999999", df.format(0.0099999999), "100E-4");
- compare("###0.00#E0: 0.0001", df.format(0.0001), "1.00E-4");
- compare("###0.00#E0: 0.00012345678", df.format(0.00012345678),
- "1.234568E-4");
- compare("###0.00#E0: 0.00099999999", df.format(0.00099999999),
- "10.0E-4");
- // Fails in JDK 1.2.2
- if (!compare(failCount, df.format(0.00001), "1000E-8"))
- failures.set(failCount);
- failCount++;
- compare("###0.00#E0: 0.000012345678", df.format(0.000012345678),
- "1234.568E-8");
- compare("###0.00#E0: 0.000099999999", df.format(0.000099999999),
- "1.00E-4");
-
- df = new DecimalFormat("###0.0#E0", dfs);
- compare("###0.0#E0: 0.1", df.format(0.1), "1000E-4");
- compare("###0.0#E0: 0.1234567", df.format(0.1234567), "1234.57E-4");
- compare("###0.0#E0: 0.9999999", df.format(0.9999999), "1.0E0");
- // Fails in JDK 1.2.2
- if (!compare(failCount, df.format(0.01), "100E-4"))
- failures.set(failCount);
- failCount++;
- compare("###0.0#E0: 0.01234567", df.format(0.01234567), "123.457E-4");
- compare("###0.0#E0: 0.09999999", df.format(0.09999999), "1000E-4");
- compare("###0.0#E0: 0.001", df.format(0.001), "10E-4");
- compare("###0.0#E0: 0.001234567", df.format(0.001234567), "12.3457E-4");
- // Fails in JDK 1.2.2
- if (!compare(failCount, df.format(0.009999999), "100E-4"))
- failures.set(failCount);
- failCount++;
- compare("###0.0#E0: 0.0001", df.format(0.0001), "1.0E-4");
- compare("###0.0#E0: 0.0001234567", df.format(0.0001234567),
- "1.23457E-4");
- compare("###0.0#E0: 0.0009999999", df.format(0.0009999999), "10E-4");
- // Fails in JDK 1.2.2
- if (!compare(failCount, df.format(0.00001), "1000E-8"))
- failures.set(failCount);
- failCount++;
- compare("###0.0#E0: 0.00001234567", df.format(0.00001234567),
- "1234.57E-8");
- compare("###0.0#E0: 0.00009999999", df.format(0.00009999999), "1.0E-4");
-
- assertTrue("Failed " + failures + " of " + failCount,
- failures.length() == 0);
-
- String formatString = "##0.#";
- df = new DecimalFormat(formatString, dfs);
- df.setMinimumFractionDigits(30);
- compare(formatString + ": 0.000000000000000000000000000000", df
- .format(0.0), "0.000000000000000000000000000000");
- compare(formatString + ": -0.000000000000000000000000000000", df
- .format(-0.0), "-0.000000000000000000000000000000");
- compare(formatString + ": 1.000000000000000000000000000000", df
- .format(1.0), "1.000000000000000000000000000000");
- compare(formatString + ": -1.000000000000000000000000000000", df
- .format(-1.0), "-1.000000000000000000000000000000");
-
- df = new DecimalFormat(formatString);
- df.setMaximumFractionDigits(30);
- compare(formatString + ": 0", df.format(0.0), "0");
- compare(formatString + ": -0", df.format(-0.0), "-0");
- compare(formatString + ": 1", df.format(1.0), "1");
- compare(formatString + ": -1", df.format(-1.0), "-1");
- }
-
- public void test_formatD() {
- DecimalFormat format = (DecimalFormat) NumberFormat
- .getInstance(Locale.ENGLISH);
- format.setGroupingUsed(false);
- format.setMaximumFractionDigits(400);
- assertEquals("123456789012345", format.format(123456789012345.));
- assertEquals("1", "12345678901234.5", format.format(12345678901234.5));
- assertEquals("2", "1234567890123.25", format.format(1234567890123.25));
- assertEquals("3", "999999999999.375", format.format(999999999999.375));
- assertEquals("4", "99999999999.0625", format.format(99999999999.0625));
- assertEquals("5", "9999999999.03125", format.format(9999999999.03125));
- assertEquals("6", "999999999.015625", format.format(999999999.015625));
- assertEquals("7", "99999999.0078125", format.format(99999999.0078125));
- assertEquals("8", "9999999.00390625", format.format(9999999.00390625));
- assertEquals("9", "999999.001953125", format.format(999999.001953125));
- assertEquals("10", "9999.00048828125", format.format(9999.00048828125));
- assertEquals("11", "999.000244140625", format.format(999.000244140625));
- assertEquals("12", "99.0001220703125", format.format(99.0001220703125));
- assertEquals("13", "9.00006103515625", format.format(9.00006103515625));
- assertEquals("14", "0.000030517578125", format.format(0.000030517578125));
- }
-
-
- public void test_getNegativePrefix() {
- DecimalFormat df = new DecimalFormat();
- try {
- df.setNegativePrefix("--");
- assertTrue("Incorrect negative prefix", df.getNegativePrefix()
- .equals("--"));
- } catch (Exception e) {
- fail("Unexpected exception " + e.toString());
- }
- }
-
- public void test_getNegativeSuffix() {
- DecimalFormat df = new DecimalFormat();
- try {
- df.setNegativeSuffix("&");
- assertTrue("Incorrect negative suffix", df.getNegativeSuffix()
- .equals("&"));
- } catch (Exception e) {
- fail("Unexpected exception " + e.toString());
- }
- }
-
- public void test_getPositivePrefix() {
- DecimalFormat df = new DecimalFormat();
- try {
- df.setPositivePrefix("++");
- assertTrue("Incorrect positive prefix", df.getPositivePrefix()
- .equals("++"));
- } catch (Exception e) {
- fail("Unexpected exception " + e.toString());
- }
- }
-
- public void test_getPositiveSuffix() {
- DecimalFormat df = new DecimalFormat();
- try {
- df.setPositiveSuffix("%");
- assertTrue("Incorrect positive prefix", df.getPositiveSuffix()
- .equals("%"));
- } catch (Exception e) {
- fail("Unexpected exception " + e.toString());
- }
- }
-
- public void test_hashCode() {
- try {
- DecimalFormat df1 = new DecimalFormat();
- DecimalFormat df2 = (DecimalFormat) df1.clone();
- assertTrue("Hash codes of equals object are not equal", df2
- .hashCode() == df1.hashCode());
- } catch (Exception e) {
- fail("Unexpected exception " + e.toString());
- }
- }
-
- public void test_parseLjava_lang_StringLjava_text_ParsePosition() {
- DecimalFormat format = (DecimalFormat) NumberFormat
- .getNumberInstance(Locale.ENGLISH);
- ParsePosition pos = new ParsePosition(0);
- Number result = format.parse("9223372036854775807", pos);
- assertTrue("Wrong result type for Long.MAX_VALUE",
- result.getClass() == Long.class);
- assertEquals("Wrong result Long.MAX_VALUE",
- Long.MAX_VALUE, result.longValue());
- pos = new ParsePosition(0);
- result = format.parse("-9223372036854775808", pos);
- assertTrue("Wrong result type for Long.MIN_VALUE",
- result.getClass() == Long.class);
- assertTrue("Wrong result Long.MIN_VALUE: " + result.longValue(), result
- .longValue() == Long.MIN_VALUE);
- pos = new ParsePosition(0);
- result = format.parse("9223372036854775808", pos);
- assertTrue("Wrong result type for Long.MAX_VALUE+1",
- result.getClass() == Double.class);
- assertEquals("Wrong result Long.MAX_VALUE + 1",
- (double) Long.MAX_VALUE + 1, result.doubleValue());
- pos = new ParsePosition(0);
- result = format.parse("-9223372036854775809", pos);
- assertTrue("Wrong result type for Long.MIN_VALUE - 1",
- result.getClass() == Double.class);
- assertEquals("Wrong result Long.MIN_VALUE - 1",
- (double) Long.MIN_VALUE - 1, result.doubleValue());
-
- pos = new ParsePosition(0);
- result = format.parse("18446744073709551629", pos);
- assertTrue("Wrong result type for overflow",
- result.getClass() == Double.class);
- assertEquals("Wrong result for overflow",
- 18446744073709551629d, result.doubleValue());
-
- pos = new ParsePosition(0);
- result = format.parse("42325917317067571199", pos);
- assertTrue("Wrong result type for overflow a: " + result, result
- .getClass() == Double.class);
- assertTrue("Wrong result for overflow a: " + result, result
- .doubleValue() == 42325917317067571199d);
- pos = new ParsePosition(0);
- result = format.parse("4232591731706757119E1", pos);
- assertTrue("Wrong result type for overflow b: " + result, result
- .getClass() == Double.class);
- assertEquals("Wrong result for overflow b: " + result,
- 42325917317067571190d, result.doubleValue());
- pos = new ParsePosition(0);
- result = format.parse(".42325917317067571199E20", pos);
- assertTrue("Wrong result type for overflow c: " + result, result
- .getClass() == Double.class);
- assertTrue("Wrong result for overflow c: " + result, result
- .doubleValue() == 42325917317067571199d);
- pos = new ParsePosition(0);
- result = format.parse("922337203685477580.9E1", pos);
- assertTrue("Wrong result type for overflow d: " + result, result
- .getClass() == Double.class);
- assertTrue("Wrong result for overflow d: " + result, result
- .doubleValue() == 9223372036854775809d);
- pos = new ParsePosition(0);
- result = format.parse("9.223372036854775809E18", pos);
- assertTrue("Wrong result type for overflow e: " + result, result
- .getClass() == Double.class);
- assertTrue("Wrong result for overflow e: " + result, result
- .doubleValue() == 9223372036854775809d);
-
- // test parse with multipliers
- format.setMultiplier(100);
- result = format.parse("9223372036854775807", new ParsePosition(0));
- assertEquals("Wrong result type multiplier 100: " + result, Long.class, result.getClass());
- // RI on windows and linux both answer with a slightly rounded result
- assertTrue("Wrong result for multiplier 100: " + result, result
- .longValue() == 92233720368547760L);
- format.setMultiplier(1000);
- result = format.parse("9223372036854775807", new ParsePosition(0));
- assertTrue("Wrong result type multiplier 1000: " + result, result
- .getClass() == Long.class);
- assertTrue("Wrong result for multiplier 1000: " + result, result
- .longValue() == 9223372036854776L);
-
- format.setMultiplier(10000);
- result = format.parse("9223372036854775807", new ParsePosition(0));
- assertTrue("Wrong result type multiplier 10000: " + result, result
- .getClass() == Double.class);
- assertTrue("Wrong result for multiplier 10000: " + result, result
- .doubleValue() == 922337203685477.5807d);
-
- }
-}
diff --git a/luni/src/test/java/libcore/java/text/OldFieldPositionTest.java b/luni/src/test/java/libcore/java/text/OldFieldPositionTest.java
deleted file mode 100644
index b6fbd98..0000000
--- a/luni/src/test/java/libcore/java/text/OldFieldPositionTest.java
+++ /dev/null
@@ -1,79 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package libcore.java.text;
-
-import java.text.DateFormat;
-import java.text.FieldPosition;
-
-public class OldFieldPositionTest extends junit.framework.TestCase {
-
- public void test_hashCode() {
- // Test for method int java.text.FieldPosition.hashCode()
- FieldPosition fpos1 = new FieldPosition(1);
- FieldPosition fpos2 = new FieldPosition(1);
- assertTrue("test 1: hash codes are not equal for equal objects.",
- fpos1.hashCode() == fpos2.hashCode());
- fpos1.setBeginIndex(5);
- fpos1.setEndIndex(110);
- assertTrue("test 2: hash codes are equal for non equal objects.",
- fpos1.hashCode() != fpos2.hashCode());
- fpos2.setBeginIndex(5);
- fpos2.setEndIndex(110);
- assertTrue("test 3: hash codes are not equal for equal objects.",
- fpos1.hashCode() == fpos2.hashCode());
-
- FieldPosition fpos3 = new FieldPosition(
- DateFormat.Field.DAY_OF_WEEK_IN_MONTH);
-
- assertTrue("test 4: hash codes are equal for non equal objects.",
- fpos2.hashCode() != fpos3.hashCode());
- }
-
- public void test_setBeginIndexI() {
- // Test for method void java.text.FieldPosition.setBeginIndex(int)
- FieldPosition fpos = new FieldPosition(1);
- fpos.setBeginIndex(2);
- fpos.setEndIndex(3);
- assertEquals("beginIndex should have been set to 2", 2, fpos
- .getBeginIndex());
-
- fpos.setBeginIndex(Integer.MAX_VALUE);
- assertEquals("beginIndex should have been set to Integer.MAX_VALUE",
- Integer.MAX_VALUE, fpos.getBeginIndex());
-
- fpos.setBeginIndex(-1);
- assertEquals("beginIndex should have been set to -1",
- -1, fpos.getBeginIndex());
- }
-
- public void test_setEndIndexI() {
- // Test for method void java.text.FieldPosition.setEndIndex(int)
- FieldPosition fpos = new FieldPosition(1);
- fpos.setEndIndex(3);
- fpos.setBeginIndex(2);
- assertEquals("EndIndex should have been set to 3", 3, fpos
- .getEndIndex());
-
- fpos.setEndIndex(Integer.MAX_VALUE);
- assertEquals("endIndex should have been set to Integer.MAX_VALUE",
- Integer.MAX_VALUE, fpos.getEndIndex());
-
- fpos.setEndIndex(-1);
- assertEquals("endIndex should have been set to -1",
- -1, fpos.getEndIndex());
- }
-}
diff --git a/luni/src/test/java/libcore/java/text/OldMessageFormatTest.java b/luni/src/test/java/libcore/java/text/OldMessageFormatTest.java
deleted file mode 100644
index 2701d0e..0000000
--- a/luni/src/test/java/libcore/java/text/OldMessageFormatTest.java
+++ /dev/null
@@ -1,463 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package libcore.java.text;
-
-import java.text.ChoiceFormat;
-import java.text.DateFormat;
-import java.text.FieldPosition;
-import java.text.Format;
-import java.text.MessageFormat;
-import java.text.NumberFormat;
-import java.text.ParseException;
-import java.text.ParsePosition;
-import java.util.Calendar;
-import java.util.Date;
-import java.util.Locale;
-import java.util.TimeZone;
-import junit.framework.TestCase;
-import tests.support.Support_MessageFormat;
-
-public class OldMessageFormatTest extends TestCase {
-
- private MessageFormat format1;
-
- protected void setUp() {
- Locale.setDefault(Locale.US);
-
- // test with repeating formats and max argument index < max offset
- String pattern = "A {3, number, currency} B {2, time} C {0, number, percent} D {4} E {1,choice,0#off|1#on} F {0, date}";
- format1 = new MessageFormat(pattern);
- }
-
- public void test_applyPatternLjava_lang_String_AndroidFailure() {
- MessageFormat format = new MessageFormat("test");
- format.setLocale(Locale.FRENCH); // use French since English has the
- // same LONG and FULL time patterns
- format.applyPattern("{0,time, Full}");
- assertEquals("Wrong full time pattern", "{0,time,full}", format
- .toPattern());
- }
-
- public void test_formatToCharacterIteratorLjava_lang_Object() {
- // Test for method formatToCharacterIterator(java.lang.Object)
- new Support_MessageFormat(
- "test_formatToCharacterIteratorLjava_lang_Object")
- .t_formatToCharacterIterator();
-
- try {
- new MessageFormat("{1, number}").formatToCharacterIterator(null);
- fail("NullPointerException was not thrown.");
- } catch(NullPointerException npe) {
- //expected
- }
-
- try {
- new MessageFormat("{0, time}").formatToCharacterIterator(new Object[]{""});
- fail("IllegalArgumentException was not thrown.");
- } catch(IllegalArgumentException iae) {
- //expected
- }
- }
-
- public void test_getLocale() {
- try {
- Locale[] l = {
- Locale.FRANCE,
- Locale.KOREA,
- new Locale(Locale.FRANCE.getCountry(), Locale.FRANCE
- .getLanguage()), new Locale("mk"),
- new Locale("mk", "MK"), Locale.US,
- new Locale("#ru", "@31230") };
-
- String pattern = "getLocale test {0,number,#,####}";
- MessageFormat mf;
-
- for (int i = 0; i < 0; i++) {
- mf = new MessageFormat(pattern, l[i]);
- Locale result = mf.getLocale();
- assertEquals("Returned local: " + result + " instead of "
- + l[i], l[i], result);
- assertEquals("Returned language: " + result.getLanguage()
- + " instead of " + l[i].getLanguage(), l[i]
- .getLanguage(), result.getLanguage());
- assertEquals("Returned country: " + result.getCountry()
- + " instead of " + l[i].getCountry(),
- l[i].getCountry(), result.getCountry());
- }
-
- mf = new MessageFormat(pattern);
- mf.setLocale(null);
- Locale result = mf.getLocale();
- assertEquals("Returned local: " + result + " instead of null",
- null, result);
- } catch (Exception e) {
- fail("unexpected exception " + e.toString());
- }
- }
-
- /**
- * java.text.MessageFormat#setFormat(int, Format) Test of method
- * java.text.MessageFormat#setFormat(int, Format). Case 1: Compare
- * getFormats() results after calls to setFormat(). Case 2: Try to
- * call setFormat() using incorrect index.
- */
- public void test_setFormatILjava_text_Format() {
- try {
- // case 1: Compare getFormats() results after calls to setFormat()
- MessageFormat f1 = (MessageFormat) format1.clone();
- f1.setFormat(0, DateFormat.getTimeInstance());
- f1.setFormat(1, DateFormat.getTimeInstance());
- f1.setFormat(2, NumberFormat.getInstance());
- f1.setFormat(3, new ChoiceFormat("0#off|1#on"));
- f1.setFormat(4, new ChoiceFormat("1#few|2#ok|3#a lot"));
- f1.setFormat(5, DateFormat.getTimeInstance());
-
- Format[] formats = f1.getFormats();
- formats = f1.getFormats();
-
- Format[] correctFormats = new Format[] {
- DateFormat.getTimeInstance(), DateFormat.getTimeInstance(),
- NumberFormat.getInstance(), new ChoiceFormat("0#off|1#on"),
- new ChoiceFormat("1#few|2#ok|3#a lot"),
- DateFormat.getTimeInstance() };
-
- assertEquals("Test1A:Returned wrong number of formats:",
- correctFormats.length, formats.length);
- for (int i = 0; i < correctFormats.length; i++) {
- assertEquals(
- "Test1B:wrong format for pattern index " + i + ":",
- correctFormats[i], formats[i]);
- }
-
- // case 2: Try to setFormat using incorrect index
- try {
- f1.setFormat(-1, DateFormat.getDateInstance());
- fail("Expected ArrayIndexOutOfBoundsException was not thrown");
- f1.setFormat(f1.getFormats().length, DateFormat
- .getDateInstance());
- fail("Expected ArrayIndexOutOfBoundsException was not thrown");
- } catch (ArrayIndexOutOfBoundsException e) {
- // expected
- }
- } catch (Exception e) {
- fail("Unexpected exception " + e.toString());
- }
- }
-
- public void test_format$Ljava_lang_ObjectLjava_lang_StringBufferLjava_text_FieldPosition() {
- // Test for method java.lang.StringBuffer
- // java.text.MessageFormat.format(java.lang.Object [],
- // java.lang.StringBuffer, java.text.FieldPosition)
- MessageFormat format = new MessageFormat("{1,number,integer}");
- StringBuffer buffer = new StringBuffer();
- format.format(new Object[] { "0", new Double(53.863) }, buffer,
- new FieldPosition(MessageFormat.Field.ARGUMENT));
- assertEquals("Wrong result", "54", buffer.toString());
-
- format.format(new Object[] { "0", new Double(53.863) }, buffer,
- new FieldPosition(MessageFormat.Field.ARGUMENT));
-
- assertEquals("Wrong result", "5454", buffer.toString());
-
- buffer = new StringBuffer();
- format
- .applyPattern("{0,choice,0#zero|1#one '{1,choice,2#two {2,time}}'}");
- Date date = new Date();
- String expected = "one two "
- + DateFormat.getTimeInstance().format(date);
- format.format(new Object[] { new Double(1.6),
- new Integer(3), date }, buffer, new FieldPosition(MessageFormat
- .Field.ARGUMENT));
- assertEquals("Choice not recursive:\n" + expected + "\n" + buffer,
- expected, buffer.toString());
-
- StringBuffer str = format.format(new Object[] { new Double(0.6),
- new Integer(3)}, buffer, null);
-
- assertEquals(expected + "zero", str.toString());
- assertEquals(expected + "zero", buffer.toString());
-
- try {
- format.format(new Object[] { "0", new Double(1), "" }, buffer,
- new FieldPosition(MessageFormat.Field.ARGUMENT));
- fail("IllegalArgumentException was not thrown.");
- } catch(IllegalArgumentException iae) {
- //expected
- }
-
- try {
- format.format(new Object[] { "", new Integer(3)}, buffer,
- new FieldPosition(MessageFormat.Field.ARGUMENT));
- fail("IllegalArgumentException was not thrown.");
- } catch(IllegalArgumentException iae) {
- //expected
- }
- }
-
- public void test_formatLjava_lang_StringLjava_lang_Object() {
- TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
- int iCurrency = 123;
- int iInteger = Integer.MIN_VALUE;
-
- Date date = new Date(12345678);
- Object[] args = { date, iCurrency, iInteger };
- String resStr = "Date: Jan 1, 1970 Currency: $" + iCurrency
- + ".00 Integer: -2,147,483,648";
- String pattern = "Date: {0,date} Currency: {1, number, currency} Integer: {2, number, integer}";
- String sFormat = MessageFormat.format(pattern, (Object[]) args);
- assertEquals(
- "format(String, Object[]) with valid parameters returns incorrect string: case 1",
- sFormat, resStr);
-
- pattern = "abc {4, number, integer} def {3,date} ghi {2,number} jkl {1,choice,0#low|1#high} mnop {0}";
- resStr = "abc -2,147,483,648 def Jan 1, 1970 ghi -2,147,483,648 jkl high mnop -2,147,483,648";
- Object[] args_ = { iInteger, 1, iInteger, date, iInteger };
- sFormat = MessageFormat.format(pattern, args_);
- assertEquals(
- "format(String, Object[]) with valid parameters returns incorrect string: case 1",
- sFormat, resStr);
-
- try {
- args = null;
- MessageFormat.format(null, args);
- fail("Doesn't throw IllegalArgumentException: null, null");
- } catch (Exception e) {
- // expected
- }
-
- try {
- MessageFormat.format("Invalid {1,foobar} format descriptor!",
- new Object[] {iInteger} );
- fail("Doesn't throw IllegalArgumentException with invalid pattern as a parameter: case 1");
- } catch (IllegalArgumentException ex) {
- // expected
- }
-
- try {
- MessageFormat.format(
- "Invalid {1,date,invalid-spec} format descriptor!", new Object[]{""});
- fail("Doesn't throw IllegalArgumentException with invalid pattern as a parameter: case 2");
- } catch (IllegalArgumentException ex) {
- // expected
- }
-
- try {
- MessageFormat.format("{0,number,integer", new Object[] {iInteger});
- fail("Doesn't throw IllegalArgumentException, doesn't detect unmatched brackets");
- } catch (IllegalArgumentException ex) {
- // expected
- }
-
- try {
- MessageFormat.format(
- "Valid {1, date} format {0, number} descriptor!", new Object[]{ "" } );
- fail("Doesn't throw IllegalArgumentException with invalid Object array");
- } catch (IllegalArgumentException ex) {
- // expected
- }
- }
-
- public void test_formatLjava_lang_ObjectLjava_lang_StringBufferLjava_text_FieldPosition() {
- // Test for method java.lang.StringBuffer
- // java.text.MessageFormat.format(java.lang.Object,
- // java.lang.StringBuffer, java.text.FieldPosition)
- new Support_MessageFormat(
- "test_formatLjava_lang_ObjectLjava_lang_StringBufferLjava_text_FieldPosition")
- .t_format_with_FieldPosition();
-
- String pattern = "On {4,date} at {3,time}, he ate {2,number, integer} " +
- "hamburger{2,choice,1#|1<s}.";
- MessageFormat format = new MessageFormat(pattern, Locale.US);
-
- Object[] objects = new Object[] { "", new Integer(3), 8, ""};
-
- try {
- format.format(objects, new StringBuffer(),
- new FieldPosition(DateFormat.Field.AM_PM));
- fail("IllegalArgumentException was not thrown.");
- } catch(IllegalArgumentException iae) {
- //expected
- }
- }
-
- public void test_setFormats$Ljava_text_Format() {
- try {
- MessageFormat f1 = (MessageFormat) format1.clone();
-
- // case 1: Test with repeating formats and max argument index < max
- // offset
- // compare getFormats() results after calls to setFormats(Format[])
- Format[] correctFormats = new Format[] {
- DateFormat.getTimeInstance(),
- new ChoiceFormat("0#off|1#on"),
- DateFormat.getTimeInstance(),
- NumberFormat.getCurrencyInstance(),
- new ChoiceFormat("1#few|2#ok|3#a lot") };
-
- f1.setFormats(correctFormats);
- Format[] formats = f1.getFormats();
-
- assertTrue("Test1A:Returned wrong number of formats:",
- correctFormats.length <= formats.length);
- for (int i = 0; i < correctFormats.length; i++) {
- assertEquals("Test1B:wrong format for argument index " + i
- + ":", correctFormats[i], formats[i]);
- }
-
- // case 2: Try to pass null argument to setFormats().
- try {
- f1.setFormats(null);
- fail("Expected exception NullPointerException was not thrown");
- } catch (NullPointerException e) {
- // expected
- }
- } catch (Exception e) {
- fail("Unexpected exception " + e.toString());
- }
- }
-
- public void test_parseLjava_lang_String() throws ParseException {
- String pattern = "A {3, number, currency} B {2, time} C {0, number, percent} D {4} E {1,choice,0#off|1#on} F {0, date}";
- MessageFormat mf = new MessageFormat(pattern);
- String sToParse = "A $12,345.00 B 9:56:07 AM C 3,200% D 1/15/70 9:56 AM E on F Jan 1, 1970";
- Object[] result;
- try {
- result = mf.parse(sToParse);
-
- assertTrue("No result: " + result.length, result.length == 5);
- assertTrue("Object 0 is not date", result[0] instanceof Date);
- assertEquals("Object 1 is not stringr", result[1].toString(), "1.0");
- assertTrue("Object 2 is not date", result[2] instanceof Date);
- assertEquals("Object 3 is not number", result[3].toString(),
- "12345");
- assertEquals("Object 4 is not string", result[4].toString(),
- "1/15/70 9:56 AM");
-
- } catch (java.text.ParseException pe) {
- fail("ParseException is thrown for incorrect string " + sToParse);
- }
-
- sToParse = "xxdate is Feb 28, 1999";
- try {
- result = format1.parse(sToParse);
- fail("ParseException is thrown for incorrect string " + sToParse);
- } catch (java.text.ParseException pe) {
- // expected
- }
-
- sToParse = "vm=Test, @3 4 6, 3 ";
- mf = new MessageFormat("vm={0},{1},{2}");
- try {
- result = mf.parse(sToParse);
- assertTrue("No result: " + result.length, result.length == 3);
- assertEquals("Object 0 is not string", result[0].toString(), "Test");
- assertEquals("Object 1 is not string", result[1].toString(),
- " @3 4 6");
- assertEquals("Object 2 is not string", result[2].toString(),
- " 3 ");
- } catch (java.text.ParseException pe) {
- fail("ParseException is thrown for correct string " + sToParse);
- }
-
- try {
- result = mf.parse(null);
- fail("ParseException is not thrown for null " + sToParse);
- } catch (java.text.ParseException pe) {
- // expected
- }
- }
-
- /**
- * java.text.MessageFormat#parseObject(java.lang.String,
- * java.text.ParsePosition) Test of method
- * java.text.MessageFormat#parseObject(java.lang.String,
- * java.text.ParsePosition). Case 1: Parsing of correct data string.
- * Case 2: Parsing of partial correct data string. Case 3: Try to use
- * argument ParsePosition as null.
- */
- public void test_parseObjectLjava_lang_StringLjavajava_text_ParsePosition() {
- MessageFormat mf = new MessageFormat("{0,number,#.##}, {0,number,#.#}");
- try {
- // case 1: Try to parse correct data string.
- Object[] objs = { new Double(3.1415) };
- String result = mf.format(objs);
- // result now equals "3.14, 3.1"
- Object[] res = null;
- ParsePosition pp = new ParsePosition(0);
- int parseIndex = pp.getIndex();
- res = (Object[]) mf.parseObject(result, pp);
- assertTrue("Parse operation return null", res != null);
- assertTrue("parse operation return array with incorrect length",
- 1 == res.length);
- assertTrue("ParseIndex is incorrect", pp.getIndex() != parseIndex);
- assertTrue("Result object is incorrect", new Double(3.1)
- .equals(res[0]));
-
- // case 2: Try to parse partially correct data string.
- pp.setIndex(0);
- char[] cur = result.toCharArray();
- cur[cur.length / 2] = 'Z';
- String partialCorrect = new String(cur);
- res = (Object[]) mf.parseObject(partialCorrect, pp);
- assertTrue("Parse operation return null", res == null);
- assertTrue("ParseIndex is incorrect", pp.getIndex() == 0);
- assertTrue("ParseErrorIndex is incorrect",
- pp.getErrorIndex() == cur.length / 2);
-
- // case 3: Try to use argument ParsePosition as null.
- try {
- mf.parseObject(result, null);
- fail("Expected NullPointerException was not thrown");
- } catch (NullPointerException e) {
- // expected
- }
- } catch (Exception e) {
- fail("Unexpected exception " + e.toString());
- }
- }
-
- public void test_format_Object() {
- // Regression for HARMONY-1875
- Locale.setDefault(Locale.CANADA);
- TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
- String pat = "text here {0,date,yyyyyyyyy} and here";
- Calendar c = Calendar.getInstance();
- String etalon = "text here 00000" + c.get(Calendar.YEAR) + " and here";
- MessageFormat obj = new MessageFormat(pat);
- assertEquals(etalon, obj.format(new Object[] { new Date() }));
- }
-
- public void test_parseLjava_lang_StringLjava_text_ParsePosition() {
- ParsePosition pos = new ParsePosition(2);
-
- MessageFormat mf = new MessageFormat("{0}; {0}; {0}");
- String parse = "a; b; c";
- try {
- mf.parse(parse, null);
- fail("NullPointerException was not thrown.");
- } catch(NullPointerException npe) {
- //expected
- }
-
- try {
- mf.parse(null, pos);
- } catch(NullPointerException npe) {
- fail("NullPointerException was thrown.");
- }
- }
-}
diff --git a/luni/src/test/java/libcore/java/text/OldSimpleDateFormatTest.java b/luni/src/test/java/libcore/java/text/OldSimpleDateFormatTest.java
index 1cc7554..2168342 100644
--- a/luni/src/test/java/libcore/java/text/OldSimpleDateFormatTest.java
+++ b/luni/src/test/java/libcore/java/text/OldSimpleDateFormatTest.java
@@ -144,76 +144,6 @@ public class OldSimpleDateFormatTest extends junit.framework.TestCase {
}
}
- public void test_applyLocalizedPatternLjava_lang_String() {
- // Test for method void
- // java.text.SimpleDateFormat.applyLocalizedPattern(java.lang.String)
- SimpleDateFormat f2 = new SimpleDateFormat("y", new Locale("de", "CH"));
- // BEGIN android-removed
- // This test doesn't work like this. The cause lies inside of icu
- // that doesn't support localized pattern characters anymore. So this
- // test fails because the pattern template contains characters that are
- // not part of the standard pattern returned for every locale.
- // The default pattern characters are: GyMdkHmsSEDFwWahKzZ
- //
- // f2.applyLocalizedPattern("GuMtkHmsSEDFwWahKz");
- // String pattern = f2.toPattern();
- // assertTrue("Wrong pattern: " + pattern, pattern
- // .equals("GyMdkHmsSEDFwWahKz"));
- //
- // test the new "Z" pattern char
- // f2 = new SimpleDateFormat("y", new Locale("de", "CH"));
- // f2.applyLocalizedPattern("G u M t Z");
- // pattern = f2.toPattern();
- // assertTrue("Wrong pattern: " + pattern, pattern.equals("G y M d Z"));
- // END android-removed
-
- // test invalid patterns
- try {
- f2.applyLocalizedPattern("b");
- fail("Expected IllegalArgumentException for pattern with invalid pattern letter: b");
- } catch (IllegalArgumentException e) {
- }
-
- try {
- // ICU only! this fails on the RI
- f2.applyLocalizedPattern("u");
- fail("Expected IllegalArgumentException for pattern with invalid pattern letter: u");
- } catch (IllegalArgumentException e) {
- }
-
- try {
- f2.applyLocalizedPattern("a '");
- fail("Expected IllegalArgumentException for pattern with unterminated quote: a '");
- } catch (IllegalArgumentException e) {
- }
-
- try {
- f2.applyLocalizedPattern(null);
- fail("Expected NullPointerException for null pattern");
- } catch (NullPointerException e) {
- }
- }
-
- /**
- * java.text.SimpleDateFormat#applyPattern(java.lang.String)
- */
- public void test_applyPatternLjava_lang_String() {
- // Test for method void
- // java.text.SimpleDateFormat.applyPattern(java.lang.String)
- SimpleDateFormat f2 = new SimpleDateFormat("y", new Locale("de", "CH"));
- // BEGIN android-changed
- f2.applyPattern("GyMdkHmsSEDFwWahKzZ");
- assertEquals("Wrong pattern", "GyMdkHmsSEDFwWahKzZ", f2.toPattern());
- // END android-changed
-
- // test invalid patterns
- try {
- f2.applyPattern("u");
- fail("Expected IllegalArgumentException for pattern with invalid patter letter: u");
- } catch (IllegalArgumentException e) {
- }
- }
-
public void test_hashCode() {
SimpleDateFormat format = (SimpleDateFormat) DateFormat.getInstance();
SimpleDateFormat clone = (SimpleDateFormat) format.clone();
@@ -229,130 +159,6 @@ public class OldSimpleDateFormatTest extends junit.framework.TestCase {
.hashCode());
}
- public void test_formatLjava_util_DateLjava_lang_StringBufferLjava_text_FieldPosition() {
- FormatTester test = new FormatTester();
-
- Calendar cal = new GregorianCalendar(1999, Calendar.JUNE, 2, 15, 3, 6);
- test.test(" G", cal, " AD", DateFormat.ERA_FIELD);
- test.test(" GG", cal, " AD", DateFormat.ERA_FIELD);
- test.test(" GGG", cal, " AD", DateFormat.ERA_FIELD);
- test.test(" G", new GregorianCalendar(-1999, Calendar.JUNE, 2), " BC",
- DateFormat.ERA_FIELD);
-
- test.test(" M", cal, " 6", DateFormat.MONTH_FIELD);
- test.test(" M", new GregorianCalendar(1999, Calendar.NOVEMBER, 2),
- " 11", DateFormat.MONTH_FIELD);
- test.test(" MM", cal, " 06", DateFormat.MONTH_FIELD);
- test.test(" MMM", cal, " Jun", DateFormat.MONTH_FIELD);
- test.test(" MMMM", cal, " June", DateFormat.MONTH_FIELD);
- test.test(" MMMMM", cal, " J", DateFormat.MONTH_FIELD);
-
- test.test(" d", cal, " 2", DateFormat.DATE_FIELD);
- test.test(" d", new GregorianCalendar(1999, Calendar.NOVEMBER, 12),
- " 12", DateFormat.DATE_FIELD);
- test.test(" dd", cal, " 02", DateFormat.DATE_FIELD);
- test.test(" dddd", cal, " 0002", DateFormat.DATE_FIELD);
-
- test.test(" h", cal, " 3", DateFormat.HOUR1_FIELD);
- test.test(" h", new GregorianCalendar(1999, Calendar.NOVEMBER, 12),
- " 12", DateFormat.HOUR1_FIELD);
- test.test(" hh", cal, " 03", DateFormat.HOUR1_FIELD);
- test.test(" hhhh", cal, " 0003", DateFormat.HOUR1_FIELD);
-
- test.test(" H", cal, " 15", DateFormat.HOUR_OF_DAY0_FIELD);
- test.test(" H",
- new GregorianCalendar(1999, Calendar.NOVEMBER, 12, 4, 0), " 4",
- DateFormat.HOUR_OF_DAY0_FIELD);
- test.test(" H", new GregorianCalendar(1999, Calendar.NOVEMBER, 12, 12,
- 0), " 12", DateFormat.HOUR_OF_DAY0_FIELD);
- test.test(" H", new GregorianCalendar(1999, Calendar.NOVEMBER, 12),
- " 0", DateFormat.HOUR_OF_DAY0_FIELD);
- test.test(" HH", cal, " 15", DateFormat.HOUR_OF_DAY0_FIELD);
- test.test(" HHHH", cal, " 0015", DateFormat.HOUR_OF_DAY0_FIELD);
-
- test.test(" m", cal, " 3", DateFormat.MINUTE_FIELD);
- test.test(" m", new GregorianCalendar(1999, Calendar.NOVEMBER, 12, 4,
- 47), " 47", DateFormat.MINUTE_FIELD);
- test.test(" mm", cal, " 03", DateFormat.MINUTE_FIELD);
- test.test(" mmmm", cal, " 0003", DateFormat.MINUTE_FIELD);
-
- test.test(" s", cal, " 6", DateFormat.SECOND_FIELD);
- test.test(" s", new GregorianCalendar(1999, Calendar.NOVEMBER, 12, 4,
- 47, 13), " 13", DateFormat.SECOND_FIELD);
- test.test(" ss", cal, " 06", DateFormat.SECOND_FIELD);
- test.test(" ssss", cal, " 0006", DateFormat.SECOND_FIELD);
-
- test.test(" S", cal, " 0", DateFormat.MILLISECOND_FIELD);
- Calendar temp = new GregorianCalendar();
- temp.set(Calendar.MILLISECOND, 961);
-
- test.test(" SS", temp, " 961", DateFormat.MILLISECOND_FIELD);
- test.test(" SSSS", cal, " 0000", DateFormat.MILLISECOND_FIELD);
-
- test.test(" SS", cal, " 00", DateFormat.MILLISECOND_FIELD);
-
- test.test(" E", cal, " Wed", DateFormat.DAY_OF_WEEK_FIELD);
- test.test(" EE", cal, " Wed", DateFormat.DAY_OF_WEEK_FIELD);
- test.test(" EEE", cal, " Wed", DateFormat.DAY_OF_WEEK_FIELD);
- test.test(" EEEE", cal, " Wednesday", DateFormat.DAY_OF_WEEK_FIELD);
- test.test(" EEEEE", cal, " W", DateFormat.DAY_OF_WEEK_FIELD);
-
- test.test(" D", cal, " 153", DateFormat.DAY_OF_YEAR_FIELD);
- test.test(" DD", cal, " 153", DateFormat.DAY_OF_YEAR_FIELD);
- test.test(" DDDD", cal, " 0153", DateFormat.DAY_OF_YEAR_FIELD);
-
- test.test(" F", cal, " 1", DateFormat.DAY_OF_WEEK_IN_MONTH_FIELD);
- test.test(" F", new GregorianCalendar(1999, Calendar.NOVEMBER, 14),
- " 2", DateFormat.DAY_OF_WEEK_IN_MONTH_FIELD);
- test.test(" FF", cal, " 01", DateFormat.DAY_OF_WEEK_IN_MONTH_FIELD);
- test.test(" FFFF", cal, " 0001", DateFormat.DAY_OF_WEEK_IN_MONTH_FIELD);
-
- test.test(" a", cal, " PM", DateFormat.AM_PM_FIELD);
- test.test(" a", new GregorianCalendar(1999, Calendar.NOVEMBER, 14),
- " AM", DateFormat.AM_PM_FIELD);
- test.test(" a", new GregorianCalendar(1999, Calendar.NOVEMBER, 14, 12,
- 0), " PM", DateFormat.AM_PM_FIELD);
- test.test(" aa", cal, " PM", DateFormat.AM_PM_FIELD);
- test.test(" aaa", cal, " PM", DateFormat.AM_PM_FIELD);
- test.test(" aaaa", cal, " PM", DateFormat.AM_PM_FIELD);
- test.test(" aaaaa", cal, " PM", DateFormat.AM_PM_FIELD);
-
- test.test(" k", cal, " 15", DateFormat.HOUR_OF_DAY1_FIELD);
- test.test(" k",
- new GregorianCalendar(1999, Calendar.NOVEMBER, 12, 4, 0), " 4",
- DateFormat.HOUR_OF_DAY1_FIELD);
- test.test(" k", new GregorianCalendar(1999, Calendar.NOVEMBER, 12, 12,
- 0), " 12", DateFormat.HOUR_OF_DAY1_FIELD);
- test.test(" k", new GregorianCalendar(1999, Calendar.NOVEMBER, 12),
- " 24", DateFormat.HOUR_OF_DAY1_FIELD);
- test.test(" kk", cal, " 15", DateFormat.HOUR_OF_DAY1_FIELD);
- test.test(" kkkk", cal, " 0015", DateFormat.HOUR_OF_DAY1_FIELD);
-
- test.test(" K", cal, " 3", DateFormat.HOUR0_FIELD);
- test.test(" K", new GregorianCalendar(1999, Calendar.NOVEMBER, 12),
- " 0", DateFormat.HOUR0_FIELD);
- test.test(" KK", cal, " 03", DateFormat.HOUR0_FIELD);
- test.test(" KKKK", cal, " 0003", DateFormat.HOUR0_FIELD);
-
- format.applyPattern("'Mkz''':.@5");
- assertEquals("Wrong output", "Mkz':.@5", format.format(new Date()));
-
- //assertTrue("Tests failed", !test.testsFailed());
-
- // Test invalid args to format.
- SimpleDateFormat dateFormat = new SimpleDateFormat();
- try {
- dateFormat.format(null, new StringBuffer(), new FieldPosition(1));
- fail("Expected test to throw NPE.");
- } catch (NullPointerException ex) {
- // expected
- } catch (Throwable ex) {
- fail("Expected test to throw NPE, not " + ex.getClass().getName());
- }
-
- assertFalse(test.testsFailed);
- }
-
/**
* This test assumes Unicode behavior where 'y' and 'yyy' don't truncate,
* which means that it will fail on the RI.
@@ -363,12 +169,9 @@ public class OldSimpleDateFormatTest extends junit.framework.TestCase {
Calendar cal = new GregorianCalendar(1999, Calendar.JUNE, 2, 15, 3, 6);
test.test(" y", cal, " 1999", DateFormat.YEAR_FIELD);
test.test(" yy", cal, " 99", DateFormat.YEAR_FIELD);
- test.test(" yy", new GregorianCalendar(2001, Calendar.JUNE, 2), " 01",
- DateFormat.YEAR_FIELD);
- test.test(" yy", new GregorianCalendar(2000, Calendar.JUNE, 2), " 00",
- DateFormat.YEAR_FIELD);
- test.test(" yyy", new GregorianCalendar(2000, Calendar.JUNE, 2), " 2000",
- DateFormat.YEAR_FIELD);
+ test.test(" yy", new GregorianCalendar(2001, Calendar.JUNE, 2), " 01", DateFormat.YEAR_FIELD);
+ test.test(" yy", new GregorianCalendar(2000, Calendar.JUNE, 2), " 00", DateFormat.YEAR_FIELD);
+ test.test(" yyy", new GregorianCalendar(2000, Calendar.JUNE, 2), " 2000", DateFormat.YEAR_FIELD);
test.test(" yyy", cal, " 1999", DateFormat.YEAR_FIELD);
test.test(" yyyy", cal, " 1999", DateFormat.YEAR_FIELD);
test.test(" yyyyy", cal, " 01999", DateFormat.YEAR_FIELD);
@@ -433,31 +236,6 @@ public class OldSimpleDateFormatTest extends junit.framework.TestCase {
assertFalse(test.testsFailed);
}
- /**
- * java.text.SimpleDateFormat#format(java.util.Date)
- */
- public void test_timeZoneFormatting() {
- // tests specific to formatting of timezones
- Date summerDate = new GregorianCalendar(1999, Calendar.JUNE, 2, 15, 3, 6).getTime();
- Date winterDate = new GregorianCalendar(1999, Calendar.JANUARY, 12).getTime();
-
- FormatTester test = new FormatTester();
- test.verifyFormatTimezone("GMT-7", "GMT-07:00, GMT-07:00", "-0700, GMT-07:00", summerDate);
- test.verifyFormatTimezone("GMT-7", "GMT-07:00, GMT-07:00", "-0700, GMT-07:00", winterDate);
-
- test.verifyFormatTimezone("GMT+14", "GMT+14:00, GMT+14:00", "+1400, GMT+14:00", summerDate);
- test.verifyFormatTimezone("GMT+14", "GMT+14:00, GMT+14:00", "+1400, GMT+14:00", winterDate);
-
- test.verifyFormatTimezone("America/Los_Angeles", "PDT, Pacific Daylight Time", "-0700, GMT-07:00", summerDate);
- test.verifyFormatTimezone("America/Los_Angeles", "PST, Pacific Standard Time", "-0800, GMT-08:00", winterDate);
-
- // this fails on the RI!
- test.verifyFormatTimezone("America/Detroit", "EDT, Eastern Daylight Time", "-0400, GMT-04:00", summerDate);
- test.verifyFormatTimezone("America/Detroit", "EST, Eastern Standard Time", "-0500, GMT-05:00", winterDate);
-
- assertFalse(test.testsFailed);
- }
-
public void test_parseLjava_lang_StringLjava_text_ParsePosition_2() {
try {
format.parse("240 11 2002 March", null);
@@ -499,29 +277,6 @@ public class OldSimpleDateFormatTest extends junit.framework.TestCase {
}
}
- public void test_toLocalizedPattern() {
- // BEGIN android-changed
- // Test for method java.lang.String
- // java.text.SimpleDateFormat.toLocalizedPattern()
- SimpleDateFormat f2 = new SimpleDateFormat("GyMdkHmsSEDFwWahKzZ",
- new Locale("de", "CH"));
- String pattern = f2.toLocalizedPattern();
- // the default localized pattern characters are the same for all locales
- // since icu has dropped support for this. the default pattern characters
- // are these: GyMdkHmsSEDFwWahKz
- // ICU only! this fails on the RI
- assertTrue("Wrong pattern: " + pattern, pattern
- .equals("GyMdkHmsSEDFwWahKzZ"));
-
-
- // test the new "Z" pattern char
- f2 = new SimpleDateFormat("G y M d Z", new Locale("de", "CH"));
- pattern = f2.toLocalizedPattern();
- // assertTrue("Wrong pattern: " + pattern, pattern.equals("G u M t Z"));
- assertTrue("Wrong pattern: " + pattern, pattern.equals("G y M d Z"));
- // END android-changed
- }
-
public void test_toPattern() {
String pattern = "yyyy mm dd";
SimpleDateFormat f = new SimpleDateFormat(pattern);
diff --git a/luni/src/test/java/libcore/javax/net/ssl/SSLSessionTest.java b/luni/src/test/java/libcore/javax/net/ssl/SSLSessionTest.java
index 67c83bf..ba048a8 100644
--- a/luni/src/test/java/libcore/javax/net/ssl/SSLSessionTest.java
+++ b/luni/src/test/java/libcore/javax/net/ssl/SSLSessionTest.java
@@ -96,7 +96,9 @@ public class SSLSessionTest extends TestCase {
assertTrue(s.invalid.getLastAccessedTime() > 0);
assertTrue(s.server.getLastAccessedTime() > 0);
assertTrue(s.client.getLastAccessedTime() > 0);
- assertTrue(Math.abs(s.server.getLastAccessedTime()
+ assertTrue("s.server.getLastAccessedTime()=" + s.server.getLastAccessedTime() + " " +
+ "s.client.getLastAccessedTime()=" + s.client.getLastAccessedTime(),
+ Math.abs(s.server.getLastAccessedTime()
- s.client.getLastAccessedTime()) < 1 * 1000);
assertTrue(s.server.getLastAccessedTime() >=
s.server.getCreationTime());
diff --git a/luni/src/test/java/libcore/javax/net/ssl/SSLSocketTest.java b/luni/src/test/java/libcore/javax/net/ssl/SSLSocketTest.java
index de12967..04b81b0 100644
--- a/luni/src/test/java/libcore/javax/net/ssl/SSLSocketTest.java
+++ b/luni/src/test/java/libcore/javax/net/ssl/SSLSocketTest.java
@@ -1283,7 +1283,7 @@ public class SSLSocketTest extends TestCase {
});
executor.shutdown();
try {
- toRead.setSoTimeout(5 * 1000);
+ toRead.setSoTimeout(10 * 1000);
toRead.getInputStream().read();
fail();
} catch (SocketTimeoutException e) {
diff --git a/luni/src/test/java/libcore/java/lang/ref/FinalizationTester.java b/support/src/test/java/libcore/java/lang/ref/FinalizationTester.java
index 66ac1a4..66ac1a4 100644
--- a/luni/src/test/java/libcore/java/lang/ref/FinalizationTester.java
+++ b/support/src/test/java/libcore/java/lang/ref/FinalizationTester.java