jdk/test/javax/xml/jaxp/common/8020430/TestBase.java
changeset 18816 ad694ff288f7
equal deleted inserted replaced
18815:5da35ed47cfa 18816:ad694ff288f7
       
     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 
       
    24 import java.security.Policy;
       
    25 
       
    26 /**
       
    27  *
       
    28  *
       
    29  * @author huizhe.wang@oracle.com
       
    30  */
       
    31 public class TestBase {
       
    32     String filePath;
       
    33     boolean hasSM;
       
    34     String curDir;
       
    35     Policy origPolicy;
       
    36 
       
    37     String testName;
       
    38     static String errMessage;
       
    39 
       
    40     int passed = 0, failed = 0;
       
    41 
       
    42     /**
       
    43      * Creates a new instance of StreamReader
       
    44      */
       
    45     public TestBase(String name) {
       
    46         testName = name;
       
    47     }
       
    48 
       
    49     //junit @Override
       
    50     protected void setUp() {
       
    51         if (System.getSecurityManager() != null) {
       
    52             hasSM = true;
       
    53             System.setSecurityManager(null);
       
    54         }
       
    55 
       
    56         filePath = System.getProperty("test.src");
       
    57         if (filePath == null) {
       
    58             //current directory
       
    59             filePath = System.getProperty("user.dir");
       
    60         }
       
    61         origPolicy = Policy.getPolicy();
       
    62 
       
    63     }
       
    64 
       
    65     //junit @Override
       
    66     public void tearDown() {
       
    67         // turn off security manager and restore policy
       
    68         System.setSecurityManager(null);
       
    69         Policy.setPolicy(origPolicy);
       
    70         if (hasSM) {
       
    71             System.setSecurityManager(new SecurityManager());
       
    72         }
       
    73         System.out.println("\nNumber of tests passed: " + passed);
       
    74         System.out.println("Number of tests failed: " + failed + "\n");
       
    75 
       
    76         if (errMessage != null ) {
       
    77             throw new RuntimeException(errMessage);
       
    78         }
       
    79     }
       
    80 
       
    81     void fail(String errMsg) {
       
    82         if (errMessage == null) {
       
    83             errMessage = errMsg;
       
    84         } else {
       
    85             errMessage = errMessage + "\n" + errMsg;
       
    86         }
       
    87         failed++;
       
    88     }
       
    89 
       
    90     void success(String msg) {
       
    91         passed++;
       
    92         System.out.println(msg);
       
    93     }
       
    94 
       
    95 }