Blame SOURCES/TestTranslations.java

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