mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-09-03 21:53:39 +02:00
Make editing tests faster
This commit is contained in:
parent
b58ed032fb
commit
8c172d53d7
1 changed files with 24 additions and 7 deletions
|
@ -20,7 +20,9 @@ import org.eclipse.core.resources.IFile;
|
||||||
import org.eclipse.core.resources.IProject;
|
import org.eclipse.core.resources.IProject;
|
||||||
import org.eclipse.core.runtime.NullProgressMonitor;
|
import org.eclipse.core.runtime.NullProgressMonitor;
|
||||||
import org.eclipse.core.runtime.Path;
|
import org.eclipse.core.runtime.Path;
|
||||||
|
import org.eclipse.jface.text.DocumentEvent;
|
||||||
import org.eclipse.jface.text.IDocument;
|
import org.eclipse.jface.text.IDocument;
|
||||||
|
import org.eclipse.jface.text.IDocumentListener;
|
||||||
import org.eclipse.jface.text.ITextSelection;
|
import org.eclipse.jface.text.ITextSelection;
|
||||||
import org.eclipse.jface.text.TextSelection;
|
import org.eclipse.jface.text.TextSelection;
|
||||||
import org.eclipse.jface.text.source.SourceViewer;
|
import org.eclipse.jface.text.source.SourceViewer;
|
||||||
|
@ -55,6 +57,17 @@ import org.eclipse.cdt.internal.ui.util.EditorUtility;
|
||||||
*/
|
*/
|
||||||
public class BasicCEditorTest extends BaseUITestCase {
|
public class BasicCEditorTest extends BaseUITestCase {
|
||||||
|
|
||||||
|
final static class TestDocListener implements IDocumentListener {
|
||||||
|
public boolean fDocChanged;
|
||||||
|
|
||||||
|
public void documentAboutToBeChanged(DocumentEvent event) {
|
||||||
|
}
|
||||||
|
|
||||||
|
public void documentChanged(DocumentEvent event) {
|
||||||
|
fDocChanged= true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static CEditor fEditor;
|
private static CEditor fEditor;
|
||||||
private static SourceViewer fSourceViewer;
|
private static SourceViewer fSourceViewer;
|
||||||
private ICProject fCProject;
|
private ICProject fCProject;
|
||||||
|
@ -62,6 +75,7 @@ public class BasicCEditorTest extends BaseUITestCase {
|
||||||
private StyledText fTextWidget;
|
private StyledText fTextWidget;
|
||||||
private Accessor fAccessor;
|
private Accessor fAccessor;
|
||||||
private IDocument fDocument;
|
private IDocument fDocument;
|
||||||
|
private TestDocListener fDocListener= new TestDocListener();
|
||||||
|
|
||||||
public static Test suite() {
|
public static Test suite() {
|
||||||
return new TestSuite(BasicCEditorTest.class);
|
return new TestSuite(BasicCEditorTest.class);
|
||||||
|
@ -165,10 +179,10 @@ public class BasicCEditorTest extends BaseUITestCase {
|
||||||
// if (x < other.x) {
|
// if (x < other.x) {
|
||||||
// return -1;
|
// return -1;
|
||||||
// }
|
// }
|
||||||
// else if (x > other.x) {
|
// else if (x > other.x) {
|
||||||
// return 1;
|
// return 1;
|
||||||
// }
|
// }
|
||||||
// else {
|
// else {
|
||||||
// return 0;
|
// return 0;
|
||||||
// }
|
// }
|
||||||
//}
|
//}
|
||||||
|
@ -188,18 +202,18 @@ public class BasicCEditorTest extends BaseUITestCase {
|
||||||
String line= lines[i].trim();
|
String line= lines[i].trim();
|
||||||
if (line.startsWith("}")) {
|
if (line.startsWith("}")) {
|
||||||
setCaret(fDocument.get().indexOf(line, getCaret())+line.length());
|
setCaret(fDocument.get().indexOf(line, getCaret())+line.length());
|
||||||
Thread.sleep(500);
|
Thread.sleep(100);
|
||||||
} else {
|
} else {
|
||||||
if (i > 0) type('\n');
|
if (i > 0) type('\n');
|
||||||
type(line);
|
type(line);
|
||||||
Thread.sleep(200);
|
Thread.sleep(50);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
String newContent= fDocument.get();
|
String newContent= fDocument.get();
|
||||||
String[] newLines= newContent.split("\\r\\n|\\r|\\n");
|
String[] newLines= newContent.split("\\r\\n|\\r|\\n");
|
||||||
for (int i = 0; i < lines.length; i++) {
|
for (int i = 0; i < lines.length; i++) {
|
||||||
String line= lines[i].trim();
|
String line= lines[i];
|
||||||
assertEquals(line, newLines[i].trim());
|
assertEquals(line, newLines[i]);
|
||||||
}
|
}
|
||||||
// save
|
// save
|
||||||
fEditor.doSave(new NullProgressMonitor());
|
fEditor.doSave(new NullProgressMonitor());
|
||||||
|
@ -330,6 +344,8 @@ public class BasicCEditorTest extends BaseUITestCase {
|
||||||
* @param stateMask the state mask
|
* @param stateMask the state mask
|
||||||
*/
|
*/
|
||||||
private void type(char character, int keyCode, int stateMask) {
|
private void type(char character, int keyCode, int stateMask) {
|
||||||
|
fDocument.addDocumentListener(fDocListener);
|
||||||
|
fDocListener.fDocChanged= false;
|
||||||
Event event= new Event();
|
Event event= new Event();
|
||||||
event.character= character;
|
event.character= character;
|
||||||
event.keyCode= keyCode;
|
event.keyCode= keyCode;
|
||||||
|
@ -338,9 +354,10 @@ public class BasicCEditorTest extends BaseUITestCase {
|
||||||
|
|
||||||
new DisplayHelper() {
|
new DisplayHelper() {
|
||||||
protected boolean condition() {
|
protected boolean condition() {
|
||||||
return false;
|
return fDocListener.fDocChanged;
|
||||||
}
|
}
|
||||||
}.waitForCondition(EditorTestHelper.getActiveDisplay(), 50);
|
}.waitForCondition(EditorTestHelper.getActiveDisplay(), 50);
|
||||||
|
fDocument.removeDocumentListener(fDocListener);
|
||||||
}
|
}
|
||||||
|
|
||||||
private int getCaret() {
|
private int getCaret() {
|
||||||
|
|
Loading…
Add table
Reference in a new issue