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]; 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; } 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/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") 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")