encodeTest.cpp 14.6 KB
Newer Older
H
Hongze Cheng 已提交
1 2
#include <iostream>

3
#include <gtest/gtest.h>
H
Hongze Cheng 已提交
4

S
Shengliang Guan 已提交
5
#include "tencode.h"
H
Hongze Cheng 已提交
6

S
Shengliang Guan 已提交
7 8 9 10 11
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wshift-count-overflow"
#pragma GCC diagnostic ignored "-Woverflow"
#pragma GCC diagnostic ignored "-Woverflow"

H
Hongze Cheng 已提交
12 13 14
#define BUF_SIZE 64
td_endian_t endian_arr[2] = {TD_LITTLE_ENDIAN, TD_BIG_ENDIAN};

H
Hongze Cheng 已提交
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
static int32_t encode(SEncoder *pCoder, int8_t val) { return tEncodeI8(pCoder, val); }
static int32_t encode(SEncoder *pCoder, uint8_t val) { return tEncodeU8(pCoder, val); }
static int32_t encode(SEncoder *pCoder, int16_t val) { return tEncodeI16(pCoder, val); }
static int32_t encode(SEncoder *pCoder, uint16_t val) { return tEncodeU16(pCoder, val); }
static int32_t encode(SEncoder *pCoder, int32_t val) { return tEncodeI32(pCoder, val); }
static int32_t encode(SEncoder *pCoder, uint32_t val) { return tEncodeU32(pCoder, val); }
static int32_t encode(SEncoder *pCoder, int64_t val) { return tEncodeI64(pCoder, val); }
static int32_t encode(SEncoder *pCoder, uint64_t val) { return tEncodeU64(pCoder, val); }

static int32_t decode(SDecoder *pCoder, int8_t *val) { return tDecodeI8(pCoder, val); }
static int32_t decode(SDecoder *pCoder, uint8_t *val) { return tDecodeU8(pCoder, val); }
static int32_t decode(SDecoder *pCoder, int16_t *val) { return tDecodeI16(pCoder, val); }
static int32_t decode(SDecoder *pCoder, uint16_t *val) { return tDecodeU16(pCoder, val); }
static int32_t decode(SDecoder *pCoder, int32_t *val) { return tDecodeI32(pCoder, val); }
static int32_t decode(SDecoder *pCoder, uint32_t *val) { return tDecodeU32(pCoder, val); }
static int32_t decode(SDecoder *pCoder, int64_t *val) { return tDecodeI64(pCoder, val); }
static int32_t decode(SDecoder *pCoder, uint64_t *val) { return tDecodeU64(pCoder, val); }

static int32_t encodev(SEncoder *pCoder, int8_t val) { return tEncodeI8(pCoder, val); }
static int32_t encodev(SEncoder *pCoder, uint8_t val) { return tEncodeU8(pCoder, val); }
static int32_t encodev(SEncoder *pCoder, int16_t val) { return tEncodeI16v(pCoder, val); }
static int32_t encodev(SEncoder *pCoder, uint16_t val) { return tEncodeU16v(pCoder, val); }
static int32_t encodev(SEncoder *pCoder, int32_t val) { return tEncodeI32v(pCoder, val); }
static int32_t encodev(SEncoder *pCoder, uint32_t val) { return tEncodeU32v(pCoder, val); }
static int32_t encodev(SEncoder *pCoder, int64_t val) { return tEncodeI64v(pCoder, val); }
static int32_t encodev(SEncoder *pCoder, uint64_t val) { return tEncodeU64v(pCoder, val); }

