blob: 097611284a72abbf61fc62e1ff178da598178c71 [file] [log] [blame]
Jake Farrell5d02b802014-01-07 21:42:01 -05001#define _USE_MATH_DEFINES
David Reisse71115b2010-10-06 17:09:56 +00002#include <cmath>
Roger Meier49ff8b12012-04-13 09:12:31 +00003#include <thrift/transport/TTransportUtils.h>
4#include <thrift/protocol/TBinaryProtocol.h>
David Reisse71115b2010-10-06 17:09:56 +00005#include <gen-cpp/DebugProtoTest_types.h>
6
David Reisse71115b2010-10-06 17:09:56 +00007using namespace thrift::test::debug;
8using namespace apache::thrift::transport;
9using namespace apache::thrift::protocol;
10
Claudius Heine5ef662b2015-06-24 10:03:50 +020011#define BOOST_TEST_MODULE SpecializationTest
12#include <boost/test/unit_test.hpp>
13
David Reisse71115b2010-10-06 17:09:56 +000014typedef TBinaryProtocolT<TMemoryBuffer> MyProtocol;
Konrad Grochowski16a23a62014-11-13 15:33:38 +010015// typedef TBinaryProtocolT<TTransport> MyProtocol;
David Reisse71115b2010-10-06 17:09:56 +000016
Claudius Heine5ef662b2015-06-24 10:03:50 +020017BOOST_AUTO_TEST_CASE(test_specialization_1) {
David Reisse71115b2010-10-06 17:09:56 +000018 OneOfEach ooe;
Konrad Grochowski16a23a62014-11-13 15:33:38 +010019 ooe.im_true = true;
20 ooe.im_false = false;
21 ooe.a_bite = 0x7f;
David Reisse71115b2010-10-06 17:09:56 +000022 ooe.integer16 = 27000;
Konrad Grochowski16a23a62014-11-13 15:33:38 +010023 ooe.integer32 = 1 << 24;
David Reisse71115b2010-10-06 17:09:56 +000024 ooe.integer64 = (uint64_t)6000 * 1000 * 1000;
25 ooe.double_precision = M_PI;
Konrad Grochowski16a23a62014-11-13 15:33:38 +010026 ooe.some_characters = "JSON THIS! \"\1";
27 ooe.zomg_unicode = "\xd7\n\a\t";
David Reisse71115b2010-10-06 17:09:56 +000028 ooe.base64 = "\1\2\3\255";
CJCombrink1d886ca2024-03-23 21:32:28 +010029 ooe.rfc4122_uuid = "00000000-0000-0000-0000-000000000000";
David Reisse71115b2010-10-06 17:09:56 +000030
31 Nesting n;
32 n.my_ooe = ooe;
33 n.my_ooe.integer16 = 16;
34 n.my_ooe.integer32 = 32;
35 n.my_ooe.integer64 = 64;
Konrad Grochowski16a23a62014-11-13 15:33:38 +010036 n.my_ooe.double_precision = (std::sqrt(5.0) + 1) / 2;
37 n.my_ooe.some_characters = ":R (me going \"rrrr\")";
Claudius Heine5ef662b2015-06-24 10:03:50 +020038 n.my_ooe.zomg_unicode = "\xd3\x80\xe2\x85\xae\xce\x9d\x20\xd0\x9d\xce"
39 "\xbf\xe2\x85\xbf\xd0\xbe\xc9\xa1\xd0\xb3\xd0"
40 "\xb0\xcf\x81\xe2\x84\x8e\x20\xce\x91\x74\x74"
41 "\xce\xb1\xe2\x85\xbd\xce\xba\xc7\x83\xe2\x80"
42 "\xbc";
Konrad Grochowski16a23a62014-11-13 15:33:38 +010043 n.my_bonk.type = 31337;
David Reisse71115b2010-10-06 17:09:56 +000044 n.my_bonk.message = "I am a bonk... xor!";
45
46 HolyMoley hm;
47
48 hm.big.push_back(ooe);
49 hm.big.push_back(n.my_ooe);
50 hm.big[0].a_bite = 0x22;
51 hm.big[1].a_bite = 0x33;
52
53 std::vector<std::string> stage1;
54 stage1.push_back("and a one");
55 stage1.push_back("and a two");
56 hm.contain.insert(stage1);
57 stage1.clear();
58 stage1.push_back("then a one, two");
59 stage1.push_back("three!");
60 stage1.push_back("FOUR!!");
61 hm.contain.insert(stage1);
62 stage1.clear();
63 hm.contain.insert(stage1);
64
65 std::vector<Bonk> stage2;
66 hm.bonks["nothing"] = stage2;
Konrad Grochowski16a23a62014-11-13 15:33:38 +010067 stage2.resize(stage2.size() + 1);
David Reisse71115b2010-10-06 17:09:56 +000068 stage2.back().type = 1;
69 stage2.back().message = "Wait.";
Konrad Grochowski16a23a62014-11-13 15:33:38 +010070 stage2.resize(stage2.size() + 1);
David Reisse71115b2010-10-06 17:09:56 +000071 stage2.back().type = 2;
72 stage2.back().message = "What?";
73 hm.bonks["something"] = stage2;
74 stage2.clear();
Konrad Grochowski16a23a62014-11-13 15:33:38 +010075 stage2.resize(stage2.size() + 1);
David Reisse71115b2010-10-06 17:09:56 +000076 stage2.back().type = 3;
77 stage2.back().message = "quoth";
Konrad Grochowski16a23a62014-11-13 15:33:38 +010078 stage2.resize(stage2.size() + 1);
David Reisse71115b2010-10-06 17:09:56 +000079 stage2.back().type = 4;
80 stage2.back().message = "the raven";
Konrad Grochowski16a23a62014-11-13 15:33:38 +010081 stage2.resize(stage2.size() + 1);
David Reisse71115b2010-10-06 17:09:56 +000082 stage2.back().type = 5;
83 stage2.back().message = "nevermore";
84 hm.bonks["poe"] = stage2;
85
cyy316723a2019-01-05 16:35:14 +080086 std::shared_ptr<TMemoryBuffer> buffer(new TMemoryBuffer());
87 std::shared_ptr<TProtocol> proto(new MyProtocol(buffer));
David Reisse71115b2010-10-06 17:09:56 +000088
David Reisse71115b2010-10-06 17:09:56 +000089 ooe.write(proto.get());
90 OneOfEach ooe2;
91 ooe2.read(proto.get());
92
CJCombrink1d886ca2024-03-23 21:32:28 +010093 BOOST_TEST_INFO("Write: " << ooe);
94 BOOST_TEST_INFO("Read : " << ooe2);
Claudius Heine5ef662b2015-06-24 10:03:50 +020095 BOOST_CHECK(ooe == ooe2);
David Reisse71115b2010-10-06 17:09:56 +000096
97 hm.write(proto.get());
98 HolyMoley hm2;
99 hm2.read(proto.get());
100
Claudius Heine5ef662b2015-06-24 10:03:50 +0200101 BOOST_CHECK(hm == hm2);
David Reisse71115b2010-10-06 17:09:56 +0000102
Christian Lavoiecbf87cb2010-11-28 14:34:26 +0000103 hm2.big[0].a_bite = 0x00;
David Reisse71115b2010-10-06 17:09:56 +0000104
Claudius Heine5ef662b2015-06-24 10:03:50 +0200105 BOOST_CHECK(hm != hm2);
David Reisse71115b2010-10-06 17:09:56 +0000106}