XmlPullParser_test.cpp revision d5083f6f6b9bc76bbe64052bcec639eee752a321
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
17467f171315f9c2037fcd3eb5edcfabc40671bf7bAdam Lesinski#include "xml/XmlPullParser.h"
181ab598f46c3ff520a67f9d80194847741f3467abAdam Lesinski
191ab598f46c3ff520a67f9d80194847741f3467abAdam Lesinski#include <sstream>
201ab598f46c3ff520a67f9d80194847741f3467abAdam Lesinski
21d5083f6f6b9bc76bbe64052bcec639eee752a321Adam Lesinski#include "androidfw/StringPiece.h"
22d5083f6f6b9bc76bbe64052bcec639eee752a321Adam Lesinski
23ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski#include "test/Test.h"
24d5083f6f6b9bc76bbe64052bcec639eee752a321Adam Lesinski
25d5083f6f6b9bc76bbe64052bcec639eee752a321Adam Lesinskiusing android::StringPiece;
26ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski
271ab598f46c3ff520a67f9d80194847741f3467abAdam Lesinskinamespace aapt {
281ab598f46c3ff520a67f9d80194847741f3467abAdam Lesinski
291ab598f46c3ff520a67f9d80194847741f3467abAdam LesinskiTEST(XmlPullParserTest, NextChildNodeTraversesCorrectly) {
30ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski  std::stringstream str;
31ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski  str << "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
32ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski         "<a><b><c xmlns:a=\"http://schema.org\"><d/></c><e/></b></a>";
33ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski  xml::XmlPullParser parser(str);
341ab598f46c3ff520a67f9d80194847741f3467abAdam Lesinski
35ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski  const size_t depth_outer = parser.depth();
36ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski  ASSERT_TRUE(xml::XmlPullParser::NextChildNode(&parser, depth_outer));
371ab598f46c3ff520a67f9d80194847741f3467abAdam Lesinski
38ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski  EXPECT_EQ(xml::XmlPullParser::Event::kStartElement, parser.event());
39ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski  EXPECT_EQ(StringPiece("a"), StringPiece(parser.element_name()));
401ab598f46c3ff520a67f9d80194847741f3467abAdam Lesinski
41ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski  const size_t depth_a = parser.depth();
42ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski  ASSERT_TRUE(xml::XmlPullParser::NextChildNode(&parser, depth_a));
43ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski  EXPECT_EQ(xml::XmlPullParser::Event::kStartElement, parser.event());
44ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski  EXPECT_EQ(StringPiece("b"), StringPiece(parser.element_name()));
451ab598f46c3ff520a67f9d80194847741f3467abAdam Lesinski
46ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski  const size_t depth_b = parser.depth();
47ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski  ASSERT_TRUE(xml::XmlPullParser::NextChildNode(&parser, depth_b));
48ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski  EXPECT_EQ(xml::XmlPullParser::Event::kStartElement, parser.event());
49ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski  EXPECT_EQ(StringPiece("c"), StringPiece(parser.element_name()));
501ab598f46c3ff520a67f9d80194847741f3467abAdam Lesinski
51ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski  ASSERT_TRUE(xml::XmlPullParser::NextChildNode(&parser, depth_b));
52ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski  EXPECT_EQ(xml::XmlPullParser::Event::kStartElement, parser.event());
53ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski  EXPECT_EQ(StringPiece("e"), StringPiece(parser.element_name()));
541ab598f46c3ff520a67f9d80194847741f3467abAdam Lesinski
55ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski  ASSERT_FALSE(xml::XmlPullParser::NextChildNode(&parser, depth_outer));
56ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski  EXPECT_EQ(xml::XmlPullParser::Event::kEndDocument, parser.event());
571ab598f46c3ff520a67f9d80194847741f3467abAdam Lesinski}
581ab598f46c3ff520a67f9d80194847741f3467abAdam Lesinski
59ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski}  // namespace aapt
60