blob: 1cce4850cac567e0fabdb5212b671b5c8f4d3793 [file] [log] [blame]
Adam Lesinski1ab598f2015-08-14 14:26:04 -07001/*
2 * Copyright (C) 2015 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Adam Lesinski467f1712015-11-16 17:35:44 -080017#include "xml/XmlPullParser.h"
Adam Lesinski1ab598f2015-08-14 14:26:04 -070018
Adam Lesinski1ab598f2015-08-14 14:26:04 -070019#include <sstream>
20
Adam Lesinskid5083f62017-01-16 15:07:21 -080021#include "androidfw/StringPiece.h"
22
Adam Lesinskice5e56e2016-10-21 17:56:45 -070023#include "test/Test.h"
Adam Lesinskid5083f62017-01-16 15:07:21 -080024
25using android::StringPiece;
Adam Lesinskice5e56e2016-10-21 17:56:45 -070026
Adam Lesinski1ab598f2015-08-14 14:26:04 -070027namespace aapt {
28
29TEST(XmlPullParserTest, NextChildNodeTraversesCorrectly) {
Adam Lesinskice5e56e2016-10-21 17:56:45 -070030 std::stringstream str;
31 str << "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
32 "<a><b><c xmlns:a=\"http://schema.org\"><d/></c><e/></b></a>";
33 xml::XmlPullParser parser(str);
Adam Lesinski1ab598f2015-08-14 14:26:04 -070034
Adam Lesinskice5e56e2016-10-21 17:56:45 -070035 const size_t depth_outer = parser.depth();
36 ASSERT_TRUE(xml::XmlPullParser::NextChildNode(&parser, depth_outer));
Adam Lesinski1ab598f2015-08-14 14:26:04 -070037
Adam Lesinskice5e56e2016-10-21 17:56:45 -070038 EXPECT_EQ(xml::XmlPullParser::Event::kStartElement, parser.event());
39 EXPECT_EQ(StringPiece("a"), StringPiece(parser.element_name()));
Adam Lesinski1ab598f2015-08-14 14:26:04 -070040
Adam Lesinskice5e56e2016-10-21 17:56:45 -070041 const size_t depth_a = parser.depth();
42 ASSERT_TRUE(xml::XmlPullParser::NextChildNode(&parser, depth_a));
43 EXPECT_EQ(xml::XmlPullParser::Event::kStartElement, parser.event());
44 EXPECT_EQ(StringPiece("b"), StringPiece(parser.element_name()));
Adam Lesinski1ab598f2015-08-14 14:26:04 -070045
Adam Lesinskice5e56e2016-10-21 17:56:45 -070046 const size_t depth_b = parser.depth();
47 ASSERT_TRUE(xml::XmlPullParser::NextChildNode(&parser, depth_b));
48 EXPECT_EQ(xml::XmlPullParser::Event::kStartElement, parser.event());
49 EXPECT_EQ(StringPiece("c"), StringPiece(parser.element_name()));
Adam Lesinski1ab598f2015-08-14 14:26:04 -070050
Adam Lesinskice5e56e2016-10-21 17:56:45 -070051 ASSERT_TRUE(xml::XmlPullParser::NextChildNode(&parser, depth_b));
52 EXPECT_EQ(xml::XmlPullParser::Event::kStartElement, parser.event());
53 EXPECT_EQ(StringPiece("e"), StringPiece(parser.element_name()));
Adam Lesinski1ab598f2015-08-14 14:26:04 -070054
Adam Lesinskice5e56e2016-10-21 17:56:45 -070055 ASSERT_FALSE(xml::XmlPullParser::NextChildNode(&parser, depth_outer));
56 EXPECT_EQ(xml::XmlPullParser::Event::kEndDocument, parser.event());
Adam Lesinski1ab598f2015-08-14 14:26:04 -070057}
58
Adam Lesinskice5e56e2016-10-21 17:56:45 -070059} // namespace aapt