blob: a74be918e9da0181e8e4e6ca5581bab46cf6975f [file] [log] [blame]
jfarrelle0e83162014-04-08 22:45:01 -04001/*
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 * Contains some contributions under the Thrift Software License.
20 * Please see doc/old-thrift-license.txt in the Thrift distribution for
21 * details.
22 */
23
24#include "gen-cpp/Recursive_types.h"
25#include <thrift/transport/TBufferTransports.h>
26#include <thrift/protocol/TBinaryProtocol.h>
27
28using apache::thrift::transport::TMemoryBuffer;
29using apache::thrift::protocol::TBinaryProtocol;
Konrad Grochowski16a23a62014-11-13 15:33:38 +010030using boost::shared_ptr;
jfarrelle0e83162014-04-08 22:45:01 -040031
32int main() {
33 shared_ptr<TMemoryBuffer> buf(new TMemoryBuffer());
34 shared_ptr<TBinaryProtocol> prot(new TBinaryProtocol(buf));
35
36 RecTree tree;
37 RecTree child;
38 tree.children.push_back(child);
39
40 tree.write(prot.get());
41
42 RecTree result;
43 result.read(prot.get());
44 assert(tree == result);
45
46 RecList l;
Jens Geyer885c6792014-05-02 21:31:55 +020047 boost::shared_ptr<RecList> l2(new RecList);
jfarrelle0e83162014-04-08 22:45:01 -040048 l.nextitem = l2;
49
50 l.write(prot.get());
51
52 RecList resultlist;
53 resultlist.read(prot.get());
54 assert(resultlist.nextitem != NULL);
55 assert(resultlist.nextitem->nextitem == NULL);
56
57 CoRec c;
Jens Geyer885c6792014-05-02 21:31:55 +020058 boost::shared_ptr<CoRec2> r(new CoRec2);
jfarrelle0e83162014-04-08 22:45:01 -040059 c.other = r;
60
61 c.write(prot.get());
62
63 c.read(prot.get());
64 assert(c.other != NULL);
65 assert(c.other->other.other == NULL);
66
Jens Geyer885c6792014-05-02 21:31:55 +020067 boost::shared_ptr<RecList> depthLimit(new RecList);
68 depthLimit->nextitem = depthLimit;
69 try {
70 depthLimit->write(prot.get());
71 assert(false);
72 } catch (const apache::thrift::protocol::TProtocolException& e) {
73 }
jfarrelle0e83162014-04-08 22:45:01 -040074}