blob: 0575b83cdd57ee687aa585eec74763a2be158c68 [file] [log] [blame]
commit-bot@chromium.org0a98d872014-05-19 15:15:24 +00001#ifndef RecordTestUtils_DEFINED
2#define RecordTestUtils_DEFINED
3
4#include "SkRecord.h"
5#include "SkRecords.h"
6
7// If the command we're reading is a U, set ptr to it, otherwise set it to NULL.
8template <typename U>
9struct ReadAs {
10 ReadAs() : ptr(NULL), type(SkRecords::Type(~0)) {}
11
12 const U* ptr;
13 SkRecords::Type type;
14
15 void operator()(const U& r) { ptr = &r; type = U::kType; }
16
17 template <typename T>
18 void operator()(const T&) { type = U::kType; }
19};
20
21// Assert that the ith command in record is of type T, and return it.
22template <typename T>
23static const T* assert_type(skiatest::Reporter* r, const SkRecord& record, unsigned index) {
24 ReadAs<T> reader;
25 record.visit<void>(index, reader);
26 REPORTER_ASSERT(r, T::kType == reader.type);
bsalomon49f085d2014-09-05 13:34:00 -070027 REPORTER_ASSERT(r, SkToBool(reader.ptr));
commit-bot@chromium.org0a98d872014-05-19 15:15:24 +000028 return reader.ptr;
29}
30
31#endif//RecordTestUtils_DEFINED