]> git.saurik.com Git - apple/icu.git/blob - icuSources/test/cintltst/cformtst.c
ICU-57132.0.1.tar.gz
[apple/icu.git] / icuSources / test / cintltst / cformtst.c
1 /********************************************************************
2 * COPYRIGHT:
3 * Copyright (c) 1997-2016, International Business Machines
4 * Corporation and others. All Rights Reserved.
5 ********************************************************************/
6 /********************************************************************************
7 *
8 * File CFORMTST.C
9 *
10 * Modification History:
11 * Name Description
12 * Madhu Katragadda Creation
13 *********************************************************************************
14 */
15
16 /* FormatTest is a medium top level test for everything in the C FORMAT API */
17
18 #include "unicode/utypes.h"
19
20 #if !UCONFIG_NO_FORMATTING
21
22 #include "cintltst.h"
23 #include "cformtst.h"
24
25 void addCalTest(TestNode**);
26 void addDateForTest(TestNode**);
27 void addDateTimePatternGeneratorTest(TestNode**);
28 void addDateIntervalFormatTest(TestNode**);
29 void addRelativeDateFormatTest(TestNode**);
30 void addNumForTest(TestNode**);
31 void addMsgForTest(TestNode**);
32 void addDateForRgrTest(TestNode**);
33 void addNumFrDepTest(TestNode**);
34 void addDtFrDepTest(TestNode**);
35 void addUtmsTest(TestNode**);
36 void addCurrencyTest(TestNode**);
37 void addPluralRulesTest(TestNode**);
38 void addURegionTest(TestNode** root);
39 void addUListFmtTest(TestNode** root);
40 void addMeasureFormatTest(TestNode** root);
41
42 void addFormatTest(TestNode** root);
43
44 void addFormatTest(TestNode** root)
45 {
46 addCalTest(root);
47 addDateForTest(root);
48 addDateTimePatternGeneratorTest(root);
49 addDateIntervalFormatTest(root);
50 #if !UCONFIG_NO_BREAK_ITERATION
51 addRelativeDateFormatTest(root);
52 #endif /* !UCONFIG_NO_BREAK_ITERATION */
53 addNumForTest(root);
54 addNumFrDepTest(root);
55 addMsgForTest(root);
56 addDateForRgrTest(root);
57 addDtFrDepTest(root);
58 addUtmsTest(root);
59 addCurrencyTest(root);
60 addPluralRulesTest(root);
61 addURegionTest(root);
62 addUListFmtTest(root);
63 addMeasureFormatTest(root);
64 }
65 /*Internal functions used*/
66
67 UChar* myDateFormat(UDateFormat* dat, UDate d1)
68 {
69 UChar *result1=NULL;
70 int32_t resultlength, resultlengthneeded;
71 UErrorCode status = U_ZERO_ERROR;
72
73
74 resultlength=0;
75 resultlengthneeded=udat_format(dat, d1, NULL, resultlength, NULL, &status);
76 if(status==U_BUFFER_OVERFLOW_ERROR)
77 {
78 status=U_ZERO_ERROR;
79 resultlength=resultlengthneeded+1;
80 result1=(UChar*)ctst_malloc(sizeof(UChar) * resultlength);
81 udat_format(dat, d1, result1, resultlength, NULL, &status);
82 }
83 if(U_FAILURE(status))
84 {
85 log_err("Error in formatting using udat_format(.....): %s\n", myErrorName(status));
86 return 0;
87 }
88 return result1;
89
90 }
91
92 #endif /* #if !UCONFIG_NO_FORMATTING */