OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "config.h" |
| 6 #include "core/svg/SVGPathParser.h" |
| 7 |
| 8 #include "core/svg/SVGPathStringBuilder.h" |
| 9 #include "core/svg/SVGPathStringSource.h" |
| 10 |
| 11 #include <gtest/gtest.h> |
| 12 |
| 13 namespace blink { |
| 14 |
| 15 namespace { |
| 16 |
| 17 bool parsePath(const char* input, String& output) |
| 18 { |
| 19 String inputString(input); |
| 20 SVGPathStringSource source(inputString); |
| 21 SVGPathStringBuilder builder; |
| 22 SVGPathParser parser(&source, &builder); |
| 23 bool hadError = parser.parsePathDataFromSource(UnalteredParsing, true); |
| 24 output = builder.result(); |
| 25 // Coerce a null result to empty. |
| 26 if (output.isNull()) |
| 27 output = emptyString(); |
| 28 return hadError; |
| 29 } |
| 30 |
| 31 #define VALID(input, expected) \ |
| 32 { \ |
| 33 String output; \ |
| 34 EXPECT_TRUE(parsePath(input, output)); \ |
| 35 EXPECT_EQ(expected, output); \ |
| 36 } |
| 37 |
| 38 #define MALFORMED(input, expected) \ |
| 39 { \ |
| 40 String output; \ |
| 41 EXPECT_FALSE(parsePath(input, output)); \ |
| 42 EXPECT_EQ(expected, output); \ |
| 43 } |
| 44 |
| 45 TEST(SVGPathParserTest, Simple) |
| 46 { |
| 47 VALID("M1,2", "M 1 2"); |
| 48 VALID("m1,2", "m 1 2"); |
| 49 VALID("M100,200 m3,4", "M 100 200 m 3 4"); |
| 50 VALID("M100,200 L3,4", "M 100 200 L 3 4"); |
| 51 VALID("M100,200 l3,4", "M 100 200 l 3 4"); |
| 52 VALID("M100,200 H3", "M 100 200 H 3"); |
| 53 VALID("M100,200 h3", "M 100 200 h 3"); |
| 54 VALID("M100,200 V3", "M 100 200 V 3"); |
| 55 VALID("M100,200 v3", "M 100 200 v 3"); |
| 56 VALID("M100,200 Z", "M 100 200 Z"); |
| 57 VALID("M100,200 z", "M 100 200 Z"); |
| 58 VALID("M100,200 C3,4,5,6,7,8", "M 100 200 C 3 4 5 6 7 8"); |
| 59 VALID("M100,200 c3,4,5,6,7,8", "M 100 200 c 3 4 5 6 7 8"); |
| 60 VALID("M100,200 S3,4,5,6", "M 100 200 S 3 4 5 6"); |
| 61 VALID("M100,200 s3,4,5,6", "M 100 200 s 3 4 5 6"); |
| 62 VALID("M100,200 Q3,4,5,6", "M 100 200 Q 3 4 5 6"); |
| 63 VALID("M100,200 q3,4,5,6", "M 100 200 q 3 4 5 6"); |
| 64 VALID("M100,200 T3,4", "M 100 200 T 3 4"); |
| 65 VALID("M100,200 t3,4", "M 100 200 t 3 4"); |
| 66 VALID("M100,200 A3,4,5,0,0,6,7", "M 100 200 A 3 4 5 0 0 6 7"); |
| 67 VALID("M100,200 A3,4,5,1,0,6,7", "M 100 200 A 3 4 5 1 0 6 7"); |
| 68 VALID("M100,200 A3,4,5,0,1,6,7", "M 100 200 A 3 4 5 0 1 6 7"); |
| 69 VALID("M100,200 A3,4,5,1,1,6,7", "M 100 200 A 3 4 5 1 1 6 7"); |
| 70 VALID("M100,200 a3,4,5,0,0,6,7", "M 100 200 a 3 4 5 0 0 6 7"); |
| 71 VALID("M100,200 a3,4,5,0,1,6,7", "M 100 200 a 3 4 5 0 1 6 7"); |
| 72 VALID("M100,200 a3,4,5,1,0,6,7", "M 100 200 a 3 4 5 1 0 6 7"); |
| 73 VALID("M100,200 a3,4,5,1,1,6,7", "M 100 200 a 3 4 5 1 1 6 7"); |
| 74 VALID("M100,200 a3,4,5,006,7", "M 100 200 a 3 4 5 0 0 6 7"); |
| 75 VALID("M100,200 a3,4,5,016,7", "M 100 200 a 3 4 5 0 1 6 7"); |
| 76 VALID("M100,200 a3,4,5,106,7", "M 100 200 a 3 4 5 1 0 6 7"); |
| 77 VALID("M100,200 a3,4,5,116,7", "M 100 200 a 3 4 5 1 1 6 7"); |
| 78 MALFORMED("M100,200 a3,4,5,2,1,6,7", "M 100 200"); |
| 79 MALFORMED("M100,200 a3,4,5,1,2,6,7", "M 100 200"); |
| 80 |
| 81 VALID("M100,200 a0,4,5,0,0,10,0 a4,0,5,0,0,0,10 a0,0,5,0,0,-10,0 z", "M 100
200 a 0 4 5 0 0 10 0 a 4 0 5 0 0 0 10 a 0 0 5 0 0 -10 0 Z"); |
| 82 |
| 83 VALID("M1,2,3,4", "M 1 2 L 3 4"); |
| 84 VALID("m100,200,3,4", "m 100 200 l 3 4"); |
| 85 |
| 86 VALID("M 100-200", "M 100 -200"); |
| 87 VALID("M 0.6.5", "M 0.6 0.5"); |
| 88 |
| 89 VALID(" M1,2", "M 1 2"); |
| 90 VALID(" M1,2", "M 1 2"); |
| 91 VALID("\tM1,2", "M 1 2"); |
| 92 VALID("\nM1,2", "M 1 2"); |
| 93 VALID("\rM1,2", "M 1 2"); |
| 94 MALFORMED("\vM1,2", ""); |
| 95 MALFORMED("xM1,2", ""); |
| 96 VALID("M1,2 ", "M 1 2"); |
| 97 VALID("M1,2\t", "M 1 2"); |
| 98 VALID("M1,2\n", "M 1 2"); |
| 99 VALID("M1,2\r", "M 1 2"); |
| 100 MALFORMED("M1,2\v", "M 1 2"); |
| 101 MALFORMED("M1,2x", "M 1 2"); |
| 102 MALFORMED("M1,2 L40,0#90", "M 1 2 L 40 0"); |
| 103 |
| 104 VALID("", ""); |
| 105 VALID(" ", ""); |
| 106 MALFORMED("x", ""); |
| 107 MALFORMED("L1,2", ""); |
| 108 VALID("M.1 .2 L.3 .4 .5 .6", "M 0.1 0.2 L 0.3 0.4 L 0.5 0.6"); |
| 109 |
| 110 MALFORMED("M", ""); |
| 111 MALFORMED("M\0", ""); |
| 112 |
| 113 MALFORMED("M1,1Z0", "M 1 1 Z"); |
| 114 } |
| 115 |
| 116 #undef MALFORMED |
| 117 #undef VALID |
| 118 |
| 119 } |
| 120 |
| 121 } // namespace blink |
OLD | NEW |