Blame SOURCES/TestTranslations.java

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