2014-07-28 07:20:39 +02:00
|
|
|
#include <boost/test/unit_test.hpp>
|
2016-05-07 19:29:08 +02:00
|
|
|
#include <engine/ScreenText.hpp>
|
2017-09-07 18:44:21 +02:00
|
|
|
#include <fonts/GameTexts.hpp>
|
2016-09-09 22:13:22 +02:00
|
|
|
#include <loaders/LoaderGXT.hpp>
|
2018-07-06 22:05:43 +02:00
|
|
|
#include <platform/FileHandle.hpp>
|
2017-10-26 03:51:24 +02:00
|
|
|
#include "test_Globals.hpp"
|
2014-07-28 07:20:39 +02:00
|
|
|
|
2017-09-07 19:00:16 +02:00
|
|
|
#define T(x) GameStringUtil::fromString(x, FONT_PRICEDOWN)
|
2016-08-16 01:53:27 +02:00
|
|
|
|
2014-07-28 07:20:39 +02:00
|
|
|
BOOST_AUTO_TEST_SUITE(TextTests)
|
|
|
|
|
2019-01-18 02:29:59 +01:00
|
|
|
BOOST_AUTO_TEST_CASE(load_test, DATA_TEST_PREDICATE) {
|
2016-09-09 22:13:22 +02:00
|
|
|
{
|
2018-06-21 23:41:10 +02:00
|
|
|
auto d = Global::get().e->data->index.openFileRaw("text/english.gxt");
|
2014-07-28 07:20:39 +02:00
|
|
|
|
2016-09-09 22:13:22 +02:00
|
|
|
GameTexts texts;
|
2014-07-28 07:20:39 +02:00
|
|
|
|
2016-09-09 22:13:22 +02:00
|
|
|
LoaderGXT loader;
|
2014-07-28 07:20:39 +02:00
|
|
|
|
2016-09-09 22:13:22 +02:00
|
|
|
loader.load(texts, d);
|
2014-07-28 07:20:39 +02:00
|
|
|
|
2016-09-09 22:13:22 +02:00
|
|
|
BOOST_CHECK_EQUAL(texts.text("1008"), T("BUSTED"));
|
|
|
|
}
|
2014-07-28 07:20:39 +02:00
|
|
|
}
|
|
|
|
|
2017-09-07 18:44:21 +02:00
|
|
|
BOOST_AUTO_TEST_CASE(special_chars) {
|
|
|
|
{
|
|
|
|
auto newline = T("\n");
|
|
|
|
BOOST_CHECK_EQUAL(newline.size(), 1);
|
|
|
|
BOOST_CHECK_EQUAL(newline[0], '\n');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-09 22:13:22 +02:00
|
|
|
BOOST_AUTO_TEST_CASE(big_test) {
|
|
|
|
// Check that makeBig creates a text in the right place
|
|
|
|
{
|
|
|
|
auto big =
|
|
|
|
ScreenTextEntry::makeBig("TEST_1", T("Test String"), 1, 5000);
|
|
|
|
|
|
|
|
BOOST_CHECK_EQUAL("TEST_1", big.id);
|
|
|
|
BOOST_CHECK_EQUAL(T("Test String"), big.text);
|
|
|
|
BOOST_CHECK_EQUAL(5000, big.durationMS);
|
|
|
|
BOOST_CHECK_EQUAL(0, big.displayedMS);
|
|
|
|
BOOST_CHECK_EQUAL(1, big.alignment);
|
|
|
|
BOOST_CHECK_EQUAL(50, big.size);
|
|
|
|
}
|
|
|
|
{
|
|
|
|
auto big =
|
|
|
|
ScreenTextEntry::makeBig("TEST_1", T("Test String"), 2, 5000);
|
|
|
|
|
|
|
|
BOOST_CHECK_EQUAL(T("Test String"), big.text);
|
|
|
|
BOOST_CHECK_EQUAL(5000, big.durationMS);
|
|
|
|
BOOST_CHECK_EQUAL(0, big.displayedMS);
|
|
|
|
BOOST_CHECK_EQUAL(2, big.alignment);
|
|
|
|
BOOST_CHECK_EQUAL(30, big.size);
|
|
|
|
}
|
2016-05-07 19:29:08 +02:00
|
|
|
}
|
|
|
|
|
2016-09-09 22:13:22 +02:00
|
|
|
BOOST_AUTO_TEST_CASE(help_test) {
|
|
|
|
auto help = ScreenTextEntry::makeHelp("TEST_1", T("Test Help"));
|
2016-05-07 19:29:08 +02:00
|
|
|
|
2016-09-09 22:13:22 +02:00
|
|
|
BOOST_CHECK_EQUAL(T("Test Help"), help.text);
|
|
|
|
BOOST_CHECK_EQUAL(5000, help.durationMS);
|
|
|
|
BOOST_CHECK_EQUAL(0, help.displayedMS);
|
|
|
|
BOOST_CHECK_EQUAL(18, help.size);
|
2016-05-07 19:29:08 +02:00
|
|
|
}
|
|
|
|
|
2016-09-09 22:13:22 +02:00
|
|
|
BOOST_AUTO_TEST_CASE(queue_test) {
|
|
|
|
// Check that creating a test puts it on the right queue.
|
2016-05-07 19:29:08 +02:00
|
|
|
|
2016-09-09 22:13:22 +02:00
|
|
|
ScreenText st;
|
2016-05-07 19:29:08 +02:00
|
|
|
|
2016-09-09 22:13:22 +02:00
|
|
|
st.addText<ScreenTextType::Big>(
|
|
|
|
ScreenTextEntry::makeBig("TEST_1", T("Test String"), 2, 5000));
|
|
|
|
st.addText<ScreenTextType::HighPriority>(
|
|
|
|
ScreenTextEntry::makeHighPriority("TEST_1", T("Test String"), 5000));
|
2016-05-07 19:29:08 +02:00
|
|
|
|
2016-09-09 22:13:22 +02:00
|
|
|
BOOST_REQUIRE(st.getText<ScreenTextType::Big>().size() == 1);
|
|
|
|
BOOST_CHECK_EQUAL(T("Test String"),
|
|
|
|
st.getText<ScreenTextType::Big>()[0].text);
|
|
|
|
BOOST_CHECK_EQUAL(5000, st.getText<ScreenTextType::Big>()[0].durationMS);
|
|
|
|
BOOST_CHECK_EQUAL(0, st.getText<ScreenTextType::Big>()[0].displayedMS);
|
2016-05-07 19:29:08 +02:00
|
|
|
|
2016-09-09 22:13:22 +02:00
|
|
|
BOOST_CHECK_EQUAL(1, st.getText<ScreenTextType::HighPriority>().size());
|
2016-05-07 19:29:08 +02:00
|
|
|
|
2016-09-09 22:13:22 +02:00
|
|
|
st.tick(6.f);
|
2016-05-07 19:29:08 +02:00
|
|
|
|
2016-09-09 22:13:22 +02:00
|
|
|
BOOST_CHECK_EQUAL(0, st.getText<ScreenTextType::Big>().size());
|
|
|
|
BOOST_CHECK_EQUAL(0, st.getText<ScreenTextType::HighPriority>().size());
|
2016-05-07 19:29:08 +02:00
|
|
|
}
|
|
|
|
|
2016-09-09 22:13:22 +02:00
|
|
|
BOOST_AUTO_TEST_CASE(clear_test) {
|
|
|
|
ScreenText st;
|
2016-05-07 19:29:08 +02:00
|
|
|
|
2016-09-09 22:13:22 +02:00
|
|
|
st.addText<ScreenTextType::Big>(
|
|
|
|
ScreenTextEntry::makeBig("TEST_1", T("Test String"), 2, 5000));
|
2016-05-07 19:29:08 +02:00
|
|
|
|
2016-09-09 22:13:22 +02:00
|
|
|
BOOST_CHECK_EQUAL(1, st.getText<ScreenTextType::Big>().size());
|
2016-05-07 19:29:08 +02:00
|
|
|
|
2016-09-09 22:13:22 +02:00
|
|
|
st.clear<ScreenTextType::Big>();
|
2016-05-07 19:29:08 +02:00
|
|
|
|
2016-09-09 22:13:22 +02:00
|
|
|
BOOST_CHECK_EQUAL(0, st.getText<ScreenTextType::Big>().size());
|
2016-05-07 19:29:08 +02:00
|
|
|
}
|
|
|
|
|
2016-09-09 22:13:22 +02:00
|
|
|
BOOST_AUTO_TEST_CASE(format_test) {
|
|
|
|
// Test formating of string codes into strings.
|
|
|
|
const auto codeStr1 = T("Hello ~1~ world");
|
|
|
|
const auto codeStr2 = T("~1~Hello ~1~ world~1~");
|
|
|
|
const auto codeStr3 = T("Hello world~1~");
|
2016-05-07 19:29:08 +02:00
|
|
|
|
2018-08-05 23:19:02 +02:00
|
|
|
auto f1 = ScreenText::format(codeStr1, T("r"));
|
2016-09-09 22:13:22 +02:00
|
|
|
BOOST_CHECK_EQUAL(f1, T("Hello r world"));
|
2016-05-07 19:29:08 +02:00
|
|
|
|
2018-08-05 23:19:02 +02:00
|
|
|
auto f2 = ScreenText::format(codeStr2, T("k"), T("h"));
|
2016-09-09 22:13:22 +02:00
|
|
|
BOOST_CHECK_EQUAL(f2, T("kHello h world~1~"));
|
2016-05-07 19:29:08 +02:00
|
|
|
|
2018-08-05 23:19:02 +02:00
|
|
|
auto f3 = ScreenText::format(codeStr3, T("x"));
|
2016-09-09 22:13:22 +02:00
|
|
|
BOOST_CHECK_EQUAL(f3, T("Hello worldx"));
|
2016-05-07 19:29:08 +02:00
|
|
|
|
2018-08-05 23:19:02 +02:00
|
|
|
auto f4 = ScreenText::format(codeStr3, T("x"), T("k"));
|
2016-09-09 22:13:22 +02:00
|
|
|
BOOST_CHECK_EQUAL(f4, T("Hello worldx"));
|
2016-05-07 19:29:08 +02:00
|
|
|
}
|
|
|
|
|
2016-09-09 22:13:22 +02:00
|
|
|
BOOST_AUTO_TEST_CASE(format_remove) {
|
|
|
|
// Test removing an identified string from the list
|
|
|
|
ScreenText st;
|
|
|
|
|
|
|
|
st.addText<ScreenTextType::Big>(
|
|
|
|
ScreenTextEntry::makeBig("TEST_2", T("Test String"), 2, 5000));
|
|
|
|
|
|
|
|
st.addText<ScreenTextType::Big>(
|
|
|
|
ScreenTextEntry::makeBig("TEST_1", T("Test String"), 2, 5000));
|
|
|
|
|
|
|
|
st.addText<ScreenTextType::Big>(
|
|
|
|
ScreenTextEntry::makeBig("TEST_1", T("Test String"), 2, 5000));
|
|
|
|
|
|
|
|
BOOST_CHECK_EQUAL(3, st.getText<ScreenTextType::Big>().size());
|
|
|
|
|
|
|
|
st.remove<ScreenTextType::Big>("TEST_1");
|
|
|
|
|
|
|
|
BOOST_CHECK_EQUAL(1, st.getText<ScreenTextType::Big>().size());
|
2016-05-07 19:29:08 +02:00
|
|
|
}
|
|
|
|
|
2014-07-28 07:20:39 +02:00
|
|
|
BOOST_AUTO_TEST_SUITE_END()
|