void CollationAPITest::TestKeywordValues() {
IcuTestErrorCode errorCode(*this, "TestKeywordValues");
LocalPointer<Collator> col(Collator::createInstance(Locale::getEnglish(), errorCode));
- if (errorCode.logIfFailureAndReset("English Collator creation failed")) {
+ if (errorCode.errIfFailureAndReset("English Collator creation failed")) {
return;
}
LocalPointer<StringEnumeration> kwEnum(
col->getKeywordValuesForLocale("collation", Locale::getEnglish(), TRUE, errorCode));
- if (errorCode.logIfFailureAndReset("Get Keyword Values for English Collator failed")) {
+ if (errorCode.errIfFailureAndReset("Get Keyword Values for English Collator failed")) {
return;
}
assertTrue("expect at least one collation tailoring for English", kwEnum->count(errorCode) > 0);
void CollationAPITest::TestSortKeyOverflow() {
IcuTestErrorCode errorCode(*this, "TestSortKeyOverflow()");
LocalPointer<Collator> col(Collator::createInstance(Locale::getEnglish(), errorCode));
- if (errorCode.logDataIfFailureAndReset("Collator::createInstance(English) failed")) {
+ if (errorCode.errDataIfFailureAndReset("Collator::createInstance(English) failed")) {
return;
}
col->setAttribute(UCOL_STRENGTH, UCOL_PRIMARY, errorCode);
IcuTestErrorCode errorCode(*this, "TestCloneBinary");
LocalPointer<Collator> root(Collator::createInstance(Locale::getRoot(), errorCode));
LocalPointer<Collator> coll(Collator::createInstance("de@collation=phonebook", errorCode));
- if(errorCode.logDataIfFailureAndReset("Collator::createInstance(de@collation=phonebook)")) {
+ if(errorCode.errDataIfFailureAndReset("Collator::createInstance(de@collation=phonebook)")) {
return;
}
RuleBasedCollator *rbRoot = dynamic_cast<RuleBasedCollator *>(root.getAlias());
assertEquals("rbc/primary: u-umlaut==ue", (int32_t)UCOL_EQUAL, rbc->compare(uUmlaut, ue, errorCode));
uint8_t bin[25000];
int32_t binLength = rbc->cloneBinary(bin, UPRV_LENGTHOF(bin), errorCode);
- if(errorCode.logDataIfFailureAndReset("rbc->cloneBinary()")) {
+ if(errorCode.errDataIfFailureAndReset("rbc->cloneBinary()")) {
return;
}
logln("rbc->cloneBinary() -> %d bytes", (int)binLength);
RuleBasedCollator rbc2(bin, binLength, rbRoot, errorCode);
- if(errorCode.logDataIfFailureAndReset("RuleBasedCollator(rbc binary)")) {
+ if(errorCode.errDataIfFailureAndReset("RuleBasedCollator(rbc binary)")) {
return;
}
assertEquals("rbc2.strength==primary", (int32_t)UCOL_PRIMARY, rbc2.getAttribute(UCOL_STRENGTH, errorCode));
assertTrue("rbc binary==rbc2 binary", binLength == bin2Length && memcmp(bin, bin2, binLength) == 0);
RuleBasedCollator rbc3(bin, -1, rbRoot, errorCode);
- if(errorCode.logDataIfFailureAndReset("RuleBasedCollator(rbc binary, length<0)")) {
+ if(errorCode.errDataIfFailureAndReset("RuleBasedCollator(rbc binary, length<0)")) {
return;
}
assertEquals("rbc3.strength==primary", (int32_t)UCOL_PRIMARY, rbc3.getAttribute(UCOL_STRENGTH, errorCode));
// and on the implementation code.
IcuTestErrorCode errorCode(*this, "TestIterNumeric");
RuleBasedCollator coll(UnicodeString("[reorder Hang Hani]"), errorCode);
- if(errorCode.logDataIfFailureAndReset("RuleBasedCollator constructor")) {
+ if(errorCode.errDataIfFailureAndReset("RuleBasedCollator constructor")) {
return;
}
coll.setAttribute(UCOL_NUMERIC_COLLATION, UCOL_ON, errorCode);
{
RuleBasedCollator coll(u"&[before 1]\uFDD1€<*\u4E00-\u9FFF", errorCode);
assertTrue("tailored Han before currency", coll.compare(u"\u4E00", u"$", errorCode) < 0);
- errorCode.logIfFailureAndReset(
+ errorCode.errIfFailureAndReset(
"unexpected exception for tailoring many characters at the end of symbols");
}
}
void BiDiConformanceTest::TestBidiTest() {
IcuTestErrorCode errorCode(*this, "TestBidiTest");
const char *sourceTestDataPath=getSourceTestData(errorCode);
- if(errorCode.logIfFailureAndReset("unable to find the source/test/testdata "
+ if(errorCode.errIfFailureAndReset("unable to find the source/test/testdata "
"folder (getSourceTestData())")) {
return;
}
LocalUBiDiPointer ubidi(ubidi_open());
ubidi_setClassCallback(ubidi.getAlias(), biDiConfUBiDiClassCallback, NULL,
NULL, NULL, errorCode);
- if(errorCode.logIfFailureAndReset("ubidi_setClassCallback()")) {
+ if(errorCode.errIfFailureAndReset("ubidi_setClassCallback()")) {
return;
}
lineNumber=0;
ubidi_setPara(ubidi.getAlias(), inputString.getBuffer(), inputString.length(),
paraLevels[i], NULL, errorCode);
const UBiDiLevel *actualLevels=ubidi_getLevels(ubidi.getAlias(), errorCode);
- if(errorCode.logIfFailureAndReset("ubidi_setPara() or ubidi_getLevels()")) {
+ if(errorCode.errIfFailureAndReset("ubidi_setPara() or ubidi_getLevels()")) {
errln("Input line %d: %s", (int)lineNumber, line);
return;
}
void BiDiConformanceTest::TestBidiCharacterTest() {
IcuTestErrorCode errorCode(*this, "TestBidiCharacterTest");
const char *sourceTestDataPath=getSourceTestData(errorCode);
- if(errorCode.logIfFailureAndReset("unable to find the source/test/testdata "
+ if(errorCode.errIfFailureAndReset("unable to find the source/test/testdata "
"folder (getSourceTestData())")) {
return;
}
// Parse the code point string in field 0.
UChar *buffer=inputString.getBuffer(200);
int32_t length=u_parseString(start, buffer, inputString.getCapacity(), NULL, errorCode);
- if(errorCode.logIfFailureAndReset("Invalid string in field 0")) {
+ if(errorCode.errIfFailureAndReset("Invalid string in field 0")) {
errln("Input line %d: %s", (int)lineNumber, line);
inputString.remove();
continue;
ubidi_setPara(ubidi.getAlias(), inputString.getBuffer(), inputString.length(),
paraLevel, NULL, errorCode);
const UBiDiLevel *actualLevels=ubidi_getLevels(ubidi.getAlias(), errorCode);
- if(errorCode.logIfFailureAndReset("ubidi_setPara() or ubidi_getLevels()")) {
+ if(errorCode.errIfFailureAndReset("ubidi_setPara() or ubidi_getLevels()")) {
errln("Input line %d: %s", (int)lineNumber, line);
continue;
}
// and loop over each run's indexes, but that seems unnecessary for this test code.
for(i=visualIndex=0; i<resultLength; ++i) {
int32_t logicalIndex=ubidi_getLogicalIndex(ubidi, i, errorCode);
- if(errorCode.logIfFailureAndReset("ubidi_getLogicalIndex()")) {
+ if(errorCode.errIfFailureAndReset("ubidi_getLogicalIndex()")) {
errln("Input line %d: %s", (int)lineNumber, line);
return FALSE;
}
trie->next('n');
IcuTestErrorCode errorCode(*this, "TestIteratorFromBranch()");
BytesTrie::Iterator iter(*trie, 0, errorCode);
- if(errorCode.logIfFailureAndReset("BytesTrie::Iterator(trie) constructor")) {
+ if(errorCode.errIfFailureAndReset("BytesTrie::Iterator(trie) constructor")) {
return;
}
// Expected data: Same as in buildMonthsTrie(), except only the suffixes
trie->next('a');
IcuTestErrorCode errorCode(*this, "TestIteratorFromLinearMatch()");
BytesTrie::Iterator iter(*trie, 0, errorCode);
- if(errorCode.logIfFailureAndReset("BytesTrie::Iterator(trie) constructor")) {
+ if(errorCode.errIfFailureAndReset("BytesTrie::Iterator(trie) constructor")) {
return;
}
// Expected data: Same as in buildMonthsTrie(), except only the suffixes
}
IcuTestErrorCode errorCode(*this, "TestTruncatingIteratorFromRoot()");
BytesTrie::Iterator iter(*trie, 4, errorCode);
- if(errorCode.logIfFailureAndReset("BytesTrie::Iterator(trie) constructor")) {
+ if(errorCode.errIfFailureAndReset("BytesTrie::Iterator(trie) constructor")) {
return;
}
// Expected data: Same as in buildMonthsTrie(), except only the first 4 characters
IcuTestErrorCode errorCode(*this, "TestTruncatingIteratorFromLinearMatchShort()");
// Truncate within the linear-match node.
BytesTrie::Iterator iter(*trie, 2, errorCode);
- if(errorCode.logIfFailureAndReset("BytesTrie::Iterator(trie) constructor")) {
+ if(errorCode.errIfFailureAndReset("BytesTrie::Iterator(trie) constructor")) {
return;
}
static const StringAndValue expected[]={
IcuTestErrorCode errorCode(*this, "TestTruncatingIteratorFromLinearMatchLong()");
// Truncate after the linear-match node.
BytesTrie::Iterator iter(*trie, 3, errorCode);
- if(errorCode.logIfFailureAndReset("BytesTrie::Iterator(trie) constructor")) {
+ if(errorCode.errIfFailureAndReset("BytesTrie::Iterator(trie) constructor")) {
return;
}
static const StringAndValue expected[]={
}
StringPiece sp=builder_->buildStringPiece(buildOption, errorCode);
LocalPointer<BytesTrie> trie(builder_->build(buildOption, errorCode));
- if(!errorCode.logIfFailureAndReset("add()/build()")) {
+ if(!errorCode.errIfFailureAndReset("add()/build()")) {
builder_->add("zzz", 999, errorCode);
if(errorCode.reset()!=U_NO_WRITE_PERMISSION) {
errln("builder.build().add(zzz) did not set U_NO_WRITE_PERMISSION");
const StringAndValue data[], int32_t dataLength) {
IcuTestErrorCode errorCode(*this, "checkIterator()");
BytesTrie::Iterator iter(trie, 0, errorCode);
- if(errorCode.logIfFailureAndReset("BytesTrie::Iterator(trie) constructor")) {
+ if(errorCode.errIfFailureAndReset("BytesTrie::Iterator(trie) constructor")) {
return;
}
checkIterator(iter, data, dataLength);
break;
}
UBool hasNext=iter.next(errorCode);
- if(errorCode.logIfFailureAndReset("trie iterator next() for item %d: %s", (int)i, data[i].s)) {
+ if(errorCode.errIfFailureAndReset("trie iterator next() for item %d: %s", (int)i, data[i].s)) {
break;
}
if(!hasNext) {
errln("trie iterator hasNext()=TRUE after all items");
}
UBool hasNext=iter.next(errorCode);
- errorCode.logIfFailureAndReset("trie iterator next() after all items");
+ errorCode.errIfFailureAndReset("trie iterator next() after all items");
if(hasNext) {
errln("trie iterator next()=TRUE after all items");
}
IcuTestErrorCode errorCode(*this, "TestImplicits");
const CollationData *cd = CollationRoot::getData(errorCode);
- if(errorCode.logDataIfFailureAndReset("CollationRoot::getData()")) {
+ if(errorCode.errDataIfFailureAndReset("CollationRoot::getData()")) {
return;
}
errorCode);
UnicodeSet inOrder(someHanInCPOrder);
inOrder.addAll(unassigned).freeze();
- if(errorCode.logIfFailureAndReset("UnicodeSet")) {
+ if(errorCode.errIfFailureAndReset("UnicodeSet")) {
return;
}
const UnicodeSet *sets[] = { &coreHan, &otherHan, &unassigned };
ci.setText(s.getBuffer(), s.getBuffer() + s.length());
int64_t ce = ci.nextCE(errorCode);
int64_t ce2 = ci.nextCE(errorCode);
- if(errorCode.logIfFailureAndReset("CollationIterator.nextCE()")) {
+ if(errorCode.errIfFailureAndReset("CollationIterator.nextCE()")) {
return;
}
if(ce == Collation::NO_CE || ce2 != Collation::NO_CE) {
void CollationTest::TestNulTerminated() {
IcuTestErrorCode errorCode(*this, "TestNulTerminated");
const CollationData *data = CollationRoot::getData(errorCode);
- if(errorCode.logDataIfFailureAndReset("CollationRoot::getData()")) {
+ if(errorCode.errDataIfFailureAndReset("CollationRoot::getData()")) {
return;
}
for(int32_t i = 0;; ++i) {
int64_t ce1 = ci1.nextCE(errorCode);
int64_t ce2 = ci2.nextCE(errorCode);
- if(errorCode.logIfFailureAndReset("CollationIterator.nextCE()")) {
+ if(errorCode.errIfFailureAndReset("CollationIterator.nextCE()")) {
return;
}
if(ce1 != ce2) {
void CollationTest::TestFCD() {
IcuTestErrorCode errorCode(*this, "TestFCD");
const CollationData *data = CollationRoot::getData(errorCode);
- if(errorCode.logDataIfFailureAndReset("CollationRoot::getData()")) {
+ if(errorCode.errDataIfFailureAndReset("CollationRoot::getData()")) {
return;
}
};
FCDUTF16CollationIterator u16ci(data, FALSE, s, s, NULL);
- if(errorCode.logIfFailureAndReset("FCDUTF16CollationIterator constructor")) {
+ if(errorCode.errIfFailureAndReset("FCDUTF16CollationIterator constructor")) {
return;
}
CodePointIterator cpi(cp, UPRV_LENGTHOF(cp));
UnicodeString(s).toUTF8String(utf8);
FCDUTF8CollationIterator u8ci(data, FALSE,
reinterpret_cast<const uint8_t *>(utf8.c_str()), 0, -1);
- if(errorCode.logIfFailureAndReset("FCDUTF8CollationIterator constructor")) {
+ if(errorCode.errIfFailureAndReset("FCDUTF8CollationIterator constructor")) {
return;
}
checkFCD("FCDUTF8CollationIterator", u8ci, cpi);
UCharIterator iter;
uiter_setString(&iter, s, UPRV_LENGTHOF(s) - 1); // -1: without the terminating NUL
FCDUIterCollationIterator uici(data, FALSE, iter, 0);
- if(errorCode.logIfFailureAndReset("FCDUIterCollationIterator constructor")) {
+ if(errorCode.errIfFailureAndReset("FCDUIterCollationIterator constructor")) {
return;
}
checkFCD("FCDUIterCollationIterator", uici, cpi);
void CollationTest::TestRootElements() {
IcuTestErrorCode errorCode(*this, "TestRootElements");
const CollationData *root = CollationRoot::getData(errorCode);
- if(errorCode.logDataIfFailureAndReset("CollationRoot::getData()")) {
+ if(errorCode.errDataIfFailureAndReset("CollationRoot::getData()")) {
return;
}
CollationRootElements rootElements(root->rootElements, root->rootElementsLength);
void CollationTest::TestTailoredElements() {
IcuTestErrorCode errorCode(*this, "TestTailoredElements");
const CollationData *root = CollationRoot::getData(errorCode);
- if(errorCode.logDataIfFailureAndReset("CollationRoot::getData()")) {
+ if(errorCode.errDataIfFailureAndReset("CollationRoot::getData()")) {
return;
}
CollationRootElements rootElements(root->rootElements, root->rootElementsLength);
UHashtable *prevLocales = uhash_open(uhash_hashChars, uhash_compareChars, NULL, errorCode);
- if(errorCode.logIfFailureAndReset("failed to create a hash table")) {
+ if(errorCode.errIfFailureAndReset("failed to create a hash table")) {
return;
}
uhash_setKeyDeleter(prevLocales, uprv_free);
localeWithType.setKeywordValue("collation", type, errorCode);
errorCode.assertSuccess();
LocalPointer<Collator> coll(Collator::createInstance(localeWithType, errorCode));
- if(errorCode.logIfFailureAndReset("Collator::createInstance(%s)",
+ if(errorCode.errIfFailureAndReset("Collator::createInstance(%s)",
localeWithType.getName())) {
continue;
}
fcd = Normalizer2Factory::getFCDInstance(errorCode);
nfd = Normalizer2::getNFDInstance(errorCode);
- if(errorCode.logDataIfFailureAndReset("Normalizer2Factory::getFCDInstance() or getNFDInstance()")) {
+ if(errorCode.errDataIfFailureAndReset("Normalizer2Factory::getFCDInstance() or getNFDInstance()")) {
return;
}
path.appendPathPart("collationtest.txt", errorCode);
const char *codePage = "UTF-8";
LocalUCHARBUFPointer f(ucbuf_open(path.data(), &codePage, TRUE, FALSE, errorCode));
- if(errorCode.logIfFailureAndReset("ucbuf_open(collationtest.txt)")) {
+ if(errorCode.errIfFailureAndReset("ucbuf_open(collationtest.txt)")) {
return;
}
// Read a new line if necessary.
// actualPattern, locale);
LocalPointer<DateTimePatternGenerator> generator(
DateTimePatternGenerator::createInstance(locale, errorCode));
- if(errorCode.logDataIfFailureAndReset("DateTimePatternGenerator::createInstance() failed for locale ID \"%s\"", EXPECTED[i].localeID)) {
+ if(errorCode.errDataIfFailureAndReset("DateTimePatternGenerator::createInstance() failed for locale ID \"%s\"", EXPECTED[i].localeID)) {
continue;
}
UnicodeString pattern = generator->getBestPattern(actualPattern, errorCode);
SimpleDateFormat date1(pattern, locale, errorCode);
SimpleDateFormat date2(pattern, locale, errorCode);
date2.adoptCalendar(Calendar::createInstance(locale, errorCode));
- if(errorCode.logIfFailureAndReset("DateFormat::getInstanceForSkeleton() failed")) {
+ if(errorCode.errIfFailureAndReset("DateFormat::getInstanceForSkeleton() failed")) {
errln(" for actualPattern \"%s\" & locale ID \"%s\"",
EXPECTED[i].actualPattern, EXPECTED[i].localeID);
continue;
switch (index) {
case 0: name = "TestErrorCode"; if (exec) TestErrorCode(); break;
case 1: name = "TestSubclass"; if (exec) TestSubclass(); break;
+ case 2: name = "TestIcuTestErrorCode"; if (exec) TestIcuTestErrorCode(); break;
default: name = ""; break; //needed to end loop
}
}
}
}
+class IcuTestErrorCodeTestHelper : public IntlTest {
+ public:
+ void errln( const UnicodeString &message ) U_OVERRIDE {
+ test->assertEquals("Message for Error", expectedErrln, message);
+ if (expectedDataErr) {
+ test->errln("Got non-data error, but expected data error");
+ }
+ }
+
+ void dataerrln( const UnicodeString &message ) U_OVERRIDE {
+ test->assertEquals("Message for Error", expectedErrln, message);
+ if (!expectedDataErr) {
+ test->errln("Got data error, but expected non-data error");
+ }
+ }
+
+ IntlTest* test;
+ UBool expectedDataErr;
+ UnicodeString expectedErrln;
+};
+
+void ErrorCodeTest::TestIcuTestErrorCode() {
+ IcuTestErrorCodeTestHelper helper;
+ helper.test = this;
+
+ // Test destructor message
+ helper.expectedErrln = u"AAA failure: U_ILLEGAL_PAD_POSITION";
+ helper.expectedDataErr = FALSE;
+ {
+ IcuTestErrorCode testStatus(helper, "AAA");
+ testStatus.set(U_ILLEGAL_PAD_POSITION);
+ }
+
+ // Test destructor message with scope
+ helper.expectedErrln = u"BBB failure: U_ILLEGAL_PAD_POSITION scope: foo";
+ helper.expectedDataErr = FALSE;
+ {
+ IcuTestErrorCode testStatus(helper, "BBB");
+ testStatus.setScope("foo");
+ testStatus.set(U_ILLEGAL_PAD_POSITION);
+ }
+
+ // Check errIfFailure message with scope
+ helper.expectedErrln = u"CCC failure: U_ILLEGAL_PAD_POSITION scope: foo";
+ helper.expectedDataErr = FALSE;
+ {
+ IcuTestErrorCode testStatus(helper, "CCC");
+ testStatus.setScope("foo");
+ testStatus.set(U_ILLEGAL_PAD_POSITION);
+ testStatus.errIfFailureAndReset();
+ helper.expectedErrln = u"CCC failure: U_ILLEGAL_CHAR_FOUND scope: foo - 5.4300";
+ testStatus.set(U_ILLEGAL_CHAR_FOUND);
+ testStatus.errIfFailureAndReset("%6.4f", 5.43);
+ }
+
+ // Check errDataIfFailure message without scope
+ helper.expectedErrln = u"DDD failure: U_ILLEGAL_PAD_POSITION";
+ helper.expectedDataErr = TRUE;
+ {
+ IcuTestErrorCode testStatus(helper, "DDD");
+ testStatus.set(U_ILLEGAL_PAD_POSITION);
+ testStatus.errDataIfFailureAndReset();
+ helper.expectedErrln = u"DDD failure: U_ILLEGAL_CHAR_FOUND - 5.4300";
+ testStatus.set(U_ILLEGAL_CHAR_FOUND);
+ testStatus.errDataIfFailureAndReset("%6.4f", 5.43);
+ }
+}
+
+
class LocalPointerTest : public IntlTest {
public:
LocalPointerTest() {}
static const char *const encoding="ISO-8859-1";
LocalUConverterSelectorPointer sel(
ucnvsel_open(&encoding, 1, NULL, UCNV_ROUNDTRIP_SET, errorCode));
- if(errorCode.logIfFailureAndReset("ucnvsel_open()")) {
+ if(errorCode.errIfFailureAndReset("ucnvsel_open()")) {
return;
}
if(sel.isNull()) {
#if !UCONFIG_NO_FORMATTING
LocalUCalendarPointer cal(ucal_open(NULL, 0, "root", UCAL_GREGORIAN, errorCode));
- if(errorCode.logDataIfFailureAndReset("ucal_open()")) {
+ if(errorCode.errDataIfFailureAndReset("ucal_open()")) {
return;
}
if(cal.isNull()) {
}
LocalUDateTimePatternGeneratorPointer patgen(udatpg_open("root", errorCode));
- if(errorCode.logDataIfFailureAndReset("udatpg_open()")) {
+ if(errorCode.errDataIfFailureAndReset("udatpg_open()")) {
return;
}
if(patgen.isNull()) {
}
LocalULocaleDisplayNamesPointer ldn(uldn_open("de-CH", ULDN_STANDARD_NAMES, errorCode));
- if(errorCode.logIfFailureAndReset("uldn_open()")) {
+ if(errorCode.errIfFailureAndReset("uldn_open()")) {
return;
}
if(ldn.isNull()) {
UnicodeString hello=UNICODE_STRING_SIMPLE("Hello {0}!");
LocalUMessageFormatPointer msg(
umsg_open(hello.getBuffer(), hello.length(), "root", NULL, errorCode));
- if(errorCode.logIfFailureAndReset("umsg_open()")) {
+ if(errorCode.errIfFailureAndReset("umsg_open()")) {
return;
}
if(msg.isNull()) {
const UNormalizer2 *nfc=unorm2_getNFCInstance(errorCode);
UnicodeSet emptySet;
LocalUNormalizer2Pointer fn2(unorm2_openFiltered(nfc, emptySet.toUSet(), errorCode));
- if(errorCode.logIfFailureAndReset("unorm2_openFiltered()")) {
+ if(errorCode.errIfFailureAndReset("unorm2_openFiltered()")) {
return;
}
if(fn2.isNull()) {
#if !UCONFIG_NO_IDNA
LocalUIDNAPointer idna(uidna_openUTS46(0, errorCode));
- if(errorCode.logIfFailureAndReset("uidna_openUTS46()")) {
+ if(errorCode.errIfFailureAndReset("uidna_openUTS46()")) {
return;
}
if(idna.isNull()) {
UnicodeString pattern=UNICODE_STRING_SIMPLE("abc|xy+z");
LocalURegularExpressionPointer regex(
uregex_open(pattern.getBuffer(), pattern.length(), 0, NULL, errorCode));
- if(errorCode.logIfFailureAndReset("uregex_open()")) {
+ if(errorCode.errIfFailureAndReset("uregex_open()")) {
return;
}
if(regex.isNull()) {
UnicodeString id=UNICODE_STRING_SIMPLE("Grek-Latn");
LocalUTransliteratorPointer trans(
utrans_openU(id.getBuffer(), id.length(), UTRANS_FORWARD, NULL, 0, NULL, errorCode));
- if(errorCode.logIfFailureAndReset("utrans_open()")) {
+ if(errorCode.errIfFailureAndReset("utrans_open()")) {
return;
}
if(trans.isNull()) {
IcuTestErrorCode errorCode(*this, "TestLocalXyzPointerMoveSwap");
const UNormalizer2 *nfc=unorm2_getNFCInstance(errorCode);
const UNormalizer2 *nfd=unorm2_getNFDInstance(errorCode);
- if(errorCode.logIfFailureAndReset("unorm2_getNF[CD]Instance()")) {
+ if(errorCode.errIfFailureAndReset("unorm2_getNF[CD]Instance()")) {
return;
}
UnicodeSet emptySet;
UNormalizer2 *p2 = unorm2_openFiltered(nfd, emptySet.toUSet(), errorCode);
LocalUNormalizer2Pointer f1(p1);
LocalUNormalizer2Pointer f2(p2);
- if(errorCode.logIfFailureAndReset("unorm2_openFiltered()")) {
+ if(errorCode.errIfFailureAndReset("unorm2_openFiltered()")) {
return;
}
if(f1.isNull() || f2.isNull()) {
IcuTestErrorCode errorCode(*this, "TestLocalXyzPointerNull/LocalUCalendarPointer");
LocalUCalendarPointer null;
LocalUCalendarPointer cal(ucal_open(NULL, 0, "root", UCAL_GREGORIAN, errorCode));
- if(!errorCode.logDataIfFailureAndReset("ucal_open()")) {
+ if(!errorCode.errDataIfFailureAndReset("ucal_open()")) {
cal.adoptInstead(NULL);
}
}
LocalURegularExpressionPointer null;
LocalURegularExpressionPointer regex(
uregex_open(pattern.getBuffer(), pattern.length(), 0, NULL, errorCode));
- if(!errorCode.logDataIfFailureAndReset("urege_open()")) {
+ if(!errorCode.errDataIfFailureAndReset("urege_open()")) {
regex.adoptInstead(NULL);
}
}
LocalUTransliteratorPointer null;
LocalUTransliteratorPointer trans(
utrans_openU(id.getBuffer(), id.length(), UTRANS_FORWARD, NULL, 0, NULL, errorCode));
- if(!errorCode.logDataIfFailureAndReset("utrans_openU()")) {
+ if(!errorCode.errDataIfFailureAndReset("utrans_openU()")) {
trans.adoptInstead(NULL);
}
}
void runIndexedTest(int32_t index, UBool exec, const char* &name, char* par = NULL);
void TestErrorCode();
void TestSubclass();
+ void TestIcuTestErrorCode();
};
#endif
UnicodeString result;
FieldPositionIterator positions;
df.format(NAN, result, &positions, errorCode);
- errorCode.logIfFailureAndReset("DecimalFormat.format(NAN, FieldPositionIterator) failed");
+ errorCode.errIfFailureAndReset("DecimalFormat.format(NAN, FieldPositionIterator) failed");
FieldPosition fp;
while (positions.next(fp)) {
// Should not loop forever
IcuTestErrorCode errorCode(*this, "ordinalFormatTest");
UnicodeString pattern("one{#st file}two{#nd file}few{#rd file}other{#th file}");
PluralFormat pf(Locale::getEnglish(), UPLURAL_TYPE_ORDINAL, pattern, errorCode);
- if (errorCode.logDataIfFailureAndReset("PluralFormat(en, UPLURAL_TYPE_ORDINAL, pattern) failed")) {
+ if (errorCode.errDataIfFailureAndReset("PluralFormat(en, UPLURAL_TYPE_ORDINAL, pattern) failed")) {
return;
}
UnicodeString result = pf.format((int32_t)321, errorCode);
- if (!errorCode.logIfFailureAndReset("PluralFormat.format(321) failed") &&
+ if (!errorCode.errIfFailureAndReset("PluralFormat.format(321) failed") &&
result != UNICODE_STRING_SIMPLE("321st file")) {
errln(UnicodeString("PluralFormat.format(321) wrong result string: ") + result);
}
result = pf.format((int32_t)22, errorCode);
- if (!errorCode.logIfFailureAndReset("PluralFormat.format(22) failed") &&
+ if (!errorCode.errIfFailureAndReset("PluralFormat.format(22) failed") &&
result != UNICODE_STRING_SIMPLE("22nd file")) {
errln(UnicodeString("PluralFormat.format(22) wrong result string: ") + result);
}
result = pf.format((int32_t)3, errorCode);
- if (!errorCode.logIfFailureAndReset("PluralFormat.format(3) failed") &&
+ if (!errorCode.errIfFailureAndReset("PluralFormat.format(3) failed") &&
result != UNICODE_STRING_SIMPLE("3rd file")) {
errln(UnicodeString("PluralFormat.format(3) wrong result string: ") + result);
}
// Code coverage: Use the other new-for-UPluralType constructor as well.
PluralFormat pf2(Locale::getEnglish(), UPLURAL_TYPE_ORDINAL, errorCode);
pf2.applyPattern(pattern, errorCode);
- if (errorCode.logIfFailureAndReset("PluralFormat(en, UPLURAL_TYPE_ORDINAL, pattern) failed")) {
+ if (errorCode.errIfFailureAndReset("PluralFormat(en, UPLURAL_TYPE_ORDINAL, pattern) failed")) {
return;
}
result = pf2.format((int32_t)456, errorCode);
- if (!errorCode.logIfFailureAndReset("PluralFormat.format(456) failed") &&
+ if (!errorCode.errIfFailureAndReset("PluralFormat.format(456) failed") &&
result != UNICODE_STRING_SIMPLE("456th file")) {
errln(UnicodeString("PluralFormat.format(456) wrong result string: ") + result);
}
result = pf2.format((int32_t)111, errorCode);
- if (!errorCode.logIfFailureAndReset("PluralFormat.format(111) failed") &&
+ if (!errorCode.errIfFailureAndReset("PluralFormat.format(111) failed") &&
result != UNICODE_STRING_SIMPLE("111th file")) {
errln(UnicodeString("PluralFormat.format(111) wrong result string: ") + result);
}
void PluralRulesTest::testOrdinal() {
IcuTestErrorCode errorCode(*this, "testOrdinal");
LocalPointer<PluralRules> pr(PluralRules::forLocale("en", UPLURAL_TYPE_ORDINAL, errorCode));
- if (errorCode.logIfFailureAndReset("PluralRules::forLocale(en, UPLURAL_TYPE_ORDINAL) failed")) {
+ if (errorCode.errIfFailureAndReset("PluralRules::forLocale(en, UPLURAL_TYPE_ORDINAL) failed")) {
return;
}
UnicodeString keyword = pr->select(2.);
void TestMessageFormat::testGetFormatNames() {
IcuTestErrorCode errorCode(*this, "testGetFormatNames");
MessageFormat msgfmt("Hello, {alice,number} {oops,date,full} {zip,spellout} World.", Locale::getRoot(), errorCode);
- if(errorCode.logDataIfFailureAndReset("MessageFormat() failed")) {
+ if(errorCode.errDataIfFailureAndReset("MessageFormat() failed")) {
return;
}
LocalPointer<StringEnumeration> names(msgfmt.getFormatNames(errorCode));
- if(errorCode.logIfFailureAndReset("msgfmt.getFormatNames() failed")) {
+ if(errorCode.errIfFailureAndReset("msgfmt.getFormatNames() failed")) {
return;
}
const UnicodeString *name;
// ICU 4.8 allows and ignores white space around argument names and numbers.
IcuTestErrorCode errorCode(*this, "TestTrimArgumentName");
MessageFormat m("a { 0 , number , '#,#'#.0 } z", Locale::getEnglish(), errorCode);
- if (errorCode.logDataIfFailureAndReset("Unable to instantiate MessageFormat")) {
+ if (errorCode.errDataIfFailureAndReset("Unable to instantiate MessageFormat")) {
return;
}
Formattable args[1] = { (int32_t)2 };
"{0,plural,one{1 file}other{# files}}, "
"{0,selectordinal,one{#st file}two{#nd file}few{#rd file}other{#th file}}",
Locale::getEnglish(), errorCode);
- if (errorCode.logDataIfFailureAndReset("Unable to instantiate MessageFormat")) {
+ if (errorCode.errDataIfFailureAndReset("Unable to instantiate MessageFormat")) {
return;
}
Formattable args[1] = { (int32_t)21 };
assertEquals("plural-and-ordinal format(3) failed", "3 files, 3rd file",
m.format(args, 1, result.remove(), ignore, errorCode), TRUE);
- errorCode.logDataIfFailureAndReset("");
+ errorCode.errDataIfFailureAndReset("");
}
void TestMessageFormat::TestDecimals() {
IcuTestErrorCode errorCode(*this, "testLastResortData");
LocalPointer<DecimalFormatSymbols> lastResort(
DecimalFormatSymbols::createWithLastResortData(errorCode));
- if(errorCode.logIfFailureAndReset("DecimalFormatSymbols::createWithLastResortData() failed")) {
+ if(errorCode.errIfFailureAndReset("DecimalFormatSymbols::createWithLastResortData() failed")) {
return;
}
DecimalFormatSymbols root(Locale::getRoot(), errorCode);
- if(errorCode.logDataIfFailureAndReset("DecimalFormatSymbols(root) failed")) {
+ if(errorCode.errDataIfFailureAndReset("DecimalFormatSymbols(root) failed")) {
return;
}
// Note: It is not necessary that the last resort data matches the root locale,
testcase cas = cases[i];
Locale loc(cas.locid);
LocalPointer<NumberingSystem> ns(NumberingSystem::createInstanceByName(cas.nsname, errorCode));
- if (errorCode.logDataIfFailureAndReset("NumberingSystem failed")) {
+ if (errorCode.errDataIfFailureAndReset("NumberingSystem failed")) {
return;
}
UnicodeString expected1(cas.expected1);
UnicodeString expected2(cas.expected2);
DecimalFormatSymbols dfs(loc, *ns, errorCode);
- if (errorCode.logDataIfFailureAndReset("DecimalFormatSymbols failed")) {
+ if (errorCode.errDataIfFailureAndReset("DecimalFormatSymbols failed")) {
return;
}
Verify(1234.56, "#,##0.##", dfs, expected1);
skipSets[UNORM_NFKD].applyPattern(UNICODE_STRING_SIMPLE("[:NFKD_Inert:]"), errorCode);
skipSets[UNORM_NFC].applyPattern(UNICODE_STRING_SIMPLE("[:NFC_Inert:]"), errorCode);
skipSets[UNORM_NFKC].applyPattern(UNICODE_STRING_SIMPLE("[:NFKC_Inert:]"), errorCode);
- if(errorCode.logDataIfFailureAndReset("UnicodeSet(NF..._Inert) failed")) {
+ if(errorCode.errDataIfFailureAndReset("UnicodeSet(NF..._Inert) failed")) {
return;
}
const Normalizer2 *customNorm2=
Normalizer2::getInstance(loadTestData(errorCode), "testnorm",
UNORM2_COMPOSE, errorCode);
- if(errorCode.logDataIfFailureAndReset("unable to load testdata/testnorm.nrm")) {
+ if(errorCode.errDataIfFailureAndReset("unable to load testdata/testnorm.nrm")) {
return;
}
for(int32_t i=0; i<UPRV_LENGTHOF(pairs); ++i) {
const Normalizer2 *customNorm2=
Normalizer2::getInstance(loadTestData(errorCode), "testnorm",
UNORM2_COMPOSE_CONTIGUOUS, errorCode);
- if(errorCode.logDataIfFailureAndReset("unable to load testdata/testnorm.nrm")) {
+ if(errorCode.errDataIfFailureAndReset("unable to load testdata/testnorm.nrm")) {
return;
}
for(int32_t i=0; i<UPRV_LENGTHOF(pairs); ++i) {
BasicNormalizerTest::TestNormalizeUTF8WithEdits() {
IcuTestErrorCode errorCode(*this, "TestNormalizeUTF8WithEdits");
const Normalizer2 *nfkc_cf=Normalizer2::getNFKCCasefoldInstance(errorCode);
- if(errorCode.logDataIfFailureAndReset("Normalizer2::getNFKCCasefoldInstance() call failed")) {
+ if(errorCode.errDataIfFailureAndReset("Normalizer2::getNFKCCasefoldInstance() call failed")) {
return;
}
static const char *const src =
IcuTestErrorCode errorCode(*this, "TestLowMappingToEmpty_D");
const Normalizer2 *n2 = Normalizer2::getInstance(
nullptr, "nfkc_cf", UNORM2_DECOMPOSE, errorCode);
- if (errorCode.logDataIfFailureAndReset("Normalizer2::getInstance() call failed")) {
+ if (errorCode.errDataIfFailureAndReset("Normalizer2::getInstance() call failed")) {
return;
}
checkLowMappingToEmpty(*n2);
IcuTestErrorCode errorCode(*this, "TestLowMappingToEmpty_FCD");
const Normalizer2 *n2 = Normalizer2::getInstance(
nullptr, "nfkc_cf", UNORM2_FCD, errorCode);
- if (errorCode.logDataIfFailureAndReset("Normalizer2::getInstance() call failed")) {
+ if (errorCode.errDataIfFailureAndReset("Normalizer2::getInstance() call failed")) {
return;
}
checkLowMappingToEmpty(*n2);
BasicNormalizerTest::TestNormalizeIllFormedText() {
IcuTestErrorCode errorCode(*this, "TestNormalizeIllFormedText");
const Normalizer2 *nfkc_cf = Normalizer2::getNFKCCasefoldInstance(errorCode);
- if(errorCode.logDataIfFailureAndReset("Normalizer2::getNFKCCasefoldInstance() call failed")) {
+ if(errorCode.errDataIfFailureAndReset("Normalizer2::getNFKCCasefoldInstance() call failed")) {
return;
}
// Normalization behavior for ill-formed text is not defined.
// which is not a conjoining Jamo Trailing consonant.
IcuTestErrorCode errorCode(*this, "TestComposeJamoTBase");
const Normalizer2 *nfkc = Normalizer2::getNFKCInstance(errorCode);
- if(errorCode.logDataIfFailureAndReset("Normalizer2::getNFKCInstance() call failed")) {
+ if(errorCode.errDataIfFailureAndReset("Normalizer2::getNFKCInstance() call failed")) {
return;
}
UnicodeString s(u"\u1100\u1161\u11A7\u1100\u314F\u11A7가\u11A7");
BasicNormalizerTest::TestComposeBoundaryAfter() {
IcuTestErrorCode errorCode(*this, "TestComposeBoundaryAfter");
const Normalizer2 *nfkc = Normalizer2::getNFKCInstance(errorCode);
- if(errorCode.logDataIfFailureAndReset("Normalizer2::getNFKCInstance() call failed")) {
+ if(errorCode.errDataIfFailureAndReset("Normalizer2::getNFKCInstance() call failed")) {
return;
}
// U+02DA and U+FB2C do not have compose-boundaries-after.
trie->next(u_n);
IcuTestErrorCode errorCode(*this, "TestIteratorFromBranch()");
UCharsTrie::Iterator iter(*trie, 0, errorCode);
- if(errorCode.logIfFailureAndReset("UCharsTrie::Iterator(trie) constructor")) {
+ if(errorCode.errIfFailureAndReset("UCharsTrie::Iterator(trie) constructor")) {
return;
}
// Expected data: Same as in buildMonthsTrie(), except only the suffixes
trie->next(u_a);
IcuTestErrorCode errorCode(*this, "TestIteratorFromLinearMatch()");
UCharsTrie::Iterator iter(*trie, 0, errorCode);
- if(errorCode.logIfFailureAndReset("UCharsTrie::Iterator(trie) constructor")) {
+ if(errorCode.errIfFailureAndReset("UCharsTrie::Iterator(trie) constructor")) {
return;
}
// Expected data: Same as in buildMonthsTrie(), except only the suffixes
}
IcuTestErrorCode errorCode(*this, "TestTruncatingIteratorFromRoot()");
UCharsTrie::Iterator iter(*trie, 4, errorCode);
- if(errorCode.logIfFailureAndReset("UCharsTrie::Iterator(trie) constructor")) {
+ if(errorCode.errIfFailureAndReset("UCharsTrie::Iterator(trie) constructor")) {
return;
}
// Expected data: Same as in buildMonthsTrie(), except only the first 4 characters
IcuTestErrorCode errorCode(*this, "TestTruncatingIteratorFromLinearMatchShort()");
// Truncate within the linear-match node.
UCharsTrie::Iterator iter(*trie, 2, errorCode);
- if(errorCode.logIfFailureAndReset("UCharsTrie::Iterator(trie) constructor")) {
+ if(errorCode.errIfFailureAndReset("UCharsTrie::Iterator(trie) constructor")) {
return;
}
static const StringAndValue expected[]={
IcuTestErrorCode errorCode(*this, "TestTruncatingIteratorFromLinearMatchLong()");
// Truncate after the linear-match node.
UCharsTrie::Iterator iter(*trie, 3, errorCode);
- if(errorCode.logIfFailureAndReset("UCharsTrie::Iterator(trie) constructor")) {
+ if(errorCode.errIfFailureAndReset("UCharsTrie::Iterator(trie) constructor")) {
return;
}
static const StringAndValue expected[]={
UnicodeString trieUChars;
builder_->buildUnicodeString(buildOption, trieUChars, errorCode);
LocalPointer<UCharsTrie> trie(builder_->build(buildOption, errorCode));
- if(!errorCode.logIfFailureAndReset("add()/build()")) {
+ if(!errorCode.errIfFailureAndReset("add()/build()")) {
builder_->add("zzz", 999, errorCode);
if(errorCode.reset()!=U_NO_WRITE_PERMISSION) {
errln("builder.build().add(zzz) did not set U_NO_WRITE_PERMISSION");
const StringAndValue data[], int32_t dataLength) {
IcuTestErrorCode errorCode(*this, "checkIterator()");
UCharsTrie::Iterator iter(trie, 0, errorCode);
- if(errorCode.logIfFailureAndReset("UCharsTrie::Iterator(trieUChars) constructor")) {
+ if(errorCode.errIfFailureAndReset("UCharsTrie::Iterator(trieUChars) constructor")) {
return;
}
checkIterator(iter, data, dataLength);
break;
}
UBool hasNext=iter.next(errorCode);
- if(errorCode.logIfFailureAndReset("trie iterator next() for item %d: %s", (int)i, data[i].s)) {
+ if(errorCode.errIfFailureAndReset("trie iterator next() for item %d: %s", (int)i, data[i].s)) {
break;
}
if(!hasNext) {
errln("trie iterator hasNext()=TRUE after all items");
}
UBool hasNext=iter.next(errorCode);
- errorCode.logIfFailureAndReset("trie iterator next() after all items");
+ errorCode.errIfFailureAndReset("trie iterator next() after all items");
if(hasNext) {
errln("trie iterator next()=TRUE after all items");
}
commonOptions|
UIDNA_NONTRANSITIONAL_TO_ASCII|UIDNA_NONTRANSITIONAL_TO_UNICODE,
errorCode);
- if(errorCode.logDataIfFailureAndReset("createUTS46Instance()")) {
+ if(errorCode.errDataIfFailureAndReset("createUTS46Instance()")) {
name="";
return;
}
trans->nameToUnicode(input, uT, uTInfo, errorCode);
nontrans->nameToASCII(input, aN, aNInfo, errorCode);
nontrans->nameToUnicode(input, uN, uNInfo, errorCode);
- if(errorCode.logIfFailureAndReset("first-level processing [%d/%s] %s",
+ if(errorCode.errIfFailureAndReset("first-level processing [%d/%s] %s",
(int)i, testCase.o, testCase.s)
) {
continue;
nontrans->nameToASCII(uT, uTaN, uTaNInfo, errorCode);
nontrans->nameToUnicode(aN, aNuN, aNuNInfo, errorCode);
nontrans->nameToASCII(uN, uNaN, uNaNInfo, errorCode);
- if(errorCode.logIfFailureAndReset("second-level processing [%d/%s] %s",
+ if(errorCode.errIfFailureAndReset("second-level processing [%d/%s] %s",
(int)i, testCase.o, testCase.s)
) {
continue;
trans->labelToUnicode(input, uTL, uTLInfo, errorCode);
nontrans->labelToASCII(input, aNL, aNLInfo, errorCode);
nontrans->labelToUnicode(input, uNL, uNLInfo, errorCode);
- if(errorCode.logIfFailureAndReset("labelToXYZ processing [%d/%s] %s",
+ if(errorCode.errIfFailureAndReset("labelToXYZ processing [%d/%s] %s",
(int)i, testCase.o, testCase.s)
) {
continue;
trans->nameToUnicodeUTF8(input8, uT8Sink, uT8Info, errorCode);
nontrans->nameToASCII_UTF8(input8, aN8Sink, aN8Info, errorCode);
nontrans->nameToUnicodeUTF8(input8, uN8Sink, uN8Info, errorCode);
- if(errorCode.logIfFailureAndReset("UTF-8 processing [%d/%s] %s",
+ if(errorCode.errIfFailureAndReset("UTF-8 processing [%d/%s] %s",
(int)i, testCase.o, testCase.s)
) {
continue;
void UTS46Test::IdnaTest() {
IcuTestErrorCode errorCode(*this, "IdnaTest");
const char *sourceTestDataPath = getSourceTestData(errorCode);
- if (errorCode.logIfFailureAndReset("unable to find the source/test/testdata "
+ if (errorCode.errIfFailureAndReset("unable to find the source/test/testdata "
"folder (getSourceTestData())")) {
return;
}
// Comments are indicated with hash marks.
char *fields[kNumFields][2];
u_parseDelimitedFile(path.data(), ';', fields, kNumFields, idnaTestLineFn, this, errorCode);
- if (errorCode.logIfFailureAndReset("error parsing IdnaTest.txt")) {
+ if (errorCode.errIfFailureAndReset("error parsing IdnaTest.txt")) {
return;
}
}
IcuTestErrorCode::~IcuTestErrorCode() {
// Safe because our handleFailure() does not throw exceptions.
- if(isFailure()) { handleFailure(); }
+ if(isFailure()) {
+ errlog(FALSE, nullptr);
+ }
+}
+
+UBool IcuTestErrorCode::errIfFailureAndReset() {
+ if(isFailure()) {
+ errlog(FALSE, nullptr);
+ reset();
+ return TRUE;
+ } else {
+ reset();
+ return FALSE;
+ }
}
-UBool IcuTestErrorCode::logIfFailureAndReset(const char *fmt, ...) {
+UBool IcuTestErrorCode::errIfFailureAndReset(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);
+ errlog(FALSE, buffer);
reset();
return TRUE;
} else {
}
}
-UBool IcuTestErrorCode::logDataIfFailureAndReset(const char *fmt, ...) {
+UBool IcuTestErrorCode::errDataIfFailureAndReset() {
+ if(isFailure()) {
+ errlog(TRUE, nullptr);
+ reset();
+ return TRUE;
+ } else {
+ reset();
+ return FALSE;
+ }
+}
+
+UBool IcuTestErrorCode::errDataIfFailureAndReset(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);
+ errlog(TRUE, buffer);
reset();
return TRUE;
} else {
}
void IcuTestErrorCode::setScope(const char* message) {
- scopeMessage = message;
+ scopeMessage.remove().append({ message, -1, US_INV });
}
-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;
+ scopeMessage.remove().append(message);
}
void IcuTestErrorCode::handleFailure() const {
- // testClass.errln("%s failure - %s", testName, errorName());
+ errlog(FALSE, nullptr);
+}
+
+void IcuTestErrorCode::errlog(UBool dataErr, const char* extraMessage) const {
UnicodeString msg(testName, -1, US_INV);
- msg.append(UNICODE_STRING_SIMPLE(" failure: ")).append(UnicodeString(errorName(), -1, US_INV));
+ msg.append(u" failure: ").append(UnicodeString(errorName(), -1, US_INV));
+
+ if (!scopeMessage.isEmpty()) {
+ msg.append(u" scope: ").append(scopeMessage);
+ }
- if (scopeMessage != nullptr) {
- msg.append(UNICODE_STRING_SIMPLE(" scope: ")).append(UnicodeString(scopeMessage, -1, US_INV));
+ if (extraMessage != nullptr) {
+ msg.append(u" - ").append(UnicodeString(extraMessage, -1, US_INV));
}
- if (get() == U_MISSING_RESOURCE_ERROR || get() == U_FILE_ACCESS_ERROR) {
+ if (dataErr || get() == U_MISSING_RESOURCE_ERROR || get() == U_FILE_ACCESS_ERROR) {
testClass.dataerrln(msg);
} else {
testClass.errln(msg);
class T_CTEST_EXPORT_API IcuTestErrorCode : public ErrorCode {
public:
- IcuTestErrorCode(TestLog& callingTestClass, const char* callingTestName)
- : testClass(callingTestClass), testName(callingTestName), scopeMessage(nullptr) {}
+ IcuTestErrorCode(TestLog &callingTestClass, const char *callingTestName)
+ : testClass(callingTestClass), testName(callingTestName), scopeMessage() {}
virtual ~IcuTestErrorCode();
+
// Returns TRUE if isFailure().
- UBool logIfFailureAndReset(const char *fmt, ...);
- UBool logDataIfFailureAndReset(const char *fmt, ...);
+ UBool errIfFailureAndReset();
+ UBool errIfFailureAndReset(const char *fmt, ...);
+ UBool errDataIfFailureAndReset();
+ UBool errDataIfFailureAndReset(const char *fmt, ...);
/** Sets an additional message string to be appended to failure output. */
void setScope(const char* message);
protected:
virtual void handleFailure() const;
+
private:
TestLog &testClass;
const char *const testName;
- const char* scopeMessage;
+ UnicodeString scopeMessage;
+
+ void errlog(UBool dataErr, const char* extraMessage) const;
};
#endif