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>
|
|
|
|
#include "test_globals.hpp"
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_SUITE(MenuUnitTests)
|
|
|
|
|
2016-09-09 22:13:22 +02:00
|
|
|
BOOST_AUTO_TEST_CASE(menu_test_click) {
|
|
|
|
bool clickered = false;
|
2016-10-18 23:00:53 +02:00
|
|
|
Menu test({{"Test", [&] { clickered = true; }}});
|
2016-09-09 22:13:22 +02:00
|
|
|
|
|
|
|
BOOST_CHECK(!clickered);
|
|
|
|
|
|
|
|
// Click underneath the menu item.
|
|
|
|
test.click(0.f, -1.f);
|
|
|
|
|
|
|
|
BOOST_CHECK(!clickered);
|
|
|
|
|
2016-10-18 23:00:53 +02:00
|
|
|
float h = test.getEntries().at(0).getHeight();
|
2016-09-09 22:13:22 +02:00
|
|
|
|
|
|
|
test.click(0.f, h + 1.f);
|
|
|
|
|
|
|
|
BOOST_CHECK(!clickered);
|
|
|
|
|
|
|
|
test.click(0.f, h / 2.f);
|
|
|
|
|
|
|
|
BOOST_CHECK(clickered);
|
2013-12-25 20:54:22 +01:00
|
|
|
}
|
|
|
|
|
2016-09-09 22:13:22 +02:00
|
|
|
BOOST_AUTO_TEST_CASE(menu_test_click_offset) {
|
|
|
|
bool clickered = false;
|
2016-10-18 23:00:53 +02:00
|
|
|
Menu test({{"Test", [&] { clickered = true; }}});
|
2016-09-09 22:13:22 +02:00
|
|
|
test.offset = glm::vec2(200.f, 200.f);
|
|
|
|
|
|
|
|
BOOST_CHECK(!clickered);
|
|
|
|
|
|
|
|
// Click underneath the menu item.
|
|
|
|
test.click(201.f, -1.f);
|
|
|
|
|
|
|
|
BOOST_CHECK(!clickered);
|
|
|
|
|
2016-10-18 23:00:53 +02:00
|
|
|
float h = test.getEntries().at(0).getHeight();
|
2016-09-09 22:13:22 +02:00
|
|
|
|
|
|
|
test.click(201.f, 200.f + h + 1.f);
|
|
|
|
|
|
|
|
BOOST_CHECK(!clickered);
|
|
|
|
|
|
|
|
test.click(201.f, 200.f + h / 2.f);
|
|
|
|
|
|
|
|
BOOST_CHECK(clickered);
|
2013-12-27 22:58:47 +01:00
|
|
|
}
|
|
|
|
|
2016-09-09 22:13:22 +02:00
|
|
|
BOOST_AUTO_TEST_CASE(menu_test_active_index) {
|
|
|
|
int clickindex = -1;
|
2016-10-18 23:00:53 +02:00
|
|
|
Menu test({{"Test1", [&] { clickindex = 0; }},
|
|
|
|
{"Test2", [&] { clickindex = 1; }}});
|
2016-09-09 22:13:22 +02:00
|
|
|
|
|
|
|
test.activate();
|
|
|
|
|
|
|
|
BOOST_CHECK(clickindex == -1);
|
|
|
|
|
|
|
|
test.move(1);
|
|
|
|
test.activate();
|
|
|
|
|
|
|
|
BOOST_CHECK(clickindex == 0);
|
|
|
|
|
|
|
|
test.move(1);
|
|
|
|
test.activate();
|
|
|
|
|
|
|
|
BOOST_CHECK(clickindex == 1);
|
|
|
|
|
|
|
|
test.move(-1);
|
|
|
|
test.activate();
|
|
|
|
|
|
|
|
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) {
|
|
|
|
int clickindex = -1;
|
2016-10-18 23:00:53 +02:00
|
|
|
Menu test({{"Test1", [&] { clickindex = 0; }},
|
|
|
|
{"Test2", [&] { clickindex = 1; }}});
|
2016-09-09 22:13:22 +02:00
|
|
|
|
2016-10-18 23:00:53 +02:00
|
|
|
test.hover(0.f, test.getEntries()[0].getHeight() - 0.1f);
|
2016-09-09 22:13:22 +02:00
|
|
|
BOOST_CHECK(test.activeEntry == 0);
|
|
|
|
|
2016-10-18 23:00:53 +02:00
|
|
|
test.hover(0.f, test.getEntries()[0].getHeight() + 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()
|