use of org.eclipse.core.filebuffers.ITextFileBuffer in project eclipse.platform.text by eclipse.
the class FileBufferFunctions method test19.
/*
* Test notification in case of failing listener.
*/
@Test
public void test19() throws Exception {
class NotifiedListener extends FileBufferListener {
int notifyCount = 0;
@Override
public void bufferCreated(IFileBuffer buffer) {
notifyCount++;
}
@Override
public void bufferDisposed(IFileBuffer buffer) {
notifyCount++;
}
}
class ForcedException extends RuntimeException {
private static final long serialVersionUID = 1L;
@Override
public void printStackTrace(PrintStream s) {
s.println("!FORCED BY TEST: this entry is intentional");
}
@Override
public void printStackTrace(PrintWriter s) {
s.println("!FORCED BY TEST: this entry is intentional");
}
}
NotifiedListener notifyCounter1 = new NotifiedListener();
NotifiedListener notifyCounter2 = new NotifiedListener();
FileBufferListener failingListener = new FileBufferListener() {
@Override
public void bufferCreated(IFileBuffer buffer) {
throw new ForcedException();
}
@Override
public void bufferDisposed(IFileBuffer buffer) {
throw new ForcedException();
}
};
fManager.addFileBufferListener(notifyCounter1);
fManager.addFileBufferListener(failingListener);
fManager.addFileBufferListener(notifyCounter2);
fManager.connect(fPath, LocationKind.NORMALIZE, null);
try {
ITextFileBuffer buffer = fManager.getTextFileBuffer(fPath, LocationKind.NORMALIZE);
assertNotNull(buffer);
Class<IAnnotationModel> clazz = getAnnotationModelClass();
if (clazz != null) {
IAnnotationModel model = buffer.getAnnotationModel();
assertTrue(clazz.isInstance(model));
}
} finally {
fManager.disconnect(fPath, LocationKind.NORMALIZE, null);
fManager.removeFileBufferListener(notifyCounter1);
fManager.removeFileBufferListener(failingListener);
fManager.removeFileBufferListener(notifyCounter2);
}
assertEquals(2, notifyCounter1.notifyCount);
assertEquals(2, notifyCounter2.notifyCount);
}
use of org.eclipse.core.filebuffers.ITextFileBuffer in project eclipse.platform.text by eclipse.
the class FileBufferFunctions method test5.
/*
* Tests getModificationStamp.
*/
@Test
public void test5() throws Exception {
fManager.connect(fPath, LocationKind.NORMALIZE, null);
try {
ITextFileBuffer fileBuffer = fManager.getTextFileBuffer(fPath, LocationKind.NORMALIZE);
long modificationStamp = fileBuffer.getModificationStamp();
IFileStore fileStore = FileBuffers.getFileStoreAtLocation(fPath);
IFileInfo fileInfo = fileStore.fetchInfo();
assertEquals(modificationStamp != IDocumentExtension4.UNKNOWN_MODIFICATION_STAMP, fileInfo.exists());
fileInfo.setLastModified(1000);
if (fileInfo.exists())
fileStore.putInfo(fileInfo, EFS.SET_LAST_MODIFIED, null);
long lastModified = fileStore.fetchInfo().getLastModified();
assertTrue(lastModified == EFS.NONE || modificationStamp != fileBuffer.getModificationStamp());
} 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 test8_2.
/*
* Test validateState.
*/
@Test
public void test8_2() throws Exception {
fManager.connect(fPath, LocationKind.NORMALIZE, null);
try {
setReadOnly(true);
ITextFileBuffer fileBuffer = fManager.getTextFileBuffer(fPath, LocationKind.NORMALIZE);
fileBuffer.validateState(null, null);
assertTrue(fileBuffer.isStateValidated());
} finally {
setReadOnly(false);
fManager.disconnect(fPath, LocationKind.NORMALIZE, null);
}
}
use of org.eclipse.core.filebuffers.ITextFileBuffer in project eclipse.platform.text by eclipse.
the class FileBufferFunctions method test9_1.
/*
* Test resetStateValidation.
*/
@Test
public void test9_1() throws Exception {
fManager.connect(fPath, LocationKind.NORMALIZE, null);
try {
ITextFileBuffer fileBuffer = fManager.getTextFileBuffer(fPath, LocationKind.NORMALIZE);
fileBuffer.validateState(null, null);
fileBuffer.resetStateValidation();
if (isStateValidationSupported())
assertFalse(fileBuffer.isStateValidated());
} 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 tearDown.
@After
public void tearDown() {
ITextFileBuffer buffer = fManager.getTextFileBuffer(fPath, LocationKind.NORMALIZE);
assertTrue(buffer == null);
ResourceHelper.deleteProject("project");
}
Aggregations