From d84753ae20078a02a9e45464bf099b8ec4c937ef Mon Sep 17 00:00:00 2001 From: Dnomd343 Date: Mon, 30 Jan 2023 21:22:55 +0800 Subject: [PATCH] test: add ffi codec convert test --- test/ffi/codec.cc | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/test/ffi/codec.cc b/test/ffi/codec.cc index 7a5b9d3..b2cabe5 100644 --- a/test/ffi/codec.cc +++ b/test/ffi/codec.cc @@ -74,3 +74,39 @@ TEST(FFI, codec_string) { EXPECT_EQ(common_code_from_string(common_code_buffer, &common_code), true); EXPECT_EQ(common_code, TEST_COMMON_CODE_OK); } + +TEST(FFI, codec_convert) { + uint64_t raw_code; + uint32_t short_code; + uint64_t common_code; + + /// raw code -> short code + EXPECT_EQ(raw_code_to_short_code(TEST_RAW_CODE_ERR, &short_code), false); + EXPECT_EQ(raw_code_to_short_code(TEST_RAW_CODE_OK, &short_code), true); + EXPECT_EQ(TEST_SHORT_CODE_OK, short_code); + + /// short code -> raw code + EXPECT_EQ(short_code_to_raw_code(TEST_SHORT_CODE_ERR, &raw_code), false); + EXPECT_EQ(short_code_to_raw_code(TEST_SHORT_CODE_OK, &raw_code), true); + EXPECT_EQ(TEST_RAW_CODE_OK, raw_code); + + /// raw code -> common code + EXPECT_EQ(raw_code_to_common_code(TEST_RAW_CODE_ERR, &common_code), false); + EXPECT_EQ(raw_code_to_common_code(TEST_RAW_CODE_OK, &common_code), true); + EXPECT_EQ(TEST_COMMON_CODE_OK, common_code); + + /// common code -> raw code + EXPECT_EQ(common_code_to_raw_code(TEST_COMMON_CODE_ERR, &raw_code), false); + EXPECT_EQ(common_code_to_raw_code(TEST_COMMON_CODE_OK, &raw_code), true); + EXPECT_EQ(TEST_RAW_CODE_OK, raw_code); + + /// short code -> common code + EXPECT_EQ(short_code_to_common_code(TEST_SHORT_CODE_ERR, &common_code), false); + EXPECT_EQ(short_code_to_common_code(TEST_SHORT_CODE_OK, &common_code), true); + EXPECT_EQ(TEST_COMMON_CODE_OK, common_code); + + /// common code -> short code + EXPECT_EQ(common_code_to_short_code(TEST_COMMON_CODE_ERR, &short_code), false); + EXPECT_EQ(common_code_to_short_code(TEST_COMMON_CODE_OK, &short_code), true); + EXPECT_EQ(TEST_SHORT_CODE_OK, short_code); +}