Jake Farrell | 5d02b80 | 2014-01-07 21:42:01 -0500 | [diff] [blame] | 1 | #define _USE_MATH_DEFINES |
David Reiss | e71115b | 2010-10-06 17:09:56 +0000 | [diff] [blame] | 2 | #include <cmath> |
Roger Meier | 49ff8b1 | 2012-04-13 09:12:31 +0000 | [diff] [blame] | 3 | #include <thrift/transport/TTransportUtils.h> |
| 4 | #include <thrift/protocol/TBinaryProtocol.h> |
David Reiss | e71115b | 2010-10-06 17:09:56 +0000 | [diff] [blame] | 5 | #include <gen-cpp/DebugProtoTest_types.h> |
| 6 | |
David Reiss | e71115b | 2010-10-06 17:09:56 +0000 | [diff] [blame] | 7 | using namespace thrift::test::debug; |
| 8 | using namespace apache::thrift::transport; |
| 9 | using namespace apache::thrift::protocol; |
| 10 | |
Claudius Heine | 5ef662b | 2015-06-24 10:03:50 +0200 | [diff] [blame] | 11 | #define BOOST_TEST_MODULE SpecializationTest |
| 12 | #include <boost/test/unit_test.hpp> |
| 13 | |
David Reiss | e71115b | 2010-10-06 17:09:56 +0000 | [diff] [blame] | 14 | typedef TBinaryProtocolT<TMemoryBuffer> MyProtocol; |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 15 | // typedef TBinaryProtocolT<TTransport> MyProtocol; |
David Reiss | e71115b | 2010-10-06 17:09:56 +0000 | [diff] [blame] | 16 | |
Claudius Heine | 5ef662b | 2015-06-24 10:03:50 +0200 | [diff] [blame] | 17 | BOOST_AUTO_TEST_CASE(test_specialization_1) { |
David Reiss | e71115b | 2010-10-06 17:09:56 +0000 | [diff] [blame] | 18 | OneOfEach ooe; |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 19 | ooe.im_true = true; |
| 20 | ooe.im_false = false; |
| 21 | ooe.a_bite = 0x7f; |
David Reiss | e71115b | 2010-10-06 17:09:56 +0000 | [diff] [blame] | 22 | ooe.integer16 = 27000; |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 23 | ooe.integer32 = 1 << 24; |
David Reiss | e71115b | 2010-10-06 17:09:56 +0000 | [diff] [blame] | 24 | ooe.integer64 = (uint64_t)6000 * 1000 * 1000; |
| 25 | ooe.double_precision = M_PI; |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 26 | ooe.some_characters = "JSON THIS! \"\1"; |
| 27 | ooe.zomg_unicode = "\xd7\n\a\t"; |
David Reiss | e71115b | 2010-10-06 17:09:56 +0000 | [diff] [blame] | 28 | ooe.base64 = "\1\2\3\255"; |
| 29 | |
| 30 | Nesting n; |
| 31 | n.my_ooe = ooe; |
| 32 | n.my_ooe.integer16 = 16; |
| 33 | n.my_ooe.integer32 = 32; |
| 34 | n.my_ooe.integer64 = 64; |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 35 | n.my_ooe.double_precision = (std::sqrt(5.0) + 1) / 2; |
| 36 | n.my_ooe.some_characters = ":R (me going \"rrrr\")"; |
Claudius Heine | 5ef662b | 2015-06-24 10:03:50 +0200 | [diff] [blame] | 37 | n.my_ooe.zomg_unicode = "\xd3\x80\xe2\x85\xae\xce\x9d\x20\xd0\x9d\xce" |
| 38 | "\xbf\xe2\x85\xbf\xd0\xbe\xc9\xa1\xd0\xb3\xd0" |
| 39 | "\xb0\xcf\x81\xe2\x84\x8e\x20\xce\x91\x74\x74" |
| 40 | "\xce\xb1\xe2\x85\xbd\xce\xba\xc7\x83\xe2\x80" |
| 41 | "\xbc"; |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 42 | n.my_bonk.type = 31337; |
David Reiss | e71115b | 2010-10-06 17:09:56 +0000 | [diff] [blame] | 43 | n.my_bonk.message = "I am a bonk... xor!"; |
| 44 | |
| 45 | HolyMoley hm; |
| 46 | |
| 47 | hm.big.push_back(ooe); |
| 48 | hm.big.push_back(n.my_ooe); |
| 49 | hm.big[0].a_bite = 0x22; |
| 50 | hm.big[1].a_bite = 0x33; |
| 51 | |
| 52 | std::vector<std::string> stage1; |
| 53 | stage1.push_back("and a one"); |
| 54 | stage1.push_back("and a two"); |
| 55 | hm.contain.insert(stage1); |
| 56 | stage1.clear(); |
| 57 | stage1.push_back("then a one, two"); |
| 58 | stage1.push_back("three!"); |
| 59 | stage1.push_back("FOUR!!"); |
| 60 | hm.contain.insert(stage1); |
| 61 | stage1.clear(); |
| 62 | hm.contain.insert(stage1); |
| 63 | |
| 64 | std::vector<Bonk> stage2; |
| 65 | hm.bonks["nothing"] = stage2; |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 66 | stage2.resize(stage2.size() + 1); |
David Reiss | e71115b | 2010-10-06 17:09:56 +0000 | [diff] [blame] | 67 | stage2.back().type = 1; |
| 68 | stage2.back().message = "Wait."; |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 69 | stage2.resize(stage2.size() + 1); |
David Reiss | e71115b | 2010-10-06 17:09:56 +0000 | [diff] [blame] | 70 | stage2.back().type = 2; |
| 71 | stage2.back().message = "What?"; |
| 72 | hm.bonks["something"] = stage2; |
| 73 | stage2.clear(); |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 74 | stage2.resize(stage2.size() + 1); |
David Reiss | e71115b | 2010-10-06 17:09:56 +0000 | [diff] [blame] | 75 | stage2.back().type = 3; |
| 76 | stage2.back().message = "quoth"; |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 77 | stage2.resize(stage2.size() + 1); |
David Reiss | e71115b | 2010-10-06 17:09:56 +0000 | [diff] [blame] | 78 | stage2.back().type = 4; |
| 79 | stage2.back().message = "the raven"; |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 80 | stage2.resize(stage2.size() + 1); |
David Reiss | e71115b | 2010-10-06 17:09:56 +0000 | [diff] [blame] | 81 | stage2.back().type = 5; |
| 82 | stage2.back().message = "nevermore"; |
| 83 | hm.bonks["poe"] = stage2; |
| 84 | |
James E. King, III | 82ae957 | 2017-08-05 12:23:54 -0400 | [diff] [blame] | 85 | apache::thrift::stdcxx::shared_ptr<TMemoryBuffer> buffer(new TMemoryBuffer()); |
| 86 | apache::thrift::stdcxx::shared_ptr<TProtocol> proto(new MyProtocol(buffer)); |
David Reiss | e71115b | 2010-10-06 17:09:56 +0000 | [diff] [blame] | 87 | |
David Reiss | e71115b | 2010-10-06 17:09:56 +0000 | [diff] [blame] | 88 | ooe.write(proto.get()); |
| 89 | OneOfEach ooe2; |
| 90 | ooe2.read(proto.get()); |
| 91 | |
Claudius Heine | 5ef662b | 2015-06-24 10:03:50 +0200 | [diff] [blame] | 92 | BOOST_CHECK(ooe == ooe2); |
David Reiss | e71115b | 2010-10-06 17:09:56 +0000 | [diff] [blame] | 93 | |
| 94 | hm.write(proto.get()); |
| 95 | HolyMoley hm2; |
| 96 | hm2.read(proto.get()); |
| 97 | |
Claudius Heine | 5ef662b | 2015-06-24 10:03:50 +0200 | [diff] [blame] | 98 | BOOST_CHECK(hm == hm2); |
David Reiss | e71115b | 2010-10-06 17:09:56 +0000 | [diff] [blame] | 99 | |
Christian Lavoie | cbf87cb | 2010-11-28 14:34:26 +0000 | [diff] [blame] | 100 | hm2.big[0].a_bite = 0x00; |
David Reiss | e71115b | 2010-10-06 17:09:56 +0000 | [diff] [blame] | 101 | |
Claudius Heine | 5ef662b | 2015-06-24 10:03:50 +0200 | [diff] [blame] | 102 | BOOST_CHECK(hm != hm2); |
David Reiss | e71115b | 2010-10-06 17:09:56 +0000 | [diff] [blame] | 103 | } |