OSDN Git Service

abff4ecbc8f5c2ee249518d1491893c678425217
[mikutoga/TogaGem.git] / src / test / java / jp / sfjp / mikutoga / xml / BasicXmlExporterTest.java
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  * @author silva
17  */
18 public class BasicXmlExporterTest {
19
20     public BasicXmlExporterTest() {
21     }
22
23     @BeforeClass
24     public static void setUpClass() {
25     }
26
27     @AfterClass
28     public static void tearDownClass() {
29     }
30
31     @Before
32     public void setUp() {
33     }
34
35     @After
36     public void tearDown() {
37     }
38
39     /**
40      * Test of append method, of class BasicXmlExporter.
41      */
42     @Test
43     public void testAppend() {
44         System.out.println("setAppendable");
45
46         BasicXmlExporter instance;
47         Appendable app;
48         StringBuffer buf;
49         
50         instance = new BasicXmlExporter();
51
52         try{
53             instance.append(null);
54             fail();
55         }catch(NullPointerException e){
56             assert true;
57         }catch(IOException e){
58             fail();
59         }
60
61         buf = new StringBuffer();
62         app = buf;
63
64         instance.setAppendable(app);
65
66         try{
67             instance.append("abc");
68             instance.append('d');
69             instance.append("abcdef", 4, 5);
70         }catch(IOException e){
71             fail();
72         }
73
74         assertEquals("abcde", buf.toString());
75
76         try{
77             instance.flush();
78             instance.close();
79         }catch(IOException e){
80             fail();
81         }
82
83         return;
84     }
85
86     @Test
87     public void testPutXsdInt() throws IOException{
88         System.out.println("putXsdInt");
89
90         BasicXmlExporter instance;
91         StringBuffer buf;
92
93         instance = new BasicXmlExporter();
94
95         buf = new StringBuffer();
96         instance.setAppendable(buf);
97         instance.putXsdInt(-1).putCh(',').putXsdInt(0).putCh(',').putXsdInt(1);
98         assertEquals("-1,0,1", buf.toString());
99
100         buf = new StringBuffer();
101         instance.setAppendable(buf);
102         instance.putXsdInt(-999).putCh(',').putXsdInt(9999);
103         assertEquals("-999,9999", buf.toString());
104
105         buf = new StringBuffer();
106         instance.setAppendable(buf);
107         instance.putXsdInt(Integer.MIN_VALUE).putCh(',').putXsdInt(Integer.MAX_VALUE);
108         assertEquals("-2147483648,2147483647", buf.toString());
109
110         return;
111     }
112
113     @Test
114     public void testPutXsdFloat() throws IOException{
115         System.out.println("putXsdFloat");
116
117         BasicXmlExporter instance;
118         StringBuffer buf;
119
120         instance = new BasicXmlExporter();
121
122         buf = new StringBuffer();
123         instance.setAppendable(buf);
124         instance.putXsdFloat(-1.0f).putCh(',')
125                 .putXsdFloat(-0.0f).putCh(',')
126                 .putXsdFloat(0.0f).putCh(',')
127                 .putXsdFloat(1.0f);
128         assertEquals("-1.0,-0.0,0.0,1.0", buf.toString());
129
130         buf = new StringBuffer();
131         instance.setAppendable(buf);
132         instance.putXsdFloat(Float.NEGATIVE_INFINITY).putCh(',')
133                 .putXsdFloat(Float.POSITIVE_INFINITY).putCh(',')
134                 .putXsdFloat(Float.NaN);
135         assertEquals("-INF,INF,NaN", buf.toString());
136
137         buf = new StringBuffer();
138         instance.setAppendable(buf);
139         instance.putXsdFloat(Float.MIN_VALUE).putCh(',')
140                 .putXsdFloat(Float.MIN_NORMAL).putCh(',')
141                 .putXsdFloat(Float.MAX_VALUE);
142         assertEquals("1.4E-45,1.17549435E-38,3.4028235E38", buf.toString());
143
144         buf = new StringBuffer();
145         instance.setAppendable(buf);
146         instance.putXsdFloat(0.001f);
147         assertEquals("0.001", buf.toString()); // fuzzy "0.0010" on JDK1.6
148
149         buf = new StringBuffer();
150         instance.setAppendable(buf);
151         instance.putXsdFloat(StrictMath.nextDown(0.001f));
152         assertEquals("9.999999E-4", buf.toString());
153
154         buf = new StringBuffer();
155         instance.setAppendable(buf);
156         instance.putXsdFloat(10000000.0f);
157         assertEquals("1.0E7", buf.toString());
158
159         buf = new StringBuffer();
160         instance.setAppendable(buf);
161         instance.putXsdFloat(StrictMath.nextDown(10000000.0f));
162         assertEquals("9999999.0", buf.toString());
163
164         buf = new StringBuffer();
165         instance.setAppendable(buf);
166         instance.putXsdFloat((float)StrictMath.E).putCh(',')
167                 .putXsdFloat((float)StrictMath.PI);
168         assertEquals("2.7182817,3.1415927", buf.toString());
169
170         return;
171     }
172
173 }