ICU-13533 Fix address sanitizer failures found with no-data ICU testing.
diff --git a/icu4c/source/i18n/calendar.cpp b/icu4c/source/i18n/calendar.cpp
index 82a0e23..c730245 100644
--- a/icu4c/source/i18n/calendar.cpp
+++ b/icu4c/source/i18n/calendar.cpp
@@ -750,6 +750,7 @@
validLocale[0] = 0;
actualLocale[0] = 0;
if (U_FAILURE(success)) {
+ delete zone;
return;
}
if(zone == 0) {
diff --git a/icu4c/source/i18n/numfmt.cpp b/icu4c/source/i18n/numfmt.cpp
index 8dcc8fa..672d466 100644
--- a/icu4c/source/i18n/numfmt.cpp
+++ b/icu4c/source/i18n/numfmt.cpp
@@ -986,15 +986,19 @@
URegistryKey U_EXPORT2
NumberFormat::registerFactory(NumberFormatFactory* toAdopt, UErrorCode& status)
{
- ICULocaleService *service = getNumberFormatService();
- if (service) {
- NFFactory *tempnnf = new NFFactory(toAdopt);
- if (tempnnf != NULL) {
- return service->registerFactory(tempnnf, status);
- }
- }
- status = U_MEMORY_ALLOCATION_ERROR;
- return NULL;
+ if (U_FAILURE(status)) {
+ delete toAdopt;
+ return nullptr;
+ }
+ ICULocaleService *service = getNumberFormatService();
+ if (service) {
+ NFFactory *tempnnf = new NFFactory(toAdopt);
+ if (tempnnf != NULL) {
+ return service->registerFactory(tempnnf, status);
+ }
+ }
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return NULL;
}
// -------------------------------------
diff --git a/icu4c/source/i18n/translit.cpp b/icu4c/source/i18n/translit.cpp
index 3feb0a3..a3ad1fc 100644
--- a/icu4c/source/i18n/translit.cpp
+++ b/icu4c/source/i18n/translit.cpp
@@ -923,13 +923,15 @@
return NULL;
}
- UnicodeSet* globalFilter;
+ UnicodeSet* globalFilter = nullptr;
// TODO add code for parseError...currently unused, but
// later may be used by parsing code...
if (!TransliteratorIDParser::parseCompoundID(ID, dir, canonID, list, globalFilter)) {
status = U_INVALID_ID;
+ delete globalFilter;
return NULL;
}
+ LocalPointer<UnicodeSet> lpGlobalFilter(globalFilter);
TransliteratorIDParser::instantiateList(list, status);
if (U_FAILURE(status)) {
@@ -953,8 +955,8 @@
// Check null pointer
if (t != NULL) {
t->setID(canonID);
- if (globalFilter != NULL) {
- t->adoptFilter(globalFilter);
+ if (lpGlobalFilter.isValid()) {
+ t->adoptFilter(lpGlobalFilter.orphan());
}
}
else if (U_SUCCESS(status)) {
@@ -1101,6 +1103,10 @@
UnicodeString* idBlock = (UnicodeString*)parser.idBlockVector.elementAt(i);
if (!idBlock->isEmpty()) {
Transliterator* temp = createInstance(*idBlock, UTRANS_FORWARD, parseError, status);
+ if (U_FAILURE(status)) {
+ delete temp;
+ return nullptr;
+ }
if (temp != NULL && typeid(*temp) != typeid(NullTransliterator))
transliterators.addElement(temp, status);
else
@@ -1114,8 +1120,10 @@
data, TRUE);
// Check if NULL before adding it to transliterators to avoid future usage of NULL pointer.
if (temprbt == NULL) {
- status = U_MEMORY_ALLOCATION_ERROR;
- return t;
+ if (U_SUCCESS(status)) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ }
+ return t;
}
transliterators.addElement(temprbt, status);
}
diff --git a/icu4c/source/i18n/tridpars.cpp b/icu4c/source/i18n/tridpars.cpp
index 9de8a16..65bfc88 100644
--- a/icu4c/source/i18n/tridpars.cpp
+++ b/icu4c/source/i18n/tridpars.cpp
@@ -294,6 +294,7 @@
pos = ppos.getIndex();
if (withParens == 1 && !ICU_Utility::parseChar(id, pos, CLOSE_REV)) {
+ delete filter;
pos = start;
return NULL;
}
diff --git a/icu4c/source/i18n/udat.cpp b/icu4c/source/i18n/udat.cpp
index b47e321..ab91bcf 100644
--- a/icu4c/source/i18n/udat.cpp
+++ b/icu4c/source/i18n/udat.cpp
@@ -167,9 +167,13 @@
}
}
- if(fmt == 0) {
+ if(fmt == nullptr) {
*status = U_MEMORY_ALLOCATION_ERROR;
- return 0;
+ return nullptr;
+ }
+ if (U_FAILURE(*status)) {
+ delete fmt;
+ return nullptr;
}
if(tzID != 0) {
diff --git a/icu4c/source/i18n/unum.cpp b/icu4c/source/i18n/unum.cpp
index c0bb9cb..cce3db7 100644
--- a/icu4c/source/i18n/unum.cpp
+++ b/icu4c/source/i18n/unum.cpp
@@ -135,6 +135,11 @@
*status = U_MEMORY_ALLOCATION_ERROR;
}
+ if (U_FAILURE(*status) && retVal != NULL) {
+ delete retVal;
+ retVal = NULL;
+ }
+
return reinterpret_cast<UNumberFormat *>(retVal);
}
diff --git a/icu4c/source/io/ucln_io.cpp b/icu4c/source/io/ucln_io.cpp
index 7a7216b..5cd367c 100644
--- a/icu4c/source/io/ucln_io.cpp
+++ b/icu4c/source/io/ucln_io.cpp
@@ -16,6 +16,7 @@
* created by: George Rhoten
*/
+#include "unicode/utypes.h"
#include "mutex.h"
#include "ucln.h"
#include "ucln_io.h"
diff --git a/icu4c/source/test/cintltst/cbiapts.c b/icu4c/source/test/cintltst/cbiapts.c
index 2e7404a..c72de75 100644
--- a/icu4c/source/test/cintltst/cbiapts.c
+++ b/icu4c/source/test/cintltst/cbiapts.c
@@ -736,12 +736,15 @@
bi = ubrk_open(UBRK_WORD, "en_US", NULL, 0, &status);
if (U_FAILURE(status)) {
log_err_status(status, "Failure at file %s, line %d, error = %s\n", __FILE__, __LINE__, u_errorName(status));
+ utext_close(ut);
return;
}
ubrk_setUText(bi, ut, &status);
if (U_FAILURE(status)) {
log_err("Failure at file %s, line %d, error = %s\n", __FILE__, __LINE__, u_errorName(status));
+ ubrk_close(bi);
+ utext_close(ut);
return;
}
diff --git a/icu4c/source/test/cintltst/ccaltst.c b/icu4c/source/test/cintltst/ccaltst.c
index eaff8f3..a7517cd 100644
--- a/icu4c/source/test/cintltst/ccaltst.c
+++ b/icu4c/source/test/cintltst/ccaltst.c
@@ -356,6 +356,11 @@
datdef=udat_open(UDAT_FULL,UDAT_FULL ,NULL, NULL, 0,NULL,0,&status);
if(U_FAILURE(status)){
log_data_err("FAIL: error in creating the dateformat : %s (Are you missing data?)\n", u_errorName(status));
+ ucal_close(caldef2);
+ ucal_close(calfr);
+ ucal_close(calit);
+ ucal_close(calfrclone);
+ ucal_close(caldef);
return;
}
log_verbose("PASS: The current date and time fetched is %s\n", u_austrcpy(tempMsgBuf, myDateFormat(datdef, now)) );
@@ -535,6 +540,10 @@
if(U_FAILURE(status))
{
log_data_err("error in creating the dateformat : %s (Are you missing data?)\n", u_errorName(status));
+ ucal_close(caldef);
+ ucal_close(caldef2);
+ ucal_close(caldef3);
+ udat_close(datdef);
return;
}
@@ -1248,30 +1257,33 @@
log_verbose("\nTesting the DOW progression\n");
initialDOW = ucal_get(cal, UCAL_DAY_OF_WEEK, &status);
- if (U_FAILURE(status)) { log_data_err("ucal_get() failed: %s (Are you missing data?)\n", u_errorName(status) ); return; }
- newDOW = initialDOW;
- do {
- DOW = newDOW;
- log_verbose("DOW = %d...\n", DOW);
- date1=ucal_getMillis(cal, &status);
- if(U_FAILURE(status)){ log_err("ucal_getMiilis() failed: %s\n", u_errorName(status)); return;}
- log_verbose("%s\n", u_austrcpy(tempMsgBuf, myDateFormat(datfor, date1)));
-
- ucal_add(cal,UCAL_DAY_OF_WEEK, delta, &status);
- if (U_FAILURE(status)) { log_err("ucal_add() failed: %s\n", u_errorName(status)); return; }
-
- newDOW = ucal_get(cal, UCAL_DAY_OF_WEEK, &status);
- if (U_FAILURE(status)) { log_err("ucal_get() failed: %s\n", u_errorName(status)); return; }
- expectedDOW = 1 + (DOW + delta - 1) % 7;
- date1=ucal_getMillis(cal, &status);
- if(U_FAILURE(status)){ log_err("ucal_getMiilis() failed: %s\n", u_errorName(status)); return;}
- if (newDOW != expectedDOW) {
- log_err("Day of week should be %d instead of %d on %s", expectedDOW, newDOW,
- u_austrcpy(tempMsgBuf, myDateFormat(datfor, date1)) );
- return;
+ if (U_FAILURE(status)) {
+ log_data_err("ucal_get() failed: %s (Are you missing data?)\n", u_errorName(status) );
+ } else {
+ newDOW = initialDOW;
+ do {
+ DOW = newDOW;
+ log_verbose("DOW = %d...\n", DOW);
+ date1=ucal_getMillis(cal, &status);
+ if(U_FAILURE(status)){ log_err("ucal_getMiilis() failed: %s\n", u_errorName(status)); break;}
+ log_verbose("%s\n", u_austrcpy(tempMsgBuf, myDateFormat(datfor, date1)));
+
+ ucal_add(cal,UCAL_DAY_OF_WEEK, delta, &status);
+ if (U_FAILURE(status)) { log_err("ucal_add() failed: %s\n", u_errorName(status)); break; }
+
+ newDOW = ucal_get(cal, UCAL_DAY_OF_WEEK, &status);
+ if (U_FAILURE(status)) { log_err("ucal_get() failed: %s\n", u_errorName(status)); break; }
+ expectedDOW = 1 + (DOW + delta - 1) % 7;
+ date1=ucal_getMillis(cal, &status);
+ if(U_FAILURE(status)){ log_err("ucal_getMiilis() failed: %s\n", u_errorName(status)); break;}
+ if (newDOW != expectedDOW) {
+ log_err("Day of week should be %d instead of %d on %s", expectedDOW, newDOW,
+ u_austrcpy(tempMsgBuf, myDateFormat(datfor, date1)) );
+ break;
+ }
}
+ while (newDOW != initialDOW);
}
- while (newDOW != initialDOW);
ucal_close(cal);
udat_close(datfor);
@@ -1307,13 +1319,13 @@
gmtcal=ucal_open(tzID, 3, "en_US", UCAL_TRADITIONAL, &status);
if (U_FAILURE(status)) {
log_data_err("ucal_open failed: %s - (Are you missing data?)\n", u_errorName(status));
- return;
+ goto cleanup;
}
u_uastrcpy(tzID, "PST");
cal = ucal_open(tzID, 3, "en_US", UCAL_TRADITIONAL, &status);
if (U_FAILURE(status)) {
log_err("ucal_open failed: %s\n", u_errorName(status));
- return;
+ goto cleanup;
}
datfor=udat_open(UDAT_MEDIUM,UDAT_MEDIUM ,NULL, fgGMTID,-1,NULL, 0, &status);
@@ -1324,13 +1336,13 @@
ucal_setDateTime(gmtcal, yr, mo - 1, dt, hr, mn, sc, &status);
if (U_FAILURE(status)) {
log_data_err("ucal_setDateTime failed: %s (Are you missing data?)\n", u_errorName(status));
- return;
+ goto cleanup;
}
ucal_set(gmtcal, UCAL_MILLISECOND, 0);
date1 = ucal_getMillis(gmtcal, &status);
if (U_FAILURE(status)) {
log_err("ucal_getMillis failed: %s\n", u_errorName(status));
- return;
+ goto cleanup;
}
log_verbose("date = %s\n", u_austrcpy(tempMsgBuf, myDateFormat(datfor, date1)) );
@@ -1338,7 +1350,7 @@
ucal_setMillis(cal, date1, &status);
if (U_FAILURE(status)) {
log_err("ucal_setMillis() failed: %s\n", u_errorName(status));
- return;
+ goto cleanup;
}
offset = ucal_get(cal, UCAL_ZONE_OFFSET, &status);
@@ -1346,7 +1358,7 @@
if (U_FAILURE(status)) {
log_err("ucal_get() failed: %s\n", u_errorName(status));
- return;
+ goto cleanup;
}
temp=(double)((double)offset / 1000.0 / 60.0 / 60.0);
/*printf("offset for %s %f hr\n", austrdup(myDateFormat(datfor, date1)), temp);*/
@@ -1357,7 +1369,7 @@
ucal_get(cal, UCAL_MILLISECOND, &status) - offset;
if (U_FAILURE(status)) {
log_err("ucal_get() failed: %s\n", u_errorName(status));
- return;
+ goto cleanup;
}
expected = ((hr * 60 + mn) * 60 + sc) * 1000;
@@ -1367,6 +1379,8 @@
}
else
log_verbose("PASS: the offset between local and GMT is correct\n");
+
+cleanup:
ucal_close(gmtcal);
ucal_close(cal);
udat_close(datfor);
diff --git a/icu4c/source/test/cintltst/cdtdptst.c b/icu4c/source/test/cintltst/cdtdptst.c
index 447bd89..d7126ec 100644
--- a/icu4c/source/test/cintltst/cdtdptst.c
+++ b/icu4c/source/test/cintltst/cdtdptst.c
@@ -207,6 +207,7 @@
format = udat_open(UDAT_PATTERN, UDAT_PATTERN, NULL, NULL, 0,pattern, u_strlen(pattern), &status);
if(U_FAILURE(status)){
log_data_err("FAIL: Error in date format construction with pattern: %s - (Are you missing data?)\n", myErrorName(status));
+ free(pattern);
return;
}
date1 = ucal_getNow();
@@ -304,10 +305,12 @@
*/
void TestQuotePattern161()
{
- UDateFormat *format;
- UCalendar *cal;
+ UDateFormat *format = NULL;
+ UCalendar *cal = NULL;
UDate currentTime_1;
- UChar *pattern, *tzID, *exp;
+ UChar *pattern = NULL;
+ UChar *tzID = NULL;
+ UChar *exp = NULL;
UChar *dateString;
UErrorCode status = U_ZERO_ERROR;
const char* expStr = "04/13/1999 at 10:42:28 AM ";
@@ -323,27 +326,27 @@
format= udat_open(UDAT_PATTERN, UDAT_PATTERN,"en_US", NULL, 0,pattern, u_strlen(pattern), &status);
if(U_FAILURE(status)){
log_data_err("error in udat_open: %s - (Are you missing data?)\n", myErrorName(status));
- return;
- }
- tzID=(UChar*)malloc(sizeof(UChar) * 4);
- u_uastrcpy(tzID, "PST");
- /* this is supposed to open default date format, but later on it treats it like it is "en_US"
- - very bad if you try to run the tests on machine where default locale is NOT "en_US" */
- /* cal=ucal_open(tzID, u_strlen(tzID), NULL, UCAL_TRADITIONAL, &status); */
- cal=ucal_open(tzID, u_strlen(tzID), "en_US", UCAL_TRADITIONAL, &status);
- if(U_FAILURE(status)){ log_err("error in ucal_open cal : %s\n", myErrorName(status)); }
-
- ucal_setDateTime(cal, 1999, UCAL_APRIL, 13, 10, 42, 28, &status);
- currentTime_1 = ucal_getMillis(cal, &status);
-
- dateString = myDateFormat(format, currentTime_1);
- exp=(UChar*)malloc(sizeof(UChar) * (strlen(expStr) + 1) );
- u_uastrcpy(exp, expStr);
-
- log_verbose("%s\n", austrdup(dateString) );
- if(u_strncmp(dateString, exp, (int32_t)strlen(expStr)) !=0)
- log_err("Error in formatting a pattern with single quotes\n");
+ } else {
+ tzID=(UChar*)malloc(sizeof(UChar) * 4);
+ u_uastrcpy(tzID, "PST");
+ /* this is supposed to open default date format, but later on it treats it like it is "en_US"
+ - very bad if you try to run the tests on machine where default locale is NOT "en_US" */
+ /* cal=ucal_open(tzID, u_strlen(tzID), NULL, UCAL_TRADITIONAL, &status); */
+ cal=ucal_open(tzID, u_strlen(tzID), "en_US", UCAL_TRADITIONAL, &status);
+ if(U_FAILURE(status)){ log_err("error in ucal_open cal : %s\n", myErrorName(status)); }
+ ucal_setDateTime(cal, 1999, UCAL_APRIL, 13, 10, 42, 28, &status);
+ currentTime_1 = ucal_getMillis(cal, &status);
+
+ dateString = myDateFormat(format, currentTime_1);
+ exp=(UChar*)malloc(sizeof(UChar) * (strlen(expStr) + 1) );
+ u_uastrcpy(exp, expStr);
+
+ log_verbose("%s\n", austrdup(dateString) );
+ if(u_strncmp(dateString, exp, (int32_t)strlen(expStr)) !=0) {
+ log_err("Error in formatting a pattern with single quotes\n");
+ }
+ }
udat_close(format);
ucal_close(cal);
free(exp);
diff --git a/icu4c/source/test/cintltst/cdtrgtst.c b/icu4c/source/test/cintltst/cdtrgtst.c
index 66ca85b..e88327d 100644
--- a/icu4c/source/test/cintltst/cdtrgtst.c
+++ b/icu4c/source/test/cintltst/cdtrgtst.c
@@ -166,6 +166,7 @@
if(U_FAILURE(status))
{
log_data_err("FAIL: error in creating the dateformat using u_openPattern(): %s - (Are you missing data?)\n", myErrorName(status));
+ ucal_close(cal);
return;
}
start = 1800;
diff --git a/icu4c/source/test/cintltst/cloctst.c b/icu4c/source/test/cintltst/cloctst.c
index b53fe7c..0a1a0ae 100644
--- a/icu4c/source/test/cintltst/cloctst.c
+++ b/icu4c/source/test/cintltst/cloctst.c
@@ -2420,6 +2420,7 @@
displayKeywordLen = uloc_getDisplayKeyword(keyword, testCases[i].displayLocale, displayKeyword, displayKeywordLen, &status);
if(U_FAILURE(status)){
log_err("uloc_getDisplayKeyword filed for keyword : %s in locale id: %s for display locale: %s \n", testCases[i].localeID, keyword, testCases[i].displayLocale, u_errorName(status));
+ free(displayKeyword);
break;
}
if(u_strncmp(displayKeyword, testCases[i].displayKeyword, displayKeywordLen)!=0){
@@ -2428,6 +2429,7 @@
} else {
log_err("uloc_getDisplayKeyword did not get the expected value for keyword : %s in locale id: %s for display locale: %s \n", testCases[i].localeID, keyword, testCases[i].displayLocale);
}
+ free(displayKeyword);
break;
}
}else{
@@ -2503,6 +2505,7 @@
displayKeywordValueLen = uloc_getDisplayKeywordValue(testCases[i].localeID, keyword, testCases[i].displayLocale, displayKeywordValue, displayKeywordValueLen, &status);
if(U_FAILURE(status)){
log_err("uloc_getDisplayKeywordValue failed for keyword : %s in locale id: %s for display locale: %s with error : %s \n", testCases[i].localeID, keyword, testCases[i].displayLocale, u_errorName(status));
+ free(displayKeywordValue);
break;
}
if(u_strncmp(displayKeywordValue, testCases[i].displayKeywordValue, displayKeywordValueLen)!=0){
@@ -2511,6 +2514,7 @@
} else {
log_err("uloc_getDisplayKeywordValue did not return the expected value keyword : %s in locale id: %s for display locale: %s with error : %s \n", testCases[i].localeID, keyword, testCases[i].displayLocale, u_errorName(status));
}
+ free(displayKeywordValue);
break;
}
}else{
@@ -2556,6 +2560,7 @@
displayKeywordValueLen = uloc_getDisplayKeywordValue(localeID, keyword, displayLocale, displayKeywordValue, displayKeywordValueLen, &status);
if(U_FAILURE(status)){
log_err("uloc_getDisplayKeywordValue failed for keyword : %s in locale id: %s for display locale: %s with error : %s \n", localeID, keyword, displayLocale, u_errorName(status));
+ free(displayKeywordValue);
break;
}
if(u_strncmp(displayKeywordValue, expected[keywordCount], displayKeywordValueLen)!=0){
@@ -2564,6 +2569,7 @@
} else {
log_err("uloc_getDisplayKeywordValue did not return the expected value keyword : %s in locale id: %s for display locale: %s \n", localeID, keyword, displayLocale);
}
+ free(displayKeywordValue);
break;
}
}else{
diff --git a/icu4c/source/test/cintltst/cmsccoll.c b/icu4c/source/test/cintltst/cmsccoll.c
index 7ad2336..bc7a766 100644
--- a/icu4c/source/test/cintltst/cmsccoll.c
+++ b/icu4c/source/test/cintltst/cmsccoll.c
@@ -588,11 +588,13 @@
coll = ucol_open("", &status);
if (U_FAILURE(status)) {
log_data_err("Error opening collator -> %s (Are you missing data?)\n", u_errorName(status));
+ uset_close(charsToTest);
return;
}
charsToTestSize = uset_size(charsToTest);
if (charsToTestSize <= 0) {
log_err("Set was zero. Missing data?\n");
+ uset_close(charsToTest);
return;
}
t = (tester **)malloc(charsToTestSize * sizeof(tester *));
diff --git a/icu4c/source/test/cintltst/cmsgtst.c b/icu4c/source/test/cintltst/cmsgtst.c
index 1673009..06952d8 100644
--- a/icu4c/source/test/cintltst/cmsgtst.c
+++ b/icu4c/source/test/cintltst/cmsgtst.c
@@ -189,6 +189,7 @@
if(U_FAILURE(ec)){
log_data_err("umsg_open() failed for testCasePattens[0]. -> %s (Are you missing data?)\n", u_errorName(ec));
+ umsg_close(formatter);
return;
}
for(i = 0;i<cnt_testCases; i++){
@@ -205,6 +206,7 @@
umsg_applyPattern(formatter,testCasePatterns[i],patternLength,&parseError,&ec);
if(U_FAILURE(ec)){
log_err("umsg_applyPattern() failed for testCasePattens[%d].\n",i);
+ umsg_close(formatter);
return;
}
/* pre-flight */
@@ -216,6 +218,7 @@
if(U_FAILURE(ec)){
log_err("ERROR: failure in message format on testcase %d: %s\n", i, u_errorName(status) );
free(result);
+ umsg_close(formatter);
return;
}
@@ -404,6 +407,7 @@
d1=ucal_getMillis(cal, &status);
if(U_FAILURE(status)){
log_err("Error: failure in get millis: %s\n", myErrorName(status) );
+ goto cleanup;
}
log_verbose("\nTesting with pattern test#4");
@@ -536,14 +540,17 @@
/*try to parse this and check*/
log_verbose("\nTesting the parse Message test#5\n");
- u_parseMessageWithError("en_US", pattern, u_strlen(pattern), result, u_strlen(result), &parseError,&status, &d, ret, &value);
- if(U_FAILURE(status)){
- log_data_err("ERROR: error in parsing: test#5: %s (Are you missing data?)\n", myErrorName(status));
+ if (U_SUCCESS(status)) {
+ u_parseMessageWithError("en_US", pattern, u_strlen(pattern), result, u_strlen(result),
+ &parseError,&status, &d, ret, &value);
+ if(U_FAILURE(status)){
+ log_data_err("ERROR: error in parsing: test#5: %s (Are you missing data?)\n", myErrorName(status));
+ }
+ else if(value!=7 && u_strcmp(str,ret)!=0)
+ log_err("FAIL: Error in parseMessage on test#5 \n");
+ else
+ log_verbose("PASS: parseMessage successful on test#5\n");
}
- else if(value!=7 && u_strcmp(str,ret)!=0)
- log_err("FAIL: Error in parseMessage on test#5 \n");
- else
- log_verbose("PASS: parseMessage successful on test#5\n");
def1 = udat_open(UDAT_DEFAULT,UDAT_DEFAULT ,NULL, NULL, 0, NULL,0,&status);
if(U_FAILURE(status))
@@ -632,14 +639,16 @@
/*try to parse this and check*/
log_verbose("\nTesting the parse Message test#5\n");
- u_parseMessage("en_US", pattern, u_strlen(pattern), result, u_strlen(result), &status, &d, ret, &value);
- if(U_FAILURE(status)){
- log_data_err("ERROR: error in parsing: test#5: %s (Are you missing data?)\n", myErrorName(status));
+ if (U_SUCCESS(status)) {
+ u_parseMessage("en_US", pattern, u_strlen(pattern), result, u_strlen(result), &status, &d, ret, &value);
+ if(U_FAILURE(status)){
+ log_data_err("ERROR: error in parsing: test#5: %s (Are you missing data?)\n", myErrorName(status));
+ }
+ else if(value!=7 && u_strcmp(str,ret)!=0)
+ log_err("FAIL: Error in parseMessage on test#5 \n");
+ else
+ log_verbose("PASS: parseMessage successful on test#5\n");
}
- else if(value!=7 && u_strcmp(str,ret)!=0)
- log_err("FAIL: Error in parseMessage on test#5 \n");
- else
- log_verbose("PASS: parseMessage successful on test#5\n");
def1 = udat_open(UDAT_DEFAULT,UDAT_DEFAULT ,NULL, NULL, 0, NULL,0,&status);
if(U_FAILURE(status))
diff --git a/icu4c/source/test/cintltst/cnmdptst.c b/icu4c/source/test/cintltst/cnmdptst.c
index 1af298e..a40db7c 100644
--- a/icu4c/source/test/cintltst/cnmdptst.c
+++ b/icu4c/source/test/cintltst/cnmdptst.c
@@ -256,6 +256,8 @@
fmt=unum_open(UNUM_IGNORE,upat, u_strlen(upat), "en_US",NULL, &status);
if (U_FAILURE(status)) {
log_err_status(status, "FAIL: Bad status returned by Number format construction with pattern %s -> %s\n", pat[p], u_errorName(status));
+ free(upat);
+ upat = NULL;
continue;
}
lneed= u_strlen(upat) + 1;
diff --git a/icu4c/source/test/cintltst/cnormtst.c b/icu4c/source/test/cintltst/cnormtst.c
index 8f31ad4..a71a3f3 100644
--- a/icu4c/source/test/cintltst/cnormtst.c
+++ b/icu4c/source/test/cintltst/cnormtst.c
@@ -484,6 +484,7 @@
UNORM_YES)
{
log_data_err("ERROR in NFD quick check for string at count %d - (Are you missing data?)\n", count);
+ free(d); free(c);
return;
}
@@ -491,6 +492,7 @@
UNORM_NO)
{
log_err("ERROR in NFC quick check for string at count %d\n", count);
+ free(d); free(c);
return;
}
@@ -506,6 +508,7 @@
UNORM_YES)
{
log_data_err("ERROR in NFKD quick check for string at count %d\n", count);
+ free(d); free(c);
return;
}
@@ -513,6 +516,7 @@
UNORM_YES)
{
log_err("ERROR in NFKC quick check for string at count %d\n", count);
+ free(d); free(c);
return;
}
@@ -1413,6 +1417,7 @@
log_data_err("%s:%d errorCode=%s\n", __FILE__, __LINE__, u_errorName(errorCode));
break;
}
+
/* length-length == 0 is used to get around a compiler warning. */
U16_GET(nfd, 0, length-length, length, lead);
U16_GET(nfd, 0, length-1, length, trail);
diff --git a/icu4c/source/test/cintltst/cstrcase.c b/icu4c/source/test/cintltst/cstrcase.c
index 7ea8424..0a9ec2c 100644
--- a/icu4c/source/test/cintltst/cstrcase.c
+++ b/icu4c/source/test/cintltst/cstrcase.c
@@ -916,6 +916,7 @@
ucasemap_setOptions(csm, U_TITLECASE_NO_BREAK_ADJUSTMENT, &errorCode);
if(U_FAILURE(errorCode)) {
log_err_status(errorCode, "error: ucasemap_setOptions(U_TITLECASE_NO_BREAK_ADJUSTMENT) failed - %s\n", u_errorName(errorCode));
+ ucasemap_close(csm);
return;
}
@@ -951,6 +952,7 @@
ucasemap_setOptions(csm, U_TITLECASE_NO_LOWERCASE, &errorCode);
if(U_FAILURE(errorCode)) {
log_err("error: ucasemap_setOptions(U_TITLECASE_NO_LOWERCASE) failed - %s\n", u_errorName(errorCode));
+ ucasemap_close(csm);
return;
}
diff --git a/icu4c/source/test/cintltst/nucnvtst.c b/icu4c/source/test/cintltst/nucnvtst.c
index aa0a7c7..e85c4d0 100644
--- a/icu4c/source/test/cintltst/nucnvtst.c
+++ b/icu4c/source/test/cintltst/nucnvtst.c
@@ -3095,17 +3095,18 @@
UChar *uTarget;
char *cTarget;
const char *cTargetLimit;
- char *cBuf;
- UChar *uBuf,*test;
+ char *cBuf = NULL;
+ UChar *uBuf = NULL;
+ UChar *test;
int32_t uBufSize = 120;
UErrorCode errorCode=U_ZERO_ERROR;
- UConverter *cnv;
+ UConverter *cnv = NULL;
int32_t* offsets = (int32_t*) malloc(uBufSize * sizeof(int32_t) * 5);
int32_t* myOff= offsets;
cnv=ucnv_open("HZ", &errorCode);
if(U_FAILURE(errorCode)) {
log_data_err("Unable to open HZ converter: %s\n", u_errorName(errorCode));
- return;
+ goto cleanup;
}
uBuf = (UChar*)malloc(uBufSize * sizeof(UChar)*5);
@@ -3119,7 +3120,7 @@
ucnv_fromUnicode( cnv , &cTarget, cTargetLimit,&uSource,uSourceLimit,myOff,TRUE, &errorCode);
if(U_FAILURE(errorCode)){
log_err("ucnv_fromUnicode conversion failed reason %s\n", u_errorName(errorCode));
- return;
+ goto cleanup;
}
cSource = cBuf;
cSourceLimit =cTarget;
@@ -3128,7 +3129,7 @@
ucnv_toUnicode(cnv,&uTarget,uTargetLimit,&cSource,cSourceLimit,myOff,TRUE,&errorCode);
if(U_FAILURE(errorCode)){
log_err("ucnv_toUnicode conversion failed reason %s\n", u_errorName(errorCode));
- return;
+ goto cleanup;
}
uSource = (const UChar*)in;
while(uSource<uSourceLimit){
@@ -3144,6 +3145,8 @@
TestSmallSourceBuffer(in,(const UChar*)in + UPRV_LENGTHOF(in),cnv);
TestToAndFromUChars(in,(const UChar*)in + UPRV_LENGTHOF(in),cnv);
TestJitterbug930("csISO2022JP");
+
+cleanup:
ucnv_close(cnv);
free(offsets);
free(uBuf);
@@ -3314,17 +3317,18 @@
UChar *uTarget;
char *cTarget;
const char *cTargetLimit;
- char *cBuf;
- UChar *uBuf,*test;
+ char *cBuf = NULL;
+ UChar *uBuf = NULL;
+ UChar *test;
int32_t uBufSize = 120;
UErrorCode errorCode=U_ZERO_ERROR;
- UConverter *cnv;
+ UConverter *cnv = NULL;
int32_t* offsets = (int32_t*) malloc(uBufSize * sizeof(int32_t) * 5);
int32_t* myOff= offsets;
cnv=ucnv_open("ISO_2022_JP_1", &errorCode);
if(U_FAILURE(errorCode)) {
log_data_err("Unable to open an ISO_2022_JP_1 converter: %s\n", u_errorName(errorCode));
- return;
+ goto cleanup;
}
uBuf = (UChar*)malloc(uBufSize * sizeof(UChar)*5);
@@ -3338,7 +3342,7 @@
ucnv_fromUnicode( cnv , &cTarget, cTargetLimit,&uSource,uSourceLimit,myOff,TRUE, &errorCode);
if(U_FAILURE(errorCode)){
log_err("ucnv_fromUnicode conversion failed reason %s\n", u_errorName(errorCode));
- return;
+ goto cleanup;
}
cSource = cBuf;
cSourceLimit =cTarget;
@@ -3347,7 +3351,7 @@
ucnv_toUnicode(cnv,&uTarget,uTargetLimit,&cSource,cSourceLimit,myOff,TRUE,&errorCode);
if(U_FAILURE(errorCode)){
log_err("ucnv_toUnicode conversion failed reason %s\n", u_errorName(errorCode));
- return;
+ goto cleanup;
}
uSource = (const UChar*)in;
@@ -3365,6 +3369,8 @@
TestGetNextUChar2022(cnv, cBuf, cTarget, in, "ISO-2022-JP encoding");
TestToAndFromUChars(in,(const UChar*)in + UPRV_LENGTHOF(in),cnv);
TestJitterbug930("csISO2022JP");
+
+cleanup:
ucnv_close(cnv);
free(uBuf);
free(cBuf);
@@ -3946,17 +3952,18 @@
UChar *uTarget;
char *cTarget;
const char *cTargetLimit;
- char *cBuf;
- UChar *uBuf,*test;
+ char *cBuf = NULL;
+ UChar *uBuf = NULL;
+ UChar *test;
int32_t uBufSize = 120;
UErrorCode errorCode=U_ZERO_ERROR;
- UConverter *cnv;
+ UConverter *cnv = NULL;
int32_t* offsets = (int32_t*) malloc(uBufSize * sizeof(int32_t) * 5);
int32_t* myOff= offsets;
cnv=ucnv_open("ISO_2022_JP_2", &errorCode);
if(U_FAILURE(errorCode)) {
log_data_err("Unable to open a iso-2022 converter: %s\n", u_errorName(errorCode));
- return;
+ goto cleanup;
}
uBuf = (UChar*)malloc(uBufSize * sizeof(UChar)*5);
@@ -3970,7 +3977,7 @@
ucnv_fromUnicode( cnv , &cTarget, cTargetLimit,&uSource,uSourceLimit,myOff,TRUE, &errorCode);
if(U_FAILURE(errorCode)){
log_err("ucnv_fromUnicode conversion failed reason %s\n", u_errorName(errorCode));
- return;
+ goto cleanup;
}
cSource = cBuf;
cSourceLimit =cTarget;
@@ -3979,7 +3986,7 @@
ucnv_toUnicode(cnv,&uTarget,uTargetLimit,&cSource,cSourceLimit,myOff,TRUE,&errorCode);
if(U_FAILURE(errorCode)){
log_err("ucnv_toUnicode conversion failed reason %s\n", u_errorName(errorCode));
- return;
+ goto cleanup;
}
uSource = (const UChar*)in;
while(uSource<uSourceLimit){
@@ -3999,6 +4006,8 @@
static const uint8_t source2[]={0x0e,0x24,0x053};
TestNextUCharError(cnv, (const char*)source2, (const char*)source2+sizeof(source2), U_ZERO_ERROR, "an invalid character [ISO-2022-JP-2]");
}
+
+cleanup:
ucnv_close(cnv);
free(uBuf);
free(cBuf);
@@ -4023,17 +4032,18 @@
UChar *uTarget;
char *cTarget;
const char *cTargetLimit;
- char *cBuf;
- UChar *uBuf,*test;
+ char *cBuf = NULL;
+ UChar *uBuf = NULL;
+ UChar *test;
int32_t uBufSize = 120;
UErrorCode errorCode=U_ZERO_ERROR;
- UConverter *cnv;
+ UConverter *cnv = NULL;
int32_t* offsets = (int32_t*) malloc(uBufSize * sizeof(int32_t) * 5);
int32_t* myOff= offsets;
cnv=ucnv_open("ISO_2022,locale=kr", &errorCode);
if(U_FAILURE(errorCode)) {
log_data_err("Unable to open a iso-2022 converter: %s\n", u_errorName(errorCode));
- return;
+ goto cleanup;
}
uBuf = (UChar*)malloc(uBufSize * sizeof(UChar)*5);
@@ -4047,7 +4057,7 @@
ucnv_fromUnicode( cnv , &cTarget, cTargetLimit,&uSource,uSourceLimit,myOff,TRUE, &errorCode);
if(U_FAILURE(errorCode)){
log_err("ucnv_fromUnicode conversion failed reason %s\n", u_errorName(errorCode));
- return;
+ goto cleanup;
}
cSource = cBuf;
cSourceLimit =cTarget;
@@ -4056,7 +4066,7 @@
ucnv_toUnicode(cnv,&uTarget,uTargetLimit,&cSource,cSourceLimit,myOff,TRUE,&errorCode);
if(U_FAILURE(errorCode)){
log_err("ucnv_toUnicode conversion failed reason %s\n", u_errorName(errorCode));
- return;
+ goto cleanup;
}
uSource = (const UChar*)in;
while(uSource<uSourceLimit){
@@ -4078,6 +4088,8 @@
ucnv_setToUCallBack(cnv, UCNV_TO_U_CALLBACK_STOP, NULL, NULL, NULL, &errorCode);
TestNextUCharError(cnv, (const char*)source2, (const char*)source2+sizeof(source2), U_ILLEGAL_ESCAPE_SEQUENCE, "an invalid character [ISO-2022-KR]");
}
+
+cleanup:
ucnv_close(cnv);
free(uBuf);
free(cBuf);
@@ -4102,17 +4114,18 @@
UChar *uTarget;
char *cTarget;
const char *cTargetLimit;
- char *cBuf;
- UChar *uBuf,*test;
+ char *cBuf = NULL;
+ UChar *uBuf = NULL;
+ UChar *test;
int32_t uBufSize = 120;
UErrorCode errorCode=U_ZERO_ERROR;
- UConverter *cnv;
+ UConverter *cnv = NULL;
int32_t* offsets = (int32_t*) malloc(uBufSize * sizeof(int32_t) * 5);
int32_t* myOff= offsets;
cnv=ucnv_open("ibm-25546", &errorCode);
if(U_FAILURE(errorCode)) {
log_data_err("Unable to open a iso-2022 converter: %s\n", u_errorName(errorCode));
- return;
+ goto cleanup;
}
uBuf = (UChar*)malloc(uBufSize * sizeof(UChar)*5);
@@ -4126,7 +4139,7 @@
ucnv_fromUnicode( cnv , &cTarget, cTargetLimit,&uSource,uSourceLimit,myOff,TRUE, &errorCode);
if(U_FAILURE(errorCode)){
log_err("ucnv_fromUnicode conversion failed reason %s\n", u_errorName(errorCode));
- return;
+ goto cleanup;
}
cSource = cBuf;
cSourceLimit =cTarget;
@@ -4135,7 +4148,7 @@
ucnv_toUnicode(cnv,&uTarget,uTargetLimit,&cSource,cSourceLimit,myOff,TRUE,&errorCode);
if(U_FAILURE(errorCode)){
log_err("ucnv_toUnicode conversion failed reason %s\n", u_errorName(errorCode));
- return;
+ goto cleanup;
}
uSource = (const UChar*)in;
while(uSource<uSourceLimit){
@@ -4158,6 +4171,8 @@
ucnv_setToUCallBack(cnv, UCNV_TO_U_CALLBACK_STOP, NULL, NULL, NULL, &errorCode);
TestNextUCharError(cnv, (const char*)source2, (const char*)source2+sizeof(source2), U_ILLEGAL_ESCAPE_SEQUENCE, "an invalid character [ISO-2022-KR]");
}
+
+cleanup:
ucnv_close(cnv);
free(uBuf);
free(cBuf);
@@ -4408,17 +4423,18 @@
UChar *uTarget;
char *cTarget;
const char *cTargetLimit;
- char *cBuf;
- UChar *uBuf,*test;
+ char *cBuf = NULL;
+ UChar *uBuf = NULL;
+ UChar *test;
int32_t uBufSize = 180;
UErrorCode errorCode=U_ZERO_ERROR;
- UConverter *cnv;
+ UConverter *cnv = NULL;
int32_t* offsets = (int32_t*) malloc(uBufSize * sizeof(int32_t) * 5);
int32_t* myOff= offsets;
cnv=ucnv_open("ISO_2022,locale=cn,version=1", &errorCode);
if(U_FAILURE(errorCode)) {
log_data_err("Unable to open a iso-2022 converter: %s\n", u_errorName(errorCode));
- return;
+ goto cleanup;
}
uBuf = (UChar*)malloc(uBufSize * sizeof(UChar)*5);
@@ -4432,7 +4448,7 @@
ucnv_fromUnicode( cnv , &cTarget, cTargetLimit,&uSource,uSourceLimit,myOff,TRUE, &errorCode);
if(U_FAILURE(errorCode)){
log_err("ucnv_fromUnicode conversion failed reason %s\n", u_errorName(errorCode));
- return;
+ goto cleanup;
}
cSource = cBuf;
cSourceLimit =cTarget;
@@ -4441,7 +4457,7 @@
ucnv_toUnicode(cnv,&uTarget,uTargetLimit,&cSource,cSourceLimit,myOff,TRUE,&errorCode);
if(U_FAILURE(errorCode)){
log_err("ucnv_toUnicode conversion failed reason %s\n", u_errorName(errorCode));
- return;
+ goto cleanup;
}
uSource = (const UChar*)in;
while(uSource<uSourceLimit){
@@ -4462,6 +4478,8 @@
static const uint8_t source2[]={0x0e,0x24,0x053};
TestNextUCharError(cnv, (const char*)source2, (const char*)source2+sizeof(source2), U_ZERO_ERROR, "an invalid character [ISO-2022-CN-EXT]");
}
+
+cleanup:
ucnv_close(cnv);
free(uBuf);
free(cBuf);
@@ -4507,17 +4525,18 @@
UChar *uTarget;
char *cTarget;
const char *cTargetLimit;
- char *cBuf;
- UChar *uBuf,*test;
+ char *cBuf = NULL;
+ UChar *uBuf = NULL;
+ UChar *test;
int32_t uBufSize = 180;
UErrorCode errorCode=U_ZERO_ERROR;
- UConverter *cnv;
+ UConverter *cnv = NULL;
int32_t* offsets = (int32_t*) malloc(uBufSize * sizeof(int32_t) * 5);
int32_t* myOff= offsets;
cnv=ucnv_open("ISO_2022,locale=cn,version=0", &errorCode);
if(U_FAILURE(errorCode)) {
log_data_err("Unable to open a iso-2022 converter: %s\n", u_errorName(errorCode));
- return;
+ goto cleanup;
}
uBuf = (UChar*)malloc(uBufSize * sizeof(UChar)*5);
@@ -4531,7 +4550,7 @@
ucnv_fromUnicode( cnv , &cTarget, cTargetLimit,&uSource,uSourceLimit,myOff,TRUE, &errorCode);
if(U_FAILURE(errorCode)){
log_err("ucnv_fromUnicode conversion failed reason %s\n", u_errorName(errorCode));
- return;
+ goto cleanup;
}
cSource = cBuf;
cSourceLimit =cTarget;
@@ -4540,7 +4559,7 @@
ucnv_toUnicode(cnv,&uTarget,uTargetLimit,&cSource,cSourceLimit,myOff,TRUE,&errorCode);
if(U_FAILURE(errorCode)){
log_err("ucnv_toUnicode conversion failed reason %s\n", u_errorName(errorCode));
- return;
+ goto cleanup;
}
uSource = (const UChar*)in;
while(uSource<uSourceLimit){
@@ -4565,6 +4584,7 @@
TestNextUCharError(cnv, (const char*)source2, (const char*)source2+sizeof(source2), U_ZERO_ERROR, "an invalid character [ISO-2022-CN]");
}
+cleanup:
ucnv_close(cnv);
free(uBuf);
free(cBuf);
diff --git a/icu4c/source/test/intltest/alphaindextst.cpp b/icu4c/source/test/intltest/alphaindextst.cpp
index 5b1c606..de49eb2 100644
--- a/icu4c/source/test/intltest/alphaindextst.cpp
+++ b/icu4c/source/test/intltest/alphaindextst.cpp
@@ -96,34 +96,35 @@
UErrorCode status = U_ZERO_ERROR;
int32_t lc = 0;
int32_t i = 0;
- AlphabeticIndex *index = new AlphabeticIndex(Locale::getEnglish(), status);
+ LocalPointer<AlphabeticIndex> index(new AlphabeticIndex(Locale::getEnglish(), status));
TEST_CHECK_STATUS;
lc = index->getBucketCount(status);
TEST_CHECK_STATUS;
TEST_ASSERT(28 == lc); // 26 letters plus two under/overflow labels.
//printf("getBucketCount() == %d\n", lc);
- delete index;
+ index.adoptInstead(nullptr);
// Constructor from a Collator
//
status = U_ZERO_ERROR;
- RuleBasedCollator *coll = dynamic_cast<RuleBasedCollator *>(
- Collator::createInstance(Locale::getGerman(), status));
+ LocalPointer<RuleBasedCollator> coll(dynamic_cast<RuleBasedCollator *>(
+ Collator::createInstance(Locale::getGerman(), status)), status);
TEST_CHECK_STATUS;
- TEST_ASSERT(coll != NULL);
- index = new AlphabeticIndex(coll, status);
+ TEST_ASSERT(coll.isValid());
+ RuleBasedCollator *originalColl = coll.getAlias();
+ index.adoptInstead(new AlphabeticIndex(coll.orphan(), status));
TEST_CHECK_STATUS;
- TEST_ASSERT(coll == &index->getCollator());
+ TEST_ASSERT(originalColl == &index->getCollator());
assertEquals("only the underflow label in an index built from a collator",
1, index->getBucketCount(status));
TEST_CHECK_STATUS;
- delete index;
+ index.adoptInstead(nullptr);
// addLabels()
status = U_ZERO_ERROR;
- index = new AlphabeticIndex(Locale::getEnglish(), status);
+ index.adoptInstead(new AlphabeticIndex(Locale::getEnglish(), status));
TEST_CHECK_STATUS;
UnicodeSet additions;
additions.add((UChar32)0x410).add((UChar32)0x415); // A couple of Cyrillic letters
@@ -134,32 +135,31 @@
assertEquals("underflow, A-Z, inflow, 2 Cyrillic, overflow",
31, index->getBucketCount(status));
// std::cout << lc << std::endl;
- delete index;
+ index.adoptInstead(nullptr);
// addLabels(Locale)
status = U_ZERO_ERROR;
- index = new AlphabeticIndex(Locale::getEnglish(), status);
+ index.adoptInstead(new AlphabeticIndex(Locale::getEnglish(), status));
TEST_CHECK_STATUS;
AlphabeticIndex &aip = index->addLabels(Locale::getJapanese(), status);
- TEST_ASSERT(&aip == index);
+ TEST_ASSERT(&aip == index.getAlias());
TEST_CHECK_STATUS;
lc = index->getBucketCount(status);
TEST_CHECK_STATUS;
TEST_ASSERT(35 < lc); // Japanese should add a bunch. Don't rely on the exact value.
- delete index;
+ index.adoptInstead(nullptr);
// GetCollator(), Get under/in/over flow labels
status = U_ZERO_ERROR;
- index = new AlphabeticIndex(Locale::getGerman(), status);
+ index.adoptInstead(new AlphabeticIndex(Locale::getGerman(), status));
TEST_CHECK_STATUS;
- Collator *germanCol = Collator::createInstance(Locale::getGerman(), status);
+ LocalPointer<Collator> germanCol(Collator::createInstance(Locale::getGerman(), status));
TEST_CHECK_STATUS;
const RuleBasedCollator &indexCol = index->getCollator();
TEST_ASSERT(*germanCol == indexCol);
- delete germanCol;
UnicodeString ELLIPSIS; ELLIPSIS.append((UChar32)0x2026);
UnicodeString s = index->getUnderflowLabel();
@@ -180,7 +180,7 @@
- delete index;
+ index.adoptInstead(nullptr);
@@ -194,7 +194,7 @@
// addRecord(), verify that it comes back out.
//
status = U_ZERO_ERROR;
- index = new AlphabeticIndex(Locale::getEnglish(), status);
+ index.adoptInstead(new AlphabeticIndex(Locale::getEnglish(), status));
TEST_CHECK_STATUS;
index->addRecord(UnicodeString("Adam"), this, status);
UBool b;
@@ -217,12 +217,12 @@
const void *itemContext = index->getRecordData();
TEST_ASSERT(itemContext == this);
- delete index;
+ index.adoptInstead(nullptr);
// clearRecords, addRecord(), Iteration
status = U_ZERO_ERROR;
- index = new AlphabeticIndex(Locale::getEnglish(), status);
+ index.adoptInstead(new AlphabeticIndex(Locale::getEnglish(), status));
TEST_CHECK_STATUS;
while (index->nextBucket(status)) {
TEST_CHECK_STATUS;
@@ -265,12 +265,12 @@
}
}
TEST_CHECK_STATUS;
- delete index;
+ index.adoptInstead(nullptr);
// getBucketLabel(), getBucketType()
status = U_ZERO_ERROR;
- index = new AlphabeticIndex(Locale::getEnglish(), status);
+ index.adoptInstead(new AlphabeticIndex(Locale::getEnglish(), status));
TEST_CHECK_STATUS;
index->setUnderflowLabel(adam, status).setOverflowLabel(charlie, status);
TEST_CHECK_STATUS;
@@ -294,12 +294,12 @@
}
}
TEST_ASSERT(i==28);
- delete index;
+ index.adoptInstead(nullptr);
// getBucketIndex()
status = U_ZERO_ERROR;
- index = new AlphabeticIndex(Locale::getEnglish(), status);
+ index.adoptInstead(new AlphabeticIndex(Locale::getEnglish(), status));
TEST_CHECK_STATUS;
int32_t n = index->getBucketIndex(adam, status);
TEST_CHECK_STATUS;
@@ -319,8 +319,8 @@
}
TEST_ASSERT(i == 28);
- delete index;
- index = new AlphabeticIndex(Locale::createFromName("ru"), status);
+ index.adoptInstead(nullptr);
+ index.adoptInstead(new AlphabeticIndex(Locale::createFromName("ru"), status));
TEST_CHECK_STATUS;
assertEquals("Russian index.getBucketCount()", 32, index->getBucketCount(status));
// Latin-script names should go into the underflow label (0)
@@ -342,8 +342,6 @@
n = index->getBucketIndex(zed, status);
assertEquals("Russian index.getBucketIndex(zed)", expectedLatinIndex, n);
- delete index;
-
}
diff --git a/icu4c/source/test/intltest/astrotst.cpp b/icu4c/source/test/intltest/astrotst.cpp
index 3650c08..059e645 100644
--- a/icu4c/source/test/intltest/astrotst.cpp
+++ b/icu4c/source/test/intltest/astrotst.cpp
@@ -261,7 +261,7 @@
logln("Sunrise/Sunset times for Toronto, Canada");
// long = 79 25", lat = 43 40"
- CalendarAstronomer *astro3 = new CalendarAstronomer(-(79+25/60), 43+40/60);
+ CalendarAstronomer astro3(-(79+25/60), 43+40/60);
// As of ICU4J 2.8 the ICU4J time zones implement pass-through
// to the underlying JDK. Because of variation in the
@@ -271,46 +271,47 @@
// [aliu 10/15/03]
// TimeZone tz = TimeZone.getTimeZone("America/Montreal");
- TimeZone *tz = new SimpleTimeZone(-18000000 + 3600000, "Montreal(FIXED)");
+ SimpleTimeZone tz(-18000000 + 3600000, "Montreal(FIXED)");
- GregorianCalendar *cal = new GregorianCalendar(tz->clone(), Locale::getUS(), status);
- GregorianCalendar *cal2 = new GregorianCalendar(tz->clone(), Locale::getUS(), status);
- cal->clear();
- cal->set(UCAL_YEAR, 2001);
- cal->set(UCAL_MONTH, UCAL_APRIL);
- cal->set(UCAL_DAY_OF_MONTH, 1);
- cal->set(UCAL_HOUR_OF_DAY, 12); // must be near local noon for getSunRiseSet to work
+ GregorianCalendar cal(tz.clone(), Locale::getUS(), status);
+ GregorianCalendar cal2(tz.clone(), Locale::getUS(), status);
+ cal.clear();
+ cal.set(UCAL_YEAR, 2001);
+ cal.set(UCAL_MONTH, UCAL_APRIL);
+ cal.set(UCAL_DAY_OF_MONTH, 1);
+ cal.set(UCAL_HOUR_OF_DAY, 12); // must be near local noon for getSunRiseSet to work
- DateFormat *df_t = DateFormat::createTimeInstance(DateFormat::MEDIUM,Locale::getUS());
- DateFormat *df_d = DateFormat::createDateInstance(DateFormat::MEDIUM,Locale::getUS());
- DateFormat *df_dt = DateFormat::createDateTimeInstance(DateFormat::MEDIUM, DateFormat::MEDIUM, Locale::getUS());
- if(!df_t || !df_d || !df_dt) {
- dataerrln("couldn't create dateformats.");
- return;
+ LocalPointer<DateFormat> df_t(DateFormat::createTimeInstance(DateFormat::MEDIUM,Locale::getUS()));
+ LocalPointer<DateFormat> df_d(DateFormat::createDateInstance(DateFormat::MEDIUM,Locale::getUS()));
+ LocalPointer<DateFormat> df_dt(DateFormat::createDateTimeInstance(DateFormat::MEDIUM, DateFormat::MEDIUM, Locale::getUS()));
+ if(!df_t.isValid() || !df_d.isValid() || !df_dt.isValid()) {
+ dataerrln("couldn't create dateformats.");
+ closeAstro(status);
+ return;
}
- df_t->adoptTimeZone(tz->clone());
- df_d->adoptTimeZone(tz->clone());
- df_dt->adoptTimeZone(tz->clone());
+ df_t->adoptTimeZone(tz.clone());
+ df_d->adoptTimeZone(tz.clone());
+ df_dt->adoptTimeZone(tz.clone());
for (int32_t i=0; i < 30; i++) {
logln("setDate\n");
- astro3->setDate(cal->getTime(status));
+ astro3.setDate(cal.getTime(status));
logln("getRiseSet(TRUE)\n");
- UDate sunrise = astro3->getSunRiseSet(TRUE);
+ UDate sunrise = astro3.getSunRiseSet(TRUE);
logln("getRiseSet(FALSE)\n");
- UDate sunset = astro3->getSunRiseSet(FALSE);
+ UDate sunset = astro3.getSunRiseSet(FALSE);
logln("end of getRiseSet\n");
- cal2->setTime(cal->getTime(status), status);
- cal2->set(UCAL_SECOND, 0);
- cal2->set(UCAL_MILLISECOND, 0);
+ cal2.setTime(cal.getTime(status), status);
+ cal2.set(UCAL_SECOND, 0);
+ cal2.set(UCAL_MILLISECOND, 0);
- cal2->set(UCAL_HOUR_OF_DAY, USNO[4*i+0]);
- cal2->set(UCAL_MINUTE, USNO[4*i+1]);
- UDate exprise = cal2->getTime(status);
- cal2->set(UCAL_HOUR_OF_DAY, USNO[4*i+2]);
- cal2->set(UCAL_MINUTE, USNO[4*i+3]);
- UDate expset = cal2->getTime(status);
+ cal2.set(UCAL_HOUR_OF_DAY, USNO[4*i+0]);
+ cal2.set(UCAL_MINUTE, USNO[4*i+1]);
+ UDate exprise = cal2.getTime(status);
+ cal2.set(UCAL_HOUR_OF_DAY, USNO[4*i+2]);
+ cal2.set(UCAL_MINUTE, USNO[4*i+3]);
+ UDate expset = cal2.getTime(status);
// Compute delta of what we got to the USNO data, in seconds
int32_t deltarise = (int32_t)uprv_fabs((sunrise - exprise) / 1000);
int32_t deltaset = (int32_t)uprv_fabs((sunset - expset) / 1000);
@@ -323,34 +324,34 @@
UnicodeString s1, s2, s3, s4, s5;
if (deltarise > MAX_DEV || deltaset > MAX_DEV) {
if (deltarise > MAX_DEV) {
- errln("FAIL: (rise) " + df_d->format(cal->getTime(status),s1) +
+ errln("FAIL: (rise) " + df_d->format(cal.getTime(status),s1) +
", Sunrise: " + df_dt->format(sunrise, s2) +
" (USNO " + df_t->format(exprise,s3) +
" d=" + deltarise + "s)");
} else {
- logln(df_d->format(cal->getTime(status),s1) +
+ logln(df_d->format(cal.getTime(status),s1) +
", Sunrise: " + df_dt->format(sunrise,s2) +
" (USNO " + df_t->format(exprise,s3) + ")");
}
s1.remove(); s2.remove(); s3.remove(); s4.remove(); s5.remove();
if (deltaset > MAX_DEV) {
- errln("FAIL: (set) " + df_d->format(cal->getTime(status),s1) +
+ errln("FAIL: (set) " + df_d->format(cal.getTime(status),s1) +
", Sunset: " + df_dt->format(sunset,s2) +
" (USNO " + df_t->format(expset,s3) +
" d=" + deltaset + "s)");
} else {
- logln(df_d->format(cal->getTime(status),s1) +
+ logln(df_d->format(cal.getTime(status),s1) +
", Sunset: " + df_dt->format(sunset,s2) +
" (USNO " + df_t->format(expset,s3) + ")");
}
} else {
- logln(df_d->format(cal->getTime(status),s1) +
+ logln(df_d->format(cal.getTime(status),s1) +
", Sunrise: " + df_dt->format(sunrise,s2) +
" (USNO " + df_t->format(exprise,s3) + ")" +
", Sunset: " + df_dt->format(sunset,s4) +
" (USNO " + df_t->format(expset,s5) + ")");
}
- cal->add(UCAL_DATE, 1, status);
+ cal.add(UCAL_DATE, 1, status);
}
// CalendarAstronomer a = new CalendarAstronomer(-(71+5/60), 42+37/60);
@@ -363,13 +364,6 @@
// cal.set(cal.DATE, 27);
// a.setDate(cal.getTime());
// long r = a.getSunRiseSet2(true);
- delete astro3;
- delete tz;
- delete cal;
- delete cal2;
- delete df_t;
- delete df_d;
- delete df_dt;
closeAstro(status);
ASSERT_OK(status);
}
@@ -385,38 +379,43 @@
}
// Check that our JD computation is the same as the book's (p. 88)
- GregorianCalendar *cal3 = new GregorianCalendar(TimeZone::getGMT()->clone(), Locale::getUS(), status);
- DateFormat *d3 = DateFormat::createDateTimeInstance(DateFormat::MEDIUM,DateFormat::MEDIUM,Locale::getUS());
+ GregorianCalendar cal3(TimeZone::getGMT()->clone(), Locale::getUS(), status);
+ LocalPointer<DateFormat> d3(DateFormat::createDateTimeInstance(DateFormat::MEDIUM,DateFormat::MEDIUM,Locale::getUS()));
+ if (d3.isNull()) {
+ dataerrln("Got error: %s", u_errorName(status));
+ closeAstro(status);
+ return;
+ }
d3->setTimeZone(*TimeZone::getGMT());
- cal3->clear();
- cal3->set(UCAL_YEAR, 1980);
- cal3->set(UCAL_MONTH, UCAL_JULY);
- cal3->set(UCAL_DATE, 2);
- logln("cal3[a]=%.1lf, d=%d\n", cal3->getTime(status), cal3->get(UCAL_JULIAN_DAY,status));
+ cal3.clear();
+ cal3.set(UCAL_YEAR, 1980);
+ cal3.set(UCAL_MONTH, UCAL_JULY);
+ cal3.set(UCAL_DATE, 2);
+ logln("cal3[a]=%.1lf, d=%d\n", cal3.getTime(status), cal3.get(UCAL_JULIAN_DAY,status));
{
UnicodeString s;
- logln(UnicodeString("cal3[a] = ") + d3->format(cal3->getTime(status),s));
+ logln(UnicodeString("cal3[a] = ") + d3->format(cal3.getTime(status),s));
}
- cal3->clear();
- cal3->set(UCAL_YEAR, 1980);
- cal3->set(UCAL_MONTH, UCAL_JULY);
- cal3->set(UCAL_DATE, 27);
- logln("cal3=%.1lf, d=%d\n", cal3->getTime(status), cal3->get(UCAL_JULIAN_DAY,status));
+ cal3.clear();
+ cal3.set(UCAL_YEAR, 1980);
+ cal3.set(UCAL_MONTH, UCAL_JULY);
+ cal3.set(UCAL_DATE, 27);
+ logln("cal3=%.1lf, d=%d\n", cal3.getTime(status), cal3.get(UCAL_JULIAN_DAY,status));
ASSERT_OK(status);
{
UnicodeString s;
- logln(UnicodeString("cal3 = ") + d3->format(cal3->getTime(status),s));
+ logln(UnicodeString("cal3 = ") + d3->format(cal3.getTime(status),s));
}
- astro->setTime(cal3->getTime(status));
+ astro->setTime(cal3.getTime(status));
double jd = astro->getJulianDay() - 2447891.5;
double exp = -3444.;
if (jd == exp) {
UnicodeString s;
- logln(d3->format(cal3->getTime(status),s) + " => " + jd);
+ logln(d3->format(cal3.getTime(status),s) + " => " + jd);
} else {
UnicodeString s;
- errln("FAIL: " + d3->format(cal3->getTime(status), s) + " => " + jd +
+ errln("FAIL: " + d3->format(cal3.getTime(status), s) + " => " + jd +
", expected " + exp);
}
@@ -428,8 +427,6 @@
// astro.setDate(cal3.getTime());
// astro.foo();
- delete cal3;
- delete d3;
ASSERT_OK(status);
closeAstro(status);
ASSERT_OK(status);
diff --git a/icu4c/source/test/intltest/calregts.cpp b/icu4c/source/test/intltest/calregts.cpp
index e933c7c..33bcd2f 100644
--- a/icu4c/source/test/intltest/calregts.cpp
+++ b/icu4c/source/test/intltest/calregts.cpp
@@ -1455,31 +1455,26 @@
void CalendarRegressionTest::test4125881()
{
UErrorCode status = U_ZERO_ERROR;
- GregorianCalendar *cal = (GregorianCalendar*) Calendar::createInstance(status);
+ LocalPointer<GregorianCalendar> cal((GregorianCalendar*) Calendar::createInstance(status), status);
if(U_FAILURE(status)) {
- dataerrln("Error creating calendar %s", u_errorName(status));
- delete cal;
- return;
+ dataerrln("Error creating calendar %s", u_errorName(status));
+ return;
}
- DateFormat *fmt = new SimpleDateFormat(UnicodeString("MMMM d, yyyy G"),status);
+ SimpleDateFormat fmt(UnicodeString("MMMM d, yyyy G"),status);
if(U_FAILURE(status)) {
- dataerrln("Error creating SimpleDateFormat - %s", u_errorName(status));
- delete cal;
- return;
+ dataerrln("Error creating SimpleDateFormat - %s", u_errorName(status));
+ return;
}
cal->clear();
for (int32_t y=-20; y<=10; ++y) {
cal->set(UCAL_ERA, y < 1 ? GregorianCalendar::BC : GregorianCalendar::AD);
cal->set(UCAL_YEAR, y < 1 ? 1 - y : y);
UnicodeString temp;
- logln(UnicodeString("") + y + UnicodeString(" = ") + fmt->format(cal->getTime(status), temp) + " " +
+ logln(UnicodeString("") + y + UnicodeString(" = ") + fmt.format(cal->getTime(status), temp) + " " +
cal->isLeapYear(y));
if (cal->isLeapYear(y) != ((y+40)%4 == 0))
errln("Leap years broken");
}
-
- delete cal;
- delete fmt;
}
/**
@@ -1489,17 +1484,15 @@
*/
void CalendarRegressionTest::test4125892() {
UErrorCode status = U_ZERO_ERROR;
- GregorianCalendar *cal = (GregorianCalendar*) Calendar::createInstance(status);
+ LocalPointer<GregorianCalendar> cal((GregorianCalendar*) Calendar::createInstance(status), status);
if(U_FAILURE(status)) {
- dataerrln("Error creating calendar %s", u_errorName(status));
- delete cal;
- return;
+ dataerrln("Error creating calendar %s", u_errorName(status));
+ return;
}
- DateFormat *fmt = new SimpleDateFormat(UnicodeString("MMMM d, yyyy G"),status);
+ SimpleDateFormat fmt(UnicodeString("MMMM d, yyyy G"),status);
if(U_FAILURE(status)) {
- dataerrln("Error creating SimpleDateFormat - %s", u_errorName(status));
- delete cal;
- return;
+ dataerrln("Error creating SimpleDateFormat - %s", u_errorName(status));
+ return;
}
cal->clear();
cal->set(UCAL_ERA, GregorianCalendar::BC);
@@ -1513,8 +1506,6 @@
!cal->isLeapYear(-80)) // -80 == 81 BC
errln("Calendar not proleptic");
- delete cal;
- delete fmt;
}
/**
@@ -1913,22 +1904,21 @@
{
UErrorCode status = U_ZERO_ERROR;
UCalendarDateFields field = UCAL_YEAR;
- DateFormat *format = new SimpleDateFormat(UnicodeString("EEE MMM dd HH:mm:ss zzz yyyy G"),
- Locale::getUS(), status);
+ LocalPointer<DateFormat> format (new SimpleDateFormat(UnicodeString("EEE MMM dd HH:mm:ss zzz yyyy G"),
+ Locale::getUS(), status));
if(U_FAILURE(status)) {
dataerrln("Couldn't create SimpleDateFormat - %s", u_errorName(status));
return;
}
- GregorianCalendar *calendars [] = {
- new GregorianCalendar(100, UCAL_NOVEMBER, 1, status),
- new GregorianCalendar(-99 /*100BC*/, UCAL_JANUARY, 1, status),
- new GregorianCalendar(1996, UCAL_FEBRUARY, 29, status),
+ GregorianCalendar calendars [] = {
+ {100, UCAL_NOVEMBER, 1, status},
+ {-99 /*100BC*/, UCAL_JANUARY, 1, status},
+ {1996, UCAL_FEBRUARY, 29, status}
};
if(U_FAILURE(status)) {
errln("Couldn't create GregorianCalendars");
return;
- // could leak
}
UnicodeString id [] = { "Hybrid", "Gregorian", "Julian" };
@@ -1937,7 +1927,7 @@
logln("--- " + id[k] + " ---");
for (int32_t j=0; j < 3; ++j) {
- GregorianCalendar *calendar = calendars[j];
+ GregorianCalendar *calendar = &calendars[j];
if (k == 1) {
calendar->setGregorianChange(EARLIEST_SUPPORTED_MILLIS, status);
}
@@ -1988,11 +1978,6 @@
}
}
}
-
- delete format;
- delete calendars[0];
- delete calendars[1];
- delete calendars[2];
}
/**
@@ -2283,15 +2268,18 @@
1999, UCAL_JUNE, 4, 1964, UCAL_SEPTEMBER, 7,
};
int32_t DATA_length = UPRV_LENGTHOF(DATA);
- Calendar* pcal = Calendar::createInstance(Locale::getUS(), ec);
+ LocalPointer<Calendar> pcal(Calendar::createInstance(Locale::getUS(), ec));
if(U_FAILURE(ec)) {
- dataerrln("Error creating calendar %s", u_errorName(ec));
- delete pcal;
- return;
+ dataerrln("Error creating calendar %s", u_errorName(ec));
+ return;
}
Calendar& cal = *pcal;
int32_t i;
SimpleDateFormat fmt(UnicodeString("MMM dd yyyy",""), ec);
+ if (U_FAILURE(ec)) {
+ dataerrln("Error creating calendar %s", u_errorName(ec));
+ return;
+ }
fmt.setCalendar(cal);
UnicodeString s, t, u;
if (U_SUCCESS(ec)) {
@@ -2323,7 +2311,7 @@
break;
{
- Calendar *cal2 = cal.clone();
+ LocalPointer<Calendar> cal2(cal.clone());
UErrorCode ec2 = U_ZERO_ERROR;
cal2->setTime(date1, ec2);
@@ -2338,7 +2326,6 @@
(dy2 != dy)){
errln("fieldDifference(UCAL_...) and fieldDifference(Calendar::...) give different results!\n");
}
- delete cal2;
}
@@ -2374,7 +2361,6 @@
} else {
dataerrln("Error creating SimpleDateFormat - %s", u_errorName(ec));
}
- delete pcal;
}
void CalendarRegressionTest::TestT5555()
diff --git a/icu4c/source/test/intltest/convtest.cpp b/icu4c/source/test/intltest/convtest.cpp
index edadb12..53d8cfd 100644
--- a/icu4c/source/test/intltest/convtest.cpp
+++ b/icu4c/source/test/intltest/convtest.cpp
@@ -651,26 +651,26 @@
const char *pattern_ignorable = "[:Default_Ignorable_Code_Point:]";
const char *pattern_not_ignorable = "[:^Default_Ignorable_Code_Point:]";
- UnicodeSet *set_ignorable = new UnicodeSet(pattern_ignorable, status);
+ LocalPointer<UnicodeSet> set_ignorable(new UnicodeSet(pattern_ignorable, status));
if (U_FAILURE(status)) {
dataerrln("Unable to create Unicodeset: %s - %s\n", pattern_ignorable, u_errorName(status));
return;
}
- UnicodeSet *set_not_ignorable = new UnicodeSet(pattern_not_ignorable, status);
+ LocalPointer<UnicodeSet> set_not_ignorable(new UnicodeSet(pattern_not_ignorable, status));
if (U_FAILURE(status)) {
dataerrln("Unable to create Unicodeset: %s - %s\n", pattern_not_ignorable, u_errorName(status));
return;
}
- UConverter *cnv = cnv_open(cnv_name, status);
+ LocalUConverterPointer cnv(cnv_open(cnv_name, status));
if (U_FAILURE(status)) {
dataerrln("Unable to open converter: %s - %s\n", cnv_name, u_errorName(status));
return;
}
// set callback for the converter
- ucnv_setFromUCallBack(cnv, UCNV_FROM_U_CALLBACK_SUBSTITUTE, NULL, NULL, NULL, &status);
+ ucnv_setFromUCallBack(cnv.getAlias(), UCNV_FROM_U_CALLBACK_SUBSTITUTE, NULL, NULL, NULL, &status);
UChar32 input[1];
char output[10];
@@ -684,7 +684,7 @@
input[0] = set_ignorable->charAt(i);
- outputLength = ucnv_fromUChars(cnv, output, 10, UnicodeString::fromUTF32(input, 1).getTerminatedBuffer(), -1, &status);
+ outputLength = ucnv_fromUChars(cnv.getAlias(), output, 10, UnicodeString::fromUTF32(input, 1).getTerminatedBuffer(), -1, &status);
if (U_FAILURE(status) || outputLength != 0) {
errln("Ignorable code point: U+%04X not skipped as expected - %s", input[0], u_errorName(status));
}
@@ -702,15 +702,11 @@
continue;
}
- outputLength = ucnv_fromUChars(cnv, output, 10, UnicodeString::fromUTF32(input, 1).getTerminatedBuffer(), -1, &status);
+ outputLength = ucnv_fromUChars(cnv.getAlias(), output, 10, UnicodeString::fromUTF32(input, 1).getTerminatedBuffer(), -1, &status);
if (U_FAILURE(status) || outputLength <= 0) {
errln("Non-ignorable code point: U+%04X skipped unexpectedly - %s", input[0], u_errorName(status));
}
}
-
- ucnv_close(cnv);
- delete set_not_ignorable;
- delete set_ignorable;
}
void
diff --git a/icu4c/source/test/intltest/csdetest.cpp b/icu4c/source/test/intltest/csdetest.cpp
index 9058b3a..4068df3 100644
--- a/icu4c/source/test/intltest/csdetest.cpp
+++ b/icu4c/source/test/intltest/csdetest.cpp
@@ -20,6 +20,7 @@
#include "xmlparser.h"
+#include <memory>
#include <stdlib.h>
#include <string.h>
@@ -27,8 +28,6 @@
#include <stdio.h>
#endif
-#define NEW_ARRAY(type,count) (type *) /*uprv_*/malloc((count) * sizeof(type))
-#define DELETE_ARRAY(array) /*uprv_*/free((void *) (array))
#define CH_SPACE 0x0020
#define CH_SLASH 0x002F
@@ -148,23 +147,18 @@
length = source.extract(0, sLength, NULL, codepage);
if (length > 0) {
- bytes = NEW_ARRAY(char, length + 1);
+ bytes = new char[length + 1];
source.extract(0, sLength, bytes, codepage);
}
return bytes;
}
-static void freeBytes(char *bytes)
-{
- DELETE_ARRAY(bytes);
-}
-
void CharsetDetectionTest::checkEncoding(const UnicodeString &testString, const UnicodeString &encoding, const UnicodeString &id)
{
int32_t splits = 0;
int32_t testLength = testString.length();
- UnicodeString *eSplit = split(encoding, CH_SLASH, splits);
+ std::unique_ptr<UnicodeString []> eSplit(split(encoding, CH_SLASH, splits));
UErrorCode status = U_ZERO_ERROR;
int32_t cpLength = eSplit[0].length();
char codepage[64];
@@ -175,16 +169,16 @@
LocalUCharsetDetectorPointer csd(ucsdet_open(&status));
int32_t byteLength = 0;
- char *bytes = extractBytes(testString, codepage, byteLength);
+ std::unique_ptr<char []> bytes(extractBytes(testString, codepage, byteLength));
- if (bytes == NULL) {
+ if (! bytes) {
#if !UCONFIG_NO_LEGACY_CONVERSION
dataerrln("Can't open a " + encoding + " converter for " + id);
#endif
return;
}
- ucsdet_setText(csd.getAlias(), bytes, byteLength, &status);
+ ucsdet_setText(csd.getAlias(), bytes.get(), byteLength, &status);
int32_t matchCount = 0;
const UCharsetMatch **matches = ucsdet_detectAll(csd.getAlias(), &matchCount, &status);
@@ -197,7 +191,7 @@
if (matchCount == 0) {
errln("Encoding detection failure for " + id + ": expected " + eSplit[0] + ", got no matches");
- goto bail;
+ return;
}
if (name.compare(eSplit[0]) != 0) {
@@ -212,15 +206,15 @@
printf("%s (%s) %d\n", name, lang, confidence);
}
#endif
- goto bail;
+ return;
}
if (splits > 1 && lang.compare(eSplit[1]) != 0) {
errln("Language detection failure for " + id + ", " + eSplit[0] + ": expected " + eSplit[1] + ", got " + lang);
- goto bail;
+ return;
}
- decoded = NEW_ARRAY(UChar, testLength);
+ decoded = new UChar[testLength];
dLength = ucsdet_getUChars(matches[0], decoded, testLength, &status);
if (testString.compare(decoded, dLength) != 0) {
@@ -237,11 +231,7 @@
}
- DELETE_ARRAY(decoded);
-
-bail:
- freeBytes(bytes);
- delete[] eSplit;
+ delete[] decoded;
}
const char *CharsetDetectionTest::getPath(char buffer[2048], const char *filename) {
@@ -334,7 +324,7 @@
char *bytes = extractBytes(s, "UTF-8", byteLength);
UCharsetDetector *csd = ucsdet_open(&status);
const UCharsetMatch *match;
- UChar *detected = NEW_ARRAY(UChar, sLength);
+ UChar *detected = new UChar[sLength];
ucsdet_setText(csd, bytes, byteLength, &status);
match = ucsdet_detect(csd, &status);
@@ -353,8 +343,8 @@
ucsdet_setDeclaredEncoding(csd, "UTF-8", 5, &status); /* for coverage */
bail:
- DELETE_ARRAY(detected);
- freeBytes(bytes);
+ delete[] detected;
+ delete[] bytes;
ucsdet_close(csd);
}
@@ -370,66 +360,55 @@
0x064a, 0x062a, 0x0000};
UnicodeString s(chars);
int32_t beLength = 0, leLength = 0;
- char *beBytes = extractBytes(s, "UTF-16BE", beLength);
- char *leBytes = extractBytes(s, "UTF-16LE", leLength);
- UCharsetDetector *csd = ucsdet_open(&status);
+ std::unique_ptr<char []>beBytes(extractBytes(s, "UTF-16BE", beLength));
+ std::unique_ptr<char []>leBytes(extractBytes(s, "UTF-16LE", leLength));
+ LocalUCharsetDetectorPointer csd(ucsdet_open(&status));
const UCharsetMatch *match;
const char *name;
int32_t conf;
- ucsdet_setText(csd, beBytes, beLength, &status);
- match = ucsdet_detect(csd, &status);
+ ucsdet_setText(csd.getAlias(), beBytes.get(), beLength, &status);
+ match = ucsdet_detect(csd.getAlias(), &status);
if (match == NULL) {
errln("Encoding detection failure for UTF-16BE: got no matches.");
- goto try_le;
+ } else {
+
+ name = ucsdet_getName(match, &status);
+ conf = ucsdet_getConfidence(match, &status);
+
+ if (strcmp(name, "UTF-16BE") != 0) {
+ errln("Encoding detection failure for UTF-16BE: got %s", name);
+ } else if (conf != 100) {
+ errln("Did not get 100%% confidence for UTF-16BE: got %d", conf);
+ }
}
- name = ucsdet_getName(match, &status);
- conf = ucsdet_getConfidence(match, &status);
-
- if (strcmp(name, "UTF-16BE") != 0) {
- errln("Encoding detection failure for UTF-16BE: got %s", name);
- goto try_le; // no point in looking at confidence if we got the wrong character set.
- }
-
- if (conf != 100) {
- errln("Did not get 100%% confidence for UTF-16BE: got %d", conf);
- }
-
-try_le:
- ucsdet_setText(csd, leBytes, leLength, &status);
- match = ucsdet_detect(csd, &status);
+ ucsdet_setText(csd.getAlias(), leBytes.get(), leLength, &status);
+ match = ucsdet_detect(csd.getAlias(), &status);
if (match == NULL) {
errln("Encoding detection failure for UTF-16LE: got no matches.");
- goto bail;
+ return;
}
name = ucsdet_getName(match, &status);
conf = ucsdet_getConfidence(match, &status);
-
if (strcmp(name, "UTF-16LE") != 0) {
errln("Enconding detection failure for UTF-16LE: got %s", name);
- goto bail; // no point in looking at confidence if we got the wrong character set.
+ return;
}
if (conf != 100) {
errln("Did not get 100%% confidence for UTF-16LE: got %d", conf);
}
-
-bail:
- freeBytes(leBytes);
- freeBytes(beBytes);
- ucsdet_close(csd);
}
void CharsetDetectionTest::InputFilterTest()
{
UErrorCode status = U_ZERO_ERROR;
- UnicodeString ss = "<a> <lot> <of> <English> <inside> <the> <markup> Un tr\\u00E8s petit peu de Fran\\u00E7ais. <to> <confuse> <the> <detector>";
- UnicodeString s = ss.unescape();
+ UnicodeString s(u"<a> <lot> <of> <English> <inside> <the> <markup> Un très petit peu de Français. <to> <confuse> <the> <detector>");
int32_t byteLength = 0;
char *bytes = extractBytes(s, "ISO-8859-1", byteLength);
UCharsetDetector *csd = ucsdet_open(&status);
@@ -486,7 +465,7 @@
}
bail:
- freeBytes(bytes);
+ delete[] bytes;
ucsdet_close(csd);
}
@@ -533,8 +512,8 @@
}
bail:
- freeBytes(bWindows);
- freeBytes(bISO);
+ delete[] bWindows;
+ delete[] bISO;
ucsdet_close(csd);
#endif
@@ -680,8 +659,8 @@
}
bail:
- freeBytes(bytes);
- freeBytes(bytes_r);
+ delete[] bytes;
+ delete[] bytes_r;
ucsdet_close(csd);
#endif
}
@@ -770,8 +749,8 @@
}
bail:
- freeBytes(bytes);
- freeBytes(bytes_r);
+ delete[] bytes;
+ delete[] bytes_r;
ucsdet_close(csd);
#endif
}
@@ -831,23 +810,23 @@
"It also includes some \\u201CC1\\u201D bytes.", -1, US_INV);
UnicodeString sWindows = ssWindows.unescape();
int32_t lISO = 0, lWindows = 0;
- char *bISO = extractBytes(sISO, "ISO-8859-1", lISO);
- char *bWindows = extractBytes(sWindows, "windows-1252", lWindows);
+ std::unique_ptr<char[]> bISO(extractBytes(sISO, "ISO-8859-1", lISO));
+ std::unique_ptr<char[]> bWindows(extractBytes(sWindows, "windows-1252", lWindows));
// First do a plain vanilla detect of 1252 text
- UCharsetDetector *csd1 = ucsdet_open(&status);
- ucsdet_setText(csd1, bWindows, lWindows, &status);
- const UCharsetMatch *match1 = ucsdet_detect(csd1, &status);
+ LocalUCharsetDetectorPointer csd1(ucsdet_open(&status));
+ ucsdet_setText(csd1.getAlias(), bWindows.get(), lWindows, &status);
+ const UCharsetMatch *match1 = ucsdet_detect(csd1.getAlias(), &status);
const char *name1 = ucsdet_getName(match1, &status);
TEST_ASSERT_SUCCESS(status);
TEST_ASSERT(strcmp(name1, "windows-1252")==0);
// Next, using a completely separate detector, detect some 8859-1 text
- UCharsetDetector *csd2 = ucsdet_open(&status);
- ucsdet_setText(csd2, bISO, lISO, &status);
- const UCharsetMatch *match2 = ucsdet_detect(csd2, &status);
+ LocalUCharsetDetectorPointer csd2(ucsdet_open(&status));
+ ucsdet_setText(csd2.getAlias(), bISO.get(), lISO, &status);
+ const UCharsetMatch *match2 = ucsdet_detect(csd2.getAlias(), &status);
const char *name2 = ucsdet_getName(match2, &status);
TEST_ASSERT_SUCCESS(status);
TEST_ASSERT(strcmp(name2, "ISO-8859-1")==0);
@@ -858,10 +837,5 @@
name1 = ucsdet_getName(match1, &status);
TEST_ASSERT_SUCCESS(status);
TEST_ASSERT(strcmp(name1, "windows-1252")==0);
-
- ucsdet_close(csd1);
- ucsdet_close(csd2);
- freeBytes(bISO);
- freeBytes(bWindows);
#endif
}
diff --git a/icu4c/source/test/intltest/dadrcal.cpp b/icu4c/source/test/intltest/dadrcal.cpp
index 658d652..08c9cec 100644
--- a/icu4c/source/test/intltest/dadrcal.cpp
+++ b/icu4c/source/test/intltest/dadrcal.cpp
@@ -366,7 +366,7 @@
void DataDrivenCalendarTest::testConvert(TestData *testData,
const DataMap *settings, UBool forward) {
UErrorCode status = U_ZERO_ERROR;
- Calendar *toCalendar= NULL;
+ LocalPointer<Calendar> toCalendar;
const DataMap *currentCase= NULL;
char toCalLoc[256] = "";
char fromCalLoc[256] = "";
@@ -374,7 +374,7 @@
UnicodeString testSetting = settings->getString("ToCalendar", status);
if (U_SUCCESS(status)) {
testSetting.extract(0, testSetting.length(), toCalLoc, (const char*)0);
- toCalendar = Calendar::createInstance(toCalLoc, status);
+ toCalendar.adoptInstead(Calendar::createInstance(toCalLoc, status));
if (U_FAILURE(status)) {
dataerrln(UnicodeString("Unable to instantiate ToCalendar for ")+testSetting);
return;
@@ -393,11 +393,11 @@
int n = 0;
while (testData->nextCase(currentCase, status)) {
++n;
- Calendar *fromCalendar= NULL;
+ LocalPointer<Calendar> fromCalendar;
UnicodeString locale = currentCase->getString("locale", status);
if (U_SUCCESS(status)) {
locale.extract(0, locale.length(), fromCalLoc, (const char*)0); // default codepage. Invariant codepage doesn't have '@'!
- fromCalendar = Calendar::createInstance(fromCalLoc, status);
+ fromCalendar.adoptInstead(Calendar::createInstance(fromCalLoc, status));
if (U_FAILURE(status)) {
errln("Unable to instantiate fromCalendar for "+locale);
return;
@@ -435,16 +435,13 @@
if (forward) {
logln((UnicodeString)"#"+n+" "+locale+"/"+from+" >>> "+toCalLoc+"/"
+to);
- testConvert(n, fromSet, fromCalendar, toSet, toCalendar, forward);
+ testConvert(n, fromSet, fromCalendar.getAlias(), toSet, toCalendar.getAlias(), forward);
} else {
logln((UnicodeString)"#"+n+" "+locale+"/"+from+" <<< "+toCalLoc+"/"
+to);
- testConvert(n, toSet, toCalendar, fromSet, fromCalendar, forward);
+ testConvert(n, toSet, toCalendar.getAlias(), fromSet, fromCalendar.getAlias(), forward);
}
-
- delete fromCalendar;
}
- delete toCalendar;
}
void DataDrivenCalendarTest::processTest(TestData *testData) {
diff --git a/icu4c/source/test/intltest/dcfmapts.cpp b/icu4c/source/test/intltest/dcfmapts.cpp
index 04cd389..c8bf97a 100644
--- a/icu4c/source/test/intltest/dcfmapts.cpp
+++ b/icu4c/source/test/intltest/dcfmapts.cpp
@@ -453,9 +453,10 @@
void IntlTestDecimalFormatAPI::TestCurrencyPluralInfo(){
UErrorCode status = U_ZERO_ERROR;
- CurrencyPluralInfo *cpi = new CurrencyPluralInfo(status);
+ LocalPointer<CurrencyPluralInfo>cpi(new CurrencyPluralInfo(status), status);
if(U_FAILURE(status)) {
errln((UnicodeString)"ERROR: CurrencyPluralInfo(UErrorCode) could not be created");
+ return;
}
CurrencyPluralInfo cpi1 = *cpi;
@@ -479,19 +480,18 @@
errln((UnicodeString)"ERROR: CurrencyPluralInfo::setPluralRules");
}
- DecimalFormat *df = new DecimalFormat(status);
+ LocalPointer<DecimalFormat>df(new DecimalFormat(status));
if(U_FAILURE(status)) {
errcheckln(status, "ERROR: Could not create DecimalFormat - %s", u_errorName(status));
return;
}
- df->adoptCurrencyPluralInfo(cpi);
+ df->adoptCurrencyPluralInfo(cpi.orphan());
df->getCurrencyPluralInfo();
df->setCurrencyPluralInfo(cpi1);
- delete df;
}
void IntlTestDecimalFormatAPI::testRounding(/*char *par*/)
diff --git a/icu4c/source/test/intltest/dtfmrgts.cpp b/icu4c/source/test/intltest/dtfmrgts.cpp
index 771a66e..7b772f1 100644
--- a/icu4c/source/test/intltest/dtfmrgts.cpp
+++ b/icu4c/source/test/intltest/dtfmrgts.cpp
@@ -290,23 +290,17 @@
{
UErrorCode status = U_ZERO_ERROR;
- SimpleDateFormat *fmt;
UnicodeString myDate;
- fmt = new SimpleDateFormat( UnicodeString("yyyy/MM/dd"), status );
+ SimpleDateFormat fmt(UnicodeString(u"yyyy/MM/dd"), status );
if (failure(status, "new SimpleDateFormat", TRUE)) return;
myDate = "1997/01/01";
- aux917( fmt, myDate );
-
- delete fmt;
- fmt = NULL;
-
- fmt = new SimpleDateFormat( UnicodeString("yyyyMMdd"), status );
+ aux917( &fmt, myDate );
+
+ SimpleDateFormat fmt2( UnicodeString(u"yyyyMMdd"), status );
if(failure(status, "new SimpleDateFormat")) return;
myDate = "19970101";
- aux917( fmt, myDate );
-
- delete fmt;
+ aux917(&fmt2, myDate );
}
void DateFormatRegressionTest::aux917( SimpleDateFormat *fmt, UnicodeString& str ) {
@@ -349,23 +343,22 @@
logln( "dateString= " + dateString );
logln("Using yyyy-DDD.hh:mm:ss");
UErrorCode status = U_ZERO_ERROR;
- SimpleDateFormat *formatter = new SimpleDateFormat(UnicodeString("yyyy-DDD.hh:mm:ss"), status);
+ SimpleDateFormat formatter(UnicodeString("yyyy-DDD.hh:mm:ss"), status);
if (failure(status, "new SimpleDateFormat", TRUE)) return;
ParsePosition pos(0);
- UDate myDate = formatter->parse( dateString, pos );
+ UDate myDate = formatter.parse( dateString, pos );
UnicodeString myString;
- DateFormat *fmt = DateFormat::createDateTimeInstance( DateFormat::FULL,
- DateFormat::LONG);
- if (fmt == NULL) {
+ LocalPointer<DateFormat> fmt(DateFormat::createDateTimeInstance( DateFormat::FULL,
+ DateFormat::LONG));
+ if (!fmt.isValid()) {
dataerrln("Error calling DateFormat::createDateTimeInstance");
- delete formatter;
return;
}
myString = fmt->format( myDate, myString);
logln( myString );
- Calendar *cal = new GregorianCalendar(status);
+ LocalPointer<Calendar> cal(new GregorianCalendar(status));
failure(status, "new GregorianCalendar");
cal->setTime(myDate, status);
failure(status, "cal->setTime");
@@ -376,12 +369,10 @@
// this is an odd usage of "ddd" and it doesn't
// work now that date values are range checked per #3579.
logln("Using yyyy-ddd.hh:mm:ss");
- delete formatter;
- formatter = NULL;
- formatter = new SimpleDateFormat(UnicodeString("yyyy-ddd.hh:mm:ss"), status);
+ SimpleDateFormat formatter2(UnicodeString(u"yyyy-ddd.hh:mm:ss"), status);
if(failure(status, "new SimpleDateFormat")) return;
pos.setIndex(0);
- myDate = formatter->parse( dateString, pos );
+ myDate = formatter2.parse( dateString, pos );
myString = fmt->format( myDate, myString );
logln( myString );
cal->setTime(myDate, status);
@@ -389,10 +380,6 @@
if ((cal->get(UCAL_DAY_OF_YEAR, status) != 40) || failure(status, "cal->get"))
errln((UnicodeString) "Fail: Got " + cal->get(UCAL_DAY_OF_YEAR, status) +
" Want 40");
-
- delete formatter;
- delete fmt;
- delete cal;
}
/**
@@ -719,22 +706,20 @@
void DateFormatRegressionTest::Test4101483(void)
{
UErrorCode status = U_ZERO_ERROR;
- SimpleDateFormat *sdf = new SimpleDateFormat(UnicodeString("z"), Locale::getUS(), status);
+ SimpleDateFormat sdf(UnicodeString("z"), Locale::getUS(), status);
if (failure(status, "new SimpleDateFormat", TRUE)) return;
FieldPosition fp(UDAT_TIMEZONE_FIELD);
//Date d = date(9234567890L);
UDate d = 9234567890.0;
//StringBuffer buf = new StringBuffer("");
UnicodeString buf;
- sdf->format(d, buf, fp);
+ sdf.format(d, buf, fp);
//logln(sdf.format(d, buf, fp).toString());
logln(dateToString(d) + " => " + buf);
logln(UnicodeString("beginIndex = ") + fp.getBeginIndex());
logln(UnicodeString("endIndex = ") + fp.getEndIndex());
if (fp.getBeginIndex() == fp.getEndIndex())
errln("Fail: Empty field");
-
- delete sdf;
}
/**
@@ -752,22 +737,20 @@
// choose a date that is the FIRST of some month
// and some arbitrary time
UDate d = date(97, 3, 1, 1, 1, 1);
- SimpleDateFormat *df = new SimpleDateFormat(UnicodeString("MMMM"), Locale::getUS(), status);
+ SimpleDateFormat df(UnicodeString(u"MMMM"), Locale::getUS(), status);
if (failure(status, "new SimpleDateFormat", TRUE)) return;
UnicodeString s;
s = dateToString(d, s);
UnicodeString s2;
FieldPosition pos(FieldPosition::DONT_CARE);
- s2 = df->format(d, s2, pos);
+ s2 = df.format(d, s2, pos);
logln("Date=" + s);
logln("DF=" + s2);
UnicodeString substr;
s2.extract(0,2, substr);
if (s.indexOf(substr) == -1)
- errln("Months should match");
-
- delete df;
+ errln("Months should match");
}
/**
@@ -775,29 +758,23 @@
*/
void DateFormatRegressionTest::Test4103341(void)
{
- TimeZone *saveZone =TimeZone::createDefault();
- //try {
-
+ LocalPointer<TimeZone> saveZone(TimeZone::createDefault());
+ if (!saveZone.isValid()) {
+ dataerrln("TimeZone::createDefault() failed.");
+ return;
+ }
// {sfb} changed from setDefault to adoptDefault
TimeZone::adoptDefault(TimeZone::createTimeZone("CST"));
UErrorCode status = U_ZERO_ERROR;
- SimpleDateFormat *simple = new SimpleDateFormat(UnicodeString("MM/dd/yyyy HH:mm"), status);
+ SimpleDateFormat simple(UnicodeString("MM/dd/yyyy HH:mm"), status);
if(U_FAILURE(status)) {
- dataerrln("Couldn't create SimpleDateFormat, error %s", u_errorName(status));
- delete simple;
- return;
- }
- failure(status, "new SimpleDateFormat");
- TimeZone *temp = TimeZone::createDefault();
- if(simple->getTimeZone() != *temp)
+ dataerrln("Couldn't create SimpleDateFormat, error %s", u_errorName(status));
+ } else {
+ LocalPointer<TimeZone> temp(TimeZone::createDefault());
+ if(simple.getTimeZone() != *temp)
errln("Fail: SimpleDateFormat not using default zone");
- //}
- //finally {
- TimeZone::adoptDefault(saveZone);
- //}
-
- delete temp;
- delete simple;
+ }
+ TimeZone::adoptDefault(saveZone.orphan());
}
/**
@@ -1018,17 +995,15 @@
{
UErrorCode status = U_ZERO_ERROR;
UnicodeString dateFormat = "MM/dd/yy HH:mm:ss zzz";
- SimpleDateFormat *fmt = new SimpleDateFormat(dateFormat, status);
+ SimpleDateFormat fmt (dateFormat, status);
if (failure(status, "new SimpleDateFormat", TRUE)) return;
ParsePosition p0(0);
- UDate d = fmt->parse("01/22/92 04:52:00 GMT", p0);
+ UDate d = fmt.parse("01/22/92 04:52:00 GMT", p0);
logln(dateToString(d));
if(p0 == ParsePosition(0))
errln("Fail: failed to parse 'GMT'");
// In the failure case an exception is thrown by parse();
// if no exception is thrown, the test passes.
-
- delete fmt;
}
/**
@@ -1040,19 +1015,17 @@
UnicodeString pattern = "'TO_DATE('''dd'-'MM'-'yyyy HH:mm:ss''' , ''DD-MM-YYYY HH:MI:SS'')'";
logln("pattern=" + pattern);
UErrorCode status = U_ZERO_ERROR;
- SimpleDateFormat *format = new SimpleDateFormat(pattern, Locale::getUS(), status);
+ SimpleDateFormat format(pattern, Locale::getUS(), status);
if (failure(status, "new SimpleDateFormat", TRUE)) return;
UnicodeString result;
FieldPosition pos(FieldPosition::DONT_CARE);
- result = format->format(date(1998-1900, UCAL_JUNE, 30, 13, 30, 0), result, pos);
+ result = format.format(date(1998-1900, UCAL_JUNE, 30, 13, 30, 0), result, pos);
if (result != "TO_DATE('30-06-1998 13:30:00' , 'DD-MM-YYYY HH:MI:SS')") {
errln("Fail: result=" + result);
}
else {
logln("Pass: result=" + result);
}
-
- delete format;
}
/**
diff --git a/icu4c/source/test/intltest/dtfmttst.cpp b/icu4c/source/test/intltest/dtfmttst.cpp
index 4a4d3cc..197a3c3 100644
--- a/icu4c/source/test/intltest/dtfmttst.cpp
+++ b/icu4c/source/test/intltest/dtfmttst.cpp
@@ -382,12 +382,12 @@
DateFormatTest::TestTwoDigitYearDSTParse(void)
{
UErrorCode status = U_ZERO_ERROR;
- SimpleDateFormat* fullFmt = new SimpleDateFormat((UnicodeString)"EEE MMM dd HH:mm:ss.SSS zzz yyyy G", status);
- SimpleDateFormat *fmt = new SimpleDateFormat((UnicodeString)"dd-MMM-yy h:mm:ss 'o''clock' a z", Locale::getEnglish(), status);
+ SimpleDateFormat fullFmt((UnicodeString)"EEE MMM dd HH:mm:ss.SSS zzz yyyy G", status);
+ SimpleDateFormat fmt((UnicodeString)"dd-MMM-yy h:mm:ss 'o''clock' a z", Locale::getEnglish(), status);
//DateFormat* fmt = DateFormat::createDateTimeInstance(DateFormat::MEDIUM, DateFormat::FULL, Locale::ENGLISH);
- UnicodeString* s = new UnicodeString("03-Apr-04 2:20:47 o'clock AM PST", "");
- TimeZone* defaultTZ = TimeZone::createDefault();
- TimeZone* PST = TimeZone::createTimeZone("PST");
+ UnicodeString s(u"03-Apr-04 2:20:47 o'clock AM PST");
+ LocalPointer<TimeZone> defaultTZ(TimeZone::createDefault());
+ LocalPointer<TimeZone> PST(TimeZone::createTimeZone("PST"));
int32_t defaultOffset = defaultTZ->getRawOffset();
int32_t PSTOffset = PST->getRawOffset();
int32_t hour = 2 + (defaultOffset - PSTOffset) / (60*60*1000);
@@ -401,8 +401,8 @@
return;
}
- UDate d = fmt->parse(*s, status);
- logln(*s + " P> " + ((DateFormat*)fullFmt)->format(d, str));
+ UDate d = fmt.parse(s, status);
+ logln(s + " P> " + fullFmt.format(d, str));
int32_t y, m, day, hr, min, sec;
dateToFields(d, y, m, day, hr, min, sec);
hour += defaultTZ->inDaylightTime(d, status) ? 1 : 0;
@@ -412,12 +412,6 @@
if (U_FAILURE(status))
errln((UnicodeString)"FAIL: " + (int32_t)status);
-
- delete s;
- delete fmt;
- delete fullFmt;
- delete PST;
- delete defaultTZ;
}
// -------------------------------------
@@ -1295,18 +1289,17 @@
int32_t DATA_length = UPRV_LENGTHOF(DATA);
for (int32_t i=0; i<DATA_length; i+=3) {
- DateFormat *fmt = new SimpleDateFormat(DATA[i+2], Locale::getEnglish(), status);
+ SimpleDateFormat fmt(DATA[i+2], Locale::getEnglish(), status);
if (U_FAILURE(status)) {
dataerrln("Unable to create SimpleDateFormat - %s", u_errorName(status));
break;
}
- fmt->setCalendar(*greenwichcalendar);
+ fmt.setCalendar(*greenwichcalendar);
UnicodeString result;
- result = fmt->format(greenwichdate, result);
+ result = fmt.format(greenwichdate, result);
logln(DATA[i] + result);
if (result != DATA[i+1])
errln("FAIL: Expected " + DATA[i+1] + ", got " + result);
- delete fmt;
}
}
//}
@@ -3411,7 +3404,7 @@
};
UErrorCode status = U_ZERO_ERROR;
- Calendar *cal = GregorianCalendar::createInstance(status);
+ LocalPointer<Calendar> cal(GregorianCalendar::createInstance(status));
if (failure(status, "GregorianCalendar::createInstance", TRUE)) return;
SimpleDateFormat testfmt(UnicodeString("yyyy-MM-dd'T'HH:mm:ss'Z'"), status);
if (failure(status, "SimpleDateFormat constructor", TRUE)) return;
@@ -3439,13 +3432,12 @@
cal->adoptTimeZone(tz);
UnicodeString result;
FieldPosition pos(FieldPosition::DONT_CARE);
- fmt.format(*cal,result,pos);
+ fmt.format(*cal.getAlias(), result,pos);
if (result != info[4]) {
errln(info[0] + ";" + info[1] + ";" + info[2] + ";" + info[3] + " expected: '" +
info[4] + "' but got: '" + result + "'");
}
}
- delete cal;
}
void DateFormatTest::TestRoundtripWithCalendar(void) {
@@ -3595,98 +3587,94 @@
{
UErrorCode status = U_ZERO_ERROR;
- SimpleDateFormat *fmt1 = new SimpleDateFormat(UnicodeString("y-M-d"), Locale("ar"), status);
+ SimpleDateFormat fmt1(UnicodeString(u"y-M-d"), Locale("ar"), status);
if (failure(status, "new SimpleDateFormat", TRUE)) return;
UDate dt1 = date(2008-1900, UCAL_JUNE, 10, 12, 00);
UnicodeString str1;
- str1 = fmt1->format(dt1, str1);
+ str1 = fmt1.format(dt1, str1);
logln(str1);
- UDate dt11 = fmt1->parse(str1, status);
+ UDate dt11 = fmt1.parse(str1, status);
failure(status, "fmt->parse");
UnicodeString str11;
- str11 = fmt1->format(dt11, str11);
+ str11 = fmt1.format(dt11, str11);
logln(str11);
if (str1 != str11) {
errln((UnicodeString)"FAIL: Different dates str1:" + str1
+ " str2:" + str11);
}
- delete fmt1;
/////////////////
status = U_ZERO_ERROR;
- SimpleDateFormat *fmt2 = new SimpleDateFormat(UnicodeString("y M d"), Locale("ar"), status);
+ SimpleDateFormat fmt2(UnicodeString(u"y M d"), Locale("ar"), status);
failure(status, "new SimpleDateFormat");
UDate dt2 = date(2008-1900, UCAL_JUNE, 10, 12, 00);
UnicodeString str2;
- str2 = fmt2->format(dt2, str2);
+ str2 = fmt2.format(dt2, str2);
logln(str2);
- UDate dt22 = fmt2->parse(str2, status);
+ UDate dt22 = fmt2.parse(str2, status);
failure(status, "fmt->parse");
UnicodeString str22;
- str22 = fmt2->format(dt22, str22);
+ str22 = fmt2.format(dt22, str22);
logln(str22);
if (str2 != str22) {
errln((UnicodeString)"FAIL: Different dates str1:" + str2
+ " str2:" + str22);
}
- delete fmt2;
/////////////////
status = U_ZERO_ERROR;
- SimpleDateFormat *fmt3 = new SimpleDateFormat(UnicodeString("y-M-d"), Locale("en-us"), status);
+ SimpleDateFormat fmt3(UnicodeString("y-M-d"), Locale("en-us"), status);
failure(status, "new SimpleDateFormat");
UDate dt3 = date(2008-1900, UCAL_JUNE, 10, 12, 00);
UnicodeString str3;
- str3 = fmt3->format(dt3, str3);
+ str3 = fmt3.format(dt3, str3);
logln(str3);
- UDate dt33 = fmt3->parse(str3, status);
+ UDate dt33 = fmt3.parse(str3, status);
failure(status, "fmt->parse");
UnicodeString str33;
- str33 = fmt3->format(dt33, str33);
+ str33 = fmt3.format(dt33, str33);
logln(str33);
if (str3 != str33) {
errln((UnicodeString)"FAIL: Different dates str1:" + str3
+ " str2:" + str33);
}
- delete fmt3;
/////////////////
status = U_ZERO_ERROR;
- SimpleDateFormat *fmt4 = new SimpleDateFormat(UnicodeString("y M d"), Locale("en-us"), status);
+ SimpleDateFormat fmt4(UnicodeString("y M d"), Locale("en-us"), status);
failure(status, "new SimpleDateFormat");
UDate dt4 = date(2008-1900, UCAL_JUNE, 10, 12, 00);
UnicodeString str4;
- str4 = fmt4->format(dt4, str4);
+ str4 = fmt4.format(dt4, str4);
logln(str4);
- UDate dt44 = fmt4->parse(str4, status);
+ UDate dt44 = fmt4.parse(str4, status);
failure(status, "fmt->parse");
UnicodeString str44;
- str44 = fmt4->format(dt44, str44);
+ str44 = fmt4.format(dt44, str44);
logln(str44);
if (str4 != str44) {
errln((UnicodeString)"FAIL: Different dates str1:" + str4
+ " str2:" + str44);
}
- delete fmt4;
}
@@ -3862,15 +3850,15 @@
for (itemPtr = items; itemPtr->localeStr != NULL; itemPtr++ ) {
Locale locale = Locale::createFromName(itemPtr->localeStr);
UErrorCode status = U_ZERO_ERROR;
- SimpleDateFormat *formatter = new SimpleDateFormat(itemPtr->datePattern, locale, status);
- if (formatter == NULL || U_FAILURE(status)) {
+ SimpleDateFormat formatter(itemPtr->datePattern, locale, status);
+ if (U_FAILURE(status)) {
dataerrln("Unable to create SimpleDateFormat - %s", u_errorName(status));
return;
}
- formatter->setLenient(itemPtr->lenient);
- formatter->setBooleanAttribute(UDAT_PARSE_ALLOW_WHITESPACE, itemPtr->lenient, status).setBooleanAttribute(UDAT_PARSE_ALLOW_NUMERIC, itemPtr->lenient, status);
- UDate date1 = formatter->parse(itemPtr->dateString, status);
+ formatter.setLenient(itemPtr->lenient);
+ formatter.setBooleanAttribute(UDAT_PARSE_ALLOW_WHITESPACE, itemPtr->lenient, status).setBooleanAttribute(UDAT_PARSE_ALLOW_NUMERIC, itemPtr->lenient, status);
+ UDate date1 = formatter.parse(itemPtr->dateString, status);
if (U_FAILURE(status)) {
if (!itemPtr->expectFail) {
errln("FAIL, err when expected success: Locale \"" + UnicodeString(itemPtr->localeStr) + "\", lenient " + itemPtr->lenient +
@@ -3881,14 +3869,12 @@
": using pattern \"" + itemPtr->datePattern + "\", did parse \"" + itemPtr->dateString + "\"." );
} else if (!itemPtr->lenient) {
UnicodeString formatted;
- formatter->format(date1, formatted);
+ formatter.format(date1, formatted);
if (formatted != itemPtr->dateString) {
errln("FAIL, mismatch formatting parsed date: Locale \"" + UnicodeString(itemPtr->localeStr) + "\", lenient " + itemPtr->lenient +
": using pattern \"" + itemPtr->datePattern + "\", did parse \"" + itemPtr->dateString + "\", formatted result \"" + formatted + "\".");
}
}
-
- delete formatter;
}
}
@@ -3940,20 +3926,19 @@
void DateFormatTest::TestFormalChineseDate() {
UErrorCode status = U_ZERO_ERROR;
- UnicodeString pattern ("y\\u5e74M\\u6708d\\u65e5", -1, US_INV );
- pattern = pattern.unescape();
- UnicodeString override ("y=hanidec;M=hans;d=hans", -1, US_INV );
+ UnicodeString pattern(u"y\u5e74M\u6708d\u65e5");
+ UnicodeString numsys_override(u"y=hanidec;M=hans;d=hans");
// create formatter
- SimpleDateFormat *sdf = new SimpleDateFormat(pattern,override,Locale::getChina(),status);
- if (failure(status, "new SimpleDateFormat with override", TRUE)) {
+ SimpleDateFormat sdf(pattern, numsys_override, Locale::getChina(),status);
+ if (failure(status, "new SimpleDateFormat with override", true)) {
return;
}
UDate thedate = date(2009-1900, UCAL_JULY, 28);
FieldPosition pos(FieldPosition::DONT_CARE);
UnicodeString result;
- sdf->format(thedate,result,pos);
+ sdf.format(thedate,result,pos);
UnicodeString expected = "\\u4e8c\\u3007\\u3007\\u4e5d\\u5e74\\u4e03\\u6708\\u4e8c\\u5341\\u516b\\u65e5";
expected = expected.unescape();
@@ -3961,37 +3946,34 @@
dataerrln((UnicodeString)"FAIL: -> " + result + " expected -> " + expected);
}
- UDate parsedate = sdf->parse(expected,status);
+ UDate parsedate = sdf.parse(expected,status);
if ( parsedate != thedate ) {
UnicodeString pat1 ("yyyy-MM-dd'T'HH:mm:ss'Z'", -1, US_INV );
- SimpleDateFormat *usf = new SimpleDateFormat(pat1,Locale::getEnglish(),status);
+ SimpleDateFormat usf(pat1, Locale::getEnglish(), status);
UnicodeString parsedres,expres;
- usf->format(parsedate,parsedres,pos);
- usf->format(thedate,expres,pos);
+ usf.format(parsedate,parsedres,pos);
+ usf.format(thedate,expres,pos);
dataerrln((UnicodeString)"FAIL: parsed -> " + parsedres + " expected -> " + expres);
- delete usf;
}
- delete sdf;
}
// Test case for #8675
// Incorrect parse offset with stand alone GMT string on 2nd or later iteration.
void DateFormatTest::TestStandAloneGMTParse() {
UErrorCode status = U_ZERO_ERROR;
- SimpleDateFormat *sdf = new SimpleDateFormat("ZZZZ", Locale(""), status);
+ SimpleDateFormat sdf("ZZZZ", Locale(""), status);
if (U_SUCCESS(status)) {
- UnicodeString inText("GMT$$$");
+ UnicodeString inText(u"GMT$$$");
for (int32_t i = 0; i < 10; i++) {
ParsePosition pos(0);
- sdf->parse(inText, pos);
+ sdf.parse(inText, pos);
if (pos.getIndex() != 3) {
errln((UnicodeString)"FAIL: Incorrect output parse position: actual=" + pos.getIndex() + " expected=3");
}
}
- delete sdf;
} else {
dataerrln("Unable to create SimpleDateFormat - %s", u_errorName(status));
}
@@ -4016,7 +3998,7 @@
for (int32_t i = 0; TestData[i][0]; i++) {
UErrorCode status = U_ZERO_ERROR;
- SimpleDateFormat *sdf = new SimpleDateFormat(UnicodeString(TestData[i][0]), status);
+ SimpleDateFormat sdf(UnicodeString(TestData[i][0]), status);
if (failure(status, "new SimpleDateFormat", TRUE)) return;
int32_t startPos, resPos;
@@ -4034,14 +4016,12 @@
ParsePosition pos(startPos);
//UDate d = sdf->parse(input, pos);
- (void)sdf->parse(input, pos);
+ (void)sdf.parse(input, pos);
if (pos.getIndex() != resPos) {
errln(UnicodeString("FAIL: Parsing [") + input + "] with pattern [" + TestData[i][0] + "] returns position - "
+ pos.getIndex() + ", expected - " + resPos);
}
-
- delete sdf;
}
}
@@ -4313,20 +4293,20 @@
const TestNonGregoItem * itemPtr;
for (itemPtr = items; itemPtr->locale != NULL; itemPtr++) {
Locale locale = Locale::createFromName(itemPtr->locale);
- DateFormat * dfmt = NULL;
+ LocalPointer<DateFormat> dfmt;
UErrorCode status = U_ZERO_ERROR;
if (itemPtr->style != DateFormat::kNone) {
- dfmt = DateFormat::createDateInstance(itemPtr->style, locale);
+ dfmt.adoptInstead(DateFormat::createDateInstance(itemPtr->style, locale));
} else {
- dfmt = new SimpleDateFormat(itemPtr->pattern, locale, status);
+ dfmt.adoptInstead(new SimpleDateFormat(itemPtr->pattern, locale, status));
}
if (U_FAILURE(status)) {
dataerrln("new SimpleDateFormat fails for locale %s", itemPtr->locale);
- } else if (dfmt == NULL) {
+ } else if (!dfmt.isValid()) {
dataerrln("DateFormat::createDateInstance fails for locale %s", itemPtr->locale);
} else {
- Calendar * cal = (dfmt->getCalendar())->clone();
- if (cal == NULL) {
+ LocalPointer<Calendar>cal((dfmt->getCalendar())->clone());
+ if (!cal.isValid()) {
dataerrln("(DateFormat::getCalendar)->clone() fails for locale %s", itemPtr->locale);
} else {
const CalAndFmtTestItem * caftItemPtr;
@@ -4362,9 +4342,7 @@
}
}
}
- delete cal;
}
- delete dfmt;
}
}
}
diff --git a/icu4c/source/test/intltest/idnaref.cpp b/icu4c/source/test/intltest/idnaref.cpp
index 9e79103..afec7c9 100644
--- a/icu4c/source/test/intltest/idnaref.cpp
+++ b/icu4c/source/test/intltest/idnaref.cpp
@@ -198,6 +198,17 @@
return b2Len;
}
+
+static NamePrepTransform* getInstance(UErrorCode& status){
+ TestIDNA *thisTest = dynamic_cast<TestIDNA *>(IntlTest::gTest);
+ if (thisTest == nullptr && U_SUCCESS(status)) {
+ status = U_INTERNAL_PROGRAM_ERROR;
+ }
+ if (U_FAILURE(status)) return nullptr;
+ return thisTest->getInstance(status);
+}
+
+
static int32_t convertFromPuny( const UChar* src, int32_t srcLength,
UChar* dest, int32_t destCapacity,
UErrorCode& status){
@@ -288,7 +299,7 @@
b1[b1Len++] = src[j];
}
- NamePrepTransform* prep = TestIDNA::getInstance(*status);
+ NamePrepTransform* prep = getInstance(*status);
if(U_FAILURE(*status)){
goto CLEANUP;
}
@@ -439,7 +450,7 @@
reqLength=0;
// UParseError parseError;
- NamePrepTransform* prep = TestIDNA::getInstance(*status);
+ NamePrepTransform* prep = getInstance(*status);
b1Len = 0;
UBool* caseFlags = NULL;
@@ -694,7 +705,7 @@
int32_t reqLength = 0;
// UParseError parseError;
- NamePrepTransform* prep = TestIDNA::getInstance(*status);
+ NamePrepTransform* prep = getInstance(*status);
//initialize pointers to stack buffers
UChar b1Stack[MAX_LABEL_BUFFER_SIZE];
@@ -850,7 +861,7 @@
UBool done = FALSE;
- NamePrepTransform* prep = TestIDNA::getInstance(*status);
+ NamePrepTransform* prep = getInstance(*status);
//initialize pointers to stack buffers
UChar b1Stack[MAX_LABEL_BUFFER_SIZE];
diff --git a/icu4c/source/test/intltest/incaltst.cpp b/icu4c/source/test/intltest/incaltst.cpp
index 3f11bf8..4c58644 100644
--- a/icu4c/source/test/intltest/incaltst.cpp
+++ b/icu4c/source/test/intltest/incaltst.cpp
@@ -418,34 +418,28 @@
// First, a contrived English test..
UDate aDate = 999932400000.0;
- SimpleDateFormat *fmt = new SimpleDateFormat(UnicodeString("MMMM d, yyyy G"), Locale("en_US@calendar=buddhist"), status);
+ SimpleDateFormat fmt(UnicodeString("MMMM d, yyyy G"), Locale("en_US@calendar=buddhist"), status);
CHECK(status, "creating date format instance");
- SimpleDateFormat *fmt2 = new SimpleDateFormat(UnicodeString("MMMM d, yyyy G"), Locale("en_US@calendar=gregorian"), status);
+ SimpleDateFormat fmt2(UnicodeString("MMMM d, yyyy G"), Locale("en_US@calendar=gregorian"), status);
CHECK(status, "creating gregorian date format instance");
- if(!fmt) {
- errln("Couldn't create en_US instance");
- } else {
- UnicodeString str;
- fmt2->format(aDate, str);
- logln(UnicodeString() + "Test Date: " + str);
- str.remove();
- fmt->format(aDate, str);
- logln(UnicodeString() + "as Buddhist Calendar: " + escape(str));
- UnicodeString expected("September 8, 2544 BE");
- if(str != expected) {
- errln("Expected " + escape(expected) + " but got " + escape(str));
- }
- UDate otherDate = fmt->parse(expected, status);
- if(otherDate != aDate) {
- UnicodeString str3;
- fmt->format(otherDate, str3);
- errln("Parse incorrect of " + escape(expected) + " - wanted " + aDate + " but got " + otherDate + ", " + escape(str3));
- } else {
- logln("Parsed OK: " + expected);
- }
- delete fmt;
+ UnicodeString str;
+ fmt2.format(aDate, str);
+ logln(UnicodeString() + "Test Date: " + str);
+ str.remove();
+ fmt.format(aDate, str);
+ logln(UnicodeString() + "as Buddhist Calendar: " + escape(str));
+ UnicodeString expected("September 8, 2544 BE");
+ if(str != expected) {
+ errln("Expected " + escape(expected) + " but got " + escape(str));
}
- delete fmt2;
+ UDate otherDate = fmt.parse(expected, status);
+ if(otherDate != aDate) {
+ UnicodeString str3;
+ fmt.format(otherDate, str3);
+ errln("Parse incorrect of " + escape(expected) + " - wanted " + aDate + " but got " + otherDate + ", " + escape(str3));
+ } else {
+ logln("Parsed OK: " + expected);
+ }
CHECK(status, "Error occurred testing Buddhist Calendar in English ");
@@ -492,81 +486,68 @@
void IntlCalendarTest::TestJapaneseFormat() {
- Calendar *cal;
+ LocalPointer<Calendar> cal;
UErrorCode status = U_ZERO_ERROR;
- cal = Calendar::createInstance("ja_JP@calendar=japanese", status);
+ cal.adoptInstead(Calendar::createInstance("ja_JP@calendar=japanese", status));
CHECK(status, UnicodeString("Creating ja_JP@calendar=japanese calendar"));
- Calendar *cal2 = cal->clone();
- delete cal;
- cal = NULL;
+ LocalPointer<Calendar> cal2(cal->clone());
+ cal.adoptInstead(nullptr);
// Test simple parse/format with adopt
UDate aDate = 999932400000.0;
- SimpleDateFormat *fmt = new SimpleDateFormat(UnicodeString("MMMM d, yy G"), Locale("en_US@calendar=japanese"), status);
- SimpleDateFormat *fmt2 = new SimpleDateFormat(UnicodeString("MMMM d, yyyy G"), Locale("en_US@calendar=gregorian"), status);
+ SimpleDateFormat fmt(UnicodeString("MMMM d, yy G"), Locale("en_US@calendar=japanese"), status);
+ SimpleDateFormat fmt2(UnicodeString("MMMM d, yyyy G"), Locale("en_US@calendar=gregorian"), status);
CHECK(status, "creating date format instance");
- if(!fmt) {
- errln("Couldn't create en_US instance");
+ UnicodeString str;
+ fmt2.format(aDate, str);
+ logln(UnicodeString() + "Test Date: " + str);
+ str.remove();
+ fmt.format(aDate, str);
+ logln(UnicodeString() + "as Japanese Calendar: " + str);
+ UnicodeString expected("September 8, 13 Heisei");
+ if(str != expected) {
+ errln("Expected " + expected + " but got " + str);
+ }
+ UDate otherDate = fmt.parse(expected, status);
+ if(otherDate != aDate) {
+ UnicodeString str3;
+ ParsePosition pp;
+ fmt.parse(expected, *cal2, pp);
+ fmt.format(otherDate, str3);
+ errln("Parse incorrect of " + expected + " - wanted " + aDate + " but got " + " = " + otherDate + ", " + str3 + " = " + CalendarTest::calToStr(*cal2) );
+
} else {
- UnicodeString str;
- fmt2->format(aDate, str);
- logln(UnicodeString() + "Test Date: " + str);
- str.remove();
- fmt->format(aDate, str);
- logln(UnicodeString() + "as Japanese Calendar: " + str);
- UnicodeString expected("September 8, 13 Heisei");
- if(str != expected) {
- errln("Expected " + expected + " but got " + str);
- }
- UDate otherDate = fmt->parse(expected, status);
- if(otherDate != aDate) {
- UnicodeString str3;
- ParsePosition pp;
- fmt->parse(expected, *cal2, pp);
- fmt->format(otherDate, str3);
- errln("Parse incorrect of " + expected + " - wanted " + aDate + " but got " + " = " + otherDate + ", " + str3 + " = " + CalendarTest::calToStr(*cal2) );
-
- } else {
- logln("Parsed OK: " + expected);
- }
- delete fmt;
+ logln("Parsed OK: " + expected);
}
// Test parse with incomplete information
- fmt = new SimpleDateFormat(UnicodeString("G y"), Locale("en_US@calendar=japanese"), status);
+ SimpleDateFormat fmti(UnicodeString("G y"), Locale("en_US@calendar=japanese"), status);
aDate = -3197117222000.0;
CHECK(status, "creating date format instance");
- if(!fmt) {
- errln("Coudln't create en_US instance");
- } else {
- UnicodeString str;
- fmt2->format(aDate, str);
- logln(UnicodeString() + "Test Date: " + str);
- str.remove();
- fmt->format(aDate, str);
- logln(UnicodeString() + "as Japanese Calendar: " + str);
- UnicodeString expected("Meiji 1");
- if(str != expected) {
- errln("Expected " + expected + " but got " + str);
- }
- UDate otherDate = fmt->parse(expected, status);
- if(otherDate != aDate) {
- UnicodeString str3;
- ParsePosition pp;
- fmt->parse(expected, *cal2, pp);
- fmt->format(otherDate, str3);
- errln("Parse incorrect of " + expected + " - wanted " + aDate + " but got " + " = " +
+ str.remove();
+ fmt2.format(aDate, str);
+ logln(UnicodeString() + "Test Date: " + str);
+ str.remove();
+ fmti.format(aDate, str);
+ logln(UnicodeString() + "as Japanese Calendar: " + str);
+ expected = u"Meiji 1";
+ if(str != expected) {
+ errln("Expected " + expected + " but got " + str);
+ }
+ otherDate = fmti.parse(expected, status);
+ if(otherDate != aDate) {
+ UnicodeString str3;
+ ParsePosition pp;
+ fmti.parse(expected, *cal2, pp);
+ fmti.format(otherDate, str3);
+ errln("Parse incorrect of " + expected + " - wanted " + aDate + " but got " + " = " +
otherDate + ", " + str3 + " = " + CalendarTest::calToStr(*cal2) );
- } else {
- logln("Parsed OK: " + expected);
- }
- delete fmt;
+ } else {
+ logln("Parsed OK: " + expected);
}
- delete cal2;
- delete fmt2;
CHECK(status, "Error occurred");
// Now, try in Japanese
@@ -626,98 +607,83 @@
void IntlCalendarTest::TestJapanese3860()
{
- Calendar *cal;
+ LocalPointer<Calendar> cal;
UErrorCode status = U_ZERO_ERROR;
- cal = Calendar::createInstance("ja_JP@calendar=japanese", status);
+ cal.adoptInstead(Calendar::createInstance("ja_JP@calendar=japanese", status));
CHECK(status, UnicodeString("Creating ja_JP@calendar=japanese calendar"));
- Calendar *cal2 = cal->clone();
- SimpleDateFormat *fmt2 = new SimpleDateFormat(UnicodeString("HH:mm:ss.S MMMM d, yyyy G"), Locale("en_US@calendar=gregorian"), status);
+ LocalPointer<Calendar> cal2(cal->clone());
+ SimpleDateFormat fmt2(UnicodeString("HH:mm:ss.S MMMM d, yyyy G"), Locale("en_US@calendar=gregorian"), status);
UnicodeString str;
-
{
// Test simple parse/format with adopt
UDate aDate = 0;
-
+
// Test parse with missing era (should default to current era, heisei)
// Test parse with incomplete information
logln("Testing parse w/ missing era...");
- SimpleDateFormat *fmt = new SimpleDateFormat(UnicodeString("y/M/d"), Locale("ja_JP@calendar=japanese"), status);
+ SimpleDateFormat fmt(UnicodeString("y/M/d"), Locale("ja_JP@calendar=japanese"), status);
CHECK(status, "creating date format instance");
- if(!fmt) {
- errln("Couldn't create en_US instance");
- } else {
- UErrorCode s2 = U_ZERO_ERROR;
- cal2->clear();
- UnicodeString samplestr("1/5/9");
- logln(UnicodeString() + "Test Year: " + samplestr);
- aDate = fmt->parse(samplestr, s2);
- ParsePosition pp=0;
- fmt->parse(samplestr, *cal2, pp);
- CHECK(s2, "parsing the 1/5/9 string");
- logln("*cal2 after 159 parse:");
- str.remove();
- fmt2->format(aDate, str);
- logln(UnicodeString() + "as Gregorian Calendar: " + str);
+ UErrorCode s2 = U_ZERO_ERROR;
+ cal2->clear();
+ UnicodeString samplestr("1/5/9");
+ logln(UnicodeString() + "Test Year: " + samplestr);
+ aDate = fmt.parse(samplestr, s2);
+ ParsePosition pp=0;
+ fmt.parse(samplestr, *cal2, pp);
+ CHECK(s2, "parsing the 1/5/9 string");
+ logln("*cal2 after 159 parse:");
+ str.remove();
+ fmt2.format(aDate, str);
+ logln(UnicodeString() + "as Gregorian Calendar: " + str);
- cal2->setTime(aDate, s2);
- int32_t gotYear = cal2->get(UCAL_YEAR, s2);
- int32_t gotEra = cal2->get(UCAL_ERA, s2);
- int32_t expectYear = 1;
- int32_t expectEra = JapaneseCalendar::getCurrentEra();
- if((gotYear!=1) || (gotEra != expectEra)) {
- errln(UnicodeString("parse "+samplestr+" of 'y/M/d' as Japanese Calendar, expected year ") + expectYear +
+ cal2->setTime(aDate, s2);
+ int32_t gotYear = cal2->get(UCAL_YEAR, s2);
+ int32_t gotEra = cal2->get(UCAL_ERA, s2);
+ int32_t expectYear = 1;
+ int32_t expectEra = JapaneseCalendar::getCurrentEra();
+ if((gotYear!=1) || (gotEra != expectEra)) {
+ errln(UnicodeString("parse "+samplestr+" of 'y/M/d' as Japanese Calendar, expected year ") + expectYear +
UnicodeString(" and era ") + expectEra +", but got year " + gotYear + " and era " + gotEra + " (Gregorian:" + str +")");
- } else {
- logln(UnicodeString() + " year: " + gotYear + ", era: " + gotEra);
- }
- delete fmt;
+ } else {
+ logln(UnicodeString() + " year: " + gotYear + ", era: " + gotEra);
}
}
{
// Test simple parse/format with adopt
UDate aDate = 0;
-
+
// Test parse with missing era (should default to current era, heisei)
// Test parse with incomplete information
logln("Testing parse w/ just year...");
- SimpleDateFormat *fmt = new SimpleDateFormat(UnicodeString("y"), Locale("ja_JP@calendar=japanese"), status);
+ SimpleDateFormat fmt(UnicodeString("y"), Locale("ja_JP@calendar=japanese"), status);
CHECK(status, "creating date format instance");
- if(!fmt) {
- errln("Couldn't create en_US instance");
- } else {
- UErrorCode s2 = U_ZERO_ERROR;
- cal2->clear();
- UnicodeString samplestr("1");
- logln(UnicodeString() + "Test Year: " + samplestr);
- aDate = fmt->parse(samplestr, s2);
- ParsePosition pp=0;
- fmt->parse(samplestr, *cal2, pp);
- CHECK(s2, "parsing the 1 string");
- logln("*cal2 after 1 parse:");
- str.remove();
- fmt2->format(aDate, str);
- logln(UnicodeString() + "as Gregorian Calendar: " + str);
+ UErrorCode s2 = U_ZERO_ERROR;
+ cal2->clear();
+ UnicodeString samplestr("1");
+ logln(UnicodeString() + "Test Year: " + samplestr);
+ aDate = fmt.parse(samplestr, s2);
+ ParsePosition pp=0;
+ fmt.parse(samplestr, *cal2, pp);
+ CHECK(s2, "parsing the 1 string");
+ logln("*cal2 after 1 parse:");
+ str.remove();
+ fmt2.format(aDate, str);
+ logln(UnicodeString() + "as Gregorian Calendar: " + str);
- cal2->setTime(aDate, s2);
- int32_t gotYear = cal2->get(UCAL_YEAR, s2);
- int32_t gotEra = cal2->get(UCAL_ERA, s2);
- int32_t expectYear = 1;
- int32_t expectEra = JapaneseCalendar::getCurrentEra();
- if((gotYear!=1) || (gotEra != expectEra)) {
- errln(UnicodeString("parse "+samplestr+" of 'y' as Japanese Calendar, expected year ") + expectYear +
+ cal2->setTime(aDate, s2);
+ int32_t gotYear = cal2->get(UCAL_YEAR, s2);
+ int32_t gotEra = cal2->get(UCAL_ERA, s2);
+ int32_t expectYear = 1;
+ int32_t expectEra = JapaneseCalendar::getCurrentEra();
+ if((gotYear!=1) || (gotEra != expectEra)) {
+ errln(UnicodeString("parse "+samplestr+" of 'y' as Japanese Calendar, expected year ") + expectYear +
UnicodeString(" and era ") + expectEra +", but got year " + gotYear + " and era " + gotEra + " (Gregorian:" + str +")");
- } else {
- logln(UnicodeString() + " year: " + gotYear + ", era: " + gotEra);
- }
- delete fmt;
+ } else {
+ logln(UnicodeString() + " year: " + gotYear + ", era: " + gotEra);
}
}
-
- delete cal2;
- delete cal;
- delete fmt2;
}
void IntlCalendarTest::TestForceGannenNumbering()
@@ -909,48 +875,42 @@
void IntlCalendarTest::TestPersianFormat() {
UErrorCode status = U_ZERO_ERROR;
- SimpleDateFormat *fmt = new SimpleDateFormat(UnicodeString("MMMM d, yyyy G"), Locale(" en_US@calendar=persian"), status);
+ SimpleDateFormat fmt(UnicodeString("MMMM d, yyyy G"), Locale(" en_US@calendar=persian"), status);
CHECK(status, "creating date format instance");
- SimpleDateFormat *fmt2 = new SimpleDateFormat(UnicodeString("MMMM d, yyyy G"), Locale("en_US@calendar=gregorian"), status);
+ SimpleDateFormat fmt2(UnicodeString("MMMM d, yyyy G"), Locale("en_US@calendar=gregorian"), status);
CHECK(status, "creating gregorian date format instance");
UnicodeString gregorianDate("January 18, 2007 AD");
- UDate aDate = fmt2->parse(gregorianDate, status);
- if(!fmt) {
- errln("Couldn't create en_US instance");
- } else {
- UnicodeString str;
- fmt->format(aDate, str);
- logln(UnicodeString() + "as Persian Calendar: " + escape(str));
- UnicodeString expected("Dey 28, 1385 AP");
- if(str != expected) {
- errln("Expected " + escape(expected) + " but got " + escape(str));
- }
- UDate otherDate = fmt->parse(expected, status);
- if(otherDate != aDate) {
- UnicodeString str3;
- fmt->format(otherDate, str3);
- errln("Parse incorrect of " + escape(expected) + " - wanted " + aDate + " but got " + otherDate + ", " + escape(str3));
- } else {
- logln("Parsed OK: " + expected);
- }
- // Two digit year parsing problem #4732
- fmt->applyPattern("yy-MM-dd");
- str.remove();
- fmt->format(aDate, str);
- expected.setTo("85-10-28");
- if(str != expected) {
- errln("Expected " + escape(expected) + " but got " + escape(str));
- }
- otherDate = fmt->parse(expected, status);
- if (otherDate != aDate) {
- errln("Parse incorrect of " + escape(expected) + " - wanted " + aDate + " but got " + otherDate);
- } else {
- logln("Parsed OK: " + expected);
- }
- delete fmt;
+ UDate aDate = fmt2.parse(gregorianDate, status);
+ UnicodeString str;
+ fmt.format(aDate, str);
+ logln(UnicodeString() + "as Persian Calendar: " + escape(str));
+ UnicodeString expected("Dey 28, 1385 AP");
+ if(str != expected) {
+ errln("Expected " + escape(expected) + " but got " + escape(str));
}
- delete fmt2;
-
+ UDate otherDate = fmt.parse(expected, status);
+ if(otherDate != aDate) {
+ UnicodeString str3;
+ fmt.format(otherDate, str3);
+ errln("Parse incorrect of " + escape(expected) + " - wanted " + aDate + " but got " + otherDate + ", " + escape(str3));
+ } else {
+ logln("Parsed OK: " + expected);
+ }
+ // Two digit year parsing problem #4732
+ fmt.applyPattern("yy-MM-dd");
+ str.remove();
+ fmt.format(aDate, str);
+ expected.setTo("85-10-28");
+ if(str != expected) {
+ errln("Expected " + escape(expected) + " but got " + escape(str));
+ }
+ otherDate = fmt.parse(expected, status);
+ if (otherDate != aDate) {
+ errln("Parse incorrect of " + escape(expected) + " - wanted " + aDate + " but got " + otherDate);
+ } else {
+ logln("Parsed OK: " + expected);
+ }
+
CHECK(status, "Error occured testing Persian Calendar in English ");
}
diff --git a/icu4c/source/test/intltest/loctest.cpp b/icu4c/source/test/intltest/loctest.cpp
index b7a28dd..98612a1 100644
--- a/icu4c/source/test/intltest/loctest.cpp
+++ b/icu4c/source/test/intltest/loctest.cpp
@@ -2700,7 +2700,7 @@
#if !UCONFIG_NO_FORMATTING
UErrorCode status = U_ZERO_ERROR;
UDate date = uprv_getUTCtime();
- UChar TMP[4];
+ UChar TMP[4] = {0, 0, 0, 0};
int32_t index = 0;
int32_t resLen = 0;
UnicodeString tempStr, resultStr;
diff --git a/icu4c/source/test/intltest/measfmttest.cpp b/icu4c/source/test/intltest/measfmttest.cpp
index 59a1eb5..f3079bf 100644
--- a/icu4c/source/test/intltest/measfmttest.cpp
+++ b/icu4c/source/test/intltest/measfmttest.cpp
@@ -2756,7 +2756,7 @@
Measure fhours(112.8765, MeasureUnit::createHour(status), status);
Measure fminutes(113.8765, MeasureUnit::createMinute(status), status);
Measure fseconds(114.8765, MeasureUnit::createSecond(status), status);
- assertSuccess("", status);
+ if (status.errDataIfFailureAndReset(WHERE)) return;
verifyFormat("hours", fmt, &hours, 1, "112h");
verifyFormat("minutes", fmt, &minutes, 1, "113m");
@@ -2805,12 +2805,13 @@
Measure fhours(2.8765432, MeasureUnit::createHour(status), status);
Measure fminutes(3.8765432, MeasureUnit::createMinute(status), status);
- assertSuccess("", status);
+ if (status.errDataIfFailureAndReset(WHERE)) return;
Measure fhoursFminutes[2] = {fhours, fminutes};
// Latvian is one of the very few locales 0-padding the hour
MeasureFormat fmtLt("lt", UMEASFMT_WIDTH_NUMERIC, status);
+ if (status.errDataIfFailureAndReset(WHERE)) return;
verifyFormat("Latvian fhoursFminutes", fmtLt, fhoursFminutes, 2, "02:03,877");
// Danish is one of the very few locales using '.' as separator
diff --git a/icu4c/source/test/intltest/miscdtfm.cpp b/icu4c/source/test/intltest/miscdtfm.cpp
index a623326..134f913 100644
--- a/icu4c/source/test/intltest/miscdtfm.cpp
+++ b/icu4c/source/test/intltest/miscdtfm.cpp
@@ -113,8 +113,8 @@
};*/
UErrorCode status = U_ZERO_ERROR;
- SimpleDateFormat *formatter;
- SimpleDateFormat *resultFormatter = new SimpleDateFormat((UnicodeString)"yyyy", status);
+ LocalPointer<SimpleDateFormat> formatter;
+ SimpleDateFormat resultFormatter((UnicodeString)u"yyyy", status);
if (U_FAILURE(status)) {
dataerrln("Fail new SimpleDateFormat: %s", u_errorName(status));
return;
@@ -125,24 +125,21 @@
for (int i = 0; i < 14/*dstring.length*/; i++)
{
log(dformat[i] + "\t" + dstring[i] + "\t");
- formatter = new SimpleDateFormat(dformat[i], status);
+ formatter.adoptInstead(new SimpleDateFormat(dformat[i], status));
if(failure(status, "new SimpleDateFormat")) return;
//try {
UnicodeString str;
FieldPosition pos(FieldPosition::DONT_CARE);
- logln(resultFormatter->format(formatter->parse(dstring[i], status), str, pos));
- failure(status, "resultFormatter->format");
+ logln(resultFormatter.format(formatter->parse(dstring[i], status), str, pos));
+ failure(status, "resultFormatter.format");
//if ( !dresult[i] ) System.out.print(" <-- error!");
/*}
catch (ParseException exception) {
//if ( dresult[i] ) System.out.print(" <-- error!");
System.out.print("exception --> " + exception);
}*/
- delete formatter;
logln();
}
-
- delete resultFormatter;
}
/*
diff --git a/icu4c/source/test/intltest/nmfmapts.cpp b/icu4c/source/test/intltest/nmfmapts.cpp
index 07b2044..4729d00 100644
--- a/icu4c/source/test/intltest/nmfmapts.cpp
+++ b/icu4c/source/test/intltest/nmfmapts.cpp
@@ -310,7 +310,7 @@
LocalPointer<NumberFormat> f3a(NumberFormat::createCurrencyInstance(SRC_LOC, status));
LocalPointer<NumberFormat> f4(NumberFormat::createInstance(SRC_LOC, status));
- StringEnumeration* locs = NumberFormat::getAvailableLocales();
+ LocalPointer<StringEnumeration> locs(NumberFormat::getAvailableLocales());
LocalUNumberFormatPointer uf3(unum_open(UNUM_CURRENCY, NULL, 0, SRC_LOC.getName(), NULL, &status));
LocalUNumberFormatPointer uf4(unum_open(UNUM_DEFAULT, NULL, 0, SRC_LOC.getName(), NULL, &status));
@@ -325,7 +325,7 @@
LocalUNumberFormatPointer uf5(unum_open(UNUM_CURRENCY, NULL, 0, SRC_LOC.getName(), NULL, &status));
if (U_FAILURE(status)) {
- dataerrln("Error creating instnaces.");
+ dataerrln("Error creating instanaces.");
return;
} else {
float n = 1234.567f;
@@ -391,8 +391,6 @@
for (res = locs->snext(status); res; res = locs->snext(status)) {
logln(*res);
}
-
- delete locs;
#endif
}
diff --git a/icu4c/source/test/intltest/nptrans.cpp b/icu4c/source/test/intltest/nptrans.cpp
index 6c1c7be..160cf51 100644
--- a/icu4c/source/test/intltest/nptrans.cpp
+++ b/icu4c/source/test/intltest/nptrans.cpp
@@ -47,11 +47,10 @@
//constructor
NamePrepTransform::NamePrepTransform(UParseError& parseError, UErrorCode& status)
-: unassigned(), prohibited(), labelSeparatorSet(){
+ : mapping(nullptr), unassigned(), prohibited(), labelSeparatorSet(), bundle(nullptr) {
- mapping = NULL;
- bundle = NULL;
-
+ LocalPointer<Transliterator> lmapping;
+ LocalUResourceBundlePointer lbundle;
const char* testDataName = IntlTest::loadTestData(status);
@@ -59,31 +58,31 @@
return;
}
- bundle = ures_openDirect(testDataName,"idna_rules",&status);
+ lbundle.adoptInstead(ures_openDirect(testDataName,"idna_rules",&status));
- if(bundle != NULL && U_SUCCESS(status)){
+ if(lbundle.isValid() && U_SUCCESS(status)){
// create the mapping transliterator
int32_t ruleLen = 0;
- const UChar* ruleUChar = ures_getStringByKey(bundle, "MapNFKC",&ruleLen, &status);
+ const UChar* ruleUChar = ures_getStringByKey(lbundle.getAlias(), "MapNFKC",&ruleLen, &status);
int32_t mapRuleLen = 0;
- const UChar *mapRuleUChar = ures_getStringByKey(bundle, "MapNoNormalization", &mapRuleLen, &status);
+ const UChar *mapRuleUChar = ures_getStringByKey(lbundle.getAlias(), "MapNoNormalization", &mapRuleLen, &status);
UnicodeString rule(mapRuleUChar, mapRuleLen);
rule.append(ruleUChar, ruleLen);
- mapping = Transliterator::createFromRules(UnicodeString("NamePrepTransform", ""), rule,
- UTRANS_FORWARD, parseError,status);
+ lmapping.adoptInstead( Transliterator::createFromRules(UnicodeString("NamePrepTransform", ""), rule,
+ UTRANS_FORWARD, parseError,status));
if(U_FAILURE(status)) {
- return;
+ return;
}
//create the unassigned set
int32_t patternLen =0;
- const UChar* pattern = ures_getStringByKey(bundle,"UnassignedSet",&patternLen, &status);
+ const UChar* pattern = ures_getStringByKey(lbundle.getAlias(),"UnassignedSet",&patternLen, &status);
unassigned.applyPattern(UnicodeString(pattern, patternLen), status);
//create prohibited set
patternLen=0;
- pattern = ures_getStringByKey(bundle,"ProhibitedSet",&patternLen, &status);
+ pattern = ures_getStringByKey(lbundle.getAlias(),"ProhibitedSet",&patternLen, &status);
UnicodeString test(pattern,patternLen);
prohibited.applyPattern(test,status);
#ifdef NPTRANS_DEBUG
@@ -107,20 +106,18 @@
//create label separator set
patternLen=0;
- pattern = ures_getStringByKey(bundle,"LabelSeparatorSet",&patternLen, &status);
+ pattern = ures_getStringByKey(lbundle.getAlias(), "LabelSeparatorSet", &patternLen, &status);
labelSeparatorSet.applyPattern(UnicodeString(pattern,patternLen),status);
}
- if(U_SUCCESS(status) &&
- (mapping == NULL)
- ){
+ if(U_SUCCESS(status) && (lmapping.isNull())) {
status = U_MEMORY_ALLOCATION_ERROR;
- delete mapping;
- ures_close(bundle);
- mapping = NULL;
- bundle = NULL;
}
-
+ if (U_FAILURE(status)) {
+ return;
+ }
+ mapping = lmapping.orphan();
+ bundle = lbundle.orphan();
}
diff --git a/icu4c/source/test/intltest/numfmtst.cpp b/icu4c/source/test/intltest/numfmtst.cpp
index c5f7e83..9bb4efa 100644
--- a/icu4c/source/test/intltest/numfmtst.cpp
+++ b/icu4c/source/test/intltest/numfmtst.cpp
@@ -8047,6 +8047,8 @@
Locale locale = Locale::createCanonical("sh_ME");
LocalPointer<NumberFormat> curFmt(NumberFormat::createInstance(locale, UNUM_CURRENCY, status));
+ // Fail here with missing data.
+ if (!assertTrue(WHERE, curFmt.isValid(), false, true)) {return;};
assertEquals("Currency instance is not for the desired locale for CURRENCYSTYLE", curFmt->getCurrency(), "EUR");
UnicodeString currBuf;
curFmt->format(-1234.5, currBuf);
diff --git a/icu4c/source/test/intltest/numrgts.cpp b/icu4c/source/test/intltest/numrgts.cpp
index 91f614e..893a639 100644
--- a/icu4c/source/test/intltest/numrgts.cpp
+++ b/icu4c/source/test/intltest/numrgts.cpp
@@ -850,15 +850,15 @@
void NumberFormatRegressionTest::Test4087244 (void) {
UErrorCode status = U_ZERO_ERROR;
char loc[256] = {0};
+
uloc_canonicalize("pt_PT@currency=PTE", loc, 256, &status);
- Locale *de = new Locale(loc);
- NumberFormat *nf = NumberFormat::createCurrencyInstance(*de, status);
+ Locale de(loc);
+ LocalPointer<NumberFormat> nf(NumberFormat::createCurrencyInstance(de, status));
if(U_FAILURE(status)) {
- dataerrln("Error creating DecimalFormat: %s", u_errorName(status));
- delete nf;
- return;
+ dataerrln("Error creating DecimalFormat: %s", u_errorName(status));
+ return;
}
- DecimalFormat *df = dynamic_cast<DecimalFormat *>(nf);
+ DecimalFormat *df = dynamic_cast<DecimalFormat *>(nf.getAlias());
if(df == NULL) {
errln("expected DecimalFormat!");
return;
@@ -887,8 +887,6 @@
monStr +
"\" and not \"" + decStr + '"');
}
- delete de;
- delete nf;
}
/* @bug 4070798
* Number format data rounding errors for locale FR
@@ -2681,18 +2679,18 @@
Locale loc("fr", "CH");
// set up the input date string & expected output
- UnicodeString udt("11.10.2000", "");
- UnicodeString exp("11.10.00", "");
+ UnicodeString udt(u"11.10.2000");
+ UnicodeString exp(u"11.10.00");
// create a Calendar for this locale
- Calendar *cal = Calendar::createInstance(loc, status);
+ LocalPointer<Calendar> cal(Calendar::createInstance(loc, status));
if (U_FAILURE(status)) {
dataerrln("FAIL: Calendar::createInstance() returned " + (UnicodeString)u_errorName(status));
return;
}
// create a NumberFormat for this locale
- NumberFormat *nf = NumberFormat::createInstance(loc, status);
+ LocalPointer<NumberFormat> nf(NumberFormat::createInstance(loc, status));
if (U_FAILURE(status)) {
dataerrln("FAIL: NumberFormat::createInstance() returned " + (UnicodeString)u_errorName(status));
return;
@@ -2705,14 +2703,14 @@
// so they are done in DateFormat::adoptNumberFormat
// create the DateFormat
- DateFormat *df = DateFormat::createDateInstance(DateFormat::kShort, loc);
+ LocalPointer<DateFormat> df(DateFormat::createDateInstance(DateFormat::kShort, loc));
if (U_FAILURE(status)) {
errln("FAIL: DateFormat::createInstance() returned " + (UnicodeString)u_errorName(status));
return;
}
- df->adoptCalendar(cal);
- df->adoptNumberFormat(nf);
+ df->adoptCalendar(cal.orphan());
+ df->adoptNumberFormat(nf.orphan());
// set parsing to lenient & parse
df->setLenient(TRUE);
@@ -2725,8 +2723,6 @@
if (outString != exp) {
errln("FAIL: " + udt + " => " + outString);
}
-
- delete df;
}
//---------------------------------------------------------------------------
diff --git a/icu4c/source/test/intltest/plurfmts.cpp b/icu4c/source/test/intltest/plurfmts.cpp
index 034190e..f431a93 100644
--- a/icu4c/source/test/intltest/plurfmts.cpp
+++ b/icu4c/source/test/intltest/plurfmts.cpp
@@ -194,7 +194,7 @@
UErrorCode status = U_ZERO_ERROR;
UnicodeString oddAndEvenRule = UNICODE_STRING_SIMPLE("odd: n mod 2 is 1");
- PluralRules* plRules = PluralRules::createRules(oddAndEvenRule, status);
+ LocalPointer<PluralRules>plRules(PluralRules::createRules(oddAndEvenRule, status));
if (U_FAILURE(status)) {
dataerrln("ERROR: create PluralRules instance failed in unit tests.- exitting");
return;
@@ -223,7 +223,7 @@
status = U_ZERO_ERROR;
UBool overwrite[PLURAL_PATTERN_DATA] = {FALSE, FALSE, TRUE, TRUE};
- NumberFormat *numFmt = NumberFormat::createInstance(status);
+ LocalPointer<NumberFormat> numFmt(NumberFormat::createInstance(status));
UnicodeString message=UnicodeString("ERROR: PluralFormat tests various pattern ...");
if (U_FAILURE(status)) {
dataerrln("ERROR: Could not create NumberFormat instance with default locale ");
@@ -240,37 +240,33 @@
errln("ERROR: PluralFormat failed to apply pattern- "+patternTestData[i]);
continue;
}
- numberFormatTest(&plFmt, numFmt, 1, 10, (UnicodeString *)&patternOddTestResult[i],
+ numberFormatTest(&plFmt, numFmt.getAlias(), 1, 10, (UnicodeString *)&patternOddTestResult[i],
(UnicodeString *)&patternEvenTestResult[i], overwrite[i], &message);
}
- delete plRules;
- delete numFmt;
// ======= Test set locale
status = U_ZERO_ERROR;
- plRules = PluralRules::createRules(UNICODE_STRING_SIMPLE("odd: n mod 2 is 1"), status);
+ plRules.adoptInstead(PluralRules::createRules(UNICODE_STRING_SIMPLE("odd: n mod 2 is 1"), status));
PluralFormat pluralFmt = PluralFormat(*plRules, status);
if (U_FAILURE(status)) {
dataerrln("ERROR: Could not create PluralFormat instance in setLocale() test - exitting. ");
- delete plRules;
return;
}
pluralFmt.applyPattern(UNICODE_STRING_SIMPLE("odd{odd} other{even}"), status);
pluralFmt.setLocale(Locale::getEnglish(), status);
if (U_FAILURE(status)) {
dataerrln("ERROR: Could not setLocale() with English locale ");
- delete plRules;
return;
}
message = UNICODE_STRING_SIMPLE("Error set locale: pattern is not reset!");
// Check that pattern gets deleted.
logln("\n Test setLocale() ..\n");
- numFmt = NumberFormat::createInstance(Locale::getEnglish(), status);
+ numFmt.adoptInstead(NumberFormat::createInstance(Locale::getEnglish(), status));
if (U_FAILURE(status)) {
dataerrln("ERROR: Could not create NumberFormat instance with English locale ");
}
- numberFormatTest(&pluralFmt, numFmt, 5, 5, NULL, NULL, FALSE, &message);
+ numberFormatTest(&pluralFmt, numFmt.getAlias(), 5, 5, NULL, NULL, FALSE, &message);
pluralFmt.applyPattern(UNICODE_STRING_SIMPLE("odd__{odd} other{even}"), status);
if (pluralFmt.format((int32_t)1, status) != UNICODE_STRING_SIMPLE("even")) {
errln("SetLocale should reset rules but did not.");
@@ -302,9 +298,6 @@
if (pluralFmt != dupPFmt) {
errln("Failed in PluralFormat copy constructor or == operator");
}
-
- delete plRules;
- delete numFmt;
}
diff --git a/icu4c/source/test/intltest/testidna.cpp b/icu4c/source/test/intltest/testidna.cpp
index e5eb44e..4b4b2d4 100644
--- a/icu4c/source/test/intltest/testidna.cpp
+++ b/icu4c/source/test/intltest/testidna.cpp
@@ -1597,25 +1597,22 @@
void TestIDNA::TestDataFile(){
testData(*this);
}
+
TestIDNA::~TestIDNA(){
- if(gPrep!=NULL){
- delete gPrep;
- gPrep = NULL;
- }
+ delete gPrep;
+ gPrep = NULL;
}
-NamePrepTransform* TestIDNA::gPrep = NULL;
-
NamePrepTransform* TestIDNA::getInstance(UErrorCode& status){
- if(TestIDNA::gPrep == NULL){
+ if(gPrep == NULL){
UParseError parseError;
- TestIDNA::gPrep = NamePrepTransform::createInstance(parseError, status);
- if(TestIDNA::gPrep ==NULL){
+ gPrep = NamePrepTransform::createInstance(parseError, status);
+ if(gPrep == NULL){
//status = U_MEMORY_ALLOCATION_ERROR;
return NULL;
}
}
- return TestIDNA::gPrep;
+ return gPrep;
}
#endif /* #if !UCONFIG_NO_IDNA */
diff --git a/icu4c/source/test/intltest/testidna.h b/icu4c/source/test/intltest/testidna.h
index 250a3f8..676d2e2 100644
--- a/icu4c/source/test/intltest/testidna.h
+++ b/icu4c/source/test/intltest/testidna.h
@@ -66,8 +66,9 @@
void TestRefIDNA();
void TestIDNAMonkeyTest();
void TestConformance();
- static NamePrepTransform* getInstance(UErrorCode& status);
- static NamePrepTransform* gPrep;
+ NamePrepTransform* getInstance(UErrorCode& status);
+ NamePrepTransform* gPrep;
+ TestIDNA() : gPrep(nullptr) {}
virtual ~TestIDNA();
private:
diff --git a/icu4c/source/test/intltest/tmsgfmt.cpp b/icu4c/source/test/intltest/tmsgfmt.cpp
index 89f3222..731bf76 100644
--- a/icu4c/source/test/intltest/tmsgfmt.cpp
+++ b/icu4c/source/test/intltest/tmsgfmt.cpp
@@ -185,7 +185,7 @@
// {sfb} use double format in pattern, so result will match (not strictly necessary)
const UnicodeString pattern = "There {0,choice,0#are no files|1#is one file|1<are {0, number} files} on disk {1}. ";
logln("The input pattern : " + pattern);
- MessageFormat *fmt = new MessageFormat(pattern, status);
+ LocalPointer<MessageFormat> fmt(new MessageFormat(pattern, status));
if (U_FAILURE(status)) {
dataerrln("MessageFormat pattern creation failed. - %s", u_errorName(status));
return;
@@ -194,7 +194,6 @@
if (pattern != result) {
errln("MessageFormat::toPattern() failed.");
}
- delete fmt;
}
#if 0
@@ -300,10 +299,10 @@
for (int32_t i = 0; i < 9; ++i) {
//it_out << "\nPat in: " << testCases[i]);
- MessageFormat *form = 0;
+ LocalPointer<MessageFormat> form;
UErrorCode success = U_ZERO_ERROR;
UnicodeString buffer;
- form = new MessageFormat(testCases[i], Locale::getUS(), success);
+ form.adoptInstead(new MessageFormat(testCases[i], Locale::getUS(), success));
if (U_FAILURE(success)) {
dataerrln("MessageFormat creation failed.#1 - %s", u_errorName(success));
logln(((UnicodeString)"MessageFormat for ") + testCases[i] + " creation failed.\n");
@@ -368,7 +367,6 @@
if (failed)
errln("MessageFormat failed test #6");
#endif
- delete form;
}
}
@@ -676,13 +674,13 @@
UnicodeString pattern ,Locale locale ,UErrorCode &status , char* errMsg)
{
//Create the MessageFormat with simple SelectFormat
- MessageFormat* msgFmt = new MessageFormat(pattern, locale, status);
+ LocalPointer<MessageFormat> msgFmt(new MessageFormat(pattern, locale, status));
if (U_FAILURE(status)) {
dataerrln( "%s error while constructing with ErrorCode as %s" ,errMsg, u_errorName(status) );
logln(UnicodeString("TestMessageFormat::testMsgFormatSelect #1 with error code ")+(int32_t)status);
- return NULL;
+ return nullptr;
}
- return msgFmt;
+ return msgFmt.orphan();
}
void TestMessageFormat::testMsgFormatSelect(/* char* par */)
@@ -809,7 +807,8 @@
//Select, plural, and number formats heavily nested
UnicodeString t6("{0} und {1, select, female {{2, plural, one {{3, select, female {ihre Freundin} other {ihr Freund}} } other {ihre {2, number, integer} {3, select, female {Freundinnen} other {Freunde}} } }} other{{2, plural, one {{3, select, female {seine Freundin} other {sein Freund}}} other {seine {2, number, integer} {3, select, female {Freundinnen} other {Freunde}}}}} } gingen nach Paris.");
//Create the MessageFormat with Select, plural, and number formats heavily nested
- MessageFormat* msgFmt6 = internalCreate(t6, Locale("de"),err,(char*)"From TestMessageFormat::TestSelectFormat create t6");
+ LocalPointer<MessageFormat> msgFmt6(
+ internalCreate(t6, Locale("de"),err,(char*)"From TestMessageFormat::TestSelectFormat create t6"));
if (!U_FAILURE(err)) {
//Arguments
Formattable testArgs10[] = {"Kirti","other",(int32_t)1,"other"};
@@ -848,10 +847,9 @@
};
//Format
for( int i=0; i< 14; i++){
- internalFormat( msgFmt6 , testArgs[i], 4, exp[i] ,(char*)"From TestMessageFormat::testSelectFormat format t6");
+ internalFormat( msgFmt6.getAlias(), testArgs[i], 4, exp[i] ,(char*)"From TestMessageFormat::testSelectFormat format t6");
}
}
- delete msgFmt6;
}
//---------------------------------
diff --git a/icu4c/source/test/intltest/transrt.cpp b/icu4c/source/test/intltest/transrt.cpp
index 233afd6..c1c30d3 100644
--- a/icu4c/source/test/intltest/transrt.cpp
+++ b/icu4c/source/test/intltest/transrt.cpp
@@ -1063,7 +1063,10 @@
void TransliteratorRoundTripTest::TestHan() {
UErrorCode status = U_ZERO_ERROR;
LocalULocaleDataPointer uld(ulocdata_open("zh",&status));
- LocalUSetPointer USetExemplars(ulocdata_getExemplarSet(uld.getAlias(), uset_openEmpty(), 0, ULOCDATA_ES_STANDARD, &status));
+ LocalUSetPointer USetExemplars(uset_openEmpty());
+ assertTrue("", USetExemplars.isValid(), false, false, __FILE__, __LINE__);
+ if (! USetExemplars.isValid()) return;
+ ulocdata_getExemplarSet(uld.getAlias(), USetExemplars.getAlias(), 0, ULOCDATA_ES_STANDARD, &status);
ASSERT_SUCCESS(status);
UnicodeString source;
diff --git a/icu4c/source/test/intltest/transtst.cpp b/icu4c/source/test/intltest/transtst.cpp
index 06a8a23..5e84c8b 100644
--- a/icu4c/source/test/intltest/transtst.cpp
+++ b/icu4c/source/test/intltest/transtst.cpp
@@ -2340,17 +2340,17 @@
exp = CharsToUnicodeString(DATA[i+3]);
}
UBool expOk = (DATA[i+1] != NULL);
- Transliterator* t = NULL;
+ LocalPointer<Transliterator> t;
UParseError pe;
UErrorCode ec = U_ZERO_ERROR;
if (id.charAt(0) == 0x23/*#*/) {
- t = Transliterator::createFromRules("ID", id, direction, pe, ec);
+ t.adoptInstead(Transliterator::createFromRules("ID", id, direction, pe, ec));
} else {
- t = Transliterator::createInstance(id, direction, pe, ec);
+ t.adoptInstead(Transliterator::createInstance(id, direction, pe, ec));
}
- UBool ok = (t != NULL && U_SUCCESS(ec));
+ UBool ok = (t.isValid() && U_SUCCESS(ec));
UnicodeString transID;
- if (t!=0) {
+ if (t.isValid()) {
transID = t->getID();
}
else {
@@ -2362,7 +2362,6 @@
if (source.length() != 0) {
expect(*t, source, exp);
}
- delete t;
} else {
dataerrln((UnicodeString)"FAIL: " + id + " => " + transID + ", " +
u_errorName(ec));
@@ -3176,12 +3175,12 @@
UParseError pe;
UErrorCode ec = U_ZERO_ERROR;
- Transliterator *t2 = Transliterator::createFromRules("source-target", UnicodeString(testRules, -1, US_INV), UTRANS_FORWARD, pe, ec);
- Transliterator *t3 = Transliterator::createFromRules("target-source", UnicodeString(testRules, -1, US_INV), UTRANS_REVERSE, pe, ec);
+ LocalPointer<Transliterator> t2(
+ Transliterator::createFromRules("source-target", UnicodeString(testRules, -1, US_INV), UTRANS_FORWARD, pe, ec));
+ LocalPointer<Transliterator> t3(
+ Transliterator::createFromRules("target-source", UnicodeString(testRules, -1, US_INV), UTRANS_REVERSE, pe, ec));
if (U_FAILURE(ec)) {
- delete t2;
- delete t3;
dataerrln((UnicodeString)"FAIL: createFromRules => " + u_errorName(ec));
return;
}
@@ -3191,9 +3190,6 @@
checkRules("Failed toRules FORWARD", *t2, UnicodeString(testRulesForward, -1, US_INV));
checkRules("Failed toRules BACKWARD", *t3, UnicodeString(testRulesBackward, -1, US_INV));
-
- delete t2;
- delete t3;
}
/**
diff --git a/icu4c/source/test/intltest/tufmtts.cpp b/icu4c/source/test/intltest/tufmtts.cpp
index 91a2667..ed7ac76 100644
--- a/icu4c/source/test/intltest/tufmtts.cpp
+++ b/icu4c/source/test/intltest/tufmtts.cpp
@@ -386,7 +386,7 @@
unitIndex < UPRV_LENGTHOF(tunits);
++unitIndex ) {
- TimeUnitAmount *tamt = new TimeUnitAmount(numbers[numberIndex], tunits[unitIndex], status);
+ LocalPointer<TimeUnitAmount>tamt(new TimeUnitAmount(numbers[numberIndex], tunits[unitIndex], status));
if (U_FAILURE(status)) {
dataerrln("generating TimeUnitAmount Object failed.");
#ifdef TUFMTTS_DEBUG
@@ -395,7 +395,7 @@
return;
}
- TimeUnitFormat *tfmt = new TimeUnitFormat(l, styles[styleIndex], status);
+ LocalPointer<TimeUnitFormat> tfmt(new TimeUnitFormat(l, styles[styleIndex], status));
if (U_FAILURE(status)) {
dataerrln("generating TimeUnitAmount Object failed.");
#ifdef TUFMTTS_DEBUG
@@ -407,10 +407,9 @@
Formattable fmt;
UnicodeString str;
- fmt.adoptObject(tamt);
- str = ((Format *)tfmt)->format(fmt, str, status);
+ fmt.adoptObject(tamt.orphan());
+ str = ((Format *)tfmt.getAlias())->format(fmt, str, status);
if (!assertSuccess("formatting relative time failed", status)) {
- delete tfmt;
#ifdef TUFMTTS_DEBUG
std::cout << "Failed to format" << "\n";
#endif
@@ -426,11 +425,9 @@
std::cout << "Formatted string : " << tmp << " expected : " << tmp1 << "\n";
#endif
if (!assertEquals("formatted time string is not expected, locale: " + UnicodeString(locales[locIndex]) + " style: " + (int)styles[styleIndex] + " units: " + (int)tunits[unitIndex], expected[counter], str)) {
- delete tfmt;
str.remove();
return;
}
- delete tfmt;
str.remove();
++counter;
}
diff --git a/icu4c/source/test/intltest/tzfmttst.cpp b/icu4c/source/test/intltest/tzfmttst.cpp
index 8578019..40362aa 100644
--- a/icu4c/source/test/intltest/tzfmttst.cpp
+++ b/icu4c/source/test/intltest/tzfmttst.cpp
@@ -728,7 +728,9 @@
if (threadNumber % 2 == 0) {
for (int32_t i = 0; i < kAdoptDefaultIteration; i++) {
std::unique_ptr<icu::StringEnumeration> timezones(
- icu::TimeZone::createEnumeration());
+ icu::TimeZone::createEnumeration());
+ // Fails with missing data.
+ if (!assertTrue(WHERE, (bool)timezones, false, true)) {return;}
while (const icu::UnicodeString* timezone = timezones->snext(status)) {
status = U_ZERO_ERROR;
icu::TimeZone::adoptDefault(icu::TimeZone::createTimeZone(*timezone));
diff --git a/icu4c/source/test/intltest/tzregts.cpp b/icu4c/source/test/intltest/tzregts.cpp
index c5f59d9..e13edab 100644
--- a/icu4c/source/test/intltest/tzregts.cpp
+++ b/icu4c/source/test/intltest/tzregts.cpp
@@ -922,26 +922,26 @@
// that does have a DST savings (which should be ignored).
UErrorCode status = U_ZERO_ERROR;
int32_t offset = 90 * 60000; // 1:30
- SimpleTimeZone* z1 = new SimpleTimeZone(offset, "_std_zone_");
- z1->setDSTSavings(45 * 60000, status); // 0:45
+ SimpleTimeZone z1(offset, "_std_zone_");
+ z1.setDSTSavings(45 * 60000, status); // 0:45
// Construct a zone that observes DST for the first 6 months.
- SimpleTimeZone* z2 = new SimpleTimeZone(offset, "_dst_zone_");
- z2->setDSTSavings(45 * 60000, status); // 0:45
- z2->setStartRule(UCAL_JANUARY, 1, 0, status);
- z2->setEndRule(UCAL_JULY, 1, 0, status);
+ SimpleTimeZone z2(offset, "_dst_zone_");
+ z2.setDSTSavings(45 * 60000, status); // 0:45
+ z2.setStartRule(UCAL_JANUARY, 1, 0, status);
+ z2.setEndRule(UCAL_JULY, 1, 0, status);
// Also check DateFormat
- DateFormat* fmt1 = new SimpleDateFormat(UnicodeString("z"), status);
+ SimpleDateFormat fmt1(UnicodeString(u"z"), status);
if (U_FAILURE(status)) {
dataerrln("Failure trying to construct: %s", u_errorName(status));
return;
}
- fmt1->setTimeZone(*z1); // Format uses standard zone
- DateFormat* fmt2 = new SimpleDateFormat(UnicodeString("z"), status);
+ fmt1.setTimeZone(z1); // Format uses standard zone
+ SimpleDateFormat fmt2(UnicodeString(u"z"), status);
if(!assertSuccess("trying to construct", status))return;
- fmt2->setTimeZone(*z2); // Format uses DST zone
- Calendar* tempcal = Calendar::createInstance(status);
+ fmt2.setTimeZone(z2); // Format uses DST zone
+ LocalPointer<Calendar> tempcal(Calendar::createInstance(status));
tempcal->clear();
tempcal->set(1970, UCAL_FEBRUARY, 1);
UDate dst = tempcal->getTime(status); // Time in DST
@@ -951,26 +951,26 @@
// Description, Result, Expected Result
UnicodeString a,b,c,d,e,f,g,h,i,j,k,l;
UnicodeString DATA[] = {
- "z1->getDisplayName(false, SHORT)/std zone",
- z1->getDisplayName(FALSE, TimeZone::SHORT, a), "GMT+1:30",
- "z1->getDisplayName(false, LONG)/std zone",
- z1->getDisplayName(FALSE, TimeZone::LONG, b), "GMT+01:30",
- "z1->getDisplayName(true, SHORT)/std zone",
- z1->getDisplayName(TRUE, TimeZone::SHORT, c), "GMT+1:30",
- "z1->getDisplayName(true, LONG)/std zone",
- z1->getDisplayName(TRUE, TimeZone::LONG, d ), "GMT+01:30",
- "z2->getDisplayName(false, SHORT)/dst zone",
- z2->getDisplayName(FALSE, TimeZone::SHORT, e), "GMT+1:30",
- "z2->getDisplayName(false, LONG)/dst zone",
- z2->getDisplayName(FALSE, TimeZone::LONG, f ), "GMT+01:30",
- "z2->getDisplayName(true, SHORT)/dst zone",
- z2->getDisplayName(TRUE, TimeZone::SHORT, g), "GMT+2:15",
- "z2->getDisplayName(true, LONG)/dst zone",
- z2->getDisplayName(TRUE, TimeZone::LONG, h ), "GMT+02:15",
- "DateFormat.format(std)/std zone", fmt1->format(std, i), "GMT+1:30",
- "DateFormat.format(dst)/std zone", fmt1->format(dst, j), "GMT+1:30",
- "DateFormat.format(std)/dst zone", fmt2->format(std, k), "GMT+1:30",
- "DateFormat.format(dst)/dst zone", fmt2->format(dst, l), "GMT+2:15",
+ "z1.getDisplayName(false, SHORT)/std zone",
+ z1.getDisplayName(FALSE, TimeZone::SHORT, a), "GMT+1:30",
+ "z1.getDisplayName(false, LONG)/std zone",
+ z1.getDisplayName(FALSE, TimeZone::LONG, b), "GMT+01:30",
+ "z1.getDisplayName(true, SHORT)/std zone",
+ z1.getDisplayName(TRUE, TimeZone::SHORT, c), "GMT+1:30",
+ "z1.getDisplayName(true, LONG)/std zone",
+ z1.getDisplayName(TRUE, TimeZone::LONG, d ), "GMT+01:30",
+ "z2.getDisplayName(false, SHORT)/dst zone",
+ z2.getDisplayName(FALSE, TimeZone::SHORT, e), "GMT+1:30",
+ "z2.getDisplayName(false, LONG)/dst zone",
+ z2.getDisplayName(FALSE, TimeZone::LONG, f ), "GMT+01:30",
+ "z2.getDisplayName(true, SHORT)/dst zone",
+ z2.getDisplayName(TRUE, TimeZone::SHORT, g), "GMT+2:15",
+ "z2.getDisplayName(true, LONG)/dst zone",
+ z2.getDisplayName(TRUE, TimeZone::LONG, h ), "GMT+02:15",
+ "DateFormat.format(std)/std zone", fmt1.format(std, i), "GMT+1:30",
+ "DateFormat.format(dst)/std zone", fmt1.format(dst, j), "GMT+1:30",
+ "DateFormat.format(std)/dst zone", fmt2.format(std, k), "GMT+1:30",
+ "DateFormat.format(dst)/dst zone", fmt2.format(dst, l), "GMT+2:15",
};
for (int32_t idx=0; idx<UPRV_LENGTHOF(DATA); idx+=3) {
@@ -978,11 +978,6 @@
errln("FAIL: " + DATA[idx] + " -> " + DATA[idx+1] + ", exp " + DATA[idx+2]);
}
}
- delete z1;
- delete z2;
- delete fmt1;
- delete fmt2;
- delete tempcal;
}
/**
diff --git a/icu4c/source/test/intltest/tztest.cpp b/icu4c/source/test/intltest/tztest.cpp
index 6b7746f..a3873bc 100644
--- a/icu4c/source/test/intltest/tztest.cpp
+++ b/icu4c/source/test/intltest/tztest.cpp
@@ -423,7 +423,7 @@
#endif
UnicodeString str;
- UnicodeString *buf = new UnicodeString("TimeZone::createEnumeration() = { ");
+ UnicodeString buf(u"TimeZone::createEnumeration() = { ");
int32_t s_length;
StringEnumeration* s = TimeZone::createEnumeration();
if (s == NULL) {
@@ -432,11 +432,11 @@
}
s_length = s->count(ec);
for (i = 0; i < s_length;++i) {
- if (i > 0) *buf += ", ";
+ if (i > 0) buf += ", ";
if ((i & 1) == 0) {
- *buf += *s->snext(ec);
+ buf += *s->snext(ec);
} else {
- *buf += UnicodeString(s->next(NULL, ec), "");
+ buf += UnicodeString(s->next(NULL, ec), "");
}
if((i % 5) == 4) {
@@ -450,8 +450,8 @@
}
}
}
- *buf += " };";
- logln(*buf);
+ buf += " };";
+ logln(buf);
/* Confirm that the following zones can be retrieved: The first
* zone, the last zone, and one in-between. This tests the binary
@@ -478,31 +478,31 @@
}
delete s;
- buf->truncate(0);
- *buf += "TimeZone::createEnumeration(GMT+01:00) = { ";
+ buf.truncate(0);
+ buf += "TimeZone::createEnumeration(GMT+01:00) = { ";
s = TimeZone::createEnumeration(1 * U_MILLIS_PER_HOUR);
s_length = s->count(ec);
for (i = 0; i < s_length;++i) {
- if (i > 0) *buf += ", ";
- *buf += *s->snext(ec);
+ if (i > 0) buf += ", ";
+ buf += *s->snext(ec);
}
delete s;
- *buf += " };";
- logln(*buf);
+ buf += " };";
+ logln(buf);
- buf->truncate(0);
- *buf += "TimeZone::createEnumeration(US) = { ";
+ buf.truncate(0);
+ buf += "TimeZone::createEnumeration(US) = { ";
s = TimeZone::createEnumeration("US");
s_length = s->count(ec);
for (i = 0; i < s_length;++i) {
- if (i > 0) *buf += ", ";
- *buf += *s->snext(ec);
+ if (i > 0) buf += ", ";
+ buf += *s->snext(ec);
}
- *buf += " };";
- logln(*buf);
+ buf += " };";
+ logln(buf);
TimeZone *tz = TimeZone::createTimeZone("PST");
if (tz != 0) logln("getTimeZone(PST) = " + tz->getID(str));
@@ -522,7 +522,6 @@
errln("FAIL: getTimeZone(NON_EXISTENT) = " + temp);
delete tz;
- delete buf;
delete s;
}