HelloAurora/Tests/Public/8. Hello Locale/Main.cpp
2023-07-28 17:31:59 +01:00

91 lines
2.7 KiB
C++

/***
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);
}
TEST(TranslateEncoding, utf16streamingillegal)
{
static const unsigned char rawData[]
{
0x3D, 0xD8, 0x02, 0xDC
};
auto readWrittenPair = Aurora::Locale::Encoding::DecodeUTF8(Aurora::Memory::MemoryViewRead(rawData, 2), {}, Aurora::Locale::ECodePage::eUTF16);
ASSERT_EQ(readWrittenPair.second, 0);
ASSERT_EQ(readWrittenPair.first, 0);
}
void RunTests()
{
Aurora::RuntimeStartInfo info;
info.console.fio.bEnableLogging = false;
Aurora::RuntimeStart(info);
PrintLocale();
}