diff options
author | Paul Cristian Sarbu <paul.cristian.sarbu@huawei.com> | 2024-04-08 13:18:22 +0200 |
---|---|---|
committer | Paul Cristian Sarbu <paul.cristian.sarbu@huawei.com> | 2024-04-08 15:19:50 +0200 |
commit | 277be6dd08633dbebfda93afdfc6b5cb57e053e0 (patch) | |
tree | 6c86157c7f93636459361264054753a1dc9d33e9 /test | |
parent | 419a458ad9d4383eb47d51fe8e4408a0e240c2f1 (diff) | |
download | justbuild-277be6dd08633dbebfda93afdfc6b5cb57e053e0.tar.gz |
Use properly included standard library types by default
Diffstat (limited to 'test')
5 files changed, 40 insertions, 36 deletions
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<size_t>()} {} + CopyCounter() : count_{std::make_shared<std::size_t>()} {} 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<size_t> count_{}; + std::shared_ptr<std::size_t> 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<int, uint64_t> { +auto FibonacciMapConsumer() -> AsyncMapConsumer<int, std::uint64_t> { auto value_creator = [](auto /*unused*/, auto setter, auto logger, @@ -38,7 +38,7 @@ auto FibonacciMapConsumer() -> AsyncMapConsumer<int, uint64_t> { return; } if (key < 2) { - (*setter)(uint64_t{static_cast<uint64_t>(key)}); + (*setter)(uint64_t{static_cast<std::uint64_t>(key)}); return; } (*subcaller)( @@ -48,10 +48,10 @@ auto FibonacciMapConsumer() -> AsyncMapConsumer<int, uint64_t> { }, logger); }; - return AsyncMapConsumer<int, uint64_t>{value_creator}; + return AsyncMapConsumer<int, std::uint64_t>{value_creator}; } -auto FibOnEvenConsumer() -> AsyncMapConsumer<int, uint64_t> { +auto FibOnEvenConsumer() -> AsyncMapConsumer<int, std::uint64_t> { auto value_creator = [](auto /*unused*/, auto setter, auto logger, @@ -63,11 +63,11 @@ auto FibOnEvenConsumer() -> AsyncMapConsumer<int, uint64_t> { return; } if (key == 0) { - (*setter)(uint64_t{static_cast<uint64_t>(0)}); + (*setter)(uint64_t{static_cast<std::uint64_t>(0)}); return; } if (key == 2) { - (*setter)(uint64_t{static_cast<uint64_t>(1)}); + (*setter)(uint64_t{static_cast<std::uint64_t>(1)}); return; } (*subcaller)( @@ -81,7 +81,7 @@ auto FibOnEvenConsumer() -> AsyncMapConsumer<int, uint64_t> { } auto CountToMaxConsumer(int max_val, int step = 1, bool cycle = false) - -> AsyncMapConsumer<int, uint64_t> { + -> AsyncMapConsumer<int, std::uint64_t> { 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<uint64_t>(key)}); + (*setter)(uint64_t{static_cast<std::uint64_t>(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<int, uint64_t>{value_creator}; + return AsyncMapConsumer<int, std::uint64_t>{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 <algorithm> // std::find #include <atomic> +#include <cstddef> #include <cstdlib> // std::system #include <filesystem> #include <optional> @@ -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<size_t> ops_all{ + const std::vector<std::size_t> ops_all{ 0, 1, 2, 3, 4}; // indices of all ops tested - const std::vector<size_t> ops_with_result{ + const std::vector<std::size_t> 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 <cstddef> +#include <cstdint> #include <fstream> #include <limits> #include <random> @@ -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 <size_t kChunkLength, size_t kPoolSize> +template <std::size_t kChunkLength, std::size_t kPoolSize> 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<std::ptrdiff_t>(index)); } @@ -62,10 +63,10 @@ class ChunkPool final { // Starts from 1 to exclude '\0' from randomization Randomizer randomizer{1, std::numeric_limits<char>::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<std::ptrdiff_t>(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<kChunkLength, kPoolSize>; // To create a random file, the initial chunk position and the shift are // randomized: - Randomizer randomizer{std::numeric_limits<size_t>::min(), - std::numeric_limits<size_t>::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<std::size_t>::min(), + std::numeric_limits<std::size_t>::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<size_t>::min(), - std::numeric_limits<size_t>::max()}; + Randomizer randomizer{std::numeric_limits<std::size_t>::min(), + std::numeric_limits<std::size_t>::max()}; std::uintmax_t entries = 0; while (entries < entries_count) { |