diff options
author | mtklein <mtklein@chromium.org> | 2014-09-02 15:19:48 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2014-09-02 15:19:48 -0700 |
commit | 937c9c7eb4e06d4d3bc495e129c7b8103a5d6c0f (patch) | |
tree | 6b55340206e8628e0cf6faf21bb72896dcea9b8b /tests | |
parent | 294739b848c7103afa92390855175dd0bd1cc2d8 (diff) |
Fix drawPosText() bounds bug.
We didn't catch this in our local tests because we tend to use default
kUTF8_TextEncoding with single-byte characters, which means N == byteLength.
BUG=409110
R=reed@google.com, mtklein@google.com
Author: mtklein@chromium.org
Review URL: https://codereview.chromium.org/531933002
Diffstat (limited to 'tests')
-rw-r--r-- | tests/RecordDrawTest.cpp | 43 |
1 files changed, 36 insertions, 7 deletions
diff --git a/tests/RecordDrawTest.cpp b/tests/RecordDrawTest.cpp index 11b835b0ca..9e42e0a1c4 100644 --- a/tests/RecordDrawTest.cpp +++ b/tests/RecordDrawTest.cpp @@ -117,13 +117,18 @@ struct TestBBH : public SkBBoxHierarchy { SkTDArray<Entry> entries; }; +// Like a==b, with a little slop recognizing that float equality can be weird. +static bool sloppy_rect_eq(SkRect a, SkRect b) { + SkRect inset(a), outset(a); + inset.inset(1, 1); + outset.outset(1, 1); + return outset.contains(b) && !inset.contains(b); +} + // This test is not meant to make total sense yet. It's testing the status quo // of SkRecordFillBounds(), which itself doesn't make total sense yet. DEF_TEST(RecordDraw_BBH, r) { - TestBBH bbh; - SkRecord record; - SkRecorder recorder(&record, W, H); recorder.save(); recorder.clipRect(SkRect::MakeWH(400, 500)); @@ -131,19 +136,43 @@ DEF_TEST(RecordDraw_BBH, r) { recorder.drawRect(SkRect::MakeWH(320, 240), SkPaint()); recorder.restore(); + TestBBH bbh; SkRecordFillBounds(record, &bbh); REPORTER_ASSERT(r, bbh.entries.count() == 5); for (int i = 0; i < bbh.entries.count(); i++) { REPORTER_ASSERT(r, bbh.entries[i].data == (uintptr_t)i); - // We'd like to assert bounds == SkRect::MakeWH(400, 480). - // But we allow a little slop in recognition that float equality can be weird. - REPORTER_ASSERT(r, SkRect::MakeLTRB(-1, -1, 401, 481).contains(bbh.entries[i].bounds)); - REPORTER_ASSERT(r, !SkRect::MakeLTRB(+1, +1, 399, 479).contains(bbh.entries[i].bounds)); + REPORTER_ASSERT(r, sloppy_rect_eq(SkRect::MakeWH(400, 480), bbh.entries[i].bounds)); } } +// A regression test for crbug.com/409110. +DEF_TEST(RecordDraw_TextBounds, r) { + SkRecord record; + SkRecorder recorder(&record, W, H); + + // Two Chinese characters in UTF-8. + const char text[] = { '\xe6', '\xbc', '\xa2', '\xe5', '\xad', '\x97' }; + const size_t bytes = SK_ARRAY_COUNT(text); + + const SkScalar xpos[] = { 10, 20 }; + recorder.drawPosTextH(text, bytes, xpos, 30, SkPaint()); + + const SkPoint pos[] = { {40, 50}, {60, 70} }; + recorder.drawPosText(text, bytes, pos, SkPaint()); + + TestBBH bbh; + SkRecordFillBounds(record, &bbh); + REPORTER_ASSERT(r, bbh.entries.count() == 2); + + // We can make these next assertions confidently because SkRecordFillBounds + // builds its bounds by overestimating font metrics in a platform-independent way. + // If that changes, these tests will need to be more flexible. + REPORTER_ASSERT(r, sloppy_rect_eq(bbh.entries[0].bounds, SkRect::MakeLTRB(-86, 6, 116, 54))); + REPORTER_ASSERT(r, sloppy_rect_eq(bbh.entries[1].bounds, SkRect::MakeLTRB(-56, 26, 156, 94))); +} + // Base test to ensure start/stop range is respected DEF_TEST(RecordDraw_PartialStartStop, r) { static const int kWidth = 10, kHeight = 10; |