blob: 43a8e6cb6a9055a9a0b306e289ec7c8cbe94f816 [file] [log] [blame]
reed@google.com419f4332011-12-21 15:21:32 +00001/*
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.orge4fafb12013-12-12 21:11:12 +00007
reed@google.comdc5f76d2012-03-14 20:05:35 +00008#include "SkPaint.h"
Hal Canaryea60b952018-08-21 11:45:46 -04009#include "SkUTF.h"
tfarina@chromium.org8f6884a2014-01-24 20:56:26 +000010#include "Test.h"
reed@google.com419f4332011-12-21 15:21:32 +000011
reed@google.comdc5f76d2012-03-14 20:05:35 +000012// 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 Canaryf107a2f2018-07-25 16:52:48 -040015DEF_TEST(Unicode_textencodings, reporter) {
reed@google.comdc5f76d2012-03-14 20:05:35 +000016 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.com6f86c3e2012-03-22 21:29:10 +000043 REPORTER_ASSERT(reporter, (int)len8 == count8);
44 REPORTER_ASSERT(reporter, (int)len8 == count16);
45 REPORTER_ASSERT(reporter, (int)len8 == count32);
rmistry@google.comd6176b02012-08-23 18:14:13 +000046
reed@google.comdc5f76d2012-03-14 20:05:35 +000047 REPORTER_ASSERT(reporter, !memcmp(glyphs8, glyphs16, count8 * sizeof(uint16_t)));
48 REPORTER_ASSERT(reporter, !memcmp(glyphs8, glyphs32, count8 * sizeof(uint16_t)));
49}