use of org.eclipse.core.filebuffers.IFileBuffer in project eclipse.platform.text by eclipse.
the class FileBufferFunctions 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.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);
if (isStateValidationSupported()) {
assertTrue(listener.count == 1);
assertTrue(listener.buffer == fileBuffer);
assertTrue(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 test16_3.
/*
* Test IFileBufferListener#stateChanging for external changes
*/
@Test
public void test16_3() 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.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 (moveUnderlyingFile() != null) {
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 test16_2.
/*
* Test IFileBufferListener#stateChanging for external changes
*/
@Test
public void test16_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.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 test11_2.
/*
* Test IFileBufferListener#dirtyStateChanged
*/
@Test
public void test11_2() throws Exception {
class Listener extends FileBufferListener {
public IFileBuffer buffer;
public int count;
public boolean isDirty;
@Override
public void dirtyStateChanged(IFileBuffer buf, boolean state) {
++count;
this.buffer = buf;
this.isDirty = 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 {
fileBuffer = fManager.getTextFileBuffer(fPath, LocationKind.NORMALIZE);
IDocument document = fileBuffer.getDocument();
document.replace(0, 0, "prefix");
assertTrue(listener.count == 1);
assertTrue(listener.buffer == fileBuffer);
assertTrue(listener.isDirty);
fileBuffer.revert(null);
assertTrue(listener.count == 2);
assertTrue(listener.buffer == fileBuffer);
assertFalse(listener.isDirty);
} 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 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.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);
if (modifyUnderlyingFile()) {
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