|
22 | 22 | */
|
23 | 23 |
|
24 | 24 | /* @test
|
25 |
| - * @bug 4313887 6838333 6925932 7006126 8037945 8072495 8140449 8254876 8298478 |
| 25 | + * @bug 4313887 6838333 6925932 7006126 7029979 8037945 8072495 8140449 |
| 26 | + * 8254876 8298478 |
26 | 27 | * @summary Unit test for java.nio.file.Path path operations
|
| 28 | + * @library .. /test/lib |
| 29 | + * @build jdk.test.lib.Platform |
| 30 | + * @run main PathOps |
27 | 31 | */
|
28 | 32 |
|
| 33 | +import java.io.File; |
29 | 34 | import java.nio.file.FileSystems;
|
30 | 35 | import java.nio.file.InvalidPathException;
|
31 | 36 | import java.nio.file.Path;
|
32 | 37 | import java.nio.file.Paths;
|
33 | 38 |
|
| 39 | +import jdk.test.lib.Platform; |
| 40 | + |
34 | 41 | public class PathOps {
|
35 | 42 |
|
36 | 43 | static final java.io.PrintStream out = System.out;
|
@@ -217,6 +224,34 @@ PathOps normalize(String expected) {
|
217 | 224 | return this;
|
218 | 225 | }
|
219 | 226 |
|
| 227 | + PathOps equals(String other) { |
| 228 | + out.format("test equals %s\n", other); |
| 229 | + checkPath(); |
| 230 | + |
| 231 | + Path that = Path.of(other); |
| 232 | + check(that, path.toString()); |
| 233 | + check(path.hashCode() == that.hashCode(), true); |
| 234 | + |
| 235 | + return this; |
| 236 | + } |
| 237 | + |
| 238 | + PathOps notEquals(Object other) { |
| 239 | + out.format("test not equals %s\n", other); |
| 240 | + checkPath(); |
| 241 | + check(path.equals(other), false); |
| 242 | + |
| 243 | + return this; |
| 244 | + } |
| 245 | + |
| 246 | + PathOps toFile() { |
| 247 | + out.println("check toFile"); |
| 248 | + checkPath(); |
| 249 | + File file = path.toFile(); |
| 250 | + check(file.toString(), path.toString()); |
| 251 | + check(file.toPath().equals(path), true); |
| 252 | + return this; |
| 253 | + } |
| 254 | + |
220 | 255 | PathOps string(String expected) {
|
221 | 256 | out.println("check string representation");
|
222 | 257 | checkPath();
|
@@ -1393,6 +1428,18 @@ static void doWindowsTests() {
|
1393 | 1428 | .parent(null)
|
1394 | 1429 | .name(null);
|
1395 | 1430 |
|
| 1431 | + // equals |
| 1432 | + test("this") |
| 1433 | + .equals("this") |
| 1434 | + .notEquals(Path.of("that")) |
| 1435 | + .notEquals(null) |
| 1436 | + .notEquals(new Object()) |
| 1437 | + .equals(Path.of("This")); |
| 1438 | + |
| 1439 | + // toFile |
| 1440 | + test("C:\\foo\\bar\\gus") |
| 1441 | + .toFile(); |
| 1442 | + |
1396 | 1443 | // invalid
|
1397 | 1444 | test(":\\foo")
|
1398 | 1445 | .invalid();
|
@@ -2045,6 +2092,18 @@ static void doUnixTests() {
|
2045 | 2092 | test("/foo/bar/gus/../..")
|
2046 | 2093 | .normalize("/foo");
|
2047 | 2094 |
|
| 2095 | + // equals |
| 2096 | + test("this") |
| 2097 | + .equals("this") |
| 2098 | + .notEquals(Path.of("that")) |
| 2099 | + .notEquals(null) |
| 2100 | + .notEquals(new Object()) |
| 2101 | + .notEquals(Path.of("This")); |
| 2102 | + |
| 2103 | + // toFile |
| 2104 | + test("/foo/bar/gus") |
| 2105 | + .toFile(); |
| 2106 | + |
2048 | 2107 | // invalid
|
2049 | 2108 | test("foo\u0000bar")
|
2050 | 2109 | .invalid();
|
@@ -2122,7 +2181,7 @@ public static void main(String[] args) {
|
2122 | 2181 |
|
2123 | 2182 | // operating system specific
|
2124 | 2183 | String osname = System.getProperty("os.name");
|
2125 |
| - if (osname.startsWith("Windows")) { |
| 2184 | + if (Platform.isWindows()) { |
2126 | 2185 | doWindowsTests();
|
2127 | 2186 | } else {
|
2128 | 2187 | doUnixTests();
|
|
0 commit comments