nwnss: extend Unicode table audit coverage

This commit is contained in:
OpenAI
2026-06-17 18:26:17 +00:00
committed by Mario Fetka
parent bb1eb80475
commit 2591f2bde1
2 changed files with 93 additions and 5 deletions

View File

@@ -17,14 +17,72 @@ extern STATUS LB_GetMacCodePageName(BYTE *nameBuffer, NINT bufferLen);
} \
} while (0)
static int check_raw_codepage_table(void)
{
char cp437_bytes[] = { (char)0x80, (char)0x82, 0 };
unicode_t cp437_unicode[] = { 0x00c7, 0x00e9, 0 };
unicode_t unicode[8];
char bytes[8];
NINT actual = -1;
CHECK(LB_ByteToUnicode(NSS_UNI_CONVERSION_RAW, unicode,
(NINT)(sizeof(unicode) / sizeof(unicode[0])),
cp437_bytes, &actual) == zOK);
CHECK(actual == 2);
CHECK(unicode[0] == 0x00c7);
CHECK(unicode[1] == 0x00e9);
CHECK(unicode[2] == 0);
CHECK(LB_UnicodeToByte(NSS_UNI_CONVERSION_RAW, bytes, sizeof(bytes),
cp437_unicode, &actual) == zOK);
CHECK(actual == 2);
CHECK((unsigned char)bytes[0] == 0x80);
CHECK((unsigned char)bytes[1] == 0x82);
CHECK(bytes[2] == 0);
return 0;
}
static int check_mac_roman_table(void)
{
char mac_bytes[] = { (char)0x80, (char)0x8e, 0 };
unicode_t mac_unicode[] = { 0x00c4, 0x00e9, 0 };
unicode_t unicode[8];
char bytes[8];
NINT actual = -1;
CHECK(LB_MacByteToUnicode(NSS_UNI_CONVERSION_RAW, unicode,
(NINT)(sizeof(unicode) / sizeof(unicode[0])),
mac_bytes, &actual) == zOK);
CHECK(actual == 2);
CHECK(unicode[0] == 0x00c4);
CHECK(unicode[1] == 0x00e9);
CHECK(unicode[2] == 0);
CHECK(LB_UnicodeToMacByte(NSS_UNI_CONVERSION_RAW, bytes, sizeof(bytes),
mac_unicode, &actual) == zOK);
CHECK(actual == 2);
CHECK((unsigned char)bytes[0] == 0x80);
CHECK((unsigned char)bytes[1] == 0x8e);
CHECK(bytes[2] == 0);
return 0;
}
static int check_mac_codepage_name(void)
{
BYTE mac_name[64];
BYTE short_name[4];
CHECK(LB_GetMacCodePageName(short_name, sizeof(short_name)) == zERR_BUFFER_TOO_SMALL);
CHECK(LB_GetMacCodePageName(mac_name, sizeof(mac_name)) == zOK);
CHECK(strcmp((const char *)mac_name, "Roman") == 0);
return 0;
}
int main(void)
{
unicode_t unicode[32];
char bytes[32];
NINT actual = -1;
BYTE mac_name[64];
(void)mac_name;
CHECK(LB_UnicodeStartup() == zOK);
@@ -56,8 +114,9 @@ int main(void)
CHECK(bytes[0] == 'O');
CHECK(bytes[1] == 'K');
CHECK(LB_GetMacCodePageName(mac_name, sizeof(mac_name)) == zOK);
CHECK(strcmp((const char *)mac_name, "Roman") == 0);
CHECK(check_raw_codepage_table() == 0);
CHECK(check_mac_roman_table() == 0);
CHECK(check_mac_codepage_name() == 0);
LB_UnicodeShutdown();
CHECK(LB_UnicodeStartup() == zOK);

View File

@@ -65,6 +65,10 @@ static int check_unicode_case_helpers(void)
CHECK(LB_GetNssUnicodeVersion() == 1);
CHECK(LB_unitolower('A') == 'a');
CHECK(LB_unitoupper('z') == 'Z');
CHECK(LB_unitolower(0x00c4) == 0x00e4);
CHECK(LB_unitoupper(0x00e4) == 0x00c4);
CHECK(LB_unitolower(0x03a9) == 0x03c9);
CHECK(LB_unitoupper(0x03c9) == 0x03a9);
CHECK(LB_unilwr(mixed) == mixed);
CHECK(LB_unicmp(mixed, (const unicode_t[]){ 'm', 'a', 'r', 's', '-', 'n', 'w', 'e', 0 }) == 0);
@@ -86,6 +90,30 @@ static int check_unicode_case_helpers(void)
return 0;
}
static int check_unicode_table_conversions(void)
{
char cp437_bytes[] = { (char)0x80, (char)0x82, 0 };
unicode_t cp437_unicode[] = { 0x00c7, 0x00e9, 0 };
unicode_t unicode[8];
char bytes[8];
NINT actual = -1;
CHECK(LB_ByteToUnicode(NSS_UNI_CONVERSION_RAW, unicode, 8,
cp437_bytes, &actual) == zOK);
CHECK(actual == 2);
CHECK(unicode[0] == cp437_unicode[0]);
CHECK(unicode[1] == cp437_unicode[1]);
CHECK(unicode[2] == 0);
CHECK(LB_UnicodeToByte(NSS_UNI_CONVERSION_RAW, bytes, sizeof(bytes),
cp437_unicode, &actual) == zOK);
CHECK(actual == 2);
CHECK((unsigned char)bytes[0] == 0x80);
CHECK((unsigned char)bytes[1] == 0x82);
CHECK(bytes[2] == 0);
return 0;
}
static int check_unicode_parse_overrides(void)
{
unicode_t out = 0;
@@ -186,6 +214,7 @@ int main(void)
CHECK(LB_UnicodeStartup() == zOK);
CHECK(check_unicode_string_helpers() == 0);
CHECK(check_unicode_case_helpers() == 0);
CHECK(check_unicode_table_conversions() == 0);
CHECK(check_unicode_parse_overrides() == 0);
CHECK(check_unicode_converter_registration() == 0);
LB_UnicodeShutdown();