From: Shane Carr <shane@unicode.org>
Date: Sat, 24 Mar 2018 05:41:10 +0000 (+0000)
Subject: ICU-13661 Adding "scope" option to IcuTestErrorCode.
X-Git-Tag: release-62-rc~200^2~74
X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=4c07b01a461ddf8eae53b21a63319b6d1279a1c4;p=icu

ICU-13661 Adding "scope" option to IcuTestErrorCode.

X-SVN-Rev: 41151
---

diff --git a/icu4c/source/tools/ctestfw/tstdtmod.cpp b/icu4c/source/tools/ctestfw/tstdtmod.cpp
index bb1008da6a6..260987a5372 100644
--- a/icu4c/source/tools/ctestfw/tstdtmod.cpp
+++ b/icu4c/source/tools/ctestfw/tstdtmod.cpp
@@ -13,6 +13,8 @@
 #include "unicode/tstdtmod.h"
 #include "cmemory.h"
 #include <stdio.h>
+#include "cstr.h"
+#include "cstring.h"
 
 TestLog::~TestLog() {}
 
@@ -59,11 +61,29 @@ UBool IcuTestErrorCode::logDataIfFailureAndReset(const char *fmt, ...) {
     }
 }
 
+void IcuTestErrorCode::setScope(const char* message) {
+    scopeMessage = message;
+}
+
+static char kScopeMessageBuf[256];
+
+void IcuTestErrorCode::setScope(const UnicodeString& message) {
+    CStr cstr(message);
+    const char* str = cstr();
+    uprv_strncpy(kScopeMessageBuf, str, 256);
+    kScopeMessageBuf[255] = 0; // ensure NUL-terminated
+    scopeMessage = kScopeMessageBuf;
+}
+
 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 (scopeMessage != nullptr) {
+        msg.append(UNICODE_STRING_SIMPLE(" scope: ")).append(UnicodeString(scopeMessage, -1, US_INV));
+    }
+
     if (get() == U_MISSING_RESOURCE_ERROR || get() == U_FILE_ACCESS_ERROR) {
         testClass.dataerrln(msg);
     } else {
diff --git a/icu4c/source/tools/ctestfw/unicode/testlog.h b/icu4c/source/tools/ctestfw/unicode/testlog.h
index 811f62fba14..32edc6f0d9e 100644
--- a/icu4c/source/tools/ctestfw/unicode/testlog.h
+++ b/icu4c/source/tools/ctestfw/unicode/testlog.h
@@ -32,17 +32,23 @@ public:
 
 class T_CTEST_EXPORT_API IcuTestErrorCode : public ErrorCode {
 public:
-    IcuTestErrorCode(TestLog &callingTestClass, const char *callingTestName) :
-        testClass(callingTestClass), testName(callingTestName) {}
+    IcuTestErrorCode(TestLog& callingTestClass, const char* callingTestName)
+            : testClass(callingTestClass), testName(callingTestName), scopeMessage(nullptr) {}
     virtual ~IcuTestErrorCode();
     // Returns TRUE if isFailure().
     UBool logIfFailureAndReset(const char *fmt, ...);
     UBool logDataIfFailureAndReset(const char *fmt, ...);
+
+    /** Sets an additional message string to be appended to failure output. */
+    void setScope(const char* message);
+    void setScope(const UnicodeString& message);
+
 protected:
     virtual void handleFailure() const;
 private:
     TestLog &testClass;
     const char *const testName;
+    const char* scopeMessage;
 };
 
 #endif