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