]> git.saurik.com Git - apple/icu.git/blame - icuSources/test/cintltst/ctstdep.c
ICU-8.11.tar.gz
[apple/icu.git] / icuSources / test / cintltst / ctstdep.c
CommitLineData
b75a7d8f
A
1/********************************************************************
2 * COPYRIGHT:
3 * Copyright (c) 1997-2003, International Business Machines Corporation and
4 * others. All Rights Reserved.
5 ********************************************************************/
6/********************************************************************************
7 *
8 * File CTSTDEP.C
9 *
10 * Modification History:
11 * Name Description
12 * Ram Viswanadha Creation
13 *
14 * Test for deprecated formatting APIs.
15 *
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 *********************************************************************************
21 */
22
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"
28#include <string.h>
29#include "cintltst.h"
30#include <stdlib.h>
31#include <stdio.h>
32
33
34#ifdef U_USE_DEPRECATED_FORMAT_API
35static void TestDeprecatedNumFmtAPI(void);
36static void TestDeprecatedDateFmtAPI(void);
37static void TestDeprecatedUErrorCode(void);
38static void TestDeprecatedUCharScript(void);
39#endif
40
41void addTestDeprecatedAPI(TestNode** root);
42
43void
44addTestDeprecatedAPI(TestNode** root)
45{
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");
51#endif
52}
53
54#ifdef U_USE_DEPRECATED_FORMAT_API
55/*
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
58 */
59
60static void
61TestDeprecatedNumFmtAPI(void)
62{
63 int32_t pat_length, i, lneed;
64 UNumberFormat *fmt;
65 UChar upat[5];
66 UChar unewpat[5];
67 UChar unum[5];
68 UChar *unewp=NULL;
69 UChar *str=NULL;
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" };
74
75 log_verbose("\nTesting different format patterns\n");
76 pat_length = sizeof(pat) / sizeof(pat[0]);
77 for (i=0; i < pat_length; ++i)
78 {
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]);
84 continue;
85 }
86 lneed=0;
87 lneed=unum_toPattern(fmt, FALSE, NULL, lneed, &status);
88 if(status==U_BUFFER_OVERFLOW_ERROR){
89 status= U_ZERO_ERROR;
90 unewp=(UChar*)malloc(sizeof(UChar) * (lneed+1) );
91 unum_toPattern(fmt, FALSE, unewp, lneed+1, &status);
92 }
93 if(U_FAILURE(status)){
94 log_err("FAIL: Number format extracting the pattern failed for %s\n", pat[i]);
95 }
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) );
99
100 lneed=0;
101 lneed=unum_format(fmt, 0, NULL, lneed, NULL, &status);
102 if(status==U_BUFFER_OVERFLOW_ERROR){
103 status=U_ZERO_ERROR;
104 str=(UChar*)malloc(sizeof(UChar) * (lneed+1) );
105 unum_format(fmt, 0, str, lneed+1, NULL, &status);
106 }
107 if(U_FAILURE(status)) {
108 log_err("Error in formatting using unum_format(.....): %s\n", myErrorName(status) );
109 }
110 u_uastrcpy(unum, num[i]);
111 if (u_strcmp(str, unum) != 0)
112 {
113 log_err("FAIL: Pattern %s should format zero as %s; %s Seen instead\n", pat[i], num[i], austrdup(str) );
114 }
115 free(unewp);
116 free(str);
117 unum_close(fmt);
118 }
119
120 {
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;
124 UChar *res=NULL;
125 UFieldPosition pos;
126 status = U_ZERO_ERROR;
127 log_verbose("\nTesting the number format with different currency patterns\n");
128 for(i=0; i < 3; i++)
129 {
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));
134 }
135 lneed=0;
136 lneed= unum_formatDouble(currencyFmt, 1.50, NULL, lneed, NULL, &status);
137 if(status==U_BUFFER_OVERFLOW_ERROR){
138 status=U_ZERO_ERROR;
139 str=(UChar*)malloc(sizeof(UChar) * (lneed+1) );
140 pos.field = 0;
141 unum_formatDouble(currencyFmt, 1.50, str, lneed+1, &pos, &status);
142 }
143 if(U_FAILURE(status)) {
144 log_err("Error in formatting using unum_formatDouble(.....): %s\n", myErrorName(status) );
145 }
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);
151 free(str);
152 free(res);
153 }
154 }
155}
156
157/*
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.
160 */
161static void
162TestDeprecatedDateFmtAPI(void)
163{
164 UDateFormat *def, *fr, *fr_pat ;
165 UErrorCode status = U_ZERO_ERROR;
166 UChar temp[30];
167
168 fr = udat_open(UDAT_FULL, UDAT_DEFAULT, "fr_FR", NULL,0, &status);
169 if(U_FAILURE(status))
170 {
171 log_err("FAIL: error in creating the dateformat using full time style with french locale\n %s\n",
172 myErrorName(status) );
173 }
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))
179 {
180 log_err("FAIL: error in creating the dateformat using short date and time style\n %s\n",
181 myErrorName(status) );
182 }
183
184 /*Testing udat_openPattern() */
185 status=U_ZERO_ERROR;
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))
190 {
191 log_err("FAIL: Error in creating a date format using udat_openPattern \n %s\n",
192 myErrorName(status) );
193 }
194 else
195 log_verbose("PASS: creating dateformat using udat_openPattern() succesful\n");
196
197 udat_close(fr);
198 udat_close(def);
199 udat_close(fr_pat);
200}
201
202static void
203TestDeprecatedUCharScript(void)
204{
205 const UCharScript scriptArray[] = {
206 /* Script names */
207 /** */
208 U_BASIC_LATIN,
209 /** */
210 U_LATIN_1_SUPPLEMENT,
211 /** */
212 U_LATIN_EXTENDED_A,
213 /** */
214 U_LATIN_EXTENDED_B,
215 /** */
216 U_IPA_EXTENSIONS,
217 /** */
218 U_SPACING_MODIFIER_LETTERS,
219 /** */
220 U_COMBINING_DIACRITICAL_MARKS,
221 /** */
222 U_GREEK,
223 /** */
224 U_CYRILLIC,
225 /** */
226 U_ARMENIAN,
227 /** */
228 U_HEBREW,
229 /** */
230 U_ARABIC,
231 /** */
232 U_SYRIAC,
233 /** */
234 U_THAANA,
235 /** */
236 U_DEVANAGARI,
237 /** */
238 U_BENGALI,
239 /** */
240 U_GURMUKHI,
241 /** */
242 U_GUJARATI,
243 /** */
244 U_ORIYA,
245 /** */
246 U_TAMIL,
247 /** */
248 U_TELUGU,
249 /** */
250 U_KANNADA,
251 /** */
252 U_MALAYALAM,
253 /** */
254 U_SINHALA,
255 /** */
256 U_THAI,
257 /** */
258 U_LAO,
259 /** */
260 U_TIBETAN,
261 /** */
262 U_MYANMAR,
263 /** */
264 U_GEORGIAN,
265 /** */
266 U_HANGUL_JAMO,
267 /** */
268 U_ETHIOPIC,
269 /** */
270 U_CHEROKEE,
271 /** */
272 U_UNIFIED_CANADIAN_ABORIGINAL_SYLLABICS,
273 /** */
274 U_OGHAM,
275 /** */
276 U_RUNIC,
277 /** */
278 U_KHMER,
279 /** */
280 U_MONGOLIAN,
281 /** */
282 U_LATIN_EXTENDED_ADDITIONAL,
283 /** */
284 U_GREEK_EXTENDED,
285 /** */
286 U_GENERAL_PUNCTUATION,
287 /** */
288 U_SUPERSCRIPTS_AND_SUBSCRIPTS,
289 /** */
290 U_CURRENCY_SYMBOLS,
291 /** */
292 U_COMBINING_MARKS_FOR_SYMBOLS,
293 /** */
294 U_LETTERLIKE_SYMBOLS,
295 /** */
296 U_NUMBER_FORMS,
297 /** */
298 U_ARROWS,
299 /** */
300 U_MATHEMATICAL_OPERATORS,
301 /** */
302 U_MISCELLANEOUS_TECHNICAL,
303 /** */
304 U_CONTROL_PICTURES,
305 /** */
306 U_OPTICAL_CHARACTER_RECOGNITION,
307 /** */
308 U_ENCLOSED_ALPHANUMERICS,
309 /** */
310 U_BOX_DRAWING,
311 /** */
312 U_BLOCK_ELEMENTS,
313 /** */
314 U_GEOMETRIC_SHAPES,
315 /** */
316 U_MISCELLANEOUS_SYMBOLS,
317 /** */
318 U_DINGBATS,
319 /** */
320 U_BRAILLE_PATTERNS,
321 /** */
322 U_CJK_RADICALS_SUPPLEMENT,
323 /** */
324 U_KANGXI_RADICALS,
325 /** */
326 U_IDEOGRAPHIC_DESCRIPTION_CHARACTERS,
327 /** */
328 U_CJK_SYMBOLS_AND_PUNCTUATION,
329 /** */
330 U_HIRAGANA,
331 /** */
332 U_KATAKANA,
333 /** */
334 U_BOPOMOFO,
335 /** */
336 U_HANGUL_COMPATIBILITY_JAMO,
337 /** */
338 U_KANBUN,
339 /** */
340 U_BOPOMOFO_EXTENDED,
341 /** */
342 U_ENCLOSED_CJK_LETTERS_AND_MONTHS,
343 /** */
344 U_CJK_COMPATIBILITY,
345 /** */
346 U_CJK_UNIFIED_IDEOGRAPHS_EXTENSION_A,
347 /** */
348 U_CJK_UNIFIED_IDEOGRAPHS,
349 /** */
350 U_YI_SYLLABLES,
351 /** */
352 U_YI_RADICALS,
353 /** */
354 U_HANGUL_SYLLABLES,
355 /** */
356 U_HIGH_SURROGATES,
357 /** */
358 U_HIGH_PRIVATE_USE_SURROGATES,
359 /** */
360 U_LOW_SURROGATES,
361 /** */
362 U_PRIVATE_USE_AREA,
363 /** */
364 U_CJK_COMPATIBILITY_IDEOGRAPHS,
365 /** */
366 U_ALPHABETIC_PRESENTATION_FORMS,
367 /** */
368 U_ARABIC_PRESENTATION_FORMS_A,
369 /** */
370 U_COMBINING_HALF_MARKS,
371 /** */
372 U_CJK_COMPATIBILITY_FORMS,
373 /** */
374 U_SMALL_FORM_VARIANTS,
375 /** */
376 U_ARABIC_PRESENTATION_FORMS_B,
377 /** */
378 U_SPECIALS,
379 /** */
380 U_HALFWIDTH_AND_FULLWIDTH_FORMS,
381 /** */
382 U_CHAR_SCRIPT_COUNT,
383 /** */
384 U_NO_SCRIPT
385 };
386 if (UBLOCK_BASIC_LATIN != scriptArray[0]) {
387 log_err("UBLOCK_BASIC_LATIN != U_BASIC_LATIN");
388 }
389}
390
391static void
392TestDeprecatedUErrorCode(void){
393 const UErrorCode code[]= {
394 U_ERROR_INFO_START,
395 U_USING_FALLBACK_ERROR,
396 U_USING_DEFAULT_ERROR,
397 U_SAFECLONE_ALLOCATED_ERROR,
398 U_ERROR_INFO_LIMIT,
399 U_ZERO_ERROR,
400 U_ILLEGAL_ARGUMENT_ERROR,
401 U_MISSING_RESOURCE_ERROR,
402 U_INVALID_FORMAT_ERROR,
403 U_FILE_ACCESS_ERROR,
404 U_INTERNAL_PROGRAM_ERROR,
405 U_MESSAGE_PARSE_ERROR,
406 U_MEMORY_ALLOCATION_ERROR,
407 U_INDEX_OUTOFBOUNDS_ERROR,
408 U_PARSE_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,
415 U_UNSUPPORTED_ERROR,
416 U_RESOURCE_TYPE_MISMATCH,
417 U_ILLEGAL_ESCAPE_SEQUENCE,
418 U_UNSUPPORTED_ESCAPE_SEQUENCE,
419 U_NO_SPACE_AVAILABLE,
420 U_ERROR_LIMIT,
421 };
422 if (U_USING_FALLBACK_WARNING != code[1]) {
423 log_err("U_USING_FALLBACK_WARNING != U_USING_FALLBACK_ERROR");
424 }
425}
426#endif