aboutsummaryrefslogtreecommitdiffstats
path: root/test/java/org/jau/util
diff options
context:
space:
mode:
Diffstat (limited to 'test/java/org/jau/util')
-rw-r--r--test/java/org/jau/util/RingBuffer01Base.java353
-rw-r--r--test/java/org/jau/util/TestArrayHashMap01.java186
-rw-r--r--test/java/org/jau/util/TestArrayHashSet01.java206
-rw-r--r--test/java/org/jau/util/TestIOUtil01.java224
-rw-r--r--test/java/org/jau/util/TestJarUtil.java271
-rw-r--r--test/java/org/jau/util/TestLFRingBuffer01.java49
-rw-r--r--test/java/org/jau/util/TestPlatform01.java94
-rw-r--r--test/java/org/jau/util/TestRunnableTask01.java111
-rw-r--r--test/java/org/jau/util/TestSystemPropsAndEnvs.java90
-rw-r--r--test/java/org/jau/util/TestTempJarCache.java273
-rw-r--r--test/java/org/jau/util/TestValueConversion.java139
-rw-r--r--test/java/org/jau/util/TestVersionInfo.java79
-rw-r--r--test/java/org/jau/util/TestVersionNumber.java301
13 files changed, 2376 insertions, 0 deletions
diff --git a/test/java/org/jau/util/RingBuffer01Base.java b/test/java/org/jau/util/RingBuffer01Base.java
new file mode 100644
index 0000000..5b04aa3
--- /dev/null
+++ b/test/java/org/jau/util/RingBuffer01Base.java
@@ -0,0 +1,353 @@
+/**
+ * Author: Sven Gothel <[email protected]>
+ * Copyright (c) 2021 Gothel Software e.K.
+ * Copyright (c) 2013 Gothel Software e.K.
+ * Copyright (c) 2013 JogAmp Community.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+ * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+ * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+package org.jau.util;
+
+
+import org.junit.Assert;
+import org.junit.Test;
+
+public abstract class RingBuffer01Base {
+ private static boolean DEBUG = false;
+
+ public abstract Ringbuffer<Integer> createEmpty(int initialCapacity);
+ public abstract Ringbuffer<Integer> createFull(Integer[] source);
+
+ public Integer[] createIntArray(final int capacity, final int startValue) {
+ final Integer[] array = new Integer[capacity];
+ for(int i=0; i<capacity; i++) {
+ array[i] = Integer.valueOf(startValue+i);
+ }
+ return array;
+ }
+
+ private void readTestImpl(final Ringbuffer<Integer> rb, final boolean clearRef, final int capacity, final int len, final int startValue) {
+ final int preSize = rb.size();
+ Assert.assertEquals("Wrong capacity "+rb, capacity, rb.capacity());
+ Assert.assertTrue("Too low capacity to read "+len+" elems: "+rb, capacity-len >= 0);
+ Assert.assertTrue("Too low size to read "+len+" elems: "+rb, preSize >= len);
+ Assert.assertTrue("Is empty "+rb, !rb.isEmpty());
+
+ for(int i=0; i<len; i++) {
+ final Integer vI = rb.get();
+ Assert.assertNotNull("Empty at read #"+(i+1)+": "+rb, vI);
+ Assert.assertEquals("Wrong value at read #"+(i+1)+": "+rb, startValue+i, vI.intValue());
+ }
+
+ Assert.assertEquals("Invalid size "+rb, preSize-len, rb.size());
+ Assert.assertTrue("Invalid free slots after reading "+len+": "+rb, rb.getFreeSlots()>= len);
+ Assert.assertTrue("Is full "+rb, !rb.isFull());
+ }
+
+ private void writeTestImpl(final Ringbuffer<Integer> rb, final int capacity, final int len, final int startValue) {
+ final int preSize = rb.size();
+
+ Assert.assertEquals("Wrong capacity "+rb, capacity, rb.capacity());
+ Assert.assertTrue("Too low capacity to write "+len+" elems: "+rb, capacity-len >= 0);
+ Assert.assertTrue("Too low size to write "+len+" elems: "+rb, preSize+len <= capacity);
+ Assert.assertTrue("Is full "+rb, !rb.isFull());
+
+ for(int i=0; i<len; i++) {
+ Assert.assertTrue("Buffer is full at put #"+i+": "+rb, rb.put( Integer.valueOf(startValue+i) ));
+ }
+
+ Assert.assertEquals("Invalid size "+rb, preSize+len, rb.size());
+ Assert.assertTrue("Is empty "+rb, !rb.isEmpty());
+ }
+
+ private void moveGetPutImpl(final Ringbuffer<Integer> rb, final int pos) {
+ Assert.assertTrue("RB is empty "+rb, !rb.isEmpty());
+ for(int i=0; i<pos; i++) {
+ Assert.assertEquals("MoveFull.get failed "+rb, i, rb.get().intValue());
+ Assert.assertTrue("MoveFull.put failed "+rb, rb.put(i));
+ }
+ }
+
+ private void movePutGetImpl(final Ringbuffer<Integer> rb, final int pos) {
+ Assert.assertTrue("RB is full "+rb, !rb.isFull());
+ for(int i=0; i<pos; i++) {
+ Assert.assertTrue("MoveEmpty.put failed "+rb, rb.put(600+i));
+ Assert.assertEquals("MoveEmpty.get failed "+rb, 600+i, rb.get().intValue());
+ }
+ }
+
+ @Test
+ public void test01_FullRead() {
+ final int capacity = 11;
+ final Integer[] source = createIntArray(capacity, 0);
+ final Ringbuffer<Integer> rb = createFull(source);
+ Assert.assertEquals("Not full size "+rb, capacity, rb.size());
+ Assert.assertTrue("Not full "+rb, rb.isFull());
+
+ readTestImpl(rb, true, capacity, capacity, 0);
+ Assert.assertTrue("Not empty "+rb, rb.isEmpty());
+ }
+
+ @Test
+ public void test02_EmptyWrite() {
+ final int capacity = 11;
+ final Ringbuffer<Integer> rb = createEmpty(capacity);
+ Assert.assertEquals("Not zero size "+rb, 0, rb.size());
+ Assert.assertTrue("Not empty "+rb, rb.isEmpty());
+
+ writeTestImpl(rb, capacity, capacity, 0);
+ Assert.assertEquals("Not full size "+rb, capacity, rb.size());
+ Assert.assertTrue("Not full "+rb, rb.isFull());
+
+ readTestImpl(rb, true, capacity, capacity, 0);
+ Assert.assertTrue("Not empty "+rb, rb.isEmpty());
+ }
+
+ @Test
+ public void test03_FullReadReset() {
+ final int capacity = 11;
+ final Integer[] source = createIntArray(capacity, 0);
+ final Ringbuffer<Integer> rb = createFull(source);
+ Assert.assertTrue("Not full "+rb, rb.isFull());
+
+ rb.resetFull(source);
+ Assert.assertTrue("Not full "+rb, rb.isFull());
+
+ readTestImpl(rb, false, capacity, capacity, 0);
+ Assert.assertTrue("Not empty "+rb, rb.isEmpty());
+
+ rb.resetFull(source);
+ Assert.assertTrue("Not full "+rb, rb.isFull());
+
+ readTestImpl(rb, false, capacity, capacity, 0);
+ Assert.assertTrue("Not empty "+rb, rb.isEmpty());
+ }
+
+ @Test
+ public void test04_EmptyWriteClear() {
+ final int capacity = 11;
+ final Ringbuffer<Integer> rb = createEmpty(capacity);
+ Assert.assertTrue("Not empty "+rb, rb.isEmpty());
+
+ rb.clear();
+ Assert.assertTrue("Not empty "+rb, rb.isEmpty());
+
+ writeTestImpl(rb, capacity, capacity, 0);
+ Assert.assertTrue("Not full "+rb, rb.isFull());
+
+ readTestImpl(rb, false, capacity, capacity, 0);
+ Assert.assertTrue("Not empty "+rb, rb.isEmpty());
+
+ rb.clear();
+ Assert.assertTrue("Not empty "+rb, rb.isEmpty());
+
+ writeTestImpl(rb, capacity, capacity, 0);
+ Assert.assertTrue("Not full "+rb, rb.isFull());
+
+ readTestImpl(rb, false, capacity, capacity, 0);
+ Assert.assertTrue("Not empty "+rb, rb.isEmpty());
+ }
+
+ @Test
+ public void test05_ReadResetMid01() {
+ final int capacity = 11;
+ final Integer[] source = createIntArray(capacity, 0);
+ final Ringbuffer<Integer> rb = createFull(source);
+ Assert.assertTrue("Not full "+rb, rb.isFull());
+
+ rb.resetFull(source);
+ Assert.assertTrue("Not full "+rb, rb.isFull());
+
+ readTestImpl(rb, false, capacity, 5, 0);
+ Assert.assertTrue("Is empty "+rb, !rb.isEmpty());
+ Assert.assertTrue("Is Full "+rb, !rb.isFull());
+
+ if( DEBUG ) {
+ rb.dump(System.err, "ReadReset01["+5+"].pre0");
+ }
+ rb.resetFull(source);
+ Assert.assertTrue("Not full "+rb, rb.isFull());
+ if( DEBUG ) {
+ rb.dump(System.err, "ReadReset01["+5+"].post");
+ }
+
+ readTestImpl(rb, false, capacity, capacity, 0);
+ Assert.assertTrue("Not empty "+rb, rb.isEmpty());
+ }
+
+ @Test
+ public void test06_ReadResetMid02() {
+ final int capacity = 11;
+ final Integer[] source = createIntArray(capacity, 0);
+ final Ringbuffer<Integer> rb = createFull(source);
+ Assert.assertTrue("Not full "+rb, rb.isFull());
+
+ rb.resetFull(source);
+ Assert.assertTrue("Not full "+rb, rb.isFull());
+
+ moveGetPutImpl(rb, 5);
+ // readTestImpl(rb, false, capacity, 5, 0);
+ // Assert.assertTrue("Is empty "+rb, !rb.isEmpty());
+ // Assert.assertTrue("Is Full "+rb, !rb.isFull());
+
+ if( DEBUG ) {
+ rb.dump(System.err, "ReadReset02["+5+"].pre0");
+ }
+ rb.resetFull(source);
+ Assert.assertTrue("Not full "+rb, rb.isFull());
+ if( DEBUG ) {
+ rb.dump(System.err, "ReadReset02["+5+"].post");
+ }
+
+ readTestImpl(rb, false, capacity, capacity, 0);
+ Assert.assertTrue("Not empty "+rb, rb.isEmpty());
+ }
+
+ private void test_GrowEmptyImpl(final int initCapacity, final int pos) {
+ final int growAmount = 5;
+ final int grownCapacity = initCapacity+growAmount;
+ final Integer[] growArray = new Integer[growAmount];
+ for(int i=0; i<growAmount; i++) {
+ growArray[i] = Integer.valueOf(100+i);
+ }
+ final Ringbuffer<Integer> rb = createEmpty(initCapacity);
+
+ if( DEBUG ) {
+ rb.dump(System.err, "GrowEmpty["+pos+"].pre0");
+ }
+ movePutGetImpl(rb, pos);
+ if( DEBUG ) {
+ rb.dump(System.err, "GrowEmpty["+pos+"].pre1");
+ }
+ rb.growEmptyBuffer(growArray);
+ if( DEBUG ) {
+ rb.dump(System.err, "GrowEmpty["+pos+"].post");
+ }
+
+ Assert.assertEquals("Wrong capacity "+rb, grownCapacity, rb.capacity());
+ Assert.assertEquals("Not growAmount size "+rb, growAmount, rb.size());
+ Assert.assertTrue("Is full "+rb, !rb.isFull());
+ Assert.assertTrue("Is empty "+rb, !rb.isEmpty());
+
+ for(int i=0; i<growAmount; i++) {
+ final Integer vI = rb.get();
+ Assert.assertNotNull("Empty at read #"+(i+1)+": "+rb, vI);
+ Assert.assertEquals("Wrong value at read #"+(i+1)+": "+rb, 100+i, vI.intValue());
+ }
+
+ Assert.assertEquals("Not zero size "+rb, 0, rb.size());
+ Assert.assertTrue("Not empty "+rb, rb.isEmpty());
+ Assert.assertTrue("Is full "+rb, !rb.isFull());
+ }
+ @Test
+ public void test10_GrowEmpty01_Begin() {
+ test_GrowEmptyImpl(11, 0);
+ }
+ @Test
+ public void test11_GrowEmpty02_Begin2() {
+ test_GrowEmptyImpl(11, 0+2);
+ }
+ @Test
+ public void test12_GrowEmpty03_End() {
+ test_GrowEmptyImpl(11, 11-1);
+ }
+ @Test
+ public void test13_GrowEmpty04_End2() {
+ test_GrowEmptyImpl(11, 11-1-2);
+ }
+
+ private void test_GrowFullImpl(final int initCapacity, final int pos, final boolean debug) {
+ final int growAmount = 5;
+ final int grownCapacity = initCapacity+growAmount;
+ final Integer[] source = createIntArray(initCapacity, 0);
+ final Ringbuffer<Integer> rb = createFull(source);
+
+ if( DEBUG || debug ) {
+ rb.dump(System.err, "GrowFull["+pos+"].pre0");
+ }
+ moveGetPutImpl(rb, pos);
+ if( DEBUG || debug ) {
+ rb.dump(System.err, "GrowFull["+pos+"].pre1");
+ }
+ rb.growFullBuffer(growAmount);
+ if( DEBUG || debug ) {
+ rb.dump(System.err, "GrowFull["+pos+"].post");
+ }
+
+ Assert.assertEquals("Wrong capacity "+rb, grownCapacity, rb.capacity());
+ Assert.assertEquals("Not orig size "+rb, initCapacity, rb.size());
+ Assert.assertTrue("Is full "+rb, !rb.isFull());
+ Assert.assertTrue("Is empty "+rb, !rb.isEmpty());
+
+ for(int i=0; i<growAmount; i++) {
+ Assert.assertTrue("Buffer is full at put #"+i+": "+rb, rb.put( Integer.valueOf(100+i) ));
+ }
+ Assert.assertEquals("Not new size "+rb, grownCapacity, rb.size());
+ Assert.assertTrue("Not full "+rb, rb.isFull());
+
+ for(int i=0; i<initCapacity; i++) {
+ final Integer vI = rb.get();
+ Assert.assertNotNull("Empty at read #"+(i+1)+": "+rb, vI);
+ Assert.assertEquals("Wrong value at read #"+(i+1)+": "+rb, (pos+i)%initCapacity, vI.intValue());
+ }
+ for(int i=0; i<growAmount; i++) {
+ final Integer vI = rb.get();
+ Assert.assertNotNull("Empty at read #"+(i+1)+": "+rb, vI);
+ Assert.assertEquals("Wrong value at read #"+(i+1)+": "+rb, 100+i, vI.intValue());
+ }
+
+ Assert.assertEquals("Not zero size "+rb, 0, rb.size());
+ Assert.assertTrue("Not empty "+rb, rb.isEmpty());
+ Assert.assertTrue("Is full "+rb, !rb.isFull());
+ }
+ @Test
+ public void test20_GrowFull01_Begin() {
+ test_GrowFullImpl(11, 0, false);
+ }
+ @Test
+ public void test21_GrowFull02_Begin1() {
+ test_GrowFullImpl(11, 0+1, false);
+ }
+ @Test
+ public void test22_GrowFull03_Begin2() {
+ test_GrowFullImpl(11, 0+2, false);
+ }
+ @Test
+ public void test23_GrowFull04_Begin3() {
+ test_GrowFullImpl(11, 0+3, false);
+ }
+ @Test
+ public void test24_GrowFull05_End() {
+ test_GrowFullImpl(11, 11-1, false);
+ }
+ @Test
+ public void test25_GrowFull11_End1() {
+ test_GrowFullImpl(11, 11-1-1, false);
+ }
+ @Test
+ public void test26_GrowFull12_End2() {
+ test_GrowFullImpl(11, 11-1-2, false);
+ }
+ @Test
+ public void test27_GrowFull13_End3() {
+ test_GrowFullImpl(11, 11-1-3, false);
+ }
+}
diff --git a/test/java/org/jau/util/TestArrayHashMap01.java b/test/java/org/jau/util/TestArrayHashMap01.java
new file mode 100644
index 0000000..cb5bf87
--- /dev/null
+++ b/test/java/org/jau/util/TestArrayHashMap01.java
@@ -0,0 +1,186 @@
+/**
+ * Author: Sven Gothel <[email protected]>
+ * Copyright (c) 2021 Gothel Software e.K.
+ * Copyright (c) 2015 Gothel Software e.K.
+ * Copyright (c) 2015 JogAmp Community.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+ * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+ * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+package org.jau.util;
+
+import java.io.IOException;
+import java.util.List;
+import java.util.Map;
+
+import org.jau.junit.util.SingletonJunitCase;
+import org.junit.Assert;
+import org.junit.FixMethodOrder;
+import org.junit.Test;
+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;
+ }
+
+ @Override
+ 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;
+ }
+
+ @Override
+ 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;
+ }
+
+ @Override
+ 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/test/java/org/jau/util/TestArrayHashSet01.java b/test/java/org/jau/util/TestArrayHashSet01.java
new file mode 100644
index 0000000..2e1eb76
--- /dev/null
+++ b/test/java/org/jau/util/TestArrayHashSet01.java
@@ -0,0 +1,206 @@
+/**
+ * Author: Sven Gothel <[email protected]>
+ * Copyright (c) 2021 Gothel Software e.K.
+ * Copyright (c) 2010 Gothel Software e.K.
+ * Copyright (c) 2010 JogAmp Community.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+ * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+ * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+package org.jau.util;
+
+import java.io.IOException;
+import java.util.List;
+
+import org.jau.junit.util.SingletonJunitCase;
+import org.junit.Assert;
+import org.junit.FixMethodOrder;
+import org.junit.Test;
+import org.junit.runners.MethodSorters;
+
+@FixMethodOrder(MethodSorters.NAME_ASCENDING)
+public class TestArrayHashSet01 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;
+ }
+
+ @Override
+ 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;
+ }
+
+ @Override
+ 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;
+ }
+
+ @Override
+ public String toString() {
+ return "Dummy["+super.toString()+": "+i1+", "+i2+", "+i3+"]";
+ }
+ }
+
+ 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();
+ 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 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_other);
+ Dummy q = l.get(i);
+ 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
+
+ // fast identity ..
+ q = l.get(p6_22_34_other);
+ 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.add(q)); // add same
+ Assert.assertTrue(!l.add(p6_22_34_other)); // add equivalent
+
+ q = l.getOrAdd(p6_22_34_other); // not added test 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
+ 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
+ Assert.assertNotNull(q);
+ 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 {
+ final String tstname = TestArrayHashSet01.class.getName();
+ org.junit.runner.JUnitCore.main(tstname);
+ }
+
+}
diff --git a/test/java/org/jau/util/TestIOUtil01.java b/test/java/org/jau/util/TestIOUtil01.java
new file mode 100644
index 0000000..489d01f
--- /dev/null
+++ b/test/java/org/jau/util/TestIOUtil01.java
@@ -0,0 +1,224 @@
+/**
+ * Author: Sven Gothel <[email protected]>
+ * Copyright (c) 2021 Gothel Software e.K.
+ * Copyright (c) 2010 Gothel Software e.K.
+ * Copyright (c) 2010 JogAmp Community.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+ * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+ * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+package org.jau.util;
+
+import java.io.BufferedInputStream;
+import java.io.BufferedOutputStream;
+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;
+import java.util.Arrays;
+
+import org.jau.io.IOUtil;
+import org.jau.junit.util.SingletonJunitCase;
+import org.jau.lang.ExceptionUtils;
+import org.jau.sys.MachineDataInfo;
+import org.jau.sys.PlatformProps;
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.FixMethodOrder;
+import org.junit.Test;
+import org.junit.runners.MethodSorters;
+
+@FixMethodOrder(MethodSorters.NAME_ASCENDING)
+public class TestIOUtil01 extends SingletonJunitCase {
+
+ static final MachineDataInfo machine = PlatformProps.MACH_DESC_STAT;
+ static final int tsz = machine.pageSizeInBytes() + machine.pageSizeInBytes() / 2 ;
+ static final byte[] orig = new byte[tsz];
+ static final String tfilename = "./test.bin" ;
+
+ @BeforeClass
+ public static void setup() throws IOException {
+ final File tfile = new File(tfilename);
+ tfile.deleteOnExit();
+ final OutputStream tout = new BufferedOutputStream(new FileOutputStream(tfile));
+ for(int i=0; i<tsz; i++) {
+ final byte b = (byte) (i%256);
+ orig[i] = b;
+ tout.write(b);
+ }
+ tout.close();
+ }
+
+ @AfterClass
+ public static void cleanup() {
+ final File tfile = new File(tfilename);
+ tfile.delete();
+ }
+
+ @Test
+ 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;
+ try {
+ bb = IOUtil.copyStream2ByteArray( bis );
+ } finally {
+ IOUtil.close(bis, false);
+ }
+ Assert.assertEquals("Byte number not equal orig vs array", orig.length, bb.length);
+ Assert.assertTrue("Bytes not equal orig vs array", Arrays.equals(orig, bb));
+
+ }
+
+ @Test
+ 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;
+ try {
+ bb = IOUtil.copyStream2ByteBuffer( bis );
+ } finally {
+ IOUtil.close(bis, false);
+ }
+ Assert.assertEquals("Byte number not equal orig vs buffer", orig.length, bb.limit());
+ int i;
+ for(i=tsz-1; i>=0 && orig[i]==bb.get(i); i--) ;
+ Assert.assertTrue("Bytes not equal orig vs array", 0>i);
+ }
+
+ @Test
+ public void test13CopyStream03Buffer() throws IOException {
+ final String tfilename2 = "./test2.bin" ;
+ 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(tfilename2, this.getClass().getClassLoader(), this.getClass());
+ Assert.assertNotNull(urlConn2);
+
+ final BufferedInputStream bis = new BufferedInputStream( urlConn2.getInputStream() );
+ final ByteBuffer bb;
+ try {
+ bb = IOUtil.copyStream2ByteBuffer( bis );
+ } finally {
+ IOUtil.close(bis, false);
+ }
+ Assert.assertEquals("Byte number not equal orig vs buffer", orig.length, bb.limit());
+ int i;
+ for(i=tsz-1; i>=0 && orig[i]==bb.get(i); i--) ;
+ Assert.assertTrue("Bytes not equal orig vs array", 0>i);
+ } finally {
+ file2.delete();
+ }
+ }
+
+ public static void main(final String args[]) throws IOException {
+ final String tstname = TestIOUtil01.class.getName();
+ org.junit.runner.JUnitCore.main(tstname);
+ }
+
+}
diff --git a/test/java/org/jau/util/TestJarUtil.java b/test/java/org/jau/util/TestJarUtil.java
new file mode 100644
index 0000000..3a3b5ae
--- /dev/null
+++ b/test/java/org/jau/util/TestJarUtil.java
@@ -0,0 +1,271 @@
+/**
+ * Author: Sven Gothel <[email protected]>
+ * Copyright (c) 2021 Gothel Software e.K.
+ * Copyright (c) 2011 Gothel Software e.K.
+ * Copyright (c) 2011 JogAmp Community.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+ * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+ * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+package org.jau.util;
+
+import java.io.IOException;
+import java.net.JarURLConnection;
+import java.net.MalformedURLException;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.net.URLConnection;
+import java.net.URLStreamHandler;
+import java.util.Enumeration;
+import java.util.jar.JarEntry;
+import java.util.jar.JarFile;
+
+import org.jau.junit.util.SingletonJunitCase;
+import org.jau.net.URIDumpUtil;
+import org.jau.net.Uri;
+import org.jau.pkg.JarUtil;
+import org.jau.pkg.cache.TempCacheReg;
+import org.jau.pkg.cache.TempFileCache;
+import org.jau.pkg.cache.TempJarCache;
+import org.jau.sys.AndroidVersion;
+import org.jau.sys.PlatformProps;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.FixMethodOrder;
+import org.junit.Test;
+import org.junit.runners.MethodSorters;
+
+@FixMethodOrder(MethodSorters.NAME_ASCENDING)
+public class TestJarUtil extends SingletonJunitCase {
+ static TempFileCache fileCache;
+
+ @BeforeClass
+ public static void init() {
+ if(AndroidVersion.isAvailable) {
+ // ClassLoader -> JarURL doesn't work w/ Dalvik
+ setTestSupported(false);
+ // we allow basic TempFileCache initialization (test) ..
+ }
+ // 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(false));
+ System.err.println("tmp dir: "+fileCache.getTempDir());
+ }
+
+ static class TestClassLoader extends URLClassLoader {
+ public TestClassLoader(final URL[] urls) {
+ super(urls);
+ }
+ public TestClassLoader(final URL[] urls, final ClassLoader parent) {
+ super(urls, parent);
+ }
+ }
+
+ void validateJarFile(final JarFile jarFile) throws IllegalArgumentException, IOException {
+ Assert.assertNotNull(jarFile);
+ Assert.assertTrue("jarFile has zero entries: "+jarFile, jarFile.size()>0);
+ final Enumeration<JarEntry> entries = jarFile.entries();
+ System.err.println("Entries of "+jarFile.getName()+": ");
+ int i = 0;
+ while(entries.hasMoreElements()) {
+ System.err.println(i+": "+entries.nextElement().getName());
+ i++;
+ }
+ }
+
+ void validateJarFileURL(final Uri jarFileURI) throws IllegalArgumentException, IOException, URISyntaxException {
+ Assert.assertNotNull(jarFileURI);
+ final URL jarFileURL = jarFileURI.toURL();
+ final URLConnection aURLc = jarFileURL.openConnection();
+ Assert.assertTrue("jarFileURI/URL has zero content: "+jarFileURL, aURLc.getContentLength()>0);
+ System.err.println("URLConnection: "+aURLc);
+ Assert.assertTrue("Not a JarURLConnection: "+aURLc, (aURLc instanceof JarURLConnection) );
+ final JarURLConnection jURLc = (JarURLConnection) aURLc;
+ final JarFile jarFile = jURLc.getJarFile();
+ validateJarFile(jarFile);
+ }
+
+ void validateJarUtil(final String expJarName, final String clazzBinName, final ClassLoader cl) throws IllegalArgumentException, IOException, URISyntaxException {
+ final Uri.Encoded expJarNameE = Uri.Encoded.cast(expJarName);
+ final Uri.Encoded jarName= JarUtil.getJarBasename(clazzBinName, cl);
+ Assert.assertNotNull(jarName);
+ Assert.assertEquals(expJarNameE, jarName);
+
+ final Uri jarUri = JarUtil.getJarUri(clazzBinName, cl);
+ Assert.assertNotNull(jarUri);
+ System.err.println("1 - jarUri:");
+ URIDumpUtil.showUri(jarUri);
+
+ final Uri jarSubUri = jarUri.getContainedUri();
+ Assert.assertNotNull(jarSubUri);
+ System.err.println("2 - jarSubUri:");
+ URIDumpUtil.showUri(jarSubUri);
+
+ final URL jarSubURL= jarSubUri.toURL();
+ final URLConnection urlConn = jarSubURL.openConnection();
+ Assert.assertTrue("jarSubURL has zero content: "+jarSubURL, urlConn.getContentLength()>0);
+ System.err.println("URLConnection of jarSubURL: "+urlConn);
+
+ final Uri jarFileURL = JarUtil.getJarFileUri(clazzBinName, cl);
+ validateJarFileURL(jarFileURL);
+
+ final JarFile jarFile = JarUtil.getJarFile(clazzBinName, cl);
+ validateJarFile(jarFile);
+ }
+
+ @Test
+ public void testJarUtilFlat01() throws IOException, IllegalArgumentException, URISyntaxException {
+ System.err.println("XXXXXXXXXXXXXXXXXXXXXXXXXXXX");
+ validateJarUtil("TestJarsInJar.jar", "ClassInJar0", this.getClass().getClassLoader());
+ System.err.println("XXXXXXXXXXXXXXXXXXXXXXXXXXXX");
+ }
+
+ @Test
+ public void testJarUtilJarInJar01() throws IOException, ClassNotFoundException, IllegalArgumentException, URISyntaxException {
+ System.err.println("XXXXXXXXXXXXXXXXXXXXXXXXXXXX");
+
+ Assert.assertTrue(TempJarCache.initSingleton());
+ Assert.assertTrue(TempCacheReg.isTempJarCacheUsed(false));
+ Assert.assertTrue(TempJarCache.isInitialized(false));
+
+ final ClassLoader rootCL = this.getClass().getClassLoader();
+
+ // Get containing JAR file "TestJarsInJar.jar" and add it to the TempJarCache
+ TempJarCache.addAll(PlatformProps.class, JarUtil.getJarFileUri("ClassInJar0", rootCL));
+
+ // Fetch and load the contained "ClassInJar1.jar"
+ final URL ClassInJar1_jarFileURL = JarUtil.getJarFileUri(TempJarCache.getResourceUri("ClassInJar1.jar")).toURL();
+ final ClassLoader cl = new URLClassLoader(new URL[] { ClassInJar1_jarFileURL }, rootCL);
+ 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(false));
+ Assert.assertTrue(TempJarCache.isInitialized(false));
+
+ final ClassLoader rootCL = this.getClass().getClassLoader();
+
+ // Get containing JAR file "TestJarsInJar.jar" and add it to the TempJarCache
+ TempJarCache.addAll(PlatformProps.class, JarUtil.getJarFileUri("ClassInJar0", rootCL));
+
+ // Fetch and load the contained "ClassInJar1.jar"
+ final URL ClassInJar2_jarFileURL = JarUtil.getJarFileUri(TempJarCache.getResourceUri("sub/ClassInJar2.jar")).toURL();
+ final ClassLoader cl = new URLClassLoader(new URL[] { ClassInJar2_jarFileURL }, rootCL);
+ 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
+ */
+ @Test
+ public void testJarUtilJarInJar03() throws IOException, ClassNotFoundException, IllegalArgumentException, URISyntaxException {
+ System.err.println("XXXXXXXXXXXXXXXXXXXXXXXXXXXX");
+
+ Assert.assertTrue(TempJarCache.initSingleton());
+ Assert.assertTrue(TempCacheReg.isTempJarCacheUsed(false));
+ Assert.assertTrue(TempJarCache.isInitialized(false));
+
+ /** This classloader mimics what OSGi's does -- it takes jar: URLs and makes them into bundleresource: URLs
+ * where the JAR is not directly accessible anymore. Here I leave the JAR name at the end of the URL so I can
+ * retrieve it later in the resolver, but OSGi obscures it completely and returns URLs like
+ * "bundleresource:4.fwk1990213994:1/Something.class" where the JAR name not present. */
+ class CustomClassLoader extends ClassLoader {
+ CustomClassLoader() {
+ super(TestJarUtil.this.getClass().getClassLoader());
+ }
+
+ /** Override normal method to return un-resolvable URL. */
+ @Override
+ public URL getResource(final String name) {
+ final URL url = super.getResource(name);
+ if(url == null)
+ return(null);
+ URL urlReturn = null;
+ try {
+ // numbers to mimic OSGi -- can be anything
+ urlReturn = new URL("bundleresource", "4.fwk1990213994", 1, url.getFile(),
+ new URLStreamHandler() {
+ @Override
+ protected URLConnection openConnection(final URL u) throws IOException {
+ return null;
+ }
+ });
+ } catch(final MalformedURLException e) {
+ // shouldn't happen, since I create the URL correctly above
+ Assert.assertTrue(false);
+ }
+ return urlReturn;
+ }
+ };
+
+ /* This resolver converts bundleresource: URLs back into jar: URLs. OSGi does this by consulting
+ * opaque bundle data inside its custom classloader to find the stored JAR path; we do it here
+ * by simply retrieving the JAR name from where we left it at the end of the URL. */
+ JarUtil.setResolver( new JarUtil.Resolver() {
+ @Override
+ public URL resolve( final URL url ) {
+ if( url.getProtocol().equals("bundleresource") ) {
+ try {
+ return new URL( Uri.JAR_SCHEME, "", url.getFile() );
+ } catch(final MalformedURLException e) {
+ return url;
+ }
+ } else {
+ return url;
+ }
+ }
+ } );
+
+ final ClassLoader rootCL = new CustomClassLoader();
+
+ // Get containing JAR file "TestJarsInJar.jar" and add it to the TempJarCache
+ TempJarCache.addAll(PlatformProps.class, JarUtil.getJarFileUri("ClassInJar0", rootCL));
+
+ // Fetch and load the contained "ClassInJar1.jar"
+ final URL ClassInJar2_jarFileURL = JarUtil.getJarFileUri(TempJarCache.getResourceUri("sub/ClassInJar2.jar")).toURL();
+ final ClassLoader cl = new URLClassLoader(new URL[] { ClassInJar2_jarFileURL }, rootCL);
+ Assert.assertNotNull(cl);
+ validateJarUtil("ClassInJar2.jar", "ClassInJar2", cl);
+ System.err.println("XXXXXXXXXXXXXXXXXXXXXXXXXXXX");
+ }
+
+ public static void main(final String args[]) throws IOException {
+ final String tstname = TestJarUtil.class.getName();
+ org.junit.runner.JUnitCore.main(tstname);
+ }
+
+}
diff --git a/test/java/org/jau/util/TestLFRingBuffer01.java b/test/java/org/jau/util/TestLFRingBuffer01.java
new file mode 100644
index 0000000..bc622e2
--- /dev/null
+++ b/test/java/org/jau/util/TestLFRingBuffer01.java
@@ -0,0 +1,49 @@
+/**
+ * Copyright 2013 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 org.jau.util;
+
+import org.junit.FixMethodOrder;
+import org.junit.runners.MethodSorters;
+
+@FixMethodOrder(MethodSorters.NAME_ASCENDING)
+public class TestLFRingBuffer01 extends RingBuffer01Base {
+ @Override
+ public Ringbuffer<Integer> createEmpty(final int initialCapacity) {
+ return new LFRingbuffer<Integer>(Integer[].class, initialCapacity);
+ }
+ @Override
+ public Ringbuffer<Integer> createFull(final Integer[] source) {
+ return new LFRingbuffer<Integer>(source);
+ }
+
+ public static void main(final String args[]) {
+ org.junit.runner.JUnitCore.main(TestLFRingBuffer01.class.getName());
+ }
+
+}
diff --git a/test/java/org/jau/util/TestPlatform01.java b/test/java/org/jau/util/TestPlatform01.java
new file mode 100644
index 0000000..cd30c81
--- /dev/null
+++ b/test/java/org/jau/util/TestPlatform01.java
@@ -0,0 +1,94 @@
+/**
+ * Copyright 2010 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 org.jau.util;
+
+import org.jau.junit.util.SingletonJunitCase;
+import org.jau.sys.MachineDataInfo;
+import org.jau.sys.PlatformProps;
+import org.junit.Assert;
+import org.junit.FixMethodOrder;
+import org.junit.Test;
+import org.junit.runners.MethodSorters;
+
+@FixMethodOrder(MethodSorters.NAME_ASCENDING)
+public class TestPlatform01 extends SingletonJunitCase {
+
+ @Test
+ public void testInfo00() {
+ System.err.println();
+ System.err.print(PlatformProps.NEWLINE);
+ System.err.println("OS name/type: "+PlatformProps.os_name+", "+PlatformProps.OS);
+ System.err.println("OS version: "+PlatformProps.os_version);
+ System.err.println();
+ System.err.println("Arch, CPU: "+PlatformProps.os_arch+", "+PlatformProps.CPU+"/"+PlatformProps.CPU.family);
+ System.err.println("OS/Arch: "+PlatformProps.os_and_arch);
+ System.err.println();
+ System.err.println("Java runtime: ");
+ System.err.println("Java version, vm: "+PlatformProps.JAVA_VERSION_NUMBER);
+ System.err.println();
+ System.err.println("MD.ST: "+PlatformProps.MACH_DESC_STAT);
+ System.err.println("MD.RT: "+PlatformProps.MACH_DESC_RT);
+ System.err.println();
+ System.err.println();
+ }
+
+ @Test
+ public void testPageSize01() {
+ final MachineDataInfo machine = PlatformProps.MACH_DESC_STAT;
+ final int ps = machine.pageSizeInBytes();
+ System.err.println("PageSize: "+ps);
+ Assert.assertTrue("PageSize is 0", 0 < ps );
+
+ final int ps_pages = machine.pageCount(ps);
+ Assert.assertTrue("PageNumber of PageSize is not 1, but "+ps_pages, 1 == ps_pages);
+
+ final int sz0 = ps - 10;
+ final int sz0_pages = machine.pageCount(sz0);
+ Assert.assertTrue("PageNumber of PageSize-10 is not 1, but "+sz0_pages, 1 == sz0_pages);
+
+ final int sz1 = ps + 10;
+ final int sz1_pages = machine.pageCount(sz1);
+ Assert.assertTrue("PageNumber of PageSize+10 is not 2, but "+sz1_pages, 2 == sz1_pages);
+
+ final int ps_psa = machine.pageAlignedSize(ps);
+ Assert.assertTrue("PageAlignedSize of PageSize is not PageSize, but "+ps_psa, ps == ps_psa);
+
+ final int sz0_psa = machine.pageAlignedSize(sz0);
+ Assert.assertTrue("PageAlignedSize of PageSize-10 is not PageSize, but "+sz0_psa, ps == sz0_psa);
+
+ final int sz1_psa = machine.pageAlignedSize(sz1);
+ Assert.assertTrue("PageAlignedSize of PageSize+10 is not 2*PageSize, but "+sz1_psa, ps*2 == sz1_psa);
+ }
+
+ public static void main(final String args[]) {
+ final String tstname = TestPlatform01.class.getName();
+ org.junit.runner.JUnitCore.main(tstname);
+ }
+
+}
diff --git a/test/java/org/jau/util/TestRunnableTask01.java b/test/java/org/jau/util/TestRunnableTask01.java
new file mode 100644
index 0000000..6c9344e
--- /dev/null
+++ b/test/java/org/jau/util/TestRunnableTask01.java
@@ -0,0 +1,111 @@
+/**
+ * Copyright 2011 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 org.jau.util;
+
+import java.io.IOException;
+import java.lang.reflect.InvocationTargetException;
+
+import org.jau.junit.util.SingletonJunitCase;
+import org.jau.lang.InterruptSource;
+import org.jau.util.parallel.RunnableTask;
+import org.junit.Assert;
+import org.junit.FixMethodOrder;
+import org.junit.Test;
+import org.junit.runners.MethodSorters;
+
+@FixMethodOrder(MethodSorters.NAME_ASCENDING)
+public class TestRunnableTask01 extends SingletonJunitCase {
+
+ @Test
+ public void testInvokeAndWait00() throws IOException, InterruptedException, InvocationTargetException {
+ final Object syncObject = new Object();
+ final boolean[] done = {false};
+ final Runnable clientAction = new Runnable() {
+ @Override
+ public void run() {
+ synchronized(syncObject) {
+ System.err.println("CA.1: "+syncObject);
+ done[ 0 ] = true;
+ System.err.println("CA.X");
+ syncObject.notifyAll();
+ }
+ }
+ };
+
+ System.err.println("BB.0: "+syncObject);
+ synchronized (syncObject) {
+ System.err.println("BB.1: "+syncObject);
+ new InterruptSource.Thread(null, clientAction, Thread.currentThread().getName()+"-clientAction").start();
+ try {
+ System.err.println("BB.2");
+ syncObject.wait();
+ System.err.println("BB.3");
+ } catch (final InterruptedException e) {
+ throw new RuntimeException(e);
+ }
+ Assert.assertTrue(done[0]);
+ System.err.println("BB.X");
+ }
+ }
+
+ @Test
+ public void testInvokeAndWait01() throws IOException, InterruptedException, InvocationTargetException {
+ final boolean[] done = {false};
+ final Runnable clientAction = new Runnable() {
+ @Override
+ public void run() {
+ System.err.println("CA.1");
+ done[ 0 ] = true;
+ System.err.println("CA.X");
+ }
+ };
+
+ final RunnableTask rTask = new RunnableTask(clientAction, new Object(), false, null);
+ System.err.println("BB.0: "+rTask.getSyncObject());
+ synchronized (rTask.getSyncObject()) {
+ System.err.println("BB.1: "+rTask.getSyncObject());
+ new InterruptSource.Thread(null, rTask, Thread.currentThread().getName()+"-clientAction").start();
+ try {
+ System.err.println("BB.2");
+ rTask.getSyncObject().wait();
+ System.err.println("BB.3");
+ } catch (final InterruptedException e) {
+ throw new RuntimeException(e);
+ }
+ Assert.assertTrue(done[0]);
+ System.err.println("BB.X");
+ }
+ }
+
+ public static void main(final String args[]) throws IOException {
+ final String tstname = TestRunnableTask01.class.getName();
+ org.junit.runner.JUnitCore.main(tstname);
+ }
+
+}
diff --git a/test/java/org/jau/util/TestSystemPropsAndEnvs.java b/test/java/org/jau/util/TestSystemPropsAndEnvs.java
new file mode 100644
index 0000000..5a07901
--- /dev/null
+++ b/test/java/org/jau/util/TestSystemPropsAndEnvs.java
@@ -0,0 +1,90 @@
+/**
+ * Copyright 2012 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 org.jau.util;
+
+import java.io.IOException;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Properties;
+
+import org.jau.junit.util.SingletonJunitCase;
+import org.junit.FixMethodOrder;
+import org.junit.Test;
+import org.junit.runners.MethodSorters;
+
+@FixMethodOrder(MethodSorters.NAME_ASCENDING)
+public class TestSystemPropsAndEnvs extends SingletonJunitCase {
+
+ @Test
+ public void dumpProperties() {
+ int i=0;
+ final Properties props = System.getProperties();
+ final Iterator<Map.Entry<Object,Object>> iter = props.entrySet().iterator();
+ while (iter.hasNext()) {
+ i++;
+ final Map.Entry<Object, Object> entry = iter.next();
+ System.out.format("%4d: %s = %s%n", i, entry.getKey(), entry.getValue());
+ }
+ System.out.println("Property count: "+i);
+ }
+
+ private static String[] suppress_envs = new String[] { "COOKIE", "SSH", "GPG" };
+
+ private static boolean contains(final String data, final String[] search) {
+ if(null != data && null != search) {
+ for(int i=0; i<search.length; i++) {
+ if(data.indexOf(search[i]) >= 0) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+ @Test
+ public void dumpEnvironment() {
+ int i=0;
+ final Map<String, String> env = System.getenv();
+ for (final String envName : env.keySet()) {
+ if(!contains(envName, suppress_envs)) {
+ i++;
+ System.out.format("%4d: %s = %s%n",
+ i, envName,
+ env.get(envName));
+ }
+ }
+ System.out.println("Environment count: "+i);
+ }
+
+ public static void main(final String args[]) throws IOException {
+ final String tstname = TestSystemPropsAndEnvs.class.getName();
+ org.junit.runner.JUnitCore.main(tstname);
+ }
+
+}
diff --git a/test/java/org/jau/util/TestTempJarCache.java b/test/java/org/jau/util/TestTempJarCache.java
new file mode 100644
index 0000000..5408f1c
--- /dev/null
+++ b/test/java/org/jau/util/TestTempJarCache.java
@@ -0,0 +1,273 @@
+/**
+ * Copyright 2011 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 org.jau.util;
+
+import java.io.File;
+import java.io.IOException;
+import java.lang.reflect.Method;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.util.jar.JarFile;
+
+import org.jau.io.IOUtil;
+import org.jau.junit.util.SingletonJunitCase;
+import org.jau.lang.ReflectionUtil;
+import org.jau.net.URIDumpUtil;
+import org.jau.net.Uri;
+import org.jau.pkg.JarUtil;
+import org.jau.pkg.cache.TempCacheReg;
+import org.jau.pkg.cache.TempFileCache;
+import org.jau.pkg.cache.TempJarCache;
+import org.jau.sys.AndroidVersion;
+import org.jau.sys.JNILibrary;
+import org.jau.sys.PlatformProps;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.FixMethodOrder;
+import org.junit.Test;
+import org.junit.runners.MethodSorters;
+
+@FixMethodOrder(MethodSorters.NAME_ASCENDING)
+public class TestTempJarCache extends SingletonJunitCase {
+ static TempFileCache fileCache;
+
+ static class TestClassLoader extends URLClassLoader {
+ public TestClassLoader(final URL[] urls) {
+ super(urls);
+ }
+ public TestClassLoader(final URL[] urls, final ClassLoader parent) {
+ super(urls, parent);
+ }
+ }
+
+ static void assertTempFileCachesIndividualInstances(final boolean shallBeSame, final TempFileCache fileCache2, final TempFileCache fileCache3) {
+ Assert.assertTrue(fileCache2.getTempDir().exists());
+ Assert.assertTrue(fileCache2.getTempDir().isDirectory());
+ Assert.assertTrue(fileCache3.getTempDir().exists());
+ Assert.assertTrue(fileCache3.getTempDir().isDirectory());
+
+ Assert.assertEquals(TempFileCache.getBaseDir(), TempFileCache.getBaseDir());
+ Assert.assertEquals(TempFileCache.getRootDir(), TempFileCache.getRootDir());
+
+ if(shallBeSame) {
+ Assert.assertTrue("file caches are not equal", fileCache2.getTempDir().equals(fileCache3.getTempDir()));
+ } else {
+ Assert.assertFalse("file caches are equal", fileCache2.getTempDir().equals(fileCache3.getTempDir()));
+ }
+ // also verify with diff classloader/reflection method,
+ // to proof that methodology is valid!
+ final ClassLoader cl = fileCache2.getClass().getClassLoader();
+ assertTempFileCachesIndividualInstances(shallBeSame, fileCache2, cl, fileCache3, cl);
+ }
+
+ static void assertTempFileCachesIndividualInstances(final boolean shallBeSame, final Object fileCache2, final ClassLoader cl2, final Object fileCache3, final ClassLoader cl3) {
+ final Class<?> fileCacheClazz2 = ReflectionUtil.getClass(TempFileCache.class.getName(), false, cl2);
+ final Class<?> fileCacheClazz3 = ReflectionUtil.getClass(TempFileCache.class.getName(), false, cl3);
+
+ final Method fc2GetBaseDir = ReflectionUtil.getMethod(fileCacheClazz2 , "getBaseDir");
+ final Method fc3GetBaseDir = ReflectionUtil.getMethod(fileCacheClazz3 , "getBaseDir");
+ final Object baseDir2 = ReflectionUtil.callMethod(fileCache2, fc2GetBaseDir);
+ final Object baseDir3 = ReflectionUtil.callMethod(fileCache3, fc3GetBaseDir);
+ Assert.assertEquals(baseDir2, baseDir3);
+
+ final Method fc2GetRootDir = ReflectionUtil.getMethod(fileCacheClazz2 , "getRootDir");
+ final Method fc3GetRootDir = ReflectionUtil.getMethod(fileCacheClazz3 , "getRootDir");
+ final Object rootDir2 = ReflectionUtil.callMethod(fileCache2, fc2GetRootDir);
+ final Object rootDir3 = ReflectionUtil.callMethod(fileCache3, fc3GetRootDir);
+ Assert.assertEquals(rootDir2, rootDir3);
+
+ final Method fc2GetTempDir = ReflectionUtil.getMethod(fileCacheClazz2 , "getTempDir");
+ final Method fc3GetTempDir = ReflectionUtil.getMethod(fileCacheClazz3 , "getTempDir");
+ final Object tempDir2 = ReflectionUtil.callMethod(fileCache2, fc2GetTempDir);
+ final 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(false));
+ 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 {
+ final TempFileCache fileCache2 = new TempFileCache();
+ final 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; }
+ final JarFile jarFile = JarUtil.getJarFile(PlatformProps.class.getName(), this.getClass().getClassLoader());
+ Assert.assertNotNull(jarFile);
+ JarUtil.extract(fileCache.getTempDir(), null, jarFile, null, false, true, true);
+ File f = new File(fileCache.getTempDir(), "META-INF/MANIFEST.MF");
+ Assert.assertTrue(f.exists());
+ f = new File(fileCache.getTempDir(), IOUtil.getClassFileName(PlatformProps.class.getName()));
+ Assert.assertTrue(f.exists());
+ }
+
+ @Test
+ public void testJarUtil01b() throws IOException {
+ if(AndroidVersion.isAvailable) { System.err.println("n/a on Android"); return; }
+ File f = new File(fileCache.getTempDir(), "META-INF/MANIFEST.MF");
+ Assert.assertTrue(f.exists());
+ f = new File(fileCache.getTempDir(), IOUtil.getClassFileName(PlatformProps.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.assertTrue(TempJarCache.initSingleton());
+ Assert.assertTrue(TempCacheReg.isTempJarCacheUsed(false));
+ Assert.assertTrue(TempJarCache.isInitialized(false));
+ }
+
+ @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(PlatformProps.class, JarUtil.getJarFileUri(PlatformProps.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(PlatformProps.class.getName()));
+ Assert.assertTrue(f0.exists());
+
+ f1 = new File(TempJarCache.findResource(IOUtil.getClassFileName(PlatformProps.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 Uri.Encoded nativeJarName = Uri.Encoded.cast("gluegen-rt-natives-"+PlatformProps.os_and_arch+".jar");
+ final String libBaseName = "gluegen_rt";
+ final ClassLoader cl = getClass().getClassLoader();
+
+ final Uri jarUri = JarUtil.getJarUri(TempJarCache.class.getName(), cl);
+ Assert.assertNotNull(jarUri);
+ System.err.println("1 - jarUri:");
+ URIDumpUtil.showUri(jarUri);
+
+ final Uri jarFileUri = jarUri.getContainedUri();
+ Assert.assertNotNull(jarFileUri);
+ System.err.println("2 - jarFileUri:");
+ URIDumpUtil.showUri(jarFileUri);
+
+ final Uri jarFileDir = jarFileUri.getParent();
+ Assert.assertNotNull(jarFileDir);
+ System.err.println("3 - jarFileDir:");
+ URIDumpUtil.showUri(jarFileDir);
+
+ final Uri nativeJarURI = JarUtil.getJarFileUri(jarFileDir, nativeJarName);
+ System.err.println("4 - nativeJarURI:");
+ URIDumpUtil.showUri(nativeJarURI);
+
+ TempJarCache.addNativeLibs(TempJarCache.class, nativeJarURI, null /* nativeLibraryPath */);
+ final String libFullPath = TempJarCache.findLibrary(libBaseName);
+ Assert.assertNotNull(libFullPath);
+ Assert.assertEquals(libBaseName, JNILibrary.isValidNativeLibraryName(libFullPath, true));
+ final File f = new File(libFullPath);
+ Assert.assertTrue(f.exists());
+ }
+
+ @Test
+ public void testTempJarCache04aSameClassLoader() throws IOException {
+ assertTempFileCachesIndividualInstances(true, TempJarCache.getTempFileCache(), TempJarCache.getTempFileCache());
+
+ final ClassLoader cl = getClass().getClassLoader();
+ final TempFileCache fileCache2 = (TempFileCache) ReflectionUtil.callStaticMethod(TempJarCache.class.getName(), "getTempFileCache", null, null, cl);
+ final 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; }
+ final URL[] urls = new URL[] { JarUtil.getJarFileUri(TempJarCache.class.getName(), getClass().getClassLoader()).toURL() };
+ System.err.println("url: "+urls[0]);
+ final ClassLoader cl2 = new TestClassLoader(urls, null);
+ final ClassLoader cl3 = new TestClassLoader(urls, null);
+
+ Assert.assertFalse(( (Boolean) ReflectionUtil.callStaticMethod(TempJarCache.class.getName(), "isInitialized", new Class<?>[] { Boolean.TYPE }, new Object[] { Boolean.FALSE }, cl2)
+ ).booleanValue());
+ Assert.assertFalse(( (Boolean) ReflectionUtil.callStaticMethod(TempJarCache.class.getName(), "isInitialized", new Class<?>[] { Boolean.TYPE }, new Object[] { Boolean.FALSE }, cl3)
+ ).booleanValue());
+ Assert.assertTrue(( (Boolean) ReflectionUtil.callStaticMethod(TempJarCache.class.getName(), "initSingleton", null, null, cl2)
+ ).booleanValue());
+ Assert.assertTrue(( (Boolean) ReflectionUtil.callStaticMethod(TempJarCache.class.getName(), "initSingleton", null, null, cl3)
+ ).booleanValue());
+ Assert.assertTrue(( (Boolean) ReflectionUtil.callStaticMethod(TempJarCache.class.getName(), "isInitialized", new Class<?>[] { Boolean.TYPE }, new Object[] { Boolean.FALSE }, cl2)
+ ).booleanValue());
+ Assert.assertTrue(( (Boolean) ReflectionUtil.callStaticMethod(TempJarCache.class.getName(), "isInitialized", new Class<?>[] { Boolean.TYPE }, new Object[] { Boolean.FALSE }, cl3)
+ ).booleanValue());
+
+ final Object fileCache2 = ReflectionUtil.callStaticMethod(TempJarCache.class.getName(), "getTempFileCache", null, null, cl2);
+ final Object fileCache3 = ReflectionUtil.callStaticMethod(TempJarCache.class.getName(), "getTempFileCache", null, null, cl3);
+
+ assertTempFileCachesIndividualInstances(false, fileCache2, cl2, fileCache3, cl3);
+ }
+
+ public static void main(final String args[]) throws IOException {
+ final String tstname = TestTempJarCache.class.getName();
+ org.junit.runner.JUnitCore.main(tstname);
+ }
+
+}
diff --git a/test/java/org/jau/util/TestValueConversion.java b/test/java/org/jau/util/TestValueConversion.java
new file mode 100644
index 0000000..ddcaa5f
--- /dev/null
+++ b/test/java/org/jau/util/TestValueConversion.java
@@ -0,0 +1,139 @@
+/**
+ * Copyright 2012 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 org.jau.util;
+
+import static org.jau.util.ValueConv.*;
+
+import org.junit.Assert;
+/**
+ * Testing ValueConv's value conversion of primitive types
+ */
+import org.junit.FixMethodOrder;
+import org.junit.Test;
+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), 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), 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), 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), 0.0);
+
+ Assert.assertEquals((short)0xffff, float_to_short( 1.0f, 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), 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), 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), 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), 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), 0.0);
+
+ Assert.assertEquals((short)0xffff, double_to_short( 1.0, 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), 0.0);
+ }
+
+ @Test
+ public void testConversion() {
+ final byte sb0 = 127;
+ final byte sb1 = -128;
+
+ final float sf0 = byte_to_float(sb0, true);
+ final float sf1 = byte_to_float(sb1, true);
+ final short ss0 = byte_to_short(sb0, true, true);
+ final short ss1 = byte_to_short(sb1, true, true);
+ final int si0 = byte_to_int(sb0, true, true);
+ final int si1 = byte_to_int(sb1, true, true);
+
+ 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));
+
+ final byte ub0 = (byte) 0xff;
+ final float uf0 = byte_to_float(ub0, false);
+ final short us0 = byte_to_short(ub0, false, false);
+ final int ui0 = byte_to_int(ub0, false, false);
+
+ 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(final String args[]) {
+ org.junit.runner.JUnitCore.main(TestValueConversion.class.getName());
+ }
+
+}
diff --git a/test/java/org/jau/util/TestVersionInfo.java b/test/java/org/jau/util/TestVersionInfo.java
new file mode 100644
index 0000000..79a4d5c
--- /dev/null
+++ b/test/java/org/jau/util/TestVersionInfo.java
@@ -0,0 +1,79 @@
+/**
+ * Copyright 2010 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 org.jau.util;
+
+import java.io.IOException;
+import java.net.URISyntaxException;
+import java.security.NoSuchAlgorithmException;
+
+import org.jau.base.JaulibVersion;
+import org.jau.junit.util.SingletonJunitCase;
+import org.jau.pkg.JaulibJarSHASum;
+import org.jau.sec.SHASum;
+import org.junit.Assert;
+import org.junit.FixMethodOrder;
+import org.junit.Test;
+import org.junit.runners.MethodSorters;
+
+@FixMethodOrder(MethodSorters.NAME_ASCENDING)
+public class TestVersionInfo extends SingletonJunitCase {
+ static boolean VERBOSE = false;
+
+ @Test
+ public void test01Info() {
+ System.err.println(VersionUtil.getPlatformInfo());
+ System.err.println("Version Info:");
+ System.err.println(JaulibVersion.getInstance());
+ System.err.println("");
+ System.err.println("Full Manifest:");
+ System.err.println(JaulibVersion.getInstance().getFullManifestInfo(null));
+ }
+
+ @Test
+ public void test02ValidateSHA()
+ throws IllegalArgumentException, IOException, URISyntaxException, SecurityException, NoSuchAlgorithmException
+ {
+ final JaulibVersion info = JaulibVersion.getInstance();
+ final String shaClassesThis = info.getImplementationSHAClassesThis();
+ System.err.println("SHA CLASSES.this (build-time): "+shaClassesThis);
+
+ final JaulibJarSHASum shaSum = new JaulibJarSHASum();
+ final byte[] shasum = shaSum.compute(VERBOSE);
+ final String shaClasses = SHASum.toHexString(shasum, null).toString();
+ System.err.println("SHA CLASSES.this (now): "+shaClasses);
+ Assert.assertEquals("SHA not equal", shaClassesThis, shaClasses);
+ }
+
+ public static void main(final String args[]) throws IOException {
+ // VERBOSE = true;
+ final String tstname = TestVersionInfo.class.getName();
+ org.junit.runner.JUnitCore.main(tstname);
+ }
+
+}
diff --git a/test/java/org/jau/util/TestVersionNumber.java b/test/java/org/jau/util/TestVersionNumber.java
new file mode 100644
index 0000000..353a1fe
--- /dev/null
+++ b/test/java/org/jau/util/TestVersionNumber.java
@@ -0,0 +1,301 @@
+/**
+ * Copyright 2012 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 org.jau.util;
+
+import java.io.IOException;
+
+import org.jau.junit.util.SingletonJunitCase;
+import org.junit.Assert;
+import org.junit.FixMethodOrder;
+import org.junit.Test;
+import org.junit.runners.MethodSorters;
+
+@FixMethodOrder(MethodSorters.NAME_ASCENDING)
+public class TestVersionNumber extends SingletonJunitCase {
+
+ @Test
+ public void test01() {
+ final String vs00 = "1.0.16";
+ final String vs01 = "OpenGL ES GLSL ES 1.0.16";
+ final String vs02 = "1.0.16 OpenGL ES GLSL ES";
+ final VersionNumber vn0 = new VersionNumber(1, 0, 16);
+ Assert.assertTrue(vn0.hasMajor());
+ Assert.assertTrue(vn0.hasMinor());
+ Assert.assertTrue(vn0.hasSub());
+
+ VersionNumber vn;
+
+ vn = new VersionNumber(vs00);
+ Assert.assertTrue(vn.hasMajor());
+ Assert.assertTrue(vn.hasMinor());
+ Assert.assertTrue(vn.hasSub());
+ Assert.assertEquals(vn0, vn);
+
+ vn = new VersionNumber(vs01);
+ Assert.assertTrue(vn.hasMajor());
+ Assert.assertTrue(vn.hasMinor());
+ Assert.assertTrue(vn.hasSub());
+ Assert.assertEquals(vn0, vn);
+
+ vn = new VersionNumber(vs02);
+ Assert.assertTrue(vn.hasMajor());
+ Assert.assertTrue(vn.hasMinor());
+ Assert.assertTrue(vn.hasSub());
+ Assert.assertEquals(vn0, vn);
+ }
+ @Test
+ public void test01b() {
+ final String delim = ",";
+
+ final String vs00 = "1,0,16";
+ final String vs01 = "OpenGL ES GLSL ES 1,0,16";
+ final String vs02 = "1,0,16 OpenGL ES GLSL ES";
+ final VersionNumber vn0 = new VersionNumber(1, 0, 16);
+ Assert.assertTrue(vn0.hasMajor());
+ Assert.assertTrue(vn0.hasMinor());
+ Assert.assertTrue(vn0.hasSub());
+
+ VersionNumber vn;
+
+ vn = new VersionNumber(vs00, delim);
+ Assert.assertTrue(vn.hasMajor());
+ Assert.assertTrue(vn.hasMinor());
+ Assert.assertTrue(vn.hasSub());
+ Assert.assertEquals(vn0, vn);
+
+ vn = new VersionNumber(vs01, delim);
+ Assert.assertTrue(vn.hasMajor());
+ Assert.assertTrue(vn.hasMinor());
+ Assert.assertTrue(vn.hasSub());
+ Assert.assertEquals(vn0, vn);
+
+ vn = new VersionNumber(vs02, delim);
+ Assert.assertTrue(vn.hasMajor());
+ Assert.assertTrue(vn.hasMinor());
+ Assert.assertTrue(vn.hasSub());
+ Assert.assertEquals(vn0, vn);
+ }
+
+ @Test
+ public void test02() {
+ final String vs00 = "4.20";
+ final String vs01 = "COMPANY via Stupid tool 4.20";
+ final String vs02 = "4.20 COMPANY via Stupid tool";
+ final VersionNumber vn0 = new VersionNumber(4, 20, 0);
+ Assert.assertTrue(vn0.hasMajor());
+ Assert.assertTrue(vn0.hasMinor());
+ Assert.assertTrue(vn0.hasSub());
+
+ VersionNumber vn;
+
+ vn = new VersionNumber(vs00);
+ Assert.assertTrue(vn.hasMajor());
+ Assert.assertTrue(vn.hasMinor());
+ Assert.assertTrue(!vn.hasSub());
+ Assert.assertEquals(vn0, vn);
+
+ vn = new VersionNumber(vs01);
+ Assert.assertTrue(vn.hasMajor());
+ Assert.assertTrue(vn.hasMinor());
+ Assert.assertTrue(!vn.hasSub());
+ Assert.assertEquals(vn0, vn);
+
+ vn = new VersionNumber(vs02);
+ Assert.assertTrue(vn.hasMajor());
+ Assert.assertTrue(vn.hasMinor());
+ Assert.assertTrue(!vn.hasSub());
+ Assert.assertEquals(vn0, vn);
+ }
+
+ @Test
+ public void test02b() {
+ final String delim = ",";
+
+ final String vs00 = "4,20";
+ final String vs01 = "COMPANY via Stupid tool 4,20";
+ final String vs02 = "4,20 COMPANY via Stupid tool";
+ final VersionNumber vn0 = new VersionNumber(4, 20, 0);
+ Assert.assertTrue(vn0.hasMajor());
+ Assert.assertTrue(vn0.hasMinor());
+ Assert.assertTrue(vn0.hasSub());
+
+ VersionNumber vn;
+
+ vn = new VersionNumber(vs00, delim);
+ Assert.assertTrue(vn.hasMajor());
+ Assert.assertTrue(vn.hasMinor());
+ Assert.assertTrue(!vn.hasSub());
+ Assert.assertEquals(vn0, vn);
+
+ vn = new VersionNumber(vs01, delim);
+ Assert.assertTrue(vn.hasMajor());
+ Assert.assertTrue(vn.hasMinor());
+ Assert.assertTrue(!vn.hasSub());
+ Assert.assertEquals(vn0, vn);
+
+ vn = new VersionNumber(vs02, delim);
+ Assert.assertTrue(vn.hasMajor());
+ Assert.assertTrue(vn.hasMinor());
+ Assert.assertTrue(!vn.hasSub());
+ Assert.assertEquals(vn0, vn);
+ }
+
+ @Test
+ public void test03() {
+ final String vs00 = "A10.11.12b";
+ final String vs01 = "Prelim Text 10.Funny11.Weird12 Something is odd";
+ final String vs02 = "Prelim Text 10.Funny11l1.Weird12 2 Something is odd";
+ final VersionNumber vn0 = new VersionNumber(10, 11, 12);
+ Assert.assertTrue(vn0.hasMajor());
+ Assert.assertTrue(vn0.hasMinor());
+ Assert.assertTrue(vn0.hasSub());
+
+ VersionNumber vn;
+
+ vn = new VersionNumber(vs00);
+ Assert.assertTrue(vn.hasMajor());
+ Assert.assertTrue(vn.hasMinor());
+ Assert.assertTrue(vn.hasSub());
+ Assert.assertEquals(vn0, vn);
+
+ vn = new VersionNumber(vs01);
+ Assert.assertTrue(vn.hasMajor());
+ Assert.assertTrue(vn.hasMinor());
+ Assert.assertTrue(vn.hasSub());
+ Assert.assertEquals(vn0, vn);
+
+ vn = new VersionNumber(vs02);
+ Assert.assertTrue(vn.hasMajor());
+ Assert.assertTrue(vn.hasMinor());
+ Assert.assertTrue(vn.hasSub());
+ Assert.assertEquals(vn0, vn);
+ }
+
+ @Test
+ public void test03b() {
+ final String delim = ",";
+
+ final String vs00 = "A10,11,12b";
+ final String vs01 = "Prelim Text 10,Funny11,Weird12 Something is odd";
+ final String vs02 = "Prelim Text 10,Funny11l1,Weird12 2 Something is odd";
+ final VersionNumber vn0 = new VersionNumber(10, 11, 12);
+ Assert.assertTrue(vn0.hasMajor());
+ Assert.assertTrue(vn0.hasMinor());
+ Assert.assertTrue(vn0.hasSub());
+
+ VersionNumber vn;
+
+ vn = new VersionNumber(vs00, delim);
+ Assert.assertTrue(vn.hasMajor());
+ Assert.assertTrue(vn.hasMinor());
+ Assert.assertTrue(vn.hasSub());
+ Assert.assertEquals(vn0, vn);
+
+ vn = new VersionNumber(vs01, delim);
+ Assert.assertTrue(vn.hasMajor());
+ Assert.assertTrue(vn.hasMinor());
+ Assert.assertTrue(vn.hasSub());
+ Assert.assertEquals(vn0, vn);
+
+ vn = new VersionNumber(vs02, delim);
+ Assert.assertTrue(vn.hasMajor());
+ Assert.assertTrue(vn.hasMinor());
+ Assert.assertTrue(vn.hasSub());
+ Assert.assertEquals(vn0, vn);
+ }
+
+ @Test
+ public void test04() {
+ final String vs00 = "A10.11.12b (git-d6c318e)";
+ final String vs01 = "Prelim Text 10.Funny11.Weird12 Something is odd (git-d6c318e)";
+ final String vs02 = "Prelim Text 10.Funny11l1.Weird12 2 Something is odd (git-d6c318e)";
+ final VersionNumber vn0 = new VersionNumber(10, 11, 12);
+ Assert.assertTrue(vn0.hasMajor());
+ Assert.assertTrue(vn0.hasMinor());
+ Assert.assertTrue(vn0.hasSub());
+
+ VersionNumber vn;
+
+ vn = new VersionNumber(vs00);
+ Assert.assertTrue(vn.hasMajor());
+ Assert.assertTrue(vn.hasMinor());
+ Assert.assertTrue(vn.hasSub());
+ Assert.assertEquals(vn0, vn);
+
+ vn = new VersionNumber(vs01);
+ Assert.assertTrue(vn.hasMajor());
+ Assert.assertTrue(vn.hasMinor());
+ Assert.assertTrue(vn.hasSub());
+ Assert.assertEquals(vn0, vn);
+
+ vn = new VersionNumber(vs02);
+ Assert.assertTrue(vn.hasMajor());
+ Assert.assertTrue(vn.hasMinor());
+ Assert.assertTrue(vn.hasSub());
+ Assert.assertEquals(vn0, vn);
+ }
+ @Test
+ public void test04b() {
+ final String delim = ",";
+
+ final String vs00 = "A10,11,12b (git-d6c318e)";
+ final String vs01 = "Prelim Text 10,Funny11,Weird12 Something is odd (git-d6c318e)";
+ final String vs02 = "Prelim Text 10,Funny11l1,Weird12 2 Something is odd (git-d6c318e)";
+ final VersionNumber vn0 = new VersionNumber(10, 11, 12);
+ Assert.assertTrue(vn0.hasMajor());
+ Assert.assertTrue(vn0.hasMinor());
+ Assert.assertTrue(vn0.hasSub());
+
+ VersionNumber vn;
+
+ vn = new VersionNumber(vs00, delim);
+ Assert.assertTrue(vn.hasMajor());
+ Assert.assertTrue(vn.hasMinor());
+ Assert.assertTrue(vn.hasSub());
+ Assert.assertEquals(vn0, vn);
+
+ vn = new VersionNumber(vs01, delim);
+ Assert.assertTrue(vn.hasMajor());
+ Assert.assertTrue(vn.hasMinor());
+ Assert.assertTrue(vn.hasSub());
+ Assert.assertEquals(vn0, vn);
+
+ vn = new VersionNumber(vs02, delim);
+ Assert.assertTrue(vn.hasMajor());
+ Assert.assertTrue(vn.hasMinor());
+ Assert.assertTrue(vn.hasSub());
+ Assert.assertEquals(vn0, vn);
+ }
+
+ public static void main(final String args[]) throws IOException {
+ final String tstname = TestVersionNumber.class.getName();
+ org.junit.runner.JUnitCore.main(tstname);
+ }
+
+}