001: package abbot.editor.recorder;
002:
003: import javax.swing.JTextField;
004: import javax.swing.JLabel;
005: import javax.swing.JPanel;
006:
007: import junit.extensions.abbot.RepeatHelper;
008: import abbot.script.Resolver;
009: import abbot.tester.JTextComponentTester;
010:
011: /** Test recording of JTextComponent-specific events. */
012: public class JTextComponentRecorderTest extends
013: AbstractSemanticRecorderFixture {
014:
015: private JTextComponentTester tester;
016:
017: protected void setUp() throws Exception {
018: super .setUp();
019: tester = new JTextComponentTester();
020: }
021:
022: // FIXME select action failure on first run on Linux/1.4.2
023: public void testCaptureSelection() {
024: String text = "Select some text";
025: JTextField tf = new JTextField(text);
026: JPanel p = new JPanel();
027: p.add(tf);
028: p.add(new JLabel(getName()));
029: showFrame(p);
030: startRecording();
031: tester.actionSelectText(tf, 1, text.length() - 1);
032: assertStep("SelectText\\(.*,1," + (text.length() - 1) + "\\)");
033: tester.actionSelectText(tf, 0, 5);
034: assertStep("SelectText\\(.*,0,5\\)");
035: tester.actionSelectText(tf, 4, text.length());
036: assertStep("SelectText\\(.*,4," + text.length() + "\\)");
037: tester.actionSelectText(tf, 0, text.length());
038: assertStep("SelectText\\(.*,0," + text.length() + "\\)");
039: }
040:
041: public void testCaptureReverseSelection() {
042: String text = "Select me backwards";
043: JTextField tf = new JTextField(text);
044: JPanel p = new JPanel();
045: p.add(tf);
046: p.add(new JLabel(getName()));
047: showFrame(p);
048: startRecording();
049: tester.actionSelectText(tf, text.length() - 1, 1);
050: assertStep("SelectText\\(.*," + (text.length() - 1) + ",1\\)");
051: tester.actionSelectText(tf, 5, 0);
052: assertStep("SelectText\\(.*,5,0\\)");
053: tester.actionSelectText(tf, text.length(), 4);
054: assertStep("SelectText\\(.*," + text.length() + ",4\\)");
055: tester.actionSelectText(tf, text.length(), 0);
056: assertStep("SelectText\\(.*," + text.length() + ",0\\)");
057: }
058:
059: // FIXME NPE due to improper drag/drop recording on linux/1.4.2
060: public void testCaptureScrollingSelection() {
061: String text = "Select some text";
062: JTextField tf = new JTextField(text);
063: JPanel p = new JPanel();
064: p.add(tf);
065: p.add(new JLabel(getName()));
066: showFrame(p);
067: tester.actionSelectText(tf, 1, text.length() - 1);
068: startRecording();
069: tester.actionDrag(tf, 1, tf.getHeight() / 2);
070: tester.actionDrop(tf, tf.getWidth() + 100, tf.getHeight() / 2);
071: assertStep("SelectText\\(.*,0," + text.length() + "\\)");
072: }
073:
074: public void testCaptureSetCaretPosition() {
075: String text = "Set the caret position";
076: JTextField tf = new JTextField(text);
077: showFrame(tf);
078: startRecording();
079: tester.actionClick(tf, 0);
080: assertStep("Click\\(.*,0\\)");
081:
082: tester.actionClick(tf, text.length() - 1);
083: assertStep("Click\\(.*," + (text.length() - 1) + "\\)");
084:
085: tester.actionClick(tf, text.length() / 2);
086: assertStep("Click\\(.*," + (text.length() / 2) + "\\)");
087: }
088:
089: /** Create a new test case with the given name. */
090: public JTextComponentRecorderTest(String name) {
091: super (name);
092: }
093:
094: protected SemanticRecorder createSemanticRecorder(Resolver r) {
095: return new JTextComponentRecorder(r);
096: }
097:
098: public static void main(String[] args) {
099: RepeatHelper.runTests(args, JTextComponentRecorderTest.class);
100: }
101: }
|