Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/smartcardio/TestCardPermission.java
38833 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 629376726* @summary Test for the CardPermission class27* @author Andreas Sterbenz28*/2930import javax.smartcardio.*;3132public class TestCardPermission {3334public static void main(String[] args) throws Exception {35CardPermission perm;3637test("*");38test("connect");39test("reset");40test("exclusive");41test("transmitControl");42test("getBasicChannel");43test("openLogicalChannel");4445test("connect,reset");46test("Reset,coNnect", "connect,reset");47test("exclusive,*,connect", "*");48test("connect,reset,exclusive,transmitControl,getBasicChannel,openLogicalChannel", "*");4950invalid(null);51invalid("");52invalid("foo");53invalid("connect, reset");54invalid("connect,,reset");55invalid("connect,");56invalid(",connect");57invalid("");58}5960private static void invalid(String s) throws Exception {61try {62CardPermission c = new CardPermission("*", s);63throw new Exception("Created invalid action: " + c);64} catch (IllegalArgumentException e) {65System.out.println("OK: " + e);66}67}6869private static void test(String actions) throws Exception {70test(actions, actions);71}7273private static void test(String actions, String canon) throws Exception {74CardPermission p = new CardPermission("*", actions);75System.out.println(p);76String a = p.getActions();77if (canon.equals(a) == false) {78throw new Exception("Canonical actions mismatch: " + canon + " != " + a);79}80}8182}838485