@@ -10,52 +10,74 @@ export namespace CppUtils::UnitTest
1010 using Logger = CppUtils::Logger<"CppUtils">;
1111
1212 public:
13+ inline DummyObject() = default;
14+
1315 explicit inline DummyObject(std::string name, std::size_t indentationLevel = 0):
1416 m_name{std::move(name)},
1517 m_indentationLevel{indentationLevel}
1618 {
17- Logger::print("{}{}()\n", std::string(m_indentationLevel, '\t'), m_name);
18- }
19+ Logger::print("{}{}()\n", std::string(m_indentationLevel, '\t'), m_name);
20+ }
1921
20- inline virtual ~DummyObject()
22+ [[nodiscard]] inline auto getCopyCount() const -> std::size_t
2123 {
22- Logger::print("{}~{}()\n", std::string(m_indentationLevel, '\t'), m_name) ;
24+ return m_copyCount ;
2325 }
2426
25- inline DummyObject( const DummyObject& other)
27+ [[nodiscard]] inline auto getMoveCount() const -> std::size_t
2628 {
27- m_name = other.m_name;
28- m_indentationLevel = other.m_indentationLevel;
29- Logger::print("{}{}(const {}&)\n", std::string(m_indentationLevel, '\t'), m_name, m_name);
29+ return m_moveCount;
3030 }
3131
32- inline DummyObject(DummyObject&& other )
32+ inline virtual ~ DummyObject()
3333 {
34- m_name = other.m_name;
35- m_indentationLevel = other.m_indentationLevel;
36- other.m_name += " [invalid object]";
37- Logger::print("{}{}({}&&)\n", std::string(m_indentationLevel, '\t'), m_name, m_name);
34+ Logger::print("{}~{}()\n", std::string(m_indentationLevel, '\t'), m_name);
3835 }
3936
37+ inline DummyObject(const DummyObject& other):
38+ m_name{other.m_name},
39+ m_indentationLevel{other.m_indentationLevel},
40+ m_copyCount{other.m_copyCount.load() + 1},
41+ m_moveCount{other.m_moveCount.load()}
42+ {
43+ Logger::print("{}{}(const {}&)\n", std::string(m_indentationLevel, '\t'), m_name, m_name);
44+ }
45+
46+ inline DummyObject(DummyObject&& other) noexcept:
47+ m_name{std::move(other.m_name)},
48+ m_indentationLevel{other.m_indentationLevel},
49+ m_copyCount{other.m_copyCount.load()},
50+ m_moveCount{other.m_moveCount.load() + 1}
51+ {
52+ other.m_name += " [invalid object]";
53+ Logger::print("{}{}({}&&)\n", std::string(m_indentationLevel, '\t'), m_name, m_name);
54+ }
55+
4056 inline auto operator=(const DummyObject& rhs) -> DummyObject&
41- {
42- m_name = rhs.m_name;
43- m_indentationLevel = rhs.m_indentationLevel;
44- Logger::print("{}{}::operator=(const {}&)\n", std::string(m_indentationLevel, '\t'), m_name, m_name);
45- return *this;
46- }
57+ {
58+ m_name = rhs.m_name;
59+ m_indentationLevel = rhs.m_indentationLevel;
60+ m_copyCount.store(rhs.m_copyCount.load() + 1);
61+ m_moveCount.store(rhs.m_moveCount.load());
62+ Logger::print("{}{}::operator=(const {}&)\n", std::string(m_indentationLevel, '\t'), m_name, m_name);
63+ return *this;
64+ }
4765
48- inline auto operator=(DummyObject&& rhs) -> DummyObject&
49- {
50- m_name = rhs.m_name;
51- m_indentationLevel = rhs.m_indentationLevel;
52- rhs.m_name += " [invalid object]";
53- Logger::print("{}{}::operator=({}&&)\n", std::string(m_indentationLevel, '\t'), m_name, m_name);
54- return *this;
55- }
66+ inline auto operator=(DummyObject&& rhs) noexcept -> DummyObject&
67+ {
68+ m_name = std::move(rhs.m_name);
69+ m_indentationLevel = rhs.m_indentationLevel;
70+ m_copyCount.store(rhs.m_copyCount.load());
71+ m_moveCount.store(rhs.m_moveCount.load() + 1);
72+ rhs.m_name += " [invalid object]";
73+ Logger::print("{}{}::operator=({}&&)\n", std::string(m_indentationLevel, '\t'), m_name, m_name);
74+ return *this;
75+ }
5676
5777 private:
5878 std::string m_name;
5979 std::size_t m_indentationLevel;
80+ std::atomic_size_t m_copyCount = 0;
81+ std::atomic_size_t m_moveCount = 0;
6082 };
6183}
0 commit comments