base.h 3.3 KB
Newer Older
S
Shengliang Guan 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
/*
 * 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/>.
 */

#ifndef _TD_TEST_BASE_H_
#define _TD_TEST_BASE_H_

#include <gtest/gtest.h>
#include "os.h"

#include "dnode.h"
H
Hongze Cheng 已提交
23
#include "tmsg.h"
S
Shengliang Guan 已提交
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
#include "tconfig.h"
#include "tdataformat.h"
#include "tglobal.h"
#include "tnote.h"
#include "trpc.h"
#include "tthread.h"
#include "ulog.h"

#include "client.h"
#include "server.h"

class Testbase {
 public:
  void     Init(const char* path, int16_t port);
  void     Cleanup();
S
Shengliang Guan 已提交
39
  void     Restart();
S
Shengliang Guan 已提交
40 41 42 43 44 45 46 47 48 49 50
  SRpcMsg* SendMsg(int8_t msgType, void* pCont, int32_t contLen);

 private:
  void InitLog(const char* path);

 private:
  TestServer server;
  TestClient client;
  int32_t    connId;

 public:
S
Shengliang Guan 已提交
51
  void SendShowMetaMsg(int8_t showType, const char* db);
S
Shengliang Guan 已提交
52 53
  void SendShowRetrieveMsg();

S
Shengliang Guan 已提交
54 55 56 57 58 59 60 61 62 63
  STableMetaMsg*     GetShowMeta();
  SRetrieveTableRsp* GetRetrieveRsp();

  int32_t     GetMetaNum();
  const char* GetMetaTbName();
  int32_t     GetMetaColId(int32_t index);
  int8_t      GetMetaType(int32_t index);
  int32_t     GetMetaBytes(int32_t index);
  const char* GetMetaName(int32_t index);

S
Shengliang Guan 已提交
64
  const char* GetShowName();
S
Shengliang Guan 已提交
65
  int32_t     GetShowRows();
S
Shengliang Guan 已提交
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
  int8_t      GetShowInt8();
  int16_t     GetShowInt16();
  int32_t     GetShowInt32();
  int64_t     GetShowInt64();
  int64_t     GetShowTimestamp();
  const char* GetShowBinary(int32_t len);

 private:
  int32_t            showId;
  STableMetaMsg*     pMeta;
  SRetrieveTableRsp* pRetrieveRsp;
  char*              pData;
  int32_t            pos;
};

S
Shengliang Guan 已提交
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129
#define CHECK_META(tbName, numOfColumns)        \
  {                                             \
    EXPECT_EQ(test.GetMetaNum(), numOfColumns); \
    EXPECT_STREQ(test.GetMetaTbName(), tbName); \
  }

#define CHECK_SCHEMA(colId, type, bytes, colName)   \
  {                                                 \
    EXPECT_EQ(test.GetMetaType(colId), type);       \
    EXPECT_EQ(test.GetMetaBytes(colId), bytes);     \
    EXPECT_STREQ(test.GetMetaName(colId), colName); \
  }

#define CheckBinary(val, len) \
  { EXPECT_STREQ(test.GetShowBinary(len), val); }

#define CheckInt8(val) \
  { EXPECT_EQ(test.GetShowInt8(), val); }

#define CheckInt16(val) \
  { EXPECT_EQ(test.GetShowInt16(), val); }

#define CheckInt32(val) \
  { EXPECT_EQ(test.GetShowInt32(), val); }

#define CheckInt64(val) \
  { EXPECT_EQ(test.GetShowInt64(), val); }

#define CheckTimestamp() \
  { EXPECT_GT(test.GetShowTimestamp(), 0); }

#define IgnoreBinary(len) \
  { test.GetShowBinary(len); }

#define IgnoreInt8() \
  { test.GetShowInt8(); }

#define IgnoreInt16() \
  { test.GetShowInt16(); }

#define IgnoreInt32() \
  { test.GetShowInt32(); }

#define IgnoreInt64() \
  { test.GetShowInt64(); }

#define IgnoreTimestamp() \
  { test.GetShowTimestamp(); }

S
Shengliang Guan 已提交
130
#endif /* _TD_TEST_BASE_H_ */