Blame SOURCES/TestTranslations.java

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