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

Side by Side Diff: base/optional_unittest.cc

Issue 2437313002: base::Optional operator bool doesn't convert to bool. (Closed)
Patch Set: Created 4 years, 1 month 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/optional.h" 5 #include "base/optional.h"
6 6
7 #include <set> 7 #include <set>
8 8
9 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 10
(...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after
434 EXPECT_EQ(0.1f, *Optional<float>(0.1f)); 434 EXPECT_EQ(0.1f, *Optional<float>(0.1f));
435 EXPECT_EQ(std::string("foo"), *Optional<std::string>("foo")); 435 EXPECT_EQ(std::string("foo"), *Optional<std::string>("foo"));
436 EXPECT_TRUE(TestObject(3, 0.1) == *Optional<TestObject>(TestObject(3, 0.1))); 436 EXPECT_TRUE(TestObject(3, 0.1) == *Optional<TestObject>(TestObject(3, 0.1)));
437 } 437 }
438 438
439 TEST(OptionalTest, OperatorArrow) { 439 TEST(OptionalTest, OperatorArrow) {
440 Optional<TestObject> a(TestObject(3, 0.1)); 440 Optional<TestObject> a(TestObject(3, 0.1));
441 EXPECT_EQ(a->foo(), 3); 441 EXPECT_EQ(a->foo(), 3);
442 } 442 }
443 443
444 TEST(OptionalTest, OperatorBool) {
445 {
446 Optional<TestObject> a;
447 EXPECT_EQ(static_cast<bool>(a), false); // works.
448 }
449
450 {
451 Optional<TestObject> a;
452 bool b = !!a; // works.
453 EXPECT_EQ(b, false);
454 }
455
456 {
457 Optional<TestObject> a;
458 bool b = a;
459 // error: no viable conversion from
460 // 'Optional<base::(anonymous namespace)::TestObject>' to 'bool'
461 EXPECT_EQ(b, false);
462 }
463
464 // More to add here... testing true etc.
465 }
466
444 TEST(OptionalTest, Value_rvalue) { 467 TEST(OptionalTest, Value_rvalue) {
445 EXPECT_EQ(0.1f, Optional<float>(0.1f).value()); 468 EXPECT_EQ(0.1f, Optional<float>(0.1f).value());
446 EXPECT_EQ(std::string("foo"), Optional<std::string>("foo").value()); 469 EXPECT_EQ(std::string("foo"), Optional<std::string>("foo").value());
447 EXPECT_TRUE(TestObject(3, 0.1) == 470 EXPECT_TRUE(TestObject(3, 0.1) ==
448 Optional<TestObject>(TestObject(3, 0.1)).value()); 471 Optional<TestObject>(TestObject(3, 0.1)).value());
449 } 472 }
450 473
451 TEST(OptionalTest, ValueOr) { 474 TEST(OptionalTest, ValueOr) {
452 { 475 {
453 Optional<float> a; 476 Optional<float> a;
(...skipping 883 matching lines...) Expand 10 before | Expand all | Expand 10 after
1337 1360
1338 TEST(OptionalTest, Reset_NoOp) { 1361 TEST(OptionalTest, Reset_NoOp) {
1339 Optional<int> a; 1362 Optional<int> a;
1340 EXPECT_FALSE(a.has_value()); 1363 EXPECT_FALSE(a.has_value());
1341 1364
1342 a.reset(); 1365 a.reset();
1343 EXPECT_FALSE(a.has_value()); 1366 EXPECT_FALSE(a.has_value());
1344 } 1367 }
1345 1368
1346 } // namespace base 1369 } // namespace base
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698