1 /* |
1 /* |
2 * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. |
7 * published by the Free Software Foundation. |
42 |
42 |
43 DateFormatProviderTest() { |
43 DateFormatProviderTest() { |
44 availableLocalesTest(); |
44 availableLocalesTest(); |
45 objectValidityTest(); |
45 objectValidityTest(); |
46 extendedVariantTest(); |
46 extendedVariantTest(); |
|
47 messageFormatTest(); |
47 } |
48 } |
48 |
49 |
49 void availableLocalesTest() { |
50 void availableLocalesTest() { |
50 Set<Locale> localesFromAPI = new HashSet<Locale>(availloc); |
51 Set<Locale> localesFromAPI = new HashSet<Locale>(availloc); |
51 Set<Locale> localesExpected = new HashSet<Locale>(jreloc); |
52 Set<Locale> localesExpected = new HashSet<Locale>(jreloc); |
116 if (!df.equals(provider)) { |
117 if (!df.equals(provider)) { |
117 throw new RuntimeException("variant fallback failed. test locale: "+test); |
118 throw new RuntimeException("variant fallback failed. test locale: "+test); |
118 } |
119 } |
119 } |
120 } |
120 } |
121 } |
|
122 |
|
123 |
|
124 private static final String[] TYPES = { |
|
125 "date", |
|
126 "time" |
|
127 }; |
|
128 private static final String[] MODIFIERS = { |
|
129 "", |
|
130 "short", |
|
131 "medium", // Same as DEFAULT |
|
132 "long", |
|
133 "full" |
|
134 }; |
|
135 |
|
136 void messageFormatTest() { |
|
137 for (Locale target : providerloc) { |
|
138 for (String type : TYPES) { |
|
139 for (String modifier : MODIFIERS) { |
|
140 String pattern, expected; |
|
141 if (modifier.equals("")) { |
|
142 pattern = String.format("%s={0,%s}", type, type); |
|
143 } else { |
|
144 pattern = String.format("%s={0,%s,%s}", type, type, modifier); |
|
145 } |
|
146 if (modifier.equals("medium")) { |
|
147 // medium is default. |
|
148 expected = String.format("%s={0,%s}", type, type); |
|
149 } else { |
|
150 expected = pattern; |
|
151 } |
|
152 MessageFormat mf = new MessageFormat(pattern, target); |
|
153 Format[] fmts = mf.getFormats(); |
|
154 if (fmts[0] instanceof SimpleDateFormat) { |
|
155 continue; |
|
156 } |
|
157 String toPattern = mf.toPattern(); |
|
158 if (!toPattern.equals(expected)) { |
|
159 throw new RuntimeException("messageFormatTest: got '" + toPattern |
|
160 + "', expected '" + expected + "'"); |
|
161 } |
|
162 } |
|
163 } |
|
164 } |
|
165 } |
121 } |
166 } |