1355f285ffd000f6cfe76680eb22d010546d124bbAdam Lesinski/*
2355f285ffd000f6cfe76680eb22d010546d124bbAdam Lesinski * Copyright (C) 2016 The Android Open Source Project
3355f285ffd000f6cfe76680eb22d010546d124bbAdam Lesinski *
4355f285ffd000f6cfe76680eb22d010546d124bbAdam Lesinski * Licensed under the Apache License, Version 2.0 (the "License");
5355f285ffd000f6cfe76680eb22d010546d124bbAdam Lesinski * you may not use this file except in compliance with the License.
6355f285ffd000f6cfe76680eb22d010546d124bbAdam Lesinski * You may obtain a copy of the License at
7355f285ffd000f6cfe76680eb22d010546d124bbAdam Lesinski *
8355f285ffd000f6cfe76680eb22d010546d124bbAdam Lesinski *      http://www.apache.org/licenses/LICENSE-2.0
9355f285ffd000f6cfe76680eb22d010546d124bbAdam Lesinski *
10355f285ffd000f6cfe76680eb22d010546d124bbAdam Lesinski * Unless required by applicable law or agreed to in writing, software
11355f285ffd000f6cfe76680eb22d010546d124bbAdam Lesinski * distributed under the License is distributed on an "AS IS" BASIS,
12355f285ffd000f6cfe76680eb22d010546d124bbAdam Lesinski * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13355f285ffd000f6cfe76680eb22d010546d124bbAdam Lesinski * See the License for the specific language governing permissions and
14355f285ffd000f6cfe76680eb22d010546d124bbAdam Lesinski * limitations under the License.
15355f285ffd000f6cfe76680eb22d010546d124bbAdam Lesinski */
16355f285ffd000f6cfe76680eb22d010546d124bbAdam Lesinski
17355f285ffd000f6cfe76680eb22d010546d124bbAdam Lesinski#include "split/TableSplitter.h"
18ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski
19fb6312fe93a8544e6a95d1c619c8cea3940cbe1aAdam Lesinski#include "test/Test.h"
20355f285ffd000f6cfe76680eb22d010546d124bbAdam Lesinski
21355f285ffd000f6cfe76680eb22d010546d124bbAdam Lesinskinamespace aapt {
22355f285ffd000f6cfe76680eb22d010546d124bbAdam Lesinski
23355f285ffd000f6cfe76680eb22d010546d124bbAdam LesinskiTEST(TableSplitterTest, NoSplitPreferredDensity) {
24ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski  std::unique_ptr<ResourceTable> table =
25ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski      test::ResourceTableBuilder()
26ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski          .AddFileReference("android:drawable/icon",
27ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski                            "res/drawable-mdpi/icon.png",
28ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski                            test::ParseConfigOrDie("mdpi"))
29ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski          .AddFileReference("android:drawable/icon",
30ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski                            "res/drawable-hdpi/icon.png",
31ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski                            test::ParseConfigOrDie("hdpi"))
32ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski          .AddFileReference("android:drawable/icon",
33ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski                            "res/drawable-xhdpi/icon.png",
34ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski                            test::ParseConfigOrDie("xhdpi"))
35ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski          .AddFileReference("android:drawable/icon",
36ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski                            "res/drawable-xxhdpi/icon.png",
37ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski                            test::ParseConfigOrDie("xxhdpi"))
38ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski          .AddSimple("android:string/one")
39ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski          .Build();
40ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski
41ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski  TableSplitterOptions options;
42672384b41e1fc7195424533b7aa6753fb771a6cbPierre Lecesne  options.preferred_densities.push_back(ConfigDescription::DENSITY_XHIGH);
43ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski  TableSplitter splitter({}, options);
44ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski  splitter.SplitTable(table.get());
45ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski
46ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski  EXPECT_EQ(nullptr, test::GetValueForConfig<FileReference>(
47ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski                         table.get(), "android:drawable/icon",
48ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski                         test::ParseConfigOrDie("mdpi")));
49ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski  EXPECT_EQ(nullptr, test::GetValueForConfig<FileReference>(
50ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski                         table.get(), "android:drawable/icon",
51ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski                         test::ParseConfigOrDie("hdpi")));
52ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski  EXPECT_NE(nullptr, test::GetValueForConfig<FileReference>(
53ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski                         table.get(), "android:drawable/icon",
54ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski                         test::ParseConfigOrDie("xhdpi")));
55ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski  EXPECT_EQ(nullptr, test::GetValueForConfig<FileReference>(
56ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski                         table.get(), "android:drawable/icon",
57ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski                         test::ParseConfigOrDie("xxhdpi")));
58ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski  EXPECT_NE(nullptr, test::GetValue<Id>(table.get(), "android:string/one"));
59355f285ffd000f6cfe76680eb22d010546d124bbAdam Lesinski}
60355f285ffd000f6cfe76680eb22d010546d124bbAdam Lesinski
61672384b41e1fc7195424533b7aa6753fb771a6cbPierre LecesneTEST(TableSplitterTest, NoSplitMultiplePreferredDensities) {
62672384b41e1fc7195424533b7aa6753fb771a6cbPierre Lecesne  std::unique_ptr<ResourceTable> table =
63672384b41e1fc7195424533b7aa6753fb771a6cbPierre Lecesne      test::ResourceTableBuilder()
64672384b41e1fc7195424533b7aa6753fb771a6cbPierre Lecesne          .AddFileReference("android:drawable/icon",
65672384b41e1fc7195424533b7aa6753fb771a6cbPierre Lecesne                            "res/drawable-mdpi/icon.png",
66672384b41e1fc7195424533b7aa6753fb771a6cbPierre Lecesne                            test::ParseConfigOrDie("mdpi"))
67672384b41e1fc7195424533b7aa6753fb771a6cbPierre Lecesne          .AddFileReference("android:drawable/icon",
68672384b41e1fc7195424533b7aa6753fb771a6cbPierre Lecesne                            "res/drawable-hdpi/icon.png",
69672384b41e1fc7195424533b7aa6753fb771a6cbPierre Lecesne                            test::ParseConfigOrDie("hdpi"))
70672384b41e1fc7195424533b7aa6753fb771a6cbPierre Lecesne          .AddFileReference("android:drawable/icon",
71672384b41e1fc7195424533b7aa6753fb771a6cbPierre Lecesne                            "res/drawable-xhdpi/icon.png",
72672384b41e1fc7195424533b7aa6753fb771a6cbPierre Lecesne                            test::ParseConfigOrDie("xhdpi"))
73672384b41e1fc7195424533b7aa6753fb771a6cbPierre Lecesne          .AddFileReference("android:drawable/icon",
74672384b41e1fc7195424533b7aa6753fb771a6cbPierre Lecesne                            "res/drawable-xxhdpi/icon.png",
75672384b41e1fc7195424533b7aa6753fb771a6cbPierre Lecesne                            test::ParseConfigOrDie("xxhdpi"))
76672384b41e1fc7195424533b7aa6753fb771a6cbPierre Lecesne          .AddSimple("android:string/one")
77672384b41e1fc7195424533b7aa6753fb771a6cbPierre Lecesne          .Build();
78672384b41e1fc7195424533b7aa6753fb771a6cbPierre Lecesne
79672384b41e1fc7195424533b7aa6753fb771a6cbPierre Lecesne  TableSplitterOptions options;
80672384b41e1fc7195424533b7aa6753fb771a6cbPierre Lecesne  options.preferred_densities.push_back(ConfigDescription::DENSITY_LOW);
81672384b41e1fc7195424533b7aa6753fb771a6cbPierre Lecesne  options.preferred_densities.push_back(ConfigDescription::DENSITY_XXXHIGH);
82672384b41e1fc7195424533b7aa6753fb771a6cbPierre Lecesne  TableSplitter splitter({}, options);
83672384b41e1fc7195424533b7aa6753fb771a6cbPierre Lecesne  splitter.SplitTable(table.get());
84672384b41e1fc7195424533b7aa6753fb771a6cbPierre Lecesne
85672384b41e1fc7195424533b7aa6753fb771a6cbPierre Lecesne  // Densities remaining:
86672384b41e1fc7195424533b7aa6753fb771a6cbPierre Lecesne  // "mdpi" is the closest available density for the requested "ldpi" density.
87672384b41e1fc7195424533b7aa6753fb771a6cbPierre Lecesne  EXPECT_NE(nullptr, test::GetValueForConfig<FileReference>(
88672384b41e1fc7195424533b7aa6753fb771a6cbPierre Lecesne                         table.get(), "android:drawable/icon",
89672384b41e1fc7195424533b7aa6753fb771a6cbPierre Lecesne                         test::ParseConfigOrDie("mdpi")));
90672384b41e1fc7195424533b7aa6753fb771a6cbPierre Lecesne  // "xxhdpi" is the closest available density for the requested "xxxhdpi" density.
91672384b41e1fc7195424533b7aa6753fb771a6cbPierre Lecesne  EXPECT_NE(nullptr, test::GetValueForConfig<FileReference>(
92672384b41e1fc7195424533b7aa6753fb771a6cbPierre Lecesne                         table.get(), "android:drawable/icon",
93672384b41e1fc7195424533b7aa6753fb771a6cbPierre Lecesne                         test::ParseConfigOrDie("xxhdpi")));
94672384b41e1fc7195424533b7aa6753fb771a6cbPierre Lecesne  EXPECT_NE(nullptr, test::GetValue<Id>(table.get(), "android:string/one"));
95672384b41e1fc7195424533b7aa6753fb771a6cbPierre Lecesne
96672384b41e1fc7195424533b7aa6753fb771a6cbPierre Lecesne  // Removed densities:
97672384b41e1fc7195424533b7aa6753fb771a6cbPierre Lecesne  EXPECT_EQ(nullptr, test::GetValueForConfig<FileReference>(
98672384b41e1fc7195424533b7aa6753fb771a6cbPierre Lecesne                         table.get(), "android:drawable/icon",
99672384b41e1fc7195424533b7aa6753fb771a6cbPierre Lecesne                         test::ParseConfigOrDie("hdpi")));
100672384b41e1fc7195424533b7aa6753fb771a6cbPierre Lecesne  EXPECT_EQ(nullptr, test::GetValueForConfig<FileReference>(
101672384b41e1fc7195424533b7aa6753fb771a6cbPierre Lecesne                         table.get(), "android:drawable/icon",
102672384b41e1fc7195424533b7aa6753fb771a6cbPierre Lecesne                         test::ParseConfigOrDie("xhdpi")));
103672384b41e1fc7195424533b7aa6753fb771a6cbPierre Lecesne}
104672384b41e1fc7195424533b7aa6753fb771a6cbPierre Lecesne
105672384b41e1fc7195424533b7aa6753fb771a6cbPierre Lecesne
10636c73a595910e96f3552f938eeb81d46356067a1Adam LesinskiTEST(TableSplitterTest, SplitTableByDensity) {
107ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski  std::unique_ptr<ResourceTable> table =
108ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski      test::ResourceTableBuilder()
109ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski          .AddFileReference("android:drawable/foo", "res/drawable-mdpi/foo.png",
110ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski                            test::ParseConfigOrDie("mdpi"))
111ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski          .AddFileReference("android:drawable/foo", "res/drawable-hdpi/foo.png",
112ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski                            test::ParseConfigOrDie("hdpi"))
113ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski          .AddFileReference("android:drawable/foo",
114ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski                            "res/drawable-xhdpi/foo.png",
115ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski                            test::ParseConfigOrDie("xhdpi"))
116ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski          .AddFileReference("android:drawable/foo",
117ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski                            "res/drawable-xxhdpi/foo.png",
118ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski                            test::ParseConfigOrDie("xxhdpi"))
119ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski          .Build();
120ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski
121ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski  std::vector<SplitConstraints> constraints;
122ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski  constraints.push_back(SplitConstraints{{test::ParseConfigOrDie("mdpi")}});
123ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski  constraints.push_back(SplitConstraints{{test::ParseConfigOrDie("hdpi")}});
124ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski  constraints.push_back(SplitConstraints{{test::ParseConfigOrDie("xhdpi")}});
125ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski
126ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski  TableSplitter splitter(constraints, TableSplitterOptions{});
127ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski  splitter.SplitTable(table.get());
128ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski
129ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski  ASSERT_EQ(3u, splitter.splits().size());
130ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski
131ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski  ResourceTable* split_one = splitter.splits()[0].get();
132ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski  ResourceTable* split_two = splitter.splits()[1].get();
133ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski  ResourceTable* split_three = splitter.splits()[2].get();
134ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski
135ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski  // Just xxhdpi should be in the base.
136ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski  EXPECT_EQ(nullptr, test::GetValueForConfig<FileReference>(
137ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski                         table.get(), "android:drawable/foo",
138ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski                         test::ParseConfigOrDie("mdpi")));
139ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski  EXPECT_EQ(nullptr, test::GetValueForConfig<FileReference>(
140ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski                         table.get(), "android:drawable/foo",
141ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski                         test::ParseConfigOrDie("hdpi")));
142ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski  EXPECT_EQ(nullptr, test::GetValueForConfig<FileReference>(
143ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski                         table.get(), "android:drawable/foo",
144ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski                         test::ParseConfigOrDie("xhdpi")));
145ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski  EXPECT_NE(nullptr, test::GetValueForConfig<FileReference>(
146ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski                         table.get(), "android:drawable/foo",
147ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski                         test::ParseConfigOrDie("xxhdpi")));
148ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski
149ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski  // Each split should have one and only one drawable.
150ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski  EXPECT_NE(nullptr, test::GetValueForConfig<FileReference>(
151ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski                         split_one, "android:drawable/foo",
152ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski                         test::ParseConfigOrDie("mdpi")));
153ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski  EXPECT_EQ(nullptr, test::GetValueForConfig<FileReference>(
154ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski                         split_one, "android:drawable/foo",
155ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski                         test::ParseConfigOrDie("hdpi")));
156ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski  EXPECT_EQ(nullptr, test::GetValueForConfig<FileReference>(
157ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski                         split_one, "android:drawable/foo",
158ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski                         test::ParseConfigOrDie("xhdpi")));
159ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski  EXPECT_EQ(nullptr, test::GetValueForConfig<FileReference>(
160ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski                         split_one, "android:drawable/foo",
161ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski                         test::ParseConfigOrDie("xxhdpi")));
162ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski
163ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski  EXPECT_EQ(nullptr, test::GetValueForConfig<FileReference>(
164ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski                         split_two, "android:drawable/foo",
165ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski                         test::ParseConfigOrDie("mdpi")));
166ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski  EXPECT_NE(nullptr, test::GetValueForConfig<FileReference>(
167ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski                         split_two, "android:drawable/foo",
168ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski                         test::ParseConfigOrDie("hdpi")));
169ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski  EXPECT_EQ(nullptr, test::GetValueForConfig<FileReference>(
170ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski                         split_two, "android:drawable/foo",
171ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski                         test::ParseConfigOrDie("xhdpi")));
172ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski  EXPECT_EQ(nullptr, test::GetValueForConfig<FileReference>(
173ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski                         split_two, "android:drawable/foo",
174ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski                         test::ParseConfigOrDie("xxhdpi")));
175ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski
176ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski  EXPECT_EQ(nullptr, test::GetValueForConfig<FileReference>(
177ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski                         split_three, "android:drawable/foo",
178ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski                         test::ParseConfigOrDie("mdpi")));
179ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski  EXPECT_EQ(nullptr, test::GetValueForConfig<FileReference>(
180ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski                         split_three, "android:drawable/foo",
181ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski                         test::ParseConfigOrDie("hdpi")));
182ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski  EXPECT_NE(nullptr, test::GetValueForConfig<FileReference>(
183ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski                         split_three, "android:drawable/foo",
184ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski                         test::ParseConfigOrDie("xhdpi")));
185ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski  EXPECT_EQ(nullptr, test::GetValueForConfig<FileReference>(
186ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski                         split_three, "android:drawable/foo",
187ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski                         test::ParseConfigOrDie("xxhdpi")));
18836c73a595910e96f3552f938eeb81d46356067a1Adam Lesinski}
18936c73a595910e96f3552f938eeb81d46356067a1Adam Lesinski
190355f285ffd000f6cfe76680eb22d010546d124bbAdam LesinskiTEST(TableSplitterTest, SplitTableByConfigAndDensity) {
191ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski  ResourceTable table;
192ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski
193ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski  const ResourceName foo = test::ParseNameOrDie("android:string/foo");
194ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski  ASSERT_TRUE(table.AddResource(foo, test::ParseConfigOrDie("land-hdpi"), {},
195ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski                                util::make_unique<Id>(),
196ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski                                test::GetDiagnostics()));
197ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski  ASSERT_TRUE(table.AddResource(foo, test::ParseConfigOrDie("land-xhdpi"), {},
198ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski                                util::make_unique<Id>(),
199ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski                                test::GetDiagnostics()));
200ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski  ASSERT_TRUE(table.AddResource(foo, test::ParseConfigOrDie("land-xxhdpi"), {},
201ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski                                util::make_unique<Id>(),
202ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski                                test::GetDiagnostics()));
203ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski
204ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski  std::vector<SplitConstraints> constraints;
205ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski  constraints.push_back(
206ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski      SplitConstraints{{test::ParseConfigOrDie("land-mdpi")}});
207ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski  constraints.push_back(
208ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski      SplitConstraints{{test::ParseConfigOrDie("land-xhdpi")}});
209ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski
210ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski  TableSplitter splitter(constraints, TableSplitterOptions{});
211ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski  splitter.SplitTable(&table);
212ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski
213ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski  ASSERT_EQ(2u, splitter.splits().size());
214ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski
215ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski  ResourceTable* split_one = splitter.splits()[0].get();
216ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski  ResourceTable* split_two = splitter.splits()[1].get();
217ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski
218ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski  // All but the xxhdpi resource should be gone, since there were closer matches
219ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski  // in land-xhdpi.
220ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski  EXPECT_EQ(nullptr,
221ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski            test::GetValueForConfig<Id>(&table, "android:string/foo",
222ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski                                        test::ParseConfigOrDie("land-hdpi")));
223ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski  EXPECT_EQ(nullptr,
224ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski            test::GetValueForConfig<Id>(&table, "android:string/foo",
225ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski                                        test::ParseConfigOrDie("land-xhdpi")));
226ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski  EXPECT_NE(nullptr,
227ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski            test::GetValueForConfig<Id>(&table, "android:string/foo",
228ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski                                        test::ParseConfigOrDie("land-xxhdpi")));
229ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski
230ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski  EXPECT_NE(nullptr,
231ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski            test::GetValueForConfig<Id>(split_one, "android:string/foo",
232ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski                                        test::ParseConfigOrDie("land-hdpi")));
233ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski  EXPECT_EQ(nullptr,
234ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski            test::GetValueForConfig<Id>(split_one, "android:string/foo",
235ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski                                        test::ParseConfigOrDie("land-xhdpi")));
236ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski  EXPECT_EQ(nullptr,
237ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski            test::GetValueForConfig<Id>(split_one, "android:string/foo",
238ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski                                        test::ParseConfigOrDie("land-xxhdpi")));
239ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski
240ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski  EXPECT_EQ(nullptr,
241ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski            test::GetValueForConfig<Id>(split_two, "android:string/foo",
242ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski                                        test::ParseConfigOrDie("land-hdpi")));
243ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski  EXPECT_NE(nullptr,
244ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski            test::GetValueForConfig<Id>(split_two, "android:string/foo",
245ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski                                        test::ParseConfigOrDie("land-xhdpi")));
246ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski  EXPECT_EQ(nullptr,
247ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski            test::GetValueForConfig<Id>(split_two, "android:string/foo",
248ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski                                        test::ParseConfigOrDie("land-xxhdpi")));
249355f285ffd000f6cfe76680eb22d010546d124bbAdam Lesinski}
250355f285ffd000f6cfe76680eb22d010546d124bbAdam Lesinski
251ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski}  // namespace aapt
252