summaryrefslogtreecommitdiff
path: root/tools/aapt2/ResourceParser_test.cpp
diff options
context:
space:
mode:
authory <rtmitchell@google.com>2018-04-18 11:29:09 -0700
committery <rtmitchell@google.com>2018-04-18 11:46:53 -0700
commit9efbbef2e060cd5e05f5b652ba5c7aaf687f64d6 (patch)
treea906595eedebc28b14a4e86e135b225eb1d5d79b /tools/aapt2/ResourceParser_test.cpp
parent34a0b18a5c730e4fa16e27c63ed0cd79a6df188e (diff)
AAPT2: Support id reference chaining from AAPT
AAPT would allow for ids to be declared in the form: <item name="name" type="id>@id/other</item> @id/name should hold a reference to @id/other. When getResources().getValue() is called on R.id.name with resolveRefs enabled, the resuling reference should be R.id.other. Bug: 69445910 Test: Created tests for correct parsing of id references and correct resolving of deep references Change-Id: Id1feb37b2565c213dc6a19b4c401906260d7fc14
Diffstat (limited to 'tools/aapt2/ResourceParser_test.cpp')
-rw-r--r--tools/aapt2/ResourceParser_test.cpp28
1 files changed, 28 insertions, 0 deletions
diff --git a/tools/aapt2/ResourceParser_test.cpp b/tools/aapt2/ResourceParser_test.cpp
index fc1aeaa58fe2..c12b9fac5704 100644
--- a/tools/aapt2/ResourceParser_test.cpp
+++ b/tools/aapt2/ResourceParser_test.cpp
@@ -933,4 +933,32 @@ TEST_F(ResourceParserTest, DuplicateOverlayableIsError) {
EXPECT_FALSE(TestParse(input));
}
+TEST_F(ResourceParserTest, ParseIdItem) {
+ std::string input = R"(
+ <item name="foo" type="id">@id/bar</item>
+ <item name="bar" type="id"/>
+ <item name="baz" type="id"></item>)";
+ ASSERT_TRUE(TestParse(input));
+
+ ASSERT_THAT(test::GetValue<Reference>(&table_, "id/foo"), NotNull());
+ ASSERT_THAT(test::GetValue<Id>(&table_, "id/bar"), NotNull());
+ ASSERT_THAT(test::GetValue<Id>(&table_, "id/baz"), NotNull());
+
+ // Reject attribute references
+ input = R"(<item name="foo2" type="id">?attr/bar"</item>)";
+ ASSERT_FALSE(TestParse(input));
+
+ // Reject non-references
+ input = R"(<item name="foo3" type="id">0x7f010001</item>)";
+ ASSERT_FALSE(TestParse(input));
+ input = R"(<item name="foo4" type="id">@drawable/my_image</item>)";
+ ASSERT_FALSE(TestParse(input));
+ input = R"(<item name="foo5" type="id"><string name="biz"></string></item>)";
+ ASSERT_FALSE(TestParse(input));
+
+ // Ids that reference other resource ids cannot be public
+ input = R"(<public name="foo6" type="id">@id/bar6</item>)";
+ ASSERT_FALSE(TestParse(input));
+}
+
} // namespace aapt