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

Side by Side Diff: base/string_util_unittest.cc

Issue 8502027: Fix AutocompleteMatch DCHECK() triggered by |RenderViewContextMenu::AppendSearchProvider()|. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 1 month 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
« no previous file with comments | « base/string_util.cc ('k') | chrome/browser/autocomplete/autocomplete_match.h » ('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 <math.h> 5 #include <math.h>
6 #include <stdarg.h> 6 #include <stdarg.h>
7 7
8 #include <limits> 8 #include <limits>
9 #include <sstream> 9 #include <sstream>
10 10
(...skipping 1048 matching lines...) Expand 10 before | Expand all | Expand 10 after
1059 // No characters match kRemoveChars. 1059 // No characters match kRemoveChars.
1060 EXPECT_FALSE(RemoveChars(input, kRemoveChars, &input)); 1060 EXPECT_FALSE(RemoveChars(input, kRemoveChars, &input));
1061 EXPECT_EQ("Abcd!", input); 1061 EXPECT_EQ("Abcd!", input);
1062 1062
1063 // Empty string. 1063 // Empty string.
1064 input.clear(); 1064 input.clear();
1065 EXPECT_FALSE(RemoveChars(input, kRemoveChars, &input)); 1065 EXPECT_FALSE(RemoveChars(input, kRemoveChars, &input));
1066 EXPECT_EQ(std::string(), input); 1066 EXPECT_EQ(std::string(), input);
1067 } 1067 }
1068 1068
1069 TEST(StringUtilTest, ReplaceChars) {
1070 struct TestData {
1071 const char* input;
1072 const char* replace_chars;
1073 const char* replace_with;
1074 const char* output;
1075 bool result;
1076 } cases[] = {
1077 { "", "", "", "", false },
1078 { "test", "", "", "test", false },
1079 { "test", "", "!", "test", false },
1080 { "test", "z", "!", "test", false },
1081 { "test", "e", "!", "t!st", true },
1082 { "test", "e", "!?", "t!?st", true },
1083 { "test", "ez", "!", "t!st", true },
1084 { "test", "zed", "!?", "t!?st", true },
1085 { "test", "t", "!?", "!?es!?", true },
1086 { "test", "et", "!>", "!>!>s!>", true },
1087 { "test", "zest", "!", "!!!!", true },
1088 { "test", "szt", "!", "!e!!", true },
1089 };
1090
1091 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) {
1092 std::string output;
1093 bool result = ReplaceChars(cases[i].input,
1094 cases[i].replace_chars,
1095 cases[i].replace_with,
1096 &output);
1097 DCHECK_EQ(cases[i].result, result);
Mark Mentovai 2011/11/09 21:08:38 You don’t want DCHECK_EQ, you want EXPECT_EQ. Same
Alexei Svitkine (slow) 2011/11/09 21:13:18 Doh, I knew that. Done.
1098 DCHECK_EQ(cases[i].output, output);
1099 }
1100 }
1101
1069 TEST(StringUtilTest, ContainsOnlyChars) { 1102 TEST(StringUtilTest, ContainsOnlyChars) {
1070 // Providing an empty list of characters should return false but for the empty 1103 // Providing an empty list of characters should return false but for the empty
1071 // string. 1104 // string.
1072 EXPECT_TRUE(ContainsOnlyChars("", "")); 1105 EXPECT_TRUE(ContainsOnlyChars("", ""));
1073 EXPECT_FALSE(ContainsOnlyChars("Hello", "")); 1106 EXPECT_FALSE(ContainsOnlyChars("Hello", ""));
1074 1107
1075 EXPECT_TRUE(ContainsOnlyChars("", "1234")); 1108 EXPECT_TRUE(ContainsOnlyChars("", "1234"));
1076 EXPECT_TRUE(ContainsOnlyChars("1", "1234")); 1109 EXPECT_TRUE(ContainsOnlyChars("1", "1234"));
1077 EXPECT_TRUE(ContainsOnlyChars("1", "4321")); 1110 EXPECT_TRUE(ContainsOnlyChars("1", "4321"));
1078 EXPECT_TRUE(ContainsOnlyChars("123", "4321")); 1111 EXPECT_TRUE(ContainsOnlyChars("123", "4321"));
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
1115 const std::string live = kLive; 1148 const std::string live = kLive;
1116 std::string dead = live; 1149 std::string dead = live;
1117 strncpy(WriteInto(&dead, 5), kDead, 4); 1150 strncpy(WriteInto(&dead, 5), kDead, 4);
1118 EXPECT_STREQ(kDead, dead.c_str()); 1151 EXPECT_STREQ(kDead, dead.c_str());
1119 EXPECT_EQ(4u, dead.size()); 1152 EXPECT_EQ(4u, dead.size());
1120 EXPECT_STREQ(kLive, live.c_str()); 1153 EXPECT_STREQ(kLive, live.c_str());
1121 EXPECT_EQ(4u, live.size()); 1154 EXPECT_EQ(4u, live.size());
1122 } 1155 }
1123 1156
1124 } // namespace base 1157 } // namespace base
OLDNEW
« no previous file with comments | « base/string_util.cc ('k') | chrome/browser/autocomplete/autocomplete_match.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698