| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include "SkTArray.h" | 8 #include "SkTArray.h" |
| 9 #include "Test.h" | 9 #include "Test.h" |
| 10 | 10 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 // { 0, 1, 2, 3 }, remove a middle, note shuffle | 51 // { 0, 1, 2, 3 }, remove a middle, note shuffle |
| 52 a.removeShuffle(1); | 52 a.removeShuffle(1); |
| 53 REPORTER_ASSERT(reporter, a.count() == SK_ARRAY_COUNT(b) - 2); | 53 REPORTER_ASSERT(reporter, a.count() == SK_ARRAY_COUNT(b) - 2); |
| 54 REPORTER_ASSERT(reporter, a[0] == 0); | 54 REPORTER_ASSERT(reporter, a[0] == 0); |
| 55 REPORTER_ASSERT(reporter, a[1] == 3); | 55 REPORTER_ASSERT(reporter, a[1] == 3); |
| 56 REPORTER_ASSERT(reporter, a[2] == 2); | 56 REPORTER_ASSERT(reporter, a[2] == 2); |
| 57 | 57 |
| 58 // {0, 3, 2 } | 58 // {0, 3, 2 } |
| 59 } | 59 } |
| 60 | 60 |
| 61 static void test_swap(skiatest::Reporter* reporter) { | 61 template <typename T> static void test_swap(skiatest::Reporter* reporter, |
| 62 SkTArray<int> arr; | 62 SkTArray<T>* (&arrays)[4], |
| 63 SkSTArray< 5, int> arr5; | 63 int (&sizes)[7]) |
| 64 SkSTArray<10, int> arr10; | 64 { |
| 65 SkSTArray<20, int> arr20; | |
| 66 | |
| 67 SkTArray<int>* arrays[] = { &arr, &arr5, &arr10, &arr20 }; | |
| 68 int sizes[] = {0, 1, 5, 10, 15, 20, 25}; | |
| 69 | |
| 70 for (auto a : arrays) { | 65 for (auto a : arrays) { |
| 71 for (auto b : arrays) { | 66 for (auto b : arrays) { |
| 72 if (a == b) { | 67 if (a == b) { |
| 73 continue; | 68 continue; |
| 74 } | 69 } |
| 75 | 70 |
| 76 for (auto sizeA : sizes) { | 71 for (auto sizeA : sizes) { |
| 77 for (auto sizeB : sizes) { | 72 for (auto sizeB : sizes) { |
| 78 a->reset(); | 73 a->reset(); |
| 79 b->reset(); | 74 b->reset(); |
| 80 | 75 |
| 81 int curr = 0; | 76 int curr = 0; |
| 82 for (int i = 0; i < sizeA; i++) { a->push_back(curr++); } | 77 for (int i = 0; i < sizeA; i++) { a->push_back(curr++); } |
| 83 for (int i = 0; i < sizeB; i++) { b->push_back(curr++); } | 78 for (int i = 0; i < sizeB; i++) { b->push_back(curr++); } |
| 84 | 79 |
| 85 a->swap(b); | 80 a->swap(b); |
| 86 REPORTER_ASSERT(reporter, b->count() == sizeA); | 81 REPORTER_ASSERT(reporter, b->count() == sizeA); |
| 87 REPORTER_ASSERT(reporter, a->count() == sizeB); | 82 REPORTER_ASSERT(reporter, a->count() == sizeB); |
| 88 | 83 |
| 89 curr = 0; | 84 curr = 0; |
| 90 for (int x : *b) { REPORTER_ASSERT(reporter, x == curr++); } | 85 for (auto&& x : *b) { REPORTER_ASSERT(reporter, x == curr++); } |
| 91 for (int x : *a) { REPORTER_ASSERT(reporter, x == curr++); } | 86 for (auto&& x : *a) { REPORTER_ASSERT(reporter, x == curr++); } |
| 92 | 87 |
| 93 a->swap(a); | 88 a->swap(a); |
| 94 curr = sizeA; | 89 curr = sizeA; |
| 95 for (int x : *a) { REPORTER_ASSERT(reporter, x == curr++); } | 90 for (auto&& x : *a) { REPORTER_ASSERT(reporter, x == curr++); } |
| 96 }} | 91 }} |
| 97 }} | 92 }} |
| 98 } | 93 } |
| 99 | 94 |
| 95 static void test_swap(skiatest::Reporter* reporter) { |
| 96 int sizes[] = {0, 1, 5, 10, 15, 20, 25}; |
| 97 |
| 98 SkTArray<int> arr; |
| 99 SkSTArray< 5, int> arr5; |
| 100 SkSTArray<10, int> arr10; |
| 101 SkSTArray<20, int> arr20; |
| 102 SkTArray<int>* arrays[] = { &arr, &arr5, &arr10, &arr20 }; |
| 103 test_swap(reporter, arrays, sizes); |
| 104 |
| 105 struct MoveOnlyInt { |
| 106 MoveOnlyInt(int i) : fInt(i) {} |
| 107 MoveOnlyInt(MoveOnlyInt&& that) : fInt(that.fInt) {} |
| 108 bool operator==(int i) { return fInt == i; } |
| 109 int fInt; |
| 110 }; |
| 111 |
| 112 SkTArray<MoveOnlyInt> moi; |
| 113 SkSTArray< 5, MoveOnlyInt> moi5; |
| 114 SkSTArray<10, MoveOnlyInt> moi10; |
| 115 SkSTArray<20, MoveOnlyInt> moi20; |
| 116 SkTArray<MoveOnlyInt>* arraysMoi[] = { &moi, &moi5, &moi10, &moi20 }; |
| 117 test_swap(reporter, arraysMoi, sizes); |
| 118 } |
| 119 |
| 100 DEF_TEST(TArray, reporter) { | 120 DEF_TEST(TArray, reporter) { |
| 101 TestTSet_basic<true>(reporter); | 121 TestTSet_basic<true>(reporter); |
| 102 TestTSet_basic<false>(reporter); | 122 TestTSet_basic<false>(reporter); |
| 103 test_swap(reporter); | 123 test_swap(reporter); |
| 104 } | 124 } |
| OLD | NEW |