AAPT2: Add support for clearer in-progress public attributes
Before, the ID assigned to a public resource without an explicitly set id
was more difficult to figure out. It would be the next available ID.
AAPT2 introduces a new way to specify public attributes in progress.
<public-group type="attr" first-id="0x0101047f">
<public name="foo" />
<public name="bar" />
...
</public-group>
The IDs assigned to each resource is auto-incremented starting from `first-id`.
This also keeps resource's with the same type grouped together so that
the auto-incrementing nature is evident.
Also, due to how AAPT2 was implemented, this is required :P
Change-Id: I95ea92ad0405e87ed0b1766879bb2f1d9d0b636e
diff --git a/tools/aapt2/ResourceParser_test.cpp b/tools/aapt2/ResourceParser_test.cpp
index ab7b172..b3ad031 100644
--- a/tools/aapt2/ResourceParser_test.cpp
+++ b/tools/aapt2/ResourceParser_test.cpp
@@ -489,4 +489,36 @@
ASSERT_FALSE(testParse(input, std::u16string(u"phone")));
}
+TEST_F(ResourceParserTest, AutoIncrementIdsInPublicGroup) {
+ std::string input = R"EOF(
+ <public-group type="attr" first-id="0x01010040">
+ <public name="foo" />
+ <public name="bar" />
+ </public-group>)EOF";
+ ASSERT_TRUE(testParse(input));
+
+ Maybe<ResourceTable::SearchResult> result = mTable.findResource(
+ test::parseNameOrDie(u"@attr/foo"));
+ AAPT_ASSERT_TRUE(result);
+
+ AAPT_ASSERT_TRUE(result.value().package->id);
+ AAPT_ASSERT_TRUE(result.value().type->id);
+ AAPT_ASSERT_TRUE(result.value().entry->id);
+ ResourceId actualId(result.value().package->id.value(),
+ result.value().type->id.value(),
+ result.value().entry->id.value());
+ EXPECT_EQ(ResourceId(0x01010040), actualId);
+
+ result = mTable.findResource(test::parseNameOrDie(u"@attr/bar"));
+ AAPT_ASSERT_TRUE(result);
+
+ AAPT_ASSERT_TRUE(result.value().package->id);
+ AAPT_ASSERT_TRUE(result.value().type->id);
+ AAPT_ASSERT_TRUE(result.value().entry->id);
+ actualId = ResourceId(result.value().package->id.value(),
+ result.value().type->id.value(),
+ result.value().entry->id.value());
+ EXPECT_EQ(ResourceId(0x01010041), actualId);
+}
+
} // namespace aapt