From ad268ad5e2f0224b6014ffbc5ee6bfcd32281734 Mon Sep 17 00:00:00 2001 From: Markus Scherer Date: Tue, 22 Jul 2003 04:17:31 +0000 Subject: [PATCH] ICU-2449 support integers and binaries for data-driven tests X-SVN-Rev: 12646 --- icu4c/source/test/intltest/datamap.cpp | 91 +++++++++++++++++++++----- icu4c/source/test/intltest/datamap.h | 51 +++++++++++++-- 2 files changed, 122 insertions(+), 20 deletions(-) diff --git a/icu4c/source/test/intltest/datamap.cpp b/icu4c/source/test/intltest/datamap.cpp index 4eff1f89acf..e9a6758e396 100644 --- a/icu4c/source/test/intltest/datamap.cpp +++ b/icu4c/source/test/intltest/datamap.cpp @@ -93,38 +93,96 @@ void RBDataMap::init(UResourceBundle *headers, UResourceBundle *data, UErrorCode ures_close(t); } - -const UnicodeString RBDataMap::getString(const char* key, UErrorCode &status) const +const ResourceBundle *RBDataMap::getItem(const char* key, UErrorCode &status) const { + if(U_FAILURE(status)) { + return NULL; + } + UnicodeString hashKey(key, ""); - ResourceBundle *r = (ResourceBundle *)fData->get(hashKey); + const ResourceBundle *r = (ResourceBundle *)fData->get(hashKey); if(r != NULL) { - return r->getString(status); + return r; } else { status = U_MISSING_RESOURCE_ERROR; - return UnicodeString("", ""); + return NULL; } } +const UnicodeString RBDataMap::getString(const char* key, UErrorCode &status) const +{ + const ResourceBundle *r = getItem(key, status); + if(U_SUCCESS(status)) { + return r->getString(status); + } else { + status = U_MISSING_RESOURCE_ERROR; + return UnicodeString(); + } +} + +int32_t +RBDataMap::getInt28(const char* key, UErrorCode &status) const +{ + const ResourceBundle *r = getItem(key, status); + if(U_SUCCESS(status)) { + return r->getInt(status); + } else { + return 0; + } +} + +uint32_t +RBDataMap::getUInt28(const char* key, UErrorCode &status) const +{ + const ResourceBundle *r = getItem(key, status); + if(U_SUCCESS(status)) { + return r->getUInt(status); + } else { + return 0; + } +} + +const int32_t * +RBDataMap::getIntVector(int32_t &length, const char *key, UErrorCode &status) const { + const ResourceBundle *r = getItem(key, status); + if(U_SUCCESS(status)) { + return r->getIntVector(length, status); + } else { + return NULL; + } +} + +const uint8_t * +RBDataMap::getBinary(int32_t &length, const char *key, UErrorCode &status) const { + const ResourceBundle *r = getItem(key, status); + if(U_SUCCESS(status)) { + return r->getBinary(length, status); + } else { + return NULL; + } +} int32_t RBDataMap::getInt(const char* key, UErrorCode &status) const { - int32_t result = 0; UnicodeString r = this->getString(key, status); if(U_SUCCESS(status)) { - result = utoi(r); + return utoi(r); + } else { + return 0; } - return result; } const UnicodeString* RBDataMap::getStringArray(int32_t& count, const char* key, UErrorCode &status) const { - UnicodeString hashKey(key, ""); - ResourceBundle *r = (ResourceBundle *)fData->get(hashKey); - if(r != NULL) { + const ResourceBundle *r = getItem(key, status); + if(U_SUCCESS(status)) { int32_t i = 0; count = r->getSize(); + if(count <= 0) { + return NULL; + } + UnicodeString *result = new UnicodeString[count]; for(i = 0; igetStringEx(i, status); @@ -138,12 +196,15 @@ const UnicodeString* RBDataMap::getStringArray(int32_t& count, const char* key, const int32_t* RBDataMap::getIntArray(int32_t& count, const char* key, UErrorCode &status) const { - UnicodeString hashKey(key, ""); - ResourceBundle *r = (ResourceBundle *)fData->get(hashKey); - if(r != NULL) { + const ResourceBundle *r = getItem(key, status); + if(U_SUCCESS(status)) { int32_t i = 0; count = r->getSize(); + if(count <= 0) { + return NULL; + } + int32_t *result = new int32_t[count]; UnicodeString stringRes; for(i = 0; i