• R/O
  • HTTP
  • SSH
  • HTTPS

TogaGem: Commit

TogaGemは、3D動画制作ツール、MikuMikuDance(MMD)で用いられる各種データファイルを読み書きするためのJavaライブラリです。
旧TogaParserライブラリの資産は、TogaGemライブラリに吸収されました。


Commit MetaInfo

Revision61e60f5daf0ec483a80f8045cb3eca8039445f7e (tree)
Zeit2019-06-04 22:32:31
AutorOlyutorskii <olyutorskii@user...>
CommiterOlyutorskii

Log Message

Merge release/v3.120.2

Ändern Zusammenfassung

Diff

--- a/CHANGELOG.txt
+++ b/CHANGELOG.txt
@@ -4,6 +4,9 @@
44 TogaGem 変更履歴
55
66
7+3.120.2 (2019-06-04)
8+ ・replacing JAXB DatatypeConverter.
9+
710 3.101.106 (2019-06-02)
811 ・必須環境をJavaSE8に引き上げ。
912 ・Mercurial(3.102.4)からGit(3.101.105-SNAPSHOT)へSCMを移行。
--- a/config/checkstyle/checkstyle-suppressions.xml
+++ b/config/checkstyle/checkstyle-suppressions.xml
@@ -31,12 +31,17 @@
3131 <suppress files="" checks="ImportControl" />
3232
3333 <!-- Javadoc Comments -->
34+ <suppress files="" checks="JavadocParagraph" />
35+ <suppress files="" checks="JavadocTagContinuationIndentation" />
3436 <suppress files="" checks="SummaryJavadocCheck" />
3537
3638 <!-- Miscellaneous -->
3739 <suppress files="" checks="FinalParameters" />
3840 <suppress files="" checks="TrailingComment" />
3941
42+ <!-- Modifier -->
43+ <suppress files="" checks="InterfaceMemberImpliedModifier" />
44+
4045 <!-- Whitespace -->
4146 <suppress files="" checks="SingleSpaceSeparator" />
4247
--- a/config/checkstyle/checkstyle.xml
+++ b/config/checkstyle/checkstyle.xml
@@ -6,7 +6,7 @@
66
77 <!--
88 Checkstyle modules
9- for Checkstyle 8.20 or later
9+ for Checkstyle 8.21 or later
1010
1111 [ https://checkstyle.org/ ]
1212
@@ -20,11 +20,12 @@
2020 <property name="localeCountry" value="JP" />
2121 <property name="localeLanguage" value="en" />
2222 <!--property name="localeLanguage" value="ja" /-->
23- <property name="fileExtensions" value="java, xml, properties" />
23+ <property name="fileExtensions" value="java, properties, xml, xsd, md, txt" />
2424 <property name="severity" value="error" />
2525
2626
2727 <!-- Filters -->
28+
2829 <module name="SeverityMatchFilter" />
2930 <!--module name="SuppressionFilter" /-->
3031 <module name="SuppressWarningsFilter" />
@@ -32,6 +33,7 @@
3233
3334
3435 <!-- Headers -->
36+
3537 <module name="Header">
3638 <property name="header" value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; ?&gt;" />
3739 <property name="fileExtensions" value="xml" />
@@ -44,18 +46,21 @@
4446
4547
4648 <!-- Javadoc Comments -->
49+
4750 <module name="JavadocPackage" />
4851
4952
5053 <!-- Miscellaneous -->
54+
5155 <module name="NewlineAtEndOfFile">
52- <property name="fileExtensions" value="java" />
56+ <property name="fileExtensions" value="java, properties, xml, xsd, md, txt" />
5357 </module>
5458 <module name="Translation" />
5559 <module name="UniqueProperties" />
5660
5761
5862 <!-- Regexp -->
63+
5964 <module name="RegexpMultiline">
6065 <property name="format" value="[\u000b\f\u001a]" />
6166 </module>
@@ -70,10 +75,12 @@
7075
7176
7277 <!-- Size Violations -->
78+
7379 <module name="FileLength" />
7480
7581
7682 <!-- Whitespace -->
83+
7784 <module name="FileTabCharacter" />
7885
7986
@@ -188,7 +195,9 @@
188195 <module name="SuperClone" />
189196 <module name="SuperFinalize" />
190197 <module name="UnnecessaryParentheses" />
191- <module name="VariableDeclarationUsageDistance" />
198+ <module name="VariableDeclarationUsageDistance">
199+ <property name="allowedDistance" value="5"/>
200+ </module>
192201
193202
194203 <!-- Imports -->
@@ -220,6 +229,8 @@
220229 <module name="JavadocVariable">
221230 <property name="scope" value="protected" />
222231 </module>
232+ <module name="MissingJavadocMethod" />
233+ <module name="MissingJavadocType" />
223234 <module name="NonEmptyAtclauseDescription" />
224235 <module name="SingleLineJavadoc" />
225236 <module name="SummaryJavadocCheck" />
@@ -344,8 +355,17 @@
344355 <module name="NoWhitespaceAfter" />
345356 <module name="NoWhitespaceBefore" />
346357 <module name="OperatorWrap" />
347- <module name="ParenPad" />
348- <module name="SeparatorWrap" />
358+ <module name="ParenPad">
359+ <property name="option" value="nospace" />
360+ <property
361+ name="tokens"
362+ value="CTOR_CALL, METHOD_CALL, SUPER_CTOR_CALL"
363+ />
364+ </module>
365+ <module name="SeparatorWrap">
366+ <property name="tokens" value="DOT"/>
367+ <property name="option" value="nl"/>
368+ </module>
349369 <module name="SingleSpaceSeparator" />
350370 <module name="TypecastParenPad" />
351371 <module name="WhitespaceAfter" >
--- a/pom.xml
+++ b/pom.xml
@@ -16,7 +16,7 @@
1616 <groupId>jp.sourceforge.mikutoga</groupId>
1717 <artifactId>togagem</artifactId>
1818
19- <version>3.101.106</version>
19+ <version>3.120.2</version>
2020
2121 <packaging>jar</packaging>
2222 <name>TogaGem</name>
@@ -96,16 +96,15 @@
9696 <detectJavaApiLink>false</detectJavaApiLink>
9797
9898 <surefire-plugin.version>3.0.0-M3</surefire-plugin.version>
99- <jacoco-plugin.version>0.8.3</jacoco-plugin.version>
99+ <jacoco-plugin.version>0.8.4</jacoco-plugin.version>
100100
101- <checkstyle-plugin.version>3.0.0</checkstyle-plugin.version>
102- <checkstyleruntime.version>8.20</checkstyleruntime.version>
101+ <checkstyle-plugin.version>3.1.0</checkstyle-plugin.version>
102+ <checkstyleruntime.version>8.21</checkstyleruntime.version>
103103 <checkstyle.config.location>${project.basedir}/config/checkstyle/checkstyle.xml</checkstyle.config.location>
104104 <checkstyle.suppressions.location>${project.basedir}/config/checkstyle/checkstyle-suppressions.xml</checkstyle.suppressions.location>
105105 <checkstyle.enable.rss>false</checkstyle.enable.rss>
106106
107107 <pmd-plugin.version>3.12.0</pmd-plugin.version>
108- <pmd.analysisCache>true</pmd.analysisCache>
109108
110109 <spotbugs-plugin.version>3.1.11</spotbugs-plugin.version>
111110 <spotbugs.effort>Max</spotbugs.effort>
@@ -202,8 +201,7 @@
202201 <version>[3.3.9,)</version>
203202 </requireMavenVersion>
204203 <requireJavaVersion>
205- <!-- JAXB -->
206- <version>1.8</version>
204+ <version>[1.8,)</version>
207205 </requireJavaVersion>
208206 </rules>
209207 </configuration>
@@ -220,7 +218,7 @@
220218 <plugin>
221219 <groupId>org.apache.maven.plugins</groupId>
222220 <artifactId>maven-compiler-plugin</artifactId>
223- <version>3.8.0</version>
221+ <version>3.8.1</version>
224222 <configuration>
225223 <source>1.8</source> <!-- for NetBeans IDE -->
226224 <target>1.8</target>
@@ -285,7 +283,7 @@
285283 <plugin>
286284 <groupId>org.apache.maven.plugins</groupId>
287285 <artifactId>maven-jar-plugin</artifactId>
288- <version>3.1.1</version>
286+ <version>3.1.2</version>
289287 <configuration>
290288 <archive>
291289 <manifest>
@@ -303,7 +301,7 @@
303301 <plugin>
304302 <groupId>org.apache.maven.plugins</groupId>
305303 <artifactId>maven-source-plugin</artifactId>
306- <version>3.0.1</version>
304+ <version>3.1.0</version>
307305 <configuration>
308306 <includePom>true</includePom>
309307 <archive>
--- a/src/main/java/jp/sfjp/mikutoga/xml/AbstractXmlExporter.java
+++ b/src/main/java/jp/sfjp/mikutoga/xml/AbstractXmlExporter.java
@@ -8,9 +8,6 @@
88 package jp.sfjp.mikutoga.xml;
99
1010 import java.io.IOException;
11-import java.util.regex.Matcher;
12-import java.util.regex.Pattern;
13-import javax.xml.bind.DatatypeConverter;
1411
1512 /**
1613 * Appendable実装に依存したXMLエクスポータの半実装。
@@ -35,9 +32,6 @@ abstract class AbstractXmlExporter implements XmlExporter{
3532 private static final String COMM_START = "<!--";
3633 private static final String COMM_END = "-->";
3734
38- private static final Pattern NUM_FUZZY =
39- Pattern.compile("([^.]*\\.[0-9][0-9]*?)0+");
40-
4135 private static final String REF_HEX = "&#x";
4236 private static final int HEX_EXP = 4; // 2 ** 4 == 16
4337 private static final int MASK_1HEX = (1 << HEX_EXP) - 1; // 0b00001111
@@ -84,28 +78,6 @@ abstract class AbstractXmlExporter implements XmlExporter{
8478 return false;
8579 }
8680
87- /**
88- * 冗長な実数出力を抑止する。
89- * <p>DatatypeConverterにおけるJDK1.6系と1.7系の仕様変更を吸収する。
90- * <p>0.001fは"0.0010"ではなく"0.001"と出力される。
91- * <p>指数表記での冗長桁は無視する。
92- * @param numTxt 実数表記
93- * @return 冗長桁が抑止された実数表記
94- * @see javax.xml.bind.DatatypeConverter
95- */
96- protected static String chopFuzzyZero(String numTxt){
97- String result;
98-
99- Matcher matcher = NUM_FUZZY.matcher(numTxt);
100- if(matcher.matches()){
101- result = matcher.group(1);
102- }else{
103- result = numTxt;
104- }
105-
106- return result;
107- }
108-
10981
11082 /**
11183 * {@inheritDoc}
@@ -617,7 +589,7 @@ abstract class AbstractXmlExporter implements XmlExporter{
617589 */
618590 @Override
619591 public XmlExporter putXsdInt(int iVal) throws IOException{
620- String value = DatatypeConverter.printInt(iVal);
592+ String value = DatatypeIo.printInt(iVal);
621593 putRawText(value);
622594 return this;
623595 }
@@ -630,8 +602,7 @@ abstract class AbstractXmlExporter implements XmlExporter{
630602 */
631603 @Override
632604 public XmlExporter putXsdFloat(float fVal) throws IOException{
633- String value = DatatypeConverter.printFloat(fVal);
634- value = chopFuzzyZero(value);
605+ String value = DatatypeIo.printFloat(fVal);
635606 putRawText(value);
636607 return this;
637608 }
--- /dev/null
+++ b/src/main/java/jp/sfjp/mikutoga/xml/DatatypeIo.java
@@ -0,0 +1,225 @@
1+/*
2+ * XML Schema datatypes input/output
3+ *
4+ * License : The MIT License
5+ * Copyright(c) 2019 MikuToga Partners
6+ */
7+
8+package jp.sfjp.mikutoga.xml;
9+
10+/**
11+ * XSD datatypes I/O utilities.
12+ *
13+ * <p>This class replaces javax.xml.bind.DatatypeConverter(JAXB) subset.
14+ * JAXB is not part of JDK9 or later.
15+ *
16+ * @see <a href="https://www.w3.org/TR/xmlschema-2/">
17+ * XML Schema Part 2: Datatypes Second Edition
18+ * </a>
19+ * @see <a href="https://docs.oracle.com/javase/8/docs/api/javax/xml/bind/DatatypeConverter.html">
20+ * JavaSE8:DatatypeConverter
21+ * </a>
22+ */
23+final class DatatypeIo {
24+
25+ /**
26+ * Hidden constructor.
27+ */
28+ private DatatypeIo(){
29+ assert false;
30+ }
31+
32+ /**
33+ * Converts an int value into a string as xsd:int.
34+ *
35+ * @param iVal int value
36+ * @return xsd:int type text
37+ */
38+ public static String printInt(int iVal){
39+ String result;
40+ result = String.valueOf(iVal);
41+ return result;
42+ }
43+
44+ /**
45+ * Converts an float value into a string as xsd:float.
46+ *
47+ * <p>Infinite value will be "INF".
48+ *
49+ * @param fVal float value
50+ * @return xsd:float type text
51+ */
52+ public static String printFloat(float fVal){
53+ String result;
54+
55+ if(fVal == Float.POSITIVE_INFINITY){
56+ result = "INF";
57+ }else if(fVal == Float.NEGATIVE_INFINITY){
58+ result = "-INF";
59+ }else{
60+ result = String.valueOf(fVal);
61+ }
62+
63+ return result;
64+ }
65+
66+ /**
67+ * trimming whitespace around XSD datatypes value.
68+ *
69+ * @param txt XSD value
70+ * @return trimmed text
71+ */
72+ public static CharSequence xsdTrim(CharSequence txt){
73+ int length = txt.length();
74+ int startPos = 0;
75+ int endPos = length;
76+
77+ for(int pt = 0; pt < length; pt++){
78+ char ch = txt.charAt(pt);
79+ if(!isXsdWhitespace(ch)){
80+ startPos = pt;
81+ break;
82+ }
83+ }
84+
85+ for(int pt = length - 1; pt >= 0; pt--){
86+ char ch = txt.charAt(pt);
87+ if(!isXsdWhitespace(ch)){
88+ endPos = pt + 1;
89+ break;
90+ }
91+ }
92+
93+ CharSequence result = txt.subSequence(startPos, endPos);
94+
95+ return result;
96+ }
97+
98+ /**
99+ * checking whitespace character around XSD datattypes.
100+ *
101+ * <p>\n, \r, \t, and &#x5c;0020 are whitespace.
102+ *
103+ * @param ch character
104+ * @return true if whitespace
105+ */
106+ public static boolean isXsdWhitespace(char ch){
107+ boolean result;
108+
109+ switch(ch){
110+ case '\n':
111+ case '\r':
112+ case '\t':
113+ case '\u0020':
114+ result = true;
115+ break;
116+ default:
117+ result = false;
118+ break;
119+ }
120+
121+ return result;
122+ }
123+
124+ /**
125+ * Converts the xsd:boolean string argument into a boolean value.
126+ *
127+ * <p>{"true", "1"} is true. {"false", "0"} is false.
128+ *
129+ * @param xsdVal xsd:boolean string
130+ * @return true if true
131+ * @throws IllegalArgumentException illegal xsd:boolean string
132+ */
133+ public static boolean parseBoolean(CharSequence xsdVal)
134+ throws IllegalArgumentException{
135+ boolean result;
136+
137+ CharSequence trimmed = xsdTrim(xsdVal);
138+
139+ if("true".contentEquals(trimmed)){
140+ result = true;
141+ }else if("false".contentEquals(trimmed)){
142+ result = false;
143+ }else if("0".contentEquals(trimmed)){
144+ result = false;
145+ }else if("1".contentEquals(trimmed)){
146+ result = true;
147+ }else{
148+ throw new IllegalArgumentException(trimmed.toString());
149+ }
150+
151+ return result;
152+ }
153+
154+ /**
155+ * Converts the xsd:byte string argument into a byte value.
156+ *
157+ * @param xsdVal xsd:byte string
158+ * @return byte value
159+ * @throws NumberFormatException illegal xsd:byte
160+ */
161+ public static byte parseByte(CharSequence xsdVal)
162+ throws NumberFormatException{
163+ CharSequence trimmed = xsdTrim(xsdVal);
164+
165+ int iVal;
166+ iVal = Integer.parseInt(trimmed.toString());
167+
168+ if(iVal < -128 || 127 < iVal){
169+ throw new NumberFormatException(xsdVal.toString());
170+ }
171+
172+ byte result;
173+ result = (byte)iVal;
174+
175+ return result;
176+ }
177+
178+ /**
179+ * Converts the xsd:int string argument into a int value.
180+ *
181+ * @param xsdVal xsd:int string
182+ * @return int value
183+ * @throws NumberFormatException illegal xsd:int
184+ */
185+ public static int parseInt(CharSequence xsdVal)
186+ throws NumberFormatException{
187+ CharSequence trimmed = xsdTrim(xsdVal);
188+ int result;
189+ result = Integer.parseInt(trimmed.toString());
190+ return result;
191+ }
192+
193+ /**
194+ * Converts the xsd:float string argument into a float value.
195+ *
196+ * @param xsdVal xsd:float string
197+ * @return float value
198+ * @throws NumberFormatException illegal xsd:float
199+ */
200+ public static float parseFloat(CharSequence xsdVal)
201+ throws NumberFormatException{
202+ String trimmed = xsdTrim(xsdVal).toString();
203+
204+ float result;
205+ if("INF".equals(trimmed)){
206+ result = Float.POSITIVE_INFINITY;
207+ }else if("-INF".equals(trimmed)){
208+ result = Float.NEGATIVE_INFINITY;
209+ }else if(trimmed.endsWith("Infinity")){
210+ throw new NumberFormatException(trimmed);
211+ }else if(trimmed.contains("x") || trimmed.contains("X")){
212+ // HexFloatingPointLiteral
213+ throw new NumberFormatException(trimmed);
214+ }else{
215+ // zero will happen when underflow.
216+ // infinite will happen when overflow.
217+ // NaN is NaN.
218+ // -0 is minus zero.
219+ result = Float.parseFloat(trimmed);
220+ }
221+
222+ return result;
223+ }
224+
225+}
--- a/src/main/java/jp/sfjp/mikutoga/xml/DomNsUtils.java
+++ b/src/main/java/jp/sfjp/mikutoga/xml/DomNsUtils.java
@@ -9,7 +9,6 @@ package jp.sfjp.mikutoga.xml;
99
1010 import java.text.MessageFormat;
1111 import java.util.Iterator;
12-import javax.xml.bind.DatatypeConverter;
1312 import org.w3c.dom.DOMException;
1413 import org.w3c.dom.Element;
1514 import org.w3c.dom.Node;
@@ -223,7 +222,7 @@ public final class DomNsUtils {
223222
224223 boolean result;
225224 try{
226- result = DatatypeConverter.parseBoolean(value);
225+ result = DatatypeIo.parseBoolean(value);
227226 }catch(IllegalArgumentException e){
228227 String message = MessageFormat.format(ERRMSG_INVATTR,
229228 localName,
@@ -250,7 +249,7 @@ public final class DomNsUtils {
250249
251250 int result;
252251 try{
253- result = DatatypeConverter.parseInt(value);
252+ result = DatatypeIo.parseInt(value);
254253 }catch(NumberFormatException e){
255254 String message = MessageFormat.format(ERRMSG_INVATTR,
256255 localName,
@@ -277,7 +276,7 @@ public final class DomNsUtils {
277276
278277 float result;
279278 try{
280- result = DatatypeConverter.parseFloat(value);
279+ result = DatatypeIo.parseFloat(value);
281280 }catch(NumberFormatException e){
282281 String message = MessageFormat.format(ERRMSG_INVATTR,
283282 localName,
--- a/src/main/java/jp/sfjp/mikutoga/xml/DomUtils.java
+++ b/src/main/java/jp/sfjp/mikutoga/xml/DomUtils.java
@@ -11,7 +11,6 @@ import java.util.Iterator;
1111 import java.util.LinkedList;
1212 import java.util.List;
1313 import java.util.NoSuchElementException;
14-import javax.xml.bind.DatatypeConverter;
1514 import org.w3c.dom.Element;
1615 import org.w3c.dom.Node;
1716
@@ -72,7 +71,7 @@ public final class DomUtils {
7271
7372 boolean result;
7473 try{
75- result = DatatypeConverter.parseBoolean(value);
74+ result = DatatypeIo.parseBoolean(value);
7675 }catch(IllegalArgumentException e){
7776 String message =
7877 "Invalid boolean attribute form "
@@ -96,7 +95,7 @@ public final class DomUtils {
9695
9796 int result;
9897 try{
99- result = DatatypeConverter.parseInt(value);
98+ result = DatatypeIo.parseInt(value);
10099 }catch(IllegalArgumentException e){
101100 String message =
102101 "Invalid integer attribute form "
@@ -120,7 +119,7 @@ public final class DomUtils {
120119
121120 float result;
122121 try{
123- result = DatatypeConverter.parseFloat(value);
122+ result = DatatypeIo.parseFloat(value);
124123 }catch(IllegalArgumentException e){
125124 String message =
126125 "Invalid float attribute form "
--- a/src/main/java/jp/sfjp/mikutoga/xml/SaxAttr.java
+++ b/src/main/java/jp/sfjp/mikutoga/xml/SaxAttr.java
@@ -7,7 +7,6 @@
77
88 package jp.sfjp.mikutoga.xml;
99
10-import javax.xml.bind.DatatypeConverter;
1110 import org.xml.sax.Attributes;
1211
1312 /**
@@ -57,7 +56,7 @@ public final class SaxAttr {
5756 throws IllegalArgumentException{
5857 String attrVal = attr.getValue(name);
5958 boolean bVal;
60- bVal = DatatypeConverter.parseBoolean(attrVal);
59+ bVal = DatatypeIo.parseBoolean(attrVal);
6160 return bVal;
6261 }
6362
@@ -77,7 +76,7 @@ public final class SaxAttr {
7776 if(attrVal == null) return def;
7877
7978 boolean bVal;
80- bVal = DatatypeConverter.parseBoolean(attrVal);
79+ bVal = DatatypeIo.parseBoolean(attrVal);
8180
8281 return bVal;
8382 }
@@ -93,7 +92,7 @@ public final class SaxAttr {
9392 throws NumberFormatException{
9493 String attrVal = attr.getValue(name);
9594 byte bVal;
96- bVal = DatatypeConverter.parseByte(attrVal);
95+ bVal = DatatypeIo.parseByte(attrVal);
9796 return bVal;
9897 }
9998
@@ -108,7 +107,7 @@ public final class SaxAttr {
108107 throws NumberFormatException {
109108 String attrVal = attr.getValue(name);
110109 float fVal;
111- fVal = DatatypeConverter.parseFloat(attrVal);
110+ fVal = DatatypeIo.parseFloat(attrVal);
112111 return fVal;
113112 }
114113
@@ -123,7 +122,7 @@ public final class SaxAttr {
123122 throws NumberFormatException {
124123 String attrVal = attr.getValue(name);
125124 int iVal;
126- iVal = DatatypeConverter.parseInt(attrVal);
125+ iVal = DatatypeIo.parseInt(attrVal);
127126 return iVal;
128127 }
129128
--- a/src/test/java/jp/sfjp/mikutoga/math/MkQuatTest.java
+++ b/src/test/java/jp/sfjp/mikutoga/math/MkQuatTest.java
@@ -41,12 +41,22 @@ public strictfp class MkQuatTest {
4141 public void tearDown() {
4242 }
4343
44- private void assert0UlpEquals(double expected, double result){
44+ /**
45+ * StrictMath.toRadians(6) results are not same between JDK8 & JDK9.
46+ */
47+ private static double toRadians(double deg){
48+ double result = deg * 0.01745329251994329576924;
49+// assert StrictMath.toRadians(6) == 0.10471975511965977; //JDK8
50+// assert StrictMath.toRadians(6) == 0.10471975511965978; //JDK9
51+ return result;
52+ }
53+
54+ private static void assert0UlpEquals(double expected, double result){
4555 assertUlpEquals(expected, result, 0);
4656 return;
4757 }
4858
49- private void assertUlpEquals(double expected, double result, int ulpNum){
59+ private static void assertUlpEquals(double expected, double result, int ulpNum){
5060 double ulpExpected = StrictMath.ulp(expected);
5161 double ulpResult = StrictMath.ulp(result);
5262 double ulp = StrictMath.max(ulpExpected, ulpResult);
@@ -434,14 +444,14 @@ public strictfp class MkQuatTest {
434444 double yRad;
435445 double zRad;
436446
437- xRad = StrictMath.toRadians(95);
438- yRad = StrictMath.toRadians(0);
439- zRad = StrictMath.toRadians(0);
447+ xRad = toRadians(95);
448+ yRad = toRadians(0);
449+ zRad = toRadians(0);
440450 qq.setEulerYXZ(xRad, yRad, zRad);
441451 qq.toEulerYXZ(eu, yRad);
442- assertUlpEquals(StrictMath.toRadians(85), eu.getXRot(), 1);
443- assertUlpEquals(StrictMath.toRadians(180), eu.getYRot(), 0);
444- assertUlpEquals(StrictMath.toRadians(180), eu.getZRot(), 0);
452+ assertUlpEquals(toRadians(85), eu.getXRot(), 1);
453+ assertUlpEquals(toRadians(180), eu.getYRot(), 0);
454+ assertUlpEquals(toRadians(180), eu.getZRot(), 0);
445455
446456 return;
447457 }
@@ -462,9 +472,9 @@ public strictfp class MkQuatTest {
462472 qq = new MkQuat();
463473 eu = new EulerYXZ();
464474
465- xRad = StrictMath.toRadians(89);
466- yRad = StrictMath.toRadians(80);
467- zRad = StrictMath.toRadians(41);
475+ xRad = toRadians(89);
476+ yRad = toRadians(80);
477+ zRad = toRadians(41);
468478 qq.setEulerYXZ(xRad, yRad, zRad);
469479 qq.toEulerYXZ(eu, 0.0);
470480 assertUlpEquals(xRad, eu.getXRot(), 164);
@@ -472,23 +482,23 @@ public strictfp class MkQuatTest {
472482 assertUlpEquals(zRad, eu.getZRot(), 211);
473483
474484 // ジンバルロック判定境界ケース
475- xRad = StrictMath.toRadians(90);
476- yRad = StrictMath.toRadians(6);
477- zRad = StrictMath.toRadians(7);
485+ xRad = toRadians(90);
486+ yRad = toRadians(6);
487+ zRad = toRadians(7);
478488 qq.setEulerYXZ(xRad, yRad, zRad);
479489 qq.toEulerYXZ(eu, yRad);
480490 assert0UlpEquals(xRad, eu.getXRot());
481491 assert0UlpEquals(yRad, eu.getYRot());
482- assert0UlpEquals(zRad, eu.getZRot());
492+ assertUlpEquals(zRad, eu.getZRot(), 1);
483493
484- xRad = StrictMath.toRadians(89.999);
485- yRad = StrictMath.toRadians(89.999);
486- zRad = StrictMath.toRadians(89.999);
494+ xRad = toRadians(89.999);
495+ yRad = toRadians(89.999);
496+ zRad = toRadians(89.999);
487497 qq.setEulerYXZ(xRad, yRad, zRad);
488498 qq.toEulerYXZ(eu, yRad);
489499 assertUlpEquals(xRad, eu.getXRot(), 83029);
490- assertUlpEquals(yRad, eu.getYRot(), 80108);
491- assertUlpEquals(zRad, eu.getZRot(), 80108);
500+ assertUlpEquals(yRad, eu.getYRot(), 91782);
501+ assertUlpEquals(zRad, eu.getZRot(), 91782);
492502
493503 return;
494504 }
@@ -668,9 +678,9 @@ public strictfp class MkQuatTest {
668678 qq = new MkQuat();
669679 result = new EulerYXZ();
670680
671- double xRad = StrictMath.toRadians(ix);
672- double yRad = StrictMath.toRadians(iy);
673- double zRad = StrictMath.toRadians(iz);
681+ double xRad = toRadians(ix);
682+ double yRad = toRadians(iy);
683+ double zRad = toRadians(iz);
674684
675685 qq.setEulerYXZ(xRad, yRad, zRad);
676686 qq.toEulerYXZ(result, yRad);
--- /dev/null
+++ b/src/test/java/jp/sfjp/mikutoga/xml/BasicXmlExporterTest.java
@@ -0,0 +1,172 @@
1+/*
2+ */
3+
4+package jp.sfjp.mikutoga.xml;
5+
6+import java.io.IOException;
7+import org.junit.After;
8+import org.junit.AfterClass;
9+import org.junit.Before;
10+import org.junit.BeforeClass;
11+import org.junit.Test;
12+import static org.junit.Assert.*;
13+
14+/**
15+ *
16+ */
17+public class BasicXmlExporterTest {
18+
19+ public BasicXmlExporterTest() {
20+ }
21+
22+ @BeforeClass
23+ public static void setUpClass() {
24+ }
25+
26+ @AfterClass
27+ public static void tearDownClass() {
28+ }
29+
30+ @Before
31+ public void setUp() {
32+ }
33+
34+ @After
35+ public void tearDown() {
36+ }
37+
38+ /**
39+ * Test of append method, of class BasicXmlExporter.
40+ */
41+ @Test
42+ public void testAppend() {
43+ System.out.println("setAppendable");
44+
45+ BasicXmlExporter instance;
46+ Appendable app;
47+ StringBuffer buf;
48+
49+ instance = new BasicXmlExporter();
50+
51+ try{
52+ instance.append(null);
53+ fail();
54+ }catch(NullPointerException e){
55+ assert true;
56+ }catch(IOException e){
57+ fail();
58+ }
59+
60+ buf = new StringBuffer();
61+ app = buf;
62+
63+ instance.setAppendable(app);
64+
65+ try{
66+ instance.append("abc");
67+ instance.append('d');
68+ instance.append("abcdef", 4, 5);
69+ }catch(IOException e){
70+ fail();
71+ }
72+
73+ assertEquals("abcde", buf.toString());
74+
75+ try{
76+ instance.flush();
77+ instance.close();
78+ }catch(IOException e){
79+ fail();
80+ }
81+
82+ return;
83+ }
84+
85+ @Test
86+ public void testPutXsdInt() throws IOException{
87+ System.out.println("putXsdInt");
88+
89+ BasicXmlExporter instance;
90+ StringBuffer buf;
91+
92+ instance = new BasicXmlExporter();
93+
94+ buf = new StringBuffer();
95+ instance.setAppendable(buf);
96+ instance.putXsdInt(-1).putCh(',').putXsdInt(0).putCh(',').putXsdInt(1);
97+ assertEquals("-1,0,1", buf.toString());
98+
99+ buf = new StringBuffer();
100+ instance.setAppendable(buf);
101+ instance.putXsdInt(-999).putCh(',').putXsdInt(9999);
102+ assertEquals("-999,9999", buf.toString());
103+
104+ buf = new StringBuffer();
105+ instance.setAppendable(buf);
106+ instance.putXsdInt(Integer.MIN_VALUE).putCh(',').putXsdInt(Integer.MAX_VALUE);
107+ assertEquals("-2147483648,2147483647", buf.toString());
108+
109+ return;
110+ }
111+
112+ @Test
113+ public void testPutXsdFloat() throws IOException{
114+ System.out.println("putXsdFloat");
115+
116+ BasicXmlExporter instance;
117+ StringBuffer buf;
118+
119+ instance = new BasicXmlExporter();
120+
121+ buf = new StringBuffer();
122+ instance.setAppendable(buf);
123+ instance.putXsdFloat(-1.0f).putCh(',')
124+ .putXsdFloat(-0.0f).putCh(',')
125+ .putXsdFloat(0.0f).putCh(',')
126+ .putXsdFloat(1.0f);
127+ assertEquals("-1.0,-0.0,0.0,1.0", buf.toString());
128+
129+ buf = new StringBuffer();
130+ instance.setAppendable(buf);
131+ instance.putXsdFloat(Float.NEGATIVE_INFINITY).putCh(',')
132+ .putXsdFloat(Float.POSITIVE_INFINITY).putCh(',')
133+ .putXsdFloat(Float.NaN);
134+ assertEquals("-INF,INF,NaN", buf.toString());
135+
136+ buf = new StringBuffer();
137+ instance.setAppendable(buf);
138+ instance.putXsdFloat(Float.MIN_VALUE).putCh(',')
139+ .putXsdFloat(Float.MIN_NORMAL).putCh(',')
140+ .putXsdFloat(Float.MAX_VALUE);
141+ assertEquals("1.4E-45,1.17549435E-38,3.4028235E38", buf.toString());
142+
143+ buf = new StringBuffer();
144+ instance.setAppendable(buf);
145+ instance.putXsdFloat(0.001f);
146+ assertEquals("0.001", buf.toString()); // fuzzy "0.0010" on JDK1.6
147+
148+ buf = new StringBuffer();
149+ instance.setAppendable(buf);
150+ instance.putXsdFloat(StrictMath.nextDown(0.001f));
151+ assertEquals("9.999999E-4", buf.toString());
152+
153+ buf = new StringBuffer();
154+ instance.setAppendable(buf);
155+ instance.putXsdFloat(10000000.0f);
156+ assertEquals("1.0E7", buf.toString());
157+
158+ buf = new StringBuffer();
159+ instance.setAppendable(buf);
160+ instance.putXsdFloat(StrictMath.nextDown(10000000.0f));
161+ assertEquals("9999999.0", buf.toString());
162+
163+ buf = new StringBuffer();
164+ instance.setAppendable(buf);
165+ instance.putXsdFloat((float)StrictMath.E).putCh(',')
166+ .putXsdFloat((float)StrictMath.PI);
167+ assertEquals("2.7182817,3.1415927", buf.toString());
168+
169+ return;
170+ }
171+
172+}
--- /dev/null
+++ b/src/test/java/jp/sfjp/mikutoga/xml/DatatypeIoTest.java
@@ -0,0 +1,388 @@
1+/*
2+ */
3+package jp.sfjp.mikutoga.xml;
4+
5+import org.junit.After;
6+import org.junit.AfterClass;
7+import org.junit.Before;
8+import org.junit.BeforeClass;
9+import org.junit.Test;
10+import static org.junit.Assert.*;
11+
12+/**
13+ *
14+ */
15+public class DatatypeIoTest {
16+
17+ public DatatypeIoTest() {
18+ }
19+
20+ @BeforeClass
21+ public static void setUpClass() {
22+ }
23+
24+ @AfterClass
25+ public static void tearDownClass() {
26+ }
27+
28+ @Before
29+ public void setUp() {
30+ }
31+
32+ @After
33+ public void tearDown() {
34+ }
35+
36+ /**
37+ * Test of printInt method, of class DatatypeIo.
38+ */
39+ @Test
40+ public void testPrintInt() {
41+ System.out.println("printInt");
42+
43+ CharSequence result;
44+
45+ result = DatatypeIo.printInt(0);
46+ assertEquals("0", result.toString());
47+
48+ result = DatatypeIo.printInt(1);
49+ assertEquals("1", result.toString());
50+
51+ result = DatatypeIo.printInt(-1);
52+ assertEquals("-1", result.toString());
53+
54+ result = DatatypeIo.printInt(999);
55+ assertEquals("999", result.toString());
56+
57+ result = DatatypeIo.printInt(-9999);
58+ assertEquals("-9999", result.toString());
59+
60+ result = DatatypeIo.printInt(Integer.MIN_VALUE);
61+ assertEquals("-2147483648", result.toString());
62+
63+ result = DatatypeIo.printInt(Integer.MAX_VALUE);
64+ assertEquals("2147483647", result.toString());
65+
66+ return;
67+ }
68+
69+ /**
70+ * Test of printFloat method, of class DatatypeIo.
71+ */
72+ @Test
73+ public void testPrintFloat() {
74+ System.out.println("printFloat");
75+
76+ CharSequence result;
77+
78+ result = DatatypeIo.printFloat(0.0f);
79+ assertEquals("0.0", result.toString());
80+
81+ result = DatatypeIo.printFloat(-0.0f);
82+ assertEquals("-0.0", result.toString());
83+
84+ result = DatatypeIo.printFloat(1.0f);
85+ assertEquals("1.0", result.toString());
86+
87+ result = DatatypeIo.printFloat(-1.0f);
88+ assertEquals("-1.0", result.toString());
89+
90+ result = DatatypeIo.printFloat((float)StrictMath.E);
91+ assertEquals("2.7182817", result.toString());
92+
93+ result = DatatypeIo.printFloat((float)StrictMath.PI);
94+ assertEquals("3.1415927", result.toString());
95+
96+ result = DatatypeIo.printFloat(0.001f);
97+ assertEquals("0.001", result.toString());
98+
99+ result = DatatypeIo.printFloat(StrictMath.nextDown(0.001f));
100+ assertEquals("9.999999E-4", result.toString());
101+
102+ result = DatatypeIo.printFloat(10_000_000.0f);
103+ assertEquals("1.0E7", result.toString());
104+
105+ result = DatatypeIo.printFloat(StrictMath.nextDown(10_000_000.0f));
106+ assertEquals("9999999.0", result.toString());
107+
108+ result = DatatypeIo.printFloat(Float.POSITIVE_INFINITY);
109+ assertEquals("INF", result.toString());
110+
111+ result = DatatypeIo.printFloat(Float.NEGATIVE_INFINITY);
112+ assertEquals("-INF", result.toString());
113+
114+ result = DatatypeIo.printFloat(Float.NaN);
115+ assertEquals("NaN", result.toString());
116+
117+ result = DatatypeIo.printFloat(Float.MIN_VALUE);
118+ assertEquals("1.4E-45", result.toString());
119+
120+ result = DatatypeIo.printFloat(Float.MIN_NORMAL);
121+ assertEquals("1.17549435E-38", result.toString());
122+
123+ result = DatatypeIo.printFloat(Float.MAX_VALUE);
124+ assertEquals("3.4028235E38", result.toString());
125+
126+ return;
127+ }
128+
129+ /**
130+ * Test of parseBoolean method, of class DatatypeIo.
131+ */
132+ @Test
133+ public void testParseBoolean() {
134+ System.out.println("parseBoolean");
135+
136+ assertFalse(DatatypeIo.parseBoolean("0"));
137+ assertFalse(DatatypeIo.parseBoolean("false"));
138+ assertTrue(DatatypeIo.parseBoolean("1"));
139+ assertTrue(DatatypeIo.parseBoolean("true"));
140+
141+ assertTrue(DatatypeIo.parseBoolean("\n\rtrue\u0020\t"));
142+
143+ try{
144+ DatatypeIo.parseBoolean("yes");
145+ fail();
146+ }catch(IllegalArgumentException e){
147+ assert true;
148+ }
149+
150+ try{
151+ DatatypeIo.parseBoolean("");
152+ fail();
153+ }catch(IllegalArgumentException e){
154+ assert true;
155+ }
156+
157+ return;
158+ }
159+
160+ /**
161+ * Test of parseInt method, of class DatatypeIo.
162+ */
163+ @Test
164+ public void testParseInt() {
165+ System.out.println("parseInt");
166+
167+ int result;
168+
169+ result = DatatypeIo.parseInt("0");
170+ assertEquals(0, result);
171+
172+ result = DatatypeIo.parseInt("+0");
173+ assertEquals(0, result);
174+
175+ result = DatatypeIo.parseInt("-0");
176+ assertEquals(0, result);
177+
178+ result = DatatypeIo.parseInt("1");
179+ assertEquals(1, result);
180+
181+ result = DatatypeIo.parseInt("+1");
182+ assertEquals(1, result);
183+
184+ result = DatatypeIo.parseInt("-1");
185+ assertEquals(-1, result);
186+
187+ result = DatatypeIo.parseInt("999");
188+ assertEquals(999, result);
189+
190+ result = DatatypeIo.parseInt("-9999");
191+ assertEquals(-9999, result);
192+
193+ result = DatatypeIo.parseInt("-2147483648");
194+ assertEquals(Integer.MIN_VALUE, result);
195+
196+ result = DatatypeIo.parseInt("2147483647");
197+ assertEquals(Integer.MAX_VALUE, result);
198+
199+ result = DatatypeIo.parseInt("\n\r999\u0020\t");
200+ assertEquals(999, result);
201+
202+ try{
203+ DatatypeIo.parseInt("?");
204+ fail();
205+ }catch(NumberFormatException e){
206+ assert true;
207+ }
208+
209+ try{
210+ DatatypeIo.parseInt("-2147483649");
211+ fail();
212+ }catch(NumberFormatException e){
213+ assert true;
214+ }
215+
216+ try{
217+ DatatypeIo.parseInt("2147483648");
218+ fail();
219+ }catch(NumberFormatException e){
220+ assert true;
221+ }
222+
223+ try{
224+ DatatypeIo.parseInt("3.14");
225+ fail();
226+ }catch(NumberFormatException e){
227+ assert true;
228+ }
229+
230+ return;
231+ }
232+
233+ /**
234+ * Test of parseFloat method, of class DatatypeIo.
235+ */
236+ @Test
237+ public void testParseFloat() {
238+ System.out.println("parseFloat");
239+
240+ float result;
241+
242+ result = DatatypeIo.parseFloat("0.0");
243+ assertEquals(0.0f, result, 0.0f);
244+
245+ result = DatatypeIo.parseFloat("+0.0");
246+ assertEquals(0.0f, result, 0.0f);
247+
248+ result = DatatypeIo.parseFloat("-0.0");
249+ assertEquals(-0.0f, result, 0.0f);
250+
251+ result = DatatypeIo.parseFloat("-123.45");
252+ assertEquals(-123.45f, result, 0.0f);
253+
254+ result = DatatypeIo.parseFloat("654.32");
255+ assertEquals(654.32f, result, 0.0f);
256+
257+ result = DatatypeIo.parseFloat("2.718281828459045");
258+ assertEquals((float)StrictMath.E, result, 0.0f);
259+
260+ result = DatatypeIo.parseFloat("3.141592653589793");
261+ assertEquals((float)StrictMath.PI, result, 0.0f);
262+
263+ result = DatatypeIo.parseFloat("1.401298464324817E-45");
264+ assertEquals(Float.MIN_VALUE, result, 0.0f);
265+
266+ result = DatatypeIo.parseFloat("1.1754943508222875E-38");
267+ assertEquals(Float.MIN_NORMAL, result, 0.0f);
268+
269+ result = DatatypeIo.parseFloat("3.4028234663852886E38");
270+ assertEquals(Float.MAX_VALUE, result, 0.0f);
271+
272+ result = DatatypeIo.parseFloat("2E3");
273+ assertEquals(2000.0f, result, 0.0f);
274+
275+ result = DatatypeIo.parseFloat("2.3E4");
276+ assertEquals(23000.0f, result, 0.0f);
277+
278+ result = DatatypeIo.parseFloat("2.3e4");
279+ assertEquals(23000.0f, result, 0.0f);
280+
281+ result = DatatypeIo.parseFloat("2.3E+4");
282+ assertEquals(23000.0f, result, 0.0f);
283+
284+ result = DatatypeIo.parseFloat("2.3E-4");
285+ assertEquals(0.00023f, result, 0.0f);
286+
287+ result = DatatypeIo.parseFloat("INF");
288+ assertEquals(Float.POSITIVE_INFINITY, result, 0.0f);
289+
290+ result = DatatypeIo.parseFloat("-INF");
291+ assertEquals(Float.NEGATIVE_INFINITY, result, 0.0f);
292+
293+ try{
294+ DatatypeIo.parseFloat("+INF");
295+ fail();
296+ }catch(NumberFormatException e){
297+ assert true;
298+ }
299+
300+ try{
301+ DatatypeIo.parseFloat("Infinity");
302+ fail();
303+ }catch(NumberFormatException e){
304+ assert true;
305+ }
306+
307+ result = DatatypeIo.parseFloat("NaN");
308+ assertTrue(Float.isNaN(result));
309+
310+ result = DatatypeIo.parseFloat("\n\r1.2\u0020\t");
311+ assertEquals(1.2f, result, 0.0f);
312+
313+ try{
314+ DatatypeIo.parseFloat("?");
315+ fail();
316+ }catch(NumberFormatException e){
317+ assert true;
318+ }
319+
320+ try{
321+ DatatypeIo.parseFloat("0x1.0p0");
322+ fail();
323+ }catch(NumberFormatException e){
324+ assert true;
325+ }
326+
327+ return;
328+ }
329+
330+ /**
331+ * Test of trim method, of class DatatypeIo.
332+ */
333+ @Test
334+ public void testTrim() {
335+ System.out.println("trim");
336+
337+ CharSequence txt;
338+ CharSequence result;
339+
340+ txt = "abc";
341+ result = DatatypeIo.xsdTrim(txt);
342+ assertEquals("abc", result.toString());
343+
344+ txt = "";
345+ result = DatatypeIo.xsdTrim(txt);
346+ assertEquals("", result.toString());
347+
348+ txt = " abc ";
349+ result = DatatypeIo.xsdTrim(txt);
350+ assertEquals("abc", result.toString());
351+
352+ txt = " abc";
353+ result = DatatypeIo.xsdTrim(txt);
354+ assertEquals("abc", result.toString());
355+
356+ txt = "abc ";
357+ result = DatatypeIo.xsdTrim(txt);
358+ assertEquals("abc", result.toString());
359+
360+ txt = " a b c ";
361+ result = DatatypeIo.xsdTrim(txt);
362+ assertEquals("a b c", result.toString());
363+
364+ txt = "\n\rabc\u0020\t";
365+ result = DatatypeIo.xsdTrim(txt);
366+ assertEquals("abc", result.toString());
367+
368+ return;
369+ }
370+
371+ /**
372+ * Test of isWhitespace method, of class DatatypeIo.
373+ */
374+ @Test
375+ public void testIsWhitespace() {
376+ System.out.println("isWhitespace");
377+
378+ assertTrue(DatatypeIo.isXsdWhitespace('\u0020'));
379+ assertTrue(DatatypeIo.isXsdWhitespace('\n'));
380+ assertTrue(DatatypeIo.isXsdWhitespace('\r'));
381+ assertTrue(DatatypeIo.isXsdWhitespace('\t'));
382+ assertFalse(DatatypeIo.isXsdWhitespace('X'));
383+ assertFalse(DatatypeIo.isXsdWhitespace('\u0001'));
384+
385+ return;
386+ }
387+
388+}
--- /dev/null
+++ b/src/test/java/jp/sfjp/mikutoga/xml/DomUtilsTest.java
@@ -0,0 +1,213 @@
1+/*
2+@see https://www.w3.org/TR/xmlschema-2/
3+ */
4+
5+package jp.sfjp.mikutoga.xml;
6+
7+import javax.xml.parsers.DocumentBuilder;
8+import javax.xml.parsers.DocumentBuilderFactory;
9+import javax.xml.parsers.ParserConfigurationException;
10+import org.junit.After;
11+import org.junit.AfterClass;
12+import org.junit.Before;
13+import org.junit.BeforeClass;
14+import org.junit.Test;
15+import static org.junit.Assert.*;
16+import org.w3c.dom.Document;
17+import org.w3c.dom.Element;
18+
19+/**
20+ *
21+ */
22+public class DomUtilsTest {
23+
24+ private static final DocumentBuilderFactory FACTORY =
25+ DocumentBuilderFactory.newInstance();
26+ private static final DocumentBuilder BUILDER;
27+
28+ private static final String TESTELEM = "testelem";
29+ private static final String TESTATTR = "testattr";
30+
31+ private static Element getTestAttredElem(String attrVal){
32+ Document doc = BUILDER.newDocument();
33+ Element elem = doc.createElement(TESTELEM);
34+ elem.setAttribute(TESTATTR, attrVal);
35+ return elem;
36+ }
37+
38+ static{
39+ try{
40+ BUILDER = FACTORY.newDocumentBuilder();
41+ }catch(ParserConfigurationException e){
42+ throw new ExceptionInInitializerError(e);
43+ }
44+ }
45+
46+ public DomUtilsTest() {
47+ }
48+
49+ @BeforeClass
50+ public static void setUpClass() throws ParserConfigurationException{
51+ }
52+
53+ @AfterClass
54+ public static void tearDownClass() {
55+ }
56+
57+ @Before
58+ public void setUp() {
59+ }
60+
61+ @After
62+ public void tearDown() {
63+ }
64+
65+ /**
66+ * Test of getBooleanAttr method, of class DomUtils.
67+ */
68+ @Test
69+ public void testGetBooleanAttr() throws Exception {
70+ System.out.println("getBooleanAttr");
71+
72+ boolean result;
73+ Element elem;
74+
75+ elem = getTestAttredElem("true");
76+ result = DomUtils.getBooleanAttr(elem, TESTATTR);
77+ assertTrue(result);
78+
79+ elem = getTestAttredElem("false");
80+ result = DomUtils.getBooleanAttr(elem, TESTATTR);
81+ assertFalse(result);
82+
83+ elem = getTestAttredElem("0");
84+ result = DomUtils.getBooleanAttr(elem, TESTATTR);
85+ assertFalse(result);
86+
87+ elem = getTestAttredElem("1");
88+ result = DomUtils.getBooleanAttr(elem, TESTATTR);
89+ assertTrue(result);
90+
91+ elem = getTestAttredElem("\n\rtrue\u0020\t");
92+ result = DomUtils.getBooleanAttr(elem, TESTATTR);
93+ assertTrue(result);
94+
95+ elem = getTestAttredElem("?");
96+ try{
97+ DomUtils.getBooleanAttr(elem, TESTATTR);
98+ fail();
99+ }catch(TogaXmlException e){
100+ assert true;
101+ }
102+
103+ return;
104+ }
105+
106+ /**
107+ * Test of getIntegerAttr method, of class DomUtils.
108+ */
109+ @Test
110+ public void testGetIntegerAttr() throws TogaXmlException {
111+ System.out.println("getIntegerAttr");
112+
113+ int result;
114+ Element elem;
115+
116+ elem = getTestAttredElem("0");
117+ result = DomUtils.getIntegerAttr(elem, TESTATTR);
118+ assertEquals(0, result);
119+
120+ elem = getTestAttredElem("1");
121+ result = DomUtils.getIntegerAttr(elem, TESTATTR);
122+ assertEquals(1, result);
123+
124+ elem = getTestAttredElem("-1");
125+ result = DomUtils.getIntegerAttr(elem, TESTATTR);
126+ assertEquals(-1, result);
127+
128+ elem = getTestAttredElem("999");
129+ result = DomUtils.getIntegerAttr(elem, TESTATTR);
130+ assertEquals(999, result);
131+
132+ elem = getTestAttredElem("-9999");
133+ result = DomUtils.getIntegerAttr(elem, TESTATTR);
134+ assertEquals(-9999, result);
135+
136+ elem = getTestAttredElem("\n\r999\u0020\t");
137+ result = DomUtils.getIntegerAttr(elem, TESTATTR);
138+ assertEquals(999, result);
139+
140+ elem = getTestAttredElem("?");
141+ try{
142+ result = DomUtils.getIntegerAttr(elem, TESTATTR);
143+ fail();
144+ }catch(TogaXmlException e){
145+ assert true;
146+ }
147+
148+ return;
149+ }
150+
151+ /**
152+ * Test of getFloatAttr method, of class DomUtils.
153+ */
154+ @Test
155+ public void testGetFloatAttr() throws TogaXmlException {
156+ System.out.println("getFloatAttr");
157+
158+ float result;
159+ Element elem;
160+
161+ elem = getTestAttredElem("0.0");
162+ result = DomUtils.getFloatAttr(elem, TESTATTR);
163+ assertEquals(0.0f, result, 0.0f);
164+
165+ elem = getTestAttredElem("-0.0");
166+ result = DomUtils.getFloatAttr(elem, TESTATTR);
167+ assertEquals(0.0f, result, 0.0f);
168+ assertEquals("-0.0", Float.toString(result));
169+
170+ elem = getTestAttredElem("-123.456");
171+ result = DomUtils.getFloatAttr(elem, TESTATTR);
172+ assertEquals(-123.456f, result, 0.0f);
173+
174+ elem = getTestAttredElem("654.321");
175+ result = DomUtils.getFloatAttr(elem, TESTATTR);
176+ assertEquals(654.321f, result, 0.0f);
177+
178+ elem = getTestAttredElem("2.3E4");
179+ result = DomUtils.getFloatAttr(elem, TESTATTR);
180+ assertEquals(23000.0f, result, 0.0f);
181+
182+ elem = getTestAttredElem("INF");
183+ result = DomUtils.getFloatAttr(elem, TESTATTR);
184+ assertEquals(Float.POSITIVE_INFINITY, result, 0.0f);
185+
186+ elem = getTestAttredElem("+INF");
187+ try{
188+ DomUtils.getFloatAttr(elem, TESTATTR);
189+ fail();
190+ }catch(TogaXmlException e){
191+ assert true;
192+ }
193+
194+ elem = getTestAttredElem("NaN");
195+ result = DomUtils.getFloatAttr(elem, TESTATTR);
196+ assertTrue(Float.isNaN(result));
197+
198+ elem = getTestAttredElem("\n\r123.456\u0020\t");
199+ result = DomUtils.getFloatAttr(elem, TESTATTR);
200+ assertEquals(123.456f, result, 0.0f);
201+
202+ elem = getTestAttredElem("?");
203+ try{
204+ DomUtils.getFloatAttr(elem, TESTATTR);
205+ fail();
206+ }catch(TogaXmlException e){
207+ assert true;
208+ }
209+
210+ return;
211+ }
212+
213+}
Show on old repository browser