From 277be6dd08633dbebfda93afdfc6b5cb57e053e0 Mon Sep 17 00:00:00 2001 From: Paul Cristian Sarbu Date: Mon, 8 Apr 2024 13:18:22 +0200 Subject: Use properly included standard library types by default --- .../build_engine/expression/linked_map.test.cpp | 4 +-- .../multithreading/async_map_consumer.test.cpp | 30 +++++++++++--------- .../git_operations/critical_git_ops.test.cpp | 7 +++-- test/utils/archive/archive_usage.test.cpp | 2 +- test/utils/large_objects/large_object_utils.cpp | 33 +++++++++++----------- 5 files changed, 40 insertions(+), 36 deletions(-) (limited to 'test') diff --git a/test/buildtool/build_engine/expression/linked_map.test.cpp b/test/buildtool/build_engine/expression/linked_map.test.cpp index 0dfe7b72..4c9a996f 100644 --- a/test/buildtool/build_engine/expression/linked_map.test.cpp +++ b/test/buildtool/build_engine/expression/linked_map.test.cpp @@ -93,7 +93,7 @@ TEST_CASE("Lookup and iteration", "[linked_map]") { class CopyCounter { public: - CopyCounter() : count_{std::make_shared()} {} + CopyCounter() : count_{std::make_shared()} {} CopyCounter(CopyCounter const& other) { ++(*other.count_); count_ = other.count_; @@ -112,7 +112,7 @@ class CopyCounter { private: // all copies of this object share the same counter - std::shared_ptr count_{}; + std::shared_ptr count_{}; }; TEST_CASE("Zero copies", "[linked_map]") { diff --git a/test/buildtool/multithreading/async_map_consumer.test.cpp b/test/buildtool/multithreading/async_map_consumer.test.cpp index fa7038b9..a2de18b7 100644 --- a/test/buildtool/multithreading/async_map_consumer.test.cpp +++ b/test/buildtool/multithreading/async_map_consumer.test.cpp @@ -27,7 +27,7 @@ #include "src/buildtool/multithreading/async_map_consumer.hpp" #include "src/buildtool/multithreading/task_system.hpp" -auto FibonacciMapConsumer() -> AsyncMapConsumer { +auto FibonacciMapConsumer() -> AsyncMapConsumer { auto value_creator = [](auto /*unused*/, auto setter, auto logger, @@ -38,7 +38,7 @@ auto FibonacciMapConsumer() -> AsyncMapConsumer { return; } if (key < 2) { - (*setter)(uint64_t{static_cast(key)}); + (*setter)(uint64_t{static_cast(key)}); return; } (*subcaller)( @@ -48,10 +48,10 @@ auto FibonacciMapConsumer() -> AsyncMapConsumer { }, logger); }; - return AsyncMapConsumer{value_creator}; + return AsyncMapConsumer{value_creator}; } -auto FibOnEvenConsumer() -> AsyncMapConsumer { +auto FibOnEvenConsumer() -> AsyncMapConsumer { auto value_creator = [](auto /*unused*/, auto setter, auto logger, @@ -63,11 +63,11 @@ auto FibOnEvenConsumer() -> AsyncMapConsumer { return; } if (key == 0) { - (*setter)(uint64_t{static_cast(0)}); + (*setter)(uint64_t{static_cast(0)}); return; } if (key == 2) { - (*setter)(uint64_t{static_cast(1)}); + (*setter)(uint64_t{static_cast(1)}); return; } (*subcaller)( @@ -81,7 +81,7 @@ auto FibOnEvenConsumer() -> AsyncMapConsumer { } auto CountToMaxConsumer(int max_val, int step = 1, bool cycle = false) - -> AsyncMapConsumer { + -> AsyncMapConsumer { auto value_creator = [max_val, step, cycle](auto /*unused*/, auto setter, auto logger, @@ -92,7 +92,7 @@ auto CountToMaxConsumer(int max_val, int step = 1, bool cycle = false) return; } if (key == max_val) { // will never be reached if cycle==true - (*setter)(uint64_t{static_cast(key)}); + (*setter)(uint64_t{static_cast(key)}); return; } auto next = key + step; @@ -101,17 +101,19 @@ auto CountToMaxConsumer(int max_val, int step = 1, bool cycle = false) } (*subcaller)( {next}, - [setter](auto const& values) { (*setter)(uint64_t{*values[0]}); }, + [setter](auto const& values) { + (*setter)(std::uint64_t{*values[0]}); + }, logger); }; - return AsyncMapConsumer{value_creator}; + return AsyncMapConsumer{value_creator}; } TEST_CASE("Fibonacci", "[async_map_consumer]") { - uint64_t result{}; + std::uint64_t result{}; int const index{92}; bool execution_failed = false; - uint64_t const expected_result{7540113804746346429}; + std::uint64_t const expected_result{7540113804746346429}; auto mapconsumer = FibonacciMapConsumer(); { TaskSystem ts; @@ -196,10 +198,10 @@ TEST_CASE("No subcalling necessary", "[async_map_consumer]") { } TEST_CASE("FibOnEven", "[async_map_consumer]") { - uint64_t result{}; + std::uint64_t result{}; int const index{184}; bool execution_failed = false; - uint64_t const expected_result{7540113804746346429}; + std::uint64_t const expected_result{7540113804746346429}; auto mapconsumer = FibOnEvenConsumer(); { TaskSystem ts; diff --git a/test/other_tools/git_operations/critical_git_ops.test.cpp b/test/other_tools/git_operations/critical_git_ops.test.cpp index 231c61d7..8c712d22 100644 --- a/test/other_tools/git_operations/critical_git_ops.test.cpp +++ b/test/other_tools/git_operations/critical_git_ops.test.cpp @@ -14,6 +14,7 @@ #include // std::find #include +#include #include // std::system #include #include @@ -146,9 +147,9 @@ TEST_CASE("Critical git operations", "[critical_git_op_map]") { // Add ops to the map. None should throw, as repeating the same operation // should retrieve the value from the map, not call the operation again. // helper lists - const std::vector ops_all{ + const std::vector ops_all{ 0, 1, 2, 3, 4}; // indices of all ops tested - const std::vector ops_with_result{ + const std::vector ops_with_result{ 0, 4}; // indices of ops that return a non-empty string // Add to the map all ops multiple times for ([[maybe_unused]] auto const& i : @@ -203,7 +204,7 @@ TEST_CASE("Critical git operations", "[critical_git_op_map]") { .op_type = GitOpType::GET_HEAD_ID}}, [&ops_all, &ops_with_result](auto const& values) { // check operations - for (size_t const& i : ops_all) { + for (std::size_t const& i : ops_all) { auto res = *values[i]; REQUIRE(res.git_cas); REQUIRE(res.result); diff --git a/test/utils/archive/archive_usage.test.cpp b/test/utils/archive/archive_usage.test.cpp index bd7a3851..282c2425 100644 --- a/test/utils/archive/archive_usage.test.cpp +++ b/test/utils/archive/archive_usage.test.cpp @@ -182,7 +182,7 @@ void extract_archive(std::string const& path) { if (archive_entry_size(entry) > 0) { void const* buf{}; std::size_t size{}; - int64_t offset{}; + std::int64_t offset{}; int r2{}; while ((r2 = archive_read_data_block(a, &buf, &size, &offset)) == ARCHIVE_OK) { diff --git a/test/utils/large_objects/large_object_utils.cpp b/test/utils/large_objects/large_object_utils.cpp index b7bcebdc..6c3000ff 100644 --- a/test/utils/large_objects/large_object_utils.cpp +++ b/test/utils/large_objects/large_object_utils.cpp @@ -15,6 +15,7 @@ #include "test/utils/large_objects/large_object_utils.hpp" #include +#include #include #include #include @@ -29,7 +30,7 @@ class Randomizer final { Randomizer(std::uint64_t min, std::uint64_t max) noexcept : range_(std::random_device{}()), distribution_(min, max) {} - [[nodiscard]] inline auto Get() noexcept -> uint64_t { + [[nodiscard]] inline auto Get() noexcept -> std::uint64_t { return distribution_(range_); } @@ -41,7 +42,7 @@ class Randomizer final { /// \brief Create a number of chunks of the predefined size. /// \tparam UChunkLength Length of each chunk. /// \tparam USize Number of chunks. -template +template class ChunkPool final { public: [[nodiscard]] static auto Instance() noexcept @@ -50,7 +51,7 @@ class ChunkPool final { return pool; } - [[nodiscard]] auto operator[](size_t index) const noexcept + [[nodiscard]] auto operator[](std::size_t index) const noexcept -> std::string const& { return gsl::at(pool_, static_cast(index)); } @@ -62,10 +63,10 @@ class ChunkPool final { // Starts from 1 to exclude '\0' from randomization Randomizer randomizer{1, std::numeric_limits::max()}; - for (size_t i = 0; i < pool_.size(); ++i) { + for (std::size_t i = 0; i < pool_.size(); ++i) { auto& chunk = gsl::at(pool_, static_cast(i)); chunk.resize(kChunkLength); - for (size_t j = 0; j < kChunkLength; ++j) { + for (std::size_t j = 0; j < kChunkLength; ++j) { chunk[j] = randomizer.Get(); } } @@ -80,22 +81,22 @@ auto LargeObjectUtils::GenerateFile(std::filesystem::path const& path, return false; } - static constexpr size_t kChunkLength = 128; - static constexpr size_t kPoolSize = 64; + static constexpr std::size_t kChunkLength = 128; + static constexpr std::size_t kPoolSize = 64; using Pool = ChunkPool; // To create a random file, the initial chunk position and the shift are // randomized: - Randomizer randomizer{std::numeric_limits::min(), - std::numeric_limits::max()}; - const size_t pool_index = randomizer.Get() % kPoolSize; - const size_t pool_shift = randomizer.Get() % 10; - const size_t step_count = size / kChunkLength + 1; + Randomizer randomizer{std::numeric_limits::min(), + std::numeric_limits::max()}; + const std::size_t pool_index = randomizer.Get() % kPoolSize; + const std::size_t pool_shift = randomizer.Get() % 10; + const std::size_t step_count = size / kChunkLength + 1; try { std::ofstream stream(path); - for (size_t i = 0; i < step_count && stream.good(); ++i) { - const size_t index = (pool_index + i * pool_shift) % kPoolSize; + for (std::size_t i = 0; i < step_count && stream.good(); ++i) { + const std::size_t index = (pool_index + i * pool_shift) % kPoolSize; if (i != step_count - 1) { stream << Pool::Instance()[index]; } @@ -123,8 +124,8 @@ auto LargeObjectUtils::GenerateDirectory(std::filesystem::path const& path, return false; } - Randomizer randomizer{std::numeric_limits::min(), - std::numeric_limits::max()}; + Randomizer randomizer{std::numeric_limits::min(), + std::numeric_limits::max()}; std::uintmax_t entries = 0; while (entries < entries_count) { -- cgit v1.2.3