Blame SOURCES/TestTranslations.java

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