ICU-13661 Adding "scope" option to IcuTestErrorCode.

X-SVN-Rev: 41151
This commit is contained in:
Shane Carr 2018-03-24 05:41:10 +00:00
parent 7da9e75441
commit 4c07b01a46
2 changed files with 28 additions and 2 deletions

View 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 {

View 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