Skip to content

Commit

Permalink
- added unit test to demonstrate the bug
Browse files Browse the repository at this point in the history
  • Loading branch information
johnmay authored and egonw committed Nov 6, 2012
1 parent 0ea90e8 commit a6d3d6e
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/test/data/cml/(1R)-1-aminoethan-1-ol-malformedDictRef.cml
@@ -0,0 +1,30 @@
<?xml version="1.0" ?>
<cml>
<MDocument>
<MChemicalStruct>
<!-- A very simple molecule to test bug 1275
- when dictRef is incomplete it should not throw an exception
-->
<molecule molID="m1">
<atomArray>
<atom id="a1" elementType="C"
x2="-1.3200000524520874" y2="-1.815000057220459"/>
<atom id="a2" elementType="N"
x2="0.013679069375948316" y2="-2.585000057220459"/>
<atom id="a3" elementType="C"
x2="-2.6536791742801227" y2="-2.5850000572204594"/>
<atom id="a4" elementType="O"
x2="-1.3200000524520874" y2="-0.27500005722045895"/>
</atomArray>
<bondArray>
<bond atomRefs2="a1 a2" order="1"/>
<bond atomRefs2="a1 a4" order="1">
<!-- the dictRef is incomplete and should not be used -->
<bondStereo dictRef="cml:">W</bondStereo>
</bond>
<bond atomRefs2="a1 a3" order="1"/>
</bondArray>
</molecule>
</MChemicalStruct>
</MDocument>
</cml>
40 changes: 40 additions & 0 deletions src/test/org/openscience/cdk/io/CMLReaderTest.java
Expand Up @@ -188,4 +188,44 @@ public void testBug1274() throws CDKException, IOException {
}
}

/**
* Ensures that {@code <bondStereo dictRef="cml:"/>} doesn't cause an exception
*
* @cdk.bug 1275
*/
@Test
public void testBug1275() throws CDKException, IOException {

InputStream in = getClass().getResourceAsStream("/data/cml/(1R)-1-aminoethan-1-ol-malformedDictRef.cml");
CMLReader reader = new CMLReader(in);
try {
IChemFile cfile = reader.read(DefaultChemObjectBuilder.getInstance().newInstance(IChemFile.class));


Assert.assertNotNull("ChemFile was null", cfile);

List<IAtomContainer> containers = ChemFileManipulator.getAllAtomContainers(cfile);

Assert.assertEquals("expected a single atom container", 1, containers.size());

IAtomContainer container = containers.get(0);

Assert.assertNotNull("null atom container read", container);

// we check here that the malformed dictRef doesn't throw an exception
Assert.assertEquals("expected non-stereo bond",
IBond.Stereo.NONE, container.getBond(0).getStereo());
Assert.assertEquals("expected Wedge (Up) Bond",
IBond.Stereo.UP, container.getBond(1).getStereo());
Assert.assertEquals("expected non-stereo bond",
IBond.Stereo.NONE, container.getBond(2).getStereo());

} finally {
reader.close();
}

}



}

0 comments on commit a6d3d6e

Please sign in to comment.