Adam Lesinski | 75f3a55 | 2015-06-03 14:54:23 -0700 | [diff] [blame] | 1 | /* |
| 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 Lesinski | 467f171 | 2015-11-16 17:35:44 -0800 | [diff] [blame] | 17 | #include "xml/XmlDom.h" |
Adam Lesinski | 75f3a55 | 2015-06-03 14:54:23 -0700 | [diff] [blame] | 18 | |
Adam Lesinski | 75f3a55 | 2015-06-03 14:54:23 -0700 | [diff] [blame] | 19 | #include <sstream> |
| 20 | #include <string> |
| 21 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame^] | 22 | #include "test/Test.h" |
| 23 | |
Adam Lesinski | 75f3a55 | 2015-06-03 14:54:23 -0700 | [diff] [blame] | 24 | namespace aapt { |
| 25 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame^] | 26 | constexpr const char* kXmlPreamble = |
| 27 | "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"; |
Adam Lesinski | 75f3a55 | 2015-06-03 14:54:23 -0700 | [diff] [blame] | 28 | |
| 29 | TEST(XmlDomTest, Inflate) { |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame^] | 30 | std::stringstream in(kXmlPreamble); |
| 31 | in << R"EOF( |
Adam Lesinski | 75f3a55 | 2015-06-03 14:54:23 -0700 | [diff] [blame] | 32 | <Layout xmlns:android="http://schemas.android.com/apk/res/android" |
| 33 | android:layout_width="match_parent" |
| 34 | android:layout_height="wrap_content"> |
| 35 | <TextView android:id="@+id/id" |
| 36 | android:layout_width="wrap_content" |
| 37 | android:layout_height="wrap_content" /> |
| 38 | </Layout> |
| 39 | )EOF"; |
| 40 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame^] | 41 | const Source source = {"test.xml"}; |
| 42 | StdErrDiagnostics diag; |
| 43 | std::unique_ptr<xml::XmlResource> doc = xml::Inflate(&in, &diag, source); |
| 44 | ASSERT_NE(doc, nullptr); |
Adam Lesinski | 75f3a55 | 2015-06-03 14:54:23 -0700 | [diff] [blame] | 45 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame^] | 46 | xml::Namespace* ns = xml::NodeCast<xml::Namespace>(doc->root.get()); |
| 47 | ASSERT_NE(ns, nullptr); |
| 48 | EXPECT_EQ(ns->namespace_uri, xml::kSchemaAndroid); |
| 49 | EXPECT_EQ(ns->namespace_prefix, "android"); |
Adam Lesinski | 75f3a55 | 2015-06-03 14:54:23 -0700 | [diff] [blame] | 50 | } |
| 51 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame^] | 52 | } // namespace aapt |