aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorPhil Burk <[email protected]>2016-11-27 13:39:42 -0800
committerPhil Burk <[email protected]>2016-11-27 13:39:42 -0800
commitff5e1fb0794cc65c32a7d9f51d03eba841eba4ad (patch)
treed85f0687742a8865ba12ce21c1ac4c95ab9de1b1 /tests
parenta6583e89166f7477a675cf3094a91b303ba7850a (diff)
Check for bounds when sample or envelope data is queued.
Add unit test. Fix: #15
Diffstat (limited to 'tests')
-rw-r--r--tests/com/jsyn/ports/TestQueuedDataPort.java39
1 files changed, 36 insertions, 3 deletions
diff --git a/tests/com/jsyn/ports/TestQueuedDataPort.java b/tests/com/jsyn/ports/TestQueuedDataPort.java
index 8c4714b..e229038 100644
--- a/tests/com/jsyn/ports/TestQueuedDataPort.java
+++ b/tests/com/jsyn/ports/TestQueuedDataPort.java
@@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -27,7 +27,7 @@ import com.jsyn.unitgen.FixedRateMonoReader;
/**
* Test sample and envelope queuing and looping.
- *
+ *
* @author Phil Burk, (C) 2009 Mobileer Inc
*/
public class TestQueuedDataPort extends TestCase {
@@ -96,6 +96,39 @@ public class TestQueuedDataPort extends TestCase {
assertEquals("end empty", false, dataQueue.hasMore());
}
+ public void testQueueOutOfBounds() {
+ float[] data = {
+ 0.4f, 1.9f, 22.7f
+ };
+ FloatSample sample = new FloatSample(data.length, 1);
+ sample.write(data);
+
+ UnitDataQueuePort dataQueue = new UnitDataQueuePort("test");
+ boolean caught = false;
+ try {
+ queueDirect(dataQueue, sample, 0, sample.getNumFrames() + 1); // should cause an error!
+ } catch(IllegalArgumentException e) {
+ caught = true;
+ }
+ assertTrue("expect exception when we go past end of the array", caught);
+
+ caught = false;
+ try {
+ queueDirect(dataQueue, sample, 1, sample.getNumFrames()); // should cause an error!
+ } catch(IllegalArgumentException e) {
+ caught = true;
+ }
+ assertTrue("expect exception when we go past end of the array", caught);
+
+ caught = false;
+ try {
+ queueDirect(dataQueue, sample, -1, sample.getNumFrames()); // should cause an error!
+ } catch(IllegalArgumentException e) {
+ caught = true;
+ }
+ assertTrue("expect exception when we start before beginning of the array", caught);
+ }
+
public void testQueueMultiple() {
short[] data = {
234, 17777, -9876, 4567, -14287