From d343428241380537f7212406f051c0d5057fbd1e Mon Sep 17 00:00:00 2001 From: wangwei <1261385937@qq.com> Date: Wed, 1 Nov 2023 17:55:49 +0800 Subject: [PATCH] add ut --- ut/Column_ut.cpp | 50 +++++++++++++----------------------------------- ut/utils_meta.h | 14 ++++++++++++++ 2 files changed, 27 insertions(+), 37 deletions(-) diff --git a/ut/Column_ut.cpp b/ut/Column_ut.cpp index 9eb3c7cf..bac666ec 100644 --- a/ut/Column_ut.cpp +++ b/ut/Column_ut.cpp @@ -376,25 +376,18 @@ TYPED_TEST(GenericColumnTest, Swap) { #endif TYPED_TEST(GenericColumnTest, ReserveAndCapacity) { - if constexpr ( - // TODO(venemkov): test that ColumnType has Reserve() and Capacity() methods - is_one_of_v) { - + using column_type = typename TestFixture::ColumnType; + auto [column0, values] = this->MakeColumnWithValues(2); + auto values_copy = values; + EXPECT_NO_THROW(column0->Reserve(0u)); + EXPECT_EQ(2u, column0->Size()); + EXPECT_TRUE(CompareRecursive(values, values_copy)); + + auto column1 = this->MakeColumn(); + column1->Reserve(10u); + EXPECT_EQ(0u, column1->Size()); + + if constexpr (has_method_Reserve_v && has_method_Capacity_v) { auto column = this->MakeColumn(); EXPECT_EQ(0u, column->Capacity()); EXPECT_NO_THROW(column->Reserve(100u)); @@ -408,24 +401,7 @@ TYPED_TEST(GenericColumnTest, ReserveAndCapacity) { TYPED_TEST(GenericColumnTest, GetWritableData) { - if constexpr ( - // TODO(venemkov): test that ColumnType has GetWritableData() method - is_one_of_v) { + if constexpr (has_method_GetWritableData_v) { auto [column, values] = this->MakeColumnWithValues(111); // Do conversion from time_t to internal representation, similar to what ColumnDate and ColumnDate32 do if constexpr (is_one_of_v { template inline constexpr bool is_one_of_v = is_one_of::value; + + +#define HAS_METHOD(FUN) \ +template \ +struct has_method_##FUN : std::false_type {}; \ +template \ +struct has_method_##FUN>> \ +: std::true_type {}; \ +template \ +constexpr bool has_method_##FUN##_v = has_method_##FUN::value; + +HAS_METHOD(Reserve); +HAS_METHOD(Capacity); +HAS_METHOD(GetWritableData);