author | joehw |
Tue, 18 Feb 2014 10:53:18 -0800 | |
changeset 22985 | e9654c36f56d |
permissions | -rw-r--r-- |
22985
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
1 |
/* |
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
2 |
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. |
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
4 |
* |
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
8 |
* |
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
13 |
* accompanied this code). |
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
14 |
* |
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
18 |
* |
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
21 |
* questions. |
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
22 |
*/ |
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
23 |
|
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
24 |
/** |
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
25 |
* @test |
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
26 |
* @bug 8033980 |
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
27 |
* @summary verify serialization compatibility for XMLGregorianCalendar and Duration |
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
28 |
* @run main SerializationTest read |
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
29 |
*/ |
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
30 |
|
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
31 |
import java.io.*; |
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
32 |
import javax.xml.datatype.DatatypeConfigurationException; |
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
33 |
import javax.xml.datatype.DatatypeFactory; |
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
34 |
import javax.xml.datatype.Duration; |
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
35 |
import javax.xml.datatype.XMLGregorianCalendar; |
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
36 |
|
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
37 |
/** |
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
38 |
* use "read" to test compatibility |
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
39 |
* SerializationTest read |
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
40 |
* |
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
41 |
* use "write" to create test files |
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
42 |
* SerializationTest write javaVersion |
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
43 |
* where javaVersion is 6, 7, 8, or 9 |
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
44 |
* |
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
45 |
* @author huizhe.wang@oracle.com</a> |
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
46 |
*/ |
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
47 |
public class SerializationTest { |
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
48 |
|
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
49 |
final String FILENAME_CAL = "_XMLGregorianCalendar.ser"; |
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
50 |
final String FILENAME_DURATION = "_Duration.ser"; |
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
51 |
String filePath; |
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
52 |
|
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
53 |
{ |
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
54 |
filePath = System.getProperty("test.src"); |
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
55 |
if (filePath == null) { |
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
56 |
//current directory |
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
57 |
filePath = System.getProperty("user.dir"); |
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
58 |
} |
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
59 |
filePath += File.separator; |
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
60 |
} |
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
61 |
final String EXPECTED_CAL = "0001-01-01T00:00:00.0000000-05:00"; |
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
62 |
final String EXPECTED_DURATION = "P1Y1M1DT1H1M1S"; |
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
63 |
static String[] JDK = {"JDK6", "JDK7", "JDK8", "JDK9"}; |
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
64 |
|
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
65 |
public static void main(String[] args) { |
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
66 |
SerializationTest test = new SerializationTest(); |
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
67 |
|
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
68 |
if (args[0].equalsIgnoreCase("read")) { |
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
69 |
test.testReadCal(); |
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
70 |
test.testReadDuration(); |
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
71 |
test.report(); |
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
72 |
} else { |
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
73 |
int ver = Integer.valueOf(args[1]).intValue(); |
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
74 |
test.createTestFile(JDK[ver - 6]); |
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
75 |
} |
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
76 |
|
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
77 |
} |
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
78 |
|
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
79 |
public void testReadCal() { |
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
80 |
try { |
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
81 |
for (String javaVersion : JDK) { |
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
82 |
XMLGregorianCalendar d1 = (XMLGregorianCalendar) fromFile( |
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
83 |
javaVersion + FILENAME_CAL); |
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
84 |
if (!d1.toString().equalsIgnoreCase(EXPECTED_CAL)) { |
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
85 |
fail("Java version: " + javaVersion |
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
86 |
+ "\nExpected: " + EXPECTED_CAL |
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
87 |
+ "\nActual: " + d1.toString()); |
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
88 |
} else { |
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
89 |
success("testReadCal: read " + javaVersion + " serialized file, passed."); |
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
90 |
} |
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
91 |
} |
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
92 |
} catch (ClassNotFoundException ex) { |
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
93 |
fail("testReadCal: " + ex.getMessage()); |
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
94 |
} catch (IOException ex) { |
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
95 |
fail("testReadCal: " + ex.getMessage()); |
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
96 |
} |
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
97 |
} |
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
98 |
|
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
99 |
public void testReadDuration() { |
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
100 |
try { |
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
101 |
for (String javaVersion : JDK) { |
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
102 |
Duration d1 = (Duration) fromFile( |
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
103 |
javaVersion + FILENAME_DURATION); |
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
104 |
if (!d1.toString().equalsIgnoreCase(EXPECTED_DURATION)) { |
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
105 |
fail("Java version: " + javaVersion |
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
106 |
+ "\nExpected: " + EXPECTED_DURATION |
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
107 |
+ "\nActual: " + d1.toString()); |
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
108 |
} else { |
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
109 |
success("testReadDuration: read " + javaVersion + " serialized file, passed."); |
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
110 |
} |
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
111 |
} |
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
112 |
} catch (ClassNotFoundException ex) { |
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
113 |
fail("testReadDuration: " + ex.getMessage()); |
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
114 |
} catch (IOException ex) { |
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
115 |
fail("testReadDuration: " + ex.getMessage()); |
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
116 |
} |
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
117 |
} |
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
118 |
|
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
119 |
/** |
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
120 |
* Create test files |
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
121 |
* |
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
122 |
* @param javaVersion JDK version |
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
123 |
*/ |
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
124 |
public void createTestFile(String javaVersion) { |
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
125 |
try { |
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
126 |
DatatypeFactory dtf = DatatypeFactory.newInstance(); |
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
127 |
XMLGregorianCalendar c = dtf.newXMLGregorianCalendar(EXPECTED_CAL); |
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
128 |
Duration d = dtf.newDuration(EXPECTED_DURATION); |
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
129 |
toFile((Serializable) c, filePath + javaVersion + FILENAME_CAL); |
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
130 |
toFile((Serializable) d, filePath + javaVersion + FILENAME_DURATION); |
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
131 |
} catch (Exception e) { |
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
132 |
fail(e.getMessage()); |
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
133 |
} |
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
134 |
} |
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
135 |
|
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
136 |
/** |
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
137 |
* Read the object from a file. |
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
138 |
*/ |
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
139 |
private static Object fromFile(String filePath) throws IOException, |
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
140 |
ClassNotFoundException { |
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
141 |
InputStream streamIn = SerializationTest.class.getResourceAsStream( |
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
142 |
filePath); |
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
143 |
ObjectInputStream objectinputstream = new ObjectInputStream(streamIn); |
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
144 |
Object o = objectinputstream.readObject(); |
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
145 |
return o; |
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
146 |
} |
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
147 |
|
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
148 |
/** |
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
149 |
* Write the object to a file. |
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
150 |
*/ |
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
151 |
private static void toFile(Serializable o, String filePath) throws IOException { |
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
152 |
FileOutputStream fout = new FileOutputStream(filePath, true); |
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
153 |
ObjectOutputStream oos = new ObjectOutputStream(fout); |
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
154 |
oos.writeObject(o); |
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
155 |
oos.close(); |
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
156 |
} |
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
157 |
|
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
158 |
static String errMessage; |
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
159 |
int passed = 0, failed = 0; |
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
160 |
|
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
161 |
void fail(String errMsg) { |
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
162 |
if (errMessage == null) { |
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
163 |
errMessage = errMsg; |
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
164 |
} else { |
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
165 |
errMessage = errMessage + "\n" + errMsg; |
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
166 |
} |
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
167 |
failed++; |
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
168 |
} |
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
169 |
|
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
170 |
void success(String msg) { |
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
171 |
passed++; |
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
172 |
System.out.println(msg); |
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
173 |
} |
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
174 |
|
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
175 |
public void report() { |
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
176 |
|
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
177 |
System.out.println("\nNumber of tests passed: " + passed); |
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
178 |
System.out.println("Number of tests failed: " + failed + "\n"); |
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
179 |
|
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
180 |
if (errMessage != null) { |
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
181 |
throw new RuntimeException(errMessage); |
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
182 |
} |
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
183 |
} |
e9654c36f56d
8033980: Xerces Update: datatype XMLGregorianCalendarImpl and DurationImpl
joehw
parents:
diff
changeset
|
184 |
} |