Blame SOURCES/TestTranslations.java

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