forked from msgpack/msgpack-java
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTestStreamPackStreamUnpack.java
More file actions
181 lines (156 loc) · 5.37 KB
/
TestStreamPackStreamUnpack.java
File metadata and controls
181 lines (156 loc) · 5.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
package org.msgpack;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.math.BigInteger;
import org.junit.Test;
import org.msgpack.packer.StreamPacker;
import org.msgpack.unpacker.StreamUnpacker;
public class TestStreamPackStreamUnpack extends TestSet {
@Test @Override
public void testBoolean() throws Exception {
super.testBoolean();
}
@Override
public void testBoolean(boolean v) throws Exception {
ByteArrayOutputStream out = new ByteArrayOutputStream();
StreamPacker packer = new StreamPacker(out);
packer.writeBoolean(v);
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
StreamUnpacker unpacker = new StreamUnpacker(in);
boolean ret = unpacker.readBoolean();
assertEquals(v, ret);
}
@Test @Override
public void testByte() throws Exception {
super.testByte();
}
@Override
public void testByte(byte v) throws Exception {
ByteArrayOutputStream out = new ByteArrayOutputStream();
StreamPacker packer = new StreamPacker(out);
packer.writeByte(v);
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
StreamUnpacker unpacker = new StreamUnpacker(in);
byte ret = unpacker.readByte();
assertEquals(v, ret);
}
@Test @Override
public void testShort() throws Exception {
super.testShort();
}
@Override
public void testShort(short v) throws Exception {
ByteArrayOutputStream out = new ByteArrayOutputStream();
StreamPacker packer = new StreamPacker(out);
packer.writeShort(v);
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
StreamUnpacker unpacker = new StreamUnpacker(in);
short ret = unpacker.readShort();
assertEquals(v, ret);
}
@Test @Override
public void testInteger() throws Exception {
super.testInteger();
}
@Override
public void testInteger(int v) throws Exception {
ByteArrayOutputStream out = new ByteArrayOutputStream();
StreamPacker packer = new StreamPacker(out);
packer.writeInt(v);
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
StreamUnpacker unpacker = new StreamUnpacker(in);
int ret = unpacker.readInt();
assertEquals(v, ret);
}
@Test @Override
public void testLong() throws Exception {
super.testLong();
}
@Override
public void testLong(long v) throws Exception {
ByteArrayOutputStream out = new ByteArrayOutputStream();
StreamPacker packer = new StreamPacker(out);
packer.writeLong(v);
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
StreamUnpacker unpacker = new StreamUnpacker(in);
long ret = unpacker.readLong();
assertEquals(v, ret);
}
@Override
public void testFloat(float v) throws Exception {
ByteArrayOutputStream out = new ByteArrayOutputStream();
StreamPacker packer = new StreamPacker(out);
packer.writeFloat(v);
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
StreamUnpacker unpacker = new StreamUnpacker(in);
float ret = unpacker.readFloat();
assertEquals(v, ret, 10e-10);
}
@Test @Override
public void testDouble() throws Exception {
super.testDouble();
}
@Override
public void testDouble(double v) throws Exception {
ByteArrayOutputStream out = new ByteArrayOutputStream();
StreamPacker packer = new StreamPacker(out);
packer.writeDouble(v);
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
StreamUnpacker unpacker = new StreamUnpacker(in);
double ret = unpacker.readDouble();
assertEquals(v, ret, 10e-10);
}
@Test @Override
public void testNil() throws Exception {
ByteArrayOutputStream out = new ByteArrayOutputStream();
StreamPacker packer = new StreamPacker(out);
packer.writeNil();
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
StreamUnpacker unpacker = new StreamUnpacker(in);
unpacker.readNil();
}
@Test @Override
public void testBigInteger() throws Exception {
super.testBigInteger();
}
@Override
public void testBigInteger(BigInteger v) throws Exception {
ByteArrayOutputStream out = new ByteArrayOutputStream();
StreamPacker packer = new StreamPacker(out);
packer.writeBigInteger(v);
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
StreamUnpacker unpacker = new StreamUnpacker(in);
BigInteger ret = unpacker.readBigInteger();
assertEquals(v, ret);
}
@Test @Override
public void testString() throws Exception {
super.testString();
}
@Override
public void testString(String v) throws Exception {
ByteArrayOutputStream out = new ByteArrayOutputStream();
StreamPacker packer = new StreamPacker(out);
packer.writeString(v);
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
StreamUnpacker unpacker = new StreamUnpacker(in);
String ret = unpacker.readString();
assertEquals(v, ret);
}
@Test @Override
public void testByteArray() throws Exception {
super.testByteArray();
}
@Override
public void testByteArray(byte[] v) throws Exception {
ByteArrayOutputStream out = new ByteArrayOutputStream();
StreamPacker packer = new StreamPacker(out);
packer.writeByteArray(v);
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
StreamUnpacker unpacker = new StreamUnpacker(in);
byte[] ret = unpacker.readByteArray();
assertArrayEquals(v, ret);
}
}