parTestUtil.h 2.3 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
/*
 * Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
 *
 * This program is free software: you can use, redistribute, and/or modify
 * it under the terms of the GNU Affero General Public License, version 3
 * or later ("AGPL"), as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */

16 17 18
#ifndef PARSER_TEST_UTIL_H
#define PARSER_TEST_UTIL_H

X
Xiaoyu Wang 已提交
19 20
#include <gtest/gtest.h>

X
Xiaoyu Wang 已提交
21 22 23
#define ALLOW_FORBID_FUNC

#include "querynodes.h"
24 25 26 27
#include "taoserror.h"

namespace ParserTest {

X
Xiaoyu Wang 已提交
28 29
class ParserTestBaseImpl;

30
enum ParserStage { PARSER_STAGE_PARSE = 1, PARSER_STAGE_TRANSLATE, PARSER_STAGE_CALC_CONST };
31

X
Xiaoyu Wang 已提交
32 33 34 35 36
class ParserTestBase : public testing::Test {
 public:
  ParserTestBase();
  virtual ~ParserTestBase();

37
  void login(const std::string& user);
X
Xiaoyu Wang 已提交
38
  void useDb(const std::string& acctId, const std::string& db);
X
Xiaoyu Wang 已提交
39
  void run(const std::string& sql, int32_t expect = TSDB_CODE_SUCCESS, ParserStage checkStage = PARSER_STAGE_TRANSLATE);
X
Xiaoyu Wang 已提交
40

X
Xiaoyu Wang 已提交
41 42
  virtual void checkDdl(const SQuery* pQuery, ParserStage stage);

X
Xiaoyu Wang 已提交
43 44 45 46
 private:
  std::unique_ptr<ParserTestBaseImpl> impl_;
};

X
Xiaoyu Wang 已提交
47 48 49 50 51 52 53
class ParserDdlTest : public ParserTestBase {
 public:
  void setCheckDdlFunc(const std::function<void(const SQuery*, ParserStage)>& func) { checkDdl_ = func; }

  virtual void checkDdl(const SQuery* pQuery, ParserStage stage) {
    ASSERT_NE(pQuery, nullptr);
    ASSERT_NE(pQuery->pRoot, nullptr);
X
Xiaoyu Wang 已提交
54 55 56 57 58 59
    if (QUERY_EXEC_MODE_RPC == pQuery->execMode) {
      ASSERT_EQ(pQuery->haveResultSet, false);
      ASSERT_EQ(pQuery->numOfResCols, 0);
      ASSERT_EQ(pQuery->pResSchema, nullptr);
      ASSERT_EQ(pQuery->precision, 0);
    }
X
Xiaoyu Wang 已提交
60 61 62 63 64 65 66 67 68
    if (nullptr != checkDdl_) {
      checkDdl_(pQuery, stage);
    }
  }

 private:
  std::function<void(const SQuery*, ParserStage)> checkDdl_;
};

69
extern bool g_dump;
70 71 72 73 74

extern void    setAsyncFlag(const char* pFlag);
extern void    setLogLevel(const char* pLogLevel);
extern int32_t getLogLevel();
extern void    setSkipSqlNum(const char* pNum);
75

76 77
}  // namespace ParserTest

78
#endif  // PARSER_TEST_UTIL_H