X-Git-Url: https://git.saurik.com/apple/icu.git/blobdiff_plain/374ca955a76ecab1204ca8bfa63ff9238d998416..586446045a9ad027ace9532db9e32639f87706dd:/icuSources/tools/ctestfw/tstdtmod.cpp?ds=sidebyside diff --git a/icuSources/tools/ctestfw/tstdtmod.cpp b/icuSources/tools/ctestfw/tstdtmod.cpp index 6846680a..4e71c457 100644 --- a/icuSources/tools/ctestfw/tstdtmod.cpp +++ b/icuSources/tools/ctestfw/tstdtmod.cpp @@ -1,13 +1,73 @@ /******************************************************************** * COPYRIGHT: - * Copyright (c) 2002-2004, 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 + #include "unicode/tstdtmod.h" #include "cmemory.h" +#include + +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) { @@ -71,7 +131,7 @@ RBTestDataModule::RBTestDataModule(const char* name, TestLog& log, UErrorCode& s fNumberOfTests = ures_getSize(fTestData); fInfoRB = ures_getByKey(fModuleBundle, "Info", NULL, &status); if(status != U_ZERO_ERROR) { - log.errln("Unable to initalize test data - missing mandatory description resources!"); + log.errln(UNICODE_STRING_SIMPLE("Unable to initalize test data - missing mandatory description resources!")); fDataTestValid = FALSE; } else { fInfo = new RBDataMap(fInfoRB, status); @@ -156,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.errln(UnicodeString("Failed: could not load test data from resourcebundle: ") + UnicodeString(bundleName)); + fLog.dataerrln(UNICODE_STRING_SIMPLE("Could not load test data from resourcebundle: ") + UnicodeString(bundleName, -1, US_INV)); fDataTestValid = FALSE; } }