Skip to content

Commit c98343b

Browse files
committed
Add test for msgpack#130
1 parent 8461d9d commit c98343b

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package org.msgpack.unpacker;
2+
3+
import org.junit.Before;
4+
import org.junit.Test;
5+
import org.msgpack.MessagePack;
6+
7+
import java.io.ByteArrayInputStream;
8+
import java.io.ByteArrayOutputStream;
9+
import java.io.IOException;
10+
11+
import static org.junit.Assert.*;
12+
13+
public class TestMessagePackUnpacker {
14+
private MessagePack msgpack;
15+
16+
@Before
17+
public void setup() {
18+
msgpack = new MessagePack();
19+
}
20+
21+
@Test
22+
public void testStr8() throws IOException {
23+
// Deserialize a data that another platform serialized a string "xxx...xxx" (length: 128).
24+
ByteArrayOutputStream out = new ByteArrayOutputStream();
25+
// 0xD9: str8, 0x80: length: 128
26+
out.write(new byte[] {(byte) 0xD9, (byte) 0x80});
27+
for (int i = 0; i < 128; i++) {
28+
// 0x78: 'x'
29+
out.write(0x78);
30+
}
31+
Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(out.toByteArray()));
32+
String string = unpacker.readString();
33+
assertEquals(128, string.length());
34+
for (int i = 0; i < 128; i++) {
35+
assertEquals('x', string.charAt(i));
36+
}
37+
}
38+
}

0 commit comments

Comments
 (0)