Path: blob/master/test/jdk/java/awt/Component/UpdatingBootTime/UpdatingBootTime.java
41153 views
/*1* Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24test25@bug 6461933 719421926@summary adjust system boot time in nowMillisUTC() frequently27@author Andrei Dmitriev : area=awt.component28@run applet/manual=yesno UpdatingBootTime.html29*/3031/*32* verifies that time updated by the system is picked up by the Java App.33*/3435import java.applet.Applet;36import java.awt.*;37import java.awt.event.*;38import java.util.Date;3940public class UpdatingBootTime extends Applet41{42//Declare things used in the test, like buttons and labels here4344public void init()45{46this.setLayout (new BorderLayout ());4748String[] instructions =49{50"1) Press the mouse over the button.",51"2) A two timestamps would be printed.",52"3) Verify that they are not differ a lot: it is okay to observe a 1 or 2 seconds difference.",53"4) Change the system time significantly(by a month or a year) by using the OS abilities.",54"5) Click on the button once again.",55"6) Printed times should still be the same. Pay attention to the Month/Year if they were changed.",56"7) It is okay to observe a 1 or 2 seconds difference and this is not a fail.",57"8) If the difference is more then 1-2 seconds noticed then the test fail; otherwise pass."58};59Sysout.createDialogWithInstructions( instructions );6061}//End init()6263public void start ()64{65Button b = new Button("Press me");66b.addMouseListener(new MouseAdapter(){67public void mousePressed(MouseEvent e){68Sysout.println("Event occured : "+e);69Sysout.println("The event time is : "+ (new Date(e.getWhen())));70Sysout.println("The system time is : "+ (new Date()));71}72});73add(b);74setSize (200,200);75setVisible(true);76validate();77}// start()78}// class UpdatingBootTime7980/* Place other classes related to the test after this line */818283848586/****************************************************87Standard Test Machinery88DO NOT modify anything below -- it's a standard89chunk of code whose purpose is to make user90interaction uniform, and thereby make it simpler91to read and understand someone else's test.92****************************************************/9394/**95This is part of the standard test machinery.96It creates a dialog (with the instructions), and is the interface97for sending text messages to the user.98To print the instructions, send an array of strings to Sysout.createDialog99WithInstructions method. Put one line of instructions per array entry.100To display a message for the tester to see, simply call Sysout.println101with the string to be displayed.102This mimics System.out.println but works within the test harness as well103as standalone.104*/105106class Sysout107{108private static TestDialog dialog;109110public static void createDialogWithInstructions( String[] instructions )111{112dialog = new TestDialog( new Frame(), "Instructions" );113dialog.printInstructions( instructions );114dialog.setVisible(true);115println( "Any messages for the tester will display here." );116}117118public static void createDialog( )119{120dialog = new TestDialog( new Frame(), "Instructions" );121String[] defInstr = { "Instructions will appear here. ", "" } ;122dialog.printInstructions( defInstr );123dialog.setVisible(true);124println( "Any messages for the tester will display here." );125}126127128public static void printInstructions( String[] instructions )129{130dialog.printInstructions( instructions );131}132133134public static void println( String messageIn )135{136dialog.displayMessage( messageIn );137}138139}// Sysout class140141/**142This is part of the standard test machinery. It provides a place for the143test instructions to be displayed, and a place for interactive messages144to the user to be displayed.145To have the test instructions displayed, see Sysout.146To have a message to the user be displayed, see Sysout.147Do not call anything in this dialog directly.148*/149class TestDialog extends Dialog150{151152TextArea instructionsText;153TextArea messageText;154int maxStringLength = 80;155156//DO NOT call this directly, go through Sysout157public TestDialog( Frame frame, String name )158{159super( frame, name );160int scrollBoth = TextArea.SCROLLBARS_BOTH;161instructionsText = new TextArea( "", 15, maxStringLength, scrollBoth );162add( "North", instructionsText );163164messageText = new TextArea( "", 5, maxStringLength, scrollBoth );165add("Center", messageText);166167pack();168169setVisible(true);170}// TestDialog()171172//DO NOT call this directly, go through Sysout173public void printInstructions( String[] instructions )174{175//Clear out any current instructions176instructionsText.setText( "" );177178//Go down array of instruction strings179180String printStr, remainingStr;181for( int i=0; i < instructions.length; i++ )182{183//chop up each into pieces maxSringLength long184remainingStr = instructions[ i ];185while( remainingStr.length() > 0 )186{187//if longer than max then chop off first max chars to print188if( remainingStr.length() >= maxStringLength )189{190//Try to chop on a word boundary191int posOfSpace = remainingStr.192lastIndexOf( ' ', maxStringLength - 1 );193194if( posOfSpace <= 0 ) posOfSpace = maxStringLength - 1;195196printStr = remainingStr.substring( 0, posOfSpace + 1 );197remainingStr = remainingStr.substring( posOfSpace + 1 );198}199//else just print200else201{202printStr = remainingStr;203remainingStr = "";204}205206instructionsText.append( printStr + "\n" );207208}// while209210}// for211212}//printInstructions()213214//DO NOT call this directly, go through Sysout215public void displayMessage( String messageIn )216{217messageText.append( messageIn + "\n" );218System.out.println(messageIn);219}220221}// TestDialog class222223224