diff options
Diffstat (limited to 'tools/aapt2/link/XmlReferenceLinker_test.cpp')
| -rw-r--r-- | tools/aapt2/link/XmlReferenceLinker_test.cpp | 137 |
1 files changed, 61 insertions, 76 deletions
diff --git a/tools/aapt2/link/XmlReferenceLinker_test.cpp b/tools/aapt2/link/XmlReferenceLinker_test.cpp index de81e73f613e..228cfb9e3d66 100644 --- a/tools/aapt2/link/XmlReferenceLinker_test.cpp +++ b/tools/aapt2/link/XmlReferenceLinker_test.cpp @@ -18,6 +18,9 @@ #include "test/Test.h" +using ::testing::IsNull; +using ::testing::NotNull; + namespace aapt { class XmlReferenceLinkerTest : public ::testing::Test { @@ -90,56 +93,48 @@ TEST_F(XmlReferenceLinkerTest, LinkBasicAttributes) { ASSERT_TRUE(linker.Consume(context_.get(), doc.get())); xml::Element* view_el = xml::FindRootElement(doc.get()); - ASSERT_NE(nullptr, view_el); + ASSERT_THAT(view_el, NotNull()); xml::Attribute* xml_attr = view_el->FindAttribute(xml::kSchemaAndroid, "layout_width"); - ASSERT_NE(nullptr, xml_attr); - AAPT_ASSERT_TRUE(xml_attr->compiled_attribute); - AAPT_ASSERT_TRUE(xml_attr->compiled_attribute.value().id); - EXPECT_EQ(ResourceId(0x01010000), xml_attr->compiled_attribute.value().id.value()); - ASSERT_NE(nullptr, xml_attr->compiled_value); - ASSERT_NE(nullptr, ValueCast<BinaryPrimitive>(xml_attr->compiled_value.get())); + ASSERT_THAT(xml_attr, NotNull()); + ASSERT_TRUE(xml_attr->compiled_attribute); + EXPECT_EQ(make_value(ResourceId(0x01010000)), xml_attr->compiled_attribute.value().id); + EXPECT_THAT(ValueCast<BinaryPrimitive>(xml_attr->compiled_value.get()), NotNull()); xml_attr = view_el->FindAttribute(xml::kSchemaAndroid, "background"); - ASSERT_NE(nullptr, xml_attr); - AAPT_ASSERT_TRUE(xml_attr->compiled_attribute); - AAPT_ASSERT_TRUE(xml_attr->compiled_attribute.value().id); - EXPECT_EQ(ResourceId(0x01010001), xml_attr->compiled_attribute.value().id.value()); - ASSERT_NE(nullptr, xml_attr->compiled_value); + ASSERT_THAT(xml_attr, NotNull()); + ASSERT_TRUE(xml_attr->compiled_attribute); + EXPECT_EQ(make_value(ResourceId(0x01010001)), xml_attr->compiled_attribute.value().id); Reference* ref = ValueCast<Reference>(xml_attr->compiled_value.get()); - ASSERT_NE(nullptr, ref); - AAPT_ASSERT_TRUE(ref->name); - EXPECT_EQ(test::ParseNameOrDie("color/green"), ref->name.value()); // Make sure the name - // didn't change. - AAPT_ASSERT_TRUE(ref->id); - EXPECT_EQ(ResourceId(0x7f020000), ref->id.value()); + ASSERT_THAT(ref, NotNull()); + EXPECT_EQ(make_value(test::ParseNameOrDie("color/green")), ref->name); // Make sure the name + // didn't change. + EXPECT_EQ(make_value(ResourceId(0x7f020000)), ref->id); xml_attr = view_el->FindAttribute(xml::kSchemaAndroid, "text"); - ASSERT_NE(nullptr, xml_attr); - AAPT_ASSERT_TRUE(xml_attr->compiled_attribute); - ASSERT_FALSE(xml_attr->compiled_value); // Strings don't get compiled for memory sake. + ASSERT_THAT(xml_attr, NotNull()); + EXPECT_TRUE(xml_attr->compiled_attribute); + EXPECT_THAT(xml_attr->compiled_value, IsNull()); // Strings don't get compiled for memory sake. xml_attr = view_el->FindAttribute(xml::kSchemaAndroid, "attr"); - ASSERT_NE(nullptr, xml_attr); - AAPT_ASSERT_TRUE(xml_attr->compiled_attribute); - ASSERT_FALSE(xml_attr->compiled_value); // Should be a plain string. + ASSERT_THAT(xml_attr, NotNull()); + EXPECT_TRUE(xml_attr->compiled_attribute); + EXPECT_THAT(xml_attr->compiled_value, IsNull()); // Should be a plain string. xml_attr = view_el->FindAttribute("", "nonAaptAttr"); - ASSERT_NE(nullptr, xml_attr); - AAPT_ASSERT_FALSE(xml_attr->compiled_attribute); - ASSERT_NE(nullptr, xml_attr->compiled_value); - ASSERT_NE(nullptr, ValueCast<BinaryPrimitive>(xml_attr->compiled_value.get())); + ASSERT_THAT(xml_attr, NotNull()); + EXPECT_FALSE(xml_attr->compiled_attribute); + EXPECT_THAT(ValueCast<BinaryPrimitive>(xml_attr->compiled_value.get()), NotNull()); xml_attr = view_el->FindAttribute("", "nonAaptAttrRef"); - ASSERT_NE(nullptr, xml_attr); - AAPT_ASSERT_FALSE(xml_attr->compiled_attribute); - ASSERT_NE(nullptr, xml_attr->compiled_value); - ASSERT_NE(nullptr, ValueCast<Reference>(xml_attr->compiled_value.get())); + ASSERT_THAT(xml_attr, NotNull()); + EXPECT_FALSE(xml_attr->compiled_attribute); + EXPECT_THAT(ValueCast<Reference>(xml_attr->compiled_value.get()), NotNull()); xml_attr = view_el->FindAttribute("", "class"); - ASSERT_NE(nullptr, xml_attr); - AAPT_ASSERT_FALSE(xml_attr->compiled_attribute); - ASSERT_EQ(nullptr, xml_attr->compiled_value); + ASSERT_THAT(xml_attr, NotNull()); + EXPECT_FALSE(xml_attr->compiled_attribute); + EXPECT_THAT(xml_attr->compiled_value, IsNull()); } TEST_F(XmlReferenceLinkerTest, PrivateSymbolsAreNotLinked) { @@ -169,15 +164,14 @@ TEST_F(XmlReferenceLinkerTest, LinkMangledAttributes) { ASSERT_TRUE(linker.Consume(context_.get(), doc.get())); xml::Element* view_el = xml::FindRootElement(doc.get()); - ASSERT_NE(view_el, nullptr); + ASSERT_THAT(view_el, NotNull()); xml::Attribute* xml_attr = view_el->FindAttribute(xml::BuildPackageNamespace("com.android.support"), "colorAccent"); - ASSERT_NE(xml_attr, nullptr); - AAPT_ASSERT_TRUE(xml_attr->compiled_attribute); - AAPT_ASSERT_TRUE(xml_attr->compiled_attribute.value().id); - EXPECT_EQ(xml_attr->compiled_attribute.value().id.value(), ResourceId(0x7f010001)); - ASSERT_NE(ValueCast<BinaryPrimitive>(xml_attr->compiled_value.get()), nullptr); + ASSERT_THAT(xml_attr, NotNull()); + ASSERT_TRUE(xml_attr->compiled_attribute); + EXPECT_EQ(make_value(ResourceId(0x7f010001)), xml_attr->compiled_attribute.value().id); + EXPECT_THAT(ValueCast<BinaryPrimitive>(xml_attr->compiled_value.get()), NotNull()); } TEST_F(XmlReferenceLinkerTest, LinkAutoResReference) { @@ -189,18 +183,16 @@ TEST_F(XmlReferenceLinkerTest, LinkAutoResReference) { ASSERT_TRUE(linker.Consume(context_.get(), doc.get())); xml::Element* view_el = xml::FindRootElement(doc.get()); - ASSERT_NE(view_el, nullptr); + ASSERT_THAT(view_el, NotNull()); xml::Attribute* xml_attr = view_el->FindAttribute(xml::kSchemaAuto, "colorAccent"); - ASSERT_NE(xml_attr, nullptr); - AAPT_ASSERT_TRUE(xml_attr->compiled_attribute); - AAPT_ASSERT_TRUE(xml_attr->compiled_attribute.value().id); - EXPECT_EQ(xml_attr->compiled_attribute.value().id.value(), ResourceId(0x7f010000)); + ASSERT_THAT(xml_attr, NotNull()); + ASSERT_TRUE(xml_attr->compiled_attribute); + EXPECT_EQ(make_value(ResourceId(0x7f010000)), xml_attr->compiled_attribute.value().id); Reference* ref = ValueCast<Reference>(xml_attr->compiled_value.get()); - ASSERT_NE(ref, nullptr); - AAPT_ASSERT_TRUE(ref->name); - AAPT_ASSERT_TRUE(ref->id); - EXPECT_EQ(ref->id.value(), ResourceId(0x7f020001)); + ASSERT_THAT(ref, NotNull()); + ASSERT_TRUE(ref->name); + EXPECT_EQ(make_value(ResourceId(0x7f020001)), ref->id); } TEST_F(XmlReferenceLinkerTest, LinkViewWithShadowedPackageAlias) { @@ -215,35 +207,31 @@ TEST_F(XmlReferenceLinkerTest, LinkViewWithShadowedPackageAlias) { ASSERT_TRUE(linker.Consume(context_.get(), doc.get())); xml::Element* view_el = xml::FindRootElement(doc.get()); - ASSERT_NE(view_el, nullptr); + ASSERT_THAT(view_el, NotNull()); // All attributes and references in this element should be referring to // "android" (0x01). xml::Attribute* xml_attr = view_el->FindAttribute(xml::kSchemaAndroid, "attr"); - ASSERT_NE(xml_attr, nullptr); - AAPT_ASSERT_TRUE(xml_attr->compiled_attribute); - AAPT_ASSERT_TRUE(xml_attr->compiled_attribute.value().id); - EXPECT_EQ(xml_attr->compiled_attribute.value().id.value(), ResourceId(0x01010002)); + ASSERT_THAT(xml_attr, NotNull()); + ASSERT_TRUE(xml_attr->compiled_attribute); + EXPECT_EQ(make_value(ResourceId(0x01010002)), xml_attr->compiled_attribute.value().id); Reference* ref = ValueCast<Reference>(xml_attr->compiled_value.get()); - ASSERT_NE(ref, nullptr); - AAPT_ASSERT_TRUE(ref->id); - EXPECT_EQ(ref->id.value(), ResourceId(0x01030000)); + ASSERT_THAT(ref, NotNull()); + EXPECT_EQ(make_value(ResourceId(0x01030000)), ref->id); ASSERT_FALSE(view_el->GetChildElements().empty()); view_el = view_el->GetChildElements().front(); - ASSERT_NE(view_el, nullptr); + ASSERT_THAT(view_el, NotNull()); // All attributes and references in this element should be referring to // "com.app.test" (0x7f). xml_attr = view_el->FindAttribute(xml::BuildPackageNamespace("com.app.test"), "attr"); - ASSERT_NE(xml_attr, nullptr); - AAPT_ASSERT_TRUE(xml_attr->compiled_attribute); - AAPT_ASSERT_TRUE(xml_attr->compiled_attribute.value().id); - EXPECT_EQ(xml_attr->compiled_attribute.value().id.value(), ResourceId(0x7f010002)); + ASSERT_THAT(xml_attr, NotNull()); + ASSERT_TRUE(xml_attr->compiled_attribute); + EXPECT_EQ(make_value(ResourceId(0x7f010002)), xml_attr->compiled_attribute.value().id); ref = ValueCast<Reference>(xml_attr->compiled_value.get()); - ASSERT_NE(ref, nullptr); - AAPT_ASSERT_TRUE(ref->id); - EXPECT_EQ(ref->id.value(), ResourceId(0x7f030000)); + ASSERT_THAT(ref, NotNull()); + EXPECT_EQ(make_value(ResourceId(0x7f030000)), ref->id); } TEST_F(XmlReferenceLinkerTest, LinkViewWithLocalPackageAndAliasOfTheSameName) { @@ -255,20 +243,17 @@ TEST_F(XmlReferenceLinkerTest, LinkViewWithLocalPackageAndAliasOfTheSameName) { ASSERT_TRUE(linker.Consume(context_.get(), doc.get())); xml::Element* view_el = xml::FindRootElement(doc.get()); - ASSERT_NE(view_el, nullptr); + ASSERT_THAT(view_el, NotNull()); // All attributes and references in this element should be referring to // "com.app.test" (0x7f). - xml::Attribute* xml_attr = - view_el->FindAttribute(xml::BuildPackageNamespace("com.app.test"), "attr"); - ASSERT_NE(xml_attr, nullptr); - AAPT_ASSERT_TRUE(xml_attr->compiled_attribute); - AAPT_ASSERT_TRUE(xml_attr->compiled_attribute.value().id); - EXPECT_EQ(xml_attr->compiled_attribute.value().id.value(), ResourceId(0x7f010002)); + xml::Attribute* xml_attr = view_el->FindAttribute(xml::BuildPackageNamespace("com.app.test"), "attr"); + ASSERT_THAT(xml_attr, NotNull()); + ASSERT_TRUE(xml_attr->compiled_attribute); + EXPECT_EQ(make_value(ResourceId(0x7f010002)), xml_attr->compiled_attribute.value().id); Reference* ref = ValueCast<Reference>(xml_attr->compiled_value.get()); - ASSERT_NE(ref, nullptr); - AAPT_ASSERT_TRUE(ref->id); - EXPECT_EQ(ref->id.value(), ResourceId(0x7f030000)); + ASSERT_THAT(ref, NotNull()); + EXPECT_EQ(make_value(ResourceId(0x7f030000)), ref->id); } } // namespace aapt |
