VFS tests moved to platform-tests

This commit is contained in:
Roman Shevchenko
2011-12-19 12:39:22 +01:00
parent 09c0ca15d8
commit 3300cd7900
10 changed files with 179 additions and 45 deletions
@@ -1,12 +1,27 @@
/*
* Copyright 2000-2011 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.openapi.vfs;
import com.intellij.openapi.application.Result;
import com.intellij.openapi.application.WriteAction;
import com.intellij.openapi.vfs.ex.dummy.DummyFileSystem;
import com.intellij.testFramework.IdeaTestCase;
import com.intellij.testFramework.PlatformLangTestCase;
public class DummyFileSystemTest extends IdeaTestCase {
DummyFileSystem fs;
public class DummyFileSystemTest extends PlatformLangTestCase {
private DummyFileSystem fs;
@Override
protected void setUp() throws Exception {
@@ -19,7 +34,7 @@ public class DummyFileSystemTest extends IdeaTestCase {
VirtualFile f = new WriteAction<VirtualFile>() {
@Override
protected void run(Result<VirtualFile> result) throws Throwable {
VirtualFile res = root.createChildData(null, "f");
VirtualFile res = root.createChildData(this, "f");
result.setResult(res);
}
}.execute().getResultObject();
@@ -37,7 +52,7 @@ public class DummyFileSystemTest extends IdeaTestCase {
}
});
f.delete(null);
f.delete(this);
for (int i = 0; i < 2; i++) {
assertNotNull(events[i]);
@@ -1,16 +1,31 @@
/*
* Copyright 2000-2011 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.openapi.vfs;
import com.intellij.openapi.Disposable;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.testFramework.LightPlatformTestCase;
import com.intellij.testFramework.LightPlatformLangTestCase;
import com.intellij.testFramework.PlatformTestUtil;
import com.intellij.util.ThrowableRunnable;
import java.io.File;
import java.io.IOException;
public class GetPathPerformanceTest extends LightPlatformTestCase {
public class GetPathPerformanceTest extends LightPlatformLangTestCase {
public void testGetPath() throws IOException, InterruptedException {
final File dir = FileUtil.createTempDirectory("GetPath","");
disposeOnTearDown(new Disposable() {
@@ -1,21 +1,34 @@
/*
* Copyright 2000-2011 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.openapi.vfs;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.testFramework.IdeaTestCase;
import com.intellij.testFramework.PlatformLangTestCase;
import java.io.*;
/**
* @author yole
*/
public class RefreshChildrenTest extends IdeaTestCase {
public class RefreshChildrenTest extends PlatformLangTestCase {
private File testDir;
@Override
protected void setUp() throws Exception {
// the superclass sets tmpdir on every run and cleans up, but we want to do it our way
// the superclass sets tmp. dir on every run and cleans up, but we want to do it our way
String baseTempDir = FileUtil.getTempDirectory();
testDir = new File(baseTempDir, "RefreshChildrenTest." + getName());
@@ -30,12 +43,13 @@ public class RefreshChildrenTest extends IdeaTestCase {
public void testRefreshSeesLatestDirectoryContents() throws Exception {
assertFalse(testDir.exists());
testDir.mkdir();
assert testDir.exists() || testDir.mkdir() : testDir;
assertTrue(testDir.isDirectory());
writeFile(testDir, "Foo.java", "");
LocalFileSystem local = LocalFileSystem.getInstance();
VirtualFile virtualDir = local.findFileByIoFile(testDir);
assert virtualDir != null : virtualDir;
virtualDir.getChildren();
virtualDir.refresh(false, true);
@@ -47,13 +61,17 @@ public class RefreshChildrenTest extends IdeaTestCase {
checkChildCount(virtualDir, 2);
}
private void writeFile(File dir, String filename, String contents) throws IOException {
private static void writeFile(File dir, String filename, String contents) throws IOException {
Writer writer = new OutputStreamWriter(new FileOutputStream(new File(dir, filename)), "UTF-8");
writer.write(contents);
writer.close();
try {
writer.write(contents);
}
finally {
writer.close();
}
}
private void checkChildCount(VirtualFile virtualDir, int expectedCount) {
private static void checkChildCount(VirtualFile virtualDir, int expectedCount) {
VirtualFile[] children = virtualDir.getChildren();
if (children.length != expectedCount) {
System.err.println("children:");
@@ -63,5 +81,4 @@ public class RefreshChildrenTest extends IdeaTestCase {
}
assertEquals(expectedCount, children.length);
}
}
@@ -1,3 +1,18 @@
/*
* Copyright 2000-2011 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.openapi.vfs;
import com.intellij.concurrency.JobUtil;
@@ -6,8 +21,9 @@ import com.intellij.openapi.application.WriteAction;
import com.intellij.openapi.application.ex.PathManagerEx;
import com.intellij.openapi.progress.ProgressManager;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.testFramework.IdeaTestCase;
import com.intellij.testFramework.IdeaTestUtil;
import com.intellij.testFramework.PlatformLangTestCase;
import com.intellij.testFramework.PlatformTestUtil;
import com.intellij.testFramework.UsefulTestCase;
import com.intellij.util.Processor;
import com.intellij.util.ui.UIUtil;
@@ -22,7 +38,7 @@ import java.util.List;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
public class VfsUtilTest extends IdeaTestCase {
public class VfsUtilTest extends PlatformLangTestCase {
@Override
protected void runBareRunnable(Runnable runnable) throws Throwable {
runnable.run();
@@ -82,7 +98,7 @@ public class VfsUtilTest extends IdeaTestCase {
final VirtualFileFilter fileFilter = new VirtualFileFilter() {
@Override
public boolean accept(VirtualFile file) {
return IdeaTestUtil.CVS_FILE_FILTER.accept(file) && !file.getName().endsWith(".new");
return PlatformTestUtil.CVS_FILE_FILTER.accept(file) && !file.getName().endsWith(".new");
}
};
for (VirtualFile child : children) {
@@ -156,8 +172,8 @@ public class VfsUtilTest extends IdeaTestCase {
}
}.execute().getResultObject();
LocalFileSystem fs = LocalFileSystem.getInstance();
VirtualFile vtemp = fs.findFileByIoFile(temp);
assert vtemp != null;
VirtualFile vTemp = fs.findFileByIoFile(temp);
assert vTemp != null;
VirtualFile[] children = new VirtualFile[N];
long[] timestamp = new long[N];
@@ -170,7 +186,7 @@ public class VfsUtilTest extends IdeaTestCase {
timestamp[i] = file.lastModified();
}
vtemp.refresh(false,true);
vTemp.refresh(false, true);
for (int i=0;i< N;i++) {
File file = new File(temp, i + ".txt");
@@ -183,7 +199,8 @@ public class VfsUtilTest extends IdeaTestCase {
assertNotNull(child);
long mod = child.getTimeStamp();
assertEquals("File:"+child.getPath()+"; mod:"+ new Date(mod)+"; io:"+new File(child.getPath()).lastModified(),timestamp[i], mod);
assertEquals("File:" + child.getPath() + "; mod:" + new Date(mod) + "; io:" + new File(child.getPath()).lastModified(),
timestamp[i], mod);
}
Thread.sleep(2000); // todo[r.sh] find a way to get timestamps with millisecond granularity on Linux ?
@@ -231,13 +248,13 @@ public class VfsUtilTest extends IdeaTestCase {
result.setResult(res);
}
}.execute().getResultObject();
VirtualFile vdir = LocalFileSystem.getInstance().findFileByIoFile(tempDir);
assertNotNull(vdir);
assertTrue(vdir.isDirectory());
VirtualFile vDir = LocalFileSystem.getInstance().findFileByIoFile(tempDir);
assertNotNull(vDir);
assertTrue(vDir.isDirectory());
VirtualFile child = vdir.findChild(" ");
VirtualFile child = vDir.findChild(" ");
assertNull(child);
assertEmpty(vdir.getChildren());
UsefulTestCase.assertEmpty(vDir.getChildren());
}
}
@@ -1,3 +1,18 @@
/*
* Copyright 2000-2011 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.openapi.vfs;
import com.intellij.concurrency.JobUtil;
@@ -11,7 +26,7 @@ import com.intellij.openapi.vfs.impl.VirtualFilePointerImpl;
import com.intellij.openapi.vfs.pointers.VirtualFilePointer;
import com.intellij.openapi.vfs.pointers.VirtualFilePointerListener;
import com.intellij.openapi.vfs.pointers.VirtualFilePointerManager;
import com.intellij.testFramework.IdeaTestCase;
import com.intellij.testFramework.PlatformLangTestCase;
import com.intellij.testFramework.PlatformTestUtil;
import com.intellij.testFramework.Timings;
import com.intellij.util.IncorrectOperationException;
@@ -28,7 +43,7 @@ import java.util.Collections;
/**
* @author dsl
*/
public class VirtualFilePointerTest extends IdeaTestCase {
public class VirtualFilePointerTest extends PlatformLangTestCase {
private VirtualFilePointerManager myVirtualFilePointerManager;
@Override
@@ -13,25 +13,32 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.openapi.vfs;
package com.intellij.openapi.vfs.local;
import com.intellij.execution.util.ExecUtil;
import com.intellij.ide.GeneralSettings;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.util.SystemInfo;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.vfs.LocalFileSystem;
import com.intellij.openapi.vfs.SafeWriteRequestor;
import com.intellij.openapi.vfs.VfsUtil;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.openapi.vfs.newvfs.ManagingFS;
import com.intellij.openapi.vfs.newvfs.persistent.PersistentFS;
import com.intellij.testFramework.IdeaTestCase;
import com.intellij.testFramework.PlatformLangTestCase;
import com.intellij.testFramework.PlatformTestUtil;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.Nullable;
import java.io.*;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.nio.charset.Charset;
import java.util.Arrays;
public class LocalFileSystemTest extends IdeaTestCase{
public class LocalFileSystemTest extends PlatformLangTestCase {
public static void setContentOnDisk(File file, byte[] bom, String content, Charset charset) throws IOException {
FileOutputStream stream = new FileOutputStream(file);
if (bom != null) {
@@ -161,11 +168,11 @@ public class LocalFileSystemTest extends IdeaTestCase{
VirtualFile toVDir = LocalFileSystem.getInstance().findFileByPath(toDir.getPath().replace(File.separatorChar, '/'));
assertNotNull(fromVDir);
assertNotNull(toVDir);
final VirtualFile fileToCopy = fromVDir.createChildData(null, "temp_file");
final VirtualFile fileToCopy = fromVDir.createChildData(this, "temp_file");
final byte[] byteContent = {0, 1, 2, 3};
fileToCopy.setBinaryContent(byteContent);
final String newName = "new_temp_file";
final VirtualFile copy = fileToCopy.copy(null, toVDir, newName);
final VirtualFile copy = fileToCopy.copy(this, toVDir, newName);
assertEquals(newName, copy.getName());
assertTrue(Arrays.equals(byteContent, copy.contentsToByteArray()));
}
@@ -190,11 +197,11 @@ public class LocalFileSystemTest extends IdeaTestCase{
VirtualFile toVDir = LocalFileSystem.getInstance().findFileByPath(toDir.getPath().replace(File.separatorChar, '/'));
assertNotNull(fromVDir);
assertNotNull(toVDir);
final VirtualFile dirToCopy = fromVDir.createChildDirectory(null, "dir");
final VirtualFile file = dirToCopy.createChildData(null, "temp_file");
final VirtualFile dirToCopy = fromVDir.createChildDirectory(this, "dir");
final VirtualFile file = dirToCopy.createChildData(this, "temp_file");
file.setBinaryContent(new byte[]{0, 1, 2, 3});
final String newName = "dir";
final VirtualFile dirCopy = dirToCopy.copy(null, toVDir, newName);
final VirtualFile dirCopy = dirToCopy.copy(this, toVDir, newName);
assertEquals(newName, dirCopy.getName());
PlatformTestUtil.assertDirectoriesEqual(toVDir, fromVDir, null);
}
@@ -23,6 +23,7 @@ import com.intellij.openapi.vfs.LocalFileSystem;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.testFramework.LightPlatformTestCase;
import com.intellij.testFramework.PlatformTestCase;
import org.jetbrains.annotations.Nullable;
import java.io.File;
import java.io.IOException;
@@ -158,6 +159,7 @@ public class SymLinkHandlingTest extends LightPlatformTestCase {
return linkFile;
}
@Nullable
private VirtualFile refreshAndFind(final File ioFile) {
refresh();
return myFileSystem.findFileByPath(ioFile.getAbsolutePath());
@@ -0,0 +1,23 @@
/*
* Copyright 2000-2011 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.testFramework;
public abstract class LightPlatformLangTestCase extends LightPlatformTestCase {
@SuppressWarnings("JUnitTestCaseWithNonTrivialConstructors")
protected LightPlatformLangTestCase() {
PlatformTestCase.initPlatformLangPrefix();
}
}
@@ -0,0 +1,23 @@
/*
* Copyright 2000-2011 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.testFramework;
public abstract class PlatformLangTestCase extends PlatformTestCase {
@SuppressWarnings("JUnitTestCaseWithNonTrivialConstructors")
protected PlatformLangTestCase() {
initPlatformLangPrefix();
}
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* Copyright 2000-2011 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -579,7 +579,7 @@ public class PlatformTestUtil {
}
}
private static HashMap<String, VirtualFile> buildNameToFileMap(VirtualFile[] files, VirtualFileFilter filter) {
private static HashMap<String, VirtualFile> buildNameToFileMap(VirtualFile[] files, @Nullable VirtualFileFilter filter) {
HashMap<String, VirtualFile> map = new HashMap<String, VirtualFile>();
for (VirtualFile file : files) {
if (filter != null && !filter.accept(file)) continue;
@@ -588,7 +588,7 @@ public class PlatformTestUtil {
return map;
}
public static void assertDirectoriesEqual(VirtualFile dirAfter, VirtualFile dirBefore, VirtualFileFilter fileFilter) throws IOException {
public static void assertDirectoriesEqual(VirtualFile dirAfter, VirtualFile dirBefore, @Nullable VirtualFileFilter fileFilter) throws IOException {
FileDocumentManager.getInstance().saveAllDocuments();
VirtualFile[] childrenAfter = dirAfter.getChildren();
if (dirAfter.isInLocalFileSystem()) {