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

Unified Diff: mojo/public/cpp/bindings/tests/string_unittest.cc

Issue 2006823002: Mojo C++ bindings: move support for mojo::String. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 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
« no previous file with comments | « mojo/public/cpp/bindings/string.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/public/cpp/bindings/tests/string_unittest.cc
diff --git a/mojo/public/cpp/bindings/tests/string_unittest.cc b/mojo/public/cpp/bindings/tests/string_unittest.cc
index 6f251dd38f59db8b4b531934ccb16f4c8fd867fd..13486ae948971cde7dc228e67be305349e7ba661 100644
--- a/mojo/public/cpp/bindings/tests/string_unittest.cc
+++ b/mojo/public/cpp/bindings/tests/string_unittest.cc
@@ -8,6 +8,10 @@
namespace mojo {
namespace test {
+namespace {
+const char* kHelloWorld = "hello world";
+} // namespace
+
TEST(StringTest, DefaultIsNotNull) {
String s;
EXPECT_FALSE(s.is_null());
@@ -38,28 +42,28 @@ TEST(StringTest, Empty) {
}
TEST(StringTest, Basic) {
- String s("hello world");
- EXPECT_EQ(std::string("hello world"), s.get());
+ String s(kHelloWorld);
+ EXPECT_EQ(std::string(kHelloWorld), s.get());
}
TEST(StringTest, Assignment) {
- String s("hello world");
+ String s(kHelloWorld);
String t = s; // Makes a copy.
EXPECT_FALSE(t.is_null());
- EXPECT_EQ(std::string("hello world"), t.get());
+ EXPECT_EQ(std::string(kHelloWorld), t.get());
EXPECT_FALSE(s.is_null());
}
TEST(StringTest, Equality) {
- String s("hello world");
- String t("hello world");
+ String s(kHelloWorld);
+ String t(kHelloWorld);
EXPECT_EQ(s, t);
EXPECT_TRUE(s == s);
EXPECT_FALSE(s != s);
EXPECT_TRUE(s == t);
EXPECT_FALSE(s != t);
- EXPECT_TRUE("hello world" == s);
- EXPECT_TRUE(s == "hello world");
+ EXPECT_TRUE(kHelloWorld == s);
+ EXPECT_TRUE(s == kHelloWorld);
EXPECT_TRUE("not" != s);
EXPECT_FALSE("not" == s);
EXPECT_TRUE(s != "not");
@@ -89,5 +93,39 @@ TEST(StringTest, LessThanNullness) {
EXPECT_FALSE(real < null);
}
+TEST(StringTest, MoveConstructors) {
+ std::string std_str(kHelloWorld);
+
+ String str1(std::move(std_str));
+ EXPECT_TRUE(kHelloWorld == str1);
+
+ String str2(std::move(str1));
+ EXPECT_TRUE(kHelloWorld == str2);
+ EXPECT_TRUE(str1.is_null());
+}
+
+TEST(StringTest, MoveAssignments) {
+ std::string std_str(kHelloWorld);
+
+ String str1;
+ str1 = std::move(std_str);
+ EXPECT_TRUE(kHelloWorld == str1);
+
+ String str2;
+ str2 = std::move(str1);
+ EXPECT_TRUE(kHelloWorld == str2);
+ EXPECT_TRUE(str1.is_null());
+}
+
+TEST(StringTest, Storage) {
+ String str(kHelloWorld);
+
+ EXPECT_TRUE(kHelloWorld == str.storage());
+
+ std::string storage = str.PassStorage();
+ EXPECT_TRUE(str.is_null());
+ EXPECT_TRUE(kHelloWorld == storage);
+}
+
} // namespace test
} // namespace mojo
« no previous file with comments | « mojo/public/cpp/bindings/string.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698