aboutsummaryrefslogtreecommitdiff
path: root/libs/kstd/tests/include
diff options
context:
space:
mode:
Diffstat (limited to 'libs/kstd/tests/include')
-rw-r--r--libs/kstd/tests/include/kstd/tests/test_types.hpp71
1 files changed, 55 insertions, 16 deletions
diff --git a/libs/kstd/tests/include/kstd/tests/test_types.hpp b/libs/kstd/tests/include/kstd/tests/test_types.hpp
index 6a06311..9207ee9 100644
--- a/libs/kstd/tests/include/kstd/tests/test_types.hpp
+++ b/libs/kstd/tests/include/kstd/tests/test_types.hpp
@@ -11,44 +11,43 @@ 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 move_tracker
+ struct special_member_tracker
{
//! A value indicating that the object was moved from.
constexpr auto static moved_from_v = -1;
- //! A simple value to be able to track the move-from state.
- int value{};
- //! A flag to track if an instance of this type was either copy constructed or copy assigned.
- bool was_copied{false};
- //! A flag to track if an instance of this type was either move constructed or move assigned.
- bool was_moved{false};
+ constexpr special_member_tracker()
+ : default_constructed_count{1}
+ {}
//! Construct a new move tracker with the given value, if any.
- constexpr move_tracker(int v = 0)
+ constexpr special_member_tracker(int v = 0)
: value{v}
+ , value_constructed_count{1}
{}
//! Construct a new move tracker by copying an existing one.
- constexpr move_tracker(move_tracker const & other)
+ constexpr special_member_tracker(special_member_tracker const & other)
: value{other.value}
- , was_copied{true}
+ , copy_constructed_count{1}
{}
//! Construct a new move tracker by moving from an existing one.
- constexpr move_tracker(move_tracker && other) noexcept
+ constexpr special_member_tracker(special_member_tracker && other) noexcept
: value{other.value}
- , was_moved{true}
+ , move_constructed_count{1}
{
other.value = moved_from_v;
}
//! Copy assign a new move tracker from an existing one.
- constexpr auto operator=(move_tracker const & other) -> move_tracker &
+ constexpr auto operator=(special_member_tracker const & other) -> special_member_tracker &
{
if (this != &other)
{
value = other.value;
- was_copied = true;
+ ++copy_assigned_count;
+ ++other.copied_from_count;
}
return *this;
}
@@ -56,16 +55,56 @@ namespace kstd::tests
//! Move assign a new move tracker from an existing one.
//!
//! This function ensures that the moved-from state is marked.
- constexpr auto operator=(move_tracker && other) noexcept -> move_tracker &
+ constexpr auto operator=(special_member_tracker && other) noexcept -> special_member_tracker &
{
if (this != &other)
{
value = other.value;
- was_moved = true;
+ ++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.