use of org.eclipse.core.filebuffers.ITextFileBuffer in project eclipse.platform.text by eclipse.
the class FileBufferFunctions method test15.
/*
* Test IFileBufferListener#underlyingFileMoved
*/
@Test
public void test15() throws Exception {
class Listener extends FileBufferListener {
public IFileBuffer buffer;
public int count;
public IPath newLocation;
@Override
public void underlyingFileMoved(IFileBuffer buf, IPath location) {
++count;
this.buffer = buf;
this.newLocation = location;
}
}
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);
IPath newLocation = moveUnderlyingFile();
if (newLocation != null) {
if (listener.count != 1 || listener.buffer != fileBuffer || !newLocation.equals(listener.newLocation)) {
StringBuilder buf = new StringBuilder();
buf.append("Wrong listener notifcation in " + getClass().getName() + ":\n");
buf.append("listener.count: " + listener.count + " (expected: 1)\n");
if (newLocation.equals(listener.newLocation))
buf.append("newLocation identical: true\n");
else {
buf.append("listener.newLocation: " + listener.newLocation + "\n");
buf.append("newLocation: " + newLocation + "\n");
}
buf.append("buffers identical: " + Boolean.valueOf(listener.buffer == fileBuffer));
fail(buf.toString());
}
}
} finally {
fManager.disconnect(fPath, LocationKind.NORMALIZE, null);
}
} finally {
fManager.removeFileBufferListener(listener);
}
}
use of org.eclipse.core.filebuffers.ITextFileBuffer in project eclipse.platform.text by eclipse.
the class FileBufferFunctions method test17_1.
/*
* Test IFileBufferListener#stateChanging for internal changes
*/
@Test
public void test17_1() 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);
fileBuffer.validateState(null, null);
if (isStateValidationSupported()) {
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.ITextFileBuffer in project eclipse.platform.text by eclipse.
the class FileBufferFunctions method test16_1.
/*
* Test IFileBufferListener#stateChanging for external changes
*/
@Test
public void test16_1() 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 (modifyUnderlyingFile()) {
assertSame(listener.buffer, fileBuffer);
assertEquals(1, listener.count);
}
} finally {
fManager.disconnect(fPath, LocationKind.NORMALIZE, null);
}
} finally {
fManager.removeFileBufferListener(listener);
}
}
use of org.eclipse.core.filebuffers.ITextFileBuffer in project eclipse.platform.text by eclipse.
the class FileBufferFunctions 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.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");
fileBuffer.revert(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.ITextFileBuffer in project eclipse.platform.text by eclipse.
the class FileStoreFileBufferFunctions 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.getFileStoreTextFileBuffer(fFileStore);
assertTrue(listener.count == 0 && listener.buffer == null);
fManager.connectFileStore(fFileStore, null);
try {
fileBuffer = fManager.getFileStoreTextFileBuffer(fFileStore);
if (moveUnderlyingFile() != null) {
assertTrue(listener.count == 1);
assertTrue(listener.buffer == fileBuffer);
}
} finally {
fManager.disconnectFileStore(fFileStore, null);
}
} finally {
fManager.removeFileBufferListener(listener);
}
}
Aggregations