blob: 856bdac9f8e603e5d89e05c43d6850bfc15c9212 [file] [log] [blame]
Jake Farrell5d02b802014-01-07 21:42:01 -05001#define _USE_MATH_DEFINES
David Reisse71115b2010-10-06 17:09:56 +00002#include <iostream>
3#include <cmath>
Roger Meier49ff8b12012-04-13 09:12:31 +00004#include <thrift/transport/TTransportUtils.h>
5#include <thrift/protocol/TBinaryProtocol.h>
David Reisse71115b2010-10-06 17:09:56 +00006#include <gen-cpp/DebugProtoTest_types.h>
7
8using std::cout;
9using std::endl;
10using namespace thrift::test::debug;
11using namespace apache::thrift::transport;
12using namespace apache::thrift::protocol;
13
14typedef TBinaryProtocolT<TMemoryBuffer> MyProtocol;
Konrad Grochowski16a23a62014-11-13 15:33:38 +010015// typedef TBinaryProtocolT<TTransport> MyProtocol;
David Reisse71115b2010-10-06 17:09:56 +000016
17int main() {
18
19 OneOfEach ooe;
Konrad Grochowski16a23a62014-11-13 15:33:38 +010020 ooe.im_true = true;
21 ooe.im_false = false;
22 ooe.a_bite = 0x7f;
David Reisse71115b2010-10-06 17:09:56 +000023 ooe.integer16 = 27000;
Konrad Grochowski16a23a62014-11-13 15:33:38 +010024 ooe.integer32 = 1 << 24;
David Reisse71115b2010-10-06 17:09:56 +000025 ooe.integer64 = (uint64_t)6000 * 1000 * 1000;
26 ooe.double_precision = M_PI;
Konrad Grochowski16a23a62014-11-13 15:33:38 +010027 ooe.some_characters = "JSON THIS! \"\1";
28 ooe.zomg_unicode = "\xd7\n\a\t";
David Reisse71115b2010-10-06 17:09:56 +000029 ooe.base64 = "\1\2\3\255";
30
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\")";
David Reisse71115b2010-10-06 17:09:56 +000038 n.my_ooe.zomg_unicode = "\xd3\x80\xe2\x85\xae\xce\x9d\x20"
39 "\xd0\x9d\xce\xbf\xe2\x85\xbf\xd0\xbe\xc9\xa1\xd0\xb3\xd0\xb0\xcf\x81\xe2\x84\x8e"
40 "\x20\xce\x91\x74\x74\xce\xb1\xe2\x85\xbd\xce\xba\xc7\x83\xe2\x80\xbc";
Konrad Grochowski16a23a62014-11-13 15:33:38 +010041 n.my_bonk.type = 31337;
David Reisse71115b2010-10-06 17:09:56 +000042 n.my_bonk.message = "I am a bonk... xor!";
43
44 HolyMoley hm;
45
46 hm.big.push_back(ooe);
47 hm.big.push_back(n.my_ooe);
48 hm.big[0].a_bite = 0x22;
49 hm.big[1].a_bite = 0x33;
50
51 std::vector<std::string> stage1;
52 stage1.push_back("and a one");
53 stage1.push_back("and a two");
54 hm.contain.insert(stage1);
55 stage1.clear();
56 stage1.push_back("then a one, two");
57 stage1.push_back("three!");
58 stage1.push_back("FOUR!!");
59 hm.contain.insert(stage1);
60 stage1.clear();
61 hm.contain.insert(stage1);
62
63 std::vector<Bonk> stage2;
64 hm.bonks["nothing"] = stage2;
Konrad Grochowski16a23a62014-11-13 15:33:38 +010065 stage2.resize(stage2.size() + 1);
David Reisse71115b2010-10-06 17:09:56 +000066 stage2.back().type = 1;
67 stage2.back().message = "Wait.";
Konrad Grochowski16a23a62014-11-13 15:33:38 +010068 stage2.resize(stage2.size() + 1);
David Reisse71115b2010-10-06 17:09:56 +000069 stage2.back().type = 2;
70 stage2.back().message = "What?";
71 hm.bonks["something"] = stage2;
72 stage2.clear();
Konrad Grochowski16a23a62014-11-13 15:33:38 +010073 stage2.resize(stage2.size() + 1);
David Reisse71115b2010-10-06 17:09:56 +000074 stage2.back().type = 3;
75 stage2.back().message = "quoth";
Konrad Grochowski16a23a62014-11-13 15:33:38 +010076 stage2.resize(stage2.size() + 1);
David Reisse71115b2010-10-06 17:09:56 +000077 stage2.back().type = 4;
78 stage2.back().message = "the raven";
Konrad Grochowski16a23a62014-11-13 15:33:38 +010079 stage2.resize(stage2.size() + 1);
David Reisse71115b2010-10-06 17:09:56 +000080 stage2.back().type = 5;
81 stage2.back().message = "nevermore";
82 hm.bonks["poe"] = stage2;
83
84 boost::shared_ptr<TMemoryBuffer> buffer(new TMemoryBuffer());
85 boost::shared_ptr<TProtocol> proto(new MyProtocol(buffer));
86
87 cout << "Testing ooe" << endl;
88
89 ooe.write(proto.get());
90 OneOfEach ooe2;
91 ooe2.read(proto.get());
92
93 assert(ooe == ooe2);
94
David Reisse71115b2010-10-06 17:09:56 +000095 cout << "Testing hm" << endl;
96
97 hm.write(proto.get());
98 HolyMoley hm2;
99 hm2.read(proto.get());
100
101 assert(hm == hm2);
102
Christian Lavoiecbf87cb2010-11-28 14:34:26 +0000103 hm2.big[0].a_bite = 0x00;
David Reisse71115b2010-10-06 17:09:56 +0000104
105 assert(hm != hm2);
106
107 return 0;
108}