From 7f388894e7f791110509649ec7568dc5d2ed882d Mon Sep 17 00:00:00 2001 From: Gerald Madlmayr Date: Sat, 20 Oct 2018 11:53:09 +0200 Subject: [PATCH] Adding Infinity Value Test (#490) --- .../com/google/api/client/xml/XmlTest.java | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/google-http-client-xml/src/test/java/com/google/api/client/xml/XmlTest.java b/google-http-client-xml/src/test/java/com/google/api/client/xml/XmlTest.java index 76417cc7b..b959e9f10 100644 --- a/google-http-client-xml/src/test/java/com/google/api/client/xml/XmlTest.java +++ b/google-http-client-xml/src/test/java/com/google/api/client/xml/XmlTest.java @@ -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 = "-INFINF-INFINF"; + + @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()); + } + }