From 70d0f2d72d992d8488afa368a75883df694fa598 Mon Sep 17 00:00:00 2001 From: George Rhoten Date: Thu, 24 Aug 2000 01:12:12 +0000 Subject: [PATCH] ICU-535 fixed some compiler warnings X-SVN-Rev: 2344 --- icu4c/source/test/intltest/citrtest.cpp | 8 ++-- icu4c/source/test/intltest/dtfmtrtts.h | 4 +- icu4c/source/test/intltest/dtfmttst.cpp | 54 +++++++++++++++---------- icu4c/source/test/intltest/intltest.cpp | 7 ++-- icu4c/source/test/intltest/itercoll.cpp | 4 +- icu4c/source/test/intltest/nmfmtrt.h | 3 +- icu4c/source/test/intltest/restest.cpp | 1 + icu4c/source/test/intltest/restsnew.cpp | 1 + icu4c/source/test/intltest/tchcfmt.cpp | 2 +- icu4c/source/test/intltest/transapi.cpp | 1 + icu4c/source/test/intltest/tsdate.cpp | 3 +- icu4c/source/test/intltest/tsnmfmt.h | 2 + icu4c/source/test/intltest/tstnorm.cpp | 6 +-- 13 files changed, 58 insertions(+), 38 deletions(-) diff --git a/icu4c/source/test/intltest/citrtest.cpp b/icu4c/source/test/intltest/citrtest.cpp index 0a6b28375eb..3de47f8f056 100644 --- a/icu4c/source/test/intltest/citrtest.cpp +++ b/icu4c/source/test/intltest/citrtest.cpp @@ -116,8 +116,8 @@ void CharIterTest::TestConstructionAndEqualityUChariter() { const char* testTextchars= {"Now is the time for all good men to come to the aid of their country."}; const char* testText2chars={"Don't bother using this string."}; - UChar *testText=(UChar*)malloc(sizeof(UChar) * (strlen(testTextchars)+1)); - UChar *testText2=(UChar*)malloc(sizeof(UChar) * (strlen(testText2chars)+1)); + UChar *testText = new UChar[strlen(testTextchars)+1]; + UChar *testText2 = new UChar[strlen(testText2chars)+1]; u_uastrcpy(testText, testTextchars); u_uastrcpy(testText2, testText2chars); @@ -184,8 +184,8 @@ void CharIterTest::TestConstructionAndEqualityUChariter() { errln("operator= failed"); - free(testText); - free(testText2); + delete testText; + delete testText2; delete test1; delete test2; diff --git a/icu4c/source/test/intltest/dtfmtrtts.h b/icu4c/source/test/intltest/dtfmtrtts.h index 6b7708b9334..f124407139f 100644 --- a/icu4c/source/test/intltest/dtfmtrtts.h +++ b/icu4c/source/test/intltest/dtfmtrtts.h @@ -7,6 +7,8 @@ #ifndef _DATEFORMATROUNDTRIPTEST_ #define _DATEFORMATROUNDTRIPTEST_ +#include + #include "unicode/utypes.h" #include "intltest.h" #include "locale.h" @@ -45,7 +47,7 @@ static uint32_t randLong() // Assume 8-bit (or larger) rand values. Also assume // that the system rand() function is very poor, which it always is. uint32_t d; - int32_t i; + uint32_t i; char* poke = (char*)&d; for (i=0; i < sizeof(uint32_t); ++i) { diff --git a/icu4c/source/test/intltest/dtfmttst.cpp b/icu4c/source/test/intltest/dtfmttst.cpp index 88868085d4b..d420009250f 100644 --- a/icu4c/source/test/intltest/dtfmttst.cpp +++ b/icu4c/source/test/intltest/dtfmttst.cpp @@ -85,8 +85,11 @@ void DateFormatTest::TestWallyWedel() cal->setTime(today, status); offset = cal->get(Calendar::ZONE_OFFSET, status) + cal->get(Calendar::DST_OFFSET, status); // logln(i + " " + ids[i] + " offset " + offset); - char* sign = "+"; - if (offset < 0) { sign = "-"; offset = -offset; } + const char* sign = "+"; + if (offset < 0) { + sign = "-"; + offset = -offset; + } hours = offset/3600000; minutes = (offset%3600000)/60000; UnicodeString dstOffset = (UnicodeString)"" + sign + (hours < 10 ? "0" : "") + @@ -679,7 +682,8 @@ DateFormatTest::TestBadInput135a() SimpleDateFormat* dateParse = new SimpleDateFormat(status); const char* s; UDate date; - int32_t PFLENGTH = sizeof(parseFormats)/sizeof(parseFormats[0]); + const uint32_t PFLENGTH = sizeof(parseFormats)/sizeof(parseFormats[0]); + dateParse->applyPattern("d MMMM, yyyy"); dateParse->adoptTimeZone(TimeZone::createDefault()); s = "not parseable"; @@ -695,7 +699,7 @@ DateFormatTest::TestBadInput135a() logln((UnicodeString)"Exception during parse: " + (int32_t)status); status = U_ZERO_ERROR; //} - for (int32_t i = 0; i < sizeof(inputStrings)/sizeof(inputStrings[0]); i += (PFLENGTH + 1)) { + for (uint32_t i = 0; i < sizeof(inputStrings)/sizeof(inputStrings[0]); i += (PFLENGTH + 1)) { ParsePosition parsePosition(0); UnicodeString s( inputStrings[i]); for (int32_t index = 0; index < PFLENGTH;++index) { @@ -706,33 +710,39 @@ DateFormatTest::TestBadInput135a() parsePosition.setIndex(0); date = dateParse->parse(s, parsePosition); if (parsePosition.getIndex() != 0) { - UnicodeString s1, s2; - s.extract(0, parsePosition.getIndex(), s1); - s.extract(parsePosition.getIndex(), s.length(), s2); - if (date == 0) errln((UnicodeString)"ERROR: null result fmt=\"" + - parseFormats[index] + - "\" pos=" + parsePosition.getIndex() + " " + - s1 + "|" + s2); - else { - UnicodeString result; ((DateFormat*)dateParse)->format(date, result); - logln((UnicodeString)"Parsed \"" + s + "\" using \"" + dateParse->toPattern(thePat) + "\" to: " + result); - if (expected == 0) errln((UnicodeString)"FAIL: Expected parse failure"); - else if (!(result == expected)) errln(UnicodeString("FAIL: Expected ") + expected); - } + UnicodeString s1, s2; + s.extract(0, parsePosition.getIndex(), s1); + s.extract(parsePosition.getIndex(), s.length(), s2); + if (date == 0) { + errln((UnicodeString)"ERROR: null result fmt=\"" + + parseFormats[index] + + "\" pos=" + parsePosition.getIndex() + " " + + s1 + "|" + s2); + } + else { + UnicodeString result; + ((DateFormat*)dateParse)->format(date, result); + logln((UnicodeString)"Parsed \"" + s + "\" using \"" + dateParse->toPattern(thePat) + "\" to: " + result); + if (expected == 0) + errln((UnicodeString)"FAIL: Expected parse failure"); + else if (!(result == expected)) + errln(UnicodeString("FAIL: Expected ") + expected); + } } - else { - if (expected != 0) errln(UnicodeString("FAIL: Expected ") + expected + " from \"" + - s + "\" with \"" + dateParse->toPattern(thePat) + "\""); + else if (expected != 0) { + errln(UnicodeString("FAIL: Expected ") + expected + " from \"" + + s + "\" with \"" + dateParse->toPattern(thePat) + "\""); } //} //catch(Exception ex) { if (U_FAILURE(status)) - errln((UnicodeString)"An exception was thrown during parse: " + (int32_t)status); + errln((UnicodeString)"An exception was thrown during parse: " + (int32_t)status); //} } } delete dateParse; - if (U_FAILURE(status)) errln((UnicodeString)"FAIL: UErrorCode received during test: " + (int32_t)status); + if (U_FAILURE(status)) + errln((UnicodeString)"FAIL: UErrorCode received during test: " + (int32_t)status); } // ------------------------------------- diff --git a/icu4c/source/test/intltest/intltest.cpp b/icu4c/source/test/intltest/intltest.cpp index e7cdf8cdbd5..713b406382e 100644 --- a/icu4c/source/test/intltest/intltest.cpp +++ b/icu4c/source/test/intltest/intltest.cpp @@ -12,7 +12,6 @@ #include -#include #include #include #include @@ -451,7 +450,7 @@ IntlTest::pathnameInContext( char* fullname, int32_t maxsize, const char* relPat const char* IntlTest::getTestDirectory() { - if (_testDirectory == NULL) + if (_testDirectory == NULL) { #if defined(_AIX) || defined(U_SOLARIS) || defined(U_LINUX) || defined(HPUX) || defined(POSIX) || defined(OS390) setTestDirectory("source|test|testdata|"); @@ -468,8 +467,8 @@ IntlTest::setTestDirectory(const char* newDir) char newTestDir[256]; IntlTest::pathnameInContext(newTestDir, sizeof(newTestDir), newDir); if(_testDirectory != NULL) - free(_testDirectory); - _testDirectory = (char*) malloc(sizeof(char) * (strlen(newTestDir) + 1)); + delete _testDirectory; + _testDirectory = new char[strlen(newTestDir) + 1]; strcpy(_testDirectory, newTestDir); } diff --git a/icu4c/source/test/intltest/itercoll.cpp b/icu4c/source/test/intltest/itercoll.cpp index 06bbb88846e..7dff749ecf0 100644 --- a/icu4c/source/test/intltest/itercoll.cpp +++ b/icu4c/source/test/intltest/itercoll.cpp @@ -4,6 +4,8 @@ * others. All Rights Reserved. ********************************************************************/ +#include "cmemory.h" + #ifndef _COLL #include "unicode/coll.h" #endif @@ -501,7 +503,7 @@ int32_t *CollationIteratorTest::getOrders(CollationElementIterator &iter, int32_ maxSize *= 2; int32_t *temp = new int32_t[maxSize]; - memcpy(temp, orders, size * sizeof(int32_t)); + uprv_memcpy(temp, orders, size * sizeof(int32_t)); delete[] orders; orders = temp; } diff --git a/icu4c/source/test/intltest/nmfmtrt.h b/icu4c/source/test/intltest/nmfmtrt.h index 8d7d58c15fd..ae3d3529482 100644 --- a/icu4c/source/test/intltest/nmfmtrt.h +++ b/icu4c/source/test/intltest/nmfmtrt.h @@ -7,6 +7,7 @@ #ifndef _NUMBERFORMATROUNDTRIPTEST_ #define _NUMBERFORMATROUNDTRIPTEST_ +#include #include "unicode/utypes.h" #include "intltest.h" @@ -60,7 +61,7 @@ static uint32_t randLong() // Assume 8-bit (or larger) rand values. Also assume // that the system rand() function is very poor, which it always is. uint32_t d; - int32_t i; + uint32_t i; char* poke = (char*)&d; for (i=0; i < sizeof(uint32_t); ++i) { diff --git a/icu4c/source/test/intltest/restest.cpp b/icu4c/source/test/intltest/restest.cpp index 87b15ae6a36..84b32027a16 100644 --- a/icu4c/source/test/intltest/restest.cpp +++ b/icu4c/source/test/intltest/restest.cpp @@ -4,6 +4,7 @@ * others. All Rights Reserved. ********************************************************************/ +#include #include #include #include diff --git a/icu4c/source/test/intltest/restsnew.cpp b/icu4c/source/test/intltest/restsnew.cpp index b547c2bb0c8..9c445a55402 100644 --- a/icu4c/source/test/intltest/restsnew.cpp +++ b/icu4c/source/test/intltest/restsnew.cpp @@ -4,6 +4,7 @@ * others. All Rights Reserved. ********************************************************************/ +#include #include #include #include diff --git a/icu4c/source/test/intltest/tchcfmt.cpp b/icu4c/source/test/intltest/tchcfmt.cpp index 9c0f3bbd4e7..a62182afc51 100644 --- a/icu4c/source/test/intltest/tchcfmt.cpp +++ b/icu4c/source/test/intltest/tchcfmt.cpp @@ -338,7 +338,7 @@ TestChoiceFormat::TestComplexExample( void ) delete form_A; delete form_A2; delete form_B; - char* testPattern = "0#none|1#one|2#many"; + const char* testPattern = "0#none|1#one|2#many"; ChoiceFormat form_pat( testPattern, status ); if (!chkstatus( status, "*** ChoiceFormat contructor( newPattern, status)" )) { delete fileform; diff --git a/icu4c/source/test/intltest/transapi.cpp b/icu4c/source/test/intltest/transapi.cpp index 1c698decd87..c697b294092 100644 --- a/icu4c/source/test/intltest/transapi.cpp +++ b/icu4c/source/test/intltest/transapi.cpp @@ -18,6 +18,7 @@ #include "unicode/nultrans.h" #include #include +#include #include "unicode/rep.h" int32_t getInt(UnicodeString str) diff --git a/icu4c/source/test/intltest/tsdate.cpp b/icu4c/source/test/intltest/tsdate.cpp index deac9e0a931..33957b903e6 100644 --- a/icu4c/source/test/intltest/tsdate.cpp +++ b/icu4c/source/test/intltest/tsdate.cpp @@ -10,6 +10,7 @@ #include "unicode/datefmt.h" #include "unicode/smpdtfmt.h" +#include #include const double IntlTestDateFormat::ONEYEAR = 365.25 * ONEDAY; // Approximate @@ -202,7 +203,7 @@ double IntlTestDateFormat::randDouble() // Assume 8-bit (or larger) rand values. Also assume // that the system rand() function is very poor, which it always is. double d=0.0; - int32_t i; + uint32_t i; char* poke = (char*)&d; do { for (i=0; i < sizeof(double); ++i) diff --git a/icu4c/source/test/intltest/tsnmfmt.h b/icu4c/source/test/intltest/tsnmfmt.h index fac2010492d..ada9da1b9cd 100644 --- a/icu4c/source/test/intltest/tsnmfmt.h +++ b/icu4c/source/test/intltest/tsnmfmt.h @@ -8,6 +8,8 @@ #define _INTLTESTNUMBERFORMAT +#include + #include "unicode/utypes.h" #include "intltest.h" diff --git a/icu4c/source/test/intltest/tstnorm.cpp b/icu4c/source/test/intltest/tstnorm.cpp index bd98136a6a0..41273a366ad 100644 --- a/icu4c/source/test/intltest/tstnorm.cpp +++ b/icu4c/source/test/intltest/tstnorm.cpp @@ -151,7 +151,7 @@ void BasicNormalizerTest::TestPrevious() Normalizer* norm = new Normalizer("", Normalizer::DECOMP, 0); logln("testing decomp..."); - int i; + uint32_t i; for (i = 0; i < ARRAY_LENGTH(canonTests); i++) { backAndForth(norm, canonTests[i][0]); } @@ -225,7 +225,7 @@ void BasicNormalizerTest::TestHangulCompose() // And finally, make sure you can do it in reverse too logln("Reverse iteration..."); norm->setMode(Normalizer::COMPOSE); - for (int i = 0; i < ARRAY_LENGTH(hangulCanon); i++) { + for (uint32_t i = 0; i < ARRAY_LENGTH(hangulCanon); i++) { backAndForth(norm, hangulCanon[i][0]); } delete norm; @@ -247,7 +247,7 @@ void BasicNormalizerTest::TestHangulDecomp() // And finally, make sure you can do it in reverse too logln("Reverse iteration..."); norm->setMode(Normalizer::DECOMP); - for (int i = 0; i < ARRAY_LENGTH(hangulCanon); i++) { + for (uint32_t i = 0; i < ARRAY_LENGTH(hangulCanon); i++) { backAndForth(norm, hangulCanon[i][0]); } delete norm;