aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--gyp/tests.gyp3
-rw-r--r--src/core/SkPicturePlayback.cpp4
-rw-r--r--tests/PictureTest.cpp42
3 files changed, 47 insertions, 2 deletions
diff --git a/gyp/tests.gyp b/gyp/tests.gyp
index 7154638be7..dcfd1b49f8 100644
--- a/gyp/tests.gyp
+++ b/gyp/tests.gyp
@@ -64,8 +64,9 @@
'../tests/PathMeasureTest.cpp',
'../tests/PathTest.cpp',
'../tests/PDFPrimitivesTest.cpp',
- '../tests/PipeTest.cpp',
+ '../tests/PictureTest.cpp',
'../tests/PictureUtilsTest.cpp',
+ '../tests/PipeTest.cpp',
'../tests/PointTest.cpp',
'../tests/PremulAlphaRoundTripTest.cpp',
'../tests/QuickRejectTest.cpp',
diff --git a/src/core/SkPicturePlayback.cpp b/src/core/SkPicturePlayback.cpp
index cb4a83828d..e3181d0cb9 100644
--- a/src/core/SkPicturePlayback.cpp
+++ b/src/core/SkPicturePlayback.cpp
@@ -69,8 +69,10 @@ SkPicturePlayback::SkPicturePlayback(const SkPictureRecord& record, bool deepCop
record.validate();
const SkWriter32& writer = record.writeStream();
init();
- if (writer.size() == 0)
+ if (writer.size() == 0) {
+ fOpData = SkData::NewEmpty();
return;
+ }
fBoundingHierarchy = record.fBoundingHierarchy;
fStateTree = record.fStateTree;
diff --git a/tests/PictureTest.cpp b/tests/PictureTest.cpp
new file mode 100644
index 0000000000..34d7832034
--- /dev/null
+++ b/tests/PictureTest.cpp
@@ -0,0 +1,42 @@
+/*
+ * Copyright 2012 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+#include "Test.h"
+#include "SkPicture.h"
+#include "SkStream.h"
+
+#ifdef SK_DEBUG
+// Ensure that deleting SkPicturePlayback does not assert. Asserts only fire in debug mode, so only
+// run in debug mode.
+static void test_deleting_empty_playback() {
+ SkPicture picture;
+ // Creates an SkPictureRecord
+ picture.beginRecording(0, 0);
+ // Turns that into an SkPicturePlayback
+ picture.endRecording();
+ // Deletes the old SkPicturePlayback, and creates a new SkPictureRecord
+ picture.beginRecording(0, 0);
+}
+
+// Ensure that serializing an empty picture does not assert. Likewise only runs in debug mode.
+static void test_serializing_empty_picture() {
+ SkPicture picture;
+ picture.beginRecording(0, 0);
+ picture.endRecording();
+ SkDynamicMemoryWStream stream;
+ picture.serialize(&stream);
+}
+#endif
+
+static void TestPicture(skiatest::Reporter* reporter) {
+#ifdef SK_DEBUG
+ test_deleting_empty_playback();
+ test_serializing_empty_picture();
+#endif
+}
+
+#include "TestClassDef.h"
+DEFINE_TESTCLASS("Picture", PictureTestClass, TestPicture)