From 6112ba118fcaf5f0ec1cc7e8420ee727858a5991 Mon Sep 17 00:00:00 2001 From: Jesper Juhl Date: Thu, 5 Mar 2026 13:23:40 +0100 Subject: [PATCH 1/4] Return EXIT_FAILURE in gui-builder main on Windows on failure Commit ef7de90b30f826fc01f91ad4c00aade913d075f8 missed a spot. --- gui-builder/src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gui-builder/src/main.cpp b/gui-builder/src/main.cpp index 6c6e9cfcb..5ab557f13 100644 --- a/gui-builder/src/main.cpp +++ b/gui-builder/src/main.cpp @@ -67,7 +67,7 @@ int main(int, char* argv[]) if (argvW == nullptr) { std::cerr << "Failed to access command line arguments\n"; - return 1; + return EXIT_FAILURE; } const tgui::String exePath = argvW[0]; From 039cdb18c51494212af1bb06b5157031476f3c39 Mon Sep 17 00:00:00 2001 From: Jesper Juhl Date: Fri, 6 Mar 2026 17:11:57 +0100 Subject: [PATCH 2/4] Add an assert for precondition !(hi < lo) to tgui::clamp As far as I can tell, tgui::clamp matches the behaviour and precondition requirements of std::clamp exactly, but if a user passes a value of 'hi' that is less than 'lo' then the returned result may be surprising (not undefined, just not what you'd expect). To guard against such surprises I think it is prudent to add an assert for debug builds that checks the precondition - it costs nothing for release builds but may save some users from a nasty surprise in debug builds. --- include/TGUI/Global.hpp | 1 + 1 file changed, 1 insertion(+) diff --git a/include/TGUI/Global.hpp b/include/TGUI/Global.hpp index f58f1de84..aa0025c28 100644 --- a/include/TGUI/Global.hpp +++ b/include/TGUI/Global.hpp @@ -63,6 +63,7 @@ namespace tgui template TGUI_NODISCARD constexpr const T& clamp(const T& v, const T& lo, const T& hi) { + TGUI_ASSERT(!(hi < lo), "The highest value must not be less than the lowest value"); return (v < lo) ? lo : (hi < v) ? hi : v; } From b2de239b5f7119c3084d11bcc72c1b26c32db753 Mon Sep 17 00:00:00 2001 From: Jesper Juhl Date: Fri, 6 Mar 2026 18:10:50 +0100 Subject: [PATCH 3/4] Expand test for DataIO::parse slightly --- tests/Loading/DataIO.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/Loading/DataIO.cpp b/tests/Loading/DataIO.cpp index cde479299..5e689d51c 100644 --- a/tests/Loading/DataIO.cpp +++ b/tests/Loading/DataIO.cpp @@ -32,6 +32,10 @@ TEST_CASE("[DataIO]") { std::stringstream input(""); REQUIRE_NOTHROW(tgui::DataIO::parse(input)); + std::stringstream input2; + REQUIRE_NOTHROW(tgui::DataIO::parse(input2)); + std::stringstream input3(" "); + REQUIRE_NOTHROW(tgui::DataIO::parse(input3)); } SECTION("Global properties") From 147a796310baf9663a55c9319732e333831a7ca7 Mon Sep 17 00:00:00 2001 From: Jesper Juhl Date: Fri, 6 Mar 2026 18:02:54 +0100 Subject: [PATCH 4/4] Add tests for global TGUI functions This adds tests for some (not all) global TGUI functions declared/defined in Global.hpp/Global.cpp Some of these were already fully or partially covered transitively by other tests, but adding explicit tests doesn't hurt. This just makes the tests explicit and expands the coverage. Some global functions are not tested yet since I need to figure out how to do that properly, but that doesn't detract from these tests. --- tests/CMakeLists.txt | 1 + tests/Global.cpp | 86 +++++++++++++++++++++++++++++++++++++++ tests/Widgets/EditBox.cpp | 7 ---- 3 files changed, 87 insertions(+), 7 deletions(-) create mode 100644 tests/Global.cpp diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 5dbb1d811..b5917efa8 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -37,6 +37,7 @@ set(TEST_SOURCES Filesystem.cpp Focus.cpp Font.cpp + Global.cpp Layouts.cpp Loading/DataIO.cpp Loading/Deserializer.cpp diff --git a/tests/Global.cpp b/tests/Global.cpp new file mode 100644 index 000000000..eaf0db238 --- /dev/null +++ b/tests/Global.cpp @@ -0,0 +1,86 @@ +///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// +// TGUI - Texus' Graphical User Interface +// Copyright (C) 2012-2026 Bruno Van de Velde (vdv_b@tgui.eu) +// +// This software is provided 'as-is', without any express or implied warranty. +// In no event will the authors be held liable for any damages arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it freely, +// subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; +// you must not claim that you wrote the original software. +// If you use this software in a product, an acknowledgment +// in the product documentation would be appreciated but is not required. +// +// 2. Altered source versions must be plainly marked as such, +// and must not be misrepresented as being the original software. +// +// 3. This notice may not be removed or altered from any source distribution. +// +///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +#include "TGUI/Filesystem.hpp" +#include "TGUI/Global.hpp" +#include "Tests.hpp" + +TEST_CASE("[Global]") +{ + SECTION("clamp") + { + REQUIRE(tgui::clamp(0, 1, 3) == 1); + REQUIRE(tgui::clamp(1, 1, 3) == 1); + REQUIRE(tgui::clamp(2, 1, 3) == 2); + REQUIRE(tgui::clamp(3, 1, 3) == 3); + REQUIRE(tgui::clamp(4, 1, 3) == 3); + REQUIRE(tgui::clamp(5, 6, 6) == 6); + REQUIRE(tgui::clamp(6, 6, 6) == 6); + REQUIRE(tgui::clamp(7, 6, 6) == 6); + } + + SECTION("Text size") + { + REQUIRE(tgui::getGlobalTextSize() == 13); + tgui::setGlobalTextSize(42); + REQUIRE(tgui::getGlobalTextSize() == 42); + // We need to set the global text size back to the default or other tests will fail + REQUIRE_NOTHROW(tgui::setGlobalTextSize(13)); + REQUIRE(tgui::getGlobalTextSize() == 13); + } + + SECTION("Double click time") + { + REQUIRE(tgui::getDoubleClickTime() == std::chrono::milliseconds(500)); + tgui::setDoubleClickTime(std::chrono::milliseconds(666)); + REQUIRE(tgui::getDoubleClickTime() == std::chrono::milliseconds(666)); + // We need to set the global double click time back to the default or other tests will fail + REQUIRE_NOTHROW(tgui::setDoubleClickTime(std::chrono::milliseconds(500))); + REQUIRE(tgui::getDoubleClickTime() == std::chrono::milliseconds(500)); + } + + SECTION("Resource path") + { + REQUIRE(tgui::getResourcePath() == tgui::Filesystem::Path("")); + tgui::setResourcePath(tgui::Filesystem::Path("/Some_arbitrary_path")); + REQUIRE(tgui::getResourcePath() == tgui::Filesystem::Path("/Some_arbitrary_path/")); + tgui::setResourcePath(tgui::Filesystem::Path("/Some_other_arbitrary_path/")); + REQUIRE(tgui::getResourcePath() == tgui::Filesystem::Path("/Some_other_arbitrary_path/")); + tgui::setResourcePath(tgui::Filesystem::Path("arbitrary_path")); + REQUIRE(tgui::getResourcePath() == tgui::Filesystem::Path("arbitrary_path/")); + // We need to set the global resource path back to the default or other tests will fail + REQUIRE_NOTHROW(tgui::setResourcePath(tgui::Filesystem::Path())); + REQUIRE(tgui::getResourcePath() == tgui::Filesystem::Path()); + } + + SECTION("Edit cursor blink rate") + { + REQUIRE(tgui::getEditCursorBlinkRate() == std::chrono::milliseconds(500)); + tgui::setEditCursorBlinkRate(std::chrono::milliseconds(123)); + REQUIRE(tgui::getEditCursorBlinkRate() == std::chrono::milliseconds(123)); + // We need to set the global edit cursor blink time back to the default or other tests will fail + REQUIRE_NOTHROW(tgui::setEditCursorBlinkRate(std::chrono::milliseconds(500))); + REQUIRE(tgui::getEditCursorBlinkRate() == std::chrono::milliseconds(500)); + } +} diff --git a/tests/Widgets/EditBox.cpp b/tests/Widgets/EditBox.cpp index af7cece1a..44da6b89a 100644 --- a/tests/Widgets/EditBox.cpp +++ b/tests/Widgets/EditBox.cpp @@ -350,13 +350,6 @@ TEST_CASE("[EditBox]") } } - SECTION("Blink rate") - { - REQUIRE(tgui::getEditCursorBlinkRate() == std::chrono::milliseconds(500)); - tgui::setEditCursorBlinkRate(std::chrono::milliseconds(100)); - REQUIRE(tgui::getEditCursorBlinkRate() == std::chrono::milliseconds(100)); - } - SECTION("Events / Signals") { SECTION("ClickableWidget")