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

Unified Diff: base/stl_util_unittest.cc

Issue 862133002: Update from https://crrev.com/312398 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 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 side-by-side diff with in-line comments
Download patch
Index: base/stl_util_unittest.cc
diff --git a/base/stl_util_unittest.cc b/base/stl_util_unittest.cc
index a3f8e16f2ce2c0a5411d1491254245c80d89ab3d..06ea7cd08f01e03c3a3b6aca8651f6182a328b8f 100644
--- a/base/stl_util_unittest.cc
+++ b/base/stl_util_unittest.cc
@@ -238,5 +238,30 @@ TEST(STLUtilTest, STLIncludes) {
EXPECT_TRUE(STLIncludes<std::set<int> >(a3, a2));
}
+TEST(StringAsArrayTest, Empty) {
+ std::string empty;
+ EXPECT_EQ(nullptr, string_as_array(&empty));
+}
+
+TEST(StringAsArrayTest, NullTerminated) {
+ // If any std::string implementation is not null-terminated, this should
+ // fail. All compilers we use return a null-terminated buffer, but please do
+ // not rely on this fact in your code.
+ std::string str("abcde");
+ str.resize(3);
+ EXPECT_STREQ("abc", string_as_array(&str));
+}
+
+TEST(StringAsArrayTest, WriteCopy) {
+ // With a COW implementation, this test will fail if
+ // string_as_array(&str) is implemented as
+ // const_cast<char*>(str->data()).
+ std::string s1("abc");
+ const std::string s2(s1);
+ string_as_array(&s1)[1] = 'x';
+ EXPECT_EQ("axc", s1);
+ EXPECT_EQ("abc", s2);
+}
+
} // namespace
} // namespace base
« no previous file with comments | « base/process/process_win.cc ('k') | base/test/gtest_util.h » ('j') | shell/BUILD.gn » ('J')

Powered by Google App Engine
This is Rietveld 408576698