Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/sun/util/calendar/Bug6653944.java
41149 views
1
/*
2
* Copyright (c) 2010, 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 6653944
27
*@summary Deserialization tests for YEAR calculcations
28
*/
29
30
import java.io.*;
31
import java.util.*;
32
33
public class Bug6653944 {
34
private static int errorCount = 0;
35
36
public static void main(String[] args) throws Exception {
37
Calendar buddhist = Calendar.getInstance(new Locale("th", "TH"));
38
int expectedYear = buddhist.get(Calendar.YEAR);
39
40
Calendar deserialized = (Calendar) deserialize(serialize(buddhist));
41
compare(deserialized, buddhist);
42
43
int deserializedYear = deserialized.get(Calendar.YEAR);
44
compare(deserializedYear, expectedYear);
45
46
// test add(YEAR, n).
47
buddhist.add(Calendar.YEAR, 12);
48
expectedYear = buddhist.get(Calendar.YEAR);
49
deserialized.add(Calendar.YEAR, 12);
50
deserializedYear = deserialized.get(Calendar.YEAR);
51
compare(deserialized, buddhist);
52
compare(deserializedYear, expectedYear);
53
54
if (errorCount > 0) {
55
throw new RuntimeException("Bug6653944: failed");
56
}
57
}
58
59
private static void compare(int got, int expected) {
60
if (got != expected) {
61
System.err.println("got " + got + ", expected " + expected);
62
errorCount++;
63
}
64
}
65
66
private static void compare(Calendar got, Calendar expected) {
67
if (!got.equals(expected)) {
68
System.err.println("got " + got + ", expected " + expected);
69
errorCount++;
70
}
71
}
72
73
private static byte[] serialize(Serializable obj) throws Exception {
74
ByteArrayOutputStream baos = new ByteArrayOutputStream();
75
ObjectOutputStream oos = new ObjectOutputStream(baos);
76
oos.writeObject(obj);
77
oos.close();
78
return baos.toByteArray();
79
}
80
81
private static Object deserialize(byte[] data) throws Exception {
82
ByteArrayInputStream bais = new ByteArrayInputStream(data);
83
ObjectInputStream ois = new ObjectInputStream(bais);
84
return ois.readObject();
85
}
86
}
87
88