diff options
author | Adam Lesinski <adamlesinski@google.com> | 2017-09-29 11:15:17 -0700 |
---|---|---|
committer | Adam Lesinski <adamlesinski@google.com> | 2017-09-29 11:20:45 -0700 |
commit | 761d4341fcbb711f55d73a31e79098837146236d (patch) | |
tree | d00cbad62516f69fb2802fd2a79f747b7e5b9292 /tools/aapt2/java/JavaClassGenerator_test.cpp | |
parent | 43ddc05bbdbf8da73da2415b3ab4d68a0180f9b2 (diff) |
AAPT2: Fix R.java styleable + indices ordering
Make sure that Styleables are directly followed by their indices.
If not, Robolectric breaks. This is not strictly incorrect to have
an arbitrary ordering in R.java, but its easier to just support
Robolectric in this case.
Bug: 65837293
Test: make aapt2_tests
(cherry picked from commit af85c4deb667843a227d62275fe6992005f4c38d)
Change-Id: Ia59ba58427ade386d075ca9fc9eb5b53e35beca0
Diffstat (limited to 'tools/aapt2/java/JavaClassGenerator_test.cpp')
-rw-r--r-- | tools/aapt2/java/JavaClassGenerator_test.cpp | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/tools/aapt2/java/JavaClassGenerator_test.cpp b/tools/aapt2/java/JavaClassGenerator_test.cpp index 4f449f0db41a..668e4340e839 100644 --- a/tools/aapt2/java/JavaClassGenerator_test.cpp +++ b/tools/aapt2/java/JavaClassGenerator_test.cpp @@ -24,6 +24,8 @@ using ::android::StringPiece; using ::testing::HasSubstr; +using ::testing::Lt; +using ::testing::Ne; using ::testing::Not; namespace aapt { @@ -306,6 +308,53 @@ TEST(JavaClassGeneratorTest, CommentsForStyleablesAndNestedAttributesArePresent) EXPECT_THAT(output, HasSubstr(styleable.GetComment())); } +TEST(JavaClassGeneratorTest, StyleableAndIndicesAreColocated) { + std::unique_ptr<ResourceTable> table = + test::ResourceTableBuilder() + .SetPackageId("android", 0x01) + .AddValue("android:attr/layout_gravity", util::make_unique<Attribute>()) + .AddValue("android:attr/background", util::make_unique<Attribute>()) + .AddValue("android:styleable/ActionBar", + test::StyleableBuilder() + .AddItem("android:attr/background", ResourceId(0x01010000)) + .Build()) + .AddValue("android:styleable/ActionBar.LayoutParams", + test::StyleableBuilder() + .AddItem("android:attr/layout_gravity", ResourceId(0x01010001)) + .Build()) + .Build(); + + std::unique_ptr<IAaptContext> context = + test::ContextBuilder() + .AddSymbolSource(util::make_unique<ResourceTableSymbolSource>(table.get())) + .SetNameManglerPolicy(NameManglerPolicy{"android"}) + .Build(); + + JavaClassGeneratorOptions options; + JavaClassGenerator generator(context.get(), table.get(), {}); + std::stringstream out; + ASSERT_TRUE(generator.Generate("android", &out)); + std::string output = out.str(); + + std::string::size_type actionbar_pos = output.find("int[] ActionBar"); + ASSERT_THAT(actionbar_pos, Ne(std::string::npos)); + + std::string::size_type actionbar_background_pos = output.find("int ActionBar_background"); + ASSERT_THAT(actionbar_background_pos, Ne(std::string::npos)); + + std::string::size_type actionbar_layout_params_pos = output.find("int[] ActionBar_LayoutParams"); + ASSERT_THAT(actionbar_layout_params_pos, Ne(std::string::npos)); + + std::string::size_type actionbar_layout_params_layout_gravity_pos = + output.find("int ActionBar_LayoutParams_layout_gravity"); + ASSERT_THAT(actionbar_layout_params_layout_gravity_pos, Ne(std::string::npos)); + + EXPECT_THAT(actionbar_pos, Lt(actionbar_background_pos)); + EXPECT_THAT(actionbar_pos, Lt(actionbar_layout_params_pos)); + EXPECT_THAT(actionbar_background_pos, Lt(actionbar_layout_params_pos)); + EXPECT_THAT(actionbar_layout_params_pos, Lt(actionbar_layout_params_layout_gravity_pos)); +} + TEST(JavaClassGeneratorTest, CommentsForRemovedAttributesAreNotPresentInClass) { Attribute attr(false); attr.SetComment(StringPiece("removed")); |