From 5480bf8a933992bf3df987ba475ad23e147aa460 Mon Sep 17 00:00:00 2001 From: alireza Date: Sat, 22 Apr 2023 19:29:05 +0300 Subject: [PATCH] Fixed move semantics for sf::Cursor and added test for it --- include/SFML/Window/Cursor.hpp | 4 ++-- src/SFML/Window/Cursor.cpp | 8 ++++++++ test/Window/Cursor.test.cpp | 16 ++++++++++++++++ 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/include/SFML/Window/Cursor.hpp b/include/SFML/Window/Cursor.hpp index 9d20f250..bd2869b2 100644 --- a/include/SFML/Window/Cursor.hpp +++ b/include/SFML/Window/Cursor.hpp @@ -145,13 +145,13 @@ public: /// \brief Move constructor /// //////////////////////////////////////////////////////////// - Cursor(Cursor&&) noexcept = default; + Cursor(Cursor&&) noexcept; //////////////////////////////////////////////////////////// /// \brief Move assignment /// //////////////////////////////////////////////////////////// - Cursor& operator=(Cursor&&) noexcept = default; + Cursor& operator=(Cursor&&) noexcept; //////////////////////////////////////////////////////////// /// \brief Create a cursor with the provided image diff --git a/src/SFML/Window/Cursor.cpp b/src/SFML/Window/Cursor.cpp index 120e2503..37a79d6c 100644 --- a/src/SFML/Window/Cursor.cpp +++ b/src/SFML/Window/Cursor.cpp @@ -44,6 +44,14 @@ Cursor::Cursor() : m_impl(std::make_unique()) Cursor::~Cursor() = default; +//////////////////////////////////////////////////////////// +Cursor::Cursor(Cursor&&) noexcept = default; + + +//////////////////////////////////////////////////////////// +Cursor& Cursor::operator=(Cursor&&) noexcept = default; + + //////////////////////////////////////////////////////////// bool Cursor::loadFromPixels(const std::uint8_t* pixels, Vector2u size, Vector2u hotspot) { diff --git a/test/Window/Cursor.test.cpp b/test/Window/Cursor.test.cpp index aafe6b26..773891ea 100644 --- a/test/Window/Cursor.test.cpp +++ b/test/Window/Cursor.test.cpp @@ -19,6 +19,22 @@ TEST_CASE("[Window] sf::Cursor" * doctest::skip(true)) const sf::Cursor cursor; } + SUBCASE("Move semantics") + { + SUBCASE("Construction") + { + sf::Cursor movedCursor; + const sf::Cursor cursor(std::move(movedCursor)); + } + + SUBCASE("Assignment") + { + sf::Cursor movedCursor; + sf::Cursor cursor; + cursor = std::move(movedCursor); + } + } + SUBCASE("loadFromPixels()") { sf::Cursor cursor;