mirror of
https://github.com/unicode-org/icu.git
synced 2025-04-06 22:15:31 +00:00
ICU-447 Addtional tests for extended code coverage
X-SVN-Rev: 1636
This commit is contained in:
parent
cdc7d9b910
commit
b429022d94
12 changed files with 588 additions and 59 deletions
|
@ -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;i++)
|
||||
{
|
||||
log_verbose("%s\n", ubrk_getAvailable(i));
|
||||
if (ubrk_getAvailable(i) == 0)
|
||||
log_err("No locale for which breakiterator is applicable\n");
|
||||
else
|
||||
log_verbose("A locale %s for which breakiterator is applicable\n",ubrk_getAvailable(i));
|
||||
}
|
||||
|
||||
/*========Test ubrk_first(), ubrk_last()...... and other functions*/
|
||||
|
||||
|
@ -125,25 +145,24 @@ void TestBreakIteratorCAPI()
|
|||
log_verbose("\nTesting the functions for character\n");
|
||||
ubrk_first(character);
|
||||
pos = ubrk_following(character, 5);
|
||||
if(pos!=18)
|
||||
log_err("error ubrk_following(character,5) did not return 18\n");
|
||||
if(pos!=6)
|
||||
log_err("error ubrk_following(character,5) did not return 6\n");
|
||||
log_verbose("Following (character,5) = %d\n", (int32_t)pos);
|
||||
pos=ubrk_following(character, 18);
|
||||
if(pos!=22)
|
||||
log_err("error ubrk_following(character,18) did not return 22\n");
|
||||
if(pos!=19)
|
||||
log_err("error ubrk_following(character,18) did not return 19\n");
|
||||
log_verbose("Followingcharacter,18) = %d\n", (int32_t)pos);
|
||||
pos=ubrk_preceding(character, 22);
|
||||
if(pos!=18)
|
||||
log_err("error ubrk_preceding(character,22) did not return 18\n");
|
||||
if(pos!=21)
|
||||
log_err("error ubrk_preceding(character,22) did not return 21\n");
|
||||
log_verbose("preceding(character,22) = %d\n", (int32_t)pos);
|
||||
|
||||
|
||||
log_verbose("\nTesting the functions for line\n");
|
||||
ubrk_first(line);
|
||||
pos=ubrk_first(line);
|
||||
if(pos != 0)
|
||||
log_err("error ubrk_first(line) returned %d, expected 0\n", (int32_t)pos);
|
||||
pos = ubrk_next(line);
|
||||
if(pos!=18)
|
||||
log_err("error ubrk_next(line) did not return 18\n");
|
||||
log_verbose("Next (line) = %d\n", (int32_t)pos);
|
||||
pos=ubrk_following(line, 18);
|
||||
if(pos!=22)
|
||||
log_err("error ubrk_following(line) did not return 22\n");
|
||||
|
|
|
@ -68,7 +68,15 @@ void TestCalendar()
|
|||
}
|
||||
log_verbose("%s\n", austrdup(ucal_getAvailableTZIDs(offset, i, &status)));
|
||||
}
|
||||
|
||||
/*get Illegal TZID where index >= 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;i<count;i++) */
|
||||
/*log_verbose("%s\n", uloc_getName(ucal_getAvailable(i))); */
|
||||
for(i=0;i<count;i++)
|
||||
log_verbose("%s\n", ucal_getAvailable(i));
|
||||
|
||||
|
||||
/*Testing the equality between calendar's*/
|
||||
|
@ -160,10 +168,27 @@ void TestCalendar()
|
|||
log_verbose("PASS: got the correct time zone display name %s\n", austrdup(result) );
|
||||
}
|
||||
else{
|
||||
log_err("FAIL: got the wrong time zone display name %s, wanted %s\n", austrdup(result) , expectPDT);
|
||||
log_err("FAIL: got the wrong time zone(DST) display name %s, wanted %s\n", austrdup(result) , expectPDT);
|
||||
}
|
||||
|
||||
ucal_getTimeZoneDisplayName(caldef, UCAL_SHORT_DST, "en_US", result, resultlength, &status);
|
||||
u_uastrcpy(tzdname, "PDT");
|
||||
if(u_strcmp(tzdname, result) != 0){
|
||||
log_err("FAIL: got the wrong time zone(SHORT_DST) display name %s, wanted %s\n", austrdup(result), austrdup(tzdname));
|
||||
}
|
||||
|
||||
ucal_getTimeZoneDisplayName(caldef, UCAL_STANDARD, "en_US", result, resultlength, &status);
|
||||
u_uastrcpy(tzdname, "Pacific Standard Time");
|
||||
if(u_strcmp(tzdname, result) != 0){
|
||||
log_err("FAIL: got the wrong time zone(STANDARD) display name %s, wanted %s\n", austrdup(result), austrdup(tzdname));
|
||||
}
|
||||
|
||||
ucal_getTimeZoneDisplayName(caldef, UCAL_SHORT_STANDARD, "en_US", result, resultlength, &status);
|
||||
u_uastrcpy(tzdname, "PST");
|
||||
if(u_strcmp(tzdname, result) != 0){
|
||||
log_err("FAIL: got the wrong time zone(SHORT_STANDARD) display name %s, wanted %s\n", austrdup(result), austrdup(tzdname));
|
||||
}
|
||||
|
||||
|
||||
/*testing the setAttributes and getAttributes of a UCalendar*/
|
||||
log_verbose("\nTesting the getAttributes and set Attributes\n");
|
||||
|
@ -189,6 +214,11 @@ void TestCalendar()
|
|||
if (ucal_getAttribute(calit, UCAL_FIRST_DAY_OF_WEEK) != i)
|
||||
log_err("FAIL: set/getFirstDayOfWeek failed\n");
|
||||
}
|
||||
/*get bogus Attribute*/
|
||||
count=ucal_getAttribute(calit, 99);//BOGUS_ATTRIBUTE
|
||||
if(count != -1){
|
||||
log_err("FAIL: get/bogus attribute should return -1\n");
|
||||
}
|
||||
|
||||
/*set it back to normal */
|
||||
ucal_setAttribute(calit, UCAL_FIRST_DAY_OF_WEEK,count);
|
||||
|
@ -782,6 +812,13 @@ void TestGetLimits()
|
|||
log_verbose("getLimits successful\n");
|
||||
|
||||
|
||||
/*get BOGUS_LIMIT type*/
|
||||
val=ucal_getLimit(cal, UCAL_SECOND, 99, &status);
|
||||
if(val != -1){
|
||||
log_err("FAIL: ucal_getLimit() with BOGUS type should return -1\n");
|
||||
}
|
||||
status=U_ZERO_ERROR;
|
||||
|
||||
|
||||
ucal_close(cal);
|
||||
free(tzID);
|
||||
|
|
|
@ -34,6 +34,7 @@ void addNumFrDepTest(TestNode** root)
|
|||
addTest(root, &TestCurrencySign, "tsformat/cnmdptst/TestCurrencySign");
|
||||
addTest(root, &TestCurrency, "tsformat/cnmdptst/TestCurrency");
|
||||
addTest(root, &TestRounding487, "tsformat/cnmdptst/TestRounding487");
|
||||
addTest(root, &TestDoubleAttribute, "tsformat/cnmdptst/TestDoubleAttribute");
|
||||
|
||||
|
||||
}
|
||||
|
@ -462,3 +463,31 @@ void roundingTest(UNumberFormat* nf, double x, int32_t maxFractionDigits, const
|
|||
u_uastrcpy(res, expected);
|
||||
if (u_strcmp(out, res) != 0) log_err("FAIL: Expected: %s or %s\n", expected, austrdup(res) );
|
||||
}
|
||||
/*
|
||||
* Testing unum_getDoubleAttribute and unum_setDoubleAttribute()
|
||||
*/
|
||||
void TestDoubleAttribute()
|
||||
{
|
||||
double mydata[] = { 1.11, 22.22, 333.33, 4444.44, 55555.55, 666666.66, 7777777.77, 88888888.88, 999999999.99};
|
||||
double dvalue;
|
||||
int i;
|
||||
UErrorCode status=U_ZERO_ERROR;
|
||||
UNumberFormatAttribute attr;
|
||||
UNumberFormatStyle style= UNUM_DEFAULT;
|
||||
UNumberFormat *def;
|
||||
def=unum_open(style, NULL, &status);
|
||||
log_verbose("\nTesting get and set DoubleAttributes\n");
|
||||
attr=UNUM_ROUNDING_INCREMENT;
|
||||
dvalue=unum_getDoubleAttribute(def, attr);
|
||||
for (i = 0; i<9 ; i++)
|
||||
{
|
||||
dvalue = mydata[i];
|
||||
unum_setDoubleAttribute(def, attr, dvalue);
|
||||
if(unum_getDoubleAttribute(def,attr)!=mydata[i])
|
||||
log_err("Fail: error in setting and getting double attributes for UNUM_ROUNDING_INCREMENT\n");
|
||||
else
|
||||
log_verbose("Pass: setting and getting double attributes for UNUM_ROUNDING_INCREMENT works fine\n");
|
||||
}
|
||||
unum_close(def);
|
||||
}
|
||||
|
||||
|
|
|
@ -37,6 +37,10 @@ static void TestRounding487(void);
|
|||
/* Test localized currency patterns. */
|
||||
static void TestCurrency(void);
|
||||
|
||||
/* Test getDoubleAttribute and getDoubleAttribute */
|
||||
static void TestDoubleAttribute(void);
|
||||
|
||||
|
||||
/*Internal functions used*/
|
||||
static void roundingTest(UNumberFormat*, double, int32_t, const char*);
|
||||
|
||||
|
|
|
@ -63,7 +63,7 @@ void TestNumberFormat()
|
|||
UErrorCode status=U_ZERO_ERROR;
|
||||
UNumberFormatStyle style= UNUM_DEFAULT;
|
||||
UNumberFormat *pattern;
|
||||
UNumberFormat *def, *fr, *cur_def, *cur_fr, *per_def, *per_fr, *cur_frpattern;
|
||||
UNumberFormat *def, *fr, *cur_def, *cur_fr, *per_def, *per_fr, *cur_frpattern, *myclone;
|
||||
/* Testing unum_open() with various Numberformat styles and locales*/
|
||||
status = U_ZERO_ERROR;
|
||||
log_verbose("Testing unum_open() with default style and locale\n");
|
||||
|
@ -108,20 +108,35 @@ void TestNumberFormat()
|
|||
if(U_FAILURE(status))
|
||||
log_err("Error: could not create NumberFormat using unum_open(spellout, NULL, &status): %s\n", myErrorName(status));
|
||||
*/
|
||||
|
||||
/* Testing unum_clone(..) */
|
||||
log_verbose("\nTesting unum_clone(fmt, status)");
|
||||
status = U_ZERO_ERROR;
|
||||
myclone = unum_clone(def,&status);
|
||||
if(U_FAILURE(status))
|
||||
log_err("Error: could not clone unum_clone(def, &status): %s\n", myErrorName(status));
|
||||
else
|
||||
{
|
||||
log_verbose("unum_clone() successful\n");
|
||||
}
|
||||
|
||||
/*Testing unum_getAvailable() and unum_countAvailable()*/
|
||||
log_verbose("\nTesting getAvailableLocales and countAvailable()\n");
|
||||
numlocales=unum_countAvailable();
|
||||
/* use something sensible w/o hardcoding the count */
|
||||
if(numlocales < 0)
|
||||
log_err("error in countAvailable");
|
||||
else{
|
||||
log_verbose("unum_countAvialable() successful\n");
|
||||
log_verbose("The no: of locales where number formattting is applicable is %d\n", numlocales);
|
||||
}
|
||||
/*for(i=0;i<numlocales;i++)
|
||||
log_verbose("%s\n", uloc_getName(unum_getAvailable(i))); */
|
||||
for(i=0;i<numlocales;i++)
|
||||
{
|
||||
log_verbose("%s\n", unum_getAvailable(i));
|
||||
if (unum_getAvailable(i) == 0)
|
||||
log_err("No locale for which number formatting patterns are applicable\n");
|
||||
else
|
||||
log_verbose("A locale %s for which number formatting patterns are applicable\n",unum_getAvailable(i));
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*Testing unum_format() and unum_formatdouble()*/
|
||||
|
@ -353,6 +368,7 @@ free(result);
|
|||
log_err("Formatting failed after setting symbols - got different result\n");
|
||||
}
|
||||
|
||||
|
||||
/*----------- */
|
||||
|
||||
free(result);
|
||||
|
@ -368,7 +384,6 @@ free(temp1);
|
|||
return;
|
||||
}
|
||||
}
|
||||
|
||||
for(i = 0; i < UNUM_FORMAT_SYMBOL_COUNT; ++i) {
|
||||
resultlength = unum_getSymbol(cur_frpattern, i, symbol, sizeof(symbol)/U_SIZEOF_UCHAR, &status);
|
||||
if(U_FAILURE(status)) {
|
||||
|
@ -379,7 +394,17 @@ free(temp1);
|
|||
log_err("Failure in unum_getSymbol(%d): got unexpected symbol\n", i);
|
||||
}
|
||||
}
|
||||
|
||||
/*try getting from a bogus symbol*/
|
||||
unum_getSymbol(cur_frpattern, i, symbol, sizeof(symbol)/U_SIZEOF_UCHAR, &status);
|
||||
if(U_SUCCESS(status)){
|
||||
log_err("Error : Expected U_ILLEGAL_ARGUMENT_ERROR for bogus symbol");
|
||||
}
|
||||
if(U_FAILURE(status)){
|
||||
if(status != U_ILLEGAL_ARGUMENT_ERROR){
|
||||
log_err("Error: Expected U_ILLEGAL_ARGUMENT_ERROR for bogus symbol, Got %s\n", myErrorName(status));
|
||||
}
|
||||
}
|
||||
status=U_ZERO_ERROR;
|
||||
|
||||
/* Testing unum_getTextAttribute() and unum_setTextAttribute()*/
|
||||
log_verbose("\nTesting getting and setting text attributes\n");
|
||||
|
@ -457,6 +482,23 @@ free(temp1);
|
|||
log_err("ERROR: get and setTextAttributes with negative suffix failed\n");
|
||||
else
|
||||
log_verbose("Pass: get and settextAttributes with negative suffix works fine\n");
|
||||
|
||||
u_uastrcpy(suffix, "++");
|
||||
unum_setTextAttribute(def, UNUM_POSITIVE_SUFFIX, suffix, u_strlen(suffix) , &status);
|
||||
if(U_FAILURE(status))
|
||||
{
|
||||
log_err("error in setting the text attributes: %s\n", myErrorName(status));
|
||||
}
|
||||
|
||||
unum_getTextAttribute(def, UNUM_POSITIVE_SUFFIX, temp, resultlength, &status);
|
||||
if(U_FAILURE(status))
|
||||
{
|
||||
log_err("error in getting the text attributes : %s\n", myErrorName(status));
|
||||
}
|
||||
if(u_strcmp(suffix, temp)!=0)
|
||||
log_err("ERROR: get and setTextAttributes with negative suffix failed\n");
|
||||
else
|
||||
log_verbose("Pass: get and settextAttributes with negative suffix works fine\n");
|
||||
|
||||
|
||||
|
||||
|
@ -483,7 +525,7 @@ free(temp1);
|
|||
|
||||
/*testing set and get Attributes extensively */
|
||||
log_verbose("\nTesting get and set attributes extensively\n");
|
||||
for(attr=UNUM_PARSE_INT_ONLY; attr<= UNUM_GROUPING_SIZE; attr=(UNumberFormatAttribute)((int32_t)attr + 1) ){
|
||||
for(attr=UNUM_PARSE_INT_ONLY; attr<= UNUM_PADDING_POSITION; attr=(UNumberFormatAttribute)((int32_t)attr + 1) ){
|
||||
newvalue=unum_getAttribute(fr, attr);
|
||||
unum_setAttribute(def, attr, newvalue);
|
||||
if(unum_getAttribute(def,attr)!=unum_getAttribute(fr, attr))
|
||||
|
|
|
@ -73,10 +73,11 @@ void setNuConvTestName(const char *codepage, const char *direction)
|
|||
void addTestConvertErrorCallBack(TestNode** root)
|
||||
{
|
||||
addTest(root, &TestSkipCallBack, "tsconv/nccbtst/TestSkipCallBack");
|
||||
addTest(root, &TestStopCallBack, "tsconv/nccbtst/TestStopCallBack");
|
||||
addTest(root, &TestSubCallBack, "tsconv/nccbtst/TestSubCallBack");
|
||||
addTest(root, &TestSubWithValueCallBack, "tsconv/nccbtst/TestSubWithValueCallBack");
|
||||
addTest(root, &TestLegalAndOtherCallBack, "tsconv/nccbtst/TestLegalAndOtherCallBack");
|
||||
addTest(root, &TestSingleByteCallBack, "tsconv/nccbtst/TestSingleByteCallBack");
|
||||
addTest(root, &TestSingleByteCallBack, "tsconv/nccbtst/TestSingleByteCallBack");
|
||||
}
|
||||
|
||||
void TestSkipCallBack()
|
||||
|
@ -86,6 +87,13 @@ void TestSkipCallBack()
|
|||
TestSkip(1,1);
|
||||
TestSkip(NEW_MAX_BUFFER, 1);
|
||||
}
|
||||
void TestStopCallBack()
|
||||
{
|
||||
TestStop(NEW_MAX_BUFFER, NEW_MAX_BUFFER);
|
||||
TestStop(1,NEW_MAX_BUFFER);
|
||||
TestStop(1,1);
|
||||
TestStop(NEW_MAX_BUFFER, 1);
|
||||
}
|
||||
void TestSubCallBack()
|
||||
{
|
||||
TestSub(NEW_MAX_BUFFER, NEW_MAX_BUFFER);
|
||||
|
@ -172,6 +180,64 @@ void TestSkip(int32_t inputsize, int32_t outputsize)
|
|||
(UConverterToUCallback)UCNV_TO_U_CALLBACK_SKIP, fromIBM930Offs ))
|
||||
log_err("ibm-930->u 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<targ;p++)
|
||||
sprintf(junk + strlen(junk), "0x%02x, ", (0xFF) & (unsigned int)*p);
|
||||
/* printSeqErr(junkout, expectlen);*/
|
||||
if(!memcmp(junkout, expect, expectLen))
|
||||
{
|
||||
log_verbose("Matches!\n");
|
||||
return TRUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
log_err("String does not match. %s\n", gNuConvTestName);
|
||||
log_verbose("String does not match. %s\n", gNuConvTestName);
|
||||
printSeq(junkout, expectLen);
|
||||
printSeq(expect, expectLen);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
}
|
||||
} while ( (status == U_INDEX_OUTOFBOUNDS_ERROR) || (sourceLimit < realSourceEnd) );
|
||||
|
||||
if(U_FAILURE(status))
|
||||
{
|
||||
log_err("Problem doing toUnicode, errcode %d %s\n", myErrorName(status), gNuConvTestName);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
log_verbose("\nConversion done [%d uchars in -> %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<targ;p++)
|
||||
|
@ -627,6 +711,10 @@ UBool testConvertToUnicode( const char *source, int sourcelen, const UChar *expe
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
} while ( (status == U_INDEX_OUTOFBOUNDS_ERROR) || (srcLimit < realSourceEnd) ); /* while we just need another buffer */
|
||||
|
||||
|
||||
if(U_FAILURE(status))
|
||||
{
|
||||
log_err("Problem doing toUnicode, errcode %d %s\n", myErrorName(status), gNuConvTestName);
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
|
||||
|
||||
static void TestSkipCallBack(void);
|
||||
static void TestStopCallBack(void);
|
||||
static void TestSubCallBack(void);
|
||||
static void TestSubWithValueCallBack(void);
|
||||
static void TestLegalAndOtherCallBack(void);
|
||||
|
@ -27,6 +28,8 @@ static void TestSingleByteCallBack(void);
|
|||
|
||||
static void TestSkip(int32_t inputsize, int32_t outputsize);
|
||||
|
||||
static void TestStop(int32_t inputsize, int32_t outputsize);
|
||||
|
||||
static void TestSub(int32_t inputsize, int32_t outputsize);
|
||||
|
||||
static void TestSubWithValue(int32_t inputsize, int32_t outputsize);
|
||||
|
|
|
@ -9,6 +9,9 @@
|
|||
**********************************************************************/
|
||||
#include "citrtest.h"
|
||||
#include "unicode/schriter.h"
|
||||
#include "unicode/uchriter.h"
|
||||
#include "unicode/ustring.h"
|
||||
#include <string.h>
|
||||
|
||||
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");
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
**/
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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};
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue