Skip to content

Commit

Permalink
Adding Infinity Value Test (googleapis#490)
Browse files Browse the repository at this point in the history
  • Loading branch information
geri-m committed Oct 20, 2018
1 parent 2f1efe9 commit 7f38889
Showing 1 changed file with 33 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -507,4 +507,37 @@ public void testFailMappingOfDataType() throws Exception {
}
}

private static class AnyTypeInf {
@Key
private double dblInfNeg;
@Key
private double dblInfPos;
@Key
private float fltInfNeg;
@Key
private float fltInfPos;
}

private static final String INF_TEST = "<?xml version=\"1.0\"?><any xmlns=\"\"><dblInfNeg>-INF</dblInfNeg><dblInfPos>INF</dblInfPos><fltInfNeg>-INF</fltInfNeg><fltInfPos>INF</fltInfPos></any>";

@Test
public void testParseInfiniteValues() throws Exception {
AnyTypeInf xml = new AnyTypeInf();
XmlPullParser parser = Xml.createParser();
parser.setInput(new StringReader(INF_TEST));
XmlNamespaceDictionary namespaceDictionary = new XmlNamespaceDictionary().set("","");
Xml.parseElement(parser, xml, namespaceDictionary, null);
// check type
assertEquals(Double.NEGATIVE_INFINITY, xml.dblInfNeg, 0.0001);
assertEquals(Double.POSITIVE_INFINITY, xml.dblInfPos, 0.0001);
assertEquals(Float.NEGATIVE_INFINITY, xml.fltInfNeg, 0.0001);
assertEquals(Float.POSITIVE_INFINITY, xml.dblInfPos, 0.0001);
// serialize
XmlSerializer serializer = Xml.createSerializer();
ByteArrayOutputStream out = new ByteArrayOutputStream();
serializer.setOutput(out, "UTF-8");
namespaceDictionary.serialize(serializer, "any", xml);
assertEquals(INF_TEST, out.toString());
}

}

0 comments on commit 7f38889

Please sign in to comment.