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