1 /* 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 17 #include "util/StringPiece.h" 18 #include "xml/XmlPullParser.h" 19 20 #include <gtest/gtest.h> 21 #include <sstream> 22 23 namespace aapt { 24 25 TEST(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>"; 29 xml::XmlPullParser parser(str); 30 31 const size_t depthOuter = parser.getDepth(); 32 ASSERT_TRUE(xml::XmlPullParser::nextChildNode(&parser, depthOuter)); 33 34 EXPECT_EQ(xml::XmlPullParser::Event::kStartElement, parser.getEvent()); 35 EXPECT_EQ(StringPiece16(u"a"), StringPiece16(parser.getElementName())); 36 37 const size_t depthA = parser.getDepth(); 38 ASSERT_TRUE(xml::XmlPullParser::nextChildNode(&parser, depthA)); 39 EXPECT_EQ(xml::XmlPullParser::Event::kStartElement, parser.getEvent()); 40 EXPECT_EQ(StringPiece16(u"b"), StringPiece16(parser.getElementName())); 41 42 const size_t depthB = parser.getDepth(); 43 ASSERT_TRUE(xml::XmlPullParser::nextChildNode(&parser, depthB)); 44 EXPECT_EQ(xml::XmlPullParser::Event::kStartElement, parser.getEvent()); 45 EXPECT_EQ(StringPiece16(u"c"), StringPiece16(parser.getElementName())); 46 47 ASSERT_TRUE(xml::XmlPullParser::nextChildNode(&parser, depthB)); 48 EXPECT_EQ(xml::XmlPullParser::Event::kStartElement, parser.getEvent()); 49 EXPECT_EQ(StringPiece16(u"e"), StringPiece16(parser.getElementName())); 50 51 ASSERT_FALSE(xml::XmlPullParser::nextChildNode(&parser, depthOuter)); 52 EXPECT_EQ(xml::XmlPullParser::Event::kEndDocument, parser.getEvent()); 53 } 54 55 } // namespace aapt 56