1 /* 2 * Copyright (c) 2010, 2014, 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. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package com.sun.javafx.css; 27 28 import static org.junit.Assert.assertEquals; 29 import static org.junit.Assert.fail; 30 31 import javafx.css.ParsedValue; 32 import javafx.scene.text.Font; 33 34 import org.junit.Test; 35 36 import javafx.css.converter.StringConverter; 37 import javafx.css.converter.URLConverter; 38 39 40 public class URLTypeTest { 41 42 public URLTypeTest() { 43 } 44 45 static final String absClassName = "/com/sun/javafx/css/URLTypeTest.class"; 46 static final String classURL = URLTypeTest.class.getResource("URLTypeTest.class").toExternalForm(); 47 48 final String baseURL = "http://a/b/c/d;p?q"; 49 50 // from rfc3986, section 5 51 final String[][] testPairs = new String[][] { 52 {"file:h" , "file:h"}, 53 {"g" , "http://a/b/c/g"}, 54 {"./g" , "http://a/b/c/g"}, 55 {"g/" , "http://a/b/c/g/"}, 56 // The following is relative to classloader root, and since it won't be found, will return null 57 {"/g" , null}, 58 // The following is relative to classloader root and will be resolved as such 59 {absClassName , classURL}, 60 {"//g" , "http://g"}, 61 // actual is http://a/b/c/?y - bug in java.net.URI? {"?y" , "http://a/b/c/d;p?y"}, 62 {"g?y" , "http://a/b/c/g?y"}, 63 {"#s" , "http://a/b/c/d;p?q#s"}, 64 {"g#s" , "http://a/b/c/g#s"}, 65 {"g?y#s" , "http://a/b/c/g?y#s"}, 66 {";x" , "http://a/b/c/;x"}, 67 {"g;x" , "http://a/b/c/g;x"}, 68 {"g;x?y#s" , "http://a/b/c/g;x?y#s"}, 69 // empty string causes URISyntaxException, so converter returns null {"" , "http://a/b/c/d;p?q"}, 70 {"", null}, // not part of the rfc test suite - converter returns null if resolving base against empty string 71 {"." , "http://a/b/c/"}, 72 {"./" , "http://a/b/c/"}, 73 {".." , "http://a/b/"}, 74 {"../" , "http://a/b/"}, 75 {"../g" , "http://a/b/g"}, 76 {"../.." , "http://a/"}, 77 {"../../" , "http://a/"}, 78 {"../../g" , "http://a/g"} 79 }; 80 81 /** 82 * Test of convert method, of class URLType. 83 */ 84 @Test 85 public void testConvert() { 86 //System.out.println("convert"); 87 ParsedValue<ParsedValue[],String>[] urls = new ParsedValue[testPairs.length]; 88 89 for(int n=0; n<testPairs.length; n++) { 90 ParsedValue[] values = new ParsedValue[] { 91 new ParsedValueImpl<String,String>(testPairs[n][0], StringConverter.getInstance()), 92 new ParsedValueImpl<String, String>(baseURL, null) 93 }; 94 urls[n] = new ParsedValueImpl<ParsedValue[],String>(values, URLConverter.getInstance()); 95 }; 96 97 ParsedValue<ParsedValue<ParsedValue[],String>[],String[]> value = 98 new ParsedValueImpl<ParsedValue<ParsedValue[],String>[],String[]>(urls, URLConverter.SequenceConverter.getInstance()); 99 100 Font font = null; 101 String[] result = value.convert(font); 102 assertEquals(testPairs.length, result.length); 103 for(int n=0; n<result.length; n++) { 104 String msg = "[" + n + "]" + "resolve \'" + testPairs[n][0] + "\'"; 105 assertEquals(msg, testPairs[n][1], result[n]); 106 } 107 } 108 109 }