Skip to content

Commit 136f113

Browse files
committed
Test mouseover
1 parent c8ec11b commit 136f113

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

tests/s25Main/UI/testControls.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "driver/KeyEvent.h"
1515
#include "driver/MouseCoords.h"
1616
#include "helpers/mathFuncs.h"
17+
#include "mockupDrivers/MockupVideoDriver.h"
1718
#include "ogl/glFont.h"
1819
#include "uiHelper/uiHelpers.hpp"
1920
#include "libsiedler2/ArchivItem_Bitmap_Player.h"
@@ -27,6 +28,7 @@
2728
#include <boost/test/unit_test.hpp>
2829
#include <Loader.h>
2930
#include <array>
31+
#include <limits>
3032
#include <numeric>
3133

3234
// LCOV_EXCL_START
@@ -54,6 +56,26 @@ static std::unique_ptr<glFont> createMockFont(const std::vector<char32_t>& chars
5456

5557
BOOST_AUTO_TEST_SUITE(Controls)
5658

59+
BOOST_FIXTURE_TEST_CASE(MouseOver, uiHelper::Fixture)
60+
{
61+
const auto pos = rttr::test::randomPoint<DrawPoint>(0, std::numeric_limits<DrawPoint::ElementType>::max() / 2);
62+
const auto size = rttr::test::randomPoint<Extent>(10, std::numeric_limits<DrawPoint::ElementType>::max() / 2);
63+
const auto font = createMockFont({'H', 'e', 'l', 'o', '?'});
64+
ctrlTextButton bt(nullptr, 1, pos, size, TextureColor::Bricks, "Hello", font.get(), "");
65+
BOOST_TEST(bt.IsMouseOver(pos));
66+
BOOST_TEST(!bt.IsMouseOver(pos - DrawPoint(1, 0)));
67+
BOOST_TEST(!bt.IsMouseOver(pos - DrawPoint(0, 1)));
68+
BOOST_TEST(bt.IsMouseOver(pos + size / 2u));
69+
BOOST_TEST(bt.IsMouseOver(pos + size - DrawPoint(1, 1)));
70+
BOOST_TEST(!bt.IsMouseOver(pos + size));
71+
BOOST_TEST(!bt.IsMouseOver(pos + size + DrawPoint(0, 1)));
72+
// Without argument asks the video driver for the mouse position
73+
uiHelper::GetVideoDriver()->SetMousePos(pos + size / 2u);
74+
BOOST_TEST(bt.IsMouseOver());
75+
uiHelper::GetVideoDriver()->SetMousePos(pos + size * 2u);
76+
BOOST_TEST(!bt.IsMouseOver());
77+
}
78+
5779
static void resizeMap(libsiedler2::ArchivItem_Map& glMap, const Extent& size)
5880
{
5981
libsiedler2::ArchivItem_Map map;

0 commit comments

Comments
 (0)