static int32_t decodev(SDecoder *pCoder, int8_t *val) { return tDecodeI8(pCoder, val); }
static int32_t decodev(SDecoder *pCoder, uint8_t *val) { return tDecodeU8(pCoder, val); }
static int32_t decodev(SDecoder *pCoder, int16_t *val) { return tDecodeI16v(pCoder, val); }
static int32_t decodev(SDecoder *pCoder, uint16_t *val) { return tDecodeU16v(pCoder, val); }
static int32_t decodev(SDecoder *pCoder, int32_t *val) { return tDecodeI32v(pCoder, val); }
static int32_t decodev(SDecoder *pCoder, uint32_t *val) { return tDecodeU32v(pCoder, val); }
static int32_t decodev(SDecoder *pCoder, int64_t *val) { return tDecodeI64v(pCoder, val); }
static int32_t decodev(SDecoder *pCoder, uint64_t *val) { return tDecodeU64v(pCoder, val); }
H
Hongze Cheng 已提交
50 51 52

template <typename T>
static void simple_encode_decode_func(bool var_len) {
H
Hongze Cheng 已提交
53 54 55 56 57
  uint8_t  buf[BUF_SIZE];
  SEncoder encoder = {0};
  SDecoder decoder = {0};
  T        min_val, max_val;
  T        step = 1;
H
Hongze Cheng 已提交
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98

  if (typeid(T) == typeid(int8_t)) {
    min_val = INT8_MIN;
    max_val = INT8_MAX;
    step = 1;
  } else if (typeid(T) == typeid(uint8_t)) {
    min_val = 0;
    max_val = UINT8_MAX;
    step = 1;
  } else if (typeid(T) == typeid(int16_t)) {
    min_val = INT16_MIN;
    max_val = INT16_MAX;
    step = 1;
  } else if (typeid(T) == typeid(uint16_t)) {
    min_val = 0;
    max_val = UINT16_MAX;
    step = 1;
  } else if (typeid(T) == typeid(int32_t)) {
    min_val = INT32_MIN;
    max_val = INT32_MAX;
    step = ((T)1) << 16;
  } else if (typeid(T) == typeid(uint32_t)) {
    min_val = 0;
    max_val = UINT32_MAX;
    step = ((T)1) << 16;
  } else if (typeid(T) == typeid(int64_t)) {
    min_val = INT64_MIN;
    max_val = INT64_MAX;
    step = ((T)1) << 48;
  } else if (typeid(T) == typeid(uint64_t)) {
    min_val = 0;
    max_val = UINT64_MAX;
    step = ((T)1) << 48;
  }

  T i = min_val;
  for (;; /*T i = min_val; i <= max_val; i += step*/) {
    T dval;

    // Encode NULL
    for (td_endian_t endian : endian_arr) {
H
Hongze Cheng 已提交
99
      tEncoderInit(&encoder, endian, NULL, 0, TD_ENCODER);
H
Hongze Cheng 已提交
100 101

      if (var_len) {
H
Hongze Cheng 已提交
102
        GTEST_ASSERT_EQ(encodev(&encoder, i), 0);
H
Hongze Cheng 已提交
103
      } else {
H
Hongze Cheng 已提交
104 105
        GTEST_ASSERT_EQ(encode(&encoder, i), 0);
        GTEST_ASSERT_EQ(encoder.pos, sizeof(T));
H
Hongze Cheng 已提交
106 107
      }

H
Hongze Cheng 已提交
108
      tCoderClear(&encoder);
H
Hongze Cheng 已提交
109 110 111 112 113 114
    }

    // Encode and decode
    for (td_endian_t e_endian : endian_arr) {
      for (td_endian_t d_endian : endian_arr) {
        // Encode
H
Hongze Cheng 已提交
115
        tCoderInit(&encoder, e_endian, buf, BUF_SIZE, TD_ENCODER);
H
Hongze Cheng 已提交
116 117

        if (var_len) {
H
Hongze Cheng 已提交
118
          GTEST_ASSERT_EQ(encodev(&encoder, i), 0);
H
Hongze Cheng 已提交
119
        } else {
H
Hongze Cheng 已提交
120 121
          GTEST_ASSERT_EQ(encode(&encoder, i), 0);
          GTEST_ASSERT_EQ(encoder.pos, sizeof(T));
H
Hongze Cheng 已提交
122 123
        }

H
Hongze Cheng 已提交
124
        int32_t epos = encoder.pos;
H
Hongze Cheng 已提交
125

H
Hongze Cheng 已提交
126
        tCoderClear(&encoder);
H
Hongze Cheng 已提交
127
        // Decode
H
Hongze Cheng 已提交
128
        tCoderInit(&encoder, d_endian, buf, BUF_SIZE, TD_DECODER);
H
Hongze Cheng 已提交
129 130

        if (var_len) {
H
Hongze Cheng 已提交
131
          GTEST_ASSERT_EQ(decodev(&encoder, &dval), 0);
H
Hongze Cheng 已提交
132
        } else {
H
Hongze Cheng 已提交
133 134
          GTEST_ASSERT_EQ(decode(&encoder, &dval), 0);
          GTEST_ASSERT_EQ(encoder.pos, sizeof(T));
H
Hongze Cheng 已提交
135 136
        }

H
Hongze Cheng 已提交
137
        GTEST_ASSERT_EQ(encoder.pos, epos);
H
Hongze Cheng 已提交
138

H
Hongze Cheng 已提交
139 140 141 142
        if (typeid(T) == typeid(int8_t) || typeid(T) == typeid(uint8_t) || e_endian == d_endian) {
          GTEST_ASSERT_EQ(i, dval);
        }

H
Hongze Cheng 已提交
143
        tCoderClear(&encoder);
H
Hongze Cheng 已提交
144 145 146 147 148 149 150 151 152 153 154 155 156
      }
    }

    if (i == max_val) break;

    if (max_val - i < step) {
      i = max_val;
    } else {
      i = i + step;
    }
  }
}

