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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « mojo/public/cpp/bindings/string.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "mojo/public/cpp/bindings/string.h" 5 #include "mojo/public/cpp/bindings/string.h"
6 #include "testing/gtest/include/gtest/gtest.h" 6 #include "testing/gtest/include/gtest/gtest.h"
7 7
8 namespace mojo { 8 namespace mojo {
9 namespace test { 9 namespace test {
10 10
11 namespace {
12 const char* kHelloWorld = "hello world";
13 } // namespace
14
11 TEST(StringTest, DefaultIsNotNull) { 15 TEST(StringTest, DefaultIsNotNull) {
12 String s; 16 String s;
13 EXPECT_FALSE(s.is_null()); 17 EXPECT_FALSE(s.is_null());
14 } 18 }
15 19
16 TEST(StringTest, ConstructedWithNULL) { 20 TEST(StringTest, ConstructedWithNULL) {
17 String s(nullptr); 21 String s(nullptr);
18 EXPECT_TRUE(s.is_null()); 22 EXPECT_TRUE(s.is_null());
19 } 23 }
20 24
(...skipping 10 matching lines...) Expand all
31 EXPECT_TRUE(s.is_null()); 35 EXPECT_TRUE(s.is_null());
32 } 36 }
33 37
34 TEST(StringTest, Empty) { 38 TEST(StringTest, Empty) {
35 String s(""); 39 String s("");
36 EXPECT_FALSE(s.is_null()); 40 EXPECT_FALSE(s.is_null());
37 EXPECT_TRUE(s.get().empty()); 41 EXPECT_TRUE(s.get().empty());
38 } 42 }
39 43
40 TEST(StringTest, Basic) { 44 TEST(StringTest, Basic) {
41 String s("hello world"); 45 String s(kHelloWorld);
42 EXPECT_EQ(std::string("hello world"), s.get()); 46 EXPECT_EQ(std::string(kHelloWorld), s.get());
43 } 47 }
44 48
45 TEST(StringTest, Assignment) { 49 TEST(StringTest, Assignment) {
46 String s("hello world"); 50 String s(kHelloWorld);
47 String t = s; // Makes a copy. 51 String t = s; // Makes a copy.
48 EXPECT_FALSE(t.is_null()); 52 EXPECT_FALSE(t.is_null());
49 EXPECT_EQ(std::string("hello world"), t.get()); 53 EXPECT_EQ(std::string(kHelloWorld), t.get());
50 EXPECT_FALSE(s.is_null()); 54 EXPECT_FALSE(s.is_null());
51 } 55 }
52 56
53 TEST(StringTest, Equality) { 57 TEST(StringTest, Equality) {
54 String s("hello world"); 58 String s(kHelloWorld);
55 String t("hello world"); 59 String t(kHelloWorld);
56 EXPECT_EQ(s, t); 60 EXPECT_EQ(s, t);
57 EXPECT_TRUE(s == s); 61 EXPECT_TRUE(s == s);
58 EXPECT_FALSE(s != s); 62 EXPECT_FALSE(s != s);
59 EXPECT_TRUE(s == t); 63 EXPECT_TRUE(s == t);
60 EXPECT_FALSE(s != t); 64 EXPECT_FALSE(s != t);
61 EXPECT_TRUE("hello world" == s); 65 EXPECT_TRUE(kHelloWorld == s);
62 EXPECT_TRUE(s == "hello world"); 66 EXPECT_TRUE(s == kHelloWorld);
63 EXPECT_TRUE("not" != s); 67 EXPECT_TRUE("not" != s);
64 EXPECT_FALSE("not" == s); 68 EXPECT_FALSE("not" == s);
65 EXPECT_TRUE(s != "not"); 69 EXPECT_TRUE(s != "not");
66 EXPECT_FALSE(s == "not"); 70 EXPECT_FALSE(s == "not");
67 71
68 // Test null strings. 72 // Test null strings.
69 String n1; 73 String n1;
70 String n2; 74 String n2;
71 EXPECT_TRUE(n1 == n1); 75 EXPECT_TRUE(n1 == n1);
72 EXPECT_FALSE(n1 != n2); 76 EXPECT_FALSE(n1 != n2);
73 EXPECT_TRUE(n1 == n2); 77 EXPECT_TRUE(n1 == n2);
74 EXPECT_FALSE(n1 != n2); 78 EXPECT_FALSE(n1 != n2);
75 EXPECT_TRUE(n1 != s); 79 EXPECT_TRUE(n1 != s);
76 EXPECT_FALSE(n1 == s); 80 EXPECT_FALSE(n1 == s);
77 EXPECT_TRUE(s != n1); 81 EXPECT_TRUE(s != n1);
78 EXPECT_FALSE(s == n1); 82 EXPECT_FALSE(s == n1);
79 } 83 }
80 84
81 TEST(StringTest, LessThanNullness) { 85 TEST(StringTest, LessThanNullness) {
82 String null; 86 String null;
83 String null2; 87 String null2;
84 EXPECT_FALSE(null < null2); 88 EXPECT_FALSE(null < null2);
85 EXPECT_FALSE(null2 < null); 89 EXPECT_FALSE(null2 < null);
86 90
87 String real("real"); 91 String real("real");
88 EXPECT_TRUE(null < real); 92 EXPECT_TRUE(null < real);
89 EXPECT_FALSE(real < null); 93 EXPECT_FALSE(real < null);
90 } 94 }
91 95
96 TEST(StringTest, MoveConstructors) {
97 std::string std_str(kHelloWorld);
98
99 String str1(std::move(std_str));
100 EXPECT_TRUE(kHelloWorld == str1);
101
102 String str2(std::move(str1));
103 EXPECT_TRUE(kHelloWorld == str2);
104 EXPECT_TRUE(str1.is_null());
105 }
106
107 TEST(StringTest, MoveAssignments) {
108 std::string std_str(kHelloWorld);
109
110 String str1;
111 str1 = std::move(std_str);
112 EXPECT_TRUE(kHelloWorld == str1);
113
114 String str2;
115 str2 = std::move(str1);
116 EXPECT_TRUE(kHelloWorld == str2);
117 EXPECT_TRUE(str1.is_null());
118 }
119
120 TEST(StringTest, Storage) {
121 String str(kHelloWorld);
122
123 EXPECT_TRUE(kHelloWorld == str.storage());
124
125 std::string storage = str.PassStorage();
126 EXPECT_TRUE(str.is_null());
127 EXPECT_TRUE(kHelloWorld == storage);
128 }
129
92 } // namespace test 130 } // namespace test
93 } // namespace mojo 131 } // namespace mojo
OLDNEW
« 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