11ab598f46c3ff520a67f9d80194847741f3467abAdam Lesinski/*
21ab598f46c3ff520a67f9d80194847741f3467abAdam Lesinski * Copyright (C) 2015 The Android Open Source Project
31ab598f46c3ff520a67f9d80194847741f3467abAdam Lesinski *
41ab598f46c3ff520a67f9d80194847741f3467abAdam Lesinski * Licensed under the Apache License, Version 2.0 (the "License");
51ab598f46c3ff520a67f9d80194847741f3467abAdam Lesinski * you may not use this file except in compliance with the License.
61ab598f46c3ff520a67f9d80194847741f3467abAdam Lesinski * You may obtain a copy of the License at
71ab598f46c3ff520a67f9d80194847741f3467abAdam Lesinski *
81ab598f46c3ff520a67f9d80194847741f3467abAdam Lesinski *      http://www.apache.org/licenses/LICENSE-2.0
91ab598f46c3ff520a67f9d80194847741f3467abAdam Lesinski *
101ab598f46c3ff520a67f9d80194847741f3467abAdam Lesinski * Unless required by applicable law or agreed to in writing, software
111ab598f46c3ff520a67f9d80194847741f3467abAdam Lesinski * distributed under the License is distributed on an "AS IS" BASIS,
121ab598f46c3ff520a67f9d80194847741f3467abAdam Lesinski * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
131ab598f46c3ff520a67f9d80194847741f3467abAdam Lesinski * See the License for the specific language governing permissions and
141ab598f46c3ff520a67f9d80194847741f3467abAdam Lesinski * limitations under the License.
151ab598f46c3ff520a67f9d80194847741f3467abAdam Lesinski */
161ab598f46c3ff520a67f9d80194847741f3467abAdam Lesinski
171ab598f46c3ff520a67f9d80194847741f3467abAdam Lesinski#include "util/StringPiece.h"
18467f171315f9c2037fcd3eb5edcfabc40671bf7bAdam Lesinski#include "xml/XmlPullParser.h"
191ab598f46c3ff520a67f9d80194847741f3467abAdam Lesinski
201ab598f46c3ff520a67f9d80194847741f3467abAdam Lesinski#include <gtest/gtest.h>
211ab598f46c3ff520a67f9d80194847741f3467abAdam Lesinski#include <sstream>
221ab598f46c3ff520a67f9d80194847741f3467abAdam Lesinski
231ab598f46c3ff520a67f9d80194847741f3467abAdam Lesinskinamespace aapt {
241ab598f46c3ff520a67f9d80194847741f3467abAdam Lesinski
251ab598f46c3ff520a67f9d80194847741f3467abAdam LesinskiTEST(XmlPullParserTest, NextChildNodeTraversesCorrectly) {
261ab598f46c3ff520a67f9d80194847741f3467abAdam Lesinski    std::stringstream str;
271ab598f46c3ff520a67f9d80194847741f3467abAdam Lesinski    str << "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
281ab598f46c3ff520a67f9d80194847741f3467abAdam Lesinski            "<a><b><c xmlns:a=\"http://schema.org\"><d/></c><e/></b></a>";
29467f171315f9c2037fcd3eb5edcfabc40671bf7bAdam Lesinski    xml::XmlPullParser parser(str);
301ab598f46c3ff520a67f9d80194847741f3467abAdam Lesinski
311ab598f46c3ff520a67f9d80194847741f3467abAdam Lesinski    const size_t depthOuter = parser.getDepth();
32467f171315f9c2037fcd3eb5edcfabc40671bf7bAdam Lesinski    ASSERT_TRUE(xml::XmlPullParser::nextChildNode(&parser, depthOuter));
331ab598f46c3ff520a67f9d80194847741f3467abAdam Lesinski
34467f171315f9c2037fcd3eb5edcfabc40671bf7bAdam Lesinski    EXPECT_EQ(xml::XmlPullParser::Event::kStartElement, parser.getEvent());
351ab598f46c3ff520a67f9d80194847741f3467abAdam Lesinski    EXPECT_EQ(StringPiece16(u"a"), StringPiece16(parser.getElementName()));
361ab598f46c3ff520a67f9d80194847741f3467abAdam Lesinski
371ab598f46c3ff520a67f9d80194847741f3467abAdam Lesinski    const size_t depthA = parser.getDepth();
38467f171315f9c2037fcd3eb5edcfabc40671bf7bAdam Lesinski    ASSERT_TRUE(xml::XmlPullParser::nextChildNode(&parser, depthA));
39467f171315f9c2037fcd3eb5edcfabc40671bf7bAdam Lesinski    EXPECT_EQ(xml::XmlPullParser::Event::kStartElement, parser.getEvent());
401ab598f46c3ff520a67f9d80194847741f3467abAdam Lesinski    EXPECT_EQ(StringPiece16(u"b"), StringPiece16(parser.getElementName()));
411ab598f46c3ff520a67f9d80194847741f3467abAdam Lesinski
421ab598f46c3ff520a67f9d80194847741f3467abAdam Lesinski    const size_t depthB = parser.getDepth();
43467f171315f9c2037fcd3eb5edcfabc40671bf7bAdam Lesinski    ASSERT_TRUE(xml::XmlPullParser::nextChildNode(&parser, depthB));
44467f171315f9c2037fcd3eb5edcfabc40671bf7bAdam Lesinski    EXPECT_EQ(xml::XmlPullParser::Event::kStartElement, parser.getEvent());
451ab598f46c3ff520a67f9d80194847741f3467abAdam Lesinski    EXPECT_EQ(StringPiece16(u"c"), StringPiece16(parser.getElementName()));
461ab598f46c3ff520a67f9d80194847741f3467abAdam Lesinski
47467f171315f9c2037fcd3eb5edcfabc40671bf7bAdam Lesinski    ASSERT_TRUE(xml::XmlPullParser::nextChildNode(&parser, depthB));
48467f171315f9c2037fcd3eb5edcfabc40671bf7bAdam Lesinski    EXPECT_EQ(xml::XmlPullParser::Event::kStartElement, parser.getEvent());
491ab598f46c3ff520a67f9d80194847741f3467abAdam Lesinski    EXPECT_EQ(StringPiece16(u"e"), StringPiece16(parser.getElementName()));
501ab598f46c3ff520a67f9d80194847741f3467abAdam Lesinski
51467f171315f9c2037fcd3eb5edcfabc40671bf7bAdam Lesinski    ASSERT_FALSE(xml::XmlPullParser::nextChildNode(&parser, depthOuter));
52467f171315f9c2037fcd3eb5edcfabc40671bf7bAdam Lesinski    EXPECT_EQ(xml::XmlPullParser::Event::kEndDocument, parser.getEvent());
531ab598f46c3ff520a67f9d80194847741f3467abAdam Lesinski}
541ab598f46c3ff520a67f9d80194847741f3467abAdam Lesinski
551ab598f46c3ff520a67f9d80194847741f3467abAdam Lesinski} // namespace aapt
56