use of org.eclipse.core.filebuffers.ITextFileBuffer in project eclipse.platform.text by eclipse.
the class FileBufferCreation method test3_1.
/*
* Tests the creation of a file buffer for a linked file.
*/
@Test
public void test3_1() throws Exception {
IPath path = createLinkedFile("file", "testResources/LinkedFileTarget");
assertNotNull(path);
ITextFileBufferManager manager = FileBuffers.getTextFileBufferManager();
manager.connect(path, LocationKind.NORMALIZE, null);
ITextFileBuffer buffer = manager.getTextFileBuffer(path, LocationKind.NORMALIZE);
Assert.assertNotNull(buffer);
IDocument document = buffer.getDocument();
Assert.assertNotNull(document);
Assert.assertTrue(CONTENT2.equals(document.get()));
assertSame(buffer, manager.getTextFileBuffer(document));
manager.disconnect(path, LocationKind.NORMALIZE, null);
assertNull(manager.getTextFileBuffer(path, LocationKind.NORMALIZE));
}
use of org.eclipse.core.filebuffers.ITextFileBuffer in project eclipse.platform.text by eclipse.
the class FileBufferCreation method test4_IFILE.
/*
* Tests that two different files linked to the same target file result
* in two different, independent file buffers.
*/
@Test
public void test4_IFILE() throws Exception {
IPath path1 = createLinkedFile("file1", "testResources/LinkedFileTarget");
assertNotNull(path1);
IPath path2 = createLinkedFile("file2", "testResources/LinkedFileTarget");
assertNotNull(path2);
ITextFileBufferManager manager = FileBuffers.getTextFileBufferManager();
manager.connect(path1, LocationKind.IFILE, null);
ITextFileBuffer buffer1 = manager.getTextFileBuffer(path1, LocationKind.IFILE);
assertNotNull(buffer1);
manager.connect(path2, LocationKind.IFILE, null);
ITextFileBuffer buffer2 = manager.getTextFileBuffer(path2, LocationKind.IFILE);
assertNotNull(buffer2);
IDocument document1 = buffer1.getDocument();
assertNotNull(document1);
assertSame(buffer1, manager.getTextFileBuffer(document1));
IDocument document2 = buffer2.getDocument();
assertNotNull(document2);
assertSame(buffer2, manager.getTextFileBuffer(document2));
assertEquals(document1.get(), document2.get());
assertEquals(CONTENT2, document1.get());
try {
document1.replace(0, document1.getLength(), CONTENT1);
} catch (BadLocationException x) {
Assert.assertFalse(false);
}
assertFalse(document1.get().equals(document2.get()));
manager.disconnect(path1, LocationKind.IFILE, null);
assertNull(manager.getTextFileBuffer(path1, LocationKind.IFILE));
assertNotNull(manager.getTextFileBuffer(path2, LocationKind.IFILE));
manager.disconnect(path2, LocationKind.IFILE, null);
assertNull(manager.getTextFileBuffer(path2, LocationKind.IFILE));
}
use of org.eclipse.core.filebuffers.ITextFileBuffer in project eclipse.platform.text by eclipse.
the class FileBufferCreation method test1_IFILE.
/*
* Tests the creation of file buffer for an existing file.
*/
@Test
public void test1_IFILE() throws Exception {
IFolder folder = ResourceHelper.createFolder("project/folderA/folderB/");
IFile file = ResourceHelper.createFile(folder, "file", CONTENT1);
IPath path = file.getFullPath();
assertNotNull(path);
ITextFileBufferManager manager = FileBuffers.getTextFileBufferManager();
manager.connect(path, LocationKind.IFILE, null);
ITextFileBuffer buffer = manager.getTextFileBuffer(path, LocationKind.IFILE);
assertNotNull(buffer);
IDocument document = buffer.getDocument();
assertNotNull(document);
assertEquals(CONTENT1, document.get());
assertSame(buffer, manager.getTextFileBuffer(document));
manager.disconnect(path, LocationKind.IFILE, null);
assertNull(manager.getTextFileBuffer(path, LocationKind.IFILE));
}
use of org.eclipse.core.filebuffers.ITextFileBuffer in project eclipse.platform.text by eclipse.
the class FileBufferFunctions method test2.
/*
* Tests isSynchronized.
*/
@Test
public void test2() throws Exception {
fManager.connect(fPath, LocationKind.NORMALIZE, null);
try {
ITextFileBuffer fileBuffer = fManager.getTextFileBuffer(fPath, LocationKind.NORMALIZE);
assertTrue(fileBuffer.isSynchronized());
IFileStore fileStore = FileBuffers.getFileStoreAtLocation(fPath);
IFileInfo fileInfo = fileStore.fetchInfo();
fileInfo.setLastModified(1000);
if (fileInfo.exists())
fileStore.putInfo(fileInfo, EFS.SET_LAST_MODIFIED, null);
long lastModified = fileStore.fetchInfo().getLastModified();
assertTrue(lastModified == EFS.NONE || !fileBuffer.isSynchronized());
} finally {
fManager.disconnect(fPath, LocationKind.NORMALIZE, null);
}
}
use of org.eclipse.core.filebuffers.ITextFileBuffer in project eclipse.platform.text by eclipse.
the class FileBufferFunctions method test12_1.
/*
* Test IFileBufferListener#bufferContentAboutToBeReplaced/replaced
*/
@Test
public void test12_1() throws Exception {
class Listener extends FileBufferListener {
public IFileBuffer preBuffer, postBuffer;
public int preCount, postCount;
@Override
public void bufferContentAboutToBeReplaced(IFileBuffer buffer) {
++preCount;
preBuffer = buffer;
}
@Override
public void bufferContentReplaced(IFileBuffer buffer) {
++postCount;
postBuffer = buffer;
}
}
Listener listener = new Listener();
fManager.addFileBufferListener(listener);
try {
ITextFileBuffer fileBuffer = fManager.getTextFileBuffer(fPath, LocationKind.NORMALIZE);
assertTrue(listener.preCount == 0 && listener.postCount == 0 && listener.preBuffer == null && listener.postBuffer == null);
fManager.connect(fPath, LocationKind.NORMALIZE, null);
try {
fileBuffer = fManager.getTextFileBuffer(fPath, LocationKind.NORMALIZE);
IDocument document = fileBuffer.getDocument();
document.replace(0, 0, "prefix");
fileBuffer.revert(null);
assertTrue(listener.preCount == 1);
assertTrue(listener.preBuffer == fileBuffer);
assertTrue(listener.postCount == 1);
assertTrue(listener.postBuffer == fileBuffer);
} finally {
fManager.disconnect(fPath, LocationKind.NORMALIZE, null);
}
} finally {
fManager.removeFileBufferListener(listener);
}
}
Aggregations