summaryrefslogtreecommitdiff
path: root/tools/aapt2/ResourceTable_test.cpp
diff options
context:
space:
mode:
authorAdam Lesinski <adamlesinski@google.com>2017-12-12 16:48:07 -0800
committerAdam Lesinski <adamlesinski@google.com>2017-12-18 14:16:02 -0800
commit71be70507de9cb619b644e55eda1cc181e3f7e90 (patch)
tree1ad3c588be3dd06b39b1ba5c3229f80ca08d62bd /tools/aapt2/ResourceTable_test.cpp
parent6bb6fad16d93a5859d47dcf962337c2719e585dd (diff)
AAPT2: Propagate SPEC_OVERLAYABLE flag to final APK
Resources can be marked as overlayable, which means they can be overlaid by runtime resource overlays. This change propagates this state to the final resource table that is installed on device. Future work: - Have the idmap tool respect the overlayable state and ignore entries that overlay anything else. Bug: 64980941 Test: make aapt2_tests Change-Id: Id45b1e141a281be2ee32a4ac3096fcf1114d523b
Diffstat (limited to 'tools/aapt2/ResourceTable_test.cpp')
-rw-r--r--tools/aapt2/ResourceTable_test.cpp105
1 files changed, 104 insertions, 1 deletions
diff --git a/tools/aapt2/ResourceTable_test.cpp b/tools/aapt2/ResourceTable_test.cpp
index 2a3c131f7b4b..eb75f947e0be 100644
--- a/tools/aapt2/ResourceTable_test.cpp
+++ b/tools/aapt2/ResourceTable_test.cpp
@@ -24,7 +24,10 @@
#include <ostream>
#include <string>
+using ::android::StringPiece;
+using ::testing::Eq;
using ::testing::NotNull;
+using ::testing::StrEq;
namespace aapt {
@@ -45,7 +48,7 @@ TEST(ResourceTableTest, FailToAddResourceWithBadName) {
TEST(ResourceTableTest, AddResourceWithWeirdNameWhenAddingMangledResources) {
ResourceTable table;
- EXPECT_TRUE(table.AddResourceAllowMangled(
+ EXPECT_TRUE(table.AddResourceMangled(
test::ParseNameOrDie("android:id/heythere "), ConfigDescription{}, "",
test::ValueBuilder<Id>().SetSource("test.xml", 21u).Build(), test::GetDiagnostics()));
}
@@ -141,4 +144,104 @@ TEST(ResourceTableTest, ProductVaryingValues) {
EXPECT_EQ(std::string("tablet"), values[1]->product);
}
+static StringPiece LevelToString(Visibility::Level level) {
+ switch (level) {
+ case Visibility::Level::kPrivate:
+ return "private";
+ case Visibility::Level::kPublic:
+ return "private";
+ default:
+ return "undefined";
+ }
+}
+
+static ::testing::AssertionResult VisibilityOfResource(const ResourceTable& table,
+ const ResourceNameRef& name,
+ Visibility::Level level,
+ const StringPiece& comment) {
+ Maybe<ResourceTable::SearchResult> result = table.FindResource(name);
+ if (!result) {
+ return ::testing::AssertionFailure() << "no resource '" << name << "' found in table";
+ }
+
+ const Visibility& visibility = result.value().entry->visibility;
+ if (visibility.level != level) {
+ return ::testing::AssertionFailure() << "expected visibility " << LevelToString(level)
+ << " but got " << LevelToString(visibility.level);
+ }
+
+ if (visibility.comment != comment) {
+ return ::testing::AssertionFailure() << "expected visibility comment '" << comment
+ << "' but got '" << visibility.comment << "'";
+ }
+ return ::testing::AssertionSuccess();
+}
+
+TEST(ResourceTableTest, SetVisibility) {
+ using Level = Visibility::Level;
+
+ ResourceTable table;
+ const ResourceName name = test::ParseNameOrDie("android:string/foo");
+
+ Visibility visibility;
+ visibility.level = Visibility::Level::kPrivate;
+ visibility.comment = "private";
+ ASSERT_TRUE(table.SetVisibility(name, visibility, test::GetDiagnostics()));
+ ASSERT_TRUE(VisibilityOfResource(table, name, Level::kPrivate, "private"));
+
+ visibility.level = Visibility::Level::kUndefined;
+ visibility.comment = "undefined";
+ ASSERT_TRUE(table.SetVisibility(name, visibility, test::GetDiagnostics()));
+ ASSERT_TRUE(VisibilityOfResource(table, name, Level::kPrivate, "private"));
+
+ visibility.level = Visibility::Level::kPublic;
+ visibility.comment = "public";
+ ASSERT_TRUE(table.SetVisibility(name, visibility, test::GetDiagnostics()));
+ ASSERT_TRUE(VisibilityOfResource(table, name, Level::kPublic, "public"));
+
+ visibility.level = Visibility::Level::kPrivate;
+ visibility.comment = "private";
+ ASSERT_TRUE(table.SetVisibility(name, visibility, test::GetDiagnostics()));
+ ASSERT_TRUE(VisibilityOfResource(table, name, Level::kPublic, "public"));
+}
+
+TEST(ResourceTableTest, SetAllowNew) {
+ ResourceTable table;
+ const ResourceName name = test::ParseNameOrDie("android:string/foo");
+
+ AllowNew allow_new;
+ Maybe<ResourceTable::SearchResult> result;
+
+ allow_new.comment = "first";
+ ASSERT_TRUE(table.SetAllowNew(name, allow_new, test::GetDiagnostics()));
+ result = table.FindResource(name);
+ ASSERT_TRUE(result);
+ ASSERT_TRUE(result.value().entry->allow_new);
+ ASSERT_THAT(result.value().entry->allow_new.value().comment, StrEq("first"));
+
+ allow_new.comment = "second";
+ ASSERT_TRUE(table.SetAllowNew(name, allow_new, test::GetDiagnostics()));
+ result = table.FindResource(name);
+ ASSERT_TRUE(result);
+ ASSERT_TRUE(result.value().entry->allow_new);
+ ASSERT_THAT(result.value().entry->allow_new.value().comment, StrEq("second"));
+}
+
+TEST(ResourceTableTest, SetOverlayable) {
+ ResourceTable table;
+ const ResourceName name = test::ParseNameOrDie("android:string/foo");
+
+ Overlayable overlayable;
+
+ overlayable.comment = "first";
+ ASSERT_TRUE(table.SetOverlayable(name, overlayable, test::GetDiagnostics()));
+ Maybe<ResourceTable::SearchResult> result = table.FindResource(name);
+ ASSERT_TRUE(result);
+ ASSERT_TRUE(result.value().entry->overlayable);
+ ASSERT_THAT(result.value().entry->overlayable.value().comment, StrEq("first"));
+
+ overlayable.comment = "second";
+ ASSERT_FALSE(table.SetOverlayable(name, overlayable, test::GetDiagnostics()));
+}
+
} // namespace aapt