diff options
author | reed@android.com <reed@android.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2009-06-05 16:21:03 +0000 |
---|---|---|
committer | reed@android.com <reed@android.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2009-06-05 16:21:03 +0000 |
commit | bbff1d507aa3f470139e2df409e94074a2f9425f (patch) | |
tree | 1c58cdd9211057604ad3b3c804637e784f83ce3c /tests | |
parent | ec3d6e5a2fada32dfc762ed82ca6155746f664a3 (diff) |
add SkParsePath to go to/from SVG strings (e.g. "M0,0 L10,20")
git-svn-id: http://skia.googlecode.com/svn/trunk@203 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'tests')
-rw-r--r-- | tests/ParsePathTest.cpp | 58 | ||||
-rw-r--r-- | tests/tests_files.mk | 20 |
2 files changed, 78 insertions, 0 deletions
diff --git a/tests/ParsePathTest.cpp b/tests/ParsePathTest.cpp new file mode 100644 index 0000000000..917b0cb538 --- /dev/null +++ b/tests/ParsePathTest.cpp @@ -0,0 +1,58 @@ +#include "Test.h" +#include "SkParsePath.h" + +static void test_to_from(skiatest::Reporter* reporter, const SkPath& path) { + SkString str, str2; + SkParsePath::ToSVGString(path, &str); + + SkPath path2; + bool success = SkParsePath::FromSVGString(str.c_str(), &path2); + REPORTER_ASSERT(reporter, success); + + SkParsePath::ToSVGString(path2, &str2); + REPORTER_ASSERT(reporter, str == str2); +#if 0 // closed paths are not equal, the iter explicitly gives the closing + // edge, even if it is not in the path. + REPORTER_ASSERT(reporter, path == path2); + if (path != path2) { + SkDebugf("str1=%s\nstr2=%s\n", str.c_str(), str2.c_str()); + } +#endif +} + +static void TestParsePath(skiatest::Reporter* reporter) { + static const struct { + const char* fStr; + SkRect fBounds; + } gRec[] = { + { "", { 0, 0, 0, 0 } }, + { "M0,0L10,10", { 0, 0, SkIntToScalar(10), SkIntToScalar(10) } }, + { "M-5.5,-0.5 Q 0 0 6,6.50", + { SkFloatToScalar(-5.5f), SkFloatToScalar(-0.5f), + SkFloatToScalar(6), SkFloatToScalar(6.5f) } } + }; + + for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); i++) { + SkPath path; + bool success = SkParsePath::FromSVGString(gRec[i].fStr, &path); + REPORTER_ASSERT(reporter, success); + const SkRect& expectedBounds = gRec[i].fBounds; + const SkRect& pathBounds = path.getBounds(); + REPORTER_ASSERT(reporter, expectedBounds == pathBounds); + + test_to_from(reporter, path); + } + + SkRect r; + r.set(0, 0, SkFloatToScalar(10), SkFloatToScalar(10.5)); + SkPath p; + p.addRect(r); + test_to_from(reporter, p); + p.addOval(r); + test_to_from(reporter, p); + p.addRoundRect(r, SkFloatToScalar(4), SkFloatToScalar(4.5)); + test_to_from(reporter, p); +} + +#include "TestClassDef.h" +DEFINE_TESTCLASS("ParsePath", ParsePathClass, TestParsePath) diff --git a/tests/tests_files.mk b/tests/tests_files.mk new file mode 100644 index 0000000000..bce5be7dc4 --- /dev/null +++ b/tests/tests_files.mk @@ -0,0 +1,20 @@ +SOURCE := \ + GeometryTest.cpp \ + MathTest.cpp \ + MatrixTest.cpp \ + PackBitsTest.cpp \ + Sk64Test.cpp \ + StringTest.cpp \ + Test.cpp \ + UtilsTest.cpp \ + ParsePathTest.cpp \ + PathTest.cpp \ + ClipCubicTest.cpp \ + SrcOverTest.cpp \ + StreamTest.cpp \ + SortTest.cpp \ + BitmapCopyTest.cpp \ + PathMeasureTest.cpp \ + TriangulationTest.cpp \ + TestSize.cpp \ + testmain.cpp |