• 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 *******************************************************************************
5 * Copyright (C) 2013-2016, International Business Machines Corporation and
6 * others. All Rights Reserved.
7 *******************************************************************************
8 *
9 * File RELDATEFMTTEST.CPP
10 *
11 *******************************************************************************
12 */
13 #include <memory>
14 #include <stdio.h>
15 #include <stdlib.h>
16 #include <vector>
17 
18 #include "intltest.h"
19 
20 #if !UCONFIG_NO_FORMATTING && !UCONFIG_NO_BREAK_ITERATION
21 
22 #include "unicode/localpointer.h"
23 #include "unicode/numfmt.h"
24 #include "unicode/reldatefmt.h"
25 #include "cmemory.h"
26 
27 static const char *DirectionStr(UDateDirection direction);
28 static const char *RelativeUnitStr(UDateRelativeUnit unit);
29 static const char *RelativeDateTimeUnitStr(URelativeDateTimeUnit unit);
30 static const char *AbsoluteUnitStr(UDateAbsoluteUnit unit);
31 
32 typedef struct WithQuantityExpected {
33     double value;
34     UDateDirection direction;
35     UDateRelativeUnit unit;
36     const char *expected;
37 } WithQuantityExpected;
38 
39 typedef struct WithoutQuantityExpected {
40     UDateDirection direction;
41     UDateAbsoluteUnit unit;
42     const char *expected;
43 } WithoutQuantityExpected;
44 
45 static WithQuantityExpected kEnglish[] = {
46         {0.0, UDAT_DIRECTION_NEXT, UDAT_RELATIVE_SECONDS, "in 0 seconds"},
47         {0.5, UDAT_DIRECTION_NEXT, UDAT_RELATIVE_SECONDS, "in 0.5 seconds"},
48         {1.0, UDAT_DIRECTION_NEXT, UDAT_RELATIVE_SECONDS, "in 1 second"},
49         {2.0, UDAT_DIRECTION_NEXT, UDAT_RELATIVE_SECONDS, "in 2 seconds"},
50         {0.0, UDAT_DIRECTION_NEXT, UDAT_RELATIVE_MINUTES, "in 0 minutes"},
51         {0.5, UDAT_DIRECTION_NEXT, UDAT_RELATIVE_MINUTES, "in 0.5 minutes"},
52         {1.0, UDAT_DIRECTION_NEXT, UDAT_RELATIVE_MINUTES, "in 1 minute"},
53         {2.0, UDAT_DIRECTION_NEXT, UDAT_RELATIVE_MINUTES, "in 2 minutes"},
54         {0.0, UDAT_DIRECTION_NEXT, UDAT_RELATIVE_HOURS, "in 0 hours"},
55         {0.5, UDAT_DIRECTION_NEXT, UDAT_RELATIVE_HOURS, "in 0.5 hours"},
56         {1.0, UDAT_DIRECTION_NEXT, UDAT_RELATIVE_HOURS, "in 1 hour"},
57         {2.0, UDAT_DIRECTION_NEXT, UDAT_RELATIVE_HOURS, "in 2 hours"},
58         {0.0, UDAT_DIRECTION_NEXT, UDAT_RELATIVE_DAYS, "in 0 days"},
59         {0.5, UDAT_DIRECTION_NEXT, UDAT_RELATIVE_DAYS, "in 0.5 days"},
60         {1.0, UDAT_DIRECTION_NEXT, UDAT_RELATIVE_DAYS, "in 1 day"},
61         {2.0, UDAT_DIRECTION_NEXT, UDAT_RELATIVE_DAYS, "in 2 days"},
62         {0.0, UDAT_DIRECTION_NEXT, UDAT_RELATIVE_WEEKS, "in 0 weeks"},
63         {0.5, UDAT_DIRECTION_NEXT, UDAT_RELATIVE_WEEKS, "in 0.5 weeks"},
64         {1.0, UDAT_DIRECTION_NEXT, UDAT_RELATIVE_WEEKS, "in 1 week"},
65         {2.0, UDAT_DIRECTION_NEXT, UDAT_RELATIVE_WEEKS, "in 2 weeks"},
66         {0.0, UDAT_DIRECTION_NEXT, UDAT_RELATIVE_MONTHS, "in 0 months"},
67         {0.5, UDAT_DIRECTION_NEXT, UDAT_RELATIVE_MONTHS, "in 0.5 months"},
68         {1.0, UDAT_DIRECTION_NEXT, UDAT_RELATIVE_MONTHS, "in 1 month"},
69         {2.0, UDAT_DIRECTION_NEXT, UDAT_RELATIVE_MONTHS, "in 2 months"},
70         {0.0, UDAT_DIRECTION_NEXT, UDAT_RELATIVE_YEARS, "in 0 years"},
71         {0.5, UDAT_DIRECTION_NEXT, UDAT_RELATIVE_YEARS, "in 0.5 years"},
72         {1.0, UDAT_DIRECTION_NEXT, UDAT_RELATIVE_YEARS, "in 1 year"},
73         {2.0, UDAT_DIRECTION_NEXT, UDAT_RELATIVE_YEARS, "in 2 years"},
74 
75         {0.0, UDAT_DIRECTION_LAST, UDAT_RELATIVE_SECONDS, "0 seconds ago"},
76         {0.5, UDAT_DIRECTION_LAST, UDAT_RELATIVE_SECONDS, "0.5 seconds ago"},
77         {1.0, UDAT_DIRECTION_LAST, UDAT_RELATIVE_SECONDS, "1 second ago"},
78         {2.0, UDAT_DIRECTION_LAST, UDAT_RELATIVE_SECONDS, "2 seconds ago"},
79         {0.0, UDAT_DIRECTION_LAST, UDAT_RELATIVE_MINUTES, "0 minutes ago"},
80         {0.5, UDAT_DIRECTION_LAST, UDAT_RELATIVE_MINUTES, "0.5 minutes ago"},
81         {1.0, UDAT_DIRECTION_LAST, UDAT_RELATIVE_MINUTES, "1 minute ago"},
82         {2.0, UDAT_DIRECTION_LAST, UDAT_RELATIVE_MINUTES, "2 minutes ago"},
83         {0.0, UDAT_DIRECTION_LAST, UDAT_RELATIVE_HOURS, "0 hours ago"},
84         {0.5, UDAT_DIRECTION_LAST, UDAT_RELATIVE_HOURS, "0.5 hours ago"},
85         {1.0, UDAT_DIRECTION_LAST, UDAT_RELATIVE_HOURS, "1 hour ago"},
86         {2.0, UDAT_DIRECTION_LAST, UDAT_RELATIVE_HOURS, "2 hours ago"},
87         {0.0, UDAT_DIRECTION_LAST, UDAT_RELATIVE_DAYS, "0 days ago"},
88         {0.5, UDAT_DIRECTION_LAST, UDAT_RELATIVE_DAYS, "0.5 days ago"},
89         {1.0, UDAT_DIRECTION_LAST, UDAT_RELATIVE_DAYS, "1 day ago"},
90         {2.0, UDAT_DIRECTION_LAST, UDAT_RELATIVE_DAYS, "2 days ago"},
91         {0.0, UDAT_DIRECTION_LAST, UDAT_RELATIVE_WEEKS, "0 weeks ago"},
92         {0.5, UDAT_DIRECTION_LAST, UDAT_RELATIVE_WEEKS, "0.5 weeks ago"},
93         {1.0, UDAT_DIRECTION_LAST, UDAT_RELATIVE_WEEKS, "1 week ago"},
94         {2.0, UDAT_DIRECTION_LAST, UDAT_RELATIVE_WEEKS, "2 weeks ago"},
95         {0.0, UDAT_DIRECTION_LAST, UDAT_RELATIVE_MONTHS, "0 months ago"},
96         {0.5, UDAT_DIRECTION_LAST, UDAT_RELATIVE_MONTHS, "0.5 months ago"},
97         {1.0, UDAT_DIRECTION_LAST, UDAT_RELATIVE_MONTHS, "1 month ago"},
98         {2.0, UDAT_DIRECTION_LAST, UDAT_RELATIVE_MONTHS, "2 months ago"},
99         {0.0, UDAT_DIRECTION_LAST, UDAT_RELATIVE_YEARS, "0 years ago"},
100         {0.5, UDAT_DIRECTION_LAST, UDAT_RELATIVE_YEARS, "0.5 years ago"},
101         {1.0, UDAT_DIRECTION_LAST, UDAT_RELATIVE_YEARS, "1 year ago"},
102         {2.0, UDAT_DIRECTION_LAST, UDAT_RELATIVE_YEARS, "2 years ago"}
103 };
104 
105 static WithQuantityExpected kEnglishCaps[] = {
106         {0.0, UDAT_DIRECTION_NEXT, UDAT_RELATIVE_SECONDS, "In 0 seconds"},
107         {0.5, UDAT_DIRECTION_NEXT, UDAT_RELATIVE_SECONDS, "In 0.5 seconds"},
108         {1.0, UDAT_DIRECTION_NEXT, UDAT_RELATIVE_SECONDS, "In 1 second"},
109         {2.0, UDAT_DIRECTION_NEXT, UDAT_RELATIVE_SECONDS, "In 2 seconds"},
110         {0.0, UDAT_DIRECTION_NEXT, UDAT_RELATIVE_MINUTES, "In 0 minutes"},
111         {0.5, UDAT_DIRECTION_NEXT, UDAT_RELATIVE_MINUTES, "In 0.5 minutes"},
112         {1.0, UDAT_DIRECTION_NEXT, UDAT_RELATIVE_MINUTES, "In 1 minute"},
113         {2.0, UDAT_DIRECTION_NEXT, UDAT_RELATIVE_MINUTES, "In 2 minutes"},
114         {0.0, UDAT_DIRECTION_NEXT, UDAT_RELATIVE_HOURS, "In 0 hours"},
115         {0.5, UDAT_DIRECTION_NEXT, UDAT_RELATIVE_HOURS, "In 0.5 hours"},
116         {1.0, UDAT_DIRECTION_NEXT, UDAT_RELATIVE_HOURS, "In 1 hour"},
117         {2.0, UDAT_DIRECTION_NEXT, UDAT_RELATIVE_HOURS, "In 2 hours"},
118         {0.0, UDAT_DIRECTION_NEXT, UDAT_RELATIVE_DAYS, "In 0 days"},
119         {0.5, UDAT_DIRECTION_NEXT, UDAT_RELATIVE_DAYS, "In 0.5 days"},
120         {1.0, UDAT_DIRECTION_NEXT, UDAT_RELATIVE_DAYS, "In 1 day"},
121         {2.0, UDAT_DIRECTION_NEXT, UDAT_RELATIVE_DAYS, "In 2 days"},
122         {0.0, UDAT_DIRECTION_NEXT, UDAT_RELATIVE_WEEKS, "In 0 weeks"},
123         {0.5, UDAT_DIRECTION_NEXT, UDAT_RELATIVE_WEEKS, "In 0.5 weeks"},
124         {1.0, UDAT_DIRECTION_NEXT, UDAT_RELATIVE_WEEKS, "In 1 week"},
125         {2.0, UDAT_DIRECTION_NEXT, UDAT_RELATIVE_WEEKS, "In 2 weeks"},
126         {0.0, UDAT_DIRECTION_NEXT, UDAT_RELATIVE_MONTHS, "In 0 months"},
127         {0.5, UDAT_DIRECTION_NEXT, UDAT_RELATIVE_MONTHS, "In 0.5 months"},
128         {1.0, UDAT_DIRECTION_NEXT, UDAT_RELATIVE_MONTHS, "In 1 month"},
129         {2.0, UDAT_DIRECTION_NEXT, UDAT_RELATIVE_MONTHS, "In 2 months"},
130         {0.0, UDAT_DIRECTION_NEXT, UDAT_RELATIVE_YEARS, "In 0 years"},
131         {0.5, UDAT_DIRECTION_NEXT, UDAT_RELATIVE_YEARS, "In 0.5 years"},
132         {1.0, UDAT_DIRECTION_NEXT, UDAT_RELATIVE_YEARS, "In 1 year"},
133         {2.0, UDAT_DIRECTION_NEXT, UDAT_RELATIVE_YEARS, "In 2 years"},
134 
135         {0.0, UDAT_DIRECTION_LAST, UDAT_RELATIVE_SECONDS, "0 seconds ago"},
136         {0.5, UDAT_DIRECTION_LAST, UDAT_RELATIVE_SECONDS, "0.5 seconds ago"},
137         {1.0, UDAT_DIRECTION_LAST, UDAT_RELATIVE_SECONDS, "1 second ago"},
138         {2.0, UDAT_DIRECTION_LAST, UDAT_RELATIVE_SECONDS, "2 seconds ago"},
139         {0.0, UDAT_DIRECTION_LAST, UDAT_RELATIVE_MINUTES, "0 minutes ago"},
140         {0.5, UDAT_DIRECTION_LAST, UDAT_RELATIVE_MINUTES, "0.5 minutes ago"},
141         {1.0, UDAT_DIRECTION_LAST, UDAT_RELATIVE_MINUTES, "1 minute ago"},
142         {2.0, UDAT_DIRECTION_LAST, UDAT_RELATIVE_MINUTES, "2 minutes ago"},
143         {0.0, UDAT_DIRECTION_LAST, UDAT_RELATIVE_HOURS, "0 hours ago"},
144         {0.5, UDAT_DIRECTION_LAST, UDAT_RELATIVE_HOURS, "0.5 hours ago"},
145         {1.0, UDAT_DIRECTION_LAST, UDAT_RELATIVE_HOURS, "1 hour ago"},
146         {2.0, UDAT_DIRECTION_LAST, UDAT_RELATIVE_HOURS, "2 hours ago"},
147         {0.0, UDAT_DIRECTION_LAST, UDAT_RELATIVE_DAYS, "0 days ago"},
148         {0.5, UDAT_DIRECTION_LAST, UDAT_RELATIVE_DAYS, "0.5 days ago"},
149         {1.0, UDAT_DIRECTION_LAST, UDAT_RELATIVE_DAYS, "1 day ago"},
150         {2.0, UDAT_DIRECTION_LAST, UDAT_RELATIVE_DAYS, "2 days ago"},
151         {0.0, UDAT_DIRECTION_LAST, UDAT_RELATIVE_WEEKS, "0 weeks ago"},
152         {0.5, UDAT_DIRECTION_LAST, UDAT_RELATIVE_WEEKS, "0.5 weeks ago"},
153         {1.0, UDAT_DIRECTION_LAST, UDAT_RELATIVE_WEEKS, "1 week ago"},
154         {2.0, UDAT_DIRECTION_LAST, UDAT_RELATIVE_WEEKS, "2 weeks ago"},
155         {0.0, UDAT_DIRECTION_LAST, UDAT_RELATIVE_MONTHS, "0 months ago"},
156         {0.5, UDAT_DIRECTION_LAST, UDAT_RELATIVE_MONTHS, "0.5 months ago"},
157         {1.0, UDAT_DIRECTION_LAST, UDAT_RELATIVE_MONTHS, "1 month ago"},
158         {2.0, UDAT_DIRECTION_LAST, UDAT_RELATIVE_MONTHS, "2 months ago"},
159         {0.0, UDAT_DIRECTION_LAST, UDAT_RELATIVE_YEARS, "0 years ago"},
160         {0.5, UDAT_DIRECTION_LAST, UDAT_RELATIVE_YEARS, "0.5 years ago"},
161         {1.0, UDAT_DIRECTION_LAST, UDAT_RELATIVE_YEARS, "1 year ago"},
162         {2.0, UDAT_DIRECTION_LAST, UDAT_RELATIVE_YEARS, "2 years ago"}
163 };
164 
165 static WithQuantityExpected kEnglishShort[] = {
166         {0.0, UDAT_DIRECTION_NEXT, UDAT_RELATIVE_SECONDS, "in 0 sec."},
167         {0.5, UDAT_DIRECTION_NEXT, UDAT_RELATIVE_SECONDS, "in 0.5 sec."},
168         {1.0, UDAT_DIRECTION_NEXT, UDAT_RELATIVE_SECONDS, "in 1 sec."},
169         {2.0, UDAT_DIRECTION_NEXT, UDAT_RELATIVE_SECONDS, "in 2 sec."},
170         {0.0, UDAT_DIRECTION_NEXT, UDAT_RELATIVE_MINUTES, "in 0 min."},
171         {0.5, UDAT_DIRECTION_NEXT, UDAT_RELATIVE_MINUTES, "in 0.5 min."},
172         {1.0, UDAT_DIRECTION_NEXT, UDAT_RELATIVE_MINUTES, "in 1 min."},
173         {2.0, UDAT_DIRECTION_NEXT, UDAT_RELATIVE_MINUTES, "in 2 min."},
174         {0.0, UDAT_DIRECTION_NEXT, UDAT_RELATIVE_HOURS, "in 0 hr."},
175         {0.5, UDAT_DIRECTION_NEXT, UDAT_RELATIVE_HOURS, "in 0.5 hr."},
176         {1.0, UDAT_DIRECTION_NEXT, UDAT_RELATIVE_HOURS, "in 1 hr."},
177         {2.0, UDAT_DIRECTION_NEXT, UDAT_RELATIVE_HOURS, "in 2 hr."},
178         {0.0, UDAT_DIRECTION_NEXT, UDAT_RELATIVE_DAYS, "in 0 days"},
179         {0.5, UDAT_DIRECTION_NEXT, UDAT_RELATIVE_DAYS, "in 0.5 days"},
180         {1.0, UDAT_DIRECTION_NEXT, UDAT_RELATIVE_DAYS, "in 1 day"},
181         {2.0, UDAT_DIRECTION_NEXT, UDAT_RELATIVE_DAYS, "in 2 days"},
182         {0.0, UDAT_DIRECTION_NEXT, UDAT_RELATIVE_WEEKS, "in 0 wk."},
183         {0.5, UDAT_DIRECTION_NEXT, UDAT_RELATIVE_WEEKS, "in 0.5 wk."},
184         {1.0, UDAT_DIRECTION_NEXT, UDAT_RELATIVE_WEEKS, "in 1 wk."},
185         {2.0, UDAT_DIRECTION_NEXT, UDAT_RELATIVE_WEEKS, "in 2 wk."},
186         {0.0, UDAT_DIRECTION_NEXT, UDAT_RELATIVE_MONTHS, "in 0 mo."},
187         {0.5, UDAT_DIRECTION_NEXT, UDAT_RELATIVE_MONTHS, "in 0.5 mo."},
188         {1.0, UDAT_DIRECTION_NEXT, UDAT_RELATIVE_MONTHS, "in 1 mo."},
189         {2.0, UDAT_DIRECTION_NEXT, UDAT_RELATIVE_MONTHS, "in 2 mo."},
190         {0.0, UDAT_DIRECTION_NEXT, UDAT_RELATIVE_YEARS, "in 0 yr."},
191         {0.5, UDAT_DIRECTION_NEXT, UDAT_RELATIVE_YEARS, "in 0.5 yr."},
192         {1.0, UDAT_DIRECTION_NEXT, UDAT_RELATIVE_YEARS, "in 1 yr."},
193         {2.0, UDAT_DIRECTION_NEXT, UDAT_RELATIVE_YEARS, "in 2 yr."},
194 
195         {0.0, UDAT_DIRECTION_LAST, UDAT_RELATIVE_SECONDS, "0 sec. ago"},
196         {0.5, UDAT_DIRECTION_LAST, UDAT_RELATIVE_SECONDS, "0.5 sec. ago"},
197         {1.0, UDAT_DIRECTION_LAST, UDAT_RELATIVE_SECONDS, "1 sec. ago"},
198         {2.0, UDAT_DIRECTION_LAST, UDAT_RELATIVE_SECONDS, "2 sec. ago"},
199         {0.0, UDAT_DIRECTION_LAST, UDAT_RELATIVE_MINUTES, "0 min. ago"},
200         {0.5, UDAT_DIRECTION_LAST, UDAT_RELATIVE_MINUTES, "0.5 min. ago"},
201         {1.0, UDAT_DIRECTION_LAST, UDAT_RELATIVE_MINUTES, "1 min. ago"},
202         {2.0, UDAT_DIRECTION_LAST, UDAT_RELATIVE_MINUTES, "2 min. ago"},
203         {0.0, UDAT_DIRECTION_LAST, UDAT_RELATIVE_HOURS, "0 hr. ago"},
204         {0.5, UDAT_DIRECTION_LAST, UDAT_RELATIVE_HOURS, "0.5 hr. ago"},
205         {1.0, UDAT_DIRECTION_LAST, UDAT_RELATIVE_HOURS, "1 hr. ago"},
206         {2.0, UDAT_DIRECTION_LAST, UDAT_RELATIVE_HOURS, "2 hr. ago"},
207         {0.0, UDAT_DIRECTION_LAST, UDAT_RELATIVE_DAYS, "0 days ago"},
208         {0.5, UDAT_DIRECTION_LAST, UDAT_RELATIVE_DAYS, "0.5 days ago"},
209         {1.0, UDAT_DIRECTION_LAST, UDAT_RELATIVE_DAYS, "1 day ago"},
210         {2.0, UDAT_DIRECTION_LAST, UDAT_RELATIVE_DAYS, "2 days ago"},
211         {0.0, UDAT_DIRECTION_LAST, UDAT_RELATIVE_WEEKS, "0 wk. ago"},
212         {0.5, UDAT_DIRECTION_LAST, UDAT_RELATIVE_WEEKS, "0.5 wk. ago"},
213         {1.0, UDAT_DIRECTION_LAST, UDAT_RELATIVE_WEEKS, "1 wk. ago"},
214         {2.0, UDAT_DIRECTION_LAST, UDAT_RELATIVE_WEEKS, "2 wk. ago"},
215         {0.0, UDAT_DIRECTION_LAST, UDAT_RELATIVE_MONTHS, "0 mo. ago"},
216         {0.5, UDAT_DIRECTION_LAST, UDAT_RELATIVE_MONTHS, "0.5 mo. ago"},
217         {1.0, UDAT_DIRECTION_LAST, UDAT_RELATIVE_MONTHS, "1 mo. ago"},
218         {2.0, UDAT_DIRECTION_LAST, UDAT_RELATIVE_MONTHS, "2 mo. ago"},
219         {0.0, UDAT_DIRECTION_LAST, UDAT_RELATIVE_YEARS, "0 yr. ago"},
220         {0.5, UDAT_DIRECTION_LAST, UDAT_RELATIVE_YEARS, "0.5 yr. ago"},
221         {1.0, UDAT_DIRECTION_LAST, UDAT_RELATIVE_YEARS, "1 yr. ago"},
222         {2.0, UDAT_DIRECTION_LAST, UDAT_RELATIVE_YEARS, "2 yr. ago"}
223 };
224 
225 static WithQuantityExpected kEnglishDecimal[] = {
226         {0.0, UDAT_DIRECTION_NEXT, UDAT_RELATIVE_SECONDS, "in 0.0 seconds"},
227         {0.5, UDAT_DIRECTION_NEXT, UDAT_RELATIVE_SECONDS, "in 0.5 seconds"},
228         {1.0, UDAT_DIRECTION_NEXT, UDAT_RELATIVE_SECONDS, "in 1.0 seconds"},
229         {2.0, UDAT_DIRECTION_NEXT, UDAT_RELATIVE_SECONDS, "in 2.0 seconds"}
230 };
231 
232 static WithQuantityExpected kSerbian[] = {
233         {0.0, UDAT_DIRECTION_NEXT, UDAT_RELATIVE_MONTHS, "\\u0437\\u0430 0 \\u043c\\u0435\\u0441\\u0435\\u0446\\u0438"},
234         {1.2, UDAT_DIRECTION_NEXT, UDAT_RELATIVE_MONTHS, "\\u0437\\u0430 1,2 \\u043c\\u0435\\u0441\\u0435\\u0446\\u0430"},
235         {21.0, UDAT_DIRECTION_NEXT, UDAT_RELATIVE_MONTHS, "\\u0437\\u0430 21 \\u043c\\u0435\\u0441\\u0435\\u0446"}
236 };
237 
238 static WithQuantityExpected kSerbianNarrow[] = {
239         {0.0, UDAT_DIRECTION_NEXT, UDAT_RELATIVE_MONTHS, "\\u0437\\u0430 0 \\u043c."},
240         {1.2, UDAT_DIRECTION_NEXT, UDAT_RELATIVE_MONTHS, "\\u0437\\u0430 1,2 \\u043c."},
241         {21.0, UDAT_DIRECTION_NEXT, UDAT_RELATIVE_MONTHS, "\\u0437\\u0430 21 \\u043c."}
242 };
243 
244 static WithoutQuantityExpected kEnglishNoQuantity[] = {
245         {UDAT_DIRECTION_NEXT_2, UDAT_ABSOLUTE_DAY, ""},
246 
247         {UDAT_DIRECTION_NEXT, UDAT_ABSOLUTE_DAY, "tomorrow"},
248         {UDAT_DIRECTION_NEXT, UDAT_ABSOLUTE_WEEK, "next week"},
249         {UDAT_DIRECTION_NEXT, UDAT_ABSOLUTE_MONTH, "next month"},
250         {UDAT_DIRECTION_NEXT, UDAT_ABSOLUTE_QUARTER, "next quarter"},
251         {UDAT_DIRECTION_NEXT, UDAT_ABSOLUTE_YEAR, "next year"},
252         {UDAT_DIRECTION_NEXT, UDAT_ABSOLUTE_MONDAY, "next Monday"},
253         {UDAT_DIRECTION_NEXT, UDAT_ABSOLUTE_TUESDAY, "next Tuesday"},
254         {UDAT_DIRECTION_NEXT, UDAT_ABSOLUTE_WEDNESDAY, "next Wednesday"},
255         {UDAT_DIRECTION_NEXT, UDAT_ABSOLUTE_THURSDAY, "next Thursday"},
256         {UDAT_DIRECTION_NEXT, UDAT_ABSOLUTE_FRIDAY, "next Friday"},
257         {UDAT_DIRECTION_NEXT, UDAT_ABSOLUTE_SATURDAY, "next Saturday"},
258         {UDAT_DIRECTION_NEXT, UDAT_ABSOLUTE_SUNDAY, "next Sunday"},
259 
260         {UDAT_DIRECTION_LAST_2, UDAT_ABSOLUTE_DAY, ""},
261 
262         {UDAT_DIRECTION_LAST, UDAT_ABSOLUTE_DAY, "yesterday"},
263         {UDAT_DIRECTION_LAST, UDAT_ABSOLUTE_WEEK, "last week"},
264         {UDAT_DIRECTION_LAST, UDAT_ABSOLUTE_MONTH, "last month"},
265         {UDAT_DIRECTION_LAST, UDAT_ABSOLUTE_QUARTER, "last quarter"},
266         {UDAT_DIRECTION_LAST, UDAT_ABSOLUTE_YEAR, "last year"},
267         {UDAT_DIRECTION_LAST, UDAT_ABSOLUTE_MONDAY, "last Monday"},
268         {UDAT_DIRECTION_LAST, UDAT_ABSOLUTE_TUESDAY, "last Tuesday"},
269         {UDAT_DIRECTION_LAST, UDAT_ABSOLUTE_WEDNESDAY, "last Wednesday"},
270         {UDAT_DIRECTION_LAST, UDAT_ABSOLUTE_THURSDAY, "last Thursday"},
271         {UDAT_DIRECTION_LAST, UDAT_ABSOLUTE_FRIDAY, "last Friday"},
272         {UDAT_DIRECTION_LAST, UDAT_ABSOLUTE_SATURDAY, "last Saturday"},
273         {UDAT_DIRECTION_LAST, UDAT_ABSOLUTE_SUNDAY, "last Sunday"},
274 
275         {UDAT_DIRECTION_THIS, UDAT_ABSOLUTE_DAY, "today"},
276         {UDAT_DIRECTION_THIS, UDAT_ABSOLUTE_WEEK, "this week"},
277         {UDAT_DIRECTION_THIS, UDAT_ABSOLUTE_MONTH, "this month"},
278         {UDAT_DIRECTION_THIS, UDAT_ABSOLUTE_QUARTER, "this quarter"},
279         {UDAT_DIRECTION_THIS, UDAT_ABSOLUTE_YEAR, "this year"},
280         {UDAT_DIRECTION_THIS, UDAT_ABSOLUTE_MONDAY, "this Monday"},
281         {UDAT_DIRECTION_THIS, UDAT_ABSOLUTE_TUESDAY, "this Tuesday"},
282         {UDAT_DIRECTION_THIS, UDAT_ABSOLUTE_WEDNESDAY, "this Wednesday"},
283         {UDAT_DIRECTION_THIS, UDAT_ABSOLUTE_THURSDAY, "this Thursday"},
284         {UDAT_DIRECTION_THIS, UDAT_ABSOLUTE_FRIDAY, "this Friday"},
285         {UDAT_DIRECTION_THIS, UDAT_ABSOLUTE_SATURDAY, "this Saturday"},
286         {UDAT_DIRECTION_THIS, UDAT_ABSOLUTE_SUNDAY, "this Sunday"},
287 
288         {UDAT_DIRECTION_PLAIN, UDAT_ABSOLUTE_DAY, "day"},
289         {UDAT_DIRECTION_PLAIN, UDAT_ABSOLUTE_WEEK, "week"},
290         {UDAT_DIRECTION_PLAIN, UDAT_ABSOLUTE_MONTH, "month"},
291         {UDAT_DIRECTION_PLAIN, UDAT_ABSOLUTE_QUARTER, "quarter"},
292         {UDAT_DIRECTION_PLAIN, UDAT_ABSOLUTE_YEAR, "year"},
293         {UDAT_DIRECTION_PLAIN, UDAT_ABSOLUTE_MONDAY, "Monday"},
294         {UDAT_DIRECTION_PLAIN, UDAT_ABSOLUTE_TUESDAY, "Tuesday"},
295         {UDAT_DIRECTION_PLAIN, UDAT_ABSOLUTE_WEDNESDAY, "Wednesday"},
296         {UDAT_DIRECTION_PLAIN, UDAT_ABSOLUTE_THURSDAY, "Thursday"},
297         {UDAT_DIRECTION_PLAIN, UDAT_ABSOLUTE_FRIDAY, "Friday"},
298         {UDAT_DIRECTION_PLAIN, UDAT_ABSOLUTE_SATURDAY, "Saturday"},
299         {UDAT_DIRECTION_PLAIN, UDAT_ABSOLUTE_SUNDAY, "Sunday"},
300 
301         {UDAT_DIRECTION_PLAIN, UDAT_ABSOLUTE_NOW, "now"}
302 };
303 
304 static WithoutQuantityExpected kEnglishNoQuantityCaps[] = {
305         {UDAT_DIRECTION_NEXT_2, UDAT_ABSOLUTE_DAY, ""},
306 
307         {UDAT_DIRECTION_NEXT, UDAT_ABSOLUTE_DAY, "Tomorrow"},
308         {UDAT_DIRECTION_NEXT, UDAT_ABSOLUTE_WEEK, "Next week"},
309         {UDAT_DIRECTION_NEXT, UDAT_ABSOLUTE_MONTH, "Next month"},
310         {UDAT_DIRECTION_NEXT, UDAT_ABSOLUTE_QUARTER, "Next quarter"},
311         {UDAT_DIRECTION_NEXT, UDAT_ABSOLUTE_YEAR, "Next year"},
312         {UDAT_DIRECTION_NEXT, UDAT_ABSOLUTE_MONDAY, "Next Monday"},
313         {UDAT_DIRECTION_NEXT, UDAT_ABSOLUTE_TUESDAY, "Next Tuesday"},
314         {UDAT_DIRECTION_NEXT, UDAT_ABSOLUTE_WEDNESDAY, "Next Wednesday"},
315         {UDAT_DIRECTION_NEXT, UDAT_ABSOLUTE_THURSDAY, "Next Thursday"},
316         {UDAT_DIRECTION_NEXT, UDAT_ABSOLUTE_FRIDAY, "Next Friday"},
317         {UDAT_DIRECTION_NEXT, UDAT_ABSOLUTE_SATURDAY, "Next Saturday"},
318         {UDAT_DIRECTION_NEXT, UDAT_ABSOLUTE_SUNDAY, "Next Sunday"},
319 
320         {UDAT_DIRECTION_LAST_2, UDAT_ABSOLUTE_DAY, ""},
321 
322         {UDAT_DIRECTION_LAST, UDAT_ABSOLUTE_DAY, "Yesterday"},
323         {UDAT_DIRECTION_LAST, UDAT_ABSOLUTE_WEEK, "Last week"},
324         {UDAT_DIRECTION_LAST, UDAT_ABSOLUTE_MONTH, "Last month"},
325         {UDAT_DIRECTION_LAST, UDAT_ABSOLUTE_QUARTER, "Last quarter"},
326         {UDAT_DIRECTION_LAST, UDAT_ABSOLUTE_YEAR, "Last year"},
327         {UDAT_DIRECTION_LAST, UDAT_ABSOLUTE_MONDAY, "Last Monday"},
328         {UDAT_DIRECTION_LAST, UDAT_ABSOLUTE_TUESDAY, "Last Tuesday"},
329         {UDAT_DIRECTION_LAST, UDAT_ABSOLUTE_WEDNESDAY, "Last Wednesday"},
330         {UDAT_DIRECTION_LAST, UDAT_ABSOLUTE_THURSDAY, "Last Thursday"},
331         {UDAT_DIRECTION_LAST, UDAT_ABSOLUTE_FRIDAY, "Last Friday"},
332         {UDAT_DIRECTION_LAST, UDAT_ABSOLUTE_SATURDAY, "Last Saturday"},
333         {UDAT_DIRECTION_LAST, UDAT_ABSOLUTE_SUNDAY, "Last Sunday"},
334 
335         {UDAT_DIRECTION_THIS, UDAT_ABSOLUTE_DAY, "Today"},
336         {UDAT_DIRECTION_THIS, UDAT_ABSOLUTE_WEEK, "This week"},
337         {UDAT_DIRECTION_THIS, UDAT_ABSOLUTE_MONTH, "This month"},
338         {UDAT_DIRECTION_THIS, UDAT_ABSOLUTE_QUARTER, "This quarter"},
339         {UDAT_DIRECTION_THIS, UDAT_ABSOLUTE_YEAR, "This year"},
340         {UDAT_DIRECTION_THIS, UDAT_ABSOLUTE_MONDAY, "This Monday"},
341         {UDAT_DIRECTION_THIS, UDAT_ABSOLUTE_TUESDAY, "This Tuesday"},
342         {UDAT_DIRECTION_THIS, UDAT_ABSOLUTE_WEDNESDAY, "This Wednesday"},
343         {UDAT_DIRECTION_THIS, UDAT_ABSOLUTE_THURSDAY, "This Thursday"},
344         {UDAT_DIRECTION_THIS, UDAT_ABSOLUTE_FRIDAY, "This Friday"},
345         {UDAT_DIRECTION_THIS, UDAT_ABSOLUTE_SATURDAY, "This Saturday"},
346         {UDAT_DIRECTION_THIS, UDAT_ABSOLUTE_SUNDAY, "This Sunday"},
347 
348         {UDAT_DIRECTION_PLAIN, UDAT_ABSOLUTE_DAY, "Day"},
349         {UDAT_DIRECTION_PLAIN, UDAT_ABSOLUTE_WEEK, "Week"},
350         {UDAT_DIRECTION_PLAIN, UDAT_ABSOLUTE_MONTH, "Month"},
351         {UDAT_DIRECTION_PLAIN, UDAT_ABSOLUTE_QUARTER, "Quarter"},
352         {UDAT_DIRECTION_PLAIN, UDAT_ABSOLUTE_YEAR, "Year"},
353         {UDAT_DIRECTION_PLAIN, UDAT_ABSOLUTE_MONDAY, "Monday"},
354         {UDAT_DIRECTION_PLAIN, UDAT_ABSOLUTE_TUESDAY, "Tuesday"},
355         {UDAT_DIRECTION_PLAIN, UDAT_ABSOLUTE_WEDNESDAY, "Wednesday"},
356         {UDAT_DIRECTION_PLAIN, UDAT_ABSOLUTE_THURSDAY, "Thursday"},
357         {UDAT_DIRECTION_PLAIN, UDAT_ABSOLUTE_FRIDAY, "Friday"},
358         {UDAT_DIRECTION_PLAIN, UDAT_ABSOLUTE_SATURDAY, "Saturday"},
359         {UDAT_DIRECTION_PLAIN, UDAT_ABSOLUTE_SUNDAY, "Sunday"},
360 
361         {UDAT_DIRECTION_PLAIN, UDAT_ABSOLUTE_NOW, "Now"}
362 };
363 
364 static WithoutQuantityExpected kEnglishNoQuantityShort[] = {
365         {UDAT_DIRECTION_NEXT_2, UDAT_ABSOLUTE_DAY, ""},
366 
367         {UDAT_DIRECTION_NEXT, UDAT_ABSOLUTE_DAY, "tomorrow"},
368         {UDAT_DIRECTION_NEXT, UDAT_ABSOLUTE_WEEK, "next wk."},
369         {UDAT_DIRECTION_NEXT, UDAT_ABSOLUTE_MONTH, "next mo."},
370         {UDAT_DIRECTION_NEXT, UDAT_ABSOLUTE_QUARTER, "next qtr."},
371         {UDAT_DIRECTION_NEXT, UDAT_ABSOLUTE_YEAR, "next yr."},
372         {UDAT_DIRECTION_NEXT, UDAT_ABSOLUTE_MONDAY, "next Mon."},
373         {UDAT_DIRECTION_NEXT, UDAT_ABSOLUTE_TUESDAY, "next Tue."},
374         {UDAT_DIRECTION_NEXT, UDAT_ABSOLUTE_WEDNESDAY, "next Wed."},
375         {UDAT_DIRECTION_NEXT, UDAT_ABSOLUTE_THURSDAY, "next Thu."},
376         {UDAT_DIRECTION_NEXT, UDAT_ABSOLUTE_FRIDAY, "next Fri."},
377         {UDAT_DIRECTION_NEXT, UDAT_ABSOLUTE_SATURDAY, "next Sat."},
378         {UDAT_DIRECTION_NEXT, UDAT_ABSOLUTE_SUNDAY, "next Sun."},
379 
380         {UDAT_DIRECTION_LAST_2, UDAT_ABSOLUTE_DAY, ""},
381 
382         {UDAT_DIRECTION_LAST, UDAT_ABSOLUTE_DAY, "yesterday"},
383         {UDAT_DIRECTION_LAST, UDAT_ABSOLUTE_WEEK, "last wk."},
384         {UDAT_DIRECTION_LAST, UDAT_ABSOLUTE_MONTH, "last mo."},
385         {UDAT_DIRECTION_LAST, UDAT_ABSOLUTE_QUARTER, "last qtr."},
386         {UDAT_DIRECTION_LAST, UDAT_ABSOLUTE_YEAR, "last yr."},
387         {UDAT_DIRECTION_LAST, UDAT_ABSOLUTE_MONDAY, "last Mon."},
388         {UDAT_DIRECTION_LAST, UDAT_ABSOLUTE_TUESDAY, "last Tue."},
389         {UDAT_DIRECTION_LAST, UDAT_ABSOLUTE_WEDNESDAY, "last Wed."},
390         {UDAT_DIRECTION_LAST, UDAT_ABSOLUTE_THURSDAY, "last Thu."},
391         {UDAT_DIRECTION_LAST, UDAT_ABSOLUTE_FRIDAY, "last Fri."},
392         {UDAT_DIRECTION_LAST, UDAT_ABSOLUTE_SATURDAY, "last Sat."},
393         {UDAT_DIRECTION_LAST, UDAT_ABSOLUTE_SUNDAY, "last Sun."},
394 
395         {UDAT_DIRECTION_THIS, UDAT_ABSOLUTE_DAY, "today"},
396         {UDAT_DIRECTION_THIS, UDAT_ABSOLUTE_WEEK, "this wk."},
397         {UDAT_DIRECTION_THIS, UDAT_ABSOLUTE_MONTH, "this mo."},
398         {UDAT_DIRECTION_THIS, UDAT_ABSOLUTE_QUARTER, "this qtr."},
399         {UDAT_DIRECTION_THIS, UDAT_ABSOLUTE_YEAR, "this yr."},
400         {UDAT_DIRECTION_THIS, UDAT_ABSOLUTE_MONDAY, "this Mon."},
401         {UDAT_DIRECTION_THIS, UDAT_ABSOLUTE_TUESDAY, "this Tue."},
402         {UDAT_DIRECTION_THIS, UDAT_ABSOLUTE_WEDNESDAY, "this Wed."},
403         {UDAT_DIRECTION_THIS, UDAT_ABSOLUTE_THURSDAY, "this Thu."},
404         {UDAT_DIRECTION_THIS, UDAT_ABSOLUTE_FRIDAY, "this Fri."},
405         {UDAT_DIRECTION_THIS, UDAT_ABSOLUTE_SATURDAY, "this Sat."},
406         {UDAT_DIRECTION_THIS, UDAT_ABSOLUTE_SUNDAY, "this Sun."},
407 
408         {UDAT_DIRECTION_PLAIN, UDAT_ABSOLUTE_DAY, "day"},
409         {UDAT_DIRECTION_PLAIN, UDAT_ABSOLUTE_WEEK, "wk."},
410         {UDAT_DIRECTION_PLAIN, UDAT_ABSOLUTE_MONTH, "mo."},
411         {UDAT_DIRECTION_PLAIN, UDAT_ABSOLUTE_QUARTER, "qtr."},
412         {UDAT_DIRECTION_PLAIN, UDAT_ABSOLUTE_YEAR, "yr."},
413         {UDAT_DIRECTION_PLAIN, UDAT_ABSOLUTE_MONDAY, "Mo"},
414         {UDAT_DIRECTION_PLAIN, UDAT_ABSOLUTE_TUESDAY, "Tu"},
415         {UDAT_DIRECTION_PLAIN, UDAT_ABSOLUTE_WEDNESDAY, "We"},
416         {UDAT_DIRECTION_PLAIN, UDAT_ABSOLUTE_THURSDAY, "Th"},
417         {UDAT_DIRECTION_PLAIN, UDAT_ABSOLUTE_FRIDAY, "Fr"},
418         {UDAT_DIRECTION_PLAIN, UDAT_ABSOLUTE_SATURDAY, "Sa"},
419         {UDAT_DIRECTION_PLAIN, UDAT_ABSOLUTE_SUNDAY, "Su"},
420 
421         {UDAT_DIRECTION_PLAIN, UDAT_ABSOLUTE_NOW, "now"}
422 };
423 
424 static WithoutQuantityExpected kEnglishNoQuantityNarrow[] = {
425         {UDAT_DIRECTION_NEXT_2, UDAT_ABSOLUTE_DAY, ""},
426 
427         {UDAT_DIRECTION_NEXT, UDAT_ABSOLUTE_DAY, "tomorrow"},
428         {UDAT_DIRECTION_NEXT, UDAT_ABSOLUTE_WEEK, "next wk."},
429         {UDAT_DIRECTION_NEXT, UDAT_ABSOLUTE_MONTH, "next mo."},
430         {UDAT_DIRECTION_NEXT, UDAT_ABSOLUTE_QUARTER, "next qtr."},
431         {UDAT_DIRECTION_NEXT, UDAT_ABSOLUTE_YEAR, "next yr."},
432         {UDAT_DIRECTION_NEXT, UDAT_ABSOLUTE_MONDAY, "next M"},
433         {UDAT_DIRECTION_NEXT, UDAT_ABSOLUTE_TUESDAY, "next Tu"},
434         {UDAT_DIRECTION_NEXT, UDAT_ABSOLUTE_WEDNESDAY, "next W"},
435         {UDAT_DIRECTION_NEXT, UDAT_ABSOLUTE_THURSDAY, "next Th"},
436         {UDAT_DIRECTION_NEXT, UDAT_ABSOLUTE_FRIDAY, "next F"},
437         {UDAT_DIRECTION_NEXT, UDAT_ABSOLUTE_SATURDAY, "next Sa"},
438         {UDAT_DIRECTION_NEXT, UDAT_ABSOLUTE_SUNDAY, "next Su"},
439 
440         {UDAT_DIRECTION_LAST_2, UDAT_ABSOLUTE_DAY, ""},
441 
442         {UDAT_DIRECTION_LAST, UDAT_ABSOLUTE_DAY, "yesterday"},
443         {UDAT_DIRECTION_LAST, UDAT_ABSOLUTE_WEEK, "last wk."},
444         {UDAT_DIRECTION_LAST, UDAT_ABSOLUTE_MONTH, "last mo."},
445         {UDAT_DIRECTION_LAST, UDAT_ABSOLUTE_QUARTER, "last qtr."},
446         {UDAT_DIRECTION_LAST, UDAT_ABSOLUTE_YEAR, "last yr."},
447         {UDAT_DIRECTION_LAST, UDAT_ABSOLUTE_MONDAY, "last M"},
448         {UDAT_DIRECTION_LAST, UDAT_ABSOLUTE_TUESDAY, "last Tu"},
449         {UDAT_DIRECTION_LAST, UDAT_ABSOLUTE_WEDNESDAY, "last W"},
450         {UDAT_DIRECTION_LAST, UDAT_ABSOLUTE_THURSDAY, "last Th"},
451         {UDAT_DIRECTION_LAST, UDAT_ABSOLUTE_FRIDAY, "last F"},
452         {UDAT_DIRECTION_LAST, UDAT_ABSOLUTE_SATURDAY, "last Sa"},
453         {UDAT_DIRECTION_LAST, UDAT_ABSOLUTE_SUNDAY, "last Su"},
454 
455         {UDAT_DIRECTION_THIS, UDAT_ABSOLUTE_DAY, "today"},
456         {UDAT_DIRECTION_THIS, UDAT_ABSOLUTE_WEEK, "this wk."},
457         {UDAT_DIRECTION_THIS, UDAT_ABSOLUTE_MONTH, "this mo."},
458         {UDAT_DIRECTION_THIS, UDAT_ABSOLUTE_QUARTER, "this qtr."},
459         {UDAT_DIRECTION_THIS, UDAT_ABSOLUTE_YEAR, "this yr."},
460         {UDAT_DIRECTION_THIS, UDAT_ABSOLUTE_MONDAY, "this M"},
461         {UDAT_DIRECTION_THIS, UDAT_ABSOLUTE_TUESDAY, "this Tu"},
462         {UDAT_DIRECTION_THIS, UDAT_ABSOLUTE_WEDNESDAY, "this W"},
463         {UDAT_DIRECTION_THIS, UDAT_ABSOLUTE_THURSDAY, "this Th"},
464         {UDAT_DIRECTION_THIS, UDAT_ABSOLUTE_FRIDAY, "this F"},
465         {UDAT_DIRECTION_THIS, UDAT_ABSOLUTE_SATURDAY, "this Sa"},
466         {UDAT_DIRECTION_THIS, UDAT_ABSOLUTE_SUNDAY, "this Su"},
467 
468         {UDAT_DIRECTION_PLAIN, UDAT_ABSOLUTE_DAY, "day"},
469         {UDAT_DIRECTION_PLAIN, UDAT_ABSOLUTE_WEEK, "wk."},
470         {UDAT_DIRECTION_PLAIN, UDAT_ABSOLUTE_MONTH, "mo."},
471         {UDAT_DIRECTION_PLAIN, UDAT_ABSOLUTE_QUARTER, "qtr."},
472         {UDAT_DIRECTION_PLAIN, UDAT_ABSOLUTE_YEAR, "yr."},
473         {UDAT_DIRECTION_PLAIN, UDAT_ABSOLUTE_MONDAY, "M"},
474         {UDAT_DIRECTION_PLAIN, UDAT_ABSOLUTE_TUESDAY, "T"},
475         {UDAT_DIRECTION_PLAIN, UDAT_ABSOLUTE_WEDNESDAY, "W"},
476         {UDAT_DIRECTION_PLAIN, UDAT_ABSOLUTE_THURSDAY, "T"},
477         {UDAT_DIRECTION_PLAIN, UDAT_ABSOLUTE_FRIDAY, "F"},
478         {UDAT_DIRECTION_PLAIN, UDAT_ABSOLUTE_SATURDAY, "S"},
479         {UDAT_DIRECTION_PLAIN, UDAT_ABSOLUTE_SUNDAY, "S"},
480 
481         {UDAT_DIRECTION_PLAIN, UDAT_ABSOLUTE_NOW, "now"}
482 };
483 
484 static WithoutQuantityExpected kSpanishNoQuantity[] = {
485         {UDAT_DIRECTION_NEXT_2, UDAT_ABSOLUTE_DAY, "pasado ma\\u00F1ana"},
486         {UDAT_DIRECTION_LAST_2, UDAT_ABSOLUTE_DAY, "anteayer"}
487 };
488 
489 typedef struct WithQuantityExpectedRelativeDateTimeUnit {
490     double value;
491     URelativeDateTimeUnit unit;
492     const char *expected;
493 } WithQuantityExpectedRelativeDateTimeUnit;
494 
495 static WithQuantityExpectedRelativeDateTimeUnit kEnglishFormatNumeric[] = {
496         {0.0, UDAT_REL_UNIT_SECOND, "in 0 seconds"},
497         {0.5, UDAT_REL_UNIT_SECOND, "in 0.5 seconds"},
498         {1.0, UDAT_REL_UNIT_SECOND, "in 1 second"},
499         {2.0, UDAT_REL_UNIT_SECOND, "in 2 seconds"},
500         {0.0, UDAT_REL_UNIT_MINUTE, "in 0 minutes"},
501         {0.5, UDAT_REL_UNIT_MINUTE, "in 0.5 minutes"},
502         {1.0, UDAT_REL_UNIT_MINUTE, "in 1 minute"},
503         {2.0, UDAT_REL_UNIT_MINUTE, "in 2 minutes"},
504         {0.0, UDAT_REL_UNIT_HOUR, "in 0 hours"},
505         {0.5, UDAT_REL_UNIT_HOUR, "in 0.5 hours"},
506         {1.0, UDAT_REL_UNIT_HOUR, "in 1 hour"},
507         {2.0, UDAT_REL_UNIT_HOUR, "in 2 hours"},
508         {0.0, UDAT_REL_UNIT_DAY, "in 0 days"},
509         {0.5, UDAT_REL_UNIT_DAY, "in 0.5 days"},
510         {1.0, UDAT_REL_UNIT_DAY, "in 1 day"},
511         {2.0, UDAT_REL_UNIT_DAY, "in 2 days"},
512         {0.0, UDAT_REL_UNIT_WEEK, "in 0 weeks"},
513         {0.5, UDAT_REL_UNIT_WEEK, "in 0.5 weeks"},
514         {1.0, UDAT_REL_UNIT_WEEK, "in 1 week"},
515         {2.0, UDAT_REL_UNIT_WEEK, "in 2 weeks"},
516         {0.0, UDAT_REL_UNIT_MONTH, "in 0 months"},
517         {0.5, UDAT_REL_UNIT_MONTH, "in 0.5 months"},
518         {1.0, UDAT_REL_UNIT_MONTH, "in 1 month"},
519         {2.0, UDAT_REL_UNIT_MONTH, "in 2 months"},
520         {0.0, UDAT_REL_UNIT_QUARTER, "in 0 quarters"},
521         {0.5, UDAT_REL_UNIT_QUARTER, "in 0.5 quarters"},
522         {1.0, UDAT_REL_UNIT_QUARTER, "in 1 quarter"},
523         {2.0, UDAT_REL_UNIT_QUARTER, "in 2 quarters"},
524         {0.0, UDAT_REL_UNIT_YEAR, "in 0 years"},
525         {0.5, UDAT_REL_UNIT_YEAR, "in 0.5 years"},
526         {1.0, UDAT_REL_UNIT_YEAR, "in 1 year"},
527         {2.0, UDAT_REL_UNIT_YEAR, "in 2 years"},
528         {0.0, UDAT_REL_UNIT_SUNDAY, "in 0 Sundays"},
529         {0.5, UDAT_REL_UNIT_SUNDAY, "in 0.5 Sundays"},
530         {1.0, UDAT_REL_UNIT_SUNDAY, "in 1 Sunday"},
531         {2.0, UDAT_REL_UNIT_SUNDAY, "in 2 Sundays"},
532         {0.0, UDAT_REL_UNIT_MONDAY, "in 0 Mondays"},
533         {0.5, UDAT_REL_UNIT_MONDAY, "in 0.5 Mondays"},
534         {1.0, UDAT_REL_UNIT_MONDAY, "in 1 Monday"},
535         {2.0, UDAT_REL_UNIT_MONDAY, "in 2 Mondays"},
536         {0.0, UDAT_REL_UNIT_TUESDAY, "in 0 Tuesdays"},
537         {0.5, UDAT_REL_UNIT_TUESDAY, "in 0.5 Tuesdays"},
538         {1.0, UDAT_REL_UNIT_TUESDAY, "in 1 Tuesday"},
539         {2.0, UDAT_REL_UNIT_TUESDAY, "in 2 Tuesdays"},
540         {0.0, UDAT_REL_UNIT_WEDNESDAY, "in 0 Wednesdays"},
541         {0.5, UDAT_REL_UNIT_WEDNESDAY, "in 0.5 Wednesdays"},
542         {1.0, UDAT_REL_UNIT_WEDNESDAY, "in 1 Wednesday"},
543         {2.0, UDAT_REL_UNIT_WEDNESDAY, "in 2 Wednesdays"},
544         {0.0, UDAT_REL_UNIT_THURSDAY, "in 0 Thursdays"},
545         {0.5, UDAT_REL_UNIT_THURSDAY, "in 0.5 Thursdays"},
546         {1.0, UDAT_REL_UNIT_THURSDAY, "in 1 Thursday"},
547         {2.0, UDAT_REL_UNIT_THURSDAY, "in 2 Thursdays"},
548         {0.0, UDAT_REL_UNIT_FRIDAY, "in 0 Fridays"},
549         {0.5, UDAT_REL_UNIT_FRIDAY, "in 0.5 Fridays"},
550         {1.0, UDAT_REL_UNIT_FRIDAY, "in 1 Friday"},
551         {2.0, UDAT_REL_UNIT_FRIDAY, "in 2 Fridays"},
552         {0.0, UDAT_REL_UNIT_SATURDAY, "in 0 Saturdays"},
553         {0.5, UDAT_REL_UNIT_SATURDAY, "in 0.5 Saturdays"},
554         {1.0, UDAT_REL_UNIT_SATURDAY, "in 1 Saturday"},
555         {2.0, UDAT_REL_UNIT_SATURDAY, "in 2 Saturdays"},
556 
557         {-0.0, UDAT_REL_UNIT_SECOND, "0 seconds ago"},
558         {-0.5, UDAT_REL_UNIT_SECOND, "0.5 seconds ago"},
559         {-1.0, UDAT_REL_UNIT_SECOND, "1 second ago"},
560         {-2.0, UDAT_REL_UNIT_SECOND, "2 seconds ago"},
561         {-0.0, UDAT_REL_UNIT_MINUTE, "0 minutes ago"},
562         {-0.5, UDAT_REL_UNIT_MINUTE, "0.5 minutes ago"},
563         {-1.0, UDAT_REL_UNIT_MINUTE, "1 minute ago"},
564         {-2.0, UDAT_REL_UNIT_MINUTE, "2 minutes ago"},
565         {-0.0, UDAT_REL_UNIT_HOUR, "0 hours ago"},
566         {-0.5, UDAT_REL_UNIT_HOUR, "0.5 hours ago"},
567         {-1.0, UDAT_REL_UNIT_HOUR, "1 hour ago"},
568         {-2.0, UDAT_REL_UNIT_HOUR, "2 hours ago"},
569         {-0.0, UDAT_REL_UNIT_DAY, "0 days ago"},
570         {-0.5, UDAT_REL_UNIT_DAY, "0.5 days ago"},
571         {-1.0, UDAT_REL_UNIT_DAY, "1 day ago"},
572         {-2.0, UDAT_REL_UNIT_DAY, "2 days ago"},
573         {-0.0, UDAT_REL_UNIT_WEEK, "0 weeks ago"},
574         {-0.5, UDAT_REL_UNIT_WEEK, "0.5 weeks ago"},
575         {-1.0, UDAT_REL_UNIT_WEEK, "1 week ago"},
576         {-2.0, UDAT_REL_UNIT_WEEK, "2 weeks ago"},
577         {-0.0, UDAT_REL_UNIT_MONTH, "0 months ago"},
578         {-0.5, UDAT_REL_UNIT_MONTH, "0.5 months ago"},
579         {-1.0, UDAT_REL_UNIT_MONTH, "1 month ago"},
580         {-2.0, UDAT_REL_UNIT_MONTH, "2 months ago"},
581         {-0.0, UDAT_REL_UNIT_QUARTER, "0 quarters ago"},
582         {-0.5, UDAT_REL_UNIT_QUARTER, "0.5 quarters ago"},
583         {-1.0, UDAT_REL_UNIT_QUARTER, "1 quarter ago"},
584         {-2.0, UDAT_REL_UNIT_QUARTER, "2 quarters ago"},
585         {-0.0, UDAT_REL_UNIT_YEAR, "0 years ago"},
586         {-0.5, UDAT_REL_UNIT_YEAR, "0.5 years ago"},
587         {-1.0, UDAT_REL_UNIT_YEAR, "1 year ago"},
588         {-2.0, UDAT_REL_UNIT_YEAR, "2 years ago"},
589         {-0.0, UDAT_REL_UNIT_SUNDAY, "0 Sundays ago"},
590         {-0.5, UDAT_REL_UNIT_SUNDAY, "0.5 Sundays ago"},
591         {-1.0, UDAT_REL_UNIT_SUNDAY, "1 Sunday ago"},
592         {-2.0, UDAT_REL_UNIT_SUNDAY, "2 Sundays ago"},
593         {-0.0, UDAT_REL_UNIT_MONDAY, "0 Mondays ago"},
594         {-0.5, UDAT_REL_UNIT_MONDAY, "0.5 Mondays ago"},
595         {-1.0, UDAT_REL_UNIT_MONDAY, "1 Monday ago"},
596         {-2.0, UDAT_REL_UNIT_MONDAY, "2 Mondays ago"},
597         {-0.0, UDAT_REL_UNIT_TUESDAY, "0 Tuesdays ago"},
598         {-0.5, UDAT_REL_UNIT_TUESDAY, "0.5 Tuesdays ago"},
599         {-1.0, UDAT_REL_UNIT_TUESDAY, "1 Tuesday ago"},
600         {-2.0, UDAT_REL_UNIT_TUESDAY, "2 Tuesdays ago"},
601         {-0.0, UDAT_REL_UNIT_WEDNESDAY, "0 Wednesdays ago"},
602         {-0.5, UDAT_REL_UNIT_WEDNESDAY, "0.5 Wednesdays ago"},
603         {-1.0, UDAT_REL_UNIT_WEDNESDAY, "1 Wednesday ago"},
604         {-2.0, UDAT_REL_UNIT_WEDNESDAY, "2 Wednesdays ago"},
605         {-0.0, UDAT_REL_UNIT_THURSDAY, "0 Thursdays ago"},
606         {-0.5, UDAT_REL_UNIT_THURSDAY, "0.5 Thursdays ago"},
607         {-1.0, UDAT_REL_UNIT_THURSDAY, "1 Thursday ago"},
608         {-2.0, UDAT_REL_UNIT_THURSDAY, "2 Thursdays ago"},
609         {-0.0, UDAT_REL_UNIT_FRIDAY, "0 Fridays ago"},
610         {-0.5, UDAT_REL_UNIT_FRIDAY, "0.5 Fridays ago"},
611         {-1.0, UDAT_REL_UNIT_FRIDAY, "1 Friday ago"},
612         {-2.0, UDAT_REL_UNIT_FRIDAY, "2 Fridays ago"},
613         {-0.0, UDAT_REL_UNIT_SATURDAY, "0 Saturdays ago"},
614         {-0.5, UDAT_REL_UNIT_SATURDAY, "0.5 Saturdays ago"},
615         {-1.0, UDAT_REL_UNIT_SATURDAY, "1 Saturday ago"},
616         {-2.0, UDAT_REL_UNIT_SATURDAY, "2 Saturdays ago"}
617 };
618 
619 static WithQuantityExpectedRelativeDateTimeUnit kEnglishFormat[] = {
620         {0.0, UDAT_REL_UNIT_SECOND, "now"},
621         {0.5, UDAT_REL_UNIT_SECOND, "in 0.5 seconds"},
622         {1.0, UDAT_REL_UNIT_SECOND, "in 1 second"},
623         {2.0, UDAT_REL_UNIT_SECOND, "in 2 seconds"},
624         {0.0, UDAT_REL_UNIT_MINUTE, "in 0 minutes"},
625         {0.5, UDAT_REL_UNIT_MINUTE, "in 0.5 minutes"},
626         {1.0, UDAT_REL_UNIT_MINUTE, "in 1 minute"},
627         {2.0, UDAT_REL_UNIT_MINUTE, "in 2 minutes"},
628         {0.0, UDAT_REL_UNIT_HOUR, "in 0 hours"},
629         {0.5, UDAT_REL_UNIT_HOUR, "in 0.5 hours"},
630         {1.0, UDAT_REL_UNIT_HOUR, "in 1 hour"},
631         {2.0, UDAT_REL_UNIT_HOUR, "in 2 hours"},
632         {0.0, UDAT_REL_UNIT_DAY, "today"},
633         {0.5, UDAT_REL_UNIT_DAY, "in 0.5 days"},
634         {1.0, UDAT_REL_UNIT_DAY, "tomorrow"},
635         {2.0, UDAT_REL_UNIT_DAY, "in 2 days"},
636         {0.0, UDAT_REL_UNIT_WEEK, "this week"},
637         {0.5, UDAT_REL_UNIT_WEEK, "in 0.5 weeks"},
638         {1.0, UDAT_REL_UNIT_WEEK, "next week"},
639         {2.0, UDAT_REL_UNIT_WEEK, "in 2 weeks"},
640         {0.0, UDAT_REL_UNIT_MONTH, "this month"},
641         {0.5, UDAT_REL_UNIT_MONTH, "in 0.5 months"},
642         {1.0, UDAT_REL_UNIT_MONTH, "next month"},
643         {2.0, UDAT_REL_UNIT_MONTH, "in 2 months"},
644         {0.0, UDAT_REL_UNIT_QUARTER, "this quarter"},
645         {0.5, UDAT_REL_UNIT_QUARTER, "in 0.5 quarters"},
646         {1.0, UDAT_REL_UNIT_QUARTER, "next quarter"},
647         {2.0, UDAT_REL_UNIT_QUARTER, "in 2 quarters"},
648         {0.0, UDAT_REL_UNIT_YEAR, "this year"},
649         {0.5, UDAT_REL_UNIT_YEAR, "in 0.5 years"},
650         {1.0, UDAT_REL_UNIT_YEAR, "next year"},
651         {2.0, UDAT_REL_UNIT_YEAR, "in 2 years"},
652         {0.0, UDAT_REL_UNIT_SUNDAY, "this Sunday"},
653         {0.5, UDAT_REL_UNIT_SUNDAY, "in 0.5 Sundays"},
654         {1.0, UDAT_REL_UNIT_SUNDAY, "next Sunday"},
655         {2.0, UDAT_REL_UNIT_SUNDAY, "in 2 Sundays"},
656         {0.0, UDAT_REL_UNIT_MONDAY, "this Monday"},
657         {0.5, UDAT_REL_UNIT_MONDAY, "in 0.5 Mondays"},
658         {1.0, UDAT_REL_UNIT_MONDAY, "next Monday"},
659         {2.0, UDAT_REL_UNIT_MONDAY, "in 2 Mondays"},
660         {0.0, UDAT_REL_UNIT_TUESDAY, "this Tuesday"},
661         {0.5, UDAT_REL_UNIT_TUESDAY, "in 0.5 Tuesdays"},
662         {1.0, UDAT_REL_UNIT_TUESDAY, "next Tuesday"},
663         {2.0, UDAT_REL_UNIT_TUESDAY, "in 2 Tuesdays"},
664         {0.0, UDAT_REL_UNIT_WEDNESDAY, "this Wednesday"},
665         {0.5, UDAT_REL_UNIT_WEDNESDAY, "in 0.5 Wednesdays"},
666         {1.0, UDAT_REL_UNIT_WEDNESDAY, "next Wednesday"},
667         {2.0, UDAT_REL_UNIT_WEDNESDAY, "in 2 Wednesdays"},
668         {0.0, UDAT_REL_UNIT_THURSDAY, "this Thursday"},
669         {0.5, UDAT_REL_UNIT_THURSDAY, "in 0.5 Thursdays"},
670         {1.0, UDAT_REL_UNIT_THURSDAY, "next Thursday"},
671         {2.0, UDAT_REL_UNIT_THURSDAY, "in 2 Thursdays"},
672         {0.0, UDAT_REL_UNIT_FRIDAY, "this Friday"},
673         {0.5, UDAT_REL_UNIT_FRIDAY, "in 0.5 Fridays"},
674         {1.0, UDAT_REL_UNIT_FRIDAY, "next Friday"},
675         {2.0, UDAT_REL_UNIT_FRIDAY, "in 2 Fridays"},
676         {0.0, UDAT_REL_UNIT_SATURDAY, "this Saturday"},
677         {0.5, UDAT_REL_UNIT_SATURDAY, "in 0.5 Saturdays"},
678         {1.0, UDAT_REL_UNIT_SATURDAY, "next Saturday"},
679         {2.0, UDAT_REL_UNIT_SATURDAY, "in 2 Saturdays"},
680 
681         {-0.0, UDAT_REL_UNIT_SECOND, "now"},
682         {-0.5, UDAT_REL_UNIT_SECOND, "0.5 seconds ago"},
683         {-1.0, UDAT_REL_UNIT_SECOND, "1 second ago"},
684         {-2.0, UDAT_REL_UNIT_SECOND, "2 seconds ago"},
685         {-0.0, UDAT_REL_UNIT_MINUTE, "0 minutes ago"},
686         {-0.5, UDAT_REL_UNIT_MINUTE, "0.5 minutes ago"},
687         {-1.0, UDAT_REL_UNIT_MINUTE, "1 minute ago"},
688         {-2.0, UDAT_REL_UNIT_MINUTE, "2 minutes ago"},
689         {-0.0, UDAT_REL_UNIT_HOUR, "0 hours ago"},
690         {-0.5, UDAT_REL_UNIT_HOUR, "0.5 hours ago"},
691         {-1.0, UDAT_REL_UNIT_HOUR, "1 hour ago"},
692         {-2.0, UDAT_REL_UNIT_HOUR, "2 hours ago"},
693         {-0.0, UDAT_REL_UNIT_DAY, "today"},
694         {-0.5, UDAT_REL_UNIT_DAY, "0.5 days ago"},
695         {-1.0, UDAT_REL_UNIT_DAY, "yesterday"},
696         {-2.0, UDAT_REL_UNIT_DAY, "2 days ago"},
697         {-0.0, UDAT_REL_UNIT_WEEK, "this week"},
698         {-0.5, UDAT_REL_UNIT_WEEK, "0.5 weeks ago"},
699         {-1.0, UDAT_REL_UNIT_WEEK, "last week"},
700         {-2.0, UDAT_REL_UNIT_WEEK, "2 weeks ago"},
701         {-0.0, UDAT_REL_UNIT_MONTH, "this month"},
702         {-0.5, UDAT_REL_UNIT_MONTH, "0.5 months ago"},
703         {-1.0, UDAT_REL_UNIT_MONTH, "last month"},
704         {-2.0, UDAT_REL_UNIT_MONTH, "2 months ago"},
705         {-0.0, UDAT_REL_UNIT_QUARTER, "this quarter"},
706         {-0.5, UDAT_REL_UNIT_QUARTER, "0.5 quarters ago"},
707         {-1.0, UDAT_REL_UNIT_QUARTER, "last quarter"},
708         {-2.0, UDAT_REL_UNIT_QUARTER, "2 quarters ago"},
709         {-0.0, UDAT_REL_UNIT_YEAR, "this year"},
710         {-0.5, UDAT_REL_UNIT_YEAR, "0.5 years ago"},
711         {-1.0, UDAT_REL_UNIT_YEAR, "last year"},
712         {-2.0, UDAT_REL_UNIT_YEAR, "2 years ago"},
713         {-0.0, UDAT_REL_UNIT_SUNDAY, "this Sunday"},
714         {-0.5, UDAT_REL_UNIT_SUNDAY, "0.5 Sundays ago"},
715         {-1.0, UDAT_REL_UNIT_SUNDAY, "last Sunday"},
716         {-2.0, UDAT_REL_UNIT_SUNDAY, "2 Sundays ago"},
717         {-0.0, UDAT_REL_UNIT_MONDAY, "this Monday"},
718         {-0.5, UDAT_REL_UNIT_MONDAY, "0.5 Mondays ago"},
719         {-1.0, UDAT_REL_UNIT_MONDAY, "last Monday"},
720         {-2.0, UDAT_REL_UNIT_MONDAY, "2 Mondays ago"},
721         {-0.0, UDAT_REL_UNIT_TUESDAY, "this Tuesday"},
722         {-0.5, UDAT_REL_UNIT_TUESDAY, "0.5 Tuesdays ago"},
723         {-1.0, UDAT_REL_UNIT_TUESDAY, "last Tuesday"},
724         {-2.0, UDAT_REL_UNIT_TUESDAY, "2 Tuesdays ago"},
725         {-0.0, UDAT_REL_UNIT_WEDNESDAY, "this Wednesday"},
726         {-0.5, UDAT_REL_UNIT_WEDNESDAY, "0.5 Wednesdays ago"},
727         {-1.0, UDAT_REL_UNIT_WEDNESDAY, "last Wednesday"},
728         {-2.0, UDAT_REL_UNIT_WEDNESDAY, "2 Wednesdays ago"},
729         {-0.0, UDAT_REL_UNIT_THURSDAY, "this Thursday"},
730         {-0.5, UDAT_REL_UNIT_THURSDAY, "0.5 Thursdays ago"},
731         {-1.0, UDAT_REL_UNIT_THURSDAY, "last Thursday"},
732         {-2.0, UDAT_REL_UNIT_THURSDAY, "2 Thursdays ago"},
733         {-0.0, UDAT_REL_UNIT_FRIDAY, "this Friday"},
734         {-0.5, UDAT_REL_UNIT_FRIDAY, "0.5 Fridays ago"},
735         {-1.0, UDAT_REL_UNIT_FRIDAY, "last Friday"},
736         {-2.0, UDAT_REL_UNIT_FRIDAY, "2 Fridays ago"},
737         {-0.0, UDAT_REL_UNIT_SATURDAY, "this Saturday"},
738         {-0.5, UDAT_REL_UNIT_SATURDAY, "0.5 Saturdays ago"},
739         {-1.0, UDAT_REL_UNIT_SATURDAY, "last Saturday"},
740         {-2.0, UDAT_REL_UNIT_SATURDAY, "2 Saturdays ago"}
741 };
742 
743 
744 class RelativeDateTimeFormatterTest : public IntlTest {
745 public:
RelativeDateTimeFormatterTest()746     RelativeDateTimeFormatterTest() {
747     }
748 
749     void runIndexedTest(int32_t index, UBool exec, const char *&name, char *par=0);
750 private:
751     void TestEnglish();
752     void TestEnglishCaps();
753     void TestEnglishShort();
754     void TestEnglishNarrow();
755     void TestSerbian();
756     void TestSerbianFallback();
757     void TestEnglishNoQuantity();
758     void TestEnglishNoQuantityCaps();
759     void TestEnglishNoQuantityShort();
760     void TestEnglishNoQuantityNarrow();
761     void TestSpanishNoQuantity();
762     void TestFormatWithQuantityIllegalArgument();
763     void TestFormatWithoutQuantityIllegalArgument();
764     void TestCustomNumberFormat();
765     void TestGetters();
766     void TestCombineDateAndTime();
767     void TestBadDisplayContext();
768     void TestFormat();
769     void TestFormatNumeric();
770     void TestLocales();
771     void RunTest(
772             const Locale& locale,
773             const WithQuantityExpected* expectedResults,
774             int32_t expectedResultLength);
775     void RunTest(
776             const Locale& locale,
777             const WithQuantityExpectedRelativeDateTimeUnit* expectedResults,
778             int32_t expectedResultLength,
779             bool numeric);
780     void RunTest(
781             const Locale& locale,
782             UDateRelativeDateTimeFormatterStyle style,
783             const WithQuantityExpected* expectedResults,
784             int32_t expectedResultLength);
785     void RunTest(
786             const Locale& locale,
787             const WithoutQuantityExpected* expectedResults,
788             int32_t expectedResultLength);
789     void RunTest(
790             const Locale& locale,
791             UDateRelativeDateTimeFormatterStyle style,
792             const WithoutQuantityExpected* expectedResults,
793             int32_t expectedResultLength);
794     void RunTest(
795             const RelativeDateTimeFormatter& fmt,
796             const WithQuantityExpected* expectedResults,
797             int32_t expectedResultLength,
798             const char *description);
799     void RunTest(
800             const RelativeDateTimeFormatter& fmt,
801             const WithQuantityExpectedRelativeDateTimeUnit* expectedResults,
802             int32_t expectedResultLength,
803             const char *description,
804             bool numeric);
805     void RunTest(
806             const RelativeDateTimeFormatter& fmt,
807             const WithoutQuantityExpected* expectedResults,
808             int32_t expectedResultLength,
809             const char *description);
810     void CheckExpectedResult(
811             const RelativeDateTimeFormatter& fmt,
812             const WithQuantityExpected& expectedResult,
813             const char* description);
814     void CheckExpectedResult(
815             const RelativeDateTimeFormatter& fmt,
816             const WithQuantityExpectedRelativeDateTimeUnit& expectedResults,
817             const char* description,
818             bool numeric);
819     void CheckExpectedResult(
820             const RelativeDateTimeFormatter& fmt,
821             const WithoutQuantityExpected& expectedResult,
822             const char* description);
823     void VerifyIllegalArgument(
824             const RelativeDateTimeFormatter& fmt,
825             UDateDirection direction,
826             UDateRelativeUnit unit);
827     void VerifyIllegalArgument(
828             const RelativeDateTimeFormatter& fmt,
829             UDateDirection direction,
830             UDateAbsoluteUnit unit);
831     void TestSidewaysDataLoading(void);
832 };
833 
runIndexedTest(int32_t index,UBool exec,const char * & name,char *)834 void RelativeDateTimeFormatterTest::runIndexedTest(
835         int32_t index, UBool exec, const char *&name, char *) {
836     if (exec) {
837         logln("TestSuite RelativeDateTimeFormatterTest: ");
838     }
839     TESTCASE_AUTO_BEGIN;
840     TESTCASE_AUTO(TestEnglish);
841     TESTCASE_AUTO(TestEnglishCaps);
842     TESTCASE_AUTO(TestEnglishShort);
843     TESTCASE_AUTO(TestEnglishNarrow);
844     TESTCASE_AUTO(TestSerbian);
845     TESTCASE_AUTO(TestSerbianFallback);
846     TESTCASE_AUTO(TestEnglishNoQuantity);
847     TESTCASE_AUTO(TestEnglishNoQuantityCaps);
848     TESTCASE_AUTO(TestEnglishNoQuantityShort);
849     TESTCASE_AUTO(TestEnglishNoQuantityNarrow);
850     TESTCASE_AUTO(TestSpanishNoQuantity);
851     TESTCASE_AUTO(TestFormatWithQuantityIllegalArgument);
852     TESTCASE_AUTO(TestFormatWithoutQuantityIllegalArgument);
853     TESTCASE_AUTO(TestCustomNumberFormat);
854     TESTCASE_AUTO(TestGetters);
855     TESTCASE_AUTO(TestCombineDateAndTime);
856     TESTCASE_AUTO(TestBadDisplayContext);
857     TESTCASE_AUTO(TestSidewaysDataLoading);
858     TESTCASE_AUTO(TestFormat);
859     TESTCASE_AUTO(TestFormatNumeric);
860     TESTCASE_AUTO(TestLocales);
861     TESTCASE_AUTO_END;
862 }
863 
TestEnglish()864 void RelativeDateTimeFormatterTest::TestEnglish() {
865     RunTest("en", kEnglish, UPRV_LENGTHOF(kEnglish));
866 }
867 
TestEnglishCaps()868 void RelativeDateTimeFormatterTest::TestEnglishCaps() {
869     UErrorCode status = U_ZERO_ERROR;
870     RelativeDateTimeFormatter fmt(
871             "en",
872             NULL,
873             UDAT_STYLE_LONG,
874             UDISPCTX_CAPITALIZATION_FOR_BEGINNING_OF_SENTENCE,
875             status);
876     if (U_FAILURE(status)) {
877         dataerrln("Failed call to RelativeDateTimeFormatter(\"en\", NULL, UDAT_STYLE_LONG, UDISPCTX_CAPITALIZATION_FOR_BEGINNING_OF_SENTENCE, status); : %s", u_errorName(status));
878         return;
879     }
880     RelativeDateTimeFormatter fmt3(status);
881 
882     // Test assignment and copy constructor with capitalization on.
883     RelativeDateTimeFormatter fmt2(fmt);
884     fmt3 = fmt2;
885     assertSuccess("", status);
886     RunTest(fmt3, kEnglishCaps, UPRV_LENGTHOF(kEnglishCaps), "en caps");
887 }
888 
TestEnglishShort()889 void RelativeDateTimeFormatterTest::TestEnglishShort() {
890     RunTest("en", UDAT_STYLE_SHORT, kEnglishShort, UPRV_LENGTHOF(kEnglishShort));
891 }
892 
TestEnglishNarrow()893 void RelativeDateTimeFormatterTest::TestEnglishNarrow() {
894     RunTest("en", UDAT_STYLE_NARROW, kEnglishShort, UPRV_LENGTHOF(kEnglishShort));
895 }
896 
TestSerbian()897 void RelativeDateTimeFormatterTest::TestSerbian() {
898     RunTest("sr", kSerbian, UPRV_LENGTHOF(kSerbian));
899 }
900 
TestSerbianFallback()901 void RelativeDateTimeFormatterTest::TestSerbianFallback() {
902     RunTest("sr", UDAT_STYLE_NARROW, kSerbianNarrow, UPRV_LENGTHOF(kSerbianNarrow));
903 }
904 
TestEnglishNoQuantity()905 void RelativeDateTimeFormatterTest::TestEnglishNoQuantity() {
906     RunTest("en", kEnglishNoQuantity, UPRV_LENGTHOF(kEnglishNoQuantity));
907 }
908 
TestEnglishNoQuantityCaps()909 void RelativeDateTimeFormatterTest::TestEnglishNoQuantityCaps() {
910     UErrorCode status = U_ZERO_ERROR;
911     RelativeDateTimeFormatter fmt(
912             "en",
913             NULL,
914             UDAT_STYLE_LONG,
915             UDISPCTX_CAPITALIZATION_FOR_BEGINNING_OF_SENTENCE,
916             status);
917     if (assertSuccess("RelativeDateTimeFormatter", status, TRUE) == FALSE) {
918         return;
919     }
920     RunTest(
921             fmt,
922             kEnglishNoQuantityCaps,
923             UPRV_LENGTHOF(kEnglishNoQuantityCaps),
924             "en caps no quantity");
925 }
926 
TestEnglishNoQuantityShort()927 void RelativeDateTimeFormatterTest::TestEnglishNoQuantityShort() {
928     RunTest(
929             "en",
930             UDAT_STYLE_SHORT,
931             kEnglishNoQuantityShort,
932             UPRV_LENGTHOF(kEnglishNoQuantityShort));
933 }
934 
TestEnglishNoQuantityNarrow()935 void RelativeDateTimeFormatterTest::TestEnglishNoQuantityNarrow() {
936     RunTest(
937             "en",
938             UDAT_STYLE_NARROW,
939             kEnglishNoQuantityNarrow,
940             UPRV_LENGTHOF(kEnglishNoQuantityNarrow));
941 }
942 
TestSpanishNoQuantity()943 void RelativeDateTimeFormatterTest::TestSpanishNoQuantity() {
944     RunTest("es", kSpanishNoQuantity, UPRV_LENGTHOF(kSpanishNoQuantity));
945 }
946 
TestFormatWithQuantityIllegalArgument()947 void RelativeDateTimeFormatterTest::TestFormatWithQuantityIllegalArgument() {
948     UErrorCode status = U_ZERO_ERROR;
949     RelativeDateTimeFormatter fmt("en", status);
950     if (U_FAILURE(status)) {
951         dataerrln("Failure creating format object - %s", u_errorName(status));
952         return;
953     }
954     VerifyIllegalArgument(fmt, UDAT_DIRECTION_PLAIN, UDAT_RELATIVE_DAYS);
955     VerifyIllegalArgument(fmt, UDAT_DIRECTION_THIS, UDAT_RELATIVE_DAYS);
956 }
957 
TestFormatWithoutQuantityIllegalArgument()958 void RelativeDateTimeFormatterTest::TestFormatWithoutQuantityIllegalArgument() {
959     UErrorCode status = U_ZERO_ERROR;
960     RelativeDateTimeFormatter fmt("en", status);
961     if (U_FAILURE(status)) {
962         dataerrln("Failure creating format object - %s", u_errorName(status));
963         return;
964     }
965     VerifyIllegalArgument(fmt, UDAT_DIRECTION_LAST, UDAT_ABSOLUTE_NOW);
966     VerifyIllegalArgument(fmt, UDAT_DIRECTION_NEXT, UDAT_ABSOLUTE_NOW);
967     VerifyIllegalArgument(fmt, UDAT_DIRECTION_THIS, UDAT_ABSOLUTE_NOW);
968 }
969 
TestCustomNumberFormat()970 void RelativeDateTimeFormatterTest::TestCustomNumberFormat() {
971     NumberFormat *nf;
972     UErrorCode status = U_ZERO_ERROR;
973     {
974         RelativeDateTimeFormatter fmt("en", status);
975         if (U_FAILURE(status)) {
976             dataerrln(
977                     "Failure creating format object - %s", u_errorName(status));
978             return;
979         }
980         nf = (NumberFormat *) fmt.getNumberFormat().clone();
981     }
982     nf->setMinimumFractionDigits(1);
983     nf->setMaximumFractionDigits(1);
984     RelativeDateTimeFormatter fmt("en", nf, status);
985 
986     // Test copy constructor.
987     RelativeDateTimeFormatter fmt2(fmt);
988     RunTest(fmt2, kEnglishDecimal, UPRV_LENGTHOF(kEnglishDecimal), "en decimal digits");
989 
990     // Test assignment
991     fmt = RelativeDateTimeFormatter("es", status);
992     RunTest(fmt, kSpanishNoQuantity, UPRV_LENGTHOF(kSpanishNoQuantity), "assignment operator");
993 
994 }
995 
TestGetters()996 void RelativeDateTimeFormatterTest::TestGetters() {
997     UErrorCode status = U_ZERO_ERROR;
998     RelativeDateTimeFormatter fmt(
999             "en",
1000             NULL,
1001             UDAT_STYLE_NARROW,
1002             UDISPCTX_CAPITALIZATION_FOR_MIDDLE_OF_SENTENCE,
1003             status);
1004     if (U_FAILURE(status)) {
1005         dataerrln("Failed call to RelativeDateTimeFormatter(\"en\", NULL, UDAT_STYLE_NARROW, UDISPCTX_CAPITALIZATION_FOR_MIDDLE_OF_SENTENCE, status);) : %s", u_errorName(status));
1006         return;
1007     }
1008     RelativeDateTimeFormatter fmt3(status);
1009 
1010     // copy and assignment.
1011     RelativeDateTimeFormatter fmt2(fmt);
1012     fmt3 = fmt2;
1013     assertEquals("style", (int32_t)UDAT_STYLE_NARROW, fmt3.getFormatStyle());
1014     assertEquals(
1015             "context",
1016             (int32_t)UDISPCTX_CAPITALIZATION_FOR_MIDDLE_OF_SENTENCE,
1017             fmt3.getCapitalizationContext());
1018     assertSuccess("", status);
1019 }
1020 
TestCombineDateAndTime()1021 void RelativeDateTimeFormatterTest::TestCombineDateAndTime() {
1022     UErrorCode status = U_ZERO_ERROR;
1023     RelativeDateTimeFormatter fmt("en", status);
1024     if (U_FAILURE(status)) {
1025         dataerrln("Failure creating format object - %s", u_errorName(status));
1026         return;
1027     }
1028     UnicodeString actual;
1029     fmt.combineDateAndTime(
1030         UnicodeString("yesterday"),
1031         UnicodeString("3:50"),
1032         actual,
1033         status);
1034     UnicodeString expected("yesterday, 3:50");
1035     if (expected != actual) {
1036         errln("Expected "+expected+", got "+actual);
1037     }
1038 }
1039 
TestBadDisplayContext()1040 void RelativeDateTimeFormatterTest::TestBadDisplayContext() {
1041     UErrorCode status = U_ZERO_ERROR;
1042     RelativeDateTimeFormatter fmt(
1043             "en", NULL, UDAT_STYLE_LONG, UDISPCTX_STANDARD_NAMES, status);
1044     if (status != U_ILLEGAL_ARGUMENT_ERROR) {
1045         errln("Expected U_ILLEGAL_ARGUMENT_ERROR, got %s", u_errorName(status));
1046     }
1047 }
1048 
1049 
1050 
RunTest(const Locale & locale,const WithQuantityExpected * expectedResults,int32_t expectedResultLength)1051 void RelativeDateTimeFormatterTest::RunTest(
1052         const Locale& locale,
1053         const WithQuantityExpected* expectedResults,
1054         int32_t expectedResultLength) {
1055     UErrorCode status = U_ZERO_ERROR;
1056     RelativeDateTimeFormatter fmt(locale, status);
1057     if (U_FAILURE(status)) {
1058         dataerrln("Unable to create format object - %s", u_errorName(status));
1059         return;
1060     }
1061     RunTest(fmt, expectedResults, expectedResultLength, locale.getName());
1062 }
1063 
RunTest(const Locale & locale,const WithQuantityExpectedRelativeDateTimeUnit * expectedResults,int32_t expectedResultLength,bool numeric)1064 void RelativeDateTimeFormatterTest::RunTest(
1065         const Locale& locale,
1066         const WithQuantityExpectedRelativeDateTimeUnit* expectedResults,
1067         int32_t expectedResultLength,
1068         bool numeric) {
1069     UErrorCode status = U_ZERO_ERROR;
1070     RelativeDateTimeFormatter fmt(locale, status);
1071     if (U_FAILURE(status)) {
1072         dataerrln("Unable to create format object - %s", u_errorName(status));
1073         return;
1074     }
1075     RunTest(fmt, expectedResults, expectedResultLength, locale.getName(), numeric);
1076 }
1077 
1078 
RunTest(const Locale & locale,UDateRelativeDateTimeFormatterStyle style,const WithQuantityExpected * expectedResults,int32_t expectedResultLength)1079 void RelativeDateTimeFormatterTest::RunTest(
1080         const Locale& locale,
1081         UDateRelativeDateTimeFormatterStyle style,
1082         const WithQuantityExpected* expectedResults,
1083         int32_t expectedResultLength) {
1084     UErrorCode status = U_ZERO_ERROR;
1085     RelativeDateTimeFormatter fmt(
1086             locale, NULL, style, UDISPCTX_CAPITALIZATION_NONE, status);
1087     if (U_FAILURE(status)) {
1088         dataerrln("Unable to create format object - %s", u_errorName(status));
1089         return;
1090     }
1091     RunTest(fmt, expectedResults, expectedResultLength, locale.getName());
1092 }
1093 
RunTest(const Locale & locale,const WithoutQuantityExpected * expectedResults,int32_t expectedResultLength)1094 void RelativeDateTimeFormatterTest::RunTest(
1095         const Locale& locale,
1096         const WithoutQuantityExpected* expectedResults,
1097         int32_t expectedResultLength) {
1098     UErrorCode status = U_ZERO_ERROR;
1099     RelativeDateTimeFormatter fmt(locale, status);
1100     if (U_FAILURE(status)) {
1101         dataerrln("Unable to create format object - %s", u_errorName(status));
1102         return;
1103     }
1104     RunTest(fmt, expectedResults, expectedResultLength, locale.getName());
1105 }
1106 
RunTest(const Locale & locale,UDateRelativeDateTimeFormatterStyle style,const WithoutQuantityExpected * expectedResults,int32_t expectedResultLength)1107 void RelativeDateTimeFormatterTest::RunTest(
1108         const Locale& locale,
1109         UDateRelativeDateTimeFormatterStyle style,
1110         const WithoutQuantityExpected* expectedResults,
1111         int32_t expectedResultLength) {
1112     UErrorCode status = U_ZERO_ERROR;
1113     RelativeDateTimeFormatter fmt(
1114             locale, NULL, style, UDISPCTX_CAPITALIZATION_NONE, status);
1115     if (U_FAILURE(status)) {
1116         dataerrln("Unable to create format object - %s", u_errorName(status));
1117         return;
1118     }
1119     RunTest(fmt, expectedResults, expectedResultLength, locale.getName());
1120 }
1121 
RunTest(const RelativeDateTimeFormatter & fmt,const WithQuantityExpected * expectedResults,int32_t expectedResultLength,const char * description)1122 void RelativeDateTimeFormatterTest::RunTest(
1123         const RelativeDateTimeFormatter& fmt,
1124         const WithQuantityExpected* expectedResults,
1125         int32_t expectedResultLength,
1126         const char *description) {
1127     for (int32_t i = 0; i < expectedResultLength; ++i) {
1128         CheckExpectedResult(fmt, expectedResults[i], description);
1129     }
1130 }
1131 
RunTest(const RelativeDateTimeFormatter & fmt,const WithQuantityExpectedRelativeDateTimeUnit * expectedResults,int32_t expectedResultLength,const char * description,bool numeric)1132 void RelativeDateTimeFormatterTest::RunTest(
1133         const RelativeDateTimeFormatter& fmt,
1134         const WithQuantityExpectedRelativeDateTimeUnit* expectedResults,
1135         int32_t expectedResultLength,
1136         const char *description,
1137         bool numeric) {
1138     for (int32_t i = 0; i < expectedResultLength; ++i) {
1139         CheckExpectedResult(fmt, expectedResults[i], description, numeric);
1140     }
1141 }
1142 
RunTest(const RelativeDateTimeFormatter & fmt,const WithoutQuantityExpected * expectedResults,int32_t expectedResultLength,const char * description)1143 void RelativeDateTimeFormatterTest::RunTest(
1144         const RelativeDateTimeFormatter& fmt,
1145         const WithoutQuantityExpected* expectedResults,
1146         int32_t expectedResultLength,
1147         const char *description) {
1148     for (int32_t i = 0; i < expectedResultLength; ++i) {
1149         CheckExpectedResult(fmt, expectedResults[i], description);
1150     }
1151 }
1152 
CheckExpectedResult(const RelativeDateTimeFormatter & fmt,const WithQuantityExpected & expectedResult,const char * description)1153 void RelativeDateTimeFormatterTest::CheckExpectedResult(
1154         const RelativeDateTimeFormatter& fmt,
1155         const WithQuantityExpected& expectedResult,
1156         const char* description) {
1157     UErrorCode status = U_ZERO_ERROR;
1158     UnicodeString actual;
1159     fmt.format(expectedResult.value, expectedResult.direction, expectedResult.unit, actual, status);
1160     UnicodeString expected(expectedResult.expected, -1, US_INV);
1161     expected = expected.unescape();
1162     char buffer[256];
1163     sprintf(
1164             buffer,
1165             "%s, %f, %s, %s",
1166             description,
1167             expectedResult.value,
1168             DirectionStr(expectedResult.direction),
1169             RelativeUnitStr(expectedResult.unit));
1170     if (actual != expected) {
1171         errln(UnicodeString("Fail: Expected: ") + expected
1172                 + ", Got: " + actual
1173                 + ", For: " + buffer);
1174     }
1175 }
1176 
CheckExpectedResult(const RelativeDateTimeFormatter & fmt,const WithQuantityExpectedRelativeDateTimeUnit & expectedResult,const char * description,bool numeric)1177 void RelativeDateTimeFormatterTest::CheckExpectedResult(
1178         const RelativeDateTimeFormatter& fmt,
1179         const WithQuantityExpectedRelativeDateTimeUnit& expectedResult,
1180         const char* description,
1181         bool numeric) {
1182     UErrorCode status = U_ZERO_ERROR;
1183     UnicodeString actual;
1184     if (numeric) {
1185       fmt.formatNumeric(expectedResult.value, expectedResult.unit, actual, status);
1186     } else {
1187       fmt.format(expectedResult.value, expectedResult.unit, actual, status);
1188     }
1189     UnicodeString expected(expectedResult.expected, -1, US_INV);
1190     expected = expected.unescape();
1191     char buffer[256];
1192     sprintf(
1193             buffer,
1194             "%s, %f, %s",
1195             description,
1196             expectedResult.value,
1197             RelativeDateTimeUnitStr(expectedResult.unit));
1198     if (actual != expected) {
1199         errln(UnicodeString("Fail: Expected: ") + expected
1200                 + ", Got: " + actual
1201                 + ", For: " + buffer);
1202     }
1203 }
1204 
CheckExpectedResult(const RelativeDateTimeFormatter & fmt,const WithoutQuantityExpected & expectedResult,const char * description)1205 void RelativeDateTimeFormatterTest::CheckExpectedResult(
1206         const RelativeDateTimeFormatter& fmt,
1207         const WithoutQuantityExpected& expectedResult,
1208         const char* description) {
1209     UErrorCode status = U_ZERO_ERROR;
1210     UnicodeString actual;
1211     fmt.format(expectedResult.direction, expectedResult.unit, actual, status);
1212     UnicodeString expected(expectedResult.expected, -1, US_INV);
1213     expected = expected.unescape();
1214     char buffer[256];
1215     sprintf(
1216             buffer,
1217             "%s, %s, %s",
1218             description,
1219             DirectionStr(expectedResult.direction),
1220             AbsoluteUnitStr(expectedResult.unit));
1221     if (actual != expected) {
1222         errln(UnicodeString("Fail: Expected: ") + expected
1223                 + ", Got: " + actual
1224                 + ", For: " + buffer);
1225     }
1226 }
1227 
VerifyIllegalArgument(const RelativeDateTimeFormatter & fmt,UDateDirection direction,UDateRelativeUnit unit)1228 void RelativeDateTimeFormatterTest::VerifyIllegalArgument(
1229         const RelativeDateTimeFormatter& fmt,
1230         UDateDirection direction,
1231         UDateRelativeUnit unit) {
1232     UnicodeString appendTo;
1233     UErrorCode status = U_ZERO_ERROR;
1234     fmt.format(1.0, direction, unit, appendTo, status);
1235     if (status != U_ILLEGAL_ARGUMENT_ERROR) {
1236         errln("Expected U_ILLEGAL_ARGUMENT_ERROR, got %s", u_errorName(status));
1237     }
1238 }
1239 
VerifyIllegalArgument(const RelativeDateTimeFormatter & fmt,UDateDirection direction,UDateAbsoluteUnit unit)1240 void RelativeDateTimeFormatterTest::VerifyIllegalArgument(
1241         const RelativeDateTimeFormatter& fmt,
1242         UDateDirection direction,
1243         UDateAbsoluteUnit unit) {
1244     UnicodeString appendTo;
1245     UErrorCode status = U_ZERO_ERROR;
1246     fmt.format(direction, unit, appendTo, status);
1247     if (status != U_ILLEGAL_ARGUMENT_ERROR) {
1248         errln("Expected U_ILLEGAL_ARGUMENT_ERROR, got %s", u_errorName(status));
1249     }
1250 }
1251 
1252 /* Add tests to check "sideways" data loading. */
TestSidewaysDataLoading(void)1253 void RelativeDateTimeFormatterTest::TestSidewaysDataLoading(void) {
1254     UErrorCode status = U_ZERO_ERROR;
1255     UnicodeString actual;
1256     UnicodeString expected;
1257     Locale enGbLocale("en_GB");
1258 
1259     RelativeDateTimeFormatter fmt(enGbLocale, NULL, UDAT_STYLE_NARROW,
1260                                   UDISPCTX_CAPITALIZATION_NONE, status);
1261     if (U_FAILURE(status)) {
1262         dataerrln("Unable to create RelativeDateTimeFormatter - %s", u_errorName(status));
1263         return;
1264     }
1265 
1266     status = U_ZERO_ERROR;
1267     actual = "";
1268     fmt.format(3.0, UDAT_DIRECTION_NEXT, UDAT_RELATIVE_MONTHS, actual, status);
1269     expected = "in 3 mo";
1270     assertEquals("narrow in 3 mo", expected, actual);
1271 
1272     fmt.format(3.0, UDAT_DIRECTION_LAST, UDAT_RELATIVE_DAYS, actual.remove(), status);
1273     expected = "3 days ago";
1274     assertEquals("3 days ago (positive 3.0): ", expected, actual);
1275 
1276     expected = "-3 days ago";
1277     fmt.format(-3.0, UDAT_DIRECTION_LAST, UDAT_RELATIVE_DAYS, actual.remove(), status);
1278     assertEquals("3 days ago (negative 3.0): ", expected, actual);
1279 
1280     expected = "next yr.";
1281     fmt.format(UDAT_DIRECTION_NEXT, UDAT_ABSOLUTE_YEAR, actual.remove(), status);
1282     assertEquals("next year: ", expected, actual);
1283 
1284     // Testing the SHORT style
1285     RelativeDateTimeFormatter fmtshort(enGbLocale, NULL, UDAT_STYLE_SHORT,
1286                                   UDISPCTX_CAPITALIZATION_NONE, status);
1287     expected = "now";
1288     fmtshort.format(0.0, UDAT_DIRECTION_NEXT, UDAT_RELATIVE_SECONDS, actual.remove(), status);
1289 
1290     expected = "next yr.";
1291     fmt.format(UDAT_DIRECTION_NEXT, UDAT_ABSOLUTE_YEAR, actual.remove(), status);
1292     assertEquals("next year: ", expected, actual);
1293 }
1294 
TestFormatNumeric()1295 void RelativeDateTimeFormatterTest::TestFormatNumeric() {
1296     RunTest("en", kEnglishFormatNumeric, UPRV_LENGTHOF(kEnglishFormatNumeric), true);
1297 }
1298 
TestFormat()1299 void RelativeDateTimeFormatterTest::TestFormat() {
1300     RunTest("en", kEnglishFormat, UPRV_LENGTHOF(kEnglishFormat), false);
1301 }
1302 
TestLocales()1303 void RelativeDateTimeFormatterTest::TestLocales() {
1304     int32_t numLocales = 0;
1305     const Locale *availableLocales = Locale::getAvailableLocales(numLocales);
1306     std::vector<std::unique_ptr<RelativeDateTimeFormatter>> allFormatters;
1307     for (int localeIdx=0; localeIdx<numLocales; localeIdx++) {
1308         const Locale &loc = availableLocales[localeIdx];
1309         UErrorCode status = U_ZERO_ERROR;
1310         std::unique_ptr<RelativeDateTimeFormatter> rdtf(new RelativeDateTimeFormatter(loc, status));
1311         allFormatters.push_back(std::move(rdtf));
1312         assertSuccess(loc.getName(), status);
1313     }
1314 }
1315 
1316 static const char *kLast2 = "Last_2";
1317 static const char *kLast = "Last";
1318 static const char *kThis = "This";
1319 static const char *kNext = "Next";
1320 static const char *kNext2 = "Next_2";
1321 static const char *kPlain = "Plain";
1322 
1323 static const char *kSeconds = "Seconds";
1324 static const char *kMinutes = "Minutes";
1325 static const char *kHours = "Hours";
1326 static const char *kDays = "Days";
1327 static const char *kWeeks = "Weeks";
1328 static const char *kMonths = "Months";
1329 static const char *kQuarters = "Quarters";
1330 static const char *kYears = "Years";
1331 static const char *kSundays = "Sundays";
1332 static const char *kMondays = "Mondays";
1333 static const char *kTuesdays = "Tuesdays";
1334 static const char *kWednesdays = "Wednesdays";
1335 static const char *kThursdays = "Thursdays";
1336 static const char *kFridays = "Fridays";
1337 static const char *kSaturdays = "Saturdays";
1338 
1339 static const char *kSunday = "Sunday";
1340 static const char *kMonday = "Monday";
1341 static const char *kTuesday = "Tuesday";
1342 static const char *kWednesday = "Wednesday";
1343 static const char *kThursday = "Thursday";
1344 static const char *kFriday = "Friday";
1345 static const char *kSaturday = "Saturday";
1346 static const char *kDay = "Day";
1347 static const char *kWeek = "Week";
1348 static const char *kMonth = "Month";
1349 static const char *kQuarter = "Quarter";
1350 static const char *kYear = "Year";
1351 static const char *kNow = "Now";
1352 
1353 static const char *kUndefined = "Undefined";
1354 
DirectionStr(UDateDirection direction)1355 static const char *DirectionStr(
1356         UDateDirection direction) {
1357     switch (direction) {
1358         case UDAT_DIRECTION_LAST_2:
1359             return kLast2;
1360         case UDAT_DIRECTION_LAST:
1361             return kLast;
1362         case UDAT_DIRECTION_THIS:
1363             return kThis;
1364         case UDAT_DIRECTION_NEXT:
1365             return kNext;
1366         case UDAT_DIRECTION_NEXT_2:
1367             return kNext2;
1368         case UDAT_DIRECTION_PLAIN:
1369             return kPlain;
1370         default:
1371             return kUndefined;
1372     }
1373     return kUndefined;
1374 }
1375 
RelativeUnitStr(UDateRelativeUnit unit)1376 static const char *RelativeUnitStr(
1377         UDateRelativeUnit unit) {
1378     switch (unit) {
1379         case UDAT_RELATIVE_SECONDS:
1380             return kSeconds;
1381         case UDAT_RELATIVE_MINUTES:
1382             return kMinutes;
1383         case UDAT_RELATIVE_HOURS:
1384             return kHours;
1385         case UDAT_RELATIVE_DAYS:
1386             return kDays;
1387         case UDAT_RELATIVE_WEEKS:
1388             return kWeeks;
1389         case UDAT_RELATIVE_MONTHS:
1390             return kMonths;
1391         case UDAT_RELATIVE_YEARS:
1392             return kYears;
1393         default:
1394             return kUndefined;
1395     }
1396     return kUndefined;
1397 }
1398 
RelativeDateTimeUnitStr(URelativeDateTimeUnit unit)1399 static const char *RelativeDateTimeUnitStr(
1400         URelativeDateTimeUnit  unit) {
1401     switch (unit) {
1402         case UDAT_REL_UNIT_SECOND:
1403             return kSeconds;
1404         case UDAT_REL_UNIT_MINUTE:
1405             return kMinutes;
1406         case UDAT_REL_UNIT_HOUR:
1407             return kHours;
1408         case UDAT_REL_UNIT_DAY:
1409             return kDays;
1410         case UDAT_REL_UNIT_WEEK:
1411             return kWeeks;
1412         case UDAT_REL_UNIT_MONTH:
1413             return kMonths;
1414         case UDAT_REL_UNIT_QUARTER:
1415             return kQuarters;
1416         case UDAT_REL_UNIT_YEAR:
1417             return kYears;
1418         case UDAT_REL_UNIT_SUNDAY:
1419             return kSundays;
1420         case UDAT_REL_UNIT_MONDAY:
1421             return kMondays;
1422         case UDAT_REL_UNIT_TUESDAY:
1423             return kTuesdays;
1424         case UDAT_REL_UNIT_WEDNESDAY:
1425             return kWednesdays;
1426         case UDAT_REL_UNIT_THURSDAY:
1427             return kThursdays;
1428         case UDAT_REL_UNIT_FRIDAY:
1429             return kFridays;
1430         case UDAT_REL_UNIT_SATURDAY:
1431             return kSaturdays;
1432         default:
1433             return kUndefined;
1434     }
1435     return kUndefined;
1436 }
1437 
AbsoluteUnitStr(UDateAbsoluteUnit unit)1438 static const char *AbsoluteUnitStr(
1439         UDateAbsoluteUnit unit) {
1440     switch (unit) {
1441         case UDAT_ABSOLUTE_SUNDAY:
1442             return kSunday;
1443         case UDAT_ABSOLUTE_MONDAY:
1444             return kMonday;
1445         case UDAT_ABSOLUTE_TUESDAY:
1446             return kTuesday;
1447         case UDAT_ABSOLUTE_WEDNESDAY:
1448             return kWednesday;
1449         case UDAT_ABSOLUTE_THURSDAY:
1450             return kThursday;
1451         case UDAT_ABSOLUTE_FRIDAY:
1452             return kFriday;
1453         case UDAT_ABSOLUTE_SATURDAY:
1454             return kSaturday;
1455         case UDAT_ABSOLUTE_DAY:
1456             return kDay;
1457         case UDAT_ABSOLUTE_WEEK:
1458             return kWeek;
1459         case UDAT_ABSOLUTE_MONTH:
1460             return kMonth;
1461         case UDAT_ABSOLUTE_QUARTER:
1462             return kQuarter;
1463         case UDAT_ABSOLUTE_YEAR:
1464             return kYear;
1465         case UDAT_ABSOLUTE_NOW:
1466             return kNow;
1467         default:
1468             return kUndefined;
1469     }
1470     return kUndefined;
1471 }
1472 
createRelativeDateTimeFormatterTest()1473 extern IntlTest *createRelativeDateTimeFormatterTest() {
1474     return new RelativeDateTimeFormatterTest();
1475 }
1476 
1477 #endif
1478