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
23 #include <boost/test/auto_unit_test.hpp>
25 #include <thrift/TToString.h>
27 #include "gen-cpp/ThriftTest_types.h"
28 #include "gen-cpp/OptionalRequiredTest_types.h"
29 #include "gen-cpp/DebugProtoTest_types.h"
31 using apache::thrift::to_string
;
33 BOOST_AUTO_TEST_SUITE(ToStringTest
)
35 BOOST_AUTO_TEST_CASE(base_types_to_string
) {
36 BOOST_CHECK_EQUAL(to_string(10), "10");
37 BOOST_CHECK_EQUAL(to_string(true), "1");
38 BOOST_CHECK_EQUAL(to_string('a'), "a");
39 BOOST_CHECK_EQUAL(to_string(1.2), "1.2");
40 BOOST_CHECK_EQUAL(to_string("abc"), "abc");
43 BOOST_AUTO_TEST_CASE(empty_vector_to_string
) {
45 BOOST_CHECK_EQUAL(to_string(l
), "[]");
48 BOOST_AUTO_TEST_CASE(single_item_vector_to_string
) {
51 BOOST_CHECK_EQUAL(to_string(l
), "[100]");
54 BOOST_AUTO_TEST_CASE(multiple_item_vector_to_string
) {
58 BOOST_CHECK_EQUAL(to_string(l
), "[100, 150]");
61 BOOST_AUTO_TEST_CASE(empty_map_to_string
) {
62 std::map
<int, std::string
> m
;
63 BOOST_CHECK_EQUAL(to_string(m
), "{}");
66 BOOST_AUTO_TEST_CASE(single_item_map_to_string
) {
67 std::map
<int, std::string
> m
;
69 BOOST_CHECK_EQUAL(to_string(m
), "{12: abc}");
72 BOOST_AUTO_TEST_CASE(multi_item_map_to_string
) {
73 std::map
<int, std::string
> m
;
76 BOOST_CHECK_EQUAL(to_string(m
), "{12: abc, 31: xyz}");
79 BOOST_AUTO_TEST_CASE(empty_set_to_string
) {
81 BOOST_CHECK_EQUAL(to_string(s
), "{}");
84 BOOST_AUTO_TEST_CASE(single_item_set_to_string
) {
87 BOOST_CHECK_EQUAL(to_string(s
), "{c}");
90 BOOST_AUTO_TEST_CASE(multi_item_set_to_string
) {
94 BOOST_CHECK_EQUAL(to_string(s
), "{a, z}");
97 BOOST_AUTO_TEST_CASE(generated_empty_object_to_string
) {
98 thrift::test::EmptyStruct e
;
99 BOOST_CHECK_EQUAL(to_string(e
), "EmptyStruct()");
102 BOOST_AUTO_TEST_CASE(generated_single_basic_field_object_to_string
) {
103 thrift::test::StructA a
;
105 BOOST_CHECK_EQUAL(to_string(a
), "StructA(s=abcd)");
108 BOOST_AUTO_TEST_CASE(generated_two_basic_fields_object_to_string
) {
109 thrift::test::Bonk a
;
110 a
.__set_message("abcd");
112 BOOST_CHECK_EQUAL(to_string(a
), "Bonk(message=abcd, type=1234)");
115 BOOST_AUTO_TEST_CASE(generated_optional_fields_object_to_string
) {
116 thrift::test::Tricky2 a
;
117 BOOST_CHECK_EQUAL(to_string(a
), "Tricky2(im_optional=<null>)");
118 a
.__set_im_optional(123);
119 BOOST_CHECK_EQUAL(to_string(a
), "Tricky2(im_optional=123)");
122 BOOST_AUTO_TEST_CASE(generated_nested_object_to_string
) {
123 thrift::test::OneField a
;
124 BOOST_CHECK_EQUAL(to_string(a
), "OneField(field=EmptyStruct())");
127 BOOST_AUTO_TEST_CASE(generated_nested_list_object_to_string
) {
128 thrift::test::ListBonks l
;
129 l
.bonk
.assign(2, thrift::test::Bonk());
130 l
.bonk
[0].__set_message("a");
131 l
.bonk
[1].__set_message("b");
133 BOOST_CHECK_EQUAL(to_string(l
),
134 "ListBonks(bonk=[Bonk(message=a, type=0), Bonk(message=b, type=0)])");
137 BOOST_AUTO_TEST_SUITE_END()