Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "cc/base/list_container.h" | 5 #include "cc/base/list_container.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 #include "cc/quads/draw_quad.h" | 8 #include "cc/quads/draw_quad.h" |
| 9 #include "cc/quads/largest_draw_quad.h" | 9 #include "cc/quads/largest_draw_quad.h" |
| 10 #include "cc/quads/render_pass_draw_quad.h" | 10 #include "cc/quads/render_pass_draw_quad.h" |
| (...skipping 632 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 643 } | 643 } |
| 644 | 644 |
| 645 i = 0; | 645 i = 0; |
| 646 for (ListContainer<SharedQuadState>::ReverseIterator iter = list.rbegin(); | 646 for (ListContainer<SharedQuadState>::ReverseIterator iter = list.rbegin(); |
| 647 iter != list.rend(); ++iter) { | 647 iter != list.rend(); ++iter) { |
| 648 EXPECT_EQ(i, iter.index()); | 648 EXPECT_EQ(i, iter.index()); |
| 649 ++i; | 649 ++i; |
| 650 } | 650 } |
| 651 } | 651 } |
| 652 | 652 |
| 653 // Increments an int when constructed (or the counter pointer is supplied) and | |
| 654 // decrements when destructed. | |
| 655 class InstanceCounter { | |
| 656 public: | |
| 657 InstanceCounter() : counter_(nullptr) {} | |
| 658 explicit InstanceCounter(int* counter) { SetCounter(counter); } | |
| 659 ~InstanceCounter() { | |
| 660 if (counter_) | |
| 661 --*counter_; | |
| 662 } | |
| 663 void SetCounter(int* counter) { | |
| 664 counter_ = counter; | |
| 665 ++*counter_; | |
| 666 } | |
| 667 | |
| 668 private: | |
| 669 int* counter_; | |
| 670 }; | |
| 671 | |
| 672 TEST(ListContainerTest, RemoveLast) { | |
|
jbroman
2015/06/02 19:36:19
Note that this will probably collide with a Samsun
| |
| 673 // We keep an explicit instance count to make sure that the destructors are | |
| 674 // indeed getting called. | |
| 675 int counter = 0; | |
| 676 ListContainer<InstanceCounter> list(sizeof(InstanceCounter), 1); | |
| 677 EXPECT_EQ(0, counter); | |
| 678 EXPECT_EQ(0u, list.size()); | |
| 679 | |
| 680 // We should be okay to add one and then go back to zero. | |
| 681 list.AllocateAndConstruct<InstanceCounter>()->SetCounter(&counter); | |
| 682 EXPECT_EQ(1, counter); | |
| 683 EXPECT_EQ(1u, list.size()); | |
| 684 list.RemoveLast(); | |
| 685 EXPECT_EQ(0, counter); | |
| 686 EXPECT_EQ(0u, list.size()); | |
| 687 | |
| 688 // We should also be okay to remove the last multiple times, as long as there | |
|
danakj
2015/06/02 20:04:32
Can you add a test where you append one past a new
| |
| 689 // are enough elements in the first place. | |
| 690 list.AllocateAndConstruct<InstanceCounter>()->SetCounter(&counter); | |
| 691 list.AllocateAndConstruct<InstanceCounter>()->SetCounter(&counter); | |
| 692 list.AllocateAndConstruct<InstanceCounter>()->SetCounter(&counter); | |
| 693 list.AllocateAndConstruct<InstanceCounter>()->SetCounter(&counter); | |
| 694 list.AllocateAndConstruct<InstanceCounter>()->SetCounter(&counter); | |
| 695 list.AllocateAndConstruct<InstanceCounter>()->SetCounter(&counter); | |
| 696 list.RemoveLast(); | |
| 697 list.RemoveLast(); | |
| 698 EXPECT_EQ(4, counter); // Leaves one in the last list. | |
| 699 EXPECT_EQ(4u, list.size()); | |
| 700 list.RemoveLast(); | |
| 701 EXPECT_EQ(3, counter); // Removes an inner list from before. | |
| 702 EXPECT_EQ(3u, list.size()); | |
| 703 } | |
| 704 | |
| 653 } // namespace | 705 } // namespace |
| 654 } // namespace cc | 706 } // namespace cc |
| OLD | NEW |