1 /*
  2  * Copyright (c) 1998, 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  * @library /java/text/testlib
 27  * @summary test International Date Format Symbols
 28  */
 29 /*
 30 (C) Copyright Taligent, Inc. 1996, 1997 - All Rights Reserved
 31 (C) Copyright IBM Corp. 1996, 1997 - All Rights Reserved
 32 
 33   The original version of this source code and documentation is copyrighted and
 34 owned by Taligent, Inc., a wholly-owned subsidiary of IBM. These materials are
 35 provided under terms of a License Agreement between Taligent and Sun. This
 36 technology is protected by multiple US and International patents. This notice and
 37 attribution to Taligent may not be removed.
 38   Taligent is a registered trademark of Taligent, Inc.
 39 */
 40 
 41 import java.text.*;
 42 import java.util.*;
 43 
 44 public class IntlTestDateFormatSymbols extends IntlTest
 45 {
 46     public static void main(String[] args) throws Exception {
 47         new IntlTestDateFormatSymbols().run(args);
 48     }
 49 
 50     // Test getMonths
 51     public void TestGetMonths()
 52     {
 53         final String[] month;
 54         DateFormatSymbols symbol;
 55 
 56         symbol=new DateFormatSymbols(Locale.getDefault());
 57 
 58         month=symbol.getMonths();
 59         int cnt = month.length;
 60 
 61         logln("size = " + cnt);
 62 
 63         for (int i=0; i<cnt; ++i)
 64         {
 65             logln(month[i]);
 66         }
 67     }
 68 
 69     // Test the API of DateFormatSymbols; primarily a simple get/set set.
 70     public void TestSymbols()
 71     {
 72         DateFormatSymbols fr = new DateFormatSymbols(Locale.FRENCH);
 73 
 74         DateFormatSymbols en = new DateFormatSymbols(Locale.ENGLISH);
 75 
 76         if(en.equals(fr)) {
 77             errln("ERROR: English DateFormatSymbols equal to French");
 78         }
 79 
 80         // just do some VERY basic tests to make sure that get/set work
 81 
 82         long count;
 83         final String[] eras = en.getEras();
 84         fr.setEras(eras);
 85         final String[] eras1 = fr.getEras();
 86         count = eras.length;
 87         if( count != eras1.length) {
 88             errln("ERROR: setEras() failed (different size array)");
 89         }
 90         else {
 91             for(int i = 0; i < count; i++) {
 92                 if(! eras[i].equals(eras1[i])) {
 93                     errln("ERROR: setEras() failed (different string values)");
 94                 }
 95             }
 96         }
 97 
 98 
 99         final String[] months = en.getMonths();
100         fr.setMonths(months);
101         final String[] months1 = fr.getMonths();
102         count = months.length;
103         if( count != months1.length) {
104             errln("ERROR: setMonths() failed (different size array)");
105         }
106         else {
107             for(int i = 0; i < count; i++) {
108                 if(! months[i].equals(months1[i])) {
109                     errln("ERROR: setMonths() failed (different string values)");
110                 }
111             }
112         }
113 
114         final String[] shortMonths = en.getShortMonths();
115         fr.setShortMonths(shortMonths);
116         final String[] shortMonths1 = fr.getShortMonths();
117         count = shortMonths.length;
118         if( count != shortMonths1.length) {
119             errln("ERROR: setShortMonths() failed (different size array)");
120         }
121         else {
122             for(int i = 0; i < count; i++) {
123                 if(! shortMonths[i].equals(shortMonths1[i])) {
124                     errln("ERROR: setShortMonths() failed (different string values)");
125                 }
126             }
127         }
128 
129         final String[] weekdays = en.getWeekdays();
130         fr.setWeekdays(weekdays);
131         final String[] weekdays1 = fr.getWeekdays();
132         count = weekdays.length;
133         if( count != weekdays1.length) {
134             errln("ERROR: setWeekdays() failed (different size array)");
135         }
136         else {
137             for(int i = 0; i < count; i++) {
138                 if(! weekdays[i].equals(weekdays1[i])) {
139                     errln("ERROR: setWeekdays() failed (different string values)");
140                 }
141             }
142         }
143 
144         final String[] shortWeekdays = en.getShortWeekdays();
145         fr.setShortWeekdays(shortWeekdays);
146         final String[] shortWeekdays1 = fr.getShortWeekdays();
147         count = shortWeekdays.length;
148         if( count != shortWeekdays1.length) {
149             errln("ERROR: setShortWeekdays() failed (different size array)");
150         }
151         else {
152             for(int i = 0; i < count; i++) {
153                 if(! shortWeekdays[i].equals(shortWeekdays1[i])) {
154                     errln("ERROR: setShortWeekdays() failed (different string values)");
155                 }
156             }
157         }
158 
159         final String[] ampms = en.getAmPmStrings();
160         fr.setAmPmStrings(ampms);
161         final String[] ampms1 = fr.getAmPmStrings();
162         count = ampms.length;
163         if( count != ampms1.length) {
164             errln("ERROR: setAmPmStrings() failed (different size array)");
165         }
166         else {
167             for(int i = 0; i < count; i++) {
168                 if(! ampms[i].equals(ampms1[i])) {
169                     errln("ERROR: setAmPmStrings() failed (different string values)");
170                 }
171             }
172         }
173 
174         long rowCount = 0, columnCount = 0;
175         final String[][] strings = en.getZoneStrings();
176         fr.setZoneStrings(strings);
177         final String[][] strings1 = fr.getZoneStrings();
178         rowCount = strings.length;
179         for(int i = 0; i < rowCount; i++) {
180             columnCount = strings[i].length;
181             for(int j = 0; j < columnCount; j++) {
182                 if( strings[i][j] != strings1[i][j] ) {
183                     errln("ERROR: setZoneStrings() failed");
184                 }
185             }
186         }
187 
188 //        final String pattern = DateFormatSymbols.getPatternChars();
189 
190         String localPattern, pat1, pat2;
191         localPattern = en.getLocalPatternChars();
192         fr.setLocalPatternChars(localPattern);
193         if(! en.getLocalPatternChars().equals(fr.getLocalPatternChars())) {
194             errln("ERROR: setLocalPatternChars() failed");
195         }
196 
197 
198         DateFormatSymbols foo = new DateFormatSymbols();
199 
200         en = (DateFormatSymbols) fr.clone();
201 
202         if(! en.equals(fr)) {
203             errln("ERROR: Clone failed");
204         }
205     }
206 }