reed@google.com | 419f433 | 2011-12-21 15:21:32 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2011 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
tfarina@chromium.org | e4fafb1 | 2013-12-12 21:11:12 +0000 | [diff] [blame] | 7 | |
reed@google.com | dc5f76d | 2012-03-14 20:05:35 +0000 | [diff] [blame] | 8 | #include "SkPaint.h" |
Hal Canary | ea60b95 | 2018-08-21 11:45:46 -0400 | [diff] [blame] | 9 | #include "SkUTF.h" |
tfarina@chromium.org | 8f6884a | 2014-01-24 20:56:26 +0000 | [diff] [blame] | 10 | #include "Test.h" |
reed@google.com | 419f433 | 2011-12-21 15:21:32 +0000 | [diff] [blame] | 11 | |
reed@google.com | dc5f76d | 2012-03-14 20:05:35 +0000 | [diff] [blame] | 12 | // Simple test to ensure that when we call textToGlyphs, we get the same |
| 13 | // result (for the same text) when using UTF8, UTF16, UTF32. |
| 14 | // TODO: make the text more complex (i.e. incorporate chars>7bits) |
Hal Canary | f107a2f | 2018-07-25 16:52:48 -0400 | [diff] [blame] | 15 | DEF_TEST(Unicode_textencodings, reporter) { |
reed@google.com | dc5f76d | 2012-03-14 20:05:35 +0000 | [diff] [blame] | 16 | const char text8[] = "ABCDEFGabcdefg0123456789"; |
| 17 | uint16_t text16[sizeof(text8)]; |
| 18 | int32_t text32[sizeof(text8)]; |
| 19 | size_t len8 = strlen(text8); |
| 20 | size_t len16 = len8 * 2; |
| 21 | size_t len32 = len8 * 4; |
| 22 | |
| 23 | // expand our 8bit chars to 16 and 32 |
| 24 | for (size_t i = 0; i < len8; ++i) { |
| 25 | text32[i] = text16[i] = text8[i]; |
| 26 | } |
| 27 | |
| 28 | uint16_t glyphs8[sizeof(text8)]; |
| 29 | uint16_t glyphs16[sizeof(text8)]; |
| 30 | uint16_t glyphs32[sizeof(text8)]; |
| 31 | |
| 32 | SkPaint paint; |
| 33 | |
| 34 | paint.setTextEncoding(SkPaint::kUTF8_TextEncoding); |
| 35 | int count8 = paint.textToGlyphs(text8, len8, glyphs8); |
| 36 | |
| 37 | paint.setTextEncoding(SkPaint::kUTF16_TextEncoding); |
| 38 | int count16 = paint.textToGlyphs(text16, len16, glyphs16); |
| 39 | |
| 40 | paint.setTextEncoding(SkPaint::kUTF32_TextEncoding); |
| 41 | int count32 = paint.textToGlyphs(text32, len32, glyphs32); |
| 42 | |
bsalomon@google.com | 6f86c3e | 2012-03-22 21:29:10 +0000 | [diff] [blame] | 43 | REPORTER_ASSERT(reporter, (int)len8 == count8); |
| 44 | REPORTER_ASSERT(reporter, (int)len8 == count16); |
| 45 | REPORTER_ASSERT(reporter, (int)len8 == count32); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 46 | |
reed@google.com | dc5f76d | 2012-03-14 20:05:35 +0000 | [diff] [blame] | 47 | REPORTER_ASSERT(reporter, !memcmp(glyphs8, glyphs16, count8 * sizeof(uint16_t))); |
| 48 | REPORTER_ASSERT(reporter, !memcmp(glyphs8, glyphs32, count8 * sizeof(uint16_t))); |
| 49 | } |