1 /* 2 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. 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 * 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. 22 */ 23 // Android-changed: Added package 24 package test.javax.xml.jaxp.transform; 25 26 import java.security.Policy; 27 28 /** 29 * 30 * 31 * @author huizhe.wang@oracle.com 32 */ 33 public class TestBase { 34 public static boolean isWindows = false; 35 static { 36 if (System.getProperty("os.name").indexOf("Windows")>-1) { 37 isWindows = true; 38 } 39 }; 40 41 String filepath; 42 boolean hasSM; 43 String curDir; 44 Policy origPolicy; 45 String testName; 46 static String errMessage; 47 48 int passed = 0, failed = 0; 49 50 /** 51 * Creates a new instance of StreamReader 52 */ TestBase(String name)53 public TestBase(String name) { 54 testName = name; 55 } 56 57 //junit @Override setUp()58 protected void setUp() { 59 if (System.getSecurityManager() != null) { 60 hasSM = true; 61 System.setSecurityManager(null); 62 } 63 64 filepath = System.getProperty("test.src"); 65 if (filepath == null) { 66 //current directory 67 filepath = System.getProperty("user.dir"); 68 } 69 origPolicy = Policy.getPolicy(); 70 71 } 72 73 //junit @Override tearDown()74 public void tearDown() { 75 // turn off security manager and restore policy 76 System.setSecurityManager(null); 77 Policy.setPolicy(origPolicy); 78 if (hasSM) { 79 System.setSecurityManager(new SecurityManager()); 80 } 81 System.out.println("\nNumber of tests passed: " + passed); 82 System.out.println("Number of tests failed: " + failed + "\n"); 83 84 if (errMessage != null ) { 85 throw new RuntimeException(errMessage); 86 } 87 } 88 fail(String errMsg)89 void fail(String errMsg) { 90 if (errMessage == null) { 91 errMessage = errMsg; 92 } else { 93 errMessage = errMessage + "\n" + errMsg; 94 } 95 failed++; 96 } 97 success(String msg)98 void success(String msg) { 99 passed++; 100 System.out.println(msg); 101 } 102 103 } 104