/** * Copyright (c) 2021 OceanBase * OceanBase CE is licensed under Mulan PubL v2. * You can use this software according to the terms and conditions of the Mulan PubL v2. * You may obtain a copy of Mulan PubL v2 at: * http://license.coscl.org.cn/MulanPubL-2.0 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. * See the Mulan PubL v2 for more details. */ #include #include "sql/engine/expr/ob_expr_neg.h" #include using namespace oceanbase::common; using namespace oceanbase::sql; class ObExprNegTest: public ::testing::Test { public: ObExprNegTest(); virtual ~ObExprNegTest(); virtual void SetUp(); virtual void TearDown(); private: // disallow copy ObExprNegTest(const ObExprNegTest &other); ObExprNegTest& operator=(const ObExprNegTest &other); protected: // data members }; ObExprNegTest::ObExprNegTest() { } ObExprNegTest::~ObExprNegTest() { } void ObExprNegTest::SetUp() { } void ObExprNegTest::TearDown() { } #define EV 0.00001 #define ARITH_EXPECT_TYPE_WITH_ROW(cmp_op, func, type1, res) \ { \ ObExprResType t1; \ ObExprResType vres; \ ObExprTypeCtx ctx; \ ObArenaAllocator alloc;\ cmp_op op(alloc); \ op.set_row_dimension(1); \ t1.set_type(type1); \ int err = op.func(vres, t1, ctx); \ ASSERT_EQ(res, err); \ }while(0) #define ARITH_EXPECT_TYPE(cmp_op, func, type1, res) \ { \ ObExprResType t1; \ ObExprResType vres; \ ObExprTypeCtx ctx; \ ObArenaAllocator alloc;\ cmp_op op(alloc); \ t1.set_type(type1); \ int err = op.func(vres, t1, ctx); \ ASSERT_EQ(OB_SUCCESS, err); \ ASSERT_EQ(res, vres.get_type()); \ }while(0) #define ARITH_EXPECT_TYPE_ERROR(cmp_op, func, type1) \ { \ ObExprResType t1; \ ObExprResType vres; \ ObExprTypeCtx ctx; \ ObArenaAllocator alloc;\ cmp_op op(alloc); \ t1.set_type(type1); \ int err = op.func(vres, t1, ctx); \ ASSERT_EQ(OB_ERR_INVALID_TYPE_FOR_OP, err); \ }while(0) #define ARITH_ERROR(cmp_op, str_buf, func, type1, v1, res) \ { \ ObObj t1; \ ObObj vres; \ ObArenaAllocator alloc;\ cmp_op op(alloc); \ t1.set_##type1(v1); \ int err = op.func(vres, t1, str_buf); \ ASSERT_EQ(res, err); \ }while(0) #define ARITH_EXPECT(cmp_op, str_buf, func, type1, v1, res) \ { \ ObObj t1; \ ObObj vres; \ ObArenaAllocator alloc;\ cmp_op op(alloc); \ t1.set_##type1(v1); \ int err = op.func(vres, t1, str_buf); \ if (OB_SUCCESS != err) \ { \ ASSERT_EQ(res, err); \ } \ else \ { \ ASSERT_EQ(OB_SUCCESS, err); \ switch(vres.get_type()) \ { \ case ObIntType: \ ASSERT_EQ(res, vres.get_int()); \ break; \ case ObDateTimeType: \ ASSERT_EQ(res, vres.get_datetime()); \ break; \ case ObPreciseDateTimeType: \ ASSERT_EQ(res, vres.get_precise_datetime()); \ break; \ case ObCreateTimeType: \ ASSERT_EQ(res, vres.get_ctime()); \ break; \ case ObModifyTimeType: \ ASSERT_EQ(res, vres.get_mtime()); \ break; \ case ObBoolType: \ ASSERT_EQ(res, vres.get_bool()); \ break; \ case ObFloatType: \ ASSERT_TRUE(fabsf(res-vres.get_float()