Clover coverage report - JFCUnit Test Coverage
Coverage timestamp: Mon Dec 20 2004 23:38:10 MST
file stats: LOC: 1,115   Methods: 74
NCLOC: 517   Classes: 2
 
 Source file Conditionals Statements Methods TOTAL
JFCTestCase.java 37.2% 60.6% 64.9% 55.7%
coverage coverage
 1   
 package junit.extensions.jfcunit;
 2   
 
 3   
 import java.io.FileDescriptor;
 4   
 import java.lang.reflect.InvocationTargetException;
 5   
 import java.lang.reflect.Method;
 6   
 import java.lang.reflect.Modifier;
 7   
 import java.net.InetAddress;
 8   
 import java.security.Permission;
 9   
 
 10   
 import java.awt.Toolkit;
 11   
 
 12   
 import junit.framework.TestCase;
 13   
 import javax.swing.JFrame;
 14   
 import javax.swing.JButton;
 15   
 import java.awt.event.ActionListener;
 16   
 import java.awt.event.ActionEvent;
 17   
 
 18   
 /**
 19   
  * Extend this class to create new tests for Swing based interfaces. This is a
 20   
  * subclass of TestCase, and therefore provides all of the facilities that you
 21   
  * would normally expect from TestCase.
 22   
  *
 23   
  * An important point to realize about coding with Swing classes is that most
 24   
  * methods are single threaded. This means that once a component has been
 25   
  * shown, its methods should normally only be accessed by the AWT thread.
 26   
  * While JFCTestCase runs its tests, the AWT thread is temporarily blocked to
 27   
  * prevent multi-threading issues. The effect of this is that any method calls
 28   
  * that you make on Swing components during a test will have no impact on the
 29   
  * GUI, until the AWT Thread is restarted. This can occur in one of two ways:
 30   
  * (1) The test runs to completion (2) The method "awtSleep" defined within
 31   
  * this class is called.
 32   
  *
 33   
  * @author Matt Caswell
 34   
  * @author <a href="mailto:vraravam@thoughtworks.com">Vijay Aravamudhan : ThoughtWorks Inc.</a>
 35   
  * @author Kevin Wilson
 36   
  */
 37   
 public class JFCTestCase
 38   
     extends TestCase {
 39   
     /**
 40   
      * Time to wait between lock attempts.
 41   
      */
 42   
     private static final long DEFAULTLOCKWAIT = 25L;
 43   
 
 44   
     /**
 45   
      * Default time to sleep.
 46   
      */
 47   
     private static final long DEFAULTSLEEP = 100L;
 48   
 
 49   
     /*
 50   
      * Kick Start the WindowMonitor to hopefully.
 51   
      * Get it started before any popups are displayed.
 52   
      */
 53   
     static {
 54  79
         WindowMonitor.start();
 55   
     }
 56   
 
 57   
     /**
 58   
      * Lock instance.
 59   
      */
 60   
     private Object m_lock = new Object();
 61   
 
 62   
     /**
 63   
      * Exception thrown by testcase.
 64   
      */
 65   
     private Throwable m_err;
 66   
 
 67   
     /**
 68   
      * Assert Exit was called.
 69   
      */
 70   
     private transient boolean m_assertExit = false;
 71   
 
 72   
     /**
 73   
      * The test helper to be used in testing. This has been made protected,
 74   
      * since most users already have a super class in their test hierarchy
 75   
      * where it is protected. Make sure to actually instantiate this in your
 76   
      * setUp() method or at the beginning of the test methods.
 77   
      *
 78   
      * @depricated use getHelper() instead;
 79   
      */
 80   
     private TestHelper m_helper;
 81   
 
 82   
     /**
 83   
      * Continuation flag.
 84   
      */
 85   
     private boolean m_cont = false;
 86   
 
 87   
     /**
 88   
      * True if exited.
 89   
      */
 90   
     private boolean m_exited = false;
 91   
 
 92   
     /**
 93   
      * True if runBare has begun.
 94   
      * Used when setting the assertExit.
 95   
      */
 96   
     private boolean m_runBare = false;
 97   
 
 98   
     /**
 99   
      * Forcibly wait for full time.
 100   
      */
 101   
     private boolean m_forcedWait = false;
 102   
 
 103   
     /**
 104   
      * Run the AWTThread free from interruption.
 105   
      */
 106   
     private volatile boolean m_pausingAWT = false;
 107   
 
 108   
     /**
 109   
      * Waiting flag.
 110   
      */
 111   
     private volatile boolean m_waiting = false;
 112   
 
 113   
     /**
 114   
      * Lock Wait time.
 115   
      */
 116   
     private long m_lockWait = DEFAULTLOCKWAIT;
 117   
 
 118   
     /**
 119   
      * Time to sleep.
 120   
      */
 121   
     private long m_sleepTime = DEFAULTSLEEP;
 122   
 
 123   
     /**
 124   
      * Constructs a new JFCTestCase (default Constructor if using JUnit ver 3.8).
 125   
      */
 126  12
     protected JFCTestCase() {
 127  12
         super();
 128   
     }
 129   
 
 130   
     /**
 131   
      * Constructs a new JFCTestCase.
 132   
      *
 133   
      * @param name The name of the test.
 134   
      */
 135  1010
     public JFCTestCase(final String name) {
 136  1010
         super(name);
 137   
     }
 138   
 
 139   
     /**
 140   
      * Set the value of the assert exit property.
 141   
      * When true the System.exit() call will throw
 142   
      * an junit.extensions.jfcunit.ExitException to
 143   
      * interrupt the exit process, the application
 144   
      * will not exit. The test case will
 145   
      * assert that system exit was called.
 146   
      *
 147   
      * @param aValue true if System.exit() should be asserted,
 148   
      * to allow the test case to complete.
 149   
      */
 150  1213
     public final void setAssertExit(final boolean aValue) {
 151  1213
         if (!m_assertExit && aValue && m_runBare) {
 152  1
             System.setSecurityManager(createNoExitSecurityManager());
 153   
         }
 154  1213
         m_assertExit = aValue;
 155   
     }
 156   
 
 157   
     /**
 158   
      * Get the current value of the assertExit property.
 159   
      * see setAssertExit for a details description of the
 160   
      * operation.
 161   
      *
 162   
      * @return true if System.exit() should be asserted.
 163   
      * to allow the test case to complete.
 164   
      */
 165  0
     public final boolean getAssertExit() {
 166  0
         return m_assertExit;
 167   
     }
 168   
 
 169   
     /**
 170   
      * Sets the helper.
 171   
      *
 172   
      * @param helper TestHelper to be used.
 173   
      */
 174  1373
     public final void setHelper(final TestHelper helper) {
 175  1373
         this.m_helper = helper;
 176   
     }
 177   
 
 178   
     /**
 179   
      * Get the test helper.
 180   
      *
 181   
      * @return The test helper.
 182   
      */
 183  1623
     public final TestHelper getHelper() {
 184  1623
         return m_helper;
 185   
     }
 186   
 
 187   
     /**
 188   
      * Sets the sleepTime.
 189   
      *
 190   
      * @param time New value for sleepTime
 191   
      */
 192  277
     public final void setSleepTime(final long time) {
 193  277
         m_sleepTime = time;
 194   
     }
 195   
 
 196   
     /**
 197   
      * Suspends the test for up to a maximum period of time, and allows the
 198   
      * AWT Thread to resume temporarily. If the AWT Thread has not been paused,
 199   
      * this api has no effect. The time period is what was set by the user by
 200   
      * calling 'setSleepTime()' or 'awtSleep(sleepTime)'. If the notify occurs
 201   
      * before this time has elapsed, the thread will continue.
 202   
      */
 203  26856
     public final void awtSleep() {
 204  26856
         release();
 205   
 
 206  26856
         try {
 207  26856
             acquire();
 208   
         } catch (ExitException exe) {
 209  0
             setError(exe);
 210   
         } catch (InterruptedException ie) {
 211   
             ; // shouldn't occur
 212   
         }
 213   
     }
 214   
 
 215   
     /**
 216   
      * Suspends the test for up to the specified (maximum) period of time, and allows the AWT
 217   
      * Thread to resume temporarily. If the AWT Thread has not been paused, this api has
 218   
      * no effect. Note that the sleep time for subsequent calls to awtSleep()
 219   
      * will use the time specified in the current call. If the notify occurs before
 220   
      * this time has elapsed, the thread will continue.
 221   
      *
 222   
      * @param sleepTime The number of ms to sleep
 223   
      */
 224  18
     public final void awtSleep(final long sleepTime) {
 225  18
         setSleepTime(sleepTime);
 226  18
         awtSleep();
 227   
     }
 228   
 
 229   
     /**
 230   
      * Flush all events currently in the AWTEventQueue.
 231   
      * The event queue is left running afterwards.
 232   
      */
 233  6379
     public final void flushAWT() {
 234  6379
         pauseAWT();
 235  6378
         resumeAWT();
 236   
     }
 237   
 
 238   
     /**
 239   
      * Pause the awt event queue until it is released by
 240   
      * releaseAWT() or the end of the test is reached.
 241   
      */
 242  9449
     public final void pauseAWT() {
 243  9449
         m_pausingAWT = true;
 244  9449
         awtSleep();
 245   
     }
 246   
 
 247   
     /**
 248   
      * Resets the sleepTime to the default value (DEFAULTSLEEP).
 249   
      */
 250  0
     public final void resetSleepTime() {
 251  0
         m_sleepTime = DEFAULTSLEEP;
 252   
     }
 253   
 
 254   
     /**
 255   
      * Resume the awt event queue.
 256   
      */
 257  8525
     public final void resumeAWT() {
 258  8525
         awtSleep();
 259  8525
         m_pausingAWT = false;
 260  8525
         awtSleep();
 261   
     }
 262   
 
 263   
     /**
 264   
      * Suspends the test for a period of time, and allows the
 265   
      * AWT Thread to resume during this period if it has been
 266   
      * paused.
 267   
      *
 268   
      * @param delay The minimum amount of time the test case thread
 269   
      *              should be delayed.
 270   
      */
 271  699
     public final void sleep(final long delay) {
 272  699
         long releaseTime = System.currentTimeMillis() + delay;
 273  699
         releaseTime += delay;
 274   
 
 275  699
         while (System.currentTimeMillis() < releaseTime) {
 276  7207
             release();
 277   
 
 278  7207
             try {
 279  7207
                 Thread.currentThread().sleep(m_lockWait);
 280  7207
                 acquire();
 281   
             } catch (InterruptedException ie) {
 282   
                 ; // shouldn't occur
 283   
             }
 284   
         }
 285   
     }
 286   
 
 287   
     /**
 288   
      * Get the AWT state.
 289   
      *
 290   
      * @return  boolean specifying whether the AWT Thread is still running or not.
 291   
      */
 292  262
     public boolean isAWTRunning() {
 293  262
         return !m_pausingAWT;
 294   
     }
 295   
 
 296   
     /**
 297   
      * Sets up, executes and then tears down a test.
 298   
      *
 299   
      * @exception Throwable exceptions thrown by code.
 300   
      */
 301  446
     public void runBare() throws Throwable {
 302  446
         SecurityManager oldsm = System.getSecurityManager();
 303  446
         if (m_assertExit) {
 304  0
             System.setSecurityManager(createNoExitSecurityManager());
 305   
         }
 306  446
         m_runBare = true;
 307   
 
 308  446
         try {
 309  446
             try {
 310  446
                 runCode(
 311   
                     new Runnable() {
 312  446
                     public void run() {
 313  446
                         try {
 314  446
                             JFCTestCase.this.setUp();
 315  446
                             flushAWT();
 316   
                         } catch (Throwable e) {
 317  0
                             setError(e);
 318   
                         }
 319   
                     }
 320   
                 });
 321   
 
 322  446
                 try {
 323  446
                     runTest();
 324   
                 } catch (ExitException exe) {
 325   
                     // might need it here due to the test being run
 326  0
                     setError(exe);
 327   
                 }
 328   
             } finally {
 329  446
                 runCode(
 330   
                     new Runnable() {
 331  446
                     public void run() {
 332  446
                         try {
 333  446
                             resumeAWT();
 334  446
                             JFCTestCase.this.tearDown();
 335  445
                             flushAWT();
 336   
                         } catch (Throwable e) {
 337  0
                             setError(e);
 338   
                         }
 339   
                     }
 340   
                 });
 341   
             }
 342   
         } finally {
 343   
             // put back the original security manager
 344  446
             System.setSecurityManager(oldsm);
 345   
 
 346  446
             if (m_assertExit) {
 347  1
                 assertTrue("System.exit() was not called", m_exited);
 348   
             }
 349   
         }
 350   
     }
 351   
 
 352   
     /**
 353   
      * Sets the err.
 354   
      *
 355   
      * @param error New value for err.
 356   
      */
 357  1341
     protected final void setError(final Throwable error) {
 358  1341
         if (error != null) {
 359  3
             setContinue(false);
 360   
         }
 361   
 
 362  1341
         m_err = error;
 363   
     }
 364   
 
 365   
     /**
 366   
      * Returns the error.
 367   
      *
 368   
      * @return error.
 369   
      */
 370  3
     protected final Throwable getError() {
 371  3
         return m_err;
 372   
     }
 373   
 
 374   
     /**
 375   
      * Sets the forcedWait.
 376   
      *
 377   
      * @param forced New value for forcedWait.
 378   
      */
 379  2
     protected final void setForcedWait(final boolean forced) {
 380  2
         m_forcedWait = forced;
 381   
     }
 382   
 
 383   
     /**
 384   
      * Set the duration between checking the lock.
 385   
      * @param duration in milliseconds. A value less
 386   
      * than or equal to zero will reset the lockwait to the
 387   
      * default value.
 388   
      */
 389  355
     protected final void setLockWait(final long duration) {
 390  355
         if (duration <= 0) {
 391  0
             m_lockWait = DEFAULTLOCKWAIT;
 392   
         } else {
 393  355
             m_lockWait = duration;
 394   
         }
 395   
     }
 396   
 
 397   
     /**
 398   
      * Get the current duration between checking locks.
 399   
      * @return duration in milliseconds.
 400   
      */
 401  0
     protected final long getLockWait() {
 402  0
         return m_lockWait;
 403   
     }
 404   
 
 405   
     /**
 406   
      * Default setUp which does nothing. Override this to set up the environment
 407   
      * for your test.
 408   
      *
 409   
      * @exception  Exception   An instance of java.lang.Exception can be thrown
 410   
      */
 411  301
     protected void setUp() throws Exception {
 412  301
         super.setUp();
 413   
     }
 414   
 
 415   
     /**
 416   
      * This method creates a replacement for the default system manager.
 417   
      * The goal is to intercept System.exit calls and make it throw an
 418   
      * exception instead so that a System.exit in a task does not
 419   
      * fully terminate the test run.
 420   
      *
 421   
      * @return  An instance of a SecurityManager that will "consume" a call to System.exit()
 422   
      */
 423  1
     protected final SecurityManager createNoExitSecurityManager() {
 424  1
         return new JFCSecurityManager(System.getSecurityManager());
 425   
     }
 426   
 
 427   
     /**
 428   
      * Checks of the current test case has any errors.
 429   
      *
 430   
      * @return true if the current test case has any errors.
 431   
      */
 432  1338
     protected final boolean hasError() {
 433  1338
         return ((m_err != null) && !(m_err instanceof ExitException));
 434   
     }
 435   
 
 436   
     /**
 437   
      * Resets the err to the default value (null).
 438   
      */
 439  1338
     protected final void resetError() {
 440  1338
         setError(null);
 441   
     }
 442   
 
 443   
     /**
 444   
      * Resets the forcedWait to the default value (false).
 445   
      */
 446  1
     protected final void resetForcedWait() {
 447  1
         m_forcedWait = false;
 448   
     }
 449   
 
 450   
     /**
 451   
      * Run the code of the test case.
 452   
      * Note: This method will wait till the thread running code.run() completes
 453   
      * The above behavior is overridden if the setForcedWait() has been called with 'true'
 454   
      * Then the behavior is that the thread will wait for the time specified when awtSleep()
 455   
      * was called
 456   
      *
 457   
      * @param code Code which is to be executed.
 458   
      * @exception Throwable exceptions thrown by code.
 459   
      */
 460  1338
     protected synchronized void runCode(final Runnable code) throws Throwable {
 461  1338
         m_waiting = false;
 462  1338
         setContinue(true);
 463  1338
         resetError();
 464  1338
         TestHelper.setCurrentTestCase(this);
 465  1338
         new Thread(
 466   
             new Runnable() {
 467  1338
             public void run() {
 468  1338
                 synchronized (m_lock) {
 469  1338
                     m_waiting = true;
 470   
 
 471  1338
                     try {
 472  1338
                         acquire();
 473   
                     } catch (InterruptedException ie) {
 474   
                         // shouldn't occur
 475   
                     }
 476   
 
 477  1338
                     try {
 478  1338
                         code.run();
 479   
                     } catch (Throwable exe) {
 480   
                         // might need it here due to the method invocation
 481  0
                         setError(exe);
 482   
                     }
 483   
 
 484  1337
                     setContinue(false);
 485  1337
                     release();
 486   
                 }
 487   
             }
 488   
         }
 489   
 
 490   
         ,
 491   
             getName()).start();
 492   
 
 493   
         // here we have to wait for the code.run() to block
 494  1338
         while (!m_waiting) {
 495  1325
             try {
 496  1325
                 Thread.currentThread().sleep(m_lockWait);
 497   
             } catch (ExitException exe) {
 498   
                 // might need it here due to the method invocation
 499  0
                 setError(exe);
 500   
             } catch (InterruptedException ie) {
 501   
                 ; // shouldn't occur
 502   
             }
 503   
         }
 504   
 
 505  1338
         boolean condition = false;
 506  1338
         boolean firstTime = true;
 507  1338
         long elapsedTime = 0L;
 508   
 
 509  1338
         do {
 510  44469
             if (firstTime && m_pausingAWT) {
 511   
                 // flush out any other dialog boxes, etc which were opened by the call to code.run()
 512  17158
                 Toolkit.getDefaultToolkit().getSystemEventQueue().invokeAndWait(
 513   
                     new Runnable() {
 514  17158
                     public void run() {
 515  17158
                         synchronized (m_lock) {
 516  17158
                             release();
 517   
 
 518  17158
                             try {
 519  17158
                                 acquire();
 520   
                             } catch (InterruptedException ie) {
 521   
                                 ; // shouldn't occur
 522   
                             }
 523   
                         }
 524   
                     }
 525   
                 });
 526   
 
 527  17158
                 if (m_forcedWait) {
 528  0
                     firstTime = false;
 529   
                 }
 530   
             }
 531   
 
 532  44469
             try {
 533  44469
                 elapsedTime += m_lockWait;
 534  44469
                 Thread.currentThread().sleep(m_lockWait);
 535   
             } catch (InterruptedException ie) {
 536   
                 // shouldn't occur
 537   
             }
 538   
 
 539  44469
             if (m_forcedWait) {
 540  0
                 condition = (elapsedTime <= getSleepTime());
 541   
             } else {
 542  44469
                 condition = getContinue();
 543   
             }
 544   
         }
 545  44469
         while (condition);
 546   
 
 547  1338
         if (hasError()) {
 548  3
             throw getError();
 549   
         }
 550   
     }
 551   
 
 552   
     /**
 553   
      * Executes a test.
 554   
      *
 555   
      * @exception Throwable exceptions thrown by code.
 556   
      */
 557  408
     protected void runTest() throws Throwable {
 558  408
         final Method runMethod;
 559   
 
 560  408
         try {
 561  408
             runMethod = getClass().getMethod(
 562   
                 getName(),
 563   
                 new Class[0]);
 564   
         } catch (NoSuchMethodException e) {
 565  0
             fail("Method \"" + getName() + "\" not found");
 566   
 
 567  0
             return;
 568   
         }
 569   
 
 570  408
         if ((runMethod != null) && !Modifier.isPublic(runMethod.getModifiers())) {
 571  0
             fail("Method \"" + getName() + "\" should be public");
 572   
 
 573  0
             return;
 574   
         }
 575   
 
 576  408
         runCode(
 577   
             new Runnable() {
 578  408
             public void run() {
 579  408
                 try {
 580  408
                     runMethod.invoke(
 581   
                         JFCTestCase.this,
 582   
                         new Object[0]);
 583  407
                     flushAWT();
 584   
                 } catch (InvocationTargetException e) {
 585  1
                     setError(e.getTargetException());
 586   
                 } catch (Throwable e) {
 587  0
                     setError(e);
 588   
                 }
 589   
             }
 590   
         });
 591   
     }
 592   
 
 593   
     /**
 594   
      * Default tearDown which does nothing. Override this to tear down the
 595   
      * environment for your test.
 596   
      *
 597   
      * @exception  Exception   An instance of java.lang.Exception can be thrown
 598   
      */
 599  441
     protected void tearDown() throws Exception {
 600  441
         super.tearDown();
 601   
     }
 602   
 
 603   
     /**
 604   
      * Sets the cont.
 605   
      *
 606   
      * @param c New value for cont.
 607   
      */
 608  2679
     private void setContinue(final boolean c) {
 609  2679
         m_cont = c;
 610   
     }
 611   
 
 612   
     /**
 613   
      * Returns the cont.
 614   
      *
 615   
      * @return cont.
 616   
      */
 617  44469
     private boolean getContinue() {
 618  44469
         return m_cont;
 619   
     }
 620   
 
 621   
     /**
 622   
      * Returns the value of sleepTime.
 623   
      *
 624   
      * @return sleepTime.
 625   
      */
 626  0
     private long getSleepTime() {
 627  0
         return m_sleepTime;
 628   
     }
 629   
 
 630   
     /**
 631   
      * Acquire AWT Thread Control.
 632   
      *
 633   
      * @exception InterruptedException  Thrown when a thread is waiting, sleeping, or otherwise paused
 634   
      *                                  for a long time and another thread interrupts it using the
 635   
      *                                  <code>interrupt</code> method in class <code>Thread</code>.
 636   
      */
 637  52559
     private void acquire() throws InterruptedException {
 638   
         // when any events (usually window close events) try to call System.exit,
 639   
         // we need to trap the exception here
 640  52559
         synchronized (m_lock) {
 641  52559
             try {
 642  52559
                 if (m_pausingAWT) {
 643  34321
                     m_lock.wait();
 644   
                 } else {
 645  18238
                     m_lock.wait(m_lockWait);
 646   
                 }
 647   
             } catch (ExitException exe) {
 648   
                 ; // don't do anything here
 649   
             }
 650   
         }
 651   
     }
 652   
 
 653   
     /**
 654   
      * Release the AWT Thread Control.
 655   
      */
 656  52558
     private void release() {
 657   
         // when any events (usually window close events) try to call System.exit,
 658   
         // we need to trap the exception here
 659  52558
         synchronized (m_lock) {
 660  52558
             try {
 661  52558
                 m_lock.notify();
 662   
             } catch (ExitException exe) {
 663   
                 ; // don't do anything here
 664   
             }
 665   
         }
 666   
     }
 667   
 
 668   
     /**
 669   
      * Pause the test until the Option Pane is acknowleged.
 670   
      */
 671  0
     protected void pause() {
 672  0
         final boolean[] finished = new boolean[] {false};
 673  0
         final JFrame frame = new JFrame();
 674  0
         JButton button = new JButton("Continue");
 675  0
         button.addActionListener(new ActionListener() {
 676   
             /**
 677   
              * Action was performed.
 678   
              * @param e ActionEvent which was generated by the
 679   
              * continue button.
 680   
              */
 681  0
             public void actionPerformed(final ActionEvent e) {
 682  0
                 finished[0] = true;
 683  0
                 frame.setVisible(false);
 684  0
                 frame.dispose();
 685   
             }
 686   
         });
 687  0
         frame.getContentPane().add(button);
 688  0
         frame.pack();
 689  0
         frame.setLocationRelativeTo(null);
 690  0
         frame.setVisible(true);
 691  0
         while (!finished[0]) {
 692  0
             sleep(1000);
 693   
         }
 694   
     }
 695   
 
 696   
 
 697   
     /**
 698   
      * Security manager which proxies all calls to the
 699   
      * original security manager. If the checkExit is
 700   
      * called and the setAssertExit(true) then the
 701   
      * SecurityException is thrown.
 702   
      */
 703   
     class JFCSecurityManager
 704   
         extends SecurityManager {
 705   
 
 706   
         /**
 707   
          * Original Security manager.
 708   
          */
 709   
         private SecurityManager m_delegate;
 710   
 
 711   
         /**
 712   
          * Constructor.
 713   
          * @param delegate Delegate security manager.
 714   
          */
 715  1
         public JFCSecurityManager(final SecurityManager delegate) {
 716  1
             super();
 717  1
             m_delegate = delegate;
 718   
         }
 719   
 
 720   
         /**
 721   
          * @param status Status to be used.
 722   
          * @see java.lang.SecurityManager#checkExit(int)
 723   
          */
 724  1
         public void checkExit(final int status) {
 725  1
             if (m_assertExit) {
 726  1
                 m_exited = true;
 727  1
                 setContinue(false);
 728  1
                 throw new ExitException(status);
 729   
             } else {
 730  0
                 m_delegate.checkExit(status);
 731   
             }
 732   
         }
 733   
 
 734   
         /**
 735   
          * @param perm Permission to be checked.
 736   
          * @see java.lang.SecurityManager#checkPermission(java.security.Permission)
 737   
          */
 738  26
         public void checkPermission(final Permission perm) {
 739  26
             if (m_delegate != null) {
 740  0
                 m_delegate.checkPermission(perm);
 741   
             }
 742   
         }
 743   
 
 744   
         /**
 745   
          * Throws a <code>SecurityException</code> if the calling thread is not
 746   
          * permitted to accept a socket connection from the specified host and port
 747   
          * number.
 748   
          *
 749   
          * @param host the host name of the socket connection.
 750   
          * @param port the port number of the socket connection.
 751   
          */
 752  0
         public void checkAccept(final String host, final int port) {
 753  0
             if (m_delegate != null) {
 754  0
                 m_delegate.checkAccept(host, port);
 755   
             }
 756   
         }
 757   
 
 758   
         /**
 759   
          * Throws a <code>SecurityException</code> if the calling thread is not
 760   
          * allowed to modify the thread argument.
 761   
          *
 762   
          * @param t the thread to be checked.
 763   
          */
 764  1
         public void checkAccess(final Thread t) {
 765  1
             if (m_delegate != null) {
 766  0
                 m_delegate.checkAccess(t);
 767   
             }
 768   
         }
 769   
 
 770   
         /**
 771   
          * Throws a <code>SecurityException</code> if the calling thread is not
 772   
          * allowed to modify the thread group argument.
 773   
          *
 774   
          * @param g the thread group to be checked.
 775   
          */
 776  1
         public void checkAccess(final ThreadGroup g) {
 777  1
             if (m_delegate != null) {
 778  0
                 m_delegate.checkAccess(g);
 779   
             }
 780   
         }
 781   
 
 782   
         /**
 783   
          * Throws a <code>SecurityException</code> if the calling thread is not
 784   
          * allowed to access the AWT event queue.
 785   
          */
 786  12
         public void checkAwtEventQueueAccess() {
 787  12
             if (m_delegate != null) {
 788  0
                 m_delegate.checkAwtEventQueueAccess();
 789   
             }
 790   
         }
 791   
 
 792   
         /**
 793   
          * Throws a <code>SecurityException</code> if the calling thread is not
 794   
          * allowed to open a socket connection to the specified host and port number.
 795   
          *
 796   
          * @param host the host name port to connect to.
 797   
          * @param port the protocol port to connect to.
 798   
          */
 799  0
         public void checkConnect(final String host, final int port) {
 800  0
             if (m_delegate != null) {
 801  0
                 m_delegate.checkConnect(host, port);
 802   
             }
 803   
         }
 804   
 
 805   
         /**
 806   
          * Throws a <code>SecurityException</code> if the specified security context
 807   
          * is not allowed to open a socket connection to the specified host and port
 808   
          * number.
 809   
          *
 810   
          * @param host the host name port to connect to.
 811   
          * @param port the protocol port to connect to.
 812   
          * @param context a system-dependent security context.
 813   
          */
 814  0
         public void checkConnect(final String host, final int port,
 815   
                                  final Object context) {
 816  0
             if (m_delegate != null) {
 817  0
                 m_delegate.checkConnect(host, port, context);
 818   
             }
 819   
         }
 820   
 
 821   
         /**
 822   
          * Throws a <code>SecurityException</code> if the calling thread is not
 823   
          * allowed to create a new class loader.
 824   
          */
 825  1
         public void checkCreateClassLoader() {
 826  1
             if (m_delegate != null) {
 827  0
                 m_delegate.checkCreateClassLoader();
 828   
             }
 829   
         }
 830   
 
 831   
         /**
 832   
          * Throws a <code>SecurityException</code> if the calling thread is not
 833   
          * allowed to delete the specified file.
 834   
          *
 835   
          * @param file the system-dependent filename.
 836   
          */
 837  0
         public void checkDelete(final String file) {
 838  0
             if (m_delegate != null) {
 839  0
                 m_delegate.checkDelete(file);
 840   
             }
 841   
         }
 842   
 
 843   
         /**
 844   
          * Throws a <code>SecurityException</code> if the calling thread is not
 845   
          * allowed to create a subprocess.
 846   
          *
 847   
          * @param cmd the specified system command.
 848   
          */
 849  0
         public void checkExec(final String cmd) {
 850  0
             if (m_delegate != null) {
 851  0
                 m_delegate.checkExec(cmd);
 852   
             }
 853   
         }
 854   
 
 855   
         /**
 856   
          * Throws a <code>SecurityException</code> if the calling thread is not
 857   
          * allowed to dynamic link the library code specified by the string argument
 858   
          * file.
 859   
          *
 860   
          * @param lib the name of the library.
 861   
          */
 862  1
         public void checkLink(final String lib) {
 863  1
             if (m_delegate != null) {
 864  0
                 m_delegate.checkLink(lib);
 865   
             }
 866   
         }
 867   
 
 868   
         /**
 869   
          * Throws a <code>SecurityException</code> if the calling thread is not
 870   
          * allowed to wait for a connection request on the specified local port
 871   
          * number.
 872   
          *
 873   
          * @param port the local port.
 874   
          */
 875  0
         public void checkListen(final int port) {
 876  0
             if (m_delegate != null) {
 877  0
                 m_delegate.checkListen(port);
 878   
             }
 879   
         }
 880   
 
 881   
         /**
 882   
          * Throws a <code>SecurityException</code> if the calling thread is not
 883   
          * allowed to access members.
 884   
          *
 885   
          * @param clazz the class that reflection is to be performed on.
 886   
          * @param which type of access, PUBLIC or DECLARED.
 887   
          */
 888  15
         public void checkMemberAccess(final Class clazz, final int which) {
 889  15
             if (m_delegate != null) {
 890  0
                 m_delegate.checkMemberAccess(clazz, which);
 891   
             }
 892   
         }
 893   
 
 894   
         /**
 895   
          * Throws a <code>SecurityException</code> if the calling thread is not
 896   
          * allowed to use (join/leave/send/receive) IP multicast.
 897   
          *
 898   
          * @param maddr Internet group address to be used.
 899   
          */
 900  0
         public void checkMulticast(final InetAddress maddr) {
 901  0
             if (m_delegate != null) {
 902  0
                 m_delegate.checkMulticast(maddr);
 903   
             }
 904   
         }
 905   
 
 906   
         /**
 907   
          * Throws a <code>SecurityException</code> if the calling thread is not
 908   
          * allowed to access the package specified by the argument.
 909   
          *
 910   
          * @param pkg the package name.
 911   
          */
 912  43
         public void checkPackageAccess(final String pkg) {
 913  43
             if (m_delegate != null) {
 914  0
                 m_delegate.checkPackageAccess(pkg);
 915   
             }
 916   
         }
 917   
 
 918   
         /**
 919   
          * Throws a <code>SecurityException</code> if the calling thread is not
 920   
          * allowed to define classes in the package specified by the argument.
 921   
          *
 922   
          * @param pkg the package name.
 923   
          */
 924  0
         public void checkPackageDefinition(final String pkg) {
 925  0
             if (m_delegate != null) {
 926  0
                 m_delegate.checkPackageDefinition(pkg);
 927   
             }
 928   
         }
 929   
 
 930   
         /**
 931   
          * Throws a <code>SecurityException</code> if the specified security context
 932   
          * is denied access to the resource specified by the given permission.
 933   
          *
 934   
          * @param perm the specified permission
 935   
          * @param context a system-dependent security context.
 936   
          */
 937  0
         public void checkPermission(final Permission perm, final Object context) {
 938  0
             if (m_delegate != null) {
 939  0
                 m_delegate.checkPermission(perm, context);
 940   
             }
 941   
         }
 942   
 
 943   
         /**
 944   
          * Throws a <code>SecurityException</code> if the calling thread is not
 945   
          * allowed to initiate a print job request.
 946   
          */
 947  0
         public void checkPrintJobAccess() {
 948  0
             if (m_delegate != null) {
 949  0
                 m_delegate.checkPrintJobAccess();
 950   
             }
 951   
         }
 952   
 
 953   
         /**
 954   
          * Throws a <code>SecurityException</code> if the calling thread is not
 955   
          * allowed to access or modify the system properties.
 956   
          */
 957  0
         public void checkPropertiesAccess() {
 958  0
             if (m_delegate != null) {
 959  0
                 m_delegate.checkPropertiesAccess();
 960   
             }
 961   
         }
 962   
 
 963   
         /**
 964   
          * Throws a <code>SecurityException</code> if the calling thread is not
 965   
          * allowed to access the system property with the specified <code>key</code>
 966   
          * name.
 967   
          *
 968   
          * @param key a system property key.
 969   
          */
 970  6
         public void checkPropertyAccess(final String key) {
 971  6
             if (m_delegate != null) {
 972  0
                 m_delegate.checkPropertyAccess(key);
 973   
             }
 974   
         }
 975   
 
 976   
         /**
 977   
          * Throws a <code>SecurityException</code> if the calling thread is not
 978   
          * allowed to read from the specified file descriptor.
 979   
          *
 980   
          * @param fd the system-dependent file descriptor.
 981   
          */
 982  0
         public void checkRead(final FileDescriptor fd) {
 983  0
             if (m_delegate != null) {
 984  0
                 m_delegate.checkRead(fd);
 985   
             }
 986   
         }
 987   
 
 988   
         /**
 989   
          * Throws a <code>SecurityException</code> if the calling thread is not
 990   
          * allowed to read the file specified by the string argument.
 991   
          *
 992   
          * @param file the system-dependent file name.
 993   
          */
 994  34
         public void checkRead(final String file) {
 995  34
             if (m_delegate != null) {
 996  0
                 m_delegate.checkRead(file);
 997   
             }
 998   
         }
 999   
 
 1000   
         /**
 1001   
          * Throws a <code>SecurityException</code> if the specified security context
 1002   
          * is not allowed to read the file specified by the string argument.
 1003   
          *
 1004   
          * @param file the system-dependent filename.
 1005   
          * @param context a system-dependent security context.
 1006   
          */
 1007  0
         public void checkRead(final String file, final Object context) {
 1008  0
             if (m_delegate != null) {
 1009  0
                 m_delegate.checkRead(file, context);
 1010   
             }
 1011   
         }
 1012   
 
 1013   
         /**
 1014   
          * Determines whether the permission with the specified permission target
 1015   
          * name should be granted or denied.
 1016   
          *
 1017   
          * @param target the target name of the <code>SecurityPermission</code>.
 1018   
          */
 1019  0
         public void checkSecurityAccess(final String target) {
 1020  0
             if (m_delegate != null) {
 1021  0
                 m_delegate.checkSecurityAccess(target);
 1022   
             }
 1023   
         }
 1024   
 
 1025   
         /**
 1026   
          * Throws a <code>SecurityException</code> if the calling thread is not
 1027   
          * allowed to set the socket factory used by <code>ServerSocket</code> or
 1028   
          * <code>Socket</code>, or the stream handler factory used by
 1029   
          * <code>URL</code>.
 1030   
          */
 1031  0
         public void checkSetFactory() {
 1032  0
             if (m_delegate != null) {
 1033  0
                 m_delegate.checkSetFactory();
 1034   
             }
 1035   
         }
 1036   
 
 1037   
         /**
 1038   
          * Throws a <code>SecurityException</code> if the calling thread is not
 1039   
          * allowed to access the system clipboard.
 1040   
          */
 1041  0
         public void checkSystemClipboardAccess() {
 1042  0
             if (m_delegate != null) {
 1043  0
                 m_delegate.checkSystemClipboardAccess();
 1044   
             }
 1045   
         }
 1046   
 
 1047   
         /**
 1048   
          * Returns <code>false</code> if the calling thread is not trusted to bring
 1049   
          * up the top-level window indicated by the <code>window</code> argument.
 1050   
          *
 1051   
          * @param window the new window that is being created.
 1052   
          * @return <code>true</code> if the calling thread is trusted to put up
 1053   
          *   top-level windows; <code>false</code> otherwise.
 1054   
          */
 1055  0
         public boolean checkTopLevelWindow(final Object window) {
 1056  0
             if (m_delegate != null) {
 1057  0
                 return m_delegate.checkTopLevelWindow(window);
 1058   
             }
 1059  0
             return false;
 1060   
         }
 1061   
 
 1062   
         /**
 1063   
          * Throws a <code>SecurityException</code> if the calling thread is not
 1064   
          * allowed to write to the specified file descriptor.
 1065   
          *
 1066   
          * @param fd the system-dependent file descriptor.
 1067   
          */
 1068  0
         public void checkWrite(final FileDescriptor fd) {
 1069  0
             if (m_delegate != null) {
 1070  0
                 m_delegate.checkWrite(fd);
 1071   
             }
 1072   
         }
 1073   
 
 1074   
         /**
 1075   
          * Throws a <code>SecurityException</code> if the calling thread is not
 1076   
          * allowed to write to the file specified by the string argument.
 1077   
          *
 1078   
          * @param file the system-dependent filename.
 1079   
          */
 1080  0
         public void checkWrite(final String file) {
 1081  0
             if (m_delegate != null) {
 1082  0
                 m_delegate.checkWrite(file);
 1083   
             }
 1084   
         }
 1085   
 
 1086   
         /**
 1087   
          * Creates an object that encapsulates the current execution environment.
 1088   
          *
 1089   
          * @return an implementation-dependent object that encapsulates sufficient
 1090   
          *   information about the current execution environment to perform some
 1091   
          *   security checks later.
 1092   
          */
 1093  0
         public Object getSecurityContext() {
 1094  0
             if (m_delegate != null) {
 1095  0
                 return m_delegate.getSecurityContext();
 1096   
             }
 1097  0
             return "";
 1098   
         }
 1099   
 
 1100   
         /**
 1101   
          * Returns the thread group into which to instantiate any new thread being
 1102   
          * created at the time this is being called.
 1103   
          *
 1104   
          * @return ThreadGroup that new threads are instantiated into
 1105   
          */
 1106  1
         public ThreadGroup getThreadGroup() {
 1107  1
             if (m_delegate != null) {
 1108  0
                 return m_delegate.getThreadGroup();
 1109   
             }
 1110  1
             return null;
 1111   
         }
 1112   
     }
 1113   
 
 1114   
 }
 1115