jdk/test/java/awt/Window/PropertyChangeListenerLockSerialization/PropertyChangeListenerLockSerialization.java
author goetz
Tue, 14 Jun 2016 10:44:59 +0200
changeset 39056 d99e63b6d962
parent 5506 202f599c92aa
permissions -rw-r--r--
8159690: [TESTBUG] Mark headful tests with @key headful. Reviewed-by: simonis, alexsch
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
432
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
     1
/*
39056
d99e63b6d962 8159690: [TESTBUG] Mark headful tests with @key headful.
goetz
parents: 5506
diff changeset
     2
 * Copyright (c) 2008, 2016, Oracle and/or its affiliates. All rights reserved.
432
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
     4
 *
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
     7
 * published by the Free Software Foundation.
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
     8
 *
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
    13
 * accompanied this code).
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
    14
 *
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
    18
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 432
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 432
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 432
diff changeset
    21
 * questions.
432
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
    22
 */
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
    23
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
    24
/*
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
    25
  @test
39056
d99e63b6d962 8159690: [TESTBUG] Mark headful tests with @key headful.
goetz
parents: 5506
diff changeset
    26
  @key headful
432
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
    27
  @bug 6681889
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
    28
  @summary Showing a deserialized frame should not throw NPE
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
    29
  @author anthony.petrov@...: area=awt.toplevel
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
    30
  @run main PropertyChangeListenerLockSerialization
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
    31
*/
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
    32
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
    33
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
    34
/**
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
    35
 * PropertyChangeListenerLockSerialization.java
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
    36
 *
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
    37
 * summary: Showing a deserialized frame should not throw NPE
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
    38
 */
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
    39
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
    40
import java.awt.*;
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
    41
import java.awt.event.*;
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
    42
import java.io.*;
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
    43
import java.net.*;
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
    44
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
    45
