Bug 573409 - test for [performance] Avoid File.getCanonicalPath
additional tests for case insensitive edge cases of copy and move
Change-Id: Iaca9da595f1eaf5072cd9af61c5540f68a4471d1
Signed-off-by: Joerg Kubitz <jkubitz-eclipse@gmx.de>
Reviewed-on: https://git.eclipse.org/r/c/platform/eclipse.platform.resources/+/180307
Tested-by: Lars Vogel <Lars.Vogel@vogella.com>
Reviewed-by: Lars Vogel <Lars.Vogel@vogella.com>
Reviewed-by: Sebastian Ratz <sebastian.ratz@sap.com>
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/filesystem/FileStoreTest.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/filesystem/FileStoreTest.java
index 4a050ce..a1ac0c3 100755
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/filesystem/FileStoreTest.java
+++ b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/filesystem/FileStoreTest.java
@@ -22,12 +22,14 @@
import java.util.stream.Stream;
import org.eclipse.core.filesystem.*;
import org.eclipse.core.filesystem.provider.FileSystem;
+import org.eclipse.core.internal.filesystem.Messages;
import org.eclipse.core.internal.filesystem.NullFileSystem;
import org.eclipse.core.internal.filesystem.local.LocalFile;
import org.eclipse.core.internal.filesystem.local.LocalFileSystem;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.*;
import org.eclipse.core.tests.internal.localstore.LocalStoreTest;
+import org.eclipse.osgi.util.NLS;
/**
* Basic tests for the IFileStore API
@@ -49,8 +51,8 @@
}
/**
- * Tests behavior of IFileStore#fetchInfo when underlying file system
- * throws exceptions.
+ * Tests behavior of IFileStore#fetchInfo when underlying file system throws
+ * exceptions.
*/
public void testBrokenFetchInfo() {
IFileStore broken = null;
@@ -61,16 +63,16 @@
} catch (URISyntaxException e) {
fail("0.99", e);
}
- //no-arg fetch info should return non-existent file
+ // no-arg fetch info should return non-existent file
IFileInfo info = broken.fetchInfo();
assertTrue("1.0", !info.exists());
- //two-arg fetchInfo should throw exception
+ // two-arg fetchInfo should throw exception
try {
info = broken.fetchInfo(EFS.NONE, getMonitor());
fail("2.0");
} catch (CoreException e) {
- //expected
+ // expected
}
}
@@ -83,7 +85,7 @@
private IFileStore[] getFileStoresOnTwoVolumes() {
IFileStore[] tempDirs = new IFileStore[2];
- for (int i = 99/*c*/; i < 123/*z*/; i++) {
+ for (int i = 99/* c */; i < 123/* z */; i++) {
char c = (char) i;
try {
IFileStore store = getDirFileStore(c + ":/temp");
@@ -93,10 +95,10 @@
tempDirs[0] = store;
} else {
tempDirs[1] = store;
- break; //both temp dirs have been created
+ break; // both temp dirs have been created
}
}
- } catch (CoreException e) {//ignore and go to next volume
+ } catch (CoreException e) {// ignore and go to next volume
continue;
}
}
@@ -110,7 +112,8 @@
IFileStore[] tempDirectories = getFileStoresOnTwoVolumes();
/* test if we are in the adequate environment */
- if (tempDirectories == null || tempDirectories.length < 2 || tempDirectories[0] == null || tempDirectories[1] == null) {
+ if (tempDirectories == null || tempDirectories.length < 2 || tempDirectories[0] == null
+ || tempDirectories[1] == null) {
return;
}
@@ -145,7 +148,7 @@
target.copy(destination, EFS.NONE, null);
fail("5.2");
} catch (CoreException e) {
- //should fail
+ // should fail
}
assertTrue("5.3", !verifyTree(getTree(destination)));
destination.delete(EFS.NONE, null);
@@ -163,7 +166,8 @@
public void testCopyDirectory() throws Throwable {
/* build scenario */
- IFileStore temp = EFS.getFileSystem(EFS.SCHEME_FILE).getStore(getWorkspace().getRoot().getLocation().append("temp"));
+ IFileStore temp = EFS.getFileSystem(EFS.SCHEME_FILE)
+ .getStore(getWorkspace().getRoot().getLocation().append("temp"));
temp.mkdir(EFS.NONE, null);
assertTrue("1.1", temp.fetchInfo().isDirectory());
// create tree
@@ -186,17 +190,57 @@
IFileStore child = parent.getChild("child");
IFileStore existing = getTempStore();
createFile(existing, getRandomString());
- //try to copy when parent of destination does not exist
+ // try to copy when parent of destination does not exist
try {
existing.copy(child, EFS.NONE, getMonitor());
fail("1.0");
} catch (CoreException e) {
- //should fail
+ // should fail
}
- //destination should not exist
+ // destination should not exist
assertTrue("1.1", !child.fetchInfo().exists());
}
+ public void testCaseInsensitive() throws Throwable {
+ IFileStore temp = createDir(getWorkspace().getRoot().getLocation().append("temp").toString(), true);
+ boolean isCaseSensitive = temp.getFileSystem().isCaseSensitive();
+ if (isCaseSensitive) {
+ System.out.println("Skipping copy test on caseSensitive System");
+ return;
+ }
+ // create a file
+ String content = "this is just a simple content \n to a simple file \n to test a 'simple' copy";
+ IFileStore fileWithSmallName = temp.getChild("filename");
+ fileWithSmallName.delete(EFS.NONE, null);
+ createFile(fileWithSmallName, content);
+ System.out.println(fileWithSmallName.fetchInfo().getName());
+ assertTrue("1.3", fileWithSmallName.fetchInfo().exists());
+ assertTrue("1.4", compareContent(getContents(content), fileWithSmallName.openInputStream(EFS.NONE, null)));
+
+ IFileStore fileWithOtherName = temp.getChild("FILENAME");
+ System.out.println(fileWithOtherName.fetchInfo().getName());
+ // file content is already the same for both Cases:
+ assertTrue("2.0", compareContent(getContents(content), fileWithOtherName.openInputStream(EFS.NONE, null)));
+ fileWithSmallName.copy(fileWithOtherName, IResource.DEPTH_INFINITE, null); // a NOP Operation
+ // file content is still the same for both Cases:
+ assertTrue("2.1", compareContent(getContents(content), fileWithOtherName.openInputStream(EFS.NONE, null)));
+ assertTrue("3.0", fileWithOtherName.fetchInfo().exists());
+ assertTrue("3.1", fileWithSmallName.fetchInfo().exists());
+ fileWithOtherName.delete(EFS.NONE, null);
+ assertFalse("3.2", fileWithOtherName.fetchInfo().exists());
+ assertFalse("3.3", fileWithSmallName.fetchInfo().exists());
+ try {
+ fileWithSmallName.move(fileWithOtherName, EFS.NONE, null);
+ fail("4.0");
+ } catch (CoreException e) {
+ String message = NLS.bind(Messages.couldNotMove, fileWithSmallName.toString());
+ assertEquals(message, e.getMessage());
+ }
+
+ /* take out the trash */
+ temp.delete(EFS.NONE, null);
+ }
+
public void testCopyFile() throws Throwable {
/* build scenario */
IFileStore temp = createDir(getWorkspace().getRoot().getLocation().append("temp").toString(), true);
@@ -241,7 +285,7 @@
assertTrue("7.1", bigFile.fetchInfo().exists());
assertTrue("7.2", compareContent(getContents(sb.toString()), bigFile.openInputStream(EFS.NONE, null)));
IFileStore destination = temp.getChild("copy of bigFile");
- //IProgressMonitor monitor = new LoggingProgressMonitor(System.out);
+ // IProgressMonitor monitor = new LoggingProgressMonitor(System.out);
IProgressMonitor monitor = getMonitor();
bigFile.copy(destination, EFS.NONE, monitor);
assertTrue("7.3", compareContent(getContents(sb.toString()), destination.openInputStream(EFS.NONE, null)));
@@ -258,7 +302,8 @@
IFileStore[] tempDirectories = getFileStoresOnTwoVolumes();
/* test if we are in the adequate environment */
- if (tempDirectories == null || tempDirectories.length < 2 || tempDirectories[0] == null || tempDirectories[1] == null) {
+ if (tempDirectories == null || tempDirectories.length < 2 || tempDirectories[0] == null
+ || tempDirectories[1] == null) {
return;
}
@@ -432,7 +477,8 @@
IFileStore[] tempDirectories = getFileStoresOnTwoVolumes();
/* test if we are in the adequate environment */
- if (tempDirectories == null || tempDirectories.length < 2 || tempDirectories[0] == null || tempDirectories[1] == null) {
+ if (tempDirectories == null || tempDirectories.length < 2 || tempDirectories[0] == null
+ || tempDirectories[1] == null) {
return;
}
@@ -479,31 +525,32 @@
IFileStore child = parent.getChild("child");
IFileStore existing = getTempStore();
createFile(existing, getRandomString());
- //try to move when parent of destination does not exist
+ // try to move when parent of destination does not exist
try {
existing.move(child, EFS.NONE, getMonitor());
fail("1.0");
} catch (CoreException e) {
- //should fail
+ // should fail
}
- //destination should not exist
+ // destination should not exist
assertTrue("1.1", !child.fetchInfo().exists());
}
/**
- * Tests public API method {@link IFileStore#putInfo(IFileInfo, int, IProgressMonitor)}.
+ * Tests public API method
+ * {@link IFileStore#putInfo(IFileInfo, int, IProgressMonitor)}.
*/
public void testPutInfo() {
IFileStore nonExisting = getTempStore();
- //assert that modifying a non-existing store fails
+ // assert that modifying a non-existing store fails
IFileInfo info = nonExisting.fetchInfo();
info.setLastModified(System.currentTimeMillis());
try {
nonExisting.putInfo(info, EFS.SET_LAST_MODIFIED, getMonitor());
fail("1.0");
} catch (CoreException e) {
- //expected
+ // expected
}
info = nonExisting.fetchInfo();
info.setAttribute(EFS.ATTRIBUTE_READ_ONLY, false);
@@ -511,7 +558,7 @@
nonExisting.putInfo(info, EFS.SET_ATTRIBUTES, getMonitor());
fail("1.1");
} catch (CoreException e) {
- //expected
+ // expected
}
}