1 /* 2 * Copyright (c) 2008, 2009, 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 26 * @summary Unit test for java.nio.file.Path 27 */ 28 29 import java.nio.file.*; 30 import java.net.URI; 31 import java.net.URISyntaxException; 32 import java.io.PrintStream; 33 34 public class UriImportExport { 35 36 static final PrintStream log = System.out; 37 static int failures = 0; 38 39 static void test(String fn, String expected) { 40 log.println(); 41 Path p = Paths.get(fn); 42 log.println(p); 43 URI u = p.toUri(); 44 log.println(" --> " + u); 45 if (expected != null && !(u.toString().equals(expected))) { 46 log.println("FAIL: Expected " + expected); 47 failures++; 48 return; 49 } 50 Path q = Paths.get(u); 51 log.println(" --> " + q); 52 if (!p.toAbsolutePath().equals(q)) { 53 log.println("FAIL: Expected " + p + ", got " + q); 54 failures++; 55 return; 56 } 57 } 58 59 static void test(String fn) { 60 test(fn, null); 61 } 62 63 public static void main(String[] args) throws Exception { 64 test("foo"); 65 test("/foo"); 66 test("/foo bar"); 67 68 String osname = System.getProperty("os.name"); 69 if (osname.startsWith("Windows")) { 70 test("C:\\foo"); 71 test("C:foo"); 72 test("\\\\rialto.dublin.com\\share\\"); 73 test("\\\\fe80--203-baff-fe5a-749ds1.ipv6-literal.net\\share\\missing", 74 "file://[fe80::203:baff:fe5a:749d%1]/share/missing"); 75 } 76 77 if (failures > 0) 78 throw new RuntimeException(failures + " test(s) failed"); 79 } 80 }