diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 18:45:59 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 18:45:59 +0000 |
commit | 19fcec84d8d7d21e796c7624e521b60d28ee21ed (patch) | |
tree | 42d26aa27d1e3f7c0b8bd3fd14e7d7082f5008dc /src/jaegertracing/thrift/lib/cpp/test/EnumTest.cpp | |
parent | Initial commit. (diff) | |
download | ceph-upstream.tar.xz ceph-upstream.zip |
Adding upstream version 16.2.11+ds.upstream/16.2.11+dsupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | src/jaegertracing/thrift/lib/cpp/test/EnumTest.cpp | 108 |
1 files changed, 108 insertions, 0 deletions
diff --git a/src/jaegertracing/thrift/lib/cpp/test/EnumTest.cpp b/src/jaegertracing/thrift/lib/cpp/test/EnumTest.cpp new file mode 100644 index 000000000..388abb7e9 --- /dev/null +++ b/src/jaegertracing/thrift/lib/cpp/test/EnumTest.cpp @@ -0,0 +1,108 @@ +/* + * 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. + */ +#define BOOST_TEST_MODULE EnumTest +#include <boost/test/unit_test.hpp> +#include "gen-cpp/EnumTest_types.h" + +std::ostream& operator <<(std::ostream& os, const MyEnumWithCustomOstream::type& val) +{ + os << "{" << (int)val << ":CUSTOM!" << "}"; + return os; +} + +std::string to_string(const MyEnumWithCustomOstream::type& val) +{ + std::ostringstream os; + os << val; + return os.str(); +} + +BOOST_AUTO_TEST_SUITE(EnumTest) + +BOOST_AUTO_TEST_CASE(test_enum_value) { + // Check that all the enum values match what we expect + BOOST_CHECK_EQUAL(MyEnum1::ME1_0, 0); + BOOST_CHECK_EQUAL(MyEnum1::ME1_1, 1); + BOOST_CHECK_EQUAL(MyEnum1::ME1_2, 2); + BOOST_CHECK_EQUAL(MyEnum1::ME1_3, 3); + BOOST_CHECK_EQUAL(MyEnum1::ME1_5, 5); + BOOST_CHECK_EQUAL(MyEnum1::ME1_6, 6); + + BOOST_CHECK_EQUAL(MyEnum2::ME2_0, 0); + BOOST_CHECK_EQUAL(MyEnum2::ME2_1, 1); + BOOST_CHECK_EQUAL(MyEnum2::ME2_2, 2); + + BOOST_CHECK_EQUAL(MyEnum3::ME3_0, 0); + BOOST_CHECK_EQUAL(MyEnum3::ME3_1, 1); + BOOST_CHECK_EQUAL(MyEnum3::ME3_N2, -2); + BOOST_CHECK_EQUAL(MyEnum3::ME3_N1, -1); + BOOST_CHECK_EQUAL(MyEnum3::ME3_D0, 0); + BOOST_CHECK_EQUAL(MyEnum3::ME3_D1, 1); + BOOST_CHECK_EQUAL(MyEnum3::ME3_9, 9); + BOOST_CHECK_EQUAL(MyEnum3::ME3_10, 10); + + BOOST_CHECK_EQUAL(MyEnum4::ME4_A, 0x7ffffffd); + BOOST_CHECK_EQUAL(MyEnum4::ME4_B, 0x7ffffffe); + BOOST_CHECK_EQUAL(MyEnum4::ME4_C, 0x7fffffff); + + BOOST_CHECK_EQUAL(MyEnum5::e1, 0); + BOOST_CHECK_EQUAL(MyEnum5::e2, 42); +} + +template <class _T> +std::string EnumToString(_T e) +{ + std::stringstream ss; + ss << e; + return ss.str(); +} + +BOOST_AUTO_TEST_CASE(test_enum_ostream) +{ + BOOST_CHECK_EQUAL(EnumToString(MyEnum1::ME1_0), "ME1_0"); + BOOST_CHECK_EQUAL(EnumToString(MyEnum5::e2), "e2"); + BOOST_CHECK_EQUAL(EnumToString(MyEnum3::ME3_N1), "ME3_N1"); + BOOST_CHECK_EQUAL(EnumToString(MyEnumWithCustomOstream::CustoM2), "{2:CUSTOM!}"); + + // some invalid or unknown value + auto uut = static_cast<MyEnum5::type>(44); + BOOST_CHECK_EQUAL(EnumToString(uut), "44"); +} + +BOOST_AUTO_TEST_CASE(test_enum_to_string) +{ + BOOST_CHECK_EQUAL(::to_string(MyEnum1::ME1_0), "ME1_0"); + BOOST_CHECK_EQUAL(::to_string(MyEnum5::e2), "e2"); + BOOST_CHECK_EQUAL(::to_string(MyEnum3::ME3_N1), "ME3_N1"); + BOOST_CHECK_EQUAL(::to_string(MyEnumWithCustomOstream::CustoM2), "{2:CUSTOM!}"); + + // some invalid or unknown value + auto uut = static_cast<MyEnum5::type>(44); + BOOST_CHECK_EQUAL(::to_string(uut), "44"); +} + +BOOST_AUTO_TEST_CASE(test_enum_constant) +{ + MyStruct ms; + BOOST_CHECK_EQUAL(ms.me2_2, 2); + BOOST_CHECK_EQUAL(ms.me3_n2, -2); + BOOST_CHECK_EQUAL(ms.me3_d1, 1); +} + +BOOST_AUTO_TEST_SUITE_END() |