[+] Add initial locale tests

This commit is contained in:
Reece Wilson 2022-02-21 14:17:46 +00:00
parent 0b8362a90d
commit 2ca710f145
2 changed files with 81 additions and 1 deletions

@ -1 +1 @@
Subproject commit 9e26996463b70f00bcdfa7e8439a8012c237683c
Subproject commit ef04d2bac3e2644d86ae707c877381aa55e05781

View File

@ -0,0 +1,80 @@
/***
Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: Main.cpp
Date: 2022-2-18
Author: Reece
***/
#include <AuroraRuntime.hpp>
#include <gtest/gtest.h>
static void PrintLocale()
{
auto locale = AuLocale::GetLocale();
AuLogInfo("Localization information...");
AuLogInfo("language: {}, country : {}, codeset : {})", locale.language, locale.country, locale.codeset);
}
TEST(TranslateEncoding, utf16to8)
{
AuString outUTF8;
static const unsigned char rawData[]
{
0x3D, 0xD8, 0x02, 0xDC
};
auto readWrittenPair = AuLocale::Encoding::DecodeUTF8(AuMemory::MemoryViewRead(rawData), outUTF8, AuLocale::ECodePage::eUTF16);
ASSERT_EQ(readWrittenPair.second, 4);
ASSERT_EQ(readWrittenPair.first, 4);
static const unsigned char rawDataUtf8[]
{
0xF0, 0x9F, 0x90, 0x82
};
ASSERT_EQ(outUTF8, AuString(rawDataUtf8, rawDataUtf8 + AuArraySize(rawDataUtf8)));
}
TEST(TranslateEncoding, jptoutf8)
{
static const unsigned char rawData[14] = {
0x82, 0xB1, 0x82, 0xF1, 0x82, 0xC9, 0x82, 0xBF, 0x82, 0xCD, 0x90, 0xA2,
0x8A, 0x45
};
auto readWrittenPair = AuLocale::Encoding::DecodeUTF8(AuMemory::MemoryViewRead(rawData), {}, AuLocale::ECodePage::eSJIS);
ASSERT_EQ(readWrittenPair.second, 0x15);
static const unsigned char referenceUtf8[21]
{
0xE3, 0x81, 0x93, 0xE3, 0x82, 0x93, 0xE3, 0x81, 0xAB, 0xE3, 0x81, 0xA1,
0xE3, 0x81, 0xAF, 0xE4, 0xB8, 0x96, 0xE7, 0x95, 0x8C
};
unsigned char decodedUtf8[21] = {};
AuLocale::Encoding::DecodeUTF8(AuMemory::MemoryViewRead(rawData), AuMemory::MemoryViewWrite(decodedUtf8), AuLocale::ECodePage::eSJIS);
ASSERT_EQ(AuString(decodedUtf8, decodedUtf8 + AuArraySize(decodedUtf8)), AuString(referenceUtf8, referenceUtf8 + AuArraySize(referenceUtf8)));
}
TEST(TranslateEncoding, jpstreamingbuffered)
{
static const unsigned char rawData[]
{
0x82, 0xB1, 0x82, 0xF1, 0x82, 0xC9, 0x82, 0xBF, 0x82, 0xCD, 0x90, 0xA2,
0x8A
};
auto readWrittenPair = AuLocale::Encoding::DecodeUTF8(AuMemory::MemoryViewRead(rawData), {}, AuLocale::ECodePage::eSJIS);
ASSERT_EQ(readWrittenPair.second, 0x12);
ASSERT_EQ(readWrittenPair.first, 0xc);
}
void RunTests()
{
Aurora::RuntimeStartInfo info;
info.console.fio.enableLogging = false;
info.console.forceToolKitWindow = false;
Aurora::RuntimeStart(info);
PrintLocale();
}