blob: 1a56e7edee21b0c3caa7f53e1fb52197468400fd [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 Reiss00dcccf2007-07-21 01:18:10 +000021#include <cmath>
22#include "gen-cpp/DebugProtoTest_types.h"
Roger Meier49ff8b12012-04-13 09:12:31 +000023#include <thrift/protocol/TDebugProtocol.h>
cyy316723a2019-01-05 16:35:14 +080024#include <memory>
David Reiss00dcccf2007-07-21 01:18:10 +000025
Claudius Heine5ef662b2015-06-24 10:03:50 +020026#define BOOST_TEST_MODULE DebugProtoTest
27#include <boost/test/unit_test.hpp>
David Reiss00dcccf2007-07-21 01:18:10 +000028
Claudius Heine5ef662b2015-06-24 10:03:50 +020029using namespace thrift::test::debug;
David Reiss00dcccf2007-07-21 01:18:10 +000030
cyy316723a2019-01-05 16:35:14 +080031static ::std::shared_ptr<OneOfEach> ooe;
David Reiss00dcccf2007-07-21 01:18:10 +000032
Claudius Heine5ef662b2015-06-24 10:03:50 +020033void testCaseSetup_1() {
34 ooe.reset(new OneOfEach);
35 ooe->im_true = true;
36 ooe->im_false = false;
37 ooe->a_bite = 0x7f;
38 ooe->integer16 = 27000;
39 ooe->integer32 = 1 << 24;
40 ooe->integer64 = (uint64_t)6000 * 1000 * 1000;
41 ooe->double_precision = M_PI;
42 ooe->some_characters = "Debug THIS!";
43 ooe->zomg_unicode = "\xd7\n\a\t";
44}
David Reiss00dcccf2007-07-21 01:18:10 +000045
Claudius Heine5ef662b2015-06-24 10:03:50 +020046BOOST_AUTO_TEST_CASE(test_debug_proto_1) {
47 testCaseSetup_1();
David Reiss00dcccf2007-07-21 01:18:10 +000048
Claudius Heine5ef662b2015-06-24 10:03:50 +020049 const std::string expected_result(
50 "OneOfEach {\n"
51 " 01: im_true (bool) = true,\n"
52 " 02: im_false (bool) = false,\n"
53 " 03: a_bite (byte) = 0x7f,\n"
54 " 04: integer16 (i16) = 27000,\n"
55 " 05: integer32 (i32) = 16777216,\n"
56 " 06: integer64 (i64) = 6000000000,\n"
57 " 07: double_precision (double) = 3.1415926535897931,\n"
58 " 08: some_characters (string) = \"Debug THIS!\",\n"
59 " 09: zomg_unicode (string) = \"\\xd7\\n\\a\\t\",\n"
60 " 10: what_who (bool) = false,\n"
61 " 11: base64 (string) = \"\",\n"
62 " 12: byte_list (list) = list<byte>[3] {\n"
63 " [0] = 0x01,\n"
64 " [1] = 0x02,\n"
65 " [2] = 0x03,\n"
66 " },\n"
67 " 13: i16_list (list) = list<i16>[3] {\n"
68 " [0] = 1,\n"
69 " [1] = 2,\n"
70 " [2] = 3,\n"
71 " },\n"
72 " 14: i64_list (list) = list<i64>[3] {\n"
73 " [0] = 1,\n"
74 " [1] = 2,\n"
75 " [2] = 3,\n"
76 " },\n"
CJCombrink1d886ca2024-03-23 21:32:28 +010077 " 15: rfc4122_uuid (uuid) = {\n"
CJCombrink1d886ca2024-03-23 21:32:28 +010078 " [raw] = \"\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\",\n"
79 " [enc] = \"00000000-0000-0000-0000-000000000000\"\n"
80 " }\n"
Carel Combrink4035ecc2025-05-14 08:39:55 +020081 " 16: rfc4122_uuid_list (list) = list<uuid>[0] {\n"
82 " },\n"
Claudius Heine5ef662b2015-06-24 10:03:50 +020083 "}");
84 const std::string result(apache::thrift::ThriftDebugString(*ooe));
David Reiss00dcccf2007-07-21 01:18:10 +000085
Claudius Heine5ef662b2015-06-24 10:03:50 +020086 BOOST_CHECK_MESSAGE(!expected_result.compare(result),
87 "Expected:\n" << expected_result << "\nGotten:\n" << result);
88}
89
cyy316723a2019-01-05 16:35:14 +080090static ::std::shared_ptr<Nesting> n;
Claudius Heine5ef662b2015-06-24 10:03:50 +020091
92void testCaseSetup_2() {
Carel Combrink4035ecc2025-05-14 08:39:55 +020093 using apache::thrift::TUuid;
94
Claudius Heine5ef662b2015-06-24 10:03:50 +020095 testCaseSetup_1();
96
97 n.reset(new Nesting);
98 n->my_ooe = *ooe;
99 n->my_ooe.integer16 = 16;
100 n->my_ooe.integer32 = 32;
101 n->my_ooe.integer64 = 64;
102 n->my_ooe.double_precision = (std::sqrt(5.0) + 1) / 2;
103 n->my_ooe.some_characters = ":R (me going \"rrrr\")";
104 n->my_ooe.zomg_unicode = "\xd3\x80\xe2\x85\xae\xce\x9d\x20\xd0\x9d\xce"
105 "\xbf\xe2\x85\xbf\xd0\xbe\xc9\xa1\xd0\xb3\xd0"
106 "\xb0\xcf\x81\xe2\x84\x8e\x20\xce\x91\x74\x74"
107 "\xce\xb1\xe2\x85\xbd\xce\xba\xc7\x83\xe2\x80"
108 "\xbc";
Carel Combrink4035ecc2025-05-14 08:39:55 +0200109 n->my_ooe.rfc4122_uuid = TUuid{"{5e2ab188-1726-4e75-a04f-1ed9a6a89c4c}"};
Claudius Heine5ef662b2015-06-24 10:03:50 +0200110 n->my_bonk.type = 31337;
111 n->my_bonk.message = "I am a bonk... xor!";
Carel Combrink4035ecc2025-05-14 08:39:55 +0200112
113 std::vector<TUuid> uuiid_list;
114 uuiid_list.push_back(TUuid{"{fa1af5ec-fdc2-4355-844a-9f0dbfd00e50}"});
115 uuiid_list.push_back(TUuid{"{1beece83-34f4-4fa3-b757-1ad1ac157fe3}"});
116 n->my_ooe.rfc4122_uuid_list = uuiid_list;
Claudius Heine5ef662b2015-06-24 10:03:50 +0200117}
118
119BOOST_AUTO_TEST_CASE(test_debug_proto_2) {
120 testCaseSetup_2();
121
122 const std::string expected_result(
123 "Nesting {\n"
124 " 01: my_bonk (struct) = Bonk {\n"
125 " 01: type (i32) = 31337,\n"
126 " 02: message (string) = \"I am a bonk... xor!\",\n"
127 " },\n"
128 " 02: my_ooe (struct) = OneOfEach {\n"
129 " 01: im_true (bool) = true,\n"
130 " 02: im_false (bool) = false,\n"
131 " 03: a_bite (byte) = 0x7f,\n"
132 " 04: integer16 (i16) = 16,\n"
133 " 05: integer32 (i32) = 32,\n"
134 " 06: integer64 (i64) = 64,\n"
135 " 07: double_precision (double) = 1.6180339887498949,\n"
136 " 08: some_characters (string) = \":R (me going \\\"rrrr\\\")\",\n"
137 " 09: zomg_unicode (string) = \"\\xd3\\x80\\xe2\\x85\\xae\\xce\\x9d \\xd"
138 "0\\x9d\\xce\\xbf\\xe2\\x85\\xbf\\xd0\\xbe\\xc9\\xa1\\xd0\\xb3\\xd0\\xb0"
139 "\\xcf\\x81\\xe2\\x84\\x8e \\xce\\x91tt\\xce\\xb1\\xe2\\x85\\xbd\\xce\\xb"
140 "a\\xc7\\x83\\xe2\\x80\\xbc\",\n"
141 " 10: what_who (bool) = false,\n"
142 " 11: base64 (string) = \"\",\n"
143 " 12: byte_list (list) = list<byte>[3] {\n"
144 " [0] = 0x01,\n"
145 " [1] = 0x02,\n"
146 " [2] = 0x03,\n"
147 " },\n"
148 " 13: i16_list (list) = list<i16>[3] {\n"
149 " [0] = 1,\n"
150 " [1] = 2,\n"
151 " [2] = 3,\n"
152 " },\n"
153 " 14: i64_list (list) = list<i64>[3] {\n"
154 " [0] = 1,\n"
155 " [1] = 2,\n"
156 " [2] = 3,\n"
157 " },\n"
CJCombrink1d886ca2024-03-23 21:32:28 +0100158 " 15: rfc4122_uuid (uuid) = {\n"
CJCombrink1d886ca2024-03-23 21:32:28 +0100159 " [raw] = \"^*\\xb1\\x88\\x17&Nu\\xa0O\\x1e\\xd9\\xa6\\xa8\\x9cL\",\n"
160 " [enc] = \"5e2ab188-1726-4e75-a04f-1ed9a6a89c4c\"\n"
161 " }\n"
Carel Combrink4035ecc2025-05-14 08:39:55 +0200162 " 16: rfc4122_uuid_list (list) = list<uuid>[2] {\n"
163 "{\n"
164 " [raw] = [0] = \"\\xfa\\x1a\\xf5\\xec\\xfd\\xc2CU\\x84J\\x9f\\r\\xbf\\xd0\\x0eP\",\n"
165 " [enc] = \"fa1af5ec-fdc2-4355-844a-9f0dbfd00e50\"\n"
166 " }\n"
167 "{\n"
168 " [raw] = [1] = \"\\x1b\\xee\\xce\\x834\\xf4O\\xa3\\xb7W\\x1a\\xd1\\xac\\x15\\x7f\\xe3\",\n"
169 " [enc] = \"1beece83-34f4-4fa3-b757-1ad1ac157fe3\"\n"
170 " }\n"
171 " },\n"
Claudius Heine5ef662b2015-06-24 10:03:50 +0200172 " },\n"
173 "}");
174 const std::string result(apache::thrift::ThriftDebugString(*n));
175
176 BOOST_CHECK_MESSAGE(!expected_result.compare(result),
177 "Expected:\n" << expected_result << "\nGotten:\n" << result);
178}
179
cyy316723a2019-01-05 16:35:14 +0800180static ::std::shared_ptr<HolyMoley> hm;
Claudius Heine5ef662b2015-06-24 10:03:50 +0200181
182void testCaseSetup_3() {
183 testCaseSetup_2();
184
185 hm.reset(new HolyMoley);
186
187 hm->big.push_back(*ooe);
188 hm->big.push_back(n->my_ooe);
189 hm->big[0].a_bite = 0x22;
190 hm->big[1].a_bite = 0x33;
David Reiss00dcccf2007-07-21 01:18:10 +0000191
192 std::vector<std::string> stage1;
193 stage1.push_back("and a one");
194 stage1.push_back("and a two");
Claudius Heine5ef662b2015-06-24 10:03:50 +0200195 hm->contain.insert(stage1);
David Reiss00dcccf2007-07-21 01:18:10 +0000196 stage1.clear();
197 stage1.push_back("then a one, two");
198 stage1.push_back("three!");
199 stage1.push_back("FOUR!!");
Claudius Heine5ef662b2015-06-24 10:03:50 +0200200 hm->contain.insert(stage1);
David Reiss00dcccf2007-07-21 01:18:10 +0000201 stage1.clear();
Claudius Heine5ef662b2015-06-24 10:03:50 +0200202 hm->contain.insert(stage1);
David Reiss00dcccf2007-07-21 01:18:10 +0000203
204 std::vector<Bonk> stage2;
Claudius Heine5ef662b2015-06-24 10:03:50 +0200205 hm->bonks["nothing"] = stage2;
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100206 stage2.resize(stage2.size() + 1);
David Reiss00dcccf2007-07-21 01:18:10 +0000207 stage2.back().type = 1;
208 stage2.back().message = "Wait.";
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100209 stage2.resize(stage2.size() + 1);
David Reiss00dcccf2007-07-21 01:18:10 +0000210 stage2.back().type = 2;
211 stage2.back().message = "What?";
Claudius Heine5ef662b2015-06-24 10:03:50 +0200212 hm->bonks["something"] = stage2;
David Reiss00dcccf2007-07-21 01:18:10 +0000213 stage2.clear();
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100214 stage2.resize(stage2.size() + 1);
David Reiss00dcccf2007-07-21 01:18:10 +0000215 stage2.back().type = 3;
216 stage2.back().message = "quoth";
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100217 stage2.resize(stage2.size() + 1);
David Reiss00dcccf2007-07-21 01:18:10 +0000218 stage2.back().type = 4;
219 stage2.back().message = "the raven";
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100220 stage2.resize(stage2.size() + 1);
David Reiss00dcccf2007-07-21 01:18:10 +0000221 stage2.back().type = 5;
222 stage2.back().message = "nevermore";
Claudius Heine5ef662b2015-06-24 10:03:50 +0200223 hm->bonks["poe"] = stage2;
224}
David Reiss00dcccf2007-07-21 01:18:10 +0000225
Claudius Heine5ef662b2015-06-24 10:03:50 +0200226BOOST_AUTO_TEST_CASE(test_debug_proto_3) {
227 testCaseSetup_3();
David Reiss00dcccf2007-07-21 01:18:10 +0000228
Claudius Heine5ef662b2015-06-24 10:03:50 +0200229 const std::string expected_result(
230 "HolyMoley {\n"
231 " 01: big (list) = list<struct>[2] {\n"
232 " [0] = OneOfEach {\n"
233 " 01: im_true (bool) = true,\n"
234 " 02: im_false (bool) = false,\n"
235 " 03: a_bite (byte) = 0x22,\n"
236 " 04: integer16 (i16) = 27000,\n"
237 " 05: integer32 (i32) = 16777216,\n"
238 " 06: integer64 (i64) = 6000000000,\n"
239 " 07: double_precision (double) = 3.1415926535897931,\n"
240 " 08: some_characters (string) = \"Debug THIS!\",\n"
241 " 09: zomg_unicode (string) = \"\\xd7\\n\\a\\t\",\n"
242 " 10: what_who (bool) = false,\n"
243 " 11: base64 (string) = \"\",\n"
244 " 12: byte_list (list) = list<byte>[3] {\n"
245 " [0] = 0x01,\n"
246 " [1] = 0x02,\n"
247 " [2] = 0x03,\n"
248 " },\n"
249 " 13: i16_list (list) = list<i16>[3] {\n"
250 " [0] = 1,\n"
251 " [1] = 2,\n"
252 " [2] = 3,\n"
253 " },\n"
254 " 14: i64_list (list) = list<i64>[3] {\n"
255 " [0] = 1,\n"
256 " [1] = 2,\n"
257 " [2] = 3,\n"
258 " },\n"
CJCombrink1d886ca2024-03-23 21:32:28 +0100259 " 15: rfc4122_uuid (uuid) = {\n"
CJCombrink1d886ca2024-03-23 21:32:28 +0100260 " [raw] = \"\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\",\n"
261 " [enc] = \"00000000-0000-0000-0000-000000000000\"\n"
262 " }\n"
Carel Combrink4035ecc2025-05-14 08:39:55 +0200263 " 16: rfc4122_uuid_list (list) = list<uuid>[0] {\n"
264 " },\n"
Claudius Heine5ef662b2015-06-24 10:03:50 +0200265 " },\n"
266 " [1] = OneOfEach {\n"
267 " 01: im_true (bool) = true,\n"
268 " 02: im_false (bool) = false,\n"
269 " 03: a_bite (byte) = 0x33,\n"
270 " 04: integer16 (i16) = 16,\n"
271 " 05: integer32 (i32) = 32,\n"
272 " 06: integer64 (i64) = 64,\n"
273 " 07: double_precision (double) = 1.6180339887498949,\n"
274 " 08: some_characters (string) = \":R (me going \\\"rrrr\\\")\",\n"
275 " 09: zomg_unicode (string) = \"\\xd3\\x80\\xe2\\x85\\xae\\xce\\x9d \\"
276 "xd0\\x9d\\xce\\xbf\\xe2\\x85\\xbf\\xd0\\xbe\\xc9\\xa1\\xd0\\xb3\\xd0\\xb"
277 "0\\xcf\\x81\\xe2\\x84\\x8e \\xce\\x91tt\\xce\\xb1\\xe2\\x85\\xbd\\xce\\x"
278 "ba\\xc7\\x83\\xe2\\x80\\xbc\",\n"
279 " 10: what_who (bool) = false,\n"
280 " 11: base64 (string) = \"\",\n"
281 " 12: byte_list (list) = list<byte>[3] {\n"
282 " [0] = 0x01,\n"
283 " [1] = 0x02,\n"
284 " [2] = 0x03,\n"
285 " },\n"
286 " 13: i16_list (list) = list<i16>[3] {\n"
287 " [0] = 1,\n"
288 " [1] = 2,\n"
289 " [2] = 3,\n"
290 " },\n"
291 " 14: i64_list (list) = list<i64>[3] {\n"
292 " [0] = 1,\n"
293 " [1] = 2,\n"
294 " [2] = 3,\n"
295 " },\n"
CJCombrink1d886ca2024-03-23 21:32:28 +0100296 " 15: rfc4122_uuid (uuid) = {\n"
CJCombrink1d886ca2024-03-23 21:32:28 +0100297 " [raw] = \"^*\\xb1\\x88\\x17&Nu\\xa0O\\x1e\\xd9\\xa6\\xa8\\x9cL\",\n"
298 " [enc] = \"5e2ab188-1726-4e75-a04f-1ed9a6a89c4c\"\n"
299 " }\n"
Carel Combrink4035ecc2025-05-14 08:39:55 +0200300 " 16: rfc4122_uuid_list (list) = list<uuid>[2] {\n"
301 "{\n"
302 " [raw] = [0] = \"\\xfa\\x1a\\xf5\\xec\\xfd\\xc2CU\\x84J\\x9f\\r\\xbf\\xd0\\x0eP\",\n"
303 " [enc] = \"fa1af5ec-fdc2-4355-844a-9f0dbfd00e50\"\n"
304 " }\n"
305 "{\n"
306 " [raw] = [1] = \"\\x1b\\xee\\xce\\x834\\xf4O\\xa3\\xb7W\\x1a\\xd1\\xac\\x15\\x7f\\xe3\",\n"
307 " [enc] = \"1beece83-34f4-4fa3-b757-1ad1ac157fe3\"\n"
308 " }\n"
309 " },\n"
Claudius Heine5ef662b2015-06-24 10:03:50 +0200310 " },\n"
311 " },\n"
312 " 02: contain (set) = set<list>[3] {\n"
313 " list<string>[0] {\n"
314 " },\n"
315 " list<string>[2] {\n"
316 " [0] = \"and a one\",\n"
317 " [1] = \"and a two\",\n"
318 " },\n"
319 " list<string>[3] {\n"
320 " [0] = \"then a one, two\",\n"
321 " [1] = \"three!\",\n"
322 " [2] = \"FOUR!!\",\n"
323 " },\n"
324 " },\n"
325 " 03: bonks (map) = map<string,list>[3] {\n"
326 " \"nothing\" -> list<struct>[0] {\n"
327 " },\n"
328 " \"poe\" -> list<struct>[3] {\n"
329 " [0] = Bonk {\n"
330 " 01: type (i32) = 3,\n"
331 " 02: message (string) = \"quoth\",\n"
332 " },\n"
333 " [1] = Bonk {\n"
334 " 01: type (i32) = 4,\n"
335 " 02: message (string) = \"the raven\",\n"
336 " },\n"
337 " [2] = Bonk {\n"
338 " 01: type (i32) = 5,\n"
339 " 02: message (string) = \"nevermore\",\n"
340 " },\n"
341 " },\n"
342 " \"something\" -> list<struct>[2] {\n"
343 " [0] = Bonk {\n"
344 " 01: type (i32) = 1,\n"
345 " 02: message (string) = \"Wait.\",\n"
346 " },\n"
347 " [1] = Bonk {\n"
348 " 01: type (i32) = 2,\n"
349 " 02: message (string) = \"What?\",\n"
350 " },\n"
351 " },\n"
352 " },\n"
353 "}");
354 const std::string result(apache::thrift::ThriftDebugString(*hm));
355
356 BOOST_CHECK_MESSAGE(!expected_result.compare(result),
357 "Expected:\n" << expected_result << "\nGotten:\n" << result);
David Reiss00dcccf2007-07-21 01:18:10 +0000358}