Browse Source

test: add ffi codec string test

legacy
Dnomd343 2 years ago
parent
commit
c1a9d3a933
  1. 36
      test/ffi/codec.cc

36
test/ffi/codec.cc

@ -18,14 +18,17 @@ const static uint32_t TEST_SHORT_CODE_ERR = 29670987;
const static uint64_t TEST_COMMON_CODE_ERR = 0x1'2190'2300; const static uint64_t TEST_COMMON_CODE_ERR = 0x1'2190'2300;
const static uint64_t TEST_RAW_CODE_ERR = 0x0A34'182B'3810'2D21; const static uint64_t TEST_RAW_CODE_ERR = 0x0A34'182B'3810'2D21;
const static char TEST_SHORT_CODE_STR_ERR[] = "R50EH";
const static char TEST_COMMON_CODE_STR_ERR[] = "123J432A9";
TEST(FFI, codec_warm_up) { TEST(FFI, codec_warm_up) {
// short code normal mode check /// short code normal mode check
EXPECT_EQ(is_short_code_available(), BasicRanges::status() == BasicRanges::AVAILABLE); EXPECT_EQ(is_short_code_available(), BasicRanges::status() == BasicRanges::AVAILABLE);
short_code_enable(); short_code_enable();
EXPECT_EQ(is_short_code_available(), true); EXPECT_EQ(is_short_code_available(), true);
EXPECT_EQ(is_short_code_available(), BasicRanges::status() == BasicRanges::AVAILABLE); EXPECT_EQ(is_short_code_available(), BasicRanges::status() == BasicRanges::AVAILABLE);
// short code fast mode check /// short code fast mode check
EXPECT_EQ(is_short_code_available_fast(), AllCases::status() == AllCases::AVAILABLE); EXPECT_EQ(is_short_code_available_fast(), AllCases::status() == AllCases::AVAILABLE);
short_code_enable_fast(); short_code_enable_fast();
EXPECT_EQ(is_short_code_available_fast(), true); EXPECT_EQ(is_short_code_available_fast(), true);
@ -42,3 +45,32 @@ TEST(FFI, codec_checker) {
EXPECT_EQ(common_code_check(TEST_COMMON_CODE_OK), true); EXPECT_EQ(common_code_check(TEST_COMMON_CODE_OK), true);
EXPECT_NE(common_code_check(TEST_COMMON_CODE_ERR), true); EXPECT_NE(common_code_check(TEST_COMMON_CODE_ERR), true);
} }
TEST(FFI, codec_string) {
EXPECT_EQ(SHORT_CODE_STR_SIZE, 6);
EXPECT_EQ(COMMON_CODE_STR_SIZE, 10);
/// short code string verify
uint32_t short_code;
char short_code_buffer[SHORT_CODE_STR_SIZE];
EXPECT_EQ(short_code_to_string(TEST_SHORT_CODE_ERR, short_code_buffer), false);
EXPECT_EQ(short_code_from_string(TEST_SHORT_CODE_STR_ERR, &short_code), false);
EXPECT_EQ(short_code_to_string(TEST_SHORT_CODE_OK, short_code_buffer), true);
EXPECT_EQ(short_code_from_string(short_code_buffer, &short_code), true);
EXPECT_EQ(short_code, TEST_SHORT_CODE_OK);
/// common code string verify
uint64_t common_code;
char common_code_buffer[COMMON_CODE_STR_SIZE];
EXPECT_EQ(common_code_to_string(TEST_COMMON_CODE_ERR, common_code_buffer), false);
EXPECT_EQ(common_code_from_string(TEST_COMMON_CODE_STR_ERR, &common_code), false);
EXPECT_EQ(common_code_to_string(TEST_COMMON_CODE_OK, common_code_buffer), true);
EXPECT_EQ(common_code_from_string(common_code_buffer, &common_code), true);
EXPECT_EQ(common_code, TEST_COMMON_CODE_OK);
EXPECT_EQ(common_code_to_string_shorten(TEST_COMMON_CODE_OK, common_code_buffer), true);
EXPECT_EQ(common_code_from_string(common_code_buffer, &common_code), true);
EXPECT_EQ(common_code, TEST_COMMON_CODE_OK);
}

Loading…
Cancel
Save