1ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/******************************************************************** 2ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * COPYRIGHT: 385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho * Copyright (c) 1997-2009, International Business Machines Corporation and 4ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * others. All Rights Reserved. 5ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ********************************************************************/ 6ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/******************************************************************************** 7ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru* 8ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru* File CDATTST.C 9ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru* 10ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru* Modification History: 11ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru* Name Description 12ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru* Madhu Katragadda Creation 13ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru********************************************************************************* 14ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru*/ 15ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 16ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/* C API TEST FOR DATE FORMAT */ 17ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 18ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/utypes.h" 19ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 20ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#if !UCONFIG_NO_FORMATTING 21ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 22ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/uloc.h" 23ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/udat.h" 24ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/ucal.h" 25ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/unum.h" 26ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/ustring.h" 27ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "cintltst.h" 28ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "cdattst.h" 29ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "cformtst.h" 30ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "cmemory.h" 31ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 32ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include <math.h> 33ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 34ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void TestExtremeDates(void); 35ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void TestAllLocales(void); 3685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Hostatic void TestRelativeCrash(void); 37ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 38ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#define LEN(a) (sizeof(a)/sizeof(a[0])) 39ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 40ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid addDateForTest(TestNode** root); 41ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 42ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#define TESTCASE(x) addTest(root, &x, "tsformat/cdattst/" #x) 43ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 44ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid addDateForTest(TestNode** root) 45ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{ 46ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru TESTCASE(TestDateFormat); 4785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho TESTCASE(TestRelativeDateFormat); 48ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru TESTCASE(TestSymbols); 49ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru TESTCASE(TestDateFormatCalendar); 50ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru TESTCASE(TestExtremeDates); 51ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru TESTCASE(TestAllLocales); 5285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho TESTCASE(TestRelativeCrash); 53ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 54ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/* Testing the DateFormat API */ 55ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void TestDateFormat() 56ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{ 57ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UDateFormat *def, *fr, *it, *de, *def1, *fr_pat; 58ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UDateFormat *any; 59ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UDateFormat *copy; 60ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UErrorCode status = U_ZERO_ERROR; 61ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UChar* result = NULL; 62ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const UCalendar *cal; 63ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const UNumberFormat *numformat1, *numformat2; 64ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UChar temp[50]; 65ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t numlocales; 66ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UDate d1; 67ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int i; 68ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t resultlength; 69ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t resultlengthneeded; 70ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t parsepos; 71ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UDate d = 837039928046.0; 72ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru double num = -10456.37; 73ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /*const char* str="yyyy.MM.dd G 'at' hh:mm:ss z"; 74ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const char t[]="2/3/76 2:50 AM";*/ 75ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /*Testing udat_open() to open a dateformat */ 76ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 77ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ctest_setTimeZone(NULL, &status); 78ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 79ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("\nTesting udat_open() with various parameters\n"); 80ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru fr = udat_open(UDAT_FULL, UDAT_DEFAULT, "fr_FR", NULL,0, NULL, 0,&status); 81ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_FAILURE(status)) 82ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 8385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_data_err("FAIL: error in creating the dateformat using full time style with french locale -> %s (Are you missing data?)\n", 84ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru myErrorName(status) ); 85ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return; 86ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 87ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* this is supposed to open default date format, but later on it treats it like it is "en_US" 88ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru - very bad if you try to run the tests on machine where default locale is NOT "en_US" */ 89ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* def = udat_open(UDAT_SHORT, UDAT_SHORT, NULL, NULL, 0, &status); */ 90ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru def = udat_open(UDAT_SHORT, UDAT_SHORT, "en_US", NULL, 0,NULL, 0, &status); 91ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_FAILURE(status)) 92ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 93ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("FAIL: error in creating the dateformat using short date and time style\n %s\n", 94ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru myErrorName(status) ); 95ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return; 96ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 97ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru it = udat_open(UDAT_DEFAULT, UDAT_MEDIUM, "it_IT", NULL, 0, NULL, 0,&status); 98ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_FAILURE(status)) 99ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 100ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("FAIL: error in creating the dateformat using medium date style with italian locale\n %s\n", 101ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru myErrorName(status) ); 102ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return; 103ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 104ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru de = udat_open(UDAT_LONG, UDAT_LONG, "de_DE", NULL, 0, NULL, 0,&status); 105ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_FAILURE(status)) 106ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 107ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("FAIL: error in creating the dateformat using long time and date styles with german locale\n %s\n", 108ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru myErrorName(status)); 109ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return; 110ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 111ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /*creating a default dateformat */ 112ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru def1 = udat_open(UDAT_SHORT, UDAT_SHORT, NULL, NULL, 0,NULL, 0, &status); 113ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_FAILURE(status)) 114ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 115ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("FAIL: error in creating the dateformat using short date and time style\n %s\n", 116ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru myErrorName(status) ); 117ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return; 118ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 119ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 120ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 121ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /*Testing udat_getAvailable() and udat_countAvailable()*/ 122ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("\nTesting getAvailableLocales and countAvailable()\n"); 123ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru numlocales=udat_countAvailable(); 124ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* use something sensible w/o hardcoding the count */ 125ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(numlocales < 0) 126ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_data_err("FAIL: error in countAvailable\n"); 127ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("The number of locales for which date/time formatting patterns are available is %d\n", numlocales); 128ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 129ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru for(i=0;i<numlocales;i++) { 130ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UErrorCode subStatus = U_ZERO_ERROR; 131ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("Testing open of %s\n", udat_getAvailable(i)); 132ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru any = udat_open(UDAT_SHORT, UDAT_SHORT, udat_getAvailable(i), NULL ,0, NULL, 0, &subStatus); 133ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_FAILURE(subStatus)) { 134ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_data_err("FAIL: date format %s (getAvailable(%d)) is not instantiable: %s\n", udat_getAvailable(i), i, u_errorName(subStatus)); 135ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 136ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru udat_close(any); 137ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 138ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 139ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /*Testing udat_clone()*/ 140ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("\nTesting the udat_clone() function of date format\n"); 141ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru copy=udat_clone(def, &status); 142ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_FAILURE(status)){ 143ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("Error in creating the clone using udat_clone: %s\n", myErrorName(status) ); 144ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 145ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /*if(def != copy) 146ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("Error in udat_clone");*/ /*how should i check for equality???? */ 147ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 148ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /*Testing udat_format()*/ 149ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("\nTesting the udat_format() function of date format\n"); 150ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru u_uastrcpy(temp, "7/10/96 4:05 PM"); 151ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /*format using def */ 152ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru resultlength=0; 153ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru resultlengthneeded=udat_format(def, d, NULL, resultlength, NULL, &status); 154ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(status==U_BUFFER_OVERFLOW_ERROR) 155ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 156ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru status=U_ZERO_ERROR; 157ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru resultlength=resultlengthneeded+1; 158ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(result != NULL) { 159ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru free(result); 160ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru result = NULL; 161ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 162ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru result=(UChar*)malloc(sizeof(UChar) * resultlength); 163ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru udat_format(def, d, result, resultlength, NULL, &status); 164ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 165ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_FAILURE(status) || !result) 166ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 167ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("FAIL: Error in formatting using udat_format(.....) %s\n", myErrorName(status) ); 168ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return; 169ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 170ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru else 171ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("PASS: formatting successful\n"); 172ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(u_strcmp(result, temp)==0) 17385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_verbose("PASS: Date Format for US locale successful using udat_format()\n"); 17485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho else { 17585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho char xbuf[2048]; 17685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho char gbuf[2048]; 17785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho u_austrcpy(xbuf, temp); 17885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho u_austrcpy(gbuf, result); 17985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_err("FAIL: Date Format for US locale failed using udat_format() - expected %s got %s\n", xbuf, gbuf); 18085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho } 181ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /*format using fr */ 182ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 18385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho u_unescape("10 juil. 1996 16:05:28 heure avanc\\u00E9e du Pacifique", temp, 50); 184ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(result != NULL) { 185ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru free(result); 186ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru result = NULL; 187ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 188ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru result=myDateFormat(fr, d); 189ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(u_strcmp(result, temp)==0) 190ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("PASS: Date Format for french locale successful using udat_format()\n"); 191ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru else 192ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_data_err("FAIL: Date Format for french locale failed using udat_format().\n" ); 193ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 194ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /*format using it */ 19585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho u_uastrcpy(temp, "10/lug/1996 16.05.28"); 196ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 197ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 198ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UChar *fmtted; 199ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru char g[100]; 200ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru char x[100]; 201ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 202ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru fmtted = myDateFormat(it,d); 203ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru u_austrcpy(g, fmtted); 204ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru u_austrcpy(x, temp); 205ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(u_strcmp(fmtted, temp)==0) { 206ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("PASS: Date Format for italian locale successful uisng udat_format() - wanted %s, got %s\n", x, g); 207ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } else { 208ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_data_err("FAIL: Date Format for italian locale failed using udat_format() - wanted %s, got %s\n", x, g); 209ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 210ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 211ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 212ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /*Testing parsing using udat_parse()*/ 213ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("\nTesting parsing using udat_parse()\n"); 214ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru u_uastrcpy(temp,"2/3/76 2:50 AM"); 215ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru parsepos=0; 216ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru status=U_ZERO_ERROR; 217ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 218ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru d1=udat_parse(def, temp, u_strlen(temp), &parsepos, &status); 219ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_FAILURE(status)) 220ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 221ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("FAIL: Error in parsing using udat_parse(.....) %s\n", myErrorName(status) ); 222ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 223ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru else 224ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("PASS: parsing succesful\n"); 225ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /*format it back and check for equality */ 226ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 227ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 228ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(u_strcmp(myDateFormat(def, d1),temp)!=0) 229ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("FAIL: error in parsing\n"); 230ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 231ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /*Testing parsing using udat_parse()*/ 232ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("\nTesting parsing using udat_parse()\n"); 233ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru u_uastrcpy(temp,"2/Don't parse this part"); 234ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru status=U_ZERO_ERROR; 235ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 236ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru d1=udat_parse(def, temp, u_strlen(temp), NULL, &status); 237ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(status != U_PARSE_ERROR) 238ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 239ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("FAIL: udat_parse(\"bad string\") passed when it should have failed\n"); 240ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 241ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru else 242ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("PASS: parsing succesful\n"); 243ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 244ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 245ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 246ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /*Testing udat_openPattern() */ 247ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru status=U_ZERO_ERROR; 248ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("\nTesting the udat_openPattern with a specified pattern\n"); 249ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /*for french locale */ 250ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru fr_pat=udat_open(UDAT_IGNORE, UDAT_IGNORE,"fr_FR",NULL,0,temp, u_strlen(temp), &status); 251ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_FAILURE(status)) 252ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 253ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("FAIL: Error in creating a date format using udat_openPattern \n %s\n", 254ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru myErrorName(status) ); 255ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 256ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru else 257ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("PASS: creating dateformat using udat_openPattern() succesful\n"); 258ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 259ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 260ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /*Testing applyPattern and toPattern */ 261ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("\nTesting applyPattern and toPattern()\n"); 262ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru udat_applyPattern(def1, FALSE, temp, u_strlen(temp)); 263ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("Extracting the pattern\n"); 264ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 265ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru resultlength=0; 266ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru resultlengthneeded=udat_toPattern(def1, FALSE, NULL, resultlength, &status); 267ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(status==U_BUFFER_OVERFLOW_ERROR) 268ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 269ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru status=U_ZERO_ERROR; 270ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru resultlength=resultlengthneeded + 1; 271ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru result=(UChar*)malloc(sizeof(UChar) * resultlength); 272ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru udat_toPattern(def1, FALSE, result, resultlength, &status); 273ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 274ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_FAILURE(status)) 275ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 276ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("FAIL: error in extracting the pattern from UNumberFormat\n %s\n", 277ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru myErrorName(status) ); 278ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 279ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(u_strcmp(result, temp)!=0) 280ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("FAIL: Error in extracting the pattern\n"); 281ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru else 282ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("PASS: applyPattern and toPattern work fine\n"); 283ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 284ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(result != NULL) { 285ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru free(result); 286ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru result = NULL; 287ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 288ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 289ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 290ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /*Testing getter and setter functions*/ 291ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /*isLenient and setLenient()*/ 292ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("\nTesting the isLenient and setLenient properties\n"); 293ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru udat_setLenient(fr, udat_isLenient(it)); 294ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(udat_isLenient(fr) != udat_isLenient(it)) 295ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("ERROR: setLenient() failed\n"); 296ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru else 297ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("PASS: setLenient() successful\n"); 298ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 299ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 300ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /*Test get2DigitYearStart set2DigitYearStart */ 301ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("\nTesting the get and set 2DigitYearStart properties\n"); 302ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru d1= udat_get2DigitYearStart(fr_pat,&status); 303ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_FAILURE(status)) { 304ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("ERROR: udat_get2DigitYearStart failed %s\n", myErrorName(status) ); 305ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 306ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru status = U_ZERO_ERROR; 307ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru udat_set2DigitYearStart(def1 ,d1, &status); 308ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_FAILURE(status)) { 309ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("ERROR: udat_set2DigitYearStart failed %s\n", myErrorName(status) ); 310ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 311ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(udat_get2DigitYearStart(fr_pat, &status) != udat_get2DigitYearStart(def1, &status)) 312ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("FAIL: error in set2DigitYearStart\n"); 313ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru else 314ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("PASS: set2DigitYearStart successful\n"); 315ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /*try setting it to another value */ 316ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru udat_set2DigitYearStart(de, 2000.0, &status); 317ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_FAILURE(status)){ 318ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("ERROR: udat_set2DigitYearStart failed %s\n", myErrorName(status) ); 319ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 320ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(udat_get2DigitYearStart(de, &status) != 2000) 321ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("FAIL: error in set2DigitYearStart\n"); 322ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru else 323ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("PASS: set2DigitYearStart successful\n"); 324ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 325ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 326ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 327ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /*Test getNumberFormat() and setNumberFormat() */ 328ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("\nTesting the get and set NumberFormat properties of date format\n"); 329ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru numformat1=udat_getNumberFormat(fr_pat); 330ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru udat_setNumberFormat(def1, numformat1); 331ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru numformat2=udat_getNumberFormat(def1); 332ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(u_strcmp(myNumformat(numformat1, num), myNumformat(numformat2, num)) !=0) 333ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("FAIL: error in setNumberFormat or getNumberFormat()\n"); 334ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru else 335ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("PASS:setNumberFormat and getNumberFormat succesful\n"); 336ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 337ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /*try setting the number format to another format */ 338ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru numformat1=udat_getNumberFormat(def); 339ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru udat_setNumberFormat(def1, numformat1); 340ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru numformat2=udat_getNumberFormat(def1); 341ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(u_strcmp(myNumformat(numformat1, num), myNumformat(numformat2, num)) !=0) 342ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("FAIL: error in setNumberFormat or getNumberFormat()\n"); 343ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru else 344ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("PASS: setNumberFormat and getNumberFormat succesful\n"); 345ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 346ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 347ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 348ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /*Test getCalendar and setCalendar*/ 349ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("\nTesting the udat_getCalendar() and udat_setCalendar() properties\n"); 350ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru cal=udat_getCalendar(fr_pat); 351ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 352ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 353ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru udat_setCalendar(def1, cal); 354ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(!ucal_equivalentTo(udat_getCalendar(fr_pat), udat_getCalendar(def1))) 355ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("FAIL: Error in setting and getting the calendar\n"); 356ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru else 357ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("PASS: getting and setting calendar successful\n"); 358ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 359ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(result!=NULL) { 360ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru free(result); 361ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 362ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 363ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /*Closing the UDateForamt */ 364ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru udat_close(def); 365ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru udat_close(fr); 366ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru udat_close(it); 367ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru udat_close(de); 368ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru udat_close(def1); 369ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru udat_close(fr_pat); 370ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru udat_close(copy); 371ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 372ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ctest_resetTimeZone(); 373ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 374ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 37585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho/* 37685bf2e2fbc60a9f938064abc8127d61da7d19882Claire HoTest combined relative date formatting (relative date + non-relative time). 37785bf2e2fbc60a9f938064abc8127d61da7d19882Claire HoThis is a bit tricky since we can't have static test data for comparison, the 37885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Horelative date formatting is relative to the time the tests are run. We generate 37985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Hothe data for comparison dynamically. However, the tests could fail if they are 38085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Horun right at midnight Pacific time and the call to ucal_getNow() is before midnight 38185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Howhile the calls to udat_format are after midnight or span midnight. 38285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho*/ 38385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Hostatic const UDate dayInterval = 24.0*60.0*60.0*1000.0; 38485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Hostatic const UChar trdfZone[] = { 0x0055, 0x0053, 0x002F, 0x0050, 0x0061, 0x0063, 0x0069, 0x0066, 0x0069, 0x0063, 0 }; /* US/Pacific */ 38585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Hostatic const char trdfLocale[] = "en_US"; 38685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Hostatic const UChar minutesPatn[] = { 0x006D, 0x006D, 0 }; /* "mm" */ 38785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Hostatic const UChar monthLongPatn[] = { 0x004D, 0x004D, 0x004D, 0x004D, 0 }; /* "MMMM" */ 38885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Hostatic const UChar monthMediumPatn[] = { 0x004D, 0x004D, 0x004D, 0 }; /* "MMM" */ 38985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Hostatic const UChar monthShortPatn[] = { 0x004D, 0 }; /* "M" */ 39085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Hostatic const UDateFormatStyle dateStylesList[] = { UDAT_FULL, UDAT_LONG, UDAT_MEDIUM, UDAT_SHORT, UDAT_NONE }; 39185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Hostatic const UChar *monthPatnsList[] = { monthLongPatn, monthLongPatn, monthMediumPatn, monthShortPatn, NULL }; 39285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Hostatic const UChar newTimePatn[] = { 0x0048, 0x0048, 0x002C, 0x006D, 0x006D, 0 }; /* "HH,mm" */ 39385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Hostatic const UChar minutesStr[] = { 0x0034, 0x0039, 0 }; /* "49", minutes string to search for in output */ 39485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Hoenum { kDateOrTimeOutMax = 96, kDateAndTimeOutMax = 192 }; 39585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 39685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Hostatic void TestRelativeDateFormat() 39785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho{ 39885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho UDate today = 0.0; 39985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho const UDateFormatStyle * stylePtr; 40085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho const UChar ** monthPtnPtr; 40185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho UErrorCode status = U_ZERO_ERROR; 40285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho UCalendar * ucal = ucal_open(trdfZone, -1, trdfLocale, UCAL_GREGORIAN, &status); 40385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho if ( U_SUCCESS(status) ) { 40485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho int32_t year, month, day; 40585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho ucal_setMillis(ucal, ucal_getNow(), &status); 40685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho year = ucal_get(ucal, UCAL_YEAR, &status); 40785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho month = ucal_get(ucal, UCAL_MONTH, &status); 40885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho day = ucal_get(ucal, UCAL_DATE, &status); 40985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho ucal_setDateTime(ucal, year, month, day, 18, 49, 0, &status); /* set to today at 18:49:00 */ 41085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho today = ucal_getMillis(ucal, &status); 41185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho ucal_close(ucal); 41285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho } 41385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho if ( U_FAILURE(status) || today == 0.0 ) { 41485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_err("Generate UDate for a specified time today fails, error %s\n", myErrorName(status) ); 41585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho return; 41685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho } 41785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho for (stylePtr = dateStylesList, monthPtnPtr = monthPatnsList; *stylePtr != UDAT_NONE; ++stylePtr, ++monthPtnPtr) { 41885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho UDateFormat* fmtRelDateTime; 41985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho UDateFormat* fmtRelDate; 42085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho UDateFormat* fmtTime; 42185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho int32_t dayOffset, limit; 42285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho UFieldPosition fp; 42385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho UChar strDateTime[kDateAndTimeOutMax]; 42485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho UChar strDate[kDateOrTimeOutMax]; 42585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho UChar strTime[kDateOrTimeOutMax]; 42685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho UChar * strPtr; 42785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho int32_t dtpatLen; 42885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 42985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho fmtRelDateTime = udat_open(UDAT_SHORT, *stylePtr | UDAT_RELATIVE, trdfLocale, trdfZone, -1, NULL, 0, &status); 43085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho if ( U_FAILURE(status) ) { 43185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_data_err("udat_open timeStyle SHORT dateStyle (%d | UDAT_RELATIVE) fails, error %s (Are you missing data?)\n", *stylePtr, myErrorName(status) ); 43285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho continue; 43385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho } 43485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho fmtRelDate = udat_open(UDAT_NONE, *stylePtr | UDAT_RELATIVE, trdfLocale, trdfZone, -1, NULL, 0, &status); 43585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho if ( U_FAILURE(status) ) { 43685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_err("udat_open timeStyle NONE dateStyle (%d | UDAT_RELATIVE) fails, error %s\n", *stylePtr, myErrorName(status) ); 43785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho udat_close(fmtRelDateTime); 43885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho continue; 43985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho } 44085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho fmtTime = udat_open(UDAT_SHORT, UDAT_NONE, trdfLocale, trdfZone, -1, NULL, 0, &status); 44185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho if ( U_FAILURE(status) ) { 44285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_err("udat_open timeStyle SHORT dateStyle NONE fails, error %s\n", myErrorName(status) ); 44385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho udat_close(fmtRelDateTime); 44485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho udat_close(fmtRelDate); 44585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho continue; 44685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho } 44785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 44885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho dtpatLen = udat_toPatternRelativeDate(fmtRelDateTime, strDate, kDateAndTimeOutMax, &status); 44985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho if ( U_FAILURE(status) ) { 45085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_err("udat_toPatternRelativeDate timeStyle SHORT dateStyle (%d | UDAT_RELATIVE) fails, error %s\n", *stylePtr, myErrorName(status) ); 45185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho status = U_ZERO_ERROR; 45285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho } else if ( u_strstr(strDate, *monthPtnPtr) == NULL || dtpatLen != u_strlen(strDate) ) { 45385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_err("udat_toPatternRelativeDate timeStyle SHORT dateStyle (%d | UDAT_RELATIVE) date pattern incorrect\n", *stylePtr ); 45485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho } 45585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho dtpatLen = udat_toPatternRelativeTime(fmtRelDateTime, strTime, kDateAndTimeOutMax, &status); 45685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho if ( U_FAILURE(status) ) { 45785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_err("udat_toPatternRelativeTime timeStyle SHORT dateStyle (%d | UDAT_RELATIVE) fails, error %s\n", *stylePtr, myErrorName(status) ); 45885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho status = U_ZERO_ERROR; 45985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho } else if ( u_strstr(strTime, minutesPatn) == NULL || dtpatLen != u_strlen(strTime) ) { 46085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_err("udat_toPatternRelativeTime timeStyle SHORT dateStyle (%d | UDAT_RELATIVE) time pattern incorrect\n", *stylePtr ); 46185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho } 46285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho dtpatLen = udat_toPattern(fmtRelDateTime, FALSE, strDateTime, kDateAndTimeOutMax, &status); 46385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho if ( U_FAILURE(status) ) { 46485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_err("udat_toPattern timeStyle SHORT dateStyle (%d | UDAT_RELATIVE) fails, error %s\n", *stylePtr, myErrorName(status) ); 46585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho status = U_ZERO_ERROR; 46685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho } else if ( u_strstr(strDateTime, strDate) == NULL || u_strstr(strDateTime, strTime) == NULL || dtpatLen != u_strlen(strDateTime) ) { 46785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_err("udat_toPattern timeStyle SHORT dateStyle (%d | UDAT_RELATIVE) dateTime pattern incorrect\n", *stylePtr ); 46885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho } 46985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho udat_applyPatternRelative(fmtRelDateTime, strDate, u_strlen(strDate), newTimePatn, u_strlen(newTimePatn), &status); 47085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho if ( U_FAILURE(status) ) { 47185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_err("udat_applyPatternRelative timeStyle SHORT dateStyle (%d | UDAT_RELATIVE) fails, error %s\n", *stylePtr, myErrorName(status) ); 47285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho status = U_ZERO_ERROR; 47385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho } else { 47485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho udat_toPattern(fmtRelDateTime, FALSE, strDateTime, kDateAndTimeOutMax, &status); 47585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho if ( U_FAILURE(status) ) { 47685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_err("udat_toPattern timeStyle SHORT dateStyle (%d | UDAT_RELATIVE) fails, error %s\n", *stylePtr, myErrorName(status) ); 47785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho status = U_ZERO_ERROR; 47885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho } else if ( u_strstr(strDateTime, newTimePatn) == NULL ) { 47985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_err("udat_applyPatternRelative timeStyle SHORT dateStyle (%d | UDAT_RELATIVE) didn't update time pattern\n", *stylePtr ); 48085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho } 48185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho } 48285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho udat_applyPatternRelative(fmtRelDateTime, strDate, u_strlen(strDate), strTime, u_strlen(strTime), &status); /* restore original */ 48385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 48485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho fp.field = UDAT_MINUTE_FIELD; 48585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho for (dayOffset = -2, limit = 2; dayOffset <= limit; ++dayOffset) { 48685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho UDate dateToUse = today + (float)dayOffset*dayInterval; 48785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 48885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho udat_format(fmtRelDateTime, dateToUse, strDateTime, kDateAndTimeOutMax, &fp, &status); 48985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho if ( U_FAILURE(status) ) { 49085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_err("udat_format timeStyle SHORT dateStyle (%d | UDAT_RELATIVE) fails, error %s\n", *stylePtr, myErrorName(status) ); 49185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho status = U_ZERO_ERROR; 49285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho } else { 49385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho udat_format(fmtRelDate, dateToUse, strDate, kDateOrTimeOutMax, NULL, &status); 49485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho if ( U_FAILURE(status) ) { 49585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_err("udat_format timeStyle NONE dateStyle (%d | UDAT_RELATIVE) fails, error %s\n", *stylePtr, myErrorName(status) ); 49685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho status = U_ZERO_ERROR; 49785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho } else if ( u_strstr(strDateTime, strDate) == NULL ) { 49885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_err("relative date string not found in udat_format timeStyle SHORT dateStyle (%d | UDAT_RELATIVE)\n", *stylePtr ); 49985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho } 50085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 50185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho udat_format(fmtTime, dateToUse, strTime, kDateOrTimeOutMax, NULL, &status); 50285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho if ( U_FAILURE(status) ) { 50385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_err("udat_format timeStyle SHORT dateStyle NONE fails, error %s\n", myErrorName(status) ); 50485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho status = U_ZERO_ERROR; 50585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho } else if ( u_strstr(strDateTime, strTime) == NULL ) { 50685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_err("time string not found in udat_format timeStyle SHORT dateStyle (%d | UDAT_RELATIVE)\n", *stylePtr ); 50785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho } 50885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 50985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho strPtr = u_strstr(strDateTime, minutesStr); 51085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho if ( strPtr != NULL ) { 51185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho int32_t beginIndex = strPtr - strDateTime; 51285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho if ( fp.beginIndex != beginIndex ) { 51385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_err("UFieldPosition beginIndex %d, expected %d, in udat_format timeStyle SHORT dateStyle (%d | UDAT_RELATIVE)\n", fp.beginIndex, beginIndex, *stylePtr ); 51485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho } 51585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho } else { 51685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_err("minutes string not found in udat_format timeStyle SHORT dateStyle (%d | UDAT_RELATIVE)\n", *stylePtr ); 51785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho } 51885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho } 51985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho } 52085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 52185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho udat_close(fmtRelDateTime); 52285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho udat_close(fmtRelDate); 52385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho udat_close(fmtTime); 52485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho } 52585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho} 52685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 527ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/*Testing udat_getSymbols() and udat_setSymbols() and udat_countSymbols()*/ 528ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void TestSymbols() 529ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{ 530ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UDateFormat *def, *fr; 531ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UErrorCode status = U_ZERO_ERROR; 532ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UChar *value=NULL; 533ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UChar *result = NULL; 534ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t resultlength; 535ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t resultlengthout; 536ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UChar *pattern; 537ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 538ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 539ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /*creating a dateformat with french locale */ 540ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("\ncreating a date format with french locale\n"); 541ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru fr = udat_open(UDAT_FULL, UDAT_DEFAULT, "fr_FR", NULL, 0, NULL, 0, &status); 542ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_FAILURE(status)) 543ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 54485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_data_err("error in creating the dateformat using full time style with french locale -> %s (Are you missing data?)\n", 545ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru myErrorName(status) ); 546ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return; 547ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 548ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /*creating a default dateformat */ 549ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("\ncreating a date format with default locale\n"); 550ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* this is supposed to open default date format, but later on it treats it like it is "en_US" 551ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru - very bad if you try to run the tests on machine where default locale is NOT "en_US" */ 552ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* def = udat_open(UDAT_DEFAULT,UDAT_DEFAULT ,NULL, NULL, 0, &status); */ 553ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru def = udat_open(UDAT_DEFAULT,UDAT_DEFAULT ,"en_US", NULL, 0, NULL, 0, &status); 554ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_FAILURE(status)) 555ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 556ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("error in creating the dateformat using short date and time style\n %s\n", 557ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru myErrorName(status) ); 558ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return; 559ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 560ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 561ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 562ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /*Testing countSymbols, getSymbols and setSymbols*/ 563ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("\nTesting countSymbols\n"); 564ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /*since the month names has the last string empty and week names are 1 based 1.e first string in the weeknames array is empty */ 565ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(udat_countSymbols(def, UDAT_ERAS)!=2 || udat_countSymbols(def, UDAT_MONTHS)!=12 || 566ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru udat_countSymbols(def, UDAT_SHORT_MONTHS)!=12 || udat_countSymbols(def, UDAT_WEEKDAYS)!=8 || 567ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru udat_countSymbols(def, UDAT_SHORT_WEEKDAYS)!=8 || udat_countSymbols(def, UDAT_AM_PMS)!=2 || 568ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru udat_countSymbols(def, UDAT_QUARTERS) != 4 || udat_countSymbols(def, UDAT_SHORT_QUARTERS) != 4 || 569ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru udat_countSymbols(def, UDAT_LOCALIZED_CHARS)!=1) 570ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 571ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("FAIL: error in udat_countSymbols\n"); 572ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 573ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru else 574ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("PASS: udat_countSymbols() successful\n"); 575ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 576ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /*testing getSymbols*/ 577ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("\nTesting getSymbols\n"); 578ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru pattern=(UChar*)malloc(sizeof(UChar) * 10); 579ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru u_uastrcpy(pattern, "jeudi"); 580ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru resultlength=0; 581ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru resultlengthout=udat_getSymbols(fr, UDAT_WEEKDAYS, 5 , NULL, resultlength, &status); 582ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(status==U_BUFFER_OVERFLOW_ERROR) 583ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 584ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru status=U_ZERO_ERROR; 585ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru resultlength=resultlengthout+1; 586ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(result != NULL) { 587ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru free(result); 588ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru result = NULL; 589ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 590ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru result=(UChar*)malloc(sizeof(UChar) * resultlength); 591ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru udat_getSymbols(fr, UDAT_WEEKDAYS, 5, result, resultlength, &status); 592ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 593ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 594ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_FAILURE(status)) 595ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 596ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("FAIL: Error in udat_getSymbols().... %s\n", myErrorName(status) ); 597ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 598ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru else 599ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("PASS: getSymbols succesful\n"); 600ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 601ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(u_strcmp(result, pattern)==0) 602ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("PASS: getSymbols retrieved the right value\n"); 603ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru else 604ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_data_err("FAIL: getSymbols retrieved the wrong value\n"); 605ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 606ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /*run series of tests to test getsymbols regressively*/ 607ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("\nTesting getSymbols() regressively\n"); 608ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru VerifygetSymbols(fr, UDAT_WEEKDAYS, 1, "dimanche"); 609ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru VerifygetSymbols(def, UDAT_WEEKDAYS, 1, "Sunday"); 610ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru VerifygetSymbols(fr, UDAT_SHORT_WEEKDAYS, 7, "sam."); 611ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru VerifygetSymbols(def, UDAT_SHORT_WEEKDAYS, 7, "Sat"); 612ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru VerifygetSymbols(def, UDAT_MONTHS, 11, "December"); 613ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru VerifygetSymbols(def, UDAT_MONTHS, 0, "January"); 614ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru VerifygetSymbols(fr, UDAT_ERAS, 0, "av. J.-C."); 615ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru VerifygetSymbols(def, UDAT_AM_PMS, 0, "AM"); 616ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru VerifygetSymbols(def, UDAT_AM_PMS, 1, "PM"); 617ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru VerifygetSymbols(fr, UDAT_SHORT_MONTHS, 0, "janv."); 618ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru VerifygetSymbols(def, UDAT_SHORT_MONTHS, 11, "Dec"); 619ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru VerifygetSymbols(fr, UDAT_QUARTERS, 0, "1er trimestre"); 620ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru VerifygetSymbols(def, UDAT_QUARTERS, 3, "4th quarter"); 621ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru VerifygetSymbols(fr, UDAT_SHORT_QUARTERS, 1, "T2"); 622ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru VerifygetSymbols(def, UDAT_SHORT_QUARTERS, 2, "Q3"); 623ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru VerifygetSymbols(def,UDAT_LOCALIZED_CHARS, 0, "GyMdkHmsSEDFwWahKzYeugAZvcLQqV"); 624ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 625ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 626ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(result != NULL) { 627ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru free(result); 628ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru result = NULL; 629ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 630ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querufree(pattern); 631ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 632ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("\nTesting setSymbols\n"); 633ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /*applying the pattern so that setSymbolss works */ 634ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru resultlength=0; 635ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru resultlengthout=udat_toPattern(fr, FALSE, NULL, resultlength, &status); 636ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(status==U_BUFFER_OVERFLOW_ERROR) 637ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 638ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru status=U_ZERO_ERROR; 639ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru resultlength=resultlengthout + 1; 640ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru pattern=(UChar*)malloc(sizeof(UChar) * resultlength); 641ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru udat_toPattern(fr, FALSE, pattern, resultlength, &status); 642ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 643ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_FAILURE(status)) 644ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 645ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("FAIL: error in extracting the pattern from UNumberFormat\n %s\n", 646ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru myErrorName(status) ); 647ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 648ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 649ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru udat_applyPattern(def, FALSE, pattern, u_strlen(pattern)); 650ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru resultlength=0; 651ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru resultlengthout=udat_toPattern(def, FALSE, NULL, resultlength,&status); 652ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(status==U_BUFFER_OVERFLOW_ERROR) 653ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 654ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru status=U_ZERO_ERROR; 655ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru resultlength=resultlengthout + 1; 656ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(result != NULL) { 657ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru free(result); 658ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru result = NULL; 659ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 660ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru result=(UChar*)malloc(sizeof(UChar) * resultlength); 661ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru udat_toPattern(fr, FALSE,result, resultlength, &status); 662ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 663ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_FAILURE(status)) 664ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 665ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("FAIL: error in extracting the pattern from UNumberFormat\n %s\n", 666ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru myErrorName(status) ); 667ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 668ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(u_strcmp(result, pattern)==0) 669ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("Pattern applied properly\n"); 670ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru else 671ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("pattern could not be applied properly\n"); 672ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 673ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querufree(pattern); 674ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /*testing set symbols */ 675ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru resultlength=0; 676ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru resultlengthout=udat_getSymbols(fr, UDAT_MONTHS, 11 , NULL, resultlength, &status); 677ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(status==U_BUFFER_OVERFLOW_ERROR){ 678ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru status=U_ZERO_ERROR; 679ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru resultlength=resultlengthout+1; 680ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(result != NULL) { 681ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru free(result); 682ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru result = NULL; 683ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 684ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru result=(UChar*)malloc(sizeof(UChar) * resultlength); 685ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru udat_getSymbols(fr, UDAT_MONTHS, 11, result, resultlength, &status); 686ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 687ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 688ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_FAILURE(status)) 689ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("FAIL: error in getSymbols() %s\n", myErrorName(status) ); 690ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru resultlength=resultlengthout+1; 691ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 692ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru udat_setSymbols(def, UDAT_MONTHS, 11, result, resultlength, &status); 693ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_FAILURE(status)) 694ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 695ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("FAIL: Error in udat_setSymbols() : %s\n", myErrorName(status) ); 696ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 697ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru else 698ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("PASS: SetSymbols successful\n"); 699ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 700ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru resultlength=0; 701ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru resultlengthout=udat_getSymbols(def, UDAT_MONTHS, 11, NULL, resultlength, &status); 702ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(status==U_BUFFER_OVERFLOW_ERROR){ 703ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru status=U_ZERO_ERROR; 704ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru resultlength=resultlengthout+1; 705ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru value=(UChar*)malloc(sizeof(UChar) * resultlength); 706ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru udat_getSymbols(def, UDAT_MONTHS, 11, value, resultlength, &status); 707ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 708ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_FAILURE(status)) 709ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("FAIL: error in retrieving the value using getSymbols i.e roundtrip\n"); 710ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 711ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(u_strcmp(result, value)!=0) 712ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_data_err("FAIL: Error in settting and getting symbols\n"); 713ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru else 714ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("PASS: setSymbols successful\n"); 715ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 716ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 717ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /*run series of tests to test setSymbols regressively*/ 718ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("\nTesting setSymbols regressively\n"); 719ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru VerifysetSymbols(def, UDAT_ERAS, 0, "BeforeChrist"); 720ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru VerifysetSymbols(def, UDAT_ERA_NAMES, 1, "AnnoDomini"); 721ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru VerifysetSymbols(def, UDAT_WEEKDAYS, 1, "Sundayweek"); 722ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru VerifysetSymbols(def, UDAT_SHORT_WEEKDAYS, 7, "Satweek"); 723ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru VerifysetSymbols(def, UDAT_NARROW_WEEKDAYS, 4, "M"); 724ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru VerifysetSymbols(def, UDAT_STANDALONE_WEEKDAYS, 1, "Sonntagweek"); 725ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru VerifysetSymbols(def, UDAT_STANDALONE_SHORT_WEEKDAYS, 7, "Sams"); 726ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru VerifysetSymbols(def, UDAT_STANDALONE_NARROW_WEEKDAYS, 4, "V"); 727ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru VerifysetSymbols(fr, UDAT_MONTHS, 11, "december"); 728ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru VerifysetSymbols(fr, UDAT_SHORT_MONTHS, 0, "Jan"); 729ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru VerifysetSymbols(fr, UDAT_NARROW_MONTHS, 1, "R"); 730ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru VerifysetSymbols(fr, UDAT_STANDALONE_MONTHS, 11, "dezember"); 731ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru VerifysetSymbols(fr, UDAT_STANDALONE_SHORT_MONTHS, 7, "Aug"); 732ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru VerifysetSymbols(fr, UDAT_STANDALONE_NARROW_MONTHS, 2, "M"); 733ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru VerifysetSymbols(fr, UDAT_QUARTERS, 0, "1. Quart"); 734ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru VerifysetSymbols(fr, UDAT_SHORT_QUARTERS, 1, "QQ2"); 735ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru VerifysetSymbols(fr, UDAT_STANDALONE_QUARTERS, 2, "3rd Quar."); 736ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru VerifysetSymbols(fr, UDAT_STANDALONE_SHORT_QUARTERS, 3, "4QQ"); 737ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 738ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 739ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /*run series of tests to test get and setSymbols regressively*/ 740ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("\nTesting get and set symbols regressively\n"); 741ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru VerifygetsetSymbols(fr, def, UDAT_WEEKDAYS, 1); 742ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru VerifygetsetSymbols(fr, def, UDAT_WEEKDAYS, 7); 743ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru VerifygetsetSymbols(fr, def, UDAT_SHORT_WEEKDAYS, 1); 744ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru VerifygetsetSymbols(fr, def, UDAT_SHORT_WEEKDAYS, 7); 745ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru VerifygetsetSymbols(fr, def, UDAT_MONTHS, 0); 746ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru VerifygetsetSymbols(fr, def, UDAT_SHORT_MONTHS, 0); 747ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru VerifygetsetSymbols(fr, def, UDAT_ERAS,1); 748ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru VerifygetsetSymbols(fr, def, UDAT_LOCALIZED_CHARS, 0); 749ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru VerifygetsetSymbols(fr, def, UDAT_AM_PMS, 1); 750ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 751ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 752ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /*closing*/ 753ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 754ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru udat_close(fr); 755ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru udat_close(def); 756ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(result != NULL) { 757ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru free(result); 758ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru result = NULL; 759ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 760ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru free(value); 761ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 762ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 763ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 764ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/** 765ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * Test DateFormat(Calendar) API 766ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 767ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void TestDateFormatCalendar() { 768ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UDateFormat *date=0, *time=0, *full=0; 769ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UCalendar *cal=0; 770ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UChar buf[256]; 771ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru char cbuf[256]; 772ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t pos; 773ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UDate when; 774ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UErrorCode ec = U_ZERO_ERROR; 775ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 776ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ctest_setTimeZone(NULL, &ec); 777ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 778ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* Create a formatter for date fields. */ 779ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru date = udat_open(UDAT_NONE, UDAT_SHORT, "en_US", NULL, 0, NULL, 0, &ec); 780ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (U_FAILURE(ec)) { 78185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_data_err("FAIL: udat_open(NONE, SHORT, en_US) failed with %s (Are you missing data?)\n", 782ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru u_errorName(ec)); 783ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru goto FAIL; 784ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 785ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 786ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* Create a formatter for time fields. */ 787ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru time = udat_open(UDAT_SHORT, UDAT_NONE, "en_US", NULL, 0, NULL, 0, &ec); 788ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (U_FAILURE(ec)) { 789ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("FAIL: udat_open(SHORT, NONE, en_US) failed with %s\n", 790ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru u_errorName(ec)); 791ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru goto FAIL; 792ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 793ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 794ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* Create a full format for output */ 795ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru full = udat_open(UDAT_FULL, UDAT_FULL, "en_US", NULL, 0, NULL, 0, &ec); 796ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (U_FAILURE(ec)) { 797ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("FAIL: udat_open(FULL, FULL, en_US) failed with %s\n", 798ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru u_errorName(ec)); 799ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru goto FAIL; 800ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 801ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 802ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* Create a calendar */ 803ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru cal = ucal_open(NULL, 0, "en_US", UCAL_GREGORIAN, &ec); 804ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (U_FAILURE(ec)) { 805ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("FAIL: ucal_open(en_US) failed with %s\n", 806ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru u_errorName(ec)); 807ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru goto FAIL; 808ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 809ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 810ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* Parse the date */ 811ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucal_clear(cal); 812ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru u_uastrcpy(buf, "4/5/2001"); 813ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru pos = 0; 814ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru udat_parseCalendar(date, cal, buf, -1, &pos, &ec); 815ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (U_FAILURE(ec)) { 816ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("FAIL: udat_parseCalendar(4/5/2001) failed at %d with %s\n", 817ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru pos, u_errorName(ec)); 818ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru goto FAIL; 819ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 820ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 821ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* Parse the time */ 822ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru u_uastrcpy(buf, "5:45 PM"); 823ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru pos = 0; 824ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru udat_parseCalendar(time, cal, buf, -1, &pos, &ec); 825ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (U_FAILURE(ec)) { 826ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("FAIL: udat_parseCalendar(17:45) failed at %d with %s\n", 827ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru pos, u_errorName(ec)); 828ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru goto FAIL; 829ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 830ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 831ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* Check result */ 832ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru when = ucal_getMillis(cal, &ec); 833ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (U_FAILURE(ec)) { 834ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("FAIL: ucal_getMillis() failed with %s\n", u_errorName(ec)); 835ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru goto FAIL; 836ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 837ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru udat_format(full, when, buf, sizeof(buf), NULL, &ec); 838ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (U_FAILURE(ec)) { 839ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("FAIL: udat_format() failed with %s\n", u_errorName(ec)); 840ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru goto FAIL; 841ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 842ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru u_austrcpy(cbuf, buf); 843ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* Thursday, April 5, 2001 5:45:00 PM PDT 986517900000 */ 844ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (when == 986517900000.0) { 845ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("Ok: Parsed result: %s\n", cbuf); 846ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } else { 847ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("FAIL: Parsed result: %s, exp 4/5/2001 5:45 PM\n", cbuf); 848ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 849ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 850ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru FAIL: 851ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru udat_close(date); 852ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru udat_close(time); 853ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru udat_close(full); 854ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucal_close(cal); 855ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 856ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ctest_resetTimeZone(); 857ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 858ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 859ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/*INTERNAL FUNCTIONS USED*/ 86085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho/* N.B.: use idx instead of index to avoid 'shadow' warnings in strict mode. */ 86185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Hostatic void VerifygetSymbols(UDateFormat* datfor, UDateFormatSymbolType type, int32_t idx, const char* expected) 862ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{ 863ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UChar *pattern=NULL; 864ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UErrorCode status = U_ZERO_ERROR; 865ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UChar *result=NULL; 866ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t resultlength, resultlengthout; 867ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 868ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 869ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru pattern=(UChar*)malloc(sizeof(UChar) * (strlen(expected)+1)); 870ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru u_uastrcpy(pattern, expected); 871ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru resultlength=0; 87285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho resultlengthout=udat_getSymbols(datfor, type, idx , NULL, resultlength, &status); 873ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(status==U_BUFFER_OVERFLOW_ERROR) 874ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 875ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru status=U_ZERO_ERROR; 876ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru resultlength=resultlengthout+1; 877ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru result=(UChar*)malloc(sizeof(UChar) * resultlength); 87885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho udat_getSymbols(datfor, type, idx, result, resultlength, &status); 879ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 880ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 881ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_FAILURE(status)) 882ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 883ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("FAIL: Error in udat_getSymbols()... %s\n", myErrorName(status) ); 884ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return; 885ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 886ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(u_strcmp(result, pattern)==0) 887ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("PASS: getSymbols retrieved the right value\n"); 888ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru else{ 889ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_data_err("FAIL: getSymbols retrieved the wrong value\n Expected %s Got %s\n", austrdup(pattern), 890ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru austrdup(result) ); 891ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 892ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru free(result); 893ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru free(pattern); 894ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 895ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 89685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Hostatic void VerifysetSymbols(UDateFormat* datfor, UDateFormatSymbolType type, int32_t idx, const char* expected) 897ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{ 898ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UChar *result=NULL; 899ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UChar *value=NULL; 900ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t resultlength, resultlengthout; 901ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UErrorCode status = U_ZERO_ERROR; 902ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 903ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru value=(UChar*)malloc(sizeof(UChar) * (strlen(expected) + 1)); 904ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru u_uastrcpy(value, expected); 90585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho udat_setSymbols(datfor, type, idx, value, u_strlen(value), &status); 906ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_FAILURE(status)) 907ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 908ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("FAIL: Error in udat_setSymbols() %s\n", myErrorName(status) ); 909ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return; 910ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 911ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 912ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru resultlength=0; 91385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho resultlengthout=udat_getSymbols(datfor, type, idx, NULL, resultlength, &status); 914ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(status==U_BUFFER_OVERFLOW_ERROR){ 915ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru status=U_ZERO_ERROR; 916ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru resultlength=resultlengthout+1; 917ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru result=(UChar*)malloc(sizeof(UChar) * resultlength); 91885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho udat_getSymbols(datfor, type, idx, result, resultlength, &status); 919ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 920ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_FAILURE(status)){ 921ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("FAIL: error in retrieving the value using getSymbols after setting it previously\n %s\n", 922ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru myErrorName(status) ); 923ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return; 924ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 925ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 926ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(u_strcmp(result, value)!=0){ 927ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("FAIL:Error in setting and then getting symbols\n Expected %s Got %s\n", austrdup(value), 928ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru austrdup(result) ); 929ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 930ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru else 931ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("PASS: setSymbols successful\n"); 932ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 933ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru free(value); 934ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru free(result); 935ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 936ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 937ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 93885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Hostatic void VerifygetsetSymbols(UDateFormat* from, UDateFormat* to, UDateFormatSymbolType type, int32_t idx) 939ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{ 940ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UChar *result=NULL; 941ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UChar *value=NULL; 942ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t resultlength, resultlengthout; 943ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UErrorCode status = U_ZERO_ERROR; 944ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 945ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru resultlength=0; 94685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho resultlengthout=udat_getSymbols(from, type, idx , NULL, resultlength, &status); 947ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(status==U_BUFFER_OVERFLOW_ERROR){ 948ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru status=U_ZERO_ERROR; 949ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru resultlength=resultlengthout+1; 950ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru result=(UChar*)malloc(sizeof(UChar) * resultlength); 95185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho udat_getSymbols(from, type, idx, result, resultlength, &status); 952ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 953ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_FAILURE(status)){ 954ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("FAIL: error in getSymbols() %s\n", myErrorName(status) ); 955ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return; 956ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 957ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 958ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru resultlength=resultlengthout+1; 95985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho udat_setSymbols(to, type, idx, result, resultlength, &status); 960ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_FAILURE(status)) 961ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 962ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("FAIL: Error in udat_setSymbols() : %s\n", myErrorName(status) ); 963ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return; 964ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 965ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 966ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru resultlength=0; 96785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho resultlengthout=udat_getSymbols(to, type, idx, NULL, resultlength, &status); 968ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(status==U_BUFFER_OVERFLOW_ERROR){ 969ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru status=U_ZERO_ERROR; 970ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru resultlength=resultlengthout+1; 971ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru value=(UChar*)malloc(sizeof(UChar) * resultlength); 97285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho udat_getSymbols(to, type, idx, value, resultlength, &status); 973ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 974ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_FAILURE(status)){ 975ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("FAIL: error in retrieving the value using getSymbols i.e roundtrip\n %s\n", 976ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru myErrorName(status) ); 977ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return; 978ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 979ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 980ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(u_strcmp(result, value)!=0){ 981ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_data_err("FAIL:Error in setting and then getting symbols\n Expected %s Got %s\n", austrdup(result), 982ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru austrdup(value) ); 983ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 984ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru else 985ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("PASS: setSymbols successful\n"); 986ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 987ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru free(value); 988ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru free(result); 989ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 990ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 991ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 992ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic UChar* myNumformat(const UNumberFormat* numfor, double d) 993ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{ 994ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UChar *result2=NULL; 995ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t resultlength, resultlengthneeded; 996ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UErrorCode status = U_ZERO_ERROR; 997ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 998ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru resultlength=0; 999ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru resultlengthneeded=unum_formatDouble(numfor, d, NULL, resultlength, NULL, &status); 1000ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(status==U_BUFFER_OVERFLOW_ERROR) 1001ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1002ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru status=U_ZERO_ERROR; 1003ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru resultlength=resultlengthneeded+1; 1004ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /*result2=(UChar*)malloc(sizeof(UChar) * resultlength);*/ /* this leaks */ 1005ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru result2=(UChar*)ctst_malloc(sizeof(UChar) * resultlength); /*this won't*/ 1006ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru unum_formatDouble(numfor, d, result2, resultlength, NULL, &status); 1007ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1008ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_FAILURE(status)) 1009ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1010ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("FAIL: Error in formatting using unum_format(.....) %s\n", myErrorName(status) ); 1011ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return 0; 1012ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1013ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1014ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return result2; 1015ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 1016ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1017ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/** 1018ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * The search depth for TestExtremeDates. The total number of 1019ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * dates that will be tested is (2^EXTREME_DATES_DEPTH) - 1. 1020ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 1021ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#define EXTREME_DATES_DEPTH 8 1022ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1023ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/** 1024ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * Support for TestExtremeDates (below). 1025ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * 1026ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * Test a single date to see whether udat_format handles it properly. 1027ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 1028ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic UBool _aux1ExtremeDates(UDateFormat* fmt, UDate date, 1029ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UChar* buf, int32_t buflen, char* cbuf, 1030ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UErrorCode* ec) { 1031ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t len = udat_format(fmt, date, buf, buflen, 0, ec); 1032ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (!assertSuccess("udat_format", ec)) return FALSE; 1033ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru u_austrncpy(cbuf, buf, buflen); 1034ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (len < 4) { 1035ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("FAIL: udat_format(%g) => \"%s\"\n", date, cbuf); 1036ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } else { 1037ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("udat_format(%g) => \"%s\"\n", date, cbuf); 1038ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1039ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return TRUE; 1040ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 1041ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1042ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/** 1043ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * Support for TestExtremeDates (below). 1044ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * 1045ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * Recursively test between 'small' and 'large', up to the depth 1046ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * limit specified by EXTREME_DATES_DEPTH. 1047ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 1048ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic UBool _aux2ExtremeDates(UDateFormat* fmt, UDate small, UDate large, 1049ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UChar* buf, int32_t buflen, char* cbuf, 1050ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t count, 1051ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UErrorCode* ec) { 1052ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* Logarithmic midpoint; see below */ 1053ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UDate mid = (UDate) exp((log(small) + log(large)) / 2); 1054ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (count == EXTREME_DATES_DEPTH) { 1055ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return TRUE; 1056ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1057ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return 1058ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru _aux1ExtremeDates(fmt, mid, buf, buflen, cbuf, ec) && 1059ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru _aux2ExtremeDates(fmt, small, mid, buf, buflen, cbuf, count+1, ec) && 1060ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru _aux2ExtremeDates(fmt, mid, large, buf, buflen, cbuf, count+1, ec); 1061ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 1062ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1063ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/** 1064ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * http://www.jtcsv.com/cgibin/icu-bugs?findid=3659 1065ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * 1066ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * For certain large dates, udat_format crashes on MacOS. This test 1067ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * attempts to reproduce this problem by doing a recursive logarithmic* 1068ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * binary search of a predefined interval (from 'small' to 'large'). 1069ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * 1070ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * The limit of the search is given by EXTREME_DATES_DEPTH, above. 1071ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * 1072ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * *The search has to be logarithmic, not linear. A linear search of the 1073ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * range 0..10^30, for example, will find 0.5*10^30, then 0.25*10^30 and 1074ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * 0.75*10^30, etc. A logarithmic search will find 10^15, then 10^7.5 1075ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * and 10^22.5, etc. 1076ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 1077ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void TestExtremeDates() { 1078ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UDateFormat *fmt; 1079ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UErrorCode ec; 1080ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UChar buf[256]; 1081ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru char cbuf[256]; 1082ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const double small = 1000; /* 1 sec */ 1083ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const double large = 1e+30; /* well beyond usable UDate range */ 1084ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1085ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* There is no need to test larger values from 1e+30 to 1e+300; 1086ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru the failures occur around 1e+27, and never above 1e+30. */ 1087ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1088ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ec = U_ZERO_ERROR; 1089ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru fmt = udat_open(UDAT_LONG, UDAT_LONG, "en_US", 1090ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 0, 0, 0, 0, &ec); 109185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho if (U_FAILURE(ec)) { 109285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_data_err("FAIL: udat_open (%s) (Are you missing data?)\n", u_errorName(ec)); 109385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho return; 109485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho } 1095ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1096ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru _aux2ExtremeDates(fmt, small, large, buf, LEN(buf), cbuf, 0, &ec); 1097ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1098ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru udat_close(fmt); 1099ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 1100ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1101ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void TestAllLocales(void) { 1102ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t idx, dateIdx, timeIdx, localeCount; 1103ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru static const UDateFormatStyle style[] = { 1104ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UDAT_FULL, UDAT_LONG, UDAT_MEDIUM, UDAT_SHORT 1105ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru }; 1106ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru localeCount = uloc_countAvailable(); 1107ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru for (idx = 0; idx < localeCount; idx++) { 1108ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru for (dateIdx = 0; dateIdx < (int32_t)(sizeof(style)/sizeof(style[0])); dateIdx++) { 1109ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru for (timeIdx = 0; timeIdx < (int32_t)(sizeof(style)/sizeof(style[0])); timeIdx++) { 1110ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UErrorCode status = U_ZERO_ERROR; 1111ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru udat_close(udat_open(style[dateIdx], style[timeIdx], 1112ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uloc_getAvailable(idx), NULL, 0, NULL, 0, &status)); 1113ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (U_FAILURE(status)) { 1114ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("FAIL: udat_open(%s) failed with (%s) dateIdx=%d, timeIdx=%d\n", 1115ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uloc_getAvailable(idx), u_errorName(status), dateIdx, timeIdx); 1116ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1117ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1118ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1119ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1120ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 1121ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 112285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Hostatic void TestRelativeCrash(void) { 112385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho static const UChar tzName[] = { 0x0055, 0x0053, 0x002F, 0x0050, 0x0061, 0x0063, 0x0069, 0x0066, 0x0069, 0x0063, 0 }; 112485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho static const UDate aDate = -631152000000.0; 112585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 112685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho UErrorCode status = U_ZERO_ERROR; 112785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho UErrorCode expectStatus = U_ILLEGAL_ARGUMENT_ERROR; 112885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho UDateFormat icudf; 112985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 113085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho icudf = udat_open(UDAT_NONE, UDAT_SHORT_RELATIVE, "en", tzName, -1, NULL, 0, &status); 113185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho if ( U_SUCCESS(status) ) { 113285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho const char *what = "???"; 113385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho { 113485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho UErrorCode subStatus = U_ZERO_ERROR; 113585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho what = "udat_set2DigitYearStart"; 113685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_verbose("Trying %s on a relative date..\n", what); 113785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho udat_set2DigitYearStart(icudf, aDate, &subStatus); 113885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho if(subStatus == expectStatus) { 113985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_verbose("Success: did not crash on %s, but got %s.\n", what, u_errorName(subStatus)); 114085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho } else { 114185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_err("FAIL: didn't crash on %s, but got success %s instead of %s. \n", what, u_errorName(subStatus), u_errorName(expectStatus)); 114285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho } 114385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho } 114485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho { 114585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho /* clone works polymorphically. try it anyways */ 114685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho UErrorCode subStatus = U_ZERO_ERROR; 114785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho UDateFormat *oth; 114885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho what = "clone"; 114985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_verbose("Trying %s on a relative date..\n", what); 115085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho oth = udat_clone(icudf, &subStatus); 115185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho if(subStatus == U_ZERO_ERROR) { 115285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_verbose("Success: did not crash on %s, but got %s.\n", what, u_errorName(subStatus)); 115385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho udat_close(oth); /* ? */ 115485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho } else { 115585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_err("FAIL: didn't crash on %s, but got %s instead of %s. \n", what, u_errorName(subStatus), u_errorName(expectStatus)); 115685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho } 115785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho } 115885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho { 115985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho UErrorCode subStatus = U_ZERO_ERROR; 116085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho what = "udat_get2DigitYearStart"; 116185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_verbose("Trying %s on a relative date..\n", what); 116285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho udat_get2DigitYearStart(icudf, &subStatus); 116385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho if(subStatus == expectStatus) { 116485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_verbose("Success: did not crash on %s, but got %s.\n", what, u_errorName(subStatus)); 116585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho } else { 116685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_err("FAIL: didn't crash on %s, but got success %s instead of %s. \n", what, u_errorName(subStatus), u_errorName(expectStatus)); 116785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho } 116885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho } 116985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho { 117085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho /* Now udat_toPattern works for relative date formatters, unless localized is TRUE */ 117185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho UErrorCode subStatus = U_ZERO_ERROR; 117285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho what = "udat_toPattern"; 117385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_verbose("Trying %s on a relative date..\n", what); 117485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho udat_toPattern(icudf, TRUE,NULL,0, &subStatus); 117585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho if(subStatus == expectStatus) { 117685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_verbose("Success: did not crash on %s, but got %s.\n", what, u_errorName(subStatus)); 117785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho } else { 117885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_err("FAIL: didn't crash on %s, but got success %s instead of %s. \n", what, u_errorName(subStatus), u_errorName(expectStatus)); 117985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho } 118085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho } 118185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho { 118285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho UErrorCode subStatus = U_ZERO_ERROR; 118385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho what = "udat_applyPattern"; 118485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_verbose("Trying %s on a relative date..\n", what); 118585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho udat_applyPattern(icudf, FALSE,tzName,-1); 118685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho subStatus = U_ILLEGAL_ARGUMENT_ERROR; /* what it should be, if this took an errorcode. */ 118785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho if(subStatus == expectStatus) { 118885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_verbose("Success: did not crash on %s, but got %s.\n", what, u_errorName(subStatus)); 118985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho } else { 119085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_err("FAIL: didn't crash on %s, but got success %s instead of %s. \n", what, u_errorName(subStatus), u_errorName(expectStatus)); 119185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho } 119285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho } 119385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho { 119485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho UErrorCode subStatus = U_ZERO_ERROR; 119585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho what = "udat_getSymbols"; 119685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_verbose("Trying %s on a relative date..\n", what); 119785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho udat_getSymbols(icudf, UDAT_ERAS,0,NULL,0, &subStatus); /* bogus values */ 119885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho if(subStatus == expectStatus) { 119985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_verbose("Success: did not crash on %s, but got %s.\n", what, u_errorName(subStatus)); 120085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho } else { 120185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_err("FAIL: didn't crash on %s, but got success %s instead of %s. \n", what, u_errorName(subStatus), u_errorName(expectStatus)); 120285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho } 120385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho } 120485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho { 120585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho UErrorCode subStatus = U_ZERO_ERROR; 120685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho what = "udat_countSymbols"; 120785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_verbose("Trying %s on a relative date..\n", what); 120885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho udat_countSymbols(icudf, UDAT_ERAS); 120985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho subStatus = U_ILLEGAL_ARGUMENT_ERROR; /* should have an errorcode. */ 121085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho if(subStatus == expectStatus) { 121185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_verbose("Success: did not crash on %s, but got %s.\n", what, u_errorName(subStatus)); 121285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho } else { 121385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_err("FAIL: didn't crash on %s, but got success %s instead of %s. \n", what, u_errorName(subStatus), u_errorName(expectStatus)); 121485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho } 121585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho } 121685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 121785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho udat_close(icudf); 121885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho } else { 121985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_data_err("FAIL: err calling udat_open() ->%s (Are you missing data?)\n", u_errorName(status)); 122085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho } 122185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho} 122285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 1223ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#endif /* #if !UCONFIG_NO_FORMATTING */ 1224