1
0
mirror of https://github.com/rwengine/openrw.git synced 2024-11-07 03:12:36 +01:00
openrw/tests/test_Menu.cpp

87 lines
1.7 KiB
C++
Raw Normal View History

2016-09-09 22:13:22 +02:00
#include <MenuSystem.hpp>
2013-12-25 20:54:22 +01:00
#include <boost/test/unit_test.hpp>
BOOST_AUTO_TEST_SUITE(MenuTests)
2013-12-25 20:54:22 +01:00
2016-09-09 22:13:22 +02:00
BOOST_AUTO_TEST_CASE(menu_test_click) {
2018-12-26 21:48:16 +01:00
bool clicked = false;
Menu test({{"Test", [&] { clicked = true; }}});
2016-09-09 22:13:22 +02:00
2018-12-26 21:48:16 +01:00
BOOST_CHECK(!clicked);
2016-09-09 22:13:22 +02:00
// Click underneath the menu item.
test.click(0.f, -1.f);
2018-12-26 21:48:16 +01:00
BOOST_CHECK(!clicked);
2016-09-09 22:13:22 +02:00
float h = 30.f;
2016-09-09 22:13:22 +02:00
test.click(0.f, h + 1.f);
2018-12-26 21:48:16 +01:00
BOOST_CHECK(!clicked);
2016-09-09 22:13:22 +02:00
test.click(0.f, h / 2.f);
2018-12-26 21:48:16 +01:00
BOOST_CHECK(clicked);
2013-12-25 20:54:22 +01:00
}
2016-09-09 22:13:22 +02:00
BOOST_AUTO_TEST_CASE(menu_test_click_offset) {
2018-12-26 21:48:16 +01:00
bool clicked = false;
Menu test({{"Test", [&] { clicked = true; }}}, glm::vec2(200.f, 200.f));
BOOST_CHECK(!clicked);
2016-09-09 22:13:22 +02:00
// Click underneath the menu item.
test.click(201.f, -1.f);
2018-12-26 21:48:16 +01:00
BOOST_CHECK(!clicked);
2016-09-09 22:13:22 +02:00
float h = 30.f;
2016-09-09 22:13:22 +02:00
test.click(201.f, 200.f + h + 1.f);
2018-12-26 21:48:16 +01:00
BOOST_CHECK(!clicked);
2016-09-09 22:13:22 +02:00
test.click(201.f, 200.f + h / 2.f);
2018-12-26 21:48:16 +01:00
BOOST_CHECK(clicked);
2013-12-27 22:58:47 +01:00
}
2016-09-09 22:13:22 +02:00
BOOST_AUTO_TEST_CASE(menu_test_active_index) {
2018-12-26 21:48:16 +01:00
int clickIndex = -1;
Menu test({{"Test1", [&] { clickIndex = 0; }},
{"Test2", [&] { clickIndex = 1; }}});
2016-09-09 22:13:22 +02:00
test.activate();
2018-12-26 21:48:16 +01:00
BOOST_CHECK(clickIndex == -1);
2016-09-09 22:13:22 +02:00
test.move(1);
test.activate();
2018-12-26 21:48:16 +01:00
BOOST_CHECK(clickIndex == 0);
2016-09-09 22:13:22 +02:00
test.move(1);
test.activate();
2018-12-26 21:48:16 +01:00
BOOST_CHECK(clickIndex == 1);
2016-09-09 22:13:22 +02:00
test.move(-1);
test.activate();
2018-12-26 21:48:16 +01:00
BOOST_CHECK(clickIndex == 0);
2014-01-01 01:37:16 +01:00
}
2016-09-09 22:13:22 +02:00
BOOST_AUTO_TEST_CASE(menu_test_hover_index) {
2018-12-26 21:48:16 +01:00
int clickIndex = -1;
Menu test({{"Test1", [&] { clickIndex = 0; }},
{"Test2", [&] { clickIndex = 1; }}});
2016-09-09 22:13:22 +02:00
test.hover(0.f, 30.f - 0.1f);
2016-09-09 22:13:22 +02:00
BOOST_CHECK(test.activeEntry == 0);
test.hover(0.f, 30.f + 0.1f);
2016-09-09 22:13:22 +02:00
BOOST_CHECK(test.activeEntry == 1);
2014-01-01 01:37:16 +01:00
}
2013-12-25 20:54:22 +01:00
BOOST_AUTO_TEST_SUITE_END()