OSDN Git Service

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