#include "unicode/tstdtmod.h"
#include "cmemory.h"
#include <stdio.h>
+#include "cstr.h"
+#include "cstring.h"
TestLog::~TestLog() {}
}
}
+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 {
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