OSDN Git Service

topic/jiocema とマージ
[jindolf/JinParser.git] / src / test / java / jp / sourceforge / jindolf / parser / DecodeErrorInfoTest.java
1 /*
2  * License : The MIT License
3  * Copyright(c) 2009 olyutorskii
4  */
5
6 package jp.sourceforge.jindolf.parser;
7
8 import org.junit.After;
9 import org.junit.AfterClass;
10 import org.junit.Before;
11 import org.junit.BeforeClass;
12 import org.junit.Test;
13
14 import static org.junit.Assert.*;
15
16 /**
17  */
18 public class DecodeErrorInfoTest {
19
20     public DecodeErrorInfoTest() {
21     }
22
23     @BeforeClass
24     public static void setUpClass() throws Exception{
25     }
26
27     @AfterClass
28     public static void tearDownClass() throws Exception{
29     }
30
31     @Before
32     public void setUp() {
33     }
34
35     @After
36     public void tearDown() {
37     }
38
39     /**
40      * Test of Constructor
41      */
42     @Test
43     public void testConstructor(){
44         System.out.println("Constructor");
45
46         new DecodeErrorInfo(99, (byte)0xfe);
47         new DecodeErrorInfo(999, (byte)0x87, (byte)0x40);
48
49         new DecodeErrorInfo(0, (byte)0xfe);
50         new DecodeErrorInfo(0, (byte)0x87, (byte)0x40);
51
52         try{
53             new DecodeErrorInfo(-1, (byte)0xfe);
54             fail();
55         }catch(IndexOutOfBoundsException e){
56         }catch(Throwable e){
57             fail();
58         }
59
60         try{
61             new DecodeErrorInfo(-1, (byte)0x87, (byte)0x40);
62             fail();
63         }catch(IndexOutOfBoundsException e){
64         }catch(Throwable e){
65             fail();
66         }
67
68         return;
69     }
70
71     /**
72      * Test of getCharPosition method, of class DecodeErrorInfo.
73      */
74     @Test
75     public void testGetCharPosition(){
76         System.out.println("getCharPosition");
77
78         DecodeErrorInfo info;
79
80         info = new DecodeErrorInfo(99, (byte)0xfe);
81         assertEquals(99, info.getCharPosition());
82
83         info = new DecodeErrorInfo(999, (byte)0x87, (byte)0x40);
84         assertEquals(999, info.getCharPosition());
85
86         return;
87     }
88
89     /**
90      * Test of has2nd method, of class DecodeErrorInfo.
91      */
92     @Test
93     public void testHas2nd(){
94         System.out.println("has2nd");
95
96         DecodeErrorInfo info;
97
98         info = new DecodeErrorInfo(99, (byte)0xfe);
99         assertFalse(info.has2nd());
100
101         info = new DecodeErrorInfo(999, (byte)0x87, (byte)0x40);
102         assertTrue(info.has2nd());
103
104         return;
105     }
106
107     /**
108      * Test of getRawByte1st method, of class DecodeErrorInfo.
109      */
110     @Test
111     public void testGetRawByte1st(){
112         System.out.println("getRawByte1st");
113
114         DecodeErrorInfo info;
115
116         info = new DecodeErrorInfo(99, (byte)0xfe);
117         assertEquals((byte)0xfe, info.getRawByte1st());
118
119         info = new DecodeErrorInfo(999, (byte)0x87, (byte)0x40);
120         assertEquals((byte)0x87, info.getRawByte1st());
121
122         return;
123     }
124
125     /**
126      * Test of getRawByte2nd method, of class DecodeErrorInfo.
127      */
128     @Test
129     public void testGetRawByte2nd(){
130         System.out.println("getRawByte2nd");
131
132         DecodeErrorInfo info;
133
134         info = new DecodeErrorInfo(99, (byte)0xfe);
135         try{
136             info.getRawByte2nd();
137             fail();
138         }catch(IllegalStateException e){
139         }catch(Throwable e){
140             fail();
141         }
142
143         info = new DecodeErrorInfo(999, (byte)0x87, (byte)0x40);
144         assertEquals((byte)0x40, info.getRawByte2nd());
145
146         return;
147     }
148
149     /**
150      * Test of createGappedClone method, of class DecodeErrorInfo.
151      */
152     @Test
153     public void testCreateGappedClone(){
154         System.out.println("createGappedClone");
155
156         DecodeErrorInfo info;
157
158         info = new DecodeErrorInfo(99, (byte)0xfe);
159         info = info.createGappedClone(1);
160         assertEquals(98, info.getCharPosition());
161
162         info = new DecodeErrorInfo(999, (byte)0x87, (byte)0x40);
163         info = info.createGappedClone(1);
164         assertEquals(998, info.getCharPosition());
165
166         info = new DecodeErrorInfo(99, (byte)0xfe);
167         info = info.createGappedClone(-1);
168         assertEquals(100, info.getCharPosition());
169
170         info = new DecodeErrorInfo(999, (byte)0x87, (byte)0x40);
171         info = info.createGappedClone(-1);
172         assertEquals(1000, info.getCharPosition());
173
174         info = new DecodeErrorInfo(99, (byte)0xfe);
175         info = info.createGappedClone(99);
176         assertEquals(0, info.getCharPosition());
177
178         info = new DecodeErrorInfo(999, (byte)0x87, (byte)0x40);
179         info = info.createGappedClone(999);
180         assertEquals(0, info.getCharPosition());
181
182         info = new DecodeErrorInfo(99, (byte)0xfe);
183         try{
184             info = info.createGappedClone(100);
185             fail();
186         }catch(IndexOutOfBoundsException e){
187         }catch(Throwable e){
188             fail();
189         }
190
191         info = new DecodeErrorInfo(999, (byte)0x87, (byte)0x40);
192         try{
193             info = info.createGappedClone(1000);
194             fail();
195         }catch(IndexOutOfBoundsException e){
196         }catch(Throwable e){
197             fail();
198         }
199
200         return;
201     }
202
203     /**
204      * Test of toString method, of class DecodeErrorInfo.
205      */
206     @Test
207     public void testToString(){
208         System.out.println("toString");
209
210         DecodeErrorInfo info;
211
212         info = new DecodeErrorInfo(99, (byte)0x09);
213         assertEquals("start:99 09", info.toString());
214
215         info = new DecodeErrorInfo(99, (byte)0xfe);
216         assertEquals("start:99 fe", info.toString());
217
218         info = new DecodeErrorInfo(999, (byte)0x08, (byte)0x09);
219         assertEquals("start:999 08:09", info.toString());
220
221         info = new DecodeErrorInfo(999, (byte)0x87, (byte)0x40);
222         assertEquals("start:999 87:40", info.toString());
223
224         return;
225     }
226
227     /**
228      * Test of POS_COMPARATOR.
229      */
230     @Test
231     public void testCompare(){
232         System.out.println("POS_COMPARATOR");
233
234         DecodeErrorInfo info;
235         DecodeErrorInfo other;
236
237         info  = new DecodeErrorInfo(99, (byte)0xfe);
238         other = new DecodeErrorInfo(98, (byte)0xfe);
239         assertTrue(DecodeErrorInfo.POS_COMPARATOR.compare(info, other) > 0);
240
241         info  = new DecodeErrorInfo(99, (byte)0xfe);
242         other = new DecodeErrorInfo(100, (byte)0xfe);
243         assertTrue(DecodeErrorInfo.POS_COMPARATOR.compare(info, other) < 0);
244
245         info  = new DecodeErrorInfo(99, (byte)0xfe);
246         other = new DecodeErrorInfo(99, (byte)0xfe);
247         assertTrue(DecodeErrorInfo.POS_COMPARATOR.compare(info, other) == 0);
248
249         assertTrue(DecodeErrorInfo.POS_COMPARATOR.compare(null, other) < 0);
250         assertTrue(DecodeErrorInfo.POS_COMPARATOR.compare(info, null) > 0);
251         assertTrue(DecodeErrorInfo.POS_COMPARATOR.compare(null, null) == 0);
252
253         return;
254     }
255
256 }