]>
git.proxmox.com Git - ceph.git/blob - ceph/src/jaegertracing/thrift/lib/cpp/test/RecursiveTest.cpp
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
10 * http://www.apache.org/licenses/LICENSE-2.0
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
19 * Contains some contributions under the Thrift Software License.
20 * Please see doc/old-thrift-license.txt in the Thrift distribution for
24 #include "gen-cpp/Recursive_types.h"
25 #include <thrift/protocol/TBinaryProtocol.h>
27 #include <thrift/transport/TBufferTransports.h>
29 #define BOOST_TEST_MODULE RecursiveTest
30 #include <boost/test/unit_test.hpp>
32 using apache::thrift::transport::TMemoryBuffer
;
33 using apache::thrift::protocol::TBinaryProtocol
;
34 using std::shared_ptr
;
36 BOOST_AUTO_TEST_CASE(test_recursive_1
) {
37 shared_ptr
<TMemoryBuffer
> buf(new TMemoryBuffer());
38 shared_ptr
<TBinaryProtocol
> prot(new TBinaryProtocol(buf
));
42 tree
.children
.push_back(child
);
44 tree
.write(prot
.get());
47 result
.read(prot
.get());
48 BOOST_CHECK(tree
== result
);
51 BOOST_AUTO_TEST_CASE(test_recursive_2
) {
52 shared_ptr
<TMemoryBuffer
> buf(new TMemoryBuffer());
53 shared_ptr
<TBinaryProtocol
> prot(new TBinaryProtocol(buf
));
56 shared_ptr
<RecList
> l2(new RecList
);
62 resultlist
.read(prot
.get());
63 BOOST_CHECK(resultlist
.nextitem
!= nullptr);
64 BOOST_CHECK(resultlist
.nextitem
->nextitem
== nullptr);
67 BOOST_AUTO_TEST_CASE(test_recursive_3
) {
68 shared_ptr
<TMemoryBuffer
> buf(new TMemoryBuffer());
69 shared_ptr
<TBinaryProtocol
> prot(new TBinaryProtocol(buf
));
72 shared_ptr
<CoRec2
> r(new CoRec2
);
78 BOOST_CHECK(c
.other
!= nullptr);
79 BOOST_CHECK(c
.other
->other
.other
== nullptr);
82 BOOST_AUTO_TEST_CASE(test_recursive_4
) {
83 shared_ptr
<TMemoryBuffer
> buf(new TMemoryBuffer());
84 shared_ptr
<TBinaryProtocol
> prot(new TBinaryProtocol(buf
));
86 shared_ptr
<RecList
> depthLimit(new RecList
);
87 depthLimit
->nextitem
= depthLimit
;
88 BOOST_CHECK_THROW(depthLimit
->write(prot
.get()),
89 apache::thrift::protocol::TProtocolException
);
91 depthLimit
->nextitem
.reset();