use of org.eclipse.core.filebuffers.IFileBuffer in project eclipse.platform.text by eclipse.
the class FileStoreFileBufferFunctions method test13_2.
/*
* Test IFileBufferListener#stateValidationChanged
*/
@Test
public void test13_2() 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.getFileStoreTextFileBuffer(fFileStore);
assertTrue(listener.count == 0 && listener.buffer == null);
fManager.connectFileStore(fFileStore, null);
try {
setReadOnly(true);
fileBuffer = fManager.getFileStoreTextFileBuffer(fFileStore);
fileBuffer.validateState(null, null);
if (isStateValidationSupported()) {
assertTrue(listener.count == 1);
assertTrue(listener.buffer == fileBuffer);
assertTrue(listener.isStateValidated);
}
} finally {
setReadOnly(false);
fManager.disconnectFileStore(fFileStore, null);
}
} finally {
fManager.removeFileBufferListener(listener);
}
}
use of org.eclipse.core.filebuffers.IFileBuffer in project eclipse.platform.text by eclipse.
the class FileStoreFileBufferFunctions method test13_1.
/*
* Test IFileBufferListener#stateValidationChanged
*/
@Test
public void test13_1() 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.getFileStoreTextFileBuffer(fFileStore);
assertTrue(listener.count == 0 && listener.buffer == null);
fManager.connectFileStore(fFileStore, null);
try {
fileBuffer = fManager.getFileStoreTextFileBuffer(fFileStore);
fileBuffer.validateState(null, null);
if (isStateValidationSupported()) {
assertTrue(listener.count == 1);
assertTrue(listener.buffer == fileBuffer);
assertTrue(listener.isStateValidated);
}
} finally {
fManager.disconnectFileStore(fFileStore, null);
}
} finally {
fManager.removeFileBufferListener(listener);
}
}
use of org.eclipse.core.filebuffers.IFileBuffer in project eclipse.platform.text by eclipse.
the class FileStoreFileBufferFunctions 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.connectFileStore(fFileStore, null);
try {
ITextFileBuffer buffer = fManager.getFileStoreTextFileBuffer(fFileStore);
assertNotNull(buffer);
Class<IAnnotationModel> clazz = getAnnotationModelClass();
if (clazz != null) {
IAnnotationModel model = buffer.getAnnotationModel();
assertTrue(clazz.isInstance(model));
}
} finally {
fManager.disconnectFileStore(fFileStore, 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 test12_2.
/*
* Test IFileBufferListener#bufferContentAboutToBeReplaced/replaced
*/
@Test
public void test12_2() 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.getFileStoreTextFileBuffer(fFileStore);
assertTrue(listener.preCount == 0 && listener.postCount == 0 && listener.preBuffer == null && listener.postBuffer == null);
fManager.connectFileStore(fFileStore, null);
try {
fileBuffer = fManager.getFileStoreTextFileBuffer(fFileStore);
if (modifyUnderlyingFile()) {
assertTrue(listener.preCount == 1);
assertTrue(listener.preBuffer == fileBuffer);
assertTrue(listener.postCount == 1);
assertTrue(listener.postBuffer == fileBuffer);
}
} finally {
fManager.disconnectFileStore(fFileStore, null);
}
} finally {
fManager.removeFileBufferListener(listener);
}
}
use of org.eclipse.core.filebuffers.IFileBuffer in project eclipse.platform.text by eclipse.
the class FileStoreFileBufferFunctions method test17_2.
/*
* Test IFileBufferListener#stateChanging for internal changes
*/
@Test
public void test17_2() throws Exception {
class Listener extends FileBufferListener {
public IFileBuffer buffer;
public int count;
@Override
public void stateChanging(IFileBuffer buf) {
++count;
this.buffer = buf;
}
}
Listener listener = new Listener();
fManager.addFileBufferListener(listener);
try {
ITextFileBuffer fileBuffer = fManager.getFileStoreTextFileBuffer(fFileStore);
assertTrue(listener.count == 0 && listener.buffer == null);
fManager.connectFileStore(fFileStore, null);
try {
fileBuffer = fManager.getFileStoreTextFileBuffer(fFileStore);
IDocument document = fileBuffer.getDocument();
document.replace(0, 0, "prefix");
fileBuffer.revert(null);
assertTrue(listener.count == 1);
assertTrue(listener.buffer == fileBuffer);
} finally {
fManager.disconnectFileStore(fFileStore, null);
}
} finally {
fManager.removeFileBufferListener(listener);
}
}
Aggregations