jdk/test/javax/xml/jaxp/transform/jdk8004476/TestBase.java
changeset 21364 decde35d5139
equal deleted inserted replaced
21363:82e139fdd879 21364:decde35d5139
       
     1 /*
       
     2  * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
       
     3  * ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
       
     4  */
       
     5 import java.security.Policy;
       
     6 
       
     7 /**
       
     8  *
       
     9  *
       
    10  * @author huizhe.wang@oracle.com
       
    11  */
       
    12 public class TestBase {
       
    13     public static boolean isWindows = false;
       
    14     static {
       
    15         if (System.getProperty("os.name").indexOf("Windows")>-1) {
       
    16             isWindows = true;
       
    17         }
       
    18     };
       
    19 
       
    20     String filepath;
       
    21     boolean hasSM;
       
    22     String curDir;
       
    23     Policy origPolicy;
       
    24     String testName;
       
    25     static String errMessage;
       
    26 
       
    27     int passed = 0, failed = 0;
       
    28 
       
    29     /**
       
    30      * Creates a new instance of StreamReader
       
    31      */
       
    32     public TestBase(String name) {
       
    33         testName = name;
       
    34     }
       
    35 
       
    36     //junit @Override
       
    37     protected void setUp() {
       
    38         if (System.getSecurityManager() != null) {
       
    39             hasSM = true;
       
    40             System.setSecurityManager(null);
       
    41         }
       
    42 
       
    43         filepath = System.getProperty("test.src");
       
    44         if (filepath == null) {
       
    45             //current directory
       
    46             filepath = System.getProperty("user.dir");
       
    47         }
       
    48         origPolicy = Policy.getPolicy();
       
    49 
       
    50     }
       
    51 
       
    52     //junit @Override
       
    53     public void tearDown() {
       
    54         // turn off security manager and restore policy
       
    55         System.setSecurityManager(null);
       
    56         Policy.setPolicy(origPolicy);
       
    57         if (hasSM) {
       
    58             System.setSecurityManager(new SecurityManager());
       
    59         }
       
    60         System.out.println("\nNumber of tests passed: " + passed);
       
    61         System.out.println("Number of tests failed: " + failed + "\n");
       
    62 
       
    63         if (errMessage != null ) {
       
    64             throw new RuntimeException(errMessage);
       
    65         }
       
    66     }
       
    67 
       
    68     void fail(String errMsg) {
       
    69         if (errMessage == null) {
       
    70             errMessage = errMsg;
       
    71         } else {
       
    72             errMessage = errMessage + "\n" + errMsg;
       
    73         }
       
    74         failed++;
       
    75     }
       
    76 
       
    77     void success(String msg) {
       
    78         passed++;
       
    79         System.out.println(msg);
       
    80     }
       
    81 
       
    82 }