blob: 2e18840e9f51c5a7c82752023e339b92ec97c642 [file] [log] [blame]
James E. King, IIIb4c190b2017-02-13 16:39:59 -05001/*
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#define BOOST_TEST_MODULE AnnotationTest
20#include <boost/test/unit_test.hpp>
21#include "gen-cpp/AnnotationTest_types.h"
22#include <ostream>
23#include <sstream>
24
25// Normally thrift generates ostream operators, however
26// with the annotation "cpp.customostream" one can tell the
27// compiler they are going to provide their own, and not
28// emit operator << or printTo().
29
30std::ostream& operator<<(std::ostream& os, const ostr_custom& osc)
31{
32 os << "{ bar = " << osc.bar << "; }";
33 return os;
34}
35
36BOOST_AUTO_TEST_SUITE(BOOST_TEST_MODULE)
37
38BOOST_AUTO_TEST_CASE(test_cpp_compiler_generated_ostream_operator)
39{
40 ostr_default def;
41 def.__set_bar(10);
42
43 std::stringstream ssd;
44 ssd << def;
45 BOOST_CHECK_EQUAL(ssd.str(), "ostr_default(bar=10)");
46}
47
48BOOST_AUTO_TEST_CASE(test_cpp_customostream_uses_consuming_application_definition)
49{
50 ostr_custom cus;
51 cus.__set_bar(10);
52
53 std::stringstream csd;
54 csd << cus;
55 BOOST_CHECK_EQUAL(csd.str(), "{ bar = 10; }");
56}
57
58/**
59 * Disabled; see THRIFT-1567 - not sure what it is supposed to do
60BOOST_AUTO_TEST_CASE(test_cpp_type) {
61 // Check that the "cpp.type" annotation changes "struct foo" to "DenseFoo"
62 // This won't compile if the annotation is mishandled
63 DenseFoo foo;
64 foo.__set_bar(5);
65}
66 */
67
68BOOST_AUTO_TEST_SUITE_END()