H
more  
Hongze Cheng 已提交
157
TEST(td_encode_test, encode_decode_fixed_len_integer) {
H
Hongze Cheng 已提交
158 159 160 161 162 163 164 165
  simple_encode_decode_func<int8_t>(false);
  simple_encode_decode_func<uint8_t>(false);
  simple_encode_decode_func<int16_t>(false);
  simple_encode_decode_func<uint16_t>(false);
  simple_encode_decode_func<int32_t>(false);
  simple_encode_decode_func<uint32_t>(false);
  simple_encode_decode_func<int64_t>(false);
  simple_encode_decode_func<uint64_t>(false);
H
more  
Hongze Cheng 已提交
166
}
H
Hongze Cheng 已提交
167

H
more  
Hongze Cheng 已提交
168
TEST(td_encode_test, encode_decode_variant_len_integer) {
H
Hongze Cheng 已提交
169 170 171 172 173 174
  simple_encode_decode_func<int16_t>(true);
  simple_encode_decode_func<uint16_t>(true);
  simple_encode_decode_func<int32_t>(true);
  simple_encode_decode_func<uint32_t>(true);
  simple_encode_decode_func<int64_t>(true);
  simple_encode_decode_func<uint64_t>(true);
H
more  
Hongze Cheng 已提交
175 176 177
}

TEST(td_encode_test, encode_decode_cstr) {
L
Liu Jicong 已提交
178 179
  uint8_t    *buf = new uint8_t[1024 * 1024];
  char       *cstr = new char[1024 * 1024];
H
more  
Hongze Cheng 已提交
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204
  const char *dcstr;
  SCoder      encoder;
  SCoder      decoder;

  for (size_t i = 0; i < 1024 * 2 - 1; i++) {
    memset(cstr, 'a', i);
    cstr[i] = '\0';
    for (td_endian_t endian : endian_arr) {
      // Encode
      tCoderInit(&encoder, endian, buf, 1024 * 1024, TD_ENCODER);

      GTEST_ASSERT_EQ(tEncodeCStr(&encoder, cstr), 0);

      tCoderClear(&encoder);

      // Decode
      tCoderInit(&decoder, endian, buf, 1024 * 1024, TD_DECODER);

      GTEST_ASSERT_EQ(tDecodeCStr(&decoder, &dcstr), 0);
      GTEST_ASSERT_EQ(memcmp(dcstr, cstr, i + 1), 0);

      tCoderClear(&decoder);
    }
  }

205 206
  delete[] buf;
  delete[] cstr;
H
more  
Hongze Cheng 已提交
207 208 209 210 211
}

