blob: 1909f75ad0c32f91925a9ff7ddd3be608e061051 [file] [log] [blame]
Adam Lesinski75f3a552015-06-03 14:54:23 -07001/*
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
Adam Lesinski467f1712015-11-16 17:35:44 -080017#include "xml/XmlDom.h"
Adam Lesinski75f3a552015-06-03 14:54:23 -070018
19#include <gtest/gtest.h>
20#include <sstream>
21#include <string>
22
23namespace aapt {
24
25constexpr const char* kXmlPreamble = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
26
27TEST(XmlDomTest, Inflate) {
28 std::stringstream in(kXmlPreamble);
29 in << R"EOF(
30 <Layout xmlns:android="http://schemas.android.com/apk/res/android"
31 android:layout_width="match_parent"
32 android:layout_height="wrap_content">
33 <TextView android:id="@+id/id"
34 android:layout_width="wrap_content"
35 android:layout_height="wrap_content" />
36 </Layout>
37 )EOF";
38
Adam Lesinski1ab598f2015-08-14 14:26:04 -070039 const Source source = { "test.xml" };
40 StdErrDiagnostics diag;
Adam Lesinski467f1712015-11-16 17:35:44 -080041 std::unique_ptr<xml::XmlResource> doc = xml::inflate(&in, &diag, source);
Adam Lesinski1ab598f2015-08-14 14:26:04 -070042 ASSERT_NE(doc, nullptr);
Adam Lesinski75f3a552015-06-03 14:54:23 -070043
Adam Lesinski1ab598f2015-08-14 14:26:04 -070044 xml::Namespace* ns = xml::nodeCast<xml::Namespace>(doc->root.get());
45 ASSERT_NE(ns, nullptr);
Adam Lesinskid0f116b2016-07-08 15:00:32 -070046 EXPECT_EQ(ns->namespaceUri, xml::kSchemaAndroid);
47 EXPECT_EQ(ns->namespacePrefix, "android");
Adam Lesinski75f3a552015-06-03 14:54:23 -070048}
49
50} // namespace aapt