Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(380)

Side by Side Diff: tests/RecordTestUtils.h

Issue 1300163002: unsigned -> int for counts and indices in picture-related code (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: (C) Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « tests/RecordTest.cpp ('k') | tests/RecorderTest.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /*
2 * Copyright 2015 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 */
7
1 #ifndef RecordTestUtils_DEFINED 8 #ifndef RecordTestUtils_DEFINED
2 #define RecordTestUtils_DEFINED 9 #define RecordTestUtils_DEFINED
3 10
4 #include "SkRecord.h" 11 #include "SkRecord.h"
5 #include "SkRecords.h" 12 #include "SkRecords.h"
6 13
7 // If the command we're reading is a U, set ptr to it, otherwise set it to NULL. 14 // If the command we're reading is a U, set ptr to it, otherwise set it to NULL.
8 template <typename U> 15 template <typename U>
9 struct ReadAs { 16 struct ReadAs {
10 ReadAs() : ptr(NULL), type(SkRecords::Type(~0)) {} 17 ReadAs() : ptr(NULL), type(SkRecords::Type(~0)) {}
11 18
12 const U* ptr; 19 const U* ptr;
13 SkRecords::Type type; 20 SkRecords::Type type;
14 21
15 void operator()(const U& r) { ptr = &r; type = U::kType; } 22 void operator()(const U& r) { ptr = &r; type = U::kType; }
16 23
17 template <typename T> 24 template <typename T>
18 void operator()(const T&) { type = U::kType; } 25 void operator()(const T&) { type = U::kType; }
19 }; 26 };
20 27
21 // Assert that the ith command in record is of type T, and return it. 28 // Assert that the ith command in record is of type T, and return it.
22 template <typename T> 29 template <typename T>
23 static const T* assert_type(skiatest::Reporter* r, const SkRecord& record, unsig ned index) { 30 static const T* assert_type(skiatest::Reporter* r, const SkRecord& record, int i ndex) {
24 ReadAs<T> reader; 31 ReadAs<T> reader;
25 record.visit<void>(index, reader); 32 record.visit<void>(index, reader);
26 REPORTER_ASSERT(r, T::kType == reader.type); 33 REPORTER_ASSERT(r, T::kType == reader.type);
27 REPORTER_ASSERT(r, SkToBool(reader.ptr)); 34 REPORTER_ASSERT(r, SkToBool(reader.ptr));
28 return reader.ptr; 35 return reader.ptr;
29 } 36 }
30 37
31 template <typename DrawT> struct MatchType { 38 template <typename DrawT> struct MatchType {
32 template <typename T> int operator()(const T&) { return 0; } 39 template <typename T> int operator()(const T&) { return 0; }
33 int operator()(const DrawT&) { return 1; } 40 int operator()(const DrawT&) { return 1; }
34 }; 41 };
35 42
36 template <typename DrawT> int count_instances_of_type(const SkRecord& record) { 43 template <typename DrawT> int count_instances_of_type(const SkRecord& record) {
37 MatchType<DrawT> matcher; 44 MatchType<DrawT> matcher;
38 int counter = 0; 45 int counter = 0;
39 for (unsigned i = 0; i < record.count(); i++) { 46 for (int i = 0; i < record.count(); i++) {
40 counter += record.visit<int>(i, matcher); 47 counter += record.visit<int>(i, matcher);
41 } 48 }
42 return counter; 49 return counter;
43 } 50 }
44 51
45 template <typename DrawT> int find_first_instances_of_type(const SkRecord& recor d) { 52 template <typename DrawT> int find_first_instances_of_type(const SkRecord& recor d) {
46 MatchType<DrawT> matcher; 53 MatchType<DrawT> matcher;
47 for (unsigned i = 0; i < record.count(); i++) { 54 for (int i = 0; i < record.count(); i++) {
48 if (record.visit<int>(i, matcher)) { 55 if (record.visit<int>(i, matcher)) {
49 return i; 56 return i;
50 } 57 }
51 } 58 }
52 return -1; 59 return -1;
53 } 60 }
54 61
55 #endif//RecordTestUtils_DEFINED 62 #endif//RecordTestUtils_DEFINED
OLDNEW
« no previous file with comments | « tests/RecordTest.cpp ('k') | tests/RecorderTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698