diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index d9d6466d..82fc3eaa 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 00000000..68200a32 --- /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); +}