View Javadoc
1   package org.apache.mina.core.buffer;
2   
3   import static org.junit.Assert.assertEquals;
4   
5   import org.junit.Test;
6   
7   public class IoBufferHexDumperTest {
8   
9   	@Test
10  	public void checkHexDumpLength() {
11  		IoBuffer buf = IoBuffer.allocate(5000);
12  
13  		for (int i = 0; i < 20; i++) {
14  			buf.putShort((short) 0xF0A0);
15  		}
16  
17  		buf.flip();
18  
19  		/* special case */
20  		assertEquals(0, buf.getHexDump(0).length());
21  
22  		/* no truncate needed */
23  		assertEquals(buf.limit() * 3 - 1, buf.getHexDump().length());
24  		assertEquals((Math.min(300, buf.limit()) * 3) - 1, buf.getHexDump(300).length());
25  
26  		/* must truncate */
27  		assertEquals((7 * 3) - 1, buf.getHexDump(7).length());
28  		assertEquals((10 * 3) - 1, buf.getHexDump(10).length());
29  		assertEquals((30 * 3) - 1, buf.getHexDump(30).length());
30  
31  	}
32  
33  	@Test
34  	public void checkPrettyHexDumpLength() {
35  		IoBuffer buf = IoBuffer.allocate(5000);
36  
37  		for (int i = 0; i < 20; i++) {
38  			buf.putShort((short) 0xF0A0);
39  		}
40  
41  		buf.flip();
42  
43  		String[] dump = buf.getHexDump(50, true).split("\\n");
44  		
45  		assertEquals(4, dump.length);
46  	}
47  }