mirror of
https://github.com/unicode-org/icu.git
synced 2025-04-08 06:53:45 +00:00
ICU-5787 1. Added test cases. 2. Fixed bug in == operator.
X-SVN-Rev: 22306
This commit is contained in:
parent
9991e6a097
commit
f6a2f2a082
2 changed files with 64 additions and 13 deletions
|
@ -34,9 +34,10 @@
|
|||
#include "uresimp.h"
|
||||
#include "dtptngen_impl.h"
|
||||
|
||||
#if defined U_DEBUG_DTPTN
|
||||
//TODO
|
||||
//#if defined U_DEBUG_DTPTN
|
||||
#include <stdio.h>
|
||||
#endif
|
||||
//#endif
|
||||
|
||||
#define LENGTHOF(array) (int32_t)(sizeof(array)/sizeof((array)[0]))
|
||||
|
||||
|
@ -738,6 +739,13 @@ DateTimePatternGenerator::getBestRaw(DateTimeMatcher& source,
|
|||
if (distance<bestDistance) {
|
||||
bestDistance=distance;
|
||||
bestPattern=patternMap->getPatternFromSkeleton(*trial.getSkeletonPtr());
|
||||
// TODO : remove printf if all test cases passed on AIX.
|
||||
/*
|
||||
printf("\n Distance:%x Best pattern:", bestDistance);
|
||||
for(int32_t i=0; i<bestPattern->length(); ++i) {
|
||||
printf("%c", bestPattern->charAt(i));
|
||||
}
|
||||
*/
|
||||
missingFields->setTo(tempInfo);
|
||||
if (distance==0) {
|
||||
break;
|
||||
|
@ -753,6 +761,13 @@ DateTimePatternGenerator::adjustFieldTypes(const UnicodeString& pattern,
|
|||
UBool fixFractionalSeconds) {
|
||||
UnicodeString newPattern;
|
||||
fp->set(pattern);
|
||||
// TODO : remove printf if all test cases passed on AIX.
|
||||
/*
|
||||
printf("\n Picked pattern:");
|
||||
for(int32_t i=0; i<pattern.length(); ++i) {
|
||||
printf("%c", pattern.charAt(i));
|
||||
}
|
||||
*/
|
||||
for (int32_t i=0; i < fp->itemNumber; i++) {
|
||||
UnicodeString field = fp->items[i];
|
||||
if ( fp->isQuoteLiteral(field) ) {
|
||||
|
@ -984,13 +999,14 @@ PatternMap::copyFrom(const PatternMap& other, UErrorCode& status) {
|
|||
PtnElem *curElem, *otherElem, *prevElem=NULL;
|
||||
otherElem = other.boot[bootIndex];
|
||||
while (otherElem!=NULL) {
|
||||
curElem = new PtnElem(otherElem->basePattern, otherElem->pattern);
|
||||
if ((this->boot[bootIndex]= curElem) == NULL ) {
|
||||
if ((curElem = new PtnElem(otherElem->basePattern, otherElem->pattern))==NULL) {
|
||||
// out of memory
|
||||
status = U_MEMORY_ALLOCATION_ERROR;
|
||||
return;
|
||||
}
|
||||
|
||||
if ( this->boot[bootIndex]== NULL ) {
|
||||
this->boot[bootIndex] = curElem;
|
||||
}
|
||||
if ((curElem->skeleton=new PtnSkeleton(*(otherElem->skeleton))) == NULL ) {
|
||||
// out of memory
|
||||
status = U_MEMORY_ALLOCATION_ERROR;
|
||||
|
|
|
@ -159,6 +159,14 @@ void IntlTestDateTimePatternGeneratorAPI::testAPI(/*char *par*/)
|
|||
if (decimalSymbol != newDecimalSymbol) {
|
||||
errln("ERROR: inconsistency is found in cloned object.");
|
||||
}
|
||||
if ( !(*cloneDTPatternGen == *instFromLocale) ) {
|
||||
errln("ERROR: inconsistency is found in cloned object.");
|
||||
}
|
||||
/*
|
||||
if ( *cloneDTPatternGen != *instFromLocale ) {
|
||||
errln("ERROR: inconsistency is found in cloned object.");
|
||||
}
|
||||
*/
|
||||
delete instFromLocale;
|
||||
delete cloneDTPatternGen;
|
||||
|
||||
|
@ -255,7 +263,36 @@ void IntlTestDateTimePatternGeneratorAPI::testAPI(/*char *par*/)
|
|||
if (newDateTimeFormat != gen->getDateTimeFormat()) {
|
||||
errln("ERROR: unexpected result from setDateTimeFormat() and getDateTimeFormat()!.\n");
|
||||
}
|
||||
|
||||
// ======== Test getSkeleton and getBaseSkeleton
|
||||
status = U_ZERO_ERROR;
|
||||
pattern = UnicodeString("dd-MMM");
|
||||
UnicodeString expectedSkeleton = UnicodeString("MMMdd");
|
||||
UnicodeString expectedBaseSkeleton = UnicodeString("MMMd");
|
||||
UnicodeString retSkeleton = gen->getSkeleton(pattern, status);
|
||||
if(U_FAILURE(status) || retSkeleton != expectedSkeleton ) {
|
||||
errln("ERROR: Unexpected result from getSkeleton().\n");
|
||||
errln(UnicodeString(" Got: ") + retSkeleton + UnicodeString(" Expected: ") + expectedSkeleton );
|
||||
}
|
||||
retSkeleton = gen->getBaseSkeleton(pattern, status);
|
||||
if(U_FAILURE(status) || retSkeleton != expectedBaseSkeleton) {
|
||||
errln("ERROR: Unexpected result from getBaseSkeleton().\n");
|
||||
errln(UnicodeString(" Got: ") + retSkeleton + UnicodeString(" Expected:")+ expectedBaseSkeleton);
|
||||
}
|
||||
|
||||
pattern = UnicodeString("dd/MMMM/yy");
|
||||
expectedSkeleton = UnicodeString("yyMMMMdd");
|
||||
expectedBaseSkeleton = UnicodeString("yMMMd");
|
||||
retSkeleton = gen->getSkeleton(pattern, status);
|
||||
if(U_FAILURE(status) || retSkeleton != expectedSkeleton ) {
|
||||
errln("ERROR: Unexpected result from getSkeleton().\n");
|
||||
errln(UnicodeString(" Got: ") + retSkeleton + UnicodeString(" Expected: ") + expectedSkeleton );
|
||||
}
|
||||
retSkeleton = gen->getBaseSkeleton(pattern, status);
|
||||
if(U_FAILURE(status) || retSkeleton != expectedBaseSkeleton) {
|
||||
errln("ERROR: Unexpected result from getBaseSkeleton().\n");
|
||||
errln(UnicodeString(" Got: ") + retSkeleton + UnicodeString(" Expected:")+ expectedBaseSkeleton);
|
||||
}
|
||||
delete format;
|
||||
delete zone;
|
||||
delete gen;
|
||||
|
@ -274,7 +311,8 @@ void IntlTestDateTimePatternGeneratorAPI::testAPI(/*char *par*/)
|
|||
UnicodeString bestPattern;
|
||||
|
||||
Locale loc(testLocale[localeIndex][0], testLocale[localeIndex][1], testLocale[localeIndex][2], "");
|
||||
//printf("\n\n Locale: %s_%s_%s", testLocale[localeIndex][0], testLocale[localeIndex][1], testLocale[localeIndex][2]);
|
||||
// TODO: Remove printf if all test cases passed on AIX.
|
||||
//dirprintf("\n\n Locale: %s_%s_%s", testLocale[localeIndex][0], testLocale[localeIndex][1], testLocale[localeIndex][2]);
|
||||
DateTimePatternGenerator *patGen=DateTimePatternGenerator::createInstance(loc, status);
|
||||
if(U_FAILURE(status)) {
|
||||
dataerrln("ERROR: Could not create DateTimePatternGenerator with locale index:%d . - exitting\n", localeIndex);
|
||||
|
@ -300,22 +338,19 @@ void IntlTestDateTimePatternGeneratorAPI::testAPI(/*char *par*/)
|
|||
|
||||
|
||||
// ======= Test random skeleton
|
||||
/*const char randomChars[80] = {
|
||||
'1','2','3','4','5','6','7','8','9','0','!','@','#','$','%','^','&','*','(',')',
|
||||
'`',' ','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r',
|
||||
's','t','u','v','w','x','y','z','A','B','C','D','F','G','H','I','J','K','L','M',
|
||||
'N','O','P','Q','R','S','T','U','V','W','X','Y','Z',':',';','<','.','?',';','\\'};*/
|
||||
DateTimePatternGenerator *randDTGen= DateTimePatternGenerator::createInstance(status);
|
||||
if (U_FAILURE(status)) {
|
||||
dataerrln("ERROR: Could not create DateTimePatternGenerator (Locale::getFrench()) - exitting");
|
||||
return;
|
||||
}
|
||||
|
||||
UChar newChar;
|
||||
for (int32_t i=0; i<10; ++i) {
|
||||
UnicodeString randomSkeleton="";
|
||||
int32_t len = rand() % 20;
|
||||
for (int32_t j=0; j<len; ++j ) {
|
||||
randomSkeleton += (UChar)(rand()%80);
|
||||
while ((newChar== (UChar)(rand()%0x7f))>=(UChar)0x20) {
|
||||
randomSkeleton += newChar;
|
||||
}
|
||||
}
|
||||
UnicodeString bestPattern = randDTGen->getBestPattern(randomSkeleton, status);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue