package com.jogamp.common.net; import java.io.File; import java.io.IOException; import java.net.URI; import java.net.URISyntaxException; import java.net.URL; import java.net.URLConnection; import jogamp.common.os.PlatformPropsImpl; import org.junit.Assert; import org.junit.Test; import com.jogamp.common.net.Uri; import com.jogamp.common.os.Platform; import com.jogamp.junit.util.SingletonJunitCase; import org.junit.FixMethodOrder; import org.junit.runners.MethodSorters; @FixMethodOrder(MethodSorters.NAME_ASCENDING) public class TestUri03Resolving extends SingletonJunitCase { // Bug 908, issues w/ windows file path char: $ ^ ~ # [ ] private static final String[][] uriHttpSArray = new String[][] { new String[] {"http://localhost/gluegen/build-x86_64/gluegen-rt.jar"}, new String[] {"http://localhost/gluegen/"+'\u0394'+"/gluegen-rt.jar"}, new String[] {"http://localhost/gluegen/build-x86_64%20lala/gluegen-rt.jar"}, new String[] {"http://localhost/gluegen/build-x86_64%20öä%20lala/gluegen-rt.jar"}, new String[] {"jar:http://localhost/gluegen/build-x86_64/gluegen-rt.jar!/"}, new String[] {"jar:http://localhost/gluegen/build-x86_64%20öä%20lala/gluegen-rt.jar!/"}, new String[] {"jar:http://localhost/gluegen/build-x86_64/gluegen-rt.jar!/com/jogamp/common/os/Platform.class"}, new String[] {"jar:http://localhost/gluegen/build-x86_64%20öä%20lala/gluegen-rt.jar!/com/jogamp/common/os/Platform.class"}, new String[] {"jar:http://localhost/gluegen/R%23/gluegen-rt.jar!/"}, new String[] {"jar:http://localhost/gluegen/A%24/B%5E/C~/D%23/E%5B/F%5D/gluegen-rt.jar!/"}, new String[] {"jar:http://localhost/gluegen/%24/%5E/~/%23/%5B/%5D/gluegen-rt.jar!/"}, new String[] {"jar:http://localhost/gluegen/"+'\u0394'+"/gluegen-rt.jar!/"}, }; private static final String[][] uriFileSArrayUnix = new String[][] { new String[] {"file:/gluegen/build-x86_64/gluegen-rt.jar"}, new String[] {"file:/gluegen/"+'\u0394'+"/gluegen-rt.jar"}, new String[] {"file:/gluegen/build-x86_64%20lala/gluegen-rt.jar"}, new String[] {"file:/gluegen/build-x86_64%20öä%20lala/gluegen-rt.jar"}, new String[] {"jar:file:/gluegen/build-x86_64/gluegen-rt.jar!/"}, new String[] {"jar:file:/gluegen/build-x86_64%20öä%20lala/gluegen-rt.jar!/"}, new String[] {"jar:file:/gluegen/build-x86_64/gluegen-rt.jar!/com/jogamp/common/os/Platform.class"}, new String[] {"jar:file:/gluegen/build-x86_64%20öä%20lala/gluegen-rt.jar!/com/jogamp/common/os/Platform.class"}, new String[] {"jar:file://filehost/gluegen/build-x86_64%20öä%20lala/gluegen-rt.jar!/com/jogamp/common/os/Platform.class"}, new String[] {"jar:file:/gluegen/R%23/gluegen-rt.jar!/"}, new String[] {"jar:file:/gluegen/A%24/B%5E/C~/D%23/E%5B/F%5D/gluegen-rt.jar!/"}, new String[] {"jar:file:/gluegen/%24/%5E/~/%23/%5B/%5D/gluegen-rt.jar!/"}, new String[] {"jar:file:/gluegen/"+'\u0394'+"/gluegen-rt.jar!/"}, }; private static final String[][] uriFileSArrayWindows = new String[][] { new String[] {"file:/C%3A/gluegen/build-x86_64/gluegen-rt.jar"}, new String[] {"file:/C%3A/gluegen/"+'\u0394'+"/gluegen-rt.jar"}, new String[] {"file:/C%3A/gluegen/build-x86_64%20lala/gluegen-rt.jar"}, new String[] {"file:/C%3A/gluegen/build-x86_64%20öä%20lala/gluegen-rt.jar"}, new String[] {"jar:file:/C%3A/gluegen/build-x86_64/gluegen-rt.jar!/"}, new String[] {"jar:file:/C%3A/gluegen/build-x86_64%20öä%20lala/gluegen-rt.jar!/"}, new String[] {"jar:file:/C%3A/gluegen/build-x86_64/gluegen-rt.jar!/com/jogamp/common/os/Platform.class"}, new String[] {"jar:file:/C%3A/gluegen/build-x86_64%20öä%20lala/gluegen-rt.jar!/com/jogamp/common/os/Platform.class"}, new String[] {"jar:file:///C%3A/gluegen/build-x86_64%20öä%20lala/gluegen-rt.jar!/com/jogamp/common/os/Platform.class"}, new String[] {"jar:file://filehost/gluegen/build-x86_64%20öä%20lala/gluegen-rt.jar!/com/jogamp/common/os/Platform.class"}, new String[] {"jar:file:/C%3A/gluegen/R%23/gluegen-rt.jar!/"}, new String[] {"jar:file:/C%3A/gluegen/A%24/B%5E/C~/D%23/E%5B/F%5D/gluegen-rt.jar!/"}, new String[] {"jar:file:/C%3A/gluegen/%24/%5E/~/%23/%5B/%5D/gluegen-rt.jar!/"}, new String[] {"jar:file:/C%3A/gluegen/"+'\u0394'+"/gluegen-rt.jar!/"}, }; private static final String[][] urlFileSArrayWindows = new String[][] { new String[] {"file:/C:/gluegen/build-x86_64/gluegen-rt.jar"}, new String[] {"file:/C:/gluegen/"+'\u0394'+"/gluegen-rt.jar"}, new String[] {"file:/C:/gluegen/build-x86_64%20lala/gluegen-rt.jar"}, new String[] {"file:/C:/gluegen/build-x86_64%20öä%20lala/gluegen-rt.jar"}, new String[] {"jar:file:/C:/gluegen/build-x86_64/gluegen-rt.jar!/"}, new String[] {"jar:file:/C:/gluegen/build-x86_64%20öä%20lala/gluegen-rt.jar!/"}, new String[] {"jar:file:/C:/gluegen/build-x86_64/gluegen-rt.jar!/com/jogamp/common/os/Platform.class"}, new String[] {"jar:file:/C:/gluegen/build-x86_64%20öä%20lala/gluegen-rt.jar!/com/jogamp/common/os/Platform.class"}, new String[] {"jar:file:///C:/gluegen/build-x86_64%20öä%20lala/gluegen-rt.jar!/com/jogamp/common/os/Platform.class"}, new String[] {"jar:file://filehost/gluegen/build-x86_64%20öä%20lala/gluegen-rt.jar!/com/jogamp/common/os/Platform.class"}, new String[] {"jar:file:/C:/gluegen/R%23/gluegen-rt.jar!/"}, new String[] {"jar:file:/C:/gluegen/A%24/B%5E/C~/D%23/E%5B/F%5D/gluegen-rt.jar!/"}, new String[] {"jar:file:/C:/gluegen/%24/%5E/~/%23/%5B/%5D/gluegen-rt.jar!/"}, new String[] {"jar:file:/C:/gluegen/"+'\u0394'+"/gluegen-rt.jar!/"}, }; public static final String[][] fileSArrayUnix = new String[][] { new String[] {"/gluegen/build-x86_64/gluegen-rt.jar", "file:/gluegen/build-x86_64/gluegen-rt.jar", "/gluegen/build-x86_64/gluegen-rt.jar"}, new String[] {"/gluegen/"+'\u0394'+"/gluegen-rt.jar", "file:/gluegen/"+'\u0394'+"/gluegen-rt.jar", "/gluegen/"+'\u0394'+"/gluegen-rt.jar"}, new String[] {"/gluegen/build-x86_64 lala/gluegen-rt.jar", "file:/gluegen/build-x86_64%20lala/gluegen-rt.jar", "/gluegen/build-x86_64 lala/gluegen-rt.jar"}, new String[] {"/gluegen/build-x86_64 öä lala/gluegen-rt.jar", "file:/gluegen/build-x86_64%20öä%20lala/gluegen-rt.jar", "/gluegen/build-x86_64 öä lala/gluegen-rt.jar"}, new String[] {"/gluegen/A$/B^/C~/D#/E[/F]/gluegen-rt.jar", "file:/gluegen/A%24/B%5E/C~/D%23/E%5B/F%5D/gluegen-rt.jar", "/gluegen/A$/B^/C~/D#/E[/F]/gluegen-rt.jar" }, new String[] {"/gluegen/$/^/~/#/[/]/gluegen-rt.jar", "file:/gluegen/%24/%5E/~/%23/%5B/%5D/gluegen-rt.jar", "/gluegen/$/^/~/#/[/]/gluegen-rt.jar" }, }; public static final String[][] fileSArrayWindows = new String[][] { new String[] {"C:/gluegen/build-x86_64/gluegen-rt.jar", "file:/C%3A/gluegen/build-x86_64/gluegen-rt.jar", "C:\\gluegen\\build-x86_64\\gluegen-rt.jar"}, new String[] {"C:/gluegen/"+'\u0394'+"/gluegen-rt.jar", "file:/C%3A/gluegen/"+'\u0394'+"/gluegen-rt.jar", "C:\\gluegen\\"+'\u0394'+"\\gluegen-rt.jar"}, new String[] {"C:/gluegen/build-x86_64 lala/gluegen-rt.jar", "file:/C%3A/gluegen/build-x86_64%20lala/gluegen-rt.jar", "C:\\gluegen\\build-x86_64 lala\\gluegen-rt.jar"}, new String[] {"C:/gluegen/build-x86_64 öä lala/gluegen-rt.jar", "file:/C%3A/gluegen/build-x86_64%20öä%20lala/gluegen-rt.jar", "C:\\gluegen\\build-x86_64 öä lala\\gluegen-rt.jar"}, new String[] {"C:\\gluegen\\build-x86_64 öä lala\\gluegen-rt.jar", "file:/C%3A/gluegen/build-x86_64%20öä%20lala/gluegen-rt.jar", "C:\\gluegen\\build-x86_64 öä lala\\gluegen-rt.jar"}, new String[] {"\\\\filehost\\gluegen\\build-x86_64 öä lala\\gluegen-rt.jar", "file://filehost/gluegen/build-x86_64%20öä%20lala/gluegen-rt.jar", "\\\\filehost\\gluegen\\build-x86_64 öä lala\\gluegen-rt.jar"}, new String[] {"C:/gluegen/A$/B^/C~/D#/E[/F]/gluegen-rt.jar", "file:/C%3A/gluegen/A%24/B%5E/C~/D%23/E%5B/F%5D/gluegen-rt.jar", "C:\\gluegen\\A$\\B^\\C~\\D#\\E[\\F]\\gluegen-rt.jar" }, new String[] {"C:/gluegen/$/^/~/#/[/]/gluegen-rt.jar", "file:/C%3A/gluegen/%24/%5E/~/%23/%5B/%5D/gluegen-rt.jar", "C:\\gluegen\\$\\^\\~\\#\\[\\]\\gluegen-rt.jar" }, }; @Test public void test01HttpUri2URL() throws IOException, URISyntaxException { testUri2URL(getSimpleTestName("."), uriHttpSArray); } @Test public void test02FileUnixUri2URL() throws IOException, URISyntaxException { testUri2URL(getSimpleTestName("."), uriFileSArrayUnix); } @Test public void test03FileWindowsUri2URL() throws IOException, URISyntaxException { testUri2URL(getSimpleTestName("."), uriFileSArrayWindows); } @Test public void test11HttpURL2Uri() throws IOException, URISyntaxException { testURL2Uri(getSimpleTestName("."), uriHttpSArray); } @Test public void test12FileUnixURL2Uri() throws IOException, URISyntaxException { testURL2Uri(getSimpleTestName("."), uriFileSArrayUnix); } @Test public void test13FileWindowsURL2Uri() throws IOException, URISyntaxException { testURL2Uri(getSimpleTestName("."), urlFileSArrayWindows); } @Test public void test24FileUnixURI2URL() throws IOException, URISyntaxException { if( Platform.OSType.WINDOWS != PlatformPropsImpl.OS_TYPE ) { testFile2Uri(getSimpleTestName("."), fileSArrayUnix); } } @Test public void test25FileWindowsURI2URL() throws IOException, URISyntaxException { if( Platform.OSType.WINDOWS == PlatformPropsImpl.OS_TYPE ) { testFile2Uri(getSimpleTestName("."), fileSArrayWindows); } } static void testUri2URL(final String testname, final String[][] uriSArray) throws IOException, URISyntaxException { boolean ok = true; for(int i=0; i