diff options
author | commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2014-04-08 17:31:08 +0000 |
---|---|---|
committer | commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2014-04-08 17:31:08 +0000 |
commit | 066a28d2c19c5d09a7a8f27543a8c171c5816cf5 (patch) | |
tree | 37832d5cd35712da209fc9ba6724adf662d20f2c /tests | |
parent | 6719d604856e45c789c46703204ae10046e0b448 (diff) |
Start on some unwritten SkRecord TODOs:
- add SK_OVERRIDE for SkCanvas methods in SkRecorder
- start on unit tests, here just for SkRecord itself
BUG=skia:2378
R=fmalita@google.com, mtklein@google.com, fmalita@chromium.org
Author: mtklein@chromium.org
Review URL: https://codereview.chromium.org/228723003
git-svn-id: http://skia.googlecode.com/svn/trunk@14097 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'tests')
-rw-r--r-- | tests/RecordTest.cpp | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/tests/RecordTest.cpp b/tests/RecordTest.cpp new file mode 100644 index 0000000000..1214b1a5de --- /dev/null +++ b/tests/RecordTest.cpp @@ -0,0 +1,48 @@ +#include "Test.h" + +#include "SkRecord.h" +#include "SkRecords.h" + +// Adds the area of any DrawRect command it sees into area. +class AreaSummer { +public: + explicit AreaSummer(int* area) : fArea(area) {} + + template <typename T> void operator()(const T&) { } + +private: + int* fArea; +}; +template <> void AreaSummer::operator()(const SkRecords::DrawRect& record) { + *fArea += (int) (record.rect.width() * record.rect.height()); +} + +// Scales out the bottom-right corner of any DrawRect command it sees by 2x. +struct Stretch { + template <typename T> void operator()(T*) {} +}; +template <> void Stretch::operator()(SkRecords::DrawRect* record) { + record->rect.fRight *= 2; + record->rect.fBottom *= 2; +} + +// Basic tests for the low-level SkRecord code. +DEF_TEST(Record, r) { + SkRecord record; + + // Add a simple DrawRect command. + SkRect rect = SkRect::MakeWH(10, 10); + SkPaint paint; + SkNEW_PLACEMENT_ARGS(record.append<SkRecords::DrawRect>(), SkRecords::DrawRect, (rect, paint)); + + // Its area should be 100. + int area = 0; + record.visit(AreaSummer(&area)); + REPORTER_ASSERT(r, area == 100); + + // Scale 2x. Now it's area should be 400. + record.mutate(Stretch()); + area = 0; + record.visit(AreaSummer(&area)); + REPORTER_ASSERT(r, area == 400); +} |