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

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

Issue 2432393002: Add rtc::Optional equality/unequality comparisions with object (Closed)
Patch Set: Feedback Created 4 years, 2 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
« no previous file with comments | « webrtc/base/optional.h ('k') | 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 /* 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 638 matching lines...) Expand 10 before | Expand all | Expand 10 after
649 V("0:17. explicit constructor", "1:42. explicit constructor", 649 V("0:17. explicit constructor", "1:42. explicit constructor",
650 "2:17. copy constructor (from 0:17)", 650 "2:17. copy constructor (from 0:17)",
651 "3:17. copy constructor (from 0:17)", 651 "3:17. copy constructor (from 0:17)",
652 "4:42. copy constructor (from 1:42)", "---", "operator== 2:17, 2:17", 652 "4:42. copy constructor (from 1:42)", "---", "operator== 2:17, 2:17",
653 "operator== 2:17, 3:17", "operator!= 2:17, 4:42", "---", 653 "operator== 2:17, 3:17", "operator!= 2:17, 4:42", "---",
654 "4:42. destructor", "3:17. destructor", "2:17. destructor", 654 "4:42. destructor", "3:17. destructor", "2:17. destructor",
655 "1:42. destructor", "0:17. destructor"), 655 "1:42. destructor", "0:17. destructor"),
656 *log); 656 *log);
657 } 657 }
658 658
659 TEST(OptionalTest, TestEqualityWithObject) {
660 auto log = Logger::Setup();
661 {
662 Logger a(17), b(42);
663 Optional<Logger> ma(a), me;
664 // Using operator== and operator!= explicetly instead of EXPECT_EQ/EXPECT_NE
665 // macros because those operators are under test.
666 log->push_back("---");
667
668 EXPECT_TRUE(ma == a);
669 EXPECT_TRUE(a == ma);
670 EXPECT_FALSE(ma == b);
671 EXPECT_FALSE(b == ma);
672 EXPECT_FALSE(me == a);
673 EXPECT_FALSE(a == me);
674
675 EXPECT_FALSE(ma != a);
676 EXPECT_FALSE(a != ma);
677 EXPECT_TRUE(ma != b);
678 EXPECT_TRUE(b != ma);
679 EXPECT_TRUE(me != a);
680 EXPECT_TRUE(a != me);
681
682 log->push_back("---");
683 }
684 // clang-format off
685 EXPECT_EQ(V("0:17. explicit constructor",
686 "1:42. explicit constructor",
687 "2:17. copy constructor (from 0:17)",
688 "---",
689 "operator== 2:17, 0:17",
690 "operator== 0:17, 2:17",
691 "operator== 2:17, 1:42",
692 "operator== 1:42, 2:17",
693 // No operator should be called when comparing to empty.
694 "operator!= 2:17, 0:17",
695 "operator!= 0:17, 2:17",
696 "operator!= 2:17, 1:42",
697 "operator!= 1:42, 2:17",
698 // No operator should be called when comparing to empty.
699 "---",
700 "2:17. destructor",
701 "1:42. destructor",
702 "0:17. destructor"),
703 *log);
704 // clang-format on
705 }
706
659 TEST(OptionalTest, TestSwap) { 707 TEST(OptionalTest, TestSwap) {
660 auto log = Logger::Setup(); 708 auto log = Logger::Setup();
661 { 709 {
662 Logger a(17), b(42); 710 Logger a(17), b(42);
663 Optional<Logger> x1(a), x2(b), y1(a), y2, z1, z2; 711 Optional<Logger> x1(a), x2(b), y1(a), y2, z1, z2;
664 log->push_back("---"); 712 log->push_back("---");
665 swap(x1, x2); // Swap full <-> full. 713 swap(x1, x2); // Swap full <-> full.
666 swap(y1, y2); // Swap full <-> empty. 714 swap(y1, y2); // Swap full <-> empty.
667 swap(z1, z2); // Swap empty <-> empty. 715 swap(z1, z2); // Swap empty <-> empty.
668 log->push_back("---"); 716 log->push_back("---");
669 } 717 }
670 EXPECT_EQ(V("0:17. explicit constructor", "1:42. explicit constructor", 718 EXPECT_EQ(V("0:17. explicit constructor", "1:42. explicit constructor",
671 "2:17. copy constructor (from 0:17)", 719 "2:17. copy constructor (from 0:17)",
672 "3:42. copy constructor (from 1:42)", 720 "3:42. copy constructor (from 1:42)",
673 "4:17. copy constructor (from 0:17)", "---", "swap 2:42, 3:17", 721 "4:17. copy constructor (from 0:17)", "---", "swap 2:42, 3:17",
674 "5:17. move constructor (from 4:17)", "4:17. destructor", "---", 722 "5:17. move constructor (from 4:17)", "4:17. destructor", "---",
675 "5:17. destructor", "3:17. destructor", "2:42. destructor", 723 "5:17. destructor", "3:17. destructor", "2:42. destructor",
676 "1:42. destructor", "0:17. destructor"), 724 "1:42. destructor", "0:17. destructor"),
677 *log); 725 *log);
678 } 726 }
679 727
680 } // namespace rtc 728 } // namespace rtc
OLDNEW
« no previous file with comments | « webrtc/base/optional.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698