Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
RecordTestUtils.h
Go to the documentation of this file.
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
8#ifndef RecordTestUtils_DEFINED
9#define RecordTestUtils_DEFINED
10
11#include "src/core/SkRecord.h"
12#include "src/core/SkRecords.h"
13#include "tests/Test.h"
14
15// If the command we're reading is a U, set ptr to it, otherwise set it to nullptr.
16template <typename U>
17struct ReadAs {
18 ReadAs() : ptr(nullptr), type(SkRecords::Type(~0)) {}
19
20 const U* ptr;
22
23 void operator()(const U& r) { ptr = &r; type = U::kType; }
24
25 template <typename T>
26 void operator()(const T&) { type = U::kType; }
27};
28
29// Assert that the ith command in record is of type T, and return it.
30template <typename T>
31static const T* assert_type(skiatest::Reporter* r, const SkRecord& record, int index) {
32 ReadAs<T> reader;
33 record.visit(index, reader);
34 REPORTER_ASSERT(r, T::kType == reader.type);
35 REPORTER_ASSERT(r, SkToBool(reader.ptr));
36 return reader.ptr;
37}
38
39template <typename DrawT> struct MatchType {
40 template <typename T> int operator()(const T&) { return 0; }
41 int operator()(const DrawT&) { return 1; }
42};
43
44template <typename DrawT> int count_instances_of_type(const SkRecord& record) {
45 MatchType<DrawT> matcher;
46 int counter = 0;
47 for (int i = 0; i < record.count(); i++) {
48 counter += record.visit(i, matcher);
49 }
50 return counter;
51}
52
53template <typename DrawT> int find_first_instances_of_type(const SkRecord& record) {
54 MatchType<DrawT> matcher;
55 for (int i = 0; i < record.count(); i++) {
56 if (record.visit(i, matcher)) {
57 return i;
58 }
59 }
60 return -1;
61}
62
63#endif//RecordTestUtils_DEFINED
int find_first_instances_of_type(const SkRecord &record)
static const T * assert_type(skiatest::Reporter *r, const SkRecord &record, int index)
int count_instances_of_type(const SkRecord &record)
static constexpr bool SkToBool(const T &x)
Definition SkTo.h:35
#define REPORTER_ASSERT(r, cond,...)
Definition Test.h:286
auto visit(int i, F &&f) const -> decltype(f(SkRecords::NoOp()))
Definition SkRecord.h:45
int count() const
Definition SkRecord.h:38
#define T
int operator()(const DrawT &)
int operator()(const T &)
void operator()(const T &)
const U * ptr
void operator()(const U &r)
SkRecords::Type type