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

Unified Diff: webrtc/base/optional_unittest.cc

Issue 1896833004: rtc::Optional<T>: Don't secretly contain a default-constructed T when empty (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: rebase 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 | « 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 af82b9232c402da2d48105774e4c88c11a06419c..b51701f6b26b6355f636919a2fc0dad8e5306fdf 100644
--- a/webrtc/base/optional_unittest.cc
+++ b/webrtc/base/optional_unittest.cc
@@ -125,7 +125,7 @@ TEST(OptionalTest, TestConstructDefault) {
Optional<Logger> x;
EXPECT_FALSE(x);
}
- EXPECT_EQ(V("0:0. default constructor", "0:0. destructor"), *log);
+ EXPECT_EQ(V(), *log);
}
TEST(OptionalTest, TestConstructCopyEmpty) {
@@ -136,9 +136,7 @@ TEST(OptionalTest, TestConstructCopyEmpty) {
auto y = x;
EXPECT_FALSE(y);
}
- EXPECT_EQ(V("0:0. default constructor", "1:0. copy constructor (from 0:0)",
- "1:0. destructor", "0:0. destructor"),
- *log);
+ EXPECT_EQ(V(), *log);
}
TEST(OptionalTest, TestConstructCopyFull) {
@@ -166,9 +164,7 @@ TEST(OptionalTest, TestConstructMoveEmpty) {
auto y = std::move(x);
EXPECT_FALSE(y);
}
- EXPECT_EQ(V("0:0. default constructor", "1:0. move constructor (from 0:0)",
- "1:0. destructor", "0:0. destructor"),
- *log);
+ EXPECT_EQ(V(), *log);
}
TEST(OptionalTest, TestConstructMoveFull) {
@@ -195,10 +191,7 @@ TEST(OptionalTest, TestCopyAssignToEmptyFromEmpty) {
Optional<Logger> x, y;
x = y;
}
- EXPECT_EQ(
- V("0:0. default constructor", "1:1. default constructor",
- "0:1. operator= copy (from 1:1)", "1:1. destructor", "0:1. destructor"),
- *log);
+ EXPECT_EQ(V(), *log);
}
TEST(OptionalTest, TestCopyAssignToFullFromEmpty) {
@@ -212,9 +205,7 @@ TEST(OptionalTest, TestCopyAssignToFullFromEmpty) {
}
EXPECT_EQ(
V("0:17. explicit constructor", "1:17. move constructor (from 0:17)",
- "0:17. destructor", "2:2. default constructor", "---",
- "1:2. operator= copy (from 2:2)", "---", "2:2. destructor",
- "1:2. destructor"),
+ "0:17. destructor", "---", "1:17. destructor", "---"),
*log);
}
@@ -227,11 +218,11 @@ TEST(OptionalTest, TestCopyAssignToEmptyFromFull) {
x = y;
log->push_back("---");
}
- EXPECT_EQ(V("0:0. default constructor", "1:17. explicit constructor",
- "2:17. move constructor (from 1:17)", "1:17. destructor", "---",
- "0:17. operator= copy (from 2:17)", "---", "2:17. destructor",
- "0:17. destructor"),
- *log);
+ EXPECT_EQ(
+ V("0:17. explicit constructor", "1:17. move constructor (from 0:17)",
+ "0:17. destructor", "---", "2:17. copy constructor (from 1:17)", "---",
+ "1:17. destructor", "2:17. destructor"),
+ *log);
}
TEST(OptionalTest, TestCopyAssignToFullFromFull) {
@@ -261,10 +252,10 @@ TEST(OptionalTest, TestCopyAssignToEmptyFromT) {
x = Optional<Logger>(y);
log->push_back("---");
}
- EXPECT_EQ(V("0:0. default constructor", "1:17. explicit constructor", "---",
- "2:17. copy constructor (from 1:17)",
- "0:17. operator= move (from 2:17)", "2:17. destructor", "---",
- "1:17. destructor", "0:17. destructor"),
+ EXPECT_EQ(V("0:17. explicit constructor", "---",
+ "1:17. copy constructor (from 0:17)",
+ "2:17. move constructor (from 1:17)", "1:17. destructor", "---",
+ "0:17. destructor", "2:17. destructor"),
*log);
}
@@ -292,10 +283,7 @@ TEST(OptionalTest, TestMoveAssignToEmptyFromEmpty) {
Optional<Logger> x, y;
x = std::move(y);
}
- EXPECT_EQ(
- V("0:0. default constructor", "1:1. default constructor",
- "0:1. operator= move (from 1:1)", "1:1. destructor", "0:1. destructor"),
- *log);
+ EXPECT_EQ(V(), *log);
}
TEST(OptionalTest, TestMoveAssignToFullFromEmpty) {
@@ -309,9 +297,7 @@ TEST(OptionalTest, TestMoveAssignToFullFromEmpty) {
}
EXPECT_EQ(
V("0:17. explicit constructor", "1:17. move constructor (from 0:17)",
- "0:17. destructor", "2:2. default constructor", "---",
- "1:2. operator= move (from 2:2)", "---", "2:2. destructor",
- "1:2. destructor"),
+ "0:17. destructor", "---", "1:17. destructor", "---"),
*log);
}
@@ -324,11 +310,11 @@ TEST(OptionalTest, TestMoveAssignToEmptyFromFull) {
x = std::move(y);
log->push_back("---");
}
- EXPECT_EQ(V("0:0. default constructor", "1:17. explicit constructor",
- "2:17. move constructor (from 1:17)", "1:17. destructor", "---",
- "0:17. operator= move (from 2:17)", "---", "2:17. destructor",
- "0:17. destructor"),
- *log);
+ EXPECT_EQ(
+ V("0:17. explicit constructor", "1:17. move constructor (from 0:17)",
+ "0:17. destructor", "---", "2:17. move constructor (from 1:17)", "---",
+ "1:17. destructor", "2:17. destructor"),
+ *log);
}
TEST(OptionalTest, TestMoveAssignToFullFromFull) {
@@ -358,10 +344,10 @@ TEST(OptionalTest, TestMoveAssignToEmptyFromT) {
x = Optional<Logger>(std::move(y));
log->push_back("---");
}
- EXPECT_EQ(V("0:0. default constructor", "1:17. explicit constructor", "---",
- "2:17. move constructor (from 1:17)",
- "0:17. operator= move (from 2:17)", "2:17. destructor", "---",
- "1:17. destructor", "0:17. destructor"),
+ EXPECT_EQ(V("0:17. explicit constructor", "---",
+ "1:17. move constructor (from 0:17)",
+ "2:17. move constructor (from 1:17)", "1:17. destructor", "---",
+ "0:17. destructor", "2:17. destructor"),
*log);
}
@@ -426,14 +412,13 @@ TEST(OptionalTest, TestDereferenceWithDefault) {
}
EXPECT_EQ(
V("0:17. explicit constructor", "1:42. explicit constructor",
- "2:17. copy constructor (from 0:17)", "3:3. default constructor", "-1-",
- "4:42. explicit constructor", "operator== 0:17, 2:17",
- "4:42. destructor", "-2-", "5:42. explicit constructor",
- "operator== 1:42, 5:42", "5:42. destructor", "-3-",
- "6:17. explicit constructor", "7:17. move constructor (from 6:17)",
- "operator== 0:17, 7:17", "7:17. destructor", "6:17. destructor", "-4-",
- "8:8. default constructor", "operator== 1:42, 1:42", "8:8. destructor",
- "-5-", "3:3. destructor", "2:17. destructor", "1:42. destructor",
+ "2:17. copy constructor (from 0:17)", "-1-",
+ "3:42. explicit constructor", "operator== 0:17, 2:17",
+ "3:42. destructor", "-2-", "4:42. explicit constructor",
+ "operator== 1:42, 4:42", "4:42. destructor", "-3-",
+ "5:17. explicit constructor", "6:17. move constructor (from 5:17)",
+ "operator== 0:17, 6:17", "6:17. destructor", "5:17. destructor", "-4-",
+ "operator== 1:42, 1:42", "-5-", "2:17. destructor", "1:42. destructor",
"0:17. destructor"),
*log);
}
@@ -452,16 +437,15 @@ TEST(OptionalTest, TestEquality) {
EXPECT_EQ(me1, me2);
log->push_back("---");
}
- EXPECT_EQ(V("0:17. explicit constructor", "1:42. explicit constructor",
- "2:17. copy constructor (from 0:17)",
- "3:17. copy constructor (from 0:17)",
- "4:42. copy constructor (from 1:42)", "5:5. default constructor",
- "6:6. default constructor", "---", "operator== 2:17, 2:17",
- "operator== 2:17, 3:17", "operator!= 2:17, 4:42", "---",
- "6:6. destructor", "5:5. destructor", "4:42. destructor",
- "3:17. destructor", "2:17. destructor", "1:42. destructor",
- "0:17. destructor"),
- *log);
+ EXPECT_EQ(
+ V("0:17. explicit constructor", "1:42. explicit constructor",
+ "2:17. copy constructor (from 0:17)",
+ "3:17. copy constructor (from 0:17)",
+ "4:42. copy constructor (from 1:42)", "---", "operator== 2:17, 2:17",
+ "operator== 2:17, 3:17", "operator!= 2:17, 4:42", "---",
+ "4:42. destructor", "3:17. destructor", "2:17. destructor",
+ "1:42. destructor", "0:17. destructor"),
+ *log);
}
TEST(OptionalTest, TestSwap) {
@@ -478,11 +462,9 @@ TEST(OptionalTest, TestSwap) {
EXPECT_EQ(V("0:17. explicit constructor", "1:42. explicit constructor",
"2:17. copy constructor (from 0:17)",
"3:42. copy constructor (from 1:42)",
- "4:17. copy constructor (from 0:17)", "5:5. default constructor",
- "6:6. default constructor", "7:7. default constructor", "---",
- "swap 2:42, 3:17", "swap 4:5, 5:17", "swap 6:7, 7:6", "---",
- "7:6. destructor", "6:7. destructor", "5:17. destructor",
- "4:5. destructor", "3:17. destructor", "2:42. destructor",
+ "4:17. copy constructor (from 0:17)", "---", "swap 2:42, 3:17",
+ "5:17. move constructor (from 4:17)", "4:17. destructor", "---",
+ "5:17. destructor", "3:17. destructor", "2:42. destructor",
"1:42. destructor", "0:17. destructor"),
*log);
}
« 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