|
|
5caa27 |
/* TestTranslations -- Ensure translations are available for new timezones
|
|
|
5caa27 |
Copyright (C) 2022 Red Hat, Inc.
|
|
|
5caa27 |
|
|
|
5caa27 |
This program is free software: you can redistribute it and/or modify
|
|
|
5caa27 |
it under the terms of the GNU Affero General Public License as
|
|
|
5caa27 |
published by the Free Software Foundation, either version 3 of the
|
|
|
5caa27 |
License, or (at your option) any later version.
|
|
|
5caa27 |
|
|
|
5caa27 |
This program is distributed in the hope that it will be useful,
|
|
|
5caa27 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
5caa27 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
5caa27 |
GNU Affero General Public License for more details.
|
|
|
5caa27 |
|
|
|
5caa27 |
You should have received a copy of the GNU Affero General Public License
|
|
|
5caa27 |
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
5caa27 |
*/
|
|
|
5caa27 |
|
|
|
75a6b7 |
import java.text.DateFormatSymbols;
|
|
|
75a6b7 |
|
|
|
75a6b7 |
import java.time.ZoneId;
|
|
|
75a6b7 |
import java.time.format.TextStyle;
|
|
|
75a6b7 |
|
|
|
5caa27 |
import java.util.Arrays;
|
|
|
75a6b7 |
import java.util.Collections;
|
|
|
75a6b7 |
import java.util.HashMap;
|
|
|
75a6b7 |
import java.util.Map;
|
|
|
5caa27 |
import java.util.Locale;
|
|
|
75a6b7 |
import java.util.Objects;
|
|
|
75a6b7 |
import java.util.TimeZone;
|
|
|
5caa27 |
|
|
|
5caa27 |
public class TestTranslations {
|
|
|
75a6b7 |
|
|
|
e46919 |
private static Map<Locale,String[]> KYIV, CIUDAD_JUAREZ;
|
|
|
75a6b7 |
|
|
|
75a6b7 |
static {
|
|
|
75a6b7 |
Map<Locale,String[]> map = new HashMap<Locale,String[]>();
|
|
|
75a6b7 |
map.put(Locale.US, new String[] { "Eastern European Standard Time", "GMT+02:00", "EET",
|
|
|
75a6b7 |
"Eastern European Summer Time", "GMT+03:00", "EEST",
|
|
|
75a6b7 |
"Eastern European Time", "GMT+02:00", "EET"});
|
|
|
75a6b7 |
map.put(Locale.FRANCE, new String[] { "heure normale d\u2019Europe de l\u2019Est", "UTC+02:00", "EET",
|
|
|
75a6b7 |
"heure d\u2019\u00e9t\u00e9 d\u2019Europe de l\u2019Est", "UTC+03:00", "EEST",
|
|
|
75a6b7 |
"heure d\u2019Europe de l\u2019Est", "UTC+02:00", "EET"});
|
|
|
75a6b7 |
map.put(Locale.GERMANY, new String[] { "Osteurop\u00e4ische Normalzeit", "OEZ", "OEZ",
|
|
|
75a6b7 |
"Osteurop\u00e4ische Sommerzeit", "OESZ", "OESZ",
|
|
|
75a6b7 |
"Osteurop\u00e4ische Zeit", "OEZ", "OEZ"});
|
|
|
75a6b7 |
KYIV = Collections.unmodifiableMap(map);
|
|
|
e46919 |
|
|
|
e46919 |
map = new HashMap<Locale,String[]>();
|
|
|
e46919 |
map.put(Locale.US, new String[] { "Mountain Standard Time", "MST", "MST",
|
|
|
e46919 |
"Mountain Daylight Time", "MDT", "MDT",
|
|
|
e46919 |
"Mountain Time", "MT", "MT"});
|
|
|
e46919 |
map.put(Locale.FRANCE, new String[] { "heure normale des Rocheuses", "UTC\u221207:00", "MST",
|
|
|
e46919 |
"heure d\u2019\u00e9t\u00e9 des Rocheuses", "UTC\u221206:00", "MDT",
|
|
|
e46919 |
"heure des Rocheuses", "UTC\u221207:00", "MT"});
|
|
|
e46919 |
map.put(Locale.GERMANY, new String[] { "Rocky Mountain-Normalzeit", "GMT-07:00", "MST",
|
|
|
e46919 |
"Rocky-Mountain-Sommerzeit", "GMT-06:00", "MDT",
|
|
|
e46919 |
"Rocky-Mountain-Zeit", "GMT-07:00", "MT"});
|
|
|
e46919 |
CIUDAD_JUAREZ = Collections.unmodifiableMap(map);
|
|
|
75a6b7 |
}
|
|
|
75a6b7 |
|
|
|
75a6b7 |
|
|
|
5caa27 |
public static void main(String[] args) {
|
|
|
75a6b7 |
if (args.length < 1) {
|
|
|
75a6b7 |
System.err.println("Test must be started with the name of the locale provider.");
|
|
|
75a6b7 |
System.exit(1);
|
|
|
75a6b7 |
}
|
|
|
75a6b7 |
|
|
|
75a6b7 |
System.out.println("Checking sanity of full zone string set...");
|
|
|
75a6b7 |
boolean invalid = Arrays.stream(Locale.getAvailableLocales())
|
|
|
75a6b7 |
.peek(l -> System.out.println("Locale: " + l))
|
|
|
75a6b7 |
.map(l -> DateFormatSymbols.getInstance(l).getZoneStrings())
|
|
|
75a6b7 |
.flatMap(zs -> Arrays.stream(zs))
|
|
|
75a6b7 |
.flatMap(names -> Arrays.stream(names))
|
|
|
75a6b7 |
.filter(name -> Objects.isNull(name) || name.isEmpty())
|
|
|
75a6b7 |
.findAny()
|
|
|
75a6b7 |
.isPresent();
|
|
|
75a6b7 |
if (invalid) {
|
|
|
75a6b7 |
System.err.println("Zone string for a locale returned null or empty string");
|
|
|
75a6b7 |
System.exit(2);
|
|
|
75a6b7 |
}
|
|
|
75a6b7 |
|
|
|
e46919 |
String localeProvider = args[0];
|
|
|
e46919 |
testZone(localeProvider, KYIV,
|
|
|
e46919 |
new String[] { "Europe/Kiev", "Europe/Kyiv", "Europe/Uzhgorod", "Europe/Zaporozhye" });
|
|
|
e46919 |
testZone(localeProvider, CIUDAD_JUAREZ,
|
|
|
e46919 |
new String[] { "America/Cambridge_Bay", "America/Ciudad_Juarez" });
|
|
|
e46919 |
}
|
|
|
e46919 |
|
|
|
e46919 |
private static void testZone(String localeProvider, Map<Locale,String[]> exp, String[] ids) {
|
|
|
e46919 |
for (Locale l : exp.keySet()) {
|
|
|
e46919 |
String[] expected = exp.get(l);
|
|
|
e46919 |
System.out.printf("Expected values for %s are %s\n", l, Arrays.toString(expected));
|
|
|
e46919 |
for (String id : ids) {
|
|
|
75a6b7 |
String expectedShortStd = null;
|
|
|
75a6b7 |
String expectedShortDST = null;
|
|
|
75a6b7 |
String expectedShortGen = null;
|
|
|
75a6b7 |
|
|
|
75a6b7 |
System.out.printf("Checking locale %s for %s...\n", l, id);
|
|
|
75a6b7 |
|
|
|
75a6b7 |
if ("JRE".equals(localeProvider)) {
|
|
|
75a6b7 |
expectedShortStd = expected[2];
|
|
|
75a6b7 |
expectedShortDST = expected[5];
|
|
|
75a6b7 |
expectedShortGen = expected[8];
|
|
|
75a6b7 |
} else if ("CLDR".equals(localeProvider)) {
|
|
|
75a6b7 |
expectedShortStd = expected[1];
|
|
|
75a6b7 |
expectedShortDST = expected[4];
|
|
|
75a6b7 |
expectedShortGen = expected[7];
|
|
|
75a6b7 |
} else {
|
|
|
75a6b7 |
System.err.printf("Invalid locale provider %s\n", localeProvider);
|
|
|
75a6b7 |
System.exit(3);
|
|
|
75a6b7 |
}
|
|
|
75a6b7 |
System.out.printf("Locale Provider is %s, using short values %s, %s and %s\n",
|
|
|
75a6b7 |
localeProvider, expectedShortStd, expectedShortDST, expectedShortGen);
|
|
|
75a6b7 |
|
|
|
75a6b7 |
String longStd = TimeZone.getTimeZone(id).getDisplayName(false, TimeZone.LONG, l);
|
|
|
75a6b7 |
String shortStd = TimeZone.getTimeZone(id).getDisplayName(false, TimeZone.SHORT, l);
|
|
|
75a6b7 |
String longDST = TimeZone.getTimeZone(id).getDisplayName(true, TimeZone.LONG, l);
|
|
|
75a6b7 |
String shortDST = TimeZone.getTimeZone(id).getDisplayName(true, TimeZone.SHORT, l);
|
|
|
75a6b7 |
String longGen = ZoneId.of(id).getDisplayName(TextStyle.FULL, l);
|
|
|
75a6b7 |
String shortGen = ZoneId.of(id).getDisplayName(TextStyle.SHORT, l);
|
|
|
75a6b7 |
|
|
|
75a6b7 |
if (!expected[0].equals(longStd)) {
|
|
|
75a6b7 |
System.err.printf("Long standard display name for %s in %s was %s, expected %s\n",
|
|
|
75a6b7 |
id, l, longStd, expected[0]);
|
|
|
75a6b7 |
System.exit(4);
|
|
|
75a6b7 |
}
|
|
|
75a6b7 |
|
|
|
75a6b7 |
if (!expectedShortStd.equals(shortStd)) {
|
|
|
75a6b7 |
System.err.printf("Short standard display name for %s in %s was %s, expected %s\n",
|
|
|
75a6b7 |
id, l, shortStd, expectedShortStd);
|
|
|
75a6b7 |
System.exit(5);
|
|
|
75a6b7 |
}
|
|
|
75a6b7 |
|
|
|
75a6b7 |
if (!expected[3].equals(longDST)) {
|
|
|
75a6b7 |
System.err.printf("Long DST display name for %s in %s was %s, expected %s\n",
|
|
|
75a6b7 |
id, l, longDST, expected[3]);
|
|
|
75a6b7 |
System.exit(6);
|
|
|
75a6b7 |
}
|
|
|
75a6b7 |
|
|
|
75a6b7 |
if (!expectedShortDST.equals(shortDST)) {
|
|
|
75a6b7 |
System.err.printf("Short DST display name for %s in %s was %s, expected %s\n",
|
|
|
75a6b7 |
id, l, shortDST, expectedShortDST);
|
|
|
75a6b7 |
System.exit(7);
|
|
|
75a6b7 |
}
|
|
|
75a6b7 |
|
|
|
75a6b7 |
if (!expected[6].equals(longGen)) {
|
|
|
e46919 |
System.err.printf("Long generic display name for %s in %s was %s, expected %s\n",
|
|
|
75a6b7 |
id, l, longGen, expected[6]);
|
|
|
75a6b7 |
System.exit(8);
|
|
|
75a6b7 |
}
|
|
|
75a6b7 |
|
|
|
75a6b7 |
if (!expectedShortGen.equals(shortGen)) {
|
|
|
75a6b7 |
System.err.printf("Short generic display name for %s in %s was %s, expected %s\n",
|
|
|
75a6b7 |
id, l, shortGen, expectedShortGen);
|
|
|
75a6b7 |
System.exit(9);
|
|
|
75a6b7 |
}
|
|
|
5caa27 |
}
|
|
|
5caa27 |
}
|
|
|
5caa27 |
}
|
|
|
5caa27 |
}
|