Add tests for sf::Clipboard

This commit is contained in:
Chris Thrasher 2023-09-01 23:06:32 -06:00
parent 1811951b4a
commit d304d1e57b
2 changed files with 29 additions and 0 deletions

View File

@ -59,6 +59,7 @@ target_compile_definitions(test-sfml-system PRIVATE
) )
set(WINDOW_SRC set(WINDOW_SRC
Window/Clipboard.test.cpp
Window/Context.test.cpp Window/Context.test.cpp
Window/ContextSettings.test.cpp Window/ContextSettings.test.cpp
Window/Cursor.test.cpp Window/Cursor.test.cpp

View File

@ -0,0 +1,28 @@
#include <SFML/Window/Clipboard.hpp>
// Other 1st party headers
#include <SFML/System/String.hpp>
#include <catch2/catch_test_macros.hpp>
#include <WindowUtil.hpp>
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);
}