Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/beans/XMLEncoder/java_awt_CardLayout.java
38811 views
1
/*
2
* Copyright (c) 2013, 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 8007458
27
* @summary Tests CardLayout encoding
28
* @author Sergey Malenkov
29
*/
30
31
import java.awt.CardLayout;
32
import java.lang.reflect.Field;
33
import java.util.Vector;
34
import javax.swing.JLabel;
35
36
public final class java_awt_CardLayout extends AbstractTest<CardLayout> {
37
private static final Field VECTOR = getField("java.awt.CardLayout.vector");
38
private static final Field NAME = getField("java.awt.CardLayout$Card.name");
39
private static final Field COMP = getField("java.awt.CardLayout$Card.comp");
40
41
public static void main(String[] args) throws Exception {
42
new java_awt_CardLayout().test(true);
43
}
44
45
@Override
46
protected CardLayout getObject() {
47
CardLayout layout = new CardLayout();
48
layout.addLayoutComponent(new JLabel("a"), "a");
49
layout.addLayoutComponent(new JLabel("b"), "b");
50
layout.addLayoutComponent(new JLabel("c"), "c");
51
return layout;
52
}
53
54
@Override
55
protected CardLayout getAnotherObject() {
56
CardLayout layout = new CardLayout();
57
layout.addLayoutComponent(new JLabel("a"), "a");
58
layout.addLayoutComponent(new JLabel("b"), "b");
59
layout.addLayoutComponent(new JLabel("c"), "c");
60
layout.addLayoutComponent(new JLabel("d"), "d");
61
return layout;
62
}
63
64
@Override
65
protected void validate(CardLayout before, CardLayout after) {
66
super.validate(before, after);
67
try {
68
Vector a = (Vector) VECTOR.get(after);
69
Vector b = (Vector) VECTOR.get(before);
70
int size = a.size();
71
if (size != b.size()) {
72
throw new Error("different content");
73
}
74
for (int i = 0; i < size; i++) {
75
super.validator.validate(NAME.get(a.get(i)), NAME.get(b.get(i)));
76
super.validator.validate(COMP.get(a.get(i)), COMP.get(b.get(i)));
77
}
78
}
79
catch (Exception exception) {
80
throw new Error(exception);
81
}
82
}
83
}
84
85