OLD | NEW |
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 "Test.h" | 9 #include "Test.h" |
9 | 10 |
10 #if defined(SK_XML) | 11 #if defined(SK_XML) |
11 | 12 |
12 #include "SkDOM.h" | 13 #include "SkDOM.h" |
13 | 14 |
14 DEF_TEST(SkDOM_test, r) { | 15 DEF_TEST(SkDOM_test, r) { |
15 static const char gDoc[] = | 16 static const char gDoc[] = |
16 "<root a='1' b='2'>" | 17 "<root a='1' b='2'>" |
17 "<elem1 c='3' />" | 18 "<elem1 c='3' />" |
18 "<elem2 d='4' />" | 19 "<elem2 d='4' />" |
19 "<elem3 e='5'>" | 20 "<elem3 e='5'>" |
20 "<subelem1/>" | 21 "<subelem1/>" |
21 "<subelem2 f='6' g='7'/>" | 22 "<subelem2 f='6' g='7'/>" |
22 "</elem3>" | 23 "</elem3>" |
23 "<elem4 h='8'/>" | 24 "<elem4 h='8'/>" |
24 "</root>" | 25 "</root>" |
25 ; | 26 ; |
26 | 27 |
| 28 SkMemoryStream docStream(gDoc, sizeof(gDoc) - 1); |
| 29 |
27 SkDOM dom; | 30 SkDOM dom; |
28 REPORTER_ASSERT(r, !dom.getRootNode()); | 31 REPORTER_ASSERT(r, !dom.getRootNode()); |
29 | 32 |
30 const SkDOM::Node* root = dom.build(gDoc, sizeof(gDoc) - 1); | 33 const SkDOM::Node* root = dom.build(docStream); |
31 REPORTER_ASSERT(r, root && dom.getRootNode() == root); | 34 REPORTER_ASSERT(r, root && dom.getRootNode() == root); |
32 | 35 |
33 const char* v = dom.findAttr(root, "a"); | 36 const char* v = dom.findAttr(root, "a"); |
34 REPORTER_ASSERT(r, v && !strcmp(v, "1")); | 37 REPORTER_ASSERT(r, v && !strcmp(v, "1")); |
35 v = dom.findAttr(root, "b"); | 38 v = dom.findAttr(root, "b"); |
36 REPORTER_ASSERT(r, v && !strcmp(v, "2")); | 39 REPORTER_ASSERT(r, v && !strcmp(v, "2")); |
37 v = dom.findAttr(root, "c"); | 40 v = dom.findAttr(root, "c"); |
38 REPORTER_ASSERT(r, v == nullptr); | 41 REPORTER_ASSERT(r, v == nullptr); |
39 | 42 |
40 REPORTER_ASSERT(r, dom.getFirstChild(root, "elem1")); | 43 REPORTER_ASSERT(r, dom.getFirstChild(root, "elem1")); |
41 REPORTER_ASSERT(r, !dom.getFirstChild(root, "subelem1")); | 44 REPORTER_ASSERT(r, !dom.getFirstChild(root, "subelem1")); |
42 } | 45 } |
43 | 46 |
44 #endif // SK_XML | 47 #endif // SK_XML |
OLD | NEW |