• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 Corporation and
6  * others. All Rights Reserved.
7  ********************************************************************/
8 
9 #ifndef _DATEFORMATTEST_
10 #define _DATEFORMATTEST_
11 
12 #include "unicode/utypes.h"
13 
14 #if !UCONFIG_NO_FORMATTING
15 
16 #include "unicode/datefmt.h"
17 #include "unicode/smpdtfmt.h"
18 #include "caltztst.h"
19 
20 /**
21  * Performs many different tests for DateFormat and SimpleDateFormat
22  **/
23 class DateFormatTest: public CalendarTimeZoneTest {
24     // IntlTest override
25     void runIndexedTest( int32_t index, UBool exec, const char* &name, char* par ) override;
26 public:
27     /**
28      * Verify that patterns have the correct values and could produce
29      * the DateFormat instances that contain the correct localized patterns.
30      */
31     void TestPatterns();
32     /**
33      *  "Test written by Wally Wedel and emailed to me."
34      *  Test handling of timezone offsets
35      **/
36     virtual void TestWallyWedel(void);
37     /**
38      * Test operator==
39      */
40     virtual void TestEquals(void);
41     /**
42      * Test the parsing of 2-digit years.
43      */
44     virtual void TestTwoDigitYearDSTParse(void);
45 
46 public: // package
47     // internal utility routine (generates escape sequences for characters)
48     static UnicodeString& escape(UnicodeString& s);
49 
50 public:
51     /**
52      * Verify that returned field position indices are correct.
53      */
54     void TestFieldPosition(void);
55 
56     void TestGeneral();
57 
58 public: // package
59     // internal utility function
60     static void getFieldText(DateFormat* df, int32_t field, UDate date, UnicodeString& str);
61 
62 public:
63     /**
64      * Verify that strings which contain incomplete specifications are parsed
65      * correctly.  In some instances, this means not being parsed at all, and
66      * returning an appropriate error.
67      */
68     virtual void TestPartialParse994(void);
69 
70 public: // package
71     // internal test subroutine, used by TestPartialParse994
72     virtual void tryPat994(SimpleDateFormat* format, const char* pat, const char* str, UDate expected);
73 
74 public:
75     /**
76      * Verify the behavior of patterns in which digits for different fields run together
77      * without intervening separators.
78      */
79     virtual void TestRunTogetherPattern985(void);
80     /**
81      * Verify the behavior of patterns in which digits for different fields run together
82      * without intervening separators.
83      */
84     virtual void TestRunTogetherPattern917(void);
85 
86 public: // package
87     // internal test subroutine, used by TestRunTogetherPattern917
88     virtual void testIt917(SimpleDateFormat* fmt, UnicodeString& str, UDate expected);
89 
90 public:
91     /**
92      * Verify the handling of Czech June and July, which have the unique attribute that
93      * one is a proper prefix substring of the other.
94      */
95     virtual void TestCzechMonths459(void);
96     /**
97      * Test the handling of 'D' in patterns.
98      */
99     virtual void TestLetterDPattern212(void);
100     /**
101      * Test the day of year pattern.
102      */
103     virtual void TestDayOfYearPattern195(void);
104 
105 public: // package
106     // interl test subroutine, used by TestDayOfYearPattern195
107     virtual void tryPattern(SimpleDateFormat& sdf, UDate d, const char* pattern, UDate expected);
108 
109 public:
110     /**
111      * Test the handling of single quotes in patterns.
112      */
113     virtual void TestQuotePattern161(void);
114     /**
115      * Verify the correct behavior when handling invalid input strings.
116      */
117     virtual void TestBadInput135(void);
118 
119 public:
120     /**
121      * Verify the correct behavior when parsing an array of inputs against an
122      * array of patterns, with known results.  The results are encoded after
123      * the input strings in each row.
124      */
125     virtual void TestBadInput135a(void);
126     /**
127      * Test the parsing of two-digit years.
128      */
129     virtual void TestTwoDigitYear(void);
130 
131 public: // package
132     // internal test subroutine, used by TestTwoDigitYear
133     virtual void parse2DigitYear(DateFormat& fmt, const char* str, UDate expected);
134 
135 public:
136     /**
137      * Test the formatting of time zones.
138      */
139     virtual void TestDateFormatZone061(void);
140     /**
141      * Further test the formatting of time zones.
142      */
143     virtual void TestDateFormatZone146(void);
144 
145     void TestTimeZoneStringsAPI(void);
146 
147     void TestGMTParsing(void);
148 
149 public: // package
150     /**
151      * Test the formatting of dates in different locales.
152      */
153     virtual void TestLocaleDateFormat(void);
154 
155     virtual void TestFormattingLocaleTimeSeparator(void);
156 
157     virtual void TestDateFormatCalendar(void);
158 
159     virtual void TestSpaceParsing(void);
160 
161     void TestExactCountFormat(void);
162 
163     void TestWhiteSpaceParsing(void);
164 
165     void TestInvalidPattern(void);
166 
167     void TestGreekMay(void);
168 
169     void TestGenericTime(void);
170 
171     void TestGenericTimeZoneOrder(void);
172 
173     void Test6338(void);
174 
175     void Test6726(void);
176 
177     void Test6880(void);
178 
179     void TestISOEra(void);
180 
181     void TestFormalChineseDate(void);
182 
183     void TestStandAloneGMTParse(void);
184 
185     void TestParsePosition(void);
186 
187     void TestMonthPatterns(void);
188 
189     void TestContext(void);
190 
191     void TestNonGregoFmtParse(void);
192 
193     void TestFormatsWithNumberSystems(void);
194 
195 public:
196     /**
197      * Test host-specific formatting.
198      */
199     void TestHost(void);
200 
201 public:
202     /**
203      * Test patterns added in CLDR 1.4, CLDR 23
204      */
205     void TestEras(void);
206 
207     void TestNarrowNames(void);
208 
209     void TestShortDays(void);
210 
211     void TestStandAloneDays(void);
212 
213     void TestStandAloneMonths(void);
214 
215     void TestQuarters(void);
216 
217     void TestZTimeZoneParsing(void);
218 
219     void TestRelativeClone(void);
220 
221     void TestHostClone(void);
222 
223     void TestHebrewClone(void);
224 
225     void TestDateFormatSymbolsClone(void);
226 
227     void TestTimeZoneDisplayName(void);
228 
229     void TestTimeZoneInLocale(void);
230 
231     void TestRoundtripWithCalendar(void);
232 
233 public:
234     /***
235      * Test Relative Dates
236      */
237      void TestRelative(void);
238 /*   void TestRelativeError(void);
239      void TestRelativeOther(void);
240 */
241 
242     void TestDotAndAtLeniency();
243 
244     void TestDateFormatLeniency();
245 
246     void TestParseMultiPatternMatch();
247 
248     void TestParseLeniencyAPIs();
249 
250     // test override NumberFormat
251     void TestNumberFormatOverride();
252     void TestCreateInstanceForSkeleton();
253     void TestCreateInstanceForSkeletonDefault();
254     void TestCreateInstanceForSkeletonWithCalendar();
255     void TestDFSCreateForLocaleNonGregorianLocale();
256     void TestDFSCreateForLocaleWithCalendarInLocale();
257     void TestChangeCalendar();
258 
259     void TestPatternFromSkeleton();
260 
261     void TestAmPmMidnightNoon();
262     void TestFlexibleDayPeriod();
263     void TestDayPeriodWithLocales();
264     void TestMinuteSecondFieldsInOddPlaces();
265     void TestDayPeriodParsing();
266     void TestParseRegression13744();
267     void TestAdoptCalendarLeak();
268     void Test20741_ABFields();
269     void Test22023_UTCWithMinusZero();
270 
271 private:
272     UBool showParse(DateFormat &format, const UnicodeString &formattedString);
273 
274 public:
275     /**
276      * Test parsing a number as a string
277      */
278     void TestNumberAsStringParsing(void);
279 
280  private:
281       void TestRelative(int daysdelta,
282                                   const Locale& loc,
283                                   const char *expectChars);
284 
285  private:
286     void expectParse(const char** data, int32_t data_length,
287                      const Locale& locale);
288 
289     void expect(const char** data, int32_t data_length,
290                 const Locale& loc);
291 
292     void expectFormat(const char **data, int32_t data_length,
293                       const Locale &locale);
294 
295 };
296 
297 #endif /* #if !UCONFIG_NO_FORMATTING */
298 
299 #endif // _DATEFORMATTEST_
300 //eof
301