Search in sources :

Example 61 with ITextFileBuffer

use of org.eclipse.core.filebuffers.ITextFileBuffer in project eclipse.platform.text by eclipse.

the class FileStoreFileBufferFunctions 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.getFileStoreTextFileBuffer(fFileStore);
        assertTrue(listener.count == 0 && listener.buffer == null);
        fManager.connectFileStore(fFileStore, null);
        try {
            fileBuffer = fManager.getFileStoreTextFileBuffer(fFileStore);
            if (deleteUnderlyingFile()) {
                assertTrue(listener.count == 1);
                assertTrue(listener.buffer == fileBuffer);
            }
        } finally {
            fManager.disconnectFileStore(fFileStore, null);
        }
    } finally {
        fManager.removeFileBufferListener(listener);
    }
}
Also used : IFileBuffer(org.eclipse.core.filebuffers.IFileBuffer) ITextFileBuffer(org.eclipse.core.filebuffers.ITextFileBuffer) Test(org.junit.Test)

Example 62 with ITextFileBuffer

use of org.eclipse.core.filebuffers.ITextFileBuffer in project eclipse.platform.text by eclipse.

the class FileStoreFileBufferFunctions method test2.

/*
	 * Tests isSynchronized.
	 */
@Test
public void test2() throws Exception {
    fManager.connectFileStore(fFileStore, null);
    try {
        ITextFileBuffer fileBuffer = fManager.getFileStoreTextFileBuffer(fFileStore);
        assertTrue(fileBuffer.isSynchronized());
        IFileStore fileStore = fFileStore;
        IFileInfo fileInfo = fileStore.fetchInfo();
        fileInfo.setLastModified(1000);
        if (fileInfo.exists())
            fileStore.putInfo(fileInfo, EFS.SET_LAST_MODIFIED, null);
        long lastModified = fileStore.fetchInfo().getLastModified();
        assertTrue(lastModified == EFS.NONE || !fileBuffer.isSynchronized());
    } finally {
        fManager.disconnectFileStore(fFileStore, null);
    }
}
Also used : IFileInfo(org.eclipse.core.filesystem.IFileInfo) ITextFileBuffer(org.eclipse.core.filebuffers.ITextFileBuffer) IFileStore(org.eclipse.core.filesystem.IFileStore) Test(org.junit.Test)

Example 63 with ITextFileBuffer

use of org.eclipse.core.filebuffers.ITextFileBuffer in project eclipse.platform.text by eclipse.

the class FileStoreFileBufferFunctions 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.getFileStoreTextFileBuffer(fFileStore);
        assertTrue(listener.count == 0 && listener.buffer == null);
        fManager.connectFileStore(fFileStore, null);
        try {
            setReadOnly(true);
            fileBuffer = fManager.getFileStoreTextFileBuffer(fFileStore);
            fileBuffer.validateState(null, null);
            fileBuffer.resetStateValidation();
            if (isStateValidationSupported()) {
                assertTrue(listener.count == 2);
                assertTrue(listener.buffer == fileBuffer);
                assertFalse(listener.isStateValidated);
            }
        } finally {
            setReadOnly(false);
            fManager.disconnectFileStore(fFileStore, null);
        }
    } finally {
        fManager.removeFileBufferListener(listener);
    }
}
Also used : IFileBuffer(org.eclipse.core.filebuffers.IFileBuffer) ITextFileBuffer(org.eclipse.core.filebuffers.ITextFileBuffer) Test(org.junit.Test)

Example 64 with ITextFileBuffer

use of org.eclipse.core.filebuffers.ITextFileBuffer in project eclipse.platform.text by eclipse.

the class FileStoreFileBufferFunctions 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.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");
            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.disconnectFileStore(fFileStore, null);
        }
    } finally {
        fManager.removeFileBufferListener(listener);
    }
}
Also used : IFileBuffer(org.eclipse.core.filebuffers.IFileBuffer) ITextFileBuffer(org.eclipse.core.filebuffers.ITextFileBuffer) IDocument(org.eclipse.jface.text.IDocument) Test(org.junit.Test)

Example 65 with ITextFileBuffer

use of org.eclipse.core.filebuffers.ITextFileBuffer in project eclipse.platform.text by eclipse.

the class FileStoreFileBufferFunctions method test4.

/*
	 * Tests isShared.
	 */
@Test
public void test4() throws Exception {
    fManager.connectFileStore(fFileStore, null);
    try {
        ITextFileBuffer fileBuffer1 = fManager.getFileStoreTextFileBuffer(fFileStore);
        assertFalse(fileBuffer1.isShared());
        fManager.connectFileStore(fFileStore, null);
        try {
            ITextFileBuffer fileBuffer2 = fManager.getFileStoreTextFileBuffer(fFileStore);
            assertTrue(fileBuffer1.isShared());
            assertTrue(fileBuffer2.isShared());
        } finally {
            fManager.disconnectFileStore(fFileStore, null);
        }
        assertFalse(fileBuffer1.isShared());
    } finally {
        fManager.disconnectFileStore(fFileStore, null);
    }
}
Also used : ITextFileBuffer(org.eclipse.core.filebuffers.ITextFileBuffer) Test(org.junit.Test)

Aggregations

ITextFileBuffer (org.eclipse.core.filebuffers.ITextFileBuffer)133 Test (org.junit.Test)85 IDocument (org.eclipse.jface.text.IDocument)54 IFileBuffer (org.eclipse.core.filebuffers.IFileBuffer)37 ITextFileBufferManager (org.eclipse.core.filebuffers.ITextFileBufferManager)35 IPath (org.eclipse.core.runtime.IPath)31 IFile (org.eclipse.core.resources.IFile)18 BadLocationException (org.eclipse.jface.text.BadLocationException)15 IFileStore (org.eclipse.core.filesystem.IFileStore)9 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)9 CoreException (org.eclipse.core.runtime.CoreException)8 Position (org.eclipse.jface.text.Position)8 IFileInfo (org.eclipse.core.filesystem.IFileInfo)7 IAnnotationModel (org.eclipse.jface.text.source.IAnnotationModel)7 Match (org.eclipse.search.ui.text.Match)7 IFolder (org.eclipse.core.resources.IFolder)5 IStatus (org.eclipse.core.runtime.IStatus)5 Path (org.eclipse.core.runtime.Path)5 SubProgressMonitor (org.eclipse.core.runtime.SubProgressMonitor)5 Status (org.eclipse.core.runtime.Status)4