/********************************************************************
* COPYRIGHT:
- * Copyright (c) 1997-2008, International Business Machines Corporation and
+ * Copyright (c) 1997-2010, International Business Machines Corporation and
* others. All Rights Reserved.
********************************************************************/
#include "unicode/schriter.h"
#include "unicode/regex.h"
#include "unicode/smpdtfmt.h"
-#include "unicode/dbgutil.h"
+#include "dbgutil.h"
#include <stdio.h>
name = "";
}
} else {
- dataerrln("[DATA] format/DataDriven*Test data (calendar.res) not initialized!");
+ dataerrln("format/DataDriven*Test data (calendar.res) not initialized!");
name = "";
}
void DataDrivenCalendarTest::testOps(TestData *testData,
const DataMap * /*settings*/) {
UErrorCode status = U_ZERO_ERROR;
+ UBool useDate = FALSE; // TODO
+ UnicodeString kMILLIS("MILLIS="); // TODO: static
+ UDate fromDate = 0; // TODO
+ UDate toDate = 0;
+
const DataMap *currentCase= NULL;
char toCalLoc[256] = "";
SimpleDateFormat fmt(UnicodeString("EEE MMM dd yyyy / YYYY'-W'ww-ee"),
status);
if (U_FAILURE(status)) {
- errln("FAIL: Couldn't create SimpleDateFormat: %s\n",
+ dataerrln("FAIL: Couldn't create SimpleDateFormat: %s",
u_errorName(status));
return;
}
+ UnicodeString(" - "));
continue;
}
- fromSet.parseFrom(testSetting, status);
- if (U_FAILURE(status)) {
- errln(caseString+": Failed to parse '"+param+"' parameter: "
- +testSetting);
- continue;
+
+ if(from.startsWith(kMILLIS)){
+ UnicodeString millis = UnicodeString(from, kMILLIS.length());
+ useDate = TRUE;
+ fromDate = udbg_stod(millis);
+ } else if(fromSet.parseFrom(testSetting, status)<0 || U_FAILURE(status)){
+ errln(caseString+": Failed to parse '"+param+"' parameter: "
+ +testSetting);
+ continue;
}
-
+
// #4 'operation' info
param = "operation";
UnicodeString operation = testSetting=currentCase->getString(param,
+ UnicodeString(" - "));
continue;
}
- toSet.parseFrom(testSetting, &fromSet, status); // parse with inheritance.
- if (U_FAILURE(status)) {
+ if(to.startsWith(kMILLIS)){
+ UnicodeString millis = UnicodeString(to, kMILLIS.length());
+ useDate = TRUE;
+ toDate = udbg_stod(millis);
+ } else if(toSet.parseFrom(testSetting, &fromSet, status)<0 || U_FAILURE(status)){
errln(caseString+": Failed to parse '"+param+"' parameter: "
- +testSetting);
+ +testSetting);
continue;
}
-
+
UnicodeString caseContentsString = locale+": from "+from+": "
+operation +" [[[ "+params+" ]]] >>> "+to;
logln(caseString+": "+caseContentsString);
// now, do it.
/// prepare calendar
- fromSet.setOnCalendar(fromCalendar, status);
- if (U_FAILURE(status)) {
- errln(caseString+" FAIL: Failed to set on Source calendar: "
- + u_errorName(status));
- return;
+ if(useDate){
+ fromCalendar->setTime(fromDate, status);
+ if (U_FAILURE(status)) {
+ errln(caseString+" FAIL: Failed to set time on Source calendar: "
+ + u_errorName(status));
+ return;
+ }
+ } else {
+ fromSet.setOnCalendar(fromCalendar, status);
+ if (U_FAILURE(status)) {
+ errln(caseString+" FAIL: Failed to set on Source calendar: "
+ + u_errorName(status));
+ return;
+ }
}
-
diffSet.clear();
// Is the calendar sane after being set?
// now - what's the result?
diffSet.clear();
- if (!toSet.matches(toCalendar, diffSet, status)) {
+ if(useDate){
+ if(!(toCalendar->getTime(status)==toDate) || U_FAILURE(status)){
+ errln("FAIL: "+caseString+" Match operation had an error: "
+ +u_errorName(status));
+ }else{
+ logln(caseString + " SUCCESS: got=expected="+toDate);
+ logln("PASS: "+caseString+" matched!");
+ }
+ } else if (!toSet.matches(toCalendar, diffSet, status)) {
UnicodeString diffs = diffSet.diffFrom(toSet, status);
errln((UnicodeString)"FAIL: "+caseString+" - , "+caseContentsString
+" Differences: "+ diffs +"', status: "
+ u_errorName(status));
- } else if (U_FAILURE(status)) {
+ }else if (U_FAILURE(status)) {
errln("FAIL: "+caseString+" Match operation had an error: "
+u_errorName(status));
- } else {
+ }else {
logln("PASS: "+caseString+" matched!");
}
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);
+ dataerrln(UnicodeString("Unable to instantiate ToCalendar for ")+testSetting);
return;
}
}
SimpleDateFormat fmt(UnicodeString("EEE MMM dd yyyy / YYYY'-W'ww-ee"),
status);
if (U_FAILURE(status)) {
- errln("FAIL: Couldn't create SimpleDateFormat: %s\n",
+ errcheckln(status, "FAIL: Couldn't create SimpleDateFormat: %s",
u_errorName(status));
return;
}