typedef struct {
  int32_t A_a;
  int64_t A_b;
L
Liu Jicong 已提交
212
  char   *A_c;
H
more  
Hongze Cheng 已提交
213 214
} SStructA_v1;

S
encode  
Shengliang Guan 已提交
215
static int32_t tSStructA_v1_encode(SCoder *pCoder, const SStructA_v1 *pSAV1) {
H
more  
Hongze Cheng 已提交
216 217 218 219 220 221 222 223 224 225
  if (tStartEncode(pCoder) < 0) return -1;

  if (tEncodeI32(pCoder, pSAV1->A_a) < 0) return -1;
  if (tEncodeI64(pCoder, pSAV1->A_b) < 0) return -1;
  if (tEncodeCStr(pCoder, pSAV1->A_c) < 0) return -1;

  tEndEncode(pCoder);
  return 0;
}

S
encode  
Shengliang Guan 已提交
226
static int32_t tSStructA_v1_decode(SCoder *pCoder, SStructA_v1 *pSAV1) {
H
more  
Hongze Cheng 已提交
227 228 229 230 231 232 233
  if (tStartDecode(pCoder) < 0) return -1;

  if (tDecodeI32(pCoder, &pSAV1->A_a) < 0) return -1;
  if (tDecodeI64(pCoder, &pSAV1->A_b) < 0) return -1;
  const char *tstr;
  uint64_t    len;
  if (tDecodeCStrAndLen(pCoder, &tstr, &len) < 0) return -1;
wafwerar's avatar
wafwerar 已提交
234
  pSAV1->A_c = (char *)tCoderMalloc(pCoder, len + 1);
H
more  
Hongze Cheng 已提交
235 236 237 238 239 240 241 242 243
  memcpy(pSAV1->A_c, tstr, len + 1);

  tEndDecode(pCoder);
  return 0;
}

typedef struct {
  int32_t A_a;
  int64_t A_b;
L
Liu Jicong 已提交
244
  char   *A_c;
H
more  
Hongze Cheng 已提交
245 246 247 248 249
  // -------------------BELOW FEILDS ARE ADDED IN A NEW VERSION--------------
  int16_t A_d;
  int16_t A_e;
} SStructA_v2;

S
encode  
Shengliang Guan 已提交
250
static int32_t tSStructA_v2_encode(SCoder *pCoder, const SStructA_v2 *pSAV2) {
H
more  
Hongze Cheng 已提交
251 252 253 254 255 256 257 258 259 260 261 262 263 264
  if (tStartEncode(pCoder) < 0) return -1;

  if (tEncodeI32(pCoder, pSAV2->A_a) < 0) return -1;
  if (tEncodeI64(pCoder, pSAV2->A_b) < 0) return -1;
  if (tEncodeCStr(pCoder, pSAV2->A_c) < 0) return -1;

  // ------------------------NEW FIELDS ENCODE-------------------------------
  if (tEncodeI16(pCoder, pSAV2->A_d) < 0) return -1;
  if (tEncodeI16(pCoder, pSAV2->A_e) < 0) return -1;

  tEndEncode(pCoder);
  return 0;
}

