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

Side by Side Diff: cc/base/list_container_unittest.cc

Issue 1199343004: Add ListContainer::swap (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 6 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 | « cc/base/list_container.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 // 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 "testing/gmock/include/gmock/gmock.h" 8 #include "testing/gmock/include/gmock/gmock.h"
9 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 10
(...skipping 863 matching lines...) Expand 10 before | Expand all | Expand 10 after
874 list_1.AppendByMoving(list_2.back()); 874 list_1.AppendByMoving(list_2.back());
875 EXPECT_EQ(kMagicNumberToUseForSimpleDerivedElementOne, 875 EXPECT_EQ(kMagicNumberToUseForSimpleDerivedElementOne,
876 list_1.front()->get_value()); 876 list_1.front()->get_value());
877 EXPECT_EQ(kMagicNumberToUseForSimpleDerivedElementThree, 877 EXPECT_EQ(kMagicNumberToUseForSimpleDerivedElementThree,
878 list_1.back()->get_value()); 878 list_1.back()->get_value());
879 EXPECT_EQ(kMagicNumberToUseForSimpleDerivedElementTwo, 879 EXPECT_EQ(kMagicNumberToUseForSimpleDerivedElementTwo,
880 list_2.back()->get_value()); 880 list_2.back()->get_value());
881 881
882 // AppendByMoving replaces the source element with a new derived element so 882 // AppendByMoving replaces the source element with a new derived element so
883 // we do not expect sizes to shrink after AppendByMoving is called. 883 // we do not expect sizes to shrink after AppendByMoving is called.
884 EXPECT_EQ(2u, 884 EXPECT_EQ(2u, list_1.size()); // One direct allocation, one AppendByMoving.
danakj 2015/06/24 17:53:11 teehee
885 list_1.size()); // One direct allocation and one AppendByMoving.
886 EXPECT_EQ(1u, list_2.size()); // One AppendByMoving. 885 EXPECT_EQ(1u, list_2.size()); // One AppendByMoving.
887 } 886 }
888 887
889 const size_t kLongCountForLongSimpleDerivedElement = 5; 888 const size_t kLongCountForLongSimpleDerivedElement = 5;
890 889
891 class LongSimpleDerivedElement : public SimpleDerivedElement { 890 class LongSimpleDerivedElement : public SimpleDerivedElement {
892 public: 891 public:
893 ~LongSimpleDerivedElement() override {} 892 ~LongSimpleDerivedElement() override {}
894 void SetAllValues(unsigned long value) { 893 void SetAllValues(unsigned long value) {
895 for (size_t i = 0; i < kLongCountForLongSimpleDerivedElement; i++) 894 for (size_t i = 0; i < kLongCountForLongSimpleDerivedElement; i++)
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
947 946
948 LongSimpleDerivedElement* long_element = 947 LongSimpleDerivedElement* long_element =
949 static_cast<LongSimpleDerivedElement*>(list.back()); 948 static_cast<LongSimpleDerivedElement*>(list.back());
950 list.AppendByMoving(simple_element); 949 list.AppendByMoving(simple_element);
951 EXPECT_TRUE(long_element->AreAllValuesEqualTo( 950 EXPECT_TRUE(long_element->AreAllValuesEqualTo(
952 kMagicNumberToUseForLongSimpleDerivedElement)); 951 kMagicNumberToUseForLongSimpleDerivedElement));
953 EXPECT_EQ(kMagicNumberToUseForSimpleDerivedElementOne, 952 EXPECT_EQ(kMagicNumberToUseForSimpleDerivedElementOne,
954 list.back()->get_value()); 953 list.back()->get_value());
955 } 954 }
956 955
956 TEST(ListContainerTest, Swap) {
957 ListContainer<SimpleDerivedElement> list_1(kCurrentLargestDerivedElementSize);
958 list_1.AllocateAndConstruct<SimpleDerivedElementConstructMagicNumberOne>();
959 ListContainer<SimpleDerivedElement> list_2(kCurrentLargestDerivedElementSize);
960 list_2.AllocateAndConstruct<SimpleDerivedElementConstructMagicNumberTwo>();
961 list_2.AllocateAndConstruct<SimpleDerivedElementConstructMagicNumberTwo>();
962
963 SimpleDerivedElement* pre_swap_list_1_front = list_1.front();
964
965 EXPECT_EQ(kMagicNumberToUseForSimpleDerivedElementOne,
966 list_1.front()->get_value());
chrishtr 2015/06/24 17:52:52 Why not check back() also?
967 EXPECT_EQ(kMagicNumberToUseForSimpleDerivedElementTwo,
968 list_2.front()->get_value());
969 EXPECT_EQ(kMagicNumberToUseForSimpleDerivedElementTwo,
970 list_2.back()->get_value());
971 EXPECT_EQ(1u, list_1.size());
972 EXPECT_EQ(2u, list_2.size());
973
974 list_2.swap(list_1);
975
976 EXPECT_EQ(kMagicNumberToUseForSimpleDerivedElementTwo,
977 list_1.front()->get_value());
978 EXPECT_EQ(kMagicNumberToUseForSimpleDerivedElementTwo,
979 list_1.back()->get_value());
980 EXPECT_EQ(kMagicNumberToUseForSimpleDerivedElementOne,
981 list_2.front()->get_value());
982 EXPECT_EQ(kMagicNumberToUseForSimpleDerivedElementOne,
983 list_2.back()->get_value());
danakj 2015/06/24 17:53:11 no need to check back here, since the size is 1 (v
984 EXPECT_EQ(2u, list_1.size());
985 EXPECT_EQ(1u, list_2.size());
986
987 // Ensure pointers are still valid after swapping.
988 EXPECT_EQ(pre_swap_list_1_front, list_2.front());
989 }
990
957 } // namespace 991 } // namespace
958 } // namespace cc 992 } // namespace cc
OLDNEW
« no previous file with comments | « cc/base/list_container.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698