OLD | NEW |
1 /*********************************************************************** | 1 /*********************************************************************** |
2 * COPYRIGHT: | 2 * COPYRIGHT: |
3 * Copyright (c) 1997-2013, International Business Machines Corporation | 3 * Copyright (c) 1997-2014, International Business Machines Corporation |
4 * and others. All Rights Reserved. | 4 * and others. All Rights Reserved. |
5 ***********************************************************************/ | 5 ***********************************************************************/ |
6 | 6 |
7 #include "unicode/utypes.h" | 7 #include "unicode/utypes.h" |
8 | 8 |
9 #if !UCONFIG_NO_FORMATTING | 9 #if !UCONFIG_NO_FORMATTING |
10 | 10 |
11 #include "unicode/datefmt.h" | 11 #include "unicode/datefmt.h" |
12 #include "unicode/smpdtfmt.h" | 12 #include "unicode/smpdtfmt.h" |
13 #include "unicode/gregocal.h" | 13 #include "unicode/gregocal.h" |
14 #include "dtfmtrtts.h" | 14 #include "dtfmtrtts.h" |
15 #include "caltest.h" | 15 #include "caltest.h" |
| 16 #include "cstring.h" |
16 | 17 |
17 #include <stdio.h> | 18 #include <stdio.h> |
18 #include <string.h> | 19 #include <string.h> |
19 | 20 |
20 // ***************************************************************************** | 21 // ***************************************************************************** |
21 // class DateFormatRoundTripTest | 22 // class DateFormatRoundTripTest |
22 // ***************************************************************************** | 23 // ***************************************************************************** |
23 | 24 |
24 // Useful for turning up subtle bugs: Change the following to TRUE, recompile, | 25 // Useful for turning up subtle bugs: Change the following to TRUE, recompile, |
25 // and run while at lunch. | 26 // and run while at lunch. |
26 // Warning -- makes test run infinite loop!!! | 27 // Warning -- makes test run infinite loop!!! |
27 #ifndef INFINITE | 28 #ifndef INFINITE |
28 #define INFINITE 0 | 29 #define INFINITE 0 |
29 #endif | 30 #endif |
30 | 31 |
31 static const UVersionInfo ICU_452 = {4,5,2,0}; | |
32 | |
33 // Define this to test just a single locale | 32 // Define this to test just a single locale |
34 //#define TEST_ONE_LOC "cs_CZ" | 33 //#define TEST_ONE_LOC "cs_CZ" |
35 | 34 |
36 // If SPARSENESS is > 0, we don't run each exhaustive possibility. | 35 // If SPARSENESS is > 0, we don't run each exhaustive possibility. |
37 // There are 24 total possible tests per each locale. A SPARSENESS | 36 // There are 24 total possible tests per each locale. A SPARSENESS |
38 // of 12 means we run half of them. A SPARSENESS of 23 means we run | 37 // of 12 means we run half of them. A SPARSENESS of 23 means we run |
39 // 1 of them. SPARSENESS _must_ be in the range 0..23. | 38 // 1 of them. SPARSENESS _must_ be in the range 0..23. |
40 int32_t DateFormatRoundTripTest::SPARSENESS = 0; | 39 int32_t DateFormatRoundTripTest::SPARSENESS = 0; |
41 int32_t DateFormatRoundTripTest::TRIALS = 4; | 40 int32_t DateFormatRoundTripTest::TRIALS = 4; |
42 int32_t DateFormatRoundTripTest::DEPTH = 5; | 41 int32_t DateFormatRoundTripTest::DEPTH = 5; |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 Locale loc = Locale::getDefault(); | 163 Locale loc = Locale::getDefault(); |
165 logln("ENTERING INFINITE TEST LOOP FOR Locale: " + loc.getDisplayName(temp))
; | 164 logln("ENTERING INFINITE TEST LOOP FOR Locale: " + loc.getDisplayName(temp))
; |
166 for(;;) | 165 for(;;) |
167 test(loc); | 166 test(loc); |
168 # else | 167 # else |
169 test(Locale::getDefault()); | 168 test(Locale::getDefault()); |
170 | 169 |
171 #if 1 | 170 #if 1 |
172 // installed locales | 171 // installed locales |
173 for (int i=0; i < locCount; ++i) { | 172 for (int i=0; i < locCount; ++i) { |
174 test(avail[i]); | 173 test(avail[i]); |
175 } | 174 } |
176 #endif | 175 #endif |
177 | 176 |
178 #if 1 | 177 #if 1 |
179 // special locales | 178 // special locales |
180 int32_t jCount = CalendarTest::testLocaleCount(); | 179 int32_t jCount = CalendarTest::testLocaleCount(); |
181 for (int32_t j=0; j < jCount; ++j) { | 180 for (int32_t j=0; j < jCount; ++j) { |
182 test(Locale(CalendarTest::testLocaleID(j))); | 181 test(Locale(CalendarTest::testLocaleID(j))); |
183 } | 182 } |
184 #endif | 183 #endif |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
278 void DateFormatRoundTripTest::test(DateFormat *fmt, const Locale &origLocale, UB
ool timeOnly) | 277 void DateFormatRoundTripTest::test(DateFormat *fmt, const Locale &origLocale, UB
ool timeOnly) |
279 { | 278 { |
280 UnicodeString pat; | 279 UnicodeString pat; |
281 if(fmt->getDynamicClassID() != SimpleDateFormat::getStaticClassID()) { | 280 if(fmt->getDynamicClassID() != SimpleDateFormat::getStaticClassID()) { |
282 errln("DateFormat wasn't a SimpleDateFormat"); | 281 errln("DateFormat wasn't a SimpleDateFormat"); |
283 return; | 282 return; |
284 } | 283 } |
285 | 284 |
286 UBool isGregorian = FALSE; | 285 UBool isGregorian = FALSE; |
287 UErrorCode minStatus = U_ZERO_ERROR; | 286 UErrorCode minStatus = U_ZERO_ERROR; |
| 287 if(fmt->getCalendar() == NULL) { |
| 288 errln((UnicodeString)"DateFormatRoundTripTest::test, DateFormat getCalenda
r() returns null for " + origLocale.getName()); |
| 289 return; |
| 290 } |
288 UDate minDate = CalendarTest::minDateOfCalendar(*fmt->getCalendar(), isGrego
rian, minStatus); | 291 UDate minDate = CalendarTest::minDateOfCalendar(*fmt->getCalendar(), isGrego
rian, minStatus); |
289 if(U_FAILURE(minStatus)) { | 292 if(U_FAILURE(minStatus)) { |
290 errln((UnicodeString)"Failure getting min date for " + origLocale.getName(
)); | 293 errln((UnicodeString)"Failure getting min date for " + origLocale.getName(
)); |
291 return; | 294 return; |
292 } | 295 } |
293 //logln(UnicodeString("Min date is ") + fullFormat(minDate) + " for " + ori
gLocale.getName()); | 296 //logln(UnicodeString("Min date is ") + fullFormat(minDate) + " for " + ori
gLocale.getName()); |
294 | 297 |
295 pat = ((SimpleDateFormat*)fmt)->toPattern(pat); | 298 pat = ((SimpleDateFormat*)fmt)->toPattern(pat); |
296 | 299 |
297 // NOTE TO MAINTAINER | 300 // NOTE TO MAINTAINER |
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
571 // Now scale up to ms | 574 // Now scale up to ms |
572 a *= 365.25 * 24 * 60 * 60 * 1000; | 575 a *= 365.25 * 24 * 60 * 60 * 1000; |
573 | 576 |
574 //return new Date((long)a); | 577 //return new Date((long)a); |
575 return a; | 578 return a; |
576 } | 579 } |
577 | 580 |
578 #endif /* #if !UCONFIG_NO_FORMATTING */ | 581 #endif /* #if !UCONFIG_NO_FORMATTING */ |
579 | 582 |
580 //eof | 583 //eof |
OLD | NEW |