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