1 /*
2 * Copyright (c) 2007, 2016, Oracle and/or its affiliates. All rights reserved.
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 *
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.
22 */
106 case 2:
107 testToplevel = toplevel;
108 Util.clickOnComp(showButton, robot);
109 break;
110 }
111 Util.waitForIdle(robot);
112
113 if (!Util.trackActionPerformed(testButton, action, 2000, false)) {
114 throw new TestFailedException("Stage " + stage + ". The toplevel " + toplevel + " wasn't made foreground on showing");
115 }
116 System.out.println("Stage " + stage + ". Toplevel " + toplevel + " - passed");
117 toplevel.dispose();
118 }
119 }
120
121 class TestFailedException extends RuntimeException {
122 TestFailedException(String msg) {
123 super("Test failed: " + msg);
124 }
125 }
126
127 /****************************************************
128 * Standard Test Machinery
129 * DO NOT modify anything below -- it's a standard
130 * chunk of code whose purpose is to make user
131 * interaction uniform, and thereby make it simpler
132 * to read and understand someone else's test.
133 ****************************************************/
134
135 /**
136 * This is part of the standard test machinery.
137 * It creates a dialog (with the instructions), and is the interface
138 * for sending text messages to the user.
139 * To print the instructions, send an array of strings to Sysout.createDialog
140 * WithInstructions method. Put one line of instructions per array entry.
141 * To display a message for the tester to see, simply call Sysout.println
142 * with the string to be displayed.
143 * This mimics System.out.println but works within the test harness as well
144 * as standalone.
145 */
146
147 class Sysout {
148 static TestDialog dialog;
149
150 public static void createDialogWithInstructions( String[] instructions ) {
151 dialog = new TestDialog( new Frame(), "Instructions" );
152 dialog.printInstructions( instructions );
153 dialog.setVisible(true);
154 println( "Any messages for the tester will display here." );
155 }
156
157 public static void createDialog( ) {
158 dialog = new TestDialog( new Frame(), "Instructions" );
159 String[] defInstr = { "Instructions will appear here. ", "" } ;
160 dialog.printInstructions( defInstr );
161 dialog.setVisible(true);
162 println( "Any messages for the tester will display here." );
163 }
164
165
166 public static void printInstructions( String[] instructions ) {
167 dialog.printInstructions( instructions );
168 }
169
170
171 public static void println( String messageIn ) {
172 dialog.displayMessage( messageIn );
173 }
174
175 }// Sysout class
176
177 /**
178 * This is part of the standard test machinery. It provides a place for the
179 * test instructions to be displayed, and a place for interactive messages
180 * to the user to be displayed.
181 * To have the test instructions displayed, see Sysout.
182 * To have a message to the user be displayed, see Sysout.
183 * Do not call anything in this dialog directly.
184 */
185 class TestDialog extends Dialog {
186
187 TextArea instructionsText;
188 TextArea messageText;
189 int maxStringLength = 80;
190
191 //DO NOT call this directly, go through Sysout
192 public TestDialog( Frame frame, String name ) {
193 super( frame, name );
194 int scrollBoth = TextArea.SCROLLBARS_BOTH;
195 instructionsText = new TextArea( "", 15, maxStringLength, scrollBoth );
196 add( "North", instructionsText );
197
198 messageText = new TextArea( "", 5, maxStringLength, scrollBoth );
199 add("Center", messageText);
200
201 pack();
202
203 setVisible(true);
204 }// TestDialog()
205
206 //DO NOT call this directly, go through Sysout
207 public void printInstructions( String[] instructions ) {
208 //Clear out any current instructions
209 instructionsText.setText( "" );
210
211 //Go down array of instruction strings
212
213 String printStr, remainingStr;
214 for( int i=0; i < instructions.length; i++ ) {
215 //chop up each into pieces maxSringLength long
216 remainingStr = instructions[ i ];
217 while( remainingStr.length() > 0 ) {
218 //if longer than max then chop off first max chars to print
219 if( remainingStr.length() >= maxStringLength ) {
220 //Try to chop on a word boundary
221 int posOfSpace = remainingStr.
222 lastIndexOf( ' ', maxStringLength - 1 );
223
224 if( posOfSpace <= 0 ) posOfSpace = maxStringLength - 1;
225
226 printStr = remainingStr.substring( 0, posOfSpace + 1 );
227 remainingStr = remainingStr.substring( posOfSpace + 1 );
228 }
229 //else just print
230 else {
231 printStr = remainingStr;
232 remainingStr = "";
233 }
234
235 instructionsText.append( printStr + "\n" );
236
237 }// while
238
239 }// for
240
241 }//printInstructions()
242
243 //DO NOT call this directly, go through Sysout
244 public void displayMessage( String messageIn ) {
245 messageText.append( messageIn + "\n" );
246 System.out.println(messageIn);
247 }
248
249 }// TestDialog class
|
1 /*
2 * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved.
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 *
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.
22 */
106 case 2:
107 testToplevel = toplevel;
108 Util.clickOnComp(showButton, robot);
109 break;
110 }
111 Util.waitForIdle(robot);
112
113 if (!Util.trackActionPerformed(testButton, action, 2000, false)) {
114 throw new TestFailedException("Stage " + stage + ". The toplevel " + toplevel + " wasn't made foreground on showing");
115 }
116 System.out.println("Stage " + stage + ". Toplevel " + toplevel + " - passed");
117 toplevel.dispose();
118 }
119 }
120
121 class TestFailedException extends RuntimeException {
122 TestFailedException(String msg) {
123 super("Test failed: " + msg);
124 }
125 }
|