From d304d1e57b87b0c701dc05cb772f5bf11eba2a73 Mon Sep 17 00:00:00 2001 From: Chris Thrasher Date: Fri, 1 Sep 2023 23:06:32 -0600 Subject: [PATCH] Add tests for `sf::Clipboard` --- test/CMakeLists.txt | 1 + test/Window/Clipboard.test.cpp | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 test/Window/Clipboard.test.cpp diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index d9d6466d6..82fc3eaaa 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -59,6 +59,7 @@ target_compile_definitions(test-sfml-system PRIVATE ) set(WINDOW_SRC + Window/Clipboard.test.cpp Window/Context.test.cpp Window/ContextSettings.test.cpp Window/Cursor.test.cpp diff --git a/test/Window/Clipboard.test.cpp b/test/Window/Clipboard.test.cpp new file mode 100644 index 000000000..68200a321 --- /dev/null +++ b/test/Window/Clipboard.test.cpp @@ -0,0 +1,28 @@ +#include + +// Other 1st party headers +#include + +#include + +#include + +TEST_CASE("[Window] sf::Clipboard", runDisplayTests()) +{ + // Capture current clipboard state + const auto currentClipboard = sf::Clipboard::getString(); + + SECTION("Set/get string") + { + sf::Clipboard::setString("Welcome to SFML!"); + CHECK(sf::Clipboard::getString() == "Welcome to SFML!"); + } + + // Restore clipboard + sf::Clipboard::setString(currentClipboard); + + // We rely on getString triggering clipboard event processing on X11 to make + // setString work, but note that the way setString is guaranteed to work is + // by having an open window for which events are being handled. + CHECK(sf::Clipboard::getString() == currentClipboard); +}