|
22 | 22 | */ |
23 | 23 |
|
24 | 24 | /* @test |
25 | | - * @bug 4313887 6838333 6925932 7006126 8037945 8072495 8140449 8254876 8262742 |
26 | | - * 8298478 |
| 25 | + * @bug 4313887 6838333 6925932 7006126 7029979 8037945 8072495 8140449 |
| 26 | + * 8254876 8262742 8298478 |
27 | 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 |
28 | 31 | */ |
29 | 32 |
|
| 33 | +import java.io.File; |
30 | 34 | import java.nio.file.FileSystems; |
31 | 35 | import java.nio.file.InvalidPathException; |
32 | 36 | import java.nio.file.Path; |
33 | 37 | import java.nio.file.Paths; |
34 | 38 |
|
| 39 | +import jdk.test.lib.Platform; |
| 40 | + |
35 | 41 | public class PathOps { |
36 | 42 |
|
37 | 43 | static final java.io.PrintStream out = System.out; |
@@ -239,6 +245,34 @@ PathOps normalize(String expected) { |
239 | 245 | return this; |
240 | 246 | } |
241 | 247 |
|
| 248 | + PathOps equals(String other) { |
| 249 | + out.format("test equals %s\n", other); |
| 250 | + checkPath(); |
| 251 | + |
| 252 | + Path that = Path.of(other); |
| 253 | + check(that, path.toString()); |
| 254 | + check(path.hashCode() == that.hashCode(), true); |
| 255 | + |
| 256 | + return this; |
| 257 | + } |
| 258 | + |
| 259 | + PathOps notEquals(Object other) { |
| 260 | + out.format("test not equals %s\n", other); |
| 261 | + checkPath(); |
| 262 | + check(path.equals(other), false); |
| 263 | + |
| 264 | + return this; |
| 265 | + } |
| 266 | + |
| 267 | + PathOps toFile() { |
| 268 | + out.println("check toFile"); |
| 269 | + checkPath(); |
| 270 | + File file = path.toFile(); |
| 271 | + check(file.toString(), path.toString()); |
| 272 | + check(file.toPath().equals(path), true); |
| 273 | + return this; |
| 274 | + } |
| 275 | + |
242 | 276 | PathOps string(String expected) { |
243 | 277 | out.println("check string representation"); |
244 | 278 | checkPath(); |
@@ -1444,6 +1478,18 @@ static void doWindowsTests() { |
1444 | 1478 | .parent(null) |
1445 | 1479 | .name(null); |
1446 | 1480 |
|
| 1481 | + // equals |
| 1482 | + test("this") |
| 1483 | + .equals("this") |
| 1484 | + .notEquals(Path.of("that")) |
| 1485 | + .notEquals(null) |
| 1486 | + .notEquals(new Object()) |
| 1487 | + .equals(Path.of("This")); |
| 1488 | + |
| 1489 | + // toFile |
| 1490 | + test("C:\\foo\\bar\\gus") |
| 1491 | + .toFile(); |
| 1492 | + |
1447 | 1493 | // invalid |
1448 | 1494 | test(":\\foo") |
1449 | 1495 | .invalid(); |
@@ -2121,6 +2167,18 @@ static void doUnixTests() { |
2121 | 2167 | test("/foo/bar/gus/../..") |
2122 | 2168 | .normalize("/foo"); |
2123 | 2169 |
|
| 2170 | + // equals |
| 2171 | + test("this") |
| 2172 | + .equals("this") |
| 2173 | + .notEquals(Path.of("that")) |
| 2174 | + .notEquals(null) |
| 2175 | + .notEquals(new Object()) |
| 2176 | + .notEquals(Path.of("This")); |
| 2177 | + |
| 2178 | + // toFile |
| 2179 | + test("/foo/bar/gus") |
| 2180 | + .toFile(); |
| 2181 | + |
2124 | 2182 | // invalid |
2125 | 2183 | test("foo\u0000bar") |
2126 | 2184 | .invalid(); |
@@ -2198,7 +2256,7 @@ public static void main(String[] args) { |
2198 | 2256 |
|
2199 | 2257 | // operating system specific |
2200 | 2258 | String osname = System.getProperty("os.name"); |
2201 | | - if (osname.startsWith("Windows")) { |
| 2259 | + if (Platform.isWindows()) { |
2202 | 2260 | doWindowsTests(); |
2203 | 2261 | } else { |
2204 | 2262 | doUnixTests(); |
|
0 commit comments