Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael P. Masterson2010-09-29 19:26:20 -0400
committerRyan D. Brooks2010-09-29 19:26:20 -0400
commitc24bedcf5269da35404b92dd033ef4c29ee08796 (patch)
treeb278fb680299e1d3b193def3b6dab2c15522ec77 /plugins
parentce90c86c8968f671825f8ac40da91fdc8bf4814f (diff)
downloadorg.eclipse.osee-c24bedcf5269da35404b92dd033ef4c29ee08796.tar.gz
org.eclipse.osee-c24bedcf5269da35404b92dd033ef4c29ee08796.tar.xz
org.eclipse.osee-c24bedcf5269da35404b92dd033ef4c29ee08796.zip
bug[bgz_326615]: Add illegal argument handling in RecordMap
Adding exception for out of range gets. An IllegalArgumentException was added for out of range gets for RecordArray elements. I also added some junit tests for what was added. Provided via patch from A.Jury.
Diffstat (limited to 'plugins')
-rw-r--r--plugins/org.eclipse.osee.ote.message.test/src/org/eclipse/osee/ote/message/test/mock/TestMessage.java30
-rw-r--r--plugins/org.eclipse.osee.ote.message.test/src/org/eclipse/osee/ote/message/test/recordMap/RecordMapTest.java42
-rw-r--r--plugins/org.eclipse.osee.ote.message/src/org/eclipse/osee/ote/message/elements/RecordMap.java5
3 files changed, 76 insertions, 1 deletions
diff --git a/plugins/org.eclipse.osee.ote.message.test/src/org/eclipse/osee/ote/message/test/mock/TestMessage.java b/plugins/org.eclipse.osee.ote.message.test/src/org/eclipse/osee/ote/message/test/mock/TestMessage.java
index e405675423..36a5c2cb5c 100644
--- a/plugins/org.eclipse.osee.ote.message.test/src/org/eclipse/osee/ote/message/test/mock/TestMessage.java
+++ b/plugins/org.eclipse.osee.ote.message.test/src/org/eclipse/osee/ote/message/test/mock/TestMessage.java
@@ -12,9 +12,13 @@ package org.eclipse.osee.ote.message.test.mock;
import java.util.Collection;
import org.eclipse.osee.ote.message.Message;
+import org.eclipse.osee.ote.message.data.MessageData;
import org.eclipse.osee.ote.message.elements.EnumeratedElement;
import org.eclipse.osee.ote.message.elements.Float32Element;
+import org.eclipse.osee.ote.message.elements.IRecordFactory;
import org.eclipse.osee.ote.message.elements.IntegerElement;
+import org.eclipse.osee.ote.message.elements.RecordElement;
+import org.eclipse.osee.ote.message.elements.RecordMap;
import org.eclipse.osee.ote.message.elements.StringElement;
import org.eclipse.osee.ote.message.test.TestMemType;
@@ -24,6 +28,7 @@ public class TestMessage extends Message<UnitTestAccessor, TestMessageData, Test
public final StringElement STRING_ELEMENT_1;
public final EnumeratedElement<TestEnum> ENUM_ELEMENT_1;
public final Float32Element FLOAT32_ELEMENT_1;
+ public final RecordMap<TestRecordElement> RECORD_MAP_1;
public TestMessage() {
super("TEST_MSG", 100, 0, true, 0, 50.0);
@@ -37,7 +42,9 @@ public class TestMessage extends Message<UnitTestAccessor, TestMessageData, Test
STRING_ELEMENT_1 = new StringElement(this, "STRING_ELEMENT_1", ethData, 2, 0, 159);
ENUM_ELEMENT_1 = new EnumeratedElement<TestEnum>(this, "ENUM_ELEMENT_1", TestEnum.class, ethData, 22, 0, 7);
FLOAT32_ELEMENT_1 = new Float32Element(this, "FLOAT32_ELEMENT_1", ethData, 23, 0, 31);
- addElements(INT_ELEMENT_1, STRING_ELEMENT_1, ENUM_ELEMENT_1, FLOAT32_ELEMENT_1);
+ RECORD_MAP_1 =
+ new RecordMap<TestRecordElement>(this, ethData, "RECORD_MAP_1", 2, new RECORD_MAP_1_factory(ethData));
+ addElements(INT_ELEMENT_1, STRING_ELEMENT_1, ENUM_ELEMENT_1, FLOAT32_ELEMENT_1, RECORD_MAP_1);
setMemSource(TestMemType.ETHERNET);
}
@@ -46,4 +53,25 @@ public class TestMessage extends Message<UnitTestAccessor, TestMessageData, Test
}
+ public class RECORD_MAP_1_factory implements IRecordFactory {
+ private final MessageData data;
+
+ public RECORD_MAP_1_factory(MessageData data) {
+ this.data = data;
+ }
+
+ @Override
+ public RecordElement create(int i) {
+ TestRecordElement temp =
+ new TestRecordElement(TestMessage.this, "RECORD_MAP_1", i, getBitOffset() + 0, this.data);
+ temp.addPath(RECORD_MAP_1.getElementPath().toArray());
+ return temp;
+ }
+
+ @Override
+ public int getBitLength() {
+ return 512;
+ }
+
+ }
}
diff --git a/plugins/org.eclipse.osee.ote.message.test/src/org/eclipse/osee/ote/message/test/recordMap/RecordMapTest.java b/plugins/org.eclipse.osee.ote.message.test/src/org/eclipse/osee/ote/message/test/recordMap/RecordMapTest.java
new file mode 100644
index 0000000000..b977439c0a
--- /dev/null
+++ b/plugins/org.eclipse.osee.ote.message.test/src/org/eclipse/osee/ote/message/test/recordMap/RecordMapTest.java
@@ -0,0 +1,42 @@
+/*
+ * Created on Sep 29, 2010
+ *
+ * PLACE_YOUR_DISTRIBUTION_STATEMENT_RIGHT_HERE
+ */
+package org.eclipse.osee.ote.message.test.recordMap;
+
+import junit.framework.Assert;
+import org.eclipse.osee.ote.message.test.mock.TestMessage;
+import org.junit.Test;
+
+public class RecordMapTest {
+
+ @Test
+ public void testGetInt() {
+ TestMessage msg = new TestMessage();
+
+ // Testing below the boundary.
+ try {
+ msg.RECORD_MAP_1.get(1);
+ Assert.assertTrue(true);
+ } catch (IllegalArgumentException ex) {
+ Assert.fail("We shouldn't get an exception for this get!");
+ }
+
+ // Testing on the boundary.
+ try {
+ msg.RECORD_MAP_1.get(2);
+ Assert.fail("We should get an exception for this get on the boundary!");
+ } catch (IllegalArgumentException ex) {
+ Assert.assertTrue("We should get an exception for this index", true);
+ }
+ // Testing above the boundary.
+ try {
+ msg.RECORD_MAP_1.get(3);
+ Assert.fail("We should get an exception for this get above the boundary!");
+ } catch (IllegalArgumentException ex) {
+ Assert.assertTrue("We should get an exception for this index", true);
+ }
+
+ }
+}
diff --git a/plugins/org.eclipse.osee.ote.message/src/org/eclipse/osee/ote/message/elements/RecordMap.java b/plugins/org.eclipse.osee.ote.message/src/org/eclipse/osee/ote/message/elements/RecordMap.java
index 683c7879a3..8994c0f1ce 100644
--- a/plugins/org.eclipse.osee.ote.message/src/org/eclipse/osee/ote/message/elements/RecordMap.java
+++ b/plugins/org.eclipse.osee.ote.message/src/org/eclipse/osee/ote/message/elements/RecordMap.java
@@ -41,6 +41,11 @@ public class RecordMap<T extends RecordElement> extends RecordElement {
@Override
public T get(int index) {
+ if (index >= NUMBER_OF_RECORDS) {
+ throw new IllegalArgumentException(
+ "index(zero-based):" + index + " is greater than NUMBER_OF_RECORDS:" + NUMBER_OF_RECORDS);
+ }
+
T val = records.get(index);
if (val == null) {
val = (T) factory.create(index);

Back to the top