ICU-20573 Handle NULL return value correctly, it means empty not error.

This commit is contained in:
Fredrik Roubert 2019-04-24 15:46:59 +02:00 committed by Fredrik Roubert
parent a97cfb01b9
commit 711e7e003a
3 changed files with 36 additions and 2 deletions

View file

@ -1121,7 +1121,7 @@ template<typename StringClass, typename OutputIterator> inline void
Locale::getKeywords(OutputIterator iterator, UErrorCode& status) const
{
LocalPointer<StringEnumeration> keys(createKeywords(status));
if (U_FAILURE(status)) {
if (U_FAILURE(status) || keys.isNull()) {
return;
}
for (;;) {
@ -1138,7 +1138,7 @@ template<typename StringClass, typename OutputIterator> inline void
Locale::getUnicodeKeywords(OutputIterator iterator, UErrorCode& status) const
{
LocalPointer<StringEnumeration> keys(createUnicodeKeywords(status));
if (U_FAILURE(status)) {
if (U_FAILURE(status) || keys.isNull()) {
return;
}
for (;;) {

View file

@ -233,7 +233,9 @@ void LocaleTest::runIndexedTest( int32_t index, UBool exec, const char* &name, c
TESTCASE_AUTO(TestCreateUnicodeKeywords);
TESTCASE_AUTO(TestKeywordVariantParsing);
TESTCASE_AUTO(TestCreateKeywordSet);
TESTCASE_AUTO(TestCreateKeywordSetEmpty);
TESTCASE_AUTO(TestCreateUnicodeKeywordSet);
TESTCASE_AUTO(TestCreateUnicodeKeywordSetEmpty);
TESTCASE_AUTO(TestGetKeywordValueStdString);
TESTCASE_AUTO(TestGetUnicodeKeywordValueStdString);
TESTCASE_AUTO(TestSetKeywordValue);
@ -1912,6 +1914,21 @@ LocaleTest::TestCreateKeywordSet(void) {
result.find("collation") != result.end());
}
void
LocaleTest::TestCreateKeywordSetEmpty(void) {
IcuTestErrorCode status(*this, "TestCreateKeywordSetEmpty()");
static const Locale l("de");
std::set<std::string> result;
l.getKeywords<std::string>(
std::insert_iterator<decltype(result)>(result, result.begin()),
status);
status.errIfFailureAndReset("\"%s\"", l.getName());
assertEquals("set::size()", 0, static_cast<int32_t>(result.size()));
}
void
LocaleTest::TestCreateUnicodeKeywordSet(void) {
IcuTestErrorCode status(*this, "TestCreateUnicodeKeywordSet()");
@ -1931,6 +1948,21 @@ LocaleTest::TestCreateUnicodeKeywordSet(void) {
result.find("co") != result.end());
}
void
LocaleTest::TestCreateUnicodeKeywordSetEmpty(void) {
IcuTestErrorCode status(*this, "TestCreateUnicodeKeywordSetEmpty()");
static const Locale l("de");
std::set<std::string> result;
l.getUnicodeKeywords<std::string>(
std::insert_iterator<decltype(result)>(result, result.begin()),
status);
status.errIfFailureAndReset("\"%s\"", l.getName());
assertEquals("set::size()", 0, static_cast<int32_t>(result.size()));
}
void
LocaleTest::TestGetKeywordValueStdString(void) {
IcuTestErrorCode status(*this, "TestGetKeywordValueStdString()");

View file

@ -79,7 +79,9 @@ public:
/* Test getting keyword values */
void TestKeywordVariantParsing(void);
void TestCreateKeywordSet(void);
void TestCreateKeywordSetEmpty(void);
void TestCreateUnicodeKeywordSet(void);
void TestCreateUnicodeKeywordSetEmpty(void);
void TestGetKeywordValueStdString(void);
void TestGetUnicodeKeywordValueStdString(void);