]> git.saurik.com Git - apple/icu.git/blobdiff - icuSources/tools/ctestfw/tstdtmod.cpp
ICU-57131.0.1.tar.gz
[apple/icu.git] / icuSources / tools / ctestfw / tstdtmod.cpp
index 6c2308ad5e4d98fb602c63240b070f3cc119759c..4e71c45760207d554112e7f18b9c13cfa49f1fa6 100644 (file)
@@ -1,16 +1,74 @@
 /********************************************************************
  * COPYRIGHT: 
- * Copyright (c) 2002-2008, International Business Machines Corporation and
+ * Copyright (c) 2002-2014, International Business Machines Corporation and
  * others. All Rights Reserved.
  ********************************************************************/
 
 /* Created by weiv 05/09/2002 */
 
+#include <stdarg.h>
+
 #include "unicode/tstdtmod.h"
 #include "cmemory.h"
+#include <stdio.h>
 
 TestLog::~TestLog() {}
 
+IcuTestErrorCode::~IcuTestErrorCode() {
+    // Safe because our handleFailure() does not throw exceptions.
+    if(isFailure()) { handleFailure(); }
+}
+
+UBool IcuTestErrorCode::logIfFailureAndReset(const char *fmt, ...) {
+    if(isFailure()) {
+        char buffer[4000];
+        va_list ap;
+        va_start(ap, fmt);
+        vsprintf(buffer, fmt, ap);
+        va_end(ap);
+        UnicodeString msg(testName, -1, US_INV);
+        msg.append(UNICODE_STRING_SIMPLE(" failure: ")).append(UnicodeString(errorName(), -1, US_INV));
+        msg.append(UNICODE_STRING_SIMPLE(" - ")).append(UnicodeString(buffer, -1, US_INV));
+        testClass.errln(msg);
+        reset();
+        return TRUE;
+    } else {
+        reset();
+        return FALSE;
+    }
+}
+
+UBool IcuTestErrorCode::logDataIfFailureAndReset(const char *fmt, ...) {
+    if(isFailure()) {
+        char buffer[4000];
+        va_list ap;
+        va_start(ap, fmt);
+        vsprintf(buffer, fmt, ap);
+        va_end(ap);
+        UnicodeString msg(testName, -1, US_INV);
+        msg.append(UNICODE_STRING_SIMPLE(" failure: ")).append(UnicodeString(errorName(), -1, US_INV));
+        msg.append(UNICODE_STRING_SIMPLE(" - ")).append(UnicodeString(buffer, -1, US_INV));
+        testClass.dataerrln(msg);
+        reset();
+        return TRUE;
+    } else {
+        reset();
+        return FALSE;
+    }
+}
+
+void IcuTestErrorCode::handleFailure() const {
+    // testClass.errln("%s failure - %s", testName, errorName());
+    UnicodeString msg(testName, -1, US_INV);
+    msg.append(UNICODE_STRING_SIMPLE(" failure: ")).append(UnicodeString(errorName(), -1, US_INV));
+
+    if (get() == U_MISSING_RESOURCE_ERROR || get() == U_FILE_ACCESS_ERROR) {
+        testClass.dataerrln(msg);
+    } else {
+        testClass.errln(msg);
+    }
+}
+
 TestDataModule *TestDataModule::getTestDataModule(const char* name, TestLog& log, UErrorCode &status)
 {
   if(U_FAILURE(status)) {
@@ -158,7 +216,7 @@ RBTestDataModule::getTestBundle(const char* bundleName, UErrorCode &status)
     if (testBundle == NULL) {
         testBundle = ures_openDirect(icu_data, bundleName, &status);
         if (status != U_ZERO_ERROR) {
-            fLog.dataerrln(UNICODE_STRING_SIMPLE("[DATA] Could not load test data from resourcebundle: ") + UnicodeString(bundleName, -1, US_INV));
+            fLog.dataerrln(UNICODE_STRING_SIMPLE("Could not load test data from resourcebundle: ") + UnicodeString(bundleName, -1, US_INV));
             fDataTestValid = FALSE;
         }
     }