1 19 20 package org.netbeans.test.web.core.syntax; 21 22 import java.awt.event.KeyEvent ; 23 import java.io.File ; 24 import javax.swing.JEditorPane ; 25 import javax.swing.text.Caret ; 26 import junit.framework.Test; 27 import org.netbeans.editor.Utilities; 28 import org.netbeans.jellytools.EditorOperator; 29 import org.netbeans.editor.BaseDocument; 30 import org.netbeans.test.web.FileObjectFilter; 31 import org.netbeans.test.web.RecurrentSuiteFactory; 32 import org.openide.actions.UndoAction; 33 import org.openide.filesystems.FileObject; 34 import org.openide.util.actions.SystemAction; 35 36 40 public class WritingCompletionTest extends CompletionTest { 41 42 43 public WritingCompletionTest(String name, FileObject testFileObj) { 44 super(name, testFileObj); 45 debug = false; 46 } 47 48 public static Test suite() { 49 File datadir = new AutoCompletionTest(null, null).getDataDir(); 51 File projectsDir = new File (datadir, "WritingCompletionTestProjects"); 52 FileObjectFilter filter = new FileObjectFilter() { 53 public boolean accept(FileObject fo) { 54 String ext = fo.getExt(); 55 String name = fo.getName(); 56 return (name.startsWith("test") || name.startsWith("Test")) 57 && (xmlExts.contains(ext) || jspExts.contains(ext) || ext.equals("java")); 58 } 59 }; 60 return RecurrentSuiteFactory.createSuite(WritingCompletionTest.class, projectsDir, filter); 61 } 62 63 64 protected void exec(final JEditorPane editor, TestStep step) throws Exception { 65 boolean ccError = false; 66 try { 67 ref(step.toString()); 68 BaseDocument doc = (BaseDocument) editor.getDocument(); 69 doc.insertString(step.getOffset(), "\n" + step.getPrefix(), null); 71 Caret caret = editor.getCaret(); 72 caret.setDot(step.getCursorPos()); 73 Thread.currentThread().sleep(1000); 74 75 EditorOperator eo = new EditorOperator(testFileObj.getNameExt()); 76 eo.txtEditorPane().pushKey(KeyEvent.VK_SPACE, KeyEvent.CTRL_MASK); 77 Thread.currentThread().sleep(1000); 78 eo.txtEditorPane().typeKey('a'); 79 Thread.currentThread().sleep(100); 80 eo.txtEditorPane().pushKey(KeyEvent.VK_SPACE, KeyEvent.CTRL_MASK); 83 Thread.currentThread().sleep(500); 84 int rowStart = Utilities.getRowStart(doc, step.getOffset() + 1); 85 int rowEnd = Utilities.getRowEnd(doc, step.getOffset() + 1); 86 String result = doc.getText(new int[] {rowStart, rowEnd}); 87 if (!result.equals(step.getResult())) { 88 ref("EE: unexpected CC result:\n< " + result + "\n> " 89 + step.getResult()); 90 } 91 int caretPos = caret.getDot()-step.getCursorPos(); 92 ref("End cursor position = " + caretPos); 93 } finally { 94 Thread.currentThread().sleep(500); final UndoAction ua = (UndoAction)SystemAction.get(UndoAction.class); 97 assertNotNull("Cannot obtain UndoAction", ua); 98 while (ua.isEnabled()) { 99 runInAWT(new Runnable () { 100 public void run() { 101 ua.performAction(); 102 } 103 }); 104 Thread.currentThread().sleep(50); } 106 Thread.currentThread().sleep(500); 107 } 108 109 } 110 111 } 112 | Popular Tags |