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
#define ALLOW_FORBID_FUNC

23
#include "cmdnodes.h"
X
Xiaoyu Wang 已提交
24
#include "querynodes.h"
25
#include "taoserror.h"
26 27
#include "tglobal.h"
#include "ttime.h"
28 29 30

namespace ParserTest {

X
Xiaoyu Wang 已提交
31 32
class ParserTestBaseImpl;

33
enum ParserStage { PARSER_STAGE_PARSE = 1, PARSER_STAGE_TRANSLATE, PARSER_STAGE_CALC_CONST };
34

X
Xiaoyu Wang 已提交
35 36 37 38 39
class ParserTestBase : public testing::Test {
 public:
  ParserTestBase();
  virtual ~ParserTestBase();

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

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

X
Xiaoyu Wang 已提交
46 47 48 49
 private:
  std::unique_ptr<ParserTestBaseImpl> impl_;
};

X
Xiaoyu Wang 已提交
50 51 52 53 54 55 56
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 已提交
57 58 59 60 61 62
    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 已提交
63 64 65 66 67 68 69 70 71
    if (nullptr != checkDdl_) {
      checkDdl_(pQuery, stage);
    }
  }

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

72
extern bool g_dump;
73 74 75 76 77

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

79 80
}  // namespace ParserTest

81
#endif  // PARSER_TEST_UTIL_H