XmlDom_test.cpp revision ce5e56e243d262a9b65459c3bd0bb9eaadd40628
175f3a55cc569a9b61f540a85d9828e91bdca5047Adam Lesinski/*
275f3a55cc569a9b61f540a85d9828e91bdca5047Adam Lesinski * Copyright (C) 2015 The Android Open Source Project
375f3a55cc569a9b61f540a85d9828e91bdca5047Adam Lesinski *
475f3a55cc569a9b61f540a85d9828e91bdca5047Adam Lesinski * Licensed under the Apache License, Version 2.0 (the "License");
575f3a55cc569a9b61f540a85d9828e91bdca5047Adam Lesinski * you may not use this file except in compliance with the License.
675f3a55cc569a9b61f540a85d9828e91bdca5047Adam Lesinski * You may obtain a copy of the License at
775f3a55cc569a9b61f540a85d9828e91bdca5047Adam Lesinski *
875f3a55cc569a9b61f540a85d9828e91bdca5047Adam Lesinski *      http://www.apache.org/licenses/LICENSE-2.0
975f3a55cc569a9b61f540a85d9828e91bdca5047Adam Lesinski *
1075f3a55cc569a9b61f540a85d9828e91bdca5047Adam Lesinski * Unless required by applicable law or agreed to in writing, software
1175f3a55cc569a9b61f540a85d9828e91bdca5047Adam Lesinski * distributed under the License is distributed on an "AS IS" BASIS,
1275f3a55cc569a9b61f540a85d9828e91bdca5047Adam Lesinski * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1375f3a55cc569a9b61f540a85d9828e91bdca5047Adam Lesinski * See the License for the specific language governing permissions and
1475f3a55cc569a9b61f540a85d9828e91bdca5047Adam Lesinski * limitations under the License.
1575f3a55cc569a9b61f540a85d9828e91bdca5047Adam Lesinski */
1675f3a55cc569a9b61f540a85d9828e91bdca5047Adam Lesinski
17467f171315f9c2037fcd3eb5edcfabc40671bf7bAdam Lesinski#include "xml/XmlDom.h"
1875f3a55cc569a9b61f540a85d9828e91bdca5047Adam Lesinski
1975f3a55cc569a9b61f540a85d9828e91bdca5047Adam Lesinski#include <sstream>
2075f3a55cc569a9b61f540a85d9828e91bdca5047Adam Lesinski#include <string>
2175f3a55cc569a9b61f540a85d9828e91bdca5047Adam Lesinski
22ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski#include "test/Test.h"
23ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski
2475f3a55cc569a9b61f540a85d9828e91bdca5047Adam Lesinskinamespace aapt {
2575f3a55cc569a9b61f540a85d9828e91bdca5047Adam Lesinski
26ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinskiconstexpr const char* kXmlPreamble =
27ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski    "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
2875f3a55cc569a9b61f540a85d9828e91bdca5047Adam Lesinski
2975f3a55cc569a9b61f540a85d9828e91bdca5047Adam LesinskiTEST(XmlDomTest, Inflate) {
30ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski  std::stringstream in(kXmlPreamble);
31ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski  in << R"EOF(
3275f3a55cc569a9b61f540a85d9828e91bdca5047Adam Lesinski        <Layout xmlns:android="http://schemas.android.com/apk/res/android"
3375f3a55cc569a9b61f540a85d9828e91bdca5047Adam Lesinski                android:layout_width="match_parent"
3475f3a55cc569a9b61f540a85d9828e91bdca5047Adam Lesinski                android:layout_height="wrap_content">
3575f3a55cc569a9b61f540a85d9828e91bdca5047Adam Lesinski            <TextView android:id="@+id/id"
3675f3a55cc569a9b61f540a85d9828e91bdca5047Adam Lesinski                      android:layout_width="wrap_content"
3775f3a55cc569a9b61f540a85d9828e91bdca5047Adam Lesinski                      android:layout_height="wrap_content" />
3875f3a55cc569a9b61f540a85d9828e91bdca5047Adam Lesinski        </Layout>
3975f3a55cc569a9b61f540a85d9828e91bdca5047Adam Lesinski    )EOF";
4075f3a55cc569a9b61f540a85d9828e91bdca5047Adam Lesinski
41ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski  const Source source = {"test.xml"};
42ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski  StdErrDiagnostics diag;
43ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski  std::unique_ptr<xml::XmlResource> doc = xml::Inflate(&in, &diag, source);
44ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski  ASSERT_NE(doc, nullptr);
4575f3a55cc569a9b61f540a85d9828e91bdca5047Adam Lesinski
46ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski  xml::Namespace* ns = xml::NodeCast<xml::Namespace>(doc->root.get());
47ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski  ASSERT_NE(ns, nullptr);
48ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski  EXPECT_EQ(ns->namespace_uri, xml::kSchemaAndroid);
49ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski  EXPECT_EQ(ns->namespace_prefix, "android");
5075f3a55cc569a9b61f540a85d9828e91bdca5047Adam Lesinski}
5175f3a55cc569a9b61f540a85d9828e91bdca5047Adam Lesinski
52ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski}  // namespace aapt
53