Browse Source

test: add ffi metadata test

master
Dnomd343 2 years ago
parent
commit
160174bc44
  1. 10
      src/klotski_core/klotski.h
  2. 20
      test/CMakeLists.txt
  3. 2
      test/codec/common_code.cc
  4. 2
      test/codec/raw_code.cc
  5. 2
      test/codec/short_code.cc
  6. 19
      test/ffi/metadata.cc

10
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

20
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)
################################################################################

2
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) {

2
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) {

2
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];

19
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);
}
Loading…
Cancel
Save