blob: 2d013e4764aa9f2fec9d27594a8e0bb54942233e [file] [log] [blame]
Adam Lesinski355f2852016-02-13 20:26:45 -08001/*
2 * Copyright (C) 2016 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include "split/TableSplitter.h"
Adam Lesinskifb6312f2016-06-28 14:40:32 -070018#include "test/Test.h"
Adam Lesinski355f2852016-02-13 20:26:45 -080019
20namespace aapt {
21
22TEST(TableSplitterTest, NoSplitPreferredDensity) {
23 std::unique_ptr<ResourceTable> table = test::ResourceTableBuilder()
24 .addFileReference(u"@android:drawable/icon", u"res/drawable-mdpi/icon.png",
25 test::parseConfigOrDie("mdpi"))
26 .addFileReference(u"@android:drawable/icon", u"res/drawable-hdpi/icon.png",
27 test::parseConfigOrDie("hdpi"))
28 .addFileReference(u"@android:drawable/icon", u"res/drawable-xhdpi/icon.png",
29 test::parseConfigOrDie("xhdpi"))
30 .addFileReference(u"@android:drawable/icon", u"res/drawable-xxhdpi/icon.png",
31 test::parseConfigOrDie("xxhdpi"))
Adam Lesinskifb6312f2016-06-28 14:40:32 -070032 .addSimple(u"@android:string/one")
Adam Lesinski355f2852016-02-13 20:26:45 -080033 .build();
34
35 TableSplitterOptions options;
36 options.preferredDensity = ConfigDescription::DENSITY_XHIGH;
37 TableSplitter splitter({}, options);
38 splitter.splitTable(table.get());
39
40 EXPECT_EQ(nullptr, test::getValueForConfig<FileReference>(table.get(),
41 u"@android:drawable/icon",
42 test::parseConfigOrDie("mdpi")));
43 EXPECT_EQ(nullptr, test::getValueForConfig<FileReference>(table.get(),
44 u"@android:drawable/icon",
45 test::parseConfigOrDie("hdpi")));
46 EXPECT_NE(nullptr, test::getValueForConfig<FileReference>(table.get(),
47 u"@android:drawable/icon",
48 test::parseConfigOrDie("xhdpi")));
49 EXPECT_EQ(nullptr, test::getValueForConfig<FileReference>(table.get(),
50 u"@android:drawable/icon",
51 test::parseConfigOrDie("xxhdpi")));
52 EXPECT_NE(nullptr, test::getValue<Id>(table.get(), u"@android:string/one"));
53}
54
55TEST(TableSplitterTest, SplitTableByConfigAndDensity) {
56 ResourceTable table;
57
58 const ResourceName foo = test::parseNameOrDie(u"@android:string/foo");
59 ASSERT_TRUE(table.addResource(foo, test::parseConfigOrDie("land-hdpi"), {},
60 util::make_unique<Id>(),
61 test::getDiagnostics()));
62 ASSERT_TRUE(table.addResource(foo, test::parseConfigOrDie("land-xhdpi"), {},
63 util::make_unique<Id>(),
64 test::getDiagnostics()));
65 ASSERT_TRUE(table.addResource(foo, test::parseConfigOrDie("land-xxhdpi"), {},
66 util::make_unique<Id>(),
67 test::getDiagnostics()));
68
69 std::vector<SplitConstraints> constraints;
70 constraints.push_back(SplitConstraints{ { test::parseConfigOrDie("land-mdpi") } });
71 constraints.push_back(SplitConstraints{ { test::parseConfigOrDie("land-xhdpi") } });
72
73 TableSplitter splitter(constraints, TableSplitterOptions{});
74 splitter.splitTable(&table);
75
76 ASSERT_EQ(2u, splitter.getSplits().size());
77
78 ResourceTable* splitOne = splitter.getSplits()[0].get();
79 ResourceTable* splitTwo = splitter.getSplits()[1].get();
80
81 // Since a split was defined, all densities should be gone from base.
82 EXPECT_EQ(nullptr, test::getValueForConfig<Id>(&table, u"@android:string/foo",
83 test::parseConfigOrDie("land-hdpi")));
84 EXPECT_EQ(nullptr, test::getValueForConfig<Id>(&table, u"@android:string/foo",
85 test::parseConfigOrDie("land-xhdpi")));
86 EXPECT_EQ(nullptr, test::getValueForConfig<Id>(&table, u"@android:string/foo",
87 test::parseConfigOrDie("land-xxhdpi")));
88
89 EXPECT_NE(nullptr, test::getValueForConfig<Id>(splitOne, u"@android:string/foo",
90 test::parseConfigOrDie("land-hdpi")));
91 EXPECT_EQ(nullptr, test::getValueForConfig<Id>(splitOne, u"@android:string/foo",
92 test::parseConfigOrDie("land-xhdpi")));
93 EXPECT_EQ(nullptr, test::getValueForConfig<Id>(splitOne, u"@android:string/foo",
94 test::parseConfigOrDie("land-xxhdpi")));
95
96 EXPECT_EQ(nullptr, test::getValueForConfig<Id>(splitTwo, u"@android:string/foo",
97 test::parseConfigOrDie("land-hdpi")));
98 EXPECT_NE(nullptr, test::getValueForConfig<Id>(splitTwo, u"@android:string/foo",
99 test::parseConfigOrDie("land-xhdpi")));
100 EXPECT_EQ(nullptr, test::getValueForConfig<Id>(splitTwo, u"@android:string/foo",
101 test::parseConfigOrDie("land-xxhdpi")));
102}
103
104} // namespace aapt