1 /********************************************************************
3 * Copyright (c) 1997-2003, International Business Machines Corporation and
4 * others. All Rights Reserved.
5 ********************************************************************/
6 /********************************************************************************
10 * Modification History:
12 * Ram Viswanadha Creation
14 * Test for deprecated formatting APIs.
16 * Note: This test tests all deprecated C API which follow the method of application
17 * complication using preporcessor magic suggested by SRL.Compilation of this test
18 * will fail for every release when U_USE_DEPRECATED_FORMAT_API is set, as a reminder
19 * for updating macros for deprecated APIs and eventual removal of those APIs.
20 *********************************************************************************
23 #include "unicode/unum.h"
24 #include "unicode/udat.h"
25 #include "unicode/ustring.h"
26 #include "unicode/utrans.h"
27 #include "unicode/uchar.h"
34 #ifdef U_USE_DEPRECATED_FORMAT_API
35 static void TestDeprecatedNumFmtAPI(void);
36 static void TestDeprecatedDateFmtAPI(void);
37 static void TestDeprecatedUErrorCode(void);
38 static void TestDeprecatedUCharScript(void);
41 void addTestDeprecatedAPI(TestNode
** root
);
44 addTestDeprecatedAPI(TestNode
** root
)
46 #ifdef U_USE_DEPRECATED_FORMAT_API
47 addTest(root
, &TestDeprecatedNumFmtAPI
, "ctstdep/TestDeprecatedNumFmtAPI");
48 addTest(root
, &TestDeprecatedDateFmtAPI
, "ctstdep/TestDeprecatedDateFmtAPI");
49 addTest(root
, &TestDeprecatedUErrorCode
, "ctstdep/TestDeprecatedUErrorCode");
50 addTest(root
, &TestDeprecatedUCharScript
, "ctstdep/TestDeprecatedUCharScript");
54 #ifdef U_USE_DEPRECATED_FORMAT_API
56 *TODO: The unum_open,unum_applyPattern, which does not take UParseError as one of their params
57 *and unum_openPattern methods have been deprecated in 2.0 release.Please remove this API by 10/1/2002
61 TestDeprecatedNumFmtAPI(void)
63 int32_t pat_length
, i
, lneed
;
70 UErrorCode status
= U_ZERO_ERROR
;
71 const char* pat
[] = { "#.#", "#.", ".#", "#" };
72 const char* newpat
[] = { "#0.#", "#0.", "#.0", "#" };
73 const char* num
[] = { "0", "0.", ".0", "0" };
75 log_verbose("\nTesting different format patterns\n");
76 pat_length
= sizeof(pat
) / sizeof(pat
[0]);
77 for (i
=0; i
< pat_length
; ++i
)
79 status
= U_ZERO_ERROR
;
80 u_uastrcpy(upat
, pat
[i
]);
81 fmt
= unum_openPattern(upat
, u_strlen(upat
), "en_US", &status
);
82 if (U_FAILURE(status
)) {
83 log_err("FAIL: Number format constructor failed for pattern %s\n", pat
[i
]);
87 lneed
=unum_toPattern(fmt
, FALSE
, NULL
, lneed
, &status
);
88 if(status
==U_BUFFER_OVERFLOW_ERROR
){
90 unewp
=(UChar
*)malloc(sizeof(UChar
) * (lneed
+1) );
91 unum_toPattern(fmt
, FALSE
, unewp
, lneed
+1, &status
);
93 if(U_FAILURE(status
)){
94 log_err("FAIL: Number format extracting the pattern failed for %s\n", pat
[i
]);
96 u_uastrcpy(unewpat
, newpat
[i
]);
97 if(u_strcmp(unewp
, unewpat
) != 0)
98 log_err("FAIL: Pattern %s should be transmute to %s; %s seen instead\n", pat
[i
], newpat
[i
], austrdup(unewp
) );
101 lneed
=unum_format(fmt
, 0, NULL
, lneed
, NULL
, &status
);
102 if(status
==U_BUFFER_OVERFLOW_ERROR
){
104 str
=(UChar
*)malloc(sizeof(UChar
) * (lneed
+1) );
105 unum_format(fmt
, 0, str
, lneed
+1, NULL
, &status
);
107 if(U_FAILURE(status
)) {
108 log_err("Error in formatting using unum_format(.....): %s\n", myErrorName(status
) );
110 u_uastrcpy(unum
, num
[i
]);
111 if (u_strcmp(str
, unum
) != 0)
113 log_err("FAIL: Pattern %s should format zero as %s; %s Seen instead\n", pat
[i
], num
[i
], austrdup(str
) );
121 const char* locale
[]={"fr_CA", "de_DE_PREEURO", "fr_FR_PREEURO"};
122 const char* result
[]={"1,50 $", "1,50 DM", "1,50 F"};
123 UNumberFormat
*currencyFmt
;
126 status
= U_ZERO_ERROR
;
127 log_verbose("\nTesting the number format with different currency patterns\n");
130 currencyFmt
= unum_open(UNUM_CURRENCY
, locale
[i
], &status
);
131 if(U_FAILURE(status
)){
132 log_err("Error in the construction of number format with style currency:\n%s\n",
133 myErrorName(status
));
136 lneed
= unum_formatDouble(currencyFmt
, 1.50, NULL
, lneed
, NULL
, &status
);
137 if(status
==U_BUFFER_OVERFLOW_ERROR
){
139 str
=(UChar
*)malloc(sizeof(UChar
) * (lneed
+1) );
141 unum_formatDouble(currencyFmt
, 1.50, str
, lneed
+1, &pos
, &status
);
143 if(U_FAILURE(status
)) {
144 log_err("Error in formatting using unum_formatDouble(.....): %s\n", myErrorName(status
) );
146 res
=(UChar
*)malloc(sizeof(UChar
) * (strlen(result
[i
])+1) );
147 u_uastrcpy(res
, result
[i
]);
148 if (u_strcmp(str
, res
) != 0)
149 log_err("FAIL: Expected %s\n", result
[i
]);
150 unum_close(currencyFmt
);
158 *TODO: udat_open and udat_openPatterns methods have been unified and deprecated in 2.0 release.
159 *Please remove this API by 10/1/2002.
162 TestDeprecatedDateFmtAPI(void)
164 UDateFormat
*def
, *fr
, *fr_pat
;
165 UErrorCode status
= U_ZERO_ERROR
;
168 fr
= udat_open(UDAT_FULL
, UDAT_DEFAULT
, "fr_FR", NULL
,0, &status
);
169 if(U_FAILURE(status
))
171 log_err("FAIL: error in creating the dateformat using full time style with french locale\n %s\n",
172 myErrorName(status
) );
174 /* this is supposed to open default date format, but later on it treats it like it is "en_US"
175 - very bad if you try to run the tests on machine where default locale is NOT "en_US" */
176 /* def = udat_open(UDAT_SHORT, UDAT_SHORT, NULL, NULL, 0, &status); */
177 def
= udat_open(UDAT_SHORT
, UDAT_SHORT
, "en_US", NULL
, 0, &status
);
178 if(U_FAILURE(status
))
180 log_err("FAIL: error in creating the dateformat using short date and time style\n %s\n",
181 myErrorName(status
) );
184 /*Testing udat_openPattern() */
186 log_verbose("\nTesting the udat_openPattern with a specified pattern\n");
187 /*for french locale */
188 fr_pat
=udat_openPattern(temp
, u_strlen(temp
), "fr_FR", &status
);
189 if(U_FAILURE(status
))
191 log_err("FAIL: Error in creating a date format using udat_openPattern \n %s\n",
192 myErrorName(status
) );
195 log_verbose("PASS: creating dateformat using udat_openPattern() succesful\n");
203 TestDeprecatedUCharScript(void)
205 const UCharScript scriptArray
[] = {
210 U_LATIN_1_SUPPLEMENT
,
218 U_SPACING_MODIFIER_LETTERS
,
220 U_COMBINING_DIACRITICAL_MARKS
,
272 U_UNIFIED_CANADIAN_ABORIGINAL_SYLLABICS
,
282 U_LATIN_EXTENDED_ADDITIONAL
,
286 U_GENERAL_PUNCTUATION
,
288 U_SUPERSCRIPTS_AND_SUBSCRIPTS
,
292 U_COMBINING_MARKS_FOR_SYMBOLS
,
294 U_LETTERLIKE_SYMBOLS
,
300 U_MATHEMATICAL_OPERATORS
,
302 U_MISCELLANEOUS_TECHNICAL
,
306 U_OPTICAL_CHARACTER_RECOGNITION
,
308 U_ENCLOSED_ALPHANUMERICS
,
316 U_MISCELLANEOUS_SYMBOLS
,
322 U_CJK_RADICALS_SUPPLEMENT
,
326 U_IDEOGRAPHIC_DESCRIPTION_CHARACTERS
,
328 U_CJK_SYMBOLS_AND_PUNCTUATION
,
336 U_HANGUL_COMPATIBILITY_JAMO
,
342 U_ENCLOSED_CJK_LETTERS_AND_MONTHS
,
346 U_CJK_UNIFIED_IDEOGRAPHS_EXTENSION_A
,
348 U_CJK_UNIFIED_IDEOGRAPHS
,
358 U_HIGH_PRIVATE_USE_SURROGATES
,
364 U_CJK_COMPATIBILITY_IDEOGRAPHS
,
366 U_ALPHABETIC_PRESENTATION_FORMS
,
368 U_ARABIC_PRESENTATION_FORMS_A
,
370 U_COMBINING_HALF_MARKS
,
372 U_CJK_COMPATIBILITY_FORMS
,
374 U_SMALL_FORM_VARIANTS
,
376 U_ARABIC_PRESENTATION_FORMS_B
,
380 U_HALFWIDTH_AND_FULLWIDTH_FORMS
,
386 if (UBLOCK_BASIC_LATIN
!= scriptArray
[0]) {
387 log_err("UBLOCK_BASIC_LATIN != U_BASIC_LATIN");
392 TestDeprecatedUErrorCode(void){
393 const UErrorCode code
[]= {
395 U_USING_FALLBACK_ERROR
,
396 U_USING_DEFAULT_ERROR
,
397 U_SAFECLONE_ALLOCATED_ERROR
,
400 U_ILLEGAL_ARGUMENT_ERROR
,
401 U_MISSING_RESOURCE_ERROR
,
402 U_INVALID_FORMAT_ERROR
,
404 U_INTERNAL_PROGRAM_ERROR
,
405 U_MESSAGE_PARSE_ERROR
,
406 U_MEMORY_ALLOCATION_ERROR
,
407 U_INDEX_OUTOFBOUNDS_ERROR
,
409 U_INVALID_CHAR_FOUND
,
410 U_TRUNCATED_CHAR_FOUND
,
411 U_ILLEGAL_CHAR_FOUND
,
412 U_INVALID_TABLE_FORMAT
,
413 U_INVALID_TABLE_FILE
,
414 U_BUFFER_OVERFLOW_ERROR
,
416 U_RESOURCE_TYPE_MISMATCH
,
417 U_ILLEGAL_ESCAPE_SEQUENCE
,
418 U_UNSUPPORTED_ESCAPE_SEQUENCE
,
419 U_NO_SPACE_AVAILABLE
,
422 if (U_USING_FALLBACK_WARNING
!= code
[1]) {
423 log_err("U_USING_FALLBACK_WARNING != U_USING_FALLBACK_ERROR");