add path dump test
Add a unit test for SkPath::dump(). The unit test exposed a minor
bug (inconsistent CRs) and an unused parameter (title).
R=bsalomon@google.com
TBR=bsalomon
BUG=skia:1836
Author: caryclark@google.com
Review URL: https://codereview.chromium.org/351833003
diff --git a/include/core/SkPath.h b/include/core/SkPath.h
index d78cd88..bccc8d5 100644
--- a/include/core/SkPath.h
+++ b/include/core/SkPath.h
@@ -21,6 +21,7 @@
class SkAutoPathBoundsUpdate;
class SkString;
class SkRRect;
+class SkWStream;
/** \class SkPath
@@ -930,7 +931,7 @@
*/
bool contains(SkScalar x, SkScalar y) const;
- void dump(bool forceClose, const char title[] = NULL) const;
+ void dump(SkWStream* , bool forceClose) const;
void dump() const;
/**
diff --git a/src/core/SkClipStack.cpp b/src/core/SkClipStack.cpp
index a965b1b..85746b2 100644
--- a/src/core/SkClipStack.cpp
+++ b/src/core/SkClipStack.cpp
@@ -891,7 +891,7 @@
SkDebugf("\n");
break;
case kPath_Type:
- this->getPath().dump(true);
+ this->getPath().dump(NULL, true);
break;
}
}
diff --git a/src/core/SkPath.cpp b/src/core/SkPath.cpp
index 075cfdb..7f2e67a 100644
--- a/src/core/SkPath.cpp
+++ b/src/core/SkPath.cpp
@@ -2111,6 +2111,7 @@
///////////////////////////////////////////////////////////////////////////////
#include "SkString.h"
+#include "SkStream.h"
static void append_scalar(SkString* str, SkScalar value) {
SkString tmp;
@@ -2142,14 +2143,14 @@
str->append(");\n");
}
-void SkPath::dump(bool forceClose, const char title[]) const {
+void SkPath::dump(SkWStream* wStream, bool forceClose) const {
Iter iter(*this, forceClose);
SkPoint pts[4];
Verb verb;
- SkDebugf("path: forceClose=%s %s\n", forceClose ? "true" : "false",
- title ? title : "");
-
+ if (!wStream) {
+ SkDebugf("path: forceClose=%s\n", forceClose ? "true" : "false");
+ }
SkString builder;
while ((verb = iter.next(pts, false)) != kDone_Verb) {
@@ -2170,7 +2171,7 @@
append_params(&builder, "path.cubicTo", &pts[1], 3);
break;
case kClose_Verb:
- builder.append("path.close();");
+ builder.append("path.close();\n");
break;
default:
SkDebugf(" path: UNKNOWN VERB %d, aborting dump...\n", verb);
@@ -2178,11 +2179,15 @@
break;
}
}
- SkDebugf("%s\n", builder.c_str());
+ if (wStream) {
+ wStream->writeText(builder.c_str());
+ } else {
+ SkDebugf("%s", builder.c_str());
+ }
}
void SkPath::dump() const {
- this->dump(false);
+ this->dump(NULL, false);
}
#ifdef SK_DEBUG
diff --git a/tests/PathTest.cpp b/tests/PathTest.cpp
index e265d31..3941ad6 100644
--- a/tests/PathTest.cpp
+++ b/tests/PathTest.cpp
@@ -15,6 +15,7 @@
#include "SkRandom.h"
#include "SkReader32.h"
#include "SkSize.h"
+#include "SkStream.h"
#include "SkSurface.h"
#include "SkTypes.h"
#include "SkWriter32.h"
@@ -3364,6 +3365,44 @@
REPORTER_ASSERT(reporter, a == b);
}
+static void compare_dump(skiatest::Reporter* reporter, const SkPath& path, bool force,
+ const char* str) {
+ SkDynamicMemoryWStream wStream;
+ path.dump(&wStream, force);
+ SkAutoDataUnref data(wStream.copyToData());
+ REPORTER_ASSERT(reporter, data->size() == strlen(str));
+ REPORTER_ASSERT(reporter, !memcmp(data->data(), str, strlen(str)));
+}
+
+static void test_dump(skiatest::Reporter* reporter) {
+ SkPath p;
+ compare_dump(reporter, p, false, "");
+ compare_dump(reporter, p, true, "");
+ p.moveTo(1, 2);
+ p.lineTo(3, 4);
+ compare_dump(reporter, p, false, "path.moveTo(1, 2);\n"
+ "path.lineTo(3, 4);\n");
+ compare_dump(reporter, p, true, "path.moveTo(1, 2);\n"
+ "path.lineTo(3, 4);\n"
+ "path.lineTo(1, 2);\n"
+ "path.close();\n");
+ p.reset();
+ p.moveTo(1, 2);
+ p.quadTo(3, 4, 5, 6);
+ compare_dump(reporter, p, false, "path.moveTo(1, 2);\n"
+ "path.quadTo(3, 4, 5, 6);\n");
+ p.reset();
+ p.moveTo(1, 2);
+ p.conicTo(3, 4, 5, 6, 0.5f);
+ compare_dump(reporter, p, false, "path.moveTo(1, 2);\n"
+ "path.conicTo(3, 4, 5, 6, 0.5f);\n");
+ p.reset();
+ p.moveTo(1, 2);
+ p.cubicTo(3, 4, 5, 6, 7, 8);
+ compare_dump(reporter, p, false, "path.moveTo(1, 2);\n"
+ "path.cubicTo(3, 4, 5, 6, 7, 8);\n");
+}
+
class PathTest_Private {
public:
static void TestPathTo(skiatest::Reporter* reporter) {
@@ -3513,4 +3552,5 @@
test_contains(reporter);
PathTest_Private::TestPathTo(reporter);
PathRefTest_Private::TestPathRef(reporter);
+ test_dump(reporter);
}