Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/awt/Modal/ModalitySettingsTest/ModalitySettingsTest.java
38821 views
/*1* Copyright (c) 2007, 2014, 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*/2223import java.awt.*;24import static jdk.testlibrary.Asserts.*;2526/*27* @test28* @bug 804736729* @summary Check modality settings for Window and Dialog.30*31* @library ../../../../lib/testlibrary/32* @run main ModalitySettingsTest33*/34353637public class ModalitySettingsTest {3839private void doTest() throws Exception {4041Window w = new Window(new Frame());4243boolean unexpectedExc = false;4445try {46Dialog d = new Dialog(w);47} catch (IllegalArgumentException iae) {48} catch (Exception e) {49unexpectedExc = true;50}5152assertFalse(unexpectedExc, "unexpected exception occured when a " +53"Window instance was passed to Dialog constructor");5455Dialog d = new Dialog((Frame) null);56assertTrue(d.getModalityType() == Dialog.ModalityType.MODELESS,57"the default modality type returned by Dialog " +58"differs from Dialog.ModalityType.MODELESS");5960Frame f = new Frame();61assertTrue(f.getModalExclusionType() == Dialog.ModalExclusionType.NO_EXCLUDE,62"the default modality exclusion type returned by Frame" +63"differs from Dialog.ModalExclusionType.NO_EXCLUDE");6465w = new Window((Frame) null);66assertTrue(w.getModalExclusionType() == Dialog.ModalExclusionType.NO_EXCLUDE,67"the default modality exclusion type returned by Window " +68"differs from Dialog.ModalExclusionType.NO_EXCLUDE");6970d = new Dialog((Frame) null);71assertTrue(d.getModalExclusionType() == Dialog.ModalExclusionType.NO_EXCLUDE,72"the default modality exclusion type returned by Dialog " +73"differs from Dialog.ModalExclusionType.NO_EXCLUDE");7475d.setModalityType(Dialog.ModalityType.TOOLKIT_MODAL);76assertTrue(d.getModalityType() == Dialog.ModalityType.TOOLKIT_MODAL,77"the modality type returned by Dialog " +78"differs from Dialog.ModalityType.TOOLKIT_MODAL " +79"after setting the modality type to that value");8081d.setModal(false);82assertTrue(d.getModalityType() == Dialog.ModalityType.MODELESS,83"the modality type returned by Dialog differs from " +84"Dialog.ModalityType.MODELESS after calling setModal(false)");8586d.setModal(true);87assertTrue(d.getModalityType() == Dialog.ModalityType.APPLICATION_MODAL,88"the modality type returned by Dialog differs from "89+ "Dialog.ModalityType.APPLICATION_MODAL after calling setModal(true)");9091w.setModalExclusionType(Dialog.ModalExclusionType.APPLICATION_EXCLUDE);92assertTrue(w.getModalExclusionType() ==93Dialog.ModalExclusionType.APPLICATION_EXCLUDE,94"getModalExclusionType method for Window did not return " +95"Dialog.ModalExclusionType.APPLICATION_EXCLUDE after " +96"setting it to that value");9798d = new Dialog((Frame) null);99d.setModalityType(Dialog.ModalityType.TOOLKIT_MODAL);100assertTrue(d.isModal(), "method isModal for Dialog " +101"returned false when the Dialog is toolkit modal");102103d.setModalityType(Dialog.ModalityType.MODELESS);104assertFalse(d.isModal(), "method isModal for Dialog " +105"returned true when the Dialog is MODELESS");106107d = new Dialog((Frame) null, (Dialog.ModalityType) null);108assertTrue(d.getModalityType() == Dialog.ModalityType.MODELESS,109"The modality type returned for a Dialog constructed " +110"with null modality type differs from MODELESS");111112d = new Dialog((Frame) null);113d.setModalityType(null);114assertTrue(d.getModalityType() == Dialog.ModalityType.MODELESS,115"the modality type returned for a Dialog set with null " +116"modality type differs from MODELESS");117118d.setModalExclusionType(null);119assertTrue(d.getModalExclusionType() == Dialog.ModalExclusionType.NO_EXCLUDE,120"The exlcusion type returned for a Dialog set with null " +121"exclusion type differs from NO_EXCLUDE");122123try {124Dialog.ModalityType.valueOf("invalid");125} catch (IllegalArgumentException iae) {126} catch (Exception e) {127unexpectedExc = true;128}129130assertFalse(unexpectedExc, "unexpected exception occured when an " +131"invalid value was passed to ModalityType.valueOf method");132}133134public static void main(String[] args) throws Exception {135ModalitySettingsTest test = new ModalitySettingsTest();136test.doTest();137}138}139140141