From 955a3c6dfdf46bb2396830110dba19dc1c2f030b Mon Sep 17 00:00:00 2001 From: "Scott E. Graves" Date: Sat, 31 Aug 2024 19:23:01 -0500 Subject: [PATCH] updated build system --- support/include/utils/common.hpp | 2 +- support/test/include/test.hpp | 2 -- support/test/src/test.cpp | 8 ++++++-- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/support/include/utils/common.hpp b/support/include/utils/common.hpp index bd566dde..4473fa21 100644 --- a/support/include/utils/common.hpp +++ b/support/include/utils/common.hpp @@ -114,7 +114,7 @@ inline auto generate_random_between(data_t begin, data_t end) -> data_t { throw std::range_error("end must be greater than begin"); } - static std::mt19937 gen(std::random_device{}()); + std::mt19937 gen(std::random_device{}()); std::uniform_int_distribution dis(begin, end); return dis(gen); } diff --git a/support/test/include/test.hpp b/support/test/include/test.hpp index df9498e9..1d432b0e 100644 --- a/support/test/include/test.hpp +++ b/support/test/include/test.hpp @@ -37,10 +37,8 @@ using namespace ::testing; #include "utils/all.hpp" namespace repertory::test { -#if defined(PROJECT_ENABLE_LIBSODIUM) [[nodiscard]] auto create_random_file(std::size_t size) -> utils::file::i_file &; -#endif // defined(PROJECT_ENABLE_LIBSODIUM) [[nodiscard]] auto generate_test_file_name(std::string_view file_name_no_extension) -> std::string; diff --git a/support/test/src/test.cpp b/support/test/src/test.cpp index 46f6c315..87fad0bf 100644 --- a/support/test/src/test.cpp +++ b/support/test/src/test.cpp @@ -53,7 +53,6 @@ static auto deleter{std::make_unique()}; } // namespace namespace repertory::test { -#if defined(PROJECT_ENABLE_LIBSODIUM) auto create_random_file(std::size_t size) -> utils::file::i_file & { recur_mutex_lock lock{file_mtx}; @@ -62,7 +61,13 @@ auto create_random_file(std::size_t size) -> utils::file::i_file & { EXPECT_TRUE(*file); if (*file) { data_buffer buf(size); +#if defined(PROJECT_ENABLE_LIBSODIUM) randombytes_buf(buf.data(), buf.size()); +#else // !defined(PROJECT_ENABLE_LIBSODIUM) + std::mt19937 gen(std::random_device{}()); + std::uniform_int_distribution dis(0U, 255U); + std::generate(buf.begin(), buf.end(), [&]() -> auto { return dis(gen); }); +#endif // defined(PROJECT_ENABLE_LIBSODIUM) std::size_t bytes_written{}; EXPECT_TRUE(file->write(buf, 0U, &bytes_written)); @@ -74,7 +79,6 @@ auto create_random_file(std::size_t size) -> utils::file::i_file & { generated_files.emplace_back(std::move(file)); return *dynamic_cast(generated_files.back().get()); } -#endif // defined(PROJECT_ENABLE_LIBSODIUM) auto generate_test_directory() -> utils::file::i_directory & { recur_mutex_lock lock{file_mtx};