| 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 { | 
|  | 62 SkTArray<int>* make() { | 
|  | 63     typedef SkTArray<int> IntArray; | 
|  | 64     return SkNEW(IntArray); | 
|  | 65 } | 
|  | 66 | 
|  | 67 template <int N> SkTArray<int>* make_s() { | 
|  | 68     typedef SkSTArray<N, int> IntArray; | 
|  | 69     return SkNEW(IntArray); | 
|  | 70 } | 
|  | 71 } | 
|  | 72 | 
|  | 73 static void test_swap(skiatest::Reporter* reporter) { | 
|  | 74     typedef SkTArray<int>* (*ArrayMaker)(); | 
|  | 75     ArrayMaker arrayMakers[] = {make, make_s<5>, make_s<10>, make_s<20>}; | 
|  | 76     static int kSizes[] = {0, 1, 5, 10, 15, 20, 25}; | 
|  | 77     for (size_t arrayA = 0; arrayA < SK_ARRAY_COUNT(arrayMakers); ++arrayA) { | 
|  | 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                     SkDELETE(b); | 
|  | 101 | 
|  | 102                     a->swap(a); | 
|  | 103                     curr = kSizes[dataSizeA]; | 
|  | 104                     for (int i = 0; i < kSizes[dataSizeB]; ++i) { | 
|  | 105                         REPORTER_ASSERT(reporter, curr++ == (*a)[i]); | 
|  | 106                     } | 
|  | 107                     SkDELETE(a); | 
|  | 108                 } | 
|  | 109             } | 
|  | 110         } | 
|  | 111     } | 
|  | 112 } | 
|  | 113 | 
| 61 DEF_TEST(TArray, reporter) { | 114 DEF_TEST(TArray, reporter) { | 
| 62     TestTSet_basic<true>(reporter); | 115     TestTSet_basic<true>(reporter); | 
| 63     TestTSet_basic<false>(reporter); | 116     TestTSet_basic<false>(reporter); | 
|  | 117     test_swap(reporter); | 
| 64 } | 118 } | 
| OLD | NEW | 
|---|