diff --git a/tests/auto/gui/CMakeLists.txt b/tests/auto/gui/CMakeLists.txt index 4780f2ea..6a2f5297 100644 --- a/tests/auto/gui/CMakeLists.txt +++ b/tests/auto/gui/CMakeLists.txt @@ -12,6 +12,7 @@ project(KDGui-Tests) include_directories(../KDFoundation/common) +add_subdirectory(position) add_subdirectory(window) if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux") diff --git a/tests/auto/gui/position/CMakeLists.txt b/tests/auto/gui/position/CMakeLists.txt new file mode 100644 index 00000000..fb14a42a --- /dev/null +++ b/tests/auto/gui/position/CMakeLists.txt @@ -0,0 +1,27 @@ +# This file is part of KDUtils. +# +# SPDX-FileCopyrightText: 2021-2023 Klarälvdalens Datakonsult AB, a KDAB Group company +# Author: Joshua Goins +# +# SPDX-License-Identifier: MIT +# +# Contact KDAB at for commercial licensing options. +# + +project( + test-gui-position + VERSION 0.1 + LANGUAGES CXX +) + +add_executable( + ${PROJECT_NAME} + tst_position.cpp +) + +target_link_libraries( + ${PROJECT_NAME} KDGui doctest +) + +add_test(NAME ${PROJECT_NAME} COMMAND $) +set_tests_properties(${PROJECT_NAME} PROPERTIES LABELS "Gui") diff --git a/tests/auto/gui/position/tst_position.cpp b/tests/auto/gui/position/tst_position.cpp new file mode 100644 index 00000000..19892032 --- /dev/null +++ b/tests/auto/gui/position/tst_position.cpp @@ -0,0 +1,47 @@ +/* + This file is part of KDUtils. + + SPDX-FileCopyrightText: 2021-2023 Klarälvdalens Datakonsult AB, a KDAB Group company + Author: Joshua Goins + + SPDX-License-Identifier: MIT + + Contact KDAB at for commercial licensing options. +*/ + +#include +#include + +#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN +#include + +using namespace KDGui; + +TEST_SUITE("Position") +{ + TEST_CASE("Constructor") + { + const Position pos{ 1, 2 }; + REQUIRE_EQ(pos.x, 1); + REQUIRE_EQ(pos.y, 2); + } + TEST_CASE("Equality") + { + const Position a{ 0, 2 }; + const Position b{ 3, 4 }; + const Position c{ 0, 0 }; + + REQUIRE(a == a); + REQUIRE(a != b); + REQUIRE(a != c); + } + TEST_CASE("Math Operators") + { + const Position a{ 1, 2 }; + const Position b{ 3, 4 }; + + REQUIRE_EQ(a + b, Position(4, 6)); + REQUIRE_EQ(a - b, Position(-2, -2)); + REQUIRE_EQ(a / int64_t{ 2 }, Position(0, 1)); + } +}