Reorder styleable attributes in shared libraries

This is a similar fix to
https://googleplex-android-review.git.corp.google.com/c/platform/frameworks/base/+/10109386
but deals with styleable attributes instead of style items.

Bug: 147674078
Test: JavaClassGeneratorTest.SortsDynamicAttributesAfterFrameworkAttributes
Change-Id: Ida6572cf07e2b5987e9d8941cf169a37c43578c4
This commit is contained in:
Clark DuVall
2020-04-22 13:19:28 -07:00
parent 61115d7d8f
commit 8f51d6b876
4 changed files with 51 additions and 18 deletions

View File

@@ -551,4 +551,39 @@ TEST(JavaClassGeneratorTest, OnlyGenerateRText) {
ASSERT_TRUE(generator.Generate("android", nullptr));
}
TEST(JavaClassGeneratorTest, SortsDynamicAttributesAfterFrameworkAttributes) {
std::unique_ptr<ResourceTable> table =
test::ResourceTableBuilder()
.SetPackageId("android", 0x01)
.SetPackageId("lib", 0x00)
.AddValue("android:attr/framework_attr", ResourceId(0x01010000),
test::AttributeBuilder().Build())
.AddValue("lib:attr/dynamic_attr", ResourceId(0x00010000),
test::AttributeBuilder().Build())
.AddValue("lib:styleable/MyStyleable", ResourceId(0x00030000),
test::StyleableBuilder()
.AddItem("android:attr/framework_attr", ResourceId(0x01010000))
.AddItem("lib:attr/dynamic_attr", ResourceId(0x00010000))
.Build())
.Build();
std::unique_ptr<IAaptContext> context =
test::ContextBuilder()
.AddSymbolSource(util::make_unique<ResourceTableSymbolSource>(table.get()))
.SetNameManglerPolicy(NameManglerPolicy{"custom"})
.SetCompilationPackage("custom")
.Build();
JavaClassGenerator generator(context.get(), table.get(), {});
std::string output;
StringOutputStream out(&output);
EXPECT_TRUE(generator.Generate("lib", &out));
out.Flush();
EXPECT_THAT(output, HasSubstr("public static final int[] MyStyleable={"));
EXPECT_THAT(output, HasSubstr("0x01010000, 0x00010000"));
EXPECT_THAT(output, HasSubstr("public static final int MyStyleable_android_framework_attr=0;"));
EXPECT_THAT(output, HasSubstr("public static final int MyStyleable_dynamic_attr=1;"));
}
} // namespace aapt