+#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);
+ }
+}