diff --git a/src/core_test/cases/all_cases.cc b/src/core_test/cases/all_cases.cc index 1725532..36c3cb3 100644 --- a/src/core_test/cases/all_cases.cc +++ b/src/core_test/cases/all_cases.cc @@ -2,6 +2,7 @@ #include "helper/hash.h" #include "helper/cases.h" +#include "helper/fixture.h" #include "utility/exposer.h" #include "short_code/short_code.h" @@ -28,7 +29,7 @@ constexpr auto ALL_CASES_XXH3 = std::to_array({ 0x2cdf6c14a7ce3e9a, 0xb9dd04a315583f5c, 0x19046e49c44ae90d, 0x2d06800538d394c2, }); -class AllCasesTest : public testing::Test, public Concurrent { +class AllCasesTest : public testing::Test, public helper::Concurrent { protected: void SetUp() override { Reset(); diff --git a/src/core_test/cases/basic_ranges.cc b/src/core_test/cases/basic_ranges.cc index d76c825..3028175 100644 --- a/src/core_test/cases/basic_ranges.cc +++ b/src/core_test/cases/basic_ranges.cc @@ -3,6 +3,7 @@ #include "group/group.h" #include "helper/hash.h" #include "helper/cases.h" +#include "helper/fixture.h" #include "utility/exposer.h" using klotski::array_sum; @@ -18,7 +19,7 @@ EXPOSE_VAR(BasicRanges, bool, available_) constexpr uint64_t BASIC_RANGES_XXH3 = 0x34fce9da6a052533; -class BasicRangesTest : public testing::Test, public Concurrent { +class BasicRangesTest : public testing::Test, public helper::Concurrent { protected: void SetUp() override { Reset(); diff --git a/src/core_test/cases/helper/cases.h b/src/core_test/cases/helper/cases.h index f60d530..de79fda 100644 --- a/src/core_test/cases/helper/cases.h +++ b/src/core_test/cases/helper/cases.h @@ -29,30 +29,6 @@ constexpr auto Heads = std::to_array({ // ----------------------------------------------------------------------------------------- // -/// Test fixture wrapper with concurrency tools. -class Concurrent { -protected: - // Execute same task concurrently. - helper::Racer racer_ {}; - - // Execute assigned tasks one by one. - helper::Executor serial_ {1}; - - // Execute assigned tasks on all cores. - helper::Executor executor_ {0}; - - // Atomic helpers for multi-thread testing. - std::atomic counter_ {0}; - std::atomic_flag condition_ {false}; -}; - -/// Test fixture macro with custom test suite name. -#define TEST_FF(test_suite_name, test_name) \ - GTEST_TEST_(test_suite_name, test_name, test_suite_name##Test, \ - ::testing::internal::GetTypeId()) - -// ----------------------------------------------------------------------------------------- // - /// Assert that Ranges are sorted and unique. #define EXPECT_SORTED_AND_UNIQUE(R) \ EXPECT_TRUE(std::ranges::is_sorted(R.begin(), R.end())); \ diff --git a/src/core_test/helper/fixture.h b/src/core_test/helper/fixture.h new file mode 100644 index 0000000..fee5525 --- /dev/null +++ b/src/core_test/helper/fixture.h @@ -0,0 +1,32 @@ +#pragma once + +#include +#include + +#include "helper/concurrent.h" + +namespace helper { + +/// Test fixture wrapper with concurrency tools. +class Concurrent { +protected: + // Execute same task concurrently. + Racer racer_ {}; + + // Execute assigned tasks one by one. + Executor serial_ {1}; + + // Execute assigned tasks on all cores. + Executor executor_ {0}; + + // Atomic helpers for multi-thread testing. + std::atomic counter_ {0}; + std::atomic_flag condition_ {false}; +}; + +/// Test fixture macro with custom test suite name. +#define TEST_FF(test_suite_name, test_name) \ + GTEST_TEST_(test_suite_name, test_name, test_suite_name##Test, \ + ::testing::internal::GetTypeId()) + +} // namespace helper