/******************************************************************** * COPYRIGHT: * Copyright (c) 1997-1999, International Business Machines Corporation and * others. All Rights Reserved. ********************************************************************/ /******************************************************************************** * * File CDATTST.C * * Modification History: * Name Description * Madhu Katragadda Creation ********************************************************************************* */ /* C API TEST FOR DATE FORMAT */ #include "unicode/uloc.h" #include "unicode/utypes.h" #include "unicode/udat.h" #include "unicode/ucal.h" #include "unicode/unum.h" #include "unicode/ustring.h" #include "cintltst.h" #include "cdattst.h" #include #include #include "cformtst.h" void addDateForTest(TestNode** root) { addTest(root, &TestDateFormat, "tsformat/cdattst/TestDateFormat"); addTest(root, &TestSymbols, "tsformat/cdattst/TestSymbols"); } /* Testing the DateFormat API */ void TestDateFormat() { UDateFormat *def, *fr, *it, *de, *def1, *fr_pat; UDateFormat *copy; UErrorCode status = U_ZERO_ERROR; UChar* result = NULL; const UCalendar *cal; const UNumberFormat *numformat1, *numformat2; UChar temp[30]; int32_t numlocales; UDate d1; int32_t resultlength; int32_t resultlengthneeded; int32_t parsepos; UFieldPosition pos; UDate d = 837039928046.0; double num = -10456.37; /*const char* str="yyyy.MM.dd G 'at' hh:mm:ss z"; const char t[]="2/3/76 2:50 AM";*/ /*Testing udat_open() to open a dateformat */ log_verbose("\nTesting udat_open() with various parameters\n"); fr = udat_open(UDAT_FULL, UDAT_DEFAULT, "fr_FR", NULL,0, &status); if(U_FAILURE(status)) { log_err("FAIL: error in creating the dateformat using full time style with french locale\n %s\n", myErrorName(status) ); } /* 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" */ /* def = udat_open(UDAT_SHORT, UDAT_SHORT, NULL, NULL, 0, &status); */ def = udat_open(UDAT_SHORT, UDAT_SHORT, "en_US", NULL, 0, &status); if(U_FAILURE(status)) { log_err("FAIL: error in creating the dateformat using short date and time style\n %s\n", myErrorName(status) ); } it = udat_open(UDAT_DEFAULT, UDAT_MEDIUM, "it_IT", NULL, 0, &status); if(U_FAILURE(status)) { log_err("FAIL: error in creating the dateformat using medium date style with italian locale\n %s\n", myErrorName(status) ); } de = udat_open(UDAT_LONG, UDAT_LONG, "de_DE", NULL, 0, &status); if(U_FAILURE(status)) { log_err("FAIL: error in creating the dateformat using long time and date styles with german locale\n %s\n", myErrorName(status)); } /*creating a default dateformat */ def1 = udat_open(UDAT_SHORT, UDAT_SHORT, NULL, NULL, 0, &status); if(U_FAILURE(status)) { log_err("FAIL: error in creating the dateformat using short date and time style\n %s\n", myErrorName(status) ); } /*Testing udat_getAvailable() and udat_countAvailable()*/ log_verbose("\nTesting getAvailableLocales and countAvailable()\n"); numlocales=udat_countAvailable(); /* use something sensible w/o hardcoding the count */ if(numlocales < 0) log_err("FAIL: error in countAvailable\n"); log_verbose("The number of locales for which date/time formatting patterns are available is %d\n", numlocales); /*for(i=0;i