Path: blob/master/test/jdk/java/lang/RuntimePermission/ExitVM.java
41149 views
/*1* Copyright (c) 2005, 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 626867326* @summary Test new RuntimePermission.exitVM wildcard syntax27* @author Sean Mullan28*/2930import java.security.PermissionCollection;3132public class ExitVM {3334public static void main(String[]args) throws Exception {3536RuntimePermission newWildcard = new RuntimePermission("exitVM.*");37RuntimePermission oldWildcard = new RuntimePermission("exitVM");38RuntimePermission other = new RuntimePermission("exitVM.23");39System.out.println("Testing RuntimePermission(\"exitVM.*\")");40System.out.println(" testing getName()");41if (!newWildcard.getName().equals("exitVM.*")) {42throw new Exception43("expected: exitVM.* received:" + newWildcard.getName());44}45System.out.println46(" testing equals(new RuntimePermission(\"exitVM.*\"))");47if (!newWildcard.equals(new RuntimePermission("exitVM.*"))) {48throw new Exception("expected true, received false");49}50System.out.println51(" testing equals(new RuntimePermission(\"exitVM.23\"))");52if (newWildcard.equals(other)) {53throw new Exception("expected false, received true");54}55System.out.println56(" testing implies(new RuntimePermission(\"exitVM.23\"))");57if (!newWildcard.implies(other)) {58throw new Exception("expected true, received false");59}60System.out.println61(" testing implies(new RuntimePermission(\"exitVM.*\"))");62if (!newWildcard.implies(new RuntimePermission("exitVM.*"))) {63throw new Exception("expected true, received false");64}65System.out.println66(" testing implies(new RuntimePermission(\"exitVM\"))");67if (!newWildcard.implies(oldWildcard)) {68throw new Exception("expected true, received false");69}70System.out.println("Testing RuntimePermission(\"exitVM\")");71System.out.println72(" testing implies(new RuntimePermission(\"exitVM.*\"))");73if (!oldWildcard.implies(newWildcard)) {74throw new Exception("expected true, received false");75}76System.out.println77(" testing implies(new RuntimePermission(\"exitVM\"))");78if (!oldWildcard.implies(new RuntimePermission("exitVM"))) {79throw new Exception("expected true, received false");80}81System.out.println82(" testing implies(new RuntimePermission(\"exitVM.23\"))");83if (!oldWildcard.implies(other)) {84throw new Exception("expected true, received false");85}8687// now test permission collections88System.out.println("Testing PermissionCollection containing " +89"RuntimePermission(\"exitVM.*\")");90PermissionCollection newPC = newWildcard.newPermissionCollection();91newPC.add(newWildcard);92System.out.println93(" testing implies(new RuntimePermission(\"exitVM.23\"))");94if (!newPC.implies(other)) {95throw new Exception("expected true, received false");96}97System.out.println98(" testing implies(new RuntimePermission(\"exitVM.*\"))");99if (!newPC.implies(new RuntimePermission("exitVM.*"))) {100throw new Exception("expected true, received false");101}102System.out.println103(" testing implies(new RuntimePermission(\"exitVM\"))");104if (!newPC.implies(oldWildcard)) {105throw new Exception("expected true, received false");106}107System.out.println("Testing PermissionCollection containing " +108"RuntimePermission(\"exitVM\")");109PermissionCollection oldPC = oldWildcard.newPermissionCollection();110oldPC.add(oldWildcard);111System.out.println112(" testing implies(new RuntimePermission(\"exitVM.23\"))");113if (!oldPC.implies(other)) {114throw new Exception("expected true, received false");115}116System.out.println117(" testing implies(new RuntimePermission(\"exitVM.*\"))");118if (!oldPC.implies(new RuntimePermission("exitVM.*"))) {119throw new Exception("expected true, received false");120}121System.out.println122(" testing implies(new RuntimePermission(\"exitVM\"))");123if (!oldPC.implies(oldWildcard)) {124throw new Exception("expected true, received false");125}126}127}128129130