]> git.saurik.com Git - apple/icu.git/blobdiff - icuSources/test/intltest/dtfmrgts.cpp
ICU-8.11.tar.gz
[apple/icu.git] / icuSources / test / intltest / dtfmrgts.cpp
index 6e007bcbd28211c22ca57c8191f173782bfae90c..b4d5ee4ab82812c707c3a34fb54f2b5f2899a28a 100644 (file)
@@ -1,6 +1,6 @@
 /********************************************************************
  * COPYRIGHT: 
- * Copyright (c) 1997-2004, International Business Machines Corporation and
+ * Copyright (c) 1997-2006, International Business Machines Corporation and
  * others. All Rights Reserved.
  ********************************************************************/
 
@@ -69,8 +69,15 @@ void DateFormatRegressionTest::Test4029195(void)
     logln((UnicodeString) "today: " + today);
 
     SimpleDateFormat *sdf = (SimpleDateFormat*) DateFormat::createDateInstance();
-    failure(status, "SimpleDateFormat::createDateInstance");
+    if (failure(status, "SimpleDateFormat::createDateInstance")) {
+        return;
+    }
     UnicodeString pat;
+    if(sdf == NULL){
+        dataerrln("Error calling DateFormat::createDateTimeInstance");
+        return;
+    }
+
     pat = sdf->toPattern(pat);
     logln("pattern: " + pat);
     UnicodeString fmtd;
@@ -114,6 +121,11 @@ void DateFormatRegressionTest::Test4052408(void)
 
     DateFormat *fmt = DateFormat::createDateTimeInstance(DateFormat::SHORT,
                                                 DateFormat::SHORT, Locale::getUS());
+    if (fmt == NULL) {
+        dataerrln("Error calling DateFormat::createDateTimeInstance");
+        return;
+    }
+
     UDate dt = date(97, UCAL_MAY, 3, 8, 55);
     UnicodeString str;
     str = fmt->format(dt, str);
@@ -267,7 +279,7 @@ void DateFormatRegressionTest::Test4059917(void)
     UnicodeString myDate;
 
     fmt = new SimpleDateFormat( UnicodeString("yyyy/MM/dd"), status );
-    failure(status, "new SimpleDateFormat");
+    if(failure(status, "new SimpleDateFormat")) return;
     myDate = "1997/01/01";
     aux917( fmt, myDate );
     
@@ -275,7 +287,7 @@ void DateFormatRegressionTest::Test4059917(void)
     fmt = NULL;
     
     fmt = new SimpleDateFormat( UnicodeString("yyyyMMdd"), status );
-    failure(status, "new SimpleDateFormat");
+    if(failure(status, "new SimpleDateFormat")) return;
     myDate = "19970101";
     aux917( fmt, myDate );
               
@@ -323,12 +335,18 @@ void DateFormatRegressionTest::Test4060212(void)
     logln("Using yyyy-DDD.hh:mm:ss");
     UErrorCode status = U_ZERO_ERROR;
     SimpleDateFormat *formatter = new SimpleDateFormat(UnicodeString("yyyy-DDD.hh:mm:ss"), status);
-    failure(status, "new SimpleDateFormat");
+    if(failure(status, "new SimpleDateFormat")) return;
     ParsePosition pos(0);
     UDate myDate = formatter->parse( dateString, pos );
     UnicodeString myString;
     DateFormat *fmt = DateFormat::createDateTimeInstance( DateFormat::FULL,
                                                             DateFormat::LONG);
+    if (fmt == NULL) {
+        dataerrln("Error calling DateFormat::createDateTimeInstance");
+        delete formatter;
+        return;
+    }
+
     myString = fmt->format( myDate, myString);
     logln( myString );
 
@@ -344,7 +362,7 @@ void DateFormatRegressionTest::Test4060212(void)
     delete formatter;
     formatter = NULL;
     formatter = new SimpleDateFormat(UnicodeString("yyyy-ddd.hh:mm:ss"), status);
-    failure(status, "new SimpleDateFormat");
+    if(failure(status, "new SimpleDateFormat")) return;
     pos.setIndex(0);
     myDate = formatter->parse( dateString, pos );
     myString = fmt->format( myDate, myString );
@@ -417,7 +435,16 @@ void DateFormatRegressionTest::Test4065240(void)
         TimeZone::adoptDefault(TimeZone::createTimeZone("EST"));
         curDate = date(98, 0, 1);
         shortdate = DateFormat::createDateInstance(DateFormat::SHORT);
+        if (shortdate == NULL){
+            dataerrln("Error calling DateFormat::createDateInstance");
+            return;
+        }
+
         fulldate = DateFormat::createDateTimeInstance(DateFormat::LONG, DateFormat::LONG);
+        if (fulldate == NULL){
+            dataerrln("Error calling DateFormat::createDateTimeInstance");
+            return;
+        }
         strShortDate = "The current date (short form) is ";
         UnicodeString temp;
         temp = shortdate->format(curDate, temp);
@@ -454,7 +481,6 @@ void DateFormatRegressionTest::Test4065240(void)
     failure(status, "Locale::setDefault");
     TimeZone::setDefault(*saveZone);
     //}
-
     delete shortdate;
     delete fulldate;
     delete saveZone;
