ICU-13077 Fix ICU4C test code that crashes when data file is missing (add NULL checks etc)

X-SVN-Rev: 39960
This commit is contained in:
Peter Edberg 2017-03-30 06:45:38 +00:00
parent 75100c00ac
commit 694ea699d2
8 changed files with 28 additions and 4 deletions

View file

@ -1023,6 +1023,7 @@ ConversionTest::ToUnicodeCase(ConversionCase &cc, UConverterToUCallback callback
// open the converter
IcuTestErrorCode errorCode(*this, "ToUnicodeCase");
LocalUConverterPointer cnv(cnv_open(cc.charset, errorCode));
// with no data, the above crashes with "pointer being freed was not allocated" for charset "x11-compound-text", see #13078
if(errorCode.isFailure()) {
errcheckln(errorCode, "toUnicode[%d](%s cb=\"%s\" fb=%d flush=%d) ucnv_open() failed - %s",
cc.caseNr, cc.charset, cc.cbopt, cc.fallbacks, cc.finalFlush, errorCode.errorName());

View file

@ -2604,6 +2604,10 @@ void DateFormatTest::TestDateFormatSymbolsClone(void)
Locale loc("de_CH_LUCERNE");
LocalPointer<DateFormat> fmt(
DateFormat::createDateInstance(DateFormat::kDefault, loc));
if (fmt.isNull()) {
dataerrln("FAIL: DateFormat::createDateInstance failed for %s", loc.getName());
return;
}
Locale valid1;
Locale actual1;
if (!getActualAndValidLocales(*fmt, valid1, actual1)) {

View file

@ -1597,6 +1597,10 @@ void DateIntervalFormatTest::testTicket11669() {
void DateIntervalFormatTest::testTicket12065() {
UErrorCode status = U_ZERO_ERROR;
LocalPointer<DateIntervalFormat> formatter(DateIntervalFormat::createInstance(UDAT_YEAR_MONTH_DAY, Locale::getEnglish(), status), status);
if (formatter.isNull()) {
dataerrln("FAIL: DateIntervalFormat::createInstance failed for Locale::getEnglish()");
return;
}
LocalPointer<DateIntervalFormat> clone(dynamic_cast<DateIntervalFormat *>(formatter->clone()));
if (*formatter != *clone) {
errln("%s:%d DateIntervalFormat and clone are not equal.", __FILE__, __LINE__);

View file

@ -1098,6 +1098,10 @@ void IntlTestDateTimePatternGeneratorAPI::testC() {
for (int32_t i = 0; i < numLocales; ++i) {
DateTimePatternGenerator *gen = DateTimePatternGenerator::createInstance(Locale(tests[i][0]), status);
if (gen == NULL) {
dataerrln("FAIL: DateTimePatternGenerator::createInstance failed for %s", tests[i][0]);
return;
}
UnicodeString pattern = gen->getBestPattern(tests[i][1], status);
UnicodeString expectedPattern = tests[i][2];

View file

@ -1067,9 +1067,15 @@ void RBBIAPITest::TestRoundtripRules() {
void RBBIAPITest::TestGetBinaryRules() {
UErrorCode status=U_ZERO_ERROR;
LocalPointer<BreakIterator> bi(BreakIterator::createLineInstance(Locale::getEnglish(), status));
TEST_ASSERT_SUCCESS(status);
if (U_FAILURE(status)) {
dataerrln("FAIL: BreakIterator::createLineInstance for Locale::getEnglish(): %s", u_errorName(status));
return;
}
RuleBasedBreakIterator *rbbi = dynamic_cast<RuleBasedBreakIterator *>(bi.getAlias());
TEST_ASSERT(rbbi != NULL);
if (rbbi == NULL) {
dataerrln("FAIL: RuleBasedBreakIterator is NULL");
return;
}
// Check that the new line break iterator is nominally functional.
UnicodeString helloWorld("Hello, World!");

View file

@ -4671,7 +4671,7 @@ void RBBITest::TestBug12918() {
UErrorCode status = U_ZERO_ERROR;
UBreakIterator* iter = ubrk_open(UBRK_WORD, NULL, crasherString, -1, &status);
if (U_FAILURE(status)) {
errln("%s:%d status = %s", __FILE__, __LINE__, u_errorName(status));
dataerrln("%s:%d status = %s", __FILE__, __LINE__, u_errorName(status));
return;
}
ubrk_first(iter);
@ -4738,7 +4738,7 @@ void RBBITest::TestEmoji() {
LocalPointer<BreakIterator> wordBreaks(BreakIterator::createWordInstance(Locale::getEnglish(), status), status);
LocalPointer<BreakIterator> lineBreaks(BreakIterator::createLineInstance(Locale::getEnglish(), status), status);
if (U_FAILURE(status)) {
errln("%s:%s %s while opening break iterators", __FILE__, __LINE__, u_errorName(status));
dataerrln("%s:%d %s while opening break iterators", __FILE__, __LINE__, u_errorName(status));
return;
}

View file

@ -781,6 +781,7 @@ void TestMessageFormat::testMsgFormatSelect(/* char* par */)
err = U_ZERO_ERROR;
//Create the MessageFormat with Plural format with embedded select format(nested pattern)
MessageFormat* msgFmt5 = internalCreate(t5.unescape(), Locale("fr"),err,(char*)"From TestMessageFormat::TestSelectFormat create t5");
// with no data the above should fail but it seems to construct an invalid MessageFormat with no reported error. See #13079
if (!U_FAILURE(err)) {
//Arguments
Formattable testArgs10[] = {"Kirti",(int32_t)6,"female"};

View file

@ -1239,6 +1239,10 @@ TimeZoneFormatTest::TestFormatCustomZone(void) {
UErrorCode status = U_ZERO_ERROR;
LocalPointer<TimeZoneFormat> tzfmt(TimeZoneFormat::createInstance(Locale("en"), status));
if (tzfmt.isNull()) {
dataerrln("FAIL: TimeZoneFormat::createInstance failed for en");
return;
}
UnicodeString tzstr;
UnicodeString expected = UnicodeString(TESTDATA[i].expected, -1, US_INV).unescape();