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

Unified Diff: webrtc/base/optional_unittest.cc

Issue 2432393002: Add rtc::Optional equality/unequality comparisions with object (Closed)
Patch Set: Feedback Created 4 years, 2 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 | « webrtc/base/optional.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webrtc/base/optional_unittest.cc
diff --git a/webrtc/base/optional_unittest.cc b/webrtc/base/optional_unittest.cc
index 492db4bb081ac603dc5523c884403b88b63a86b5..c1ae9c00d42fc4bc626595f7c8245e6801137585 100644
--- a/webrtc/base/optional_unittest.cc
+++ b/webrtc/base/optional_unittest.cc
@@ -656,6 +656,54 @@ TEST(OptionalTest, TestEquality) {
*log);
}
+TEST(OptionalTest, TestEqualityWithObject) {
+ auto log = Logger::Setup();
+ {
+ Logger a(17), b(42);
+ Optional<Logger> ma(a), me;
+ // Using operator== and operator!= explicetly instead of EXPECT_EQ/EXPECT_NE
+ // macros because those operators are under test.
+ log->push_back("---");
+
+ EXPECT_TRUE(ma == a);
+ EXPECT_TRUE(a == ma);
+ EXPECT_FALSE(ma == b);
+ EXPECT_FALSE(b == ma);
+ EXPECT_FALSE(me == a);
+ EXPECT_FALSE(a == me);
+
+ EXPECT_FALSE(ma != a);
+ EXPECT_FALSE(a != ma);
+ EXPECT_TRUE(ma != b);
+ EXPECT_TRUE(b != ma);
+ EXPECT_TRUE(me != a);
+ EXPECT_TRUE(a != me);
+
+ log->push_back("---");
+ }
+ // clang-format off
+ EXPECT_EQ(V("0:17. explicit constructor",
+ "1:42. explicit constructor",
+ "2:17. copy constructor (from 0:17)",
+ "---",
+ "operator== 2:17, 0:17",
+ "operator== 0:17, 2:17",
+ "operator== 2:17, 1:42",
+ "operator== 1:42, 2:17",
+ // No operator should be called when comparing to empty.
+ "operator!= 2:17, 0:17",
+ "operator!= 0:17, 2:17",
+ "operator!= 2:17, 1:42",
+ "operator!= 1:42, 2:17",
+ // No operator should be called when comparing to empty.
+ "---",
+ "2:17. destructor",
+ "1:42. destructor",
+ "0:17. destructor"),
+ *log);
+ // clang-format on
+}
+
TEST(OptionalTest, TestSwap) {
auto log = Logger::Setup();
{
« no previous file with comments | « webrtc/base/optional.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698