Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/beans/XMLEncoder/java_awt_CardLayout.java
38811 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* @author Sergey Malenkov28*/2930import java.awt.CardLayout;31import java.lang.reflect.Field;32import java.util.Vector;33import javax.swing.JLabel;3435public final class java_awt_CardLayout extends AbstractTest<CardLayout> {36private static final Field VECTOR = getField("java.awt.CardLayout.vector");37private static final Field NAME = getField("java.awt.CardLayout$Card.name");38private static final Field COMP = getField("java.awt.CardLayout$Card.comp");3940public static void main(String[] args) throws Exception {41new java_awt_CardLayout().test(true);42}4344@Override45protected CardLayout getObject() {46CardLayout layout = new CardLayout();47layout.addLayoutComponent(new JLabel("a"), "a");48layout.addLayoutComponent(new JLabel("b"), "b");49layout.addLayoutComponent(new JLabel("c"), "c");50return layout;51}5253@Override54protected CardLayout getAnotherObject() {55CardLayout layout = new CardLayout();56layout.addLayoutComponent(new JLabel("a"), "a");57layout.addLayoutComponent(new JLabel("b"), "b");58layout.addLayoutComponent(new JLabel("c"), "c");59layout.addLayoutComponent(new JLabel("d"), "d");60return layout;61}6263@Override64protected void validate(CardLayout before, CardLayout after) {65super.validate(before, after);66try {67Vector a = (Vector) VECTOR.get(after);68Vector b = (Vector) VECTOR.get(before);69int size = a.size();70if (size != b.size()) {71throw new Error("different content");72}73for (int i = 0; i < size; i++) {74super.validator.validate(NAME.get(a.get(i)), NAME.get(b.get(i)));75super.validator.validate(COMP.get(a.get(i)), COMP.get(b.get(i)));76}77}78catch (Exception exception) {79throw new Error(exception);80}81}82}838485