blob: 2c1fdc76e9ad724a2f1747b5680ca50ebf17d5a6 [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 Lesinskid0f116b2016-07-08 15:00:32 -070017#include "test/Test.h"
Adam Lesinski1ab598f2015-08-14 14:26:04 -070018#include "util/StringPiece.h"
Adam Lesinski467f1712015-11-16 17:35:44 -080019#include "xml/XmlPullParser.h"
Adam Lesinski1ab598f2015-08-14 14:26:04 -070020
Adam Lesinski1ab598f2015-08-14 14:26:04 -070021#include <sstream>
22
23namespace aapt {
24
25TEST(XmlPullParserTest, NextChildNodeTraversesCorrectly) {
26 std::stringstream str;
27 str << "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
28 "<a><b><c xmlns:a=\"http://schema.org\"><d/></c><e/></b></a>";
Adam Lesinski467f1712015-11-16 17:35:44 -080029 xml::XmlPullParser parser(str);
Adam Lesinski1ab598f2015-08-14 14:26:04 -070030
31 const size_t depthOuter = parser.getDepth();
Adam Lesinski467f1712015-11-16 17:35:44 -080032 ASSERT_TRUE(xml::XmlPullParser::nextChildNode(&parser, depthOuter));
Adam Lesinski1ab598f2015-08-14 14:26:04 -070033
Adam Lesinski467f1712015-11-16 17:35:44 -080034 EXPECT_EQ(xml::XmlPullParser::Event::kStartElement, parser.getEvent());
Adam Lesinskid0f116b2016-07-08 15:00:32 -070035 EXPECT_EQ(StringPiece("a"), StringPiece(parser.getElementName()));
Adam Lesinski1ab598f2015-08-14 14:26:04 -070036
37 const size_t depthA = parser.getDepth();
Adam Lesinski467f1712015-11-16 17:35:44 -080038 ASSERT_TRUE(xml::XmlPullParser::nextChildNode(&parser, depthA));
39 EXPECT_EQ(xml::XmlPullParser::Event::kStartElement, parser.getEvent());
Adam Lesinskid0f116b2016-07-08 15:00:32 -070040 EXPECT_EQ(StringPiece("b"), StringPiece(parser.getElementName()));
Adam Lesinski1ab598f2015-08-14 14:26:04 -070041
42 const size_t depthB = parser.getDepth();
Adam Lesinski467f1712015-11-16 17:35:44 -080043 ASSERT_TRUE(xml::XmlPullParser::nextChildNode(&parser, depthB));
44 EXPECT_EQ(xml::XmlPullParser::Event::kStartElement, parser.getEvent());
Adam Lesinskid0f116b2016-07-08 15:00:32 -070045 EXPECT_EQ(StringPiece("c"), StringPiece(parser.getElementName()));
Adam Lesinski1ab598f2015-08-14 14:26:04 -070046
Adam Lesinski467f1712015-11-16 17:35:44 -080047 ASSERT_TRUE(xml::XmlPullParser::nextChildNode(&parser, depthB));
48 EXPECT_EQ(xml::XmlPullParser::Event::kStartElement, parser.getEvent());
Adam Lesinskid0f116b2016-07-08 15:00:32 -070049 EXPECT_EQ(StringPiece("e"), StringPiece(parser.getElementName()));
Adam Lesinski1ab598f2015-08-14 14:26:04 -070050
Adam Lesinski467f1712015-11-16 17:35:44 -080051 ASSERT_FALSE(xml::XmlPullParser::nextChildNode(&parser, depthOuter));
52 EXPECT_EQ(xml::XmlPullParser::Event::kEndDocument, parser.getEvent());
Adam Lesinski1ab598f2015-08-14 14:26:04 -070053}
54
55} // namespace aapt