]> git.saurik.com Git - apple/icu.git/blobdiff - icuSources/test/intltest/dadrcal.cpp
ICU-511.34.tar.gz
[apple/icu.git] / icuSources / test / intltest / dadrcal.cpp
index b968e11f0223aa85ee8c1a3236314ee520850e9e..0720525a911defa1eb025ed7e3625c8a01be1cbf 100644 (file)
@@ -1,6 +1,6 @@
 /********************************************************************
  * COPYRIGHT: 
- * Copyright (c) 1997-2008, International Business Machines Corporation and
+ * Copyright (c) 1997-2010, International Business Machines Corporation and
  * others. All Rights Reserved.
  ********************************************************************/
 
@@ -23,7 +23,7 @@
 #include "unicode/schriter.h"
 #include "unicode/regex.h"
 #include "unicode/smpdtfmt.h"
-#include "unicode/dbgutil.h"
+#include "dbgutil.h"
 
 #include <stdio.h>
 
@@ -62,7 +62,7 @@ void DataDrivenCalendarTest::runIndexedTest(int32_t index, UBool exec,
             name = "";
         }
     } else {
-        dataerrln("[DATA] format/DataDriven*Test data (calendar.res) not initialized!");
+        dataerrln("format/DataDriven*Test data (calendar.res) not initialized!");
         name = "";
     }
 
@@ -71,6 +71,11 @@ void DataDrivenCalendarTest::runIndexedTest(int32_t index, UBool exec,
 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] = "";
 
@@ -83,7 +88,7 @@ void DataDrivenCalendarTest::testOps(TestData *testData,
     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;
     }
@@ -126,13 +131,17 @@ void DataDrivenCalendarTest::testOps(TestData *testData,
                     + 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,
@@ -174,13 +183,16 @@ void DataDrivenCalendarTest::testOps(TestData *testData,
                     + 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);
@@ -189,13 +201,21 @@ void DataDrivenCalendarTest::testOps(TestData *testData,
         // 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?
@@ -239,15 +259,23 @@ void DataDrivenCalendarTest::testOps(TestData *testData,
         // 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!");
         }
 
@@ -346,7 +374,7 @@ void DataDrivenCalendarTest::testConvert(TestData *testData,
         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;
         }
     }
@@ -355,7 +383,7 @@ void DataDrivenCalendarTest::testConvert(TestData *testData,
     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;
     }