Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/awt/MenuBar/RemoveHelpMenu/RemoveHelpMenu.java
38828 views
/*1* Copyright (c) 2015, 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.Frame;24import java.awt.Menu;25import java.awt.MenuBar;2627/**28* @test29* @bug 647536130* @author Sergey Bylokhov31*/32public final class RemoveHelpMenu {3334public static void main(final String[] args) {35final Frame frame = new Frame("RemoveHelpMenu Test");36try {37frame.pack();38// peer exists39test1(getMenuBar(frame));40test2(getMenuBar(frame));41test3(getMenuBar(frame));42test4(getMenuBar(frame));43} finally {44frame.dispose();45}46// peer is null47test1(getMenuBar(frame));48test2(getMenuBar(frame));49test3(getMenuBar(frame));50test4(getMenuBar(frame));51}5253private static MenuBar getMenuBar(final Frame frame) {54final MenuBar menuBar = new MenuBar();55frame.setMenuBar(menuBar);56return menuBar;57}5859private static void checkHelpMenu(final Menu menu, final boolean expected) {60final boolean actual = menu.toString().contains("isHelpMenu=true");61if (actual != expected) {62throw new RuntimeException("Incorrect menu type");63}64}6566private static void checkMenuCount(final MenuBar bar, final int expected) {67final int actual = bar.getMenuCount();68if (actual != expected) {69throw new RuntimeException("Incorrect menus count");70}71}7273private static void checkCurrentMenu(final MenuBar bar, final Menu menu) {74if (bar.getHelpMenu() != menu) {75throw new RuntimeException("Wrong HelpMenu");76}77}7879private static void test1(final MenuBar menuBar) {80checkCurrentMenu(menuBar, null);81checkMenuCount(menuBar, 0);82}8384private static void test2(final MenuBar menuBar) {85final Menu helpMenu = new Menu("Help Menu");86menuBar.setHelpMenu(helpMenu);87checkCurrentMenu(menuBar, helpMenu);88checkMenuCount(menuBar, 1);89checkHelpMenu(helpMenu, true);9091menuBar.remove(helpMenu);92checkCurrentMenu(menuBar, null);93checkMenuCount(menuBar, 0);94checkHelpMenu(helpMenu, false);95}9697private static void test3(final MenuBar menuBar) {98final Menu helpMenu1 = new Menu("Help Menu1");99final Menu helpMenu2 = new Menu("Help Menu2");100menuBar.setHelpMenu(helpMenu1);101checkCurrentMenu(menuBar, helpMenu1);102checkMenuCount(menuBar, 1);103checkHelpMenu(helpMenu1, true);104checkHelpMenu(helpMenu2, false);105106menuBar.setHelpMenu(helpMenu2);107checkCurrentMenu(menuBar, helpMenu2);108checkMenuCount(menuBar, 1);109checkHelpMenu(helpMenu1, false);110checkHelpMenu(helpMenu2, true);111112menuBar.remove(helpMenu2);113checkCurrentMenu(menuBar, null);114checkMenuCount(menuBar, 0);115checkHelpMenu(helpMenu1, false);116checkHelpMenu(helpMenu2, false);117}118119private static void test4(final MenuBar menuBar) {120final Menu helpMenu = new Menu("Help Menu");121menuBar.setHelpMenu(helpMenu);122checkCurrentMenu(menuBar, helpMenu);123checkMenuCount(menuBar, 1);124checkHelpMenu(helpMenu, true);125126menuBar.setHelpMenu(null);127checkCurrentMenu(menuBar, null);128checkMenuCount(menuBar, 0);129checkHelpMenu(helpMenu, false);130}131}132133