From b429022d94daa6cfd37a744bb03d94609dd6a044 Mon Sep 17 00:00:00 2001 From: Madhu K Date: Thu, 22 Jun 2000 01:09:15 +0000 Subject: [PATCH] ICU-447 Addtional tests for extended code coverage X-SVN-Rev: 1636 --- icu4c/source/test/cintltst/cbiapts.c | 49 ++++-- icu4c/source/test/cintltst/ccaltst.c | 45 ++++- icu4c/source/test/cintltst/cnmdptst.c | 29 ++++ icu4c/source/test/cintltst/cnmdptst.h | 4 + icu4c/source/test/cintltst/cnumtst.c | 58 ++++++- icu4c/source/test/cintltst/nccbtst.c | 116 +++++++++++-- icu4c/source/test/cintltst/nccbtst.h | 3 + icu4c/source/test/intltest/citrtest.cpp | 217 ++++++++++++++++++++++-- icu4c/source/test/intltest/citrtest.h | 4 + icu4c/source/test/intltest/dcfmapts.cpp | 99 ++++++++++- icu4c/source/test/intltest/dcfmapts.h | 6 +- icu4c/source/test/intltest/ucdtest.cpp | 17 +- 12 files changed, 588 insertions(+), 59 deletions(-) diff --git a/icu4c/source/test/cintltst/cbiapts.c b/icu4c/source/test/cintltst/cbiapts.c index ec65971b04e..ec28b9dc353 100644 --- a/icu4c/source/test/cintltst/cbiapts.c +++ b/icu4c/source/test/cintltst/cbiapts.c @@ -36,9 +36,10 @@ void addBrkIterAPITest(TestNode** root) void TestBreakIteratorCAPI() { UErrorCode status = U_ZERO_ERROR; - UBreakIterator *word, *sentence, *line, *character, *b; + UBreakIterator *word, *sentence, *line, *character, *b, *bogus; UChar text[50]; UTextOffset start,pos,end,to; + int32_t i; int32_t count = 0; u_uastrcpy(text, "He's from Africa. ""Mr. Livingston, I presume?"" Yeah"); status = U_ZERO_ERROR; @@ -63,7 +64,7 @@ void TestBreakIteratorCAPI() log_verbose("PASS: Successfully opened sentence breakiterator\n"); } - line = ubrk_open(UBRK_SENTENCE, "en_US", text, u_strlen(text), &status); + line = ubrk_open(UBRK_LINE, "en_US", text, u_strlen(text), &status); if(U_FAILURE(status)){ log_err("FAIL: Error in ubrk_open() for line breakiterator: %s\n", myErrorName(status)); } @@ -71,15 +72,27 @@ void TestBreakIteratorCAPI() log_verbose("PASS: Successfully opened line breakiterator\n"); } - character = ubrk_open(UBRK_SENTENCE, "en_US", text, u_strlen(text), &status); + character = ubrk_open(UBRK_CHARACTER, "en_US", text, u_strlen(text), &status); if(U_FAILURE(status)){ log_err("FAIL: Error in ubrk_open() for character breakiterator: %s\n", myErrorName(status)); } else{ log_verbose("PASS: Successfully opened character breakiterator\n"); } + /*trying to open an illegal iterator*/ + bogus = ubrk_open(4, "en_US", text, u_strlen(text), &status); + if(U_SUCCESS(status)){ + log_err("FAIL: Error in ubrk_open() for BOGUS breakiterator. Expected U_MEMORY_ALLOCATION_ERROR"); + } + if(U_FAILURE(status)){ + if(status != U_MEMORY_ALLOCATION_ERROR){ + log_err("FAIL: Error in ubrk_open() for BOGUS breakiterator. Expected U_MEMORY_ALLOCATION_ERROR\n Got %s\n", myErrorName(status)); + } + } + status=U_ZERO_ERROR; -/* ======= Test ubrk_countAvialable() and ubrk_getAvilable() */ + +/* ======= Test ubrk_countAvialable() and ubrk_getAvialable() */ log_verbose("\nTesting ubrk_countAvailable() and ubrk_getAvailable()\n"); count=ubrk_countAvailable(); @@ -90,7 +103,14 @@ void TestBreakIteratorCAPI() else{ log_verbose("PASS: ubrk_countAvialable() successful returned %d\n", count); } - + for(i=0;i= count*/ + ucal_getAvailableTZIDs(offset, i, &status); + if(U_SUCCESS(status)){ + log_err("FAIL: Expected U_INDEX_OUTOFBOUNDS_ERROR where index > count for TZID's"); + } + if(status != U_INDEX_OUTOFBOUNDS_ERROR){ + log_err("FAIL:for TZID index > count Expected INDEX_OUTOFBOUNDS_ERROR Got %s\n", myErrorName(status)); + } + status=U_ZERO_ERROR; /*Testing the ucal_open() function*/ @@ -106,8 +114,8 @@ void TestCalendar() else log_err("FAIL: Error in countAvialable()\n"); - /*for(i=0;iu with skip did not match.\n"); +} +void TestStop(int32_t inputsize, int32_t outputsize) +{ + UChar sampleText[] = { 0x0000, 0xAC00, 0xAC01, 0xEF67, 0xD700 }; + UChar sampleText2[] = { 0x6D63, 0x6D64, 0x6D65, 0x6D66 }; + + const char expstopIBM_949[]= { + (char)0x00, (char)0xb0, (char)0xa1, (char)0xb0, (char)0xa2}; + + const char expstopIBM_943[] = { + (char)0x9f, (char)0xaf, (char)0x9f, (char)0xb1}; + + const char expstopIBM_930[] = { + (char)0x0e, (char)0x5d, (char)0x5f, (char)0x5d, (char)0x63}; + + UChar IBM_949stoptoUnicode[]= {0x0000, 0xAC00, 0xAC01}; + UChar IBM_943stoptoUnicode[]= { 0x6D63, 0x6D64}; + UChar IBM_930stoptoUnicode[]= { 0x6D63, 0x6D64}; + + + int32_t toIBM949Offsstop [] = { 0, 1, 1, 2, 2}; + int32_t toIBM943Offsstop [] = { 0, 0, 1, 1}; + int32_t toIBM930Offsstop [] = { 0, 0, 0, 1, 1}; + + int32_t fromIBM949Offs [] = { 0, 1, 3}; + int32_t fromIBM943Offs [] = { 0, 2}; + int32_t fromIBM930Offs [] = { 1, 3}; + + gInBufferSize = inputsize; + gOutBufferSize = outputsize; + /*From Unicode*/ + if(!testConvertFromUnicode(sampleText, sizeof(sampleText)/sizeof(sampleText[0]), + expstopIBM_949, sizeof(expstopIBM_949), "ibm-949", + (UConverterFromUCallback)UCNV_FROM_U_CALLBACK_STOP, toIBM949Offsstop )) + log_err("u-> ibm-949 with stop did not match.\n"); + if(!testConvertFromUnicode(sampleText2, sizeof(sampleText2)/sizeof(sampleText2[0]), + expstopIBM_943, sizeof(expstopIBM_943), "ibm-943", + (UConverterFromUCallback)UCNV_FROM_U_CALLBACK_STOP, toIBM943Offsstop )) + log_err("u-> ibm-943 with stop did not match.\n"); + if(!testConvertFromUnicode(sampleText2, sizeof(sampleText2)/sizeof(sampleText2[0]), + expstopIBM_930, sizeof(expstopIBM_930), "ibm-930", + (UConverterFromUCallback)UCNV_FROM_U_CALLBACK_STOP, toIBM930Offsstop )) + log_err("u-> ibm-930 with stop did not match.\n"); + + /*to Unicode*/ + if(!testConvertToUnicode(expstopIBM_949, sizeof(expstopIBM_949), + IBM_949stoptoUnicode, sizeof(IBM_949stoptoUnicode)/sizeof(IBM_949stoptoUnicode),"ibm-949", + (UConverterToUCallback)UCNV_TO_U_CALLBACK_STOP, fromIBM949Offs )) + log_err("ibm-949->u with stop did not match.\n"); + if(!testConvertToUnicode(expstopIBM_943, sizeof(expstopIBM_943), + IBM_943stoptoUnicode, sizeof(IBM_943stoptoUnicode)/sizeof(IBM_943stoptoUnicode[0]),"ibm-943", + (UConverterToUCallback)UCNV_TO_U_CALLBACK_STOP, fromIBM943Offs )) + log_err("ibm-943->u with stop did not match.\n"); + if(!testConvertToUnicode(expstopIBM_930, sizeof(expstopIBM_930), + IBM_930stoptoUnicode, sizeof(IBM_930stoptoUnicode)/sizeof(IBM_930stoptoUnicode[0]),"ibm-930", + (UConverterToUCallback)UCNV_TO_U_CALLBACK_STOP, fromIBM930Offs )) + log_err("ibm-930->u with stop did not match.\n"); + } void TestSub(int32_t inputsize, int32_t outputsize) { @@ -437,15 +503,36 @@ UBool testConvertFromUnicode(const UChar *source, int sourceLen, const char *ex checkOffsets ? offs : NULL, doFlush, /* flush if we're at the end of the input data */ &status); - - } while ( (status == U_INDEX_OUTOFBOUNDS_ERROR) || (sourceLimit < realSourceEnd) ); - - if(U_FAILURE(status)) - { - log_err("Problem tdoing fromUnicode, errcode %d %s\n", myErrorName(status), gNuConvTestName); - return FALSE; - } + /*check for an INVALID character for testing the call back function STOP*/ + if(status == U_INVALID_CHAR_FOUND || status == U_ILLEGAL_CHAR_FOUND ) + { + for(p = junkout;p %d chars out]. \nResult :", sourceLen, targ-junkout); if(VERBOSITY) @@ -602,11 +689,8 @@ UBool testConvertToUnicode( const char *source, int sourcelen, const UChar *expe checkOffsets ? offs : NULL, (UBool)(srcLimit == realSourceEnd), /* flush if we're at the end of hte source data */ &status); - - - - } while ( (status == U_INDEX_OUTOFBOUNDS_ERROR) || (srcLimit < realSourceEnd) ); /* while we just need another buffer */ - /*check for an INVALID character for testing the call back function STOP*/ + + /*check for an INVALID character for testing the call back function STOP*/ if(status == U_INVALID_CHAR_FOUND || status == U_ILLEGAL_CHAR_FOUND ) { for(p = junkout;p CharIterTest::CharIterTest() { @@ -23,8 +26,9 @@ void CharIterTest::runIndexedTest( int32_t index, UBool exec, char* &name, char* if (exec) logln("TestSuite LocaleTest: "); switch (index) { case 0: name = "TestConstructionAndEquality"; if (exec) TestConstructionAndEquality(); break; - case 1: name = "TestIteration"; if (exec) TestIteration(); break; - case 2: name = "TestIterationUChar32"; if (exec) TestIterationUChar32(); break; + case 1: name = "TestConstructionAndEqualityUChariter"; if (exec) TestConstructionAndEqualityUChariter(); break; + case 2: name = "TestIteration"; if (exec) TestIteration(); break; + case 3: name = "TestIterationUChar32"; if (exec) TestIterationUChar32(); break; default: name = ""; break; //needed to end loop @@ -34,8 +38,13 @@ void CharIterTest::runIndexedTest( int32_t index, UBool exec, char* &name, char* void CharIterTest::TestConstructionAndEquality() { UnicodeString testText("Now is the time for all good men to come to the aid of their country."); UnicodeString testText2("Don't bother using this string."); + UnicodeString result1, result2, result3; CharacterIterator* test1 = new StringCharacterIterator(testText); + CharacterIterator* test1b= new StringCharacterIterator(testText, -1); + CharacterIterator* test1c= new StringCharacterIterator(testText, 100); + CharacterIterator* test1d= new StringCharacterIterator(testText, -2, 100, 5); + CharacterIterator* test1e= new StringCharacterIterator(testText, 100, 20, 5); CharacterIterator* test2 = new StringCharacterIterator(testText, 5); CharacterIterator* test3 = new StringCharacterIterator(testText, 2, 20, 5); CharacterIterator* test4 = new StringCharacterIterator(testText2); @@ -53,6 +62,14 @@ void CharIterTest::TestConstructionAndEquality() { if (test1->hashCode() != test5->hashCode()) errln("hashCode() failed: identical objects have different hash codes"); + + test1->getText(result1); + test1b->getText(result2); + test1c->getText(result3); + if(result1 != result2 || result1 != result3) + errln("construction failed or getText() failed"); + + test1->setIndex(5); if (*test1 != *test2 || *test1 == *test5) errln("setIndex() failed"); @@ -66,7 +83,119 @@ void CharIterTest::TestConstructionAndEquality() { delete test3; delete test4; delete test5; + delete test1b; + delete test1c; + delete test1d; + delete test1e; + + + StringCharacterIterator* testChar1=new StringCharacterIterator(testText); + StringCharacterIterator* testChar2=new StringCharacterIterator(testText2); + StringCharacterIterator* testChar3=(StringCharacterIterator*)test1->clone(); + + testChar1->getText(result1); + testChar2->getText(result2); + testChar3->getText(result3); + if(result1 != result3 || result1 == result2) + errln("getText() failed"); + testChar3->setText(testText2); + testChar3->getText(result3); + if(result1 == result3 || result2 != result3) + errln("setText() or getText() failed"); + testChar3->setText(testText); + testChar3->getText(result3); + if(result1 != result3 || result1 == result2) + errln("setText() or getText() round-trip failed"); + + delete testChar1; + delete testChar2; + delete testChar3; + } +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)); + + u_uastrcpy(testText, testTextchars); + u_uastrcpy(testText2, testText2chars); + + UnicodeString result, result4, result5; + + + UCharCharacterIterator* test1 = new UCharCharacterIterator(testText, u_strlen(testText)); + UCharCharacterIterator* test2 = new UCharCharacterIterator(testText, u_strlen(testText), 5); + UCharCharacterIterator* test3 = new UCharCharacterIterator(testText, u_strlen(testText), 2, 20, 5); + UCharCharacterIterator* test4 = new UCharCharacterIterator(testText2, u_strlen(testText2)); + UCharCharacterIterator* test5 = (UCharCharacterIterator*)test1->clone(); + UCharCharacterIterator* test6=new UCharCharacterIterator(*test1); + + UCharCharacterIterator* test7a = new UCharCharacterIterator(testText, -1); + UCharCharacterIterator* test7b = new UCharCharacterIterator(testText, -1); + UCharCharacterIterator* test7c = new UCharCharacterIterator(testText, -1, 2, 20, 5); + + + + if (*test1 == *test2 || *test1 == *test3 || *test1 == *test4 ) + errln("Construction or operator== failed: Unequal objects compared equal"); + if (*test1 != *test5 ) + errln("clone() or equals() failed: Two clones tested unequal"); + + if (*test6 != *test1 ) + errln("copy construction or equals() failed: Two copies tested unequal"); + + if (test1->hashCode() == test2->hashCode() || test1->hashCode() == test3->hashCode() + || test1->hashCode() == test4->hashCode()) + errln("hashCode() failed: different objects have same hash code"); + + if (test1->hashCode() != test5->hashCode()) + errln("hashCode() failed: identical objects have different hash codes"); + + test7a->getText(result); + test7b->getText(result4); + test7c->getText(result5); + + if(result != "" || result4 != "" || result5 != "") + errln("error in construction"); + + test1->getText(result); + test4->getText(result4); + test5->getText(result5); + if(result != result5 || result == result4) + errln("getText() failed"); + test5->setText(testText2, u_strlen(testText2)); + test5->getText(result5); + if(result == result5 || result4 != result5) + errln("setText() or getText() failed"); + test5->setText(testText, u_strlen(testText)); + test5->getText(result5); + if(result != result5 || result == result4) + errln("setText() or getText() round-trip failed"); + + + test1->setIndex(5); + if (*test1 != *test2 || *test1 == *test5) + errln("setIndex() failed"); + + *test1 = *test3; + if (*test1 != *test3 || *test1 == *test5) + errln("operator= failed"); + + + + delete test1; + delete test2; + delete test3; + delete test4; + delete test5; + delete test6; + delete test7a; + delete test7b; + delete test7c; +} + void CharIterTest::TestIteration() { UnicodeString text("Now is the time for all good men to come to the aid of their country."); @@ -109,6 +238,12 @@ void CharIterTest::TestIteration() { i++; } } while (c != CharacterIterator::DONE); + c=iter.next(); + if(c!= CharacterIterator::DONE) + errln("next() didn't return DONE at the end"); + c=iter.setIndex(text.length()+1); + if(c!= CharacterIterator::DONE) + errln("setIndex(len+1) didn't return DONE"); c = iter.last(); i = text.length() - 1; @@ -135,7 +270,12 @@ void CharIterTest::TestIteration() { } } while (c != CharacterIterator::DONE); - //testing firstPostInc, nextPostInc, setTostart + c=iter.previous(); + if(c!= CharacterIterator::DONE) + errln("previous didn't return DONE at the beginning"); + + + //testing firstPostInc, nextPostInc, setTostart i = 0; c=iter.firstPostInc(); if(c != text[i]) @@ -165,7 +305,9 @@ void CharIterTest::TestIteration() { if(iter.current() != text[i]) errln("current() after nextPostInc() isn't working right"); } while (iter.hasNext()); - + c=iter.nextPostInc(); + if(c!= CharacterIterator::DONE) + errln("nextPostInc() didn't return DONE at the beginning"); } { @@ -243,6 +385,31 @@ void CharIterTest::TestIterationUChar32() { if (iter.current32() != text[(UTextOffset)1]) errln("Iterator didn't start out in the right place."); + + c=iter.setToStart(); + i=0; + i=iter.move32(1, CharacterIterator::kStart); + c=iter.current32(); + if(c != text.char32At(1) || i!=1) + errln((UnicodeString)"move32(1, kStart) didn't work correctly expected " + c + " got " + text.char32At(1) ); + + i=iter.move32(2, CharacterIterator::kCurrent); + c=iter.current32(); + if(c != text.char32At(4) || i!=4) + errln((UnicodeString)"move32(2, kCurrent) didn't work correctly expected " + c + " got " + text.char32At(4) + "i=" + i); + + i=iter.move32(-2, CharacterIterator::kCurrent); + c=iter.current32(); + if(c != text.char32At(1) || i!=1) + errln((UnicodeString)"move32(-2, kCurrent) didn't work correctly expected " + c + " got " + text.char32At(1) + "i=" + i); + + + + i=iter.move32(-2, CharacterIterator::kEnd); + c=iter.current32(); + if(c != text.char32At((text.length()-3)) || i!=(text.length()-3)) + errln((UnicodeString)"move32(-2, kEnd) didn't work correctly expected " + c + " got " + text.char32At((text.length()-3)) + "i=" + i); + c = iter.first32(); i = 0; @@ -273,12 +440,21 @@ void CharIterTest::TestIterationUChar32() { } while (c != CharacterIterator::DONE); if(iter.hasNext() == TRUE) errln("hasNext() returned true at the end of the string"); - + + c=iter.setToEnd(); if(iter.getIndex() != text.length() || iter.hasNext() != FALSE) errln("setToEnd failed"); + c=iter.next32(); + if(c!= CharacterIterator::DONE) + errln("next32 didn't return DONE at the end"); + c=iter.setIndex32(text.length()+1); + if(c!= CharacterIterator::DONE) + errln("setIndex32(len+1) didn't return DONE"); + + c = iter.last32(); i = text.length()-1; logln("Testing backward iteration..."); @@ -305,10 +481,15 @@ void CharIterTest::TestIterationUChar32() { } while (c != CharacterIterator::DONE); if(iter.hasPrevious() == TRUE) errln("hasPrevious returned true after reaching the start"); - + + c=iter.previous32(); + if(c!= CharacterIterator::DONE) + errln("previous32 didn't return DONE at the beginning"); + - - //testing first32PostInc, next32PostInc, setTostart + + + //testing first32PostInc, next32PostInc, setTostart i = 0; c=iter.first32PostInc(); if(c != text.char32At(i)) @@ -337,8 +518,11 @@ void CharIterTest::TestIterationUChar32() { if(iter.current32() != text.char32At(i)) errln("current() after next32PostInc() isn't working right"); } while (iter.hasNext()); + c=iter.next32PostInc(); + if(c!= CharacterIterator::DONE) + errln("next32PostInc() didn't return DONE at the beginning"); - + } { @@ -350,6 +534,7 @@ void CharIterTest::TestIterationUChar32() { errln("starting the iterator in the middle didn't work"); c = iter.first32(); + i = 1; logln("Testing forward iteration over a range..."); @@ -373,8 +558,13 @@ void CharIterTest::TestIterationUChar32() { i=UTF16_NEED_MULTIPLE_UCHAR(c) ? i+2 : i+1; } } while (c != CharacterIterator::DONE); + c=iter.next32(); + if(c != CharacterIterator::DONE) + errln("error in next32()"); - c = iter.last32(); + + + c=iter.last32(); i = 10; logln("Testing backward iteration over a range..."); do { @@ -386,7 +576,6 @@ void CharIterTest::TestIterationUChar32() { errln((UnicodeString)"Character mismatch at position " + i + (UnicodeString)", iterator has " + c + (UnicodeString)", string has " + text.char32At(i)); - if (iter.current32() != c) errln("current32() isn't working right"); if (iter.getIndex() != i) @@ -398,8 +587,12 @@ void CharIterTest::TestIterationUChar32() { c = iter.previous32(); i=UTF16_NEED_MULTIPLE_UCHAR(c) ? i-2 : i-1; } + } while (c != CharacterIterator::DONE); + c=iter.previous32(); + if(c!= CharacterIterator::DONE) + errln("error on previous32"); - + } } diff --git a/icu4c/source/test/intltest/citrtest.h b/icu4c/source/test/intltest/citrtest.h index 9ba4ee9fe00..970969ae221 100644 --- a/icu4c/source/test/intltest/citrtest.h +++ b/icu4c/source/test/intltest/citrtest.h @@ -20,6 +20,10 @@ public: * Test Constructors and operators ==, != and a few other methods **/ void TestConstructionAndEquality(void); + /** + * Test Constructors and operators ==, != and a few other methods for UChariter + **/ + void TestConstructionAndEqualityUChariter(void); /** * test the iteration functionality in different ways **/ diff --git a/icu4c/source/test/intltest/dcfmapts.cpp b/icu4c/source/test/intltest/dcfmapts.cpp index 5fddafacd86..604c08ce2cf 100644 --- a/icu4c/source/test/intltest/dcfmapts.cpp +++ b/icu4c/source/test/intltest/dcfmapts.cpp @@ -29,7 +29,13 @@ void IntlTestDecimalFormatAPI::runIndexedTest( int32_t index, UBool exec, char* testAPI(par); } break; - + case 1: name = "Rounding test"; + if(exec) { + logln((UnicodeString)"DecimalFormat Rounding test---"); + testRounding(par); + } + break; + default: name = ""; break; } } @@ -219,11 +225,45 @@ void IntlTestDecimalFormatAPI::testAPI(char *par) } pat.setDecimalSeparatorAlwaysShown(TRUE); - UBool tf = pat.isDecimalSeparatorAlwaysShown(); + bool_t tf = pat.isDecimalSeparatorAlwaysShown(); logln((UnicodeString)"DecimalSeparatorIsAlwaysShown (should be TRUE) is " + (UnicodeString) (tf ? "TRUE" : "FALSE")); if(tf != TRUE) { errln((UnicodeString)"ERROR: setDecimalSeparatorAlwaysShown() failed"); } + // Added by Ken Liu testing set/isExponentSignAlwaysShown + pat.setExponentSignAlwaysShown(TRUE); + bool_t esas = pat.isExponentSignAlwaysShown(); + logln((UnicodeString)"ExponentSignAlwaysShown (should be TRUE) is " + (UnicodeString) (esas ? "TRUE" : "FALSE")); + if(esas != TRUE) { + errln((UnicodeString)"ERROR: ExponentSignAlwaysShown() failed"); + } + + // Added by Ken Liu testing set/isScientificNotation + pat.setScientificNotation(TRUE); + UBool sn = pat.isScientificNotation(); + logln((UnicodeString)"isScientificNotation (should be TRUE) is " + (UnicodeString) (sn ? "TRUE" : "FALSE")); + if(sn != TRUE) { + errln((UnicodeString)"ERROR: setScientificNotation() failed"); + } + + // Added by Ken Liu testing set/getMinimumExponentDigits + int8_t MinimumExponentDigits = 0; + pat.setMinimumExponentDigits(2); + MinimumExponentDigits = pat.getMinimumExponentDigits(); + logln((UnicodeString)"MinimumExponentDigits (should be 2) is " + (int8_t) MinimumExponentDigits); + if(MinimumExponentDigits != 2) { + errln((UnicodeString)"ERROR: setMinimumExponentDigits() failed"); + } + + // Added by Ken Liu testing set/getRoundingIncrement + double RoundingIncrement = 0.0; + pat.setRoundingIncrement(2.0); + RoundingIncrement = pat.getRoundingIncrement(); + logln((UnicodeString)"RoundingIncrement (should be 2.0) is " + (double) RoundingIncrement); + if(RoundingIncrement != 2.0) { + errln((UnicodeString)"ERROR: setRoundingIncrement() failed"); + } + //end of Ken's Adding UnicodeString funkyPat; funkyPat = pat.toPattern(funkyPat); @@ -281,3 +321,58 @@ void IntlTestDecimalFormatAPI::testAPI(char *par) delete test; } + +void IntlTestDecimalFormatAPI::testRounding(char *par) +{ + UErrorCode status = U_ZERO_ERROR; + double Roundingnumber = 2.55; + double Roundingnumber1 = -2.55; + //+2.55 results -2.55 results + double result[]={ 3.0, -2.0, // kRoundCeiling 0, + 2.0, -3.0, // kRoundFloor 1, + 2.0, -2.0, // kRoundDown 2, + 3.0, -3.0, // kRoundUp 3, + 3.0, -3.0, // kRoundHalfEven 4, + 3.0, -3.0, // kRoundHalfDown 5, + 3.0, -3.0 // kRoundHalfUp 6 + }; + DecimalFormat pat(status); + if(U_FAILURE(status)) { + errln((UnicodeString)"ERROR: Could not create DecimalFormat (default)"); + } + uint16_t mode; + uint16_t i=0; + UnicodeString message; + UnicodeString resultStr; + for(mode=0;mode < 7;mode++){ + pat.setRoundingMode((DecimalFormat::ERoundingMode)mode); + if(pat.getRoundingMode() != (DecimalFormat::ERoundingMode)mode){ + errln((UnicodeString)"SetRoundingMode or GetRoundingMode failed for mode=" + mode); + } + + + //for +2.55 with RoundingIncrement=1.0 + pat.setRoundingIncrement(1.0); + pat.format(Roundingnumber, resultStr); + message= (UnicodeString)"round(" + (double)Roundingnumber + UnicodeString(",") + mode + UnicodeString(",FALSE) with RoundingIncrement=1.0==>"); + verify(message, resultStr, result[i++]); + message.remove(); + resultStr.remove(); + + //for -2.55 with RoundingIncrement=1.0 + pat.format(Roundingnumber1, resultStr); + message= (UnicodeString)"round(" + (double)Roundingnumber1 + UnicodeString(",") + mode + UnicodeString(",FALSE) with RoundingIncrement=1.0==>"); + verify(message, resultStr, result[i++]); + message.remove(); + resultStr.remove(); + } + +} +void IntlTestDecimalFormatAPI::verify(const UnicodeString& message, const UnicodeString& got, double expected){ + logln((UnicodeString)message + got + (UnicodeString)" Expected : " + expected); + UnicodeString expectedStr(""); + expectedStr=expectedStr + expected; + if(got != expectedStr ) { + errln((UnicodeString)"ERROR: Round() failed: " + message + got + (UnicodeString)" Expected : " + expectedStr); + } +} diff --git a/icu4c/source/test/intltest/dcfmapts.h b/icu4c/source/test/intltest/dcfmapts.h index bff093833aa..04aa710f5fe 100644 --- a/icu4c/source/test/intltest/dcfmapts.h +++ b/icu4c/source/test/intltest/dcfmapts.h @@ -14,13 +14,17 @@ class IntlTestDecimalFormatAPI: public IntlTest { - void runIndexedTest( int32_t index, UBool exec, char* &name, char* par = NULL ); + void runIndexedTest( int32_t index, bool_t exec, char* &name, char* par = NULL ); private: /** * Tests basic functionality of various API functions for DecimalFormat **/ void testAPI(char *par); + void testRounding(char *par); + + /*Helper functions */ + void verify(const UnicodeString& message, const UnicodeString& got, double expected); }; #endif diff --git a/icu4c/source/test/intltest/ucdtest.cpp b/icu4c/source/test/intltest/ucdtest.cpp index 73aa6f419e1..4c2a1e01f95 100644 --- a/icu4c/source/test/intltest/ucdtest.cpp +++ b/icu4c/source/test/intltest/ucdtest.cpp @@ -30,7 +30,7 @@ void UnicodeTest::runIndexedTest( int32_t index, UBool exec, char* &name, char* case 4: name = "TestCodeUnit"; if(exec) TestCodeUnit(); break; case 5: name = "TestCodePoint"; if(exec) TestCodePoint(); break; case 6: name = "TestCharLength"; if(exec) TestCharLength(); break; - + case 7: name = "TestIdentifier"; if(exec) TestIdentifier(); break; default: name = ""; break; //needed to end loop } } @@ -167,6 +167,8 @@ void UnicodeTest::TestMisc() { const UChar sampleSpaces[] = {0x0020, 0x00a0, 0x2000, 0x2001, 0x2005}; const UChar sampleNonSpaces[] = {0x61, 0x62, 0x63, 0x64, 0x74}; + const UChar sampleWhiteSpaces[] = {0x2008, 0x2009, 0x200a, 0x001c, 0x000c}; + const UChar sampleNonWhiteSpaces[] = {0x61, 0x62, 0x3c, 0x28, 0x3f}; const UChar sampleUndefined[] = {0xfff1, 0xfff7, 0xfa30}; const UChar sampleDefined[] = {0x523E, 0x4f88, 0xfffd}; const UChar sampleBase[] = {0x0061, 0x0031, 0x03d2}; @@ -187,6 +189,15 @@ void UnicodeTest::TestMisc() errln((UnicodeString)"Space char test error : " + (int32_t)sampleSpaces[i] + " or " + (int32_t)sampleNonSpaces[i]); } + for (i = 0; i < 5; i++) { +// log_ln("Testing for isWhitespace and nonWhitespaces\n"); + if (!(Unicode::isWhitespace(sampleWhiteSpaces[i])) || + (Unicode::isWhitespace(sampleNonWhiteSpaces[i]))) + { + errln((UnicodeString)"White Space char test error : " + (int32_t)sampleWhiteSpaces[i] + + "or" + (int32_t)sampleNonWhiteSpaces[i]); + } + } for (i = 0; i < 3; i++) { // logln((UnicodeString)"testing " + (int32_t)i + "..."); if ((Unicode::isDefined(sampleUndefined[i])) || @@ -250,9 +261,9 @@ void UnicodeTest::TestIdentifier() const UChar sampleUnicodeIDStart[] = {0x0250, 0x00e2, 0x0061}; const UChar sampleNonUnicodeIDStart[] = {0x2000, 0x000a, 0x2019}; const UChar sampleJavaIDPart[] = {0x005f, 0x0032, 0x0045}; - const UChar sampleNonJavaIDPart[] = {0x007f, 0x2020, 0x0020}; + const UChar sampleNonJavaIDPart[] = {0x2030, 0x2020, 0x0020}; const UChar sampleUnicodeIDPart[] = {0x005f, 0x0032, 0x0045}; - const UChar sampleNonUnicodeIDPart[] = {0x007f, 0x00a3, 0x0020}; + const UChar sampleNonUnicodeIDPart[] = {0x2030, 0x00a3, 0x0020}; const UChar sampleIDIgnore[] = {0x0006, 0x0010, 0x206b}; const UChar sampleNonIDIgnore[] = {0x0075, 0x00a3, 0x0061};