0N/A/*
3909N/A * Copyright (c) 2008, 2011, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation.
0N/A *
2362N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
0N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
0N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
2362N/A */
2362N/A
0N/A/* @test
0N/A * @bug 4313887 6838333 6925932 7006126
0N/A * @summary Unit test for java.nio.file.Path path operations
0N/A */
0N/A
0N/Aimport java.nio.file.*;
0N/A
0N/Apublic class PathOps {
0N/A
0N/A static final java.io.PrintStream out = System.out;
1864N/A
0N/A private String input;
0N/A private Path path;
0N/A private Exception exc;
0N/A
0N/A private PathOps(String first, String... more) {
0N/A out.println();
0N/A input = first;
0N/A try {
0N/A path = FileSystems.getDefault().getPath(first, more);
0N/A out.format("%s -> %s", first, path);
0N/A } catch (Exception x) {
0N/A exc = x;
0N/A out.format("%s -> %s", first, x);
0N/A }
0N/A out.println();
0N/A }
0N/A
0N/A Path path() {
0N/A return path;
0N/A }
28N/A
28N/A void fail() {
28N/A throw new RuntimeException("PathOps failed");
28N/A }
0N/A
0N/A void checkPath() {
0N/A if (path == null) {
0N/A throw new InternalError("path is null");
0N/A }
1864N/A }
1864N/A
0N/A void check(Object result, String expected) {
0N/A out.format("\tExpected: %s\n", expected);
0N/A out.format("\tActual: %s\n", result);
0N/A if (result == null) {
0N/A if (expected == null) return;
0N/A } else {
0N/A // compare string representations
0N/A if (expected != null && result.toString().equals(expected.toString()))
0N/A return;
0N/A }
0N/A fail();
0N/A }
0N/A
0N/A void check(Object result, boolean expected) {
0N/A check(result, Boolean.toString(expected));
0N/A }
0N/A
0N/A PathOps root(String expected) {
0N/A out.println("check root");
0N/A checkPath();
0N/A check(path.getRoot(), expected);
0N/A return this;
0N/A }
0N/A
0N/A PathOps parent(String expected) {
0N/A out.println("check parent");
0N/A checkPath();
0N/A check(path.getParent(), expected);
0N/A return this;
0N/A }
0N/A
0N/A PathOps name(String expected) {
0N/A out.println("check name");
0N/A checkPath();
0N/A check(path.getFileName(), expected);
0N/A return this;
28N/A }
28N/A
0N/A PathOps element(int index, String expected) {
0N/A out.format("check element %d\n", index);
0N/A checkPath();
0N/A check(path.getName(index), expected);
0N/A return this;
0N/A }
0N/A
0N/A PathOps subpath(int startIndex, int endIndex, String expected) {
0N/A out.format("test subpath(%d,%d)\n", startIndex, endIndex);
0N/A checkPath();
0N/A check(path.subpath(startIndex, endIndex), expected);
0N/A return this;
0N/A }
0N/A
0N/A PathOps starts(String prefix) {
0N/A out.format("test startsWith with %s\n", prefix);
0N/A checkPath();
0N/A Path s = FileSystems.getDefault().getPath(prefix);
0N/A check(path.startsWith(s), true);
0N/A return this;
0N/A }
0N/A
0N/A PathOps notStarts(String prefix) {
0N/A out.format("test not startsWith with %s\n", prefix);
0N/A checkPath();
0N/A Path s = FileSystems.getDefault().getPath(prefix);
0N/A check(path.startsWith(s), false);
0N/A return this;
0N/A }
0N/A
0N/A PathOps ends(String suffix) {
0N/A out.format("test endsWith %s\n", suffix);
0N/A checkPath();
0N/A Path s = FileSystems.getDefault().getPath(suffix);
0N/A check(path.endsWith(s), true);
0N/A return this;
0N/A }
0N/A
0N/A PathOps notEnds(String suffix) {
0N/A out.format("test not endsWith %s\n", suffix);
0N/A checkPath();
0N/A Path s = FileSystems.getDefault().getPath(suffix);
0N/A check(path.endsWith(s), false);
0N/A return this;
0N/A }
0N/A
0N/A PathOps absolute() {
0N/A out.println("check path is absolute");
0N/A checkPath();
0N/A check(path.isAbsolute(), true);
0N/A return this;
0N/A }
0N/A
0N/A PathOps notAbsolute() {
0N/A out.println("check path is not absolute");
0N/A checkPath();
0N/A check(path.isAbsolute(), false);
0N/A return this;
0N/A }
28N/A
28N/A PathOps resolve(String other, String expected) {
28N/A out.format("test resolve %s\n", other);
0N/A checkPath();
0N/A check(path.resolve(other), expected);
0N/A return this;
0N/A }
0N/A
0N/A PathOps resolveSibling(String other, String expected) {
0N/A out.format("test resolveSibling %s\n", other);
0N/A checkPath();
0N/A check(path.resolveSibling(other), expected);
0N/A return this;
0N/A }
0N/A
0N/A PathOps relativize(String other, String expected) {
0N/A out.format("test relativize %s\n", other);
0N/A checkPath();
0N/A Path that = FileSystems.getDefault().getPath(other);
0N/A check(path.relativize(that), expected);
0N/A return this;
0N/A }
0N/A
0N/A PathOps normalize(String expected) {
0N/A out.println("check normalized path");
0N/A checkPath();
0N/A check(path.normalize(), expected);
0N/A return this;
0N/A }
0N/A
0N/A PathOps string(String expected) {
0N/A out.println("check string representation");
0N/A checkPath();
0N/A check(path, expected);
0N/A return this;
0N/A }
0N/A
0N/A PathOps invalid() {
0N/A if (!(exc instanceof InvalidPathException)) {
0N/A out.println("InvalidPathException not thrown as expected");
0N/A fail();
0N/A }
0N/A return this;
0N/A }
0N/A
0N/A static PathOps test(String first, String... more) {
0N/A return new PathOps(first, more);
0N/A }
0N/A
0N/A // -- PathOpss --
0N/A
0N/A static void header(String s) {
0N/A out.println();
0N/A out.println();
0N/A out.println("-- " + s + " --");
0N/A }
0N/A
0N/A static void doWindowsTests() {
0N/A header("Windows specific tests");
0N/A
0N/A // construction
0N/A test("C:\\")
0N/A .string("C:\\");
0N/A test("C:\\", "")
0N/A .string("C:\\");
0N/A test("C:\\", "foo")
0N/A .string("C:\\foo");
0N/A test("C:\\", "\\foo")
0N/A .string("C:\\foo");
0N/A test("C:\\", "foo\\")
0N/A .string("C:\\foo");
0N/A test("foo", "bar", "gus")
0N/A .string("foo\\bar\\gus");
0N/A test("")
0N/A .string("");
0N/A test("", "C:\\")
0N/A .string("C:\\");
0N/A test("", "foo", "", "bar", "", "\\gus")
0N/A .string("foo\\bar\\gus");
0N/A
0N/A // all components present
0N/A test("C:\\a\\b\\c")
0N/A .root("C:\\")
0N/A .parent("C:\\a\\b")
0N/A .name("c");
0N/A test("C:a\\b\\c")
0N/A .root("C:")
0N/A .parent("C:a\\b")
0N/A .name("c");
0N/A test("\\\\server\\share\\a")
0N/A .root("\\\\server\\share\\")
0N/A .parent("\\\\server\\share\\")
0N/A .name("a");
0N/A
0N/A // root component only
0N/A test("C:\\")
0N/A .root("C:\\")
0N/A .parent(null)
0N/A .name(null);
0N/A test("C:")
0N/A .root("C:")
0N/A .parent(null)
0N/A .name(null);
0N/A test("\\\\server\\share\\")
0N/A .root("\\\\server\\share\\")
0N/A .parent(null)
0N/A .name(null);
0N/A
0N/A // no root component
0N/A test("a\\b")
0N/A .root(null)
0N/A .parent("a")
0N/A .name("b");
0N/A
0N/A // name component only
0N/A test("foo")
0N/A .root(null)
0N/A .parent(null)
0N/A .name("foo");
0N/A test("")
0N/A .root(null)
0N/A .parent(null)
0N/A .name("");
0N/A
0N/A // startsWith
0N/A test("C:\\")
0N/A .starts("C:\\")
0N/A .starts("c:\\")
0N/A .notStarts("C")
0N/A .notStarts("C:")
0N/A .notStarts("");
0N/A test("C:")
0N/A .starts("C:")
0N/A .starts("c:")
0N/A .notStarts("C")
0N/A .notStarts("");
0N/A test("\\")
0N/A .starts("\\");
0N/A test("C:\\foo\\bar")
0N/A .starts("C:\\")
0N/A .starts("C:\\foo")
0N/A .starts("C:\\FOO")
0N/A .starts("C:\\foo\\bar")
0N/A .starts("C:\\Foo\\Bar")
0N/A .notStarts("C:")
0N/A .notStarts("C")
0N/A .notStarts("C:foo")
0N/A .notStarts("");
0N/A test("\\foo\\bar")
0N/A .starts("\\")
0N/A .starts("\\foo")
0N/A .starts("\\foO")
0N/A .starts("\\foo\\bar")
0N/A .starts("\\fOo\\BaR")
0N/A .notStarts("foo")
0N/A .notStarts("foo\\bar")
0N/A .notStarts("");
0N/A test("foo\\bar")
28N/A .starts("foo")
0N/A .starts("foo\\bar")
0N/A .notStarts("\\")
0N/A .notStarts("");
0N/A test("\\\\server\\share")
0N/A .starts("\\\\server\\share")
0N/A .starts("\\\\server\\share\\")
0N/A .notStarts("\\")
0N/A .notStarts("");
0N/A test("")
0N/A .starts("")
0N/A .notStarts("\\");
0N/A
0N/A // endsWith
0N/A test("C:\\")
0N/A .ends("C:\\")
0N/A .ends("c:\\")
0N/A .notEnds("\\")
0N/A .notEnds("");
0N/A test("C:")
0N/A .ends("C:")
0N/A .ends("c:")
0N/A .notEnds("");
0N/A test("\\")
0N/A .ends("\\")
0N/A .notEnds("");
0N/A test("C:\\foo\\bar")
0N/A .ends("bar")
0N/A .ends("BAR")
0N/A .ends("foo\\bar")
0N/A .ends("Foo\\Bar")
0N/A .ends("C:\\foo\\bar")
0N/A .ends("c:\\foO\\baR")
0N/A .notEnds("r")
0N/A .notEnds("\\foo\\bar")
0N/A .notEnds("");
3323N/A test("\\foo\\bar")
0N/A .ends("bar")
0N/A .ends("BaR")
0N/A .ends("foo\\bar")
0N/A .ends("foO\\baR")
0N/A .ends("\\foo\\bar")
0N/A .ends("\\Foo\\Bar")
0N/A .notEnds("oo\\bar")
0N/A .notEnds("");
0N/A test("foo\\bar")
0N/A .ends("bar")
0N/A .ends("BAR")
0N/A .ends("foo\\bar")
0N/A .ends("Foo\\Bar")
0N/A .notEnds("ar")
0N/A .notEnds("");
0N/A test("\\\\server\\share")
0N/A .ends("\\\\server\\share")
0N/A .ends("\\\\server\\share\\")
0N/A .notEnds("shared")
0N/A .notEnds("\\")
0N/A .notEnds("");
0N/A test("")
0N/A .ends("")
0N/A .notEnds("\\");
0N/A
0N/A // elements
0N/A test("C:\\a\\b\\c")
0N/A .element(0, "a")
0N/A .element(1, "b")
0N/A .element(2, "c");
0N/A test("foo.bar\\gus.alice")
0N/A .element(0, "foo.bar")
0N/A .element(1, "gus.alice");
0N/A test("")
0N/A .element(0, "");
0N/A
0N/A // subpath
0N/A test("C:\\foo")
0N/A .subpath(0, 1, "foo");
0N/A test("C:foo")
0N/A .subpath(0, 1, "foo");
0N/A test("foo")
0N/A .subpath(0, 1, "foo");
0N/A test("C:\\foo\\bar\\gus")
0N/A .subpath(0, 1, "foo")
0N/A .subpath(0, 2, "foo\\bar")
0N/A .subpath(0, 3, "foo\\bar\\gus")
0N/A .subpath(1, 2, "bar")
0N/A .subpath(1, 3, "bar\\gus")
0N/A .subpath(2, 3, "gus");
0N/A test("\\\\server\\share\\foo")
0N/A .subpath(0, 1, "foo");
0N/A test("")
0N/A .subpath(0, 1, "");
0N/A
0N/A // isAbsolute
0N/A test("foo").notAbsolute();
0N/A test("C:").notAbsolute();
0N/A test("C:\\").absolute();
0N/A test("C:\\abc").absolute();
0N/A test("\\\\server\\share\\").absolute();
0N/A test("").notAbsolute();
0N/A
0N/A // resolve
0N/A test("C:\\")
28N/A .resolve("foo", "C:\\foo")
0N/A .resolve("D:\\bar", "D:\\bar")
0N/A .resolve("\\\\server\\share\\bar", "\\\\server\\share\\bar")
0N/A .resolve("C:foo", "C:\\foo")
0N/A .resolve("D:foo", "D:foo")
0N/A .resolve("", "C:\\");
0N/A test("\\")
0N/A .resolve("foo", "\\foo")
0N/A .resolve("D:bar", "D:bar")
0N/A .resolve("C:\\bar", "C:\\bar")
0N/A .resolve("\\\\server\\share\\bar", "\\\\server\\share\\bar")
0N/A .resolve("\\foo", "\\foo")
0N/A .resolve("", "\\");
0N/A test("\\foo")
28N/A .resolve("bar", "\\foo\\bar")
28N/A .resolve("D:bar", "D:bar")
0N/A .resolve("C:\\bar", "C:\\bar")
0N/A .resolve("\\\\server\\share\\bar", "\\\\server\\share\\bar")
0N/A .resolve("\\bar", "\\bar")
0N/A .resolve("", "\\foo");
0N/A test("foo")
0N/A .resolve("bar", "foo\\bar")
0N/A .resolve("D:\\bar", "D:\\bar")
0N/A .resolve("\\\\server\\share\\bar", "\\\\server\\share\\bar")
0N/A .resolve("C:bar", "C:bar")
0N/A .resolve("D:foo", "D:foo")
0N/A .resolve("", "foo");
0N/A test("C:")
0N/A .resolve("foo", "C:foo")
0N/A .resolve("", "C:");
0N/A test("\\\\server\\share\\foo")
0N/A .resolve("bar", "\\\\server\\share\\foo\\bar")
0N/A .resolve("\\bar", "\\\\server\\share\\bar")
0N/A .resolve("D:\\bar", "D:\\bar")
0N/A .resolve("\\\\other\\share\\bar", "\\\\other\\share\\bar")
0N/A .resolve("D:bar", "D:bar")
0N/A .resolve("", "\\\\server\\share\\foo");
0N/A test("")
0N/A .resolve("", "")
0N/A .resolve("foo", "foo")
0N/A .resolve("C:\\", "C:\\")
0N/A .resolve("C:foo", "C:foo")
0N/A .resolve("\\\\server\\share\\bar", "\\\\server\\share\\bar");
0N/A
0N/A // resolveSibling
0N/A test("foo")
0N/A .resolveSibling("bar", "bar")
0N/A .resolveSibling("D:\\bar", "D:\\bar")
0N/A .resolveSibling("\\\\server\\share\\bar", "\\\\server\\share\\bar")
0N/A .resolveSibling("C:bar", "C:bar")
0N/A .resolveSibling("D:foo", "D:foo")
0N/A .resolveSibling("", "");
0N/A test("foo\\bar")
0N/A .resolveSibling("gus", "foo\\gus")
0N/A .resolveSibling("D:\\bar", "D:\\bar")
0N/A .resolveSibling("\\\\server\\share\\bar", "\\\\server\\share\\bar")
0N/A .resolveSibling("C:bar", "C:bar")
0N/A .resolveSibling("D:foo", "D:foo")
0N/A .resolveSibling("", "foo");
0N/A test("C:\\foo")
0N/A .resolveSibling("gus", "C:\\gus")
0N/A .resolveSibling("D:\\bar", "D:\\bar")
0N/A .resolveSibling("\\\\server\\share\\bar", "\\\\server\\share\\bar")
0N/A .resolveSibling("C:bar", "C:\\bar")
0N/A .resolveSibling("D:foo", "D:foo")
0N/A .resolveSibling("", "C:\\");
0N/A test("C:\\foo\\bar")
0N/A .resolveSibling("gus", "C:\\foo\\gus")
0N/A .resolveSibling("D:\\bar", "D:\\bar")
0N/A .resolveSibling("\\\\server\\share\\bar", "\\\\server\\share\\bar")
0N/A .resolveSibling("C:bar", "C:\\foo\\bar")
0N/A .resolveSibling("D:foo", "D:foo")
0N/A .resolveSibling("", "C:\\foo");
0N/A test("\\\\server\\share\\foo")
0N/A .resolveSibling("bar", "\\\\server\\share\\bar")
0N/A .resolveSibling("\\bar", "\\\\server\\share\\bar")
0N/A .resolveSibling("D:\\bar", "D:\\bar")
0N/A .resolveSibling("\\\\other\\share\\bar", "\\\\other\\share\\bar")
0N/A .resolveSibling("D:bar", "D:bar")
28N/A .resolveSibling("", "\\\\server\\share\\");
28N/A test("")
0N/A .resolveSibling("", "")
0N/A .resolveSibling("foo", "foo")
0N/A .resolveSibling("C:\\", "C:\\");
0N/A
0N/A // relativize
0N/A test("foo\\bar")
3323N/A .relativize("foo\\bar", "")
0N/A .relativize("foo", "..");
0N/A test("C:\\a\\b\\c")
0N/A .relativize("C:\\a", "..\\..")
0N/A .relativize("C:\\a\\b\\c", "");
0N/A test("\\\\server\\share\\foo")
0N/A .relativize("\\\\server\\share\\bar", "..\\bar")
0N/A .relativize("\\\\server\\share\\foo", "");
0N/A test("")
0N/A .relativize("", "");
0N/A
0N/A // normalize
0N/A test("C:\\")
0N/A .normalize("C:\\");
0N/A test("C:\\.")
0N/A .normalize("C:\\");
0N/A test("C:\\..")
0N/A .normalize("C:\\");
28N/A test("\\\\server\\share")
0N/A .normalize("\\\\server\\share\\");
0N/A test("\\\\server\\share\\.")
0N/A .normalize("\\\\server\\share\\");
0N/A test("\\\\server\\share\\..")
0N/A .normalize("\\\\server\\share\\");
0N/A test("C:")
0N/A .normalize("C:");
0N/A test("C:.")
0N/A .normalize("C:");
0N/A test("C:..")
0N/A .normalize("C:..");
0N/A test("\\")
0N/A .normalize("\\");
0N/A test("\\.")
0N/A .normalize("\\");
0N/A test("\\..")
0N/A .normalize("\\");
0N/A test("foo")
0N/A .normalize("foo");
0N/A test("foo\\.")
0N/A .normalize("foo");
0N/A test("foo\\..")
0N/A .normalize("");
0N/A test("C:\\foo")
3323N/A .normalize("C:\\foo");
0N/A test("C:\\foo\\.")
0N/A .normalize("C:\\foo");
0N/A test("C:\\.\\foo")
0N/A .normalize("C:\\foo");
0N/A test("C:\\foo\\..")
0N/A .normalize("C:\\");
0N/A test("C:\\..\\foo")
0N/A .normalize("C:\\foo");
0N/A test("\\\\server\\share\\foo")
0N/A .normalize("\\\\server\\share\\foo");
0N/A test("\\\\server\\share\\foo\\.")
0N/A .normalize("\\\\server\\share\\foo");
0N/A test("\\\\server\\share\\.\\foo")
28N/A .normalize("\\\\server\\share\\foo");
28N/A test("\\\\server\\share\\foo\\..")
28N/A .normalize("\\\\server\\share\\");
3323N/A test("\\\\server\\share\\..\\foo")
0N/A .normalize("\\\\server\\share\\foo");
0N/A test("C:foo")
0N/A .normalize("C:foo");
3646N/A test("C:foo\\.")
3646N/A .normalize("C:foo");
3646N/A test("C:.\\foo")
0N/A .normalize("C:foo");
0N/A test("C:foo\\..")
0N/A .normalize("C:");
0N/A test("C:..\\foo")
0N/A .normalize("C:..\\foo");
0N/A test("\\foo")
0N/A .normalize("\\foo");
3323N/A test("\\foo\\.")
0N/A .normalize("\\foo");
0N/A test("\\.\\foo")
0N/A .normalize("\\foo");
0N/A test("\\foo\\..")
0N/A .normalize("\\");
0N/A test("\\..\\foo")
0N/A .normalize("\\foo");
0N/A test(".")
0N/A .normalize("");
0N/A test("..")
0N/A .normalize("..");
0N/A test("\\..\\..")
0N/A .normalize("\\");
0N/A test("..\\..\\foo")
0N/A .normalize("..\\..\\foo");
0N/A test("foo\\bar\\..")
0N/A .normalize("foo");
0N/A test("foo\\bar\\.\\..")
0N/A .normalize("foo");
0N/A test("foo\\bar\\gus\\..\\..")
0N/A .normalize("foo");
0N/A test(".\\foo\\.\\bar\\.\\gus\\..\\.\\..")
0N/A .normalize("foo");
0N/A test("")
0N/A .normalize("");
0N/A
0N/A // UNC corner cases
0N/A test("\\\\server\\share\\")
0N/A .root("\\\\server\\share\\")
28N/A .parent(null)
28N/A .name(null);
28N/A test("\\\\server")
0N/A .invalid();
0N/A test("\\\\server\\")
0N/A .invalid();
0N/A test("\\\\server\\share")
3646N/A .root("\\\\server\\share\\")
3646N/A .parent(null)
3646N/A .name(null);
0N/A
0N/A // invalid
0N/A test(":\\foo")
0N/A .invalid();
0N/A test("C::")
0N/A .invalid();
0N/A test("C:\\?") // invalid character
0N/A .invalid();
0N/A test("C:\\*") // invalid character
0N/A .invalid();
0N/A test("C:\\abc\u0001\\foo")
0N/A .invalid();
0N/A test("C:\\\u0019\\foo")
0N/A .invalid();
0N/A test("\\\\server\u0019\\share")
0N/A .invalid();
0N/A test("\\\\server\\share\u0019")
0N/A .invalid();
28N/A test("foo\u0000\bar")
0N/A .invalid();
0N/A test("C:\\foo ") // trailing space
0N/A .invalid();
28N/A test("C:\\foo \\bar")
28N/A .invalid();
28N/A //test("C:\\foo.") // trailing dot
3323N/A //.invalid();
0N/A //test("C:\\foo...\\bar")
0N/A //.invalid();
0N/A
0N/A // normalization at construction time (remove redundant and replace slashes)
0N/A test("C:/a/b/c")
0N/A .string("C:\\a\\b\\c")
0N/A .root("C:\\")
0N/A .parent("C:\\a\\b");
0N/A test("C://a//b//c")
0N/A .string("C:\\a\\b\\c")
0N/A .root("C:\\")
0N/A .parent("C:\\a\\b");
0N/A
0N/A // hashCode
0N/A header("hashCode");
0N/A int h1 = test("C:\\foo").path().hashCode();
0N/A int h2 = test("c:\\FOO").path().hashCode();
0N/A if (h1 != h2)
0N/A throw new RuntimeException("PathOps failed");
0N/A }
0N/A
0N/A static void doUnixTests() {
0N/A header("Unix specific tests");
0N/A
0N/A // construction
0N/A test("/")
0N/A .string("/");
0N/A test("/", "")
0N/A .string("/");
0N/A test("/", "foo")
0N/A .string("/foo");
0N/A test("/", "/foo")
0N/A .string("/foo");
0N/A test("/", "foo/")
0N/A .string("/foo");
28N/A test("foo", "bar", "gus")
28N/A .string("foo/bar/gus");
28N/A test("")
0N/A .string("");
0N/A test("", "/")
0N/A .string("/");
0N/A test("", "foo", "", "bar", "", "/gus")
0N/A .string("foo/bar/gus");
0N/A
0N/A // all components
0N/A test("/a/b/c")
0N/A .root("/")
0N/A .parent("/a/b")
0N/A .name("c");
0N/A
0N/A // root component only
0N/A test("/")
0N/A .root("/")
0N/A .parent(null)
0N/A .name(null);
0N/A
0N/A // no root component
0N/A test("a/b")
0N/A .root(null)
0N/A .parent("a")
0N/A .name("b");
0N/A
0N/A // name component only
0N/A test("foo")
0N/A .root(null)
0N/A .parent(null)
0N/A .name("foo");
0N/A test("")
0N/A .root(null)
0N/A .parent(null)
0N/A .name("");
0N/A
0N/A // startsWith
0N/A test("/")
0N/A .starts("/")
0N/A .notStarts("")
0N/A .notStarts("/foo");
0N/A test("/foo")
0N/A .starts("/")
0N/A .starts("/foo")
0N/A .notStarts("/f");
0N/A test("/foo/bar")
28N/A .starts("/")
28N/A .starts("/foo")
28N/A .starts("/foo/bar")
0N/A .notStarts("/f")
0N/A .notStarts("foo")
0N/A .notStarts("foo/bar");
0N/A test("foo")
0N/A .starts("foo")
0N/A .notStarts("")
0N/A .notStarts("f");
0N/A test("foo/bar")
0N/A .starts("foo")
0N/A .starts("foo/bar")
0N/A .notStarts("f")
0N/A .notStarts("/foo")
0N/A .notStarts("/foo/bar");
28N/A test("")
28N/A .starts("")
0N/A .notStarts("/");
0N/A
0N/A // endsWith
0N/A test("/")
0N/A .ends("/")
0N/A .notEnds("")
0N/A .notEnds("foo")
0N/A .notEnds("/foo");
0N/A test("/foo")
0N/A .ends("foo")
0N/A .ends("/foo")
0N/A .notEnds("fool");
0N/A test("/foo/bar")
0N/A .ends("bar")
0N/A .ends("foo/bar")
0N/A .ends("/foo/bar")
0N/A .notEnds("ar")
0N/A .notEnds("barack")
28N/A .notEnds("/bar")
28N/A .notEnds("o/bar");
28N/A test("foo")
0N/A .ends("foo")
0N/A .notEnds("")
0N/A .notEnds("oo")
0N/A .notEnds("oola");
0N/A test("foo/bar")
0N/A .ends("bar")
0N/A .ends("foo/bar")
0N/A .notEnds("r")
0N/A .notEnds("barmaid")
0N/A .notEnds("/bar");
0N/A test("foo/bar/gus")
0N/A .ends("gus")
0N/A .ends("bar/gus")
0N/A .ends("foo/bar/gus")
0N/A .notEnds("g")
0N/A .notEnds("/gus")
0N/A .notEnds("r/gus")
0N/A .notEnds("barack/gus")
0N/A .notEnds("bar/gust");
0N/A test("")
0N/A .ends("")
0N/A .notEnds("/");
0N/A
0N/A // elements
0N/A test("a/b/c")
0N/A .element(0, "a")
3323N/A .element(1, "b")
0N/A .element(2, "c");
0N/A test("")
0N/A .element(0, "");
0N/A
0N/A // subpath
0N/A test("/foo")
0N/A .subpath(0, 1, "foo");
0N/A test("foo")
0N/A .subpath(0, 1, "foo");
0N/A test("/foo/bar")
0N/A .subpath(0, 1, "foo")
0N/A .subpath(1, 2, "bar")
0N/A .subpath(0, 2, "foo/bar");
0N/A test("foo/bar")
0N/A .subpath(0, 1, "foo")
0N/A .subpath(1, 2, "bar")
0N/A .subpath(0, 2, "foo/bar");
0N/A test("/foo/bar/gus")
0N/A .subpath(0, 1, "foo")
0N/A .subpath(1, 2, "bar")
0N/A .subpath(2, 3, "gus")
0N/A .subpath(0, 2, "foo/bar")
0N/A .subpath(1, 3, "bar/gus")
0N/A .subpath(0, 3, "foo/bar/gus");
0N/A test("foo/bar/gus")
0N/A .subpath(0, 1, "foo")
0N/A .subpath(1, 2, "bar")
0N/A .subpath(2, 3, "gus")
0N/A .subpath(0, 2, "foo/bar")
0N/A .subpath(1, 3, "bar/gus")
0N/A .subpath(0, 3, "foo/bar/gus");
0N/A test("")
0N/A .subpath(0, 1, "");
0N/A
0N/A // isAbsolute
0N/A test("/")
0N/A .absolute();
0N/A test("/tmp")
0N/A .absolute();
0N/A test("tmp")
0N/A .notAbsolute();
0N/A test("")
0N/A .notAbsolute();
0N/A
0N/A
0N/A // resolve
0N/A test("/tmp")
0N/A .resolve("foo", "/tmp/foo")
0N/A .resolve("/foo", "/foo")
0N/A .resolve("", "/tmp");
0N/A test("tmp")
0N/A .resolve("foo", "tmp/foo")
0N/A .resolve("/foo", "/foo")
0N/A .resolve("", "tmp");
0N/A test("")
0N/A .resolve("", "")
0N/A .resolve("foo", "foo")
0N/A .resolve("/foo", "/foo");
0N/A
0N/A // resolveSibling
0N/A test("foo")
0N/A .resolveSibling("bar", "bar")
0N/A .resolveSibling("/bar", "/bar")
0N/A .resolveSibling("", "");
0N/A test("foo/bar")
0N/A .resolveSibling("gus", "foo/gus")
0N/A .resolveSibling("/gus", "/gus")
0N/A .resolveSibling("", "foo");
0N/A test("/foo")
0N/A .resolveSibling("gus", "/gus")
0N/A .resolveSibling("/gus", "/gus")
0N/A .resolveSibling("", "/");
0N/A test("/foo/bar")
0N/A .resolveSibling("gus", "/foo/gus")
0N/A .resolveSibling("/gus", "/gus")
0N/A .resolveSibling("", "/foo");
0N/A test("")
0N/A .resolveSibling("foo", "foo")
0N/A .resolveSibling("/foo", "/foo")
0N/A .resolve("", "");
0N/A
0N/A // relativize
0N/A test("/a/b/c")
0N/A .relativize("/a/b/c", "")
0N/A .relativize("/a/b/c/d/e", "d/e")
0N/A .relativize("/a/x", "../../x")
0N/A .relativize("/x", "../../../x");
0N/A test("a/b/c")
0N/A .relativize("a/b/c/d", "d")
0N/A .relativize("a/x", "../../x")
0N/A .relativize("x", "../../../x")
0N/A .relativize("", "../../..");
0N/A test("")
0N/A .relativize("a", "a")
0N/A .relativize("a/b/c", "a/b/c")
0N/A .relativize("", "");
0N/A
0N/A // normalize
0N/A test("/")
0N/A .normalize("/");
0N/A test("foo")
0N/A .normalize("foo");
0N/A test("/foo")
0N/A .normalize("/foo");
0N/A test(".")
0N/A .normalize("");
0N/A test("..")
0N/A .normalize("..");
0N/A test("/..")
0N/A .normalize("/");
0N/A test("/../..")
0N/A .normalize("/");
0N/A test("foo/.")
0N/A .normalize("foo");
0N/A test("./foo")
0N/A .normalize("foo");
0N/A test("foo/..")
0N/A .normalize("");
0N/A test("../foo")
0N/A .normalize("../foo");
0N/A test("../../foo")
0N/A .normalize("../../foo");
0N/A test("foo/bar/..")
0N/A .normalize("foo");
0N/A test("foo/bar/gus/../..")
0N/A .normalize("foo");
0N/A test("/foo/bar/gus/../..")
0N/A .normalize("/foo");
0N/A
0N/A // invalid
0N/A test("foo\u0000bar")
0N/A .invalid();
0N/A test("\u0000foo")
0N/A .invalid();
0N/A test("bar\u0000")
0N/A .invalid();
0N/A test("//foo\u0000bar")
0N/A .invalid();
0N/A test("//\u0000foo")
0N/A .invalid();
0N/A test("//bar\u0000")
0N/A .invalid();
0N/A
0N/A // normalization of input
0N/A test("//foo//bar")
0N/A .string("/foo/bar")
0N/A .root("/")
0N/A .parent("/foo")
0N/A .name("bar");
0N/A }
0N/A
0N/A static void npes() {
0N/A header("NullPointerException");
0N/A
0N/A Path path = FileSystems.getDefault().getPath("foo");
0N/A
0N/A try {
0N/A path.resolve((String)null);
0N/A throw new RuntimeException("NullPointerException not thrown");
0N/A } catch (NullPointerException npe) {
0N/A }
0N/A
0N/A try {
0N/A path.relativize(null);
0N/A throw new RuntimeException("NullPointerException not thrown");
0N/A } catch (NullPointerException npe) {
0N/A }
0N/A
0N/A try {
0N/A path.compareTo(null);
0N/A throw new RuntimeException("NullPointerException not thrown");
0N/A } catch (NullPointerException npe) {
0N/A }
0N/A
0N/A try {
0N/A path.startsWith((Path)null);
0N/A throw new RuntimeException("NullPointerException not thrown");
0N/A } catch (NullPointerException npe) {
0N/A }
0N/A
0N/A try {
0N/A path.endsWith((Path)null);
0N/A throw new RuntimeException("NullPointerException not thrown");
0N/A } catch (NullPointerException npe) {
0N/A }
0N/A
0N/A }
0N/A
0N/A public static void main(String[] args) {
0N/A // all platforms
0N/A npes();
0N/A
0N/A // operating system specific
0N/A String osname = System.getProperty("os.name");
0N/A if (osname.startsWith("Windows")) {
0N/A doWindowsTests();
0N/A } else {
0N/A doUnixTests();
0N/A }
0N/A
0N/A }
0N/A}
0N/A