]> granicus.if.org Git - icu/commitdiff
ICU-13661 Adding "scope" option to IcuTestErrorCode.
authorShane Carr <shane@unicode.org>
Sat, 24 Mar 2018 05:41:10 +0000 (05:41 +0000)
committerShane Carr <shane@unicode.org>
Sat, 24 Mar 2018 05:41:10 +0000 (05:41 +0000)
X-SVN-Rev: 41151

icu4c/source/tools/ctestfw/tstdtmod.cpp
icu4c/source/tools/ctestfw/unicode/testlog.h

index bb1008da6a671d1d102b2390039c6b27f8aa58ec..260987a5372a3adb1d7ab62f7b9bc28ceee3e35f 100644 (file)
@@ -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 {
index 811f62fba1468c1b38b64aa0aa3938978d2cfaad..32edc6f0d9ecc59bebb758db3ca673bfe42565ae 100644 (file)
@@ -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