#include "font/UnicodeData.h" #include "unittest/TestSuite.h" static void testParseData(void) { const char dataString[] = "0000;;Cc;0;BN;;;;;N;NULL;;;;\n0041;LATIN CAPITAL LETTER A;Lu;0;L;;;;;N;;;;0061;\n"; UnicodeData data = UnicodeData_parse(dataString, sizeof(dataString) - 1); TestCase_assertUIntEqual(data.characterCount, 2); TestCase_assertPointerNonNULL(data.characters); TestCase_assertUIntEqual(data.characters[0].codeValue, 0x0000); TestCase_assertStringEqual(data.characters[0].characterName, ""); TestCase_assertEnumEqual(data.characters[0].generalCategory, UNICODE_GENERAL_CATEGORY_OTHER_CONTROL); TestCase_assertUIntEqual(data.characters[0].combiningClass, 0); TestCase_assertEnumEqual(data.characters[0].bidiClass, UNICODE_BIDI_BN); TestCase_assertEnumEqual(data.characters[0].decomposition.tag, UNICODE_DECOMPOSITION_canonical); TestCase_assertUIntEqual(data.characters[0].decomposition.codepointCount, 0); TestCase_assertPointerNULL(data.characters[0].decomposition.codepoints); TestCase_assertIntEqual(data.characters[0].decimalValue, UNICODE_NUMERIC_VALUE_NONE); TestCase_assertIntEqual(data.characters[0].digitValue, UNICODE_NUMERIC_VALUE_NONE); TestCase_assertIntEqual(data.characters[0].numericValue.numerator, UNICODE_NUMERIC_VALUE_NONE); TestCase_assertUIntEqual(data.characters[0].numericValue.denominator, 0); TestCase_assertBoolFalse(data.characters[0].mirrored); TestCase_assertStringEqual(data.characters[0].unicode1Name, "NULL"); TestCase_assertPointerNULL(data.characters[0].comment); TestCase_assertUIntEqual(data.characters[0].upperCaseMapping, UINT32_MAX); TestCase_assertUIntEqual(data.characters[0].lowerCaseMapping, UINT32_MAX); TestCase_assertUIntEqual(data.characters[0].titleCaseMapping, UINT32_MAX); TestCase_assertUIntEqual(data.characters[1].codeValue, 0x0041); TestCase_assertStringEqual(data.characters[1].characterName, "LATIN CAPITAL LETTER A"); TestCase_assertEnumEqual(data.characters[1].generalCategory, UNICODE_GENERAL_CATEGORY_LETTER_UPPERCASE); TestCase_assertUIntEqual(data.characters[1].combiningClass, 0); TestCase_assertEnumEqual(data.characters[1].bidiClass, UNICODE_BIDI_L); TestCase_assertEnumEqual(data.characters[1].decomposition.tag, UNICODE_DECOMPOSITION_canonical); TestCase_assertUIntEqual(data.characters[1].decomposition.codepointCount, 0); TestCase_assertPointerNULL(data.characters[1].decomposition.codepoints); TestCase_assertIntEqual(data.characters[1].decimalValue, UNICODE_NUMERIC_VALUE_NONE); TestCase_assertIntEqual(data.characters[1].digitValue, UNICODE_NUMERIC_VALUE_NONE); TestCase_assertIntEqual(data.characters[1].numericValue.numerator, UNICODE_NUMERIC_VALUE_NONE); TestCase_assertUIntEqual(data.characters[1].numericValue.denominator, 0); TestCase_assertBoolFalse(data.characters[1].mirrored); TestCase_assertPointerNULL(data.characters[1].unicode1Name); TestCase_assertPointerNULL(data.characters[1].comment); TestCase_assertUIntEqual(data.characters[1].upperCaseMapping, UINT32_MAX); TestCase_assertUIntEqual(data.characters[1].lowerCaseMapping, 0x0061); TestCase_assertUIntEqual(data.characters[1].titleCaseMapping, UINT32_MAX); UnicodeDataCharacter * character = UnicodeData_getCharacter(&data, 0x0000); TestCase_assertPointerEqual(character, &data.characters[0]); character = UnicodeData_getCharacter(&data, 0x0041); TestCase_assertPointerEqual(character, &data.characters[1]); character = UnicodeData_getCharacter(&data, 0x0042); TestCase_assertPointerNULL(character); UnicodeData_dispose(&data); const char dataString2[] = "E123;Test character;Co;100;NSM; 0123 0124;1;2;-3/4;Y;Hello;hi;0040;0041;0042\n"; data = UnicodeData_parse(dataString2, sizeof(dataString2) - 1); TestCase_assertUIntEqual(data.characterCount, 1); TestCase_assertPointerNonNULL(data.characters); TestCase_assertUIntEqual(data.characters[0].codeValue, 0xE123); TestCase_assertStringEqual(data.characters[0].characterName, "Test character"); TestCase_assertEnumEqual(data.characters[0].generalCategory, UNICODE_GENERAL_CATEGORY_OTHER_PRIVATE_USE); TestCase_assertUIntEqual(data.characters[0].combiningClass, 100); TestCase_assertEnumEqual(data.characters[0].bidiClass, UNICODE_BIDI_NSM); TestCase_assertEnumEqual(data.characters[0].decomposition.tag, UNICODE_DECOMPOSITION_circle); TestCase_assertUIntEqual(data.characters[0].decomposition.codepointCount, 2); TestCase_assertPointerNonNULL(data.characters[0].decomposition.codepoints); TestCase_assertUIntEqual(data.characters[0].decomposition.codepoints[0], 0x0123); TestCase_assertUIntEqual(data.characters[0].decomposition.codepoints[1], 0x0124); TestCase_assertIntEqual(data.characters[0].decimalValue, 1); TestCase_assertIntEqual(data.characters[0].digitValue, 2); TestCase_assertIntEqual(data.characters[0].numericValue.numerator, -3); TestCase_assertUIntEqual(data.characters[0].numericValue.denominator, 4); TestCase_assertBoolTrue(data.characters[0].mirrored); TestCase_assertStringEqual(data.characters[0].unicode1Name, "Hello"); TestCase_assertStringEqual(data.characters[0].comment, "hi"); TestCase_assertUIntEqual(data.characters[0].upperCaseMapping, 0x0040); TestCase_assertUIntEqual(data.characters[0].lowerCaseMapping, 0x0041); TestCase_assertUIntEqual(data.characters[0].titleCaseMapping, 0x0042); UnicodeData_dispose(&data); } static void testParseBlockList(void) { const char blockString[] = "# ignored\n0000..007F; Basic Latin\n0080..00FF; Latin-1 Supplement\n"; UnicodeBlockList blockList = UnicodeBlockList_parse(blockString, sizeof(blockString) - 1); TestCase_assertUIntEqual(blockList.blockCount, 2); TestCase_assertPointerNonNULL(blockList.blocks); TestCase_assertUIntEqual(blockList.blocks[0].rangeStart, 0x0000); TestCase_assertUIntEqual(blockList.blocks[0].rangeEnd, 0x007F); TestCase_assertStringEqual(blockList.blocks[0].description, "Basic Latin"); TestCase_assertUIntEqual(blockList.blocks[1].rangeStart, 0x0080); TestCase_assertUIntEqual(blockList.blocks[1].rangeEnd, 0x00FF); TestCase_assertStringEqual(blockList.blocks[1].description, "Latin-1 Supplement"); UnicodeBlock * block = UnicodeBlockList_getBlock(&blockList, 0x0000); TestCase_assertPointerEqual(block, &blockList.blocks[0]); block = UnicodeBlockList_getBlock(&blockList, 0x007F); TestCase_assertPointerEqual(block, &blockList.blocks[0]); block = UnicodeBlockList_getBlock(&blockList, 0x0080); TestCase_assertPointerEqual(block, &blockList.blocks[1]); block = UnicodeBlockList_getBlock(&blockList, 0x00FF); TestCase_assertPointerEqual(block, &blockList.blocks[1]); block = UnicodeBlockList_getBlock(&blockList, 0x0100); TestCase_assertPointerNULL(block); UnicodeBlockList_dispose(&blockList); } TEST_SUITE(UnicodeDataTest, testParseData, testParseBlockList)