| 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 namespace { | 61 static void test_swap(skiatest::Reporter* reporter) { |
| 62 SkTArray<int>* make() { | 62 SkTArray<int> arr; |
| 63 typedef SkTArray<int> IntArray; | 63 SkSTArray< 5, int> arr5; |
| 64 return new IntArray; | 64 SkSTArray<10, int> arr10; |
| 65 } | 65 SkSTArray<20, int> arr20; |
| 66 | 66 |
| 67 template <int N> SkTArray<int>* make_s() { | 67 SkTArray<int>* arrays[] = { &arr, &arr5, &arr10, &arr20 }; |
| 68 typedef SkSTArray<N, int> IntArray; | 68 int sizes[] = {0, 1, 5, 10, 15, 20, 25}; |
| 69 return new IntArray; | |
| 70 } | |
| 71 } | |
| 72 | 69 |
| 73 static void test_swap(skiatest::Reporter* reporter) { | 70 for (auto a : arrays) { |
| 74 typedef SkTArray<int>* (*ArrayMaker)(); | 71 for (auto b : arrays) { |
| 75 ArrayMaker arrayMakers[] = {make, make_s<5>, make_s<10>, make_s<20>}; | 72 if (a == b) { |
| 76 static int kSizes[] = {0, 1, 5, 10, 15, 20, 25}; | 73 continue; |
| 77 for (size_t arrayA = 0; arrayA < SK_ARRAY_COUNT(arrayMakers); ++arrayA) { | 74 } |
| 78 for (size_t arrayB = arrayA; arrayB < SK_ARRAY_COUNT(arrayMakers); ++arr
ayB) { | |
| 79 for (size_t dataSizeA = 0; dataSizeA < SK_ARRAY_COUNT(kSizes); ++dat
aSizeA) { | |
| 80 for (size_t dataSizeB = 0; dataSizeB < SK_ARRAY_COUNT(kSizes); +
+dataSizeB) { | |
| 81 int curr = 0; | |
| 82 SkTArray<int>* a = arrayMakers[arrayA](); | |
| 83 SkTArray<int>* b = arrayMakers[arrayB](); | |
| 84 for (int i = 0; i < kSizes[dataSizeA]; ++i) { | |
| 85 a->push_back(curr++); | |
| 86 } | |
| 87 for (int i = 0; i < kSizes[dataSizeB]; ++i) { | |
| 88 b->push_back(curr++); | |
| 89 } | |
| 90 a->swap(b); | |
| 91 REPORTER_ASSERT(reporter, kSizes[dataSizeA] == b->count()); | |
| 92 REPORTER_ASSERT(reporter, kSizes[dataSizeB] == a->count()); | |
| 93 curr = 0; | |
| 94 for (int i = 0; i < kSizes[dataSizeA]; ++i) { | |
| 95 REPORTER_ASSERT(reporter, curr++ == (*b)[i]); | |
| 96 } | |
| 97 for (int i = 0; i < kSizes[dataSizeB]; ++i) { | |
| 98 REPORTER_ASSERT(reporter, curr++ == (*a)[i]); | |
| 99 } | |
| 100 delete b; | |
| 101 | 75 |
| 102 a->swap(a); | 76 for (auto sizeA : sizes) { |
| 103 curr = kSizes[dataSizeA]; | 77 for (auto sizeB : sizes) { |
| 104 for (int i = 0; i < kSizes[dataSizeB]; ++i) { | 78 a->reset(); |
| 105 REPORTER_ASSERT(reporter, curr++ == (*a)[i]); | 79 b->reset(); |
| 106 } | 80 |
| 107 delete a; | 81 int curr = 0; |
| 108 } | 82 for (int i = 0; i < sizeA; i++) { a->push_back(curr++); } |
| 109 } | 83 for (int i = 0; i < sizeB; i++) { b->push_back(curr++); } |
| 110 } | 84 |
| 111 } | 85 a->swap(b); |
| 86 REPORTER_ASSERT(reporter, b->count() == sizeA); |
| 87 REPORTER_ASSERT(reporter, a->count() == sizeB); |
| 88 |
| 89 curr = 0; |
| 90 for (int x : *b) { REPORTER_ASSERT(reporter, x == curr++); } |
| 91 for (int x : *a) { REPORTER_ASSERT(reporter, x == curr++); } |
| 92 |
| 93 a->swap(a); |
| 94 curr = sizeA; |
| 95 for (int x : *a) { REPORTER_ASSERT(reporter, x == curr++); } |
| 96 }} |
| 97 }} |
| 112 } | 98 } |
| 113 | 99 |
| 114 DEF_TEST(TArray, reporter) { | 100 DEF_TEST(TArray, reporter) { |
| 115 TestTSet_basic<true>(reporter); | 101 TestTSet_basic<true>(reporter); |
| 116 TestTSet_basic<false>(reporter); | 102 TestTSet_basic<false>(reporter); |
| 117 test_swap(reporter); | 103 test_swap(reporter); |
| 118 } | 104 } |
| OLD | NEW |