]> git.saurik.com Git - apple/icu.git/blobdiff - icuSources/test/intltest/nmfmtrt.cpp
ICU-461.12.tar.gz
[apple/icu.git] / icuSources / test / intltest / nmfmtrt.cpp
index 580918aec8efaeed6f86001c145484cafc5f7469..c2c962a7968ef7f61f5b5dd784fcc6ee0e19bbc7 100644 (file)
@@ -1,6 +1,6 @@
 /***********************************************************************
  * COPYRIGHT: 
- * Copyright (c) 1997-2007, International Business Machines Corporation
+ * Copyright (c) 1997-2010, International Business Machines Corporation
  * and others. All Rights Reserved.
  ***********************************************************************/
 
@@ -43,10 +43,14 @@ void NumberFormatRoundTripTest::runIndexedTest( int32_t index, UBool exec, const
 }
 
 UBool 
-NumberFormatRoundTripTest::failure(UErrorCode status, const char* msg)
+NumberFormatRoundTripTest::failure(UErrorCode status, const char* msg, UBool possibleDataError)
 {
     if(U_FAILURE(status)) {
-        errln(UnicodeString("FAIL: ") + msg + " failed, error " + u_errorName(status));
+        if (possibleDataError) {
+            dataerrln(UnicodeString("FAIL: ") + msg + " failed, error " + u_errorName(status));
+        } else {
+            errln(UnicodeString("FAIL: ") + msg + " failed, error " + u_errorName(status));
+        }
         return TRUE;
     }
 
@@ -90,19 +94,19 @@ NumberFormatRoundTripTest::start()
     logln("Default Locale");
 
     fmt = NumberFormat::createInstance(status);
-    if (!failure(status, "NumberFormat::createInstance")){
+    if (!failure(status, "NumberFormat::createInstance", TRUE)){
         test(fmt);
     }
     delete fmt;
 
     fmt = NumberFormat::createCurrencyInstance(status);
-    if (!failure(status, "NumberFormat::createCurrencyInstance")){
+    if (!failure(status, "NumberFormat::createCurrencyInstance", TRUE)){
         test(fmt);
     }
     delete fmt;
 
     fmt = NumberFormat::createPercentInstance(status);
-    if (!failure(status, "NumberFormat::createPercentInstance")){
+    if (!failure(status, "NumberFormat::createPercentInstance", TRUE)){
         test(fmt);
     }
     delete fmt;
@@ -178,15 +182,16 @@ NumberFormatRoundTripTest::test(NumberFormat *fmt)
         // I'll get around this by dividing by the multiplier to make sure
         // the double will stay in range.
         //if(fmt->getMultipler() == 1)
-        if(fmt->getDynamicClassID() == DecimalFormat::getStaticClassID())
+        DecimalFormat *df = dynamic_cast<DecimalFormat *>(fmt);
+        if(df != NULL)
         {
 #if !defined(OS390) && !defined(OS400)
             /* DBL_MAX/2 is here because randomDouble does a *2 in the math */
-            test(fmt, randomDouble(DBL_MAX/2.0) / ((DecimalFormat*)fmt)->getMultiplier());
+            test(fmt, randomDouble(DBL_MAX/2.0) / df->getMultiplier());
 #elif IEEE_754
-            test(fmt, randomDouble(1e75) / ((DecimalFormat*)fmt)->getMultiplier());   
+            test(fmt, randomDouble(1e75) / df->getMultiplier());   
 #else
-            test(fmt, randomDouble(1e65) / ((DecimalFormat*)fmt)->getMultiplier());   /*OS390*/
+            test(fmt, randomDouble(1e65) / df->getMultiplier());   /*OS390*/
 #endif
         }
 
@@ -225,8 +230,9 @@ void
 NumberFormatRoundTripTest::test(NumberFormat *fmt, const Formattable& value)
 {
     fmt->setMaximumFractionDigits(999);
-    if(fmt->getDynamicClassID() == DecimalFormat::getStaticClassID()) {
-        ((DecimalFormat *)fmt)->setRoundingIncrement(0.0);
+    DecimalFormat *df = dynamic_cast<DecimalFormat *>(fmt);
+    if(df != NULL) {
+        df->setRoundingIncrement(0.0);
     }
     UErrorCode status = U_ZERO_ERROR;
     UnicodeString s, s2, temp;