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

Unified Diff: third_party/WebKit/Source/core/svg/SVGPathParserTest.cpp

Issue 1642463004: Extended error reporting for SVG path parsing (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: "path flag" -> "arc flag" Created 4 years, 11 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
Index: third_party/WebKit/Source/core/svg/SVGPathParserTest.cpp
diff --git a/third_party/WebKit/Source/core/svg/SVGPathParserTest.cpp b/third_party/WebKit/Source/core/svg/SVGPathParserTest.cpp
index 8cfa4de2bfc2d72409068d5bcbf7b7cf56b118c8..3a27ca62b37ecc2830272683e95adc79357a8dbc 100644
--- a/third_party/WebKit/Source/core/svg/SVGPathParserTest.cpp
+++ b/third_party/WebKit/Source/core/svg/SVGPathParserTest.cpp
@@ -141,6 +141,49 @@ TEST(SVGPathParserTest, Simple)
#undef MALFORMED
#undef VALID
+SVGParsingError parsePathWithError(const char* input)
+{
+ String inputString(input);
+ SVGPathStringSource source(inputString);
+ SVGPathStringBuilder builder;
+ SVGPathParser parser(&source, &builder);
+ parser.parsePathDataFromSource();
+ return source.parseError();
+}
+
+#define EXPECT_ERROR(input, expectedLocus, expectedError) \
+ { \
+ SVGParsingError error = parsePathWithError(input); \
+ EXPECT_EQ(expectedError, error.status()); \
+ EXPECT_TRUE(error.hasLocus()); \
+ EXPECT_EQ(expectedLocus, error.locus()); \
+ }
+
+TEST(SVGPathParserTest, ErrorReporting)
+{
+ // Missing initial moveto.
+ EXPECT_ERROR(" 10 10", 1u, SVGParseStatus::ExpectedMoveToCommand);
+ EXPECT_ERROR("L 10 10", 0u, SVGParseStatus::ExpectedMoveToCommand);
+ // Invalid command letter.
+ EXPECT_ERROR("M 10 10 #", 8u, SVGParseStatus::ExpectedPathCommand);
+ EXPECT_ERROR("M 10 10 E 100 100", 8u, SVGParseStatus::ExpectedPathCommand);
+ // Invalid number.
+ EXPECT_ERROR("M 10 10 L100 ", 13u, SVGParseStatus::ExpectedNumber);
+ EXPECT_ERROR("M 10 10 L100 #", 13u, SVGParseStatus::ExpectedNumber);
+ EXPECT_ERROR("M 10 10 L100#100", 12u, SVGParseStatus::ExpectedNumber);
+ EXPECT_ERROR("M0,0 A#,10 0 0,0 20,20", 6u, SVGParseStatus::ExpectedNumber);
+ EXPECT_ERROR("M0,0 A10,# 0 0,0 20,20", 9u, SVGParseStatus::ExpectedNumber);
+ EXPECT_ERROR("M0,0 A10,10 # 0,0 20,20", 12u, SVGParseStatus::ExpectedNumber);
+ EXPECT_ERROR("M0,0 A10,10 0 0,0 #,20", 18u, SVGParseStatus::ExpectedNumber);
+ EXPECT_ERROR("M0,0 A10,10 0 0,0 20,#", 21u, SVGParseStatus::ExpectedNumber);
+ // Invalid arc-flag.
+ EXPECT_ERROR("M0,0 A10,10 0 #,0 20,20", 14u, SVGParseStatus::ExpectedArcFlag);
+ EXPECT_ERROR("M0,0 A10,10 0 0,# 20,20", 16u, SVGParseStatus::ExpectedArcFlag);
+ EXPECT_ERROR("M0,0 A10,10 0 0,2 20,20", 16u, SVGParseStatus::ExpectedArcFlag);
+}
+
+#undef EXPECT_ERROR
+
} // namespace
} // namespace blink
« no previous file with comments | « third_party/WebKit/Source/core/svg/SVGPath.cpp ('k') | third_party/WebKit/Source/core/svg/SVGPathStringSource.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698