author | iklam |
Tue, 12 Aug 2014 17:29:01 -0700 | |
changeset 26212 | 7585e2404b2a |
parent 7504 | e490ef909bf5 |
permissions | -rw-r--r-- |
7504
e490ef909bf5
6653944: (cal) BuddhistCalendar yearOffset erased when deserialized
okutsu
parents:
diff
changeset
|
1 |
/* |
e490ef909bf5
6653944: (cal) BuddhistCalendar yearOffset erased when deserialized
okutsu
parents:
diff
changeset
|
2 |
* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. |
e490ef909bf5
6653944: (cal) BuddhistCalendar yearOffset erased when deserialized
okutsu
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
e490ef909bf5
6653944: (cal) BuddhistCalendar yearOffset erased when deserialized
okutsu
parents:
diff
changeset
|
4 |
* |
e490ef909bf5
6653944: (cal) BuddhistCalendar yearOffset erased when deserialized
okutsu
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
e490ef909bf5
6653944: (cal) BuddhistCalendar yearOffset erased when deserialized
okutsu
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
e490ef909bf5
6653944: (cal) BuddhistCalendar yearOffset erased when deserialized
okutsu
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
e490ef909bf5
6653944: (cal) BuddhistCalendar yearOffset erased when deserialized
okutsu
parents:
diff
changeset
|
8 |
* |
e490ef909bf5
6653944: (cal) BuddhistCalendar yearOffset erased when deserialized
okutsu
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
e490ef909bf5
6653944: (cal) BuddhistCalendar yearOffset erased when deserialized
okutsu
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
e490ef909bf5
6653944: (cal) BuddhistCalendar yearOffset erased when deserialized
okutsu
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
e490ef909bf5
6653944: (cal) BuddhistCalendar yearOffset erased when deserialized
okutsu
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
e490ef909bf5
6653944: (cal) BuddhistCalendar yearOffset erased when deserialized
okutsu
parents:
diff
changeset
|
13 |
* accompanied this code). |
e490ef909bf5
6653944: (cal) BuddhistCalendar yearOffset erased when deserialized
okutsu
parents:
diff
changeset
|
14 |
* |
e490ef909bf5
6653944: (cal) BuddhistCalendar yearOffset erased when deserialized
okutsu
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
e490ef909bf5
6653944: (cal) BuddhistCalendar yearOffset erased when deserialized
okutsu
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
e490ef909bf5
6653944: (cal) BuddhistCalendar yearOffset erased when deserialized
okutsu
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
e490ef909bf5
6653944: (cal) BuddhistCalendar yearOffset erased when deserialized
okutsu
parents:
diff
changeset
|
18 |
* |
e490ef909bf5
6653944: (cal) BuddhistCalendar yearOffset erased when deserialized
okutsu
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
e490ef909bf5
6653944: (cal) BuddhistCalendar yearOffset erased when deserialized
okutsu
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
e490ef909bf5
6653944: (cal) BuddhistCalendar yearOffset erased when deserialized
okutsu
parents:
diff
changeset
|
21 |
* questions. |
e490ef909bf5
6653944: (cal) BuddhistCalendar yearOffset erased when deserialized
okutsu
parents:
diff
changeset
|
22 |
*/ |
e490ef909bf5
6653944: (cal) BuddhistCalendar yearOffset erased when deserialized
okutsu
parents:
diff
changeset
|
23 |
|
e490ef909bf5
6653944: (cal) BuddhistCalendar yearOffset erased when deserialized
okutsu
parents:
diff
changeset
|
24 |
/* |
e490ef909bf5
6653944: (cal) BuddhistCalendar yearOffset erased when deserialized
okutsu
parents:
diff
changeset
|
25 |
*@test |
e490ef909bf5
6653944: (cal) BuddhistCalendar yearOffset erased when deserialized
okutsu
parents:
diff
changeset
|
26 |
*@bug 6653944 |
e490ef909bf5
6653944: (cal) BuddhistCalendar yearOffset erased when deserialized
okutsu
parents:
diff
changeset
|
27 |
*@summary Deserialization tests for YEAR calculcations |
e490ef909bf5
6653944: (cal) BuddhistCalendar yearOffset erased when deserialized
okutsu
parents:
diff
changeset
|
28 |
*/ |
e490ef909bf5
6653944: (cal) BuddhistCalendar yearOffset erased when deserialized
okutsu
parents:
diff
changeset
|
29 |
|
e490ef909bf5
6653944: (cal) BuddhistCalendar yearOffset erased when deserialized
okutsu
parents:
diff
changeset
|
30 |
import java.io.*; |
e490ef909bf5
6653944: (cal) BuddhistCalendar yearOffset erased when deserialized
okutsu
parents:
diff
changeset
|
31 |
import java.util.*; |
e490ef909bf5
6653944: (cal) BuddhistCalendar yearOffset erased when deserialized
okutsu
parents:
diff
changeset
|
32 |
|
e490ef909bf5
6653944: (cal) BuddhistCalendar yearOffset erased when deserialized
okutsu
parents:
diff
changeset
|
33 |
public class Bug6653944 { |
e490ef909bf5
6653944: (cal) BuddhistCalendar yearOffset erased when deserialized
okutsu
parents:
diff
changeset
|
34 |
private static int errorCount = 0; |
e490ef909bf5
6653944: (cal) BuddhistCalendar yearOffset erased when deserialized
okutsu
parents:
diff
changeset
|
35 |
|
e490ef909bf5
6653944: (cal) BuddhistCalendar yearOffset erased when deserialized
okutsu
parents:
diff
changeset
|
36 |
public static void main(String[] args) throws Exception { |
e490ef909bf5
6653944: (cal) BuddhistCalendar yearOffset erased when deserialized
okutsu
parents:
diff
changeset
|
37 |
Calendar buddhist = Calendar.getInstance(new Locale("th", "TH")); |
e490ef909bf5
6653944: (cal) BuddhistCalendar yearOffset erased when deserialized
okutsu
parents:
diff
changeset
|
38 |
int expectedYear = buddhist.get(Calendar.YEAR); |
e490ef909bf5
6653944: (cal) BuddhistCalendar yearOffset erased when deserialized
okutsu
parents:
diff
changeset
|
39 |
|
e490ef909bf5
6653944: (cal) BuddhistCalendar yearOffset erased when deserialized
okutsu
parents:
diff
changeset
|
40 |
Calendar deserialized = (Calendar) deserialize(serialize(buddhist)); |
e490ef909bf5
6653944: (cal) BuddhistCalendar yearOffset erased when deserialized
okutsu
parents:
diff
changeset
|
41 |
compare(deserialized, buddhist); |
e490ef909bf5
6653944: (cal) BuddhistCalendar yearOffset erased when deserialized
okutsu
parents:
diff
changeset
|
42 |
|
e490ef909bf5
6653944: (cal) BuddhistCalendar yearOffset erased when deserialized
okutsu
parents:
diff
changeset
|
43 |
int deserializedYear = deserialized.get(Calendar.YEAR); |
e490ef909bf5
6653944: (cal) BuddhistCalendar yearOffset erased when deserialized
okutsu
parents:
diff
changeset
|
44 |
compare(deserializedYear, expectedYear); |
e490ef909bf5
6653944: (cal) BuddhistCalendar yearOffset erased when deserialized
okutsu
parents:
diff
changeset
|
45 |
|
e490ef909bf5
6653944: (cal) BuddhistCalendar yearOffset erased when deserialized
okutsu
parents:
diff
changeset
|
46 |
// test add(YEAR, n). |
e490ef909bf5
6653944: (cal) BuddhistCalendar yearOffset erased when deserialized
okutsu
parents:
diff
changeset
|
47 |
buddhist.add(Calendar.YEAR, 12); |
e490ef909bf5
6653944: (cal) BuddhistCalendar yearOffset erased when deserialized
okutsu
parents:
diff
changeset
|
48 |
expectedYear = buddhist.get(Calendar.YEAR); |
e490ef909bf5
6653944: (cal) BuddhistCalendar yearOffset erased when deserialized
okutsu
parents:
diff
changeset
|
49 |
deserialized.add(Calendar.YEAR, 12); |
e490ef909bf5
6653944: (cal) BuddhistCalendar yearOffset erased when deserialized
okutsu
parents:
diff
changeset
|
50 |
deserializedYear = deserialized.get(Calendar.YEAR); |
e490ef909bf5
6653944: (cal) BuddhistCalendar yearOffset erased when deserialized
okutsu
parents:
diff
changeset
|
51 |
compare(deserialized, buddhist); |
e490ef909bf5
6653944: (cal) BuddhistCalendar yearOffset erased when deserialized
okutsu
parents:
diff
changeset
|
52 |
compare(deserializedYear, expectedYear); |
e490ef909bf5
6653944: (cal) BuddhistCalendar yearOffset erased when deserialized
okutsu
parents:
diff
changeset
|
53 |
|
e490ef909bf5
6653944: (cal) BuddhistCalendar yearOffset erased when deserialized
okutsu
parents:
diff
changeset
|
54 |
if (errorCount > 0) { |
e490ef909bf5
6653944: (cal) BuddhistCalendar yearOffset erased when deserialized
okutsu
parents:
diff
changeset
|
55 |
throw new RuntimeException("Bug6653944: failed"); |
e490ef909bf5
6653944: (cal) BuddhistCalendar yearOffset erased when deserialized
okutsu
parents:
diff
changeset
|
56 |
} |
e490ef909bf5
6653944: (cal) BuddhistCalendar yearOffset erased when deserialized
okutsu
parents:
diff
changeset
|
57 |
} |
e490ef909bf5
6653944: (cal) BuddhistCalendar yearOffset erased when deserialized
okutsu
parents:
diff
changeset
|
58 |
|
e490ef909bf5
6653944: (cal) BuddhistCalendar yearOffset erased when deserialized
okutsu
parents:
diff
changeset
|
59 |
private static void compare(int got, int expected) { |
e490ef909bf5
6653944: (cal) BuddhistCalendar yearOffset erased when deserialized
okutsu
parents:
diff
changeset
|
60 |
if (got != expected) { |
e490ef909bf5
6653944: (cal) BuddhistCalendar yearOffset erased when deserialized
okutsu
parents:
diff
changeset
|
61 |
System.err.println("got " + got + ", expected " + expected); |
e490ef909bf5
6653944: (cal) BuddhistCalendar yearOffset erased when deserialized
okutsu
parents:
diff
changeset
|
62 |
errorCount++; |
e490ef909bf5
6653944: (cal) BuddhistCalendar yearOffset erased when deserialized
okutsu
parents:
diff
changeset
|
63 |
} |
e490ef909bf5
6653944: (cal) BuddhistCalendar yearOffset erased when deserialized
okutsu
parents:
diff
changeset
|
64 |
} |
e490ef909bf5
6653944: (cal) BuddhistCalendar yearOffset erased when deserialized
okutsu
parents:
diff
changeset
|
65 |
|
e490ef909bf5
6653944: (cal) BuddhistCalendar yearOffset erased when deserialized
okutsu
parents:
diff
changeset
|
66 |
private static void compare(Calendar got, Calendar expected) { |
e490ef909bf5
6653944: (cal) BuddhistCalendar yearOffset erased when deserialized
okutsu
parents:
diff
changeset
|
67 |
if (!got.equals(expected)) { |
e490ef909bf5
6653944: (cal) BuddhistCalendar yearOffset erased when deserialized
okutsu
parents:
diff
changeset
|
68 |
System.err.println("got " + got + ", expected " + expected); |
e490ef909bf5
6653944: (cal) BuddhistCalendar yearOffset erased when deserialized
okutsu
parents:
diff
changeset
|
69 |
errorCount++; |
e490ef909bf5
6653944: (cal) BuddhistCalendar yearOffset erased when deserialized
okutsu
parents:
diff
changeset
|
70 |
} |
e490ef909bf5
6653944: (cal) BuddhistCalendar yearOffset erased when deserialized
okutsu
parents:
diff
changeset
|
71 |
} |
e490ef909bf5
6653944: (cal) BuddhistCalendar yearOffset erased when deserialized
okutsu
parents:
diff
changeset
|
72 |
|
e490ef909bf5
6653944: (cal) BuddhistCalendar yearOffset erased when deserialized
okutsu
parents:
diff
changeset
|
73 |
private static byte[] serialize(Serializable obj) throws Exception { |
e490ef909bf5
6653944: (cal) BuddhistCalendar yearOffset erased when deserialized
okutsu
parents:
diff
changeset
|
74 |
ByteArrayOutputStream baos = new ByteArrayOutputStream(); |
e490ef909bf5
6653944: (cal) BuddhistCalendar yearOffset erased when deserialized
okutsu
parents:
diff
changeset
|
75 |
ObjectOutputStream oos = new ObjectOutputStream(baos); |
e490ef909bf5
6653944: (cal) BuddhistCalendar yearOffset erased when deserialized
okutsu
parents:
diff
changeset
|
76 |
oos.writeObject(obj); |
e490ef909bf5
6653944: (cal) BuddhistCalendar yearOffset erased when deserialized
okutsu
parents:
diff
changeset
|
77 |
oos.close(); |
e490ef909bf5
6653944: (cal) BuddhistCalendar yearOffset erased when deserialized
okutsu
parents:
diff
changeset
|
78 |
return baos.toByteArray(); |
e490ef909bf5
6653944: (cal) BuddhistCalendar yearOffset erased when deserialized
okutsu
parents:
diff
changeset
|
79 |
} |
e490ef909bf5
6653944: (cal) BuddhistCalendar yearOffset erased when deserialized
okutsu
parents:
diff
changeset
|
80 |
|
e490ef909bf5
6653944: (cal) BuddhistCalendar yearOffset erased when deserialized
okutsu
parents:
diff
changeset
|
81 |
private static Object deserialize(byte[] data) throws Exception { |
e490ef909bf5
6653944: (cal) BuddhistCalendar yearOffset erased when deserialized
okutsu
parents:
diff
changeset
|
82 |
ByteArrayInputStream bais = new ByteArrayInputStream(data); |
e490ef909bf5
6653944: (cal) BuddhistCalendar yearOffset erased when deserialized
okutsu
parents:
diff
changeset
|
83 |
ObjectInputStream ois = new ObjectInputStream(bais); |
e490ef909bf5
6653944: (cal) BuddhistCalendar yearOffset erased when deserialized
okutsu
parents:
diff
changeset
|
84 |
return ois.readObject(); |
e490ef909bf5
6653944: (cal) BuddhistCalendar yearOffset erased when deserialized
okutsu
parents:
diff
changeset
|
85 |
} |
e490ef909bf5
6653944: (cal) BuddhistCalendar yearOffset erased when deserialized
okutsu
parents:
diff
changeset
|
86 |
} |