use of org.eclipse.core.filebuffers.IFileBuffer in project eclipse.platform.text by eclipse.
the class FileBufferFunctions method test10.
/*
* Test IFileBufferListener#bufferCreated and IFileBufferListener#bufferDisposed
*/
@Test
public void test10() throws Exception {
class Listener extends FileBufferListener {
public IFileBuffer buffer;
public int count;
@Override
public void bufferCreated(IFileBuffer buf) {
++count;
this.buffer = buf;
}
@Override
public void bufferDisposed(IFileBuffer buf) {
--count;
this.buffer = buf;
}
}
Listener listener = new Listener();
fManager.addFileBufferListener(listener);
try {
fManager.connect(fPath, LocationKind.NORMALIZE, null);
assertTrue(listener.count == 1);
assertNotNull(listener.buffer);
IFileBuffer fileBuffer = fManager.getFileBuffer(fPath, LocationKind.NORMALIZE);
assertTrue(listener.buffer == fileBuffer);
fManager.disconnect(fPath, LocationKind.NORMALIZE, null);
assertTrue(listener.count == 0);
assertTrue(listener.buffer == fileBuffer);
} finally {
try {
fManager.disconnect(fPath, LocationKind.NORMALIZE, null);
} finally {
fManager.removeFileBufferListener(listener);
}
}
}
use of org.eclipse.core.filebuffers.IFileBuffer in project eclipse.platform.text by eclipse.
the class FileBufferFunctions method test13_4.
/*
* Test IFileBufferListener#stateValidationChanged
*/
@Test
public void test13_4() throws Exception {
class Listener extends FileBufferListener {
public IFileBuffer buffer;
public int count;
public boolean isStateValidated;
@Override
public void stateValidationChanged(IFileBuffer buf, boolean state) {
++count;
this.buffer = buf;
this.isStateValidated = state;
}
}
Listener listener = new Listener();
fManager.addFileBufferListener(listener);
try {
ITextFileBuffer fileBuffer = fManager.getTextFileBuffer(fPath, LocationKind.NORMALIZE);
assertTrue(listener.count == 0 && listener.buffer == null);
fManager.connect(fPath, LocationKind.NORMALIZE, null);
try {
setReadOnly(true);
fileBuffer = fManager.getTextFileBuffer(fPath, LocationKind.NORMALIZE);
fileBuffer.validateState(null, null);
fileBuffer.resetStateValidation();
if (isStateValidationSupported()) {
assertTrue(listener.count == 2);
assertTrue(listener.buffer == fileBuffer);
assertFalse(listener.isStateValidated);
}
} finally {
setReadOnly(false);
fManager.disconnect(fPath, LocationKind.NORMALIZE, null);
}
} finally {
fManager.removeFileBufferListener(listener);
}
}
use of org.eclipse.core.filebuffers.IFileBuffer in project eclipse.platform.text by eclipse.
the class FileBufferFunctions method test14.
/*
* Test IFileBufferListener#underlyingFileDeleted
*/
@Test
public void test14() throws Exception {
class Listener extends FileBufferListener {
public IFileBuffer buffer;
public int count;
@Override
public void underlyingFileDeleted(IFileBuffer buf) {
++count;
this.buffer = buf;
}
}
Listener listener = new Listener();
fManager.addFileBufferListener(listener);
try {
ITextFileBuffer fileBuffer = fManager.getTextFileBuffer(fPath, LocationKind.NORMALIZE);
assertTrue(listener.count == 0 && listener.buffer == null);
fManager.connect(fPath, LocationKind.NORMALIZE, null);
try {
fileBuffer = fManager.getTextFileBuffer(fPath, LocationKind.NORMALIZE);
if (deleteUnderlyingFile()) {
assertTrue(listener.count == 1);
assertTrue(listener.buffer == fileBuffer);
}
} finally {
fManager.disconnect(fPath, LocationKind.NORMALIZE, null);
}
} finally {
fManager.removeFileBufferListener(listener);
}
}
use of org.eclipse.core.filebuffers.IFileBuffer 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.IFileBuffer in project eclipse.platform.text by eclipse.
the class FileStoreFileBufferFunctions method testGetFileStoreFileBuffers.
@Test
public void testGetFileStoreFileBuffers() throws Exception {
fManager.connectFileStore(fFileStore, null);
try {
ITextFileBuffer buffer = fManager.getFileStoreTextFileBuffer(fFileStore);
assertNotNull(buffer);
IFileBuffer[] fileBuffers = fManager.getFileStoreFileBuffers();
assertNotNull(fileBuffers);
assertEquals(1, fileBuffers.length);
assertSame(buffer, fileBuffers[0]);
fileBuffers = fManager.getFileBuffers();
assertNotNull(fileBuffers);
assertEquals(0, fileBuffers.length);
} finally {
fManager.disconnectFileStore(fFileStore, null);
}
}
Aggregations