aboutsummaryrefslogtreecommitdiff
path: root/tests/PathTest.cpp
diff options
context:
space:
mode:
authorcaryclark <caryclark@google.com>2014-06-24 08:30:15 -0700
committerCommit bot <commit-bot@chromium.org>2014-06-24 08:30:18 -0700
commit66a5d8bf13fe98baae268db0211e9c25e5ece7fa (patch)
treefed68171b00635a9d321f92d2e5aaf5b128c25c3 /tests/PathTest.cpp
parentc11530ea73b2a2fcb431df0f5c1887d08ac9113c (diff)
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
Diffstat (limited to 'tests/PathTest.cpp')
-rw-r--r--tests/PathTest.cpp40
1 files changed, 40 insertions, 0 deletions
diff --git a/tests/PathTest.cpp b/tests/PathTest.cpp
index e265d317ca..3941ad6e18 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 @@ static void test_operatorEqual(skiatest::Reporter* reporter) {
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 @@ DEF_TEST(Paths, reporter) {
test_contains(reporter);
PathTest_Private::TestPathTo(reporter);
PathRefTest_Private::TestPathRef(reporter);
+ test_dump(reporter);
}