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

Side by Side Diff: base/utf_offset_string_conversions_unittest.cc

Issue 9467017: Password support for NativeTextfieldViews, in the model (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 10 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/string_piece.h" 8 #include "base/string_piece.h"
9 #include "base/utf_offset_string_conversions.h" 9 #include "base/utf_offset_string_conversions.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
11 11
12 namespace base { 12 namespace base {
13 13
14 namespace { 14 namespace {
15 15
16 static const size_t kNpos = string16::npos; 16 static const size_t kNpos = string16::npos;
17 17
18 } // namespace 18 } // namespace
19 19
20 TEST(UTFOffsetStringConversionsTest, IndexOffsetConversions) {
21 // Valid surrogate pair surrounded by unpaired surrogates
22 const char16 foo[] = {0xDC00, 0xD800, 0xD800, 0xDFFF, 0xDFFF, 0xDBFF, 0};
23 const string16 s(foo);
24 const size_t the_invalid_index = 3;
25 for (size_t i = 0; i <= s.length(); ++i)
26 EXPECT_EQ(i != the_invalid_index, IsValidCodePointIndex(s, i));
27 for (size_t i = 0; i <= s.length(); ++i) {
28 for (size_t j = i; j <= s.length(); ++j) {
29 ptrdiff_t offset = static_cast<ptrdiff_t>(j - i);
30 if (i <= the_invalid_index && j > the_invalid_index)
31 --offset;
32 EXPECT_EQ(offset, Utf16IndexToOffset(s, i, j));
33 EXPECT_EQ(-offset, Utf16IndexToOffset(s, j, i));
34 size_t adjusted_j = (j == the_invalid_index) ? j + 1 : j;
35 EXPECT_EQ(adjusted_j, Utf16OffsetToIndex(s, i, offset));
36 size_t adjusted_i = (i == the_invalid_index) ? i + 1 : i;
37 EXPECT_EQ(adjusted_i, Utf16OffsetToIndex(s, j, -offset));
38 }
39 }
40 }
41
20 TEST(UTFOffsetStringConversionsTest, AdjustOffset) { 42 TEST(UTFOffsetStringConversionsTest, AdjustOffset) {
21 struct UTF8ToUTF16Case { 43 struct UTF8ToUTF16Case {
22 const char* utf8; 44 const char* utf8;
23 size_t input_offset; 45 size_t input_offset;
24 size_t output_offset; 46 size_t output_offset;
25 } utf8_to_utf16_cases[] = { 47 } utf8_to_utf16_cases[] = {
26 {"", 0, kNpos}, 48 {"", 0, kNpos},
27 {"\xe4\xbd\xa0\xe5\xa5\xbd", 1, kNpos}, 49 {"\xe4\xbd\xa0\xe5\xa5\xbd", 1, kNpos},
28 {"\xe4\xbd\xa0\xe5\xa5\xbd", 3, 1}, 50 {"\xe4\xbd\xa0\xe5\xa5\xbd", 3, 1},
29 {"\xed\xb0\x80z", 3, 1}, 51 {"\xed\xb0\x80z", 3, 1},
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 offset_adjuster.Add(OffsetAdjuster::Adjustment(15, 2, 0)); 166 offset_adjuster.Add(OffsetAdjuster::Adjustment(15, 2, 0));
145 } 167 }
146 size_t expected_3[] = {kNpos, kNpos, kNpos, 0, 1, kNpos, kNpos, kNpos, 5, 6, 168 size_t expected_3[] = {kNpos, kNpos, kNpos, 0, 1, kNpos, kNpos, kNpos, 5, 6,
147 7, 8, kNpos, kNpos, 11, kNpos, kNpos}; 169 7, 8, kNpos, kNpos, 11, kNpos, kNpos};
148 EXPECT_EQ(offsets.size(), arraysize(expected_3)); 170 EXPECT_EQ(offsets.size(), arraysize(expected_3));
149 for (size_t i = 0; i < arraysize(expected_3); ++i) 171 for (size_t i = 0; i < arraysize(expected_3); ++i)
150 EXPECT_EQ(expected_3[i], offsets[i]); 172 EXPECT_EQ(expected_3[i], offsets[i]);
151 } 173 }
152 } 174 }
153 175
154 } // namaspace base 176 } // namespace base
OLDNEW
« no previous file with comments | « base/utf_offset_string_conversions.cc ('k') | ui/views/controls/textfield/native_textfield_views.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698