Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/beans/XMLDecoder/spec/TestObject.java
38821 views
/*1* Copyright (c) 2008, 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* @summary Tests <object> element26* @author Sergey Malenkov27*/2829import java.beans.XMLDecoder;30import javax.swing.JButton;31import javax.swing.JLabel;32import javax.swing.JPanel;33import javax.swing.SwingConstants;3435public final class TestObject extends AbstractTest {36public static final String XML // TODO37= "<java>\n"38+ " <object class=\"javax.swing.JPanel\">\n"39+ " <void method=\"add\">\n"40+ " <object id=\"button\" class=\"javax.swing.JButton\">\n"41+ " <string>button</string>\n"42+ " <void property=\"verticalAlignment\">\n"43+ " <object field=\"CENTER\" class=\"javax.swing.SwingConstants\"/>\n"44+ " </void>\n"45+ " </object>\n"46+ " </void>\n"47+ " <void method=\"add\">\n"48+ " <object class=\"javax.swing.JLabel\">\n"49+ " <string>label</string>\n"50+ " <void property=\"labelFor\">\n"51+ " <object idref=\"button\"/>\n"52+ " </void>\n"53+ " </object>\n"54+ " </void>\n"55+ " </object>\n"56+ "</java>";5758public static void main(String[] args) {59new TestObject().test(true);60}6162@Override63protected void validate(XMLDecoder decoder) {64JPanel panel = (JPanel) decoder.readObject();65if (2 != panel.getComponents().length) {66throw new Error("unexpected component count");67}68JButton button = (JButton) panel.getComponents()[0];69if (!button.getText().equals("button")) { // NON-NLS: hardcoded in XML70throw new Error("unexpected button text");71}72if (SwingConstants.CENTER != button.getVerticalAlignment()) {73throw new Error("unexpected vertical alignment");74}75JLabel label = (JLabel) panel.getComponents()[1];76if (!label.getText().equals("label")) { // NON-NLS: hardcoded in XML77throw new Error("unexpected label text");78}79if (button != label.getLabelFor()) {80throw new Error("unexpected component");81}82}83}848586