From 129516cd83c0bf9a2f5c53af451c8f8a32fabbf1 Mon Sep 17 00:00:00 2001 From: Dnomd343 Date: Mon, 30 Jan 2023 17:31:01 +0800 Subject: [PATCH] test: add ffi all cases export test --- test/CMakeLists.txt | 2 +- test/ffi/all_cases.cc | 44 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 test/ffi/all_cases.cc diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 164a14b..39bb190 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -40,7 +40,7 @@ add_test(NAME codec COMMAND test_codec) include_directories(../src/klotski_core) include_directories(../src/klotski_core/utils) -set(TEST_FFI_SRC metadata.cc) +set(TEST_FFI_SRC metadata.cc all_cases.cc) list(TRANSFORM TEST_FFI_SRC PREPEND "ffi/") add_executable(test_ffi ${TEST_FFI_SRC}) target_link_libraries(test_ffi ${TEST_DEPS}) diff --git a/test/ffi/all_cases.cc b/test/ffi/all_cases.cc new file mode 100644 index 0000000..d4a1462 --- /dev/null +++ b/test/ffi/all_cases.cc @@ -0,0 +1,44 @@ +#include "klotski.h" +#include "all_cases.h" +#include "gtest/gtest.h" + +using klotski::AllCases; +using klotski::BasicRanges; + +TEST(FFI, all_cases_build) { + // basic ranges test + EXPECT_EQ(is_basic_ranges_available(), BasicRanges::status() == BasicRanges::AVAILABLE); + basic_ranges_build(); + EXPECT_EQ(is_basic_ranges_available(), true); + EXPECT_EQ(is_basic_ranges_available(), BasicRanges::status() == BasicRanges::AVAILABLE); + + // all cases test + EXPECT_EQ(is_all_cases_available(), AllCases::status() == AllCases::AVAILABLE); + all_cases_build(); + EXPECT_EQ(is_all_cases_available(), true); + EXPECT_EQ(is_all_cases_available(), AllCases::status() == AllCases::AVAILABLE); +} + +TEST(FFI, all_cases_size) { + EXPECT_EQ(ALL_CASES_SIZE, klotski::ALL_CASES_SIZE_SUM); + EXPECT_EQ(BASIC_RANGES_SIZE, klotski::BASIC_RANGES_SIZE); +} + +TEST(FFI, all_cases_data) { + auto *basic_ranges_buf = new uint32_t[BASIC_RANGES_SIZE]; + export_basic_ranges(basic_ranges_buf); + for (uint32_t i = 0; i < BASIC_RANGES_SIZE; ++i) { // basic ranges data verify + EXPECT_EQ(basic_ranges_buf[i], BasicRanges::fetch()[i]); + } + delete []basic_ranges_buf; + + auto *all_cases_buf = new uint64_t[ALL_CASES_SIZE]; + export_all_cases(all_cases_buf); + uint64_t index = 0; + for (uint64_t head = 0; head < 16; ++head) { + for (const auto &range : AllCases::fetch()[head]) { // all cases data verify + EXPECT_EQ(all_cases_buf[index++], head << 32 | range); + } + } + delete []all_cases_buf; +}