| Index: webrtc/base/optional_unittest.cc
|
| diff --git a/webrtc/base/optional_unittest.cc b/webrtc/base/optional_unittest.cc
|
| index 8ddbebadb9a076f961c0e5c4bc5e6d205e6137a2..57099b68d415e5fdd95d293e372700783faf4a61 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>());
|
| +}
|
| +
|
| } // namespace rtc
|
|
|