XmlDom_test.cpp revision 467f171315f9c2037fcd3eb5edcfabc40671bf7b
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 <gtest/gtest.h> 2075f3a55cc569a9b61f540a85d9828e91bdca5047Adam Lesinski#include <sstream> 2175f3a55cc569a9b61f540a85d9828e91bdca5047Adam Lesinski#include <string> 2275f3a55cc569a9b61f540a85d9828e91bdca5047Adam Lesinski 2375f3a55cc569a9b61f540a85d9828e91bdca5047Adam Lesinskinamespace aapt { 2475f3a55cc569a9b61f540a85d9828e91bdca5047Adam Lesinski 2575f3a55cc569a9b61f540a85d9828e91bdca5047Adam Lesinskiconstexpr const char* kXmlPreamble = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"; 2675f3a55cc569a9b61f540a85d9828e91bdca5047Adam Lesinski 2775f3a55cc569a9b61f540a85d9828e91bdca5047Adam LesinskiTEST(XmlDomTest, Inflate) { 2875f3a55cc569a9b61f540a85d9828e91bdca5047Adam Lesinski std::stringstream in(kXmlPreamble); 2975f3a55cc569a9b61f540a85d9828e91bdca5047Adam Lesinski in << R"EOF( 3075f3a55cc569a9b61f540a85d9828e91bdca5047Adam Lesinski <Layout xmlns:android="http://schemas.android.com/apk/res/android" 3175f3a55cc569a9b61f540a85d9828e91bdca5047Adam Lesinski android:layout_width="match_parent" 3275f3a55cc569a9b61f540a85d9828e91bdca5047Adam Lesinski android:layout_height="wrap_content"> 3375f3a55cc569a9b61f540a85d9828e91bdca5047Adam Lesinski <TextView android:id="@+id/id" 3475f3a55cc569a9b61f540a85d9828e91bdca5047Adam Lesinski android:layout_width="wrap_content" 3575f3a55cc569a9b61f540a85d9828e91bdca5047Adam Lesinski android:layout_height="wrap_content" /> 3675f3a55cc569a9b61f540a85d9828e91bdca5047Adam Lesinski </Layout> 3775f3a55cc569a9b61f540a85d9828e91bdca5047Adam Lesinski )EOF"; 3875f3a55cc569a9b61f540a85d9828e91bdca5047Adam Lesinski 391ab598f46c3ff520a67f9d80194847741f3467abAdam Lesinski const Source source = { "test.xml" }; 401ab598f46c3ff520a67f9d80194847741f3467abAdam Lesinski StdErrDiagnostics diag; 41467f171315f9c2037fcd3eb5edcfabc40671bf7bAdam Lesinski std::unique_ptr<xml::XmlResource> doc = xml::inflate(&in, &diag, source); 421ab598f46c3ff520a67f9d80194847741f3467abAdam Lesinski ASSERT_NE(doc, nullptr); 4375f3a55cc569a9b61f540a85d9828e91bdca5047Adam Lesinski 441ab598f46c3ff520a67f9d80194847741f3467abAdam Lesinski xml::Namespace* ns = xml::nodeCast<xml::Namespace>(doc->root.get()); 451ab598f46c3ff520a67f9d80194847741f3467abAdam Lesinski ASSERT_NE(ns, nullptr); 4675f3a55cc569a9b61f540a85d9828e91bdca5047Adam Lesinski EXPECT_EQ(ns->namespaceUri, u"http://schemas.android.com/apk/res/android"); 4775f3a55cc569a9b61f540a85d9828e91bdca5047Adam Lesinski EXPECT_EQ(ns->namespacePrefix, u"android"); 4875f3a55cc569a9b61f540a85d9828e91bdca5047Adam Lesinski} 4975f3a55cc569a9b61f540a85d9828e91bdca5047Adam Lesinski 5075f3a55cc569a9b61f540a85d9828e91bdca5047Adam Lesinski} // namespace aapt 51