duke | 6e45e10 | 2007-12-01 00:00:00 +0000 | [diff] [blame] | 1 | /* |
ohair | 2283b9d | 2010-05-25 15:58:33 -0700 | [diff] [blame^] | 2 | * Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved. |
duke | 6e45e10 | 2007-12-01 00:00:00 +0000 | [diff] [blame] | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
| 4 | * |
| 5 | * This code is free software; you can redistribute it and/or modify it |
| 6 | * under the terms of the GNU General Public License version 2 only, as |
| 7 | * published by the Free Software Foundation. |
| 8 | * |
| 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
| 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 12 | * version 2 for more details (a copy is included in the LICENSE file that |
| 13 | * accompanied this code). |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License version |
| 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
| 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
| 18 | * |
ohair | 2283b9d | 2010-05-25 15:58:33 -0700 | [diff] [blame^] | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
| 20 | * or visit www.oracle.com if you need additional information or have any |
| 21 | * questions. |
duke | 6e45e10 | 2007-12-01 00:00:00 +0000 | [diff] [blame] | 22 | */ |
| 23 | |
| 24 | /* |
| 25 | * @test |
| 26 | * @bug 6268673 |
| 27 | * @summary Test new RuntimePermission.exitVM wildcard syntax |
| 28 | * @author Sean Mullan |
| 29 | */ |
| 30 | |
| 31 | import java.security.PermissionCollection; |
| 32 | |
| 33 | public class ExitVM { |
| 34 | |
| 35 | public static void main(String[]args) throws Exception { |
| 36 | |
| 37 | RuntimePermission newWildcard = new RuntimePermission("exitVM.*"); |
| 38 | RuntimePermission oldWildcard = new RuntimePermission("exitVM"); |
| 39 | RuntimePermission other = new RuntimePermission("exitVM.23"); |
| 40 | System.out.println("Testing RuntimePermission(\"exitVM.*\")"); |
| 41 | System.out.println(" testing getName()"); |
| 42 | if (!newWildcard.getName().equals("exitVM.*")) { |
| 43 | throw new Exception |
| 44 | ("expected: exitVM.* received:" + newWildcard.getName()); |
| 45 | } |
| 46 | System.out.println |
| 47 | (" testing equals(new RuntimePermission(\"exitVM.*\"))"); |
| 48 | if (!newWildcard.equals(new RuntimePermission("exitVM.*"))) { |
| 49 | throw new Exception("expected true, received false"); |
| 50 | } |
| 51 | System.out.println |
| 52 | (" testing equals(new RuntimePermission(\"exitVM.23\"))"); |
| 53 | if (newWildcard.equals(other)) { |
| 54 | throw new Exception("expected false, received true"); |
| 55 | } |
| 56 | System.out.println |
| 57 | (" testing implies(new RuntimePermission(\"exitVM.23\"))"); |
| 58 | if (!newWildcard.implies(other)) { |
| 59 | throw new Exception("expected true, received false"); |
| 60 | } |
| 61 | System.out.println |
| 62 | (" testing implies(new RuntimePermission(\"exitVM.*\"))"); |
| 63 | if (!newWildcard.implies(new RuntimePermission("exitVM.*"))) { |
| 64 | throw new Exception("expected true, received false"); |
| 65 | } |
| 66 | System.out.println |
| 67 | (" testing implies(new RuntimePermission(\"exitVM\"))"); |
| 68 | if (!newWildcard.implies(oldWildcard)) { |
| 69 | throw new Exception("expected true, received false"); |
| 70 | } |
| 71 | System.out.println("Testing RuntimePermission(\"exitVM\")"); |
| 72 | System.out.println |
| 73 | (" testing implies(new RuntimePermission(\"exitVM.*\"))"); |
| 74 | if (!oldWildcard.implies(newWildcard)) { |
| 75 | throw new Exception("expected true, received false"); |
| 76 | } |
| 77 | System.out.println |
| 78 | (" testing implies(new RuntimePermission(\"exitVM\"))"); |
| 79 | if (!oldWildcard.implies(new RuntimePermission("exitVM"))) { |
| 80 | throw new Exception("expected true, received false"); |
| 81 | } |
| 82 | System.out.println |
| 83 | (" testing implies(new RuntimePermission(\"exitVM.23\"))"); |
| 84 | if (!oldWildcard.implies(other)) { |
| 85 | throw new Exception("expected true, received false"); |
| 86 | } |
| 87 | |
| 88 | // now test permission collections |
| 89 | System.out.println("Testing PermissionCollection containing " + |
| 90 | "RuntimePermission(\"exitVM.*\")"); |
| 91 | PermissionCollection newPC = newWildcard.newPermissionCollection(); |
| 92 | newPC.add(newWildcard); |
| 93 | System.out.println |
| 94 | (" testing implies(new RuntimePermission(\"exitVM.23\"))"); |
| 95 | if (!newPC.implies(other)) { |
| 96 | throw new Exception("expected true, received false"); |
| 97 | } |
| 98 | System.out.println |
| 99 | (" testing implies(new RuntimePermission(\"exitVM.*\"))"); |
| 100 | if (!newPC.implies(new RuntimePermission("exitVM.*"))) { |
| 101 | throw new Exception("expected true, received false"); |
| 102 | } |
| 103 | System.out.println |
| 104 | (" testing implies(new RuntimePermission(\"exitVM\"))"); |
| 105 | if (!newPC.implies(oldWildcard)) { |
| 106 | throw new Exception("expected true, received false"); |
| 107 | } |
| 108 | System.out.println("Testing PermissionCollection containing " + |
| 109 | "RuntimePermission(\"exitVM\")"); |
| 110 | PermissionCollection oldPC = oldWildcard.newPermissionCollection(); |
| 111 | oldPC.add(oldWildcard); |
| 112 | System.out.println |
| 113 | (" testing implies(new RuntimePermission(\"exitVM.23\"))"); |
| 114 | if (!oldPC.implies(other)) { |
| 115 | throw new Exception("expected true, received false"); |
| 116 | } |
| 117 | System.out.println |
| 118 | (" testing implies(new RuntimePermission(\"exitVM.*\"))"); |
| 119 | if (!oldPC.implies(new RuntimePermission("exitVM.*"))) { |
| 120 | throw new Exception("expected true, received false"); |
| 121 | } |
| 122 | System.out.println |
| 123 | (" testing implies(new RuntimePermission(\"exitVM\"))"); |
| 124 | if (!oldPC.implies(oldWildcard)) { |
| 125 | throw new Exception("expected true, received false"); |
| 126 | } |
| 127 | } |
| 128 | } |