Path: blob/master/test/jdk/java/beans/XMLEncoder/java_awt_CardLayout.java
41149 views
/*1* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 800745826* @summary Tests CardLayout encoding27* @modules java.desktop/java.awt:open28* @run main/othervm -Djava.security.manager=allow java_awt_CardLayout29* @author Sergey Malenkov30*/3132import java.awt.CardLayout;33import java.lang.reflect.Field;34import java.util.Vector;35import javax.swing.JLabel;3637public final class java_awt_CardLayout extends AbstractTest<CardLayout> {38private static final Field VECTOR = getField("java.awt.CardLayout.vector");39private static final Field NAME = getField("java.awt.CardLayout$Card.name");40private static final Field COMP = getField("java.awt.CardLayout$Card.comp");4142public static void main(String[] args) throws Exception {43new java_awt_CardLayout().test(true);44}4546@Override47protected CardLayout getObject() {48CardLayout layout = new CardLayout();49layout.addLayoutComponent(new JLabel("a"), "a");50layout.addLayoutComponent(new JLabel("b"), "b");51layout.addLayoutComponent(new JLabel("c"), "c");52return layout;53}5455@Override56protected CardLayout getAnotherObject() {57CardLayout layout = new CardLayout();58layout.addLayoutComponent(new JLabel("a"), "a");59layout.addLayoutComponent(new JLabel("b"), "b");60layout.addLayoutComponent(new JLabel("c"), "c");61layout.addLayoutComponent(new JLabel("d"), "d");62return layout;63}6465@Override66protected void validate(CardLayout before, CardLayout after) {67super.validate(before, after);68try {69Vector a = (Vector) VECTOR.get(after);70Vector b = (Vector) VECTOR.get(before);71int size = a.size();72if (size != b.size()) {73throw new Error("different content");74}75for (int i = 0; i < size; i++) {76super.validator.validate(NAME.get(a.get(i)), NAME.get(b.get(i)));77super.validator.validate(COMP.get(a.get(i)), COMP.get(b.get(i)));78}79}80catch (Exception exception) {81throw new Error(exception);82}83}84}858687