Direct-BT v3.3.0-1-gc2d430c
Direct-BT - Direct Bluetooth Programming.
TestUri99LaunchOnReservedCharPathBug908.java
Go to the documentation of this file.
1/**
2 * Author: Sven Gothel <sgothel@jausoft.com>
3 * Copyright (c) 2021 Gothel Software e.K.
4 * Copyright (c) 2014 Gothel Software e.K.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining
7 * a copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sublicense, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be
15 * included in all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 */
25
26package jau.test.net;
27
28import java.io.File;
29import java.io.IOException;
30import java.net.URI;
31import java.net.URISyntaxException;
32import java.net.URL;
33import java.net.URLClassLoader;
34
35import org.jau.lang.ReflectionUtil;
36import org.jau.net.Uri;
37import org.jau.pkg.JarUtil;
38import org.jau.sys.AndroidVersion;
39import org.jau.sys.RuntimeProps;
40import org.junit.Assert;
41import org.junit.FixMethodOrder;
42import org.junit.Test;
43import org.junit.runners.MethodSorters;
44
45import jau.test.junit.util.JunitTracer;
46import jau.test.junit.util.MiscUtils;
47
48/**
49 * Bug 908: Automated test, launching GlueGen jar file from an <i>odd pathname</i>.
50 * <p>
51 * The currently used jar folder is copied into [1]
52 * <pre>
53 * [1] build/test/build/TestNetIOURIReservedCharsBug908/test01TempJarCacheOddPath/A\$-B\^-C~-D#-E\]-F\[-öä
54 * [2] build/test/build/TestNetIOURIReservedCharsBug908/test01TempJarCacheOddPath/A\$-B\^-C~-D#-E\]-F\[-öä/gluegen-rt.jar
55 * </pre>
56 * A ClassLoader w/ the URL [2] is used to issue Platform.initSingleton(),
57 * i.e. issues a whole initialization sequence w/ native jar loading in the new ClassPath.
58 * </p>
59 * <p>
60 * The manual test below on the created odd folder [1] has also succeeded:
61 * <pre>
62 * java \
63 * -Djogamp.debug.IOUtil -Djogamp.debug.JNILibLoader -Djogamp.debug.TempFileCache \
64 * -Djogamp.debug.JarUtil -Djogamp.debug.TempJarCache \
65 * -cp ../build-x86_64/test/build/TestNetIOURIReservedCharsBug908/test01TempJarCacheOddPath/A\$-B\^-C~-D#-E\]-F\[-öä/gluegen-rt.jar \
66 * com.jogamp.common.GlueGenVersion
67 * </pre>
68 * </p>
69 */
70@FixMethodOrder(MethodSorters.NAME_ASCENDING)
72 static class TestClassLoader extends URLClassLoader {
73 public TestClassLoader(final URL[] urls) {
74 super(urls);
75 }
76 public TestClassLoader(final URL[] urls, final ClassLoader parent) {
77 super(urls, parent);
78 }
79 }
80
81
82 @Test
83 public void test00TempJarCacheSimplePath() throws IOException, IllegalArgumentException, URISyntaxException {
84 testTempJarCacheOddJarPathImpl("simpletons/");
85 }
86
87 @Test
88 public void test01TempJarCacheOddPath() throws IOException, IllegalArgumentException, URISyntaxException {
89 // Bug 908, issues w/ windows file path char: $ ^ ~ # [ ]
90 testTempJarCacheOddJarPathImpl("A$-B^-C~-D#-E]-F[-öä/");
91 // "A$-B%5E-C~-D#-E]-F[-%C3%B6%C3%A4/"); <- Firefox URI encoding! '#' -> [1]
92 // "A$-B%5E-C~-D%23-E]-F[-%C3%B6%C3%A4/"); <- '[' ']' -> [2]
93 // "A$-B%5E-C~-D%23-E%5D-F%5B-%C3%B6%C3%A4/");
94 /**
95 * [1] '#'
96 java.lang.IllegalArgumentException: URI has a fragment component
97 at java.io.File.<init>(Unknown Source)
98 at com.jogamp.common.net.TestNetIOURIReservedCharsBug908.testTempJarCacheOddJarPathImpl(TestNetIOURIReservedCharsBug908.java:101)
99 [2] '[' ']'
100 java.net.URISyntaxException: Illegal character in path at index 137: file:/usr/local/projects/JOGL/gluegen/build-x86_64/test/build/TestNetIOURIReservedCharsBug908/test01TempJarCacheOddPath/A$-B%5E-C~-D%23-E]-F[-%C3%B6%C3%A4/
101 at java.net.URI$Parser.fail(Unknown Source)
102 at java.net.URI$Parser.checkChars(Unknown Source)
103 at java.net.URI$Parser.parseHierarchical(Unknown Source)
104 at java.net.URI$Parser.parse(Unknown Source)
105 at java.net.URI.<init>(Unknown Source)
106 at com.jogamp.common.net.TestNetIOURIReservedCharsBug908.testTempJarCacheOddJarPathImpl(TestNetIOURIReservedCharsBug908.java:106)
107
108 */
109
110 }
111 private void testTempJarCacheOddJarPathImpl(final String subPathUTF) throws IOException, IllegalArgumentException, URISyntaxException {
112 if(AndroidVersion.isAvailable) { System.err.println("n/a on Android"); return; }
113
114 final Uri.Encoded subPathEncoded = new Uri.Encoded(subPathUTF, Uri.PATH_LEGAL);
115 final String reservedCharPathUnencoded = "test/build/"+getClass().getSimpleName()+"/"+getTestMethodName()+"/"+subPathUTF;
116 final Uri.Encoded reservedCharPathEncoded = Uri.Encoded.cast("test/build/"+getClass().getSimpleName()+"/"+getTestMethodName()+"/").concat(subPathEncoded);
117
118 System.err.println("0 Unencoded: "+reservedCharPathUnencoded);
119 System.err.println("0 Encoded: "+reservedCharPathEncoded);
120
121 // jar:file:/dir1/dir2/gluegen-rt.jar!/
122 final Uri jarFileURI = JarUtil.getJarFileUri(RuntimeProps.class.getName(), getClass().getClassLoader());
123 System.err.println("1 jarFileURI: "+jarFileURI.toString());
124 // gluegen-rt.jar
125 final Uri.Encoded jarBasename = JarUtil.getJarBasename(jarFileURI);
126 System.err.println("2 jarBasename: "+jarBasename);
127
128 // file:/dir1/build/gluegen-rt.jar
129 final Uri fileURI = jarFileURI.getContainedUri();
130 System.err.println("3 fileURI: "+fileURI.toString());
131 // file:/dir1/build/
132 final Uri fileFolderURI = fileURI.getParent();
133 System.err.println("4 fileFolderURI: "+fileFolderURI.toString());
134 // file:/dir1/build/test/build/A$-B^-C~-D#-E]-F[/
135 final Uri fileNewFolderURI = fileFolderURI.concat(reservedCharPathEncoded);
136 System.err.println("5 fileNewFolderURI: "+fileNewFolderURI.toString());
137
138 final File srcFolder = fileFolderURI.toFile();
139 final File dstFolder = fileNewFolderURI.toFile();
140 System.err.println("6 srcFolder: "+srcFolder.toString());
141 System.err.println("7 dstFolder: "+dstFolder.toString());
142 try {
143 final MiscUtils.CopyStats copyStats = MiscUtils.copy(srcFolder, dstFolder, 1, true);
144 copyStats.dump("Copy ", true);
145 Assert.assertEquals(1, copyStats.totalFolders);
146 Assert.assertTrue(copyStats.totalBytes > 0);
147 Assert.assertEquals(0, copyStats.currentDepth);
148
149 final URI jarFileNewFolderURI = new URI(fileNewFolderURI.toString()+jarBasename);
150 System.err.println("8 jarFileNewFolderURI: "+jarFileNewFolderURI.toString());
151
152 final URL[] urls = new URL[] { jarFileNewFolderURI.toURL() };
153 System.err.println("url: "+urls[0]);
154
155 final ClassLoader cl = new TestClassLoader(urls, null);
156 ReflectionUtil.callStaticMethod(RuntimeProps.class.getName(), "initSingleton", null, null, cl);
157 } finally {
158 // cleanup ? Skip this for now ..
159 // dstFolder.delete();
160 }
161 }
162
163 public static void main(final String args[]) throws IOException {
164 final String tstname = TestUri99LaunchOnReservedCharPathBug908.class.getName();
165 org.junit.runner.JUnitCore.main(tstname);
166 }
167
168}
Bug 908: Automated test, launching GlueGen jar file from an odd pathname.