summaryrefslogtreecommitdiff
path: root/tools/aapt2/split/TableSplitter_test.cpp
diff options
context:
space:
mode:
authorAdam Lesinski <adamlesinski@google.com>2016-08-11 13:39:24 -0700
committerAdam Lesinski <adamlesinski@google.com>2016-08-15 12:14:26 -0700
commit36c73a595910e96f3552f938eeb81d46356067a1 (patch)
tree69632325f13ba59c48c9951b35abc3ef6e7ceda3 /tools/aapt2/split/TableSplitter_test.cpp
parent534376f3e9e302946d6f5aae883748107d466c50 (diff)
AAPT2: Expose split support to command line
Bug:30445078 Change-Id: If4b8530dba71b9059b8e62c04757da99c1119d22
Diffstat (limited to 'tools/aapt2/split/TableSplitter_test.cpp')
-rw-r--r--tools/aapt2/split/TableSplitter_test.cpp69
1 files changed, 67 insertions, 2 deletions
diff --git a/tools/aapt2/split/TableSplitter_test.cpp b/tools/aapt2/split/TableSplitter_test.cpp
index bad02a5cb332..5150e82b6d93 100644
--- a/tools/aapt2/split/TableSplitter_test.cpp
+++ b/tools/aapt2/split/TableSplitter_test.cpp
@@ -52,6 +52,71 @@ TEST(TableSplitterTest, NoSplitPreferredDensity) {
EXPECT_NE(nullptr, test::getValue<Id>(table.get(), "android:string/one"));
}
+TEST(TableSplitterTest, SplitTableByDensity) {
+ std::unique_ptr<ResourceTable> table = test::ResourceTableBuilder()
+ .addFileReference("android:drawable/foo", "res/drawable-mdpi/foo.png",
+ test::parseConfigOrDie("mdpi"))
+ .addFileReference("android:drawable/foo", "res/drawable-hdpi/foo.png",
+ test::parseConfigOrDie("hdpi"))
+ .addFileReference("android:drawable/foo", "res/drawable-xhdpi/foo.png",
+ test::parseConfigOrDie("xhdpi"))
+ .addFileReference("android:drawable/foo", "res/drawable-xxhdpi/foo.png",
+ test::parseConfigOrDie("xxhdpi"))
+ .build();
+
+ std::vector<SplitConstraints> constraints;
+ constraints.push_back(SplitConstraints{ { test::parseConfigOrDie("mdpi") } });
+ constraints.push_back(SplitConstraints{ { test::parseConfigOrDie("hdpi") } });
+ constraints.push_back(SplitConstraints{ { test::parseConfigOrDie("xhdpi") } });
+
+ TableSplitter splitter(constraints, TableSplitterOptions{});
+ splitter.splitTable(table.get());
+
+ ASSERT_EQ(3u, splitter.getSplits().size());
+
+ ResourceTable* splitOne = splitter.getSplits()[0].get();
+ ResourceTable* splitTwo = splitter.getSplits()[1].get();
+ ResourceTable* splitThree = splitter.getSplits()[2].get();
+
+ // Just xxhdpi should be in the base.
+ EXPECT_EQ(nullptr, test::getValueForConfig<FileReference>(table.get(), "android:drawable/foo",
+ test::parseConfigOrDie("mdpi")));
+ EXPECT_EQ(nullptr, test::getValueForConfig<FileReference>(table.get(), "android:drawable/foo",
+ test::parseConfigOrDie("hdpi")));
+ EXPECT_EQ(nullptr, test::getValueForConfig<FileReference>(table.get(), "android:drawable/foo",
+ test::parseConfigOrDie("xhdpi")));
+ EXPECT_NE(nullptr, test::getValueForConfig<FileReference>(table.get(), "android:drawable/foo",
+ test::parseConfigOrDie("xxhdpi")));
+
+ // Each split should have one and only one drawable.
+ EXPECT_NE(nullptr, test::getValueForConfig<FileReference>(splitOne, "android:drawable/foo",
+ test::parseConfigOrDie("mdpi")));
+ EXPECT_EQ(nullptr, test::getValueForConfig<FileReference>(splitOne, "android:drawable/foo",
+ test::parseConfigOrDie("hdpi")));
+ EXPECT_EQ(nullptr, test::getValueForConfig<FileReference>(splitOne, "android:drawable/foo",
+ test::parseConfigOrDie("xhdpi")));
+ EXPECT_EQ(nullptr, test::getValueForConfig<FileReference>(splitOne, "android:drawable/foo",
+ test::parseConfigOrDie("xxhdpi")));
+
+ EXPECT_EQ(nullptr, test::getValueForConfig<FileReference>(splitTwo, "android:drawable/foo",
+ test::parseConfigOrDie("mdpi")));
+ EXPECT_NE(nullptr, test::getValueForConfig<FileReference>(splitTwo, "android:drawable/foo",
+ test::parseConfigOrDie("hdpi")));
+ EXPECT_EQ(nullptr, test::getValueForConfig<FileReference>(splitTwo, "android:drawable/foo",
+ test::parseConfigOrDie("xhdpi")));
+ EXPECT_EQ(nullptr, test::getValueForConfig<FileReference>(splitTwo, "android:drawable/foo",
+ test::parseConfigOrDie("xxhdpi")));
+
+ EXPECT_EQ(nullptr, test::getValueForConfig<FileReference>(splitThree, "android:drawable/foo",
+ test::parseConfigOrDie("mdpi")));
+ EXPECT_EQ(nullptr, test::getValueForConfig<FileReference>(splitThree, "android:drawable/foo",
+ test::parseConfigOrDie("hdpi")));
+ EXPECT_NE(nullptr, test::getValueForConfig<FileReference>(splitThree, "android:drawable/foo",
+ test::parseConfigOrDie("xhdpi")));
+ EXPECT_EQ(nullptr, test::getValueForConfig<FileReference>(splitThree, "android:drawable/foo",
+ test::parseConfigOrDie("xxhdpi")));
+}
+
TEST(TableSplitterTest, SplitTableByConfigAndDensity) {
ResourceTable table;
@@ -78,12 +143,12 @@ TEST(TableSplitterTest, SplitTableByConfigAndDensity) {
ResourceTable* splitOne = splitter.getSplits()[0].get();
ResourceTable* splitTwo = splitter.getSplits()[1].get();
- // Since a split was defined, all densities should be gone from base.
+ // All but the xxhdpi resource should be gone, since there were closer matches in land-xhdpi.
EXPECT_EQ(nullptr, test::getValueForConfig<Id>(&table, "android:string/foo",
test::parseConfigOrDie("land-hdpi")));
EXPECT_EQ(nullptr, test::getValueForConfig<Id>(&table, "android:string/foo",
test::parseConfigOrDie("land-xhdpi")));
- EXPECT_EQ(nullptr, test::getValueForConfig<Id>(&table, "android:string/foo",
+ EXPECT_NE(nullptr, test::getValueForConfig<Id>(&table, "android:string/foo",
test::parseConfigOrDie("land-xxhdpi")));
EXPECT_NE(nullptr, test::getValueForConfig<Id>(splitOne, "android:string/foo",