Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/text/Format/ChoiceFormat/Bug4185732Test.java
41152 views
1
/*
2
* Copyright (c) 1999, 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
* @bug 4185732
27
* @library /java/text/testlib
28
* @build Bug4185732Test IntlTest HexDumpReader
29
* @run main Bug4185732Test
30
* @summary test that ChoiceFormat invariants are preserved across serialization
31
*/
32
/*
33
*
34
*
35
* (C) Copyright IBM Corp. 1996 - 1999 - All Rights Reserved
36
*
37
* Portions copyright (c) 2007 Sun Microsystems, Inc.
38
* All Rights Reserved.
39
*
40
* The original version of this source code and documentation
41
* is copyrighted and owned by Taligent, Inc., a wholly-owned
42
* subsidiary of IBM. These materials are provided under terms
43
* of a License Agreement between Taligent and Sun. This technology
44
* is protected by multiple US and International patents.
45
*
46
* This notice and attribution to Taligent may not be removed.
47
* Taligent is a registered trademark of Taligent, Inc.
48
*
49
* Permission to use, copy, modify, and distribute this software
50
* and its documentation for NON-COMMERCIAL purposes and without
51
* fee is hereby granted provided that this copyright notice
52
* appears in all copies. Please refer to the file "copyright.html"
53
* for further important copyright and licensing information.
54
*
55
* SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF
56
* THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
57
* TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
58
* PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR
59
* ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
60
* DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
61
*/
62
63
import java.util.*;
64
import java.io.*;
65
import java.text.ChoiceFormat;
66
67
/**
68
* A Locale can never contains language codes of he, yi or id.
69
*/
70
public class Bug4185732Test extends IntlTest {
71
public static void main(String[] args) throws Exception {
72
if (args.length == 1 && args[0].equals("prepTest")) {
73
prepTest();
74
} else {
75
new Bug4185732Test().run(args);
76
}
77
}
78
79
public void testIt() throws Exception {
80
try {
81
final ObjectInputStream in
82
= new ObjectInputStream(HexDumpReader.getStreamFromHexDump("Bug4185732.ser.txt"));
83
final ChoiceFormat loc = (ChoiceFormat)in.readObject();
84
if (loc.getFormats().length != loc.getLimits().length) {
85
errln("ChoiceFormat did not properly check stream");
86
} else {
87
//for some reason, the data file was VALID. This test
88
//requires a corrupt data file the format and limit
89
//arrays are of different length.
90
errln("Test data file was not properly created");
91
}
92
} catch (InvalidObjectException e) {
93
//this is what we want to have happen
94
} catch (Exception e) {
95
errln(e.toString());
96
}
97
}
98
99
/**
100
* Create a data file for this test. The data file must be corrupted by hand.
101
*/
102
private static void prepTest() {
103
try {
104
ObjectOutputStream out = new ObjectOutputStream(
105
new FileOutputStream("Bug4185732.ser"));
106
final double[] limits = {1,2,3,4,5,6,7};
107
final String[] formats = {"Sun","Mon","Tue","Wed","Thur","Fri","Sat"};
108
final ChoiceFormat fmt = new ChoiceFormat(limits, formats);
109
out.writeObject(fmt);
110
out.close();
111
System.out.println("You must invalidate the output file before running the test");
112
System.out.println("by modifying the length of one of the array");
113
} catch (Exception e) {
114
System.out.println(e);
115
}
116
}
117
}
118
119