aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/TArrayTest.cpp
diff options
context:
space:
mode:
authorGravatar mtklein <mtklein@chromium.org>2016-03-03 09:48:53 -0800
committerGravatar Commit bot <commit-bot@chromium.org>2016-03-03 09:48:53 -0800
commit862110042d715214b484e643194336c0f0b28659 (patch)
treee0bce177d4545e47991ad5b1b16104fb1b674f70 /tests/TArrayTest.cpp
parentcd660e1c07371d9cf97824245639b1c0b5ac92fc (diff)
rewrite TArray test to not delete an SkSTArray via a SkTArray pointer.
This should decouple our thinking around SkTArray, SkSTArray, vector, allocators, etc. from getting sized-deleter clean. BUG=skia: GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1760933002 Review URL: https://codereview.chromium.org/1760933002
Diffstat (limited to 'tests/TArrayTest.cpp')
-rw-r--r--tests/TArrayTest.cpp84
1 files changed, 35 insertions, 49 deletions
diff --git a/tests/TArrayTest.cpp b/tests/TArrayTest.cpp
index 6a9b5f5a81..abf1075bc5 100644
--- a/tests/TArrayTest.cpp
+++ b/tests/TArrayTest.cpp
@@ -58,57 +58,43 @@ static void TestTSet_basic(skiatest::Reporter* reporter) {
// {0, 3, 2 }
}
-namespace {
-SkTArray<int>* make() {
- typedef SkTArray<int> IntArray;
- return new IntArray;
-}
-
-template <int N> SkTArray<int>* make_s() {
- typedef SkSTArray<N, int> IntArray;
- return new IntArray;
-}
-}
-
static void test_swap(skiatest::Reporter* reporter) {
- typedef SkTArray<int>* (*ArrayMaker)();
- ArrayMaker arrayMakers[] = {make, make_s<5>, make_s<10>, make_s<20>};
- static int kSizes[] = {0, 1, 5, 10, 15, 20, 25};
- for (size_t arrayA = 0; arrayA < SK_ARRAY_COUNT(arrayMakers); ++arrayA) {
- for (size_t arrayB = arrayA; arrayB < SK_ARRAY_COUNT(arrayMakers); ++arrayB) {
- for (size_t dataSizeA = 0; dataSizeA < SK_ARRAY_COUNT(kSizes); ++dataSizeA) {
- for (size_t dataSizeB = 0; dataSizeB < SK_ARRAY_COUNT(kSizes); ++dataSizeB) {
- int curr = 0;
- SkTArray<int>* a = arrayMakers[arrayA]();
- SkTArray<int>* b = arrayMakers[arrayB]();
- for (int i = 0; i < kSizes[dataSizeA]; ++i) {
- a->push_back(curr++);
- }
- for (int i = 0; i < kSizes[dataSizeB]; ++i) {
- b->push_back(curr++);
- }
- a->swap(b);
- REPORTER_ASSERT(reporter, kSizes[dataSizeA] == b->count());
- REPORTER_ASSERT(reporter, kSizes[dataSizeB] == a->count());
- curr = 0;
- for (int i = 0; i < kSizes[dataSizeA]; ++i) {
- REPORTER_ASSERT(reporter, curr++ == (*b)[i]);
- }
- for (int i = 0; i < kSizes[dataSizeB]; ++i) {
- REPORTER_ASSERT(reporter, curr++ == (*a)[i]);
- }
- delete b;
-
- a->swap(a);
- curr = kSizes[dataSizeA];
- for (int i = 0; i < kSizes[dataSizeB]; ++i) {
- REPORTER_ASSERT(reporter, curr++ == (*a)[i]);
- }
- delete a;
- }
- }
+ SkTArray<int> arr;
+ SkSTArray< 5, int> arr5;
+ SkSTArray<10, int> arr10;
+ SkSTArray<20, int> arr20;
+
+ SkTArray<int>* arrays[] = { &arr, &arr5, &arr10, &arr20 };
+ int sizes[] = {0, 1, 5, 10, 15, 20, 25};
+
+ for (auto a : arrays) {
+ for (auto b : arrays) {
+ if (a == b) {
+ continue;
}
- }
+
+ for (auto sizeA : sizes) {
+ for (auto sizeB : sizes) {
+ a->reset();
+ b->reset();
+
+ int curr = 0;
+ for (int i = 0; i < sizeA; i++) { a->push_back(curr++); }
+ for (int i = 0; i < sizeB; i++) { b->push_back(curr++); }
+
+ a->swap(b);
+ REPORTER_ASSERT(reporter, b->count() == sizeA);
+ REPORTER_ASSERT(reporter, a->count() == sizeB);
+
+ curr = 0;
+ for (int x : *b) { REPORTER_ASSERT(reporter, x == curr++); }
+ for (int x : *a) { REPORTER_ASSERT(reporter, x == curr++); }
+
+ a->swap(a);
+ curr = sizeA;
+ for (int x : *a) { REPORTER_ASSERT(reporter, x == curr++); }
+ }}
+ }}
}
DEF_TEST(TArray, reporter) {