@@ -478,7 +504,14 @@ void DateFormatRegressionTest::Test4071441(void)
 {
     DateFormat *fmtA = DateFormat::createInstance();
     DateFormat *fmtB = DateFormat::createInstance();
-    
+
+    if (fmtA == NULL || fmtB == NULL){
+        dataerrln("Error calling DateFormat::createInstance");
+        delete fmtA;
+        delete fmtB;
+        return;
+    }
+
     // {sfb} Is it OK to cast away const here?
     Calendar *calA = (Calendar*) fmtA->getCalendar();
     Calendar *calB = (Calendar*) fmtB->getCalendar();
@@ -670,7 +703,7 @@ void DateFormatRegressionTest::Test4101483(void)
 {
     UErrorCode status = U_ZERO_ERROR;
     SimpleDateFormat *sdf = new SimpleDateFormat(UnicodeString("z"), Locale::getUS(), status);
-    failure(status, "new SimpleDateFormat");
+    if(failure(status, "new SimpleDateFormat")) return;
     FieldPosition fp(UDAT_TIMEZONE_FIELD);
     //Date d = date(9234567890L);
     UDate d = 9234567890.0;
@@ -703,7 +736,7 @@ void DateFormatRegressionTest::Test4103340(void)
     // and some arbitrary time 
     UDate d = date(97, 3, 1, 1, 1, 1); 
     SimpleDateFormat *df = new SimpleDateFormat(UnicodeString("MMMM"), Locale::getUS(), status); 
-    failure(status, "new SimpleDateFormat");
+    if(failure(status, "new SimpleDateFormat")) return;
 
     UnicodeString s;
     s = dateToString(d, s);
@@ -762,7 +795,7 @@ void DateFormatRegressionTest::Test4104136(void)
       delete sdf;
       return;
     }
-    failure(status, "new SimpleDateFormat");
+    if(failure(status, "new SimpleDateFormat")) return;
     UnicodeString pattern = "'time' hh:mm"; 
     sdf->applyPattern(pattern); 
     logln("pattern: \"" + pattern + "\""); 
@@ -969,7 +1002,7 @@ void DateFormatRegressionTest::Test4134203(void)
     UErrorCode status = U_ZERO_ERROR;
     UnicodeString dateFormat = "MM/dd/yy HH:mm:ss zzz";
     SimpleDateFormat *fmt = new SimpleDateFormat(dateFormat, status);
-    failure(status, "new SimpleDateFormat");
+    if(failure(status, "new SimpleDateFormat")) return;
     ParsePosition p0(0);
     UDate d = fmt->parse("01/22/92 04:52:00 GMT", p0);
     logln(dateToString(d));
@@ -991,7 +1024,7 @@ void DateFormatRegressionTest::Test4151631(void)
     logln("pattern=" + pattern);
     UErrorCode status = U_ZERO_ERROR;
     SimpleDateFormat *format = new SimpleDateFormat(pattern, Locale::getUS(), status);
-    failure(status, "new SimpleDateFormat");
+    if(failure(status, "new SimpleDateFormat")) return;
     UnicodeString result;
     FieldPosition pos(FieldPosition::DONT_CARE);
     result = format->format(date(1998-1900, UCAL_JUNE, 30, 13, 30, 0), result, pos);
@@ -1015,7 +1048,7 @@ void DateFormatRegressionTest::Test4151706(void)
     UnicodeString dateString("Thursday, 31-Dec-98 23:00:00 GMT");
     UErrorCode status = U_ZERO_ERROR;
     SimpleDateFormat fmt(UnicodeString("EEEE, dd-MMM-yy HH:mm:ss z"), Locale::getUS(), status);
-    failure(status, "new SimpleDateFormat");
+    if(failure(status, "new SimpleDateFormat")) return;
     //try {
         UDate d = fmt.parse(dateString, status);
         failure(status, "fmt->parse");
@@ -1042,8 +1075,10 @@ DateFormatRegressionTest::Test4162071(void)
     UnicodeString format("EEE', 'dd-MMM-yyyy HH:mm:ss z"); // RFC 822/1123
     UErrorCode status = U_ZERO_ERROR;
     SimpleDateFormat df(format, Locale::getUS(), status);
-    if(U_FAILURE(status))
+    if(U_FAILURE(status)) {
         errln("Couldn't create SimpleDateFormat");
+        return;
+    }
     
     //try {
         UDate x = df.parse(dateString, status);
@@ -1197,6 +1232,11 @@ void DateFormatRegressionTest::Test714(void)
     DateFormat *fmt = DateFormat::createDateTimeInstance(DateFormat::NONE,
                                                          DateFormat::MEDIUM,
                                                          Locale::getUS());
+    if (fmt == NULL) {
+        dataerrln("Error calling DateFormat::createDateTimeInstance");
+        return;
+    }
+
     UnicodeString s;
         UnicodeString tests = 
           (UnicodeString) "7:25:43 AM" ;
@@ -1284,6 +1324,15 @@ void DateFormatRegressionTest::Test1684(void)
   UnicodeString pattern("yyyy MM WW EEE","");
   Calendar *cal = new GregorianCalendar(status);
   SimpleDateFormat *sdf = new SimpleDateFormat(pattern,status);
+  if (U_FAILURE(status)) {
+    dataerrln("Error constructing SimpleDateFormat");
+    for(i=0;i<kTest1684Count;i++) {
+        delete tests[i];
+    }
+    delete cal;
+    delete sdf;
+    return;
+  }
   cal->setFirstDayOfWeek(UCAL_SUNDAY);
   cal->setMinimalDaysInFirstWeek(1);
 
@@ -1368,7 +1417,7 @@ void DateFormatRegressionTest::Test1684(void)
   } else {
     logln(info);
   }
-  
+
   for(i=0;i<kTest1684Count;i++) {
     delete tests[i];
   }