summaryrefslogtreecommitdiff
path: root/tools/aapt2/xml/XmlDom_test.cpp
diff options
context:
space:
mode:
authorAdam Lesinski <adamlesinski@google.com>2017-06-29 17:53:36 -0700
committerAdam Lesinski <adamlesinski@google.com>2017-07-07 13:23:55 -0700
commitfba0cf2950a91726e475fb180090cc25bcb11a7a (patch)
tree222ec9ccc4e1710e5a269edd2fffce60ca1692d7 /tools/aapt2/xml/XmlDom_test.cpp
parent66ea8400383d5737b996a136f3aead0965f7be3d (diff)
AAPT2: Fix processing of quotes in XML
When processing attributes in XML, quotes can't be used to mark a section as whitespace preserving, so the assumption should be that the entire string is whitespace preserving, which makes quote characters literals. Bug: 62840718 Bug: 62840406 Test: make aapt2_tests Change-Id: I4afff02148b5b8e78833abf1f323c2f5325d6155
Diffstat (limited to 'tools/aapt2/xml/XmlDom_test.cpp')
-rw-r--r--tools/aapt2/xml/XmlDom_test.cpp54
1 files changed, 34 insertions, 20 deletions
diff --git a/tools/aapt2/xml/XmlDom_test.cpp b/tools/aapt2/xml/XmlDom_test.cpp
index c1aa10b89a2f..f0122e8c617a 100644
--- a/tools/aapt2/xml/XmlDom_test.cpp
+++ b/tools/aapt2/xml/XmlDom_test.cpp
@@ -21,7 +21,9 @@
#include "test/Test.h"
+using ::testing::Eq;
using ::testing::NotNull;
+using ::testing::SizeIs;
namespace aapt {
@@ -30,47 +32,59 @@ constexpr const char* kXmlPreamble =
TEST(XmlDomTest, Inflate) {
std::stringstream in(kXmlPreamble);
- in << R"EOF(
- <Layout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
- android:layout_height="wrap_content">
- <TextView android:id="@+id/id"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content" />
- </Layout>
- )EOF";
-
- const Source source = {"test.xml"};
+ in << R"(
+ <Layout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content">
+ <TextView android:id="@+id/id"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content" />
+ </Layout>)";
+
+ const Source source("test.xml");
StdErrDiagnostics diag;
std::unique_ptr<xml::XmlResource> doc = xml::Inflate(&in, &diag, source);
ASSERT_THAT(doc, NotNull());
xml::Namespace* ns = xml::NodeCast<xml::Namespace>(doc->root.get());
ASSERT_THAT(ns, NotNull());
- EXPECT_EQ(ns->namespace_uri, xml::kSchemaAndroid);
- EXPECT_EQ(ns->namespace_prefix, "android");
+ EXPECT_THAT(ns->namespace_uri, Eq(xml::kSchemaAndroid));
+ EXPECT_THAT(ns->namespace_prefix, Eq("android"));
}
// Escaping is handled after parsing of the values for resource-specific values.
TEST(XmlDomTest, ForwardEscapes) {
- std::unique_ptr<xml::XmlResource> doc = test::BuildXmlDom(R"EOF(
- <element value="\?hello" pattern="\\d{5}">\\d{5}</element>)EOF");
+ std::unique_ptr<xml::XmlResource> doc = test::BuildXmlDom(R"(
+ <element value="\?hello" pattern="\\d{5}">\\d{5}</element>)");
- xml::Element* el = xml::FindRootElement(doc->root.get());
+ xml::Element* el = xml::FindRootElement(doc.get());
ASSERT_THAT(el, NotNull());
xml::Attribute* attr = el->FindAttribute({}, "pattern");
ASSERT_THAT(attr, NotNull());
- EXPECT_EQ("\\\\d{5}", attr->value);
+ EXPECT_THAT(attr->value, Eq("\\\\d{5}"));
attr = el->FindAttribute({}, "value");
ASSERT_THAT(attr, NotNull());
- EXPECT_EQ("\\?hello", attr->value);
+ EXPECT_THAT(attr->value, Eq("\\?hello"));
+
+ ASSERT_THAT(el->children, SizeIs(1u));
- ASSERT_EQ(1u, el->children.size());
xml::Text* text = xml::NodeCast<xml::Text>(el->children[0].get());
ASSERT_THAT(text, NotNull());
- EXPECT_EQ("\\\\d{5}", text->text);
+ EXPECT_THAT(text->text, Eq("\\\\d{5}"));
+}
+
+TEST(XmlDomTest, XmlEscapeSequencesAreParsed) {
+ std::unique_ptr<xml::XmlResource> doc = test::BuildXmlDom(R"(<element value="&quot;" />)");
+
+ xml::Element* el = xml::FindRootElement(doc.get());
+ ASSERT_THAT(el, NotNull());
+
+ xml::Attribute* attr = el->FindAttribute({}, "value");
+ ASSERT_THAT(attr, NotNull());
+
+ EXPECT_THAT(attr->value, Eq("\""));
}
} // namespace aapt