Path: blob/master/test/jdk/java/awt/Modal/ModalitySettingsTest/ModalitySettingsTest.java
41153 views
/*1* Copyright (c) 2007, 2018, 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.test.lib.Asserts.*;2526/*27* @test28* @key headful29* @bug 804736730* @summary Check modality settings for Window and Dialog.31*32* @library /test/lib33* @run main ModalitySettingsTest34*/35363738public class ModalitySettingsTest {3940private void doTest() throws Exception {4142Window w = new Window(new Frame());4344boolean unexpectedExc = false;4546try {47Dialog d = new Dialog(w);48} catch (IllegalArgumentException iae) {49} catch (Exception e) {50unexpectedExc = true;51}5253assertFalse(unexpectedExc, "unexpected exception occured when a " +54"Window instance was passed to Dialog constructor");5556Dialog d = new Dialog((Frame) null);57assertTrue(d.getModalityType() == Dialog.ModalityType.MODELESS,58"the default modality type returned by Dialog " +59"differs from Dialog.ModalityType.MODELESS");6061Frame f = new Frame();62assertTrue(f.getModalExclusionType() == Dialog.ModalExclusionType.NO_EXCLUDE,63"the default modality exclusion type returned by Frame" +64"differs from Dialog.ModalExclusionType.NO_EXCLUDE");6566w = new Window((Frame) null);67assertTrue(w.getModalExclusionType() == Dialog.ModalExclusionType.NO_EXCLUDE,68"the default modality exclusion type returned by Window " +69"differs from Dialog.ModalExclusionType.NO_EXCLUDE");7071d = new Dialog((Frame) null);72assertTrue(d.getModalExclusionType() == Dialog.ModalExclusionType.NO_EXCLUDE,73"the default modality exclusion type returned by Dialog " +74"differs from Dialog.ModalExclusionType.NO_EXCLUDE");7576d.setModalityType(Dialog.ModalityType.TOOLKIT_MODAL);77assertTrue(d.getModalityType() == Dialog.ModalityType.TOOLKIT_MODAL,78"the modality type returned by Dialog " +79"differs from Dialog.ModalityType.TOOLKIT_MODAL " +80"after setting the modality type to that value");8182d.setModal(false);83assertTrue(d.getModalityType() == Dialog.ModalityType.MODELESS,84"the modality type returned by Dialog differs from " +85"Dialog.ModalityType.MODELESS after calling setModal(false)");8687d.setModal(true);88assertTrue(d.getModalityType() == Dialog.ModalityType.APPLICATION_MODAL,89"the modality type returned by Dialog differs from "90+ "Dialog.ModalityType.APPLICATION_MODAL after calling setModal(true)");9192w.setModalExclusionType(Dialog.ModalExclusionType.APPLICATION_EXCLUDE);93assertTrue(w.getModalExclusionType() ==94Dialog.ModalExclusionType.APPLICATION_EXCLUDE,95"getModalExclusionType method for Window did not return " +96"Dialog.ModalExclusionType.APPLICATION_EXCLUDE after " +97"setting it to that value");9899d = new Dialog((Frame) null);100d.setModalityType(Dialog.ModalityType.TOOLKIT_MODAL);101assertTrue(d.isModal(), "method isModal for Dialog " +102"returned false when the Dialog is toolkit modal");103104d.setModalityType(Dialog.ModalityType.MODELESS);105assertFalse(d.isModal(), "method isModal for Dialog " +106"returned true when the Dialog is MODELESS");107108d = new Dialog((Frame) null, (Dialog.ModalityType) null);109assertTrue(d.getModalityType() == Dialog.ModalityType.MODELESS,110"The modality type returned for a Dialog constructed " +111"with null modality type differs from MODELESS");112113d = new Dialog((Frame) null);114d.setModalityType(null);115assertTrue(d.getModalityType() == Dialog.ModalityType.MODELESS,116"the modality type returned for a Dialog set with null " +117"modality type differs from MODELESS");118119d.setModalExclusionType(null);120assertTrue(d.getModalExclusionType() == Dialog.ModalExclusionType.NO_EXCLUDE,121"The exlcusion type returned for a Dialog set with null " +122"exclusion type differs from NO_EXCLUDE");123124try {125Dialog.ModalityType.valueOf("invalid");126} catch (IllegalArgumentException iae) {127} catch (Exception e) {128unexpectedExc = true;129}130131assertFalse(unexpectedExc, "unexpected exception occured when an " +132"invalid value was passed to ModalityType.valueOf method");133}134135public static void main(String[] args) throws Exception {136ModalitySettingsTest test = new ModalitySettingsTest();137test.doTest();138}139}140141142