Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/util/Locale/Bug4184873Test.java
38813 views
1
/*
2
* Copyright (c) 2007, 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
@test
25
@summary test that locale invariants are preserved across serialization
26
@run main Bug4184873Test
27
@bug 4184873
28
*/
29
/*
30
*
31
*
32
* (C) Copyright IBM Corp. 1996 - 1999 - All Rights Reserved
33
*
34
* Portions copyright (c) 2007 Sun Microsystems, Inc.
35
* All Rights Reserved.
36
*
37
* The original version of this source code and documentation
38
* is copyrighted and owned by Taligent, Inc., a wholly-owned
39
* subsidiary of IBM. These materials are provided under terms
40
* of a License Agreement between Taligent and Sun. This technology
41
* is protected by multiple US and International patents.
42
*
43
* This notice and attribution to Taligent may not be removed.
44
* Taligent is a registered trademark of Taligent, Inc.
45
*
46
* Permission to use, copy, modify, and distribute this software
47
* and its documentation for NON-COMMERCIAL purposes and without
48
* fee is hereby granted provided that this copyright notice
49
* appears in all copies. Please refer to the file "copyright.html"
50
* for further important copyright and licensing information.
51
*
52
* SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF
53
* THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
54
* TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
55
* PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR
56
* ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
57
* DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
58
*/
59
60
import java.util.*;
61
import java.io.*;
62
63
/**
64
* A Locale can never contain the following language codes: he, yi or id.
65
*/
66
public class Bug4184873Test extends LocaleTestFmwk {
67
public static void main(String[] args) throws Exception {
68
if (args.length == 1 && args[0].equals("prepTest")) {
69
prepTest();
70
} else {
71
new Bug4184873Test().run(args);
72
}
73
}
74
75
public void testIt() throws Exception {
76
verify("he");
77
verify("yi");
78
verify("id");
79
}
80
81
private void verify(String lang) {
82
try {
83
ObjectInputStream in = getStream(lang);
84
if (in != null) {
85
final Locale loc = (Locale)in.readObject();
86
final Locale expected = new Locale(lang, "XX");
87
if (!(expected.equals(loc))) {
88
errln("Locale didn't maintain invariants for: "+lang);
89
errln(" got: "+loc);
90
errln(" excpeted: "+expected);
91
} else {
92
logln("Locale "+lang+" worked");
93
}
94
in.close();
95
}
96
} catch (Exception e) {
97
errln(e.toString());
98
}
99
}
100
101
private ObjectInputStream getStream(String lang) {
102
try {
103
final File f = new File(System.getProperty("test.src", "."), "Bug4184873_"+lang);
104
return new ObjectInputStream(new FileInputStream(f));
105
} catch (Exception e) {
106
errln(e.toString());
107
return null;
108
}
109
}
110
111
/**
112
* Create serialized output files of the test locales. After they are created, these test
113
* files should be corrupted (by hand) to contain invalid locale name values.
114
*/
115
private static void prepTest() {
116
outputLocale("he");
117
outputLocale("yi");
118
outputLocale("id");
119
}
120
121
private static void outputLocale(String lang) {
122
try {
123
ObjectOutputStream out = new ObjectOutputStream(
124
new FileOutputStream("Bug4184873_"+lang));
125
out.writeObject(new Locale(lang, "XX"));
126
out.close();
127
} catch (Exception e) {
128
System.out.println(e);
129
}
130
}
131
132
}
133
134