/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* 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.
*/
/**
* Tests path operations for zip provider.
*/
public class PathOps {
input = s;
try {
} catch (Exception x) {
exc = x;
}
}
return path;
}
void fail() {
throw new RuntimeException("PathOps failed");
}
void checkPath() {
throw new InternalError("path is null");
}
}
} else {
// compare string representations
return;
}
fail();
}
}
checkPath();
return this;
}
checkPath();
return this;
}
checkPath();
return this;
}
checkPath();
return this;
}
checkPath();
return this;
}
checkPath();
return this;
}
checkPath();
return this;
}
checkPath();
return this;
}
checkPath();
return this;
}
checkPath();
return this;
}
checkPath();
return this;
}
checkPath();
return this;
}
checkPath();
return this;
}
checkPath();
return this;
}
checkPath();
return this;
}
try {
checkPath();
} catch (IOException ioe) {
fail();
}
return this;
}
if (!(exc instanceof InvalidPathException)) {
fail();
}
return this;
}
return new PathOps(s);
}
// -- PathOpss --
}
static void doPathOpTests() {
header("Path operations");
// all components
test("/a/b/c")
.root("/")
.parent("/a/b")
.name("c");
// root component only
test("/")
.root("/")
// no root component
test("a/b")
.parent("a")
.name("b");
// name component only
test("foo")
.name("foo");
// startsWith
test("")
.starts("")
.notStarts("/");
test("/")
.starts("/")
.notStarts("/foo");
test("/foo")
.starts("/")
.starts("/foo")
.notStarts("/f")
.notStarts("");
.starts("/")
.starts("/foo")
.starts("/foo/")
.notStarts("/f")
.notStarts("foo")
.notStarts("");
test("foo")
.starts("foo")
.notStarts("f");
.starts("foo")
.starts("foo/")
.notStarts("f")
.notStarts("/foo")
// endsWith
test("")
.ends("")
.notEnds("/");
test("/")
.ends("/")
.notEnds("foo")
.notEnds("/foo");
test("/foo")
.ends("foo")
.ends("/foo")
.notEnds("/");
.ends("bar")
.notEnds("/bar");
.ends("bar")
.notEnds("/bar");
test("foo")
.ends("foo");
.ends("bar")
.ends("bar/")
// elements
test("a/b/c")
// isAbsolute
test("/")
.absolute();
test("/tmp")
.absolute();
test("tmp")
.notAbsolute();
test("")
.notAbsolute();
// resolve
test("/tmp")
test("tmp")
// relativize
test("/a/b/c")
// normalize
test("/")
.normalize("/");
test("foo")
.normalize("foo");
test("/foo")
.normalize("/foo");
test(".")
.normalize("");
test("..")
.normalize("..");
test("/..")
.normalize("/");
test("/../..")
.normalize("/");
test("foo/.")
.normalize("foo");
test("./foo")
.normalize("foo");
test("foo/..")
.normalize("");
test("../foo")
.normalize("../foo");
test("../../foo")
.normalize("../../foo");
.normalize("foo");
.normalize("foo");
.normalize("/foo");
test("/./.")
.normalize("/");
test("/.")
.normalize("/");
test("/./abc")
.normalize("/abc");
// invalid
test("foo\u0000bar")
.invalid();
test("\u0000foo")
.invalid();
test("bar\u0000")
.invalid();
test("//foo\u0000bar")
.invalid();
test("//\u0000foo")
.invalid();
test("//bar\u0000")
.invalid();
// normalization
test("//foo//bar")
.root("/")
.parent("/foo")
.name("bar");
// isSameFile
test("/fileDoesNotExist")
.isSameFile("/fileDoesNotExist");
}
static void npes() {
header("NullPointerException");
try {
throw new RuntimeException("NullPointerException not thrown");
} catch (NullPointerException npe) {
}
try {
throw new RuntimeException("NullPointerException not thrown");
} catch (NullPointerException npe) {
}
try {
throw new RuntimeException("NullPointerException not thrown");
} catch (NullPointerException npe) {
}
try {
throw new RuntimeException("NullPointerException not thrown");
} catch (NullPointerException npe) {
}
try {
throw new RuntimeException("NullPointerException not thrown");
} catch (NullPointerException npe) {
}
}
npes();
}
}