2 * License : The MIT License
3 * Copyright(c) 2009 olyutorskii
6 package jp.osdn.jindolf.parser.content;
9 import org.junit.After;
10 import org.junit.AfterClass;
11 import org.junit.Before;
12 import org.junit.BeforeClass;
13 import org.junit.Test;
15 import static org.junit.Assert.*;
19 public class DecodedContentTest {
21 public DecodedContentTest() {
25 public static void setUpClass() throws Exception{
29 public static void tearDownClass() throws Exception{
37 public void tearDown() {
41 * Test of Constructor, of class DecodedContent.
44 public void testConstructor(){
45 System.out.println("Constructor");
47 DecodedContent content;
49 content = new DecodedContent();
50 assertEquals("", content.toString());
52 content = new DecodedContent("abc");
53 assertEquals("abc", content.toString());
55 content = new DecodedContent(128);
56 assertEquals("", content.toString());
58 content = new DecodedContent(0);
59 assertEquals("", content.toString());
60 content.append("abc");
61 assertEquals("abc", content.toString());
64 Object o = new DecodedContent(-1);
66 }catch(NegativeArraySizeException e){
75 * Test of init method, of class DecodedContent.
78 public void testInit(){
79 System.out.println("init");
81 DecodedContent content;
83 content = new DecodedContent();
84 content.append("abc");
85 content.addDecodeError((byte)0xff);
86 content.append("def");
87 assertEquals("abc?def", content.toString());
88 assertEquals(1, content.getDecodeErrorList().size());
91 assertEquals("", content.toString());
92 assertEquals(0, content.getDecodeErrorList().size());
95 assertEquals("X", content.toString());
101 * Test of hasDecodeError method, of class DecodedContent.
104 public void testHasDecodeError(){
105 System.out.println("hasDecodeError");
107 DecodedContent content;
109 content = new DecodedContent();
110 assertFalse(content.hasDecodeError());
113 assertFalse(content.hasDecodeError());
115 content.addDecodeError((byte)0xff);
116 assertTrue(content.hasDecodeError());
119 assertTrue(content.hasDecodeError());
122 assertFalse(content.hasDecodeError());
125 assertFalse(content.hasDecodeError());
127 content = new DecodedContent();
128 List<DecodeErrorInfo> list = content.getDecodeErrorList();
129 assertEquals(0, list.size());
130 assertFalse(content.hasDecodeError());
136 * Test of getDecodeErrorList method, of class DecodedContent.
139 public void testGetDecodeErrorList(){
140 System.out.println("getDecodeErrorList");
142 DecodedContent content;
143 List<DecodeErrorInfo> list;
145 content = new DecodedContent();
146 list = content.getDecodeErrorList();
147 assertEquals(0, list.size());
149 content.append("abc");
150 list = content.getDecodeErrorList();
151 assertEquals(0, list.size());
153 content.addDecodeError((byte)0xff);
154 list = content.getDecodeErrorList();
155 assertEquals(1, list.size());
157 content.append("def");
158 list = content.getDecodeErrorList();
159 assertEquals(1, list.size());
161 content.addDecodeError((byte)0x03, (byte)0x04);
162 list = content.getDecodeErrorList();
163 assertEquals(2, list.size());
169 * Test of getRawContent method, of class DecodedContent.
172 public void testGetRawContent(){
173 System.out.println("getRawContent");
175 DecodedContent content;
177 content = new DecodedContent();
178 assertEquals("", content.getRawContent().toString());
181 assertEquals("a", content.getRawContent().toString());
183 content.addDecodeError((byte)0xff);
184 assertEquals("a?", content.getRawContent().toString());
187 assertEquals("a?b", content.getRawContent().toString());
189 assertEquals(content.toString(), content.getRawContent().toString());
195 * Test of charAt method, of class DecodedContent.
198 public void testCharAt(){
199 System.out.println("charAt");
201 DecodedContent content;
203 content = new DecodedContent();
204 content.append("12345");
205 assertEquals('1', content.charAt(0));
206 assertEquals('3', content.charAt(2));
207 assertEquals('5', content.charAt(4));
212 }catch(IndexOutOfBoundsException e){
220 }catch(IndexOutOfBoundsException e){
229 * Test of length method, of class DecodedContent.
232 public void testLength(){
233 System.out.println("length");
235 DecodedContent content;
237 content = new DecodedContent();
238 assertEquals(0, content.length());
240 content.append("12345");
241 assertEquals(5, content.length());
243 content.addDecodeError((byte)0xff);
244 assertEquals(6, content.length());
247 assertEquals(0, content.length());
253 * Test of subSequence method, of class DecodedContent.
256 public void testSubSequence(){
257 System.out.println("subSequence");
259 DecodedContent content;
261 content = new DecodedContent();
263 content.append("12345");
264 assertEquals("234", content.subSequence(1, 4).toString());
267 content.subSequence(-1, 4);
269 }catch(IndexOutOfBoundsException e){
275 content.subSequence(1, 6);
277 }catch(IndexOutOfBoundsException e){
283 content.subSequence(4, 1);
285 }catch(IndexOutOfBoundsException e){
294 * Test of subContent method, of class DecodedContent.
297 public void testSubContent(){
298 System.out.println("subContent");
300 DecodedContent content;
302 content = new DecodedContent();
304 content.append("12345");
305 assertEquals("234", content.subContent(1, 4).toString());
308 content.subContent(-1, 4);
310 }catch(IndexOutOfBoundsException e){
316 content.subContent(1, 6);
318 }catch(IndexOutOfBoundsException e){
324 content.subContent(4, 1);
326 }catch(IndexOutOfBoundsException e){
331 content = new DecodedContent();
332 content.append("ab");
333 content.addDecodeError((byte)0x01);
334 content.append("de");
335 content = content.subContent(1,4);
336 assertEquals("b?d", content.toString());
338 List<DecodeErrorInfo> list = content.getDecodeErrorList();
339 assertEquals(1, list.size());
340 assertEquals((byte)0x01, list.get(0).getRawByte1st());
346 * Test of append method, of class DecodedContent.
349 public void testAppend_char(){
350 System.out.println("append");
352 DecodedContent content;
354 content = new DecodedContent();
356 assertEquals("a", content.toString());
362 * Test of append method, of class DecodedContent.
365 public void testAppend_CharSequence(){
366 System.out.println("append");
368 DecodedContent content;
370 content = new DecodedContent();
371 CharSequence seq = "abc";
373 assertEquals("abc", content.toString());
374 content.append(null);
375 assertEquals("abcnull", content.toString());
381 * Test of append method, of class DecodedContent.
384 public void testAppend_3args_1(){
385 System.out.println("append");
387 DecodedContent content;
389 content = new DecodedContent();
390 content.append("abc");
391 assertEquals("abc", content.toString());
393 CharSequence seq = "12345";
394 content.append(seq, 1, 4);
395 assertEquals("abc234", content.toString());
396 content.append((CharSequence)null, 1, 2);
397 assertEquals("abc234null", content.toString());
403 * Test of append method, of class DecodedContent.
406 public void testAppend_3args_2(){
407 System.out.println("append");
409 DecodedContent content;
411 content = new DecodedContent();
412 content.append("abc");
414 DecodedContent other;
415 other = new DecodedContent();
416 other.append("12345");
418 content.append(other, 1, 4);
419 assertEquals("abc234", content.toString());
421 content = new DecodedContent();
422 content.append("abc");
424 other = new DecodedContent();
425 other.addDecodeError((byte)0x01);
426 other.addDecodeError((byte)0x02);
427 other.addDecodeError((byte)0x03);
428 other.addDecodeError((byte)0x04);
429 other.addDecodeError((byte)0x05);
431 content.append(other, 1, 4);
432 assertEquals("abc???", content.toString());
434 List<DecodeErrorInfo> list = content.getDecodeErrorList();
435 assertEquals(3, list.size());
437 DecodeErrorInfo info;
440 assertEquals(3, info.getCharPosition());
441 assertEquals((byte)0x02, info.getRawByte1st());
443 assertEquals(4, info.getCharPosition());
444 assertEquals((byte)0x03, info.getRawByte1st());
446 assertEquals(5, info.getCharPosition());
447 assertEquals((byte)0x04, info.getRawByte1st());
453 * Test of append method, of class DecodedContent.
456 public void testAppend_3args_3(){
457 System.out.println("append");
459 DecodedContent content;
461 content = new DecodedContent();
462 content.append("abc");
463 assertEquals("abc", content.toString());
465 char[] seq = {'1','2','3','4','5',};
466 content.append(seq, 1, 3);
467 assertEquals("abc234", content.toString());
468 content.append((char[])null, 1, 2);
469 assertEquals("abc234null", content.toString());
475 * Test of addDecodeError method, of class DecodedContent.
478 public void testAddDecodeError_byte(){
479 System.out.println("addDecodeError");
481 DecodedContent content;
483 content = new DecodedContent();
484 content.append("abc");
485 content.addDecodeError((byte)0xfe);
486 content.append("def");
487 content.addDecodeError((byte)0xff);
489 assertEquals("abc?def?", content.toString());
490 List<DecodeErrorInfo> list = content.getDecodeErrorList();
491 assertEquals(2, list.size());
493 DecodeErrorInfo info;
496 assertEquals(3, list.get(0).getCharPosition());
497 assertFalse(info.has2nd());
498 assertEquals((byte)0xfe, info.getRawByte1st());
501 assertEquals(7, info.getCharPosition());
502 assertFalse(info.has2nd());
503 assertEquals((byte)0xff, info.getRawByte1st());
509 * Test of addDecodeError method, of class DecodedContent.
512 public void testAddDecodeError_byte_byte(){
513 System.out.println("addDecodeError");
515 DecodedContent content;
517 content = new DecodedContent();
518 content.append("abc");
519 content.addDecodeError((byte)0x01, (byte)0x02);
520 content.append("def");
521 content.addDecodeError((byte)0xfe, (byte)0xff);
523 assertEquals("abc?def?", content.toString());
524 List<DecodeErrorInfo> list = content.getDecodeErrorList();
525 assertEquals(2, list.size());
527 DecodeErrorInfo info;
530 assertEquals(3, list.get(0).getCharPosition());
531 assertTrue(info.has2nd());
532 assertEquals((byte)0x01, info.getRawByte1st());
533 assertEquals((byte)0x02, info.getRawByte2nd());
536 assertEquals(7, info.getCharPosition());
537 assertTrue(info.has2nd());
538 assertEquals((byte)0xfe, info.getRawByte1st());
539 assertEquals((byte)0xff, info.getRawByte2nd());
545 * Test of toString method, of class DecodedContent.
548 public void testToString(){
549 System.out.println("toString");
551 DecodedContent content;
553 content = new DecodedContent();
554 content.append("abc");
555 content.addDecodeError((byte)0x01, (byte)0x02);
556 content.append("def");
557 content.addDecodeError((byte)0xfe, (byte)0xff);
559 assertEquals("abc?def?", content.toString());
560 assertEquals(content.getRawContent().toString(), content.toString());
566 * Test of appendGappedErrorInfo method, of class DecodedContent.
569 public void testAppendGappedErrorInfo(){
570 System.out.println("appendGappedErrorInfo");
572 DecodedContent sourceContent;
573 sourceContent = new DecodedContent();
574 for(int pos = 0; pos <= 50; pos += 10){
575 sourceContent.append("123456789");
576 sourceContent.addDecodeError((byte)0x00);
579 List<DecodeErrorInfo> result;
580 result = DecodedContent.appendGappedErrorInfo(sourceContent, 15, 35, null, -100);
581 assertNotNull(result);
582 assertEquals(2, result.size());
583 assertEquals(119, result.get(0).getCharPosition());
584 assertEquals(129, result.get(1).getCharPosition());
590 * Test of ensureCapacity method, of class DecodedContent.
593 public void testEnsureCapacity(){
594 System.out.println("ensureCapacity");
596 DecodedContent content;
598 content = new DecodedContent("abc");
599 content.ensureCapacity(-1);
600 content.ensureCapacity(0);
601 content.ensureCapacity(1);
602 content.ensureCapacity(5);
603 content.append("def");
604 assertEquals("abcdef", content.toString());
606 content = new DecodedContent();
607 content.ensureCapacity(5);
608 content.append("abc");
609 assertEquals("abc", content.toString());
615 * Test of setCharAt method, of class DecodedContent.
618 public void testSetCharAt(){
619 System.out.println("setCharAt");
621 DecodedContent content;
623 content = new DecodedContent("abc");
624 content.setCharAt(1, 'B');
625 assertEquals("aBc", content.toString());
627 content = new DecodedContent("a");
628 content.addDecodeError((byte)0xff);
630 assertEquals("a?c", content.toString());
631 content.setCharAt(1, 'B');
632 assertEquals("aBc", content.toString());
633 assertEquals(1, content.getDecodeErrorList().size());
634 assertEquals(1, content.getDecodeErrorList().get(0).getCharPosition());
635 assertEquals((byte)0xff, content.getDecodeErrorList().get(0).getRawByte1st());
637 content = new DecodedContent("abc");
639 content.setCharAt(-1, 'B');
641 }catch(IndexOutOfBoundsException e){
645 content.setCharAt(10, 'B');
647 }catch(IndexOutOfBoundsException e){