GlueGen v2.6.0-rc-20250712
GlueGen, Native Binding Generator for Java™ (public API).
TestUri99LaunchOnReservedCharPathBug908.java
Go to the documentation of this file.
1/**
2 * Copyright 2014 JogAmp Community. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without modification, are
5 * permitted provided that the following conditions are met:
6 *
7 * 1. Redistributions of source code must retain the above copyright notice, this list of
8 * conditions and the following disclaimer.
9 *
10 * 2. Redistributions in binary form must reproduce the above copyright notice, this list
11 * of conditions and the following disclaimer in the documentation and/or other materials
12 * provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
15 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
16 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
19 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
21 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
22 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 *
24 * The views and conclusions contained in the software and documentation are those of the
25 * authors and should not be interpreted as representing official policies, either expressed
26 * or implied, of JogAmp Community.
27 */
28
29package com.jogamp.common.net;
30
31import java.io.File;
32import java.io.IOException;
33import java.net.URI;
34import java.net.URISyntaxException;
35import java.net.URL;
36import java.net.URLClassLoader;
37
38import org.junit.Assert;
39import org.junit.FixMethodOrder;
40import org.junit.Test;
41import org.junit.runners.MethodSorters;
42
43import com.jogamp.common.os.AndroidVersion;
44import com.jogamp.common.os.Platform;
45import com.jogamp.common.util.JarUtil;
46import com.jogamp.common.util.ReflectionUtil;
47import com.jogamp.junit.util.SingletonJunitCase;
48import com.jogamp.junit.util.MiscUtils;
49
50/**
51 * Bug 908: Automated test, launching GlueGen jar file from an <i>odd pathname</i>.
52 * <p>
53 * The currently used jar folder is copied into [1]
54 * <pre>
55 * [1] build/test/build/TestNetIOURIReservedCharsBug908/test01TempJarCacheOddPath/A\$-B\^-C~-D#-E\]-F\[-öä
56 * [2] build/test/build/TestNetIOURIReservedCharsBug908/test01TempJarCacheOddPath/A\$-B\^-C~-D#-E\]-F\[-öä/gluegen-rt.jar
57 * </pre>
58 * A ClassLoader w/ the URL [2] is used to issue Platform.initSingleton(),
59 * i.e. issues a whole initialization sequence w/ native jar loading in the new ClassPath.
60 * </p>
61 * <p>
62 * The manual test below on the created odd folder [1] has also succeeded:
63 * <pre>
64 * java \
65 * -Djogamp.debug.IOUtil -Djogamp.debug.JNILibLoader -Djogamp.debug.TempFileCache \
66 * -Djogamp.debug.JarUtil -Djogamp.debug.TempJarCache \
67 * -cp ../build-x86_64/test/build/TestNetIOURIReservedCharsBug908/test01TempJarCacheOddPath/A\$-B\^-C~-D#-E\]-F\[-öä/gluegen-rt.jar \
68 * com.jogamp.common.GlueGenVersion
69 * </pre>
70 * </p>
71 */
72@FixMethodOrder(MethodSorters.NAME_ASCENDING)
74 static class TestClassLoader extends URLClassLoader {
75 public TestClassLoader(final URL[] urls) {
76 super(urls);
77 }
78 public TestClassLoader(final URL[] urls, final ClassLoader parent) {
79 super(urls, parent);
80 }
81 }
82
83
84 @Test
85 public void test00TempJarCacheSimplePath() throws IOException, IllegalArgumentException, URISyntaxException {
86 testTempJarCacheOddJarPathImpl("simpletons/");
87 }
88
89 @Test
90 public void test01TempJarCacheOddPath() throws IOException, IllegalArgumentException, URISyntaxException {
91 // Bug 908, issues w/ windows file path char: $ ^ ~ # [ ]
92 testTempJarCacheOddJarPathImpl("A$-B^-C~-D#-E]-F[-öä/");
93 // "A$-B%5E-C~-D#-E]-F[-%C3%B6%C3%A4/"); <- Firefox URI encoding! '#' -> [1]
94 // "A$-B%5E-C~-D%23-E]-F[-%C3%B6%C3%A4/"); <- '[' ']' -> [2]
95 // "A$-B%5E-C~-D%23-E%5D-F%5B-%C3%B6%C3%A4/");
96 /**
97 * [1] '#'
98 java.lang.IllegalArgumentException: URI has a fragment component
99 at java.io.File.<init>(Unknown Source)
100 at com.jogamp.common.net.TestNetIOURIReservedCharsBug908.testTempJarCacheOddJarPathImpl(TestNetIOURIReservedCharsBug908.java:101)
101 [2] '[' ']'
102 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/
103 at java.net.URI$Parser.fail(Unknown Source)
104 at java.net.URI$Parser.checkChars(Unknown Source)
105 at java.net.URI$Parser.parseHierarchical(Unknown Source)
106 at java.net.URI$Parser.parse(Unknown Source)
107 at java.net.URI.<init>(Unknown Source)
108 at com.jogamp.common.net.TestNetIOURIReservedCharsBug908.testTempJarCacheOddJarPathImpl(TestNetIOURIReservedCharsBug908.java:106)
109
110 */
111
112 }
113 @Test
114 public void test02TempJarCacheOddPath() throws IOException, IllegalArgumentException, URISyntaxException {
115 // Bug 1474, issues w/ windows file path char: ( )
116 testTempJarCacheOddJarPathImpl("Users/(ABC)abc/AppData/Local/Temp/");
117 }
118 private void testTempJarCacheOddJarPathImpl(final String subPathUTF) throws IOException, IllegalArgumentException, URISyntaxException {
119 if(AndroidVersion.isAvailable) { System.err.println("n/a on Android"); return; }
120
121 final Uri.Encoded subPathEncoded = new Uri.Encoded(subPathUTF, Uri.PATH_LEGAL);
122 final String reservedCharPathUnencoded = "test/build/"+getClass().getSimpleName()+"/"+getTestMethodName()+"/"+subPathUTF;
123 final Uri.Encoded reservedCharPathEncoded = Uri.Encoded.cast("test/build/"+getClass().getSimpleName()+"/"+getTestMethodName()+"/").concat(subPathEncoded);
124
125 System.err.println("0 Unencoded: "+reservedCharPathUnencoded);
126 System.err.println("0 Encoded: "+reservedCharPathEncoded);
127
128 // jar:file:/dir1/dir2/gluegen-rt.jar!/
129 final Uri jarFileURI = JarUtil.getJarFileUri(Platform.class.getName(), getClass().getClassLoader());
130 System.err.println("1 jarFileURI: "+jarFileURI.toString());
131 // gluegen-rt.jar
132 final Uri.Encoded jarBasename = JarUtil.getJarBasename(jarFileURI);
133 System.err.println("2 jarBasename: "+jarBasename);
134
135 // file:/dir1/build/gluegen-rt.jar
136 final Uri fileURI = jarFileURI.getContainedUri();
137 System.err.println("3 fileURI: "+fileURI.toString());
138 // file:/dir1/build/
139 final Uri fileFolderURI = fileURI.getParent();
140 System.err.println("4 fileFolderURI: "+fileFolderURI.toString());
141 // file:/dir1/build/test/build/A$-B^-C~-D#-E]-F[/
142 final Uri fileNewFolderURI = fileFolderURI.concat(reservedCharPathEncoded);
143 System.err.println("5 fileNewFolderURI: "+fileNewFolderURI.toString());
144
145 final File srcFolder = fileFolderURI.toFile();
146 final File dstFolder = fileNewFolderURI.toFile();
147 System.err.println("6 srcFolder: "+srcFolder.toString());
148 System.err.println("7 dstFolder: "+dstFolder.toString());
149 try {
150 final MiscUtils.CopyStats copyStats = MiscUtils.copy(srcFolder, dstFolder, 1, true);
151 copyStats.dump("Copy ", true);
152 Assert.assertEquals(1, copyStats.totalFolders);
153 Assert.assertTrue(copyStats.totalBytes > 0);
154 Assert.assertEquals(0, copyStats.currentDepth);
155
156 final URI jarFileNewFolderURI = new URI(fileNewFolderURI.toString()+jarBasename);
157 System.err.println("8 jarFileNewFolderURI: "+jarFileNewFolderURI.toString());
158
159 final URL[] urls = new URL[] { jarFileNewFolderURI.toURL() };
160 System.err.println("url: "+urls[0]);
161
162 final ClassLoader cl = new TestClassLoader(urls, null);
163 ReflectionUtil.callStaticMethod(Platform.class.getName(), "initSingleton", null, null, cl);
164 } finally {
165 // cleanup ? Skip this for now ..
166 // dstFolder.delete();
167 }
168 }
169
170 public static void main(final String args[]) throws IOException {
171 final String tstname = TestUri99LaunchOnReservedCharPathBug908.class.getName();
172 org.junit.runner.JUnitCore.main(tstname);
173 }
174
175}
Bug 908: Automated test, launching GlueGen jar file from an odd pathname.