X-Git-Url: https://git.saurik.com/apple/icu.git/blobdiff_plain/b75a7d8f3b4adbae880cab104ce2c6a50eee4db2..1a147d096ae81f4c8262f7bfc56bd19fc2dee932:/icuSources/test/cintltst/cdtdptst.c diff --git a/icuSources/test/cintltst/cdtdptst.c b/icuSources/test/cintltst/cdtdptst.c index 2c4206bb..447bd89d 100644 --- a/icuSources/test/cintltst/cdtdptst.c +++ b/icuSources/test/cintltst/cdtdptst.c @@ -1,6 +1,8 @@ +// © 2016 and later: Unicode, Inc. and others. +// License & terms of use: http://www.unicode.org/copyright.html /******************************************************************** * COPYRIGHT: - * Copyright (c) 1997-2001, International Business Machines Corporation and + * Copyright (c) 1997-2014, International Business Machines Corporation and * others. All Rights Reserved. ********************************************************************/ /******************************************************************************** @@ -38,6 +40,8 @@ void addDtFrDepTest(TestNode** root) addTest(root, &TestRunTogetherPattern985, "tsformat/cdtdptst/TestRunTogetherPattern985"); addTest(root, &TestCzechMonths459, "tsformat/cdtdptst/TestCzechMonths459"); addTest(root, &TestQuotePattern161, "tsformat/cdtdptst/TestQuotePattern161"); + addTest(root, &TestBooleanAttributes, "tsformat/cdtdptst/TestBooleanAttributes"); + } @@ -53,47 +57,53 @@ void TestTwoDigitYearDSTParse() UChar *s; int32_t pos; + ctest_setTimeZone(NULL, &status); + pattern=(UChar*)malloc(sizeof(UChar) * (strlen("EEE MMM dd HH:mm:ss.SSS zzz yyyy G")+1 )); u_uastrcpy(pattern, "EEE MMM dd HH:mm:ss.SSS zzz yyyy G"); - fullFmt= udat_open(UDAT_IGNORE, UDAT_IGNORE,"en_US",NULL,0,pattern, u_strlen(pattern),&status); + fullFmt= udat_open(UDAT_PATTERN, UDAT_PATTERN,"en_US",NULL,0,pattern, u_strlen(pattern),&status); if(U_FAILURE(status)) { - log_err("FAIL: Error in creating a date format using udat_openPattern \n %s\n", + log_data_err("FAIL: Error in creating a date format using udat_openPattern %s - (Are you missing data?)\n", myErrorName(status) ); } - else {log_verbose("PASS: creating dateformat using udat_openPattern() succesful\n");} - - u_uastrcpy(pattern, "dd-MMM-yy h:mm:ss 'o''clock' a z"); - fmt= udat_open(UDAT_IGNORE,UDAT_IGNORE,"en_US", NULL, 0,pattern, u_strlen(pattern), &status); - + else { + log_verbose("PASS: creating dateformat using udat_openPattern() succesful\n"); - s=(UChar*)malloc(sizeof(UChar) * (strlen("03-Apr-04 2:20:47 o'clock AM PST")+1) ); - u_uastrcpy(s, "03-Apr-04 2:20:47 o'clock AM PST"); - pos=0; - d = udat_parse(fmt, s, u_strlen(s), &pos, &status); - if (U_FAILURE(status)) { - log_err("FAIL: Could not parse \"%s\"\n", austrdup(s)); - } else { - UCalendar *cal = ucal_open(NULL, 0, uloc_getDefault(), UCAL_TRADITIONAL, &status); + u_uastrcpy(pattern, "dd-MMM-yy h:mm:ss 'o''clock' a z"); + fmt= udat_open(UDAT_PATTERN,UDAT_PATTERN,"en_US", NULL, 0,pattern, u_strlen(pattern), &status); + + + s=(UChar*)malloc(sizeof(UChar) * (strlen("03-Apr-04 2:20:47 o'clock AM PST")+1) ); + u_uastrcpy(s, "03-Apr-04 2:20:47 o'clock AM PST"); + pos=0; + d = udat_parse(fmt, s, u_strlen(s), &pos, &status); if (U_FAILURE(status)) { - log_err("FAIL: Could not open calendar"); + log_err("FAIL: Could not parse \"%s\"\n", austrdup(s)); } else { - int32_t h; - ucal_setMillis(cal, d, &status); - h = ucal_get(cal, UCAL_HOUR_OF_DAY, &status); + UCalendar *cal = ucal_open(NULL, 0, uloc_getDefault(), UCAL_TRADITIONAL, &status); if (U_FAILURE(status)) { - log_err("FAIL: Some calendar operations failed"); - } else if (h != 2) { - log_err("FAIL: Parse of \"%s\" returned HOUR_OF_DAY %d\n", - austrdup(s), h); + log_err_status(status, "FAIL: Could not open calendar: %s\n", u_errorName(status)); + } else { + int32_t h; + ucal_setMillis(cal, d, &status); + h = ucal_get(cal, UCAL_HOUR_OF_DAY, &status); + if (U_FAILURE(status)) { + log_err("FAIL: Some calendar operations failed"); + } else if (h != 2) { + log_err("FAIL: Parse of \"%s\" returned HOUR_OF_DAY %d\n", + austrdup(s), h); + } + ucal_close(cal); } - ucal_close(cal); } + + udat_close(fullFmt); + udat_close(fmt); + free(s); } - - udat_close(fullFmt); - udat_close(fmt); free(pattern); - free(s); + + ctest_resetTimeZone(); } @@ -117,7 +127,7 @@ void TestPartialParse994() /* f = udat_open(UDAT_DEFAULT, UDAT_SHORT, NULL, NULL, 0, &status); */ f = udat_open(UDAT_DEFAULT, UDAT_SHORT, "en_US", NULL, 0, NULL, 0,&status); if(U_FAILURE(status)){ - log_err("FAIL: ErrorCode received during test: %s\n", myErrorName(status)); + log_data_err("FAIL: ErrorCode received during test: %s (Are you missing data?)\n", myErrorName(status)); return; } s=(UChar*)malloc(sizeof(UChar) * (strlen("01/01/1997 10:11:42 AM")+1) ); @@ -194,9 +204,9 @@ void TestRunTogetherPattern985() UErrorCode status = U_ZERO_ERROR; pattern=(UChar*)malloc(sizeof(UChar) * (strlen("yyyyMMddHHmmssSSS")+1) ); u_uastrcpy(pattern, "yyyyMMddHHmmssSSS"); - format = udat_open(UDAT_IGNORE, UDAT_IGNORE, NULL, NULL, 0,pattern, u_strlen(pattern), &status); + format = udat_open(UDAT_PATTERN, UDAT_PATTERN, NULL, NULL, 0,pattern, u_strlen(pattern), &status); if(U_FAILURE(status)){ - log_err("FAIL: Error in date format construction with pattern: %s\n", myErrorName(status)); + log_data_err("FAIL: Error in date format construction with pattern: %s - (Are you missing data?)\n", myErrorName(status)); return; } date1 = ucal_getNow(); @@ -227,12 +237,13 @@ void TestCzechMonths459() UCalendar *cal; UDate june, july, d; UErrorCode status = U_ZERO_ERROR; - char buffer[512]; UChar *date; + ctest_setTimeZone(NULL, &status); fmt = udat_open(UDAT_FULL, UDAT_FULL, "cs", NULL, 0, NULL, 0, &status); if(U_FAILURE(status)){ - log_err("Error in constructing the date format\n"); + log_data_err("Error in constructing the date format -> %s (Are you missing data?)\n", u_errorName(status)); + ctest_resetTimeZone(); return; } lneed=0; @@ -253,7 +264,6 @@ void TestCzechMonths459() ucal_setDate(cal, 1997, UCAL_JULY, 15, &status); july=ucal_getMillis(cal, &status); - juneStr = myDateFormat(fmt, june); julyStr = myDateFormat(fmt, july); pos=0; @@ -263,20 +273,26 @@ void TestCzechMonths459() } d = udat_parse(fmt, juneStr, u_strlen(juneStr), &pos, &status); date = myDateFormat(fmt, d); - u_UCharsToChars(date, buffer, (int32_t)(u_strlen(date)+1)); - if(u_strcmp(myDateFormat(fmt, june), myDateFormat(fmt, d) ) !=0) - log_err("Error in handling the czech month june\n"); - else - log_verbose("Pass: Date = %s\n", buffer ); + + if(U_SUCCESS(status)){ + UChar* out1 = myDateFormat(fmt, june); + UChar* out2 = myDateFormat(fmt, d); + if(u_strcmp(out1, out2) !=0) + log_err("Error in handling the czech month june\n"); + else + log_verbose("Pass: Date = %s (czech month June)\n", aescstrdup(date, -1)); + }else{ + log_err("udat_parse failed. Error. %s\n",u_errorName(status)); + } pos=0; d = udat_parse(fmt, julyStr, u_strlen(julyStr), &pos, &status); date = myDateFormat(fmt, d); - u_UCharsToChars(date, buffer, (int32_t)(u_strlen(date)+1)); if(u_strcmp(myDateFormat(fmt, july), myDateFormat(fmt, d) ) !=0) log_err("Error in handling the czech month july\n"); else - log_verbose("Pass: Date = %s\n", buffer ); + log_verbose("Pass: Date = %s (czech month July)\n", aescstrdup(date, -1)); + ctest_resetTimeZone(); udat_close(fmt); ucal_close(cal); free(pattern); @@ -295,15 +311,18 @@ void TestQuotePattern161() UChar *dateString; UErrorCode status = U_ZERO_ERROR; const char* expStr = "04/13/1999 at 10:42:28 AM "; + + ctest_setTimeZone(NULL, &status); + pattern=(UChar*)malloc(sizeof(UChar) * (strlen("MM/dd/yyyy 'at' hh:mm:ss a zzz")+1) ); u_uastrcpy(pattern, "MM/dd/yyyy 'at' hh:mm:ss a zzz"); /* this is supposed to open default date format, but later on it treats it like it is "en_US" - very bad if you try to run the tests on machine where default locale is NOT "en_US" */ /* format= udat_openPattern(pattern, u_strlen(pattern), NULL, &status); */ - format= udat_open(UDAT_IGNORE, UDAT_IGNORE,"en_US", NULL, 0,pattern, u_strlen(pattern), &status); + format= udat_open(UDAT_PATTERN, UDAT_PATTERN,"en_US", NULL, 0,pattern, u_strlen(pattern), &status); if(U_FAILURE(status)){ - log_err("error in udat_open: %s\n", myErrorName(status)); + log_data_err("error in udat_open: %s - (Are you missing data?)\n", myErrorName(status)); return; } tzID=(UChar*)malloc(sizeof(UChar) * 4); @@ -322,7 +341,7 @@ void TestQuotePattern161() u_uastrcpy(exp, expStr); log_verbose("%s\n", austrdup(dateString) ); - if(u_strncmp(dateString, exp, strlen(expStr)) !=0) + if(u_strncmp(dateString, exp, (int32_t)strlen(expStr)) !=0) log_err("Error in formatting a pattern with single quotes\n"); udat_close(format); @@ -331,6 +350,38 @@ void TestQuotePattern161() free(tzID); free(pattern); + ctest_resetTimeZone(); +} + +/* + * Testing udat_getBooleanAttribute and unum_setBooleanAttribute() to make sure basic C wrapper functionality is present + */ +void TestBooleanAttributes(void) +{ + UDateFormat *en; + UErrorCode status=U_ZERO_ERROR; + UBool initialState = TRUE; + UBool switchedState = FALSE; + + log_verbose("\ncreating a date format with english locale\n"); + en = udat_open(UDAT_FULL, UDAT_DEFAULT, "en_US", NULL, 0, NULL, 0, &status); + if(U_FAILURE(status)) { + log_data_err("error in creating the dateformat -> %s (Are you missing data?)\n", + myErrorName(status) ); + return; + } + + + initialState = udat_getBooleanAttribute(en, UDAT_PARSE_ALLOW_NUMERIC, &status); + if(initialState != TRUE) switchedState = TRUE; // if it wasn't the default of TRUE, then flip what we expect + + udat_setBooleanAttribute(en, UDAT_PARSE_ALLOW_NUMERIC, switchedState, &status); + if(switchedState != udat_getBooleanAttribute(en, UDAT_PARSE_ALLOW_NUMERIC, &status)) { + log_err("unable to switch states!"); + return; + } + + udat_close(en); } #endif /* #if !UCONFIG_NO_FORMATTING */