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

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

Issue 1224553010: Replace base::str[n]casecmp with helper functions. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 5 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_posix.h ('k') | base/strings/string_util_win.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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/strings/string_util.h" 5 #include "base/strings/string_util.h"
6 6
7 #include <math.h> 7 #include <math.h>
8 #include <stdarg.h> 8 #include <stdarg.h>
9 9
10 #include <algorithm> 10 #include <algorithm>
(...skipping 1038 matching lines...) Expand 10 before | Expand all | Expand 10 after
1049 1049
1050 EXPECT_TRUE(ContainsOnlyChars(string16(), kWhitespaceUTF16)); 1050 EXPECT_TRUE(ContainsOnlyChars(string16(), kWhitespaceUTF16));
1051 EXPECT_TRUE(ContainsOnlyChars(ASCIIToUTF16(" "), kWhitespaceUTF16)); 1051 EXPECT_TRUE(ContainsOnlyChars(ASCIIToUTF16(" "), kWhitespaceUTF16));
1052 EXPECT_TRUE(ContainsOnlyChars(ASCIIToUTF16("\t"), kWhitespaceUTF16)); 1052 EXPECT_TRUE(ContainsOnlyChars(ASCIIToUTF16("\t"), kWhitespaceUTF16));
1053 EXPECT_TRUE(ContainsOnlyChars(ASCIIToUTF16("\t \r \n "), kWhitespaceUTF16)); 1053 EXPECT_TRUE(ContainsOnlyChars(ASCIIToUTF16("\t \r \n "), kWhitespaceUTF16));
1054 EXPECT_FALSE(ContainsOnlyChars(ASCIIToUTF16("a"), kWhitespaceUTF16)); 1054 EXPECT_FALSE(ContainsOnlyChars(ASCIIToUTF16("a"), kWhitespaceUTF16));
1055 EXPECT_FALSE(ContainsOnlyChars(ASCIIToUTF16("\thello\r \n "), 1055 EXPECT_FALSE(ContainsOnlyChars(ASCIIToUTF16("\thello\r \n "),
1056 kWhitespaceUTF16)); 1056 kWhitespaceUTF16));
1057 } 1057 }
1058 1058
1059 TEST(StringUtilTest, CompareCaseInsensitiveASCII) {
1060 EXPECT_EQ(0, CompareCaseInsensitiveASCII("", ""));
1061 EXPECT_EQ(0, CompareCaseInsensitiveASCII("Asdf", "aSDf"));
1062
1063 // Differing lengths.
1064 EXPECT_EQ(-1, CompareCaseInsensitiveASCII("Asdf", "aSDfA"));
1065 EXPECT_EQ(1, CompareCaseInsensitiveASCII("AsdfA", "aSDf"));
1066
1067 // Differing values.
1068 EXPECT_EQ(-1, CompareCaseInsensitiveASCII("AsdfA", "aSDfb"));
1069 EXPECT_EQ(1, CompareCaseInsensitiveASCII("Asdfb", "aSDfA"));
1070 }
1071
1072 TEST(StringUtilTest, EqualsCaseInsensitiveASCII) {
1073 EXPECT_TRUE(EqualsCaseInsensitiveASCII("", ""));
1074 EXPECT_TRUE(EqualsCaseInsensitiveASCII("Asdf", "aSDF"));
1075 EXPECT_FALSE(EqualsCaseInsensitiveASCII("bsdf", "aSDF"));
1076 EXPECT_FALSE(EqualsCaseInsensitiveASCII("Asdf", "aSDFz"));
1077 }
1078
1059 class WriteIntoTest : public testing::Test { 1079 class WriteIntoTest : public testing::Test {
1060 protected: 1080 protected:
1061 static void WritesCorrectly(size_t num_chars) { 1081 static void WritesCorrectly(size_t num_chars) {
1062 std::string buffer; 1082 std::string buffer;
1063 char kOriginal[] = "supercali"; 1083 char kOriginal[] = "supercali";
1064 strncpy(WriteInto(&buffer, num_chars + 1), kOriginal, num_chars); 1084 strncpy(WriteInto(&buffer, num_chars + 1), kOriginal, num_chars);
1065 // Using std::string(buffer.c_str()) instead of |buffer| truncates the 1085 // Using std::string(buffer.c_str()) instead of |buffer| truncates the
1066 // string at the first \0. 1086 // string at the first \0.
1067 EXPECT_EQ(std::string(kOriginal, 1087 EXPECT_EQ(std::string(kOriginal,
1068 std::min(num_chars, arraysize(kOriginal) - 1)), 1088 std::min(num_chars, arraysize(kOriginal) - 1)),
(...skipping 16 matching lines...) Expand all
1085 const std::string live = kLive; 1105 const std::string live = kLive;
1086 std::string dead = live; 1106 std::string dead = live;
1087 strncpy(WriteInto(&dead, 5), kDead, 4); 1107 strncpy(WriteInto(&dead, 5), kDead, 4);
1088 EXPECT_EQ(kDead, dead); 1108 EXPECT_EQ(kDead, dead);
1089 EXPECT_EQ(4u, dead.size()); 1109 EXPECT_EQ(4u, dead.size());
1090 EXPECT_EQ(kLive, live); 1110 EXPECT_EQ(kLive, live);
1091 EXPECT_EQ(4u, live.size()); 1111 EXPECT_EQ(4u, live.size());
1092 } 1112 }
1093 1113
1094 } // namespace base 1114 } // namespace base
OLDNEW
« no previous file with comments | « base/strings/string_util_posix.h ('k') | base/strings/string_util_win.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698