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

Unified Diff: tests/StreamTest.cpp

Issue 1298243002: SkPDF/Deflate: clean up old SkFlate code (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 2015-08-18 (Tuesday) 16:19:01 EDT Created 5 years, 4 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
« no previous file with comments | « tests/PDFPrimitivesTest.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/StreamTest.cpp
diff --git a/tests/StreamTest.cpp b/tests/StreamTest.cpp
index 926cfc25796b11a84716aae5ed4c77004fa42400..78c0e506db47cc77725f8a2b29cf72440bc65c79 100644
--- a/tests/StreamTest.cpp
+++ b/tests/StreamTest.cpp
@@ -11,6 +11,7 @@
#include "SkOSFile.h"
#include "SkRandom.h"
#include "SkStream.h"
+#include "SkStreamPriv.h"
#include "Test.h"
#ifndef SK_BUILD_FOR_WIN
@@ -335,3 +336,60 @@ DEF_TEST(StreamPeek_BlockMemoryStream, rep) {
}
stream_peek_test(rep, asset, expected);
}
+
+namespace {
+class DumbStream : public SkStream {
+public:
+ DumbStream(const uint8_t* data, size_t n)
+ : fData(data), fCount(n), fIdx(0) {}
+ size_t read(void* buffer, size_t size) override {
+ size_t c = SkTMin(fCount - fIdx, size);
+ if (c) {
+ memcpy(buffer, &fData[fIdx], size);
+ fIdx += c;
+ }
+ return c;
+ }
+ bool isAtEnd() const override {
+ return fCount > fIdx;
+ }
+ private:
+ const uint8_t* fData;
+ size_t fCount, fIdx;
+};
+} // namespace
+
+static void stream_copy_test(skiatest::Reporter* reporter,
+ const void* srcData,
+ size_t N,
+ SkStream* stream) {
+ SkDynamicMemoryWStream tgt;
+ if (!SkStreamCopy(&tgt, stream)) {
+ ERRORF(reporter, "SkStreamCopy failed");
+ return;
+ }
+ SkAutoTUnref<SkData> data(tgt.copyToData());
+ tgt.reset();
+ if (data->size() != N) {
+ ERRORF(reporter, "SkStreamCopy incorrect size");
+ return;
+ }
+ if (0 != memcmp(data->data(), srcData, N)) {
+ ERRORF(reporter, "SkStreamCopy bad copy");
+ }
+}
+
+DEF_TEST(StreamCopy, reporter) {
+ SkRandom random(123456);
+ static const size_t N = 10000;
+ uint8_t src[N];
+ for (size_t j = 0; j < N; ++j) {
+ src[j] = random.nextU() & 0xff;
+ }
+ // SkStreamCopy had two code paths; this test both.
hal.canary 2015/08/18 20:19:52 I also expanded this test.
+ DumbStream dumbStream(src, N);
+ stream_copy_test(reporter, src, N, &dumbStream);
+ SkMemoryStream smartStream(src, N);
+ stream_copy_test(reporter, src, N, &smartStream);
+
+}
« no previous file with comments | « tests/PDFPrimitivesTest.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698