S
encode  
Shengliang Guan 已提交
265
static int32_t tSStructA_v2_decode(SCoder *pCoder, SStructA_v2 *pSAV2) {
H
more  
Hongze Cheng 已提交
266 267 268 269 270 271 272
  if (tStartDecode(pCoder) < 0) return -1;

  if (tDecodeI32(pCoder, &pSAV2->A_a) < 0) return -1;
  if (tDecodeI64(pCoder, &pSAV2->A_b) < 0) return -1;
  const char *tstr;
  uint64_t    len;
  if (tDecodeCStrAndLen(pCoder, &tstr, &len) < 0) return -1;
wafwerar's avatar
wafwerar 已提交
273
  pSAV2->A_c = (char *)tCoderMalloc(pCoder, len + 1);
H
more  
Hongze Cheng 已提交
274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294
  memcpy(pSAV2->A_c, tstr, len + 1);

  // ------------------------NEW FIELDS DECODE-------------------------------
  if (!tDecodeIsEnd(pCoder)) {
    if (tDecodeI16(pCoder, &pSAV2->A_d) < 0) return -1;
    if (tDecodeI16(pCoder, &pSAV2->A_e) < 0) return -1;
  } else {
    pSAV2->A_d = 0;
    pSAV2->A_e = 0;
  }

  tEndDecode(pCoder);
  return 0;
}

typedef struct {
  SStructA_v1 *pA;
  int32_t      v_a;
  int8_t       v_b;
} SFinalReq_v1;

S
encode  
Shengliang Guan 已提交
295
static int32_t tSFinalReq_v1_encode(SCoder *pCoder, const SFinalReq_v1 *ps1) {
H
more  
Hongze Cheng 已提交
296 297 298 299 300 301 302 303 304 305
  if (tStartEncode(pCoder) < 0) return -1;

  if (tSStructA_v1_encode(pCoder, ps1->pA) < 0) return -1;
  if (tEncodeI32(pCoder, ps1->v_a) < 0) return -1;
  if (tEncodeI8(pCoder, ps1->v_b) < 0) return -1;

  tEndEncode(pCoder);
  return 0;
}

S
encode  
Shengliang Guan 已提交
306
static int32_t tSFinalReq_v1_decode(SCoder *pCoder, SFinalReq_v1 *ps1) {
H
more  
Hongze Cheng 已提交
307 308
  if (tStartDecode(pCoder) < 0) return -1;

wafwerar's avatar
wafwerar 已提交
309
  ps1->pA = (SStructA_v1 *)tCoderMalloc(pCoder, sizeof(*(ps1->pA)));
H
more  
Hongze Cheng 已提交
310 311 312 313
  if (tSStructA_v1_decode(pCoder, ps1->pA) < 0) return -1;
  if (tDecodeI32(pCoder, &ps1->v_a) < 0) return -1;
  if (tDecodeI8(pCoder, &ps1->v_b) < 0) return -1;

H
Hongze Cheng 已提交
314
  tEndDecode(pCoder);
H
more  
Hongze Cheng 已提交
315 316 317 318 319 320 321 322 323 324 325
  return 0;
}

typedef struct {
  SStructA_v2 *pA;
  int32_t      v_a;
  int8_t       v_b;
  // ----------------------- Feilds added -----------------------
  int16_t v_c;
} SFinalReq_v2;

S
encode  
Shengliang Guan 已提交
326
static int32_t tSFinalReq_v2_encode(SCoder *pCoder, const SFinalReq_v2 *ps2) {
H
more  
Hongze Cheng 已提交
327 328 329 330 331 332 333 334 335 336 337 338 339
  if (tStartEncode(pCoder) < 0) return -1;

  if (tSStructA_v2_encode(pCoder, ps2->pA) < 0) return -1;
  if (tEncodeI32(pCoder, ps2->v_a) < 0) return -1;
  if (tEncodeI8(pCoder, ps2->v_b) < 0) return -1;

  // ----------------------- Feilds added encode -----------------------
  if (tEncodeI16(pCoder, ps2->v_c) < 0) return -1;

  tEndEncode(pCoder);
  return 0;
}

