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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 namespace { |
62 SkTArray<int>* make() { | 62 SkTArray<int>* make() { |
63 typedef SkTArray<int> IntArray; | 63 typedef SkTArray<int> IntArray; |
64 return SkNEW(IntArray); | 64 return new IntArray; |
65 } | 65 } |
66 | 66 |
67 template <int N> SkTArray<int>* make_s() { | 67 template <int N> SkTArray<int>* make_s() { |
68 typedef SkSTArray<N, int> IntArray; | 68 typedef SkSTArray<N, int> IntArray; |
69 return SkNEW(IntArray); | 69 return new IntArray; |
70 } | 70 } |
71 } | 71 } |
72 | 72 |
73 static void test_swap(skiatest::Reporter* reporter) { | 73 static void test_swap(skiatest::Reporter* reporter) { |
74 typedef SkTArray<int>* (*ArrayMaker)(); | 74 typedef SkTArray<int>* (*ArrayMaker)(); |
75 ArrayMaker arrayMakers[] = {make, make_s<5>, make_s<10>, make_s<20>}; | 75 ArrayMaker arrayMakers[] = {make, make_s<5>, make_s<10>, make_s<20>}; |
76 static int kSizes[] = {0, 1, 5, 10, 15, 20, 25}; | 76 static int kSizes[] = {0, 1, 5, 10, 15, 20, 25}; |
77 for (size_t arrayA = 0; arrayA < SK_ARRAY_COUNT(arrayMakers); ++arrayA) { | 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) { | 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) { | 79 for (size_t dataSizeA = 0; dataSizeA < SK_ARRAY_COUNT(kSizes); ++dat
aSizeA) { |
(...skipping 10 matching lines...) Expand all Loading... |
90 a->swap(b); | 90 a->swap(b); |
91 REPORTER_ASSERT(reporter, kSizes[dataSizeA] == b->count()); | 91 REPORTER_ASSERT(reporter, kSizes[dataSizeA] == b->count()); |
92 REPORTER_ASSERT(reporter, kSizes[dataSizeB] == a->count()); | 92 REPORTER_ASSERT(reporter, kSizes[dataSizeB] == a->count()); |
93 curr = 0; | 93 curr = 0; |
94 for (int i = 0; i < kSizes[dataSizeA]; ++i) { | 94 for (int i = 0; i < kSizes[dataSizeA]; ++i) { |
95 REPORTER_ASSERT(reporter, curr++ == (*b)[i]); | 95 REPORTER_ASSERT(reporter, curr++ == (*b)[i]); |
96 } | 96 } |
97 for (int i = 0; i < kSizes[dataSizeB]; ++i) { | 97 for (int i = 0; i < kSizes[dataSizeB]; ++i) { |
98 REPORTER_ASSERT(reporter, curr++ == (*a)[i]); | 98 REPORTER_ASSERT(reporter, curr++ == (*a)[i]); |
99 } | 99 } |
100 SkDELETE(b); | 100 delete b; |
101 | 101 |
102 a->swap(a); | 102 a->swap(a); |
103 curr = kSizes[dataSizeA]; | 103 curr = kSizes[dataSizeA]; |
104 for (int i = 0; i < kSizes[dataSizeB]; ++i) { | 104 for (int i = 0; i < kSizes[dataSizeB]; ++i) { |
105 REPORTER_ASSERT(reporter, curr++ == (*a)[i]); | 105 REPORTER_ASSERT(reporter, curr++ == (*a)[i]); |
106 } | 106 } |
107 SkDELETE(a); | 107 delete a; |
108 } | 108 } |
109 } | 109 } |
110 } | 110 } |
111 } | 111 } |
112 } | 112 } |
113 | 113 |
114 DEF_TEST(TArray, reporter) { | 114 DEF_TEST(TArray, reporter) { |
115 TestTSet_basic<true>(reporter); | 115 TestTSet_basic<true>(reporter); |
116 TestTSet_basic<false>(reporter); | 116 TestTSet_basic<false>(reporter); |
117 test_swap(reporter); | 117 test_swap(reporter); |
118 } | 118 } |
OLD | NEW |