2 * License : The MIT License
\r
3 * Copyright(c) 2009 olyutorskii
\r
6 package jp.sourceforge.jindolf.parser;
\r
8 import java.util.List;
\r
9 import org.junit.After;
\r
10 import org.junit.AfterClass;
\r
11 import org.junit.Before;
\r
12 import org.junit.BeforeClass;
\r
13 import org.junit.Test;
\r
14 import static org.junit.Assert.*;
\r
18 public class EntityConverterTest {
\r
20 public EntityConverterTest() {
\r
24 public static void setUpClass() throws Exception{
\r
28 public static void tearDownClass() throws Exception{
\r
32 public void setUp() {
\r
36 public void tearDown() {
\r
40 * Test of convert method, of class EntityConverter.
\r
43 public void testConvert(){
\r
44 System.out.println("convert");
\r
46 EntityConverter converter = new EntityConverter();
\r
48 DecodedContent from;
\r
49 DecodedContent result;
\r
51 from = new DecodedContent();
\r
52 from.append("a>b<c"d&e");
\r
53 result = converter.convert(from, 0, from.length());
\r
54 assertEquals("a>b<c\"d&e", result.toString());
\r
56 from = new DecodedContent();
\r
57 from.append("><"&");
\r
58 result = converter.convert(from, 0, from.length());
\r
59 assertEquals("><\"&", result.toString());
\r
61 from = new DecodedContent();
\r
62 from.append("12345");
\r
63 result = converter.convert(from, 1, 3);
\r
64 assertEquals("23", result.toString());
\r
66 from = new DecodedContent();
\r
67 from.append("12>45");
\r
68 result = converter.convert(from, 1, 7);
\r
69 assertEquals("2>4", result.toString());
\r
71 from = new DecodedContent();
\r
72 from.append("12>45");
\r
73 result = converter.convert(from, 3, 7);
\r
74 assertEquals("gt;4", result.toString());
\r
76 from = new DecodedContent();
\r
77 from.append("&gt;");
\r
78 result = converter.convert(from, 0, from.length());
\r
79 assertEquals(">", result.toString());
\r
81 from = new DecodedContent();
\r
82 from.append("a>b");
\r
83 result = converter.convert(from);
\r
84 assertEquals("a>b", result.toString());
\r
86 from = new DecodedContent();
\r
87 from.append("a>b");
\r
88 from.addDecodeError((byte)0x03);
\r
90 result = converter.convert(from);
\r
91 assertEquals("a>b?c", result.toString());
\r
92 assertTrue(result.hasDecodeError());
\r
93 List<DecodeErrorInfo> list = result.getDecodeErrorList();
\r
94 assertEquals(1, list.size());
\r
95 assertEquals((byte)0x03, list.get(0).getRawByte1st());
\r
97 from = new DecodedContent();
\r
99 result = converter.convert(from, 0, 0);
\r
100 assertEquals("", result.toString());
\r
102 from = new DecodedContent();
\r
103 from.append("a\\b");
\r
104 result = converter.convert(from, 0, from.length());
\r
105 assertEquals("a¥b", result.toString());
\r
107 from = new DecodedContent();
\r
108 from.append("abcde");
\r
109 SeqRange range = new SeqRange(1,4);
\r
110 result = converter.convert(from, range);
\r
111 assertEquals("bcd", result.toString());
\r
117 * Test of append method, of class EntityConverter.
\r
120 public void testAppend(){
\r
121 System.out.println("append");
\r
123 EntityConverter converter = new EntityConverter();
\r
124 DecodedContent target;
\r
125 DecodedContent from;
\r
126 DecodedContent result;
\r
128 target = new DecodedContent("abc");
\r
129 from = new DecodedContent("d>f");
\r
130 result = converter.append(target,from);
\r
131 assertEquals("abcd>f", result.toString());
\r
133 target = new DecodedContent("abc");
\r
134 from = new DecodedContent("d>fg<i");
\r
135 result = converter.append(target, from, 6, 12);
\r
136 assertEquals("abcg<i", result.toString());
\r
138 target = new DecodedContent("abc");
\r
139 from = new DecodedContent("d>fg<i");
\r
140 result = converter.append(target, from, new SeqRange(6, 12));
\r
141 assertEquals("abcg<i", result.toString());
\r
143 target = new DecodedContent();
\r
144 target.append('a');
\r
145 target.addDecodeError((byte)0xff);
\r
146 target.append('c');
\r
147 from = new DecodedContent();
\r
149 from.addDecodeError((byte)0xfe);
\r
151 result = converter.append(target, from);
\r
152 assertEquals("a?cd?f", result.toString());
\r
153 assertTrue(result.hasDecodeError());
\r
154 List<DecodeErrorInfo> list = result.getDecodeErrorList();
\r
155 assertEquals(2, list.size());
\r
156 assertEquals((byte)0xff, list.get(0).getRawByte1st());
\r
157 assertEquals((byte)0xfe, list.get(1).getRawByte1st());
\r
158 assertEquals(1, list.get(0).getCharPosition());
\r
159 assertEquals(4, list.get(1).getCharPosition());
\r