4import java.io.IOException;
6import java.net.URISyntaxException;
8import java.net.URLConnection;
10import org.jau.net.Uri;
11import org.jau.sys.PlatformProps;
12import org.jau.sys.PlatformTypes;
13import org.junit.Assert;
14import org.junit.FixMethodOrder;
16import org.junit.runners.MethodSorters;
18import jau.test.junit.util.JunitTracer;
20@FixMethodOrder(MethodSorters.NAME_ASCENDING)
25 private static final String[][] uriHttpSArray =
new String[][] {
26 new String[] {
"http://localhost/gluegen/build-x86_64/gluegen-rt.jar"},
28 new String[] {
"http://localhost/gluegen/"+
'\u0394'+
"/gluegen-rt.jar"},
30 new String[] {
"http://localhost/gluegen/build-x86_64%20lala/gluegen-rt.jar"},
32 new String[] {
"http://localhost/gluegen/build-x86_64%20öä%20lala/gluegen-rt.jar"},
34 new String[] {
"jar:http://localhost/gluegen/build-x86_64/gluegen-rt.jar!/"},
36 new String[] {
"jar:http://localhost/gluegen/build-x86_64%20öä%20lala/gluegen-rt.jar!/"},
38 new String[] {
"jar:http://localhost/gluegen/build-x86_64/gluegen-rt.jar!/com/jogamp/common/os/Platform.class"},
40 new String[] {
"jar:http://localhost/gluegen/build-x86_64%20öä%20lala/gluegen-rt.jar!/com/jogamp/common/os/Platform.class"},
42 new String[] {
"jar:http://localhost/gluegen/R%23/gluegen-rt.jar!/"},
44 new String[] {
"jar:http://localhost/gluegen/A%24/B%5E/C~/D%23/E%5B/F%5D/gluegen-rt.jar!/"},
46 new String[] {
"jar:http://localhost/gluegen/%24/%5E/~/%23/%5B/%5D/gluegen-rt.jar!/"},
48 new String[] {
"jar:http://localhost/gluegen/"+
'\u0394'+
"/gluegen-rt.jar!/"},
51 private static final String[][] uriFileSArrayUnix =
new String[][] {
52 new String[] {
"file:/gluegen/build-x86_64/gluegen-rt.jar"},
54 new String[] {
"file:/gluegen/"+
'\u0394'+
"/gluegen-rt.jar"},
56 new String[] {
"file:/gluegen/build-x86_64%20lala/gluegen-rt.jar"},
58 new String[] {
"file:/gluegen/build-x86_64%20öä%20lala/gluegen-rt.jar"},
60 new String[] {
"jar:file:/gluegen/build-x86_64/gluegen-rt.jar!/"},
62 new String[] {
"jar:file:/gluegen/build-x86_64%20öä%20lala/gluegen-rt.jar!/"},
64 new String[] {
"jar:file:/gluegen/build-x86_64/gluegen-rt.jar!/com/jogamp/common/os/Platform.class"},
66 new String[] {
"jar:file:/gluegen/build-x86_64%20öä%20lala/gluegen-rt.jar!/com/jogamp/common/os/Platform.class"},
68 new String[] {
"jar:file://filehost/gluegen/build-x86_64%20öä%20lala/gluegen-rt.jar!/com/jogamp/common/os/Platform.class"},
70 new String[] {
"jar:file:/gluegen/R%23/gluegen-rt.jar!/"},
72 new String[] {
"jar:file:/gluegen/A%24/B%5E/C~/D%23/E%5B/F%5D/gluegen-rt.jar!/"},
74 new String[] {
"jar:file:/gluegen/%24/%5E/~/%23/%5B/%5D/gluegen-rt.jar!/"},
76 new String[] {
"jar:file:/gluegen/"+
'\u0394'+
"/gluegen-rt.jar!/"},
79 private static final String[][] uriFileSArrayWindows =
new String[][] {
80 new String[] {
"file:/C%3A/gluegen/build-x86_64/gluegen-rt.jar"},
82 new String[] {
"file:/C%3A/gluegen/"+
'\u0394'+
"/gluegen-rt.jar"},
84 new String[] {
"file:/C%3A/gluegen/build-x86_64%20lala/gluegen-rt.jar"},
86 new String[] {
"file:/C%3A/gluegen/build-x86_64%20öä%20lala/gluegen-rt.jar"},
88 new String[] {
"jar:file:/C%3A/gluegen/build-x86_64/gluegen-rt.jar!/"},
90 new String[] {
"jar:file:/C%3A/gluegen/build-x86_64%20öä%20lala/gluegen-rt.jar!/"},
92 new String[] {
"jar:file:/C%3A/gluegen/build-x86_64/gluegen-rt.jar!/com/jogamp/common/os/Platform.class"},
94 new String[] {
"jar:file:/C%3A/gluegen/build-x86_64%20öä%20lala/gluegen-rt.jar!/com/jogamp/common/os/Platform.class"},
96 new String[] {
"jar:file:///C%3A/gluegen/build-x86_64%20öä%20lala/gluegen-rt.jar!/com/jogamp/common/os/Platform.class"},
98 new String[] {
"jar:file://filehost/gluegen/build-x86_64%20öä%20lala/gluegen-rt.jar!/com/jogamp/common/os/Platform.class"},
100 new String[] {
"jar:file:/C%3A/gluegen/R%23/gluegen-rt.jar!/"},
102 new String[] {
"jar:file:/C%3A/gluegen/A%24/B%5E/C~/D%23/E%5B/F%5D/gluegen-rt.jar!/"},
104 new String[] {
"jar:file:/C%3A/gluegen/%24/%5E/~/%23/%5B/%5D/gluegen-rt.jar!/"},
106 new String[] {
"jar:file:/C%3A/gluegen/"+
'\u0394'+
"/gluegen-rt.jar!/"},
109 private static final String[][] urlFileSArrayWindows =
new String[][] {
110 new String[] {
"file:/C:/gluegen/build-x86_64/gluegen-rt.jar"},
112 new String[] {
"file:/C:/gluegen/"+
'\u0394'+
"/gluegen-rt.jar"},
114 new String[] {
"file:/C:/gluegen/build-x86_64%20lala/gluegen-rt.jar"},
116 new String[] {
"file:/C:/gluegen/build-x86_64%20öä%20lala/gluegen-rt.jar"},
118 new String[] {
"jar:file:/C:/gluegen/build-x86_64/gluegen-rt.jar!/"},
120 new String[] {
"jar:file:/C:/gluegen/build-x86_64%20öä%20lala/gluegen-rt.jar!/"},
122 new String[] {
"jar:file:/C:/gluegen/build-x86_64/gluegen-rt.jar!/com/jogamp/common/os/Platform.class"},
124 new String[] {
"jar:file:/C:/gluegen/build-x86_64%20öä%20lala/gluegen-rt.jar!/com/jogamp/common/os/Platform.class"},
126 new String[] {
"jar:file:///C:/gluegen/build-x86_64%20öä%20lala/gluegen-rt.jar!/com/jogamp/common/os/Platform.class"},
128 new String[] {
"jar:file://filehost/gluegen/build-x86_64%20öä%20lala/gluegen-rt.jar!/com/jogamp/common/os/Platform.class"},
130 new String[] {
"jar:file:/C:/gluegen/R%23/gluegen-rt.jar!/"},
132 new String[] {
"jar:file:/C:/gluegen/A%24/B%5E/C~/D%23/E%5B/F%5D/gluegen-rt.jar!/"},
134 new String[] {
"jar:file:/C:/gluegen/%24/%5E/~/%23/%5B/%5D/gluegen-rt.jar!/"},
136 new String[] {
"jar:file:/C:/gluegen/"+
'\u0394'+
"/gluegen-rt.jar!/"},
139 public static final String[][] fileSArrayUnix =
new String[][] {
140 new String[] {
"/gluegen/build-x86_64/gluegen-rt.jar",
141 "file:/gluegen/build-x86_64/gluegen-rt.jar",
142 "/gluegen/build-x86_64/gluegen-rt.jar"},
144 new String[] {
"/gluegen/"+
'\u0394'+
"/gluegen-rt.jar",
145 "file:/gluegen/"+
'\u0394'+
"/gluegen-rt.jar",
146 "/gluegen/"+
'\u0394'+
"/gluegen-rt.jar"},
148 new String[] {
"/gluegen/build-x86_64 lala/gluegen-rt.jar",
149 "file:/gluegen/build-x86_64%20lala/gluegen-rt.jar",
150 "/gluegen/build-x86_64 lala/gluegen-rt.jar"},
152 new String[] {
"/gluegen/build-x86_64 öä lala/gluegen-rt.jar",
153 "file:/gluegen/build-x86_64%20öä%20lala/gluegen-rt.jar",
154 "/gluegen/build-x86_64 öä lala/gluegen-rt.jar"},
156 new String[] {
"/gluegen/A$/B^/C~/D#/E[/F]/gluegen-rt.jar",
157 "file:/gluegen/A%24/B%5E/C~/D%23/E%5B/F%5D/gluegen-rt.jar",
158 "/gluegen/A$/B^/C~/D#/E[/F]/gluegen-rt.jar" },
160 new String[] {
"/gluegen/$/^/~/#/[/]/gluegen-rt.jar",
161 "file:/gluegen/%24/%5E/~/%23/%5B/%5D/gluegen-rt.jar",
162 "/gluegen/$/^/~/#/[/]/gluegen-rt.jar" },
165 public static final String[][] fileSArrayWindows =
new String[][] {
166 new String[] {
"C:/gluegen/build-x86_64/gluegen-rt.jar",
167 "file:/C%3A/gluegen/build-x86_64/gluegen-rt.jar",
168 "C:\\gluegen\\build-x86_64\\gluegen-rt.jar"},
170 new String[] {
"C:/gluegen/"+
'\u0394'+
"/gluegen-rt.jar",
171 "file:/C%3A/gluegen/"+
'\u0394'+
"/gluegen-rt.jar",
172 "C:\\gluegen\\"+
'\u0394'+
"\\gluegen-rt.jar"},
174 new String[] {
"C:/gluegen/build-x86_64 lala/gluegen-rt.jar",
175 "file:/C%3A/gluegen/build-x86_64%20lala/gluegen-rt.jar",
176 "C:\\gluegen\\build-x86_64 lala\\gluegen-rt.jar"},
178 new String[] {
"C:/gluegen/build-x86_64 öä lala/gluegen-rt.jar",
179 "file:/C%3A/gluegen/build-x86_64%20öä%20lala/gluegen-rt.jar",
180 "C:\\gluegen\\build-x86_64 öä lala\\gluegen-rt.jar"},
182 new String[] {
"C:\\gluegen\\build-x86_64 öä lala\\gluegen-rt.jar",
183 "file:/C%3A/gluegen/build-x86_64%20öä%20lala/gluegen-rt.jar",
184 "C:\\gluegen\\build-x86_64 öä lala\\gluegen-rt.jar"},
186 new String[] {
"\\\\filehost\\gluegen\\build-x86_64 öä lala\\gluegen-rt.jar",
187 "file://filehost/gluegen/build-x86_64%20öä%20lala/gluegen-rt.jar",
188 "\\\\filehost\\gluegen\\build-x86_64 öä lala\\gluegen-rt.jar"},
190 new String[] {
"C:/gluegen/A$/B^/C~/D#/E[/F]/gluegen-rt.jar",
191 "file:/C%3A/gluegen/A%24/B%5E/C~/D%23/E%5B/F%5D/gluegen-rt.jar",
192 "C:\\gluegen\\A$\\B^\\C~\\D#\\E[\\F]\\gluegen-rt.jar" },
194 new String[] {
"C:/gluegen/$/^/~/#/[/]/gluegen-rt.jar",
195 "file:/C%3A/gluegen/%24/%5E/~/%23/%5B/%5D/gluegen-rt.jar",
196 "C:\\gluegen\\$\\^\\~\\#\\[\\]\\gluegen-rt.jar" },
201 testUri2URL(getSimpleTestName(
"."), uriHttpSArray);
206 testUri2URL(getSimpleTestName(
"."), uriFileSArrayUnix);
211 testUri2URL(getSimpleTestName(
"."), uriFileSArrayWindows);
216 testURL2Uri(getSimpleTestName(
"."), uriHttpSArray);
221 testURL2Uri(getSimpleTestName(
"."), uriFileSArrayUnix);
226 testURL2Uri(getSimpleTestName(
"."), urlFileSArrayWindows);
231 if( PlatformTypes.OSType.WINDOWS != PlatformProps.OS ) {
232 testFile2Uri(getSimpleTestName(
"."), fileSArrayUnix);
238 if( PlatformTypes.OSType.WINDOWS == PlatformProps.OS ) {
239 testFile2Uri(getSimpleTestName(
"."), fileSArrayWindows);
243 static void testUri2URL(
final String testname,
final String[][] uriSArray)
throws IOException, URISyntaxException {
245 for(
int i=0; i<uriSArray.length; i++) {
246 final String[] uriSPair = uriSArray[i];
247 final String uriSource = uriSPair[0];
248 System.err.println(
"SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS "+testname+
": "+(i+1)+
"/"+uriSArray.length);
249 ok = testUri2URL(Uri.Encoded.cast(uriSource)) && ok;
250 System.err.println(
"EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE "+testname+
": "+(i+1)+
"/"+uriSArray.length);
252 Assert.assertTrue(
"One or more errors occured see stderr above", ok);
255 static boolean testUri2URL(
final Uri.Encoded uriSource)
throws IOException, URISyntaxException {
256 System.err.println(
"uriSource : "+uriSource);
257 final Uri uri0 =
new Uri(uriSource);
258 URIDumpUtil.showUri(uri0);
260 final URI actualURI = uri0.toURI();
261 URIDumpUtil.showURI(actualURI);
262 final Uri.Encoded actualURIStr = Uri.Encoded.cast(actualURI.toString());
264 final URL actualURL = uri0.toURL();
265 URIDumpUtil.showURL(actualURL);
266 final Uri.Encoded actualURLStr = Uri.Encoded.cast(actualURL.toExternalForm());
268 System.err.println(
"expected_URX: "+uriSource);
270 final boolean equalsURI = uriSource.equals(actualURIStr);
271 System.err.println(
"actual URI: "+actualURIStr+
" - "+(equalsURI?
"OK":
"ERROR"));
272 final boolean equalsURL = uriSource.equals(actualURLStr);
273 System.err.println(
"actual URL: "+actualURLStr+
" - "+(equalsURL?
"OK":
"ERROR"));
274 URIDumpUtil.showReencodedURIOfUri(uri0);
275 URIDumpUtil.showReencodedUriOfURI(actualURI);
277 boolean ok = equalsURL && equalsURI;
281 URLConnection con =
null;
283 con = actualURL.openConnection();
284 }
catch (
final Throwable _t) {
288 System.err.println(
"XXX: "+t.getClass().getName()+
": "+t.getMessage());
291 System.err.println(
"XXX: No openConnection() failure");
292 System.err.println(
"XXX: "+con);
295 if( uri0.scheme.toString().equals(Uri.JAR_SCHEME) ) {
297 final Uri uriSub0 = uri0.getContainedUri();
298 Assert.assertNotNull(uriSub0);
299 System.err.println(
"EXT JAR contained:");
300 URIDumpUtil.showUri(uriSub0);
301 final Uri uriSubDir0 = uriSub0.getDirectory();
302 final Uri uriSubParent0 = uriSub0.getParent();
303 System.err.println(
"EXT JAR contained Dir:");
304 URIDumpUtil.showUri(uriSubDir0);
305 System.err.println(
"EXT JAR contained Parent:");
306 URIDumpUtil.showUri(uriSubParent0);
307 ok = uriSubDir0.equals(uriSubParent0) && ok;
312 static void testURL2Uri(
final String testname,
final String[][] urlSArray)
throws IOException, URISyntaxException {
314 for(
int i=0; i<urlSArray.length; i++) {
315 final String[] uriSPair = urlSArray[i];
316 final String uriSource = uriSPair[0];
317 System.err.println(
"SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS "+testname+
": "+(i+1)+
"/"+urlSArray.length);
318 ok = testURL2Uri(
new URL(uriSource)) && ok;
319 System.err.println(
"EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE "+testname+
": "+(i+1)+
"/"+urlSArray.length);
321 Assert.assertTrue(
"One or more errors occured see stderr above", ok);
324 static boolean testURL2Uri(
final URL urlSource)
throws IOException, URISyntaxException {
325 System.err.println(
"URL Source : "+urlSource);
326 URIDumpUtil.showURL(urlSource);
328 final URI uriSource = urlSource.toURI();
329 URIDumpUtil.showURI(uriSource);
331 final Uri uri0 = Uri.valueOf(urlSource);
332 URIDumpUtil.showUri(uri0);
334 final URL uriToURL = uri0.toURL();
335 URIDumpUtil.showURL(uriToURL);
339 URLConnection con =
null;
341 con = uriToURL.openConnection();
342 }
catch (
final Throwable _t) {
346 System.err.println(
"XXX: "+t.getClass().getName()+
": "+t.getMessage());
349 System.err.println(
"XXX: No openConnection() failure");
350 System.err.println(
"XXX: "+con);
355 if( uri0.scheme.toString().equals(Uri.JAR_SCHEME) ) {
357 final Uri uriSub0 = uri0.getContainedUri();
358 Assert.assertNotNull(uriSub0);
359 System.err.println(
"EXT JAR contained:");
360 URIDumpUtil.showUri(uriSub0);
361 final Uri uriSubDir0 = uriSub0.getDirectory();
362 final Uri uriSubParent0 = uriSub0.getParent();
363 System.err.println(
"EXT JAR contained Dir:");
364 URIDumpUtil.showUri(uriSubDir0);
365 System.err.println(
"EXT JAR contained Parent:");
366 URIDumpUtil.showUri(uriSubParent0);
367 ok = uriSubDir0.equals(uriSubParent0) && ok;
372 static void testFile2Uri(
final String testname,
final String[][] uriSArray)
throws IOException, URISyntaxException {
374 for(
int i=0; i<uriSArray.length; i++) {
375 final String[] uriSPair = uriSArray[i];
376 final String uriSource = uriSPair[0];
377 final String uriEncExpected= uriSPair[1];
378 final String fileExpected= uriSPair[2];
379 System.err.println(
"SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS "+testname+
": "+(i+1)+
"/"+uriSArray.length);
380 ok = testFile2Uri(uriSource, Uri.Encoded.cast(uriEncExpected), fileExpected) && ok;
381 System.err.println(
"EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE "+testname+
": "+(i+1)+
"/"+uriSArray.length);
383 Assert.assertTrue(
"One or more errors occured see stderr above", ok);
386 static boolean testFile2Uri(
final String fileSource,
final Uri.Encoded uriEncExpected,
final String fileExpected)
throws IOException, URISyntaxException {
387 System.err.println(
"fileSource: "+fileSource);
388 final File file =
new File(fileSource);
389 System.err.println(
"file: "+file.getAbsolutePath());
391 final Uri uri0 = Uri.valueOf(file);
392 URIDumpUtil.showReencodedURIOfUri(uri0);
394 final URL actualUrl = uri0.toURL();
395 final File actualFile = uri0.toFile();
396 final boolean equalsFilePath = fileExpected.equals(actualFile.getPath());
397 System.err.println(
"expected_path: "+fileExpected);
398 System.err.println(
"actual___file-path: "+actualFile+
" - "+(equalsFilePath?
"OK":
"ERROR"));
399 final boolean equalsEncUri = uriEncExpected.equals(uri0.getEncoded());
400 System.err.println(
"expected__encUri: "+uriEncExpected);
401 System.err.println(
"actual_______Uri: "+uri0.getEncoded()+
" - "+(equalsEncUri?
"OK":
"ERROR"));
402 final boolean ok = equalsEncUri && equalsFilePath;
404 System.err.println(
"actual_______URL: "+actualUrl.toExternalForm());
408 URLConnection con =
null;
410 con = actualUrl.openConnection();
411 }
catch (
final Throwable _t) {
415 System.err.println(
"XXX: "+t.getClass().getName()+
": "+t.getMessage());
418 System.err.println(
"XXX: No openConnection() failure");
419 System.err.println(
"XXX: "+con);
424 public static void main(
final String args[])
throws IOException {
426 org.junit.runner.JUnitCore.
main(tstname);
void test13FileWindowsURL2Uri()
void test03FileWindowsUri2URL()
void test12FileUnixURL2Uri()
void test02FileUnixUri2URL()
void test25FileWindowsURI2URL()
void test24FileUnixURI2URL()
static void main(final String args[])