From 160174bc444a208ed9dcf315afcfd8476225c13d Mon Sep 17 00:00:00 2001 From: Dnomd343 Date: Mon, 30 Jan 2023 16:46:52 +0800 Subject: [PATCH] test: add ffi metadata test --- src/klotski_core/klotski.h | 10 +++++----- test/CMakeLists.txt | 20 +++++++++++--------- test/codec/common_code.cc | 2 ++ test/codec/raw_code.cc | 2 ++ test/codec/short_code.cc | 2 ++ test/ffi/metadata.cc | 19 +++++++++++++++++++ 6 files changed, 41 insertions(+), 14 deletions(-) create mode 100644 test/ffi/metadata.cc diff --git a/src/klotski_core/klotski.h b/src/klotski_core/klotski.h index 6e29f9f..ae48a71 100644 --- a/src/klotski_core/klotski.h +++ b/src/klotski_core/klotski.h @@ -22,6 +22,11 @@ extern "C" { #ifdef __cplusplus extern "C" { #endif + // version -> major.minor.patch + extern uint32_t get_version_major(); + extern uint32_t get_version_minor(); + extern uint32_t get_version_patch(); + extern const char* get_author(); extern const char* get_git_tag(); extern const char* get_version(); @@ -31,11 +36,6 @@ extern "C" { extern const char* get_project_url(); extern const char* get_system_info(); extern const char* get_compiler_info(); - - // version -> major.minor.patch - extern uint32_t get_version_major(); - extern uint32_t get_version_minor(); - extern uint32_t get_version_patch(); #ifdef __cplusplus } #endif diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 2701fc0..164a14b 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -20,10 +20,6 @@ include_directories(../src/klotski_core/all_cases) set(TEST_BASIC_SRC utils.cc all_cases.cc) list(TRANSFORM TEST_BASIC_SRC PREPEND "basic/") add_executable(test_basic ${TEST_BASIC_SRC}) -#add_executable(test_basic -# basic/utils.cc -# basic/all_cases.cc -#) target_link_libraries(test_basic PUBLIC ${TEST_DEPS} md5) add_test(NAME basic COMMAND test_basic) @@ -36,12 +32,18 @@ include_directories(../src/klotski_core/common_code) set(TEST_CODEC_SRC short_code.cc raw_code.cc common_code.cc) list(TRANSFORM TEST_CODEC_SRC PREPEND "codec/") add_executable(test_codec ${TEST_CODEC_SRC}) -#add_executable(test_codec -# codec/short_code.cc -# codec/common_code.cc -# codec/raw_code.cc -#) target_link_libraries(test_codec ${TEST_DEPS}) add_test(NAME codec COMMAND test_codec) ################################################################################ + +include_directories(../src/klotski_core) +include_directories(../src/klotski_core/utils) + +set(TEST_FFI_SRC metadata.cc) +list(TRANSFORM TEST_FFI_SRC PREPEND "ffi/") +add_executable(test_ffi ${TEST_FFI_SRC}) +target_link_libraries(test_ffi ${TEST_DEPS}) +add_test(NAME ffi COMMAND test_ffi) + +################################################################################ diff --git a/test/codec/common_code.cc b/test/codec/common_code.cc index eea92c7..3c93469 100644 --- a/test/codec/common_code.cc +++ b/test/codec/common_code.cc @@ -12,6 +12,8 @@ using klotski::CommonCode; const static uint64_t TEST_CODE = 0x1A9BF0C00; const static std::string TEST_CODE_STR = "1A9BF0C00"; +// TODO: test some invalid cases + TEST(CommonCode, code_verify) { std::thread threads[16]; auto test = [](uint64_t head) { diff --git a/test/codec/raw_code.cc b/test/codec/raw_code.cc index ba26c71..791e18e 100644 --- a/test/codec/raw_code.cc +++ b/test/codec/raw_code.cc @@ -9,6 +9,8 @@ using klotski::CommonCode; const static uint64_t TEST_CODE = 0x0603'EDF5'CAFF'F5E2; +// TODO: test some invalid cases + TEST(RawCode, code_verify) { std::thread threads[16]; auto test = [](uint64_t head) { diff --git a/test/codec/short_code.cc b/test/codec/short_code.cc index a45ed08..01e30aa 100644 --- a/test/codec/short_code.cc +++ b/test/codec/short_code.cc @@ -12,6 +12,8 @@ using klotski::BasicRanges; const static uint64_t TEST_CODE = 4091296; const static std::string TEST_CODE_STR = "4WVE1"; +// TODO: test some invalid cases + TEST(ShortCode, speed_up) { std::thread threads[4]; diff --git a/test/ffi/metadata.cc b/test/ffi/metadata.cc new file mode 100644 index 0000000..346123b --- /dev/null +++ b/test/ffi/metadata.cc @@ -0,0 +1,19 @@ +#include "klotski.h" +#include "metadata.h" +#include "gtest/gtest.h" + +TEST(FFI, metadata) { + EXPECT_STREQ(get_author(), AUTHOR); + EXPECT_STREQ(get_git_tag(), GIT_TAG_ID); + EXPECT_STREQ(get_version(), VERSION_STR); + EXPECT_STREQ(get_commit_id(), GIT_COMMIT_ID); + EXPECT_STREQ(get_build_time(), BUILD_TIME); + EXPECT_STREQ(get_git_branch(), GIT_BRANCH); + EXPECT_STREQ(get_project_url(), GIT_PROJECT); + EXPECT_STREQ(get_system_info(), SYSTEM); + EXPECT_STREQ(get_compiler_info(), COMPILER); + + EXPECT_EQ(get_version_major(), VERSION_MAJOR); + EXPECT_EQ(get_version_minor(), VERSION_MINOR); + EXPECT_EQ(get_version_patch(), VERSION_PATCH); +}