Chromium Code Reviews| Index: webrtc/base/optional_unittest.cc |
| diff --git a/webrtc/base/optional_unittest.cc b/webrtc/base/optional_unittest.cc |
| index 89e538b7d52d76ff37bdb1eaca84d86ebbfece53..0606868b3cda2c3e3720bf7e4568461b1058ca5b 100644 |
| --- a/webrtc/base/optional_unittest.cc |
| +++ b/webrtc/base/optional_unittest.cc |
| @@ -12,6 +12,7 @@ |
| #include <string> |
| #include <utility> |
| #include <vector> |
| +#include <sstream> |
| #include "webrtc/base/gunit.h" |
| #include "webrtc/base/optional.h" |
| @@ -62,6 +63,7 @@ class Logger { |
| Log2("operator!=", a, b); |
| return a.origin_ != b.origin_; |
| } |
| + friend std::ostream& operator<<(std::ostream& stream, const Logger& l); |
| void Foo() { Log("Foo()"); } |
| void Foo() const { Log("Foo() const"); } |
| static rtc::scoped_ptr<std::vector<std::string>> Setup() { |
| @@ -98,6 +100,19 @@ class Logger { |
| std::vector<std::string>* Logger::g_log = nullptr; |
| int Logger::g_next_id = 0; |
| +// Operator<< for Logger. EXPECT_EQ internally uses operator<< to format the |
| +// error message, which uses operator<< for Optional<T> which in turn depends |
| +// on operator<< for T. |
| +std::ostream& operator<<(std::ostream& stream, const Logger& logger) { |
| + for (auto it = Logger::g_log->begin(); it != Logger::g_log->end(); ++it) { |
| + if (it != Logger::g_log->begin()) { |
| + stream << "; "; |
| + } |
| + stream << *it; |
| + } |
| + return stream; |
| +} |
| + |
| // Append all the other args to the vector pointed to by the first arg. |
| template <typename T> |
| void VectorAppend(std::vector<T>* v) {} |
| @@ -486,4 +501,18 @@ TEST(OptionalTest, TestSwap) { |
| *log); |
| } |
| +template <typename T> |
| +void ExpectWriteResult(const std::string& expected, rtc::Optional<T> value) { |
| + std::ostringstream stream; |
| + stream << value; |
| + EXPECT_EQ(expected, stream.str()); |
| +} |
| + |
| +TEST(OptionalTest, TestWriteToOstream) { |
| + ExpectWriteResult("1", rtc::Optional<int>(1)); |
| + ExpectWriteResult("<not set>", rtc::Optional<int>()); |
| + ExpectWriteResult("", rtc::Optional<std::string>(std::string())); |
| + ExpectWriteResult("<not set>", rtc::Optional<std::string>()); |
| +} |
|
Taylor Brandstetter
2016/03/29 02:26:58
Again, impressed with how thorough your unit tests
|
| + |
| } // namespace rtc |