ICU-5445 Fix some compiler warnings.
X-SVN-Rev: 22008
This commit is contained in:
parent
0abc6413d3
commit
d1f7d0ed12
@ -1,7 +1,7 @@
|
||||
/*
|
||||
******************************************************************************
|
||||
* *
|
||||
* Copyright (C) 2001-2004, International Business Machines *
|
||||
* Copyright (C) 2001-2007, International Business Machines *
|
||||
* Corporation and others. All Rights Reserved. *
|
||||
* *
|
||||
******************************************************************************
|
||||
@ -50,7 +50,7 @@
|
||||
typedef enum ECleanupLibraryType {
|
||||
UCLN_START = -1,
|
||||
UCLN_CUSTOM, /* Custom is for anyone else. */
|
||||
UCLN_CTESTFW,
|
||||
UCLN_CTESTFW,
|
||||
UCLN_LAYOUTEX,
|
||||
UCLN_LAYOUT,
|
||||
UCLN_IO,
|
||||
|
@ -2278,7 +2278,7 @@ static void TestLocDataErrorCodeChaining(void) {
|
||||
UErrorCode ec = U_USELESS_COLLATOR_ERROR;
|
||||
ulocdata_open(NULL, &ec);
|
||||
ulocdata_getExemplarSet(NULL, NULL, 0, ULOCDATA_ES_STANDARD, &ec);
|
||||
ulocdata_getDelimiter(NULL, ULOCDATA_ES_STANDARD, NULL, -1, &ec);
|
||||
ulocdata_getDelimiter(NULL, ULOCDATA_DELIMITER_COUNT, NULL, -1, &ec);
|
||||
ulocdata_getMeasurementSystem(NULL, &ec);
|
||||
ulocdata_getPaperSize(NULL, NULL, NULL, &ec);
|
||||
if (ec != U_USELESS_COLLATOR_ERROR) {
|
||||
|
@ -2,15 +2,10 @@
|
||||
* COPYRIGHT:
|
||||
* Copyright (c) 1997-2007, International Business Machines Corporation and
|
||||
* others. All Rights Reserved.
|
||||
********************************************************************/
|
||||
|
||||
|
||||
/***********************************************************************
|
||||
***********************************************************************
|
||||
* Modification history
|
||||
* Date Name Description
|
||||
* 07/09/2007 srl Copied from dadrcoll.cpp
|
||||
* 02/14/2001 synwee Compare with cintltst and commented away tests
|
||||
* that are not run.
|
||||
***********************************************************************/
|
||||
|
||||
#include "unicode/utypes.h"
|
||||
@ -34,141 +29,141 @@
|
||||
/** ------- Calendar Fields Set -------- **/
|
||||
class CalendarFieldsSet {
|
||||
public:
|
||||
CalendarFieldsSet();
|
||||
~CalendarFieldsSet();
|
||||
|
||||
void clear();
|
||||
void clear(UCalendarDateFields field);
|
||||
void set(UCalendarDateFields field, int32_t amount);
|
||||
|
||||
UBool isSet(UCalendarDateFields field) const;
|
||||
int32_t get(UCalendarDateFields field) const;
|
||||
|
||||
/**
|
||||
* set the specified fields on this calendar. Doesn't clear first. Returns any errors the cale
|
||||
*/
|
||||
void setOnCalendar(Calendar *cal, UErrorCode& status) const;
|
||||
|
||||
/**
|
||||
* @param diffSet fillin to hold any fields different. Will have the calendar's value set on them.
|
||||
* @return true if the calendar matches in these fields
|
||||
*/
|
||||
UBool matches(Calendar *cal, CalendarFieldsSet &diffSet, UErrorCode& status) const;
|
||||
|
||||
|
||||
/**
|
||||
* @param "expected" set to match against
|
||||
* @return a formatted string listing which fields are set in
|
||||
* this, with the comparison made agaainst those fields in other.
|
||||
*/
|
||||
UnicodeString diffFrom(const CalendarFieldsSet& other) const;
|
||||
/**
|
||||
* parse from a string.
|
||||
* @param str the string to parse
|
||||
* @param inherit the CalendarFieldsSet to inherit any inherited items from, or NULL
|
||||
* @param status error code
|
||||
* @return the number of items successfully parsed
|
||||
*/
|
||||
int32_t parseFrom(const UnicodeString& str, CalendarFieldsSet* inheritFrom, UErrorCode& status);
|
||||
int32_t parseFrom(const UnicodeString& str, UErrorCode& status);
|
||||
|
||||
CalendarFieldsSet();
|
||||
~CalendarFieldsSet();
|
||||
|
||||
void clear();
|
||||
void clear(UCalendarDateFields field);
|
||||
void set(UCalendarDateFields field, int32_t amount);
|
||||
|
||||
UBool isSet(UCalendarDateFields field) const;
|
||||
int32_t get(UCalendarDateFields field) const;
|
||||
|
||||
/**
|
||||
* set the specified fields on this calendar. Doesn't clear first. Returns any errors the cale
|
||||
*/
|
||||
void setOnCalendar(Calendar *cal, UErrorCode& status) const;
|
||||
|
||||
/**
|
||||
* @param diffSet fillin to hold any fields different. Will have the calendar's value set on them.
|
||||
* @return true if the calendar matches in these fields
|
||||
*/
|
||||
UBool matches(Calendar *cal, CalendarFieldsSet &diffSet, UErrorCode& status) const;
|
||||
|
||||
|
||||
/**
|
||||
* @param "expected" set to match against
|
||||
* @return a formatted string listing which fields are set in
|
||||
* this, with the comparison made agaainst those fields in other.
|
||||
*/
|
||||
UnicodeString diffFrom(const CalendarFieldsSet& other) const;
|
||||
/**
|
||||
* parse from a string.
|
||||
* @param str the string to parse
|
||||
* @param inherit the CalendarFieldsSet to inherit any inherited items from, or NULL
|
||||
* @param status error code
|
||||
* @return the number of items successfully parsed
|
||||
*/
|
||||
int32_t parseFrom(const UnicodeString& str, CalendarFieldsSet* inheritFrom, UErrorCode& status);
|
||||
int32_t parseFrom(const UnicodeString& str, UErrorCode& status);
|
||||
|
||||
private:
|
||||
int32_t fValue[UDAT_FIELD_COUNT]; /** field values **/
|
||||
UBool fIsSet[UDAT_FIELD_COUNT]; /** Is this field set? **/
|
||||
int32_t fValue[UDAT_FIELD_COUNT]; /** field values **/
|
||||
UBool fIsSet[UDAT_FIELD_COUNT]; /** Is this field set? **/
|
||||
};
|
||||
|
||||
CalendarFieldsSet::CalendarFieldsSet() {
|
||||
clear();
|
||||
clear();
|
||||
}
|
||||
|
||||
CalendarFieldsSet::~CalendarFieldsSet() {
|
||||
//
|
||||
//
|
||||
}
|
||||
|
||||
void CalendarFieldsSet::clear() {
|
||||
for(int i=0;i<UDAT_FIELD_COUNT;i++) {
|
||||
fValue[i]=-1;
|
||||
fIsSet[i]=FALSE;
|
||||
}
|
||||
for(int i=0;i<UDAT_FIELD_COUNT;i++) {
|
||||
fValue[i]=-1;
|
||||
fIsSet[i]=FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
void CalendarFieldsSet::clear(UCalendarDateFields field) {
|
||||
if(field<0 || field>=UCAL_FIELD_COUNT) {
|
||||
return;
|
||||
}
|
||||
fValue[field] = -1;
|
||||
fIsSet[field] = FALSE;
|
||||
if(field<0 || field>=UCAL_FIELD_COUNT) {
|
||||
return;
|
||||
}
|
||||
fValue[field] = -1;
|
||||
fIsSet[field] = FALSE;
|
||||
}
|
||||
void CalendarFieldsSet::set(UCalendarDateFields field, int32_t amount) {
|
||||
if(field<0 || field>=UCAL_FIELD_COUNT) {
|
||||
return;
|
||||
}
|
||||
fValue[field] = amount;
|
||||
fIsSet[field] = TRUE;
|
||||
if(field<0 || field>=UCAL_FIELD_COUNT) {
|
||||
return;
|
||||
}
|
||||
fValue[field] = amount;
|
||||
fIsSet[field] = TRUE;
|
||||
}
|
||||
|
||||
UBool CalendarFieldsSet::isSet(UCalendarDateFields field) const {
|
||||
if(field<0 || field>=UCAL_FIELD_COUNT) {
|
||||
return FALSE;
|
||||
}
|
||||
return fIsSet[field];
|
||||
if(field<0 || field>=UCAL_FIELD_COUNT) {
|
||||
return FALSE;
|
||||
}
|
||||
return fIsSet[field];
|
||||
}
|
||||
int32_t CalendarFieldsSet::get(UCalendarDateFields field) const {
|
||||
if(field<0 || field>=UCAL_FIELD_COUNT) {
|
||||
return -1;
|
||||
}
|
||||
return fValue[field];
|
||||
if(field<0 || field>=UCAL_FIELD_COUNT) {
|
||||
return -1;
|
||||
}
|
||||
return fValue[field];
|
||||
}
|
||||
|
||||
/**
|
||||
* set the specified fields on this calendar. Doesn't clear first. Returns any errors the caller
|
||||
*/
|
||||
* set the specified fields on this calendar. Doesn't clear first. Returns any errors the caller
|
||||
*/
|
||||
void CalendarFieldsSet::setOnCalendar(Calendar *cal, UErrorCode& status) const {
|
||||
for(int i=0;i<UDAT_FIELD_COUNT;i++) {
|
||||
if(isSet((UCalendarDateFields)i)) {
|
||||
int32_t value = get((UCalendarDateFields)i);
|
||||
//fprintf(stderr, "Setting: %s#%d=%d\n",udbg_enumName(UDBG_UCalendarDateFields,i),i,value);
|
||||
cal->set((UCalendarDateFields)i,get((UCalendarDateFields)i));
|
||||
}
|
||||
}
|
||||
for(int i=0;i<UDAT_FIELD_COUNT;i++) {
|
||||
if(isSet((UCalendarDateFields)i)) {
|
||||
int32_t value = get((UCalendarDateFields)i);
|
||||
//fprintf(stderr, "Setting: %s#%d=%d\n",udbg_enumName(UDBG_UCalendarDateFields,i),i,value);
|
||||
cal->set((UCalendarDateFields)i,get((UCalendarDateFields)i));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* return true if the calendar matches in these fields
|
||||
*/
|
||||
UBool CalendarFieldsSet::matches(Calendar *cal, CalendarFieldsSet &diffSet, UErrorCode& status) const {
|
||||
UBool match = TRUE;
|
||||
if(U_FAILURE(status)) return FALSE;
|
||||
for(int i=0;i<UDAT_FIELD_COUNT;i++) {
|
||||
if(isSet((UCalendarDateFields)i)) {
|
||||
int32_t calVal = cal->get((UCalendarDateFields)i,status);
|
||||
if(U_FAILURE(status)) return FALSE;
|
||||
if(calVal != get((UCalendarDateFields)i)) {
|
||||
match = FALSE;
|
||||
diffSet.set((UCalendarDateFields)i,calVal);
|
||||
//fprintf(stderr, "match failed: %s#%d=%d != %d\n",udbg_enumName(UDBG_UCalendarDateFields,i),i,cal->get((UCalendarDateFields)i,status), get((UCalendarDateFields)i));;
|
||||
}
|
||||
}
|
||||
}
|
||||
return match;
|
||||
UBool match = TRUE;
|
||||
if(U_FAILURE(status)) return FALSE;
|
||||
for(int i=0;i<UDAT_FIELD_COUNT;i++) {
|
||||
if(isSet((UCalendarDateFields)i)) {
|
||||
int32_t calVal = cal->get((UCalendarDateFields)i,status);
|
||||
if(U_FAILURE(status)) return FALSE;
|
||||
if(calVal != get((UCalendarDateFields)i)) {
|
||||
match = FALSE;
|
||||
diffSet.set((UCalendarDateFields)i,calVal);
|
||||
//fprintf(stderr, "match failed: %s#%d=%d != %d\n",udbg_enumName(UDBG_UCalendarDateFields,i),i,cal->get((UCalendarDateFields)i,status), get((UCalendarDateFields)i));;
|
||||
}
|
||||
}
|
||||
}
|
||||
return match;
|
||||
}
|
||||
|
||||
UnicodeString CalendarFieldsSet::diffFrom(const CalendarFieldsSet& other) const {
|
||||
UnicodeString str;
|
||||
for(int i=0;i<UDAT_FIELD_COUNT;i++) {
|
||||
if(isSet((UCalendarDateFields)i)) {
|
||||
int32_t myVal = get((UCalendarDateFields)i);
|
||||
int32_t theirVal = other.get((UCalendarDateFields)i);
|
||||
const UnicodeString& fieldName = udbg_enumString(UDBG_UCalendarDateFields,i);
|
||||
|
||||
str = str + fieldName +"="+myVal+" not "+theirVal+", ";
|
||||
}
|
||||
}
|
||||
return str;
|
||||
UnicodeString str;
|
||||
for(int i=0;i<UDAT_FIELD_COUNT;i++) {
|
||||
if(isSet((UCalendarDateFields)i)) {
|
||||
int32_t myVal = get((UCalendarDateFields)i);
|
||||
int32_t theirVal = other.get((UCalendarDateFields)i);
|
||||
const UnicodeString& fieldName = udbg_enumString(UDBG_UCalendarDateFields,i);
|
||||
|
||||
str = str + fieldName +"="+myVal+" not "+theirVal+", ";
|
||||
}
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
int32_t CalendarFieldsSet::parseFrom(const UnicodeString& str, UErrorCode& status) {
|
||||
return parseFrom(str, NULL, status);
|
||||
return parseFrom(str, NULL, status);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -179,110 +174,104 @@ int32_t CalendarFieldsSet::parseFrom(const UnicodeString& str, UErrorCode& statu
|
||||
* @return the number of items successfully parsed or -1 on error
|
||||
*/
|
||||
int32_t CalendarFieldsSet::parseFrom(const UnicodeString& str, CalendarFieldsSet* inheritFrom, UErrorCode& status) {
|
||||
UnicodeString pattern(",","");
|
||||
RegexMatcher matcher(pattern,0,status);
|
||||
UnicodeString pattern2("=","");
|
||||
RegexMatcher matcher2(pattern2,0,status);
|
||||
if(U_FAILURE(status)) return -1;
|
||||
|
||||
UnicodeString dest[UDAT_FIELD_COUNT+10];
|
||||
int32_t destCount = matcher.split(str,dest,sizeof(dest)/sizeof(dest[0]), status);
|
||||
if(U_FAILURE(status)) return -1;
|
||||
for(int i=0;i<destCount;i++) {
|
||||
UnicodeString kv[2];
|
||||
int32_t kvCount = matcher2.split(dest[i],kv,2,status);
|
||||
if(U_FAILURE(status)) return -1;
|
||||
|
||||
int32_t field = udbg_enumByString(UDBG_UCalendarDateFields, kv[0]);
|
||||
|
||||
if(field == -1) {
|
||||
char ch[256];
|
||||
const UChar *u = kv[0].getBuffer();
|
||||
int32_t len = kv[0].length();
|
||||
u_UCharsToChars(u, ch, len);
|
||||
ch[len] = 0; /* include terminating \0 */
|
||||
fprintf(stderr,"Parse Failed: Unknown Field %s\n", ch);
|
||||
status = U_ILLEGAL_ARGUMENT_ERROR;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int value = -1;
|
||||
|
||||
if(kv[1].length()==0) {
|
||||
// inherit
|
||||
if((inheritFrom == NULL) || !inheritFrom->isSet((UCalendarDateFields)field)) {
|
||||
// couldn't inherit from field
|
||||
fprintf(stderr,"Parse Failed: Couldn't inherit field %d [%s]\n", field, udbg_enumName(UDBG_UCalendarDateFields, field));
|
||||
status = U_ILLEGAL_ARGUMENT_ERROR;
|
||||
return -1;
|
||||
}
|
||||
value = inheritFrom->get((UCalendarDateFields)field);
|
||||
} else {
|
||||
if(field==UCAL_MONTH) {
|
||||
value = udbg_enumByString(UDBG_UCalendarMonths, kv[1]);
|
||||
} // else, other types..
|
||||
if(value==-1) {
|
||||
// parse as decimal
|
||||
value = udbg_stoi(kv[1]);
|
||||
}
|
||||
}
|
||||
//fprintf(stderr, "Parsed: %s#%d=%d\n",udbg_enumName(UDBG_UCalendarDateFields,field),field,value);
|
||||
set((UCalendarDateFields)field,value);
|
||||
}
|
||||
|
||||
return -1;
|
||||
UnicodeString pattern(",","");
|
||||
RegexMatcher matcher(pattern,0,status);
|
||||
UnicodeString pattern2("=","");
|
||||
RegexMatcher matcher2(pattern2,0,status);
|
||||
if(U_FAILURE(status)) return -1;
|
||||
|
||||
UnicodeString dest[UDAT_FIELD_COUNT+10];
|
||||
int32_t destCount = matcher.split(str,dest,sizeof(dest)/sizeof(dest[0]), status);
|
||||
if(U_FAILURE(status)) return -1;
|
||||
for(int i=0;i<destCount;i++) {
|
||||
UnicodeString kv[2];
|
||||
int32_t kvCount = matcher2.split(dest[i],kv,2,status);
|
||||
if(U_FAILURE(status)) return -1;
|
||||
|
||||
int32_t field = udbg_enumByString(UDBG_UCalendarDateFields, kv[0]);
|
||||
|
||||
if(field == -1) {
|
||||
char ch[256];
|
||||
const UChar *u = kv[0].getBuffer();
|
||||
int32_t len = kv[0].length();
|
||||
u_UCharsToChars(u, ch, len);
|
||||
ch[len] = 0; /* include terminating \0 */
|
||||
fprintf(stderr,"Parse Failed: Unknown Field %s\n", ch);
|
||||
status = U_ILLEGAL_ARGUMENT_ERROR;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int value = -1;
|
||||
|
||||
if(kv[1].length()==0) {
|
||||
// inherit
|
||||
if((inheritFrom == NULL) || !inheritFrom->isSet((UCalendarDateFields)field)) {
|
||||
// couldn't inherit from field
|
||||
fprintf(stderr,"Parse Failed: Couldn't inherit field %d [%s]\n", field, udbg_enumName(UDBG_UCalendarDateFields, field));
|
||||
status = U_ILLEGAL_ARGUMENT_ERROR;
|
||||
return -1;
|
||||
}
|
||||
value = inheritFrom->get((UCalendarDateFields)field);
|
||||
} else {
|
||||
if(field==UCAL_MONTH) {
|
||||
value = udbg_enumByString(UDBG_UCalendarMonths, kv[1]);
|
||||
} // else, other types..
|
||||
if(value==-1) {
|
||||
// parse as decimal
|
||||
value = udbg_stoi(kv[1]);
|
||||
}
|
||||
}
|
||||
//fprintf(stderr, "Parsed: %s#%d=%d\n",udbg_enumName(UDBG_UCalendarDateFields,field),field,value);
|
||||
set((UCalendarDateFields)field,value);
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
DataDrivenCalendarTest::DataDrivenCalendarTest()
|
||||
: // seq(StringCharacterIterator("")),
|
||||
status(U_ZERO_ERROR)
|
||||
//sequences(status)
|
||||
//: status(U_ZERO_ERROR)
|
||||
{
|
||||
driver = TestDataModule::getTestDataModule("calendar", *this, status);
|
||||
//sequences.setDeleter(deleteSeqElement);
|
||||
//UCA = (RuleBasedCalendar*)Calendar::createInstance("root", status);
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
driver = TestDataModule::getTestDataModule("calendar", *this, status);
|
||||
}
|
||||
|
||||
DataDrivenCalendarTest::~DataDrivenCalendarTest()
|
||||
{
|
||||
delete driver;
|
||||
//delete UCA;
|
||||
delete driver;
|
||||
}
|
||||
|
||||
void DataDrivenCalendarTest::runIndexedTest( int32_t index, UBool exec, const char* &name, char* /*par */)
|
||||
{
|
||||
if(driver != NULL) {
|
||||
if (exec)
|
||||
{
|
||||
// logln("Begin ");
|
||||
}
|
||||
const DataMap *info = NULL;
|
||||
TestData *testData = driver->createTestData(index, status);
|
||||
if(U_SUCCESS(status)) {
|
||||
name = testData->getName();
|
||||
if(testData->getInfo(info, status)) {
|
||||
log(info->getString("Description", status));
|
||||
}
|
||||
if(exec) {
|
||||
log(name);
|
||||
logln("---");
|
||||
logln("");
|
||||
|
||||
|
||||
processTest(testData);
|
||||
}
|
||||
delete testData;
|
||||
if(driver != NULL) {
|
||||
if (exec)
|
||||
{
|
||||
// logln("Begin ");
|
||||
}
|
||||
const DataMap *info = NULL;
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
TestData *testData = driver->createTestData(index, status);
|
||||
if(U_SUCCESS(status)) {
|
||||
name = testData->getName();
|
||||
if(testData->getInfo(info, status)) {
|
||||
log(info->getString("Description", status));
|
||||
}
|
||||
if(exec) {
|
||||
log(name);
|
||||
logln("---");
|
||||
logln("");
|
||||
|
||||
processTest(testData, status);
|
||||
}
|
||||
delete testData;
|
||||
} else {
|
||||
name = "";
|
||||
}
|
||||
} else {
|
||||
name = "";
|
||||
errln("format/DataDrivenTest data (calendar.res) not initialized!");
|
||||
name = "";
|
||||
}
|
||||
} else {
|
||||
errln("format/DataDrivenTest data (calendar.res) not initialized!");
|
||||
name = "";
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
// Reads the options string and sets appropriate attributes in Calendar
|
||||
@ -291,193 +280,196 @@ DataDrivenCalendarTest::processArguments(Calendar *col, const UChar *start, int3
|
||||
}
|
||||
|
||||
void DataDrivenCalendarTest::testConvert(int32_t n, const CalendarFieldsSet &fromSet, Calendar *fromCalendar,
|
||||
const CalendarFieldsSet &toSet, Calendar *toCalendar, UBool forward) {
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
UnicodeString thisString = (UnicodeString)"#"+n+" "+(forward?"forward":"reverse")+" "+fromCalendar->getType()+"->"+
|
||||
toCalendar->getType();
|
||||
|
||||
const CalendarFieldsSet &toSet, Calendar *toCalendar, UBool forward)
|
||||
{
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
UnicodeString thisString = (UnicodeString)"#"+n+" "+(forward?"forward":"reverse")+" "+fromCalendar->getType()+"->"+
|
||||
toCalendar->getType();
|
||||
|
||||
fromCalendar->clear();
|
||||
|
||||
|
||||
fromSet.setOnCalendar(fromCalendar,status);
|
||||
if(U_FAILURE(status)) {
|
||||
errln("FAIL: Failed to set on Source calendar: %s", u_errorName(status));
|
||||
return;
|
||||
errln("FAIL: Failed to set on Source calendar: %s", u_errorName(status));
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
CalendarFieldsSet diffSet;
|
||||
|
||||
|
||||
// turn this on to test that the calendar was set as expected. Normally not needed.
|
||||
#if 0
|
||||
diffSet.clear();
|
||||
// Is the calendar sane at the first?
|
||||
if(!fromSet.matches(fromCalendar, diffSet, status)) {
|
||||
UnicodeString diffs = diffSet.diffFrom(fromSet);
|
||||
errln((UnicodeString)"FAIL: "+thisString+", SOURCE calendar was not set: Differences: " + diffs +"', status: " + u_errorName(status));
|
||||
UnicodeString diffs = diffSet.diffFrom(fromSet);
|
||||
errln((UnicodeString)"FAIL: "+thisString+", SOURCE calendar was not set: Differences: " + diffs +"', status: " + u_errorName(status));
|
||||
} else if(U_FAILURE(status)) {
|
||||
errln("FAIL: "+thisString+" SOURCE calendar Failed to match: "+u_errorName(status));
|
||||
errln("FAIL: "+thisString+" SOURCE calendar Failed to match: "+u_errorName(status));
|
||||
} else {
|
||||
logln("PASS: "+thisString+" SOURCE calendar match.");
|
||||
logln("PASS: "+thisString+" SOURCE calendar match.");
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
//logln("Set Source calendar: " + from);
|
||||
|
||||
|
||||
UDate fromTime = fromCalendar->getTime(status);
|
||||
if(U_FAILURE(status)) {
|
||||
errln("FAIL: Failed to get Source time: %s", u_errorName(status));
|
||||
return;
|
||||
errln("FAIL: Failed to get Source time: %s", u_errorName(status));
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// turn this on to test that the calendar completed as expected. Normally not needed.
|
||||
#if 0
|
||||
diffSet.clear();
|
||||
// Is the calendar sane after being set?
|
||||
if(!fromSet.matches(fromCalendar, diffSet, status)) {
|
||||
UnicodeString diffs = diffSet.diffFrom(fromSet);
|
||||
errln((UnicodeString)"FAIL: "+thisString+", SET SOURCE calendar was not set: Differences: " + diffs +"', status: " + u_errorName(status));
|
||||
UnicodeString diffs = diffSet.diffFrom(fromSet);
|
||||
errln((UnicodeString)"FAIL: "+thisString+", SET SOURCE calendar was not set: Differences: " + diffs +"', status: " + u_errorName(status));
|
||||
} else if(U_FAILURE(status)) {
|
||||
errln("FAIL: "+thisString+" SET SOURCE calendar Failed to match: "+u_errorName(status));
|
||||
errln("FAIL: "+thisString+" SET SOURCE calendar Failed to match: "+u_errorName(status));
|
||||
} else {
|
||||
logln("PASS: "+thisString+" SET SOURCE calendar match.");
|
||||
logln("PASS: "+thisString+" SET SOURCE calendar match.");
|
||||
}
|
||||
#endif
|
||||
toCalendar->clear();
|
||||
toCalendar->setTime(fromTime, status);
|
||||
if(U_FAILURE(status)) {
|
||||
errln("FAIL: Failed to set Target time: %s", u_errorName(status));
|
||||
return;
|
||||
errln("FAIL: Failed to set Target time: %s", u_errorName(status));
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
diffSet.clear();
|
||||
if(!toSet.matches(toCalendar, diffSet, status)) {
|
||||
UnicodeString diffs = diffSet.diffFrom(toSet);
|
||||
errln((UnicodeString)"FAIL: "+thisString+", Differences: " + diffs +"', status: " + u_errorName(status));
|
||||
SimpleDateFormat fmt(UnicodeString("EEE MMM dd yyyy G"), status);
|
||||
UnicodeString fromString;
|
||||
fmt.format(fromTime,fromString);
|
||||
logln("Source Time: "+fromString+", Source Calendar: "+fromCalendar->getType());
|
||||
UnicodeString diffs = diffSet.diffFrom(toSet);
|
||||
errln((UnicodeString)"FAIL: "+thisString+", Differences: " + diffs +"', status: " + u_errorName(status));
|
||||
SimpleDateFormat fmt(UnicodeString("EEE MMM dd yyyy G"), status);
|
||||
UnicodeString fromString;
|
||||
fmt.format(fromTime,fromString);
|
||||
logln("Source Time: "+fromString+", Source Calendar: "+fromCalendar->getType());
|
||||
} else if(U_FAILURE(status)) {
|
||||
errln("FAIL: "+thisString+" Failed to match: "+u_errorName(status));
|
||||
errln("FAIL: "+thisString+" Failed to match: "+u_errorName(status));
|
||||
} else {
|
||||
logln("PASS: "+thisString+" match.");
|
||||
logln("PASS: "+thisString+" match.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void DataDrivenCalendarTest::testConvert(TestData *testData, const DataMap *settings, UBool forward) {
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
Calendar *toCalendar = NULL;
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
Calendar *toCalendar = NULL;
|
||||
const DataMap *currentCase = NULL;
|
||||
char toCalLoc[256] = "";
|
||||
char fromCalLoc[256] = "";
|
||||
// build to calendar
|
||||
UnicodeString testSetting = settings->getString("ToCalendar", status);
|
||||
// build to calendar
|
||||
UnicodeString testSetting = settings->getString("ToCalendar", status);
|
||||
if(U_SUCCESS(status)) {
|
||||
testSetting.extract(0, testSetting.length(), toCalLoc, (const char*)0);
|
||||
toCalendar = Calendar::createInstance(toCalLoc, status);
|
||||
if(U_FAILURE(status)) {
|
||||
errln("Unable to instantiate ToCalendar for "+testSetting);
|
||||
return;
|
||||
}
|
||||
testSetting.extract(0, testSetting.length(), toCalLoc, (const char*)0);
|
||||
toCalendar = Calendar::createInstance(toCalLoc, status);
|
||||
if(U_FAILURE(status)) {
|
||||
errln("Unable to instantiate ToCalendar for "+testSetting);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
CalendarFieldsSet fromSet, toSet, diffSet;
|
||||
SimpleDateFormat fmt(UnicodeString("EEE MMM dd yyyy / YYYY'-W'ww-ee"), status);
|
||||
if(U_FAILURE(status)) {
|
||||
errln("FAIL: Couldn't create SimpleDateFormat: %s\n", u_errorName(status));
|
||||
return;
|
||||
errln("FAIL: Couldn't create SimpleDateFormat: %s\n", u_errorName(status));
|
||||
return;
|
||||
}
|
||||
// Start the processing
|
||||
int n = 0;
|
||||
while(testData->nextCase(currentCase, status)) {
|
||||
++n;
|
||||
Calendar *fromCalendar = NULL;
|
||||
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);
|
||||
if(U_FAILURE(status)) {
|
||||
errln("Unable to instantiate fromCalendar for "+locale);
|
||||
return;
|
||||
++n;
|
||||
Calendar *fromCalendar = NULL;
|
||||
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);
|
||||
if(U_FAILURE(status)) {
|
||||
errln("Unable to instantiate fromCalendar for "+locale);
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
errln("No 'locale' line.");
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
errln("No 'locale' line.");
|
||||
continue;
|
||||
}
|
||||
|
||||
fromSet.clear();
|
||||
toSet.clear();
|
||||
|
||||
UnicodeString from = currentCase->getString("from", status);
|
||||
if(U_FAILURE(status)) {
|
||||
errln("No 'from' line.");
|
||||
continue;
|
||||
}
|
||||
fromSet.parseFrom(from, status);
|
||||
if(U_FAILURE(status)) {
|
||||
errln("Failed to parse 'from' parameter: "+from);
|
||||
continue;
|
||||
}
|
||||
UnicodeString to = currentCase->getString("to", status);
|
||||
if(U_FAILURE(status)) {
|
||||
errln("No 'to' line.");
|
||||
continue;
|
||||
}
|
||||
toSet.parseFrom(to, &fromSet, status);
|
||||
if(U_FAILURE(status)) {
|
||||
errln("Failed to parse 'to' parameter: "+to);
|
||||
continue;
|
||||
}
|
||||
|
||||
// now, do it.
|
||||
if(forward) {
|
||||
logln((UnicodeString)"#"+n+" "+locale+"/"+from+" >>> "+toCalLoc+"/"+to);
|
||||
testConvert(n, fromSet, fromCalendar, toSet, toCalendar, forward);
|
||||
} else {
|
||||
logln((UnicodeString)"#"+n+" "+locale+"/"+from+" <<< "+toCalLoc+"/"+to);
|
||||
testConvert(n, toSet, toCalendar, fromSet, fromCalendar, forward);
|
||||
}
|
||||
|
||||
delete fromCalendar;
|
||||
|
||||
fromSet.clear();
|
||||
toSet.clear();
|
||||
|
||||
UnicodeString from = currentCase->getString("from", status);
|
||||
if(U_FAILURE(status)) {
|
||||
errln("No 'from' line.");
|
||||
continue;
|
||||
}
|
||||
fromSet.parseFrom(from, status);
|
||||
if(U_FAILURE(status)) {
|
||||
errln("Failed to parse 'from' parameter: "+from);
|
||||
continue;
|
||||
}
|
||||
UnicodeString to = currentCase->getString("to", status);
|
||||
if(U_FAILURE(status)) {
|
||||
errln("No 'to' line.");
|
||||
continue;
|
||||
}
|
||||
toSet.parseFrom(to, &fromSet, status);
|
||||
if(U_FAILURE(status)) {
|
||||
errln("Failed to parse 'to' parameter: "+to);
|
||||
continue;
|
||||
}
|
||||
|
||||
// now, do it.
|
||||
if(forward) {
|
||||
logln((UnicodeString)"#"+n+" "+locale+"/"+from+" >>> "+toCalLoc+"/"+to);
|
||||
testConvert(n, fromSet, fromCalendar, toSet, toCalendar, forward);
|
||||
} else {
|
||||
logln((UnicodeString)"#"+n+" "+locale+"/"+from+" <<< "+toCalLoc+"/"+to);
|
||||
testConvert(n, toSet, toCalendar, fromSet, fromCalendar, forward);
|
||||
}
|
||||
|
||||
delete fromCalendar;
|
||||
}
|
||||
delete toCalendar;
|
||||
}
|
||||
|
||||
void
|
||||
DataDrivenCalendarTest::processTest(TestData *testData) {
|
||||
Calendar *cal = NULL;
|
||||
const UChar *arguments = NULL;
|
||||
int32_t argLen = 0;
|
||||
char testType[256];
|
||||
const DataMap *settings = NULL;
|
||||
const UChar *type = NULL;
|
||||
UErrorCode intStatus = U_ZERO_ERROR;
|
||||
UnicodeString testSetting;
|
||||
int n = 0;
|
||||
while(testData->nextSettings(settings, status)) {
|
||||
intStatus = U_ZERO_ERROR;
|
||||
// try to get a locale
|
||||
testSetting = settings->getString("Type", intStatus);
|
||||
if(U_SUCCESS(intStatus)) {
|
||||
if((++n)>0) {
|
||||
logln("---");
|
||||
}
|
||||
logln(testSetting + "---");
|
||||
testSetting.extract(0, testSetting.length(), testType, "");
|
||||
} else {
|
||||
errln("Unable to extract 'Type'. Skipping..");
|
||||
continue;
|
||||
DataDrivenCalendarTest::processTest(TestData *testData, UErrorCode status) {
|
||||
Calendar *cal = NULL;
|
||||
const UChar *arguments = NULL;
|
||||
int32_t argLen = 0;
|
||||
char testType[256];
|
||||
const DataMap *settings = NULL;
|
||||
const UChar *type = NULL;
|
||||
UnicodeString testSetting;
|
||||
int n = 0;
|
||||
while(testData->nextSettings(settings, status)) {
|
||||
status = U_ZERO_ERROR;
|
||||
// try to get a locale
|
||||
testSetting = settings->getString("Type", status);
|
||||
if(U_SUCCESS(status)) {
|
||||
if((++n)>0) {
|
||||
logln("---");
|
||||
}
|
||||
logln(testSetting + "---");
|
||||
testSetting.extract(0, testSetting.length(), testType, "");
|
||||
} else {
|
||||
errln("Unable to extract 'Type'. Skipping..");
|
||||
continue;
|
||||
}
|
||||
|
||||
if(!strcmp(testType,"convert_fwd")) {
|
||||
testConvert(testData, settings, true);
|
||||
} else if(!strcmp(testType,"convert_rev")) {
|
||||
testConvert(testData, settings, false);
|
||||
} else {
|
||||
errln("Unknown type: %s", testType);
|
||||
}
|
||||
}
|
||||
|
||||
if(!strcmp(testType,"convert_fwd")) {
|
||||
testConvert(testData, settings, true);
|
||||
} else if(!strcmp(testType,"convert_rev")) {
|
||||
testConvert(testData, settings, false);
|
||||
} else {
|
||||
errln("Unknown type: %s", testType);
|
||||
if (U_FAILURE(status)) {
|
||||
errln("Failure: %s", u_errorName(status));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -36,19 +36,16 @@ protected:
|
||||
|
||||
void DataDrivenTest(char *par);
|
||||
void processSequence(Calendar* cal, const UnicodeString &sequence);
|
||||
void processTest(TestData *testData);
|
||||
void processTest(TestData *testData, UErrorCode status);
|
||||
void processArguments(Calendar *cal, const UChar *start, int32_t optLen);
|
||||
private:
|
||||
void testConvert(TestData *testData, const DataMap *settings, UBool fwd);
|
||||
void testConvert(int32_t n, const CalendarFieldsSet &fromSet, Calendar *fromCal,
|
||||
const CalendarFieldsSet &toSet, Calendar *toCal, UBool fwd);
|
||||
const CalendarFieldsSet &toSet, Calendar *toCal, UBool fwd);
|
||||
private:
|
||||
TestDataModule *driver;
|
||||
UErrorCode status;
|
||||
TestDataModule *driver;
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif /* #if !UCONFIG_NO_COLLATION */
|
||||
|
||||
#endif
|
||||
|
@ -1,120 +1,122 @@
|
||||
/********************************************************************
|
||||
* COPYRIGHT:
|
||||
* Copyright (c) 2007, International Business Machines Corporation and
|
||||
* others. All Rights Reserved.
|
||||
********************************************************************/
|
||||
|
||||
#include "unicode/udbgutil.h"
|
||||
#include "unicode/dbgutil.h"
|
||||
|
||||
#if !UCONFIG_NO_FORMATTING
|
||||
|
||||
#include "unicode/unistr.h"
|
||||
#include "unicode/ustring.h"
|
||||
#include "ucln.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
UnicodeString **strs = NULL;
|
||||
|
||||
static const UnicodeString& _fieldString(UDebugEnumType type, int32_t field, UnicodeString& fillin) {
|
||||
const char *str = udbg_enumName(type, field);
|
||||
if(str == NULL) {
|
||||
return fillin.remove();
|
||||
} else {
|
||||
return fillin = UnicodeString(str, ""); // optimize?
|
||||
}
|
||||
}
|
||||
|
||||
static void udbg_cleanup(void) {
|
||||
if(strs != NULL) {
|
||||
for(int t=0;t<=UDBG_ENUM_COUNT;t++) {
|
||||
delete [] strs[t];
|
||||
}
|
||||
delete[] strs;
|
||||
strs = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/********************************************************************
|
||||
* COPYRIGHT:
|
||||
* Copyright (c) 2007, International Business Machines Corporation and
|
||||
* others. All Rights Reserved.
|
||||
********************************************************************/
|
||||
|
||||
#include "unicode/udbgutil.h"
|
||||
#include "unicode/dbgutil.h"
|
||||
|
||||
#if !UCONFIG_NO_FORMATTING
|
||||
|
||||
#include "unicode/unistr.h"
|
||||
#include "unicode/ustring.h"
|
||||
#include "ucln.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
UnicodeString **strs = NULL;
|
||||
|
||||
static const UnicodeString& _fieldString(UDebugEnumType type, int32_t field, UnicodeString& fillin) {
|
||||
const char *str = udbg_enumName(type, field);
|
||||
if(str == NULL) {
|
||||
return fillin.remove();
|
||||
} else {
|
||||
return fillin = UnicodeString(str, ""); // optimize?
|
||||
}
|
||||
}
|
||||
|
||||
U_CDECL_BEGIN
|
||||
static void udbg_cleanup(void) {
|
||||
if(strs != NULL) {
|
||||
for(int t=0;t<=UDBG_ENUM_COUNT;t++) {
|
||||
delete [] strs[t];
|
||||
}
|
||||
delete[] strs;
|
||||
strs = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static UBool ctestfw_cleanup(void)
|
||||
{
|
||||
udbg_cleanup();
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void udbg_register_cleanup(void) {
|
||||
ucln_registerCleanup(UCLN_CTESTFW, ctestfw_cleanup);
|
||||
}
|
||||
|
||||
static void udbg_setup(void) {
|
||||
if(strs == NULL) {
|
||||
udbg_register_cleanup();
|
||||
//fprintf(stderr,"Initializing string cache..\n");
|
||||
//fflush(stderr);
|
||||
UnicodeString **newStrs = new UnicodeString*[UDBG_ENUM_COUNT+1];
|
||||
for(int t=0;t<UDBG_ENUM_COUNT;t++) {
|
||||
int32_t c = udbg_enumCount((UDebugEnumType)t);
|
||||
newStrs[t] = new UnicodeString[c+1];
|
||||
for(int f=0;f<=c;f++) {
|
||||
_fieldString((UDebugEnumType)t, f, newStrs[t][f]);
|
||||
}
|
||||
}
|
||||
newStrs[UDBG_ENUM_COUNT] = new UnicodeString[1]; // empty string
|
||||
|
||||
strs = newStrs;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
T_CTEST_API const UnicodeString& T_CTEST_EXPORT2 udbg_enumString(UDebugEnumType type, int32_t field) {
|
||||
if(strs == NULL ) {
|
||||
udbg_setup();
|
||||
}
|
||||
if(type<0||type>=UDBG_ENUM_COUNT) {
|
||||
// use UDBG_ENUM_COUNT,0 to mean an empty string
|
||||
//fprintf(stderr, "** returning out of range on %d\n",type);
|
||||
//fflush(stderr);
|
||||
return strs[UDBG_ENUM_COUNT][0];
|
||||
}
|
||||
int32_t count = udbg_enumCount(type);
|
||||
//fprintf(stderr, "enumString [%d,%d]: typecount %d, fieldcount %d\n", type,field,UDBG_ENUM_COUNT,count);
|
||||
//fflush(stderr);
|
||||
if(field<0 || field > count) {
|
||||
return strs[type][count];
|
||||
} else {
|
||||
return strs[type][field];
|
||||
}
|
||||
}
|
||||
|
||||
T_CTEST_API int32_t T_CTEST_EXPORT2 udbg_enumByString(UDebugEnumType type, const UnicodeString& string) {
|
||||
if(type<0||type>=UDBG_ENUM_COUNT) {
|
||||
return -1;
|
||||
}
|
||||
// initialize array
|
||||
udbg_enumString(type,0);
|
||||
// search
|
||||
for(int i=0;i<udbg_enumCount(type);i++) {
|
||||
if(string == (strs[type][i])) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
// from DataMap::utoi
|
||||
T_CTEST_API int32_t
|
||||
udbg_stoi(const UnicodeString &s)
|
||||
{
|
||||
char ch[256];
|
||||
const UChar *u = s.getBuffer();
|
||||
int32_t len = s.length();
|
||||
u_UCharsToChars(u, ch, len);
|
||||
ch[len] = 0; /* include terminating \0 */
|
||||
return atoi(ch);
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
static void udbg_register_cleanup(void) {
|
||||
ucln_registerCleanup(UCLN_CTESTFW, ctestfw_cleanup);
|
||||
}
|
||||
U_CDECL_END
|
||||
|
||||
static void udbg_setup(void) {
|
||||
if(strs == NULL) {
|
||||
udbg_register_cleanup();
|
||||
//fprintf(stderr,"Initializing string cache..\n");
|
||||
//fflush(stderr);
|
||||
UnicodeString **newStrs = new UnicodeString*[UDBG_ENUM_COUNT+1];
|
||||
for(int t=0;t<UDBG_ENUM_COUNT;t++) {
|
||||
int32_t c = udbg_enumCount((UDebugEnumType)t);
|
||||
newStrs[t] = new UnicodeString[c+1];
|
||||
for(int f=0;f<=c;f++) {
|
||||
_fieldString((UDebugEnumType)t, f, newStrs[t][f]);
|
||||
}
|
||||
}
|
||||
newStrs[UDBG_ENUM_COUNT] = new UnicodeString[1]; // empty string
|
||||
|
||||
strs = newStrs;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
T_CTEST_API const UnicodeString& T_CTEST_EXPORT2 udbg_enumString(UDebugEnumType type, int32_t field) {
|
||||
if(strs == NULL ) {
|
||||
udbg_setup();
|
||||
}
|
||||
if(type<0||type>=UDBG_ENUM_COUNT) {
|
||||
// use UDBG_ENUM_COUNT,0 to mean an empty string
|
||||
//fprintf(stderr, "** returning out of range on %d\n",type);
|
||||
//fflush(stderr);
|
||||
return strs[UDBG_ENUM_COUNT][0];
|
||||
}
|
||||
int32_t count = udbg_enumCount(type);
|
||||
//fprintf(stderr, "enumString [%d,%d]: typecount %d, fieldcount %d\n", type,field,UDBG_ENUM_COUNT,count);
|
||||
//fflush(stderr);
|
||||
if(field<0 || field > count) {
|
||||
return strs[type][count];
|
||||
} else {
|
||||
return strs[type][field];
|
||||
}
|
||||
}
|
||||
|
||||
T_CTEST_API int32_t T_CTEST_EXPORT2 udbg_enumByString(UDebugEnumType type, const UnicodeString& string) {
|
||||
if(type<0||type>=UDBG_ENUM_COUNT) {
|
||||
return -1;
|
||||
}
|
||||
// initialize array
|
||||
udbg_enumString(type,0);
|
||||
// search
|
||||
for(int i=0;i<udbg_enumCount(type);i++) {
|
||||
if(string == (strs[type][i])) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
// from DataMap::utoi
|
||||
T_CTEST_API int32_t
|
||||
udbg_stoi(const UnicodeString &s)
|
||||
{
|
||||
char ch[256];
|
||||
const UChar *u = s.getBuffer();
|
||||
int32_t len = s.length();
|
||||
u_UCharsToChars(u, ch, len);
|
||||
ch[len] = 0; /* include terminating \0 */
|
||||
return atoi(ch);
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user