From 3ab0a15fb6aba0ad9516da69589b9da8dbd63a8e Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Sat, 2 May 2026 17:12:21 +0200 Subject: libs: adopt p1204 layout for kstd --- libs/kstd/tests/include/kstd/tests/os_panic.hpp | 23 -- libs/kstd/tests/include/kstd/tests/test_types.hpp | 313 ---------------------- 2 files changed, 336 deletions(-) delete mode 100644 libs/kstd/tests/include/kstd/tests/os_panic.hpp delete mode 100644 libs/kstd/tests/include/kstd/tests/test_types.hpp (limited to 'libs/kstd/tests/include') diff --git a/libs/kstd/tests/include/kstd/tests/os_panic.hpp b/libs/kstd/tests/include/kstd/tests/os_panic.hpp deleted file mode 100644 index 4396a9f..0000000 --- a/libs/kstd/tests/include/kstd/tests/os_panic.hpp +++ /dev/null @@ -1,23 +0,0 @@ -#ifndef KSTD_TESTS_OS_PANIC_HPP -#define KSTD_TESTS_OS_PANIC_HPP - -#include -#include -#include - -namespace kstd::tests -{ - - struct os_panic : std::runtime_error - { - os_panic(std::string message, std::source_location location) - : std::runtime_error{message} - , location(location) - {} - - std::source_location location; - }; - -} // namespace kstd::tests - -#endif \ No newline at end of file diff --git a/libs/kstd/tests/include/kstd/tests/test_types.hpp b/libs/kstd/tests/include/kstd/tests/test_types.hpp deleted file mode 100644 index 8231fd3..0000000 --- a/libs/kstd/tests/include/kstd/tests/test_types.hpp +++ /dev/null @@ -1,313 +0,0 @@ -#ifndef KSTD_TESTS_TEST_TYPES_HPP -#define KSTD_TESTS_TEST_TYPES_HPP - -#include -#include -#include - -namespace kstd::tests -{ - - //! A type tracking copy and move operations - //! - //! This type is designed to test move and copy semantics of standard library containers implemented in kstd. - struct special_member_tracker - { - //! A value indicating that the object was moved from. - constexpr auto static moved_from_v = -1; - - constexpr special_member_tracker() - : default_constructed_count{1} - {} - - //! Construct a new move tracker with the given value, if any. - constexpr special_member_tracker(int v = 0) - : value{v} - , value_constructed_count{1} - {} - - //! Construct a new move tracker by copying an existing one. - constexpr special_member_tracker(special_member_tracker const & other) - : value{other.value} - , copy_constructed_count{1} - {} - - //! Construct a new move tracker by moving from an existing one. - constexpr special_member_tracker(special_member_tracker && other) noexcept - : value{other.value} - , move_constructed_count{1} - { - other.value = moved_from_v; - } - - //! Copy assign a new move tracker from an existing one. - constexpr auto operator=(special_member_tracker const & other) -> special_member_tracker & - { - if (this != &other) - { - value = other.value; - ++copy_assigned_count; - ++other.copied_from_count; - } - return *this; - } - - //! Move assign a new move tracker from an existing one. - //! - //! This function ensures that the moved-from state is marked. - constexpr auto operator=(special_member_tracker && other) noexcept -> special_member_tracker & - { - if (this != &other) - { - value = other.value; - ++move_assigned_count; - other.value = moved_from_v; - ++other.moved_from_count; - } - return *this; - } - - ~special_member_tracker() - { - ++destroyed_count; - } - - auto reset_counts() -> void - { - default_constructed_count = 0; - copy_constructed_count = 0; - move_constructed_count = 0; - value_constructed_count = 0; - copy_assigned_count = 0; - move_assigned_count = 0; - destroyed_count = 0; - copied_from_count = 0; - moved_from_count = 0; - } - - //! A simple value to be able to track the move-from state. - int value{}; - //! A counter to track how many times an instance of this type was default constructed. - std::size_t default_constructed_count{0}; - //! A counter to track how many times an instance of this type was copy constructed. - std::size_t copy_constructed_count{0}; - //! A counter to track how many times an instance of this type was move constructed. - std::size_t move_constructed_count{0}; - //! A counter to track how many times an instance of this type was value constructed. - std::size_t value_constructed_count{0}; - //! A counter to track how many times an instance of this type was copy assigned. - std::size_t copy_assigned_count{0}; - //! A counter to track how many times an instance of this type was move assigned. - std::size_t move_assigned_count{0}; - //! A counter to track how many times an instance of this type was destroyed. - std::size_t destroyed_count{0}; - //! A counter to track how many times an instance of this type was copied from another instance. - mutable std::size_t copied_from_count{0}; - //! A counter to track how many times an instance of this type was moved from another instance. - std::size_t moved_from_count{0}; - }; - - //! A type that is not default constructible. - //! - //! This type is designed to test default construction semantics of standard library containers implemented in kstd. - struct non_default_constructible - { - //! A simple placeholder value. - int value{}; - - //! Construct a new non-default-constructible object with the given value. - constexpr explicit non_default_constructible(int v) - : value{v} - {} - - //! Compare two non-default-constructible objects for equality. - [[nodiscard]] constexpr auto operator==(non_default_constructible const & other) const -> bool - { - return value == other.value; - } - }; - - //! An allocator that tracks the number of allocations. - //! - //! This allocator is designed to test allocation semantics of standard library containers implemented in kstd. - //! - //! @tparam T The type of the elements to be allocated. - template - struct tracking_allocator - { - using value_type = T; - using size_type = std::size_t; - using difference_type = std::ptrdiff_t; - - //! A pointer to a counter that is incremented on allocation. - //! - //! A pointer is used so that multiple allocators can share the same counter. - int * allocation_count{}; - - //! Construct a new tracking allocator referencing the given counter. - tracking_allocator(int * counter) - : allocation_count{counter} - {} - - //! Construct a new tracking allocator by copying from another tracking allocator. - //! - //! This constructor is templated to allow for conversion from allocators of different types. - //! - //! @tparam U The type of the elements to be allocated by the other allocator. - template - tracking_allocator(tracking_allocator const & other) noexcept - : allocation_count{other.allocation_count} - {} - - //! Allocate memory for n elements of type T. - //! - //! @param n The number of elements to allocate. - //! @return A pointer to the allocated memory. - [[nodiscard]] auto allocate(std::size_t n) -> T * - { - if (allocation_count != nullptr) - { - ++(*allocation_count); - } - return static_cast(::operator new(n * sizeof(T))); - } - - //! Deallocate memory for n elements of type T. - //! - //! @param p A pointer to the memory to deallocate. - //! @param n The number of elements to deallocate. - auto deallocate(T * p, std::size_t n) noexcept -> void - { - ::operator delete(p, n * sizeof(T)); - } - - //! Compare two tracking allocators for equality. - //! - //! Two allocators are considered equal if they reference the same allocation counter. - //! - //! @param other The other tracking allocator to compare to. - //! @return True if the two tracking allocators are equal, false otherwise. - [[nodiscard]] auto operator==(tracking_allocator const & other) const -> bool - { - return allocation_count == other.allocation_count; - } - - //! Compare two tracking_allocators for inequality. - //! - //! @param other The other tracking_allocator to compare to. - //! @return True if the two tracking_allocators are not equal, false otherwise. - [[nodiscard]] auto operator!=(tracking_allocator const & other) const -> bool - { - return allocation_count != other.allocation_count; - } - }; - - //! An allocator that propagates copy assignment. - //! - //! This allocator is designed to test copy assignment semantics of standard library containers implemented in kstd. - //! - //! @tparam T The type of the elements to be allocated. - template - struct propagating_allocator : tracking_allocator - { - //! A flag to indicate that the allocator propagates copy assignment. - using propagate_on_container_copy_assignment = std::true_type; - - //! Construct a new propagating allocator referencing the given counter. - //! - //! @param counter A pointer to a counter that is incremented on allocation. - //! @see tracking_allocator::tracking_allocator(int*) - propagating_allocator(int * counter) - : tracking_allocator{counter} - {} - - //! Construct a new propagating allocator by copying from another propagating allocator. - //! - //! This constructor is templated to allow for conversion from allocators of different types. - //! - //! @tparam U The type of the elements to be allocated by the other allocator. - //! @see tracking_allocator::tracking_allocator(tracking_allocator const&) - template - propagating_allocator(propagating_allocator const & other) noexcept - : tracking_allocator{other.allocation_count} - {} - }; - - //! A test input iterator. - //! - //! This iterator is designed to test input iterator semantics of standard library containers implemented in kstd. - struct test_input_iterator - { - using iterator_concept = std::input_iterator_tag; - using iterator_category = std::input_iterator_tag; - using difference_type = std::ptrdiff_t; - using value_type = int; - using reference = int const &; - using pointer = int const *; - - //! The current element pointed to by the iterator. - int const * current; - //! The number of elements in the range. - std::size_t count; - - explicit test_input_iterator() - : current{nullptr} - , count{0} - {} - - //! Construct a new test input iterator. - //! - //! @param current The current element pointed to by the iterator. - //! @param count The number of elements in the range. - explicit test_input_iterator(int const * current, std::size_t count) - : current{current} - , count{count} - {} - - //! Dereference the iterator to get the current element. - //! - //! @return The current element pointed to by the iterator. - [[nodiscard]] auto operator*() const -> int - { - return *current; - } - - //! Increment the iterator to point to the next element. - //! - //! @return A reference to the incremented iterator. - auto operator++() -> test_input_iterator & - { - ++current; - --count; - return *this; - } - - //! Increment the iterator to point to the next element. - auto operator++(int) -> void - { - ++*this; - } - - //! Compare two test input iterators for equality. - //! - //! @param other The other test input iterator to compare to. - //! @return True if the two test input iterators are equal, false otherwise. - [[nodiscard]] auto operator==(test_input_iterator const & other) const -> bool - { - if (current == nullptr && other.current == nullptr) - { - return true; - } - - if (current == nullptr || other.current == nullptr) - { - return count == other.count; - } - - return current == other.current && count == other.count; - } - }; - -} // namespace kstd::tests - -#endif -- cgit v1.2.3