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

Side by Side Diff: webrtc/base/optional_unittest.cc

Issue 1813763005: Updated structures and functions for setting the max bitrate limit to take rtc::Optional<int> Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 4 years, 9 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
OLDNEW
1 /* 1 /*
2 * Copyright 2015 The WebRTC Project Authors. All rights reserved. 2 * Copyright 2015 The WebRTC Project Authors. All rights reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 #include <sstream> 11 #include <sstream>
12 #include <string> 12 #include <string>
13 #include <utility> 13 #include <utility>
14 #include <vector> 14 #include <vector>
15 #include <sstream>
15 16
16 #include "webrtc/base/gunit.h" 17 #include "webrtc/base/gunit.h"
17 #include "webrtc/base/optional.h" 18 #include "webrtc/base/optional.h"
19 #include "webrtc/base/optional_ios.h"
18 20
19 namespace rtc { 21 namespace rtc {
20 22
21 namespace { 23 namespace {
22 24
23 // Class whose instances logs various method calls (constructor, destructor, 25 // Class whose instances logs various method calls (constructor, destructor,
24 // etc.). Each instance has a unique ID (a simple global sequence number) and 26 // etc.). Each instance has a unique ID (a simple global sequence number) and
25 // an origin ID. When a copy is made, the new object gets a fresh ID but copies 27 // an origin ID. When a copy is made, the new object gets a fresh ID but copies
26 // the origin ID from the original. When a new Logger is created from scratch, 28 // the origin ID from the original. When a new Logger is created from scratch,
27 // it gets a fresh ID, and the origin ID is the same as the ID (default 29 // it gets a fresh ID, and the origin ID is the same as the ID (default
(...skipping 27 matching lines...) Expand all
55 Log2("swap", a, b); 57 Log2("swap", a, b);
56 } 58 }
57 friend bool operator==(const Logger& a, const Logger& b) { 59 friend bool operator==(const Logger& a, const Logger& b) {
58 Log2("operator==", a, b); 60 Log2("operator==", a, b);
59 return a.origin_ == b.origin_; 61 return a.origin_ == b.origin_;
60 } 62 }
61 friend bool operator!=(const Logger& a, const Logger& b) { 63 friend bool operator!=(const Logger& a, const Logger& b) {
62 Log2("operator!=", a, b); 64 Log2("operator!=", a, b);
63 return a.origin_ != b.origin_; 65 return a.origin_ != b.origin_;
64 } 66 }
67 friend std::ostream& operator<<(std::ostream& stream, const Logger& l);
65 void Foo() { Log("Foo()"); } 68 void Foo() { Log("Foo()"); }
66 void Foo() const { Log("Foo() const"); } 69 void Foo() const { Log("Foo() const"); }
67 static rtc::scoped_ptr<std::vector<std::string>> Setup() { 70 static rtc::scoped_ptr<std::vector<std::string>> Setup() {
68 auto s = rtc_make_scoped_ptr(new std::vector<std::string>); 71 auto s = rtc_make_scoped_ptr(new std::vector<std::string>);
69 g_log = s.get(); 72 g_log = s.get();
70 g_next_id = 0; 73 g_next_id = 0;
71 return s; 74 return s;
72 } 75 }
73 76
74 private: 77 private:
(...skipping 16 matching lines...) Expand all
91 std::ostringstream oss; 94 std::ostringstream oss;
92 oss << msg << ' ' << a.id_ << ':' << a.origin_ << ", " << b.id_ << ':' 95 oss << msg << ' ' << a.id_ << ':' << a.origin_ << ", " << b.id_ << ':'
93 << b.origin_; 96 << b.origin_;
94 g_log->push_back(oss.str()); 97 g_log->push_back(oss.str());
95 } 98 }
96 }; 99 };
97 100
98 std::vector<std::string>* Logger::g_log = nullptr; 101 std::vector<std::string>* Logger::g_log = nullptr;
99 int Logger::g_next_id = 0; 102 int Logger::g_next_id = 0;
100 103
104 // Operator<< for Logger. EXPECT_EQ internally uses operator<< to format the
105 // error message, which uses operator<< for Optional<T> which in turn depends
106 // on operator<< for T.
107 std::ostream& operator<<(std::ostream& stream, const Logger& logger) {
108 for (auto it = Logger::g_log->begin(); it != Logger::g_log->end(); ++it) {
109 if (it != Logger::g_log->begin()) {
110 stream << "; ";
111 }
112 stream << *it;
113 }
114 return stream;
115 }
116
101 // Append all the other args to the vector pointed to by the first arg. 117 // Append all the other args to the vector pointed to by the first arg.
102 template <typename T> 118 template <typename T>
103 void VectorAppend(std::vector<T>* v) {} 119 void VectorAppend(std::vector<T>* v) {}
104 template <typename T, typename... Ts> 120 template <typename T, typename... Ts>
105 void VectorAppend(std::vector<T>* v, const T& e, Ts... es) { 121 void VectorAppend(std::vector<T>* v, const T& e, Ts... es) {
106 v->push_back(e); 122 v->push_back(e);
107 VectorAppend(v, es...); 123 VectorAppend(v, es...);
108 } 124 }
109 125
110 // Create a vector of strings. Because we're not allowed to use 126 // Create a vector of strings. Because we're not allowed to use
(...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after
479 "3:42. copy constructor (from 1:42)", 495 "3:42. copy constructor (from 1:42)",
480 "4:17. copy constructor (from 0:17)", "5:5. default constructor", 496 "4:17. copy constructor (from 0:17)", "5:5. default constructor",
481 "6:6. default constructor", "7:7. default constructor", "---", 497 "6:6. default constructor", "7:7. default constructor", "---",
482 "swap 2:42, 3:17", "swap 4:5, 5:17", "swap 6:7, 7:6", "---", 498 "swap 2:42, 3:17", "swap 4:5, 5:17", "swap 6:7, 7:6", "---",
483 "7:6. destructor", "6:7. destructor", "5:17. destructor", 499 "7:6. destructor", "6:7. destructor", "5:17. destructor",
484 "4:5. destructor", "3:17. destructor", "2:42. destructor", 500 "4:5. destructor", "3:17. destructor", "2:42. destructor",
485 "1:42. destructor", "0:17. destructor"), 501 "1:42. destructor", "0:17. destructor"),
486 *log); 502 *log);
487 } 503 }
488 504
505 template <typename T>
506 void ExpectWriteResult(const std::string& expected, rtc::Optional<T> value) {
507 std::ostringstream stream;
508 stream << value;
509 EXPECT_EQ(expected, stream.str());
510 }
511
512 TEST(OptionalTest, TestWriteToOstream) {
513 ExpectWriteResult("1", rtc::Optional<int>(1));
514 ExpectWriteResult("<not set>", rtc::Optional<int>());
515 ExpectWriteResult("", rtc::Optional<std::string>(std::string()));
516 ExpectWriteResult("<not set>", rtc::Optional<std::string>());
517 }
518
489 } // namespace rtc 519 } // namespace rtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698