S
encode  
Shengliang Guan 已提交
340
static int32_t tSFinalReq_v2_decode(SCoder *pCoder, SFinalReq_v2 *ps2) {
H
more  
Hongze Cheng 已提交
341 342
  if (tStartDecode(pCoder) < 0) return -1;

wafwerar's avatar
wafwerar 已提交
343
  ps2->pA = (SStructA_v2 *)tCoderMalloc(pCoder, sizeof(*(ps2->pA)));
H
more  
Hongze Cheng 已提交
344 345 346 347 348 349 350 351 352 353 354
  if (tSStructA_v2_decode(pCoder, ps2->pA) < 0) return -1;
  if (tDecodeI32(pCoder, &ps2->v_a) < 0) return -1;
  if (tDecodeI8(pCoder, &ps2->v_b) < 0) return -1;

  // ----------------------- Feilds added decode -----------------------
  if (tDecodeIsEnd(pCoder)) {
    ps2->v_c = 0;
  } else {
    if (tDecodeI16(pCoder, &ps2->v_c) < 0) return -1;
  }

H
Hongze Cheng 已提交
355
  tEndDecode(pCoder);
H
more  
Hongze Cheng 已提交
356 357
  return 0;
}
358
#if 0
H
more  
Hongze Cheng 已提交
359 360 361 362
TEST(td_encode_test, compound_struct_encode_test) {
  SCoder       encoder, decoder;
  uint8_t *    buf1;
  int32_t      buf1size;
S
Shengliang Guan 已提交
363
  uint8_t     *buf2;
H
more  
Hongze Cheng 已提交
364
  int32_t      buf2size;
S
Shengliang Guan 已提交
365 366
  SStructA_v1  sa1 = {.A_a = 10, .A_b = 65478, .A_c = (char *)"Hello"};
  SStructA_v2  sa2 = {.A_a = 10, .A_b = 65478, .A_c = (char *)"Hello", .A_d = 67, .A_e = 13};
H
more  
Hongze Cheng 已提交
367 368
  SFinalReq_v1 req1 = {.pA = &sa1, .v_a = 15, .v_b = 35};
  SFinalReq_v2 req2 = {.pA = &sa2, .v_a = 15, .v_b = 32, .v_c = 37};
H
Hongze Cheng 已提交
369 370
  SFinalReq_v1 dreq11, dreq21;
  SFinalReq_v2 dreq12, dreq22;
H
more  
Hongze Cheng 已提交
371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394

  // Get size
  tCoderInit(&encoder, TD_LITTLE_ENDIAN, nullptr, 0, TD_ENCODER);
  GTEST_ASSERT_EQ(tSFinalReq_v1_encode(&encoder, &req1), 0);
  buf1size = encoder.pos;
  buf1 = new uint8_t[encoder.pos];
  tCoderClear(&encoder);

  tCoderInit(&encoder, TD_LITTLE_ENDIAN, nullptr, 0, TD_ENCODER);
  GTEST_ASSERT_EQ(tSFinalReq_v2_encode(&encoder, &req2), 0);
  buf2size = encoder.pos;
  buf2 = new uint8_t[encoder.pos];
  tCoderClear(&encoder);

  // Encode
  tCoderInit(&encoder, TD_LITTLE_ENDIAN, buf1, buf1size, TD_ENCODER);
  GTEST_ASSERT_EQ(tSFinalReq_v1_encode(&encoder, &req1), 0);
  tCoderClear(&encoder);

  tCoderInit(&encoder, TD_LITTLE_ENDIAN, buf2, buf2size, TD_ENCODER);
  GTEST_ASSERT_EQ(tSFinalReq_v2_encode(&encoder, &req2), 0);
  tCoderClear(&encoder);

  // Decode
H
Hongze Cheng 已提交
395
  // buf1 -> req1
H
more  
Hongze Cheng 已提交
396
  tCoderInit(&decoder, TD_LITTLE_ENDIAN, buf1, buf1size, TD_DECODER);
H
Hongze Cheng 已提交
397 398 399 400 401 402
  GTEST_ASSERT_EQ(tSFinalReq_v1_decode(&decoder, &dreq11), 0);
  GTEST_ASSERT_EQ(dreq11.pA->A_a, req1.pA->A_a);
  GTEST_ASSERT_EQ(dreq11.pA->A_b, req1.pA->A_b);
  GTEST_ASSERT_EQ(strcmp(dreq11.pA->A_c, req1.pA->A_c), 0);
  GTEST_ASSERT_EQ(dreq11.v_a, req1.v_a);
  GTEST_ASSERT_EQ(dreq11.v_b, req1.v_b);
H
more  
Hongze Cheng 已提交
403 404
  tCoderClear(&decoder);

H
Hongze Cheng 已提交
405
  // buf1 -> req2 (backward compatibility)
H
more  
Hongze Cheng 已提交
406
  tCoderInit(&decoder, TD_LITTLE_ENDIAN, buf1, buf1size, TD_DECODER);
H
Hongze Cheng 已提交
407 408 409 410 411 412 413 414 415
  GTEST_ASSERT_EQ(tSFinalReq_v2_decode(&decoder, &dreq12), 0);
  GTEST_ASSERT_EQ(dreq12.pA->A_a, req1.pA->A_a);
  GTEST_ASSERT_EQ(dreq12.pA->A_b, req1.pA->A_b);
  GTEST_ASSERT_EQ(strcmp(dreq12.pA->A_c, req1.pA->A_c), 0);
  GTEST_ASSERT_EQ(dreq12.pA->A_d, 0);
  GTEST_ASSERT_EQ(dreq12.pA->A_e, 0);
  GTEST_ASSERT_EQ(dreq12.v_a, req1.v_a);
  GTEST_ASSERT_EQ(dreq12.v_b, req1.v_b);
  GTEST_ASSERT_EQ(dreq12.v_c, 0);
H
more  
Hongze Cheng 已提交
416 417
  tCoderClear(&decoder);

H
Hongze Cheng 已提交
418
  // buf2 -> req2
H
more  
Hongze Cheng 已提交
419 420
  tCoderInit(&decoder, TD_LITTLE_ENDIAN, buf2, buf2size, TD_DECODER);
  GTEST_ASSERT_EQ(tSFinalReq_v2_decode(&decoder, &dreq22), 0);
H
Hongze Cheng 已提交
421 422 423 424 425 426 427 428
  GTEST_ASSERT_EQ(dreq22.pA->A_a, req2.pA->A_a);
  GTEST_ASSERT_EQ(dreq22.pA->A_b, req2.pA->A_b);
  GTEST_ASSERT_EQ(strcmp(dreq22.pA->A_c, req2.pA->A_c), 0);
  GTEST_ASSERT_EQ(dreq22.pA->A_d, req2.pA->A_d);
  GTEST_ASSERT_EQ(dreq22.pA->A_e, req2.pA->A_e);
  GTEST_ASSERT_EQ(dreq22.v_a, req2.v_a);
  GTEST_ASSERT_EQ(dreq22.v_b, req2.v_b);
  GTEST_ASSERT_EQ(dreq22.v_c, req2.v_c);
H
more  
Hongze Cheng 已提交
429
  tCoderClear(&decoder);
H
Hongze Cheng 已提交
430 431 432 433 434 435 436 437 438

  tCoderInit(&decoder, TD_LITTLE_ENDIAN, buf2, buf2size, TD_DECODER);
  GTEST_ASSERT_EQ(tSFinalReq_v1_decode(&decoder, &dreq21), 0);
  GTEST_ASSERT_EQ(dreq21.pA->A_a, req2.pA->A_a);
  GTEST_ASSERT_EQ(dreq21.pA->A_b, req2.pA->A_b);
  GTEST_ASSERT_EQ(strcmp(dreq21.pA->A_c, req2.pA->A_c), 0);
  GTEST_ASSERT_EQ(dreq21.v_a, req2.v_a);
  GTEST_ASSERT_EQ(dreq21.v_b, req2.v_b);
  tCoderClear(&decoder);
S
Shengliang Guan 已提交
439
}
440
#endif
L
Liu Jicong 已提交
441
#pragma GCC diagnostic pop