Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/nio/file/Path/PathOps.java
38828 views
1
/*
2
* Copyright (c) 2008, 2012, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation.
8
*
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
14
*
15
* You should have received a copy of the GNU General Public License version
16
* 2 along with this work; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
*
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* questions.
22
*/
23
24
/* @test
25
* @bug 4313887 6838333 6925932 7006126 8037945
26
* @summary Unit test for java.nio.file.Path path operations
27
*/
28
29
import java.nio.file.*;
30
31
public class PathOps {
32
33
static final java.io.PrintStream out = System.out;
34
35
private String input;
36
private Path path;
37
private Exception exc;
38
39
private PathOps(String first, String... more) {
40
out.println();
41
input = first;
42
try {
43
path = FileSystems.getDefault().getPath(first, more);
44
out.format("%s -> %s", first, path);
45
} catch (Exception x) {
46
exc = x;
47
out.format("%s -> %s", first, x);
48
}
49
out.println();
50
}
51
52
Path path() {
53
return path;
54
}
55
56
void fail() {
57
throw new RuntimeException("PathOps failed");
58
}
59
60
void checkPath() {
61
if (path == null) {
62
throw new InternalError("path is null");
63
}
64
}
65
66
void check(Object result, String expected) {
67
out.format("\tExpected: %s\n", expected);
68
out.format("\tActual: %s\n", result);
69
if (result == null) {
70
if (expected == null) return;
71
} else {
72
// compare string representations
73
if (expected != null && result.toString().equals(expected.toString()))
74
return;
75
}
76
fail();
77
}
78
79
void check(Object result, boolean expected) {
80
check(result, Boolean.toString(expected));
81
}
82
83
PathOps root(String expected) {
84
out.println("check root");
85
checkPath();
86
check(path.getRoot(), expected);
87
return this;
88
}
89
90
PathOps parent(String expected) {
91
out.println("check parent");
92
checkPath();
93
check(path.getParent(), expected);
94
return this;
95
}
96
97
PathOps name(String expected) {
98
out.println("check name");
99
checkPath();
100
check(path.getFileName(), expected);
101
return this;
102
}
103
104
PathOps element(int index, String expected) {
105
out.format("check element %d\n", index);
106
checkPath();
107
check(path.getName(index), expected);
108
return this;
109
}
110
111
PathOps subpath(int startIndex, int endIndex, String expected) {
112
out.format("test subpath(%d,%d)\n", startIndex, endIndex);
113
checkPath();
114
check(path.subpath(startIndex, endIndex), expected);
115
return this;
116
}
117
118
PathOps starts(String prefix) {
119
out.format("test startsWith with %s\n", prefix);
120
checkPath();
121
Path s = FileSystems.getDefault().getPath(prefix);
122
check(path.startsWith(s), true);
123
return this;
124
}
125
126
PathOps notStarts(String prefix) {
127
out.format("test not startsWith with %s\n", prefix);
128
checkPath();
129
Path s = FileSystems.getDefault().getPath(prefix);
130
check(path.startsWith(s), false);
131
return this;
132
}
133
134
PathOps ends(String suffix) {
135
out.format("test endsWith %s\n", suffix);
136
checkPath();
137
Path s = FileSystems.getDefault().getPath(suffix);
138
check(path.endsWith(s), true);
139
return this;
140
}
141
142
PathOps notEnds(String suffix) {
143
out.format("test not endsWith %s\n", suffix);
144
checkPath();
145
Path s = FileSystems.getDefault().getPath(suffix);
146
check(path.endsWith(s), false);
147
return this;
148
}
149
150
PathOps absolute() {
151
out.println("check path is absolute");
152
checkPath();
153
check(path.isAbsolute(), true);
154
return this;
155
}
156
157
PathOps notAbsolute() {
158
out.println("check path is not absolute");
159
checkPath();
160
check(path.isAbsolute(), false);
161
return this;
162
}
163
164
PathOps resolve(String other, String expected) {
165
out.format("test resolve %s\n", other);
166
checkPath();
167
check(path.resolve(other), expected);
168
return this;
169
}
170
171
PathOps resolveSibling(String other, String expected) {
172
out.format("test resolveSibling %s\n", other);
173
checkPath();
174
check(path.resolveSibling(other), expected);
175
return this;
176
}
177
178
PathOps relativize(String other, String expected) {
179
out.format("test relativize %s\n", other);
180
checkPath();
181
Path that = FileSystems.getDefault().getPath(other);
182
check(path.relativize(that), expected);
183
return this;
184
}
185
186
PathOps normalize(String expected) {
187
out.println("check normalized path");
188
checkPath();
189
check(path.normalize(), expected);
190
return this;
191
}
192
193
PathOps string(String expected) {
194
out.println("check string representation");
195
checkPath();
196
check(path, expected);
197
return this;
198
}
199
200
PathOps invalid() {
201
if (!(exc instanceof InvalidPathException)) {
202
out.println("InvalidPathException not thrown as expected");
203
fail();
204
}
205
return this;
206
}
207
208
static PathOps test(String first, String... more) {
209
return new PathOps(first, more);
210
}
211
212
// -- PathOpss --
213
214
static void header(String s) {
215
out.println();
216
out.println();
217
out.println("-- " + s + " --");
218
}
219
220
static void doWindowsTests() {
221
header("Windows specific tests");
222
223
// construction
224
test("C:\\")
225
.string("C:\\");
226
test("C:\\", "")
227
.string("C:\\");
228
test("C:\\", "foo")
229
.string("C:\\foo");
230
test("C:\\", "\\foo")
231
.string("C:\\foo");
232
test("C:\\", "foo\\")
233
.string("C:\\foo");
234
test("foo", "bar", "gus")
235
.string("foo\\bar\\gus");
236
test("")
237
.string("");
238
test("", "C:\\")
239
.string("C:\\");
240
test("", "foo", "", "bar", "", "\\gus")
241
.string("foo\\bar\\gus");
242
243
// all components present
244
test("C:\\a\\b\\c")
245
.root("C:\\")
246
.parent("C:\\a\\b")
247
.name("c");
248
test("C:a\\b\\c")
249
.root("C:")
250
.parent("C:a\\b")
251
.name("c");
252
test("\\\\server\\share\\a")
253
.root("\\\\server\\share\\")
254
.parent("\\\\server\\share\\")
255
.name("a");
256
257
// root component only
258
test("C:\\")
259
.root("C:\\")
260
.parent(null)
261
.name(null);
262
test("C:")
263
.root("C:")
264
.parent(null)
265
.name(null);
266
test("\\\\server\\share\\")
267
.root("\\\\server\\share\\")
268
.parent(null)
269
.name(null);
270
271
// no root component
272
test("a\\b")
273
.root(null)
274
.parent("a")
275
.name("b");
276
277
// name component only
278
test("foo")
279
.root(null)
280
.parent(null)
281
.name("foo");
282
test("")
283
.root(null)
284
.parent(null)
285
.name("");
286
287
// startsWith
288
test("C:\\")
289
.starts("C:\\")
290
.starts("c:\\")
291
.notStarts("C")
292
.notStarts("C:")
293
.notStarts("");
294
test("C:")
295
.starts("C:")
296
.starts("c:")
297
.notStarts("C")
298
.notStarts("");
299
test("\\")
300
.starts("\\");
301
test("C:\\foo\\bar")
302
.starts("C:\\")
303
.starts("C:\\foo")
304
.starts("C:\\FOO")
305
.starts("C:\\foo\\bar")
306
.starts("C:\\Foo\\Bar")
307
.notStarts("C:")
308
.notStarts("C")
309
.notStarts("C:foo")
310
.notStarts("");
311
test("\\foo\\bar")
312
.starts("\\")
313
.starts("\\foo")
314
.starts("\\foO")
315
.starts("\\foo\\bar")
316
.starts("\\fOo\\BaR")
317
.notStarts("foo")
318
.notStarts("foo\\bar")
319
.notStarts("");
320
test("foo\\bar")
321
.starts("foo")
322
.starts("foo\\bar")
323
.notStarts("\\")
324
.notStarts("");
325
test("\\\\server\\share")
326
.starts("\\\\server\\share")
327
.starts("\\\\server\\share\\")
328
.notStarts("\\")
329
.notStarts("");
330
test("")
331
.starts("")
332
.notStarts("\\");
333
334
// endsWith
335
test("C:\\")
336
.ends("C:\\")
337
.ends("c:\\")
338
.notEnds("\\")
339
.notEnds("");
340
test("C:")
341
.ends("C:")
342
.ends("c:")
343
.notEnds("");
344
test("\\")
345
.ends("\\")
346
.notEnds("");
347
test("C:\\foo\\bar")
348
.ends("bar")
349
.ends("BAR")
350
.ends("foo\\bar")
351
.ends("Foo\\Bar")
352
.ends("C:\\foo\\bar")
353
.ends("c:\\foO\\baR")
354
.notEnds("r")
355
.notEnds("\\foo\\bar")
356
.notEnds("");
357
test("\\foo\\bar")
358
.ends("bar")
359
.ends("BaR")
360
.ends("foo\\bar")
361
.ends("foO\\baR")
362
.ends("\\foo\\bar")
363
.ends("\\Foo\\Bar")
364
.notEnds("oo\\bar")
365
.notEnds("");
366
test("foo\\bar")
367
.ends("bar")
368
.ends("BAR")
369
.ends("foo\\bar")
370
.ends("Foo\\Bar")
371
.notEnds("ar")
372
.notEnds("");
373
test("\\\\server\\share")
374
.ends("\\\\server\\share")
375
.ends("\\\\server\\share\\")
376
.notEnds("shared")
377
.notEnds("\\")
378
.notEnds("");
379
test("")
380
.ends("")
381
.notEnds("\\");
382
383
// elements
384
test("C:\\a\\b\\c")
385
.element(0, "a")
386
.element(1, "b")
387
.element(2, "c");
388
test("foo.bar\\gus.alice")
389
.element(0, "foo.bar")
390
.element(1, "gus.alice");
391
test("")
392
.element(0, "");
393
394
// subpath
395
test("C:\\foo")
396
.subpath(0, 1, "foo");
397
test("C:foo")
398
.subpath(0, 1, "foo");
399
test("foo")
400
.subpath(0, 1, "foo");
401
test("C:\\foo\\bar\\gus")
402
.subpath(0, 1, "foo")
403
.subpath(0, 2, "foo\\bar")
404
.subpath(0, 3, "foo\\bar\\gus")
405
.subpath(1, 2, "bar")
406
.subpath(1, 3, "bar\\gus")
407
.subpath(2, 3, "gus");
408
test("\\\\server\\share\\foo")
409
.subpath(0, 1, "foo");
410
test("")
411
.subpath(0, 1, "");
412
413
// isAbsolute
414
test("foo").notAbsolute();
415
test("C:").notAbsolute();
416
test("C:\\").absolute();
417
test("C:\\abc").absolute();
418
test("\\\\server\\share\\").absolute();
419
test("").notAbsolute();
420
421
// resolve
422
test("C:\\")
423
.resolve("foo", "C:\\foo")
424
.resolve("D:\\bar", "D:\\bar")
425
.resolve("\\\\server\\share\\bar", "\\\\server\\share\\bar")
426
.resolve("C:foo", "C:\\foo")
427
.resolve("D:foo", "D:foo")
428
.resolve("", "C:\\");
429
test("\\")
430
.resolve("foo", "\\foo")
431
.resolve("D:bar", "D:bar")
432
.resolve("C:\\bar", "C:\\bar")
433
.resolve("\\\\server\\share\\bar", "\\\\server\\share\\bar")
434
.resolve("\\foo", "\\foo")
435
.resolve("", "\\");
436
test("\\foo")
437
.resolve("bar", "\\foo\\bar")
438
.resolve("D:bar", "D:bar")
439
.resolve("C:\\bar", "C:\\bar")
440
.resolve("\\\\server\\share\\bar", "\\\\server\\share\\bar")
441
.resolve("\\bar", "\\bar")
442
.resolve("", "\\foo");
443
test("foo")
444
.resolve("bar", "foo\\bar")
445
.resolve("D:\\bar", "D:\\bar")
446
.resolve("\\\\server\\share\\bar", "\\\\server\\share\\bar")
447
.resolve("C:bar", "C:bar")
448
.resolve("D:foo", "D:foo")
449
.resolve("", "foo");
450
test("C:")
451
.resolve("foo", "C:foo")
452
.resolve("", "C:");
453
test("\\\\server\\share\\foo")
454
.resolve("bar", "\\\\server\\share\\foo\\bar")
455
.resolve("\\bar", "\\\\server\\share\\bar")
456
.resolve("D:\\bar", "D:\\bar")
457
.resolve("\\\\other\\share\\bar", "\\\\other\\share\\bar")
458
.resolve("D:bar", "D:bar")
459
.resolve("", "\\\\server\\share\\foo");
460
test("")
461
.resolve("", "")
462
.resolve("foo", "foo")
463
.resolve("C:\\", "C:\\")
464
.resolve("C:foo", "C:foo")
465
.resolve("\\\\server\\share\\bar", "\\\\server\\share\\bar");
466
467
// resolveSibling
468
test("foo")
469
.resolveSibling("bar", "bar")
470
.resolveSibling("D:\\bar", "D:\\bar")
471
.resolveSibling("\\\\server\\share\\bar", "\\\\server\\share\\bar")
472
.resolveSibling("C:bar", "C:bar")
473
.resolveSibling("D:foo", "D:foo")
474
.resolveSibling("", "");
475
test("foo\\bar")
476
.resolveSibling("gus", "foo\\gus")
477
.resolveSibling("D:\\bar", "D:\\bar")
478
.resolveSibling("\\\\server\\share\\bar", "\\\\server\\share\\bar")
479
.resolveSibling("C:bar", "C:bar")
480
.resolveSibling("D:foo", "D:foo")
481
.resolveSibling("", "foo");
482
test("C:\\foo")
483
.resolveSibling("gus", "C:\\gus")
484
.resolveSibling("D:\\bar", "D:\\bar")
485
.resolveSibling("\\\\server\\share\\bar", "\\\\server\\share\\bar")
486
.resolveSibling("C:bar", "C:\\bar")
487
.resolveSibling("D:foo", "D:foo")
488
.resolveSibling("", "C:\\");
489
test("C:\\foo\\bar")
490
.resolveSibling("gus", "C:\\foo\\gus")
491
.resolveSibling("D:\\bar", "D:\\bar")
492
.resolveSibling("\\\\server\\share\\bar", "\\\\server\\share\\bar")
493
.resolveSibling("C:bar", "C:\\foo\\bar")
494
.resolveSibling("D:foo", "D:foo")
495
.resolveSibling("", "C:\\foo");
496
test("\\\\server\\share\\foo")
497
.resolveSibling("bar", "\\\\server\\share\\bar")
498
.resolveSibling("\\bar", "\\\\server\\share\\bar")
499
.resolveSibling("D:\\bar", "D:\\bar")
500
.resolveSibling("\\\\other\\share\\bar", "\\\\other\\share\\bar")
501
.resolveSibling("D:bar", "D:bar")
502
.resolveSibling("", "\\\\server\\share\\");
503
test("")
504
.resolveSibling("", "")
505
.resolveSibling("foo", "foo")
506
.resolveSibling("C:\\", "C:\\");
507
508
// relativize
509
test("foo\\bar")
510
.relativize("foo\\bar", "")
511
.relativize("foo", "..");
512
test("C:\\a\\b\\c")
513
.relativize("C:\\a", "..\\..")
514
.relativize("C:\\a\\b\\c", "");
515
test("\\\\server\\share\\foo")
516
.relativize("\\\\server\\share\\bar", "..\\bar")
517
.relativize("\\\\server\\share\\foo", "");
518
test("")
519
.relativize("", "");
520
521
// normalize
522
test("C:\\")
523
.normalize("C:\\");
524
test("C:\\.")
525
.normalize("C:\\");
526
test("C:\\..")
527
.normalize("C:\\");
528
test("\\\\server\\share")
529
.normalize("\\\\server\\share\\");
530
test("\\\\server\\share\\.")
531
.normalize("\\\\server\\share\\");
532
test("\\\\server\\share\\..")
533
.normalize("\\\\server\\share\\");
534
test("C:")
535
.normalize("C:");
536
test("C:.")
537
.normalize("C:");
538
test("C:..")
539
.normalize("C:..");
540
test("\\")
541
.normalize("\\");
542
test("\\.")
543
.normalize("\\");
544
test("\\..")
545
.normalize("\\");
546
test("foo")
547
.normalize("foo");
548
test("foo\\.")
549
.normalize("foo");
550
test("foo\\..")
551
.normalize("");
552
test("C:\\foo")
553
.normalize("C:\\foo");
554
test("C:\\foo\\.")
555
.normalize("C:\\foo");
556
test("C:\\.\\foo")
557
.normalize("C:\\foo");
558
test("C:\\foo\\..")
559
.normalize("C:\\");
560
test("C:\\..\\foo")
561
.normalize("C:\\foo");
562
test("\\\\server\\share\\foo")
563
.normalize("\\\\server\\share\\foo");
564
test("\\\\server\\share\\foo\\.")
565
.normalize("\\\\server\\share\\foo");
566
test("\\\\server\\share\\.\\foo")
567
.normalize("\\\\server\\share\\foo");
568
test("\\\\server\\share\\foo\\..")
569
.normalize("\\\\server\\share\\");
570
test("\\\\server\\share\\..\\foo")
571
.normalize("\\\\server\\share\\foo");
572
test("C:foo")
573
.normalize("C:foo");
574
test("C:foo\\.")
575
.normalize("C:foo");
576
test("C:.\\foo")
577
.normalize("C:foo");
578
test("C:foo\\..")
579
.normalize("C:");
580
test("C:..\\foo")
581
.normalize("C:..\\foo");
582
test("\\foo")
583
.normalize("\\foo");
584
test("\\foo\\.")
585
.normalize("\\foo");
586
test("\\.\\foo")
587
.normalize("\\foo");
588
test("\\foo\\..")
589
.normalize("\\");
590
test("\\..\\foo")
591
.normalize("\\foo");
592
test(".")
593
.normalize("");
594
test("..")
595
.normalize("..");
596
test("\\..\\..")
597
.normalize("\\");
598
test("..\\..\\foo")
599
.normalize("..\\..\\foo");
600
test("foo\\bar\\..")
601
.normalize("foo");
602
test("foo\\bar\\.\\..")
603
.normalize("foo");
604
test("foo\\bar\\gus\\..\\..")
605
.normalize("foo");
606
test(".\\foo\\.\\bar\\.\\gus\\..\\.\\..")
607
.normalize("foo");
608
test("")
609
.normalize("");
610
611
// UNC corner cases
612
test("\\\\server\\share\\")
613
.root("\\\\server\\share\\")
614
.parent(null)
615
.name(null);
616
test("\\\\server")
617
.invalid();
618
test("\\\\server\\")
619
.invalid();
620
test("\\\\server\\share")
621
.root("\\\\server\\share\\")
622
.parent(null)
623
.name(null);
624
625
// invalid
626
test(":\\foo")
627
.invalid();
628
test("C::")
629
.invalid();
630
test("C:\\?") // invalid character
631
.invalid();
632
test("C:\\*") // invalid character
633
.invalid();
634
test("C:\\abc\u0001\\foo")
635
.invalid();
636
test("C:\\\u0019\\foo")
637
.invalid();
638
test("\\\\server\u0019\\share")
639
.invalid();
640
test("\\\\server\\share\u0019")
641
.invalid();
642
test("foo\u0000\bar")
643
.invalid();
644
test("C:\\foo ") // trailing space
645
.invalid();
646
test("C:\\foo \\bar")
647
.invalid();
648
//test("C:\\foo.") // trailing dot
649
//.invalid();
650
//test("C:\\foo...\\bar")
651
//.invalid();
652
653
// normalization at construction time (remove redundant and replace slashes)
654
test("C:/a/b/c")
655
.string("C:\\a\\b\\c")
656
.root("C:\\")
657
.parent("C:\\a\\b");
658
test("C://a//b//c")
659
.string("C:\\a\\b\\c")
660
.root("C:\\")
661
.parent("C:\\a\\b");
662
663
// hashCode
664
header("hashCode");
665
int h1 = test("C:\\foo").path().hashCode();
666
int h2 = test("c:\\FOO").path().hashCode();
667
if (h1 != h2)
668
throw new RuntimeException("PathOps failed");
669
}
670
671
static void doUnixTests() {
672
header("Unix specific tests");
673
674
// construction
675
test("/")
676
.string("/");
677
test("/", "")
678
.string("/");
679
test("/", "foo")
680
.string("/foo");
681
test("/", "/foo")
682
.string("/foo");
683
test("/", "foo/")
684
.string("/foo");
685
test("foo", "bar", "gus")
686
.string("foo/bar/gus");
687
test("")
688
.string("");
689
test("", "/")
690
.string("/");
691
test("", "foo", "", "bar", "", "/gus")
692
.string("foo/bar/gus");
693
694
// all components
695
test("/a/b/c")
696
.root("/")
697
.parent("/a/b")
698
.name("c");
699
700
// root component only
701
test("/")
702
.root("/")
703
.parent(null)
704
.name(null);
705
706
// no root component
707
test("a/b")
708
.root(null)
709
.parent("a")
710
.name("b");
711
712
// name component only
713
test("foo")
714
.root(null)
715
.parent(null)
716
.name("foo");
717
test("")
718
.root(null)
719
.parent(null)
720
.name("");
721
722
// startsWith
723
test("/")
724
.starts("/")
725
.notStarts("")
726
.notStarts("/foo");
727
test("/foo")
728
.starts("/")
729
.starts("/foo")
730
.notStarts("/f");
731
test("/foo/bar")
732
.starts("/")
733
.starts("/foo")
734
.starts("/foo/bar")
735
.notStarts("/f")
736
.notStarts("foo")
737
.notStarts("foo/bar");
738
test("foo")
739
.starts("foo")
740
.notStarts("")
741
.notStarts("f");
742
test("foo/bar")
743
.starts("foo")
744
.starts("foo/bar")
745
.notStarts("f")
746
.notStarts("/foo")
747
.notStarts("/foo/bar");
748
test("")
749
.starts("")
750
.notStarts("/");
751
752
// endsWith
753
test("/")
754
.ends("/")
755
.notEnds("")
756
.notEnds("foo")
757
.notEnds("/foo");
758
test("/foo")
759
.ends("foo")
760
.ends("/foo")
761
.notEnds("fool");
762
test("/foo/bar")
763
.ends("bar")
764
.ends("foo/bar")
765
.ends("/foo/bar")
766
.notEnds("ar")
767
.notEnds("barack")
768
.notEnds("/bar")
769
.notEnds("o/bar");
770
test("foo")
771
.ends("foo")
772
.notEnds("")
773
.notEnds("oo")
774
.notEnds("oola");
775
test("foo/bar")
776
.ends("bar")
777
.ends("foo/bar")
778
.notEnds("r")
779
.notEnds("barmaid")
780
.notEnds("/bar");
781
test("foo/bar/gus")
782
.ends("gus")
783
.ends("bar/gus")
784
.ends("foo/bar/gus")
785
.notEnds("g")
786
.notEnds("/gus")
787
.notEnds("r/gus")
788
.notEnds("barack/gus")
789
.notEnds("bar/gust");
790
test("")
791
.ends("")
792
.notEnds("/");
793
794
// elements
795
test("a/b/c")
796
.element(0, "a")
797
.element(1, "b")
798
.element(2, "c");
799
test("")
800
.element(0, "");
801
802
// subpath
803
test("/foo")
804
.subpath(0, 1, "foo");
805
test("foo")
806
.subpath(0, 1, "foo");
807
test("/foo/bar")
808
.subpath(0, 1, "foo")
809
.subpath(1, 2, "bar")
810
.subpath(0, 2, "foo/bar");
811
test("foo/bar")
812
.subpath(0, 1, "foo")
813
.subpath(1, 2, "bar")
814
.subpath(0, 2, "foo/bar");
815
test("/foo/bar/gus")
816
.subpath(0, 1, "foo")
817
.subpath(1, 2, "bar")
818
.subpath(2, 3, "gus")
819
.subpath(0, 2, "foo/bar")
820
.subpath(1, 3, "bar/gus")
821
.subpath(0, 3, "foo/bar/gus");
822
test("foo/bar/gus")
823
.subpath(0, 1, "foo")
824
.subpath(1, 2, "bar")
825
.subpath(2, 3, "gus")
826
.subpath(0, 2, "foo/bar")
827
.subpath(1, 3, "bar/gus")
828
.subpath(0, 3, "foo/bar/gus");
829
test("")
830
.subpath(0, 1, "");
831
832
// isAbsolute
833
test("/")
834
.absolute();
835
test("/tmp")
836
.absolute();
837
test("tmp")
838
.notAbsolute();
839
test("")
840
.notAbsolute();
841
842
843
// resolve
844
test("/tmp")
845
.resolve("foo", "/tmp/foo")
846
.resolve("/foo", "/foo")
847
.resolve("", "/tmp");
848
test("tmp")
849
.resolve("foo", "tmp/foo")
850
.resolve("/foo", "/foo")
851
.resolve("", "tmp");
852
test("")
853
.resolve("", "")
854
.resolve("foo", "foo")
855
.resolve("/foo", "/foo");
856
857
// resolveSibling
858
test("foo")
859
.resolveSibling("bar", "bar")
860
.resolveSibling("/bar", "/bar")
861
.resolveSibling("", "");
862
test("foo/bar")
863
.resolveSibling("gus", "foo/gus")
864
.resolveSibling("/gus", "/gus")
865
.resolveSibling("", "foo");
866
test("/foo")
867
.resolveSibling("gus", "/gus")
868
.resolveSibling("/gus", "/gus")
869
.resolveSibling("", "/");
870
test("/foo/bar")
871
.resolveSibling("gus", "/foo/gus")
872
.resolveSibling("/gus", "/gus")
873
.resolveSibling("", "/foo");
874
test("")
875
.resolveSibling("foo", "foo")
876
.resolveSibling("/foo", "/foo")
877
.resolve("", "");
878
879
// relativize
880
test("/a/b/c")
881
.relativize("/a/b/c", "")
882
.relativize("/a/b/c/d/e", "d/e")
883
.relativize("/a/x", "../../x")
884
.relativize("/x", "../../../x");
885
test("a/b/c")
886
.relativize("a/b/c/d", "d")
887
.relativize("a/x", "../../x")
888
.relativize("x", "../../../x")
889
.relativize("", "../../..");
890
test("")
891
.relativize("a", "a")
892
.relativize("a/b/c", "a/b/c")
893
.relativize("", "");
894
895
// normalize
896
test("/")
897
.normalize("/");
898
test("foo")
899
.normalize("foo");
900
test("/foo")
901
.normalize("/foo");
902
test("")
903
.normalize("");
904
test(".")
905
.normalize("");
906
test("..")
907
.normalize("..");
908
test("/..")
909
.normalize("/");
910
test("/../..")
911
.normalize("/");
912
test("foo/.")
913
.normalize("foo");
914
test("./foo")
915
.normalize("foo");
916
test("foo/..")
917
.normalize("");
918
test("../foo")
919
.normalize("../foo");
920
test("../../foo")
921
.normalize("../../foo");
922
test("foo/bar/..")
923
.normalize("foo");
924
test("foo/bar/gus/../..")
925
.normalize("foo");
926
test("/foo/bar/gus/../..")
927
.normalize("/foo");
928
929
// invalid
930
test("foo\u0000bar")
931
.invalid();
932
test("\u0000foo")
933
.invalid();
934
test("bar\u0000")
935
.invalid();
936
test("//foo\u0000bar")
937
.invalid();
938
test("//\u0000foo")
939
.invalid();
940
test("//bar\u0000")
941
.invalid();
942
943
// normalization of input
944
test("//foo//bar")
945
.string("/foo/bar")
946
.root("/")
947
.parent("/foo")
948
.name("bar");
949
}
950
951
static void npes() {
952
header("NullPointerException");
953
954
Path path = FileSystems.getDefault().getPath("foo");
955
956
try {
957
path.resolve((String)null);
958
throw new RuntimeException("NullPointerException not thrown");
959
} catch (NullPointerException npe) {
960
}
961
962
try {
963
path.relativize(null);
964
throw new RuntimeException("NullPointerException not thrown");
965
} catch (NullPointerException npe) {
966
}
967
968
try {
969
path.compareTo(null);
970
throw new RuntimeException("NullPointerException not thrown");
971
} catch (NullPointerException npe) {
972
}
973
974
try {
975
path.startsWith((Path)null);
976
throw new RuntimeException("NullPointerException not thrown");
977
} catch (NullPointerException npe) {
978
}
979
980
try {
981
path.endsWith((Path)null);
982
throw new RuntimeException("NullPointerException not thrown");
983
} catch (NullPointerException npe) {
984
}
985
986
}
987
988
public static void main(String[] args) {
989
// all platforms
990
npes();
991
992
// operating system specific
993
String osname = System.getProperty("os.name");
994
if (osname.startsWith("Windows")) {
995
doWindowsTests();
996
} else {
997
doUnixTests();
998
}
999
1000
}
1001
}
1002
1003