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