diff options
Diffstat (limited to 'tools/aapt2/link/XmlReferenceLinker_test.cpp')
-rw-r--r-- | tools/aapt2/link/XmlReferenceLinker_test.cpp | 60 |
1 files changed, 28 insertions, 32 deletions
diff --git a/tools/aapt2/link/XmlReferenceLinker_test.cpp b/tools/aapt2/link/XmlReferenceLinker_test.cpp index af9098b9e483..51eb62c2c0ff 100644 --- a/tools/aapt2/link/XmlReferenceLinker_test.cpp +++ b/tools/aapt2/link/XmlReferenceLinker_test.cpp @@ -14,7 +14,6 @@ * limitations under the License. */ -#include <test/Context.h> #include "link/Linkers.h" #include "test/Test.h" @@ -24,44 +23,44 @@ class XmlReferenceLinkerTest : public ::testing::Test { public: void SetUp() override { mContext = test::ContextBuilder() - .setCompilationPackage(u"com.app.test") + .setCompilationPackage("com.app.test") .setNameManglerPolicy( - NameManglerPolicy{ u"com.app.test", { u"com.android.support" } }) + NameManglerPolicy{ "com.app.test", { "com.android.support" } }) .addSymbolSource(test::StaticSymbolSourceBuilder() - .addPublicSymbol(u"@android:attr/layout_width", ResourceId(0x01010000), + .addPublicSymbol("android:attr/layout_width", ResourceId(0x01010000), test::AttributeBuilder() .setTypeMask(android::ResTable_map::TYPE_ENUM | android::ResTable_map::TYPE_DIMENSION) - .addItem(u"match_parent", 0xffffffff) + .addItem("match_parent", 0xffffffff) .build()) - .addPublicSymbol(u"@android:attr/background", ResourceId(0x01010001), + .addPublicSymbol("android:attr/background", ResourceId(0x01010001), test::AttributeBuilder() .setTypeMask(android::ResTable_map::TYPE_COLOR).build()) - .addPublicSymbol(u"@android:attr/attr", ResourceId(0x01010002), + .addPublicSymbol("android:attr/attr", ResourceId(0x01010002), test::AttributeBuilder().build()) - .addPublicSymbol(u"@android:attr/text", ResourceId(0x01010003), + .addPublicSymbol("android:attr/text", ResourceId(0x01010003), test::AttributeBuilder() .setTypeMask(android::ResTable_map::TYPE_STRING) .build()) // Add one real symbol that was introduces in v21 - .addPublicSymbol(u"@android:attr/colorAccent", ResourceId(0x01010435), + .addPublicSymbol("android:attr/colorAccent", ResourceId(0x01010435), test::AttributeBuilder().build()) // Private symbol. - .addSymbol(u"@android:color/hidden", ResourceId(0x01020001)) + .addSymbol("android:color/hidden", ResourceId(0x01020001)) - .addPublicSymbol(u"@android:id/id", ResourceId(0x01030000)) - .addSymbol(u"@com.app.test:id/id", ResourceId(0x7f030000)) - .addSymbol(u"@com.app.test:color/green", ResourceId(0x7f020000)) - .addSymbol(u"@com.app.test:color/red", ResourceId(0x7f020001)) - .addSymbol(u"@com.app.test:attr/colorAccent", ResourceId(0x7f010000), + .addPublicSymbol("android:id/id", ResourceId(0x01030000)) + .addSymbol("com.app.test:id/id", ResourceId(0x7f030000)) + .addSymbol("com.app.test:color/green", ResourceId(0x7f020000)) + .addSymbol("com.app.test:color/red", ResourceId(0x7f020001)) + .addSymbol("com.app.test:attr/colorAccent", ResourceId(0x7f010000), test::AttributeBuilder() .setTypeMask(android::ResTable_map::TYPE_COLOR).build()) - .addPublicSymbol(u"@com.app.test:attr/com.android.support$colorAccent", + .addPublicSymbol("com.app.test:attr/com.android.support$colorAccent", ResourceId(0x7f010001), test::AttributeBuilder() .setTypeMask(android::ResTable_map::TYPE_COLOR).build()) - .addPublicSymbol(u"@com.app.test:attr/attr", ResourceId(0x7f010002), + .addPublicSymbol("com.app.test:attr/attr", ResourceId(0x7f010002), test::AttributeBuilder().build()) .build()) .build(); @@ -85,8 +84,7 @@ TEST_F(XmlReferenceLinkerTest, LinkBasicAttributes) { xml::Element* viewEl = xml::findRootElement(doc.get()); ASSERT_NE(viewEl, nullptr); - xml::Attribute* xmlAttr = viewEl->findAttribute(u"http://schemas.android.com/apk/res/android", - u"layout_width"); + xml::Attribute* xmlAttr = viewEl->findAttribute(xml::kSchemaAndroid, "layout_width"); ASSERT_NE(xmlAttr, nullptr); AAPT_ASSERT_TRUE(xmlAttr->compiledAttribute); AAPT_ASSERT_TRUE(xmlAttr->compiledAttribute.value().id); @@ -94,7 +92,7 @@ TEST_F(XmlReferenceLinkerTest, LinkBasicAttributes) { ASSERT_NE(xmlAttr->compiledValue, nullptr); ASSERT_NE(valueCast<BinaryPrimitive>(xmlAttr->compiledValue.get()), nullptr); - xmlAttr = viewEl->findAttribute(u"http://schemas.android.com/apk/res/android", u"background"); + xmlAttr = viewEl->findAttribute(xml::kSchemaAndroid, "background"); ASSERT_NE(xmlAttr, nullptr); AAPT_ASSERT_TRUE(xmlAttr->compiledAttribute); AAPT_ASSERT_TRUE(xmlAttr->compiledAttribute.value().id); @@ -103,17 +101,17 @@ TEST_F(XmlReferenceLinkerTest, LinkBasicAttributes) { Reference* ref = valueCast<Reference>(xmlAttr->compiledValue.get()); ASSERT_NE(ref, nullptr); AAPT_ASSERT_TRUE(ref->name); - EXPECT_EQ(ref->name.value(), test::parseNameOrDie(u"@color/green")); // Make sure the name - // didn't change. + EXPECT_EQ(ref->name.value(), test::parseNameOrDie("color/green")); // Make sure the name + // didn't change. AAPT_ASSERT_TRUE(ref->id); EXPECT_EQ(ref->id.value(), ResourceId(0x7f020000)); - xmlAttr = viewEl->findAttribute(u"http://schemas.android.com/apk/res/android", u"text"); + xmlAttr = viewEl->findAttribute(xml::kSchemaAndroid, "text"); ASSERT_NE(xmlAttr, nullptr); AAPT_ASSERT_TRUE(xmlAttr->compiledAttribute); ASSERT_FALSE(xmlAttr->compiledValue); // Strings don't get compiled for memory sake. - xmlAttr = viewEl->findAttribute(u"", u"class"); + xmlAttr = viewEl->findAttribute("", "class"); ASSERT_NE(xmlAttr, nullptr); AAPT_ASSERT_FALSE(xmlAttr->compiledAttribute); ASSERT_EQ(xmlAttr->compiledValue, nullptr); @@ -159,7 +157,7 @@ TEST_F(XmlReferenceLinkerTest, LinkMangledAttributes) { ASSERT_NE(viewEl, nullptr); xml::Attribute* xmlAttr = viewEl->findAttribute( - u"http://schemas.android.com/apk/res/com.android.support", u"colorAccent"); + xml::buildPackageNamespace("com.android.support"), "colorAccent"); ASSERT_NE(xmlAttr, nullptr); AAPT_ASSERT_TRUE(xmlAttr->compiledAttribute); AAPT_ASSERT_TRUE(xmlAttr->compiledAttribute.value().id); @@ -178,8 +176,7 @@ TEST_F(XmlReferenceLinkerTest, LinkAutoResReference) { xml::Element* viewEl = xml::findRootElement(doc.get()); ASSERT_NE(viewEl, nullptr); - xml::Attribute* xmlAttr = viewEl->findAttribute(u"http://schemas.android.com/apk/res-auto", - u"colorAccent"); + xml::Attribute* xmlAttr = viewEl->findAttribute(xml::kSchemaAuto, "colorAccent"); ASSERT_NE(xmlAttr, nullptr); AAPT_ASSERT_TRUE(xmlAttr->compiledAttribute); AAPT_ASSERT_TRUE(xmlAttr->compiledAttribute.value().id); @@ -206,8 +203,7 @@ TEST_F(XmlReferenceLinkerTest, LinkViewWithShadowedPackageAlias) { ASSERT_NE(viewEl, nullptr); // All attributes and references in this element should be referring to "android" (0x01). - xml::Attribute* xmlAttr = viewEl->findAttribute(u"http://schemas.android.com/apk/res/android", - u"attr"); + xml::Attribute* xmlAttr = viewEl->findAttribute(xml::kSchemaAndroid, "attr"); ASSERT_NE(xmlAttr, nullptr); AAPT_ASSERT_TRUE(xmlAttr->compiledAttribute); AAPT_ASSERT_TRUE(xmlAttr->compiledAttribute.value().id); @@ -222,7 +218,7 @@ TEST_F(XmlReferenceLinkerTest, LinkViewWithShadowedPackageAlias) { ASSERT_NE(viewEl, nullptr); // All attributes and references in this element should be referring to "com.app.test" (0x7f). - xmlAttr = viewEl->findAttribute(u"http://schemas.android.com/apk/res/com.app.test", u"attr"); + xmlAttr = viewEl->findAttribute(xml::buildPackageNamespace("com.app.test"), "attr"); ASSERT_NE(xmlAttr, nullptr); AAPT_ASSERT_TRUE(xmlAttr->compiledAttribute); AAPT_ASSERT_TRUE(xmlAttr->compiledAttribute.value().id); @@ -245,8 +241,8 @@ TEST_F(XmlReferenceLinkerTest, LinkViewWithLocalPackageAndAliasOfTheSameName) { ASSERT_NE(viewEl, nullptr); // All attributes and references in this element should be referring to "com.app.test" (0x7f). - xml::Attribute* xmlAttr = viewEl->findAttribute( - u"http://schemas.android.com/apk/res/com.app.test", u"attr"); + xml::Attribute* xmlAttr = viewEl->findAttribute(xml::buildPackageNamespace("com.app.test"), + "attr"); ASSERT_NE(xmlAttr, nullptr); AAPT_ASSERT_TRUE(xmlAttr->compiledAttribute); AAPT_ASSERT_TRUE(xmlAttr->compiledAttribute.value().id); |