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

Side by Side Diff: base/strings/utf_offset_string_conversions_unittest.cc

Issue 656033009: Convert ARRAYSIZE_UNSAFE -> arraysize in base/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 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 | « base/strings/string_util_unittest.cc ('k') | base/strings/utf_string_conversions_unittest.cc » ('j') | 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 Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <algorithm> 5 #include <algorithm>
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/strings/string_piece.h" 8 #include "base/strings/string_piece.h"
9 #include "base/strings/utf_offset_string_conversions.h" 9 #include "base/strings/utf_offset_string_conversions.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 16 matching lines...) Expand all
27 {"", kNpos, kNpos}, 27 {"", kNpos, kNpos},
28 {"\xe4\xbd\xa0\xe5\xa5\xbd", 1, kNpos}, 28 {"\xe4\xbd\xa0\xe5\xa5\xbd", 1, kNpos},
29 {"\xe4\xbd\xa0\xe5\xa5\xbd", 3, 1}, 29 {"\xe4\xbd\xa0\xe5\xa5\xbd", 3, 1},
30 {"\xed\xb0\x80z", 3, 1}, 30 {"\xed\xb0\x80z", 3, 1},
31 {"A\xF0\x90\x8C\x80z", 1, 1}, 31 {"A\xF0\x90\x8C\x80z", 1, 1},
32 {"A\xF0\x90\x8C\x80z", 2, kNpos}, 32 {"A\xF0\x90\x8C\x80z", 2, kNpos},
33 {"A\xF0\x90\x8C\x80z", 5, 3}, 33 {"A\xF0\x90\x8C\x80z", 5, 3},
34 {"A\xF0\x90\x8C\x80z", 6, 4}, 34 {"A\xF0\x90\x8C\x80z", 6, 4},
35 {"A\xF0\x90\x8C\x80z", kNpos, kNpos}, 35 {"A\xF0\x90\x8C\x80z", kNpos, kNpos},
36 }; 36 };
37 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(utf8_to_utf16_cases); ++i) { 37 for (size_t i = 0; i < arraysize(utf8_to_utf16_cases); ++i) {
38 const size_t offset = utf8_to_utf16_cases[i].input_offset; 38 const size_t offset = utf8_to_utf16_cases[i].input_offset;
39 std::vector<size_t> offsets; 39 std::vector<size_t> offsets;
40 offsets.push_back(offset); 40 offsets.push_back(offset);
41 UTF8ToUTF16AndAdjustOffsets(utf8_to_utf16_cases[i].utf8, &offsets); 41 UTF8ToUTF16AndAdjustOffsets(utf8_to_utf16_cases[i].utf8, &offsets);
42 EXPECT_EQ(utf8_to_utf16_cases[i].output_offset, offsets[0]); 42 EXPECT_EQ(utf8_to_utf16_cases[i].output_offset, offsets[0]);
43 } 43 }
44 44
45 struct UTF16ToUTF8Case { 45 struct UTF16ToUTF8Case {
46 char16 utf16[10]; 46 char16 utf16[10];
47 size_t input_offset; 47 size_t input_offset;
48 size_t output_offset; 48 size_t output_offset;
49 } utf16_to_utf8_cases[] = { 49 } utf16_to_utf8_cases[] = {
50 {{}, 0, 0}, 50 {{}, 0, 0},
51 // Converted to 3-byte utf-8 sequences 51 // Converted to 3-byte utf-8 sequences
52 {{0x5909, 0x63DB}, 3, kNpos}, 52 {{0x5909, 0x63DB}, 3, kNpos},
53 {{0x5909, 0x63DB}, 2, 6}, 53 {{0x5909, 0x63DB}, 2, 6},
54 {{0x5909, 0x63DB}, 1, 3}, 54 {{0x5909, 0x63DB}, 1, 3},
55 {{0x5909, 0x63DB}, 0, 0}, 55 {{0x5909, 0x63DB}, 0, 0},
56 // Converted to 2-byte utf-8 sequences 56 // Converted to 2-byte utf-8 sequences
57 {{'A', 0x00bc, 0x00be, 'z'}, 1, 1}, 57 {{'A', 0x00bc, 0x00be, 'z'}, 1, 1},
58 {{'A', 0x00bc, 0x00be, 'z'}, 2, 3}, 58 {{'A', 0x00bc, 0x00be, 'z'}, 2, 3},
59 {{'A', 0x00bc, 0x00be, 'z'}, 3, 5}, 59 {{'A', 0x00bc, 0x00be, 'z'}, 3, 5},
60 {{'A', 0x00bc, 0x00be, 'z'}, 4, 6}, 60 {{'A', 0x00bc, 0x00be, 'z'}, 4, 6},
61 // Surrogate pair 61 // Surrogate pair
62 {{'A', 0xd800, 0xdf00, 'z'}, 1, 1}, 62 {{'A', 0xd800, 0xdf00, 'z'}, 1, 1},
63 {{'A', 0xd800, 0xdf00, 'z'}, 2, kNpos}, 63 {{'A', 0xd800, 0xdf00, 'z'}, 2, kNpos},
64 {{'A', 0xd800, 0xdf00, 'z'}, 3, 5}, 64 {{'A', 0xd800, 0xdf00, 'z'}, 3, 5},
65 {{'A', 0xd800, 0xdf00, 'z'}, 4, 6}, 65 {{'A', 0xd800, 0xdf00, 'z'}, 4, 6},
66 }; 66 };
67 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(utf16_to_utf8_cases); ++i) { 67 for (size_t i = 0; i < arraysize(utf16_to_utf8_cases); ++i) {
68 size_t offset = utf16_to_utf8_cases[i].input_offset; 68 size_t offset = utf16_to_utf8_cases[i].input_offset;
69 std::vector<size_t> offsets; 69 std::vector<size_t> offsets;
70 offsets.push_back(offset); 70 offsets.push_back(offset);
71 UTF16ToUTF8AndAdjustOffsets(utf16_to_utf8_cases[i].utf16, &offsets); 71 UTF16ToUTF8AndAdjustOffsets(utf16_to_utf8_cases[i].utf16, &offsets);
72 EXPECT_EQ(utf16_to_utf8_cases[i].output_offset, offsets[0]) << i; 72 EXPECT_EQ(utf16_to_utf8_cases[i].output_offset, offsets[0]) << i;
73 } 73 }
74 } 74 }
75 75
76 TEST(UTFOffsetStringConversionsTest, LimitOffsets) { 76 TEST(UTFOffsetStringConversionsTest, LimitOffsets) {
77 const size_t kLimit = 10; 77 const size_t kLimit = 10;
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 EXPECT_EQ(1u, adjustments_on_adjusted_string[3].output_length); 287 EXPECT_EQ(1u, adjustments_on_adjusted_string[3].output_length);
288 EXPECT_EQ(19u, adjustments_on_adjusted_string[4].original_offset); 288 EXPECT_EQ(19u, adjustments_on_adjusted_string[4].original_offset);
289 EXPECT_EQ(3u, adjustments_on_adjusted_string[4].original_length); 289 EXPECT_EQ(3u, adjustments_on_adjusted_string[4].original_length);
290 EXPECT_EQ(0u, adjustments_on_adjusted_string[4].output_length); 290 EXPECT_EQ(0u, adjustments_on_adjusted_string[4].output_length);
291 EXPECT_EQ(25u, adjustments_on_adjusted_string[5].original_offset); 291 EXPECT_EQ(25u, adjustments_on_adjusted_string[5].original_offset);
292 EXPECT_EQ(1u, adjustments_on_adjusted_string[5].original_length); 292 EXPECT_EQ(1u, adjustments_on_adjusted_string[5].original_length);
293 EXPECT_EQ(2u, adjustments_on_adjusted_string[5].output_length); 293 EXPECT_EQ(2u, adjustments_on_adjusted_string[5].output_length);
294 } 294 }
295 295
296 } // namaspace base 296 } // namaspace base
OLDNEW
« no previous file with comments | « base/strings/string_util_unittest.cc ('k') | base/strings/utf_string_conversions_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698