From 8dfde28b289cbb53173f0ab759156088bbaf74f1 Mon Sep 17 00:00:00 2001 From: Brian Burkhalter Date: Fri, 15 Sep 2023 15:15:46 +0000 Subject: [PATCH] 8315485: (fs) Move java/nio/file/Path/Misc.java tests into java/nio/file/Path/PathOps.java Reviewed-by: alanb --- test/jdk/java/nio/file/Path/Misc.java | 88 ------------------------ test/jdk/java/nio/file/Path/PathOps.java | 64 ++++++++++++++++- 2 files changed, 61 insertions(+), 91 deletions(-) delete mode 100644 test/jdk/java/nio/file/Path/Misc.java diff --git a/test/jdk/java/nio/file/Path/Misc.java b/test/jdk/java/nio/file/Path/Misc.java deleted file mode 100644 index 550f4588f20..00000000000 --- a/test/jdk/java/nio/file/Path/Misc.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Copyright (c) 2008, 2023, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -/* @test - * @bug 4313887 6838333 7029979 - * @summary Unit test for miscellenous java.nio.file.Path methods - * @library .. /test/lib - * @build jdk.test.lib.Platform - * @run main Misc - */ - -import java.io.*; -import java.nio.file.*; - -import jdk.test.lib.Platform; - -public class Misc { - public static void main(String[] args) throws IOException { - Path dir = TestUtil.createTemporaryDirectory(); - try { - // equals and hashCode methods - testEqualsAndHashCode(); - - // toFile method - testToFile(dir); - } finally { - TestUtil.removeAll(dir); - } - } - - /** - * Exercise equals and hashCode methods - */ - static void testEqualsAndHashCode() { - Path thisFile = Paths.get("this"); - Path thatFile = Paths.get("that"); - - assertTrue(thisFile.equals(thisFile)); - assertTrue(!thisFile.equals(thatFile)); - - assertTrue(!thisFile.equals(null)); - assertTrue(!thisFile.equals(new Object())); - - Path likeThis = Paths.get("This"); - if (Platform.isWindows()) { - // case insensitive - assertTrue(thisFile.equals(likeThis)); - assertTrue(thisFile.hashCode() == likeThis.hashCode()); - } else { - // case senstive - assertTrue(!thisFile.equals(likeThis)); - } - } - - /** - * Exercise toFile method - */ - static void testToFile(Path dir) throws IOException { - File d = dir.toFile(); - assertTrue(d.toString().equals(dir.toString())); - assertTrue(d.toPath().equals(dir)); - } - - static void assertTrue(boolean okay) { - if (!okay) - throw new RuntimeException("Assertion Failed"); - } -} diff --git a/test/jdk/java/nio/file/Path/PathOps.java b/test/jdk/java/nio/file/Path/PathOps.java index eab74101769..a2d9dd69f99 100644 --- a/test/jdk/java/nio/file/Path/PathOps.java +++ b/test/jdk/java/nio/file/Path/PathOps.java @@ -22,16 +22,22 @@ */ /* @test - * @bug 4313887 6838333 6925932 7006126 8037945 8072495 8140449 8254876 8262742 - * 8298478 + * @bug 4313887 6838333 6925932 7006126 7029979 8037945 8072495 8140449 + * 8254876 8262742 8298478 * @summary Unit test for java.nio.file.Path path operations + * @library .. /test/lib + * @build jdk.test.lib.Platform + * @run main PathOps */ +import java.io.File; import java.nio.file.FileSystems; import java.nio.file.InvalidPathException; import java.nio.file.Path; import java.nio.file.Paths; +import jdk.test.lib.Platform; + public class PathOps { static final java.io.PrintStream out = System.out; @@ -239,6 +245,34 @@ public class PathOps { return this; } + PathOps equals(String other) { + out.format("test equals %s\n", other); + checkPath(); + + Path that = Path.of(other); + check(that, path.toString()); + check(path.hashCode() == that.hashCode(), true); + + return this; + } + + PathOps notEquals(Object other) { + out.format("test not equals %s\n", other); + checkPath(); + check(path.equals(other), false); + + return this; + } + + PathOps toFile() { + out.println("check toFile"); + checkPath(); + File file = path.toFile(); + check(file.toString(), path.toString()); + check(file.toPath().equals(path), true); + return this; + } + PathOps string(String expected) { out.println("check string representation"); checkPath(); @@ -1444,6 +1478,18 @@ public class PathOps { .parent(null) .name(null); + // equals + test("this") + .equals("this") + .notEquals(Path.of("that")) + .notEquals(null) + .notEquals(new Object()) + .equals(Path.of("This")); + + // toFile + test("C:\\foo\\bar\\gus") + .toFile(); + // invalid test(":\\foo") .invalid(); @@ -2121,6 +2167,18 @@ public class PathOps { test("/foo/bar/gus/../..") .normalize("/foo"); + // equals + test("this") + .equals("this") + .notEquals(Path.of("that")) + .notEquals(null) + .notEquals(new Object()) + .notEquals(Path.of("This")); + + // toFile + test("/foo/bar/gus") + .toFile(); + // invalid test("foo\u0000bar") .invalid(); @@ -2198,7 +2256,7 @@ public class PathOps { // operating system specific String osname = System.getProperty("os.name"); - if (osname.startsWith("Windows")) { + if (Platform.isWindows()) { doWindowsTests(); } else { doUnixTests();