diff options
author | reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2012-03-14 20:05:35 +0000 |
---|---|---|
committer | reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2012-03-14 20:05:35 +0000 |
commit | dc5f76d806dd9299630ba2d05447e49f34be034d (patch) | |
tree | 8bac7866a3f4868d79c6a4326e9e5c06221b28c2 /tests | |
parent | e5d7078747cb5e31aa6b3ca199ebfc7f15e5c730 (diff) |
unittest for kUTF32_TextEncoding
git-svn-id: http://skia.googlecode.com/svn/trunk@3390 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'tests')
-rw-r--r-- | tests/UnicodeTest.cpp | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/tests/UnicodeTest.cpp b/tests/UnicodeTest.cpp index 602ff81431..04fee49608 100644 --- a/tests/UnicodeTest.cpp +++ b/tests/UnicodeTest.cpp @@ -6,6 +6,7 @@ * found in the LICENSE file. */ #include "Test.h" +#include "SkPaint.h" #include "SkUtils.h" // Unicode Variation Selector ranges: inclusive @@ -37,8 +38,48 @@ static void test_uvs(skiatest::Reporter* reporter) { } } +// Simple test to ensure that when we call textToGlyphs, we get the same +// result (for the same text) when using UTF8, UTF16, UTF32. +// TODO: make the text more complex (i.e. incorporate chars>7bits) +static void test_textencodings(skiatest::Reporter* reporter) { + const char text8[] = "ABCDEFGabcdefg0123456789"; + uint16_t text16[sizeof(text8)]; + int32_t text32[sizeof(text8)]; + size_t len8 = strlen(text8); + size_t len16 = len8 * 2; + size_t len32 = len8 * 4; + + // expand our 8bit chars to 16 and 32 + for (size_t i = 0; i < len8; ++i) { + text32[i] = text16[i] = text8[i]; + } + + uint16_t glyphs8[sizeof(text8)]; + uint16_t glyphs16[sizeof(text8)]; + uint16_t glyphs32[sizeof(text8)]; + + SkPaint paint; + + paint.setTextEncoding(SkPaint::kUTF8_TextEncoding); + int count8 = paint.textToGlyphs(text8, len8, glyphs8); + + paint.setTextEncoding(SkPaint::kUTF16_TextEncoding); + int count16 = paint.textToGlyphs(text16, len16, glyphs16); + + paint.setTextEncoding(SkPaint::kUTF32_TextEncoding); + int count32 = paint.textToGlyphs(text32, len32, glyphs32); + + REPORTER_ASSERT(reporter, len8 == count8); + REPORTER_ASSERT(reporter, len8 == count16); + REPORTER_ASSERT(reporter, len8 == count32); + + REPORTER_ASSERT(reporter, !memcmp(glyphs8, glyphs16, count8 * sizeof(uint16_t))); + REPORTER_ASSERT(reporter, !memcmp(glyphs8, glyphs32, count8 * sizeof(uint16_t))); +} + static void TestUnicode(skiatest::Reporter* reporter) { test_uvs(reporter); + test_textencodings(reporter); } #include "TestClassDef.h" |