public class PropertyChangeListenerLockSerialization
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
    46
{
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
    47
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
    48
    private static void init()
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
    49
    {
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
    50
        //*** Create instructions for the user here ***
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
    51
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
    52
        String[] instructions =
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
    53
        {
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
    54
            "This is an AUTOMATIC test, simply wait until it is done.",
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
    55
            "The result (passed or failed) will be shown in the",
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
    56
            "message window below."
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
    57
        };
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
    58
        Sysout.createDialog( );
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
    59
        Sysout.printInstructions( instructions );
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
    60
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
    61
        File file =
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
    62
            new File(System.getProperty("test.classes", "."), "frame.ser");
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
    63
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
    64
        Frame f = new Frame("Frame");
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
    65
        f.setBounds(250, 50, 300, 300);
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
    66
        try {
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
    67
            OutputStream o = new FileOutputStream(file);
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
    68
            ObjectOutputStream oo = new ObjectOutputStream(o);
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
    69
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
    70
            oo.writeObject(f);
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
    71
            oo.close();
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
    72
        } catch (IOException ex) {
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
    73
            ex.printStackTrace();
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
    74
            fail("Unable to serialize the frame: " + ex);
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
    75
        }
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
    76
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
    77
        // Cleanup the frame
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
    78
        f.dispose();
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
    79
        f = null;
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
    80
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
    81
        try {
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
    82
            ObjectInputStream i = new ObjectInputStream(new FileInputStream(file));
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
    83
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
    84
            f = (Frame)i.readObject();
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
    85
            f.show();
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
    86
        } catch (NullPointerException ex) {
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
    87
            ex.printStackTrace();
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
    88
            fail("The NullPointerException has been thrown: " + ex);
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
    89
        } catch (Exception ex) {
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
    90
            ex.printStackTrace();
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
    91
            fail("Error while deserializing the frame: " + ex);
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
    92
        }
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
    93
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
    94
        // Cleanup the frame
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
    95
        f.dispose();
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
    96
        f = null;
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
    97
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
    98
        pass();
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
    99
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   100
    }//End  init()
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   101
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   102
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   103
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   104
    /*****************************************************
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   105
     * Standard Test Machinery Section
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   106
     * DO NOT modify anything in this section -- it's a
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   107
     * standard chunk of code which has all of the
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   108
     * synchronisation necessary for the test harness.
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   109
     * By keeping it the same in all tests, it is easier
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   110
     * to read and understand someone else's test, as
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   111
     * well as insuring that all tests behave correctly
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   112
     * with the test harness.
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   113
     * There is a section following this for test-
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   114
     * classes
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   115
     ******************************************************/
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   116
    private static boolean theTestPassed = false;
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   117
    private static boolean testGeneratedInterrupt = false;
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   118
    private static String failureMessage = "";
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   119
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   120
    private static Thread mainThread = null;
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   121
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   122
    private static int sleepTime = 300000;
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   123
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   124
    // Not sure about what happens if multiple of this test are
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   125
    //  instantiated in the same VM.  Being static (and using
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   126
    //  static vars), it aint gonna work.  Not worrying about
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   127
    //  it for now.
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   128
    public static void main( String args[] ) throws InterruptedException
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   129
    {
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   130
        mainThread = Thread.currentThread();
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   131
        try
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   132
        {
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   133
            init();
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   134
        }
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   135
        catch( TestPassedException e )
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   136
        {
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   137
            //The test passed, so just return from main and harness will
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   138
            // interepret this return as a pass
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   139
            return;
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   140
        }
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   141
        //At this point, neither test pass nor test fail has been
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   142
        // called -- either would have thrown an exception and ended the
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   143
        // test, so we know we have multiple threads.
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   144
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   145
        //Test involves other threads, so sleep and wait for them to
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   146
        // called pass() or fail()
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   147
        try
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   148
        {
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   149
            Thread.sleep( sleepTime );
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   150
            //Timed out, so fail the test
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   151
            throw new RuntimeException( "Timed out after " + sleepTime/1000 + " seconds" );
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   152
        }
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   153
        catch (InterruptedException e)
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   154
        {
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   155
            //The test harness may have interrupted the test.  If so, rethrow the exception
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   156
            // so that the harness gets it and deals with it.
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   157
            if( ! testGeneratedInterrupt ) throw e;
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   158
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   159
            //reset flag in case hit this code more than once for some reason (just safety)
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   160
            testGeneratedInterrupt = false;
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   161
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   162
            if ( theTestPassed == false )
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   163
            {
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   164
                throw new RuntimeException( failureMessage );
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   165
            }
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   166
        }
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   167
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   168
    }//main
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   169
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   170
    public static synchronized void setTimeoutTo( int seconds )
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   171
    {
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   172
        sleepTime = seconds * 1000;
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   173
    }
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   174
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   175
    public static synchronized void pass()
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   176
    {
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   177
        Sysout.println( "The test passed." );
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   178
        Sysout.println( "The test is over, hit  Ctl-C to stop Java VM" );
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   179
        //first check if this is executing in main thread
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   180
        if ( mainThread == Thread.currentThread() )
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   181
        {
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   182
            //Still in the main thread, so set the flag just for kicks,
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   183
            // and throw a test passed exception which will be caught
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   184
            // and end the test.
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   185
            theTestPassed = true;
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   186
            throw new TestPassedException();
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   187
        }
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   188
        theTestPassed = true;
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   189
        testGeneratedInterrupt = true;
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   190
        mainThread.interrupt();
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   191
    }//pass()
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   192
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   193
    public static synchronized void fail()
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   194
    {
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   195
        //test writer didn't specify why test failed, so give generic
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   196
        fail( "it just plain failed! :-)" );
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   197
    }
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   198
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   199
    public static synchronized void fail( String whyFailed )
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   200
    {
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   201
        Sysout.println( "The test failed: " + whyFailed );
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   202
        Sysout.println( "The test is over, hit  Ctl-C to stop Java VM" );
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   203
        //check if this called from main thread
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   204
        if ( mainThread == Thread.currentThread() )
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   205
        {
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   206
            //If main thread, fail now 'cause not sleeping
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   207
            throw new RuntimeException( whyFailed );
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   208
        }
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   209
        theTestPassed = false;
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   210
        testGeneratedInterrupt = true;
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   211
        failureMessage = whyFailed;
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   212
        mainThread.interrupt();
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   213
    }//fail()
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   214
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   215
}// class PropertyChangeListenerLockSerialization
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   216
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   217
//This exception is used to exit from any level of call nesting
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   218
// when it's determined that the test has passed, and immediately
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   219
// end the test.
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   220
class TestPassedException extends RuntimeException
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   221
{
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   222
}
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   223
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   224
//*********** End Standard Test Machinery Section **********
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   225
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   226
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   227
//************ Begin classes defined for the test ****************
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   228
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   229
// if want to make listeners, here is the recommended place for them, then instantiate
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   230
//  them in init()
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   231
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   232
/* Example of a class which may be written as part of a test
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   233
class NewClass implements anInterface
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   234
 {
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   235
   static int newVar = 0;
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   236
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   237
   public void eventDispatched(AWTEvent e)
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   238
    {
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   239
      //Counting events to see if we get enough
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   240
      eventCount++;
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   241
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   242
      if( eventCount == 20 )
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   243
       {
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   244
         //got enough events, so pass
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   245
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   246
         PropertyChangeListenerLockSerialization.pass();
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   247
       }
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   248
      else if( tries == 20 )
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   249
       {
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   250
         //tried too many times without getting enough events so fail
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   251
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   252
         PropertyChangeListenerLockSerialization.fail();
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   253
       }
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   254
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   255
    }// eventDispatched()
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   256
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   257
 }// NewClass class
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   258
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   259
*/
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   260
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   261
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   262
//************** End classes defined for the test *******************
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   263
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   264
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   265
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   266
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   267
/****************************************************
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   268
 Standard Test Machinery
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   269
 DO NOT modify anything below -- it's a standard
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   270
  chunk of code whose purpose is to make user
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   271
  interaction uniform, and thereby make it simpler
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   272
  to read and understand someone else's test.
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   273
 ****************************************************/
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   274
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   275
/**
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   276
 This is part of the standard test machinery.
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   277
 It creates a dialog (with the instructions), and is the interface
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   278
  for sending text messages to the user.
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   279
 To print the instructions, send an array of strings to Sysout.createDialog
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   280
  WithInstructions method.  Put one line of instructions per array entry.
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   281
 To display a message for the tester to see, simply call Sysout.println
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   282
  with the string to be displayed.
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   283
 This mimics System.out.println but works within the test harness as well
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   284
  as standalone.
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   285
 */
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   286
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   287
class Sysout
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   288
{
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   289
    private static TestDialog dialog;
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   290
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   291
    public static void createDialogWithInstructions( String[] instructions )
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   292
    {
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   293
        dialog = new TestDialog( new Frame(), "Instructions" );
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   294
        dialog.printInstructions( instructions );
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   295
        dialog.setVisible(true);
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   296
        println( "Any messages for the tester will display here." );
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   297
    }
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   298
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   299
    public static void createDialog( )
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   300
    {
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   301
        dialog = new TestDialog( new Frame(), "Instructions" );
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   302
        String[] defInstr = { "Instructions will appear here. ", "" } ;
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   303
        dialog.printInstructions( defInstr );
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   304
        dialog.setVisible(true);
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   305
        println( "Any messages for the tester will display here." );
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   306
    }
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   307
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   308
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   309
    public static void printInstructions( String[] instructions )
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   310
    {
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   311
        dialog.printInstructions( instructions );
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   312
    }
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   313
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   314
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   315
    public static void println( String messageIn )
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   316
    {
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   317
        dialog.displayMessage( messageIn );
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   318
        System.out.println(messageIn);
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   319
    }
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   320
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   321
}// Sysout  class
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   322
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   323
/**
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   324
  This is part of the standard test machinery.  It provides a place for the
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   325
   test instructions to be displayed, and a place for interactive messages
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   326
   to the user to be displayed.
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   327
  To have the test instructions displayed, see Sysout.
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   328
  To have a message to the user be displayed, see Sysout.
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   329
  Do not call anything in this dialog directly.
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   330
  */
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   331
class TestDialog extends Dialog
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   332
{
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   333
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   334
    TextArea instructionsText;
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   335
    TextArea messageText;
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   336
    int maxStringLength = 80;
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   337
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   338
    //DO NOT call this directly, go through Sysout
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   339
    public TestDialog( Frame frame, String name )
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   340
    {
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   341
        super( frame, name );
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   342
        int scrollBoth = TextArea.SCROLLBARS_BOTH;
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   343
        instructionsText = new TextArea( "", 15, maxStringLength, scrollBoth );
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   344
        add( "North", instructionsText );
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   345
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   346
        messageText = new TextArea( "", 5, maxStringLength, scrollBoth );
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   347
        add("Center", messageText);
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   348
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   349
        pack();
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   350
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   351
        setVisible(true);
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   352
    }// TestDialog()
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   353
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   354
    //DO NOT call this directly, go through Sysout
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   355
    public void printInstructions( String[] instructions )
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   356
    {
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   357
        //Clear out any current instructions
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   358
        instructionsText.setText( "" );
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   359
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   360
        //Go down array of instruction strings
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   361
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   362
        String printStr, remainingStr;
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   363
        for( int i=0; i < instructions.length; i++ )
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   364
        {
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   365
            //chop up each into pieces maxSringLength long
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   366
            remainingStr = instructions[ i ];
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   367
            while( remainingStr.length() > 0 )
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   368
            {
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   369
                //if longer than max then chop off first max chars to print
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   370
                if( remainingStr.length() >= maxStringLength )
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   371
                {
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   372
                    //Try to chop on a word boundary
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   373
                    int posOfSpace = remainingStr.
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   374
                        lastIndexOf( ' ', maxStringLength - 1 );
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   375
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   376
                    if( posOfSpace <= 0 ) posOfSpace = maxStringLength - 1;
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   377
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   378
                    printStr = remainingStr.substring( 0, posOfSpace + 1 );
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   379
                    remainingStr = remainingStr.substring( posOfSpace + 1 );
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   380
                }
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   381
                //else just print
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   382
                else
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   383
                {
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   384
                    printStr = remainingStr;
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   385
                    remainingStr = "";
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   386
                }
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   387
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   388
                instructionsText.append( printStr + "\n" );
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   389
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   390
            }// while
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   391
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   392
        }// for
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   393
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   394
    }//printInstructions()
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   395
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   396
    //DO NOT call this directly, go through Sysout
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   397
    public void displayMessage( String messageIn )
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   398
    {
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   399
        messageText.append( messageIn + "\n" );
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   400
        System.out.println(messageIn);
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   401
    }
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   402
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
diff changeset
   403
}// TestDialog  class