Added
Link Here
|
1 |
/******************************************************************************* |
2 |
* Copyright (c) 2006 IBM Corporation and others. |
3 |
* All rights reserved. This program and the accompanying materials |
4 |
* are made available under the terms of the Eclipse Public License v1.0 |
5 |
* which accompanies this distribution, and is available at |
6 |
* http://www.eclipse.org/legal/epl-v10.html |
7 |
* |
8 |
* Contributors: |
9 |
* IBM Corporation - initial API and implementation |
10 |
*******************************************************************************/ |
11 |
/* |
12 |
* Here we focus on various aspects of the runtime behavior of the generated |
13 |
* code. |
14 |
*/ |
15 |
package org.eclipse.jdt.core.tests.compiler.regression; |
16 |
|
17 |
import java.util.Map; |
18 |
|
19 |
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; |
20 |
|
21 |
import junit.framework.Test; |
22 |
|
23 |
public class SerialVersionUIDTests extends AbstractRegressionTest { |
24 |
|
25 |
public SerialVersionUIDTests(String name) { |
26 |
super(name); |
27 |
} |
28 |
// Static initializer to specify tests subset using TESTS_* static variables |
29 |
// All specified tests which does not belong to the class are skipped... |
30 |
// Only the highest compliance level is run; add the VM argument |
31 |
// -Dcompliance=1.4 (for example) to lower it if needed |
32 |
static { |
33 |
// TESTS_NAMES = new String[] { "test0001" }; |
34 |
// TESTS_NUMBERS = new int[] { 1 }; |
35 |
// TESTS_RANGE = new int[] { 1, -1 }; |
36 |
} |
37 |
public static Test suite() { |
38 |
return buildAllCompliancesTestSuite(testClass()); |
39 |
} |
40 |
public static Class testClass() { |
41 |
return SerialVersionUIDTests.class; |
42 |
} |
43 |
protected Map getCompilerOptions() { |
44 |
Map options = super.getCompilerOptions(); |
45 |
options.put(CompilerOptions.OPTION_ReportMissingSerialVersion, CompilerOptions.ERROR); |
46 |
return options; |
47 |
} |
48 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=101476 |
49 |
public void test001() { |
50 |
this.runConformTest( |
51 |
new String[] { |
52 |
"X.java", |
53 |
"import java.io.Serializable;\n" + |
54 |
"\n" + |
55 |
"public class X implements Serializable {\n" + |
56 |
" private void readObject(java.io.ObjectInputStream stream) throws java.io.IOException {}\n" + |
57 |
" private void writeObject(java.io.ObjectOutputStream stream) throws java.io.IOException {}\n" + |
58 |
"}" |
59 |
}, |
60 |
"" |
61 |
); |
62 |
} |
63 |
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=101476 |
64 |
public void test002() { |
65 |
this.runConformTest( |
66 |
new String[] { |
67 |
"X.java", |
68 |
"public class X implements java.io.Externalizable {\n" + |
69 |
" public void writeExternal(java.io.ObjectOutput out) throws java.io.IOException {}\n" + |
70 |
" public void readExternal(java.io.ObjectInput in) throws java.io.IOException, ClassNotFoundException {}\n" + |
71 |
"}" |
72 |
}, |
73 |
"" |
74 |
); |
75 |
} |
76 |
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=101476 |
77 |
public void test003() { |
78 |
this.runNegativeTest( |
79 |
new String[] { |
80 |
"X.java", |
81 |
"public class X implements java.io.Serializable {\n" + |
82 |
" private void writeObject(java.io.ObjectOutputStream stream) throws java.io.IOException {}\n" + |
83 |
"}" |
84 |
}, |
85 |
"----------\n" + |
86 |
"1. ERROR in X.java (at line 1)\n" + |
87 |
" public class X implements java.io.Serializable {\n" + |
88 |
" ^\n" + |
89 |
"The serializable class X does not declare a static final serialVersionUID field of type long\n" + |
90 |
"----------\n" |
91 |
); |
92 |
} |
93 |
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=101476 |
94 |
public void test004() { |
95 |
this.runNegativeTest( |
96 |
new String[] { |
97 |
"X.java", |
98 |
"public class X implements java.io.Serializable {\n" + |
99 |
" private void readObject(java.io.ObjectInputStream stream) throws java.io.IOException {}\n" + |
100 |
"}" |
101 |
}, |
102 |
"----------\n" + |
103 |
"1. ERROR in X.java (at line 1)\n" + |
104 |
" public class X implements java.io.Serializable {\n" + |
105 |
" ^\n" + |
106 |
"The serializable class X does not declare a static final serialVersionUID field of type long\n" + |
107 |
"----------\n" |
108 |
); |
109 |
} |
110 |
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=101476 |
111 |
public void test005() { |
112 |
this.runNegativeTest( |
113 |
new String[] { |
114 |
"X.java", |
115 |
"public class X implements java.io.Serializable {\n" + |
116 |
"}" |
117 |
}, |
118 |
"----------\n" + |
119 |
"1. ERROR in X.java (at line 1)\n" + |
120 |
" public class X implements java.io.Serializable {\n" + |
121 |
" ^\n" + |
122 |
"The serializable class X does not declare a static final serialVersionUID field of type long\n" + |
123 |
"----------\n" |
124 |
); |
125 |
} |
126 |
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=101476 |
127 |
public void test006() { |
128 |
this.runConformTest( |
129 |
new String[] { |
130 |
"X.java", |
131 |
"public class X implements java.io.Serializable {\n" + |
132 |
" Object writeReplace() throws java.io.ObjectStreamException { return null;}\n" + |
133 |
"}" |
134 |
}, |
135 |
"" |
136 |
); |
137 |
} |
138 |
} |