|
| 1 | +/* |
| 2 | + * Copyright (c) 2026, Oracle and/or its affiliates. All rights reserved. |
| 3 | + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
| 4 | + * |
| 5 | + * This code is free software; you can redistribute it and/or modify it |
| 6 | + * under the terms of the GNU General Public License version 2 only, as |
| 7 | + * published by the Free Software Foundation. |
| 8 | + * |
| 9 | + * This code is distributed in the hope that it will be useful, but WITHOUT |
| 10 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 11 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 12 | + * version 2 for more details (a copy is included in the LICENSE file that |
| 13 | + * accompanied this code). |
| 14 | + * |
| 15 | + * You should have received a copy of the GNU General Public License version |
| 16 | + * 2 along with this work; if not, write to the Free Software Foundation, |
| 17 | + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
| 18 | + * |
| 19 | + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
| 20 | + * or visit www.oracle.com if you need additional information or have any |
| 21 | + * questions. |
| 22 | + */ |
| 23 | + |
| 24 | +/* @test |
| 25 | + * @bug 8380993 |
| 26 | + * @library /test/lib |
| 27 | + * @summary Validates AIX timezone mapping behavior where POSIX TZ strings |
| 28 | + * with comma-separated DST rules are truncated and mapped through tzmappings |
| 29 | + * to the expected IANA timezone IDs. |
| 30 | + * @requires os.family == "aix" |
| 31 | + * @run main/othervm AIXTzMappingTest |
| 32 | + */ |
| 33 | + |
| 34 | +import java.util.TimeZone; |
| 35 | + |
| 36 | +import jdk.test.lib.process.ProcessTools; |
| 37 | +import jdk.test.lib.process.OutputAnalyzer; |
| 38 | + |
| 39 | +public class AIXTzMappingTest { |
| 40 | + |
| 41 | + // POSIX TZ strings that should be mapped via tzmappings |
| 42 | + private static final String TZ_CET = "CET-1CEST,M3.5.0,M10.5.0"; |
| 43 | + private static final String TZ_MEZ = "MEZ-1MESZ,M3.5.0,M10.5.0/3"; |
| 44 | + |
| 45 | + private static final String ID_PARIS = "Europe/Paris"; |
| 46 | + private static final String ID_BERLIN = "Europe/Berlin"; |
| 47 | + |
| 48 | + public static void main(String[] args) throws Throwable { |
| 49 | + if (args.length == 0) { |
| 50 | + runWithTZ(TZ_CET, ID_PARIS); |
| 51 | + runWithTZ(TZ_MEZ, ID_BERLIN); |
| 52 | + } else if (args.length == 1) { |
| 53 | + runTZTest(args[0]); |
| 54 | + } else { |
| 55 | + throw new RuntimeException( |
| 56 | + "Expected 0 or 1 arguments, got " + args.length); |
| 57 | + } |
| 58 | + } |
| 59 | + |
| 60 | + private static void runWithTZ(String tz, String expectedId) |
| 61 | + throws Throwable { |
| 62 | + ProcessBuilder pb = ProcessTools.createTestJavaProcessBuilder( |
| 63 | + "AIXTzMappingTest", expectedId); |
| 64 | + |
| 65 | + pb.environment().put("TZ", tz); |
| 66 | + |
| 67 | + OutputAnalyzer output = ProcessTools.executeProcess(pb); |
| 68 | + output.shouldHaveExitValue(0); |
| 69 | + } |
| 70 | + |
| 71 | + /* |
| 72 | + * On AIX, POSIX TZ strings such as: |
| 73 | + * CET-1CEST,M3.5.0,M10.5.0 |
| 74 | + * MEZ-1MESZ,M3.5.0,M10.5.0/3 |
| 75 | + * are truncated at the comma and mapped through tzmappings to |
| 76 | + * IANA timezone IDs. |
| 77 | + * |
| 78 | + * This test verifies that the expected IANA timezone ID is selected. |
| 79 | + */ |
| 80 | + private static void runTZTest(String expectedId) { |
| 81 | + String tzStr = System.getenv("TZ"); |
| 82 | + |
| 83 | + if (tzStr == null) { |
| 84 | + throw new RuntimeException( |
| 85 | + "Got unexpected timezone information: TZ is null"); |
| 86 | + } |
| 87 | + |
| 88 | + TimeZone tz = TimeZone.getDefault(); |
| 89 | + String tzId = tz.getID(); |
| 90 | + |
| 91 | + if (!expectedId.equals(tzId)) { |
| 92 | + throw new RuntimeException( |
| 93 | + "Expected timezone ID " + expectedId |
| 94 | + + " but got " + tzId |
| 95 | + + " for TZ=" + tzStr); |
| 96 | + } |
| 97 | + |
| 98 | + System.out.println( |
| 99 | + "AIX timezone mapping test passed: " |
| 100 | + + tzId + " for TZ=" + tzStr); |
| 101 | + } |
| 102 | +} |
0 commit comments