TogaGem 変更履歴
+X.XXX.XXX (XXXX-XX-XX)
+ ・replacing JAXB.
+
3.101.106 (2019-06-02)
・必須環境をJavaSE8に引き上げ。
・Mercurial(3.102.4)からGit(3.101.105-SNAPSHOT)へSCMを移行。
<checkstyle.enable.rss>false</checkstyle.enable.rss>
<pmd-plugin.version>3.12.0</pmd-plugin.version>
- <pmd.analysisCache>true</pmd.analysisCache>
<spotbugs-plugin.version>3.1.11</spotbugs-plugin.version>
<spotbugs.effort>Max</spotbugs.effort>
package jp.sfjp.mikutoga.xml;
import java.io.IOException;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-import javax.xml.bind.DatatypeConverter;
/**
* Appendable実装に依存したXMLエクスポータの半実装。
private static final String COMM_START = "<!--";
private static final String COMM_END = "-->";
- private static final Pattern NUM_FUZZY =
- Pattern.compile("([^.]*\\.[0-9][0-9]*?)0+");
-
private static final String REF_HEX = "&#x";
private static final int HEX_EXP = 4; // 2 ** 4 == 16
private static final int MASK_1HEX = (1 << HEX_EXP) - 1; // 0b00001111
return false;
}
- /**
- * 冗長な実数出力を抑止する。
- * <p>DatatypeConverterにおけるJDK1.6系と1.7系の仕様変更を吸収する。
- * <p>0.001fは"0.0010"ではなく"0.001"と出力される。
- * <p>指数表記での冗長桁は無視する。
- * @param numTxt 実数表記
- * @return 冗長桁が抑止された実数表記
- * @see javax.xml.bind.DatatypeConverter
- */
- protected static String chopFuzzyZero(String numTxt){
- String result;
-
- Matcher matcher = NUM_FUZZY.matcher(numTxt);
- if(matcher.matches()){
- result = matcher.group(1);
- }else{
- result = numTxt;
- }
-
- return result;
- }
-
/**
* {@inheritDoc}
*/
@Override
public XmlExporter putXsdInt(int iVal) throws IOException{
- String value = DatatypeConverter.printInt(iVal);
+ String value = DatatypeIo.printInt(iVal);
putRawText(value);
return this;
}
*/
@Override
public XmlExporter putXsdFloat(float fVal) throws IOException{
- String value = DatatypeConverter.printFloat(fVal);
- value = chopFuzzyZero(value);
+ String value = DatatypeIo.printFloat(fVal);
putRawText(value);
return this;
}
--- /dev/null
+/*
+ * XML Schema datatypes input/output
+ *
+ * License : The MIT License
+ * Copyright(c) 2019 MikuToga Partners
+ */
+
+package jp.sfjp.mikutoga.xml;
+
+/**
+ * XSD datatypes I/O utilities.
+ *
+ * <p>This class replaces javax.xml.bind.DatatypeConverter(JAXB) subset.
+ * JAXB is not part of JDK9 or later.
+ *
+ * @see <a href="https://www.w3.org/TR/xmlschema-2/">
+ * XML Schema Part 2: Datatypes Second Edition
+ * </a>
+ * @see <a href="https://docs.oracle.com/javase/8/docs/api/javax/xml/bind/DatatypeConverter.html">
+ * JavaSE8:DatatypeConverter
+ * </a>
+ */
+final class DatatypeIo {
+
+ /**
+ * Hidden constructor.
+ */
+ private DatatypeIo(){
+ assert false;
+ }
+
+ /**
+ * Converts an int value into a string as xsd:int.
+ *
+ * @param iVal int value
+ * @return xsd:int type text
+ */
+ public static String printInt(int iVal){
+ String result;
+ result = String.valueOf(iVal);
+ return result;
+ }
+
+ /**
+ * Converts an float value into a string as xsd:float.
+ *
+ * <p>Infinite value will be "INF".
+ *
+ * @param fVal float value
+ * @return xsd:float type text
+ */
+ public static String printFloat(float fVal){
+ String result;
+
+ if(fVal == Float.POSITIVE_INFINITY){
+ result = "INF";
+ }else if(fVal == Float.NEGATIVE_INFINITY){
+ result = "-INF";
+ }else{
+ result = String.valueOf(fVal);
+ }
+
+ return result;
+ }
+
+ /**
+ * trimming whitespace around XSD datatypes value.
+ *
+ * @param txt XSD value
+ * @return trimmed text
+ */
+ public static CharSequence xsdTrim(CharSequence txt){
+ int length = txt.length();
+ int startPos = 0;
+ int endPos = length;
+
+ for(int pt = 0; pt < length; pt++){
+ char ch = txt.charAt(pt);
+ if(!isXsdWhitespace(ch)){
+ startPos = pt;
+ break;
+ }
+ }
+
+ for(int pt = length - 1; pt >= 0; pt--){
+ char ch = txt.charAt(pt);
+ if(!isXsdWhitespace(ch)){
+ endPos = pt + 1;
+ break;
+ }
+ }
+
+ CharSequence result = txt.subSequence(startPos, endPos);
+
+ return result;
+ }
+
+ /**
+ * checking whitespace character around XSD datattypes.
+ *
+ * <p>\n, \r, \t, and \0020 are whitespace.
+ *
+ * @param ch character
+ * @return true if whitespace
+ */
+ public static boolean isXsdWhitespace(char ch){
+ boolean result;
+
+ switch(ch){
+ case '\n':
+ case '\r':
+ case '\t':
+ case '\u0020':
+ result = true;
+ break;
+ default:
+ result = false;
+ break;
+ }
+
+ return result;
+ }
+
+ /**
+ * Converts the xsd:boolean string argument into a boolean value.
+ *
+ * <p>{"true", "1"} is true. {"false", "0"} is false.
+ *
+ * @param xsdVal xsd:boolean string
+ * @return true if true
+ * @throws IllegalArgumentException illegal xsd:boolean string
+ */
+ public static boolean parseBoolean(CharSequence xsdVal)
+ throws IllegalArgumentException{
+ boolean result;
+
+ CharSequence trimmed = xsdTrim(xsdVal);
+
+ if("true".contentEquals(trimmed)){
+ result = true;
+ }else if("false".contentEquals(trimmed)){
+ result = false;
+ }else if("0".contentEquals(trimmed)){
+ result = false;
+ }else if("1".contentEquals(trimmed)){
+ result = true;
+ }else{
+ throw new IllegalArgumentException(trimmed.toString());
+ }
+
+ return result;
+ }
+
+ /**
+ * Converts the xsd:byte string argument into a byte value.
+ *
+ * @param xsdVal xsd:byte string
+ * @return byte value
+ * @throws NumberFormatException illegal xsd:byte
+ */
+ public static byte parseByte(CharSequence xsdVal)
+ throws NumberFormatException{
+ CharSequence trimmed = xsdTrim(xsdVal);
+
+ int iVal;
+ iVal = Integer.parseInt(trimmed.toString());
+
+ if(iVal < -128 || 127 < iVal){
+ throw new NumberFormatException(xsdVal.toString());
+ }
+
+ byte result;
+ result = (byte)iVal;
+
+ return result;
+ }
+
+ /**
+ * Converts the xsd:int string argument into a int value.
+ *
+ * @param xsdVal xsd:int string
+ * @return int value
+ * @throws NumberFormatException illegal xsd:int
+ */
+ public static int parseInt(CharSequence xsdVal)
+ throws NumberFormatException{
+ CharSequence trimmed = xsdTrim(xsdVal);
+ int result;
+ result = Integer.parseInt(trimmed.toString());
+ return result;
+ }
+
+ /**
+ * Converts the xsd:float string argument into a float value.
+ *
+ * @param xsdVal xsd:float string
+ * @return float value
+ * @throws NumberFormatException illegal xsd:float
+ */
+ public static float parseFloat(CharSequence xsdVal)
+ throws NumberFormatException{
+ String trimmed = xsdTrim(xsdVal).toString();
+
+ float result;
+ if("INF".equals(trimmed)){
+ result = Float.POSITIVE_INFINITY;
+ }else if("-INF".equals(trimmed)){
+ result = Float.NEGATIVE_INFINITY;
+ }else if(trimmed.endsWith("Infinity")){
+ throw new NumberFormatException(trimmed);
+ }else if(trimmed.contains("x") || trimmed.contains("X")){
+ // HexFloatingPointLiteral
+ throw new NumberFormatException(trimmed);
+ }else{
+ // zero will happen when underflow.
+ // infinite will happen when overflow.
+ // NaN is NaN.
+ // -0 is minus zero.
+ result = Float.parseFloat(trimmed);
+ }
+
+ return result;
+ }
+
+}
import java.text.MessageFormat;
import java.util.Iterator;
-import javax.xml.bind.DatatypeConverter;
import org.w3c.dom.DOMException;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
boolean result;
try{
- result = DatatypeConverter.parseBoolean(value);
+ result = DatatypeIo.parseBoolean(value);
}catch(IllegalArgumentException e){
String message = MessageFormat.format(ERRMSG_INVATTR,
localName,
int result;
try{
- result = DatatypeConverter.parseInt(value);
+ result = DatatypeIo.parseInt(value);
}catch(NumberFormatException e){
String message = MessageFormat.format(ERRMSG_INVATTR,
localName,
float result;
try{
- result = DatatypeConverter.parseFloat(value);
+ result = DatatypeIo.parseFloat(value);
}catch(NumberFormatException e){
String message = MessageFormat.format(ERRMSG_INVATTR,
localName,
import java.util.LinkedList;
import java.util.List;
import java.util.NoSuchElementException;
-import javax.xml.bind.DatatypeConverter;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
boolean result;
try{
- result = DatatypeConverter.parseBoolean(value);
+ result = DatatypeIo.parseBoolean(value);
}catch(IllegalArgumentException e){
String message =
"Invalid boolean attribute form "
int result;
try{
- result = DatatypeConverter.parseInt(value);
+ result = DatatypeIo.parseInt(value);
}catch(IllegalArgumentException e){
String message =
"Invalid integer attribute form "
float result;
try{
- result = DatatypeConverter.parseFloat(value);
+ result = DatatypeIo.parseFloat(value);
}catch(IllegalArgumentException e){
String message =
"Invalid float attribute form "
package jp.sfjp.mikutoga.xml;
-import javax.xml.bind.DatatypeConverter;
import org.xml.sax.Attributes;
/**
throws IllegalArgumentException{
String attrVal = attr.getValue(name);
boolean bVal;
- bVal = DatatypeConverter.parseBoolean(attrVal);
+ bVal = DatatypeIo.parseBoolean(attrVal);
return bVal;
}
if(attrVal == null) return def;
boolean bVal;
- bVal = DatatypeConverter.parseBoolean(attrVal);
+ bVal = DatatypeIo.parseBoolean(attrVal);
return bVal;
}
throws NumberFormatException{
String attrVal = attr.getValue(name);
byte bVal;
- bVal = DatatypeConverter.parseByte(attrVal);
+ bVal = DatatypeIo.parseByte(attrVal);
return bVal;
}
throws NumberFormatException {
String attrVal = attr.getValue(name);
float fVal;
- fVal = DatatypeConverter.parseFloat(attrVal);
+ fVal = DatatypeIo.parseFloat(attrVal);
return fVal;
}
throws NumberFormatException {
String attrVal = attr.getValue(name);
int iVal;
- iVal = DatatypeConverter.parseInt(attrVal);
+ iVal = DatatypeIo.parseInt(attrVal);
return iVal;
}
/**
*
- * @author silva
*/
public class BasicXmlExporterTest {
--- /dev/null
+/*
+ */
+package jp.sfjp.mikutoga.xml;
+
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import static org.junit.Assert.*;
+
+/**
+ *
+ */
+public class DatatypeIoTest {
+
+ public DatatypeIoTest() {
+ }
+
+ @BeforeClass
+ public static void setUpClass() {
+ }
+
+ @AfterClass
+ public static void tearDownClass() {
+ }
+
+ @Before
+ public void setUp() {
+ }
+
+ @After
+ public void tearDown() {
+ }
+
+ /**
+ * Test of printInt method, of class DatatypeIo.
+ */
+ @Test
+ public void testPrintInt() {
+ System.out.println("printInt");
+
+ CharSequence result;
+
+ result = DatatypeIo.printInt(0);
+ assertEquals("0", result.toString());
+
+ result = DatatypeIo.printInt(1);
+ assertEquals("1", result.toString());
+
+ result = DatatypeIo.printInt(-1);
+ assertEquals("-1", result.toString());
+
+ result = DatatypeIo.printInt(999);
+ assertEquals("999", result.toString());
+
+ result = DatatypeIo.printInt(-9999);
+ assertEquals("-9999", result.toString());
+
+ result = DatatypeIo.printInt(Integer.MIN_VALUE);
+ assertEquals("-2147483648", result.toString());
+
+ result = DatatypeIo.printInt(Integer.MAX_VALUE);
+ assertEquals("2147483647", result.toString());
+
+ return;
+ }
+
+ /**
+ * Test of printFloat method, of class DatatypeIo.
+ */
+ @Test
+ public void testPrintFloat() {
+ System.out.println("printFloat");
+
+ CharSequence result;
+
+ result = DatatypeIo.printFloat(0.0f);
+ assertEquals("0.0", result.toString());
+
+ result = DatatypeIo.printFloat(-0.0f);
+ assertEquals("-0.0", result.toString());
+
+ result = DatatypeIo.printFloat(1.0f);
+ assertEquals("1.0", result.toString());
+
+ result = DatatypeIo.printFloat(-1.0f);
+ assertEquals("-1.0", result.toString());
+
+ result = DatatypeIo.printFloat((float)StrictMath.E);
+ assertEquals("2.7182817", result.toString());
+
+ result = DatatypeIo.printFloat((float)StrictMath.PI);
+ assertEquals("3.1415927", result.toString());
+
+ result = DatatypeIo.printFloat(0.001f);
+ assertEquals("0.001", result.toString());
+
+ result = DatatypeIo.printFloat(StrictMath.nextDown(0.001f));
+ assertEquals("9.999999E-4", result.toString());
+
+ result = DatatypeIo.printFloat(10_000_000.0f);
+ assertEquals("1.0E7", result.toString());
+
+ result = DatatypeIo.printFloat(StrictMath.nextDown(10_000_000.0f));
+ assertEquals("9999999.0", result.toString());
+
+ result = DatatypeIo.printFloat(Float.POSITIVE_INFINITY);
+ assertEquals("INF", result.toString());
+
+ result = DatatypeIo.printFloat(Float.NEGATIVE_INFINITY);
+ assertEquals("-INF", result.toString());
+
+ result = DatatypeIo.printFloat(Float.NaN);
+ assertEquals("NaN", result.toString());
+
+ result = DatatypeIo.printFloat(Float.MIN_VALUE);
+ assertEquals("1.4E-45", result.toString());
+
+ result = DatatypeIo.printFloat(Float.MIN_NORMAL);
+ assertEquals("1.17549435E-38", result.toString());
+
+ result = DatatypeIo.printFloat(Float.MAX_VALUE);
+ assertEquals("3.4028235E38", result.toString());
+
+ return;
+ }
+
+ /**
+ * Test of parseBoolean method, of class DatatypeIo.
+ */
+ @Test
+ public void testParseBoolean() {
+ System.out.println("parseBoolean");
+
+ assertFalse(DatatypeIo.parseBoolean("0"));
+ assertFalse(DatatypeIo.parseBoolean("false"));
+ assertTrue(DatatypeIo.parseBoolean("1"));
+ assertTrue(DatatypeIo.parseBoolean("true"));
+
+ assertTrue(DatatypeIo.parseBoolean("\n\rtrue\u0020\t"));
+
+ try{
+ DatatypeIo.parseBoolean("yes");
+ fail();
+ }catch(IllegalArgumentException e){
+ assert true;
+ }
+
+ try{
+ DatatypeIo.parseBoolean("");
+ fail();
+ }catch(IllegalArgumentException e){
+ assert true;
+ }
+
+ return;
+ }
+
+ /**
+ * Test of parseInt method, of class DatatypeIo.
+ */
+ @Test
+ public void testParseInt() {
+ System.out.println("parseInt");
+
+ int result;
+
+ result = DatatypeIo.parseInt("0");
+ assertEquals(0, result);
+
+ result = DatatypeIo.parseInt("+0");
+ assertEquals(0, result);
+
+ result = DatatypeIo.parseInt("-0");
+ assertEquals(0, result);
+
+ result = DatatypeIo.parseInt("1");
+ assertEquals(1, result);
+
+ result = DatatypeIo.parseInt("+1");
+ assertEquals(1, result);
+
+ result = DatatypeIo.parseInt("-1");
+ assertEquals(-1, result);
+
+ result = DatatypeIo.parseInt("999");
+ assertEquals(999, result);
+
+ result = DatatypeIo.parseInt("-9999");
+ assertEquals(-9999, result);
+
+ result = DatatypeIo.parseInt("-2147483648");
+ assertEquals(Integer.MIN_VALUE, result);
+
+ result = DatatypeIo.parseInt("2147483647");
+ assertEquals(Integer.MAX_VALUE, result);
+
+ result = DatatypeIo.parseInt("\n\r999\u0020\t");
+ assertEquals(999, result);
+
+ try{
+ DatatypeIo.parseInt("?");
+ fail();
+ }catch(NumberFormatException e){
+ assert true;
+ }
+
+ try{
+ DatatypeIo.parseInt("-2147483649");
+ fail();
+ }catch(NumberFormatException e){
+ assert true;
+ }
+
+ try{
+ DatatypeIo.parseInt("2147483648");
+ fail();
+ }catch(NumberFormatException e){
+ assert true;
+ }
+
+ try{
+ DatatypeIo.parseInt("3.14");
+ fail();
+ }catch(NumberFormatException e){
+ assert true;
+ }
+
+ return;
+ }
+
+ /**
+ * Test of parseFloat method, of class DatatypeIo.
+ */
+ @Test
+ public void testParseFloat() {
+ System.out.println("parseFloat");
+
+ float result;
+
+ result = DatatypeIo.parseFloat("0.0");
+ assertEquals(0.0f, result, 0.0f);
+
+ result = DatatypeIo.parseFloat("+0.0");
+ assertEquals(0.0f, result, 0.0f);
+
+ result = DatatypeIo.parseFloat("-0.0");
+ assertEquals(-0.0f, result, 0.0f);
+
+ result = DatatypeIo.parseFloat("-123.45");
+ assertEquals(-123.45f, result, 0.0f);
+
+ result = DatatypeIo.parseFloat("654.32");
+ assertEquals(654.32f, result, 0.0f);
+
+ result = DatatypeIo.parseFloat("2.718281828459045");
+ assertEquals((float)StrictMath.E, result, 0.0f);
+
+ result = DatatypeIo.parseFloat("3.141592653589793");
+ assertEquals((float)StrictMath.PI, result, 0.0f);
+
+ result = DatatypeIo.parseFloat("1.401298464324817E-45");
+ assertEquals(Float.MIN_VALUE, result, 0.0f);
+
+ result = DatatypeIo.parseFloat("1.1754943508222875E-38");
+ assertEquals(Float.MIN_NORMAL, result, 0.0f);
+
+ result = DatatypeIo.parseFloat("3.4028234663852886E38");
+ assertEquals(Float.MAX_VALUE, result, 0.0f);
+
+ result = DatatypeIo.parseFloat("2E3");
+ assertEquals(2000.0f, result, 0.0f);
+
+ result = DatatypeIo.parseFloat("2.3E4");
+ assertEquals(23000.0f, result, 0.0f);
+
+ result = DatatypeIo.parseFloat("2.3e4");
+ assertEquals(23000.0f, result, 0.0f);
+
+ result = DatatypeIo.parseFloat("2.3E+4");
+ assertEquals(23000.0f, result, 0.0f);
+
+ result = DatatypeIo.parseFloat("2.3E-4");
+ assertEquals(0.00023f, result, 0.0f);
+
+ result = DatatypeIo.parseFloat("INF");
+ assertEquals(Float.POSITIVE_INFINITY, result, 0.0f);
+
+ result = DatatypeIo.parseFloat("-INF");
+ assertEquals(Float.NEGATIVE_INFINITY, result, 0.0f);
+
+ try{
+ DatatypeIo.parseFloat("+INF");
+ fail();
+ }catch(NumberFormatException e){
+ assert true;
+ }
+
+ try{
+ DatatypeIo.parseFloat("Infinity");
+ fail();
+ }catch(NumberFormatException e){
+ assert true;
+ }
+
+ result = DatatypeIo.parseFloat("NaN");
+ assertTrue(Float.isNaN(result));
+
+ result = DatatypeIo.parseFloat("\n\r1.2\u0020\t");
+ assertEquals(1.2f, result, 0.0f);
+
+ try{
+ DatatypeIo.parseFloat("?");
+ fail();
+ }catch(NumberFormatException e){
+ assert true;
+ }
+
+ try{
+ DatatypeIo.parseFloat("0x1.0p0");
+ fail();
+ }catch(NumberFormatException e){
+ assert true;
+ }
+
+ return;
+ }
+
+ /**
+ * Test of trim method, of class DatatypeIo.
+ */
+ @Test
+ public void testTrim() {
+ System.out.println("trim");
+
+ CharSequence txt;
+ CharSequence result;
+
+ txt = "abc";
+ result = DatatypeIo.xsdTrim(txt);
+ assertEquals("abc", result.toString());
+
+ txt = "";
+ result = DatatypeIo.xsdTrim(txt);
+ assertEquals("", result.toString());
+
+ txt = " abc ";
+ result = DatatypeIo.xsdTrim(txt);
+ assertEquals("abc", result.toString());
+
+ txt = " abc";
+ result = DatatypeIo.xsdTrim(txt);
+ assertEquals("abc", result.toString());
+
+ txt = "abc ";
+ result = DatatypeIo.xsdTrim(txt);
+ assertEquals("abc", result.toString());
+
+ txt = " a b c ";
+ result = DatatypeIo.xsdTrim(txt);
+ assertEquals("a b c", result.toString());
+
+ txt = "\n\rabc\u0020\t";
+ result = DatatypeIo.xsdTrim(txt);
+ assertEquals("abc", result.toString());
+
+ return;
+ }
+
+ /**
+ * Test of isWhitespace method, of class DatatypeIo.
+ */
+ @Test
+ public void testIsWhitespace() {
+ System.out.println("isWhitespace");
+
+ assertTrue(DatatypeIo.isXsdWhitespace('\u0020'));
+ assertTrue(DatatypeIo.isXsdWhitespace('\n'));
+ assertTrue(DatatypeIo.isXsdWhitespace('\r'));
+ assertTrue(DatatypeIo.isXsdWhitespace('\t'));
+ assertFalse(DatatypeIo.isXsdWhitespace('X'));
+ assertFalse(DatatypeIo.isXsdWhitespace('\u0001'));
+
+ return;
+ }
+
+}
package jp.sfjp.mikutoga.xml;
-import javax.xml.bind.DatatypeConverter;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
/**
*
- * @author silva
*/
public class DomUtilsTest {
result = DomUtils.getBooleanAttr(elem, TESTATTR);
assertTrue(result);
- elem = getTestAttredElem(null);
- result = DomUtils.getBooleanAttr(elem, TESTATTR);
- assertFalse(result); // Why?
-
- elem = getTestAttredElem("X");
- result = DomUtils.getBooleanAttr(elem, TESTATTR);
- assertFalse(result); // Why?
-
- elem = getTestAttredElem("");
- result = DomUtils.getBooleanAttr(elem, TESTATTR);
- assertFalse(result); // Why?
-
elem = getTestAttredElem("\n\rtrue\u0020\t");
result = DomUtils.getBooleanAttr(elem, TESTATTR);
assertTrue(result);
+ elem = getTestAttredElem("?");
+ try{
+ DomUtils.getBooleanAttr(elem, TESTATTR);
+ fail();
+ }catch(TogaXmlException e){
+ assert true;
+ }
+
return;
}
result = DomUtils.getIntegerAttr(elem, TESTATTR);
assertEquals(-1, result);
- elem = getTestAttredElem("-0");
- result = DomUtils.getIntegerAttr(elem, TESTATTR);
- assertEquals(0, result);
-
- elem = getTestAttredElem("+1");
- result = DomUtils.getIntegerAttr(elem, TESTATTR);
- assertEquals(1, result);
-
elem = getTestAttredElem("999");
result = DomUtils.getIntegerAttr(elem, TESTATTR);
assertEquals(999, result);
result = DomUtils.getIntegerAttr(elem, TESTATTR);
assertEquals(-9999, result);
- elem = getTestAttredElem("-2147483648");
- result = DomUtils.getIntegerAttr(elem, TESTATTR);
- assertEquals(Integer.MIN_VALUE, result);
-
- elem = getTestAttredElem("2147483647");
- result = DomUtils.getIntegerAttr(elem, TESTATTR);
- assertEquals(Integer.MAX_VALUE, result);
-
elem = getTestAttredElem("\n\r999\u0020\t");
result = DomUtils.getIntegerAttr(elem, TESTATTR);
assertEquals(999, result);
- elem = getTestAttredElem("X");
+ elem = getTestAttredElem("?");
try{
result = DomUtils.getIntegerAttr(elem, TESTATTR);
fail();
assertEquals(0.0f, result, 0.0f);
assertEquals("-0.0", Float.toString(result));
- elem = getTestAttredElem("+0.0");
- result = DomUtils.getFloatAttr(elem, TESTATTR);
- assertEquals(0.0f, result, 0.0f);
-
elem = getTestAttredElem("-123.456");
result = DomUtils.getFloatAttr(elem, TESTATTR);
assertEquals(-123.456f, result, 0.0f);
result = DomUtils.getFloatAttr(elem, TESTATTR);
assertEquals(654.321f, result, 0.0f);
- elem = getTestAttredElem("2.718281828459045");
- result = DomUtils.getFloatAttr(elem, TESTATTR);
- assertEquals((float)StrictMath.E, result, 0.0f);
-
- elem = getTestAttredElem("3.141592653589793");
- result = DomUtils.getFloatAttr(elem, TESTATTR);
- assertEquals((float)StrictMath.PI, result, 0.0f);
-
- elem = getTestAttredElem("1.401298464324817E-45");
- result = DomUtils.getFloatAttr(elem, TESTATTR);
- assertEquals(Float.MIN_VALUE, result, 0.0f);
-
- elem = getTestAttredElem("1.1754943508222875E-38");
- result = DomUtils.getFloatAttr(elem, TESTATTR);
- assertEquals(Float.MIN_NORMAL, result, 0.0f);
-
- elem = getTestAttredElem("3.4028234663852886E38");
- result = DomUtils.getFloatAttr(elem, TESTATTR);
- assertEquals(Float.MAX_VALUE, result, 0.0f);
-
- elem = getTestAttredElem("2E3");
- result = DomUtils.getFloatAttr(elem, TESTATTR);
- assertEquals(2000.0f, result, 0.0f);
-
elem = getTestAttredElem("2.3E4");
result = DomUtils.getFloatAttr(elem, TESTATTR);
assertEquals(23000.0f, result, 0.0f);
- elem = getTestAttredElem("2.3e4");
- result = DomUtils.getFloatAttr(elem, TESTATTR);
- assertEquals(23000.0f, result, 0.0f);
-
- elem = getTestAttredElem("2.3E+4");
- result = DomUtils.getFloatAttr(elem, TESTATTR);
- assertEquals(23000.0f, result, 0.0f);
-
- elem = getTestAttredElem("2.3E-4");
- result = DomUtils.getFloatAttr(elem, TESTATTR);
- assertEquals(0.00023f, result, 0.0f);
-
elem = getTestAttredElem("INF");
result = DomUtils.getFloatAttr(elem, TESTATTR);
assertEquals(Float.POSITIVE_INFINITY, result, 0.0f);
- elem = getTestAttredElem("-INF");
- result = DomUtils.getFloatAttr(elem, TESTATTR);
- assertEquals(Float.NEGATIVE_INFINITY, result, 0.0f);
-
elem = getTestAttredElem("+INF");
try{
- result = DomUtils.getFloatAttr(elem, TESTATTR);
+ DomUtils.getFloatAttr(elem, TESTATTR);
fail();
}catch(TogaXmlException e){
assert true;
}
- //assertEquals(Float.POSITIVE_INFINITY, result, 0.0f);
elem = getTestAttredElem("NaN");
result = DomUtils.getFloatAttr(elem, TESTATTR);
result = DomUtils.getFloatAttr(elem, TESTATTR);
assertEquals(123.456f, result, 0.0f);
- elem = getTestAttredElem("X");
+ elem = getTestAttredElem("?");
try{
- result = DomUtils.getFloatAttr(elem, TESTATTR);
+ DomUtils.getFloatAttr(elem, TESTATTR);
fail();
}catch(TogaXmlException e){
assert true;
return;
}
- private static byte parseByte(String str){
- byte result;
- result = DatatypeConverter.parseByte(str);
- return result;
- }
-
- /**
- * Test of parseByte method, of class DomUtils.
- */
- @Test
- public void testparseByte() throws TogaXmlException {
- System.out.println("prseByte");
-
- byte result;
-
- result = parseByte("0");
- assertEquals((byte)0, result);
-
- result = parseByte("-1");
- assertEquals((byte)-1, result);
-
- result = parseByte("1");
- assertEquals((byte)1, result);
-
- result = parseByte("-0");
- assertEquals((byte)0, result);
-
- result = parseByte("+1");
- assertEquals((byte)1, result);
-
- result = parseByte("-128");
- assertEquals((byte)-128, result);
-
- result = parseByte("127");
- assertEquals((byte)127, result);
-
- result = parseByte("\n\r99\u0020\t");
- assertEquals((byte)99, result);
-
- return;
- }
-
}