Files
OpenRCT2-Unity/test/tests/LanguagePackTest.cpp

76 lines
2.9 KiB
C++
Raw Permalink Normal View History

/*****************************************************************************
* Copyright (c) 2014-2024 OpenRCT2 developers
*
* For a complete list of all authors, please refer to contributors.md
* Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2
*
* OpenRCT2 is licensed under the GNU General Public License version 3.
*****************************************************************************/
2016-12-28 13:39:21 +01:00
#include "openrct2/localisation/LanguagePack.h"
2018-06-22 22:29:03 +02:00
2018-09-29 23:06:26 +02:00
#include "openrct2/localisation/Language.h"
2018-01-06 18:32:25 +01:00
#include "openrct2/localisation/StringIds.h"
2018-06-22 22:29:03 +02:00
2016-11-30 11:51:55 +01:00
#include <gtest/gtest.h>
using namespace OpenRCT2;
class LanguagePackTest : public testing::Test
{
protected:
2018-06-22 22:29:03 +02:00
static const utf8* LanguageEnGB;
static const utf8* LanguageZhTW;
};
TEST_F(LanguagePackTest, create_empty)
2016-11-30 11:51:55 +01:00
{
auto empty = LanguagePackFactory::FromText(0, "");
2016-11-30 11:51:55 +01:00
ASSERT_EQ(empty->GetId(), 0);
2022-10-17 19:21:18 +02:00
ASSERT_EQ(empty->GetCount(), 0u);
2016-11-30 11:51:55 +01:00
}
TEST_F(LanguagePackTest, create_mutable_id_1)
2016-11-30 11:51:55 +01:00
{
auto lang = LanguagePackFactory::FromText(1, "STR_0000:\n");
2016-11-30 11:51:55 +01:00
ASSERT_EQ(lang->GetId(), 1);
2022-10-17 19:21:18 +02:00
ASSERT_EQ(lang->GetCount(), 1u);
ASSERT_STREQ(lang->GetString(0), nullptr);
2016-11-30 11:51:55 +01:00
lang->SetString(0, "xx");
2022-10-17 19:21:18 +02:00
ASSERT_EQ(lang->GetCount(), 1u);
2016-11-30 11:51:55 +01:00
ASSERT_STREQ(lang->GetString(0), "xx");
}
TEST_F(LanguagePackTest, language_pack_simple)
2016-11-30 11:51:55 +01:00
{
auto lang = LanguagePackFactory::FromText(0, LanguageEnGB);
2016-11-30 11:51:55 +01:00
ASSERT_EQ(lang->GetId(), 0);
2022-10-17 19:21:18 +02:00
ASSERT_EQ(lang->GetCount(), 4u);
2016-11-30 11:51:55 +01:00
ASSERT_STREQ(lang->GetString(2), "Spiral Roller Coaster");
// Test some negatives too
ASSERT_EQ(lang->GetString(1000), nullptr);
2016-11-30 11:51:55 +01:00
}
TEST_F(LanguagePackTest, language_pack_multibyte)
2016-12-01 23:21:35 +01:00
{
auto lang = LanguagePackFactory::FromText(0, LanguageZhTW);
2016-12-01 23:21:35 +01:00
ASSERT_EQ(lang->GetId(), 0);
2022-10-17 19:21:18 +02:00
ASSERT_EQ(lang->GetCount(), 4u);
2016-12-01 23:21:35 +01:00
ASSERT_STREQ(lang->GetString(2), u8"懸吊式雲霄飛車");
}
2018-06-22 22:29:03 +02:00
const utf8* LanguagePackTest::LanguageEnGB = "# STR_XXXX part is read and XXXX becomes the string id number.\n"
"# Everything after the colon and before the new line will be saved as the "
"string.\n"
"# Use # at the beginning of a line to leave a comment.\n"
"STR_0000 :\n"
"STR_0001 :{STRINGID} {COMMA16}\n"
"STR_0002 :Spiral Roller Coaster\n"
"STR_0003 :Stand-up Roller Coaster\n";
2016-12-01 23:21:35 +01:00
// This includes a few entries extracted from zh-TW localisation.
const utf8* LanguagePackTest::LanguageZhTW = u8"STR_0000 :螺旋式雲霄飛車\n"
u8"STR_0001 :站立式雲霄飛車\n"
u8"STR_0002 :懸吊式雲霄飛車\n"
u8"STR_0003 :反轉式雲霄飛車\n";