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

Side by Side 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, 10 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 unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "core/svg/SVGPathParser.h" 5 #include "core/svg/SVGPathParser.h"
6 6
7 #include "core/svg/SVGPathStringBuilder.h" 7 #include "core/svg/SVGPathStringBuilder.h"
8 #include "core/svg/SVGPathStringSource.h" 8 #include "core/svg/SVGPathStringSource.h"
9 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 10
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 VALID("M1,1T2,3 4,5", "M 1 1 T 2 3 T 4 5"); 134 VALID("M1,1T2,3 4,5", "M 1 1 T 2 3 T 4 5");
135 MALFORMED("M1,1a2,3,4,0,0,5,6 7", "M 1 1 a 2 3 4 0 0 5 6"); 135 MALFORMED("M1,1a2,3,4,0,0,5,6 7", "M 1 1 a 2 3 4 0 0 5 6");
136 VALID("M1,1a2,3,4,0,0,5,6 7,8,9,0,0,10,11", "M 1 1 a 2 3 4 0 0 5 6 a 7 8 9 0 0 10 11"); 136 VALID("M1,1a2,3,4,0,0,5,6 7,8,9,0,0,10,11", "M 1 1 a 2 3 4 0 0 5 6 a 7 8 9 0 0 10 11");
137 MALFORMED("M1,1A2,3,4,0,0,5,6 7", "M 1 1 A 2 3 4 0 0 5 6"); 137 MALFORMED("M1,1A2,3,4,0,0,5,6 7", "M 1 1 A 2 3 4 0 0 5 6");
138 VALID("M1,1A2,3,4,0,0,5,6 7,8,9,0,0,10,11", "M 1 1 A 2 3 4 0 0 5 6 A 7 8 9 0 0 10 11"); 138 VALID("M1,1A2,3,4,0,0,5,6 7,8,9,0,0,10,11", "M 1 1 A 2 3 4 0 0 5 6 A 7 8 9 0 0 10 11");
139 } 139 }
140 140
141 #undef MALFORMED 141 #undef MALFORMED
142 #undef VALID 142 #undef VALID
143 143
144 SVGParsingError parsePathWithError(const char* input)
145 {
146 String inputString(input);
147 SVGPathStringSource source(inputString);
148 SVGPathStringBuilder builder;
149 SVGPathParser parser(&source, &builder);
150 parser.parsePathDataFromSource();
151 return source.parseError();
152 }
153
154 #define EXPECT_ERROR(input, expectedLocus, expectedError) \
155 { \
156 SVGParsingError error = parsePathWithError(input); \
157 EXPECT_EQ(expectedError, error.status()); \
158 EXPECT_TRUE(error.hasLocus()); \
159 EXPECT_EQ(expectedLocus, error.locus()); \
160 }
161
162 TEST(SVGPathParserTest, ErrorReporting)
163 {
164 // Missing initial moveto.
165 EXPECT_ERROR(" 10 10", 1u, SVGParseStatus::ExpectedMoveToCommand);
166 EXPECT_ERROR("L 10 10", 0u, SVGParseStatus::ExpectedMoveToCommand);
167 // Invalid command letter.
168 EXPECT_ERROR("M 10 10 #", 8u, SVGParseStatus::ExpectedPathCommand);
169 EXPECT_ERROR("M 10 10 E 100 100", 8u, SVGParseStatus::ExpectedPathCommand);
170 // Invalid number.
171 EXPECT_ERROR("M 10 10 L100 ", 13u, SVGParseStatus::ExpectedNumber);
172 EXPECT_ERROR("M 10 10 L100 #", 13u, SVGParseStatus::ExpectedNumber);
173 EXPECT_ERROR("M 10 10 L100#100", 12u, SVGParseStatus::ExpectedNumber);
174 EXPECT_ERROR("M0,0 A#,10 0 0,0 20,20", 6u, SVGParseStatus::ExpectedNumber);
175 EXPECT_ERROR("M0,0 A10,# 0 0,0 20,20", 9u, SVGParseStatus::ExpectedNumber);
176 EXPECT_ERROR("M0,0 A10,10 # 0,0 20,20", 12u, SVGParseStatus::ExpectedNumber) ;
177 EXPECT_ERROR("M0,0 A10,10 0 0,0 #,20", 18u, SVGParseStatus::ExpectedNumber);
178 EXPECT_ERROR("M0,0 A10,10 0 0,0 20,#", 21u, SVGParseStatus::ExpectedNumber);
179 // Invalid arc-flag.
180 EXPECT_ERROR("M0,0 A10,10 0 #,0 20,20", 14u, SVGParseStatus::ExpectedArcFlag );
181 EXPECT_ERROR("M0,0 A10,10 0 0,# 20,20", 16u, SVGParseStatus::ExpectedArcFlag );
182 EXPECT_ERROR("M0,0 A10,10 0 0,2 20,20", 16u, SVGParseStatus::ExpectedArcFlag );
183 }
184
185 #undef EXPECT_ERROR
186
144 } // namespace 187 } // namespace
145 188
146 } // namespace blink 189 } // namespace blink
OLDNEW
« 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