diff options
author | Adam Lesinski <adamlesinski@google.com> | 2017-12-08 16:06:10 -0800 |
---|---|---|
committer | Adam Lesinski <adamlesinski@google.com> | 2018-01-11 13:54:11 -0800 |
commit | 73bff1e8519bb73f17a801f45977d41b69b5b0d0 (patch) | |
tree | 9ac5f4e491ed617b6cefe118b91edb637c6c35a4 /tools/aapt2/ResourceTable_test.cpp | |
parent | 14c2ae4a6e62b78f2c994112d08dbe3d4de64695 (diff) |
AAPT2: Allow compatible duplicate Attributes
If a resource XML file defines two compatible Attributes, they should
be merged without throwing an error. Ex:
<declare-styleable>
<attr name="conflict" format="string" />
</declare-styleable>
<declare-styleable>
<attr name="conflict" format="string|reference" />
</declare-styleable>
In this case, string|reference and string are the same, so these should
merge correctly.
Bug: 65699599
Test: make aapt2_tests
Test: make AaptBasicTest
Change-Id: I7b0f956d2332f7f0b458acd59ca0a606b2cfdf95
Diffstat (limited to 'tools/aapt2/ResourceTable_test.cpp')
-rw-r--r-- | tools/aapt2/ResourceTable_test.cpp | 26 |
1 files changed, 20 insertions, 6 deletions
diff --git a/tools/aapt2/ResourceTable_test.cpp b/tools/aapt2/ResourceTable_test.cpp index eb75f947e0be..7fa8ea2f7f94 100644 --- a/tools/aapt2/ResourceTable_test.cpp +++ b/tools/aapt2/ResourceTable_test.cpp @@ -102,23 +102,37 @@ TEST(ResourceTableTest, AddMultipleResources) { TEST(ResourceTableTest, OverrideWeakResourceValue) { ResourceTable table; - ASSERT_TRUE(table.AddResource( - test::ParseNameOrDie("android:attr/foo"), ConfigDescription{}, "", - util::make_unique<Attribute>(true), test::GetDiagnostics())); + ASSERT_TRUE(table.AddResource(test::ParseNameOrDie("android:attr/foo"), ConfigDescription{}, "", + test::AttributeBuilder().SetWeak(true).Build(), + test::GetDiagnostics())); Attribute* attr = test::GetValue<Attribute>(&table, "android:attr/foo"); ASSERT_THAT(attr, NotNull()); EXPECT_TRUE(attr->IsWeak()); - ASSERT_TRUE(table.AddResource( - test::ParseNameOrDie("android:attr/foo"), ConfigDescription{}, "", - util::make_unique<Attribute>(false), test::GetDiagnostics())); + ASSERT_TRUE(table.AddResource(test::ParseNameOrDie("android:attr/foo"), ConfigDescription{}, "", + util::make_unique<Attribute>(), test::GetDiagnostics())); attr = test::GetValue<Attribute>(&table, "android:attr/foo"); ASSERT_THAT(attr, NotNull()); EXPECT_FALSE(attr->IsWeak()); } +TEST(ResourceTableTest, AllowCompatibleDuplicateAttributes) { + ResourceTable table; + + const ResourceName name = test::ParseNameOrDie("android:attr/foo"); + Attribute attr_one(android::ResTable_map::TYPE_STRING); + attr_one.SetWeak(true); + Attribute attr_two(android::ResTable_map::TYPE_STRING | android::ResTable_map::TYPE_REFERENCE); + attr_two.SetWeak(true); + + ASSERT_TRUE(table.AddResource(name, ConfigDescription{}, "", + util::make_unique<Attribute>(attr_one), test::GetDiagnostics())); + ASSERT_TRUE(table.AddResource(name, ConfigDescription{}, "", + util::make_unique<Attribute>(attr_two), test::GetDiagnostics())); +} + TEST(ResourceTableTest, ProductVaryingValues) { ResourceTable table; |