Blame SOURCES/TestTranslations.java

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