Path: blob/master/test/jdk/sun/text/resources/Format/Bug4685470.java
41155 views
/*1* Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24*@test25*@bug 468547026*@summary verify whether contain pattern for the day of week in sch and tch's default FULL pattern27*/2829import java.util.*;30import java.text.*;3132public class Bug468547033{34public static void main(String args[])35{36int result = 0;37Bug4685470 testsuite = new Bug4685470();3839if(!testsuite.TestSCH()) result ++;40if(!testsuite.TestTCH()) result ++;4142if(result > 0) throw new RuntimeException();43}4445private boolean TestSCH()46{47Date now = new Date();48DateFormat s = DateFormat.getDateTimeInstance(DateFormat.FULL,DateFormat.FULL,Locale.SIMPLIFIED_CHINESE);4950return Test(s.format(now), getDayofWeek(now, Locale.SIMPLIFIED_CHINESE), "\"EEEE\" in " + Locale.SIMPLIFIED_CHINESE.toString());51}5253private boolean TestTCH()54{55Date now = new Date();56DateFormat s = DateFormat.getDateTimeInstance(DateFormat.FULL,DateFormat.FULL,Locale.TRADITIONAL_CHINESE);5758return Test(s.format(now), getDayofWeek(now, Locale.TRADITIONAL_CHINESE), "\"EEEE\" in " + Locale.TRADITIONAL_CHINESE.toString());59}6061private boolean Test(String parent, String child, String patterninfo)62{63boolean result = true;6465if( ! contains(parent, child)){66System.out.println("Full date: " + parent);67System.out.println("Which should contain the day of the week: " + child);68System.out.println("DateFormat.FULL don't contain pattern for the day of the week : " + patterninfo);6970result = false;71}7273return result;74}7576private boolean contains(String parent, String child)77{78boolean result = false;7980if(parent.length() < child.length()) result = false;81else {82for ( int i = 0; i < parent.length() - child.length(); i++){83result = parent.regionMatches(i, child, 0, child.length());84if ( result == true) break;85}86}8788return result;89}9091private String getDayofWeek(Date date, Locale loc){92return (new SimpleDateFormat("EEEE", loc)).format(date);93}94}959697