From e8e4d3c245fec01548bb8352abd859b3acad80ca Mon Sep 17 00:00:00 2001 From: Dnomd343 Date: Mon, 30 Jan 2023 21:47:10 +0800 Subject: [PATCH] test: add ffi codec unsafe convert test --- src/klotski_core/klotski.h | 1 - test/ffi/codec.cc | 14 ++++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/klotski_core/klotski.h b/src/klotski_core/klotski.h index a935714..1936e45 100644 --- a/src/klotski_core/klotski.h +++ b/src/klotski_core/klotski.h @@ -81,7 +81,6 @@ extern "C" { extern bool short_code_to_common_code(uint32_t short_code, uint64_t *common_code); extern bool common_code_to_short_code(uint64_t common_code, uint32_t *short_code); - // TODO: allow unsafe convert extern uint32_t raw_code_to_short_code_unsafe(uint64_t raw_code); extern uint64_t short_code_to_raw_code_unsafe(uint32_t short_code); extern uint64_t raw_code_to_common_code_unsafe(uint64_t raw_code); diff --git a/test/ffi/codec.cc b/test/ffi/codec.cc index b2cabe5..e986015 100644 --- a/test/ffi/codec.cc +++ b/test/ffi/codec.cc @@ -110,3 +110,17 @@ TEST(FFI, codec_convert) { EXPECT_EQ(common_code_to_short_code(TEST_COMMON_CODE_OK, &short_code), true); EXPECT_EQ(TEST_SHORT_CODE_OK, short_code); } + +TEST(FFI, codec_convert_unsafe) { + /// raw code <---> short code + EXPECT_EQ(raw_code_to_short_code_unsafe(TEST_RAW_CODE_OK), TEST_SHORT_CODE_OK); + EXPECT_EQ(short_code_to_raw_code_unsafe(TEST_SHORT_CODE_OK), TEST_RAW_CODE_OK); + + /// raw code <---> common code + EXPECT_EQ(raw_code_to_common_code_unsafe(TEST_RAW_CODE_OK), TEST_COMMON_CODE_OK); + EXPECT_EQ(common_code_to_raw_code_unsafe(TEST_COMMON_CODE_OK), TEST_RAW_CODE_OK); + + /// short code <---> common code + EXPECT_EQ(short_code_to_common_code_unsafe(TEST_SHORT_CODE_OK), TEST_COMMON_CODE_OK); + EXPECT_EQ(common_code_to_short_code_unsafe(TEST_COMMON_CODE_OK), TEST_SHORT_CODE_OK); +}