Path: blob/master/test/jdk/javax/xml/jaxp/common/8020430/TestBase.java
41154 views
/*1* Copyright (c) 2013, 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.security.Policy;2425/**26*27*28* @author [email protected]29*/30public class TestBase {31String filePath;32boolean hasSM;33String curDir;34Policy origPolicy;3536String testName;37static String errMessage;3839int passed = 0, failed = 0;4041/**42* Creates a new instance of StreamReader43*/44public TestBase(String name) {45testName = name;46}4748//junit @Override49protected void setUp() {50if (System.getSecurityManager() != null) {51hasSM = true;52System.setSecurityManager(null);53}5455filePath = System.getProperty("test.src");56if (filePath == null) {57//current directory58filePath = System.getProperty("user.dir");59}60origPolicy = Policy.getPolicy();6162}6364//junit @Override65public void tearDown() {66// turn off security manager and restore policy67System.setSecurityManager(null);68Policy.setPolicy(origPolicy);69if (hasSM) {70System.setSecurityManager(new SecurityManager());71}72System.out.println("\nNumber of tests passed: " + passed);73System.out.println("Number of tests failed: " + failed + "\n");7475if (errMessage != null ) {76throw new RuntimeException(errMessage);77}78}7980void fail(String errMsg) {81if (errMessage == null) {82errMessage = errMsg;83} else {84errMessage = errMessage + "\n" + errMsg;85}86failed++;87}8889void success(String msg) {90passed++;91System.out.println(msg);92}9394}959697