diff --git a/src/test/java/ca/mjdsystems/jmatio/test/MatlabMCOSTest.java b/src/test/java/ca/mjdsystems/jmatio/test/MatlabMCOSTest.java index 356a258eabc81cb64926988b98d03075462d3c1c..febc8fb2d6e85eddb1f45e1e9e0ceaf5761fa4c0 100644 --- a/src/test/java/ca/mjdsystems/jmatio/test/MatlabMCOSTest.java +++ b/src/test/java/ca/mjdsystems/jmatio/test/MatlabMCOSTest.java @@ -6,6 +6,7 @@ package ca.mjdsystems.jmatio.test; import ca.mjdsystems.jmatio.io.MatFileReader; import ca.mjdsystems.jmatio.types.MLArray; import ca.mjdsystems.jmatio.types.MLChar; +import ca.mjdsystems.jmatio.types.MLInt8; import ca.mjdsystems.jmatio.types.MLObject; import org.junit.Rule; import org.junit.Test; @@ -19,6 +20,7 @@ import java.util.Map; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.notNullValue; +import static org.hamcrest.CoreMatchers.sameInstance; import static org.junit.Assert.assertThat; /** @@ -147,6 +149,79 @@ public class MatlabMCOSTest { assertThat(obj.getObject().getFieldNames().iterator().next(), is("test_text")); } + @Test + public void testParsingHandleSinglePropertyMultipleMCOS() throws IOException + { + File file = fileFromStream("/mcos/handlesingle_multiple.mat"); + MatFileReader reader = new MatFileReader(file); + Map content = reader.getContent(); + + assertThat(content.size(), is(4)); + + MLObject obj = (MLObject) content.get("obj1"); + assertThat(obj, is(notNullValue())); + + assertThat(obj.getName(), is("obj1")); + assertThat(obj.getClassName(), is("HandleSingle")); + assertThat(((MLObject) content.get("obj3")).getObject(), is(sameInstance(obj.getObject()))); + Collection fields = obj.getObject().getAllFields(); + assertThat(fields.size(), is(1)); + + MLInt8 intField = (MLInt8) fields.toArray()[0]; + assertThat(intField.getSize(), is(1)); + assertThat(intField.get(0).byteValue(), is((byte)25)); + + assertThat(obj.getObject().getFieldNames().iterator().next(), is("myelement")); + + + obj = (MLObject) content.get("obj3"); + assertThat(obj, is(notNullValue())); + + assertThat(obj.getName(), is("obj3")); + assertThat(obj.getClassName(), is("HandleSingle")); + assertThat(((MLObject) content.get("obj1")).getObject(), is(sameInstance(obj.getObject()))); + fields = obj.getObject().getAllFields(); + assertThat(fields.size(), is(1)); + + intField = (MLInt8) fields.toArray()[0]; + assertThat(intField.getSize(), is(1)); + assertThat(intField.get(0).byteValue(), is((byte)25)); + + assertThat(obj.getObject().getFieldNames().iterator().next(), is("myelement")); + + + + + obj = (MLObject) content.get("obj2"); + assertThat(obj, is(notNullValue())); + + assertThat(obj.getName(), is("obj2")); + assertThat(obj.getClassName(), is("HandleSingle")); + assertThat(((MLObject) content.get("obj4")).getObject(), is(sameInstance(obj.getObject()))); + fields = obj.getObject().getAllFields(); + assertThat(fields.size(), is(1)); + + MLChar charField = (MLChar) fields.toArray()[0]; + assertThat(charField.getString(0), is("testing")); + + assertThat(obj.getObject().getFieldNames().iterator().next(), is("myelement")); + + + obj = (MLObject) content.get("obj4"); + assertThat(obj, is(notNullValue())); + + assertThat(obj.getName(), is("obj4")); + assertThat(obj.getClassName(), is("HandleSingle")); + assertThat(((MLObject) content.get("obj2")).getObject(), is(sameInstance(obj.getObject()))); + fields = obj.getObject().getAllFields(); + assertThat(fields.size(), is(1)); + + charField = (MLChar) fields.toArray()[0]; + assertThat(charField.getString(0), is("testing")); + + assertThat(obj.getObject().getFieldNames().iterator().next(), is("myelement")); + } + private File fileFromStream(String location) throws IOException { String outname = location.replace("/", "_"); diff --git a/src/test/resources/mcos/handlesingle_multiple.mat b/src/test/resources/mcos/handlesingle_multiple.mat new file mode 100644 index 0000000000000000000000000000000000000000..e9316c6c59eef689cb6db00fd6e943c62919af2f Binary files /dev/null and b/src/test/resources/mcos/handlesingle_multiple.mat differ