blob: 13fb60681aaefb8c116fe60a92b43b85ece2403a [file] [log] [blame]
peytoia0e645952008-09-08 15:21:55 +09001/*
ohair2283b9d2010-05-25 15:58:33 -07002 * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
peytoia0e645952008-09-08 15:21:55 +09003 * 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
serb9adafbe2013-11-12 20:24:25 +04007 * published by the Free Software Foundation.
peytoia0e645952008-09-08 15:21:55 +09008 *
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 *
ohair2283b9d2010-05-25 15:58:33 -070019 * 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.
peytoia0e645952008-09-08 15:21:55 +090022 */
23
24/*
25 * See OldMappingTest.sh
26 */
27
28import java.lang.reflect.*;
29import java.util.*;
30
31public class OldIDMappingTest {
32 private static final String MAPPING_PROPERTY_NAME = "sun.timezone.ids.oldmapping";
33 private static final Map<String, String> newmap = new HashMap<String, String>();
34 static {
35 // Add known new mappings
36 newmap.put("EST", "EST");
37 newmap.put("MST", "MST");
38 newmap.put("HST", "HST");
39 }
40
41 public static void main(String[] args) {
42 boolean useOldMapping = true;
43 String arg = args[0];
44 if (arg.equals("-new")) {
45 useOldMapping = false;
46 } else if (arg.equals("-old")) {
47 useOldMapping = true;
48 } else {
49 throw new RuntimeException("-old or -new must be specified; got " + arg);
50 }
51
sherman4749a262013-02-12 09:25:43 -080052 Map<String, String> oldmap = TzIDOldMapping.MAP;
peytoia0e645952008-09-08 15:21:55 +090053 String prop = System.getProperty(MAPPING_PROPERTY_NAME);
54 System.out.println(MAPPING_PROPERTY_NAME + "=" + prop);
55
56 // Try the test multiple times with modifying TimeZones to
57 // make sure TimeZone instances for the old mapping are
58 // properly copied (defensive copy).
59 for (int count = 0; count < 3; count++) {
60 for (String id : oldmap.keySet()) {
61 TimeZone tzAlias = TimeZone.getTimeZone(id);
62 TimeZone tz = TimeZone.getTimeZone(oldmap.get(id));
63 if (useOldMapping) {
64 if (!tzAlias.hasSameRules(tz)) {
65 throw new RuntimeException("OLDMAP: " + MAPPING_PROPERTY_NAME + "=" + prop + ": "
66 + id + " isn't an alias of " + oldmap.get(id));
67 }
68 if (count == 0) {
69 System.out.println(" " + id + " => " + oldmap.get(id));
70 }
71 tzAlias.setRawOffset(tzAlias.getRawOffset() * count);
72 } else {
73 if (!newmap.containsKey(id)) {
74 // ignore ids not contained in the new map
75 if (count == 0) {
76 System.out.println(" " + id + " => " + oldmap.get(id));
77 }
78 tzAlias.setRawOffset(tzAlias.getRawOffset() * count);
79 continue;
80 }
81 if (tzAlias.hasSameRules(tz)) {
82 throw new RuntimeException("NEWMAP: " + MAPPING_PROPERTY_NAME + "=" + prop + ": "
83 + id + " is an alias of " + oldmap.get(id));
84 }
85 tz = TimeZone.getTimeZone(newmap.get(id));
86 if (!tzAlias.hasSameRules(tz)) {
87 throw new RuntimeException("NEWMAP: " + MAPPING_PROPERTY_NAME + "=" + prop + ": "
88 + id + " isn't an alias of " + newmap.get(id));
89 }
90 if (count == 0) {
91 System.out.println(" " + id + " => " + newmap.get(id));
92 }
93 tzAlias.setRawOffset(tzAlias.getRawOffset() * count);
94 }
95 }
96 }
97 }
98}