< prev index next >
test/jdk/java/nio/file/Files/CopyAndMove.java
Print this page
*** 51,83 ****
public static void main(String[] args) throws Exception {
Path dir1 = TestUtil.createTemporaryDirectory();
try {
// Same directory
! testPosixAttributes = getFileStore(dir1).supportsFileAttributeView("posix");
testCopyFileToFile(dir1, dir1, TestUtil.supportsLinks(dir1));
testMove(dir1, dir1, TestUtil.supportsLinks(dir1));
// Different directories. Use test.dir if possible as it might be
// a different volume/file system and so improve test coverage.
String testDir = System.getProperty("test.dir", ".");
Path dir2 = TestUtil.createTemporaryDirectory(testDir);
try {
boolean testSymbolicLinks =
TestUtil.supportsLinks(dir1) && TestUtil.supportsLinks(dir2);
! testPosixAttributes = getFileStore(dir1).supportsFileAttributeView("posix") &&
! getFileStore(dir2).supportsFileAttributeView("posix");
testCopyFileToFile(dir1, dir2, testSymbolicLinks);
testMove(dir1, dir2, testSymbolicLinks);
} finally {
TestUtil.removeAll(dir2);
}
// Target is location associated with custom provider
Path dir3 = PassThroughFileSystem.create().getPath(dir1.toString());
! testPosixAttributes = getFileStore(dir1).supportsFileAttributeView("posix") &&
! getFileStore(dir3).supportsFileAttributeView("posix");
testCopyFileToFile(dir1, dir3, false);
testMove(dir1, dir3, false);
// Test copy(InputStream,Path) and copy(Path,OutputStream)
testCopyInputStreamToFile();
--- 51,89 ----
public static void main(String[] args) throws Exception {
Path dir1 = TestUtil.createTemporaryDirectory();
try {
// Same directory
! FileStore fileStore1 = getFileStore(dir1);
! printDirInfo("dir1", dir1, fileStore1);
! testPosixAttributes = fileStore1.supportsFileAttributeView("posix");
testCopyFileToFile(dir1, dir1, TestUtil.supportsLinks(dir1));
testMove(dir1, dir1, TestUtil.supportsLinks(dir1));
// Different directories. Use test.dir if possible as it might be
// a different volume/file system and so improve test coverage.
String testDir = System.getProperty("test.dir", ".");
Path dir2 = TestUtil.createTemporaryDirectory(testDir);
try {
boolean testSymbolicLinks =
TestUtil.supportsLinks(dir1) && TestUtil.supportsLinks(dir2);
! FileStore fileStore2 = getFileStore(dir2);
! printDirInfo("dir2", dir2, fileStore2);
! testPosixAttributes = fileStore1.supportsFileAttributeView("posix") &&
! fileStore2.supportsFileAttributeView("posix");
testCopyFileToFile(dir1, dir2, testSymbolicLinks);
testMove(dir1, dir2, testSymbolicLinks);
} finally {
TestUtil.removeAll(dir2);
}
// Target is location associated with custom provider
Path dir3 = PassThroughFileSystem.create().getPath(dir1.toString());
! FileStore fileStore3 = getFileStore(dir3);
! printDirInfo("dir3", dir3, fileStore3);
! testPosixAttributes = fileStore1.supportsFileAttributeView("posix") &&
! fileStore3.supportsFileAttributeView("posix");
testCopyFileToFile(dir1, dir3, false);
testMove(dir1, dir3, false);
// Test copy(InputStream,Path) and copy(Path,OutputStream)
testCopyInputStreamToFile();
*** 86,105 ****
} finally {
TestUtil.removeAll(dir1);
}
}
! static void printDirInfo(String name, Path dir) throws IOException {
System.err.format("%s: %s (%s)%n", name, dir,
! Files.getFileStore(dir).type());
! }
!
! static void printDirInfo(String label, Path dir1, Path dir2)
! throws IOException {
! System.err.format("--- %s ---%n", label);
! printDirInfo("dir1", dir1);
! printDirInfo("dir2", dir2);
}
static void checkBasicAttributes(BasicFileAttributes attrs1,
BasicFileAttributes attrs2)
{
--- 92,104 ----
} finally {
TestUtil.removeAll(dir1);
}
}
! static void printDirInfo(String name, Path dir, FileStore store) throws IOException {
System.err.format("%s: %s (%s)%n", name, dir,
! store != null ? store.type() : "null");
}
static void checkBasicAttributes(BasicFileAttributes attrs1,
BasicFileAttributes attrs2)
{
*** 127,174 ****
}
static void checkPosixAttributes(PosixFileAttributes attrs1,
PosixFileAttributes attrs2)
{
! try {
! assertTrue(attrs1.permissions().equals(attrs2.permissions()));
! assertTrue(attrs1.owner().equals(attrs2.owner()));
! assertTrue(attrs1.group().equals(attrs2.group()));
! } catch (Exception e) {
! if (!attrs1.permissions().equals(attrs2.permissions()))
! System.err.format("permissions%n1 (%d): %s%n2 (%d): %s%n%n",
attrs1.permissions().size(), attrs1.permissions(),
attrs2.permissions().size(), attrs2.permissions());
! if (!attrs1.owner().equals(attrs2.owner()))
! System.err.format("owner%n1: %s%n2: %s%n%n",
! attrs1.owner(), attrs2.owner());
! if (!attrs1.group().equals(attrs2.group()))
! System.err.format("group%n1: %s%n2: %s%n%n",
! attrs1.group(), attrs2.group());
! throw e;
! }
}
static void checkDosAttributes(DosFileAttributes attrs1,
DosFileAttributes attrs2)
{
! try {
! assertTrue(attrs1.isReadOnly() == attrs2.isReadOnly());
! assertTrue(attrs1.isHidden() == attrs2.isHidden());
! assertTrue(attrs1.isSystem() == attrs2.isSystem());
! } catch (Exception e) {
! if(attrs1.isReadOnly() != attrs2.isReadOnly())
! System.err.format("isReadOnly%n1: %s%n2: %s%n%n",
! attrs1.isReadOnly(), attrs2.isReadOnly());
! if(attrs1.isHidden() != attrs2.isHidden())
! System.err.format("isHidden%n1: %s%n2: %s%n%n",
! attrs1.isHidden(), attrs2.isHidden());
! if(attrs1.isSystem() != attrs2.isSystem())
! System.err.format("isSystem%n1: %s%n2: %s%n%n",
! attrs1.isSystem(), attrs2.isSystem());
! throw e;
! }
}
static void checkUserDefinedFileAttributes(Map<String,ByteBuffer> attrs1,
Map<String,ByteBuffer> attrs2)
{
--- 126,154 ----
}
static void checkPosixAttributes(PosixFileAttributes attrs1,
PosixFileAttributes attrs2)
{
! assertTrue(attrs1.permissions().equals(attrs2.permissions()),
! "permissions%n1 (%d): %s%n2 (%d): %s%n%n",
attrs1.permissions().size(), attrs1.permissions(),
attrs2.permissions().size(), attrs2.permissions());
! assertTrue(attrs1.owner().equals(attrs2.owner()),
! "owner%n1: %s%n2: %s%n%n", attrs1.owner(), attrs2.owner());
! assertTrue(attrs1.group().equals(attrs2.group()),
! "group%n1: %s%n2: %s%n%n", attrs1.group(), attrs2.group());
}
static void checkDosAttributes(DosFileAttributes attrs1,
DosFileAttributes attrs2)
{
! assertTrue(attrs1.isReadOnly() == attrs2.isReadOnly(),
! "isReadOnly%n1: %s%n2: %s%n%n", attrs1.isReadOnly(), attrs2.isReadOnly());
! assertTrue(attrs1.isHidden() == attrs2.isHidden(),
! "isHidden%n1: %s%n2: %s%n%n", attrs1.isHidden(), attrs2.isHidden());
! assertTrue(attrs1.isSystem() == attrs2.isSystem(),
! "isSystem%n1: %s%n2: %s%n%n", attrs1.isSystem(), attrs2.isSystem());
}
static void checkUserDefinedFileAttributes(Map<String,ByteBuffer> attrs1,
Map<String,ByteBuffer> attrs2)
{
*** 290,301 ****
* Tests all possible ways to invoke move
*/
static void testMove(Path dir1, Path dir2, boolean supportsLinks)
throws IOException
{
- printDirInfo("testMove", dir1, dir2);
-
Path source, target, entry;
boolean sameDevice = getFileStore(dir1).equals(getFileStore(dir2));
// -- regular file --
--- 270,279 ----
*** 727,738 ****
* Tests all possible ways to invoke copy to copy a file to a file
*/
static void testCopyFileToFile(Path dir1, Path dir2, boolean supportsLinks)
throws IOException
{
- printDirInfo("testCopyFileToFile", dir1, dir2);
-
Path source, target, link, entry;
// -- regular file --
/**
--- 705,714 ----
*** 1154,1163 ****
--- 1130,1146 ----
static void assertTrue(boolean value) {
if (!value)
throw new RuntimeException("Assertion failed");
}
+ static void assertTrue(boolean value, String format, Object... args) {
+ if (!value) {
+ System.err.format(format, args);
+ throw new RuntimeException("Assertion failed");
+ }
+ }
+
// computes simple hash of the given file
static int computeHash(Path file) throws IOException {
int h = 0;
try (InputStream in = newInputStream(file)) {
< prev index next >