OLD | NEW |
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 |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 return strings; | 149 return strings; |
150 } | 150 } |
151 | 151 |
152 } // namespace | 152 } // namespace |
153 | 153 |
154 TEST(OptionalTest, TestConstructDefault) { | 154 TEST(OptionalTest, TestConstructDefault) { |
155 auto log = Logger::Setup(); | 155 auto log = Logger::Setup(); |
156 { | 156 { |
157 Optional<Logger> x; | 157 Optional<Logger> x; |
158 EXPECT_FALSE(x); | 158 EXPECT_FALSE(x); |
| 159 EXPECT_FALSE(x.has_value()); |
159 } | 160 } |
160 EXPECT_EQ(V(), *log); | 161 EXPECT_EQ(V(), *log); |
161 } | 162 } |
162 | 163 |
163 TEST(OptionalTest, TestConstructCopyEmpty) { | 164 TEST(OptionalTest, TestConstructCopyEmpty) { |
164 auto log = Logger::Setup(); | 165 auto log = Logger::Setup(); |
165 { | 166 { |
166 Optional<Logger> x; | 167 Optional<Logger> x; |
167 EXPECT_FALSE(x); | 168 EXPECT_FALSE(x); |
| 169 EXPECT_FALSE(x.has_value()); |
168 auto y = x; | 170 auto y = x; |
169 EXPECT_FALSE(y); | 171 EXPECT_FALSE(y); |
| 172 EXPECT_FALSE(y.has_value()); |
170 } | 173 } |
171 EXPECT_EQ(V(), *log); | 174 EXPECT_EQ(V(), *log); |
172 } | 175 } |
173 | 176 |
174 TEST(OptionalTest, TestConstructCopyFull) { | 177 TEST(OptionalTest, TestConstructCopyFull) { |
175 auto log = Logger::Setup(); | 178 auto log = Logger::Setup(); |
176 { | 179 { |
177 Logger a; | 180 Logger a; |
178 Optional<Logger> x(a); | 181 Optional<Logger> x(a); |
179 EXPECT_TRUE(x); | 182 EXPECT_TRUE(x); |
| 183 EXPECT_TRUE(x.has_value()); |
180 log->push_back("---"); | 184 log->push_back("---"); |
181 auto y = x; | 185 auto y = x; |
182 EXPECT_TRUE(y); | 186 EXPECT_TRUE(y); |
| 187 EXPECT_TRUE(y.has_value()); |
183 log->push_back("---"); | 188 log->push_back("---"); |
184 } | 189 } |
185 EXPECT_EQ(V("0:0. default constructor", "1:0. copy constructor (from 0:0)", | 190 EXPECT_EQ(V("0:0. default constructor", "1:0. copy constructor (from 0:0)", |
186 "---", "2:0. copy constructor (from 1:0)", "---", | 191 "---", "2:0. copy constructor (from 1:0)", "---", |
187 "2:0. destructor", "1:0. destructor", "0:0. destructor"), | 192 "2:0. destructor", "1:0. destructor", "0:0. destructor"), |
188 *log); | 193 *log); |
189 } | 194 } |
190 | 195 |
191 TEST(OptionalTest, TestConstructMoveEmpty) { | 196 TEST(OptionalTest, TestConstructMoveEmpty) { |
192 auto log = Logger::Setup(); | 197 auto log = Logger::Setup(); |
193 { | 198 { |
194 Optional<Logger> x; | 199 Optional<Logger> x; |
195 EXPECT_FALSE(x); | 200 EXPECT_FALSE(x); |
| 201 EXPECT_FALSE(x.has_value()); |
196 auto y = std::move(x); | 202 auto y = std::move(x); |
197 EXPECT_FALSE(y); | 203 EXPECT_FALSE(y); |
| 204 EXPECT_FALSE(y.has_value()); |
198 } | 205 } |
199 EXPECT_EQ(V(), *log); | 206 EXPECT_EQ(V(), *log); |
200 } | 207 } |
201 | 208 |
202 TEST(OptionalTest, TestConstructMoveFull) { | 209 TEST(OptionalTest, TestConstructMoveFull) { |
203 auto log = Logger::Setup(); | 210 auto log = Logger::Setup(); |
204 { | 211 { |
205 Optional<Logger> x(Logger(17)); | 212 Optional<Logger> x(Logger(17)); |
206 EXPECT_TRUE(x); | 213 EXPECT_TRUE(x); |
| 214 EXPECT_TRUE(x.has_value()); |
207 log->push_back("---"); | 215 log->push_back("---"); |
208 auto y = std::move(x); | 216 auto y = std::move(x); |
209 EXPECT_TRUE(x); | 217 EXPECT_TRUE(x); |
| 218 EXPECT_TRUE(x.has_value()); |
210 EXPECT_TRUE(y); | 219 EXPECT_TRUE(y); |
| 220 EXPECT_TRUE(y.has_value()); |
211 log->push_back("---"); | 221 log->push_back("---"); |
212 } | 222 } |
213 EXPECT_EQ( | 223 EXPECT_EQ( |
214 V("0:17. explicit constructor", "1:17. move constructor (from 0:17)", | 224 V("0:17. explicit constructor", "1:17. move constructor (from 0:17)", |
215 "0:17. destructor", "---", "2:17. move constructor (from 1:17)", "---", | 225 "0:17. destructor", "---", "2:17. move constructor (from 1:17)", "---", |
216 "2:17. destructor", "1:17. destructor"), | 226 "2:17. destructor", "1:17. destructor"), |
217 *log); | 227 *log); |
218 } | 228 } |
219 | 229 |
220 TEST(OptionalTest, TestCopyAssignToEmptyFromEmpty) { | 230 TEST(OptionalTest, TestCopyAssignToEmptyFromEmpty) { |
(...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
614 x->Foo(); | 624 x->Foo(); |
615 y->Foo(); | 625 y->Foo(); |
616 std::move(x)->Foo(); | 626 std::move(x)->Foo(); |
617 std::move(y)->Foo(); | 627 std::move(y)->Foo(); |
618 log->push_back("---"); | 628 log->push_back("---"); |
619 (*x).Foo(); | 629 (*x).Foo(); |
620 (*y).Foo(); | 630 (*y).Foo(); |
621 (*std::move(x)).Foo(); | 631 (*std::move(x)).Foo(); |
622 (*std::move(y)).Foo(); | 632 (*std::move(y)).Foo(); |
623 log->push_back("---"); | 633 log->push_back("---"); |
| 634 x.value().Foo(); |
| 635 y.value().Foo(); |
| 636 std::move(x).value().Foo(); |
| 637 std::move(y).value().Foo(); |
| 638 log->push_back("---"); |
624 } | 639 } |
| 640 // clang-format off |
625 EXPECT_EQ(V("0:42. explicit constructor", | 641 EXPECT_EQ(V("0:42. explicit constructor", |
626 "1:42. move constructor (from 0:42)", "0:42. destructor", "---", | 642 "1:42. move constructor (from 0:42)", |
627 "1:42. Foo()", "1:42. Foo() const", "1:42. Foo()", | 643 "0:42. destructor", |
628 "1:42. Foo() const", "---", "1:42. Foo()", "1:42. Foo() const", | 644 "---", |
629 "1:42. Foo()", "1:42. Foo() const", "---", "1:42. destructor"), | 645 "1:42. Foo()", |
| 646 "1:42. Foo() const", |
| 647 "1:42. Foo()", |
| 648 "1:42. Foo() const", |
| 649 "---", |
| 650 "1:42. Foo()", |
| 651 "1:42. Foo() const", |
| 652 "1:42. Foo()", |
| 653 "1:42. Foo() const", |
| 654 "---", |
| 655 "1:42. Foo()", |
| 656 "1:42. Foo() const", |
| 657 "1:42. Foo()", |
| 658 "1:42. Foo() const", |
| 659 "---", |
| 660 "1:42. destructor"), |
630 *log); | 661 *log); |
| 662 // clang-format on |
631 } | 663 } |
632 | 664 |
633 TEST(OptionalTest, TestDereferenceWithDefault) { | 665 TEST(OptionalTest, TestDereferenceWithDefault) { |
634 auto log = Logger::Setup(); | 666 auto log = Logger::Setup(); |
635 { | 667 { |
636 const Logger a(17), b(42); | 668 const Logger a(17), b(42); |
637 Optional<Logger> x(a); | 669 Optional<Logger> x(a); |
638 Optional<Logger> y; | 670 Optional<Logger> y; |
639 log->push_back("-1-"); | 671 log->push_back("-1-"); |
640 EXPECT_EQ(a, x.value_or(Logger(42))); | 672 EXPECT_EQ(a, x.value_or(Logger(42))); |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
790 // for MyPrintableType never getting called. | 822 // for MyPrintableType never getting called. |
791 const MyPrintableType dont_warn{17}; | 823 const MyPrintableType dont_warn{17}; |
792 const MyOstreamPrintableType dont_warn2{18}; | 824 const MyOstreamPrintableType dont_warn2{18}; |
793 std::stringstream sstr; | 825 std::stringstream sstr; |
794 sstr << dont_warn; | 826 sstr << dont_warn; |
795 PrintTo(dont_warn, &sstr); | 827 PrintTo(dont_warn, &sstr); |
796 sstr << dont_warn2; | 828 sstr << dont_warn2; |
797 } | 829 } |
798 | 830 |
799 } // namespace rtc | 831 } // namespace rtc |
OLD | NEW |