jdk/test/java/awt/Component/UpdatingBootTime/UpdatingBootTime.java
author mfang
Wed, 17 Aug 2011 14:18:26 -0700
changeset 10294 8fcdae2a7ec7
parent 5506 202f599c92aa
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     2
 * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
  test
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
  @bug 6461933
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
  @summary adjust system boot time in nowMillisUTC() frequently
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
  @author Andrei Dmitriev : area=awt.component
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
  @run applet/manual=yesno UpdatingBootTime.html
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * verifies that time updated by the system is picked up by the Java App.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.applet.Applet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.awt.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.awt.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import java.util.Date;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
public class UpdatingBootTime extends Applet
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
    //Declare things used in the test, like buttons and labels here
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    public void init()
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
        this.setLayout (new BorderLayout ());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
        String[] instructions =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
            "1) Press the mouse over the button.",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
            "2) A two timestamps would be printed.",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
            "3) Verify that they are not differ a lot: it is okay to observe a 1 or 2 seconds difference.",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
            "4) Change the system time significantly(by a month or a year) by using the OS abilities.",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
            "5) Click on the button once again.",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
            "6) Printed times should still be the same. Pay attention to the Month/Year if they were changed.",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
            "7) It is okay to observe a 1 or 2 seconds difference and this is not a fail.",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
            "8) If the difference is more then 1-2 seconds noticed then the test fail; otherwise pass."
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
        };
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
        Sysout.createDialogWithInstructions( instructions );
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    }//End  init()
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    public void start ()
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
        Button b = new Button("Press me");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        b.addMouseListener(new MouseAdapter(){
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
                public void mousePressed(MouseEvent e){
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
                    Sysout.println("Event occured : "+e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
                    Sysout.println("The event time is : "+ (new Date(e.getWhen())));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
                    Sysout.println("The system time is : "+ (new Date()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
            });
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        add(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        setSize (200,200);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        setVisible(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        validate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    }// start()
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
}// class UpdatingBootTime
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
/* Place other classes related to the test after this line */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
/****************************************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
 Standard Test Machinery
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
 DO NOT modify anything below -- it's a standard
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
  chunk of code whose purpose is to make user
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
  interaction uniform, and thereby make it simpler
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
  to read and understand someone else's test.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
 ****************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
 This is part of the standard test machinery.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
 It creates a dialog (with the instructions), and is the interface
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
  for sending text messages to the user.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
 To print the instructions, send an array of strings to Sysout.createDialog
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
  WithInstructions method.  Put one line of instructions per array entry.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
 To display a message for the tester to see, simply call Sysout.println
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
  with the string to be displayed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
 This mimics System.out.println but works within the test harness as well
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
  as standalone.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
class Sysout
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    private static TestDialog dialog;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    public static void createDialogWithInstructions( String[] instructions )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        dialog = new TestDialog( new Frame(), "Instructions" );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        dialog.printInstructions( instructions );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        dialog.setVisible(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        println( "Any messages for the tester will display here." );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    public static void createDialog( )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        dialog = new TestDialog( new Frame(), "Instructions" );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        String[] defInstr = { "Instructions will appear here. ", "" } ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        dialog.printInstructions( defInstr );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        dialog.setVisible(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        println( "Any messages for the tester will display here." );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    public static void printInstructions( String[] instructions )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        dialog.printInstructions( instructions );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    public static void println( String messageIn )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        dialog.displayMessage( messageIn );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
}// Sysout  class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
  This is part of the standard test machinery.  It provides a place for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
   test instructions to be displayed, and a place for interactive messages
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
   to the user to be displayed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
  To have the test instructions displayed, see Sysout.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
  To have a message to the user be displayed, see Sysout.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
  Do not call anything in this dialog directly.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
  */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
class TestDialog extends Dialog
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    TextArea instructionsText;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    TextArea messageText;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    int maxStringLength = 80;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    //DO NOT call this directly, go through Sysout
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    public TestDialog( Frame frame, String name )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        super( frame, name );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        int scrollBoth = TextArea.SCROLLBARS_BOTH;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        instructionsText = new TextArea( "", 15, maxStringLength, scrollBoth );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        add( "North", instructionsText );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        messageText = new TextArea( "", 5, maxStringLength, scrollBoth );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        add("Center", messageText);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        pack();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        setVisible(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    }// TestDialog()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    //DO NOT call this directly, go through Sysout
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    public void printInstructions( String[] instructions )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        //Clear out any current instructions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        instructionsText.setText( "" );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        //Go down array of instruction strings
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        String printStr, remainingStr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        for( int i=0; i < instructions.length; i++ )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
            //chop up each into pieces maxSringLength long
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
            remainingStr = instructions[ i ];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
            while( remainingStr.length() > 0 )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
                //if longer than max then chop off first max chars to print
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
                if( remainingStr.length() >= maxStringLength )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
                {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
                    //Try to chop on a word boundary
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
                    int posOfSpace = remainingStr.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
                        lastIndexOf( ' ', maxStringLength - 1 );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
                    if( posOfSpace <= 0 ) posOfSpace = maxStringLength - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
                    printStr = remainingStr.substring( 0, posOfSpace + 1 );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
                    remainingStr = remainingStr.substring( posOfSpace + 1 );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
                //else just print
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
                else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
                {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
                    printStr = remainingStr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
                    remainingStr = "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
                instructionsText.append( printStr + "\n" );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
            }// while
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        }// for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    }//printInstructions()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
    //DO NOT call this directly, go through Sysout
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    public void displayMessage( String messageIn )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        messageText.append( messageIn + "\n" );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        System.out.println(messageIn);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
}// TestDialog  class