Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(393)

Side by Side Diff: runtime/vm/unicode_test.cc

Issue 2952193002: VM: Speed up output of UTF8 for 1-byte strings.
Patch Set: Add test that would have caught bug pointed out by Slava Created 3 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « runtime/vm/unicode.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "vm/unicode.h" 5 #include "vm/unicode.h"
6 #include "vm/globals.h" 6 #include "vm/globals.h"
7 #include "vm/unit_test.h" 7 #include "vm/unit_test.h"
8 8
9 namespace dart { 9 namespace dart {
10 10
11 TEST_CASE(Utf8Encode) {
12 const intptr_t kInputLen = 3;
13 const uint16_t kInput[kInputLen] = {0xe6, 0xe7, 0xe8}; // æøå
14 const String& input = String::Handle(String::FromUTF16(kInput, kInputLen));
15 static const uintptr_t kBufferLength = 10;
16 unsigned char buffer[kBufferLength];
17 for (uintptr_t i = 0; i < kBufferLength; i++) {
18 buffer[i] = 42;
19 }
20 Utf8::Encode(input, reinterpret_cast<char*>(&buffer[0]), 10);
21 uintptr_t i;
22 for (i = 0; i < static_cast<uintptr_t>(Utf8::Length(input)); i++) {
23 EXPECT(buffer[i] > 127);
24 }
25 for (; i < kBufferLength; i++) {
26 EXPECT(buffer[i] == 42);
27 }
28 }
29
11 TEST_CASE(Utf8Decode) { 30 TEST_CASE(Utf8Decode) {
12 // Examples from the Unicode specification, chapter 3 31 // Examples from the Unicode specification, chapter 3
13 { 32 {
14 const char* src = "\x41\xC3\xB1\x42"; 33 const char* src = "\x41\xC3\xB1\x42";
15 int32_t expected[] = {0x41, 0xF1, 0x42}; 34 int32_t expected[] = {0x41, 0xF1, 0x42};
16 int32_t dst[ARRAY_SIZE(expected)]; 35 int32_t dst[ARRAY_SIZE(expected)];
17 memset(dst, 0, sizeof(dst)); 36 memset(dst, 0, sizeof(dst));
18 bool is_valid = Utf8::DecodeCStringToUTF32(src, dst, ARRAY_SIZE(dst)); 37 bool is_valid = Utf8::DecodeCStringToUTF32(src, dst, ARRAY_SIZE(dst));
19 EXPECT(is_valid); 38 EXPECT(is_valid);
20 EXPECT(!memcmp(expected, dst, sizeof(expected))); 39 EXPECT(!memcmp(expected, dst, sizeof(expected)));
(...skipping 1010 matching lines...) Expand 10 before | Expand all | Expand 10 after
1031 int32_t expected[] = {0xFFFF}; 1050 int32_t expected[] = {0xFFFF};
1032 int32_t dst[ARRAY_SIZE(expected)]; 1051 int32_t dst[ARRAY_SIZE(expected)];
1033 memset(dst, 0, sizeof(dst)); 1052 memset(dst, 0, sizeof(dst));
1034 bool is_valid = Utf8::DecodeCStringToUTF32(src, dst, ARRAY_SIZE(dst)); 1053 bool is_valid = Utf8::DecodeCStringToUTF32(src, dst, ARRAY_SIZE(dst));
1035 EXPECT(is_valid); 1054 EXPECT(is_valid);
1036 EXPECT(!memcmp(expected, dst, sizeof(expected))); 1055 EXPECT(!memcmp(expected, dst, sizeof(expected)));
1037 } 1056 }
1038 } 1057 }
1039 1058
1040 } // namespace dart 1059 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/unicode.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698