Blame SOURCES/TestTranslations.java

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