From 19fcec84d8d7d21e796c7624e521b60d28ee21ed Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 20:45:59 +0200 Subject: Adding upstream version 16.2.11+ds. Signed-off-by: Daniel Baumann --- .../thrift/lib/cpp/test/ToStringTest.cpp | 137 +++++++++++++++++++++ 1 file changed, 137 insertions(+) create mode 100644 src/jaegertracing/thrift/lib/cpp/test/ToStringTest.cpp (limited to 'src/jaegertracing/thrift/lib/cpp/test/ToStringTest.cpp') diff --git a/src/jaegertracing/thrift/lib/cpp/test/ToStringTest.cpp b/src/jaegertracing/thrift/lib/cpp/test/ToStringTest.cpp new file mode 100644 index 000000000..d204cb346 --- /dev/null +++ b/src/jaegertracing/thrift/lib/cpp/test/ToStringTest.cpp @@ -0,0 +1,137 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +#include +#include + +#include + +#include + +#include "gen-cpp/ThriftTest_types.h" +#include "gen-cpp/OptionalRequiredTest_types.h" +#include "gen-cpp/DebugProtoTest_types.h" + +using apache::thrift::to_string; + +BOOST_AUTO_TEST_SUITE(ToStringTest) + +BOOST_AUTO_TEST_CASE(base_types_to_string) { + BOOST_CHECK_EQUAL(to_string(10), "10"); + BOOST_CHECK_EQUAL(to_string(true), "1"); + BOOST_CHECK_EQUAL(to_string('a'), "a"); + BOOST_CHECK_EQUAL(to_string(1.2), "1.2"); + BOOST_CHECK_EQUAL(to_string("abc"), "abc"); +} + +BOOST_AUTO_TEST_CASE(empty_vector_to_string) { + std::vector l; + BOOST_CHECK_EQUAL(to_string(l), "[]"); +} + +BOOST_AUTO_TEST_CASE(single_item_vector_to_string) { + std::vector l; + l.push_back(100); + BOOST_CHECK_EQUAL(to_string(l), "[100]"); +} + +BOOST_AUTO_TEST_CASE(multiple_item_vector_to_string) { + std::vector l; + l.push_back(100); + l.push_back(150); + BOOST_CHECK_EQUAL(to_string(l), "[100, 150]"); +} + +BOOST_AUTO_TEST_CASE(empty_map_to_string) { + std::map m; + BOOST_CHECK_EQUAL(to_string(m), "{}"); +} + +BOOST_AUTO_TEST_CASE(single_item_map_to_string) { + std::map m; + m[12] = "abc"; + BOOST_CHECK_EQUAL(to_string(m), "{12: abc}"); +} + +BOOST_AUTO_TEST_CASE(multi_item_map_to_string) { + std::map m; + m[12] = "abc"; + m[31] = "xyz"; + BOOST_CHECK_EQUAL(to_string(m), "{12: abc, 31: xyz}"); +} + +BOOST_AUTO_TEST_CASE(empty_set_to_string) { + std::set s; + BOOST_CHECK_EQUAL(to_string(s), "{}"); +} + +BOOST_AUTO_TEST_CASE(single_item_set_to_string) { + std::set s; + s.insert('c'); + BOOST_CHECK_EQUAL(to_string(s), "{c}"); +} + +BOOST_AUTO_TEST_CASE(multi_item_set_to_string) { + std::set s; + s.insert('a'); + s.insert('z'); + BOOST_CHECK_EQUAL(to_string(s), "{a, z}"); +} + +BOOST_AUTO_TEST_CASE(generated_empty_object_to_string) { + thrift::test::EmptyStruct e; + BOOST_CHECK_EQUAL(to_string(e), "EmptyStruct()"); +} + +BOOST_AUTO_TEST_CASE(generated_single_basic_field_object_to_string) { + thrift::test::StructA a; + a.__set_s("abcd"); + BOOST_CHECK_EQUAL(to_string(a), "StructA(s=abcd)"); +} + +BOOST_AUTO_TEST_CASE(generated_two_basic_fields_object_to_string) { + thrift::test::Bonk a; + a.__set_message("abcd"); + a.__set_type(1234); + BOOST_CHECK_EQUAL(to_string(a), "Bonk(message=abcd, type=1234)"); +} + +BOOST_AUTO_TEST_CASE(generated_optional_fields_object_to_string) { + thrift::test::Tricky2 a; + BOOST_CHECK_EQUAL(to_string(a), "Tricky2(im_optional=)"); + a.__set_im_optional(123); + BOOST_CHECK_EQUAL(to_string(a), "Tricky2(im_optional=123)"); +} + +BOOST_AUTO_TEST_CASE(generated_nested_object_to_string) { + thrift::test::OneField a; + BOOST_CHECK_EQUAL(to_string(a), "OneField(field=EmptyStruct())"); +} + +BOOST_AUTO_TEST_CASE(generated_nested_list_object_to_string) { + thrift::test::ListBonks l; + l.bonk.assign(2, thrift::test::Bonk()); + l.bonk[0].__set_message("a"); + l.bonk[1].__set_message("b"); + + BOOST_CHECK_EQUAL(to_string(l), + "ListBonks(bonk=[Bonk(message=a, type=0), Bonk(message=b, type=0)])"); +} + +BOOST_AUTO_TEST_SUITE_END() -- cgit v1.2.3