1 /*
  2  * Copyright (c) 1998, 2023, 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  * @summary test International Date Format Symbols
 27  * @run junit IntlTestDateFormatSymbols
 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 import org.junit.jupiter.api.Test;
 45 
 46 import static org.junit.jupiter.api.Assertions.fail;
 47 
 48 public class IntlTestDateFormatSymbols
 49 {
 50     // Test getMonths
 51     @Test
 52     public void TestGetMonths()
 53     {
 54         final String[] month;
 55         DateFormatSymbols symbol;
 56 
 57         symbol=new DateFormatSymbols(Locale.getDefault());
 58 
 59         month=symbol.getMonths();
 60         int cnt = month.length;
 61 
 62         System.out.println("size = " + cnt);
 63 
 64         for (int i=0; i<cnt; ++i)
 65         {
 66             System.out.println(month[i]);
 67         }
 68     }
 69 
 70     // Test the API of DateFormatSymbols; primarily a simple get/set set.
 71     @Test
 72     public void TestSymbols()
 73     {
 74         DateFormatSymbols fr = new DateFormatSymbols(Locale.FRENCH);
 75 
 76         DateFormatSymbols en = new DateFormatSymbols(Locale.ENGLISH);
 77 
 78         if(en.equals(fr)) {
 79             fail("ERROR: English DateFormatSymbols equal to French");
 80         }
 81 
 82         // just do some VERY basic tests to make sure that get/set work
 83 
 84         long count;
 85         final String[] eras = en.getEras();
 86         fr.setEras(eras);
 87         final String[] eras1 = fr.getEras();
 88         count = eras.length;
 89         if( count != eras1.length) {
 90             fail("ERROR: setEras() failed (different size array)");
 91         }
 92         else {
 93             for(int i = 0; i < count; i++) {
 94                 if(! eras[i].equals(eras1[i])) {
 95                     fail("ERROR: setEras() failed (different string values)");
 96                 }
 97             }
 98         }
 99 
100 
101         final String[] months = en.getMonths();
102         fr.setMonths(months);
103         final String[] months1 = fr.getMonths();
104         count = months.length;
105         if( count != months1.length) {
106             fail("ERROR: setMonths() failed (different size array)");
107         }
108         else {
109             for(int i = 0; i < count; i++) {
110                 if(! months[i].equals(months1[i])) {
111                     fail("ERROR: setMonths() failed (different string values)");
112                 }
113             }
114         }
115 
116         final String[] shortMonths = en.getShortMonths();
117         fr.setShortMonths(shortMonths);
118         final String[] shortMonths1 = fr.getShortMonths();
119         count = shortMonths.length;
120         if( count != shortMonths1.length) {
121             fail("ERROR: setShortMonths() failed (different size array)");
122         }
123         else {
124             for(int i = 0; i < count; i++) {
125                 if(! shortMonths[i].equals(shortMonths1[i])) {
126                     fail("ERROR: setShortMonths() failed (different string values)");
127                 }
128             }
129         }
130 
131         final String[] weekdays = en.getWeekdays();
132         fr.setWeekdays(weekdays);
133         final String[] weekdays1 = fr.getWeekdays();
134         count = weekdays.length;
135         if( count != weekdays1.length) {
136             fail("ERROR: setWeekdays() failed (different size array)");
137         }
138         else {
139             for(int i = 0; i < count; i++) {
140                 if(! weekdays[i].equals(weekdays1[i])) {
141                     fail("ERROR: setWeekdays() failed (different string values)");
142                 }
143             }
144         }
145 
146         final String[] shortWeekdays = en.getShortWeekdays();
147         fr.setShortWeekdays(shortWeekdays);
148         final String[] shortWeekdays1 = fr.getShortWeekdays();
149         count = shortWeekdays.length;
150         if( count != shortWeekdays1.length) {
151             fail("ERROR: setShortWeekdays() failed (different size array)");
152         }
153         else {
154             for(int i = 0; i < count; i++) {
155                 if(! shortWeekdays[i].equals(shortWeekdays1[i])) {
156                     fail("ERROR: setShortWeekdays() failed (different string values)");
157                 }
158             }
159         }
160 
161         final String[] ampms = en.getAmPmStrings();
162         fr.setAmPmStrings(ampms);
163         final String[] ampms1 = fr.getAmPmStrings();
164         count = ampms.length;
165         if( count != ampms1.length) {
166             fail("ERROR: setAmPmStrings() failed (different size array)");
167         }
168         else {
169             for(int i = 0; i < count; i++) {
170                 if(! ampms[i].equals(ampms1[i])) {
171                     fail("ERROR: setAmPmStrings() failed (different string values)");
172                 }
173             }
174         }
175 
176         long rowCount = 0, columnCount = 0;
177         final String[][] strings = en.getZoneStrings();
178         fr.setZoneStrings(strings);
179         final String[][] strings1 = fr.getZoneStrings();
180         rowCount = strings.length;
181         for(int i = 0; i < rowCount; i++) {
182             columnCount = strings[i].length;
183             for(int j = 0; j < columnCount; j++) {
184                 if( strings[i][j] != strings1[i][j] ) {
185                     fail("ERROR: setZoneStrings() failed");
186                 }
187             }
188         }
189 
190 //        final String pattern = DateFormatSymbols.getPatternChars();
191 
192         String localPattern, pat1, pat2;
193         localPattern = en.getLocalPatternChars();
194         fr.setLocalPatternChars(localPattern);
195         if(! en.getLocalPatternChars().equals(fr.getLocalPatternChars())) {
196             fail("ERROR: setLocalPatternChars() failed");
197         }
198 
199 
200         DateFormatSymbols foo = new DateFormatSymbols();
201 
202         en = (DateFormatSymbols) fr.clone();
203 
204         if(! en.equals(fr)) {
205             fail("ERROR: Clone failed");
206         }
207     }
208 }