< prev index next >

test/java/awt/TextArea/TextAreaEditing/TextAreaEditing.java

Print this page




   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  */
  23 
  24 /*
  25  @test
  26  @bug 8040322


  27  @summary Test TextArea APIs replaceRange, insert, append & setText
  28  @run main TextAreaEditing
  29  */
  30 
  31 import java.awt.Frame;

  32 import java.awt.TextArea;



  33 
  34 public class TextAreaEditing {
  35 

  36     private int testFailCount;
  37     private boolean isTestFail;
  38     private StringBuilder testFailMessage;
  39 
  40     private Frame mainFrame;
  41     private TextArea textArea;
  42 
  43     private TextAreaEditing() {
  44         testFailMessage = new StringBuilder();
  45         mainFrame = new Frame();
  46         mainFrame.setSize(200, 200);
  47 
  48         textArea = new TextArea();
  49         mainFrame.add(textArea);
  50         mainFrame.setVisible(true);
  51     }
  52 
  53     private void dispose() {
  54         if (mainFrame != null) {
  55             mainFrame.dispose();
  56         }
  57     }
  58 
  59     public static void main(String[] s) {
  60         TextAreaEditing textArea = new TextAreaEditing();
  61         textArea.testReplaceRange();
  62         textArea.testInsert();
  63         textArea.testAppend();

  64         textArea.checkFailures();
  65         textArea.dispose();
  66     }
  67 
  68     private void testReplaceRange() {
  69         textArea.setText(null);
  70         textArea.replaceRange("Replace", 0, 0);
  71         textArea.setText(null);
  72         checkTest("");
  73 
  74         textArea.setText("SetText");
  75         textArea.replaceRange("Replace", 0, 3);
  76         checkTest("ReplaceText");
  77 
  78         textArea.replaceRange("String", textArea.getText().length(),
  79                 textArea.getText().length());
  80         checkTest("ReplaceTextString");
  81 
  82         textArea.replaceRange("String", 0, 0);
  83         checkTest("StringReplaceTextString");


  99         textArea.insert("Insert", 0);
 100         checkTest("InsertSetInsertText");
 101 
 102         textArea.insert("Insert", textArea.getText().length());
 103         checkTest("InsertSetInsertTextInsert");
 104     }
 105 
 106     private void testAppend() {
 107         textArea.setText(null);
 108         textArea.append("Append");
 109         textArea.setText(null);
 110         checkTest("");
 111 
 112         textArea.setText("SetText");
 113         textArea.append("Append");
 114         checkTest("SetTextAppend");
 115 
 116         textArea.append("");
 117         checkTest("SetTextAppend");
 118         textArea.setText("");














 119         checkTest("");
 120     }
 121 
 122     private void checkTest(String str) {
 123         if (str != null && !str.equals(textArea.getText())) {
 124             testFailMessage.append("TestFail line : ");
 125             testFailMessage.append(Thread.currentThread().getStackTrace()[2].
 126                     getLineNumber());
 127             testFailMessage.append(" TextArea string : \"");
 128             testFailMessage.append(textArea.getText());
 129             testFailMessage.append("\" does not match expected string : \"");
 130             testFailMessage.append(str).append("\"");
 131             testFailMessage.append(System.getProperty("line.separator"));
 132             testFailCount++;
 133             isTestFail = true;
 134         }
 135     }
 136 
 137     private void checkFailures() {
 138         if (isTestFail) {


   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  */
  23 
  24 /*
  25  @test
  26  @bug 8040322 8060137
  27  @library ../../regtesthelpers
  28  @build Util
  29  @summary Test TextArea APIs replaceRange, insert, append & setText
  30  @run main TextAreaEditing
  31  */
  32 
  33 import java.awt.Frame;
  34 import java.awt.Robot;
  35 import java.awt.TextArea;
  36 import java.awt.AWTException;
  37 import java.awt.event.KeyEvent;
  38 import test.java.awt.regtesthelpers.Util;
  39 
  40 public class TextAreaEditing {
  41 
  42     final static Robot robot = Util.createRobot();
  43     private int testFailCount;
  44     private boolean isTestFail;
  45     private StringBuilder testFailMessage;
  46 
  47     private Frame mainFrame;
  48     private TextArea textArea;
  49 
  50     private TextAreaEditing() {
  51         testFailMessage = new StringBuilder();
  52         mainFrame = new Frame();
  53         mainFrame.setSize(200, 200);
  54 
  55         textArea = new TextArea();
  56         mainFrame.add(textArea);
  57         mainFrame.setVisible(true);
  58     }
  59 
  60     private void dispose() {
  61         if (mainFrame != null) {
  62             mainFrame.dispose();
  63         }
  64     }
  65 
  66     public static void main(String[] s) {
  67         TextAreaEditing textArea = new TextAreaEditing();
  68         textArea.testReplaceRange();
  69         textArea.testInsert();
  70         textArea.testAppend();
  71         textArea.testSetText();
  72         textArea.checkFailures();
  73         textArea.dispose();
  74     }
  75 
  76     private void testReplaceRange() {
  77         textArea.setText(null);
  78         textArea.replaceRange("Replace", 0, 0);
  79         textArea.setText(null);
  80         checkTest("");
  81 
  82         textArea.setText("SetText");
  83         textArea.replaceRange("Replace", 0, 3);
  84         checkTest("ReplaceText");
  85 
  86         textArea.replaceRange("String", textArea.getText().length(),
  87                 textArea.getText().length());
  88         checkTest("ReplaceTextString");
  89 
  90         textArea.replaceRange("String", 0, 0);
  91         checkTest("StringReplaceTextString");


 107         textArea.insert("Insert", 0);
 108         checkTest("InsertSetInsertText");
 109 
 110         textArea.insert("Insert", textArea.getText().length());
 111         checkTest("InsertSetInsertTextInsert");
 112     }
 113 
 114     private void testAppend() {
 115         textArea.setText(null);
 116         textArea.append("Append");
 117         textArea.setText(null);
 118         checkTest("");
 119 
 120         textArea.setText("SetText");
 121         textArea.append("Append");
 122         checkTest("SetTextAppend");
 123 
 124         textArea.append("");
 125         checkTest("SetTextAppend");
 126         textArea.setText("");
 127         checkTest("");
 128     }
 129 
 130     // 8060137
 131     private void testSetText() {
 132         textArea.setText(null);
 133         textArea.requestFocus();
 134         Util.clickOnComp(textArea, robot);
 135         Util.waitForIdle(robot);
 136         robot.keyPress(KeyEvent.VK_A);
 137         robot.delay(5);
 138         robot.keyRelease(KeyEvent.VK_A);
 139         Util.waitForIdle(robot);
 140         textArea.setText(null);
 141         checkTest("");
 142     }
 143 
 144     private void checkTest(String str) {
 145         if (str != null && !str.equals(textArea.getText())) {
 146             testFailMessage.append("TestFail line : ");
 147             testFailMessage.append(Thread.currentThread().getStackTrace()[2].
 148                     getLineNumber());
 149             testFailMessage.append(" TextArea string : \"");
 150             testFailMessage.append(textArea.getText());
 151             testFailMessage.append("\" does not match expected string : \"");
 152             testFailMessage.append(str).append("\"");
 153             testFailMessage.append(System.getProperty("line.separator"));
 154             testFailCount++;
 155             isTestFail = true;
 156         }
 157     }
 158 
 159     private void checkFailures() {
 160         if (isTestFail) {
< prev index next >