X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=blobdiff_plain;f=automated-tests%2Fsrc%2Fdali-toolkit-internal%2Futc-Dali-Text-CharacterSetConversion.cpp;h=3175baf90de3becdbef561e3bed58f100929a927;hp=9f816ef9ca8aef9a7b05af2f62be7069a99fb852;hb=21f60153d688233c47b7e86dfe1d6e06450ed3a0;hpb=63618525421c207278841dc1d866047169412866 diff --git a/automated-tests/src/dali-toolkit-internal/utc-Dali-Text-CharacterSetConversion.cpp b/automated-tests/src/dali-toolkit-internal/utc-Dali-Text-CharacterSetConversion.cpp old mode 100644 new mode 100755 index 9f816ef..3175baf --- a/automated-tests/src/dali-toolkit-internal/utc-Dali-Text-CharacterSetConversion.cpp +++ b/automated-tests/src/dali-toolkit-internal/utc-Dali-Text-CharacterSetConversion.cpp @@ -30,6 +30,7 @@ using namespace Text; // Tests the following functions for scripts with different number of bytes per character. // Latin 1 byte per character, Arabic 2 bytes per character, Devanagari 3 bytes per character and emojis 4 bytes per character. // +// uint8_t GetUtf8Length( uint8_t utf8LeadByte ); // uint32_t GetNumberOfUtf8Characters( const uint8_t* const utf8, uint32_t length ); // uint32_t GetNumberOfUtf8Bytes( const uint32_t* const utf32, uint32_t numberOfCharacters ); // uint32_t Utf8ToUtf32( const uint8_t* const utf8, uint32_t length, uint32_t* utf32 ); @@ -122,6 +123,67 @@ bool Utf32ToUtf8Test( const Utf32ToUtf8Data& data ) ////////////////////////////////////////////////////////// +int UtcDaliTextCharacterSetConversionGetUtf8Length(void) +{ + ToolkitTestApplication application; + tet_infoline(" UtcDaliTextCharacterSetConversionGetUtf8Length"); + + // Copy of the table used to get the size in bytes of a character encoded with utf8. + // If the table used by the GetUtf8Length() function is updated, this one needs to be updated as well. + const static uint8_t U1 = 1u; + const static uint8_t U2 = 2u; + const static uint8_t U3 = 3u; + const static uint8_t U4 = 4u; + const static uint8_t U0 = 0u; + const static uint8_t UTF8_LENGTH[256] = { + U1, U1, U1, U1, U1, U1, U1, U1, U1, U1, // + U1, U1, U1, U1, U1, U1, U1, U1, U1, U1, // + U1, U1, U1, U1, U1, U1, U1, U1, U1, U1, // + U1, U1, U1, U1, U1, U1, U1, U1, U1, U1, // + U1, U1, U1, U1, U1, U1, U1, U1, U1, U1, // + U1, U1, U1, U1, U1, U1, U1, U1, U1, U1, // + U1, U1, U1, U1, U1, U1, U1, U1, U1, U1, // + U1, U1, U1, U1, U1, U1, U1, U1, U1, U1, // + U1, U1, U1, U1, U1, U1, U1, U1, U1, U1, // lead byte = 0xxx xxxx (U+0000 - U+007F + some extended ascii characters) + U1, U1, U1, U1, U1, U1, U1, U1, U1, U1, // + U1, U1, U1, U1, U1, U1, U1, U1, U1, U1, // + U1, U1, U1, U1, U1, U1, U1, U1, U1, U1, // + U1, U1, U1, U1, U1, U1, U1, U1, U1, U1, // + U1, U1, U1, U1, U1, U1, U1, U1, U1, U1, // + U1, U1, U1, U1, U1, U1, U1, U1, U1, U1, // + U1, U1, U1, U1, U1, U1, U1, U1, U1, U1, // + U1, U1, U1, U1, U1, U1, U1, U1, U1, U1, // + U1, U1, U1, U1, U1, U1, U1, U1, U1, U1, // + U1, U1, U1, U1, U1, U1, U1, U1, U1, U1, // + U1, U1, // + + U2, U2, U2, U2, U2, U2, U2, U2, U2, U2, // + U2, U2, U2, U2, U2, U2, U2, U2, U2, U2, // lead byte = 110x xxxx (U+0080 - U+07FF) + U2, U2, U2, U2, U2, U2, U2, U2, U2, U2, // + U2, U2, // + + U3, U3, U3, U3, U3, U3, U3, U3, U3, U3, // lead byte = 1110 xxxx (U+0800 - U+FFFF) + U3, U3, U3, U3, U3, U3, // + + U4, U4, U4, U4, U4, U4, U4, U4, // lead byte = 1111 0xxx (U+10000 - U+1FFFFF) + + U0, U0, U0, U0, // Non valid. + U0, U0, U0, U0, // Non valid. + }; + + for( unsigned int index = 0; index < 256u; ++index ) + { + if( GetUtf8Length( index ) != UTF8_LENGTH[static_cast(index)] ) + { + tet_result(TET_FAIL); + } + } + + tet_result(TET_PASS); + END_TEST; +} + + int UtcDaliTextCharacterSetConversionGetNumberOfUtf8Characters(void) { ToolkitTestApplication application; @@ -220,10 +282,14 @@ int UtcDaliTextCharacterSetConversionUtf8ToUtf32(void) ToolkitTestApplication application; tet_infoline(" UtcDaliTextCharacterSetConversionGetNumberOfUtf8Bytes"); + char utf8_06[] = { -8, -7, -6, -5, -4, -3, -2, -1 }; // Invalid string + unsigned int utf32_01[] = { 0x48, 0x65, 0x6C, 0x6C, 0x6F, 0x20, 0x57, 0x6F, 0x72, 0x6C, 0x64 }; // Hello World - unsigned int utf32_02[] = { 0x645, 0x631, 0x62D, 0x628, 0x627, 0x20, 0x628, 0x627, 0x644, 0x639, 0x627, 0x644, 0x645 }; // مرحبا بالعالم - unsigned int utf32_03[] = { 0x939, 0x948, 0x932, 0x94B, 0x20, 0x935, 0x930, 0x94D, 0x932, 0x94D, 0x921 }; // हैलो वर्ल्ड - unsigned int utf32_04[] = { 0x1F601, 0x20, 0x1F602, 0x20, 0x1F603, 0x20, 0x1F604 }; // Emojis + unsigned int utf32_02[] = { 0xA, 0x20, 0x48, 0x65, 0x6C, 0x6C, 0x6F, 0xA, 0x20, 0x57, 0x6F, 0x72, 0x6C, 0x64 }; // Hello World + CR and CR+LF + unsigned int utf32_03[] = { 0x645, 0x631, 0x62D, 0x628, 0x627, 0x20, 0x628, 0x627, 0x644, 0x639, 0x627, 0x644, 0x645 }; // مرحبا بالعالم + unsigned int utf32_04[] = { 0x939, 0x948, 0x932, 0x94B, 0x20, 0x935, 0x930, 0x94D, 0x932, 0x94D, 0x921 }; // हैलो वर्ल्ड + unsigned int utf32_05[] = { 0x1F601, 0x20, 0x1F602, 0x20, 0x1F603, 0x20, 0x1F604 }; // Emojis + unsigned int utf32_06[] = { 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20 }; // Invalid string const Utf8ToUtf32Data data[] = { @@ -233,22 +299,32 @@ int UtcDaliTextCharacterSetConversionUtf8ToUtf32(void) utf32_01, }, { + "Latin script with 'CR' and 'CR'+'LF'", + "\xd Hello\xd\xa World", + utf32_02, + }, + { "Arabic script", "مرحبا بالعالم", - utf32_02, + utf32_03, }, { "Devanagari script", "हैलो वर्ल्ड", - utf32_03, + utf32_04, }, { "Emojis", "\xF0\x9F\x98\x81 \xF0\x9F\x98\x82 \xF0\x9F\x98\x83 \xF0\x9F\x98\x84", - utf32_04, + utf32_05, + }, + { + "Invalid text", + utf8_06, + utf32_06, }, }; - const unsigned int numberOfTests = 4u; + const unsigned int numberOfTests = 6u; for( unsigned int index = 0u; index < numberOfTests; ++index ) {