summaryrefslogtreecommitdiff
path: root/tools/aapt2/split/TableSplitter_test.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tools/aapt2/split/TableSplitter_test.cpp')
-rw-r--r--tools/aapt2/split/TableSplitter_test.cpp112
1 files changed, 87 insertions, 25 deletions
diff --git a/tools/aapt2/split/TableSplitter_test.cpp b/tools/aapt2/split/TableSplitter_test.cpp
index 74ca32e04a30..5150e82b6d93 100644
--- a/tools/aapt2/split/TableSplitter_test.cpp
+++ b/tools/aapt2/split/TableSplitter_test.cpp
@@ -15,24 +15,21 @@
*/
#include "split/TableSplitter.h"
-#include "test/Builders.h"
-#include "test/Common.h"
-
-#include <gtest/gtest.h>
+#include "test/Test.h"
namespace aapt {
TEST(TableSplitterTest, NoSplitPreferredDensity) {
std::unique_ptr<ResourceTable> table = test::ResourceTableBuilder()
- .addFileReference(u"@android:drawable/icon", u"res/drawable-mdpi/icon.png",
+ .addFileReference("android:drawable/icon", "res/drawable-mdpi/icon.png",
test::parseConfigOrDie("mdpi"))
- .addFileReference(u"@android:drawable/icon", u"res/drawable-hdpi/icon.png",
+ .addFileReference("android:drawable/icon", "res/drawable-hdpi/icon.png",
test::parseConfigOrDie("hdpi"))
- .addFileReference(u"@android:drawable/icon", u"res/drawable-xhdpi/icon.png",
+ .addFileReference("android:drawable/icon", "res/drawable-xhdpi/icon.png",
test::parseConfigOrDie("xhdpi"))
- .addFileReference(u"@android:drawable/icon", u"res/drawable-xxhdpi/icon.png",
+ .addFileReference("android:drawable/icon", "res/drawable-xxhdpi/icon.png",
test::parseConfigOrDie("xxhdpi"))
- .addSimple(u"@android:string/one", {})
+ .addSimple("android:string/one")
.build();
TableSplitterOptions options;
@@ -41,24 +38,89 @@ TEST(TableSplitterTest, NoSplitPreferredDensity) {
splitter.splitTable(table.get());
EXPECT_EQ(nullptr, test::getValueForConfig<FileReference>(table.get(),
- u"@android:drawable/icon",
+ "android:drawable/icon",
test::parseConfigOrDie("mdpi")));
EXPECT_EQ(nullptr, test::getValueForConfig<FileReference>(table.get(),
- u"@android:drawable/icon",
+ "android:drawable/icon",
test::parseConfigOrDie("hdpi")));
EXPECT_NE(nullptr, test::getValueForConfig<FileReference>(table.get(),
- u"@android:drawable/icon",
+ "android:drawable/icon",
test::parseConfigOrDie("xhdpi")));
EXPECT_EQ(nullptr, test::getValueForConfig<FileReference>(table.get(),
- u"@android:drawable/icon",
+ "android:drawable/icon",
+ test::parseConfigOrDie("xxhdpi")));
+ 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")));
- EXPECT_NE(nullptr, test::getValue<Id>(table.get(), u"@android:string/one"));
}
TEST(TableSplitterTest, SplitTableByConfigAndDensity) {
ResourceTable table;
- const ResourceName foo = test::parseNameOrDie(u"@android:string/foo");
+ const ResourceName foo = test::parseNameOrDie("android:string/foo");
ASSERT_TRUE(table.addResource(foo, test::parseConfigOrDie("land-hdpi"), {},
util::make_unique<Id>(),
test::getDiagnostics()));
@@ -81,26 +143,26 @@ 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.
- EXPECT_EQ(nullptr, test::getValueForConfig<Id>(&table, u"@android:string/foo",
+ // 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, u"@android:string/foo",
+ EXPECT_EQ(nullptr, test::getValueForConfig<Id>(&table, "android:string/foo",
test::parseConfigOrDie("land-xhdpi")));
- EXPECT_EQ(nullptr, test::getValueForConfig<Id>(&table, u"@android:string/foo",
+ EXPECT_NE(nullptr, test::getValueForConfig<Id>(&table, "android:string/foo",
test::parseConfigOrDie("land-xxhdpi")));
- EXPECT_NE(nullptr, test::getValueForConfig<Id>(splitOne, u"@android:string/foo",
+ EXPECT_NE(nullptr, test::getValueForConfig<Id>(splitOne, "android:string/foo",
test::parseConfigOrDie("land-hdpi")));
- EXPECT_EQ(nullptr, test::getValueForConfig<Id>(splitOne, u"@android:string/foo",
+ EXPECT_EQ(nullptr, test::getValueForConfig<Id>(splitOne, "android:string/foo",
test::parseConfigOrDie("land-xhdpi")));
- EXPECT_EQ(nullptr, test::getValueForConfig<Id>(splitOne, u"@android:string/foo",
+ EXPECT_EQ(nullptr, test::getValueForConfig<Id>(splitOne, "android:string/foo",
test::parseConfigOrDie("land-xxhdpi")));
- EXPECT_EQ(nullptr, test::getValueForConfig<Id>(splitTwo, u"@android:string/foo",
+ EXPECT_EQ(nullptr, test::getValueForConfig<Id>(splitTwo, "android:string/foo",
test::parseConfigOrDie("land-hdpi")));
- EXPECT_NE(nullptr, test::getValueForConfig<Id>(splitTwo, u"@android:string/foo",
+ EXPECT_NE(nullptr, test::getValueForConfig<Id>(splitTwo, "android:string/foo",
test::parseConfigOrDie("land-xhdpi")));
- EXPECT_EQ(nullptr, test::getValueForConfig<Id>(splitTwo, u"@android:string/foo",
+ EXPECT_EQ(nullptr, test::getValueForConfig<Id>(splitTwo, "android:string/foo",
test::parseConfigOrDie("land-xxhdpi")));
}