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

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

Issue 1202153002: Add ListContainer::AppendByMoving (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Appease the compiler overlords with the gift of a type literal suffix 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
« cc/base/list_container.h ('K') | « cc/base/list_container.cc ('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 802 matching lines...) Expand 10 before | Expand all | Expand 10 after
813 check_equal(); // One full, one partially full, one empty. 813 check_equal(); // One full, one partially full, one empty.
814 pop(); 814 pop();
815 check_equal(); // One full, one empty. 815 check_equal(); // One full, one empty.
816 push(); 816 push();
817 pop(); 817 pop();
818 pop(); 818 pop();
819 ASSERT_TRUE(list.empty()); 819 ASSERT_TRUE(list.empty());
820 check_equal(); // Empty. 820 check_equal(); // Empty.
821 } 821 }
822 822
823 TEST(ListContainerTest, AppendByMovingSameList) {
824 ListContainer<SimpleDerivedElement> list(kCurrentLargestDerivedElementSize);
825 list.AllocateAndConstruct<SimpleDerivedElementConstructMagicNumberOne>();
826
827 list.AppendByMoving(list.front());
828 EXPECT_EQ(kMagicNumberToUseForSimpleDerivedElementOne,
829 list.back()->get_value());
830 EXPECT_EQ(2u, list.size());
831
832 list.front()->set_value(kMagicNumberToUseForSimpleDerivedElementTwo);
833 EXPECT_EQ(kMagicNumberToUseForSimpleDerivedElementTwo,
834 list.front()->get_value());
835 list.AppendByMoving(list.front());
836 EXPECT_EQ(kMagicNumberToUseForSimpleDerivedElementTwo,
837 list.back()->get_value());
838 EXPECT_EQ(3u, list.size());
839 }
840
841 TEST(ListContainerTest, AppendByMovingDoesNotDestruct) {
842 ListContainer<DerivedElement> list_1(kCurrentLargestDerivedElementSize);
843 ListContainer<DerivedElement> list_2(kCurrentLargestDerivedElementSize);
844 ListContainer<DerivedElement> list_3(kCurrentLargestDerivedElementSize);
845
846 MockDerivedElement* de_1 = list_1.AllocateAndConstruct<MockDerivedElement>();
847 list_2.AppendByMoving(de_1);
848 list_3.AppendByMoving(list_2.back());
849 list_3.AppendByMoving(list_3.back());
850
danakj 2015/06/23 20:01:12 Can you VerifyExpectations here that it wasn't des
pdr. 2015/06/23 21:42:42 Done.
851 EXPECT_CALL(*de_1, Destruct());
danakj 2015/06/23 20:01:12 Then do this as the last step in the test?
pdr. 2015/06/23 21:42:42 Done (Now the last step in a sequence.)
852 EXPECT_EQ(1u, list_1.size());
853 EXPECT_EQ(1u, list_2.size());
854 EXPECT_EQ(2u, list_3.size());
855 }
856
857 TEST(ListContainerTest, AppendByMovingReplacesSourceWithNewDerivedElement) {
858 ListContainer<SimpleDerivedElementConstructMagicNumberOne> list_1(
859 kCurrentLargestDerivedElementSize);
860 ListContainer<SimpleDerivedElementConstructMagicNumberTwo> list_2(
861 kCurrentLargestDerivedElementSize);
862
863 list_1.AllocateAndConstruct<SimpleDerivedElementConstructMagicNumberOne>();
864 EXPECT_EQ(kMagicNumberToUseForSimpleDerivedElementOne,
865 list_1.front()->get_value());
866
867 list_2.AppendByMoving(list_1.front());
868 EXPECT_EQ(kMagicNumberToUseForSimpleDerivedElementOne,
869 list_1.front()->get_value());
870 EXPECT_EQ(kMagicNumberToUseForSimpleDerivedElementOne,
871 list_2.front()->get_value());
872
873 list_1.AppendByMoving(list_2.back());
danakj 2015/06/23 20:01:13 Can you change the value of the item before moving
pdr. 2015/06/23 21:42:42 Done. I needed to add a new constant, kMagicNumbe
874 EXPECT_EQ(kMagicNumberToUseForSimpleDerivedElementOne,
875 list_1.front()->get_value());
876 EXPECT_EQ(kMagicNumberToUseForSimpleDerivedElementOne,
877 list_1.back()->get_value());
878 EXPECT_EQ(kMagicNumberToUseForSimpleDerivedElementTwo,
879 list_2.back()->get_value());
880
881 EXPECT_EQ(2u, list_1.size());
danakj 2015/06/23 20:01:13 Can you leave a comment explaining these numbers?
pdr. 2015/06/23 21:42:42 Done. The comment now reads: // AppendByMoving rep
882 EXPECT_EQ(1u, list_2.size());
883 }
884
885 const size_t kLongCountForLongSimpleDerivedElement = 5;
886 class LongSimpleDerivedElement : public SimpleDerivedElement {
danakj 2015/06/23 20:01:12 whitespace before the class
pdr. 2015/06/23 21:42:42 Done. The new whitespace looks like:
887 public:
888 ~LongSimpleDerivedElement() override {}
889 void set_all_values(unsigned long value) {
danakj 2015/06/23 20:01:12 SetAllValues
pdr. 2015/06/23 21:42:42 Done.
890 for (size_t i = 0; i < kLongCountForLongSimpleDerivedElement; i++)
891 values[i] = value;
892 }
893 bool all_values_equal_to(size_t value) const {
danakj 2015/06/23 20:01:12 AreAllValuesEqualTo
pdr. 2015/06/23 21:42:42 Done.
894 for (size_t i = 1; i < kLongCountForLongSimpleDerivedElement; i++) {
895 if (values[i] != values[0])
896 return false;
897 }
898 return true;
899 }
900
901 private:
902 unsigned long values[kLongCountForLongSimpleDerivedElement];
903 };
904
905 const unsigned long kMagicNumberToUseForLongSimpleDerivedElement = -1618ul;
danakj 2015/06/23 20:01:44 e:\b\build\slave\win\build\src\cc\base\list_contai
pdr. 2015/06/23 21:42:42 Done. I was hoping to use a value that would be s
906 class LongSimpleDerivedElementConstructMagicNumber
danakj 2015/06/23 20:01:12 whitespace before the class pls
pdr. 2015/06/23 21:42:42 Done.
907 : public LongSimpleDerivedElement {
908 public:
909 LongSimpleDerivedElementConstructMagicNumber() : LongSimpleDerivedElement() {
danakj 2015/06/23 20:01:13 you don't need to explicitly call default construc
pdr. 2015/06/23 21:42:42 Good catch. Fixed. I also updated SimpleDerivedEl
910 set_all_values(kMagicNumberToUseForLongSimpleDerivedElement);
911 }
912 };
913
914 TEST(ListContainerTest, AppendByMovingLongAndSimpleDerivedElements) {
915 static_assert(sizeof(LongSimpleDerivedElement) > sizeof(SimpleDerivedElement),
916 "LongSimpleDerivedElement should be larger than "
917 "SimpleDerivedElement's size.");
918 static_assert(sizeof(LongSimpleDerivedElement) <= kLargestDerivedElementSize,
919 "LongSimpleDerivedElement should be smaller than the maximum "
920 "DerivedElement size.");
921
922 ListContainer<SimpleDerivedElement> list(kCurrentLargestDerivedElementSize);
923 list.AllocateAndConstruct<LongSimpleDerivedElementConstructMagicNumber>();
924 list.AllocateAndConstruct<SimpleDerivedElementConstructMagicNumberOne>();
925
926 EXPECT_TRUE(
927 static_cast<LongSimpleDerivedElement*>(list.front())
928 ->all_values_equal_to(kMagicNumberToUseForLongSimpleDerivedElement));
929 EXPECT_EQ(kMagicNumberToUseForSimpleDerivedElementOne,
930 list.back()->get_value());
931
932 SimpleDerivedElement* simple_element = list.back();
933 list.AppendByMoving(list.front());
danakj 2015/06/23 20:01:12 Can you comment explaining what you are testing he
pdr. 2015/06/23 21:42:42 Done. The comment now reads: // Test that moving a
934 EXPECT_TRUE(
935 static_cast<LongSimpleDerivedElement*>(list.back())
936 ->all_values_equal_to(kMagicNumberToUseForLongSimpleDerivedElement));
937 EXPECT_EQ(kMagicNumberToUseForSimpleDerivedElementOne,
938 simple_element->get_value());
939
940 LongSimpleDerivedElement* long_element =
941 static_cast<LongSimpleDerivedElement*>(list.back());
942 list.AppendByMoving(simple_element);
943 EXPECT_TRUE(long_element->all_values_equal_to(
944 kMagicNumberToUseForLongSimpleDerivedElement));
945 EXPECT_EQ(kMagicNumberToUseForSimpleDerivedElementOne,
946 list.back()->get_value());
947 }
948
823 } // namespace 949 } // namespace
824 } // namespace cc 950 } // namespace cc
OLDNEW
« cc/base/list_container.h ('K') | « cc/base/list_container.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698