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