diff options
Diffstat (limited to 'tools/aapt2/xml/XmlDom_test.cpp')
| -rw-r--r-- | tools/aapt2/xml/XmlDom_test.cpp | 37 |
1 files changed, 22 insertions, 15 deletions
diff --git a/tools/aapt2/xml/XmlDom_test.cpp b/tools/aapt2/xml/XmlDom_test.cpp index 031801e1dd2f..f0122e8c617a 100644 --- a/tools/aapt2/xml/XmlDom_test.cpp +++ b/tools/aapt2/xml/XmlDom_test.cpp @@ -21,6 +21,10 @@ #include "test/Test.h" +using ::testing::Eq; +using ::testing::NotNull; +using ::testing::SizeIs; + namespace aapt { constexpr const char* kXmlPreamble = @@ -40,12 +44,12 @@ TEST(XmlDomTest, Inflate) { const Source source("test.xml"); StdErrDiagnostics diag; std::unique_ptr<xml::XmlResource> doc = xml::Inflate(&in, &diag, source); - ASSERT_NE(doc, nullptr); + ASSERT_THAT(doc, NotNull()); xml::Namespace* ns = xml::NodeCast<xml::Namespace>(doc->root.get()); - ASSERT_NE(ns, nullptr); - EXPECT_EQ(ns->namespace_uri, xml::kSchemaAndroid); - EXPECT_EQ(ns->namespace_prefix, "android"); + ASSERT_THAT(ns, NotNull()); + 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. @@ -53,31 +57,34 @@ TEST(XmlDomTest, ForwardEscapes) { 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()); - ASSERT_NE(nullptr, el); + xml::Element* el = xml::FindRootElement(doc.get()); + ASSERT_THAT(el, NotNull()); xml::Attribute* attr = el->FindAttribute({}, "pattern"); - ASSERT_NE(nullptr, attr); - EXPECT_EQ("\\\\d{5}", attr->value); + ASSERT_THAT(attr, NotNull()); + EXPECT_THAT(attr->value, Eq("\\\\d{5}")); attr = el->FindAttribute({}, "value"); - ASSERT_NE(nullptr, attr); - EXPECT_EQ("\\?hello", attr->value); + ASSERT_THAT(attr, NotNull()); + EXPECT_THAT(attr->value, Eq("\\?hello")); + + ASSERT_THAT(el->children, SizeIs(1u)); xml::Text* text = xml::NodeCast<xml::Text>(el->children[0].get()); - ASSERT_NE(nullptr, text); - EXPECT_EQ("\\\\d{5}", text->text); + ASSERT_THAT(text, NotNull()); + EXPECT_THAT(text->text, Eq("\\\\d{5}")); } TEST(XmlDomTest, XmlEscapeSequencesAreParsed) { std::unique_ptr<xml::XmlResource> doc = test::BuildXmlDom(R"(<element value=""" />)"); xml::Element* el = xml::FindRootElement(doc.get()); - ASSERT_NE(nullptr, el); + ASSERT_THAT(el, NotNull()); xml::Attribute* attr = el->FindAttribute({}, "value"); - ASSERT_NE(nullptr, attr); - EXPECT_EQ("\"", attr->value); + ASSERT_THAT(attr, NotNull()); + + EXPECT_THAT(attr->value, Eq("\"")); } } // namespace aapt |
