Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(65)

Unified Diff: tests/DataRefTest.cpp

Issue 1871953002: Fixes for SkRWBuffer (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« include/core/SkRWBuffer.h ('K') | « src/core/SkRWBuffer.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/DataRefTest.cpp
diff --git a/tests/DataRefTest.cpp b/tests/DataRefTest.cpp
index 03b80fb2af4683ffe97bd8ce24e68f2340a35cf7..9acb59ababb2de0af0cf08a0f3bb83d6639c4e2e 100644
--- a/tests/DataRefTest.cpp
+++ b/tests/DataRefTest.cpp
@@ -245,7 +245,7 @@ static void check_abcs(skiatest::Reporter* reporter, const char buffer[], size_t
}
}
-// stream should contains an integral number of copies of gABC.
+// stream should contain an integral number of copies of gABC.
static void check_alphabet_stream(skiatest::Reporter* reporter, SkStream* stream) {
REPORTER_ASSERT(reporter, stream->hasLength());
size_t size = stream->getLength();
@@ -284,6 +284,8 @@ static void check_alphabet_buffer(skiatest::Reporter* reporter, const SkROBuffer
check_abcs(reporter, storage.get(), size);
}
+#include "SkTaskGroup.h"
+
DEF_TEST(RWBuffer, reporter) {
// Knowing that the default capacity is 4096, choose N large enough so we force it to use
// multiple buffers internally.
@@ -292,6 +294,10 @@ DEF_TEST(RWBuffer, reporter) {
SkStream* streams[N];
{
+ // Declaring this SkTaskGroup inside this block ensures that all tasks will
mtklein 2016/04/08 17:13:49 You may just want to call .wait() instead of havin
scroggo 2016/04/11 16:24:42 Done.
+ // finish before testing again, down below. (This is necessary because the
+ // streams need to be rewound to be read again.)
+ SkTaskGroup tasks;
SkRWBuffer buffer;
for (int i = 0; i < N; ++i) {
if (0 == (i & 1)) {
@@ -301,12 +307,24 @@ DEF_TEST(RWBuffer, reporter) {
}
readers[i] = buffer.newRBufferSnapshot();
streams[i] = buffer.newStreamSnapshot();
+ REPORTER_ASSERT(reporter, readers[i]->size() == buffer.size());
+ REPORTER_ASSERT(reporter, streams[i]->getLength() == buffer.size());
+
+ tasks.add([reporter, i, readers, streams] {
scroggo 2016/04/08 16:15:29 DM will put this whole test in a task, and it will
mtklein 2016/04/08 17:13:49 The tasks this tests spawns can run in parallel wi
scroggo 2016/04/11 16:24:42 I have a different issue. It is perfectly safe to
+ REPORTER_ASSERT(reporter, (i + 1) * 26U == readers[i]->size());
+ REPORTER_ASSERT(reporter, streams[i]->getLength() == readers[i]->size());
+ check_alphabet_buffer(reporter, readers[i]);
+ check_alphabet_stream(reporter, streams[i]);
+ REPORTER_ASSERT(reporter, streams[i]->rewind());
+ });
}
REPORTER_ASSERT(reporter, N*26 == buffer.size());
}
+ // Test again, to verify that the snapshots work even after the SkRWBuffer is gone.
for (int i = 0; i < N; ++i) {
REPORTER_ASSERT(reporter, (i + 1) * 26U == readers[i]->size());
+ REPORTER_ASSERT(reporter, streams[i]->getLength() == readers[i]->size());
check_alphabet_buffer(reporter, readers[i]);
check_alphabet_stream(reporter, streams[i]);
readers[i]->unref();
@@ -329,9 +347,27 @@ DEF_TEST(RWBuffer_size, r) {
REPORTER_ASSERT(r, 0 == iter.size());
}
-// Tests that it is safe to destruct an SkRWBuffer without appending
-// anything to it.
+// Tests that operations (including the destructor) are safe on an SkRWBuffer
+// without any data appended.
DEF_TEST(RWBuffer_noAppend, r) {
SkRWBuffer buffer;
REPORTER_ASSERT(r, 0 == buffer.size());
+
+ sk_sp<SkROBuffer> roBuffer = sk_sp<SkROBuffer>(buffer.newRBufferSnapshot());
+ REPORTER_ASSERT(r, roBuffer);
+ if (roBuffer) {
+ REPORTER_ASSERT(r, roBuffer->size() == 0);
+ SkROBuffer::Iter iter(roBuffer.get());
+ REPORTER_ASSERT(r, iter.size() == 0);
+ REPORTER_ASSERT(r, !iter.data());
+ REPORTER_ASSERT(r, !iter.next());
+ }
+
+ SkAutoTDelete<SkStream> stream(buffer.newStreamSnapshot());
+ REPORTER_ASSERT(r, stream);
+ if (stream) {
+ REPORTER_ASSERT(r, stream->hasLength());
+ REPORTER_ASSERT(r, stream->getLength() == 0);
+ REPORTER_ASSERT(r, stream->skip(10) == 0);
+ }
}
« include/core/SkRWBuffer.h ('K') | « src/core/SkRWBuffer.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698