summaryrefslogtreecommitdiffstats
path: root/src/junit/com/jogamp/common/util
diff options
context:
space:
mode:
Diffstat (limited to 'src/junit/com/jogamp/common/util')
-rw-r--r--src/junit/com/jogamp/common/util/RingBuffer01Base.java30
-rw-r--r--src/junit/com/jogamp/common/util/TestLFRingBuffer01.java10
-rw-r--r--src/junit/com/jogamp/common/util/TestSyncRingBuffer01.java11
3 files changed, 19 insertions, 32 deletions
diff --git a/src/junit/com/jogamp/common/util/RingBuffer01Base.java b/src/junit/com/jogamp/common/util/RingBuffer01Base.java
index 7ac94d4..f7e8fcf 100644
--- a/src/junit/com/jogamp/common/util/RingBuffer01Base.java
+++ b/src/junit/com/jogamp/common/util/RingBuffer01Base.java
@@ -36,7 +36,7 @@ import com.jogamp.common.util.Ringbuffer;
public abstract class RingBuffer01Base {
private static boolean DEBUG = false;
-
+
public abstract Ringbuffer<Integer> createEmpty(int initialCapacity);
public abstract Ringbuffer<Integer> createFull(Integer[] source);
@@ -75,7 +75,7 @@ public abstract class RingBuffer01Base {
Assert.assertTrue("Is full "+rb, !rb.isFull());
for(int i=0; i<len; i++) {
- rb.put( Integer.valueOf(startValue+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());
@@ -225,13 +225,6 @@ public abstract class RingBuffer01Base {
Assert.assertTrue("Not empty "+rb, rb.isEmpty());
}
- private static Ringbuffer.AllocEmptyArray<Integer> rbAllocIntArray = new Ringbuffer.AllocEmptyArray<Integer>() {
- @Override
- public Integer[] newArray(int size) {
- return new Integer[size];
- }
- };
-
private void test_GrowEmptyImpl(int initCapacity, int pos) {
final int growAmount = 5;
final int grownCapacity = initCapacity+growAmount;
@@ -248,7 +241,7 @@ public abstract class RingBuffer01Base {
if( DEBUG ) {
rb.dump(System.err, "GrowEmpty["+pos+"].pre1");
}
- rb.growBuffer(growArray, growAmount, rbAllocIntArray);
+ rb.growEmptyBuffer(growArray);
if( DEBUG ) {
rb.dump(System.err, "GrowEmpty["+pos+"].post");
}
@@ -288,10 +281,6 @@ public abstract class RingBuffer01Base {
private void test_GrowFullImpl(int initCapacity, int pos, boolean debug) {
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 Integer[] source = createIntArray(initCapacity, 0);
final Ringbuffer<Integer> rb = createFull(source);
@@ -302,7 +291,7 @@ public abstract class RingBuffer01Base {
if( DEBUG || debug ) {
rb.dump(System.err, "GrowFull["+pos+"].pre1");
}
- rb.growBuffer(growArray, growAmount, rbAllocIntArray);
+ rb.growFullBuffer(growAmount);
if( DEBUG || debug ) {
rb.dump(System.err, "GrowFull["+pos+"].post");
}
@@ -312,11 +301,22 @@ public abstract class RingBuffer01Base {
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++) {
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++) {
+ 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());
diff --git a/src/junit/com/jogamp/common/util/TestLFRingBuffer01.java b/src/junit/com/jogamp/common/util/TestLFRingBuffer01.java
index 52e433d..bcfeb11 100644
--- a/src/junit/com/jogamp/common/util/TestLFRingBuffer01.java
+++ b/src/junit/com/jogamp/common/util/TestLFRingBuffer01.java
@@ -32,17 +32,11 @@ import com.jogamp.common.util.LFRingbuffer;
import com.jogamp.common.util.Ringbuffer;
public class TestLFRingBuffer01 extends RingBuffer01Base {
- static final Ringbuffer.AllocEmptyArray<Integer> allocEmptyIntArray = new Ringbuffer.AllocEmptyArray<Integer>() {
- @Override
- public Integer[] newArray(int size) {
- return new Integer[size];
- } };
-
public Ringbuffer<Integer> createEmpty(int initialCapacity) {
- return new LFRingbuffer<Integer>(initialCapacity, allocEmptyIntArray);
+ return new LFRingbuffer<Integer>(Integer[].class, initialCapacity);
}
public Ringbuffer<Integer> createFull(Integer[] source) {
- return new LFRingbuffer<Integer>(source, allocEmptyIntArray);
+ return new LFRingbuffer<Integer>(source);
}
public static void main(String args[]) {
diff --git a/src/junit/com/jogamp/common/util/TestSyncRingBuffer01.java b/src/junit/com/jogamp/common/util/TestSyncRingBuffer01.java
index bc9284b..b598f15 100644
--- a/src/junit/com/jogamp/common/util/TestSyncRingBuffer01.java
+++ b/src/junit/com/jogamp/common/util/TestSyncRingBuffer01.java
@@ -32,18 +32,11 @@ import com.jogamp.common.util.Ringbuffer;
import com.jogamp.common.util.SyncedRingbuffer;
public class TestSyncRingBuffer01 extends RingBuffer01Base {
-
- static final Ringbuffer.AllocEmptyArray<Integer> allocEmptyIntArray = new Ringbuffer.AllocEmptyArray<Integer>() {
- @Override
- public Integer[] newArray(int size) {
- return new Integer[size];
- } };
-
public Ringbuffer<Integer> createEmpty(int initialCapacity) {
- return new SyncedRingbuffer<Integer>(initialCapacity, allocEmptyIntArray);
+ return new SyncedRingbuffer<Integer>(Integer[].class, initialCapacity);
}
public Ringbuffer<Integer> createFull(Integer[] source) {
- return new SyncedRingbuffer<Integer>(source, allocEmptyIntArray);
+ return new SyncedRingbuffer<Integer>(source);
}
public static void main(String args[]) {