blob: c2ad73e71db3a3d52ab7ea4bd88ebb25e963dc85 [file] [log] [blame]
David Reissea2cba82009-03-30 21:35:00 +00001/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19
Jake Farrell5d02b802014-01-07 21:42:01 -050020#define _USE_MATH_DEFINES
David Reissdb0ea152008-02-18 01:49:37 +000021#include <cmath>
Konrad Grochowskia84e1392015-10-16 11:22:10 +020022#include <iomanip>
23#include <sstream>
Roger Meier49ff8b12012-04-13 09:12:31 +000024#include <thrift/protocol/TJSONProtocol.h>
cyy316723a2019-01-05 16:35:14 +080025#include <memory>
James E. King, III82ae9572017-08-05 12:23:54 -040026#include <thrift/transport/TBufferTransports.h>
David Reissdb0ea152008-02-18 01:49:37 +000027#include "gen-cpp/DebugProtoTest_types.h"
28
Claudius Heine5ef662b2015-06-24 10:03:50 +020029#define BOOST_TEST_MODULE JSONProtoTest
30#include <boost/test/unit_test.hpp>
David Reissdb0ea152008-02-18 01:49:37 +000031
Claudius Heine5ef662b2015-06-24 10:03:50 +020032using namespace thrift::test::debug;
James E. King, III82ae9572017-08-05 12:23:54 -040033using namespace apache::thrift;
Claudius Heine5ef662b2015-06-24 10:03:50 +020034using apache::thrift::transport::TMemoryBuffer;
35using apache::thrift::protocol::TJSONProtocol;
David Reissdb0ea152008-02-18 01:49:37 +000036
cyy316723a2019-01-05 16:35:14 +080037static std::shared_ptr<OneOfEach> ooe;
David Reissdb0ea152008-02-18 01:49:37 +000038
Claudius Heine5ef662b2015-06-24 10:03:50 +020039void testCaseSetup_1() {
40 ooe.reset(new OneOfEach);
41 ooe->im_true = true;
42 ooe->im_false = false;
43 ooe->a_bite = 0x7f;
44 ooe->integer16 = 27000;
45 ooe->integer32 = 1 << 24;
46 ooe->integer64 = (uint64_t)6000 * 1000 * 1000;
47 ooe->double_precision = M_PI;
48 ooe->some_characters = "JSON THIS! \"\1";
49 ooe->zomg_unicode = "\xd7\n\a\t";
50 ooe->base64 = "\1\2\3\255";
51}
David Reissdb0ea152008-02-18 01:49:37 +000052
Claudius Heine5ef662b2015-06-24 10:03:50 +020053BOOST_AUTO_TEST_CASE(test_json_proto_1) {
54 testCaseSetup_1();
David Reissdb0ea152008-02-18 01:49:37 +000055
Claudius Heine5ef662b2015-06-24 10:03:50 +020056 const std::string expected_result(
57 "{\"1\":{\"tf\":1},\"2\":{\"tf\":0},\"3\":{\"i8\":127},\"4\":{\"i16\":27000},"
58 "\"5\":{\"i32\":16777216},\"6\":{\"i64\":6000000000},\"7\":{\"dbl\":3.1415926"
Wang Yaofu0433d172016-02-15 10:43:09 +080059 "535897931},\"8\":{\"str\":\"JSON THIS! \\\"\\u0001\"},\"9\":{\"str\":\"\xd7\\"
Claudius Heine5ef662b2015-06-24 10:03:50 +020060 "n\\u0007\\t\"},\"10\":{\"tf\":0},\"11\":{\"str\":\"AQIDrQ\"},\"12\":{\"lst\""
61 ":[\"i8\",3,1,2,3]},\"13\":{\"lst\":[\"i16\",3,1,2,3]},\"14\":{\"lst\":[\"i64"
62 "\",3,1,2,3]}}");
63
64 const std::string result(apache::thrift::ThriftJSONString(*ooe));
65
66 BOOST_CHECK_MESSAGE(!expected_result.compare(result),
67 "Expected:\n" << expected_result << "\nGotten:\n" << result);
68}
69
cyy316723a2019-01-05 16:35:14 +080070static std::shared_ptr<Nesting> n;
Claudius Heine5ef662b2015-06-24 10:03:50 +020071
72void testCaseSetup_2() {
73 testCaseSetup_1();
74
75 n.reset(new Nesting);
76 n->my_ooe = *ooe;
77 n->my_ooe.integer16 = 16;
78 n->my_ooe.integer32 = 32;
79 n->my_ooe.integer64 = 64;
80 n->my_ooe.double_precision = (std::sqrt(5.0) + 1) / 2;
81 n->my_ooe.some_characters = ":R (me going \"rrrr\")";
82 n->my_ooe.zomg_unicode = "\xd3\x80\xe2\x85\xae\xce\x9d\x20\xd0\x9d\xce"
83 "\xbf\xe2\x85\xbf\xd0\xbe\xc9\xa1\xd0\xb3\xd0"
84 "\xb0\xcf\x81\xe2\x84\x8e\x20\xce\x91\x74\x74"
85 "\xce\xb1\xe2\x85\xbd\xce\xba\xc7\x83\xe2\x80"
86 "\xbc";
87 n->my_bonk.type = 31337;
88 n->my_bonk.message = "I am a bonk... xor!";
89}
90
91BOOST_AUTO_TEST_CASE(test_json_proto_2) {
92 testCaseSetup_2();
93
94 const std::string expected_result(
95 "{\"1\":{\"rec\":{\"1\":{\"i32\":31337},\"2\":{\"str\":\"I am a bonk... xor"
96 "!\"}}},\"2\":{\"rec\":{\"1\":{\"tf\":1},\"2\":{\"tf\":0},\"3\":{\"i8\":127"
97 "},\"4\":{\"i16\":16},\"5\":{\"i32\":32},\"6\":{\"i64\":64},\"7\":{\"dbl\":"
Wang Yaofu0433d172016-02-15 10:43:09 +080098 "1.6180339887498949},\"8\":{\"str\":\":R (me going \\\"rrrr\\\")\"},\"9\":{"
Claudius Heine5ef662b2015-06-24 10:03:50 +020099 "\"str\":\"ӀⅮΝ Нοⅿоɡгаρℎ Αttαⅽκǃ‼\"},\"10\":{\"tf\":0},\"11\":{\"str\":\""
100 "AQIDrQ\"},\"12\":{\"lst\":[\"i8\",3,1,2,3]},\"13\":{\"lst\":[\"i16\",3,1,2"
101 ",3]},\"14\":{\"lst\":[\"i64\",3,1,2,3]}}}}"
102 );
103
104 const std::string result(apache::thrift::ThriftJSONString(*n));
105
106 BOOST_CHECK_MESSAGE(!expected_result.compare(result),
107 "Expected:\n" << expected_result << "\nGotten:\n" << result);
108}
109
cyy316723a2019-01-05 16:35:14 +0800110static std::shared_ptr<HolyMoley> hm;
Claudius Heine5ef662b2015-06-24 10:03:50 +0200111
112void testCaseSetup_3() {
113 testCaseSetup_2();
114
115 hm.reset(new HolyMoley);
116
117 hm->big.push_back(*ooe);
118 hm->big.push_back(n->my_ooe);
119 hm->big[0].a_bite = 0x22;
120 hm->big[1].a_bite = 0x33;
David Reissdb0ea152008-02-18 01:49:37 +0000121
122 std::vector<std::string> stage1;
123 stage1.push_back("and a one");
124 stage1.push_back("and a two");
Claudius Heine5ef662b2015-06-24 10:03:50 +0200125 hm->contain.insert(stage1);
David Reissdb0ea152008-02-18 01:49:37 +0000126 stage1.clear();
127 stage1.push_back("then a one, two");
128 stage1.push_back("three!");
129 stage1.push_back("FOUR!!");
Claudius Heine5ef662b2015-06-24 10:03:50 +0200130 hm->contain.insert(stage1);
David Reissdb0ea152008-02-18 01:49:37 +0000131 stage1.clear();
Claudius Heine5ef662b2015-06-24 10:03:50 +0200132 hm->contain.insert(stage1);
David Reissdb0ea152008-02-18 01:49:37 +0000133
134 std::vector<Bonk> stage2;
Claudius Heine5ef662b2015-06-24 10:03:50 +0200135 hm->bonks["nothing"] = stage2;
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100136 stage2.resize(stage2.size() + 1);
David Reissdb0ea152008-02-18 01:49:37 +0000137 stage2.back().type = 1;
138 stage2.back().message = "Wait.";
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100139 stage2.resize(stage2.size() + 1);
David Reissdb0ea152008-02-18 01:49:37 +0000140 stage2.back().type = 2;
141 stage2.back().message = "What?";
Claudius Heine5ef662b2015-06-24 10:03:50 +0200142 hm->bonks["something"] = stage2;
David Reissdb0ea152008-02-18 01:49:37 +0000143 stage2.clear();
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100144 stage2.resize(stage2.size() + 1);
David Reissdb0ea152008-02-18 01:49:37 +0000145 stage2.back().type = 3;
146 stage2.back().message = "quoth";
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100147 stage2.resize(stage2.size() + 1);
David Reissdb0ea152008-02-18 01:49:37 +0000148 stage2.back().type = 4;
149 stage2.back().message = "the raven";
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100150 stage2.resize(stage2.size() + 1);
David Reissdb0ea152008-02-18 01:49:37 +0000151 stage2.back().type = 5;
152 stage2.back().message = "nevermore";
Claudius Heine5ef662b2015-06-24 10:03:50 +0200153 hm->bonks["poe"] = stage2;
154}
David Reissdb0ea152008-02-18 01:49:37 +0000155
Claudius Heine5ef662b2015-06-24 10:03:50 +0200156BOOST_AUTO_TEST_CASE(test_json_proto_3) {
157 testCaseSetup_3();
158
159 const std::string expected_result(
160 "{\"1\":{\"lst\":[\"rec\",2,{\"1\":{\"tf\":1},\"2\":{\"tf\":0},\"3\":{\"i8\":"
161 "34},\"4\":{\"i16\":27000},\"5\":{\"i32\":16777216},\"6\":{\"i64\":6000000000"
Wang Yaofu0433d172016-02-15 10:43:09 +0800162 "},\"7\":{\"dbl\":3.1415926535897931},\"8\":{\"str\":\"JSON THIS! \\\"\\u0001"
Claudius Heine5ef662b2015-06-24 10:03:50 +0200163 "\"},\"9\":{\"str\":\"\xd7\\n\\u0007\\t\"},\"10\":{\"tf\":0},\"11\":{\"str\":"
164 "\"AQIDrQ\"},\"12\":{\"lst\":[\"i8\",3,1,2,3]},\"13\":{\"lst\":[\"i16\",3,1,2"
165 ",3]},\"14\":{\"lst\":[\"i64\",3,1,2,3]}},{\"1\":{\"tf\":1},\"2\":{\"tf\":0},"
166 "\"3\":{\"i8\":51},\"4\":{\"i16\":16},\"5\":{\"i32\":32},\"6\":{\"i64\":64},"
Wang Yaofu0433d172016-02-15 10:43:09 +0800167 "\"7\":{\"dbl\":1.6180339887498949},\"8\":{\"str\":\":R (me going \\\"rrrr\\\""
Claudius Heine5ef662b2015-06-24 10:03:50 +0200168 ")\"},\"9\":{\"str\":\"ӀⅮΝ Нοⅿоɡгаρℎ Αttαⅽκǃ‼\"},\"10\":{\"tf\":0},\"11\":{"
169 "\"str\":\"AQIDrQ\"},\"12\":{\"lst\":[\"i8\",3,1,2,3]},\"13\":{\"lst\":[\"i16"
170 "\",3,1,2,3]},\"14\":{\"lst\":[\"i64\",3,1,2,3]}}]},\"2\":{\"set\":[\"lst\",3"
171 ",[\"str\",0],[\"str\",2,\"and a one\",\"and a two\"],[\"str\",3,\"then a one"
172 ", two\",\"three!\",\"FOUR!!\"]]},\"3\":{\"map\":[\"str\",\"lst\",3,{\"nothin"
173 "g\":[\"rec\",0],\"poe\":[\"rec\",3,{\"1\":{\"i32\":3},\"2\":{\"str\":\"quoth"
174 "\"}},{\"1\":{\"i32\":4},\"2\":{\"str\":\"the raven\"}},{\"1\":{\"i32\":5},\""
175 "2\":{\"str\":\"nevermore\"}}],\"something\":[\"rec\",2,{\"1\":{\"i32\":1},\""
176 "2\":{\"str\":\"Wait.\"}},{\"1\":{\"i32\":2},\"2\":{\"str\":\"What?\"}}]}]}}"
177 );
178
179 const std::string result(apache::thrift::ThriftJSONString(*hm));
180
181 BOOST_CHECK_MESSAGE(!expected_result.compare(result),
182 "Expected:\n" << expected_result << "\nGotten:\n" << result);
183}
184
185BOOST_AUTO_TEST_CASE(test_json_proto_4) {
186 testCaseSetup_1();
David Reissdb0ea152008-02-18 01:49:37 +0000187
cyy316723a2019-01-05 16:35:14 +0800188 std::shared_ptr<TMemoryBuffer> buffer(new TMemoryBuffer());
189 std::shared_ptr<TJSONProtocol> proto(new TJSONProtocol(buffer));
David Reissdb0ea152008-02-18 01:49:37 +0000190
Claudius Heine5ef662b2015-06-24 10:03:50 +0200191 ooe->write(proto.get());
David Reissdb0ea152008-02-18 01:49:37 +0000192 OneOfEach ooe2;
193 ooe2.read(proto.get());
194
Claudius Heine5ef662b2015-06-24 10:03:50 +0200195 BOOST_CHECK(*ooe == ooe2);
196}
David Reissdb0ea152008-02-18 01:49:37 +0000197
Claudius Heine5ef662b2015-06-24 10:03:50 +0200198BOOST_AUTO_TEST_CASE(test_json_proto_5) {
199 testCaseSetup_3();
David Reissdb0ea152008-02-18 01:49:37 +0000200
cyy316723a2019-01-05 16:35:14 +0800201 std::shared_ptr<TMemoryBuffer> buffer(new TMemoryBuffer());
202 std::shared_ptr<TJSONProtocol> proto(new TJSONProtocol(buffer));
Claudius Heine5ef662b2015-06-24 10:03:50 +0200203
204 hm->write(proto.get());
David Reissdb0ea152008-02-18 01:49:37 +0000205 HolyMoley hm2;
206 hm2.read(proto.get());
207
Claudius Heine5ef662b2015-06-24 10:03:50 +0200208 BOOST_CHECK(*hm == hm2);
David Reissdb0ea152008-02-18 01:49:37 +0000209
Christian Lavoiecbf87cb2010-11-28 14:34:26 +0000210 hm2.big[0].a_bite = 0x00;
David Reiss4a8f46c2008-03-07 20:12:07 +0000211
Claudius Heine5ef662b2015-06-24 10:03:50 +0200212 BOOST_CHECK(*hm != hm2);
213}
David Reiss4a8f46c2008-03-07 20:12:07 +0000214
Claudius Heine5ef662b2015-06-24 10:03:50 +0200215BOOST_AUTO_TEST_CASE(test_json_proto_6) {
David Reissdb0ea152008-02-18 01:49:37 +0000216 Doubles dub;
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100217 dub.nan = HUGE_VAL / HUGE_VAL;
David Reissdb0ea152008-02-18 01:49:37 +0000218 dub.inf = HUGE_VAL;
219 dub.neginf = -HUGE_VAL;
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100220 dub.repeating = 10.0 / 3.0;
David Reissdb0ea152008-02-18 01:49:37 +0000221 dub.big = 1E+305;
Roger Meier22888ce2014-02-09 11:31:02 +0100222 dub.tiny = 1E-305;
David Reissdb0ea152008-02-18 01:49:37 +0000223 dub.zero = 0.0;
224 dub.negzero = -0.0;
David Reissdb0ea152008-02-18 01:49:37 +0000225
Claudius Heine5ef662b2015-06-24 10:03:50 +0200226 const std::string expected_result(
227 "{\"1\":{\"dbl\":\"NaN\"},\"2\":{\"dbl\":\"Infinity\"},\"3\":{\"dbl\":\"-Infi"
Wang Yaofu0433d172016-02-15 10:43:09 +0800228 "nity\"},\"4\":{\"dbl\":3.3333333333333335},\"5\":{\"dbl\":9.9999999999999994e+"
Claudius Heine5ef662b2015-06-24 10:03:50 +0200229 "304},\"6\":{\"dbl\":1e-305},\"7\":{\"dbl\":0},\"8\":{\"dbl\":-0}}"
230 );
231
232 const std::string result(apache::thrift::ThriftJSONString(dub));
233
234 BOOST_CHECK_MESSAGE(!expected_result.compare(result),
235 "Expected:\n" << expected_result << "\nGotten:\n" << result);
236}
237
238BOOST_AUTO_TEST_CASE(test_json_proto_7) {
cyy316723a2019-01-05 16:35:14 +0800239 std::shared_ptr<TMemoryBuffer> buffer(new TMemoryBuffer());
240 std::shared_ptr<TJSONProtocol> proto(new TJSONProtocol(buffer));
David Reiss4a8f46c2008-03-07 20:12:07 +0000241
242 Base64 base;
243 base.a = 123;
244 base.b1 = "1";
245 base.b2 = "12";
246 base.b3 = "123";
247 base.b4 = "1234";
248 base.b5 = "12345";
249 base.b6 = "123456";
250
251 base.write(proto.get());
252 Base64 base2;
253 base2.read(proto.get());
254
Claudius Heine5ef662b2015-06-24 10:03:50 +0200255 BOOST_CHECK(base == base2);
David Reissdb0ea152008-02-18 01:49:37 +0000256}
Claudius Heine8f11f522015-07-01 10:35:38 +0200257
258BOOST_AUTO_TEST_CASE(test_json_proto_8) {
259 const char* json_string =
260 "{\"1\":{\"tf\":1},\"2\":{\"tf\":0},\"3\":{\"i8\":127},\"4\":{\"i16\":27000},"
261 "\"5\":{\"i32\":16.77216},\"6\":{\"i64\":6000000000},\"7\":{\"dbl\":3.1415926"
Wang Yaofu0433d172016-02-15 10:43:09 +0800262 "535897931},\"8\":{\"str\":\"JSON THIS! \\\"\\u0001\"},\"9\":{\"str\":\"\xd7\\"
Claudius Heine8f11f522015-07-01 10:35:38 +0200263 "n\\u0007\\t\"},\"10\":{\"tf\":0},\"11\":{\"str\":\"AQIDrQ\"},\"12\":{\"lst\""
264 ":[\"i8\",3,1,2,3]},\"13\":{\"lst\":[\"i16\",3,1,2,3]},\"14\":{\"lst\":[\"i64"
265 "\",3,1,2,3]}}";
266
James E. King, III7edc8fa2017-01-20 10:11:41 -0500267 const std::size_t bufSiz = strlen(json_string) * sizeof(char);
cyy316723a2019-01-05 16:35:14 +0800268 std::shared_ptr<TMemoryBuffer> buffer(new TMemoryBuffer(
James E. King, III7edc8fa2017-01-20 10:11:41 -0500269 (uint8_t*)(json_string), static_cast<uint32_t>(bufSiz)));
cyy316723a2019-01-05 16:35:14 +0800270 std::shared_ptr<TJSONProtocol> proto(new TJSONProtocol(buffer));
Claudius Heine8f11f522015-07-01 10:35:38 +0200271
272 OneOfEach ooe2;
273
274 BOOST_CHECK_THROW(ooe2.read(proto.get()),
275 apache::thrift::protocol::TProtocolException);
276}
Konrad Grochowskia84e1392015-10-16 11:22:10 +0200277
278static std::string toHexSequence(const std::string& str) {
279 std::stringstream ss;
280 ss << std::hex << std::setfill('0');
281 for (std::size_t i = 0; i < str.size(); i++) {
282 ss << "\\x" << int(uint8_t(str[i]));
283 }
284 return ss.str();
285}
286
287BOOST_AUTO_TEST_CASE(test_json_unicode_escaped) {
288 const char json_string[] =
289 "{\"1\":{\"tf\":1},\"2\":{\"tf\":0},\"3\":{\"i8\":127},\"4\":{\"i16\":27000},"
290 "\"5\":{\"i32\":16},\"6\":{\"i64\":6000000000},\"7\":{\"dbl\":3.1415926"
Wang Yaofu0433d172016-02-15 10:43:09 +0800291 "535897931},\"8\":{\"str\":\"JSON THIS!\"},\"9\":{\"str\":\"\\u0e01 \\ud835\\udd3e\"},"
Konrad Grochowskia84e1392015-10-16 11:22:10 +0200292 "\"10\":{\"tf\":0},\"11\":{\"str\":\"000000\"},\"12\":{\"lst\""
293 ":[\"i8\",3,1,2,3]},\"13\":{\"lst\":[\"i16\",3,1,2,3]},\"14\":{\"lst\":[\"i64"
294 "\",3,1,2,3]}}";
295 const char* expected_zomg_unicode = "\xe0\xb8\x81 \xf0\x9d\x94\xbe";
296
cyy316723a2019-01-05 16:35:14 +0800297 std::shared_ptr<TMemoryBuffer> buffer(new TMemoryBuffer(
Konrad Grochowskia84e1392015-10-16 11:22:10 +0200298 (uint8_t*)(json_string), sizeof(json_string)));
cyy316723a2019-01-05 16:35:14 +0800299 std::shared_ptr<TJSONProtocol> proto(new TJSONProtocol(buffer));
Konrad Grochowskia84e1392015-10-16 11:22:10 +0200300
301 OneOfEach ooe2;
302 ooe2.read(proto.get());
303 BOOST_CHECK_MESSAGE(!ooe2.zomg_unicode.compare(expected_zomg_unicode),
304 "Expected:\n" << toHexSequence(expected_zomg_unicode) << "\nGotten:\n"
305 << toHexSequence(ooe2.zomg_unicode));
306
307}
308
309BOOST_AUTO_TEST_CASE(test_json_unicode_escaped_missing_low_surrogate) {
310 const char json_string[] =
311 "{\"1\":{\"tf\":1},\"2\":{\"tf\":0},\"3\":{\"i8\":127},\"4\":{\"i16\":27000},"
312 "\"5\":{\"i32\":16},\"6\":{\"i64\":6000000000},\"7\":{\"dbl\":3.1415926"
Wang Yaofu0433d172016-02-15 10:43:09 +0800313 "535897931},\"8\":{\"str\":\"JSON THIS!\"},\"9\":{\"str\":\"\\ud835\"},"
Konrad Grochowskia84e1392015-10-16 11:22:10 +0200314 "\"10\":{\"tf\":0},\"11\":{\"str\":\"000000\"},\"12\":{\"lst\""
315 ":[\"i8\",3,1,2,3]},\"13\":{\"lst\":[\"i16\",3,1,2,3]},\"14\":{\"lst\":[\"i64"
316 "\",3,1,2,3]}}";
317
cyy316723a2019-01-05 16:35:14 +0800318 std::shared_ptr<TMemoryBuffer> buffer(new TMemoryBuffer(
Konrad Grochowskia84e1392015-10-16 11:22:10 +0200319 (uint8_t*)(json_string), sizeof(json_string)));
cyy316723a2019-01-05 16:35:14 +0800320 std::shared_ptr<TJSONProtocol> proto(new TJSONProtocol(buffer));
Konrad Grochowskia84e1392015-10-16 11:22:10 +0200321
322 OneOfEach ooe2;
323 BOOST_CHECK_THROW(ooe2.read(proto.get()),
324 apache::thrift::protocol::TProtocolException);
325}
326
327BOOST_AUTO_TEST_CASE(test_json_unicode_escaped_missing_hi_surrogate) {
328 const char json_string[] =
329 "{\"1\":{\"tf\":1},\"2\":{\"tf\":0},\"3\":{\"i8\":127},\"4\":{\"i16\":27000},"
330 "\"5\":{\"i32\":16},\"6\":{\"i64\":6000000000},\"7\":{\"dbl\":3.1415926"
Wang Yaofu0433d172016-02-15 10:43:09 +0800331 "535897931},\"8\":{\"str\":\"JSON THIS!\"},\"9\":{\"str\":\"\\udd3e\"},"
Konrad Grochowskia84e1392015-10-16 11:22:10 +0200332 "\"10\":{\"tf\":0},\"11\":{\"str\":\"000000\"},\"12\":{\"lst\""
333 ":[\"i8\",3,1,2,3]},\"13\":{\"lst\":[\"i16\",3,1,2,3]},\"14\":{\"lst\":[\"i64"
334 "\",3,1,2,3]}}";
335
cyy316723a2019-01-05 16:35:14 +0800336 std::shared_ptr<TMemoryBuffer> buffer(new TMemoryBuffer(
Konrad Grochowskia84e1392015-10-16 11:22:10 +0200337 (uint8_t*)(json_string), sizeof(json_string)));
cyy316723a2019-01-05 16:35:14 +0800338 std::shared_ptr<TJSONProtocol> proto(new TJSONProtocol(buffer));
Konrad Grochowskia84e1392015-10-16 11:22:10 +0200339
340 OneOfEach ooe2;
341 BOOST_CHECK_THROW(ooe2.read(proto.get()),
342 apache::thrift::protocol::TProtocolException);
343}