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

Side by Side Diff: base/i18n/char_iterator_unittest.cc

Issue 6355005: base/i18n: Add namespace i18n to CharIterator. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: brett review Created 9 years, 11 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) 2010 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 "base/i18n/char_iterator.h" 5 #include "base/i18n/char_iterator.h"
6 6
7 #include "base/utf_string_conversions.h" 7 #include "base/utf_string_conversions.h"
8 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
9 9
10 namespace base {
11 namespace i18n {
12
10 TEST(CharIteratorsTest, TestUTF8) { 13 TEST(CharIteratorsTest, TestUTF8) {
11 std::string empty(""); 14 std::string empty("");
12 base::UTF8CharIterator empty_iter(&empty); 15 UTF8CharIterator empty_iter(&empty);
13 ASSERT_TRUE(empty_iter.end()); 16 ASSERT_TRUE(empty_iter.end());
14 ASSERT_EQ(0, empty_iter.array_pos()); 17 ASSERT_EQ(0, empty_iter.array_pos());
15 ASSERT_EQ(0, empty_iter.char_pos()); 18 ASSERT_EQ(0, empty_iter.char_pos());
16 ASSERT_FALSE(empty_iter.Advance()); 19 ASSERT_FALSE(empty_iter.Advance());
17 20
18 std::string str("s\303\273r"); // [u with circumflex] 21 std::string str("s\303\273r"); // [u with circumflex]
19 base::UTF8CharIterator iter(&str); 22 UTF8CharIterator iter(&str);
20 ASSERT_FALSE(iter.end()); 23 ASSERT_FALSE(iter.end());
21 ASSERT_EQ(0, iter.array_pos()); 24 ASSERT_EQ(0, iter.array_pos());
22 ASSERT_EQ(0, iter.char_pos()); 25 ASSERT_EQ(0, iter.char_pos());
23 ASSERT_EQ('s', iter.get()); 26 ASSERT_EQ('s', iter.get());
24 ASSERT_TRUE(iter.Advance()); 27 ASSERT_TRUE(iter.Advance());
25 28
26 ASSERT_FALSE(iter.end()); 29 ASSERT_FALSE(iter.end());
27 ASSERT_EQ(1, iter.array_pos()); 30 ASSERT_EQ(1, iter.array_pos());
28 ASSERT_EQ(1, iter.char_pos()); 31 ASSERT_EQ(1, iter.char_pos());
29 ASSERT_EQ(251, iter.get()); 32 ASSERT_EQ(251, iter.get());
(...skipping 10 matching lines...) Expand all
40 ASSERT_EQ(3, iter.char_pos()); 43 ASSERT_EQ(3, iter.char_pos());
41 44
42 // Don't care what it returns, but this shouldn't crash 45 // Don't care what it returns, but this shouldn't crash
43 iter.get(); 46 iter.get();
44 47
45 ASSERT_FALSE(iter.Advance()); 48 ASSERT_FALSE(iter.Advance());
46 } 49 }
47 50
48 TEST(CharIteratorsTest, TestUTF16) { 51 TEST(CharIteratorsTest, TestUTF16) {
49 string16 empty = UTF8ToUTF16(""); 52 string16 empty = UTF8ToUTF16("");
50 base::UTF16CharIterator empty_iter(&empty); 53 UTF16CharIterator empty_iter(&empty);
51 ASSERT_TRUE(empty_iter.end()); 54 ASSERT_TRUE(empty_iter.end());
52 ASSERT_EQ(0, empty_iter.array_pos()); 55 ASSERT_EQ(0, empty_iter.array_pos());
53 ASSERT_EQ(0, empty_iter.char_pos()); 56 ASSERT_EQ(0, empty_iter.char_pos());
54 ASSERT_FALSE(empty_iter.Advance()); 57 ASSERT_FALSE(empty_iter.Advance());
55 58
56 // This test string contains 4 characters: 59 // This test string contains 4 characters:
57 // x 60 // x
58 // u with circumflex - 2 bytes in UTF8, 1 codeword in UTF16 61 // u with circumflex - 2 bytes in UTF8, 1 codeword in UTF16
59 // math double-struck A - 4 bytes in UTF8, 2 codewords in UTF16 62 // math double-struck A - 4 bytes in UTF8, 2 codewords in UTF16
60 // z 63 // z
61 string16 str = UTF8ToUTF16("x\303\273\360\235\224\270z"); 64 string16 str = UTF8ToUTF16("x\303\273\360\235\224\270z");
62 base::UTF16CharIterator iter(&str); 65 UTF16CharIterator iter(&str);
63 ASSERT_FALSE(iter.end()); 66 ASSERT_FALSE(iter.end());
64 ASSERT_EQ(0, iter.array_pos()); 67 ASSERT_EQ(0, iter.array_pos());
65 ASSERT_EQ(0, iter.char_pos()); 68 ASSERT_EQ(0, iter.char_pos());
66 ASSERT_EQ('x', iter.get()); 69 ASSERT_EQ('x', iter.get());
67 ASSERT_TRUE(iter.Advance()); 70 ASSERT_TRUE(iter.Advance());
68 71
69 ASSERT_FALSE(iter.end()); 72 ASSERT_FALSE(iter.end());
70 ASSERT_EQ(1, iter.array_pos()); 73 ASSERT_EQ(1, iter.array_pos());
71 ASSERT_EQ(1, iter.char_pos()); 74 ASSERT_EQ(1, iter.char_pos());
72 ASSERT_EQ(251, iter.get()); 75 ASSERT_EQ(251, iter.get());
(...skipping 13 matching lines...) Expand all
86 89
87 ASSERT_TRUE(iter.end()); 90 ASSERT_TRUE(iter.end());
88 ASSERT_EQ(5, iter.array_pos()); 91 ASSERT_EQ(5, iter.array_pos());
89 ASSERT_EQ(4, iter.char_pos()); 92 ASSERT_EQ(4, iter.char_pos());
90 93
91 // Don't care what it returns, but this shouldn't crash 94 // Don't care what it returns, but this shouldn't crash
92 iter.get(); 95 iter.get();
93 96
94 ASSERT_FALSE(iter.Advance()); 97 ASSERT_FALSE(iter.Advance());
95 } 98 }
99
100 } // namespace i18n
101 } // namespace base
OLDNEW
« no previous file with comments | « base/i18n/char_iterator.cc ('k') | chrome/browser/chromeos/login/wizard_accessibility_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698