Browse Source

test: add ffi codec unsafe convert test

legacy
Dnomd343 2 years ago
parent
commit
e8e4d3c245
  1. 1
      src/klotski_core/klotski.h
  2. 14
      test/ffi/codec.cc

1
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 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); 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 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 short_code_to_raw_code_unsafe(uint32_t short_code);
extern uint64_t raw_code_to_common_code_unsafe(uint64_t raw_code); extern uint64_t raw_code_to_common_code_unsafe(uint64_t raw_code);

14
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(common_code_to_short_code(TEST_COMMON_CODE_OK, &short_code), true);
EXPECT_EQ(TEST_SHORT_CODE_OK, short_code); 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);
}

Loading…
Cancel
Save