diff options
author | Sven Gothel <[email protected]> | 2013-10-24 20:30:31 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2013-10-24 20:30:31 +0200 |
commit | bb7c2da1ed6791bf50a32a880a939cdaecf82701 (patch) | |
tree | f4afa51ac6f483eaf2d88d7ffc192002ee87c582 /src/junit/com | |
parent | aa7a0d3a3feee1360ae4d7465a9da263aea530ac (diff) |
Use org.junit.Assert instead of deprecated junit.framework.Assert
Diffstat (limited to 'src/junit/com')
7 files changed, 187 insertions, 194 deletions
diff --git a/src/junit/com/jogamp/common/util/TestJarUtil.java b/src/junit/com/jogamp/common/util/TestJarUtil.java index 18fcaa7..6434469 100644 --- a/src/junit/com/jogamp/common/util/TestJarUtil.java +++ b/src/junit/com/jogamp/common/util/TestJarUtil.java @@ -3,14 +3,14 @@ * * Redistribution and use in source and binary forms, with or without modification, are * permitted provided that the following conditions are met: - * + * * 1. Redistributions of source code must retain the above copyright notice, this list of * conditions and the following disclaimer. - * + * * 2. Redistributions in binary form must reproduce the above copyright notice, this list * of conditions and the following disclaimer in the documentation and/or other materials * provided with the distribution. - * + * * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR @@ -20,12 +20,12 @@ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * + * * The views and conclusions contained in the software and documentation are those of the * authors and should not be interpreted as representing official policies, either expressed * or implied, of JogAmp Community. */ - + package com.jogamp.common.util; import java.io.IOException; @@ -41,8 +41,7 @@ import java.util.Enumeration; import java.util.jar.JarEntry; import java.util.jar.JarFile; -import junit.framework.Assert; - +import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Test; @@ -59,7 +58,7 @@ import org.junit.runners.MethodSorters; @FixMethodOrder(MethodSorters.NAME_ASCENDING) public class TestJarUtil extends JunitTracer { static TempFileCache fileCache; - + @BeforeClass public static void init() { if(AndroidVersion.isAvailable) { @@ -71,12 +70,12 @@ public class TestJarUtil extends JunitTracer { // Assert.assertFalse(TempCacheReg.isTempFileCacheUsed()); Assert.assertTrue(TempFileCache.initSingleton()); Assert.assertTrue(TempCacheReg.isTempFileCacheUsed()); - + fileCache = new TempFileCache(); Assert.assertTrue(fileCache.isValid()); System.err.println("tmp dir: "+fileCache.getTempDir()); } - + static class TestClassLoader extends URLClassLoader { public TestClassLoader(URL[] urls) { super(urls); @@ -85,9 +84,9 @@ public class TestJarUtil extends JunitTracer { super(urls, parent); } } - + void validateJarFile(JarFile jarFile) throws IllegalArgumentException, IOException { - Assert.assertNotNull(jarFile); + Assert.assertNotNull(jarFile); Assert.assertTrue("jarFile has zero entries: "+jarFile, jarFile.size()>0); Enumeration<JarEntry> entries = jarFile.entries(); System.err.println("Entries of "+jarFile.getName()+": "); @@ -97,7 +96,7 @@ public class TestJarUtil extends JunitTracer { i++; } } - + void validateJarFileURL(URI jarFileURI) throws IllegalArgumentException, IOException, URISyntaxException { Assert.assertNotNull(jarFileURI); final URL jarFileURL = IOUtil.toURL(jarFileURI); @@ -109,26 +108,26 @@ public class TestJarUtil extends JunitTracer { JarFile jarFile = jURLc.getJarFile(); validateJarFile(jarFile); } - + void validateJarUtil(String expJarName, String clazzBinName, ClassLoader cl) throws IllegalArgumentException, IOException, URISyntaxException { String jarName= JarUtil.getJarBasename(clazzBinName, cl); Assert.assertNotNull(jarName); Assert.assertEquals(expJarName, jarName); - + URI jarSubURI = JarUtil.getJarSubURI(clazzBinName, cl); Assert.assertNotNull(jarSubURI); final URL jarSubURL= IOUtil.toURL(jarSubURI); URLConnection urlConn = jarSubURL.openConnection(); Assert.assertTrue("jarSubURL has zero content: "+jarSubURL, urlConn.getContentLength()>0); System.err.println("URLConnection of jarSubURL: "+urlConn); - + URI jarFileURL = JarUtil.getJarFileURI(clazzBinName, cl); validateJarFileURL(jarFileURL); - + JarFile jarFile = JarUtil.getJarFile(clazzBinName, cl); validateJarFile(jarFile); } - + @Test public void testJarUtilFlat01() throws IOException, IllegalArgumentException, URISyntaxException { System.err.println("XXXXXXXXXXXXXXXXXXXXXXXXXXXX"); @@ -139,56 +138,56 @@ public class TestJarUtil extends JunitTracer { @Test public void testJarUtilJarInJar01() throws IOException, ClassNotFoundException, IllegalArgumentException, URISyntaxException { System.err.println("XXXXXXXXXXXXXXXXXXXXXXXXXXXX"); - + Assert.assertTrue(TempJarCache.initSingleton()); Assert.assertTrue(TempCacheReg.isTempJarCacheUsed()); Assert.assertTrue(TempJarCache.isInitialized()); - + final ClassLoader rootCL = this.getClass().getClassLoader(); - + // Get containing JAR file "TestJarsInJar.jar" and add it to the TempJarCache - TempJarCache.addAll(GlueGenVersion.class, JarUtil.getJarFileURI("ClassInJar0", rootCL)); - + TempJarCache.addAll(GlueGenVersion.class, JarUtil.getJarFileURI("ClassInJar0", rootCL)); + // Fetch and load the contained "ClassInJar1.jar" final URL ClassInJar1_jarFileURL = JarUtil.getJarFileURI(TempJarCache.getResource("ClassInJar1.jar")).toURL(); final ClassLoader cl = new URLClassLoader(new URL[] { ClassInJar1_jarFileURL }, rootCL); - Assert.assertNotNull(cl); + Assert.assertNotNull(cl); validateJarUtil("ClassInJar1.jar", "ClassInJar1", cl); System.err.println("XXXXXXXXXXXXXXXXXXXXXXXXXXXX"); } - + @Test public void testJarUtilJarInJar02() throws IOException, ClassNotFoundException, IllegalArgumentException, URISyntaxException { System.err.println("XXXXXXXXXXXXXXXXXXXXXXXXXXXX"); - + Assert.assertTrue(TempJarCache.initSingleton()); Assert.assertTrue(TempCacheReg.isTempJarCacheUsed()); Assert.assertTrue(TempJarCache.isInitialized()); - + final ClassLoader rootCL = this.getClass().getClassLoader(); - + // Get containing JAR file "TestJarsInJar.jar" and add it to the TempJarCache TempJarCache.addAll(GlueGenVersion.class, JarUtil.getJarFileURI("ClassInJar0", rootCL)); - + // Fetch and load the contained "ClassInJar1.jar" final URL ClassInJar2_jarFileURL = JarUtil.getJarFileURI(TempJarCache.getResource("sub/ClassInJar2.jar")).toURL(); final ClassLoader cl = new URLClassLoader(new URL[] { ClassInJar2_jarFileURL }, rootCL); - Assert.assertNotNull(cl); + Assert.assertNotNull(cl); validateJarUtil("ClassInJar2.jar", "ClassInJar2", cl); System.err.println("XXXXXXXXXXXXXXXXXXXXXXXXXXXX"); } - + /** * Tests JarUtil's ability to resolve non-JAR URLs with a custom resolver. Meant to be used * in cases like an OSGi plugin, where all classes are loaded with custom classloaders and * therefore return URLs that don't start with "jar:". Adapted from test 02 above. - * @throws URISyntaxException - * @throws IllegalArgumentException + * @throws URISyntaxException + * @throws IllegalArgumentException */ @Test public void testJarUtilJarInJar03() throws IOException, ClassNotFoundException, IllegalArgumentException, URISyntaxException { System.err.println("XXXXXXXXXXXXXXXXXXXXXXXXXXXX"); - + Assert.assertTrue(TempJarCache.initSingleton()); Assert.assertTrue(TempCacheReg.isTempJarCacheUsed()); Assert.assertTrue(TempJarCache.isInitialized()); @@ -243,18 +242,18 @@ public class TestJarUtil extends JunitTracer { } ); final ClassLoader rootCL = new CustomClassLoader(); - + // Get containing JAR file "TestJarsInJar.jar" and add it to the TempJarCache TempJarCache.addAll(GlueGenVersion.class, JarUtil.getJarFileURI("ClassInJar0", rootCL)); - + // Fetch and load the contained "ClassInJar1.jar" final URL ClassInJar2_jarFileURL = JarUtil.getJarFileURI(TempJarCache.getResource("sub/ClassInJar2.jar")).toURL(); final ClassLoader cl = new URLClassLoader(new URL[] { ClassInJar2_jarFileURL }, rootCL); - Assert.assertNotNull(cl); + Assert.assertNotNull(cl); validateJarUtil("ClassInJar2.jar", "ClassInJar2", cl); System.err.println("XXXXXXXXXXXXXXXXXXXXXXXXXXXX"); } - + public static void main(String args[]) throws IOException { String tstname = TestJarUtil.class.getName(); org.junit.runner.JUnitCore.main(tstname); diff --git a/src/junit/com/jogamp/common/util/TestTempJarCache.java b/src/junit/com/jogamp/common/util/TestTempJarCache.java index 7ddf52a..a4518f0 100644 --- a/src/junit/com/jogamp/common/util/TestTempJarCache.java +++ b/src/junit/com/jogamp/common/util/TestTempJarCache.java @@ -3,14 +3,14 @@ * * Redistribution and use in source and binary forms, with or without modification, are * permitted provided that the following conditions are met: - * + * * 1. Redistributions of source code must retain the above copyright notice, this list of * conditions and the following disclaimer. - * + * * 2. Redistributions in binary form must reproduce the above copyright notice, this list * of conditions and the following disclaimer in the documentation and/or other materials * provided with the distribution. - * + * * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR @@ -20,12 +20,12 @@ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * + * * The views and conclusions contained in the software and documentation are those of the * authors and should not be interpreted as representing official policies, either expressed * or implied, of JogAmp Community. */ - + package com.jogamp.common.util; import java.io.File; @@ -38,8 +38,7 @@ import java.net.URL; import java.net.URLClassLoader; import java.util.jar.JarFile; -import junit.framework.Assert; - +import org.junit.Assert; import org.junit.BeforeClass; import org.junit.FixMethodOrder; import org.junit.Test; @@ -58,7 +57,7 @@ import com.jogamp.junit.util.JunitTracer; @FixMethodOrder(MethodSorters.NAME_ASCENDING) public class TestTempJarCache extends JunitTracer { static TempFileCache fileCache; - + static class TestClassLoader extends URLClassLoader { public TestClassLoader(URL[] urls) { super(urls); @@ -67,81 +66,81 @@ public class TestTempJarCache extends JunitTracer { super(urls, parent); } } - + static void assertTempFileCachesIndividualInstances(boolean shallBeSame, TempFileCache fileCache2, TempFileCache fileCache3) { Assert.assertTrue(fileCache2.getTempDir().exists()); Assert.assertTrue(fileCache2.getTempDir().isDirectory()); Assert.assertTrue(fileCache3.getTempDir().exists()); Assert.assertTrue(fileCache3.getTempDir().isDirectory()); - + Assert.assertEquals(fileCache2.getBaseDir(), fileCache3.getBaseDir()); Assert.assertEquals(fileCache2.getRootDir(), fileCache3.getRootDir()); - + if(shallBeSame) { - Assert.assertTrue("file caches are not equal", fileCache2.getTempDir().equals(fileCache3.getTempDir())); + Assert.assertTrue("file caches are not equal", fileCache2.getTempDir().equals(fileCache3.getTempDir())); } else { - Assert.assertFalse("file caches are equal", fileCache2.getTempDir().equals(fileCache3.getTempDir())); + Assert.assertFalse("file caches are equal", fileCache2.getTempDir().equals(fileCache3.getTempDir())); } - // also verify with diff classloader/reflection method, + // also verify with diff classloader/reflection method, // to proof that methodology is valid! ClassLoader cl = fileCache2.getClass().getClassLoader(); assertTempFileCachesIndividualInstances(shallBeSame, fileCache2, cl, fileCache3, cl); } - + static void assertTempFileCachesIndividualInstances(boolean shallBeSame, Object fileCache2, ClassLoader cl2, Object fileCache3, ClassLoader cl3) { Class<?> fileCacheClazz2 = ReflectionUtil.getClass(TempFileCache.class.getName(), false, cl2); Class<?> fileCacheClazz3 = ReflectionUtil.getClass(TempFileCache.class.getName(), false, cl3); Method fc2GetBaseDir = ReflectionUtil.getMethod(fileCacheClazz2 , "getBaseDir"); - Method fc3GetBaseDir = ReflectionUtil.getMethod(fileCacheClazz3 , "getBaseDir"); + Method fc3GetBaseDir = ReflectionUtil.getMethod(fileCacheClazz3 , "getBaseDir"); Object baseDir2 = ReflectionUtil.callMethod(fileCache2, fc2GetBaseDir); Object baseDir3 = ReflectionUtil.callMethod(fileCache3, fc3GetBaseDir); Assert.assertEquals(baseDir2, baseDir3); - + Method fc2GetRootDir = ReflectionUtil.getMethod(fileCacheClazz2 , "getRootDir"); - Method fc3GetRootDir = ReflectionUtil.getMethod(fileCacheClazz3 , "getRootDir"); + Method fc3GetRootDir = ReflectionUtil.getMethod(fileCacheClazz3 , "getRootDir"); Object rootDir2 = ReflectionUtil.callMethod(fileCache2, fc2GetRootDir); Object rootDir3 = ReflectionUtil.callMethod(fileCache3, fc3GetRootDir); Assert.assertEquals(rootDir2, rootDir3); - + Method fc2GetTempDir = ReflectionUtil.getMethod(fileCacheClazz2 , "getTempDir"); - Method fc3GetTempDir = ReflectionUtil.getMethod(fileCacheClazz3 , "getTempDir"); + Method fc3GetTempDir = ReflectionUtil.getMethod(fileCacheClazz3 , "getTempDir"); Object tempDir2 = ReflectionUtil.callMethod(fileCache2, fc2GetTempDir); Object tempDir3 = ReflectionUtil.callMethod(fileCache3, fc3GetTempDir); - + if(shallBeSame) { Assert.assertTrue("file caches are not equal", tempDir2.equals(tempDir3)); } else { Assert.assertFalse("file caches are equal", tempDir2.equals(tempDir3)); } } - + @BeforeClass public static void init() { // may already been initialized by other test // Assert.assertFalse(TempCacheReg.isTempFileCacheUsed()); Assert.assertTrue(TempFileCache.initSingleton()); Assert.assertTrue(TempCacheReg.isTempFileCacheUsed()); - + fileCache = new TempFileCache(); Assert.assertTrue(fileCache.isValid()); System.err.println("tmp dir: "+fileCache.getTempDir()); } - + @Test public void testTempFileCache01FileExist() throws IOException { Assert.assertTrue(fileCache.getTempDir().exists()); Assert.assertTrue(fileCache.getTempDir().isDirectory()); } - + @Test - public void testTempFileCache02Instances() throws IOException { + public void testTempFileCache02Instances() throws IOException { TempFileCache fileCache2 = new TempFileCache(); TempFileCache fileCache3 = new TempFileCache(); - + assertTempFileCachesIndividualInstances(false, fileCache2, fileCache3); } - + @Test public void testJarUtil01a() throws IOException, IllegalArgumentException, URISyntaxException { if(AndroidVersion.isAvailable) { System.err.println("n/a on Android"); return; } @@ -162,51 +161,51 @@ public class TestTempJarCache extends JunitTracer { f = new File(fileCache.getTempDir(), IOUtil.getClassFileName(GlueGenVersion.class.getName())); Assert.assertTrue(f.exists()); } - + @Test public void testTempJarCache00Init() throws IOException { // may already been initialized by other test // Assert.assertFalse(TempCacheReg.isTempJarCacheUsed()); - // Assert.assertFalse(TempJarCache.isInitialized()); + // Assert.assertFalse(TempJarCache.isInitialized()); Assert.assertTrue(TempJarCache.initSingleton()); Assert.assertTrue(TempCacheReg.isTempJarCacheUsed()); - Assert.assertTrue(TempJarCache.isInitialized()); + Assert.assertTrue(TempJarCache.isInitialized()); } - + @Test public void testTempJarCache01LoadAllTestManifestAndClass() throws IOException, SecurityException, IllegalArgumentException, URISyntaxException { if(AndroidVersion.isAvailable) { System.err.println("n/a on Android"); return; } final ClassLoader cl = getClass().getClassLoader(); TempJarCache.addAll(GlueGenVersion.class, JarUtil.getJarFileURI(GlueGenVersion.class.getName(), cl)); - + File f0 = new File(TempJarCache.getTempFileCache().getTempDir(), "META-INF/MANIFEST.MF"); Assert.assertTrue(f0.exists()); - + File f1 = new File(TempJarCache.findResource("META-INF/MANIFEST.MF")); Assert.assertTrue(f1.exists()); Assert.assertEquals(f0, f1); f0 = new File(TempJarCache.getTempFileCache().getTempDir(), IOUtil.getClassFileName(GlueGenVersion.class.getName())); Assert.assertTrue(f0.exists()); - + f1 = new File(TempJarCache.findResource(IOUtil.getClassFileName(GlueGenVersion.class.getName()))); Assert.assertTrue(f1.exists()); Assert.assertEquals(f0, f1); } - + @Test public void testTempJarCache02AddNativeLibs() throws IOException, IllegalArgumentException, URISyntaxException { if(AndroidVersion.isAvailable) { System.err.println("n/a on Android"); return; } final String nativeJarName = "gluegen-rt-natives-"+Platform.getOSAndArch()+".jar"; - final String libBaseName = "gluegen-rt"; + final String libBaseName = "gluegen-rt"; final ClassLoader cl = getClass().getClassLoader(); - + URI jarUriRoot = JarUtil.getJarSubURI(TempJarCache.class.getName(), cl); jarUriRoot = IOUtil.getURIDirname(jarUriRoot); - - URI nativeJarURI = JarUtil.getJarFileURI(jarUriRoot, nativeJarName); - + + URI nativeJarURI = JarUtil.getJarFileURI(jarUriRoot, nativeJarName); + TempJarCache.addNativeLibs(TempJarCache.class, nativeJarURI, null /* nativeLibraryPath */); String libFullPath = TempJarCache.findLibrary(libBaseName); Assert.assertNotNull(libFullPath); @@ -218,36 +217,36 @@ public class TestTempJarCache extends JunitTracer { @Test public void testTempJarCache03AddNativeJarLibs() throws IOException { if(AndroidVersion.isAvailable) { System.err.println("n/a on Android"); return; } - final String libBaseName = "gluegen-rt"; - + final String libBaseName = "gluegen-rt"; + JNILibLoaderBase.addNativeJarLibs(TempJarCache.class, libBaseName); Assert.assertTrue(JNILibLoaderBase.isLoaded(libBaseName)); - + String libFullPath = TempJarCache.findLibrary(libBaseName); Assert.assertNotNull(libFullPath); Assert.assertEquals(libBaseName, NativeLibrary.isValidNativeLibraryName(libFullPath, true)); File f = new File(libFullPath); Assert.assertTrue(f.exists()); } - + @Test public void testTempJarCache04aSameClassLoader() throws IOException { assertTempFileCachesIndividualInstances(true, TempJarCache.getTempFileCache(), TempJarCache.getTempFileCache()); - - ClassLoader cl = getClass().getClassLoader(); + + ClassLoader cl = getClass().getClassLoader(); TempFileCache fileCache2 = (TempFileCache) ReflectionUtil.callStaticMethod(TempJarCache.class.getName(), "getTempFileCache", null, null, cl); TempFileCache fileCache3 = (TempFileCache) ReflectionUtil.callStaticMethod(TempJarCache.class.getName(), "getTempFileCache", null, null, cl); assertTempFileCachesIndividualInstances(true, fileCache2, fileCache3); } - + @Test public void testTempJarCache04bDiffClassLoader() throws IOException, IllegalArgumentException, URISyntaxException { if(AndroidVersion.isAvailable) { System.err.println("n/a on Android"); return; } - URL[] urls = new URL[] { JarUtil.getJarFileURI(TempJarCache.class.getName(), getClass().getClassLoader()).toURL() }; + URL[] urls = new URL[] { JarUtil.getJarFileURI(TempJarCache.class.getName(), getClass().getClassLoader()).toURL() }; System.err.println("url: "+urls[0]); ClassLoader cl2 = new TestClassLoader(urls, null); ClassLoader cl3 = new TestClassLoader(urls, null); - + Assert.assertFalse(( (Boolean) ReflectionUtil.callStaticMethod(TempJarCache.class.getName(), "isInitialized", null, null, cl2) ).booleanValue()); Assert.assertFalse(( (Boolean) ReflectionUtil.callStaticMethod(TempJarCache.class.getName(), "isInitialized", null, null, cl3) @@ -260,13 +259,13 @@ public class TestTempJarCache extends JunitTracer { ).booleanValue()); Assert.assertTrue(( (Boolean) ReflectionUtil.callStaticMethod(TempJarCache.class.getName(), "isInitialized", null, null, cl3) ).booleanValue()); - + Object fileCache2 = ReflectionUtil.callStaticMethod(TempJarCache.class.getName(), "getTempFileCache", null, null, cl2); Object fileCache3 = ReflectionUtil.callStaticMethod(TempJarCache.class.getName(), "getTempFileCache", null, null, cl3); assertTempFileCachesIndividualInstances(false, fileCache2, cl2, fileCache3, cl3); } - + public static void main(String args[]) throws IOException { String tstname = TestTempJarCache.class.getName(); org.junit.runner.JUnitCore.main(tstname); diff --git a/src/junit/com/jogamp/common/util/TestValueConversion.java b/src/junit/com/jogamp/common/util/TestValueConversion.java index b70a414..13cd0cd 100644 --- a/src/junit/com/jogamp/common/util/TestValueConversion.java +++ b/src/junit/com/jogamp/common/util/TestValueConversion.java @@ -3,14 +3,14 @@ * * Redistribution and use in source and binary forms, with or without modification, are * permitted provided that the following conditions are met: - * + * * 1. Redistributions of source code must retain the above copyright notice, this list of * conditions and the following disclaimer. - * + * * 2. Redistributions in binary form must reproduce the above copyright notice, this list * of conditions and the following disclaimer in the documentation and/or other materials * provided with the distribution. - * + * * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR @@ -20,15 +20,15 @@ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * + * * The views and conclusions contained in the software and documentation are those of the * authors and should not be interpreted as representing official policies, either expressed * or implied, of JogAmp Community. */ - + package com.jogamp.common.util; -import junit.framework.Assert; +import org.junit.Assert; import org.junit.Test; @@ -42,98 +42,98 @@ import org.junit.runners.MethodSorters; @FixMethodOrder(MethodSorters.NAME_ASCENDING) public class TestValueConversion { - + @Test public void testBaseFloat() { Assert.assertEquals(Byte.MAX_VALUE, float_to_byte( 1.0f, true)); Assert.assertEquals(Byte.MIN_VALUE, float_to_byte(-1.0f, true)); - Assert.assertEquals( 1.0f, byte_to_float( Byte.MAX_VALUE, true)); - Assert.assertEquals(-1.0f, byte_to_float( Byte.MIN_VALUE, true)); - + Assert.assertEquals( 1.0f, byte_to_float( Byte.MAX_VALUE, true), 0.0); + Assert.assertEquals(-1.0f, byte_to_float( Byte.MIN_VALUE, true), 0.0); + Assert.assertEquals(Short.MAX_VALUE, float_to_short( 1.0f, true)); Assert.assertEquals(Short.MIN_VALUE, float_to_short(-1.0f, true)); - Assert.assertEquals( 1.0f, short_to_float( Short.MAX_VALUE, true)); - Assert.assertEquals(-1.0f, short_to_float( Short.MIN_VALUE, true)); - + Assert.assertEquals( 1.0f, short_to_float( Short.MAX_VALUE, true), 0.0); + Assert.assertEquals(-1.0f, short_to_float( Short.MIN_VALUE, true), 0.0); + Assert.assertEquals(Integer.MAX_VALUE, float_to_int( 1.0f, true)); Assert.assertEquals(Integer.MIN_VALUE, float_to_int(-1.0f, true)); - Assert.assertEquals( 1.0f, int_to_float( Integer.MAX_VALUE, true)); - Assert.assertEquals(-1.0f, int_to_float( Integer.MIN_VALUE, true)); - + Assert.assertEquals( 1.0f, int_to_float( Integer.MAX_VALUE, true), 0.0); + Assert.assertEquals(-1.0f, int_to_float( Integer.MIN_VALUE, true), 0.0); + Assert.assertEquals((byte)0xff, float_to_byte( 1.0f, false)); - Assert.assertEquals( 1.0f, byte_to_float( (byte)0xff, false)); - + Assert.assertEquals( 1.0f, byte_to_float( (byte)0xff, false), 0.0); + Assert.assertEquals((short)0xffff, float_to_short( 1.0f, false)); - Assert.assertEquals( 1.0f, short_to_float( (short)0xffff, false)); - + Assert.assertEquals( 1.0f, short_to_float( (short)0xffff, false), 0.0); + Assert.assertEquals(0xffffffff, float_to_int( 1.0f, false)); - Assert.assertEquals( 1.0f, int_to_float( 0xffffffff, false)); + Assert.assertEquals( 1.0f, int_to_float( 0xffffffff, false), 0.0); } - + @Test public void testBaseDouble() { Assert.assertEquals(Byte.MAX_VALUE, double_to_byte( 1.0, true)); Assert.assertEquals(Byte.MIN_VALUE, double_to_byte(-1.0, true)); - Assert.assertEquals( 1.0, byte_to_double( Byte.MAX_VALUE, true)); - Assert.assertEquals(-1.0, byte_to_double( Byte.MIN_VALUE, true)); - + Assert.assertEquals( 1.0, byte_to_double( Byte.MAX_VALUE, true), 0.0); + Assert.assertEquals(-1.0, byte_to_double( Byte.MIN_VALUE, true), 0.0); + Assert.assertEquals(Short.MAX_VALUE, double_to_short( 1.0, true)); Assert.assertEquals(Short.MIN_VALUE, double_to_short(-1.0, true)); - Assert.assertEquals( 1.0, short_to_double( Short.MAX_VALUE, true)); - Assert.assertEquals(-1.0, short_to_double( Short.MIN_VALUE, true)); - + Assert.assertEquals( 1.0, short_to_double( Short.MAX_VALUE, true), 0.0); + Assert.assertEquals(-1.0, short_to_double( Short.MIN_VALUE, true), 0.0); + Assert.assertEquals(Integer.MAX_VALUE, double_to_int( 1.0, true)); Assert.assertEquals(Integer.MIN_VALUE, double_to_int(-1.0, true)); - Assert.assertEquals( 1.0, int_to_double( Integer.MAX_VALUE, true)); - Assert.assertEquals(-1.0, int_to_double( Integer.MIN_VALUE, true)); - + Assert.assertEquals( 1.0, int_to_double( Integer.MAX_VALUE, true), 0.0); + Assert.assertEquals(-1.0, int_to_double( Integer.MIN_VALUE, true), 0.0); + Assert.assertEquals((byte)0xff, double_to_byte( 1.0, false)); - Assert.assertEquals( 1.0, byte_to_double( (byte)0xff, false)); - + Assert.assertEquals( 1.0, byte_to_double( (byte)0xff, false), 0.0); + Assert.assertEquals((short)0xffff, double_to_short( 1.0, false)); - Assert.assertEquals( 1.0, short_to_double( (short)0xffff, false)); - + Assert.assertEquals( 1.0, short_to_double( (short)0xffff, false), 0.0); + Assert.assertEquals(0xffffffff, double_to_int( 1.0, false)); - Assert.assertEquals( 1.0, int_to_double( 0xffffffff, false)); + Assert.assertEquals( 1.0, int_to_double( 0xffffffff, false), 0.0); } - + @Test - public void testConversion() { + public void testConversion() { byte sb0 = 127; byte sb1 = -128; - + float sf0 = byte_to_float(sb0, true); float sf1 = byte_to_float(sb1, true); short ss0 = byte_to_short(sb0, true, true); short ss1 = byte_to_short(sb1, true, true); int si0 = byte_to_int(sb0, true, true); int si1 = byte_to_int(sb1, true, true); - - Assert.assertEquals(1.0f, sf0); - Assert.assertEquals(-1.0f, sf1); + + Assert.assertEquals(1.0f, sf0, 0.0); + Assert.assertEquals(-1.0f, sf1, 0.0); Assert.assertEquals(Short.MAX_VALUE, ss0); Assert.assertEquals(Short.MIN_VALUE, ss1); Assert.assertEquals(Integer.MAX_VALUE, si0); Assert.assertEquals(Integer.MIN_VALUE, si1); - + Assert.assertEquals(sb0, short_to_byte(ss0, true, true)); Assert.assertEquals(sb1, short_to_byte(ss1, true, true)); Assert.assertEquals(sb0, int_to_byte(si0, true, true)); Assert.assertEquals(sb1, int_to_byte(si1, true, true)); - + byte ub0 = (byte) 0xff; float uf0 = byte_to_float(ub0, false); short us0 = byte_to_short(ub0, false, false); int ui0 = byte_to_int(ub0, false, false); - - Assert.assertEquals(1.0f, uf0); + + Assert.assertEquals(1.0f, uf0, 0.0); Assert.assertEquals((short)0xffff, us0); Assert.assertEquals(0xffffffff, ui0); - + Assert.assertEquals(ub0, short_to_byte(us0, false, false)); Assert.assertEquals(us0, int_to_short(ui0, false, false)); } - + public static void main(String args[]) { org.junit.runner.JUnitCore.main(TestValueConversion.class.getName()); } diff --git a/src/junit/com/jogamp/common/util/locks/TestSingletonServerSocket00.java b/src/junit/com/jogamp/common/util/locks/TestSingletonServerSocket00.java index 2ab6d52..c699e2e 100644 --- a/src/junit/com/jogamp/common/util/locks/TestSingletonServerSocket00.java +++ b/src/junit/com/jogamp/common/util/locks/TestSingletonServerSocket00.java @@ -3,14 +3,14 @@ * * Redistribution and use in source and binary forms, with or without modification, are * permitted provided that the following conditions are met: - * + * * 1. Redistributions of source code must retain the above copyright notice, this list of * conditions and the following disclaimer. - * + * * 2. Redistributions in binary form must reproduce the above copyright notice, this list * of conditions and the following disclaimer in the documentation and/or other materials * provided with the distribution. - * + * * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR @@ -20,7 +20,7 @@ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * + * * The views and conclusions contained in the software and documentation are those of the * authors and should not be interpreted as representing official policies, either expressed * or implied, of JogAmp Community. @@ -29,8 +29,7 @@ package com.jogamp.common.util.locks; import java.io.IOException; -import junit.framework.Assert; - +import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Test; @@ -44,10 +43,10 @@ public class TestSingletonServerSocket00 { public static final long SINGLE_INSTANCE_LOCK_TO = 3*60*1000; // wait up to 3 min public static final long SINGLE_INSTANCE_LOCK_POLL = 100; // poll every 100ms private static volatile SingletonInstance singletonInstance; - + @BeforeClass public static void oneTimeSetUp() { - // one-time initialization code + // one-time initialization code singletonInstance = SingletonInstance.createServerSocket(SINGLE_INSTANCE_LOCK_POLL, SINGLE_INSTANCE_LOCK_PORT); } @@ -66,14 +65,14 @@ public class TestSingletonServerSocket00 { System.gc(); // force cleanup singletonInstance.unlock(); } - + private Thread startLockUnlockOffThread(int i) { final Thread t = new Thread(new Runnable() { public void run() { SingletonInstance myLock = SingletonInstance.createServerSocket(10, SINGLE_INSTANCE_LOCK_PORT); System.err.println(Thread.currentThread().getName()+" LOCK try .."); Assert.assertTrue(Thread.currentThread().getName()+" - Could not lock instance: "+myLock.getName(), myLock.tryLock(1000)); - System.err.println(Thread.currentThread().getName()+" LOCK ON"); + System.err.println(Thread.currentThread().getName()+" LOCK ON"); try { Thread.sleep(300); } catch (InterruptedException e) { } @@ -84,7 +83,7 @@ public class TestSingletonServerSocket00 { t.start(); return t; } - + @Test public void testOffthreadLockUnlock() throws InterruptedException { Assert.assertTrue("Could not lock single instance: "+singletonInstance.getName(), singletonInstance.tryLock(SINGLE_INSTANCE_LOCK_TO)); @@ -97,7 +96,7 @@ public class TestSingletonServerSocket00 { Thread.sleep(100); } } - + public static void main(String args[]) throws IOException, InterruptedException { String tstname = TestSingletonServerSocket00.class.getName(); org.junit.runner.JUnitCore.main(tstname); diff --git a/src/junit/com/jogamp/common/util/locks/TestSingletonServerSocket01.java b/src/junit/com/jogamp/common/util/locks/TestSingletonServerSocket01.java index 6cb5d39..4bdc9bf 100644 --- a/src/junit/com/jogamp/common/util/locks/TestSingletonServerSocket01.java +++ b/src/junit/com/jogamp/common/util/locks/TestSingletonServerSocket01.java @@ -3,14 +3,14 @@ * * Redistribution and use in source and binary forms, with or without modification, are * permitted provided that the following conditions are met: - * + * * 1. Redistributions of source code must retain the above copyright notice, this list of * conditions and the following disclaimer. - * + * * 2. Redistributions in binary form must reproduce the above copyright notice, this list * of conditions and the following disclaimer in the documentation and/or other materials * provided with the distribution. - * + * * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR @@ -20,7 +20,7 @@ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * + * * The views and conclusions contained in the software and documentation are those of the * authors and should not be interpreted as representing official policies, either expressed * or implied, of JogAmp Community. @@ -29,9 +29,7 @@ package com.jogamp.common.util.locks; import java.io.IOException; -import junit.framework.Assert; - -import org.junit.AfterClass; +import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Test; @@ -45,10 +43,10 @@ public class TestSingletonServerSocket01 { public static final long SINGLE_INSTANCE_LOCK_TO = 3*60*1000; // wait up to 3 min public static final long SINGLE_INSTANCE_LOCK_POLL = 1000; // poll every 1s private static volatile SingletonInstance singletonInstance; - + @BeforeClass public static void oneTimeSetUp() { - // one-time initialization code + // one-time initialization code singletonInstance = SingletonInstance.createServerSocket(SINGLE_INSTANCE_LOCK_POLL, SINGLE_INSTANCE_LOCK_PORT); } @@ -57,7 +55,7 @@ public class TestSingletonServerSocket01 { Assert.assertTrue("Could not lock single instance: "+singletonInstance.getName(), singletonInstance.tryLock(SINGLE_INSTANCE_LOCK_TO)); singletonInstance.unlock(); } - + public static void main(String args[]) throws IOException, InterruptedException { String tstname = TestSingletonServerSocket01.class.getName(); org.junit.runner.JUnitCore.main(tstname); diff --git a/src/junit/com/jogamp/common/util/locks/TestSingletonServerSocket02.java b/src/junit/com/jogamp/common/util/locks/TestSingletonServerSocket02.java index 32a1c00..cb862ce 100644 --- a/src/junit/com/jogamp/common/util/locks/TestSingletonServerSocket02.java +++ b/src/junit/com/jogamp/common/util/locks/TestSingletonServerSocket02.java @@ -3,14 +3,14 @@ * * Redistribution and use in source and binary forms, with or without modification, are * permitted provided that the following conditions are met: - * + * * 1. Redistributions of source code must retain the above copyright notice, this list of * conditions and the following disclaimer. - * + * * 2. Redistributions in binary form must reproduce the above copyright notice, this list * of conditions and the following disclaimer in the documentation and/or other materials * provided with the distribution. - * + * * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR @@ -20,7 +20,7 @@ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * + * * The views and conclusions contained in the software and documentation are those of the * authors and should not be interpreted as representing official policies, either expressed * or implied, of JogAmp Community. @@ -29,8 +29,7 @@ package com.jogamp.common.util.locks; import java.io.IOException; -import junit.framework.Assert; - +import org.junit.Assert; import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; @@ -45,10 +44,10 @@ public class TestSingletonServerSocket02 { public static final long SINGLE_INSTANCE_LOCK_TO = 3*60*1000; // wait up to 3 min public static final long SINGLE_INSTANCE_LOCK_POLL = 1000; // poll every 1s private static volatile SingletonInstance singletonInstance; - + @BeforeClass public static void oneTimeSetUp() { - // one-time initialization code + // one-time initialization code singletonInstance = SingletonInstance.createServerSocket(SINGLE_INSTANCE_LOCK_POLL, SINGLE_INSTANCE_LOCK_PORT); Assert.assertTrue("Could not lock single instance: "+singletonInstance.getName(), singletonInstance.tryLock(SINGLE_INSTANCE_LOCK_TO)); } @@ -56,14 +55,14 @@ public class TestSingletonServerSocket02 { @AfterClass public static void oneTimeTearDown() { System.gc(); // force cleanup - singletonInstance.unlock(); + singletonInstance.unlock(); } - + @Test public void dummy() throws InterruptedException { // make junit happy } - + // @Test(timeout=10) // Only enable manually to test timeout behavior public void testTimeout() throws InterruptedException { Thread.sleep(3000); diff --git a/src/junit/com/jogamp/junit/sec/TestSecIOUtil01.java b/src/junit/com/jogamp/junit/sec/TestSecIOUtil01.java index cc734ec..9ee735c 100644 --- a/src/junit/com/jogamp/junit/sec/TestSecIOUtil01.java +++ b/src/junit/com/jogamp/junit/sec/TestSecIOUtil01.java @@ -3,14 +3,14 @@ * * Redistribution and use in source and binary forms, with or without modification, are * permitted provided that the following conditions are met: - * + * * 1. Redistributions of source code must retain the above copyright notice, this list of * conditions and the following disclaimer. - * + * * 2. Redistributions in binary form must reproduce the above copyright notice, this list * of conditions and the following disclaimer in the documentation and/or other materials * provided with the distribution. - * + * * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR @@ -20,12 +20,12 @@ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * + * * The views and conclusions contained in the software and documentation are those of the * authors and should not be interpreted as representing official policies, either expressed * or implied, of JogAmp Community. */ - + package com.jogamp.junit.sec; import java.net.URISyntaxException; @@ -34,8 +34,7 @@ import java.security.AccessControlException; import java.io.File; import java.io.IOException; -import junit.framework.Assert; - +import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Test; @@ -54,17 +53,17 @@ public class TestSecIOUtil01 extends JunitTracer { static final String java_home_propkey = "java.home"; static final String os_name_propkey = "os.name"; static final boolean usesSecurityManager; - + static { if( null == System.getSecurityManager() ) { usesSecurityManager = false; System.err.println("No SecurityManager Installed"); } else { usesSecurityManager = true; - System.err.println("SecurityManager Already Installed"); + System.err.println("SecurityManager Already Installed"); } } - + @BeforeClass public static void setup() throws IOException { Platform.initSingleton(); @@ -72,7 +71,7 @@ public class TestSecIOUtil01 extends JunitTracer { static void testPropImpl01(String propKey, boolean isSecure) { isSecure |= !usesSecurityManager; - + Exception se0 = null; try { String p0 = System.getProperty(propKey); @@ -93,25 +92,25 @@ public class TestSecIOUtil01 extends JunitTracer { Assert.assertNotNull("AccessControlException not thrown on insecure property <"+propKey+">", se0); } } - + @Test public void testProp00_Temp() { testPropImpl01(os_name_propkey, true); } - + @Test public void testProp01_Temp() { testPropImpl01(java_home_propkey, false); } - + @Test public void testProp02_Temp() { testPropImpl01(java_io_tmpdir_propkey, false); } - + static void testTempDirImpl(boolean isSecure) { isSecure |= !usesSecurityManager; - + Exception se0 = null; try { File tmp = IOUtil.getTempDir(true); @@ -132,7 +131,7 @@ public class TestSecIOUtil01 extends JunitTracer { Assert.assertNotNull("AccessControlException not thrown on insecure temp dir", se0); } } - + @Test public void testTempDir00() { testTempDirImpl(false); @@ -141,7 +140,7 @@ public class TestSecIOUtil01 extends JunitTracer { private NativeLibrary openLibraryImpl(boolean global) { final ClassLoader cl = getClass().getClassLoader(); System.err.println("CL "+cl); - + String libBaseName = null; final Class<?> clazz = this.getClass(); URL libURL = clazz.getResource("/libtest1.so"); @@ -154,7 +153,7 @@ public class TestSecIOUtil01 extends JunitTracer { } } System.err.println("Untrusted Library (URL): "+libURL); - + String libDir1 = null; if( null != libURL ) { try { @@ -187,7 +186,7 @@ public class TestSecIOUtil01 extends JunitTracer { } else { System.err.println("Unexpected exception for loading native library"); se0.printStackTrace(); - } + } } if( !usesSecurityManager ) { Assert.assertNull("SecurityException thrown on loading native library", se0); @@ -196,17 +195,17 @@ public class TestSecIOUtil01 extends JunitTracer { } return nlib; } - + public void testOpenLibrary() { NativeLibrary nlib = openLibraryImpl(true); if( null != nlib ) { nlib.close(); } } - + public static void main(String args[]) throws IOException { TestSecIOUtil01.setup(); - + TestSecIOUtil01 aa = new TestSecIOUtil01(); aa.testProp00_Temp(); aa.testProp01_Temp(); |