ICU-13661 Renaming logIfFailureAndReset to errIfFailureAndReset.

X-SVN-Rev: 41362
This commit is contained in:
Shane Carr 2018-05-08 23:55:47 +00:00
parent 3275a9c5d3
commit 1fe1497d88
17 changed files with 230 additions and 134 deletions

View file

@ -228,13 +228,13 @@ CollationAPITest::TestProperty(/* char* par */)
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);
@ -1238,7 +1238,7 @@ void CollationAPITest::TestSortKey()
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);
@ -2371,7 +2371,7 @@ void CollationAPITest::TestCloneBinary() {
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());
@ -2386,13 +2386,13 @@ void CollationAPITest::TestCloneBinary() {
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));
@ -2404,7 +2404,7 @@ void CollationAPITest::TestCloneBinary() {
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));
@ -2424,7 +2424,7 @@ void CollationAPITest::TestIterNumeric() {
// 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);
@ -2512,7 +2512,7 @@ void CollationAPITest::TestGapTooSmall() {
{
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");
}
}

View file

@ -260,7 +260,7 @@ UBool BiDiConformanceTest::parseInputStringFromBiDiClasses(const char *&start) {
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;
}
@ -275,7 +275,7 @@ void BiDiConformanceTest::TestBidiTest() {
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;
@ -333,7 +333,7 @@ void BiDiConformanceTest::TestBidiTest() {
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;
}
@ -429,7 +429,7 @@ L L R R R B R R L L L B ON ON ; 3 ; 0 ; 0 0 1 1 1 0 1 1 2 2 2 1 1 1
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;
}
@ -463,7 +463,7 @@ void BiDiConformanceTest::TestBidiCharacterTest() {
// 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;
@ -542,7 +542,7 @@ void BiDiConformanceTest::TestBidiCharacterTest() {
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;
}
@ -633,7 +633,7 @@ UBool BiDiConformanceTest::checkOrdering(UBiDi *ubidi) {
// 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;
}

View file

@ -402,7 +402,7 @@ void BytesTrieTest::TestIteratorFromBranch() {
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
@ -453,7 +453,7 @@ void BytesTrieTest::TestIteratorFromLinearMatch() {
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
@ -475,7 +475,7 @@ void BytesTrieTest::TestTruncatingIteratorFromRoot() {
}
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
@ -530,7 +530,7 @@ void BytesTrieTest::TestTruncatingIteratorFromLinearMatchShort() {
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[]={
@ -559,7 +559,7 @@ void BytesTrieTest::TestTruncatingIteratorFromLinearMatchLong() {
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[]={
@ -641,7 +641,7 @@ BytesTrie *BytesTrieTest::buildTrie(const StringAndValue data[], int32_t dataLen
}
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");
@ -848,7 +848,7 @@ void BytesTrieTest::checkIterator(const BytesTrie &trie,
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);
@ -863,7 +863,7 @@ void BytesTrieTest::checkIterator(BytesTrie::Iterator &iter,
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) {
@ -885,7 +885,7 @@ void BytesTrieTest::checkIterator(BytesTrie::Iterator &iter,
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");
}

View file

@ -189,7 +189,7 @@ void CollationTest::TestImplicits() {
IcuTestErrorCode errorCode(*this, "TestImplicits");
const CollationData *cd = CollationRoot::getData(errorCode);
if(errorCode.logDataIfFailureAndReset("CollationRoot::getData()")) {
if(errorCode.errDataIfFailureAndReset("CollationRoot::getData()")) {
return;
}
@ -220,7 +220,7 @@ void CollationTest::TestImplicits() {
errorCode);
UnicodeSet inOrder(someHanInCPOrder);
inOrder.addAll(unassigned).freeze();
if(errorCode.logIfFailureAndReset("UnicodeSet")) {
if(errorCode.errIfFailureAndReset("UnicodeSet")) {
return;
}
const UnicodeSet *sets[] = { &coreHan, &otherHan, &unassigned };
@ -235,7 +235,7 @@ void CollationTest::TestImplicits() {
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) {
@ -261,7 +261,7 @@ void CollationTest::TestImplicits() {
void CollationTest::TestNulTerminated() {
IcuTestErrorCode errorCode(*this, "TestNulTerminated");
const CollationData *data = CollationRoot::getData(errorCode);
if(errorCode.logDataIfFailureAndReset("CollationRoot::getData()")) {
if(errorCode.errDataIfFailureAndReset("CollationRoot::getData()")) {
return;
}
@ -272,7 +272,7 @@ void CollationTest::TestNulTerminated() {
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) {
@ -440,7 +440,7 @@ void CollationTest::checkFCD(const char *name,
void CollationTest::TestFCD() {
IcuTestErrorCode errorCode(*this, "TestFCD");
const CollationData *data = CollationRoot::getData(errorCode);
if(errorCode.logDataIfFailureAndReset("CollationRoot::getData()")) {
if(errorCode.errDataIfFailureAndReset("CollationRoot::getData()")) {
return;
}
@ -473,7 +473,7 @@ void CollationTest::TestFCD() {
};
FCDUTF16CollationIterator u16ci(data, FALSE, s, s, NULL);
if(errorCode.logIfFailureAndReset("FCDUTF16CollationIterator constructor")) {
if(errorCode.errIfFailureAndReset("FCDUTF16CollationIterator constructor")) {
return;
}
CodePointIterator cpi(cp, UPRV_LENGTHOF(cp));
@ -484,7 +484,7 @@ void CollationTest::TestFCD() {
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);
@ -493,7 +493,7 @@ void CollationTest::TestFCD() {
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);
@ -759,7 +759,7 @@ private:
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);
@ -862,13 +862,13 @@ void CollationTest::TestRootElements() {
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);
@ -896,7 +896,7 @@ void CollationTest::TestTailoredElements() {
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;
}
@ -1808,7 +1808,7 @@ void CollationTest::TestDataDriven() {
fcd = Normalizer2Factory::getFCDInstance(errorCode);
nfd = Normalizer2::getNFDInstance(errorCode);
if(errorCode.logDataIfFailureAndReset("Normalizer2Factory::getFCDInstance() or getNFDInstance()")) {
if(errorCode.errDataIfFailureAndReset("Normalizer2Factory::getFCDInstance() or getNFDInstance()")) {
return;
}
@ -1816,7 +1816,7 @@ void CollationTest::TestDataDriven() {
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.

View file

@ -205,14 +205,14 @@ void DateFormatTest::TestPatterns() {
// 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;

View file

@ -144,6 +144,7 @@ void ErrorCodeTest::runIndexedTest(int32_t index, UBool exec, const char* &name,
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
}
}
@ -255,6 +256,75 @@ void ErrorCodeTest::TestSubclass() {
}
}
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() {}
@ -502,7 +572,7 @@ void LocalPointerTest::TestLocalXyzPointer() {
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()) {
@ -512,7 +582,7 @@ void LocalPointerTest::TestLocalXyzPointer() {
#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()) {
@ -521,7 +591,7 @@ void LocalPointerTest::TestLocalXyzPointer() {
}
LocalUDateTimePatternGeneratorPointer patgen(udatpg_open("root", errorCode));
if(errorCode.logDataIfFailureAndReset("udatpg_open()")) {
if(errorCode.errDataIfFailureAndReset("udatpg_open()")) {
return;
}
if(patgen.isNull()) {
@ -530,7 +600,7 @@ void LocalPointerTest::TestLocalXyzPointer() {
}
LocalULocaleDisplayNamesPointer ldn(uldn_open("de-CH", ULDN_STANDARD_NAMES, errorCode));
if(errorCode.logIfFailureAndReset("uldn_open()")) {
if(errorCode.errIfFailureAndReset("uldn_open()")) {
return;
}
if(ldn.isNull()) {
@ -541,7 +611,7 @@ void LocalPointerTest::TestLocalXyzPointer() {
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()) {
@ -554,7 +624,7 @@ void LocalPointerTest::TestLocalXyzPointer() {
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()) {
@ -565,7 +635,7 @@ void LocalPointerTest::TestLocalXyzPointer() {
#if !UCONFIG_NO_IDNA
LocalUIDNAPointer idna(uidna_openUTS46(0, errorCode));
if(errorCode.logIfFailureAndReset("uidna_openUTS46()")) {
if(errorCode.errIfFailureAndReset("uidna_openUTS46()")) {
return;
}
if(idna.isNull()) {
@ -578,7 +648,7 @@ void LocalPointerTest::TestLocalXyzPointer() {
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()) {
@ -591,7 +661,7 @@ void LocalPointerTest::TestLocalXyzPointer() {
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()) {
@ -608,7 +678,7 @@ void LocalPointerTest::TestLocalXyzPointerMoveSwap() {
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;
@ -616,7 +686,7 @@ void LocalPointerTest::TestLocalXyzPointerMoveSwap() {
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()) {
@ -668,7 +738,7 @@ void LocalPointerTest::TestLocalXyzPointerNull() {
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);
}
}
@ -695,7 +765,7 @@ void LocalPointerTest::TestLocalXyzPointerNull() {
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);
}
}
@ -708,7 +778,7 @@ void LocalPointerTest::TestLocalXyzPointerNull() {
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);
}
}

View file

@ -25,6 +25,7 @@ public:
void runIndexedTest(int32_t index, UBool exec, const char* &name, char* par = NULL);
void TestErrorCode();
void TestSubclass();
void TestIcuTestErrorCode();
};
#endif

View file

@ -9324,7 +9324,7 @@ void NumberFormatTest::Test10354() {
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

View file

@ -630,21 +630,21 @@ PluralFormatTest::ordinalFormatTest(void) {
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);
}
@ -652,16 +652,16 @@ PluralFormatTest::ordinalFormatTest(void) {
// 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);
}

View file

@ -595,7 +595,7 @@ PluralRulesTest::testGetAllKeywordValues() {
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.);

View file

@ -1799,11 +1799,11 @@ void TestMessageFormat::testCoverage(void) {
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;
@ -1845,7 +1845,7 @@ void TestMessageFormat::TestTrimArgumentName() {
// 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 };
@ -1870,7 +1870,7 @@ void TestMessageFormat::TestSelectOrdinal() {
"{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 };
@ -1891,7 +1891,7 @@ void TestMessageFormat::TestSelectOrdinal() {
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() {

View file

@ -217,11 +217,11 @@ void IntlTestDecimalFormatSymbols::testLastResortData() {
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,
@ -370,13 +370,13 @@ void IntlTestDecimalFormatSymbols::testNumberingSystem() {
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);

View file

@ -1394,7 +1394,7 @@ BasicNormalizerTest::TestSkippable() {
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;
}
@ -1445,7 +1445,7 @@ BasicNormalizerTest::TestCustomComp() {
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) {
@ -1477,7 +1477,7 @@ BasicNormalizerTest::TestCustomFCC() {
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) {
@ -1537,7 +1537,7 @@ void
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 =
@ -1641,7 +1641,7 @@ BasicNormalizerTest::TestLowMappingToEmpty_D() {
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);
@ -1663,7 +1663,7 @@ BasicNormalizerTest::TestLowMappingToEmpty_FCD() {
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);
@ -1690,7 +1690,7 @@ void
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.
@ -1733,7 +1733,7 @@ BasicNormalizerTest::TestComposeJamoTBase() {
// 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");
@ -1759,7 +1759,7 @@ void
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.

View file

@ -559,7 +559,7 @@ void UCharsTrieTest::TestIteratorFromBranch() {
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
@ -610,7 +610,7 @@ void UCharsTrieTest::TestIteratorFromLinearMatch() {
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
@ -632,7 +632,7 @@ void UCharsTrieTest::TestTruncatingIteratorFromRoot() {
}
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
@ -687,7 +687,7 @@ void UCharsTrieTest::TestTruncatingIteratorFromLinearMatchShort() {
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[]={
@ -716,7 +716,7 @@ void UCharsTrieTest::TestTruncatingIteratorFromLinearMatchLong() {
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[]={
@ -792,7 +792,7 @@ UCharsTrie *UCharsTrieTest::buildTrie(const StringAndValue data[], int32_t dataL
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");
@ -1011,7 +1011,7 @@ void UCharsTrieTest::checkIterator(UCharsTrie &trie,
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);
@ -1026,7 +1026,7 @@ void UCharsTrieTest::checkIterator(UCharsTrie::Iterator &iter,
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) {
@ -1052,7 +1052,7 @@ void UCharsTrieTest::checkIterator(UCharsTrie::Iterator &iter,
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");
}

View file

@ -73,7 +73,7 @@ void UTS46Test::runIndexedTest(int32_t index, UBool exec, const char *&name, cha
commonOptions|
UIDNA_NONTRANSITIONAL_TO_ASCII|UIDNA_NONTRANSITIONAL_TO_UNICODE,
errorCode);
if(errorCode.logDataIfFailureAndReset("createUTS46Instance()")) {
if(errorCode.errDataIfFailureAndReset("createUTS46Instance()")) {
name="";
return;
}
@ -611,7 +611,7 @@ void UTS46Test::TestSomeCases() {
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;
@ -688,7 +688,7 @@ void UTS46Test::TestSomeCases() {
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;
@ -732,7 +732,7 @@ void UTS46Test::TestSomeCases() {
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;
@ -852,7 +852,7 @@ void UTS46Test::TestSomeCases() {
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;
@ -1022,7 +1022,7 @@ U_DEFINE_LOCAL_OPEN_POINTER(LocalStdioFilePointer, FILE, fclose);
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;
}
@ -1039,7 +1039,7 @@ void UTS46Test::IdnaTest() {
// 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;
}
}

View file

@ -20,20 +20,14 @@ TestLog::~TestLog() {}
IcuTestErrorCode::~IcuTestErrorCode() {
// Safe because our handleFailure() does not throw exceptions.
if(isFailure()) { handleFailure(); }
if(isFailure()) {
errlog(FALSE, nullptr);
}
}
UBool IcuTestErrorCode::logIfFailureAndReset(const char *fmt, ...) {
UBool IcuTestErrorCode::errIfFailureAndReset() {
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, nullptr);
reset();
return TRUE;
} else {
@ -42,17 +36,41 @@ UBool IcuTestErrorCode::logIfFailureAndReset(const char *fmt, ...) {
}
}
UBool IcuTestErrorCode::logDataIfFailureAndReset(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.dataerrln(msg);
errlog(FALSE, buffer);
reset();
return TRUE;
} else {
reset();
return FALSE;
}
}
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);
errlog(TRUE, buffer);
reset();
return TRUE;
} else {
@ -62,29 +80,30 @@ UBool IcuTestErrorCode::logDataIfFailureAndReset(const char *fmt, ...) {
}
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());
UnicodeString msg(testName, -1, US_INV);
msg.append(UNICODE_STRING_SIMPLE(" failure: ")).append(UnicodeString(errorName(), -1, US_INV));
errlog(FALSE, nullptr);
}
if (scopeMessage != nullptr) {
msg.append(UNICODE_STRING_SIMPLE(" scope: ")).append(UnicodeString(scopeMessage, -1, US_INV));
void IcuTestErrorCode::errlog(UBool dataErr, const char* extraMessage) const {
UnicodeString msg(testName, -1, US_INV);
msg.append(u" failure: ").append(UnicodeString(errorName(), -1, US_INV));
if (!scopeMessage.isEmpty()) {
msg.append(u" scope: ").append(scopeMessage);
}
if (get() == U_MISSING_RESOURCE_ERROR || get() == U_FILE_ACCESS_ERROR) {
if (extraMessage != nullptr) {
msg.append(u" - ").append(UnicodeString(extraMessage, -1, US_INV));
}
if (dataErr || get() == U_MISSING_RESOURCE_ERROR || get() == U_FILE_ACCESS_ERROR) {
testClass.dataerrln(msg);
} else {
testClass.errln(msg);

View file

@ -32,12 +32,15 @@ public:
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);
@ -45,10 +48,13 @@ public:
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