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

Side by Side Diff: tests/SkDOMTest.cpp

Issue 2154853002: [SkXMLParser] Initial text node support (Closed) Base URL: https://chromium.googlesource.com/skia.git@master
Patch Set: rebase Created 4 years, 5 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
« no previous file with comments | « src/xml/SkXMLParser.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2016 Google Inc. 2 * Copyright 2016 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SkStream.h" 8 #include "SkStream.h"
9 #include "Test.h" 9 #include "Test.h"
10 10
11 #if defined(SK_XML) 11 #if defined(SK_XML)
12 12
13 #include "SkDOM.h" 13 #include "SkDOM.h"
14 14
15 static const SkDOM::Node* check_node(skiatest::Reporter* r, const SkDOM& dom,
16 const SkDOM::Node* node, const char* expect edName,
17 SkDOM::Type expectedType) {
18 REPORTER_ASSERT(r, node);
19 if (node) {
20 REPORTER_ASSERT(r, !strcmp(dom.getName(node), expectedName));
21 REPORTER_ASSERT(r, dom.getType(node) == expectedType);
22 }
23 return node;
24 }
25
15 DEF_TEST(SkDOM_test, r) { 26 DEF_TEST(SkDOM_test, r) {
16 static const char gDoc[] = 27 static const char gDoc[] =
17 "<root a='1' b='2'>" 28 "<root a='1' b='2'>"
18 "<elem1 c='3' />" 29 "<elem1 c='3' />"
19 "<elem2 d='4' />" 30 "<elem2 d='4' />"
20 "<elem3 e='5'>" 31 "<elem3 e='5'>"
21 "<subelem1/>" 32 "<subelem1>Some text.</subelem1>"
22 "<subelem2 f='6' g='7'/>" 33 "<subelem2 f='6' g='7'/>"
34 "<subelem3>Some more text.</subelem3>"
23 "</elem3>" 35 "</elem3>"
24 "<elem4 h='8'/>" 36 "<elem4 h='8'/>"
25 "</root>" 37 "</root>"
26 ; 38 ;
27 39
28 SkMemoryStream docStream(gDoc, sizeof(gDoc) - 1); 40 SkMemoryStream docStream(gDoc, sizeof(gDoc) - 1);
29 41
30 SkDOM dom; 42 SkDOM dom;
31 REPORTER_ASSERT(r, !dom.getRootNode()); 43 REPORTER_ASSERT(r, !dom.getRootNode());
32 44
33 const SkDOM::Node* root = dom.build(docStream); 45 const SkDOM::Node* root = dom.build(docStream);
34 REPORTER_ASSERT(r, root && dom.getRootNode() == root); 46 REPORTER_ASSERT(r, root && dom.getRootNode() == root);
35 47
36 const char* v = dom.findAttr(root, "a"); 48 const char* v = dom.findAttr(root, "a");
37 REPORTER_ASSERT(r, v && !strcmp(v, "1")); 49 REPORTER_ASSERT(r, v && !strcmp(v, "1"));
38 v = dom.findAttr(root, "b"); 50 v = dom.findAttr(root, "b");
39 REPORTER_ASSERT(r, v && !strcmp(v, "2")); 51 REPORTER_ASSERT(r, v && !strcmp(v, "2"));
40 v = dom.findAttr(root, "c"); 52 v = dom.findAttr(root, "c");
41 REPORTER_ASSERT(r, v == nullptr); 53 REPORTER_ASSERT(r, v == nullptr);
42 54
43 REPORTER_ASSERT(r, dom.getFirstChild(root, "elem1")); 55 REPORTER_ASSERT(r, dom.getFirstChild(root, "elem1"));
44 REPORTER_ASSERT(r, !dom.getFirstChild(root, "subelem1")); 56 REPORTER_ASSERT(r, !dom.getFirstChild(root, "subelem1"));
57
58 {
59 const auto* elem1 = check_node(r, dom, dom.getFirstChild(root),
60 "elem1", SkDOM::kElement_Type);
61 const auto* elem2 = check_node(r, dom, dom.getNextSibling(elem1),
62 "elem2", SkDOM::kElement_Type);
63 const auto* elem3 = check_node(r, dom, dom.getNextSibling(elem2),
64 "elem3", SkDOM::kElement_Type);
65 {
66 const auto* subelem1 = check_node(r, dom, dom.getFirstChild(elem3),
67 "subelem1", SkDOM::kElement_Type);
68 {
69 check_node(r, dom, dom.getFirstChild(subelem1),
70 "Some text.", SkDOM::kText_Type);
71 }
72 const auto* subelem2 = check_node(r, dom, dom.getNextSibling(subelem 1),
73 "subelem2", SkDOM::kElement_Type);
74 const auto* subelem3 = check_node(r, dom, dom.getNextSibling(subelem 2),
75 "subelem3", SkDOM::kElement_Type);
76 {
77 check_node(r, dom, dom.getFirstChild(subelem3),
78 "Some more text.", SkDOM::kText_Type);
79 }
80 }
81 check_node(r, dom, dom.getNextSibling(elem3),
82 "elem4", SkDOM::kElement_Type);
83 }
45 } 84 }
46 85
47 #endif // SK_XML 86 #endif // SK_XML
OLDNEW
« no previous file with comments | « src/xml/SkXMLParser.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698