OLD | NEW |
1 /* | 1 /* |
2 **************************************************************************** | 2 **************************************************************************** |
3 * Copyright (c) 1997-2013, International Business Machines Corporation and * | 3 * Copyright (c) 1997-2014, International Business Machines Corporation and * |
4 * others. All Rights Reserved. * | 4 * others. All Rights Reserved. * |
5 **************************************************************************** | 5 **************************************************************************** |
6 */ | 6 */ |
7 | 7 |
8 #include "unicode/utypes.h" | 8 #include "unicode/utypes.h" |
9 | 9 |
10 #if !UCONFIG_NO_FORMATTING | 10 #if !UCONFIG_NO_FORMATTING |
11 | 11 |
12 #include "unicode/utmscale.h" | 12 #include "unicode/utmscale.h" |
13 #include "unicode/ucal.h" | 13 #include "unicode/ucal.h" |
14 | 14 |
15 #include "cintltst.h" | 15 #include "cintltst.h" |
| 16 #include "cmemory.h" |
16 | 17 |
17 #include <stdlib.h> | 18 #include <stdlib.h> |
18 #include <time.h> | 19 #include <time.h> |
19 | 20 |
20 #define LENGTHOF(array) (int32_t)(sizeof(array)/sizeof((array)[0])) | |
21 | |
22 #define LOOP_COUNT 10000 | 21 #define LOOP_COUNT 10000 |
23 | 22 |
24 static void TestAPI(void); | 23 static void TestAPI(void); |
25 static void TestData(void); | 24 static void TestData(void); |
26 static void TestMonkey(void); | 25 static void TestMonkey(void); |
27 static void TestDotNet(void); | 26 static void TestDotNet(void); |
28 | 27 |
29 void addUtmsTest(TestNode** root); | 28 void addUtmsTest(TestNode** root); |
30 | 29 |
31 void addUtmsTest(TestNode** root) | 30 void addUtmsTest(TestNode** root) |
(...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
454 | 453 |
455 /* Open a proleptic Gregorian calendar. */ | 454 /* Open a proleptic Gregorian calendar. */ |
456 errorCode = U_ZERO_ERROR; | 455 errorCode = U_ZERO_ERROR; |
457 cal = ucal_open(utc, -1, "", UCAL_GREGORIAN, &errorCode); | 456 cal = ucal_open(utc, -1, "", UCAL_GREGORIAN, &errorCode); |
458 ucal_setGregorianChange(cal, -1000000 * (dayMillis * (UDate)1), &errorCode); | 457 ucal_setGregorianChange(cal, -1000000 * (dayMillis * (UDate)1), &errorCode); |
459 if(U_FAILURE(errorCode)) { | 458 if(U_FAILURE(errorCode)) { |
460 log_data_err("ucal_open(UTC/proleptic Gregorian) failed: %s - (Are you m
issing data?)\n", u_errorName(errorCode)); | 459 log_data_err("ucal_open(UTC/proleptic Gregorian) failed: %s - (Are you m
issing data?)\n", u_errorName(errorCode)); |
461 ucal_close(cal); | 460 ucal_close(cal); |
462 return; | 461 return; |
463 } | 462 } |
464 for(i = 0; i < LENGTHOF(dotNetDateTimeTicks); ++i) { | 463 for(i = 0; i < UPRV_LENGTHOF(dotNetDateTimeTicks); ++i) { |
465 /* Test conversion from .Net/Universal time to ICU time. */ | 464 /* Test conversion from .Net/Universal time to ICU time. */ |
466 dt = dotNetDateTimeTicks + i; | 465 dt = dotNetDateTimeTicks + i; |
467 millis = utmscale_toInt64(dt->ticks, UDTS_ICU4C_TIME, &errorCode); | 466 millis = utmscale_toInt64(dt->ticks, UDTS_ICU4C_TIME, &errorCode); |
468 ucal_clear(cal); | 467 ucal_clear(cal); |
469 ucal_setDate(cal, dt->year, dt->month - 1, dt->day, &errorCode); /* Java
& ICU use January = month 0. */ | 468 ucal_setDate(cal, dt->year, dt->month - 1, dt->day, &errorCode); /* Java
& ICU use January = month 0. */ |
470 icuDate = ucal_getMillis(cal, &errorCode); | 469 icuDate = ucal_getMillis(cal, &errorCode); |
471 if(millis != icuDate) { | 470 if(millis != icuDate) { |
472 /* Print days not millis to stay within printf() range. */ | 471 /* Print days not millis to stay within printf() range. */ |
473 log_err("utmscale_toInt64(ticks[%d], ICU4C)=%dd != %dd=ucal_getMilli
s(%04d-%02d-%02d)\n", | 472 log_err("utmscale_toInt64(ticks[%d], ICU4C)=%dd != %dd=ucal_getMilli
s(%04d-%02d-%02d)\n", |
474 (int)i, (int)(millis/dayMillis), (int)(icuDate/dayMillis), (
int)dt->year, (int)dt->month, (int)dt->day); | 473 (int)i, (int)(millis/dayMillis), (int)(icuDate/dayMillis), (
int)dt->year, (int)dt->month, (int)dt->day); |
475 } | 474 } |
476 | 475 |
477 /* Test conversion from ICU time to .Net/Universal time. */ | 476 /* Test conversion from ICU time to .Net/Universal time. */ |
478 ticks = utmscale_fromInt64((int64_t)icuDate, UDTS_ICU4C_TIME, &errorCode
); | 477 ticks = utmscale_fromInt64((int64_t)icuDate, UDTS_ICU4C_TIME, &errorCode
); |
479 if(ticks != dt->ticks) { | 478 if(ticks != dt->ticks) { |
480 /* Print days not ticks to stay within printf() range. */ | 479 /* Print days not ticks to stay within printf() range. */ |
481 log_err("utmscale_fromInt64(date[%d], ICU4C)=%dd != %dd=.Net System.
DateTime(%04d-%02d-%02d).Ticks\n", | 480 log_err("utmscale_fromInt64(date[%d], ICU4C)=%dd != %dd=.Net System.
DateTime(%04d-%02d-%02d).Ticks\n", |
482 (int)i, (int)(ticks/dayTicks), (int)(dt->ticks/dayTicks), (i
nt)dt->year, (int)dt->month, (int)dt->day); | 481 (int)i, (int)(ticks/dayTicks), (int)(dt->ticks/dayTicks), (i
nt)dt->year, (int)dt->month, (int)dt->day); |
483 } | 482 } |
484 } | 483 } |
485 | 484 |
486 ucal_close(cal); | 485 ucal_close(cal); |
487 } | 486 } |
488 | 487 |
489 #endif /* #if !UCONFIG_NO_FORMATTING */ | 488 #endif /* #if !UCONFIG_NO_FORMATTING */ |
OLD | NEW |