Blame SOURCES/TestTranslations.java

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