blob: 46ef27ea42726710d8af98536cc9da029f9bfa4c [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001/*
2 * Copyright 2011 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
tfarina@chromium.orge4fafb12013-12-12 21:11:12 +00007
Mike Kleinc0bd9f92019-04-23 12:05:21 -05008#include "include/core/SkRefCnt.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -05009#include "include/utils/SkRandom.h"
Herb Derbycbd235c2019-07-03 18:05:12 -040010#include "src/core/SkEnumerate.h"
Herb Derby10e48d42019-08-08 12:30:13 -040011#include "src/core/SkSpan.h"
Ben Wagner8bd6e8f2019-05-15 09:28:52 -040012#include "src/core/SkTSearch.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050013#include "src/core/SkTSort.h"
Herb Derbyc44ee1a2019-09-09 11:36:39 -040014#include "src/core/SkZip.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050015#include "tests/Test.h"
reed@android.comed673312009-02-27 16:24:51 +000016
Herb Derby10e48d42019-08-08 12:30:13 -040017#include <array>
Herb Derbyc44ee1a2019-09-09 11:36:39 -040018#include <initializer_list>
19#include <tuple>
Herb Derby10e48d42019-08-08 12:30:13 -040020#include <vector>
21
reed@android.comb00cd722010-04-16 20:35:47 +000022class RefClass : public SkRefCnt {
23public:
24 RefClass(int n) : fN(n) {}
25 int get() const { return fN; }
26
27private:
28 int fN;
robertphillips@google.coma22e2112012-08-16 14:58:06 +000029
30 typedef SkRefCnt INHERITED;
reed@android.comb00cd722010-04-16 20:35:47 +000031};
32
reed@google.coma67573e2011-02-25 18:10:29 +000033static void test_autounref(skiatest::Reporter* reporter) {
34 RefClass obj(0);
mtkleinbbb61d72014-11-24 13:09:39 -080035 REPORTER_ASSERT(reporter, obj.unique());
reed@google.coma67573e2011-02-25 18:10:29 +000036
Hal Canary342b7ac2016-11-04 11:49:42 -040037 sk_sp<RefClass> tmp(&obj);
reed@google.coma67573e2011-02-25 18:10:29 +000038 REPORTER_ASSERT(reporter, &obj == tmp.get());
mtkleinbbb61d72014-11-24 13:09:39 -080039 REPORTER_ASSERT(reporter, obj.unique());
reed@google.coma67573e2011-02-25 18:10:29 +000040
mtklein18300a32016-03-16 13:53:35 -070041 REPORTER_ASSERT(reporter, &obj == tmp.release());
mtkleinbbb61d72014-11-24 13:09:39 -080042 REPORTER_ASSERT(reporter, obj.unique());
mtklein18300a32016-03-16 13:53:35 -070043 REPORTER_ASSERT(reporter, nullptr == tmp.release());
halcanary96fcdcc2015-08-27 07:41:13 -070044 REPORTER_ASSERT(reporter, nullptr == tmp.get());
reed@google.coma67573e2011-02-25 18:10:29 +000045
46 obj.ref();
mtkleinbbb61d72014-11-24 13:09:39 -080047 REPORTER_ASSERT(reporter, !obj.unique());
reed@google.coma67573e2011-02-25 18:10:29 +000048 {
Hal Canary342b7ac2016-11-04 11:49:42 -040049 sk_sp<RefClass> tmp2(&obj);
reed@google.coma67573e2011-02-25 18:10:29 +000050 }
mtkleinbbb61d72014-11-24 13:09:39 -080051 REPORTER_ASSERT(reporter, obj.unique());
reed@google.coma67573e2011-02-25 18:10:29 +000052}
53
robertphillips@google.com4d376732013-07-12 18:44:23 +000054static void test_autostarray(skiatest::Reporter* reporter) {
55 RefClass obj0(0);
56 RefClass obj1(1);
mtkleinbbb61d72014-11-24 13:09:39 -080057 REPORTER_ASSERT(reporter, obj0.unique());
58 REPORTER_ASSERT(reporter, obj1.unique());
robertphillips@google.com4d376732013-07-12 18:44:23 +000059
60 {
Hal Canary342b7ac2016-11-04 11:49:42 -040061 SkAutoSTArray<2, sk_sp<RefClass> > tmp;
robertphillips@google.com4d376732013-07-12 18:44:23 +000062 REPORTER_ASSERT(reporter, 0 == tmp.count());
63
64 tmp.reset(0); // test out reset(0) when already at 0
65 tmp.reset(4); // this should force a new allocation
66 REPORTER_ASSERT(reporter, 4 == tmp.count());
bungeman733418f2014-07-17 12:17:55 -070067 tmp[0].reset(SkRef(&obj0));
68 tmp[1].reset(SkRef(&obj1));
mtkleinbbb61d72014-11-24 13:09:39 -080069 REPORTER_ASSERT(reporter, !obj0.unique());
70 REPORTER_ASSERT(reporter, !obj1.unique());
robertphillips@google.com4d376732013-07-12 18:44:23 +000071
72 // test out reset with data in the array (and a new allocation)
73 tmp.reset(0);
74 REPORTER_ASSERT(reporter, 0 == tmp.count());
mtkleinbbb61d72014-11-24 13:09:39 -080075 REPORTER_ASSERT(reporter, obj0.unique());
76 REPORTER_ASSERT(reporter, obj1.unique());
humper@google.com9c96d4b2013-07-14 01:44:59 +000077
robertphillips@google.com4d376732013-07-12 18:44:23 +000078 tmp.reset(2); // this should use the preexisting allocation
79 REPORTER_ASSERT(reporter, 2 == tmp.count());
bungeman733418f2014-07-17 12:17:55 -070080 tmp[0].reset(SkRef(&obj0));
81 tmp[1].reset(SkRef(&obj1));
robertphillips@google.com4d376732013-07-12 18:44:23 +000082 }
83
84 // test out destructor with data in the array (and using existing allocation)
mtkleinbbb61d72014-11-24 13:09:39 -080085 REPORTER_ASSERT(reporter, obj0.unique());
86 REPORTER_ASSERT(reporter, obj1.unique());
robertphillips@google.com4d376732013-07-12 18:44:23 +000087
88 {
89 // test out allocating ctor (this should allocate new memory)
Hal Canary342b7ac2016-11-04 11:49:42 -040090 SkAutoSTArray<2, sk_sp<RefClass> > tmp(4);
robertphillips@google.com4d376732013-07-12 18:44:23 +000091 REPORTER_ASSERT(reporter, 4 == tmp.count());
92
bungeman733418f2014-07-17 12:17:55 -070093 tmp[0].reset(SkRef(&obj0));
94 tmp[1].reset(SkRef(&obj1));
mtkleinbbb61d72014-11-24 13:09:39 -080095 REPORTER_ASSERT(reporter, !obj0.unique());
96 REPORTER_ASSERT(reporter, !obj1.unique());
robertphillips@google.com4d376732013-07-12 18:44:23 +000097
98 // Test out resut with data in the array and malloced storage
99 tmp.reset(0);
mtkleinbbb61d72014-11-24 13:09:39 -0800100 REPORTER_ASSERT(reporter, obj0.unique());
101 REPORTER_ASSERT(reporter, obj1.unique());
robertphillips@google.com4d376732013-07-12 18:44:23 +0000102
103 tmp.reset(2); // this should use the preexisting storage
bungeman733418f2014-07-17 12:17:55 -0700104 tmp[0].reset(SkRef(&obj0));
105 tmp[1].reset(SkRef(&obj1));
mtkleinbbb61d72014-11-24 13:09:39 -0800106 REPORTER_ASSERT(reporter, !obj0.unique());
107 REPORTER_ASSERT(reporter, !obj1.unique());
robertphillips@google.com4d376732013-07-12 18:44:23 +0000108
109 tmp.reset(4); // this should force a new malloc
mtkleinbbb61d72014-11-24 13:09:39 -0800110 REPORTER_ASSERT(reporter, obj0.unique());
111 REPORTER_ASSERT(reporter, obj1.unique());
robertphillips@google.com4d376732013-07-12 18:44:23 +0000112
bungeman733418f2014-07-17 12:17:55 -0700113 tmp[0].reset(SkRef(&obj0));
114 tmp[1].reset(SkRef(&obj1));
mtkleinbbb61d72014-11-24 13:09:39 -0800115 REPORTER_ASSERT(reporter, !obj0.unique());
116 REPORTER_ASSERT(reporter, !obj1.unique());
robertphillips@google.com4d376732013-07-12 18:44:23 +0000117 }
118
mtkleinbbb61d72014-11-24 13:09:39 -0800119 REPORTER_ASSERT(reporter, obj0.unique());
120 REPORTER_ASSERT(reporter, obj1.unique());
robertphillips@google.com4d376732013-07-12 18:44:23 +0000121}
122
epoger@google.combcc56832011-05-20 17:35:46 +0000123/////////////////////////////////////////////////////////////////////////////
reed@android.comb00cd722010-04-16 20:35:47 +0000124
reed@android.comed673312009-02-27 16:24:51 +0000125#define kSEARCH_COUNT 91
126
127static void test_search(skiatest::Reporter* reporter) {
128 int i, array[kSEARCH_COUNT];
commit-bot@chromium.orge0e7cfe2013-09-09 20:09:12 +0000129 SkRandom rand;
reed@android.comed673312009-02-27 16:24:51 +0000130
131 for (i = 0; i < kSEARCH_COUNT; i++) {
132 array[i] = rand.nextS();
133 }
134
135 SkTHeapSort<int>(array, kSEARCH_COUNT);
136 // make sure we got sorted properly
137 for (i = 1; i < kSEARCH_COUNT; i++) {
138 REPORTER_ASSERT(reporter, array[i-1] <= array[i]);
139 }
140
141 // make sure we can find all of our values
142 for (i = 0; i < kSEARCH_COUNT; i++) {
143 int index = SkTSearch<int>(array, kSEARCH_COUNT, array[i], sizeof(int));
144 REPORTER_ASSERT(reporter, index == i);
145 }
146
147 // make sure that random values are either found, or the correct
148 // insertion index is returned
149 for (i = 0; i < 10000; i++) {
150 int value = rand.nextS();
151 int index = SkTSearch<int>(array, kSEARCH_COUNT, value, sizeof(int));
152
153 if (index >= 0) {
154 REPORTER_ASSERT(reporter,
155 index < kSEARCH_COUNT && array[index] == value);
156 } else {
157 index = ~index;
158 REPORTER_ASSERT(reporter, index <= kSEARCH_COUNT);
159 if (index < kSEARCH_COUNT) {
160 REPORTER_ASSERT(reporter, value < array[index]);
161 if (index > 0) {
162 REPORTER_ASSERT(reporter, value > array[index - 1]);
163 }
164 } else {
165 // we should append the new value
166 REPORTER_ASSERT(reporter, value > array[kSEARCH_COUNT - 1]);
167 }
168 }
169 }
170}
171
tfarina@chromium.orge4fafb12013-12-12 21:11:12 +0000172DEF_TEST(Utils, reporter) {
reed@android.comed673312009-02-27 16:24:51 +0000173 test_search(reporter);
reed@google.coma67573e2011-02-25 18:10:29 +0000174 test_autounref(reporter);
robertphillips@google.com4d376732013-07-12 18:44:23 +0000175 test_autostarray(reporter);
reed@android.comed673312009-02-27 16:24:51 +0000176}
Herb Derby10e48d42019-08-08 12:30:13 -0400177
178DEF_TEST(SkMakeSpan, reporter) {
179 // Test constness preservation for SkMakeSpan.
180 {
181 std::vector<int> v = {{1, 2, 3, 4, 5}};
182 auto s = SkMakeSpan(v);
183 REPORTER_ASSERT(reporter, s[3] == 4);
184 s[3] = 100;
185 REPORTER_ASSERT(reporter, s[3] == 100);
186 }
187
188 {
189 std::vector<int> t = {{1, 2, 3, 4, 5}};
190 const std::vector<int>& v = t;
191 auto s = SkMakeSpan(v);
192 //s[3] = 100; // Should fail to compile
193 REPORTER_ASSERT(reporter, s[3] == 4);
194 REPORTER_ASSERT(reporter, t[3] == 4);
195 t[3] = 100;
196 REPORTER_ASSERT(reporter, s[3] == 100);
197 }
198
199 {
200 std::array<int, 5> v = {{1, 2, 3, 4, 5}};
201 auto s = SkMakeSpan(v);
202 REPORTER_ASSERT(reporter, s[3] == 4);
203 s[3] = 100;
204 REPORTER_ASSERT(reporter, s[3] == 100);
205 }
206
207 {
208 std::array<int, 5> t = {{1, 2, 3, 4, 5}};
209 const std::array<int, 5>& v = t;
210 auto s = SkMakeSpan(v);
211 //s[3] = 100; // Should fail to compile
212 REPORTER_ASSERT(reporter, s[3] == 4);
213 REPORTER_ASSERT(reporter, t[3] == 4);
214 t[3] = 100;
215 REPORTER_ASSERT(reporter, s[3] == 100);
216 }
Herb Derby986ab2c2019-09-19 11:27:43 -0400217
218 {
219 std::vector<int> v;
220 auto s = SkMakeSpan(v);
221 REPORTER_ASSERT(reporter, s.empty());
222 }
Herb Derby10e48d42019-08-08 12:30:13 -0400223}
Herb Derbyc44ee1a2019-09-09 11:36:39 -0400224
Herb Derbycbd235c2019-07-03 18:05:12 -0400225DEF_TEST(SkEnumerate, reporter) {
226
227 int A[] = {1, 2, 3, 4};
228 auto enumeration = SkMakeEnumerate(A);
229
230 size_t check = 0;
231 for (auto t : enumeration) {
232 size_t i; int v;
233 std::tie(i, v) = t;
234 REPORTER_ASSERT(reporter, i == check);
235 REPORTER_ASSERT(reporter, v == (int)check+1);
236
237 check++;
238 }
239
240 check = 0;
241 for (auto t : SkMakeEnumerate(A)) {
242 size_t i; int v;
243 std::tie(i, v) = t;
244 REPORTER_ASSERT(reporter, i == check);
245 REPORTER_ASSERT(reporter, v == (int)check+1);
246
247 check++;
248 }
249
250 check = 0;
251 std::vector<int> vec = {1, 2, 3, 4};
252 for (auto t : SkMakeEnumerate(vec)) {
253 size_t i; int v;
254 std::tie(i, v) = t;
255 REPORTER_ASSERT(reporter, i == check);
256 REPORTER_ASSERT(reporter, v == (int)check+1);
257 check++;
258 }
259 REPORTER_ASSERT(reporter, check == 4);
260
261 check = 0;
262 for (auto t : SkMakeEnumerate(SkMakeSpan(vec))) {
263 size_t i; int v;
264 std::tie(i, v) = t;
265 REPORTER_ASSERT(reporter, i == check);
266 REPORTER_ASSERT(reporter, v == (int)check+1);
267 check++;
268 }
269}
270
Herb Derbyc44ee1a2019-09-09 11:36:39 -0400271DEF_TEST(SkZip, reporter) {
272 uint16_t A[] = {1, 2, 3, 4};
273 const float B[] = {10.f, 20.f, 30.f, 40.f};
274 std::vector<int> C = {{20, 30, 40, 50}};
275 std::array<int, 4> D = {{100, 200, 300, 400}};
276 SkSpan<int> S = SkMakeSpan(C);
277
278 // Check SkZip calls
279 SkZip<uint16_t, const float, int, int, int>
280 z{4, &A[0], &B[0], C.data(), D.data(), S.data()};
281
282 REPORTER_ASSERT(reporter, z.size() == 4);
283 REPORTER_ASSERT(reporter, !z.empty());
284
285 {
286 // Check front
287 auto t = z.front();
288 REPORTER_ASSERT(reporter, std::get<0>(t) == 1);
289 REPORTER_ASSERT(reporter, std::get<1>(t) == 10.f);
290 REPORTER_ASSERT(reporter, std::get<2>(t) == 20);
291 REPORTER_ASSERT(reporter, std::get<3>(t) == 100);
292 REPORTER_ASSERT(reporter, std::get<4>(t) == 20);
293 }
294
295 {
296 // Check back
297 auto t = z.back();
298 REPORTER_ASSERT(reporter, std::get<0>(t) == 4);
299 REPORTER_ASSERT(reporter, std::get<1>(t) == 40.f);
300 }
301
302 {
303 // Check ranged-for
304 int i = 0;
305 for (auto t : z) {
306 uint16_t a; float b; int c; int d; int s;
307 std::tie(a, b, c, d, s) = t;
308 REPORTER_ASSERT(reporter, a == A[i]);
309 REPORTER_ASSERT(reporter, b == B[i]);
310 REPORTER_ASSERT(reporter, c == C[i]);
311 REPORTER_ASSERT(reporter, d == D[i]);
312 REPORTER_ASSERT(reporter, s == S[i]);
313
314 i++;
315 }
316 REPORTER_ASSERT(reporter, i = 4);
317 }
318
319 // Check copy.
320 auto zz{z};
321 {
322 int i = 0;
323 for (auto t : zz) {
324 uint16_t a; float b; int c; int d; int s;
325 std::tie(a, b, c, d, s) = t;
326 REPORTER_ASSERT(reporter, a == A[i]);
327 REPORTER_ASSERT(reporter, b == B[i]);
328 REPORTER_ASSERT(reporter, c == C[i]);
329 REPORTER_ASSERT(reporter, d == D[i]);
330 REPORTER_ASSERT(reporter, s == S[i]);
331
332 i++;
333 }
334 REPORTER_ASSERT(reporter, i = 4);
335 }
336
337 // Check index getter
338 {
339 auto span = z.get<1>();
340 REPORTER_ASSERT(reporter, span[1] == 20.f);
341 }
342
343 // The following mutates the data.
344 {
345 // Check indexing
346 auto t = z[1];
347 REPORTER_ASSERT(reporter, std::get<0>(t) == 2);
348 REPORTER_ASSERT(reporter, std::get<1>(t) == 20.f);
349 REPORTER_ASSERT(reporter, std::get<2>(t) == 30);
350 REPORTER_ASSERT(reporter, std::get<3>(t) == 200);
351 REPORTER_ASSERT(reporter, std::get<4>(t) == 30);
352
353 // Check correct refs returned.
354 REPORTER_ASSERT(reporter, &std::get<0>(t) == &A[1]);
355 REPORTER_ASSERT(reporter, &std::get<1>(t) == &B[1]);
356 REPORTER_ASSERT(reporter, &std::get<2>(t) == &C[1]);
357 REPORTER_ASSERT(reporter, &std::get<3>(t) == &D[1]);
358 REPORTER_ASSERT(reporter, &std::get<4>(t) == &S[1]);
359
360 // Check assignment
361 std::get<0>(t) = 20;
362 // std::get<1>(t) = 300.f; // is const
363 std::get<2>(t) = 300;
364 std::get<3>(t) = 2000;
365 std::get<4>(t) = 300;
366
367 auto t1 = z[1];
368 REPORTER_ASSERT(reporter, std::get<0>(t1) == 20);
369 REPORTER_ASSERT(reporter, std::get<1>(t1) == 20.f);
370 REPORTER_ASSERT(reporter, std::get<2>(t1) == 300);
371 REPORTER_ASSERT(reporter, std::get<3>(t1) == 2000);
372 REPORTER_ASSERT(reporter, std::get<4>(t1) == 300);
373 }
374}
Herb Derby986ab2c2019-09-19 11:27:43 -0400375
376DEF_TEST(SkMakeZip, reporter) {
377 uint16_t A[] = {1, 2, 3, 4};
378 const float B[] = {10.f, 20.f, 30.f, 40.f};
379 const std::vector<int> C = {{20, 30, 40, 50}};
380 std::array<int, 4> D = {{100, 200, 300, 400}};
381 SkSpan<const int> S = SkMakeSpan(C);
382 uint16_t* P = &A[0];
383 {
384 // Check make zip
385 auto zz = SkMakeZip(&A[0], B, C, D, S, P);
386
387 int i = 0;
388 for (auto t : zz) {
389 uint16_t a; float b; int c; int d; int s; uint16_t p;
390 std::tie(a, b ,c ,d, s, p) = t;
391 REPORTER_ASSERT(reporter, a == A[i]);
392 REPORTER_ASSERT(reporter, b == B[i]);
393 REPORTER_ASSERT(reporter, c == C[i]);
394 REPORTER_ASSERT(reporter, d == D[i]);
395 REPORTER_ASSERT(reporter, s == S[i]);
396 REPORTER_ASSERT(reporter, p == P[i]);
397
398 i++;
399 }
400 REPORTER_ASSERT(reporter, i = 4);
401 }
402
403 {
404 // Check SkMakeZip in ranged for check OneSize calc of B.
405 int i = 0;
406 for (auto t : SkMakeZip(&A[0], B, C, D, S)) {
407 uint16_t a; float b; int c; int d; int s;
408 std::tie(a, b ,c ,d, s) = t;
409 REPORTER_ASSERT(reporter, a == A[i]);
410 REPORTER_ASSERT(reporter, b == B[i]);
411 REPORTER_ASSERT(reporter, c == C[i]);
412 REPORTER_ASSERT(reporter, d == D[i]);
413 REPORTER_ASSERT(reporter, s == S[i]);
414
415 i++;
416 }
417 REPORTER_ASSERT(reporter, i = 4);
418 }
419
420 {
421 // Check SkMakeZip in ranged for OneSize of C
422 int i = 0;
423 for (auto t : SkMakeZip(&A[0], &B[0], C, D, S)) {
424 uint16_t a; float b; int c; int d; int s;
425 std::tie(a, b ,c ,d, s) = t;
426 REPORTER_ASSERT(reporter, a == A[i]);
427 REPORTER_ASSERT(reporter, b == B[i]);
428 REPORTER_ASSERT(reporter, c == C[i]);
429 REPORTER_ASSERT(reporter, d == D[i]);
430 REPORTER_ASSERT(reporter, s == S[i]);
431
432 i++;
433 }
434 REPORTER_ASSERT(reporter, i = 4);
435 }
436
437 {
438 // Check SkMakeZip in ranged for OneSize for S
439 int i = 0;
440 for (auto t : SkMakeZip(S, A, B, C, D)) {
441 uint16_t a; float b; int c; int d; int s;
442 std::tie(s, a, b, c, d) = t;
443 REPORTER_ASSERT(reporter, a == A[i]);
444 REPORTER_ASSERT(reporter, b == B[i]);
445 REPORTER_ASSERT(reporter, c == C[i]);
446 REPORTER_ASSERT(reporter, d == D[i]);
447 REPORTER_ASSERT(reporter, s == S[i]);
448
449 i++;
450 }
451 REPORTER_ASSERT(reporter, i = 4);
452 }
453
454 {
455 // Check SkMakeZip in ranged for
456 int i = 0;
457 for (auto t : SkMakeZip(C, S, A, B, D)) {
458 uint16_t a; float b; int c; int d; int s;
459 std::tie(c, s, a, b, d) = t;
460 REPORTER_ASSERT(reporter, a == A[i]);
461 REPORTER_ASSERT(reporter, b == B[i]);
462 REPORTER_ASSERT(reporter, c == C[i]);
463 REPORTER_ASSERT(reporter, d == D[i]);
464 REPORTER_ASSERT(reporter, s == S[i]);
465
466 i++;
467 }
468 REPORTER_ASSERT(reporter, i = 4);
469 }
470
471 {
Herb Derbycbd235c2019-07-03 18:05:12 -0400472 // Check SkEnumerate and SkMakeZip in ranged for
473 auto zz = SkMakeZip(A, B, C, D, S);
474 for (auto t : SkMakeEnumerate(zz)) {
475 int i;
476 uint16_t a; float b; int c; int d; int s;
477 std::forward_as_tuple(i, std::tie(a, b, c, d, s)) = t;
478 REPORTER_ASSERT(reporter, a == A[i]);
479 REPORTER_ASSERT(reporter, b == B[i]);
480 REPORTER_ASSERT(reporter, c == C[i]);
481 REPORTER_ASSERT(reporter, d == D[i]);
482 REPORTER_ASSERT(reporter, s == S[i]);
483 }
484 }
485
486 {
487 // Check SkEnumerate and SkMakeZip in ranged for
488 const auto& zz = SkMakeZip(A, B, C, D, S);
489 for (auto t : SkMakeEnumerate(zz)) {
490 int i;
491 uint16_t a; float b; int c; int d; int s;
492 std::forward_as_tuple(i, std::tie(a, b, c, d, s)) = t;
493 REPORTER_ASSERT(reporter, a == A[i]);
494 REPORTER_ASSERT(reporter, b == B[i]);
495 REPORTER_ASSERT(reporter, c == C[i]);
496 REPORTER_ASSERT(reporter, d == D[i]);
497 REPORTER_ASSERT(reporter, s == S[i]);
498 }
499 }
500
501 {
502 // Check SkEnumerate and SkMakeZip in ranged for
503 for (auto t : SkMakeEnumerate(SkMakeZip(A, B, C, D, S))) {
504 int i;
505 uint16_t a; float b; int c; int d; int s;
506 std::forward_as_tuple(i, std::tie(a, b, c, d, s)) = t;
507 REPORTER_ASSERT(reporter, a == A[i]);
508 REPORTER_ASSERT(reporter, b == B[i]);
509 REPORTER_ASSERT(reporter, c == C[i]);
510 REPORTER_ASSERT(reporter, d == D[i]);
511 REPORTER_ASSERT(reporter, s == S[i]);
512 }
513 }
514
515 {
Herb Derby986ab2c2019-09-19 11:27:43 -0400516 std::vector<int>v;
517 auto z = SkMakeZip(v);
518 REPORTER_ASSERT(reporter, z.empty());
519 }
520
521 {
522 constexpr static uint16_t cA[] = {1, 2, 3, 4};
523 // Not constexpr in stdc++11 library.
524 //constexpr static std::array<int, 4> cD = {{100, 200, 300, 400}};
525 constexpr static const uint16_t* cP = &cA[0];
526 constexpr auto z = SkMakeZip(cA, cP);
527 REPORTER_ASSERT(reporter, !z.empty());
528 }
529}