/* * Copyright (c) Meta Platforms, Inc. and affiliates. * * Licensed 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 #include #include using namespace apache::thrift; using namespace apache::thrift::protocol; namespace tc = apache::thrift::type_class; class TraitsTest : public testing::Test { public: template struct indy_value { T value; }; struct indy_access { template constexpr auto operator()(T&& t) const noexcept -> decltype((static_cast(t).value)); }; template using indy_tag = detail::indirection_tag; }; TEST_F(TraitsTest, protocol_type) { EXPECT_EQ(TType::T_BOOL, (protocol_type_v)); EXPECT_EQ(TType::T_I08, (protocol_type_v)); EXPECT_EQ(TType::T_I08, (protocol_type_v)); EXPECT_EQ(TType::T_I16, (protocol_type_v)); EXPECT_EQ(TType::T_I16, (protocol_type_v)); EXPECT_EQ(TType::T_I32, (protocol_type_v)); EXPECT_EQ(TType::T_I32, (protocol_type_v)); EXPECT_EQ(TType::T_I64, (protocol_type_v)); EXPECT_EQ(TType::T_I64, (protocol_type_v)); EXPECT_EQ(TType::T_FLOAT, (protocol_type_v)); EXPECT_EQ(TType::T_DOUBLE, (protocol_type_v)); EXPECT_EQ(TType::T_I32, (protocol_type_v)); EXPECT_EQ(TType::T_STRING, (protocol_type_v)); EXPECT_EQ(TType::T_STRING, (protocol_type_v)); EXPECT_EQ(TType::T_STRUCT, (protocol_type_v)); EXPECT_EQ(TType::T_STRUCT, (protocol_type_v)); EXPECT_EQ(TType::T_LIST, (protocol_type_v, void>)); EXPECT_EQ(TType::T_SET, (protocol_type_v, void>)); EXPECT_EQ(TType::T_MAP, (protocol_type_v, void>)); EXPECT_EQ( TType::T_FLOAT, (protocol_type_v, indy_value>)); } template class FixedCostSkipTest : public testing::Test {}; struct Struct {}; enum class Enum {}; using TypeClassesAndType = ::testing::Types< std::pair, std::pair, std::pair, std::pair, std::pair, std::pair, std::pair, std::pair, std::pair, std::pair>; TYPED_TEST_CASE(FixedCostSkipTest, TypeClassesAndType); TYPED_TEST(FixedCostSkipTest, Compact) { using P = CompactProtocolReader; using TC = typename TypeParam::first_type; using T = typename TypeParam::second_type; EXPECT_EQ( (!std::is_same_v && !std::is_same_v), (fixed_cost_skip_v)); EXPECT_EQ( (std::is_same_v || // std::is_same_v || // std::is_same_v), (fixed_cost_skip_v, std::vector>)); EXPECT_EQ( (std::is_same_v || // std::is_same_v || // std::is_same_v), (fixed_cost_skip_v, std::set>)); EXPECT_EQ( (fixed_cost_skip_v, std::vector>), (fixed_cost_skip_v< P, tc::map, std::map>)); EXPECT_FALSE( // (fixed_cost_skip_v< P, tc::map, std::map>)); EXPECT_FALSE(( fixed_cost_skip_v, std::map>)); } TYPED_TEST(FixedCostSkipTest, Binary) { using P = BinaryProtocolReader; using TC = typename TypeParam::first_type; using T = typename TypeParam::second_type; EXPECT_EQ( (!std::is_same_v && !std::is_same_v), (fixed_cost_skip_v)); EXPECT_EQ( (std::is_same_v || std::is_same_v || std::is_same_v), (fixed_cost_skip_v, std::vector>)); EXPECT_EQ( (std::is_same_v || std::is_same_v || std::is_same_v), (fixed_cost_skip_v, std::set>)); EXPECT_EQ( (fixed_cost_skip_v, std::vector>), (fixed_cost_skip_v< P, tc::map, std::map>)); EXPECT_EQ( (fixed_cost_skip_v, std::vector>), (fixed_cost_skip_v< P, tc::map, std::map>)); EXPECT_FALSE(( fixed_cost_skip_v, std::map>)); } TYPED_TEST(FixedCostSkipTest, SimpleJSON) { using P = SimpleJSONProtocolReader; using TC = typename TypeParam::first_type; using T = typename TypeParam::second_type; EXPECT_EQ( (std::is_same_v || std::is_same_v || std::is_same_v), (fixed_cost_skip_v)); EXPECT_FALSE((fixed_cost_skip_v, std::vector>)); EXPECT_FALSE((fixed_cost_skip_v, std::set>)); EXPECT_FALSE((fixed_cost_skip_v< P, tc::map, std::map>)); EXPECT_FALSE((fixed_cost_skip_v< P, tc::map, std::map>)); EXPECT_FALSE(( fixed_cost_skip_v, std::map>)); }