Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion gui-builder/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
1 change: 1 addition & 0 deletions include/TGUI/Global.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ namespace tgui
template <typename T>
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;
}

Expand Down
1 change: 1 addition & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ set(TEST_SOURCES
Filesystem.cpp
Focus.cpp
Font.cpp
Global.cpp
Layouts.cpp
Loading/DataIO.cpp
Loading/Deserializer.cpp
Expand Down
86 changes: 86 additions & 0 deletions tests/Global.cpp
Original file line number Diff line number Diff line change
@@ -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));
}
}
4 changes: 4 additions & 0 deletions tests/Loading/DataIO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
7 changes: 0 additions & 7 deletions tests/Widgets/EditBox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down