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