diff options
author | scroggo <scroggo@google.com> | 2016-01-11 06:38:00 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-01-11 06:38:00 -0800 |
commit | b512aaa5c808bcb1336c147682657882ee54e652 (patch) | |
tree | f41946ac736809519f55ce9b46ba5da98ed3331e /tests/DataRefTest.cpp | |
parent | 0b558cb42c6771b310520b2db41310c1da746f0c (diff) |
Make SkROBuffer::Iter::size() work when exhausted
According to the documentation, this method will return 0 when the Iter
is exhausted. Prior to this CL, it crashes instead.
Prevent a crash with a null fHead, and add a test to verify the
behavior.
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1574603002
Review URL: https://codereview.chromium.org/1574603002
Diffstat (limited to 'tests/DataRefTest.cpp')
-rw-r--r-- | tests/DataRefTest.cpp | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/tests/DataRefTest.cpp b/tests/DataRefTest.cpp index 0c7d5f4520..f1e645ec7e 100644 --- a/tests/DataRefTest.cpp +++ b/tests/DataRefTest.cpp @@ -313,3 +313,18 @@ DEF_TEST(RWBuffer, reporter) { delete streams[i]; } } + +// Tests that it is safe to call SkROBuffer::Iter::size() when exhausted. +DEF_TEST(RWBuffer_size, r) { + SkRWBuffer buffer; + buffer.append(gABC, 26); + + SkAutoTUnref<SkROBuffer> roBuffer(buffer.newRBufferSnapshot()); + SkROBuffer::Iter iter(roBuffer); + REPORTER_ASSERT(r, iter.data()); + REPORTER_ASSERT(r, iter.size() == 26); + + // There is only one block in this buffer. + REPORTER_ASSERT(r, !iter.next()); + REPORTER_ASSERT(r, 0 == iter.size()); +} |