blob: 5649e18f72f0d557854ff6c8cc06b62e0a8f0d7c [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 <iostream>
22#include <cmath>
23#include "gen-cpp/DebugProtoTest_types.h"
Roger Meier49ff8b12012-04-13 09:12:31 +000024#include <thrift/protocol/TDebugProtocol.h>
David Reiss00dcccf2007-07-21 01:18:10 +000025
26int main() {
27 using std::cout;
28 using std::endl;
David Reiss2a4bfd62008-04-07 23:45:00 +000029 using namespace thrift::test::debug;
David Reiss00dcccf2007-07-21 01:18:10 +000030
31
32 OneOfEach ooe;
33 ooe.im_true = true;
34 ooe.im_false = false;
Christian Lavoiecbf87cb2010-11-28 14:34:26 +000035 ooe.a_bite = 0x7f;
David Reiss00dcccf2007-07-21 01:18:10 +000036 ooe.integer16 = 27000;
37 ooe.integer32 = 1<<24;
David Reiss6f226552007-08-06 20:33:00 +000038 ooe.integer64 = (uint64_t)6000 * 1000 * 1000;
David Reiss00dcccf2007-07-21 01:18:10 +000039 ooe.double_precision = M_PI;
40 ooe.some_characters = "Debug THIS!";
41 ooe.zomg_unicode = "\xd7\n\a\t";
42
T Jake Lucianib5e62212009-01-31 22:36:20 +000043 cout << apache::thrift::ThriftDebugString(ooe) << endl << endl;
David Reiss00dcccf2007-07-21 01:18:10 +000044
45
46 Nesting n;
47 n.my_ooe = ooe;
48 n.my_ooe.integer16 = 16;
49 n.my_ooe.integer32 = 32;
50 n.my_ooe.integer64 = 64;
David Reisse5eef132009-05-21 02:28:30 +000051 n.my_ooe.double_precision = (std::sqrt(5.0)+1)/2;
David Reiss00dcccf2007-07-21 01:18:10 +000052 n.my_ooe.some_characters = ":R (me going \"rrrr\")";
David Reiss8dae9942007-08-06 20:32:59 +000053 n.my_ooe.zomg_unicode = "\xd3\x80\xe2\x85\xae\xce\x9d\x20"
54 "\xd0\x9d\xce\xbf\xe2\x85\xbf\xd0\xbe\xc9\xa1\xd0\xb3\xd0\xb0\xcf\x81\xe2\x84\x8e"
55 "\x20\xce\x91\x74\x74\xce\xb1\xe2\x85\xbd\xce\xba\xc7\x83\xe2\x80\xbc";
David Reiss00dcccf2007-07-21 01:18:10 +000056 n.my_bonk.type = 31337;
57 n.my_bonk.message = "I am a bonk... xor!";
58
T Jake Lucianib5e62212009-01-31 22:36:20 +000059 cout << apache::thrift::ThriftDebugString(n) << endl << endl;
David Reiss00dcccf2007-07-21 01:18:10 +000060
61
62 HolyMoley hm;
63
64 hm.big.push_back(ooe);
65 hm.big.push_back(n.my_ooe);
66 hm.big[0].a_bite = 0x22;
67 hm.big[1].a_bite = 0x33;
68
69 std::vector<std::string> stage1;
70 stage1.push_back("and a one");
71 stage1.push_back("and a two");
72 hm.contain.insert(stage1);
73 stage1.clear();
74 stage1.push_back("then a one, two");
75 stage1.push_back("three!");
76 stage1.push_back("FOUR!!");
77 hm.contain.insert(stage1);
78 stage1.clear();
79 hm.contain.insert(stage1);
80
81 std::vector<Bonk> stage2;
82 hm.bonks["nothing"] = stage2;
83 stage2.resize(stage2.size()+1);
84 stage2.back().type = 1;
85 stage2.back().message = "Wait.";
86 stage2.resize(stage2.size()+1);
87 stage2.back().type = 2;
88 stage2.back().message = "What?";
89 hm.bonks["something"] = stage2;
90 stage2.clear();
91 stage2.resize(stage2.size()+1);
92 stage2.back().type = 3;
93 stage2.back().message = "quoth";
94 stage2.resize(stage2.size()+1);
95 stage2.back().type = 4;
96 stage2.back().message = "the raven";
97 stage2.resize(stage2.size()+1);
98 stage2.back().type = 5;
99 stage2.back().message = "nevermore";
100 hm.bonks["poe"] = stage2;
101
T Jake Lucianib5e62212009-01-31 22:36:20 +0000102 cout << apache::thrift::ThriftDebugString(hm) << endl << endl;
David Reiss00dcccf2007-07-21 01:18:10 +0000103
104
105 return 0;
106}