1 /* 2 * Copyright (c) 2005, 2016, 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 /* 25 * @test 26 * @bug 6215962 27 * @summary Confirm that replacing Utility.arayEquals methods have with 28 * Arrays.equals introduces no problem. 29 */ 30 import java.text.*; 31 import java.util.*; 32 33 public class Bug6215962 { 34 35 public static void main(String[] args) { 36 testMessageFormat(); 37 testChoiceFormat(); 38 testDateFormatSymbols(); 39 } 40 41 /** 42 * Test cases for MessageFormat 43 */ 44 static void testMessageFormat() { 45 MessageFormat mf1 = new MessageFormat("{0}", null); 46 MessageFormat mf2 = new MessageFormat("{0}", null); 47 check(mf1, mf2, true); 48 49 mf1.setLocale(null); 50 check(mf1, mf2, true); 51 52 mf1 = new MessageFormat("{0}", Locale.US); 53 check(mf1, mf2, false); 54 55 mf2 = new MessageFormat("{0}", Locale.JAPAN); 56 check(mf1, mf2, false); 57 58 mf1 = new MessageFormat("{0}", new Locale("ja", "JP")); 59 check(mf1, mf2, true); 60 61 mf1.setLocale(null); 62 check(mf1, mf2, false); 63 64 mf1 = new MessageFormat("{0}", new Locale("ja", "JP", "FOO")); 65 check(mf1, mf2, false); 66 67 mf2 = new MessageFormat("{1}", new Locale("ja", "JP", "FOO")); 68 check(mf1, mf2, false); 69 70 mf1 = new MessageFormat("{1}", new Locale("ja", "JP", "FOO")); 71 check(mf1, mf2, true); 72 73 mf1 = new MessageFormat("{1, date}", new Locale("ja", "JP", "FOO")); 74 check(mf1, mf2, false); 75 76 mf2 = new MessageFormat("{1, date}", new Locale("ja", "JP", "FOO")); 77 check(mf1, mf2, true); 78 } 79 80 static void check(MessageFormat f1, MessageFormat f2, boolean expected) { 81 boolean got = f1.equals(f2); 82 if (got != expected) { 83 throw new RuntimeException("Test failed for MessageFormat.equals(). Got: " + got + ", Expected: " + expected); 84 } 85 } 86 87 /** 88 * Test cases for MessageFormat 89 */ 90 static void testChoiceFormat() { 91 double[] limits0 = {0,1,2,3,4,5,6}; 92 double[] limits1 = {1,2,3,4,5,6,7}; 93 String[] monthNames0 = {"Sun","Mon","Tue","Wed","Thu","Fri","Sat"}; 94 String[] monthNames1 = {"Sun","Mon","Tue","Wed","Thur","Fri","Sat"}; 95 96 ChoiceFormat cf1 = new ChoiceFormat(limits1, monthNames0); 97 ChoiceFormat cf2 = new ChoiceFormat(limits1, monthNames0); 98 check(cf1, cf2, true); 99 100 cf2 = new ChoiceFormat(limits0, monthNames0); 101 check(cf1, cf2, false); 102 103 cf2 = new ChoiceFormat(limits1, monthNames1); 104 check(cf1, cf2, false); 105 } 106 107 static void check(ChoiceFormat f1, ChoiceFormat f2, boolean expected) { 108 boolean got = f1.equals(f2); 109 if (got != expected) { 110 throw new RuntimeException("Test failed for ChoiceFormat.equals(). Got: " + got + ", Expected: " + expected); 111 } 112 } 113 114 /** 115 * Test cases for DateFormatSymbols 116 */ 117 static void testDateFormatSymbols() { 118 DateFormatSymbols dfs1 = new DateFormatSymbols(); 119 DateFormatSymbols dfs2 = new DateFormatSymbols(); 120 check(dfs1, dfs2, true); 121 122 // Becase eras, months, shortmonths, weekdays, shortweekdays, ampms are 123 // the same data type (String[]) and are treated in the same way, here 124 // I test only Months. 125 String[] tmp = dfs1.getMonths(); 126 String saved = tmp[0]; 127 tmp[0] = "Foo"; 128 dfs1.setMonths(tmp); 129 check(dfs1, dfs2, false); 130 131 tmp[0] = saved; 132 dfs1.setMonths(tmp); 133 check(dfs1, dfs2, true); 134 135 // Test LocalizedpatternChars (String) 136 String pattern = dfs2.getLocalPatternChars(); 137 dfs2.setLocalPatternChars("Bar"); 138 check(dfs1, dfs2, false); 139 140 dfs2.setLocalPatternChars(pattern); 141 check(dfs1, dfs2, true); 142 143 // Test TimeZone strings (String[][]) 144 String[][] zones = dfs1.getZoneStrings(); 145 saved = zones[0][1]; 146 zones[0][1] = "Yokohama Summer Time"; 147 dfs1.setZoneStrings(zones); 148 check(dfs1, dfs2, false); 149 150 zones[0][1] = saved; 151 dfs1.setZoneStrings(zones); 152 check(dfs1, dfs2, true); 153 } 154 155 static void check(DateFormatSymbols dfs1, DateFormatSymbols dfs2, boolean expected) { 156 boolean got = dfs1.equals(dfs2); 157 if (got != expected) { 158 throw new RuntimeException("Test failed for DateFormatSymbols.equals(). Got: " + got + ", Expected: " + expected); 159 } 160 } 161 }