0
|
1 package org.msgpack.template;
|
|
2
|
|
3 import static org.junit.Assert.assertEquals;
|
|
4
|
|
5 import java.io.ByteArrayInputStream;
|
|
6 import java.io.ByteArrayOutputStream;
|
|
7 import java.math.BigInteger;
|
|
8
|
|
9 import org.junit.Test;
|
|
10 import org.msgpack.MessagePack;
|
|
11 import org.msgpack.TestSet;
|
|
12 import org.msgpack.packer.BufferPacker;
|
|
13 import org.msgpack.packer.Packer;
|
|
14 import org.msgpack.unpacker.BufferUnpacker;
|
|
15 import org.msgpack.unpacker.Unpacker;
|
|
16
|
|
17
|
|
18 public class TestBigIntegerTemplate {
|
|
19
|
|
20 @Test
|
|
21 public void testPackUnpack() throws Exception {
|
|
22 new TestPackUnpack().testBigInteger();
|
|
23 }
|
|
24
|
|
25 @Test
|
|
26 public void testPackBufferUnpack() throws Exception {
|
|
27 new TestPackBufferUnpack().testBigInteger();
|
|
28 }
|
|
29
|
|
30 @Test
|
|
31 public void testBufferPackBufferUnpack() throws Exception {
|
|
32 new TestBufferPackBufferUnpack().testBigInteger();
|
|
33 }
|
|
34
|
|
35 @Test
|
|
36 public void testBufferPackUnpack() throws Exception {
|
|
37 new TestBufferPackUnpack().testBigInteger();
|
|
38 }
|
|
39
|
|
40 private static class TestPackUnpack extends TestSet {
|
|
41 @Test @Override
|
|
42 public void testBigInteger() throws Exception {
|
|
43 super.testBigInteger();
|
|
44 }
|
|
45
|
|
46 @Override
|
|
47 public void testBigInteger(BigInteger v) throws Exception {
|
|
48 MessagePack msgpack = new MessagePack();
|
|
49 Template<BigInteger> tmpl = BigIntegerTemplate.instance;
|
|
50 ByteArrayOutputStream out = new ByteArrayOutputStream();
|
|
51 Packer packer = msgpack.createPacker(out);
|
|
52 tmpl.write(packer, v);
|
|
53 byte[] bytes = out.toByteArray();
|
|
54 Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes));
|
|
55 unpacker.resetReadByteCount();
|
|
56 BigInteger ret = tmpl.read(unpacker, null);
|
|
57 assertEquals(v, ret);
|
|
58 assertEquals(bytes.length, unpacker.getReadByteCount());
|
|
59 }
|
|
60 }
|
|
61
|
|
62 private static class TestPackBufferUnpack extends TestSet {
|
|
63 @Test @Override
|
|
64 public void testBigInteger() throws Exception {
|
|
65 super.testBigInteger();
|
|
66 }
|
|
67
|
|
68 @Override
|
|
69 public void testBigInteger(BigInteger v) throws Exception {
|
|
70 MessagePack msgpack = new MessagePack();
|
|
71 Template<BigInteger> tmpl = BigIntegerTemplate.instance;
|
|
72 ByteArrayOutputStream out = new ByteArrayOutputStream();
|
|
73 Packer packer = msgpack.createPacker(out);
|
|
74 tmpl.write(packer, v);
|
|
75 byte[] bytes = out.toByteArray();
|
|
76 BufferUnpacker unpacker = msgpack.createBufferUnpacker(bytes);
|
|
77 unpacker.resetReadByteCount();
|
|
78 BigInteger ret = tmpl.read(unpacker, null);
|
|
79 assertEquals(v, ret);
|
|
80 assertEquals(bytes.length, unpacker.getReadByteCount());
|
|
81 }
|
|
82 }
|
|
83
|
|
84 private static class TestBufferPackBufferUnpack extends TestSet {
|
|
85 @Test @Override
|
|
86 public void testBigInteger() throws Exception {
|
|
87 super.testBigInteger();
|
|
88 }
|
|
89
|
|
90 @Override
|
|
91 public void testBigInteger(BigInteger v) throws Exception {
|
|
92 MessagePack msgpack = new MessagePack();
|
|
93 Template<BigInteger> tmpl = BigIntegerTemplate.instance;
|
|
94 BufferPacker packer = msgpack.createBufferPacker();
|
|
95 tmpl.write(packer, v);
|
|
96 byte[] bytes = packer.toByteArray();
|
|
97 BufferUnpacker unpacker = msgpack.createBufferUnpacker(bytes);
|
|
98 unpacker.resetReadByteCount();
|
|
99 BigInteger ret = tmpl.read(unpacker, null);
|
|
100 assertEquals(v, ret);
|
|
101 assertEquals(bytes.length, unpacker.getReadByteCount());
|
|
102 }
|
|
103 }
|
|
104
|
|
105 private static class TestBufferPackUnpack extends TestSet {
|
|
106 @Test @Override
|
|
107 public void testBigInteger() throws Exception {
|
|
108 super.testBigInteger();
|
|
109 }
|
|
110
|
|
111 @Override
|
|
112 public void testBigInteger(BigInteger v) throws Exception {
|
|
113 MessagePack msgpack = new MessagePack();
|
|
114 Template<BigInteger> tmpl = BigIntegerTemplate.instance;
|
|
115 BufferPacker packer = msgpack.createBufferPacker();
|
|
116 tmpl.write(packer, v);
|
|
117 byte[] bytes = packer.toByteArray();
|
|
118 Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes));
|
|
119 unpacker.resetReadByteCount();
|
|
120 BigInteger ret = tmpl.read(unpacker, null);
|
|
121 assertEquals(v, ret);
|
|
122 assertEquals(bytes.length, unpacker.getReadByteCount());
|
|
123 }
|
|
124 }
|
|
125 }
|