Skip to content

Commit

Permalink
ICU-20573 Handle NULL return value correctly, it means empty not error.
Browse files Browse the repository at this point in the history
  • Loading branch information
roubert committed Apr 25, 2019
1 parent a97cfb0 commit 711e7e0
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
4 changes: 2 additions & 2 deletions icu4c/source/common/unicode/locid.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 (;;) {
Expand All @@ -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 (;;) {
Expand Down
32 changes: 32 additions & 0 deletions icu4c/source/test/intltest/loctest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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()");
Expand All @@ -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()");
Expand Down
2 changes: 2 additions & 0 deletions icu4c/source/test/intltest/loctest.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,9 @@ class LocaleTest: public IntlTest {
/* 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);

Expand Down

0 comments on commit 711e7e0

Please sign in to comment.