test/jdk/nio/zipfs/PathOps.java

Print this page




  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 import java.io.IOException;
  25 import java.nio.file.FileSystem;
  26 import java.nio.file.FileSystems;
  27 import java.nio.file.Files;
  28 import java.nio.file.InvalidPathException;
  29 import java.nio.file.Path;
  30 
  31 /**
  32  *
  33  * @test
  34  * @bug 8038500 8040059
  35  * @summary Tests path operations for zip provider.
  36  *
  37  * @run main PathOps
  38  * @run main/othervm/java.security.policy=test.policy PathOps

  39  */
  40 
  41 public class PathOps {
  42 
  43     static final java.io.PrintStream out = System.out;
  44     static FileSystem fs;
  45 
  46     private String input;
  47     private Path path;
  48     private Exception exc;
  49 
  50     private PathOps(String first, String... more) {
  51         out.println();
  52         input = first;
  53         try {
  54             path = fs.getPath(first, more);
  55             out.format("%s -> %s", first, path);
  56         } catch (Exception x) {
  57             exc = x;
  58             out.format("%s -> %s", first, x);


 407             .resolve("", "");
 408 
 409         // relativize
 410         test("/a/b/c")
 411             .relativize("/a/b/c", "")
 412             .relativize("/a/b/c/d/e", "d/e")
 413             .relativize("/a/x", "../../x")
 414             .relativize("/x", "../../../x");
 415         test("a/b/c")
 416             .relativize("a/b/c/d", "d")
 417             .relativize("a/x", "../../x")
 418             .relativize("x", "../../../x")
 419             .relativize("", "../../..");
 420         test("")
 421             .relativize("a", "a")
 422             .relativize("a/b/c", "a/b/c")
 423             .relativize("", "");
 424         test("/")
 425             .relativize("/a", "a")
 426             .relativize("/a/c", "a/c");





 427 
 428         // normalize
 429         test("/")
 430             .normalize("/");
 431         test("foo")
 432             .normalize("foo");
 433         test("/foo")
 434             .normalize("/foo");
 435         test(".")
 436             .normalize("");
 437         test("..")
 438             .normalize("..");
 439         test("/..")
 440             .normalize("/");
 441         test("/../..")
 442             .normalize("/");
 443         test("foo/.")
 444             .normalize("foo");
 445         test("./foo")
 446             .normalize("foo");


 469             .invalid();
 470         test("bar\u0000")
 471             .invalid();
 472         test("//foo\u0000bar")
 473             .invalid();
 474         test("//\u0000foo")
 475             .invalid();
 476         test("//bar\u0000")
 477             .invalid();
 478 
 479         // normalization
 480         test("//foo//bar")
 481             .string("/foo/bar")
 482             .root("/")
 483             .parent("/foo")
 484             .name("bar");
 485 
 486         // isSameFile
 487         test("/fileDoesNotExist")
 488             .isSameFile("/fileDoesNotExist");









 489     }
 490 
 491     static void npes() {
 492         header("NullPointerException");
 493 
 494         Path path = fs.getPath("foo");
 495 
 496         try {
 497             path.resolve((String)null);
 498             throw new RuntimeException("NullPointerException not thrown");
 499         } catch (NullPointerException npe) {
 500         }
 501 
 502         try {
 503             path.relativize(null);
 504             throw new RuntimeException("NullPointerException not thrown");
 505         } catch (NullPointerException npe) {
 506         }
 507 
 508         try {




  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 import java.io.IOException;
  25 import java.nio.file.FileSystem;
  26 import java.nio.file.FileSystems;
  27 import java.nio.file.Files;
  28 import java.nio.file.InvalidPathException;
  29 import java.nio.file.Path;
  30 
  31 /**
  32  *
  33  * @test
  34  * @bug 8038500 8040059 8139956 8146754
  35  * @summary Tests path operations for zip provider.
  36  *
  37  * @run main PathOps
  38  * @run main/othervm/java.security.policy=test.policy PathOps
  39  * @modules jdk.zipfs
  40  */
  41 
  42 public class PathOps {
  43 
  44     static final java.io.PrintStream out = System.out;
  45     static FileSystem fs;
  46 
  47     private String input;
  48     private Path path;
  49     private Exception exc;
  50 
  51     private PathOps(String first, String... more) {
  52         out.println();
  53         input = first;
  54         try {
  55             path = fs.getPath(first, more);
  56             out.format("%s -> %s", first, path);
  57         } catch (Exception x) {
  58             exc = x;
  59             out.format("%s -> %s", first, x);


 408             .resolve("", "");
 409 
 410         // relativize
 411         test("/a/b/c")
 412             .relativize("/a/b/c", "")
 413             .relativize("/a/b/c/d/e", "d/e")
 414             .relativize("/a/x", "../../x")
 415             .relativize("/x", "../../../x");
 416         test("a/b/c")
 417             .relativize("a/b/c/d", "d")
 418             .relativize("a/x", "../../x")
 419             .relativize("x", "../../../x")
 420             .relativize("", "../../..");
 421         test("")
 422             .relativize("a", "a")
 423             .relativize("a/b/c", "a/b/c")
 424             .relativize("", "");
 425         test("/")
 426             .relativize("/a", "a")
 427             .relativize("/a/c", "a/c");
 428         // 8146754
 429         test("/tmp/path")
 430             .relativize("/tmp/path/a.txt", "a.txt");
 431         test("/tmp/path/")
 432             .relativize("/tmp/path/a.txt", "a.txt");
 433 
 434         // normalize
 435         test("/")
 436             .normalize("/");
 437         test("foo")
 438             .normalize("foo");
 439         test("/foo")
 440             .normalize("/foo");
 441         test(".")
 442             .normalize("");
 443         test("..")
 444             .normalize("..");
 445         test("/..")
 446             .normalize("/");
 447         test("/../..")
 448             .normalize("/");
 449         test("foo/.")
 450             .normalize("foo");
 451         test("./foo")
 452             .normalize("foo");


 475             .invalid();
 476         test("bar\u0000")
 477             .invalid();
 478         test("//foo\u0000bar")
 479             .invalid();
 480         test("//\u0000foo")
 481             .invalid();
 482         test("//bar\u0000")
 483             .invalid();
 484 
 485         // normalization
 486         test("//foo//bar")
 487             .string("/foo/bar")
 488             .root("/")
 489             .parent("/foo")
 490             .name("bar");
 491 
 492         // isSameFile
 493         test("/fileDoesNotExist")
 494             .isSameFile("/fileDoesNotExist");
 495 
 496         // 8139956
 497         out.println("check getNameCount");
 498         int nc = fs.getPath("/").relativize(fs.getPath("/")).getNameCount();
 499         if (nc != 1) {
 500             out.format("\tExpected: 1\n");
 501             out.format("\tActual: %d\n",  nc);
 502             throw new RuntimeException("getNameCount of empty path failed");
 503         }
 504      }
 505 
 506     static void npes() {
 507         header("NullPointerException");
 508 
 509         Path path = fs.getPath("foo");
 510 
 511         try {
 512             path.resolve((String)null);
 513             throw new RuntimeException("NullPointerException not thrown");
 514         } catch (NullPointerException npe) {
 515         }
 516 
 517         try {
 518             path.relativize(null);
 519             throw new RuntimeException("NullPointerException not thrown");
 520         } catch (NullPointerException npe) {
 521         }
 522 
 523         try {