mirror of
https://github.com/mollyim/webrtc.git
synced 2025-05-19 08:37:54 +01:00
Revert "Remove rtc::Optional alias and api:optional target"
This reverts commit 6f5b0f920a
.
Reason for revert: Breaks internal project.
Original change's description:
> Remove rtc::Optional alias and api:optional target
>
> Update left-overs where old target still was used.
>
> Bug: webrtc:9078
> Change-Id: I2162c928091fc4ff1dea33a3f03adbe47207d206
> Reviewed-on: https://webrtc-review.googlesource.com/84740
> Commit-Queue: Danil Chapovalov <danilchap@webrtc.org>
> Reviewed-by: Karl Wiberg <kwiberg@webrtc.org>
> Cr-Commit-Position: refs/heads/master@{#23913}
TBR=danilchap@webrtc.org,kwiberg@webrtc.org
Change-Id: I95f5ec33520b823c3d0c9cb83d945d6a15355367
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: webrtc:9078
Reviewed-on: https://webrtc-review.googlesource.com/88140
Reviewed-by: Ilya Nikolaevskiy <ilnik@webrtc.org>
Commit-Queue: Ilya Nikolaevskiy <ilnik@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#23921}
This commit is contained in:
parent
2d82adea03
commit
b661c658da
10 changed files with 968 additions and 16 deletions
1
BUILD.gn
1
BUILD.gn
|
@ -390,6 +390,7 @@ rtc_source_set("webrtc_common") {
|
|||
deps = [
|
||||
":typedefs",
|
||||
"api:array_view",
|
||||
"api:optional",
|
||||
"api/video:video_bitrate_allocation",
|
||||
"rtc_base:checks",
|
||||
"rtc_base:deprecation",
|
||||
|
|
19
api/BUILD.gn
19
api/BUILD.gn
|
@ -256,9 +256,9 @@ rtc_source_set("simulated_network_api") {
|
|||
"test/simulated_network.h",
|
||||
]
|
||||
deps = [
|
||||
":optional",
|
||||
"../rtc_base:criticalsection",
|
||||
"../rtc_base:rtc_base",
|
||||
"//third_party/abseil-cpp/absl/types:optional",
|
||||
]
|
||||
}
|
||||
|
||||
|
@ -285,6 +285,18 @@ rtc_source_set("array_view") {
|
|||
]
|
||||
}
|
||||
|
||||
# TODO(bugs.webrtc.org/9078): Deprecated, replaced by absl/types:optional.
|
||||
# Delete after webrtc and downstreams users are updated.
|
||||
rtc_source_set("optional") {
|
||||
visibility = [ "*" ]
|
||||
sources = [
|
||||
"optional.h",
|
||||
]
|
||||
deps = [
|
||||
"//third_party/abseil-cpp/absl/types:optional",
|
||||
]
|
||||
}
|
||||
|
||||
rtc_source_set("refcountedbase") {
|
||||
visibility = [ "*" ]
|
||||
sources = [
|
||||
|
@ -444,6 +456,10 @@ if (rtc_include_tests) {
|
|||
|
||||
sources = [
|
||||
"array_view_unittest.cc",
|
||||
|
||||
# TODO(bugs.webrtc.org/8821): Remove optional_unittests when webrtc starts
|
||||
# running absl unittest on each commit.
|
||||
"optional_unittest.cc",
|
||||
"ortc/mediadescription_unittest.cc",
|
||||
"ortc/sessiondescription_unittest.cc",
|
||||
"rtcerror_unittest.cc",
|
||||
|
@ -459,6 +475,7 @@ if (rtc_include_tests) {
|
|||
":array_view",
|
||||
":libjingle_peerconnection_api",
|
||||
":libjingle_peerconnection_test_api",
|
||||
":optional",
|
||||
":ortc_api",
|
||||
"../rtc_base:checks",
|
||||
"../rtc_base:rtc_base_approved",
|
||||
|
|
27
api/optional.h
Normal file
27
api/optional.h
Normal file
|
@ -0,0 +1,27 @@
|
|||
/*
|
||||
* Copyright 2015 The WebRTC Project Authors. All rights reserved.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license
|
||||
* that can be found in the LICENSE file in the root of the source
|
||||
* tree. An additional intellectual property rights grant can be found
|
||||
* in the file PATENTS. All contributing project authors may
|
||||
* be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
|
||||
// TODO(bugs.webrtc.org/9078): Use absl::optional directly.
|
||||
#ifndef API_OPTIONAL_H_
|
||||
#define API_OPTIONAL_H_
|
||||
|
||||
#include "absl/types/optional.h"
|
||||
|
||||
namespace rtc {
|
||||
|
||||
using absl::nullopt_t;
|
||||
using absl::nullopt;
|
||||
|
||||
template <typename T>
|
||||
using Optional = absl::optional<T>;
|
||||
|
||||
} // namespace rtc
|
||||
|
||||
#endif // API_OPTIONAL_H_
|
906
api/optional_unittest.cc
Normal file
906
api/optional_unittest.cc
Normal file
|
@ -0,0 +1,906 @@
|
|||
/*
|
||||
* Copyright 2015 The WebRTC Project Authors. All rights reserved.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license
|
||||
* that can be found in the LICENSE file in the root of the source
|
||||
* tree. An additional intellectual property rights grant can be found
|
||||
* in the file PATENTS. All contributing project authors may
|
||||
* be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
|
||||
// TODO(bugs.webrtc.org/8821): Delete this file when absl unittests run on
|
||||
// webrtc bots.
|
||||
|
||||
#include <memory>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "api/optional.h"
|
||||
#include "rtc_base/gunit.h"
|
||||
|
||||
namespace rtc {
|
||||
|
||||
namespace {
|
||||
|
||||
struct MyUnprintableType {
|
||||
int value;
|
||||
};
|
||||
|
||||
struct MyPrintableType {
|
||||
int value;
|
||||
};
|
||||
|
||||
struct MyOstreamPrintableType {
|
||||
int value;
|
||||
};
|
||||
|
||||
void PrintTo(const MyPrintableType& mpt, std::ostream* os) {
|
||||
*os << "The value is " << mpt.value;
|
||||
}
|
||||
|
||||
std::ostream& operator<<(std::ostream& os, const MyPrintableType& mpt) {
|
||||
os << mpt.value;
|
||||
return os;
|
||||
}
|
||||
|
||||
std::ostream& operator<<(std::ostream& os, const MyOstreamPrintableType& mpt) {
|
||||
os << mpt.value;
|
||||
return os;
|
||||
}
|
||||
|
||||
// Class whose instances logs various method calls (constructor, destructor,
|
||||
// etc.). Each instance has a unique ID (a simple global sequence number) and
|
||||
// an origin ID. When a copy is made, the new object gets a fresh ID but copies
|
||||
// the origin ID from the original. When a new Logger is created from scratch,
|
||||
// it gets a fresh ID, and the origin ID is the same as the ID (default
|
||||
// constructor) or given as an argument (explicit constructor).
|
||||
class Logger {
|
||||
public:
|
||||
Logger() : id_(g_next_id++), origin_(id_) { Log("default constructor"); }
|
||||
explicit Logger(int origin) : id_(g_next_id++), origin_(origin) {
|
||||
Log("explicit constructor");
|
||||
}
|
||||
Logger(int origin, const Logger& pass_by_ref, Logger pass_by_value)
|
||||
: id_(g_next_id++), origin_(origin) {
|
||||
Log("multi parameter constructor");
|
||||
}
|
||||
Logger(const Logger& other) : id_(g_next_id++), origin_(other.origin_) {
|
||||
LogFrom("copy constructor", other);
|
||||
}
|
||||
Logger(Logger&& other) : id_(g_next_id++), origin_(other.origin_) {
|
||||
LogFrom("move constructor", other);
|
||||
}
|
||||
~Logger() { Log("destructor"); }
|
||||
Logger& operator=(const Logger& other) {
|
||||
origin_ = other.origin_;
|
||||
LogFrom("operator= copy", other);
|
||||
return *this;
|
||||
}
|
||||
Logger& operator=(Logger&& other) {
|
||||
origin_ = other.origin_;
|
||||
LogFrom("operator= move", other);
|
||||
return *this;
|
||||
}
|
||||
friend void swap(Logger& a, Logger& b) {
|
||||
using std::swap;
|
||||
swap(a.origin_, b.origin_);
|
||||
Log2("swap", a, b);
|
||||
}
|
||||
friend bool operator==(const Logger& a, const Logger& b) {
|
||||
Log2("operator==", a, b);
|
||||
return a.origin_ == b.origin_;
|
||||
}
|
||||
friend bool operator!=(const Logger& a, const Logger& b) {
|
||||
Log2("operator!=", a, b);
|
||||
return a.origin_ != b.origin_;
|
||||
}
|
||||
void Foo() { Log("Foo()"); }
|
||||
void Foo() const { Log("Foo() const"); }
|
||||
static std::unique_ptr<std::vector<std::string>> Setup() {
|
||||
std::unique_ptr<std::vector<std::string>> s(new std::vector<std::string>);
|
||||
g_log = s.get();
|
||||
g_next_id = 0;
|
||||
return s;
|
||||
}
|
||||
|
||||
private:
|
||||
int id_;
|
||||
int origin_;
|
||||
static std::vector<std::string>* g_log;
|
||||
static int g_next_id;
|
||||
void Log(const char* msg) const {
|
||||
std::ostringstream oss;
|
||||
oss << id_ << ':' << origin_ << ". " << msg;
|
||||
g_log->push_back(oss.str());
|
||||
}
|
||||
void LogFrom(const char* msg, const Logger& other) const {
|
||||
std::ostringstream oss;
|
||||
oss << id_ << ':' << origin_ << ". " << msg << " (from " << other.id_ << ':'
|
||||
<< other.origin_ << ")";
|
||||
g_log->push_back(oss.str());
|
||||
}
|
||||
static void Log2(const char* msg, const Logger& a, const Logger& b) {
|
||||
std::ostringstream oss;
|
||||
oss << msg << ' ' << a.id_ << ':' << a.origin_ << ", " << b.id_ << ':'
|
||||
<< b.origin_;
|
||||
g_log->push_back(oss.str());
|
||||
}
|
||||
};
|
||||
|
||||
std::vector<std::string>* Logger::g_log = nullptr;
|
||||
int Logger::g_next_id = 0;
|
||||
|
||||
// Append all the other args to the vector pointed to by the first arg.
|
||||
template <typename T>
|
||||
void VectorAppend(std::vector<T>* v) {}
|
||||
template <typename T, typename... Ts>
|
||||
void VectorAppend(std::vector<T>* v, const T& e, Ts... es) {
|
||||
v->push_back(e);
|
||||
VectorAppend(v, es...);
|
||||
}
|
||||
|
||||
// Create a vector of strings. Because we're not allowed to use
|
||||
// std::initializer_list.
|
||||
template <typename... Ts>
|
||||
std::vector<std::string> V(Ts... es) {
|
||||
std::vector<std::string> strings;
|
||||
VectorAppend(&strings, static_cast<std::string>(es)...);
|
||||
return strings;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
TEST(OptionalTest, TestConstructDefault) {
|
||||
auto log = Logger::Setup();
|
||||
{
|
||||
Optional<Logger> x;
|
||||
EXPECT_FALSE(x);
|
||||
EXPECT_FALSE(x.has_value());
|
||||
}
|
||||
EXPECT_EQ(V(), *log);
|
||||
}
|
||||
|
||||
TEST(OptionalTest, TestConstructNullopt) {
|
||||
auto log = Logger::Setup();
|
||||
{
|
||||
Optional<Logger> x(nullopt);
|
||||
EXPECT_FALSE(x);
|
||||
EXPECT_FALSE(x.has_value());
|
||||
}
|
||||
EXPECT_EQ(V(), *log);
|
||||
}
|
||||
|
||||
TEST(OptionalTest, TestConstructCopyEmpty) {
|
||||
auto log = Logger::Setup();
|
||||
{
|
||||
Optional<Logger> x;
|
||||
EXPECT_FALSE(x);
|
||||
EXPECT_FALSE(x.has_value());
|
||||
auto y = x;
|
||||
EXPECT_FALSE(y);
|
||||
EXPECT_FALSE(y.has_value());
|
||||
}
|
||||
EXPECT_EQ(V(), *log);
|
||||
}
|
||||
|
||||
TEST(OptionalTest, TestConstructCopyFull) {
|
||||
auto log = Logger::Setup();
|
||||
{
|
||||
Logger a;
|
||||
Optional<Logger> x(a);
|
||||
EXPECT_TRUE(x);
|
||||
EXPECT_TRUE(x.has_value());
|
||||
log->push_back("---");
|
||||
auto y = x;
|
||||
EXPECT_TRUE(y);
|
||||
EXPECT_TRUE(y.has_value());
|
||||
log->push_back("---");
|
||||
}
|
||||
EXPECT_EQ(V("0:0. default constructor", "1:0. copy constructor (from 0:0)",
|
||||
"---", "2:0. copy constructor (from 1:0)", "---",
|
||||
"2:0. destructor", "1:0. destructor", "0:0. destructor"),
|
||||
*log);
|
||||
}
|
||||
|
||||
TEST(OptionalTest, TestConstructMoveEmpty) {
|
||||
auto log = Logger::Setup();
|
||||
{
|
||||
Optional<Logger> x;
|
||||
EXPECT_FALSE(x);
|
||||
EXPECT_FALSE(x.has_value());
|
||||
auto y = std::move(x);
|
||||
EXPECT_FALSE(y);
|
||||
EXPECT_FALSE(y.has_value());
|
||||
}
|
||||
EXPECT_EQ(V(), *log);
|
||||
}
|
||||
|
||||
TEST(OptionalTest, TestConstructMoveFull) {
|
||||
auto log = Logger::Setup();
|
||||
{
|
||||
Optional<Logger> x(Logger(17));
|
||||
EXPECT_TRUE(x);
|
||||
EXPECT_TRUE(x.has_value());
|
||||
log->push_back("---");
|
||||
auto y = std::move(x);
|
||||
EXPECT_TRUE(x);
|
||||
EXPECT_TRUE(x.has_value());
|
||||
EXPECT_TRUE(y);
|
||||
EXPECT_TRUE(y.has_value());
|
||||
log->push_back("---");
|
||||
}
|
||||
EXPECT_EQ(
|
||||
V("0:17. explicit constructor", "1:17. move constructor (from 0:17)",
|
||||
"0:17. destructor", "---", "2:17. move constructor (from 1:17)", "---",
|
||||
"2:17. destructor", "1:17. destructor"),
|
||||
*log);
|
||||
}
|
||||
|
||||
TEST(OptionalTest, TestCopyAssignToEmptyFromEmpty) {
|
||||
auto log = Logger::Setup();
|
||||
{
|
||||
Optional<Logger> x, y;
|
||||
x = y;
|
||||
}
|
||||
EXPECT_EQ(V(), *log);
|
||||
}
|
||||
|
||||
TEST(OptionalTest, TestCopyAssignToFullFromEmpty) {
|
||||
auto log = Logger::Setup();
|
||||
{
|
||||
Optional<Logger> x(Logger(17));
|
||||
Optional<Logger> y;
|
||||
log->push_back("---");
|
||||
x = y;
|
||||
log->push_back("---");
|
||||
}
|
||||
EXPECT_EQ(
|
||||
V("0:17. explicit constructor", "1:17. move constructor (from 0:17)",
|
||||
"0:17. destructor", "---", "1:17. destructor", "---"),
|
||||
*log);
|
||||
}
|
||||
|
||||
TEST(OptionalTest, TestCopyAssignToFullFromNullopt) {
|
||||
auto log = Logger::Setup();
|
||||
{
|
||||
Optional<Logger> x(Logger(17));
|
||||
log->push_back("---");
|
||||
x = nullopt;
|
||||
log->push_back("---");
|
||||
EXPECT_FALSE(x);
|
||||
}
|
||||
EXPECT_EQ(
|
||||
V("0:17. explicit constructor", "1:17. move constructor (from 0:17)",
|
||||
"0:17. destructor", "---", "1:17. destructor", "---"),
|
||||
*log);
|
||||
}
|
||||
|
||||
TEST(OptionalTest, TestCopyAssignToFullFromEmptyBraces) {
|
||||
auto log = Logger::Setup();
|
||||
{
|
||||
Optional<Logger> x(Logger(17));
|
||||
log->push_back("---");
|
||||
x = {};
|
||||
log->push_back("---");
|
||||
EXPECT_FALSE(x);
|
||||
}
|
||||
EXPECT_EQ(
|
||||
V("0:17. explicit constructor", "1:17. move constructor (from 0:17)",
|
||||
"0:17. destructor", "---", "1:17. destructor", "---"),
|
||||
*log);
|
||||
}
|
||||
|
||||
TEST(OptionalTest, TestCopyAssignToEmptyFromFull) {
|
||||
auto log = Logger::Setup();
|
||||
{
|
||||
Optional<Logger> x;
|
||||
Optional<Logger> y(Logger(17));
|
||||
log->push_back("---");
|
||||
x = y;
|
||||
log->push_back("---");
|
||||
}
|
||||
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) {
|
||||
auto log = Logger::Setup();
|
||||
{
|
||||
Optional<Logger> x(Logger(17));
|
||||
Optional<Logger> y(Logger(42));
|
||||
log->push_back("---");
|
||||
x = y;
|
||||
log->push_back("---");
|
||||
}
|
||||
EXPECT_EQ(
|
||||
V("0:17. explicit constructor", "1:17. move constructor (from 0:17)",
|
||||
"0:17. destructor", "2:42. explicit constructor",
|
||||
"3:42. move constructor (from 2:42)", "2:42. destructor", "---",
|
||||
"1:42. operator= copy (from 3:42)", "---", "3:42. destructor",
|
||||
"1:42. destructor"),
|
||||
*log);
|
||||
}
|
||||
|
||||
TEST(OptionalTest, TestCopyAssignToEmptyFromT) {
|
||||
auto log = Logger::Setup();
|
||||
{
|
||||
Optional<Logger> x;
|
||||
Logger y(17);
|
||||
log->push_back("---");
|
||||
x = Optional<Logger>(y);
|
||||
log->push_back("---");
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
TEST(OptionalTest, TestCopyAssignToFullFromT) {
|
||||
auto log = Logger::Setup();
|
||||
{
|
||||
Optional<Logger> x(Logger(17));
|
||||
Logger y(42);
|
||||
log->push_back("---");
|
||||
x = Optional<Logger>(y);
|
||||
log->push_back("---");
|
||||
}
|
||||
EXPECT_EQ(
|
||||
V("0:17. explicit constructor", "1:17. move constructor (from 0:17)",
|
||||
"0:17. destructor", "2:42. explicit constructor", "---",
|
||||
"3:42. copy constructor (from 2:42)",
|
||||
"1:42. operator= move (from 3:42)", "3:42. destructor", "---",
|
||||
"2:42. destructor", "1:42. destructor"),
|
||||
*log);
|
||||
}
|
||||
|
||||
TEST(OptionalTest, TestMoveAssignToEmptyFromEmpty) {
|
||||
auto log = Logger::Setup();
|
||||
{
|
||||
Optional<Logger> x, y;
|
||||
x = std::move(y);
|
||||
}
|
||||
EXPECT_EQ(V(), *log);
|
||||
}
|
||||
|
||||
TEST(OptionalTest, TestMoveAssignToFullFromEmpty) {
|
||||
auto log = Logger::Setup();
|
||||
{
|
||||
Optional<Logger> x(Logger(17));
|
||||
Optional<Logger> y;
|
||||
log->push_back("---");
|
||||
x = std::move(y);
|
||||
log->push_back("---");
|
||||
}
|
||||
EXPECT_EQ(
|
||||
V("0:17. explicit constructor", "1:17. move constructor (from 0:17)",
|
||||
"0:17. destructor", "---", "1:17. destructor", "---"),
|
||||
*log);
|
||||
}
|
||||
|
||||
TEST(OptionalTest, TestMoveAssignToEmptyFromFull) {
|
||||
auto log = Logger::Setup();
|
||||
{
|
||||
Optional<Logger> x;
|
||||
Optional<Logger> y(Logger(17));
|
||||
log->push_back("---");
|
||||
x = std::move(y);
|
||||
log->push_back("---");
|
||||
}
|
||||
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) {
|
||||
auto log = Logger::Setup();
|
||||
{
|
||||
Optional<Logger> x(Logger(17));
|
||||
Optional<Logger> y(Logger(42));
|
||||
log->push_back("---");
|
||||
x = std::move(y);
|
||||
log->push_back("---");
|
||||
}
|
||||
EXPECT_EQ(
|
||||
V("0:17. explicit constructor", "1:17. move constructor (from 0:17)",
|
||||
"0:17. destructor", "2:42. explicit constructor",
|
||||
"3:42. move constructor (from 2:42)", "2:42. destructor", "---",
|
||||
"1:42. operator= move (from 3:42)", "---", "3:42. destructor",
|
||||
"1:42. destructor"),
|
||||
*log);
|
||||
}
|
||||
|
||||
TEST(OptionalTest, TestMoveAssignToEmptyFromT) {
|
||||
auto log = Logger::Setup();
|
||||
{
|
||||
Optional<Logger> x;
|
||||
Logger y(17);
|
||||
log->push_back("---");
|
||||
x = Optional<Logger>(std::move(y));
|
||||
log->push_back("---");
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
TEST(OptionalTest, TestMoveAssignToFullFromT) {
|
||||
auto log = Logger::Setup();
|
||||
{
|
||||
Optional<Logger> x(Logger(17));
|
||||
Logger y(42);
|
||||
log->push_back("---");
|
||||
x = Optional<Logger>(std::move(y));
|
||||
log->push_back("---");
|
||||
}
|
||||
EXPECT_EQ(
|
||||
V("0:17. explicit constructor", "1:17. move constructor (from 0:17)",
|
||||
"0:17. destructor", "2:42. explicit constructor", "---",
|
||||
"3:42. move constructor (from 2:42)",
|
||||
"1:42. operator= move (from 3:42)", "3:42. destructor", "---",
|
||||
"2:42. destructor", "1:42. destructor"),
|
||||
*log);
|
||||
}
|
||||
|
||||
TEST(OptionalTest, TestResetEmpty) {
|
||||
auto log = Logger::Setup();
|
||||
{
|
||||
Optional<Logger> x;
|
||||
x.reset();
|
||||
}
|
||||
EXPECT_EQ(V(), *log);
|
||||
}
|
||||
|
||||
TEST(OptionalTest, TestResetFull) {
|
||||
auto log = Logger::Setup();
|
||||
{
|
||||
Optional<Logger> x(Logger(17));
|
||||
log->push_back("---");
|
||||
x.reset();
|
||||
log->push_back("---");
|
||||
}
|
||||
EXPECT_EQ(
|
||||
V("0:17. explicit constructor", "1:17. move constructor (from 0:17)",
|
||||
"0:17. destructor", "---", "1:17. destructor", "---"),
|
||||
*log);
|
||||
}
|
||||
|
||||
TEST(OptionalTest, TestEmplaceEmptyWithExplicit) {
|
||||
auto log = Logger::Setup();
|
||||
{
|
||||
Optional<Logger> x;
|
||||
log->push_back("---");
|
||||
x.emplace(42);
|
||||
log->push_back("---");
|
||||
}
|
||||
// clang-format off
|
||||
EXPECT_EQ(V("---",
|
||||
"0:42. explicit constructor",
|
||||
"---",
|
||||
"0:42. destructor"),
|
||||
*log);
|
||||
// clang-format on
|
||||
}
|
||||
|
||||
TEST(OptionalTest, TestEmplaceEmptyWithMultipleParameters) {
|
||||
auto log = Logger::Setup();
|
||||
{
|
||||
Optional<Logger> x;
|
||||
Logger ref(21);
|
||||
Logger value(35);
|
||||
log->push_back("---");
|
||||
x.emplace(42, ref, std::move(value));
|
||||
log->push_back("---");
|
||||
}
|
||||
// clang-format off
|
||||
EXPECT_EQ(V("0:21. explicit constructor",
|
||||
"1:35. explicit constructor",
|
||||
"---",
|
||||
"2:35. move constructor (from 1:35)",
|
||||
"3:42. multi parameter constructor",
|
||||
"2:35. destructor",
|
||||
"---",
|
||||
"1:35. destructor",
|
||||
"0:21. destructor",
|
||||
"3:42. destructor"),
|
||||
*log);
|
||||
// clang-format on
|
||||
}
|
||||
|
||||
TEST(OptionalTest, TestEmplaceEmptyWithCopy) {
|
||||
auto log = Logger::Setup();
|
||||
{
|
||||
Optional<Logger> x;
|
||||
Logger y(42);
|
||||
log->push_back("---");
|
||||
x.emplace(y);
|
||||
log->push_back("---");
|
||||
}
|
||||
// clang-format off
|
||||
EXPECT_EQ(V("0:42. explicit constructor",
|
||||
"---",
|
||||
"1:42. copy constructor (from 0:42)",
|
||||
"---",
|
||||
"0:42. destructor",
|
||||
"1:42. destructor"),
|
||||
*log);
|
||||
// clang-format on
|
||||
}
|
||||
|
||||
TEST(OptionalTest, TestEmplaceEmptyWithMove) {
|
||||
auto log = Logger::Setup();
|
||||
{
|
||||
Optional<Logger> x;
|
||||
Logger y(42);
|
||||
log->push_back("---");
|
||||
x.emplace(std::move(y));
|
||||
log->push_back("---");
|
||||
}
|
||||
// clang-format off
|
||||
EXPECT_EQ(V("0:42. explicit constructor",
|
||||
"---",
|
||||
"1:42. move constructor (from 0:42)",
|
||||
"---",
|
||||
"0:42. destructor",
|
||||
"1:42. destructor"),
|
||||
*log);
|
||||
// clang-format on
|
||||
}
|
||||
|
||||
TEST(OptionalTest, TestEmplaceFullWithExplicit) {
|
||||
auto log = Logger::Setup();
|
||||
{
|
||||
Optional<Logger> x(Logger(17));
|
||||
log->push_back("---");
|
||||
x.emplace(42);
|
||||
log->push_back("---");
|
||||
}
|
||||
// clang-format off
|
||||
EXPECT_EQ(
|
||||
V("0:17. explicit constructor",
|
||||
"1:17. move constructor (from 0:17)",
|
||||
"0:17. destructor",
|
||||
"---",
|
||||
"1:17. destructor",
|
||||
"2:42. explicit constructor",
|
||||
"---",
|
||||
"2:42. destructor"),
|
||||
*log);
|
||||
// clang-format on
|
||||
}
|
||||
|
||||
TEST(OptionalTest, TestEmplaceFullWithMultipleParameters) {
|
||||
auto log = Logger::Setup();
|
||||
{
|
||||
Optional<Logger> x(Logger(17));
|
||||
Logger ref(21);
|
||||
Logger value(35);
|
||||
log->push_back("---");
|
||||
x.emplace(42, ref, std::move(value));
|
||||
log->push_back("---");
|
||||
}
|
||||
// clang-format off
|
||||
EXPECT_EQ(V("0:17. explicit constructor",
|
||||
"1:17. move constructor (from 0:17)",
|
||||
"0:17. destructor",
|
||||
"2:21. explicit constructor",
|
||||
"3:35. explicit constructor",
|
||||
"---",
|
||||
"1:17. destructor",
|
||||
"4:35. move constructor (from 3:35)",
|
||||
"5:42. multi parameter constructor",
|
||||
"4:35. destructor",
|
||||
"---",
|
||||
"3:35. destructor",
|
||||
"2:21. destructor",
|
||||
"5:42. destructor"),
|
||||
*log);
|
||||
// clang-format on
|
||||
}
|
||||
|
||||
TEST(OptionalTest, TestEmplaceFullWithCopy) {
|
||||
auto log = Logger::Setup();
|
||||
{
|
||||
Optional<Logger> x(Logger(17));
|
||||
Logger y(42);
|
||||
log->push_back("---");
|
||||
x.emplace(y);
|
||||
log->push_back("---");
|
||||
}
|
||||
// clang-format off
|
||||
EXPECT_EQ(V("0:17. explicit constructor",
|
||||
"1:17. move constructor (from 0:17)",
|
||||
"0:17. destructor",
|
||||
"2:42. explicit constructor",
|
||||
"---",
|
||||
"1:17. destructor",
|
||||
"3:42. copy constructor (from 2:42)",
|
||||
"---",
|
||||
"2:42. destructor",
|
||||
"3:42. destructor"),
|
||||
*log);
|
||||
// clang-format on
|
||||
}
|
||||
|
||||
TEST(OptionalTest, TestEmplaceFullWithMove) {
|
||||
auto log = Logger::Setup();
|
||||
{
|
||||
Optional<Logger> x(Logger(17));
|
||||
Logger y(42);
|
||||
log->push_back("---");
|
||||
x.emplace(std::move(y));
|
||||
log->push_back("---");
|
||||
}
|
||||
// clang-format off
|
||||
EXPECT_EQ(V("0:17. explicit constructor",
|
||||
"1:17. move constructor (from 0:17)",
|
||||
"0:17. destructor",
|
||||
"2:42. explicit constructor",
|
||||
"---",
|
||||
"1:17. destructor",
|
||||
"3:42. move constructor (from 2:42)",
|
||||
"---",
|
||||
"2:42. destructor",
|
||||
"3:42. destructor"),
|
||||
*log);
|
||||
// clang-format on
|
||||
}
|
||||
|
||||
TEST(OptionalTest, TestDereference) {
|
||||
auto log = Logger::Setup();
|
||||
{
|
||||
Optional<Logger> x(Logger(42));
|
||||
const auto& y = x;
|
||||
log->push_back("---");
|
||||
x->Foo();
|
||||
y->Foo();
|
||||
std::move(x)->Foo();
|
||||
std::move(y)->Foo();
|
||||
log->push_back("---");
|
||||
(*x).Foo();
|
||||
(*y).Foo();
|
||||
(*std::move(x)).Foo();
|
||||
(*std::move(y)).Foo();
|
||||
log->push_back("---");
|
||||
x.value().Foo();
|
||||
y.value().Foo();
|
||||
std::move(x).value().Foo();
|
||||
std::move(y).value().Foo();
|
||||
log->push_back("---");
|
||||
}
|
||||
// clang-format off
|
||||
EXPECT_EQ(V("0:42. explicit constructor",
|
||||
"1:42. move constructor (from 0:42)",
|
||||
"0:42. destructor",
|
||||
"---",
|
||||
"1:42. Foo()",
|
||||
"1:42. Foo() const",
|
||||
"1:42. Foo()",
|
||||
"1:42. Foo() const",
|
||||
"---",
|
||||
"1:42. Foo()",
|
||||
"1:42. Foo() const",
|
||||
"1:42. Foo()",
|
||||
"1:42. Foo() const",
|
||||
"---",
|
||||
"1:42. Foo()",
|
||||
"1:42. Foo() const",
|
||||
"1:42. Foo()",
|
||||
"1:42. Foo() const",
|
||||
"---",
|
||||
"1:42. destructor"),
|
||||
*log);
|
||||
// clang-format on
|
||||
}
|
||||
|
||||
TEST(OptionalTest, TestDereferenceWithDefault) {
|
||||
auto log = Logger::Setup();
|
||||
const Logger a(17), b(42);
|
||||
Optional<Logger> x(a);
|
||||
Optional<Logger> y;
|
||||
EXPECT_EQ(a, x.value_or(Logger(42)));
|
||||
EXPECT_EQ(b, y.value_or(Logger(42)));
|
||||
EXPECT_EQ(a, Optional<Logger>(Logger(17)).value_or(b));
|
||||
EXPECT_EQ(b, Optional<Logger>().value_or(b));
|
||||
// Can't expect exact list of constructors and destructors because it is
|
||||
// compiler-dependent. i.e. msvc produce different output than clang. Calls
|
||||
// above are subject to copy elision that allow to change behavior.
|
||||
}
|
||||
|
||||
TEST(OptionalTest, TestEquality) {
|
||||
auto log = Logger::Setup();
|
||||
{
|
||||
Logger a(17), b(42);
|
||||
Optional<Logger> ma1(a), ma2(a), mb(b), me1, me2;
|
||||
log->push_back("---");
|
||||
EXPECT_EQ(ma1, ma1);
|
||||
EXPECT_EQ(ma1, ma2);
|
||||
EXPECT_NE(ma1, mb);
|
||||
EXPECT_NE(ma1, me1);
|
||||
EXPECT_EQ(me1, me1);
|
||||
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)", "---", "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, TestEqualityWithNullopt) {
|
||||
auto log = Logger::Setup();
|
||||
{
|
||||
Logger a(17);
|
||||
Optional<Logger> ma(a), me;
|
||||
// Using operator== and operator!= explicitly instead of EXPECT_EQ/EXPECT_NE
|
||||
// macros because those operators are under test.
|
||||
log->push_back("---");
|
||||
|
||||
EXPECT_FALSE(ma == nullopt);
|
||||
EXPECT_FALSE(nullopt == ma);
|
||||
EXPECT_TRUE(me == nullopt);
|
||||
EXPECT_TRUE(nullopt == me);
|
||||
|
||||
EXPECT_TRUE(ma != nullopt);
|
||||
EXPECT_TRUE(nullopt != ma);
|
||||
EXPECT_FALSE(me != nullopt);
|
||||
EXPECT_FALSE(nullopt != me);
|
||||
|
||||
log->push_back("---");
|
||||
}
|
||||
// clang-format off
|
||||
EXPECT_EQ(V("0:17. explicit constructor",
|
||||
"1:17. copy constructor (from 0:17)",
|
||||
"---",
|
||||
// No operators should be called when comparing to empty.
|
||||
"---",
|
||||
"1:17. destructor",
|
||||
"0:17. destructor"),
|
||||
*log);
|
||||
// clang-format on
|
||||
}
|
||||
|
||||
TEST(OptionalTest, TestEqualityWithObject) {
|
||||
auto log = Logger::Setup();
|
||||
{
|
||||
Logger a(17), b(42);
|
||||
Optional<Logger> ma(a), me;
|
||||
// Using operator== and operator!= explicitly 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();
|
||||
{
|
||||
Logger a(17), b(42);
|
||||
Optional<Logger> x1(a), x2(b), y1(a), y2, z1, z2;
|
||||
log->push_back("---");
|
||||
swap(x1, x2); // Swap full <-> full.
|
||||
swap(y1, y2); // Swap full <-> empty.
|
||||
swap(z1, z2); // Swap empty <-> empty.
|
||||
log->push_back("---");
|
||||
}
|
||||
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)", "---", "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);
|
||||
}
|
||||
|
||||
TEST(OptionalTest, TestMoveValue) {
|
||||
auto log = Logger::Setup();
|
||||
{
|
||||
Optional<Logger> x(Logger(42));
|
||||
log->push_back("---");
|
||||
Logger moved = std::move(x.value());
|
||||
log->push_back("---");
|
||||
}
|
||||
EXPECT_EQ(
|
||||
V("0:42. explicit constructor", "1:42. move constructor (from 0:42)",
|
||||
"0:42. destructor", "---", "2:42. move constructor (from 1:42)", "---",
|
||||
"2:42. destructor", "1:42. destructor"),
|
||||
*log);
|
||||
}
|
||||
|
||||
// Nice printing available only when GTEST aware ABSL is present
|
||||
#ifdef GTEST_HAS_ABSL
|
||||
#define MaybeTestPrintTo TestPrintTo
|
||||
#define MaybeTestUnprintablePrintTo TestUnprintablePrintTo
|
||||
#else
|
||||
#define MaybeTestPrintTo DISABLED_TestPrintTo
|
||||
#define MaybeTestUnprintablePrintTo DISABLED_TestUnprintablePrintTo
|
||||
#endif
|
||||
TEST(OptionalTest, MaybeTestPrintTo) {
|
||||
constexpr char kEmptyOptionalMessage[] = "(nullopt)";
|
||||
const Optional<MyUnprintableType> empty_unprintable;
|
||||
const Optional<MyPrintableType> empty_printable;
|
||||
const Optional<MyOstreamPrintableType> empty_ostream_printable;
|
||||
EXPECT_EQ(kEmptyOptionalMessage, ::testing::PrintToString(empty_unprintable));
|
||||
EXPECT_EQ(kEmptyOptionalMessage, ::testing::PrintToString(empty_printable));
|
||||
EXPECT_EQ(kEmptyOptionalMessage,
|
||||
::testing::PrintToString(empty_ostream_printable));
|
||||
EXPECT_NE("(1)", ::testing::PrintToString(Optional<MyUnprintableType>({1})));
|
||||
EXPECT_NE("(1)", ::testing::PrintToString(Optional<MyPrintableType>({1})));
|
||||
EXPECT_EQ("(The value is 1)",
|
||||
::testing::PrintToString(Optional<MyPrintableType>({1})));
|
||||
EXPECT_EQ("(1)",
|
||||
::testing::PrintToString(Optional<MyOstreamPrintableType>({1})));
|
||||
}
|
||||
|
||||
TEST(OptionalTest, MaybeTestUnprintablePrintTo) {
|
||||
struct UnprintableType {
|
||||
uint8_t value[5];
|
||||
};
|
||||
Optional<UnprintableType> opt({0xa1, 0xb2, 0xc3, 0xd4, 0xe5});
|
||||
EXPECT_EQ("(5-byte object <A1-B2 C3-D4 E5>)", ::testing::PrintToString(opt));
|
||||
}
|
||||
|
||||
void UnusedFunctionWorkaround() {
|
||||
// These are here to ensure we don't get warnings about ostream and PrintTo
|
||||
// for MyPrintableType never getting called.
|
||||
const MyPrintableType dont_warn{17};
|
||||
const MyOstreamPrintableType dont_warn2{18};
|
||||
std::stringstream sstr;
|
||||
sstr << dont_warn;
|
||||
PrintTo(dont_warn, &sstr);
|
||||
sstr << dont_warn2;
|
||||
}
|
||||
|
||||
} // namespace rtc
|
|
@ -17,7 +17,7 @@
|
|||
#include <queue>
|
||||
#include <vector>
|
||||
|
||||
#include "absl/types/optional.h"
|
||||
#include "api/optional.h"
|
||||
#include "rtc_base/criticalsection.h"
|
||||
#include "rtc_base/random.h"
|
||||
#include "rtc_base/thread_annotations.h"
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
#include <vector>
|
||||
|
||||
#include "api/array_view.h"
|
||||
#include "api/optional.h"
|
||||
// TODO(sprang): Remove this include when all usage includes it directly.
|
||||
#include "api/video/video_bitrate_allocation.h"
|
||||
#include "rtc_base/checks.h"
|
||||
|
|
|
@ -54,8 +54,8 @@ absl::optional<VP9Profile> ParseSdpForVP9Profile(
|
|||
|
||||
bool IsSameVP9Profile(const SdpVideoFormat::Parameters& params1,
|
||||
const SdpVideoFormat::Parameters& params2) {
|
||||
const absl::optional<VP9Profile> profile = ParseSdpForVP9Profile(params1);
|
||||
const absl::optional<VP9Profile> other_profile =
|
||||
const rtc::Optional<VP9Profile> profile = ParseSdpForVP9Profile(params1);
|
||||
const rtc::Optional<VP9Profile> other_profile =
|
||||
ParseSdpForVP9Profile(params2);
|
||||
return profile && other_profile && profile == other_profile;
|
||||
}
|
||||
|
|
|
@ -34,12 +34,12 @@ TimeLimitedNetEqInput::TimeLimitedNetEqInput(std::unique_ptr<NetEqInput> input,
|
|||
start_time_ms_(input_->NextEventTime()),
|
||||
duration_ms_(duration_ms) {}
|
||||
|
||||
absl::optional<int64_t> TimeLimitedNetEqInput::NextPacketTime() const {
|
||||
return ended_ ? absl::nullopt : input_->NextPacketTime();
|
||||
rtc::Optional<int64_t> TimeLimitedNetEqInput::NextPacketTime() const {
|
||||
return ended_ ? rtc::Optional<int64_t>() : input_->NextPacketTime();
|
||||
}
|
||||
|
||||
absl::optional<int64_t> TimeLimitedNetEqInput::NextOutputEventTime() const {
|
||||
return ended_ ? absl::nullopt : input_->NextOutputEventTime();
|
||||
rtc::Optional<int64_t> TimeLimitedNetEqInput::NextOutputEventTime() const {
|
||||
return ended_ ? rtc::Optional<int64_t>() : input_->NextOutputEventTime();
|
||||
}
|
||||
|
||||
std::unique_ptr<NetEqInput::PacketData> TimeLimitedNetEqInput::PopPacket() {
|
||||
|
@ -62,8 +62,8 @@ bool TimeLimitedNetEqInput::ended() const {
|
|||
return ended_ || input_->ended();
|
||||
}
|
||||
|
||||
absl::optional<RTPHeader> TimeLimitedNetEqInput::NextHeader() const {
|
||||
return ended_ ? absl::nullopt : input_->NextHeader();
|
||||
rtc::Optional<RTPHeader> TimeLimitedNetEqInput::NextHeader() const {
|
||||
return ended_ ? rtc::Optional<RTPHeader>() : input_->NextHeader();
|
||||
}
|
||||
|
||||
void TimeLimitedNetEqInput::MaybeSetEnded() {
|
||||
|
|
|
@ -84,18 +84,18 @@ class NetEqInput {
|
|||
class TimeLimitedNetEqInput : public NetEqInput {
|
||||
public:
|
||||
TimeLimitedNetEqInput(std::unique_ptr<NetEqInput> input, int64_t duration_ms);
|
||||
absl::optional<int64_t> NextPacketTime() const override;
|
||||
absl::optional<int64_t> NextOutputEventTime() const override;
|
||||
rtc::Optional<int64_t> NextPacketTime() const override;
|
||||
rtc::Optional<int64_t> NextOutputEventTime() const override;
|
||||
std::unique_ptr<PacketData> PopPacket() override;
|
||||
void AdvanceOutputEvent() override;
|
||||
bool ended() const override;
|
||||
absl::optional<RTPHeader> NextHeader() const override;
|
||||
rtc::Optional<RTPHeader> NextHeader() const override;
|
||||
|
||||
private:
|
||||
void MaybeSetEnded();
|
||||
|
||||
std::unique_ptr<NetEqInput> input_;
|
||||
const absl::optional<int64_t> start_time_ms_;
|
||||
const rtc::Optional<int64_t> start_time_ms_;
|
||||
const int64_t duration_ms_;
|
||||
bool ended_ = false;
|
||||
};
|
||||
|
|
|
@ -42,8 +42,8 @@ class FrameGeneratorCapturerVideoTrackSource : public VideoTrackSource {
|
|||
FrameGeneratorCapturerVideoTrackSource(Config config, Clock* clock)
|
||||
: VideoTrackSource(false /* remote */) {
|
||||
video_capturer_.reset(test::FrameGeneratorCapturer::Create(
|
||||
config.width, config.height, absl::nullopt,
|
||||
config.num_squares_generated, config.frames_per_second, clock));
|
||||
config.width, config.height, rtc::nullopt, config.num_squares_generated,
|
||||
config.frames_per_second, clock));
|
||||
}
|
||||
|
||||
~FrameGeneratorCapturerVideoTrackSource() = default;
|
||||
|
|
Loading…
Reference in a new issue