Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/util/Locale/Bug4184873Test.java
38813 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*/22/*23@test24@summary test that locale invariants are preserved across serialization25@run main Bug4184873Test26@bug 418487327*/28/*29*30*31* (C) Copyright IBM Corp. 1996 - 1999 - All Rights Reserved32*33* Portions copyright (c) 2007 Sun Microsystems, Inc.34* All Rights Reserved.35*36* The original version of this source code and documentation37* is copyrighted and owned by Taligent, Inc., a wholly-owned38* subsidiary of IBM. These materials are provided under terms39* of a License Agreement between Taligent and Sun. This technology40* is protected by multiple US and International patents.41*42* This notice and attribution to Taligent may not be removed.43* Taligent is a registered trademark of Taligent, Inc.44*45* Permission to use, copy, modify, and distribute this software46* and its documentation for NON-COMMERCIAL purposes and without47* fee is hereby granted provided that this copyright notice48* appears in all copies. Please refer to the file "copyright.html"49* for further important copyright and licensing information.50*51* SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF52* THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED53* TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A54* PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR55* ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR56* DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.57*/5859import java.util.*;60import java.io.*;6162/**63* A Locale can never contain the following language codes: he, yi or id.64*/65public class Bug4184873Test extends LocaleTestFmwk {66public static void main(String[] args) throws Exception {67if (args.length == 1 && args[0].equals("prepTest")) {68prepTest();69} else {70new Bug4184873Test().run(args);71}72}7374public void testIt() throws Exception {75verify("he");76verify("yi");77verify("id");78}7980private void verify(String lang) {81try {82ObjectInputStream in = getStream(lang);83if (in != null) {84final Locale loc = (Locale)in.readObject();85final Locale expected = new Locale(lang, "XX");86if (!(expected.equals(loc))) {87errln("Locale didn't maintain invariants for: "+lang);88errln(" got: "+loc);89errln(" excpeted: "+expected);90} else {91logln("Locale "+lang+" worked");92}93in.close();94}95} catch (Exception e) {96errln(e.toString());97}98}99100private ObjectInputStream getStream(String lang) {101try {102final File f = new File(System.getProperty("test.src", "."), "Bug4184873_"+lang);103return new ObjectInputStream(new FileInputStream(f));104} catch (Exception e) {105errln(e.toString());106return null;107}108}109110/**111* Create serialized output files of the test locales. After they are created, these test112* files should be corrupted (by hand) to contain invalid locale name values.113*/114private static void prepTest() {115outputLocale("he");116outputLocale("yi");117outputLocale("id");118}119120private static void outputLocale(String lang) {121try {122ObjectOutputStream out = new ObjectOutputStream(123new FileOutputStream("Bug4184873_"+lang));124out.writeObject(new Locale(lang, "XX"));125out.close();126} catch (Exception e) {127System.out.println(e);128}129}130131}132133134