mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-01 06:05:24 +02:00
Add test case for editing in new file
This commit is contained in:
parent
c438a17939
commit
6b196a807d
1 changed files with 119 additions and 2 deletions
|
@ -81,8 +81,8 @@ public class BasicCEditorTest extends BaseUITestCase {
|
|||
super.tearDown();
|
||||
}
|
||||
|
||||
private void setUpEditor(String file) throws PartInitException {
|
||||
IEditorPart editor= EditorTestHelper.openInEditor(ResourceTestHelper.findFile(file), true);
|
||||
private void setUpEditor(IFile file) throws PartInitException {
|
||||
IEditorPart editor= EditorTestHelper.openInEditor(file, true);
|
||||
assertNotNull(editor);
|
||||
assertTrue(editor instanceof CEditor);
|
||||
fEditor= (CEditor) editor;
|
||||
|
@ -93,6 +93,10 @@ public class BasicCEditorTest extends BaseUITestCase {
|
|||
assertNotNull(fDocument);
|
||||
}
|
||||
|
||||
private void setUpEditor(String file) throws PartInitException {
|
||||
setUpEditor(ResourceTestHelper.findFile(file));
|
||||
}
|
||||
|
||||
private void setUpEditor(File file) throws PartInitException, CModelException {
|
||||
IEditorPart editor= EditorUtility.openInEditor(new ExternalTranslationUnit(fCProject, Path.fromOSString(file.toString()), CCorePlugin.CONTENT_TYPE_CXXSOURCE));
|
||||
assertNotNull(editor);
|
||||
|
@ -105,6 +109,119 @@ public class BasicCEditorTest extends BaseUITestCase {
|
|||
assertNotNull(fDocument);
|
||||
}
|
||||
|
||||
public void testEditTranslationUnit() throws Exception {
|
||||
final String file= "/ceditor/src/main.cpp";
|
||||
fCProject= EditorTestHelper.createCProject("ceditor", "resources/ceditor", false);
|
||||
IFile mainFile= ResourceTestHelper.findFile(file);
|
||||
assertNotNull(mainFile);
|
||||
setUpEditor(mainFile);
|
||||
fSourceViewer= EditorTestHelper.getSourceViewer(fEditor);
|
||||
assertTrue(EditorTestHelper.joinReconciler(fSourceViewer, 0, 10000, 100));
|
||||
String content= fDocument.get();
|
||||
setCaret(0);
|
||||
String newtext= "/* "+getName()+" */";
|
||||
type(newtext);
|
||||
type('\n');
|
||||
String newContent= fDocument.get();
|
||||
assertEquals("Edit failed", newtext, newContent.substring(0, newtext.length()));
|
||||
// save
|
||||
fEditor.doSave(new NullProgressMonitor());
|
||||
assertFalse("Editor is still dirty", fEditor.isDirty());
|
||||
// close and reopen
|
||||
EditorTestHelper.closeEditor(fEditor);
|
||||
setUpEditor(mainFile);
|
||||
fSourceViewer= EditorTestHelper.getSourceViewer(fEditor);
|
||||
assertTrue(EditorTestHelper.joinReconciler(fSourceViewer, 0, 10000, 100));
|
||||
content= fDocument.get();
|
||||
assertEquals("Save failed", newContent, content);
|
||||
// check reconciler
|
||||
ITranslationUnit tUnit= (ITranslationUnit)fEditor.getInputCElement();
|
||||
ICElement[] children= tUnit.getChildren();
|
||||
assertEquals(2, children.length);
|
||||
setCaret(content.length());
|
||||
type('\n');
|
||||
type("void func() {}\n");
|
||||
assertTrue(EditorTestHelper.joinReconciler(fSourceViewer, 0, 10000, 100));
|
||||
children= tUnit.getChildren();
|
||||
assertEquals(3, children.length);
|
||||
}
|
||||
//{Point.cpp}
|
||||
//#include <math.h>
|
||||
//class Point {
|
||||
//public:
|
||||
// Point(double xc, double yc) :
|
||||
// x(xc), y(yc) {}
|
||||
// double distance(const Point& other) const;
|
||||
// int compareX(const Point& other) const;
|
||||
// double x;
|
||||
// double y;
|
||||
//};
|
||||
//double Point::distance(const Point& other) const {
|
||||
// double dx = x - other.x;
|
||||
// double dy = y - other.y;
|
||||
// return sqrt(dx * dx + dy * dy);
|
||||
//}
|
||||
//int Point::compareX(const Point& other) const {
|
||||
// if (x < other.x) {
|
||||
// return -1;
|
||||
// }
|
||||
// else if (x > other.x) {
|
||||
// return 1;
|
||||
// }
|
||||
// else {
|
||||
// return 0;
|
||||
// }
|
||||
//}
|
||||
public void testEditNewTranslationUnit() throws Exception {
|
||||
fCProject= EditorTestHelper.createCProject("ceditor", "resources/ceditor", false);
|
||||
IFile newFile= createFile(fCProject.getProject(), "Point.cpp", "");
|
||||
assertNotNull(newFile);
|
||||
setUpEditor(newFile);
|
||||
fSourceViewer= EditorTestHelper.getSourceViewer(fEditor);
|
||||
assertTrue(EditorTestHelper.joinReconciler(fSourceViewer, 0, 10000, 100));
|
||||
String content= fDocument.get();
|
||||
setCaret(0);
|
||||
String newText= "/* "+getName()+" */\n";
|
||||
newText += readTaggedComment("Point.cpp");
|
||||
String[] lines= newText.split("\\r\\n|\\r|\\n");
|
||||
for (int i = 0; i < lines.length; i++) {
|
||||
String line= lines[i].trim();
|
||||
if (line.startsWith("}")) {
|
||||
setCaret(fDocument.get().indexOf(line, getCaret())+line.length());
|
||||
Thread.sleep(500);
|
||||
} else {
|
||||
if (i > 0) type('\n');
|
||||
type(line);
|
||||
Thread.sleep(200);
|
||||
}
|
||||
}
|
||||
String newContent= fDocument.get();
|
||||
String[] newLines= newContent.split("\\r\\n|\\r|\\n");
|
||||
for (int i = 0; i < lines.length; i++) {
|
||||
String line= lines[i].trim();
|
||||
assertEquals(line, newLines[i].trim());
|
||||
}
|
||||
// save
|
||||
fEditor.doSave(new NullProgressMonitor());
|
||||
assertFalse("Editor is still dirty", fEditor.isDirty());
|
||||
// close and reopen
|
||||
EditorTestHelper.closeEditor(fEditor);
|
||||
setUpEditor(newFile);
|
||||
fSourceViewer= EditorTestHelper.getSourceViewer(fEditor);
|
||||
assertTrue(EditorTestHelper.joinReconciler(fSourceViewer, 0, 10000, 100));
|
||||
content= fDocument.get();
|
||||
assertEquals("Save failed", newContent, content);
|
||||
// check reconciler
|
||||
ITranslationUnit tUnit= (ITranslationUnit)fEditor.getInputCElement();
|
||||
ICElement[] children= tUnit.getChildren();
|
||||
assertEquals(4, children.length);
|
||||
setCaret(content.length());
|
||||
type('\n');
|
||||
type("void func() {}\n");
|
||||
assertTrue(EditorTestHelper.joinReconciler(fSourceViewer, 0, 10000, 100));
|
||||
children= tUnit.getChildren();
|
||||
assertEquals(5, children.length);
|
||||
}
|
||||
public void testEditInNonCProject() throws Exception {
|
||||
final String file= "/ceditor/src/main.cpp";
|
||||
fNonCProject= EditorTestHelper.createNonCProject("ceditor", "resources/ceditor", false);
|
||||
|
|
Loading…
Add table
Reference in a new issue