forked from json-iterator/java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestNative.java
More file actions
161 lines (133 loc) · 4.6 KB
/
TestNative.java
File metadata and controls
161 lines (133 loc) · 4.6 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
package com.jsoniter.output;
import junit.framework.TestCase;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.math.BigDecimal;
import java.math.BigInteger;
public class TestNative extends TestCase {
static {
// JsonStream.setMode(EncodingMode.REFLECTION_MODE);
}
private ByteArrayOutputStream baos;
private JsonStream stream;
public void setUp() {
baos = new ByteArrayOutputStream();
stream = new JsonStream(baos, 4096);
}
public void test_string() throws IOException {
stream = new JsonStream(baos, 32);
stream.writeVal("1234567890123456789012345678901234567890");
stream.close();
assertEquals("'1234567890123456789012345678901234567890'".replace('\'', '"'), baos.toString());
}
public void test_slash() throws IOException {
stream.writeVal("/\\");
stream.close();
assertEquals("\"/\\\\\"", baos.toString());
}
public void test_escape() throws IOException {
stream.writeVal("hel\nlo");
stream.close();
assertEquals("'hel\\nlo'".replace('\'', '"'), baos.toString());
}
public void test_utf8() throws IOException {
stream.writeVal("中文");
stream.close();
assertEquals("\"\\u4e2d\\u6587\"", baos.toString());
}
public void test_int() throws IOException {
stream.writeVal(100);
stream.close();
assertEquals("100", baos.toString());
}
public void test_boxed_int() throws IOException {
Object val = Integer.valueOf(100);
stream.writeVal(val);
stream.close();
assertEquals("100", baos.toString());
}
public void test_negative_int() throws IOException {
stream.writeVal(-100);
stream.close();
assertEquals("-100", baos.toString());
}
public void test_small_int() throws IOException {
stream.writeVal(3);
stream.close();
assertEquals("3", baos.toString());
}
public void test_large_int() throws IOException {
stream.writeVal(31415926);
stream.close();
assertEquals("31415926", baos.toString());
}
public void test_long() throws IOException {
stream.writeVal(100L);
stream.close();
assertEquals("100", baos.toString());
}
public void test_negative_long() throws IOException {
stream.writeVal(-100L);
stream.close();
assertEquals("-100", baos.toString());
}
public void test_short() throws IOException {
stream.writeVal(((short)555));
stream.close();
assertEquals("555", baos.toString());
assertEquals("555", JsonStream.serialize(new Short((short)555)));
}
public void test_no_decimal_float() throws IOException {
stream.writeVal(100f);
stream.close();
assertEquals("100", baos.toString());
}
public void test_float2() throws IOException {
stream.writeVal(0.000001f);
stream.close();
assertEquals("0.000001", baos.toString());
}
public void test_float3() throws IOException {
stream.writeVal(0.00001f);
stream.close();
assertEquals("0.00001", baos.toString());
}
public void test_big_float() throws IOException {
stream.writeVal((float)0x4ffffff);
stream.close();
assertEquals("83886080", baos.toString());
}
public void test_double() throws IOException {
stream.writeVal(1.001d);
stream.close();
assertEquals("1.001", baos.toString());
}
public void test_large_double() throws IOException {
stream.writeVal(Double.MAX_VALUE);
stream.close();
assertEquals("1.7976931348623157E308", baos.toString());
}
public void test_boolean() throws IOException {
stream.writeVal(true);
stream.writeVal(false);
stream.close();
assertEquals("truefalse".replace('\'', '"'), baos.toString());
}
public void test_big_decimal() throws IOException {
stream.writeVal(new BigDecimal("12.34"));
stream.close();
assertEquals("12.34".replace('\'', '"'), baos.toString());
}
public void test_big_integer() throws IOException {
stream.writeVal(new BigInteger("1234"));
stream.close();
assertEquals("1234".replace('\'', '"'), baos.toString());
}
public void test_raw() throws IOException {
stream = new JsonStream(baos, 32);
String val = "1234567890123456789012345678901234567890";
stream.writeRaw(val, val.length());
stream.close();
assertEquals(val.replace('\'', '"'), baos.toString());
}
}