blob: 71d1fbae0002e432180cbf1f894c6669dc8ea009 [file] [log] [blame]
fmalita7a048692015-02-20 13:54:40 -08001/*
2 * Copyright 2015 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
Anas AlJabri84dd1832018-07-31 15:53:05 -07008#define ABORT_TEST(r, cond, ...) \
9 do { \
10 if (cond) { \
11 REPORT_FAILURE(r, #cond, SkStringPrintf(__VA_ARGS__)); \
12 return; \
13 } \
14 } while (0)
15
Mike Kleinc0bd9f92019-04-23 12:05:21 -050016#include "include/core/SkBitmap.h"
17#include "include/core/SkCanvas.h"
18#include "include/core/SkColorFilter.h"
19#include "include/core/SkData.h"
20#include "include/core/SkImage.h"
21#include "include/core/SkShader.h"
22#include "include/core/SkStream.h"
Florin Malita673e87c2019-07-19 13:59:38 -040023#include "include/core/SkTextBlob.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050024#include "include/private/SkTo.h"
Florin Malitaabc96532019-07-19 09:11:29 -040025#include "include/svg/SkSVGCanvas.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050026#include "include/utils/SkParse.h"
27#include "src/core/SkMakeUnique.h"
28#include "src/shaders/SkImageShader.h"
29#include "tests/Test.h"
Florin Malitaabc96532019-07-19 09:11:29 -040030#include "tools/ToolUtils.h"
fmalita7a048692015-02-20 13:54:40 -080031
32#include <string.h>
33
Alexander Midlash77e3afc2018-03-06 17:21:28 -080034#ifdef SK_XML
35
Mike Kleinc0bd9f92019-04-23 12:05:21 -050036#include "src/svg/SkSVGDevice.h"
37#include "src/xml/SkDOM.h"
38#include "src/xml/SkXMLWriter.h"
Ben Wagner6ce482a2018-03-27 10:57:43 -040039
Florin Malitaabc96532019-07-19 09:11:29 -040040static std::unique_ptr<SkCanvas> MakeDOMCanvas(SkDOM* dom, uint32_t flags = 0) {
Florin Malita562017b2019-02-14 13:42:15 -050041 auto svgDevice = SkSVGDevice::Make(SkISize::Make(100, 100),
Florin Malitaabc96532019-07-19 09:11:29 -040042 skstd::make_unique<SkXMLParserWriter>(dom->beginParsing()),
43 flags);
Florin Malita562017b2019-02-14 13:42:15 -050044 return svgDevice ? skstd::make_unique<SkCanvas>(svgDevice)
45 : nullptr;
46}
47
fmalita7a048692015-02-20 13:54:40 -080048namespace {
49
Alexander Midlash77e3afc2018-03-06 17:21:28 -080050
fmalita7a048692015-02-20 13:54:40 -080051void check_text_node(skiatest::Reporter* reporter,
52 const SkDOM& dom,
53 const SkDOM::Node* root,
54 const SkPoint& offset,
55 unsigned scalarsPerPos,
Florin Malita673e87c2019-07-19 13:59:38 -040056 const char* txt,
fmalita7a048692015-02-20 13:54:40 -080057 const char* expected) {
halcanary96fcdcc2015-08-27 07:41:13 -070058 if (root == nullptr) {
fmalita7a048692015-02-20 13:54:40 -080059 ERRORF(reporter, "root element not found.");
60 return;
61 }
62
63 const SkDOM::Node* textElem = dom.getFirstChild(root, "text");
halcanary96fcdcc2015-08-27 07:41:13 -070064 if (textElem == nullptr) {
fmalita7a048692015-02-20 13:54:40 -080065 ERRORF(reporter, "<text> element not found.");
66 return;
67 }
68 REPORTER_ASSERT(reporter, dom.getType(textElem) == SkDOM::kElement_Type);
69
70 const SkDOM::Node* textNode= dom.getFirstChild(textElem);
halcanary96fcdcc2015-08-27 07:41:13 -070071 REPORTER_ASSERT(reporter, textNode != nullptr);
72 if (textNode != nullptr) {
fmalita7a048692015-02-20 13:54:40 -080073 REPORTER_ASSERT(reporter, dom.getType(textNode) == SkDOM::kText_Type);
74 REPORTER_ASSERT(reporter, strcmp(expected, dom.getName(textNode)) == 0);
75 }
76
77 int textLen = SkToInt(strlen(expected));
78
79 const char* x = dom.findAttr(textElem, "x");
halcanary96fcdcc2015-08-27 07:41:13 -070080 REPORTER_ASSERT(reporter, x != nullptr);
81 if (x != nullptr) {
Florin Malita673e87c2019-07-19 13:59:38 -040082 int xposCount = textLen;
fmalita7a048692015-02-20 13:54:40 -080083 REPORTER_ASSERT(reporter, SkParse::Count(x) == xposCount);
84
85 SkAutoTMalloc<SkScalar> xpos(xposCount);
86 SkParse::FindScalars(x, xpos.get(), xposCount);
87 if (scalarsPerPos < 1) {
Florin Malita673e87c2019-07-19 13:59:38 -040088 // For default-positioned text, we cannot make any assumptions regarding
89 // the first glyph position when the string has leading whitespace (to be stripped).
90 if (txt[0] != ' ' && txt[0] != '\t') {
91 REPORTER_ASSERT(reporter, xpos[0] == offset.x());
92 }
fmalita7a048692015-02-20 13:54:40 -080093 } else {
94 for (int i = 0; i < xposCount; ++i) {
95 REPORTER_ASSERT(reporter, xpos[i] == SkIntToScalar(expected[i]));
96 }
97 }
98 }
99
100 const char* y = dom.findAttr(textElem, "y");
halcanary96fcdcc2015-08-27 07:41:13 -0700101 REPORTER_ASSERT(reporter, y != nullptr);
102 if (y != nullptr) {
fmalita7a048692015-02-20 13:54:40 -0800103 int yposCount = (scalarsPerPos < 2) ? 1 : textLen;
104 REPORTER_ASSERT(reporter, SkParse::Count(y) == yposCount);
105
106 SkAutoTMalloc<SkScalar> ypos(yposCount);
107 SkParse::FindScalars(y, ypos.get(), yposCount);
108 if (scalarsPerPos < 2) {
109 REPORTER_ASSERT(reporter, ypos[0] == offset.y());
110 } else {
111 for (int i = 0; i < yposCount; ++i) {
Florin Malita673e87c2019-07-19 13:59:38 -0400112 REPORTER_ASSERT(reporter, ypos[i] == 150 - SkIntToScalar(expected[i]));
fmalita7a048692015-02-20 13:54:40 -0800113 }
114 }
115 }
116}
117
118void test_whitespace_pos(skiatest::Reporter* reporter,
119 const char* txt,
120 const char* expected) {
121 size_t len = strlen(txt);
122
123 SkDOM dom;
124 SkPaint paint;
Florin Malita673e87c2019-07-19 13:59:38 -0400125 SkFont font(ToolUtils::create_portable_typeface());
fmalita7a048692015-02-20 13:54:40 -0800126 SkPoint offset = SkPoint::Make(10, 20);
127
128 {
Florin Malita673e87c2019-07-19 13:59:38 -0400129 MakeDOMCanvas(&dom)->drawSimpleText(txt, len, SkTextEncoding::kUTF8,
130 offset.x(), offset.y(), font, paint);
fmalita7a048692015-02-20 13:54:40 -0800131 }
Florin Malita673e87c2019-07-19 13:59:38 -0400132 check_text_node(reporter, dom, dom.finishParsing(), offset, 0, txt, expected);
fmalita7a048692015-02-20 13:54:40 -0800133
134 {
135 SkAutoTMalloc<SkScalar> xpos(len);
136 for (int i = 0; i < SkToInt(len); ++i) {
137 xpos[i] = SkIntToScalar(txt[i]);
138 }
139
Mike Reed212e9062018-12-25 17:35:49 -0500140 auto blob = SkTextBlob::MakeFromPosTextH(txt, len, &xpos[0], offset.y(), font);
Florin Malita673e87c2019-07-19 13:59:38 -0400141 MakeDOMCanvas(&dom)->drawTextBlob(blob, 0, 0, paint);
fmalita7a048692015-02-20 13:54:40 -0800142 }
Florin Malita673e87c2019-07-19 13:59:38 -0400143 check_text_node(reporter, dom, dom.finishParsing(), offset, 1, txt, expected);
fmalita7a048692015-02-20 13:54:40 -0800144
145 {
146 SkAutoTMalloc<SkPoint> pos(len);
147 for (int i = 0; i < SkToInt(len); ++i) {
Florin Malita673e87c2019-07-19 13:59:38 -0400148 pos[i] = SkPoint::Make(SkIntToScalar(txt[i]), 150 - SkIntToScalar(txt[i]));
fmalita7a048692015-02-20 13:54:40 -0800149 }
150
Florin Malita673e87c2019-07-19 13:59:38 -0400151 auto blob = SkTextBlob::MakeFromPosText(txt, len, &pos[0], font);
152 MakeDOMCanvas(&dom)->drawTextBlob(blob, 0, 0, paint);
fmalita7a048692015-02-20 13:54:40 -0800153 }
Florin Malita673e87c2019-07-19 13:59:38 -0400154 check_text_node(reporter, dom, dom.finishParsing(), offset, 2, txt, expected);
fmalita7a048692015-02-20 13:54:40 -0800155}
156
Florin Malita673e87c2019-07-19 13:59:38 -0400157} // namespace
Herb Derby41f4f312018-06-06 17:45:53 +0000158
fmalita7a048692015-02-20 13:54:40 -0800159DEF_TEST(SVGDevice_whitespace_pos, reporter) {
160 static const struct {
161 const char* tst_in;
162 const char* tst_out;
163 } tests[] = {
164 { "abcd" , "abcd" },
165 { "ab cd" , "ab cd" },
166 { "ab \t\t cd", "ab cd" },
167 { " abcd" , "abcd" },
168 { " abcd" , "abcd" },
169 { " \t\t abcd", "abcd" },
170 { "abcd " , "abcd " }, // we allow one trailing whitespace char
171 { "abcd " , "abcd " }, // because it makes no difference and
Florin Malita673e87c2019-07-19 13:59:38 -0400172 { "abcd\t " , "abcd " }, // simplifies the implementation
fmalita7a048692015-02-20 13:54:40 -0800173 { "\t\t \t ab \t\t \t cd \t\t \t ", "ab cd " },
174 };
175
176 for (unsigned i = 0; i < SK_ARRAY_COUNT(tests); ++i) {
177 test_whitespace_pos(reporter, tests[i].tst_in, tests[i].tst_out);
178 }
179}
Alexander Midlash77e3afc2018-03-06 17:21:28 -0800180
Mike Reede25b4472019-04-02 17:49:12 -0400181void SetImageShader(SkPaint* paint, int imageWidth, int imageHeight, SkTileMode xTile,
182 SkTileMode yTile) {
Alexander Midlash77e3afc2018-03-06 17:21:28 -0800183 auto surface = SkSurface::MakeRasterN32Premul(imageWidth, imageHeight);
Mike Reede25b4472019-04-02 17:49:12 -0400184 paint->setShader(surface->makeImageSnapshot()->makeShader(xTile, yTile, nullptr));
Alexander Midlash77e3afc2018-03-06 17:21:28 -0800185}
186
187// Attempt to find the three nodes on which we have expectations:
188// the pattern node, the image within that pattern, and the rect which
189// uses the pattern as a fill.
190// returns false if not all nodes are found.
191bool FindImageShaderNodes(skiatest::Reporter* reporter, const SkDOM* dom, const SkDOM::Node* root,
192 const SkDOM::Node** patternOut, const SkDOM::Node** imageOut,
193 const SkDOM::Node** rectOut) {
194 if (root == nullptr || dom == nullptr) {
195 ERRORF(reporter, "root element not found");
196 return false;
197 }
198
199
200 const SkDOM::Node* rect = dom->getFirstChild(root, "rect");
201 if (rect == nullptr) {
202 ERRORF(reporter, "rect not found");
203 return false;
204 }
205 *rectOut = rect;
206
207 const SkDOM::Node* defs = dom->getFirstChild(root, "defs");
208 if (defs == nullptr) {
209 ERRORF(reporter, "defs not found");
210 return false;
211 }
212
213 const SkDOM::Node* pattern = dom->getFirstChild(defs, "pattern");
214 if (pattern == nullptr) {
215 ERRORF(reporter, "pattern not found");
216 return false;
217 }
218 *patternOut = pattern;
219
220 const SkDOM::Node* image = dom->getFirstChild(pattern, "image");
221 if (image == nullptr) {
222 ERRORF(reporter, "image not found");
223 return false;
224 }
225 *imageOut = image;
226
227 return true;
228}
229
230void ImageShaderTestSetup(SkDOM* dom, SkPaint* paint, int imageWidth, int imageHeight,
Mike Reede25b4472019-04-02 17:49:12 -0400231 int rectWidth, int rectHeight, SkTileMode xTile, SkTileMode yTile) {
Alexander Midlash77e3afc2018-03-06 17:21:28 -0800232 SetImageShader(paint, imageWidth, imageHeight, xTile, yTile);
Florin Malita562017b2019-02-14 13:42:15 -0500233 auto svgCanvas = MakeDOMCanvas(dom);
Alexander Midlash77e3afc2018-03-06 17:21:28 -0800234
235 SkRect bounds{0, 0, SkIntToScalar(rectWidth), SkIntToScalar(rectHeight)};
236 svgCanvas->drawRect(bounds, *paint);
237}
238
239
240DEF_TEST(SVGDevice_image_shader_norepeat, reporter) {
241 SkDOM dom;
242 SkPaint paint;
243 int imageWidth = 3, imageHeight = 3;
244 int rectWidth = 10, rectHeight = 10;
245 ImageShaderTestSetup(&dom, &paint, imageWidth, imageHeight, rectWidth, rectHeight,
Mike Reede25b4472019-04-02 17:49:12 -0400246 SkTileMode::kClamp, SkTileMode::kClamp);
Alexander Midlash77e3afc2018-03-06 17:21:28 -0800247
248 const SkDOM::Node* root = dom.finishParsing();
249
250 const SkDOM::Node *patternNode, *imageNode, *rectNode;
251 bool structureAppropriate =
252 FindImageShaderNodes(reporter, &dom, root, &patternNode, &imageNode, &rectNode);
253 REPORTER_ASSERT(reporter, structureAppropriate);
254
255 // the image should always maintain its size.
256 REPORTER_ASSERT(reporter, atoi(dom.findAttr(imageNode, "width")) == imageWidth);
257 REPORTER_ASSERT(reporter, atoi(dom.findAttr(imageNode, "height")) == imageHeight);
258
259 // making the pattern as large as the container prevents
260 // it from repeating.
261 REPORTER_ASSERT(reporter, strcmp(dom.findAttr(patternNode, "width"), "100%") == 0);
262 REPORTER_ASSERT(reporter, strcmp(dom.findAttr(patternNode, "height"), "100%") == 0);
263}
264
265DEF_TEST(SVGDevice_image_shader_tilex, reporter) {
266 SkDOM dom;
267 SkPaint paint;
268 int imageWidth = 3, imageHeight = 3;
269 int rectWidth = 10, rectHeight = 10;
270 ImageShaderTestSetup(&dom, &paint, imageWidth, imageHeight, rectWidth, rectHeight,
Mike Reede25b4472019-04-02 17:49:12 -0400271 SkTileMode::kRepeat, SkTileMode::kClamp);
Alexander Midlash77e3afc2018-03-06 17:21:28 -0800272
273 const SkDOM::Node* root = dom.finishParsing();
274 const SkDOM::Node* innerSvg = dom.getFirstChild(root, "svg");
275 if (innerSvg == nullptr) {
276 ERRORF(reporter, "inner svg element not found");
277 return;
278 }
279
280 const SkDOM::Node *patternNode, *imageNode, *rectNode;
281 bool structureAppropriate =
282 FindImageShaderNodes(reporter, &dom, innerSvg, &patternNode, &imageNode, &rectNode);
283 REPORTER_ASSERT(reporter, structureAppropriate);
284
285 // the imageNode should always maintain its size.
286 REPORTER_ASSERT(reporter, atoi(dom.findAttr(imageNode, "width")) == imageWidth);
287 REPORTER_ASSERT(reporter, atoi(dom.findAttr(imageNode, "height")) == imageHeight);
288
289 // if the patternNode width matches the imageNode width,
290 // it will repeat in along the x axis.
291 REPORTER_ASSERT(reporter, atoi(dom.findAttr(patternNode, "width")) == imageWidth);
292 REPORTER_ASSERT(reporter, strcmp(dom.findAttr(patternNode, "height"), "100%") == 0);
293}
294
295DEF_TEST(SVGDevice_image_shader_tiley, reporter) {
296 SkDOM dom;
297 SkPaint paint;
298 int imageNodeWidth = 3, imageNodeHeight = 3;
299 int rectNodeWidth = 10, rectNodeHeight = 10;
300 ImageShaderTestSetup(&dom, &paint, imageNodeWidth, imageNodeHeight, rectNodeWidth,
Mike Reede25b4472019-04-02 17:49:12 -0400301 rectNodeHeight, SkTileMode::kClamp, SkTileMode::kRepeat);
Alexander Midlash77e3afc2018-03-06 17:21:28 -0800302
303 const SkDOM::Node* root = dom.finishParsing();
304 const SkDOM::Node* innerSvg = dom.getFirstChild(root, "svg");
305 if (innerSvg == nullptr) {
306 ERRORF(reporter, "inner svg element not found");
307 return;
308 }
309
310 const SkDOM::Node *patternNode, *imageNode, *rectNode;
311 bool structureAppropriate =
312 FindImageShaderNodes(reporter, &dom, innerSvg, &patternNode, &imageNode, &rectNode);
313 REPORTER_ASSERT(reporter, structureAppropriate);
314
315 // the imageNode should always maintain its size.
316 REPORTER_ASSERT(reporter, atoi(dom.findAttr(imageNode, "width")) == imageNodeWidth);
317 REPORTER_ASSERT(reporter, atoi(dom.findAttr(imageNode, "height")) == imageNodeHeight);
318
319 // making the patternNode as large as the container prevents
320 // it from repeating.
321 REPORTER_ASSERT(reporter, strcmp(dom.findAttr(patternNode, "width"), "100%") == 0);
322 REPORTER_ASSERT(reporter, atoi(dom.findAttr(patternNode, "height")) == imageNodeHeight);
323}
324
325DEF_TEST(SVGDevice_image_shader_tileboth, reporter) {
326 SkDOM dom;
327 SkPaint paint;
328 int imageWidth = 3, imageHeight = 3;
329 int rectWidth = 10, rectHeight = 10;
330 ImageShaderTestSetup(&dom, &paint, imageWidth, imageHeight, rectWidth, rectHeight,
Mike Reede25b4472019-04-02 17:49:12 -0400331 SkTileMode::kRepeat, SkTileMode::kRepeat);
Alexander Midlash77e3afc2018-03-06 17:21:28 -0800332
333 const SkDOM::Node* root = dom.finishParsing();
334
335 const SkDOM::Node *patternNode, *imageNode, *rectNode;
336 const SkDOM::Node* innerSvg = dom.getFirstChild(root, "svg");
337 if (innerSvg == nullptr) {
338 ERRORF(reporter, "inner svg element not found");
339 return;
340 }
341 bool structureAppropriate =
342 FindImageShaderNodes(reporter, &dom, innerSvg, &patternNode, &imageNode, &rectNode);
343 REPORTER_ASSERT(reporter, structureAppropriate);
344
345 // the imageNode should always maintain its size.
346 REPORTER_ASSERT(reporter, atoi(dom.findAttr(imageNode, "width")) == imageWidth);
347 REPORTER_ASSERT(reporter, atoi(dom.findAttr(imageNode, "height")) == imageHeight);
348
349 REPORTER_ASSERT(reporter, atoi(dom.findAttr(patternNode, "width")) == imageWidth);
350 REPORTER_ASSERT(reporter, atoi(dom.findAttr(patternNode, "height")) == imageHeight);
351}
352
Anas AlJabri84dd1832018-07-31 15:53:05 -0700353DEF_TEST(SVGDevice_ColorFilters, reporter) {
354 SkDOM dom;
355 SkPaint paint;
Mike Reedb286bc22019-04-08 16:23:20 -0400356 paint.setColorFilter(SkColorFilters::Blend(SK_ColorRED, SkBlendMode::kSrcIn));
Anas AlJabri84dd1832018-07-31 15:53:05 -0700357 {
Florin Malita562017b2019-02-14 13:42:15 -0500358 auto svgCanvas = MakeDOMCanvas(&dom);
Anas AlJabri84dd1832018-07-31 15:53:05 -0700359 SkRect bounds{0, 0, SkIntToScalar(100), SkIntToScalar(100)};
360 svgCanvas->drawRect(bounds, paint);
361 }
362 const SkDOM::Node* rootElement = dom.finishParsing();
363 ABORT_TEST(reporter, !rootElement, "root element not found");
364
365 const SkDOM::Node* filterElement = dom.getFirstChild(rootElement, "filter");
366 ABORT_TEST(reporter, !filterElement, "filter element not found");
367
368 const SkDOM::Node* floodElement = dom.getFirstChild(filterElement, "feFlood");
369 ABORT_TEST(reporter, !floodElement, "feFlood element not found");
370
371 const SkDOM::Node* compositeElement = dom.getFirstChild(filterElement, "feComposite");
372 ABORT_TEST(reporter, !compositeElement, "feComposite element not found");
373
374 REPORTER_ASSERT(reporter, strcmp(dom.findAttr(filterElement, "width"), "100%") == 0);
375 REPORTER_ASSERT(reporter, strcmp(dom.findAttr(filterElement, "height"), "100%") == 0);
376
377 REPORTER_ASSERT(reporter,
Florin Malita3f412f92019-08-22 13:37:32 -0400378 strcmp(dom.findAttr(floodElement, "flood-color"), "red") == 0);
Anas AlJabri84dd1832018-07-31 15:53:05 -0700379 REPORTER_ASSERT(reporter, atoi(dom.findAttr(floodElement, "flood-opacity")) == 1);
380
381 REPORTER_ASSERT(reporter, strcmp(dom.findAttr(compositeElement, "in"), "flood") == 0);
382 REPORTER_ASSERT(reporter, strcmp(dom.findAttr(compositeElement, "operator"), "in") == 0);
383}
384
Florin Malitaabc96532019-07-19 09:11:29 -0400385DEF_TEST(SVGDevice_textpath, reporter) {
386 SkDOM dom;
387 SkFont font(ToolUtils::create_portable_typeface());
388 SkPaint paint;
389
390 // By default, we emit <text> nodes.
391 {
392 auto svgCanvas = MakeDOMCanvas(&dom);
393 svgCanvas->drawString("foo", 100, 100, font, paint);
394 }
395 const auto* rootElement = dom.finishParsing();
396 REPORTER_ASSERT(reporter, rootElement, "root element not found");
397 const auto* textElement = dom.getFirstChild(rootElement, "text");
398 REPORTER_ASSERT(reporter, textElement, "text element not found");
399 const auto* pathElement = dom.getFirstChild(rootElement, "path");
400 REPORTER_ASSERT(reporter, !pathElement, "path element found");
401
402 // With kConvertTextToPaths_Flag, we emit <path> nodes.
403 {
404 auto svgCanvas = MakeDOMCanvas(&dom, SkSVGCanvas::kConvertTextToPaths_Flag);
405 svgCanvas->drawString("foo", 100, 100, font, paint);
406 }
407 rootElement = dom.finishParsing();
408 REPORTER_ASSERT(reporter, rootElement, "root element not found");
409 textElement = dom.getFirstChild(rootElement, "text");
410 REPORTER_ASSERT(reporter, !textElement, "text element found");
411 pathElement = dom.getFirstChild(rootElement, "path");
412 REPORTER_ASSERT(reporter, pathElement, "path element not found");
413}
414
Florin Malita05bab9a2019-08-21 12:13:21 -0400415DEF_TEST(SVGDevice_fill_stroke, reporter) {
416 struct {
417 SkColor color;
418 SkPaint::Style style;
419 const char* expected_fill;
420 const char* expected_stroke;
421 } gTests[] = {
Florin Malita3f412f92019-08-22 13:37:32 -0400422 { SK_ColorBLACK, SkPaint::kFill_Style , nullptr, nullptr },
423 { SK_ColorBLACK, SkPaint::kStroke_Style, "none" , "black" },
424 { SK_ColorRED , SkPaint::kFill_Style , "red" , nullptr },
425 { SK_ColorRED , SkPaint::kStroke_Style, "none" , "red" },
Florin Malita05bab9a2019-08-21 12:13:21 -0400426 };
427
428 for (const auto& tst : gTests) {
429 SkPaint p;
430 p.setColor(tst.color);
431 p.setStyle(tst.style);
432
433 SkDOM dom;
434 {
435 MakeDOMCanvas(&dom)->drawRect(SkRect::MakeWH(100, 100), p);
436 }
437
438 const auto* root = dom.finishParsing();
439 REPORTER_ASSERT(reporter, root, "root element not found");
440 const auto* rect = dom.getFirstChild(root, "rect");
441 REPORTER_ASSERT(reporter, rect, "rect element not found");
442 const auto* fill = dom.findAttr(rect, "fill");
443 REPORTER_ASSERT(reporter, !!fill == !!tst.expected_fill);
444 if (fill) {
445 REPORTER_ASSERT(reporter, strcmp(fill, tst.expected_fill) == 0);
446 }
447 const auto* stroke = dom.findAttr(rect, "stroke");
448 REPORTER_ASSERT(reporter, !!stroke == !!tst.expected_stroke);
449 if (stroke) {
450 REPORTER_ASSERT(reporter, strcmp(stroke, tst.expected_stroke) == 0);
451 }
452 }
453}
454
Hal Canaryff2742e2018-01-30 11:35:47 -0500455#endif