ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/tck/JSR166TestCase.java
(Generate patch)

Comparing jsr166/src/test/tck/JSR166TestCase.java (file contents):
Revision 1.91 by jsr166, Thu Dec 8 18:54:46 2011 UTC vs.
Revision 1.95 by jsr166, Mon Jan 21 19:43:52 2013 UTC

# Line 11 | Line 11 | import java.io.ByteArrayInputStream;
11   import java.io.ByteArrayOutputStream;
12   import java.io.ObjectInputStream;
13   import java.io.ObjectOutputStream;
14 + import java.util.ArrayList;
15   import java.util.Arrays;
16   import java.util.Date;
17 + import java.util.Enumeration;
18 + import java.util.List;
19   import java.util.NoSuchElementException;
20   import java.util.PropertyPermission;
21   import java.util.concurrent.*;
# Line 69 | Line 72 | import java.security.SecurityPermission;
72   *
73   * </ol>
74   *
75 < * <p> <b>Other notes</b>
75 > * <p><b>Other notes</b>
76   * <ul>
77   *
78   * <li> Usually, there is one testcase method per JSR166 method
# Line 142 | Line 145 | public class JSR166TestCase extends Test
145      }
146  
147      /**
148 <     * Runs all JSR166 unit tests using junit.textui.TestRunner
148 >     * Runs all JSR166 unit tests using junit.textui.TestRunner.
149 >     * Optional command line arg provides the number of iterations to
150 >     * repeat running the tests.
151       */
152      public static void main(String[] args) {
153          if (useSecurityManager) {
# Line 507 | Line 512 | public class JSR166TestCase extends Test
512      }
513  
514      /**
515 +     * A debugging tool to print all stack traces, as jstack does.
516 +     */
517 +    void printAllStackTraces() {
518 +        System.err.println(
519 +            Arrays.toString(
520 +                java.lang.management.ManagementFactory.getThreadMXBean()
521 +                .dumpAllThreads(true, true)));
522 +    }
523 +
524 +    /**
525       * Checks that thread does not terminate within the default
526       * millisecond delay of {@code timeoutMillis()}.
527       */
# Line 623 | Line 638 | public class JSR166TestCase extends Test
638          SecurityManager sm = System.getSecurityManager();
639          if (sm == null) {
640              r.run();
641 +        }
642 +        runWithSecurityManagerWithPermissions(r, permissions);
643 +    }
644 +
645 +    /**
646 +     * Runs Runnable r with a security policy that permits precisely
647 +     * the specified permissions.  If there is no current security
648 +     * manager, a temporary one is set for the duration of the
649 +     * Runnable.  We require that any security manager permit
650 +     * getPolicy/setPolicy.
651 +     */
652 +    public void runWithSecurityManagerWithPermissions(Runnable r,
653 +                                                      Permission... permissions) {
654 +        SecurityManager sm = System.getSecurityManager();
655 +        if (sm == null) {
656              Policy savedPolicy = Policy.getPolicy();
657              try {
658                  Policy.setPolicy(permissivePolicy());
659                  System.setSecurityManager(new SecurityManager());
660 <                runWithPermissions(r, permissions);
660 >                runWithSecurityManagerWithPermissions(r, permissions);
661              } finally {
662                  System.setSecurityManager(null);
663                  Policy.setPolicy(savedPolicy);
# Line 675 | Line 705 | public class JSR166TestCase extends Test
705              return perms.implies(p);
706          }
707          public void refresh() {}
708 +        public String toString() {
709 +            List<Permission> ps = new ArrayList<Permission>();
710 +            for (Enumeration<Permission> e = perms.elements(); e.hasMoreElements();)
711 +                ps.add(e.nextElement());
712 +            return "AdjustablePolicy with permissions " + ps;
713 +        }
714      }
715  
716      /**

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines