diff options
Diffstat (limited to 'src/junit/com')
31 files changed, 1493 insertions, 156 deletions
diff --git a/src/junit/com/jogamp/common/net/AssetURLConnectionUnregisteredTest.java b/src/junit/com/jogamp/common/net/AssetURLConnectionUnregisteredTest.java index 5167abb..1bb88c5 100644 --- a/src/junit/com/jogamp/common/net/AssetURLConnectionUnregisteredTest.java +++ b/src/junit/com/jogamp/common/net/AssetURLConnectionUnregisteredTest.java @@ -38,7 +38,7 @@ public class AssetURLConnectionUnregisteredTest extends AssetURLConnectionBase { @Test public void assetUnregisteredIOUtilGetResourceRel0_RT() throws IOException, URISyntaxException { - final URLConnection urlConn0 = IOUtil.getResource(this.getClass(), test_asset_test2_rel.get()); + final URLConnection urlConn0 = IOUtil.getResource(test_asset_test2_rel.get(), this.getClass().getClassLoader(), this.getClass()); testAssetConnection(urlConn0, test_asset_test2_entry); final Uri uri1 = Uri.valueOf(urlConn0.getURL()).getRelativeOf(test_asset_test3_rel); diff --git a/src/junit/com/jogamp/common/net/TestUri01.java b/src/junit/com/jogamp/common/net/TestUri01.java index 1173610..4205de1 100644 --- a/src/junit/com/jogamp/common/net/TestUri01.java +++ b/src/junit/com/jogamp/common/net/TestUri01.java @@ -248,6 +248,20 @@ public class TestUri01 extends SingletonJunitCase { @Test public void test08NormalizedHierarchy() throws IOException, URISyntaxException { { + final Uri input = Uri.cast("./dummy/nop/../a.txt"); + final Uri expected = Uri.cast("dummy/a.txt"); + URIDumpUtil.showUri(input); + final Uri normal = input.getNormalized(); + Assert.assertEquals(expected, normal); + } + { + final Uri input = Uri.cast("../dummy/nop/../a.txt"); + final Uri expected = Uri.cast("../dummy/a.txt"); + URIDumpUtil.showUri(input); + final Uri normal = input.getNormalized(); + Assert.assertEquals(expected, normal); + } + { final Uri input = Uri.cast("http://localhost/dummy/../"); final Uri expected = Uri.cast("http://localhost/"); URIDumpUtil.showUri(input); @@ -255,7 +269,21 @@ public class TestUri01 extends SingletonJunitCase { Assert.assertEquals(expected, normal); } { - final Uri input = Uri.cast("http://localhost/test/dummy/../text.txt"); + final Uri input = Uri.cast("http://localhost/dummy/./../"); + final Uri expected = Uri.cast("http://localhost/"); + URIDumpUtil.showUri(input); + final Uri normal = input.getNormalized(); + Assert.assertEquals(expected, normal); + } + { + final Uri input = Uri.cast("http://localhost/dummy/../aa/././../"); + final Uri expected = Uri.cast("http://localhost/"); + URIDumpUtil.showUri(input); + final Uri normal = input.getNormalized(); + Assert.assertEquals(expected, normal); + } + { + final Uri input = Uri.cast("http://localhost/test/dummy/./../text.txt"); final Uri expected = Uri.cast("http://localhost/test/text.txt"); URIDumpUtil.showUri(input); final Uri normal = input.getNormalized(); @@ -280,7 +308,7 @@ public class TestUri01 extends SingletonJunitCase { Assert.assertEquals(expected, normal); } { - final Uri input = Uri.cast("jar:http://localhost/test/dummy/../abc.jar!/"); + final Uri input = Uri.cast("jar:http://localhost/test/./dummy/../abc.jar!/"); final Uri expected = Uri.cast("jar:http://localhost/test/abc.jar!/"); URIDumpUtil.showUri(input); final Uri normal = input.getNormalized(); diff --git a/src/junit/com/jogamp/common/nio/BuffersTest.java b/src/junit/com/jogamp/common/nio/BuffersTest.java index c6a89f1..c267100 100644 --- a/src/junit/com/jogamp/common/nio/BuffersTest.java +++ b/src/junit/com/jogamp/common/nio/BuffersTest.java @@ -31,7 +31,15 @@ */ package com.jogamp.common.nio; +import java.io.IOException; +import java.nio.ByteBuffer; +import java.nio.CharBuffer; +import java.nio.DoubleBuffer; +import java.nio.FloatBuffer; import java.nio.IntBuffer; +import java.nio.LongBuffer; +import java.nio.ShortBuffer; + import org.junit.Test; import com.jogamp.junit.util.SingletonJunitCase; @@ -48,7 +56,66 @@ import org.junit.runners.MethodSorters; public class BuffersTest extends SingletonJunitCase { @Test - public void slice() { + public void test01PositionLimitCapacityAfterArrayAllocation() { + final byte[] byteData = { 1, 2, 3, 4, 5, 6, 7, 8 }; + final ByteBuffer byteBuffer = Buffers.newDirectByteBuffer(byteData); + assertEquals(0, byteBuffer.position()); + assertEquals(8, byteBuffer.limit()); + assertEquals(8, byteBuffer.capacity()); + assertEquals(8, byteBuffer.remaining()); + assertEquals(5, byteBuffer.get(4)); + + final double[] doubleData = { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 }; + final DoubleBuffer doubleBuffer = Buffers.newDirectDoubleBuffer(doubleData); + assertEquals(0, doubleBuffer.position()); + assertEquals(8, doubleBuffer.limit()); + assertEquals(8, doubleBuffer.capacity()); + assertEquals(8, doubleBuffer.remaining()); + assertEquals(5.0, doubleBuffer.get(4), 0.1); + + final float[] floatData = { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f }; + final FloatBuffer floatBuffer = Buffers.newDirectFloatBuffer(floatData); + assertEquals(0, floatBuffer.position()); + assertEquals(8, floatBuffer.limit()); + assertEquals(8, floatBuffer.capacity()); + assertEquals(8, floatBuffer.remaining()); + assertEquals(5.0f, floatBuffer.get(4), 0.1f); + + final int[] intData = { 1, 2, 3, 4, 5, 6, 7, 8 }; + final IntBuffer intBuffer = Buffers.newDirectIntBuffer(intData); + assertEquals(0, intBuffer.position()); + assertEquals(8, intBuffer.limit()); + assertEquals(8, intBuffer.capacity()); + assertEquals(8, intBuffer.remaining()); + assertEquals(5, intBuffer.get(4)); + + final long[] longData = { 1, 2, 3, 4, 5, 6, 7, 8 }; + final LongBuffer longBuffer = Buffers.newDirectLongBuffer(longData); + assertEquals(0, longBuffer.position()); + assertEquals(8, longBuffer.limit()); + assertEquals(8, longBuffer.capacity()); + assertEquals(8, longBuffer.remaining()); + assertEquals(5, longBuffer.get(4)); + + final short[] shortData = { 1, 2, 3, 4, 5, 6, 7, 8 }; + final ShortBuffer shortBuffer = Buffers.newDirectShortBuffer(shortData); + assertEquals(0, shortBuffer.position()); + assertEquals(8, shortBuffer.limit()); + assertEquals(8, shortBuffer.capacity()); + assertEquals(8, shortBuffer.remaining()); + assertEquals(5, shortBuffer.get(4)); + + final char[] charData = { 1, 2, 3, 4, 5, 6, 7, 8 }; + final CharBuffer charBuffer = Buffers.newDirectCharBuffer(charData); + assertEquals(0, charBuffer.position()); + assertEquals(8, charBuffer.limit()); + assertEquals(8, charBuffer.capacity()); + assertEquals(8, charBuffer.remaining()); + assertEquals(5, charBuffer.get(4)); + } + + @Test + public void test10Slice() { final IntBuffer buffer = Buffers.newDirectIntBuffer(6); buffer.put(new int[]{1,2,3,4,5,6}).rewind(); @@ -87,8 +154,10 @@ public class BuffersTest extends SingletonJunitCase { assertEquals(42, buffer.get(2)); assertEquals(42, onetwothree.get(2)); - - } + public static void main(final String args[]) throws IOException { + final String tstname = BuffersTest.class.getName(); + org.junit.runner.JUnitCore.main(tstname); + } } diff --git a/src/junit/com/jogamp/common/util/BitstreamData.java b/src/junit/com/jogamp/common/util/BitDemoData.java index a5a0bd9..9d605fc 100644 --- a/src/junit/com/jogamp/common/util/BitstreamData.java +++ b/src/junit/com/jogamp/common/util/BitDemoData.java @@ -30,11 +30,49 @@ package com.jogamp.common.util; import java.nio.ByteBuffer; -public class BitstreamData { +public class BitDemoData { + public static final long UNSIGNED_INT_MAX_VALUE = 0xffffffffL; + + public static final String[] pyramid32bit_one = { + "00000000000000000000000000000001", + "00000000000000000000000000000010", + "00000000000000000000000000000100", + "00000000000000000000000000001000", + "00000000000000000000000000010000", + "00000000000000000000000000100000", + "00000000000000000000000001000000", + "00000000000000000000000010000000", + "00000000000000000000000100000000", + "00000000000000000000001000000000", + "00000000000000000000010000000000", + "00000000000000000000100000000000", + "00000000000000000001000000000000", + "00000000000000000010000000000000", + "00000000000000000100000000000000", + "00000000000000001000000000000000", + "00000000000000010000000000000000", + "00000000000000100000000000000000", + "00000000000001000000000000000000", + "00000000000010000000000000000000", + "00000000000100000000000000000000", + "00000000001000000000000000000000", + "00000000010000000000000000000000", + "00000000100000000000000000000000", + "00000001000000000000000000000000", + "00000010000000000000000000000000", + "00000100000000000000000000000000", + "00001000000000000000000000000000", + "00010000000000000000000000000000", + "00100000000000000000000000000000", + "01000000000000000000000000000000", + "10000000000000000000000000000000" + }; + // // MSB -> LSB over whole data // public static final byte[] testBytesMSB = new byte[] { (byte)0xde, (byte)0xaf, (byte)0xca, (byte)0xfe }; + public static final int testIntMSB = 0xdeafcafe; // 11011110 10101111 11001010 11111110 public static final String[] testStringsMSB = new String[] { "11011110", "10101111", "11001010", "11111110" }; public static final String testStringMSB = testStringsMSB[0]+testStringsMSB[1]+testStringsMSB[2]+testStringsMSB[3]; @@ -42,6 +80,7 @@ public class BitstreamData { // MSB -> LSB, reverse bit-order over each byte of testBytesLSB // public static final byte[] testBytesMSB_rev = new byte[] { (byte)0xfe, (byte)0xca, (byte)0xaf, (byte)0xde }; + public static final int testIntMSB_rev = 0xfecaafde; public static final String[] testStringsMSB_rev = new String[] { "11111110", "11001010", "10101111", "11011110" }; public static final String testStringMSB_rev = testStringsMSB_rev[0]+testStringsMSB_rev[1]+testStringsMSB_rev[2]+testStringsMSB_rev[3]; @@ -49,6 +88,7 @@ public class BitstreamData { // LSB -> MSB over whole data // public static final byte[] testBytesLSB = new byte[] { (byte)0x7f, (byte)0x53, (byte)0xf5, (byte)0x7b }; + public static final int testIntLSB = 0x7f53f57b; public static final String[] testStringsLSB = new String[] { "01111111", "01010011", "11110101", "01111011" }; public static final String testStringLSB = testStringsLSB[0]+testStringsLSB[1]+testStringsLSB[2]+testStringsLSB[3]; @@ -56,6 +96,7 @@ public class BitstreamData { // LSB -> MSB, reverse bit-order over each byte of testBytesMSB // public static final byte[] testBytesLSB_revByte = new byte[] { (byte)0x7b, (byte)0xf5, (byte)0x53, (byte)0x7f }; + public static final int testIntLSB_revByte = 0x7bf5537f; public static final String[] testStringsLSB_revByte = new String[] { "01111011", "11110101", "01010011", "01111111" }; public static final String testStringLSB_revByte = testStringsLSB_revByte[0]+testStringsLSB_revByte[1]+testStringsLSB_revByte[2]+testStringsLSB_revByte[3]; @@ -80,6 +121,26 @@ public class BitstreamData { } } + public static int getOneBitCount(final String pattern) { + int c=0; + for(int i=0; i<pattern.length(); i++) { + if( '1' == pattern.charAt(i) ) { + c++; + } + } + return c; + } + public static long toLong(final String bitPattern) { + return Long.valueOf(bitPattern, 2).longValue(); + } + public static int toInteger(final String bitPattern) { + final long res = Long.valueOf(bitPattern, 2).longValue(); + if( res > UNSIGNED_INT_MAX_VALUE ) { + throw new NumberFormatException("Exceeds "+toHexString(UNSIGNED_INT_MAX_VALUE)+": "+toHexString(res)+" - source "+bitPattern); + } + return (int)res; + } + public static String toHexString(final int v) { return "0x"+Integer.toHexString(v); } diff --git a/src/junit/com/jogamp/common/util/CustomDeflate.java b/src/junit/com/jogamp/common/util/CustomDeflate.java new file mode 100644 index 0000000..d4682e8 --- /dev/null +++ b/src/junit/com/jogamp/common/util/CustomDeflate.java @@ -0,0 +1,115 @@ +/** + * Copyright 2015 JogAmp Community. All rights reserved. + * + * 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 + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * 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; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; + +public class CustomDeflate { + public static void main(final String[] args) { + if (args.length != 2) { + System.err.println("Usage: java "+CustomDeflate.class.getName()+" file-in file-out"); + } else { + final File fileIn = new File(args[0]); + final File fileOut = new File(args[1]); + final int inSize; + { + final long _inSize = fileIn.length(); + if( 0 >= _inSize || _inSize > Integer.MAX_VALUE ) { + throw new IllegalArgumentException(""); + } + inSize = (int) _inSize; + } + final byte[] input = new byte[inSize]; + InputStream in = null; + OutputStream out = null; + try { + in = new FileInputStream(fileIn); + int numBytes = 0; + try { + while (true) { + final int remBytes = inSize - numBytes; + int count; + if ( 0 >= remBytes || (count = in.read(input, numBytes, remBytes)) == -1 ) { + break; + } + numBytes += count; + } + } finally { + in.close(); + } + if( inSize != numBytes ) { + throw new IOException("Got "+numBytes+" bytes != expected "+inSize); + } + out = new FileOutputStream(fileOut); + CustomCompress.deflateToStream(input, 0, inSize, 9, out); + } catch (final IOException ioe) { + ioe.printStackTrace(); + } finally { + if( null != in ) { + try { in.close(); } catch (final IOException e) { } + } + if( null != out ) { + try { out.close(); } catch (final IOException e) { } + } + } + + // + // Test + // + in = null; + out = null; + try { + in = new FileInputStream(fileOut); + final byte[] compare = CustomCompress.inflateFromStream(in); + if( compare.length != inSize ) { + throw new InternalError("Inflated Size Mismatch: Has "+compare.length+", expected "+inSize); + } + for(int i=0; i<inSize; i++) { + if( input[i] != compare[i] ) { + throw new InternalError("Inflated Bytes Mismatch at "+i+"/"+inSize+": Has "+Integer.toHexString(compare[i])+", expected "+Integer.toHexString(input[i])); + } + } + } catch (final IOException ioe) { + ioe.printStackTrace(); + } finally { + if( null != in ) { + try { in.close(); } catch (final IOException e) { } + } + if( null != out ) { + try { out.close(); } catch (final IOException e) { } + } + } + } + } + +} diff --git a/src/junit/com/jogamp/common/util/CustomInflate.java b/src/junit/com/jogamp/common/util/CustomInflate.java new file mode 100644 index 0000000..477439e --- /dev/null +++ b/src/junit/com/jogamp/common/util/CustomInflate.java @@ -0,0 +1,68 @@ +/** + * Copyright 2015 JogAmp Community. All rights reserved. + * + * 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 + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * 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; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; + +public class CustomInflate { + public static final int magic = 0xDEF1A7E0; + + public static void main(final String[] args) { + if (args.length != 2) { + System.err.println("Usage: java "+CustomCompress.class.getName()+" file-in file-out"); + } else { + InputStream in = null; + OutputStream out = null; + try { + final File fileIn = new File(args[0]); + in = new FileInputStream(fileIn); + + final byte[] output = CustomCompress.inflateFromStream(in); + + final File fileOut = new File(args[1]); + out = new FileOutputStream(fileOut); + out.write(output, 0, output.length); + out.flush(); + } catch (final IOException ioe) { + ioe.printStackTrace(); + } finally { + if( null != in ) { + try { in.close(); } catch (final IOException e) { } + } + if( null != out ) { + try { out.close(); } catch (final IOException e) { } + } + } + } + } +} diff --git a/src/junit/com/jogamp/common/util/TestArrayHashMap01.java b/src/junit/com/jogamp/common/util/TestArrayHashMap01.java new file mode 100644 index 0000000..529612c --- /dev/null +++ b/src/junit/com/jogamp/common/util/TestArrayHashMap01.java @@ -0,0 +1,186 @@ +/** + * Copyright 2015 JogAmp Community. All rights reserved. + * + * 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 + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * 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.util.*; +import java.io.IOException; + +import org.junit.Assert; +import org.junit.Test; + +import com.jogamp.junit.util.SingletonJunitCase; + +import org.junit.FixMethodOrder; +import org.junit.runners.MethodSorters; + +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +public class TestArrayHashMap01 extends SingletonJunitCase { + + public static class Dummy { + int i1, i2, i3; + + public Dummy(final int i1, final int i2, final int i3) { + this.i1 = i1; + this.i2 = i2; + this.i3 = i3; + } + + public boolean equals(final Object o) { + if(o instanceof Dummy) { + final Dummy d = (Dummy)o; + return this.i1 == d.i1 && + this.i2 == d.i2 && + this.i3 == d.i3 ; + } + return false; + } + + public final int hashCode() { + // 31 * x == (x << 5) - x + int hash = 31 + i1; + hash = ((hash << 5) - hash) + i2; + hash = ((hash << 5) - hash) + i3; + return hash; + } + + public String toString() { + return "Dummy["+super.toString()+": "+i1+", "+i2+", "+i3+"]"; + } + } + + void populate(final Map<Integer, Dummy> l, final int start, final int len, + final int i2, final int i3, final int expectedPlusSize) { + final int oldSize = l.size(); + for(int pos = start+len-1; pos>=start; pos--) { + l.put(pos, new Dummy(pos, i2, i3)); + } + Assert.assertEquals(expectedPlusSize, l.size() - oldSize); + } + boolean checkOrder(final List<Dummy> l, final int startIdx, final int start, final int len) { + for(int i=0; i<len; i++) { + final Dummy d = l.get(startIdx+i); + final int i1 = start+len-1-i; + if( d.i1 != i1 ) { + return false; + } + } + return true; + } + + @Test + public void test01ArrayHashMapWithNullValue() { + testArrayHashMapImpl(true); + } + @Test + public void test02ArrayHashSetWithoutNullValue() { + testArrayHashMapImpl(false); + } + void testArrayHashMapImpl(final boolean supportNullValue) { + final ArrayHashMap<Integer, Dummy> l = + new ArrayHashMap<Integer, Dummy>(supportNullValue, + ArrayHashSet.DEFAULT_INITIAL_CAPACITY, + ArrayHashSet.DEFAULT_LOAD_FACTOR); + Assert.assertEquals(supportNullValue, l.supportsNullValue()); + final int p7_22_34_key, p7_22_34_idx; + final Dummy p7_22_34_orig; + final int p6_22_34_key, p6_22_34_idx; + final Dummy p6_22_34_orig; + { + populate(l, 10, 100, 22, 34, 100); // [109 .. 10] + Assert.assertTrue(checkOrder(l.getData(), 0, 10, 100)); + populate(l, 10, 100, 22, 34, 0); // [109 .. 10] + Assert.assertTrue(checkOrder(l.getData(), 0, 10, 100)); + populate(l, 6, 5, 22, 34, 4); // [ 9 .. 6], 10 already exists + Assert.assertTrue(checkOrder(l.getData(), 100, 6, 4)); + p7_22_34_idx = l.size() - 2; + p7_22_34_key = 7; + p7_22_34_orig = l.get(p7_22_34_key); + p6_22_34_idx = l.size() - 1; + p6_22_34_key = 6; + p6_22_34_orig = l.get(p6_22_34_key); + } + Assert.assertNotNull(p7_22_34_orig); + Assert.assertEquals(7, p7_22_34_orig.i1); + Assert.assertEquals(l.getData().get(p7_22_34_idx), p7_22_34_orig); + Assert.assertNotNull(p6_22_34_orig); + Assert.assertEquals(6, p6_22_34_orig.i1); + Assert.assertEquals(l.getData().get(p6_22_34_idx), p6_22_34_orig); + + final Dummy p7_22_34_other = new Dummy(7, 22, 34); + Assert.assertEquals(p7_22_34_other, p7_22_34_orig); + Assert.assertTrue(p7_22_34_other.hashCode() == p7_22_34_orig.hashCode()); + Assert.assertTrue(p7_22_34_other != p7_22_34_orig); // diff reference + final Dummy p6_22_34_other = new Dummy(6, 22, 34); + Assert.assertEquals(p6_22_34_other, p6_22_34_orig); + Assert.assertTrue(p6_22_34_other.hashCode() == p6_22_34_orig.hashCode()); + Assert.assertTrue(p6_22_34_other != p6_22_34_orig); // diff reference + + // fast identity .. + Dummy q = l.get(p6_22_34_key); + Assert.assertNotNull(q); + Assert.assertEquals(p6_22_34_other, q); + Assert.assertTrue(p6_22_34_other.hashCode() == q.hashCode()); + Assert.assertTrue(p6_22_34_other != q); // diff reference + Assert.assertTrue(p6_22_34_orig == q); // same reference + + Assert.assertTrue(l.containsValue(q)); + Assert.assertTrue(l.containsValue(p6_22_34_other)); // add equivalent + + q = l.put(p6_22_34_key, p6_22_34_other); // override w/ diff hash-obj + Assert.assertNotNull(q); + Assert.assertEquals(p6_22_34_other, q); + Assert.assertTrue(p6_22_34_other.hashCode() == q.hashCode()); + Assert.assertTrue(p6_22_34_other != q); // diff reference new != old (q) + Assert.assertTrue(p6_22_34_orig == q); // same reference orig == old (q) + Assert.assertTrue(checkOrder(l.getData(), 0, 10, 100)); + Assert.assertTrue(checkOrder(l.getData(), 100, 6, 4)); + + final Dummy p1_2_3 = new Dummy(1, 2, 3); // a new one .. + q = l.put(1, p1_2_3); // added test + Assert.assertNull(q); + + final Dummy pNull = null; + NullPointerException npe = null; + try { + q = l.put(0, pNull); + Assert.assertNull(q); + } catch (final NullPointerException _npe) { npe = _npe; } + if( l.supportsNullValue() ) { + Assert.assertNull(npe); + } else { + Assert.assertNotNull(npe); + } + } + + public static void main(final String args[]) throws IOException { + final String tstname = TestArrayHashMap01.class.getName(); + org.junit.runner.JUnitCore.main(tstname); + } + +} diff --git a/src/junit/com/jogamp/common/util/TestArrayHashSet01.java b/src/junit/com/jogamp/common/util/TestArrayHashSet01.java index 51db2c7..3e8fbc0 100644 --- a/src/junit/com/jogamp/common/util/TestArrayHashSet01.java +++ b/src/junit/com/jogamp/common/util/TestArrayHashSet01.java @@ -74,47 +74,99 @@ public class TestArrayHashSet01 extends SingletonJunitCase { } } - public void populate(final List<Dummy> l, final int start, final int len, final int i2, final int i3, final int expectedPlusSize) { + void populate(final List<Dummy> l, final int start, final int len, + final int i2, final int i3, final int expectedPlusSize) { final int oldSize = l.size(); - int pos = start+len-1; - while(pos>=start) { - l.add(new Dummy(pos--, i2, i3)); + for(int pos = start+len-1; pos>=start; pos--) { + l.add(new Dummy(pos, i2, i3)); } Assert.assertEquals(expectedPlusSize, l.size() - oldSize); } + boolean checkOrder(final List<Dummy> l, final int startIdx, final int start, final int len) { + for(int i=0; i<len; i++) { + final Dummy d = l.get(startIdx+i); + final int i1 = start+len-1-i; + if( d.i1 != i1 ) { + return false; + } + } + return true; + } @Test - public void test01ArrayHashSet() { - final ArrayHashSet<Dummy> l = new ArrayHashSet<Dummy>(); - populate(l, 10, 100, 22, 34, 100); // [10 .. 109] - populate(l, 10, 100, 22, 34, 0); // [10 .. 109] - populate(l, 6, 5, 22, 34, 4); // [ 6 .. 9], 10 already exists - - final Dummy p6_22_34 = new Dummy(6, 22, 34); + public void test01ArrayHashSetWithNullValue() { + testArrayHashSetImpl(true); + } + @Test + public void test02ArrayHashSetWithoutNullValue() { + testArrayHashSetImpl(false); + } + void testArrayHashSetImpl(final boolean supportNullValue) { + final ArrayHashSet<Dummy> l = + new ArrayHashSet<Dummy>(supportNullValue, + ArrayHashSet.DEFAULT_INITIAL_CAPACITY, + ArrayHashSet.DEFAULT_LOAD_FACTOR); + Assert.assertEquals(supportNullValue, l.supportsNullValue()); + final int p7_22_34_idx; + final Dummy p7_22_34_orig; + final int p6_22_34_idx; + final Dummy p6_22_34_orig; + { + populate(l, 10, 100, 22, 34, 100); // [109 .. 10] + Assert.assertTrue(checkOrder(l, 0, 10, 100)); + populate(l, 10, 100, 22, 34, 0); // [109 .. 10] + Assert.assertTrue(checkOrder(l, 0, 10, 100)); + populate(l, 6, 5, 22, 34, 4); // [ 9 .. 6], 10 already exists + Assert.assertTrue(checkOrder(l, 100, 6, 4)); + p7_22_34_idx = l.size() - 2; + p7_22_34_orig = l.get(p7_22_34_idx); + p6_22_34_idx = l.size() - 1; + p6_22_34_orig = l.get(p6_22_34_idx); + } + Assert.assertNotNull(p7_22_34_orig); + Assert.assertEquals(7, p7_22_34_orig.i1); + Assert.assertEquals(l.getData().get(p7_22_34_idx), p7_22_34_orig); + Assert.assertNotNull(p6_22_34_orig); + Assert.assertEquals(6, p6_22_34_orig.i1); + Assert.assertEquals(l.getData().get(p6_22_34_idx), p6_22_34_orig); + + final Dummy p7_22_34_other = new Dummy(7, 22, 34); + Assert.assertEquals(p7_22_34_other, p7_22_34_orig); + Assert.assertTrue(p7_22_34_other.hashCode() == p7_22_34_orig.hashCode()); + Assert.assertTrue(p7_22_34_other != p7_22_34_orig); // diff reference + final Dummy p6_22_34_other = new Dummy(6, 22, 34); + Assert.assertEquals(p6_22_34_other, p6_22_34_orig); + Assert.assertTrue(p6_22_34_other.hashCode() == p6_22_34_orig.hashCode()); + Assert.assertTrue(p6_22_34_other != p6_22_34_orig); // diff reference // slow get on position .. - final int i = l.indexOf(p6_22_34); + final int i = l.indexOf(p6_22_34_other); Dummy q = l.get(i); Assert.assertNotNull(q); - Assert.assertEquals(p6_22_34, q); - Assert.assertTrue(p6_22_34.hashCode() == q.hashCode()); - Assert.assertTrue(p6_22_34 != q); // diff reference + Assert.assertEquals(p6_22_34_other, q); + Assert.assertTrue(p6_22_34_other.hashCode() == q.hashCode()); + Assert.assertTrue(p6_22_34_other != q); // diff reference + Assert.assertTrue(p6_22_34_orig == q); // same reference // fast identity .. - q = l.get(p6_22_34); + q = l.get(p6_22_34_other); Assert.assertNotNull(q); - Assert.assertEquals(p6_22_34, q); - Assert.assertTrue(p6_22_34.hashCode() == q.hashCode()); - Assert.assertTrue(p6_22_34 != q); // diff reference + Assert.assertEquals(p6_22_34_other, q); + Assert.assertTrue(p6_22_34_other.hashCode() == q.hashCode()); + Assert.assertTrue(p6_22_34_other != q); // diff reference + Assert.assertTrue(p6_22_34_orig == q); // same reference Assert.assertTrue(!l.add(q)); // add same - Assert.assertTrue(!l.add(p6_22_34)); // add equivalent + Assert.assertTrue(!l.add(p6_22_34_other)); // add equivalent - q = l.getOrAdd(p6_22_34); // not added test + q = l.getOrAdd(p6_22_34_other); // not added test w/ diff hash-obj Assert.assertNotNull(q); - Assert.assertEquals(p6_22_34, q); - Assert.assertTrue(p6_22_34.hashCode() == q.hashCode()); - Assert.assertTrue(p6_22_34 != q); // diff reference + Assert.assertEquals(p6_22_34_other, q); + Assert.assertTrue(p6_22_34_other.hashCode() == q.hashCode()); + Assert.assertTrue(p6_22_34_other != q); // diff reference + Assert.assertTrue(p6_22_34_orig == q); // same reference + Assert.assertTrue(checkOrder(l, 0, 10, 100)); + Assert.assertTrue(checkOrder(l, 100, 6, 4)); final Dummy p1_2_3 = new Dummy(1, 2, 3); // a new one .. q = l.getOrAdd(p1_2_3); // added test @@ -122,6 +174,29 @@ public class TestArrayHashSet01 extends SingletonJunitCase { Assert.assertEquals(p1_2_3, q); Assert.assertTrue(p1_2_3.hashCode() == q.hashCode()); Assert.assertTrue(p1_2_3 == q); // _same_ reference, since getOrAdd added it + Assert.assertTrue(checkOrder(l, 0, 10, 100)); + Assert.assertTrue(checkOrder(l, 100, 6, 4)); + + final Dummy pNull = null; + NullPointerException npe = null; + try { + q = l.getOrAdd(pNull); + Assert.assertNull(q); + } catch (final NullPointerException _npe) { npe = _npe; } + if( l.supportsNullValue() ) { + Assert.assertNull(npe); + } else { + Assert.assertNotNull(npe); + } + + try { + Assert.assertTrue(l.remove(pNull)); + } catch (final NullPointerException _npe) { npe = _npe; } + if( l.supportsNullValue() ) { + Assert.assertNull(npe); + } else { + Assert.assertNotNull(npe); + } } public static void main(final String args[]) throws IOException { diff --git a/src/junit/com/jogamp/common/util/TestBitfield00.java b/src/junit/com/jogamp/common/util/TestBitfield00.java new file mode 100644 index 0000000..9ace743 --- /dev/null +++ b/src/junit/com/jogamp/common/util/TestBitfield00.java @@ -0,0 +1,431 @@ +/** + * Copyright 2015 JogAmp Community. All rights reserved. + * + * 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 + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * 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; + +import org.junit.Test; +import org.junit.Assert; + +import com.jogamp.junit.util.SingletonJunitCase; + +import org.junit.FixMethodOrder; +import org.junit.runners.MethodSorters; + +/** + * Test basic bitfield operations for {@link Bitfield} + */ +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +public class TestBitfield00 extends SingletonJunitCase { + + @Test + public void test01_BitCount32_One() { + final String[] pyramid32bit_one = BitDemoData.pyramid32bit_one; + for(int i=0; i<pyramid32bit_one.length; i++) { + final int val0 = 1 << i; + final int oneBitCountI = Integer.bitCount(val0); + final String pattern0 = pyramid32bit_one[i]; + final int val1 = BitDemoData.toInteger(pattern0); + final String pattern1 = BitDemoData.toBinaryString(val0, 32); + final int oneBitCount0 = BitDemoData.getOneBitCount(pattern0); + final int oneBitCount1 = Bitfield.Util.bitCount(val0); + final String msg = String.format("Round %02d: 0x%08x %s, c %d / %d%n : 0x%08x %s, c %d%n", + i, val0, pattern0, oneBitCount0, oneBitCountI, val1, pattern1, oneBitCount1); + + Assert.assertEquals(msg, val0, val1); + Assert.assertEquals(msg, pattern0, pattern1); + + Assert.assertEquals(msg, oneBitCount0, oneBitCountI); + Assert.assertEquals(msg, oneBitCount0, oneBitCount1); + } + } + + @SuppressWarnings("unused") + @Test + public void test02_BitCount32_Samples() { + final long MAX = BitDemoData.UNSIGNED_INT_MAX_VALUE; + final long MAX_minus = MAX-0x1FF; + final long MAX_half = MAX/2; + final long MAX_half_minus = MAX_half-0x1FF; + final long MAX_half_plus = MAX_half+0x1FF; + + if( false ) { + for(long l=0; l<=MAX; l++) { + test_BitCount32_Samples(l); + } + } + for(long l=0; l>=0x1FF; l++) { + test_BitCount32_Samples(l); + } + for(long l=MAX_half_minus; l<=MAX_half_plus; l++) { + test_BitCount32_Samples(l); + } + for(long l=MAX_minus; l<=MAX; l++) { + test_BitCount32_Samples(l); + } + } + static void test_BitCount32_Samples(final long l) { + final int oneBitCountL = Long.bitCount(l); + final int val0 = (int)l; + final int oneBitCountI = Integer.bitCount(val0); + final int oneBitCount1 = Bitfield.Util.bitCount(val0); + final String msg = String.format("Round 0x%08x, c %d / %d / %d", val0, + oneBitCountL, oneBitCountI, oneBitCount1); + Assert.assertEquals(msg, oneBitCountI, oneBitCountL); + Assert.assertEquals(msg, oneBitCountI, oneBitCount1); + } + + static int[] testDataOneBit = new int[] { + 0,0, 1,1, 2,1, 3,2, 4,1, 5,2, 6,2, 7,3, + 8,1, 9,2, 10,2, 11,3, 12,2, 13,3, 14,3, 15,4, 16,1, 17,2, + 0x3F,6, 0x40,1, 0x41,2, 0x7f,7, 0x80,1, 0x81,2, 0xfe,7, 0xff,8, + 0x4000,1, 0x4001,2, 0x7000,3, 0x7fff,15, + 0x0FFFFFF0,24, + 0x55555555,16, + 0x7F53F57B,23, 0xFEA7EAF6,23, /* << 1 */ + 0x80000000, 1, + 0xAAAAAAAA,16, + 0xC0C0C0C0, 8, + 0xFF000000, 8, + 0xFFFFFFFF,32 + }; + @Test + public void test03_BitCount32_Data() { + for(int i = 0; i<testDataOneBit.length; i+=2) { + test_BitCount32_Data(testDataOneBit[i], testDataOneBit[i+1]); + } + } + static void test_BitCount32_Data(final int i, final int expOneBits) { + final int oneBitCountI = Integer.bitCount(i); + final int oneBitCount1 = Bitfield.Util.bitCount(i); + final String msg = String.format("Round 0x%08x, c %d / %d", i, + oneBitCountI, oneBitCount1); + Assert.assertEquals(msg, oneBitCount1, expOneBits); + Assert.assertEquals(msg, oneBitCountI, oneBitCount1); + } + + @Test + public void test10_Setup() { + final int bitSize32 = 32; + final int bitSize128 = 128; + final Bitfield bf1 = Bitfield.Factory.create(bitSize32); + Assert.assertEquals(bitSize32, bf1.size()); + Assert.assertTrue(bf1 instanceof jogamp.common.util.Int32Bitfield); + final Bitfield bf2 = Bitfield.Factory.create(bitSize128); + Assert.assertEquals(bitSize128, bf2.size()); + Assert.assertTrue(bf2 instanceof jogamp.common.util.Int32ArrayBitfield); + + // verify no bit is set + Assert.assertEquals(0, bf1.bitCount()); + Assert.assertEquals(0, bf2.bitCount()); + + bf1.clearField(true); + bf2.clearField(true); + Assert.assertEquals(bf1.size(), bf1.bitCount()); + Assert.assertEquals(bf2.size(), bf2.bitCount()); + + bf1.clearField(false); + bf2.clearField(false); + Assert.assertEquals(0, bf1.bitCount()); + Assert.assertEquals(0, bf2.bitCount()); + } + static class TestDataBF { + final int bitSize; + final int val; + final String pattern; + public TestDataBF(final int bitSize, final int value, final String pattern) { + this.bitSize = bitSize; + this.val = value; + this.pattern = pattern; + } + } + static TestDataBF[] testDataBF32Bit = { + new TestDataBF(32, BitDemoData.testIntMSB, BitDemoData.testStringMSB), + new TestDataBF(32, BitDemoData.testIntMSB_rev, BitDemoData.testStringMSB_rev), + new TestDataBF(32, BitDemoData.testIntLSB, BitDemoData.testStringLSB), + new TestDataBF(32, BitDemoData.testIntLSB_revByte, BitDemoData.testStringLSB_revByte), + + // H->L : 0x04030201: 00000100 00000011 00000010 00000001 + new TestDataBF(32, 0x04030201, "00000100000000110000001000000001"), + + // H->L : 0xAFFECAFE: 10101111 11111110 11001010 11111110 + new TestDataBF(32, 0xAFFECAFE, "10101111111111101100101011111110"), + // H->L : 0xDEADBEEF: 11011110 10101101 10111110 11101111 + new TestDataBF(32, 0xDEADBEEF, "11011110101011011011111011101111") + }; + static TestDataBF[] testDataBF16Bit = { + // H->L : 0x0201: 00000100 00000011 00000010 00000001 + new TestDataBF(16, 0x0201, "0000001000000001"), + // H->L : 0x0403: 00000100 00000011 + new TestDataBF(16, 0x0403, "0000010000000011"), + + // H->L : 0xAFFE: 10101111 11111110 + new TestDataBF(16, 0xAFFE, "1010111111111110"), + // H->L : 0xCAFE: 11001010 11111110 + new TestDataBF(16, 0xCAFE, "1100101011111110"), + + // H->L : 0xDEADBEEF: 11011110 10101101 10111110 11101111 + new TestDataBF(16, 0xDEAD, "1101111010101101"), + new TestDataBF(16, 0xBEEF, "1011111011101111") + }; + static TestDataBF[] testDataBF3Bit = { + new TestDataBF(3, 0x01, "001"), + new TestDataBF(3, 0x02, "010"), + new TestDataBF(3, 0x05, "101") + }; + + @Test + public void test20_ValidateTestData() { + for(int i=0; i<testDataBF32Bit.length; i++) { + test_ValidateTestData( testDataBF32Bit[i] ); + } + for(int i=0; i<testDataBF16Bit.length; i++) { + test_ValidateTestData( testDataBF16Bit[i] ); + } + for(int i=0; i<testDataBF3Bit.length; i++) { + test_ValidateTestData( testDataBF3Bit[i] ); + } + } + static void test_ValidateTestData(final TestDataBF d) { + final int oneBitCount0 = Bitfield.Util.bitCount(d.val); + final int oneBitCount1 = BitDemoData.getOneBitCount(d.pattern); + Assert.assertEquals(oneBitCount1, oneBitCount0); + final String pattern0 = BitDemoData.toBinaryString(d.val, d.bitSize); + Assert.assertEquals(d.pattern, pattern0); + final int val1 = BitDemoData.toInteger(d.pattern); + Assert.assertEquals(d.val, val1); + Assert.assertEquals(d.bitSize, pattern0.length()); + } + + static void assertEquals(final Bitfield bf, final int bf_off, final int v, final String pattern, final int oneBitCount) { + final int len = pattern.length(); + for(int i=0; i<len; i++) { + final boolean exp0 = 0 != ( v & ( 1 << i ) ); + final boolean exp1 = '1' == pattern.charAt(len-1-i); + final boolean has = bf.get(i+bf_off); + final String msg = String.format("Pos %04d: Value 0x%08x / %s, c %d", i, v, pattern, oneBitCount); + Assert.assertEquals(msg, exp0, has); + Assert.assertEquals(msg, exp1, has); + } + } + + @Test + public void test21_Aligned32bit() { + for(int i=0; i<testDataBF32Bit.length; i++) { + test_Aligned32bit( testDataBF32Bit[i] ); + } + for(int i=0; i<testDataBF16Bit.length; i++) { + test_Aligned32bit( testDataBF16Bit[i] ); + } + for(int i=0; i<testDataBF3Bit.length; i++) { + test_Aligned32bit( testDataBF3Bit[i] ); + } + } + static int get32BitStorageSize(final int bits) { + final int units = Math.max(1, ( bits + 31 ) >>> 5); + return units << 5; + } + static void test_Aligned32bit(final TestDataBF d) { + final int oneBitCount = Bitfield.Util.bitCount(d.val); + + final Bitfield bf1 = Bitfield.Factory.create(d.bitSize); + Assert.assertEquals(get32BitStorageSize(d.bitSize), bf1.size()); + final Bitfield bf2 = Bitfield.Factory.create(d.bitSize+128); + Assert.assertEquals(get32BitStorageSize(d.bitSize+128), bf2.size()); + + bf1.put32( 0, d.bitSize, d.val); + Assert.assertEquals(d.val, bf1.get32( 0, d.bitSize)); + Assert.assertEquals(oneBitCount, bf1.bitCount()); + assertEquals(bf1, 0, d.val, d.pattern, oneBitCount); + + bf2.put32( 0, d.bitSize, d.val); + Assert.assertEquals(d.val, bf2.get32( 0, d.bitSize)); + Assert.assertEquals(oneBitCount*1, bf2.bitCount()); + assertEquals(bf2, 0, d.val, d.pattern, oneBitCount); + bf2.put32(64, d.bitSize, d.val); + Assert.assertEquals(d.val, bf2.get32(64, d.bitSize)); + Assert.assertEquals(oneBitCount*2, bf2.bitCount()); + assertEquals(bf2, 64, d.val, d.pattern, oneBitCount); + + Assert.assertEquals(d.val, bf2.copy32(0, 96, d.bitSize)); + Assert.assertEquals(d.val, bf2.get32(96, d.bitSize)); + Assert.assertEquals(oneBitCount*3, bf2.bitCount()); + assertEquals(bf2, 96, d.val, d.pattern, oneBitCount); + } + + @Test + public void test21_Unaligned() { + for(int i=0; i<testDataBF32Bit.length; i++) { + test_Unaligned(testDataBF32Bit[i]); + } + for(int i=0; i<testDataBF16Bit.length; i++) { + test_Unaligned(testDataBF16Bit[i]); + } + for(int i=0; i<testDataBF3Bit.length; i++) { + test_Unaligned( testDataBF3Bit[i] ); + } + } + static void test_Unaligned(final TestDataBF d) { + final Bitfield bf1 = Bitfield.Factory.create(d.bitSize); + final Bitfield bf2 = Bitfield.Factory.create(d.bitSize+128); + Assert.assertEquals(get32BitStorageSize(d.bitSize), bf1.size()); + Assert.assertEquals(get32BitStorageSize(d.bitSize+128), bf2.size()); + test_Unaligned( d, bf1 ); + test_Unaligned( d, bf2 ); + } + static void test_Unaligned(final TestDataBF d, final Bitfield bf) { + final int maxBitpos = bf.size()-d.bitSize; + for(int i=0; i<=maxBitpos; i++) { + bf.clearField(false); + test_Unaligned(d, bf, i); + } + } + static void test_Unaligned(final TestDataBF d, final Bitfield bf, final int lowBitnum) { + final int maxBitpos = bf.size()-d.bitSize; + final int oneBitCount = Bitfield.Util.bitCount(d.val); + + final String msg = String.format("Value 0x%08x / %s, l %d/%d, c %d, lbPos %d -> %d", + d.val, d.pattern, d.bitSize, bf.size(), oneBitCount, lowBitnum, maxBitpos); + + // + // via put32 + // + bf.put32( lowBitnum, d.bitSize, d.val); + for(int i=0; i<d.bitSize; i++) { + Assert.assertEquals(msg+", bitpos "+i, 0 != ( d.val & ( 1 << i ) ), bf.get(lowBitnum+i)); + } + Assert.assertEquals(msg, d.val, bf.get32( lowBitnum, d.bitSize)); + Assert.assertEquals(msg, oneBitCount, bf.bitCount()); + assertEquals(bf, lowBitnum, d.val, d.pattern, oneBitCount); + + // + // via copy32 + // + if( lowBitnum < maxBitpos ) { + // copy bits 1 forward + // clear trailing orig bit + Assert.assertEquals(msg, d.val, bf.copy32(lowBitnum, lowBitnum+1, d.bitSize)); + bf.clear(lowBitnum); + Assert.assertEquals(msg, d.val, bf.get32( lowBitnum+1, d.bitSize)); + Assert.assertEquals(msg, oneBitCount, bf.bitCount()); + assertEquals(bf, lowBitnum+1, d.val, d.pattern, oneBitCount); + } + + // test put() return value (previous value) + bf.clearField(false); + Assert.assertEquals(msg+", bitpos "+0, false, bf.put(lowBitnum+0, true)); + Assert.assertEquals(msg+", bitpos "+0, true, bf.put(lowBitnum+0, false)); + + // + // via put + // + for(int i=0; i<d.bitSize; i++) { + Assert.assertEquals(msg+", bitpos "+i, false, bf.put(lowBitnum+i, 0 != ( d.val & ( 1 << i ) ))); + } + Assert.assertEquals(msg, d.val, bf.get32(lowBitnum, d.bitSize)); + for(int i=0; i<d.bitSize; i++) { + Assert.assertEquals(msg+", bitpos "+i, 0 != ( d.val & ( 1 << i ) ), bf.get(lowBitnum+i)); + } + Assert.assertEquals(msg, oneBitCount, bf.bitCount()); + assertEquals(bf, lowBitnum, d.val, d.pattern, oneBitCount); + + // + // via copy + // + if( lowBitnum < maxBitpos ) { + // copy bits 1 forward + // clear trailing orig bit + for(int i=d.bitSize-1; i>=0; i--) { + Assert.assertEquals(msg+", bitpos "+i, 0 != ( d.val & ( 1 << i ) ), + bf.copy(lowBitnum+i, lowBitnum+1+i) ); + } + bf.clear(lowBitnum); + Assert.assertEquals(msg, d.val, bf.get32( lowBitnum+1, d.bitSize)); + for(int i=0; i<d.bitSize; i++) { + Assert.assertEquals(msg+", bitpos "+i, 0 != ( d.val & ( 1 << i ) ), bf.get(lowBitnum+1+i)); + } + Assert.assertEquals(msg, oneBitCount, bf.bitCount()); + assertEquals(bf, lowBitnum+1, d.val, d.pattern, oneBitCount); + } + + // + // via set/clear + // + bf.clearField(false); + for(int i=0; i<d.bitSize; i++) { + if( 0 != ( d.val & ( 1 << i ) ) ) { + bf.set(lowBitnum+i); + } else { + bf.clear(lowBitnum+i); + } + } + Assert.assertEquals(msg, d.val, bf.get32(lowBitnum, d.bitSize)); + for(int i=0; i<d.bitSize; i++) { + Assert.assertEquals(msg+", bitpos "+i, 0 != ( d.val & ( 1 << i ) ), bf.get(lowBitnum+i)); + } + Assert.assertEquals(msg, oneBitCount, bf.bitCount()); + assertEquals(bf, lowBitnum, d.val, d.pattern, oneBitCount); + + // + // Validate 'other bits' put32/get32 + // + bf.clearField(false); + bf.put32( lowBitnum, d.bitSize, d.val); + checkOtherBits(d, bf, lowBitnum, msg, 0); + + bf.clearField(true); + bf.put32( lowBitnum, d.bitSize, d.val); + checkOtherBits(d, bf, lowBitnum, msg, Bitfield.UNSIGNED_INT_MAX_VALUE); + } + + static void checkOtherBits(final TestDataBF d, final Bitfield bf, final int lowBitnum, final String msg, final int expBits) { + final int highBitnum = lowBitnum + d.bitSize - 1; + // System.err.println(msg+": [0"+".."+"("+lowBitnum+".."+highBitnum+").."+(bf.size()-1)+"]"); + for(int i=0; i<lowBitnum; i+=32) { + final int len = Math.min(32, lowBitnum-i); + final int val = bf.get32(i, len); + final int exp = expBits & Bitfield.Util.getBitMask(len); + // System.err.println(" <"+i+".."+(i+len-1)+">, exp "+BitDemoData.toHexString(exp)); + Assert.assertEquals(msg+", bitpos "+i, exp, val); + } + for(int i=highBitnum+1; i<bf.size(); i+=32) { + final int len = Math.min(32, bf.size() - i); + final int val = bf.get32(i, len); + final int exp = expBits & Bitfield.Util.getBitMask(len); + // System.err.println(" <"+i+".."+(i+len-1)+">, exp "+BitDemoData.toHexString(exp)); + Assert.assertEquals(msg+", bitpos "+i, exp, val); + } + } + + public static void main(final String args[]) throws IOException { + final String tstname = TestBitfield00.class.getName(); + org.junit.runner.JUnitCore.main(tstname); + } + +} diff --git a/src/junit/com/jogamp/common/util/TestBitstream00.java b/src/junit/com/jogamp/common/util/TestBitstream00.java index 920363b..a2fd095 100644 --- a/src/junit/com/jogamp/common/util/TestBitstream00.java +++ b/src/junit/com/jogamp/common/util/TestBitstream00.java @@ -40,7 +40,7 @@ import org.junit.Assert; import com.jogamp.common.nio.Buffers; import com.jogamp.common.os.Platform; -import static com.jogamp.common.util.BitstreamData.*; +import static com.jogamp.common.util.BitDemoData.*; import com.jogamp.junit.util.SingletonJunitCase; diff --git a/src/junit/com/jogamp/common/util/TestBitstream01.java b/src/junit/com/jogamp/common/util/TestBitstream01.java index 49931a3..bff37e3 100644 --- a/src/junit/com/jogamp/common/util/TestBitstream01.java +++ b/src/junit/com/jogamp/common/util/TestBitstream01.java @@ -35,7 +35,7 @@ import org.junit.Assert; import org.junit.Test; import com.jogamp.junit.util.SingletonJunitCase; -import static com.jogamp.common.util.BitstreamData.*; +import static com.jogamp.common.util.BitDemoData.*; import org.junit.FixMethodOrder; import org.junit.runners.MethodSorters; diff --git a/src/junit/com/jogamp/common/util/TestBitstream02.java b/src/junit/com/jogamp/common/util/TestBitstream02.java index 16904a2..5e6da1c 100644 --- a/src/junit/com/jogamp/common/util/TestBitstream02.java +++ b/src/junit/com/jogamp/common/util/TestBitstream02.java @@ -37,7 +37,7 @@ import org.junit.Test; import com.jogamp.common.nio.Buffers; import com.jogamp.junit.util.SingletonJunitCase; -import static com.jogamp.common.util.BitstreamData.*; +import static com.jogamp.common.util.BitDemoData.*; import org.junit.FixMethodOrder; import org.junit.runners.MethodSorters; diff --git a/src/junit/com/jogamp/common/util/TestBitstream03.java b/src/junit/com/jogamp/common/util/TestBitstream03.java index a6129d8..bd09d4a 100644 --- a/src/junit/com/jogamp/common/util/TestBitstream03.java +++ b/src/junit/com/jogamp/common/util/TestBitstream03.java @@ -38,7 +38,7 @@ import org.junit.Test; import com.jogamp.common.nio.Buffers; import com.jogamp.junit.util.SingletonJunitCase; -import static com.jogamp.common.util.BitstreamData.*; +import static com.jogamp.common.util.BitDemoData.*; import org.junit.FixMethodOrder; import org.junit.runners.MethodSorters; diff --git a/src/junit/com/jogamp/common/util/TestBitstream04.java b/src/junit/com/jogamp/common/util/TestBitstream04.java index 47be38d..2302e2e 100644 --- a/src/junit/com/jogamp/common/util/TestBitstream04.java +++ b/src/junit/com/jogamp/common/util/TestBitstream04.java @@ -38,7 +38,7 @@ import org.junit.Test; import com.jogamp.common.nio.Buffers; import com.jogamp.junit.util.SingletonJunitCase; -import static com.jogamp.common.util.BitstreamData.*; +import static com.jogamp.common.util.BitDemoData.*; import org.junit.FixMethodOrder; import org.junit.runners.MethodSorters; diff --git a/src/junit/com/jogamp/common/util/TestIOUtil01.java b/src/junit/com/jogamp/common/util/TestIOUtil01.java index e85aa37..19bc8b0 100644 --- a/src/junit/com/jogamp/common/util/TestIOUtil01.java +++ b/src/junit/com/jogamp/common/util/TestIOUtil01.java @@ -35,6 +35,7 @@ import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStream; +import java.net.URISyntaxException; import java.net.URLConnection; import java.nio.ByteBuffer; @@ -43,6 +44,9 @@ import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Test; +import com.jogamp.common.ExceptionUtils; +import com.jogamp.common.net.URIDumpUtil; +import com.jogamp.common.net.Uri; import com.jogamp.common.os.MachineDataInfo; import com.jogamp.common.os.Platform; import com.jogamp.junit.util.SingletonJunitCase; @@ -78,8 +82,86 @@ public class TestIOUtil01 extends SingletonJunitCase { } @Test - public void testCopyStream01Array() throws IOException { - final URLConnection urlConn = IOUtil.getResource(this.getClass(), tfilename); + public void test01CleanPathString() throws IOException, URISyntaxException { + { + final String input = "./dummy/nop/../a.txt"; + final String expected = "dummy/a.txt"; + Assert.assertEquals(expected, IOUtil.cleanPathString(input)); + } + { + final String input = "../dummy/nop/../a.txt"; + final String expected = "../dummy/a.txt"; + Assert.assertEquals(expected, IOUtil.cleanPathString(input)); + } + { + final String input = ".././dummy/nop/../a.txt"; + final String expected = "../dummy/a.txt"; + Assert.assertEquals(expected, IOUtil.cleanPathString(input)); + } + { + final String input = "./../dummy/nop/../a.txt"; + final String expected = "../dummy/a.txt"; + Assert.assertEquals(expected, IOUtil.cleanPathString(input)); + } + { + final String input = "../dummy/./nop/../a.txt"; + final String expected = "../dummy/a.txt"; + Assert.assertEquals(expected, IOUtil.cleanPathString(input)); + } + { + final String input = "/dummy/nop/./../a.txt"; + final String expected = "/dummy/a.txt"; + Assert.assertEquals(expected, IOUtil.cleanPathString(input)); + } + { + final String input = "dummy/../nop/./.././aaa/bbb/../../a.txt"; + final String expected = "a.txt"; + Assert.assertEquals(expected, IOUtil.cleanPathString(input)); + } + { + final String input = "/dummy/../nop/./.././aaa/bbb/././ccc/../../../a.txt"; + final String expected = "/a.txt"; + Assert.assertEquals(expected, IOUtil.cleanPathString(input)); + } + { + URISyntaxException use = null; + try { + // Error case! + final String input = "../../error.txt"; + final String expected = "error.txt"; + final String result = IOUtil.cleanPathString(input); // URISyntaxException + System.err.println("input : "+input); + System.err.println("expected: "+expected); + System.err.println("result : "+result); + Assert.assertEquals(expected, result); + } catch (final URISyntaxException _use) { + use = _use; + ExceptionUtils.dumpThrowable("", _use, 0, 3); + } + Assert.assertNotNull("URISyntaxException expected", use); + } + { + URISyntaxException use = null; + try { + // Error case! + final String input = ".././a/../../error.txt"; + final String expected = "error.txt"; + final String result = IOUtil.cleanPathString(input); // URISyntaxException + System.err.println("input : "+input); + System.err.println("expected: "+expected); + System.err.println("result : "+result); + Assert.assertEquals(expected, result); + } catch (final URISyntaxException _use) { + use = _use; + ExceptionUtils.dumpThrowable("", _use, 0, 3); + } + Assert.assertNotNull("URISyntaxException expected", use); + } + } + + @Test + public void test11CopyStream01Array() throws IOException { + final URLConnection urlConn = IOUtil.getResource(tfilename, this.getClass().getClassLoader(), this.getClass()); Assert.assertNotNull(urlConn); final BufferedInputStream bis = new BufferedInputStream( urlConn.getInputStream() ); final byte[] bb; @@ -94,8 +176,8 @@ public class TestIOUtil01 extends SingletonJunitCase { } @Test - public void testCopyStream02Buffer() throws IOException { - final URLConnection urlConn = IOUtil.getResource(this.getClass(), tfilename); + public void test12CopyStream02Buffer() throws IOException { + final URLConnection urlConn = IOUtil.getResource(tfilename, this.getClass().getClassLoader(), this.getClass()); Assert.assertNotNull(urlConn); final BufferedInputStream bis = new BufferedInputStream( urlConn.getInputStream() ); final ByteBuffer bb; @@ -111,16 +193,16 @@ public class TestIOUtil01 extends SingletonJunitCase { } @Test - public void testCopyStream03Buffer() throws IOException { + public void test13CopyStream03Buffer() throws IOException { final String tfilename2 = "./test2.bin" ; - final URLConnection urlConn1 = IOUtil.getResource(this.getClass(), tfilename); + final URLConnection urlConn1 = IOUtil.getResource(tfilename, this.getClass().getClassLoader(), this.getClass()); Assert.assertNotNull(urlConn1); final File file2 = new File(tfilename2); file2.deleteOnExit(); try { IOUtil.copyURLConn2File(urlConn1, file2); - final URLConnection urlConn2 = IOUtil.getResource(this.getClass(), tfilename2); + final URLConnection urlConn2 = IOUtil.getResource(tfilename2, this.getClass().getClassLoader(), this.getClass()); Assert.assertNotNull(urlConn2); final BufferedInputStream bis = new BufferedInputStream( urlConn2.getInputStream() ); diff --git a/src/junit/com/jogamp/common/util/TestPlatform01.java b/src/junit/com/jogamp/common/util/TestPlatform01.java index 6f1fe0e..bf3e79d 100644 --- a/src/junit/com/jogamp/common/util/TestPlatform01.java +++ b/src/junit/com/jogamp/common/util/TestPlatform01.java @@ -44,7 +44,7 @@ public class TestPlatform01 extends SingletonJunitCase { @Test public void testInfo00() { System.err.println(); - System.err.println(); + System.err.print(Platform.getNewline()); System.err.println("OS name/type: "+Platform.getOSName()+", "+Platform.getOSType()); System.err.println("OS version: "+Platform.getOSVersion()+", "+Platform.getOSVersionNumber()); System.err.println(); diff --git a/src/junit/com/jogamp/common/util/TestRunnableTask01.java b/src/junit/com/jogamp/common/util/TestRunnableTask01.java index 76c2d2a..6fd8f19 100644 --- a/src/junit/com/jogamp/common/util/TestRunnableTask01.java +++ b/src/junit/com/jogamp/common/util/TestRunnableTask01.java @@ -60,7 +60,7 @@ public class TestRunnableTask01 extends SingletonJunitCase { System.err.println("BB.0: "+syncObject); synchronized (syncObject) { System.err.println("BB.1: "+syncObject); - new Thread(clientAction, Thread.currentThread().getName()+"-clientAction").start(); + new InterruptSource.Thread(null, clientAction, Thread.currentThread().getName()+"-clientAction").start(); try { System.err.println("BB.2"); syncObject.wait(); @@ -88,7 +88,7 @@ public class TestRunnableTask01 extends SingletonJunitCase { System.err.println("BB.0: "+rTask.getSyncObject()); synchronized (rTask.getSyncObject()) { System.err.println("BB.1: "+rTask.getSyncObject()); - new Thread(rTask, Thread.currentThread().getName()+"-clientAction").start(); + new InterruptSource.Thread(null, rTask, Thread.currentThread().getName()+"-clientAction").start(); try { System.err.println("BB.2"); rTask.getSyncObject().wait(); diff --git a/src/junit/com/jogamp/common/util/TestVersionSemantics.java b/src/junit/com/jogamp/common/util/TestVersionSemantics.java index 4fe4bcd..8e36684 100644 --- a/src/junit/com/jogamp/common/util/TestVersionSemantics.java +++ b/src/junit/com/jogamp/common/util/TestVersionSemantics.java @@ -89,6 +89,11 @@ public class TestVersionSemantics extends SingletonJunitCase { testVersions(diffCriteria, Delta.CompatibilityType.NON_BACKWARD_COMPATIBLE, "2.2.1", "2.3.0", excludesDefault); } + @Test + public void testVersionV230V232() throws IllegalArgumentException, IOException, URISyntaxException { + testVersions(diffCriteria, Delta.CompatibilityType.BACKWARD_COMPATIBLE_BINARY, "2.3.0", "2.3.2", excludesDefault); + } + void testVersions(final DiffCriteria diffCriteria, final Delta.CompatibilityType expectedCompatibilityType, final String v1, final String v2, final Set<String> excludes) throws IllegalArgumentException, IOException, URISyntaxException { @@ -100,16 +105,16 @@ public class TestVersionSemantics extends SingletonJunitCase { VersionSemanticsUtil.testVersion(diffCriteria, expectedCompatibilityType, previousJar, preVersionNumber, - currentJar, curVersionNumber, - excludes); + currentJar, curVersionNumber, excludes); } @Test - public void testVersionV230V23x() throws IllegalArgumentException, IOException, URISyntaxException { - // final Delta.CompatibilityType expectedCompatibilityType = Delta.CompatibilityType.NON_BACKWARD_COMPATIBLE; - final Delta.CompatibilityType expectedCompatibilityType = Delta.CompatibilityType.BACKWARD_COMPATIBLE_USER; + public void testVersionV232V24x() throws IllegalArgumentException, IOException, URISyntaxException { + final Delta.CompatibilityType expectedCompatibilityType = Delta.CompatibilityType.NON_BACKWARD_COMPATIBLE; + // final Delta.CompatibilityType expectedCompatibilityType = Delta.CompatibilityType.BACKWARD_COMPATIBLE_USER; + // final Delta.CompatibilityType expectedCompatibilityType = Delta.CompatibilityType.BACKWARD_COMPATIBLE_BINARY; - final VersionNumberString preVersionNumber = new VersionNumberString("2.3.0"); + final VersionNumberString preVersionNumber = new VersionNumberString("2.3.2"); final File previousJar = new File("lib/v"+preVersionNumber.getVersionString()+"/"+jarFile); final ClassLoader currentCL = TestVersionSemantics.class.getClassLoader(); diff --git a/src/junit/com/jogamp/common/util/locks/TestRecursiveLock01.java b/src/junit/com/jogamp/common/util/locks/TestRecursiveLock01.java index 4508f94..7455618 100644 --- a/src/junit/com/jogamp/common/util/locks/TestRecursiveLock01.java +++ b/src/junit/com/jogamp/common/util/locks/TestRecursiveLock01.java @@ -38,6 +38,7 @@ import org.junit.Assert; import org.junit.Test; import com.jogamp.common.os.Platform; +import com.jogamp.common.util.InterruptSource; import com.jogamp.junit.util.SingletonJunitCase; import org.junit.FixMethodOrder; @@ -170,7 +171,7 @@ public class TestRecursiveLock01 extends SingletonJunitCase { public final void action2Deferred(final int l, final YieldMode yieldMode) { final Action2 action2 = new Action2(l, yieldMode); - new Thread(action2, Thread.currentThread().getName()+"-deferred").start(); + new InterruptSource.Thread(null, action2, Thread.currentThread().getName()+"-deferred").start(); } public final void lock() { @@ -296,14 +297,14 @@ public class TestRecursiveLock01 extends SingletonJunitCase { final long t0 = System.currentTimeMillis(); final LockedObject lo = new LockedObject(implType, fair); final LockedObjectRunner[] runners = new LockedObjectRunner[threadNum]; - final Thread[] threads = new Thread[threadNum]; + final InterruptSource.Thread[] threads = new InterruptSource.Thread[threadNum]; int i; for(i=0; i<threadNum; i++) { runners[i] = new LockedObjectRunner1(lo, loops, iloops, yieldMode); // String name = Thread.currentThread().getName()+"-ActionThread-"+i+"_of_"+threadNum; final String name = "ActionThread-"+i+"_of_"+threadNum; - threads[i] = new Thread( runners[i], name ); + threads[i] = new InterruptSource.Thread( null, runners[i], name ); threads[i].start(); } diff --git a/src/junit/com/jogamp/common/util/locks/TestRecursiveThreadGroupLock01.java b/src/junit/com/jogamp/common/util/locks/TestRecursiveThreadGroupLock01.java index e35d146..30a0274 100644 --- a/src/junit/com/jogamp/common/util/locks/TestRecursiveThreadGroupLock01.java +++ b/src/junit/com/jogamp/common/util/locks/TestRecursiveThreadGroupLock01.java @@ -34,6 +34,7 @@ import org.junit.Assert; import org.junit.Test; import com.jogamp.common.os.Platform; +import com.jogamp.common.util.InterruptSource; import com.jogamp.junit.util.SingletonJunitCase; import org.junit.FixMethodOrder; @@ -239,15 +240,15 @@ public class TestRecursiveThreadGroupLock01 extends SingletonJunitCase { final LockedObject lo = new LockedObject(); final LockedObjectRunner[] concurrentRunners = new LockedObjectRunner[concurrentThreadNum]; final LockedObjectRunner[] slaveRunners = new LockedObjectRunner[slaveThreadNum]; - final Thread[] concurrentThreads = new Thread[concurrentThreadNum]; - final Thread[] slaveThreads = new Thread[slaveThreadNum]; - final Thread[] noCoOwnerThreads = new Thread[0]; + final InterruptSource.Thread[] concurrentThreads = new InterruptSource.Thread[concurrentThreadNum]; + final InterruptSource.Thread[] slaveThreads = new InterruptSource.Thread[slaveThreadNum]; + final InterruptSource.Thread[] noCoOwnerThreads = new InterruptSource.Thread[0]; int i; for(i=0; i<slaveThreadNum; i++) { slaveRunners[i] = new LockedObjectRunner1(" ", "s"+i, lo, loops, mark, yieldMode); final String name = "ActionThread-Slaves-"+i+"_of_"+slaveThreadNum; - slaveThreads[i] = new Thread( slaveRunners[i], name ); + slaveThreads[i] = new InterruptSource.Thread( null, slaveRunners[i], name ); } for(i=0; i<concurrentThreadNum; i++) { String name; @@ -258,7 +259,7 @@ public class TestRecursiveThreadGroupLock01 extends SingletonJunitCase { concurrentRunners[i] = new LockedObjectRunner1(" ", "O"+i, lo, noCoOwnerThreads, loops, mark, yieldMode); name = "ActionThread-Others-"+i+"_of_"+concurrentThreadNum; } - concurrentThreads[i] = new Thread( concurrentRunners[i], name ); + concurrentThreads[i] = new InterruptSource.Thread( null, concurrentRunners[i], name ); concurrentThreads[i].start(); if(i==0) { // master thread w/ slaves shall start first diff --git a/src/junit/com/jogamp/common/util/locks/TestSingletonServerSocket00.java b/src/junit/com/jogamp/common/util/locks/TestSingletonServerSocket00.java index b018a79..ce0087a 100644 --- a/src/junit/com/jogamp/common/util/locks/TestSingletonServerSocket00.java +++ b/src/junit/com/jogamp/common/util/locks/TestSingletonServerSocket00.java @@ -35,10 +35,12 @@ import org.junit.Test; import org.junit.FixMethodOrder; import org.junit.runners.MethodSorters; +import com.jogamp.common.util.InterruptSource; +import com.jogamp.junit.util.JunitTracer; import com.jogamp.junit.util.SingletonJunitCase; @FixMethodOrder(MethodSorters.NAME_ASCENDING) -public class TestSingletonServerSocket00 { +public class TestSingletonServerSocket00 extends JunitTracer { public static final long SINGLE_INSTANCE_LOCK_TO = SingletonJunitCase.SINGLE_INSTANCE_LOCK_TO; public static final long SINGLE_INSTANCE_LOCK_POLL = 100; // poll every 100ms @@ -69,7 +71,7 @@ public class TestSingletonServerSocket00 { } private Thread startLockUnlockOffThread(final int i) { - final Thread t = new Thread(new Runnable() { + final Thread t = new InterruptSource.Thread(null, new Runnable() { public void run() { final SingletonInstance myLock = SingletonInstance.createServerSocket(10, SingletonJunitCase.SINGLE_INSTANCE_LOCK_PORT); System.err.println(Thread.currentThread().getName()+" LOCK try .."); diff --git a/src/junit/com/jogamp/common/util/locks/TestSingletonServerSocket01.java b/src/junit/com/jogamp/common/util/locks/TestSingletonServerSocket01.java index b37e600..c637865 100644 --- a/src/junit/com/jogamp/common/util/locks/TestSingletonServerSocket01.java +++ b/src/junit/com/jogamp/common/util/locks/TestSingletonServerSocket01.java @@ -35,10 +35,11 @@ import org.junit.Test; import org.junit.FixMethodOrder; import org.junit.runners.MethodSorters; +import com.jogamp.junit.util.JunitTracer; import com.jogamp.junit.util.SingletonJunitCase; @FixMethodOrder(MethodSorters.NAME_ASCENDING) -public class TestSingletonServerSocket01 { +public class TestSingletonServerSocket01 extends JunitTracer { private static volatile SingletonInstance singletonInstance; @BeforeClass diff --git a/src/junit/com/jogamp/gluegen/test/junit/generation/BaseClass.java b/src/junit/com/jogamp/gluegen/test/junit/generation/BaseClass.java index b5f4f2c..db8c157 100644 --- a/src/junit/com/jogamp/gluegen/test/junit/generation/BaseClass.java +++ b/src/junit/com/jogamp/gluegen/test/junit/generation/BaseClass.java @@ -98,63 +98,6 @@ public class BaseClass extends SingletonJunitCase { AnonBlob ab = null; PointerBuffer pb=null; - // Test constants values: binding and value! - { - // Plain vanilla CPP constants - Assert.assertEquals( 1, Bindingtest1.CONSTANT_ONE); - Assert.assertEquals( 8, Bindingtest1.ARRAY_SIZE); - Assert.assertEquals(1234, Bindingtest1.DEFINE_01); - - // Enums - Assert.assertEquals( 1, Bindingtest1.LI); - Assert.assertEquals( 3, Bindingtest1.LO); - Assert.assertEquals( 2, Bindingtest1.LU); - Assert.assertEquals( 1, Bindingtest1.MI); - Assert.assertEquals( 3, Bindingtest1.MO); - Assert.assertEquals( 2, Bindingtest1.MU); - Assert.assertEquals( 0, Bindingtest1.ZERO); - Assert.assertEquals( 1, Bindingtest1.ONE); - Assert.assertEquals( 2, Bindingtest1.TWO); - Assert.assertEquals( 3, Bindingtest1.THREE); - - // CPP Macro Expansion! - Assert.assertEquals( 1, Bindingtest1.NUMBER_ONE); - Assert.assertEquals( 2, Bindingtest1.NUMBER_TWO); - Assert.assertEquals( 4, Bindingtest1.NUMBER_FOUR); - Assert.assertEquals( 8, Bindingtest1.NUMBER_EIGHT); - Assert.assertEquals( 9, Bindingtest1.NUMBER_NINE); - Assert.assertEquals( 10, Bindingtest1.NUMBER_TEN); - - - // Floating point hexadecimals - final float CL_FLT_A0 = Bindingtest1.CL_FLT_A0; - final float CL_FLT_A1 = Bindingtest1.CL_FLT_A1; - final float CL_FLT_A2 = Bindingtest1.CL_FLT_A2; - Assert.assertEquals( 0x1.p127f, CL_FLT_A0, EPSILON); - Assert.assertEquals( 0x1.p+127F, CL_FLT_A1, EPSILON); - Assert.assertEquals( 0x1.p-127f, CL_FLT_A2, EPSILON); - - final float CL_FLT_EPSILON = Bindingtest1.CL_FLT_EPSILON; - final double CL_FLT_MAX= Bindingtest1.CL_FLT_MAX; - final double CL_FLT_MIN = Bindingtest1.CL_FLT_MIN; - Assert.assertEquals( 0x1.0p-23f, CL_FLT_EPSILON, EPSILON); - Assert.assertEquals( 0x1.fffffep127f, CL_FLT_MAX, EPSILON); - Assert.assertEquals( 0x1.0p-126f, CL_FLT_MIN, EPSILON); - - final double CL_DBL_B0 = Bindingtest1.CL_DBL_B0; - final double CL_DBL_B1 = Bindingtest1.CL_DBL_B1; - final double CL_DBL_B2 = Bindingtest1.CL_DBL_B2; - Assert.assertEquals( 0x1.p127d, CL_DBL_B0, EPSILON); - Assert.assertEquals( 0x1.p+127D, CL_DBL_B1, EPSILON); - Assert.assertEquals( 0x1.p-127d, CL_DBL_B2, EPSILON); - - final float CL_DBL_EPSILON = Bindingtest1.CL_DBL_EPSILON; - final double CL_DBL_MAX= Bindingtest1.CL_DBL_MAX; - final double CL_DBL_MIN = Bindingtest1.CL_DBL_MIN; - Assert.assertEquals( 0x1.0p-52f, CL_DBL_EPSILON, EPSILON); - Assert.assertEquals( 0x1.fffffffffffffp1023, CL_DBL_MAX, EPSILON); - Assert.assertEquals( 0x1.0p-1022, CL_DBL_MIN, EPSILON); - } { l = binding.testXID(l); l = binding.testXID_2(l); @@ -267,6 +210,185 @@ public class BaseClass extends SingletonJunitCase { l = binding.typeTestUIntPtrT(l, l); } + /** + * Verifies if all generated static constant values are completed, + * and whether their value is as expected! + * <p> + * Covers all enumerates and defines. + * </p> + */ + public void chapter01TestStaticConstants(final Bindingtest1 binding) throws Exception { + // Plain vanilla CPP constants + Assert.assertEquals( 1, Bindingtest1.CONSTANT_ONE); + Assert.assertEquals( 8, Bindingtest1.ARRAY_SIZE); + Assert.assertEquals(1234, Bindingtest1.DEFINE_01); + + // Enums + Assert.assertEquals( 1, Bindingtest1.LI); + Assert.assertEquals( 3, Bindingtest1.LO); + Assert.assertEquals( 2, Bindingtest1.LU); + Assert.assertEquals( 1, Bindingtest1.MI); + Assert.assertEquals( 3, Bindingtest1.MO); + Assert.assertEquals( 2, Bindingtest1.MU); + Assert.assertEquals( 0, Bindingtest1.ZERO); + Assert.assertEquals( 1, Bindingtest1.ONE); + Assert.assertEquals( 2, Bindingtest1.TWO); + Assert.assertEquals( 3, Bindingtest1.THREE); + + // CPP Macro Expansion! + Assert.assertEquals( 1, Bindingtest1.NUMBER_ONE); + Assert.assertEquals( 2, Bindingtest1.NUMBER_TWO); + Assert.assertEquals( 4, Bindingtest1.NUMBER_FOUR); + Assert.assertEquals( 5, Bindingtest1.NUMBER_FIVE); + Assert.assertEquals( 8, Bindingtest1.NUMBER_EIGHT); + Assert.assertEquals( 9, Bindingtest1.NUMBER_NINE); + Assert.assertEquals( 10, Bindingtest1.NUMBER_TEN); + + // Enum Constant Expressions! + Assert.assertEquals( 1, Bindingtest1.ENUM_NUM_ONE); + Assert.assertEquals( 2, Bindingtest1.ENUM_NUM_TWO); + Assert.assertEquals( 3, Bindingtest1.ENUM_NUM_THREE); + Assert.assertEquals( 4, Bindingtest1.ENUM_NUM_FOUR); + Assert.assertEquals( 5, Bindingtest1.ENUM_NUM_FIVE); + Assert.assertEquals( 8, Bindingtest1.ENUM_NUM_EIGHT); + Assert.assertEquals( 9, Bindingtest1.ENUM_NUM_NINE); + Assert.assertEquals( 10, Bindingtest1.ENUM_NUM_TEN); + + // Integer 32bit (int / enum) + final int ENUM_I0 = Bindingtest1.ENUM_I0; + final int ENUM_I1 = Bindingtest1.ENUM_I1; + final int ENUM_I2 = Bindingtest1.ENUM_I2; + final int ENUM_I3 = Bindingtest1.ENUM_I3; + final int ENUM_I4 = -Bindingtest1.ENUM_I4; + final int ENUM_I5 = -Bindingtest1.ENUM_I5; + final int ENUM_I6 = -Bindingtest1.ENUM_I6; + final int ENUM_I7 = Bindingtest1.ENUM_I7; + final int ENUM_I8 = Bindingtest1.ENUM_I8; + final int ENUM_I9 = Bindingtest1.ENUM_I9; + final int ENUM_IA = Bindingtest1.ENUM_IA; + final int ENUM_IB = Bindingtest1.ENUM_IB; + final int ENUM_IX = Bindingtest1.ENUM_IX; + int iexp = 10; + Assert.assertEquals(iexp++, ENUM_I0); + Assert.assertEquals(iexp++, ENUM_I1); + Assert.assertEquals(iexp++, ENUM_I2); + Assert.assertEquals(iexp++, ENUM_I3); + Assert.assertEquals(iexp++, ENUM_I4); + Assert.assertEquals(iexp++, ENUM_I5); + Assert.assertEquals(iexp++, ENUM_I6); + Assert.assertEquals(iexp++, ENUM_I7); + Assert.assertEquals(iexp++, ENUM_I8); + Assert.assertEquals(iexp++, ENUM_I9); + Assert.assertEquals(iexp++, ENUM_IA); + Assert.assertEquals(iexp++, ENUM_IB); + Assert.assertEquals(0xffffffff, ENUM_IX); + + // Integer 32bit (int / define) + final int CL_INT_I0 = Bindingtest1.CL_INT_I0; + final int CL_INT_I1 = Bindingtest1.CL_INT_I1; + final int CL_INT_I2 = Bindingtest1.CL_INT_I2; + final int CL_INT_I3 = Bindingtest1.CL_INT_I3; + final int CL_INT_I4 = -Bindingtest1.CL_INT_I4; + final int CL_INT_I5 = -Bindingtest1.CL_INT_I5; + final int CL_INT_I6 = -Bindingtest1.CL_INT_I6; + final int CL_INT_I7 = -Bindingtest1.CL_INT_I7; + final int CL_INT_I8 = Bindingtest1.CL_INT_I8; + final int CL_INT_I9 = Bindingtest1.CL_INT_I9; + final int CL_INT_IA = Bindingtest1.CL_INT_IA; + final int CL_INT_IB = Bindingtest1.CL_INT_IB; + final int CL_INT_IX = Bindingtest1.CL_INT_IX; + iexp = 10; + Assert.assertEquals(iexp++, CL_INT_I0); + Assert.assertEquals(iexp++, CL_INT_I1); + Assert.assertEquals(iexp++, CL_INT_I2); + Assert.assertEquals(iexp++, CL_INT_I3); + Assert.assertEquals(iexp++, CL_INT_I4); + Assert.assertEquals(iexp++, CL_INT_I5); + Assert.assertEquals(iexp++, CL_INT_I6); + Assert.assertEquals(iexp++, CL_INT_I7); + Assert.assertEquals(iexp++, CL_INT_I8); + Assert.assertEquals(iexp++, CL_INT_I9); + Assert.assertEquals(iexp++, CL_INT_IA); + Assert.assertEquals(iexp++, CL_INT_IB); + Assert.assertEquals(0xffffffff, CL_INT_IX); + + // Integer 64bit (long / define ) + final long CL_LNG_L0 = Bindingtest1.CL_LNG_L0; + final long CL_LNG_L1 = Bindingtest1.CL_LNG_L1; + final long CL_LNG_L2 = Bindingtest1.CL_LNG_L2; + final long CL_LNG_L3 = Bindingtest1.CL_LNG_L3; + final long CL_LNG_L4 = -Bindingtest1.CL_LNG_L4; + final long CL_LNG_L5 = -Bindingtest1.CL_LNG_L5; + final long CL_LNG_L6 = -Bindingtest1.CL_LNG_L6; + final long CL_LNG_L7 = -Bindingtest1.CL_LNG_L7; + final long CL_LNG_L8 = Bindingtest1.CL_LNG_L8; + final long CL_LNG_L9 = Bindingtest1.CL_LNG_L9; + final long CL_LNG_LA = Bindingtest1.CL_LNG_LA; + final long CL_LNG_LB = Bindingtest1.CL_LNG_LB; + final long CL_LNG_LX = Bindingtest1.CL_LNG_LX; + long lexp = 2147483648L; + Assert.assertEquals(lexp++, CL_LNG_L0); + Assert.assertEquals(lexp++, CL_LNG_L1); + Assert.assertEquals(lexp++, CL_LNG_L2); + Assert.assertEquals(lexp++, CL_LNG_L3); + Assert.assertEquals(lexp++, CL_LNG_L4); + Assert.assertEquals(lexp++, CL_LNG_L5); + Assert.assertEquals(lexp++, CL_LNG_L6); + Assert.assertEquals(lexp++, CL_LNG_L7); + Assert.assertEquals(lexp++, CL_LNG_L8); + Assert.assertEquals(lexp++, CL_LNG_L9); + Assert.assertEquals(lexp++, CL_LNG_LA); + Assert.assertEquals(lexp++, CL_LNG_LB); + Assert.assertEquals(0xffffffffffffffffL, CL_LNG_LX); + + // Floating point hexadecimals + final float CL_FLT_A0 = Bindingtest1.CL_FLT_A0; + final float CL_FLT_A1 = Bindingtest1.CL_FLT_A1; + final float CL_FLT_A2 = Bindingtest1.CL_FLT_A2; + final float CL_FLT_A3 = Bindingtest1.CL_FLT_A3; + final float CL_FLT_A4 = Bindingtest1.CL_FLT_A4; + final float CL_FLT_A5 = Bindingtest1.CL_FLT_A5; + final float CL_FLT_A6 = Bindingtest1.CL_FLT_A6; + final float CL_FLT_A7 = Bindingtest1.CL_FLT_A7; + Assert.assertEquals( 0x1.p127f, CL_FLT_A0, EPSILON); + Assert.assertEquals( 0x1.p+127F, CL_FLT_A1, EPSILON); + Assert.assertEquals( 0x1.p-127f, CL_FLT_A2, EPSILON); + Assert.assertEquals( -0.1f, CL_FLT_A3, EPSILON); + Assert.assertEquals( 0.2f, CL_FLT_A4, EPSILON); + Assert.assertEquals( 0.3f, CL_FLT_A5, EPSILON); + Assert.assertEquals( 0.4f, CL_FLT_A6, EPSILON); + Assert.assertEquals( 1.0f, CL_FLT_A7, EPSILON); + + final float CL_FLT_EPSILON = Bindingtest1.CL_FLT_EPSILON; + final double CL_FLT_MAX= Bindingtest1.CL_FLT_MAX; + final double CL_FLT_MIN = Bindingtest1.CL_FLT_MIN; + Assert.assertEquals( 0x1.0p-23f, CL_FLT_EPSILON, EPSILON); + Assert.assertEquals( 0x1.fffffep127f, CL_FLT_MAX, EPSILON); + Assert.assertEquals( 0x1.0p-126f, CL_FLT_MIN, EPSILON); + + final double CL_DBL_B0 = Bindingtest1.CL_DBL_B0; + final double CL_DBL_B1 = Bindingtest1.CL_DBL_B1; + final double CL_DBL_B2 = Bindingtest1.CL_DBL_B2; + final double CL_DBL_B3 = Bindingtest1.CL_DBL_B3; + final double CL_DBL_B4 = Bindingtest1.CL_DBL_B4; + final double CL_DBL_B5 = Bindingtest1.CL_DBL_B5; + final double CL_DBL_B6 = Bindingtest1.CL_DBL_B6; + Assert.assertEquals( 0x1.p127d, CL_DBL_B0, EPSILON); + Assert.assertEquals( 0x1.p+127D, CL_DBL_B1, EPSILON); + Assert.assertEquals( 0x1.p-127d, CL_DBL_B2, EPSILON); + Assert.assertEquals( -0.1, CL_DBL_B3, EPSILON); + Assert.assertEquals( 0.2, CL_DBL_B4, EPSILON); + Assert.assertEquals( 0.3, CL_DBL_B5, EPSILON); + Assert.assertEquals( 3.5e+38, CL_DBL_B6, EPSILON); + + final float CL_DBL_EPSILON = Bindingtest1.CL_DBL_EPSILON; + final double CL_DBL_MAX= Bindingtest1.CL_DBL_MAX; + final double CL_DBL_MIN = Bindingtest1.CL_DBL_MIN; + Assert.assertEquals( 0x1.0p-52f, CL_DBL_EPSILON, EPSILON); + Assert.assertEquals( 0x1.fffffffffffffp1023, CL_DBL_MAX, EPSILON); + Assert.assertEquals( 0x1.0p-1022, CL_DBL_MIN, EPSILON); + } + ByteBuffer newByteBuffer(final int size, final boolean direct) { if(direct) { final ByteBuffer bb = Buffers.newDirectByteBuffer(size); diff --git a/src/junit/com/jogamp/gluegen/test/junit/generation/Test1p1JavaEmitter.java b/src/junit/com/jogamp/gluegen/test/junit/generation/Test1p1JavaEmitter.java index 9e961cb..5809acf 100644 --- a/src/junit/com/jogamp/gluegen/test/junit/generation/Test1p1JavaEmitter.java +++ b/src/junit/com/jogamp/gluegen/test/junit/generation/Test1p1JavaEmitter.java @@ -50,7 +50,7 @@ public class Test1p1JavaEmitter extends BaseClass { * Verifies loading of the new library. */ @BeforeClass - public static void chapter01TestLoadLibrary() throws Exception { + public static void chapter__TestLoadLibrary() throws Exception { BindingJNILibLoader.loadBindingtest1p1(); } @@ -58,7 +58,7 @@ public class Test1p1JavaEmitter extends BaseClass { * Verifies the existence and creation of the generated class. */ @Test - public void chapter02TestClassExist() throws Exception { + public void chapter00TestClassExist() throws Exception { testClassExist("test1p1"); } @@ -71,6 +71,18 @@ public class Test1p1JavaEmitter extends BaseClass { } /** + * Verifies if all generated static constant values are completed, + * and whether their value is as expected! + * <p> + * Covers all enumerates and defines. + * </p> + */ + @Test + public void chapter01TestStaticConstants() throws Exception { + chapter01TestStaticConstants(new Bindingtest1p1Impl()); + } + + /** * Verifies if all methods / signatures are properly generated, * can be invoked and functions. * This is a compilation (coverage) and runtime time (semantic) test. diff --git a/src/junit/com/jogamp/gluegen/test/junit/generation/Test1p2LoadJNIAndImplLib.java b/src/junit/com/jogamp/gluegen/test/junit/generation/Test1p2LoadJNIAndImplLib.java index b8adab0..e61c600 100644 --- a/src/junit/com/jogamp/gluegen/test/junit/generation/Test1p2LoadJNIAndImplLib.java +++ b/src/junit/com/jogamp/gluegen/test/junit/generation/Test1p2LoadJNIAndImplLib.java @@ -46,9 +46,9 @@ public class Test1p2LoadJNIAndImplLib extends BaseClass { * Verifies loading of the new library. */ @BeforeClass - public static void chapter01TestLoadLibrary() throws Exception { + public static void chapter__TestLoadLibrary() throws Exception { BindingJNILibLoader.loadBindingtest1p2(); - dynamicLookupHelper = NativeLibrary.open("test1", Test1p2LoadJNIAndImplLib.class.getClassLoader(), true); + dynamicLookupHelper = NativeLibrary.open("test1", true, true, Test1p2LoadJNIAndImplLib.class.getClassLoader(), true); Assert.assertNotNull("NativeLibrary.open(test1) failed", dynamicLookupHelper); Bindingtest1p2Impl.resetProcAddressTable(dynamicLookupHelper); @@ -58,17 +58,16 @@ public class Test1p2LoadJNIAndImplLib extends BaseClass { * Verifies the existence and creation of the generated class. */ @Test - public void chapter02TestClassExist() throws Exception { + public void chapter00TestClassExist() throws Exception { testClassExist("test1p2"); } - @SuppressWarnings("unused") public static void main(final String args[]) throws Exception { if( true ) { - chapter01TestLoadLibrary(); + chapter__TestLoadLibrary(); final Test1p2LoadJNIAndImplLib tst = new Test1p2LoadJNIAndImplLib(); - tst.chapter02TestClassExist(); + tst.chapter00TestClassExist(); } else { final String tstname = Test1p2LoadJNIAndImplLib.class.getName(); org.junit.runner.JUnitCore.main(tstname); diff --git a/src/junit/com/jogamp/gluegen/test/junit/generation/Test1p2ProcAddressEmitter.java b/src/junit/com/jogamp/gluegen/test/junit/generation/Test1p2ProcAddressEmitter.java index 49a1851..fa99915 100644 --- a/src/junit/com/jogamp/gluegen/test/junit/generation/Test1p2ProcAddressEmitter.java +++ b/src/junit/com/jogamp/gluegen/test/junit/generation/Test1p2ProcAddressEmitter.java @@ -30,6 +30,7 @@ package com.jogamp.gluegen.test.junit.generation; import java.io.IOException; +import com.jogamp.gluegen.test.junit.generation.impl.Bindingtest1p1Impl; import com.jogamp.gluegen.test.junit.generation.impl.Bindingtest1p2Impl; import com.jogamp.common.os.NativeLibrary; @@ -54,9 +55,9 @@ public class Test1p2ProcAddressEmitter extends BaseClass { * Verifies loading of the new library. */ @BeforeClass - public static void chapter01TestLoadLibrary() throws Exception { + public static void chapter__TestLoadLibrary() throws Exception { BindingJNILibLoader.loadBindingtest1p2(); - dynamicLookupHelper = NativeLibrary.open("test1", Test1p2ProcAddressEmitter.class.getClassLoader(), true); + dynamicLookupHelper = NativeLibrary.open("test1", false, false, Test1p2ProcAddressEmitter.class.getClassLoader(), true); Assert.assertNotNull("NativeLibrary.open(test1) failed", dynamicLookupHelper); Bindingtest1p2Impl.resetProcAddressTable(dynamicLookupHelper); @@ -66,7 +67,7 @@ public class Test1p2ProcAddressEmitter extends BaseClass { * Verifies the existence and creation of the generated class. */ @Test - public void chapter02TestClassExist() throws Exception { + public void chapter00TestClassExist() throws Exception { testClassExist("test1p2"); } @@ -79,6 +80,18 @@ public class Test1p2ProcAddressEmitter extends BaseClass { } /** + * Verifies if all generated static constant values are completed, + * and whether their value is as expected! + * <p> + * Covers all enumerates and defines. + * </p> + */ + @Test + public void chapter01TestStaticConstants() throws Exception { + chapter01TestStaticConstants(new Bindingtest1p2Impl()); + } + + /** * Verifies if all methods / signatures are properly generated, * can be invoked and functions. * This is a compilation (coverage) and runtime time (semantic) test. diff --git a/src/junit/com/jogamp/gluegen/test/junit/generation/test1.h b/src/junit/com/jogamp/gluegen/test/junit/generation/test1.h index 4e60114..4896165 100644 --- a/src/junit/com/jogamp/gluegen/test/junit/generation/test1.h +++ b/src/junit/com/jogamp/gluegen/test/junit/generation/test1.h @@ -39,13 +39,53 @@ typedef void * AnonBuffer; // Non Opaque // typedef XID XID_2; // Duplicate w/ compatible type (ignored) - OpenSolaris: Native gcc error // typedef int XID_2; // Duplicate w/ incompatible type ERROR +#define CL_INT_I0 10 +#define CL_INT_I1 11u +#define CL_INT_I2 12U +#define CL_INT_I3 0x0d +#define CL_INT_I4 -14 +#define CL_INT_I5 -15u +#define CL_INT_I6 -16U +#define CL_INT_I7 -0x11U +#define CL_INT_I8 +18 +#define CL_INT_I9 +19u +#define CL_INT_IA +20U +#define CL_INT_IB +0x15u +#define CL_INT_IX 0xffffffffU + +enum CL_INT { ENUM_I0=10, ENUM_I1, ENUM_I2=+12U, ENUM_I3=0x0d, ENUM_I4=-14, ENUM_I5=-15u, ENUM_I6=-16U, ENUM_I7=0x11U, + ENUM_I8=+18, ENUM_I9=+19u, ENUM_IA, ENUM_IB=+0x15u, ENUM_IX=0xffffffffU }; + +#define CL_LNG_L0 2147483648 +#define CL_LNG_L1 0x80000001ul +#define CL_LNG_L2 2147483650UL +#define CL_LNG_L3 0x80000003l +#define CL_LNG_L4 -2147483652L +#define CL_LNG_L5 -2147483653ul +#define CL_LNG_L6 -2147483654lu +#define CL_LNG_L7 -0x80000007UL +#define CL_LNG_L8 +2147483656LU +#define CL_LNG_L9 +2147483657uL +#define CL_LNG_LA +2147483658lU +#define CL_LNG_LB +0x8000000BLu +#define CL_LNG_LX 0xffffffffffffffffUL + #define CL_FLT_A0 0x1p127 #define CL_FLT_A1 0x1p+127F -#define CL_FLT_A2 0x1p-127f +#define CL_FLT_A2 +0x1p-127f +#define CL_FLT_A3 -0.1 +#define CL_FLT_A4 0.2f +#define CL_FLT_A5 0.3F +#define CL_FLT_A6 .4 +#define CL_FLT_A7 1.0 #define CL_DBL_B0 0x1.p127d #define CL_DBL_B1 0x1.p+127D -#define CL_DBL_B2 0x1.p-127d +#define CL_DBL_B2 +0x1.p-127d +#define CL_DBL_B3 -0.1d +#define CL_DBL_B4 0.2D +#define CL_DBL_B5 .3D +#define CL_DBL_B6 3.5e+38 #define CL_FLT_MAX 0x1.fffffep127f #define CL_FLT_MIN 0x1.0p-126f @@ -69,10 +109,22 @@ typedef void * AnonBuffer; // Non Opaque #define NUMBER_ONE CONSTANT_ONE #define NUMBER_TWO ( NUMBER_ONE + NUMBER_ONE ) #define NUMBER_FOUR ( NUMBER_ONE << NUMBER_TWO ) +#define NUMBER_FIVE ( ( CONSTANT_ONE << NUMBER_TWO ) + NUMBER_ONE ) #define NUMBER_EIGHT ( NUMBER_TWO * NUMBER_TWO + ( NUMBER_ONE << NUMBER_TWO ) ) #define NUMBER_NINE ( 2 * 2 + ( 1 << 2 ) + 1 ) #define NUMBER_TEN ( NUMBER_EIGHT | NUMBER_TWO ) +enum NumberOps { ENUM_NUM_ONE = CONSTANT_ONE, + ENUM_NUM_TWO = 1+1, + ENUM_NUM_THREE, + ENUM_NUM_FOUR = ( ENUM_NUM_ONE << ENUM_NUM_TWO ), + ENUM_NUM_FIVE = ( CONSTANT_ONE << ENUM_NUM_TWO ) + ENUM_NUM_ONE, + ENUM_NUM_EIGHT = ( ENUM_NUM_TWO * ENUM_NUM_TWO + ( ENUM_NUM_ONE << ENUM_NUM_TWO ) ), + ENUM_NUM_NINE = ( 2 * 2 + ( 1 << 2 ) + 1 ), + ENUM_NUM_TEN = ENUM_NUM_EIGHT | + ENUM_NUM_TWO + }; + enum Lala { LI=1, LU, LO }; // enum Lala { LI=1, LU, LO }; // Duplicate w/ same value (ignored, ERROR in native compilation) // enum Lala { LI=1, LU=3, LO }; // Duplicate w/ diff value ERROR diff --git a/src/junit/com/jogamp/junit/sec/Applet01.java b/src/junit/com/jogamp/junit/sec/Applet01.java index f028d7c..fd13207 100644 --- a/src/junit/com/jogamp/junit/sec/Applet01.java +++ b/src/junit/com/jogamp/junit/sec/Applet01.java @@ -201,7 +201,7 @@ public class Applet01 extends Applet { final Uri absLib = libDir1.concat(Uri.Encoded.cast("natives/" + libBaseName)); Exception sec01 = null; try { - final NativeLibrary nlib = NativeLibrary.open(absLib.toFile().getPath(), cl); + final NativeLibrary nlib = NativeLibrary.open(absLib.toFile().getPath(), true, true, cl, true); System.err.println("NativeLibrary: "+nlib); } catch (final SecurityException e) { sec01 = e; diff --git a/src/junit/com/jogamp/junit/sec/TestSecIOUtil01.java b/src/junit/com/jogamp/junit/sec/TestSecIOUtil01.java index b3a1877..27f8d0b 100644 --- a/src/junit/com/jogamp/junit/sec/TestSecIOUtil01.java +++ b/src/junit/com/jogamp/junit/sec/TestSecIOUtil01.java @@ -183,7 +183,7 @@ public class TestSecIOUtil01 extends SingletonJunitCase { Exception se0 = null; NativeLibrary nlib = null; try { - nlib = NativeLibrary.open(absLib.toFile().getPath(), cl); + nlib = NativeLibrary.open(absLib.toFile().getPath(), true, true, cl, true); System.err.println("NativeLibrary: "+nlib); } catch (final SecurityException e) { se0 = e; diff --git a/src/junit/com/jogamp/junit/util/SingletonJunitCase.java b/src/junit/com/jogamp/junit/util/SingletonJunitCase.java index 7fb5fea..ad80bde 100644 --- a/src/junit/com/jogamp/junit/util/SingletonJunitCase.java +++ b/src/junit/com/jogamp/junit/util/SingletonJunitCase.java @@ -45,19 +45,29 @@ public abstract class SingletonJunitCase extends JunitTracer { private static SingletonInstance singletonInstance = null; // system wide lock via port locking private static final Object singletonSync = new Object(); // classloader wide lock + private static boolean enabled = true; + + /** + * Default is {@code true}. + */ + public static final void enableSingletonLock(final boolean v) { + enabled = v; + } @BeforeClass public static final void oneTimeSetUpSingleton() { // one-time initialization code synchronized( singletonSync ) { - if( null == singletonInstance ) { - System.err.println("++++ Test Singleton.ctor()"); - // singletonInstance = SingletonInstance.createFileLock(SINGLE_INSTANCE_LOCK_POLL, SINGLE_INSTANCE_LOCK_FILE); - singletonInstance = SingletonInstance.createServerSocket(SINGLE_INSTANCE_LOCK_POLL, SINGLE_INSTANCE_LOCK_PORT); - } - System.err.println("++++ Test Singleton.lock()"); - if(!singletonInstance.tryLock(SINGLE_INSTANCE_LOCK_TO)) { - throw new RuntimeException("Fatal: Could not lock single instance: "+singletonInstance.getName()); + if( enabled ) { + if( null == singletonInstance ) { + System.err.println("++++ Test Singleton.ctor()"); + // singletonInstance = SingletonInstance.createFileLock(SINGLE_INSTANCE_LOCK_POLL, SINGLE_INSTANCE_LOCK_FILE); + singletonInstance = SingletonInstance.createServerSocket(SINGLE_INSTANCE_LOCK_POLL, SINGLE_INSTANCE_LOCK_PORT); + } + System.err.println("++++ Test Singleton.lock()"); + if(!singletonInstance.tryLock(SINGLE_INSTANCE_LOCK_TO)) { + throw new RuntimeException("Fatal: Could not lock single instance: "+singletonInstance.getName()); + } } } } @@ -67,12 +77,14 @@ public abstract class SingletonJunitCase extends JunitTracer { // one-time cleanup code synchronized( singletonSync ) { System.gc(); // force cleanup - System.err.println("++++ Test Singleton.unlock()"); - singletonInstance.unlock(); - try { - // allowing other JVM instances to pick-up socket - Thread.sleep( SINGLE_INSTANCE_LOCK_POLL ); - } catch (final InterruptedException e) { } + if( enabled ) { + System.err.println("++++ Test Singleton.unlock()"); + singletonInstance.unlock(); + try { + // allowing other JVM instances to pick-up socket + Thread.sleep( SINGLE_INSTANCE_LOCK_POLL ); + } catch (final InterruptedException e) { } + } } } } diff --git a/src/junit/com/jogamp/junit/util/VersionSemanticsUtil.java b/src/junit/com/jogamp/junit/util/VersionSemanticsUtil.java index 78f4460..de850d0 100644 --- a/src/junit/com/jogamp/junit/util/VersionSemanticsUtil.java +++ b/src/junit/com/jogamp/junit/util/VersionSemanticsUtil.java @@ -86,16 +86,18 @@ public class VersionSemanticsUtil { } System.err.println("Semantic Version Test"); - System.err.println("Previous version: "+preVersionNumber+" - "+previousJar.toString()); - System.err.println("Current version: "+curVersionNumber+" - "+currentJar.toString()); - System.err.println("Compat. expected: "+expectedCompatibilityType); - System.err.println("Compat. detected: "+detectedCompatibilityType); - System.err.println("Compat. result: detected "+compS+" expected -> "+(compOK ? "OK" : "ERROR")); + System.err.println(" criteria: "+diffCriteria); + System.err.println(" Previous version: "+preVersionNumber+" - "+previousJar.toString()); + System.err.println(" Current version: "+curVersionNumber+" - "+currentJar.toString()); + System.err.println(" Field values changed: "+delta.fieldCompatChanged()); + System.err.println(" Compat. expected: "+expectedCompatibilityType); + System.err.println(" Compat. detected: "+detectedCompatibilityType); + System.err.println(" Compat. result: detected "+compS+" expected -> "+(compOK ? "OK" : "ERROR")); final String resS; if( compOK ) { - resS = "Current version "+curVersionNumber+" is "+expectedCompatibilityType+" to previous version "+preVersionNumber+", actually "+detectedCompatibilityType; + resS = " Current version "+curVersionNumber+" is "+expectedCompatibilityType+" to previous version "+preVersionNumber+", actually "+detectedCompatibilityType; } else { - resS = "Current version "+curVersionNumber+" is not "+expectedCompatibilityType+" to previous version "+preVersionNumber+", but "+detectedCompatibilityType; + resS = " Current version "+curVersionNumber+" is not "+expectedCompatibilityType+" to previous version "+preVersionNumber+", but "+detectedCompatibilityType; } System.err.println(resS); System.err.printf("%n%n"); |