blob: e5eacccb682ed945866e766fb8ccd1b80dda778e [file] [log] [blame]
Shane Farmer74cdea32017-05-12 16:22:36 -07001/*
2 * Copyright (C) 2017 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 "configuration/ConfigurationParser.h"
18
19#include <string>
20
Shane Farmer67e8a302017-12-06 14:39:10 -080021#include "android-base/stringprintf.h"
Shane Farmer74cdea32017-05-12 16:22:36 -070022#include "androidfw/ResourceTypes.h"
23
Shane Farmer67e8a302017-12-06 14:39:10 -080024#include "SdkConstants.h"
Shane Farmercb6c3f92017-11-27 13:19:36 -080025#include "configuration/ConfigurationParser.internal.h"
Shane Farmer74cdea32017-05-12 16:22:36 -070026#include "test/Test.h"
27#include "xml/XmlDom.h"
28
MÃ¥rten Kongstad24c9aa62018-06-20 08:46:41 +020029using ::android::ConfigDescription;
30
Shane Farmer74cdea32017-05-12 16:22:36 -070031namespace aapt {
Shane Farmer3edd4722017-09-01 14:34:22 -070032
33namespace configuration {
Shane Farmercb6c3f92017-11-27 13:19:36 -080034
Shane Farmer78c43d72017-12-04 09:08:38 -080035bool operator==(const ConfiguredArtifact& lhs, const ConfiguredArtifact& rhs) {
36 return lhs.name == rhs.name && lhs.abi_group == rhs.abi_group &&
37 lhs.screen_density_group == rhs.screen_density_group &&
38 lhs.locale_group == rhs.locale_group && lhs.android_sdk == rhs.android_sdk &&
39 lhs.device_feature_group == rhs.device_feature_group &&
40 lhs.gl_texture_group == rhs.gl_texture_group;
41}
42
Shane Farmercb6c3f92017-11-27 13:19:36 -080043namespace handler {
Shane Farmer3edd4722017-09-01 14:34:22 -070044
Shane Farmer74cdea32017-05-12 16:22:36 -070045namespace {
46
Shane Farmer67e8a302017-12-06 14:39:10 -080047using ::aapt::configuration::Abi;
48using ::aapt::configuration::AndroidManifest;
49using ::aapt::configuration::AndroidSdk;
Shane Farmercb6c3f92017-11-27 13:19:36 -080050using ::aapt::configuration::ConfiguredArtifact;
Shane Farmer67e8a302017-12-06 14:39:10 -080051using ::aapt::configuration::DeviceFeature;
Shane Farmer78c43d72017-12-04 09:08:38 -080052using ::aapt::configuration::ExtractConfiguration;
Shane Farmer67e8a302017-12-06 14:39:10 -080053using ::aapt::configuration::GlTexture;
54using ::aapt::configuration::Locale;
55using ::aapt::configuration::PostProcessingConfiguration;
56using ::aapt::xml::Element;
57using ::aapt::xml::NodeCast;
Adam Lesinski6b372992017-08-09 10:54:23 -070058using ::android::ResTable_config;
Shane Farmer67e8a302017-12-06 14:39:10 -080059using ::android::base::StringPrintf;
Adam Lesinski6b372992017-08-09 10:54:23 -070060using ::testing::ElementsAre;
Shane Farmer78c43d72017-12-04 09:08:38 -080061using ::testing::Eq;
Shane Farmercb6c3f92017-11-27 13:19:36 -080062using ::testing::SizeIs;
Shane Farmer78c43d72017-12-04 09:08:38 -080063using ::testing::StrEq;
Shane Farmer74cdea32017-05-12 16:22:36 -070064
65constexpr const char* kValidConfig = R"(<?xml version="1.0" encoding="utf-8" ?>
66<post-process xmlns="http://schemas.android.com/tools/aapt">
Shane Farmer78c43d72017-12-04 09:08:38 -080067 <abi-groups>
Shane Farmer11cdc1c2018-01-31 16:43:24 -080068 <abi-group label="other" version-code-order="2">
Shane Farmer74cdea32017-05-12 16:22:36 -070069 <abi>x86</abi>
70 <abi>mips</abi>
71 </abi-group>
Shane Farmer11cdc1c2018-01-31 16:43:24 -080072 <abi-group label="arm" version-code-order="1">
73 <abi>armeabi-v7a</abi>
74 <abi>arm64-v8a</abi>
75 </abi-group>
Shane Farmer78c43d72017-12-04 09:08:38 -080076 </abi-groups>
77 <screen-density-groups>
Shane Farmer11cdc1c2018-01-31 16:43:24 -080078 <screen-density-group label="large" version-code-order="2">
Shane Farmer74cdea32017-05-12 16:22:36 -070079 <screen-density>xhdpi</screen-density>
80 <screen-density>xxhdpi</screen-density>
81 <screen-density>xxxhdpi</screen-density>
82 </screen-density-group>
Shane Farmer11cdc1c2018-01-31 16:43:24 -080083 <screen-density-group label="alldpi" version-code-order="1">
Shane Farmer74cdea32017-05-12 16:22:36 -070084 <screen-density>ldpi</screen-density>
85 <screen-density>mdpi</screen-density>
86 <screen-density>hdpi</screen-density>
87 <screen-density>xhdpi</screen-density>
88 <screen-density>xxhdpi</screen-density>
89 <screen-density>xxxhdpi</screen-density>
90 </screen-density-group>
Shane Farmer78c43d72017-12-04 09:08:38 -080091 </screen-density-groups>
92 <locale-groups>
Shane Farmer11cdc1c2018-01-31 16:43:24 -080093 <locale-group label="europe" version-code-order="1">
Shane Farmer0a5b2012017-06-22 12:24:12 -070094 <locale>en</locale>
95 <locale>es</locale>
96 <locale>fr</locale>
97 <locale>de</locale>
Shane Farmer74cdea32017-05-12 16:22:36 -070098 </locale-group>
Shane Farmer11cdc1c2018-01-31 16:43:24 -080099 <locale-group label="north-america" version-code-order="2">
Shane Farmer0a5b2012017-06-22 12:24:12 -0700100 <locale>en</locale>
101 <locale>es-rMX</locale>
102 <locale>fr-rCA</locale>
Shane Farmer74cdea32017-05-12 16:22:36 -0700103 </locale-group>
Shane Farmer11cdc1c2018-01-31 16:43:24 -0800104 <locale-group label="all" version-code-order="-1">
105 <locale />
106 </locale-group>
Shane Farmer78c43d72017-12-04 09:08:38 -0800107 </locale-groups>
108 <android-sdks>
109 <android-sdk
110 label="v19"
111 minSdkVersion="19"
112 targetSdkVersion="24"
113 maxSdkVersion="25">
114 <manifest>
115 <!--- manifest additions here XSLT? TODO -->
116 </manifest>
117 </android-sdk>
118 </android-sdks>
119 <gl-texture-groups>
Shane Farmer11cdc1c2018-01-31 16:43:24 -0800120 <gl-texture-group label="dxt1" version-code-order="2">
Shane Farmer74cdea32017-05-12 16:22:36 -0700121 <gl-texture name="GL_EXT_texture_compression_dxt1">
122 <texture-path>assets/dxt1/*</texture-path>
123 </gl-texture>
124 </gl-texture-group>
Shane Farmer78c43d72017-12-04 09:08:38 -0800125 </gl-texture-groups>
126 <device-feature-groups>
Shane Farmer11cdc1c2018-01-31 16:43:24 -0800127 <device-feature-group label="low-latency" version-code-order="2">
Shane Farmer74cdea32017-05-12 16:22:36 -0700128 <supports-feature>android.hardware.audio.low_latency</supports-feature>
129 </device-feature-group>
Shane Farmer78c43d72017-12-04 09:08:38 -0800130 </device-feature-groups>
Shane Farmer74cdea32017-05-12 16:22:36 -0700131 <artifacts>
132 <artifact-format>
133 ${base}.${abi}.${screen-density}.${locale}.${sdk}.${gl}.${feature}.release
134 </artifact-format>
135 <artifact
136 name="art1"
137 abi-group="arm"
138 screen-density-group="large"
139 locale-group="europe"
Shane Farmer78c43d72017-12-04 09:08:38 -0800140 android-sdk="v19"
Shane Farmer74cdea32017-05-12 16:22:36 -0700141 gl-texture-group="dxt1"
142 device-feature-group="low-latency"/>
143 <artifact
144 name="art2"
145 abi-group="other"
146 screen-density-group="alldpi"
147 locale-group="north-america"
Shane Farmer78c43d72017-12-04 09:08:38 -0800148 android-sdk="v19"
Shane Farmer74cdea32017-05-12 16:22:36 -0700149 gl-texture-group="dxt1"
150 device-feature-group="low-latency"/>
151 </artifacts>
152</post-process>
153)";
154
155class ConfigurationParserTest : public ConfigurationParser, public ::testing::Test {
156 public:
Shane Farmer78c43d72017-12-04 09:08:38 -0800157 ConfigurationParserTest() : ConfigurationParser("", "config.xml") {
158 }
Shane Farmer74cdea32017-05-12 16:22:36 -0700159
160 protected:
161 StdErrDiagnostics diag_;
162};
163
Shane Farmerb1027272017-06-14 09:10:28 -0700164TEST_F(ConfigurationParserTest, ForPath_NoFile) {
165 auto result = ConfigurationParser::ForPath("./does_not_exist.xml");
166 EXPECT_FALSE(result);
167}
168
Shane Farmer78c43d72017-12-04 09:08:38 -0800169TEST_F(ConfigurationParserTest, ExtractConfiguration) {
Ryan Mitchell4382e442021-07-14 12:53:01 -0700170 std::optional<PostProcessingConfiguration> maybe_config =
Ryan Mitchell4ea90752020-07-31 08:21:43 -0700171 ExtractConfiguration(kValidConfig, "fake.xml", &diag_);
Shane Farmer78c43d72017-12-04 09:08:38 -0800172
173 PostProcessingConfiguration config = maybe_config.value();
174
175 auto& arm = config.abi_groups["arm"];
176 auto& other = config.abi_groups["other"];
Shane Farmer11cdc1c2018-01-31 16:43:24 -0800177 EXPECT_EQ(arm.order, 1);
178 EXPECT_EQ(other.order, 2);
Shane Farmer78c43d72017-12-04 09:08:38 -0800179
180 auto& large = config.screen_density_groups["large"];
181 auto& alldpi = config.screen_density_groups["alldpi"];
Shane Farmer11cdc1c2018-01-31 16:43:24 -0800182 EXPECT_EQ(large.order, 2);
183 EXPECT_EQ(alldpi.order, 1);
Shane Farmer78c43d72017-12-04 09:08:38 -0800184
185 auto& north_america = config.locale_groups["north-america"];
186 auto& europe = config.locale_groups["europe"];
Shane Farmer11cdc1c2018-01-31 16:43:24 -0800187 auto& all = config.locale_groups["all"];
Shane Farmer78c43d72017-12-04 09:08:38 -0800188 // Checked in reverse to make sure access order does not matter.
Shane Farmer11cdc1c2018-01-31 16:43:24 -0800189 EXPECT_EQ(north_america.order, 2);
190 EXPECT_EQ(europe.order, 1);
191 EXPECT_EQ(all.order, -1);
192 EXPECT_EQ(3ul, config.locale_groups.size());
Shane Farmer78c43d72017-12-04 09:08:38 -0800193}
194
Shane Farmer74cdea32017-05-12 16:22:36 -0700195TEST_F(ConfigurationParserTest, ValidateFile) {
Shane Farmer78c43d72017-12-04 09:08:38 -0800196 auto parser = ConfigurationParser::ForContents(kValidConfig, "conf.xml").WithDiagnostics(&diag_);
Shane Farmercb6c3f92017-11-27 13:19:36 -0800197 auto result = parser.Parse("test.apk");
Shane Farmer74cdea32017-05-12 16:22:36 -0700198 ASSERT_TRUE(result);
Shane Farmercb6c3f92017-11-27 13:19:36 -0800199 const std::vector<OutputArtifact>& value = result.value();
200 EXPECT_THAT(value, SizeIs(2ul));
Shane Farmer74cdea32017-05-12 16:22:36 -0700201
Shane Farmercb6c3f92017-11-27 13:19:36 -0800202 const OutputArtifact& a1 = value[0];
203 EXPECT_EQ(a1.name, "art1.apk");
Shane Farmer78c43d72017-12-04 09:08:38 -0800204 EXPECT_EQ(a1.version, 1);
Shane Farmercb6c3f92017-11-27 13:19:36 -0800205 EXPECT_THAT(a1.abis, ElementsAre(Abi::kArmV7a, Abi::kArm64V8a));
206 EXPECT_THAT(a1.screen_densities,
207 ElementsAre(test::ParseConfigOrDie("xhdpi").CopyWithoutSdkVersion(),
208 test::ParseConfigOrDie("xxhdpi").CopyWithoutSdkVersion(),
209 test::ParseConfigOrDie("xxxhdpi").CopyWithoutSdkVersion()));
210 EXPECT_THAT(a1.locales, ElementsAre(test::ParseConfigOrDie("en"), test::ParseConfigOrDie("es"),
211 test::ParseConfigOrDie("fr"), test::ParseConfigOrDie("de")));
Shane Farmer78c43d72017-12-04 09:08:38 -0800212 ASSERT_TRUE(a1.android_sdk);
213 ASSERT_TRUE(a1.android_sdk.value().min_sdk_version);
Chih-Hung Hsieh054dab12018-12-10 13:52:46 -0800214 EXPECT_EQ(a1.android_sdk.value().min_sdk_version, 19L);
Shane Farmercb6c3f92017-11-27 13:19:36 -0800215 EXPECT_THAT(a1.textures, SizeIs(1ul));
216 EXPECT_THAT(a1.features, SizeIs(1ul));
Shane Farmer74cdea32017-05-12 16:22:36 -0700217
Shane Farmercb6c3f92017-11-27 13:19:36 -0800218 const OutputArtifact& a2 = value[1];
219 EXPECT_EQ(a2.name, "art2.apk");
Shane Farmer78c43d72017-12-04 09:08:38 -0800220 EXPECT_EQ(a2.version, 2);
Shane Farmercb6c3f92017-11-27 13:19:36 -0800221 EXPECT_THAT(a2.abis, ElementsAre(Abi::kX86, Abi::kMips));
222 EXPECT_THAT(a2.screen_densities,
223 ElementsAre(test::ParseConfigOrDie("ldpi").CopyWithoutSdkVersion(),
224 test::ParseConfigOrDie("mdpi").CopyWithoutSdkVersion(),
225 test::ParseConfigOrDie("hdpi").CopyWithoutSdkVersion(),
226 test::ParseConfigOrDie("xhdpi").CopyWithoutSdkVersion(),
227 test::ParseConfigOrDie("xxhdpi").CopyWithoutSdkVersion(),
228 test::ParseConfigOrDie("xxxhdpi").CopyWithoutSdkVersion()));
229 EXPECT_THAT(a2.locales,
230 ElementsAre(test::ParseConfigOrDie("en"), test::ParseConfigOrDie("es-rMX"),
231 test::ParseConfigOrDie("fr-rCA")));
Shane Farmer78c43d72017-12-04 09:08:38 -0800232 ASSERT_TRUE(a2.android_sdk);
233 ASSERT_TRUE(a2.android_sdk.value().min_sdk_version);
Chih-Hung Hsieh054dab12018-12-10 13:52:46 -0800234 EXPECT_EQ(a2.android_sdk.value().min_sdk_version, 19L);
Shane Farmercb6c3f92017-11-27 13:19:36 -0800235 EXPECT_THAT(a2.textures, SizeIs(1ul));
236 EXPECT_THAT(a2.features, SizeIs(1ul));
Shane Farmer74cdea32017-05-12 16:22:36 -0700237}
238
Shane Farmer78c43d72017-12-04 09:08:38 -0800239TEST_F(ConfigurationParserTest, ConfiguredArtifactOrdering) {
240 // Create a base builder with the configuration groups but no artifacts to allow it to be copied.
241 test::PostProcessingConfigurationBuilder base_builder = test::PostProcessingConfigurationBuilder()
242 .AddAbiGroup("arm")
243 .AddAbiGroup("arm64")
244 .AddAndroidSdk("v23", 23)
245 .AddAndroidSdk("v19", 19);
246
247 {
248 // Test version ordering.
249 ConfiguredArtifact v23;
250 v23.android_sdk = {"v23"};
251 ConfiguredArtifact v19;
252 v19.android_sdk = {"v19"};
253
254 test::PostProcessingConfigurationBuilder builder = base_builder;
255 PostProcessingConfiguration config = builder.AddArtifact(v23).AddArtifact(v19).Build();
256
257 config.SortArtifacts();
258 ASSERT_THAT(config.artifacts, SizeIs(2));
259 EXPECT_THAT(config.artifacts[0], Eq(v19));
260 EXPECT_THAT(config.artifacts[1], Eq(v23));
261 }
262
263 {
264 // Test ABI ordering.
265 ConfiguredArtifact arm;
266 arm.android_sdk = {"v19"};
267 arm.abi_group = {"arm"};
268 ConfiguredArtifact arm64;
269 arm64.android_sdk = {"v19"};
270 arm64.abi_group = {"arm64"};
271
272 test::PostProcessingConfigurationBuilder builder = base_builder;
273 PostProcessingConfiguration config = builder.AddArtifact(arm64).AddArtifact(arm).Build();
274
275 config.SortArtifacts();
276 ASSERT_THAT(config.artifacts, SizeIs(2));
277 EXPECT_THAT(config.artifacts[0], Eq(arm));
278 EXPECT_THAT(config.artifacts[1], Eq(arm64));
279 }
280
281 {
282 // Test Android SDK has precedence over ABI.
283 ConfiguredArtifact arm;
284 arm.android_sdk = {"v23"};
285 arm.abi_group = {"arm"};
286 ConfiguredArtifact arm64;
287 arm64.android_sdk = {"v19"};
288 arm64.abi_group = {"arm64"};
289
290 test::PostProcessingConfigurationBuilder builder = base_builder;
291 PostProcessingConfiguration config = builder.AddArtifact(arm64).AddArtifact(arm).Build();
292
293 config.SortArtifacts();
294 ASSERT_THAT(config.artifacts, SizeIs(2));
295 EXPECT_THAT(config.artifacts[0], Eq(arm64));
296 EXPECT_THAT(config.artifacts[1], Eq(arm));
297 }
298
299 {
300 // Test version is better than ABI.
301 ConfiguredArtifact arm;
302 arm.abi_group = {"arm"};
303 ConfiguredArtifact v19;
304 v19.android_sdk = {"v19"};
305
306 test::PostProcessingConfigurationBuilder builder = base_builder;
307 PostProcessingConfiguration config = builder.AddArtifact(v19).AddArtifact(arm).Build();
308
309 config.SortArtifacts();
310 ASSERT_THAT(config.artifacts, SizeIs(2));
311 EXPECT_THAT(config.artifacts[0], Eq(arm));
312 EXPECT_THAT(config.artifacts[1], Eq(v19));
313 }
314
315 {
316 // Test version is sorted higher than no version.
317 ConfiguredArtifact arm;
318 arm.abi_group = {"arm"};
319 ConfiguredArtifact v19;
320 v19.abi_group = {"arm"};
321 v19.android_sdk = {"v19"};
322
323 test::PostProcessingConfigurationBuilder builder = base_builder;
324 PostProcessingConfiguration config = builder.AddArtifact(v19).AddArtifact(arm).Build();
325
326 config.SortArtifacts();
327 ASSERT_THAT(config.artifacts, SizeIs(2));
328 EXPECT_THAT(config.artifacts[0], Eq(arm));
329 EXPECT_THAT(config.artifacts[1], Eq(v19));
330 }
331}
332
Shane Farmer74cdea32017-05-12 16:22:36 -0700333TEST_F(ConfigurationParserTest, InvalidNamespace) {
334 constexpr const char* invalid_ns = R"(<?xml version="1.0" encoding="utf-8" ?>
Shane Farmer78c43d72017-12-04 09:08:38 -0800335 <post-process xmlns="http://schemas.android.com/tools/another-unknown-tool" />)";
Shane Farmer74cdea32017-05-12 16:22:36 -0700336
Shane Farmer78c43d72017-12-04 09:08:38 -0800337 auto result = ConfigurationParser::ForContents(invalid_ns, "config.xml").Parse("test.apk");
Shane Farmer74cdea32017-05-12 16:22:36 -0700338 ASSERT_FALSE(result);
339}
340
341TEST_F(ConfigurationParserTest, ArtifactAction) {
Shane Farmer810fd182017-09-21 14:37:44 -0700342 PostProcessingConfiguration config;
Shane Farmer78c43d72017-12-04 09:08:38 -0800343 const auto doc = test::BuildXmlDom(R"xml(
Shane Farmer810fd182017-09-21 14:37:44 -0700344 <artifact
345 abi-group="arm"
346 screen-density-group="large"
347 locale-group="europe"
Shane Farmer78c43d72017-12-04 09:08:38 -0800348 android-sdk="v19"
Shane Farmer810fd182017-09-21 14:37:44 -0700349 gl-texture-group="dxt1"
350 device-feature-group="low-latency"/>)xml");
351
Shane Farmer78c43d72017-12-04 09:08:38 -0800352 ASSERT_TRUE(ArtifactTagHandler(&config, NodeCast<Element>(doc->root.get()), &diag_));
Shane Farmer810fd182017-09-21 14:37:44 -0700353
Shane Farmer78c43d72017-12-04 09:08:38 -0800354 EXPECT_THAT(config.artifacts, SizeIs(1ul));
Shane Farmer810fd182017-09-21 14:37:44 -0700355
Shane Farmer78c43d72017-12-04 09:08:38 -0800356 auto& artifact = config.artifacts.back();
357 EXPECT_FALSE(artifact.name); // TODO: make this fail.
358 EXPECT_EQ("arm", artifact.abi_group.value());
359 EXPECT_EQ("large", artifact.screen_density_group.value());
360 EXPECT_EQ("europe", artifact.locale_group.value());
361 EXPECT_EQ("v19", artifact.android_sdk.value());
362 EXPECT_EQ("dxt1", artifact.gl_texture_group.value());
363 EXPECT_EQ("low-latency", artifact.device_feature_group.value());
Shane Farmer74cdea32017-05-12 16:22:36 -0700364}
365
366TEST_F(ConfigurationParserTest, ArtifactFormatAction) {
Shane Farmer810fd182017-09-21 14:37:44 -0700367 const auto doc = test::BuildXmlDom(R"xml(
Shane Farmer74cdea32017-05-12 16:22:36 -0700368 <artifact-format>
369 ${base}.${abi}.${screen-density}.${locale}.${sdk}.${gl}.${feature}.release
Shane Farmer810fd182017-09-21 14:37:44 -0700370 </artifact-format>)xml");
Shane Farmer74cdea32017-05-12 16:22:36 -0700371
Shane Farmer280be342017-06-21 15:20:15 -0700372 PostProcessingConfiguration config;
Shane Farmercb6c3f92017-11-27 13:19:36 -0800373 bool ok = ArtifactFormatTagHandler(&config, NodeCast<Element>(doc.get()->root.get()), &diag_);
Shane Farmer74cdea32017-05-12 16:22:36 -0700374 ASSERT_TRUE(ok);
375 ASSERT_TRUE(config.artifact_format);
376 EXPECT_EQ(
377 "${base}.${abi}.${screen-density}.${locale}.${sdk}.${gl}.${feature}.release",
378 static_cast<std::string>(config.artifact_format.value())
379 );
380}
381
382TEST_F(ConfigurationParserTest, AbiGroupAction) {
383 static constexpr const char* xml = R"xml(
Shane Farmer11cdc1c2018-01-31 16:43:24 -0800384 <abi-group label="arm" version-code-order="2">
Shane Farmer74cdea32017-05-12 16:22:36 -0700385 <!-- First comment. -->
386 <abi>
387 armeabi-v7a
388 </abi>
389 <!-- Another comment. -->
390 <abi>arm64-v8a</abi>
391 </abi-group>)xml";
392
393 auto doc = test::BuildXmlDom(xml);
394
Shane Farmer280be342017-06-21 15:20:15 -0700395 PostProcessingConfiguration config;
Shane Farmercb6c3f92017-11-27 13:19:36 -0800396 bool ok = AbiGroupTagHandler(&config, NodeCast<Element>(doc.get()->root.get()), &diag_);
Shane Farmer74cdea32017-05-12 16:22:36 -0700397 ASSERT_TRUE(ok);
398
Shane Farmercb6c3f92017-11-27 13:19:36 -0800399 EXPECT_THAT(config.abi_groups, SizeIs(1ul));
Shane Farmer74cdea32017-05-12 16:22:36 -0700400 ASSERT_EQ(1u, config.abi_groups.count("arm"));
401
Shane Farmer78c43d72017-12-04 09:08:38 -0800402 auto& out = config.abi_groups["arm"].entry;
Shane Farmer74cdea32017-05-12 16:22:36 -0700403 ASSERT_THAT(out, ElementsAre(Abi::kArmV7a, Abi::kArm64V8a));
404}
405
Shane Farmer39e474f2017-12-18 14:44:11 -0800406TEST_F(ConfigurationParserTest, AbiGroupAction_EmptyGroup) {
Shane Farmer11cdc1c2018-01-31 16:43:24 -0800407 static constexpr const char* xml =
408 R"xml(<abi-group label="arm64-v8a" version-code-order="3"/>)xml";
Shane Farmer39e474f2017-12-18 14:44:11 -0800409
410 auto doc = test::BuildXmlDom(xml);
411
412 PostProcessingConfiguration config;
413 bool ok = AbiGroupTagHandler(&config, NodeCast<Element>(doc.get()->root.get()), &diag_);
414 ASSERT_TRUE(ok);
415
416 EXPECT_THAT(config.abi_groups, SizeIs(1ul));
417 ASSERT_EQ(1u, config.abi_groups.count("arm64-v8a"));
418
Shane Farmer11cdc1c2018-01-31 16:43:24 -0800419 auto& out = config.abi_groups["arm64-v8a"];
420 ASSERT_THAT(out.entry, ElementsAre(Abi::kArm64V8a));
421 EXPECT_EQ(3, out.order);
422}
423
424TEST_F(ConfigurationParserTest, AbiGroupAction_EmptyGroup_NoOrder) {
425 static constexpr const char* xml = R"xml(<abi-group label="arm64-v8a"/>)xml";
426
427 auto doc = test::BuildXmlDom(xml);
428
429 PostProcessingConfiguration config;
430 bool ok = AbiGroupTagHandler(&config, NodeCast<Element>(doc.get()->root.get()), &diag_);
431 ASSERT_FALSE(ok);
Shane Farmer39e474f2017-12-18 14:44:11 -0800432}
433
434TEST_F(ConfigurationParserTest, AbiGroupAction_InvalidEmptyGroup) {
Shane Farmer11cdc1c2018-01-31 16:43:24 -0800435 static constexpr const char* xml = R"xml(<abi-group label="arm" order="2"/>)xml";
Shane Farmer39e474f2017-12-18 14:44:11 -0800436
437 auto doc = test::BuildXmlDom(xml);
438
439 PostProcessingConfiguration config;
440 bool ok = AbiGroupTagHandler(&config, NodeCast<Element>(doc.get()->root.get()), &diag_);
441 ASSERT_FALSE(ok);
442}
443
Shane Farmer74cdea32017-05-12 16:22:36 -0700444TEST_F(ConfigurationParserTest, ScreenDensityGroupAction) {
445 static constexpr const char* xml = R"xml(
Shane Farmer11cdc1c2018-01-31 16:43:24 -0800446 <screen-density-group label="large" version-code-order="2">
Shane Farmer74cdea32017-05-12 16:22:36 -0700447 <screen-density>xhdpi</screen-density>
448 <screen-density>
449 xxhdpi
450 </screen-density>
451 <screen-density>xxxhdpi</screen-density>
452 </screen-density-group>)xml";
453
454 auto doc = test::BuildXmlDom(xml);
455
Shane Farmer280be342017-06-21 15:20:15 -0700456 PostProcessingConfiguration config;
Shane Farmercb6c3f92017-11-27 13:19:36 -0800457 bool ok = ScreenDensityGroupTagHandler(&config, NodeCast<Element>(doc.get()->root.get()), &diag_);
Shane Farmer74cdea32017-05-12 16:22:36 -0700458 ASSERT_TRUE(ok);
459
Shane Farmercb6c3f92017-11-27 13:19:36 -0800460 EXPECT_THAT(config.screen_density_groups, SizeIs(1ul));
Shane Farmer74cdea32017-05-12 16:22:36 -0700461 ASSERT_EQ(1u, config.screen_density_groups.count("large"));
462
463 ConfigDescription xhdpi;
464 xhdpi.density = ResTable_config::DENSITY_XHIGH;
465 ConfigDescription xxhdpi;
466 xxhdpi.density = ResTable_config::DENSITY_XXHIGH;
467 ConfigDescription xxxhdpi;
468 xxxhdpi.density = ResTable_config::DENSITY_XXXHIGH;
469
Shane Farmer78c43d72017-12-04 09:08:38 -0800470 auto& out = config.screen_density_groups["large"].entry;
Shane Farmer74cdea32017-05-12 16:22:36 -0700471 ASSERT_THAT(out, ElementsAre(xhdpi, xxhdpi, xxxhdpi));
472}
473
Shane Farmer39e474f2017-12-18 14:44:11 -0800474TEST_F(ConfigurationParserTest, ScreenDensityGroupAction_EmtpyGroup) {
Shane Farmer11cdc1c2018-01-31 16:43:24 -0800475 static constexpr const char* xml =
476 R"xml(<screen-density-group label="xhdpi" version-code-order="4"/>)xml";
Shane Farmer39e474f2017-12-18 14:44:11 -0800477
478 auto doc = test::BuildXmlDom(xml);
479
480 PostProcessingConfiguration config;
481 bool ok = ScreenDensityGroupTagHandler(&config, NodeCast<Element>(doc.get()->root.get()), &diag_);
482 ASSERT_TRUE(ok);
483
484 EXPECT_THAT(config.screen_density_groups, SizeIs(1ul));
485 ASSERT_EQ(1u, config.screen_density_groups.count("xhdpi"));
486
487 ConfigDescription xhdpi;
488 xhdpi.density = ResTable_config::DENSITY_XHIGH;
489
Shane Farmer11cdc1c2018-01-31 16:43:24 -0800490 auto& out = config.screen_density_groups["xhdpi"];
491 EXPECT_THAT(out.entry, ElementsAre(xhdpi));
492 EXPECT_EQ(4, out.order);
493}
494
495TEST_F(ConfigurationParserTest, ScreenDensityGroupAction_EmtpyGroup_NoVersion) {
496 static constexpr const char* xml = R"xml(<screen-density-group label="xhdpi"/>)xml";
497
498 auto doc = test::BuildXmlDom(xml);
499
500 PostProcessingConfiguration config;
501 bool ok = ScreenDensityGroupTagHandler(&config, NodeCast<Element>(doc.get()->root.get()), &diag_);
502 ASSERT_FALSE(ok);
Shane Farmer39e474f2017-12-18 14:44:11 -0800503}
504
505TEST_F(ConfigurationParserTest, ScreenDensityGroupAction_InvalidEmtpyGroup) {
506 static constexpr const char* xml = R"xml(<screen-density-group label="really-big-screen"/>)xml";
507
508 auto doc = test::BuildXmlDom(xml);
509
510 PostProcessingConfiguration config;
511 bool ok = ScreenDensityGroupTagHandler(&config, NodeCast<Element>(doc.get()->root.get()), &diag_);
512 ASSERT_FALSE(ok);
513}
514
Shane Farmer74cdea32017-05-12 16:22:36 -0700515TEST_F(ConfigurationParserTest, LocaleGroupAction) {
516 static constexpr const char* xml = R"xml(
Shane Farmer11cdc1c2018-01-31 16:43:24 -0800517 <locale-group label="europe" version-code-order="2">
Shane Farmer0a5b2012017-06-22 12:24:12 -0700518 <locale>en</locale>
519 <locale>es</locale>
520 <locale>fr</locale>
521 <locale>de</locale>
Shane Farmer74cdea32017-05-12 16:22:36 -0700522 </locale-group>)xml";
523
524 auto doc = test::BuildXmlDom(xml);
525
Shane Farmer280be342017-06-21 15:20:15 -0700526 PostProcessingConfiguration config;
Shane Farmercb6c3f92017-11-27 13:19:36 -0800527 bool ok = LocaleGroupTagHandler(&config, NodeCast<Element>(doc.get()->root.get()), &diag_);
Shane Farmer74cdea32017-05-12 16:22:36 -0700528 ASSERT_TRUE(ok);
529
530 ASSERT_EQ(1ul, config.locale_groups.size());
531 ASSERT_EQ(1u, config.locale_groups.count("europe"));
532
Shane Farmer78c43d72017-12-04 09:08:38 -0800533 const auto& out = config.locale_groups["europe"].entry;
Shane Farmer74cdea32017-05-12 16:22:36 -0700534
Shane Farmer0a5b2012017-06-22 12:24:12 -0700535 ConfigDescription en = test::ParseConfigOrDie("en");
536 ConfigDescription es = test::ParseConfigOrDie("es");
537 ConfigDescription fr = test::ParseConfigOrDie("fr");
538 ConfigDescription de = test::ParseConfigOrDie("de");
Shane Farmer74cdea32017-05-12 16:22:36 -0700539
540 ASSERT_THAT(out, ElementsAre(en, es, fr, de));
541}
542
Shane Farmer39e474f2017-12-18 14:44:11 -0800543TEST_F(ConfigurationParserTest, LocaleGroupAction_EmtpyGroup) {
Shane Farmer11cdc1c2018-01-31 16:43:24 -0800544 static constexpr const char* xml = R"xml(<locale-group label="en" version-code-order="6"/>)xml";
Shane Farmer39e474f2017-12-18 14:44:11 -0800545
546 auto doc = test::BuildXmlDom(xml);
547
548 PostProcessingConfiguration config;
549 bool ok = LocaleGroupTagHandler(&config, NodeCast<Element>(doc.get()->root.get()), &diag_);
550 ASSERT_TRUE(ok);
551
552 ASSERT_EQ(1ul, config.locale_groups.size());
553 ASSERT_EQ(1u, config.locale_groups.count("en"));
554
Shane Farmer11cdc1c2018-01-31 16:43:24 -0800555 const auto& out = config.locale_groups["en"];
Shane Farmer39e474f2017-12-18 14:44:11 -0800556
557 ConfigDescription en = test::ParseConfigOrDie("en");
558
Shane Farmer11cdc1c2018-01-31 16:43:24 -0800559 EXPECT_THAT(out.entry, ElementsAre(en));
560 EXPECT_EQ(6, out.order);
561}
562
563TEST_F(ConfigurationParserTest, LocaleGroupAction_EmtpyGroup_NoOrder) {
564 static constexpr const char* xml = R"xml(<locale-group label="en"/>)xml";
565
566 auto doc = test::BuildXmlDom(xml);
567
568 PostProcessingConfiguration config;
569 bool ok = LocaleGroupTagHandler(&config, NodeCast<Element>(doc.get()->root.get()), &diag_);
570 ASSERT_FALSE(ok);
Shane Farmer39e474f2017-12-18 14:44:11 -0800571}
572
573TEST_F(ConfigurationParserTest, LocaleGroupAction_InvalidEmtpyGroup) {
574 static constexpr const char* xml = R"xml(<locale-group label="arm64"/>)xml";
575
576 auto doc = test::BuildXmlDom(xml);
577
578 PostProcessingConfiguration config;
579 bool ok = LocaleGroupTagHandler(&config, NodeCast<Element>(doc.get()->root.get()), &diag_);
580 ASSERT_FALSE(ok);
581}
582
Shane Farmer74cdea32017-05-12 16:22:36 -0700583TEST_F(ConfigurationParserTest, AndroidSdkGroupAction) {
584 static constexpr const char* xml = R"xml(
Shane Farmer78c43d72017-12-04 09:08:38 -0800585 <android-sdk label="v19"
Shane Farmer3edd4722017-09-01 14:34:22 -0700586 minSdkVersion="19"
587 targetSdkVersion="24"
588 maxSdkVersion="25">
Shane Farmer74cdea32017-05-12 16:22:36 -0700589 <manifest>
590 <!--- manifest additions here XSLT? TODO -->
591 </manifest>
Shane Farmer78c43d72017-12-04 09:08:38 -0800592 </android-sdk>)xml";
Shane Farmer74cdea32017-05-12 16:22:36 -0700593
594 auto doc = test::BuildXmlDom(xml);
595
Shane Farmer280be342017-06-21 15:20:15 -0700596 PostProcessingConfiguration config;
Shane Farmer78c43d72017-12-04 09:08:38 -0800597 bool ok = AndroidSdkTagHandler(&config, NodeCast<Element>(doc.get()->root.get()), &diag_);
Shane Farmer74cdea32017-05-12 16:22:36 -0700598 ASSERT_TRUE(ok);
599
Shane Farmer78c43d72017-12-04 09:08:38 -0800600 ASSERT_EQ(1ul, config.android_sdks.size());
601 ASSERT_EQ(1u, config.android_sdks.count("v19"));
Shane Farmer74cdea32017-05-12 16:22:36 -0700602
Shane Farmer78c43d72017-12-04 09:08:38 -0800603 auto& out = config.android_sdks["v19"];
Shane Farmer74cdea32017-05-12 16:22:36 -0700604
605 AndroidSdk sdk;
Shane Farmer3edd4722017-09-01 14:34:22 -0700606 sdk.min_sdk_version = 19;
607 sdk.target_sdk_version = 24;
608 sdk.max_sdk_version = 25;
Shane Farmer74cdea32017-05-12 16:22:36 -0700609 sdk.manifest = AndroidManifest();
610
Shane Farmerefe45392017-08-21 14:39:28 -0700611 ASSERT_EQ(sdk, out);
Shane Farmer74cdea32017-05-12 16:22:36 -0700612}
613
Shane Farmer67e8a302017-12-06 14:39:10 -0800614TEST_F(ConfigurationParserTest, AndroidSdkGroupAction_SingleVersion) {
615 {
Shane Farmer78c43d72017-12-04 09:08:38 -0800616 const char* xml = "<android-sdk label='v19' minSdkVersion='19'></android-sdk>";
Shane Farmer67e8a302017-12-06 14:39:10 -0800617 auto doc = test::BuildXmlDom(xml);
618
619 PostProcessingConfiguration config;
Shane Farmer78c43d72017-12-04 09:08:38 -0800620 bool ok = AndroidSdkTagHandler(&config, NodeCast<Element>(doc.get()->root.get()), &diag_);
Shane Farmer67e8a302017-12-06 14:39:10 -0800621 ASSERT_TRUE(ok);
622
Shane Farmer78c43d72017-12-04 09:08:38 -0800623 ASSERT_EQ(1ul, config.android_sdks.size());
624 ASSERT_EQ(1u, config.android_sdks.count("v19"));
Shane Farmer67e8a302017-12-06 14:39:10 -0800625
Shane Farmer78c43d72017-12-04 09:08:38 -0800626 auto& out = config.android_sdks["v19"];
627 EXPECT_EQ(19, out.min_sdk_version);
Shane Farmer67e8a302017-12-06 14:39:10 -0800628 EXPECT_FALSE(out.max_sdk_version);
629 EXPECT_FALSE(out.target_sdk_version);
630 }
631
632 {
Shane Farmer78c43d72017-12-04 09:08:38 -0800633 const char* xml =
634 "<android-sdk label='v19' minSdkVersion='19' maxSdkVersion='19'></android-sdk>";
Shane Farmer67e8a302017-12-06 14:39:10 -0800635 auto doc = test::BuildXmlDom(xml);
636
637 PostProcessingConfiguration config;
Shane Farmer78c43d72017-12-04 09:08:38 -0800638 bool ok = AndroidSdkTagHandler(&config, NodeCast<Element>(doc.get()->root.get()), &diag_);
Shane Farmer67e8a302017-12-06 14:39:10 -0800639 ASSERT_TRUE(ok);
640
Shane Farmer78c43d72017-12-04 09:08:38 -0800641 ASSERT_EQ(1ul, config.android_sdks.size());
642 ASSERT_EQ(1u, config.android_sdks.count("v19"));
Shane Farmer67e8a302017-12-06 14:39:10 -0800643
Shane Farmer78c43d72017-12-04 09:08:38 -0800644 auto& out = config.android_sdks["v19"];
Shane Farmer67e8a302017-12-06 14:39:10 -0800645 EXPECT_EQ(19, out.max_sdk_version.value());
Shane Farmer78c43d72017-12-04 09:08:38 -0800646 EXPECT_EQ(19, out.min_sdk_version);
Shane Farmer67e8a302017-12-06 14:39:10 -0800647 EXPECT_FALSE(out.target_sdk_version);
648 }
649
650 {
Shane Farmer78c43d72017-12-04 09:08:38 -0800651 const char* xml =
652 "<android-sdk label='v19' minSdkVersion='19' targetSdkVersion='19'></android-sdk>";
Shane Farmer67e8a302017-12-06 14:39:10 -0800653 auto doc = test::BuildXmlDom(xml);
654
655 PostProcessingConfiguration config;
Shane Farmer78c43d72017-12-04 09:08:38 -0800656 bool ok = AndroidSdkTagHandler(&config, NodeCast<Element>(doc.get()->root.get()), &diag_);
Shane Farmer67e8a302017-12-06 14:39:10 -0800657 ASSERT_TRUE(ok);
658
Shane Farmer78c43d72017-12-04 09:08:38 -0800659 ASSERT_EQ(1ul, config.android_sdks.size());
660 ASSERT_EQ(1u, config.android_sdks.count("v19"));
Shane Farmer67e8a302017-12-06 14:39:10 -0800661
Shane Farmer78c43d72017-12-04 09:08:38 -0800662 auto& out = config.android_sdks["v19"];
Shane Farmer67e8a302017-12-06 14:39:10 -0800663 EXPECT_EQ(19, out.target_sdk_version.value());
Shane Farmer78c43d72017-12-04 09:08:38 -0800664 EXPECT_EQ(19, out.min_sdk_version);
Shane Farmer67e8a302017-12-06 14:39:10 -0800665 EXPECT_FALSE(out.max_sdk_version);
666 }
667}
668
669TEST_F(ConfigurationParserTest, AndroidSdkGroupAction_InvalidVersion) {
Shane Farmer3edd4722017-09-01 14:34:22 -0700670 static constexpr const char* xml = R"xml(
Shane Farmer78c43d72017-12-04 09:08:38 -0800671 <android-sdk
672 label="v19"
673 minSdkVersion="v19"
674 targetSdkVersion="v24"
675 maxSdkVersion="v25">
676 <manifest>
677 <!--- manifest additions here XSLT? TODO -->
678 </manifest>
679 </android-sdk>)xml";
Shane Farmer3edd4722017-09-01 14:34:22 -0700680
681 auto doc = test::BuildXmlDom(xml);
682
683 PostProcessingConfiguration config;
Shane Farmer78c43d72017-12-04 09:08:38 -0800684 bool ok = AndroidSdkTagHandler(&config, NodeCast<Element>(doc.get()->root.get()), &diag_);
Shane Farmer67e8a302017-12-06 14:39:10 -0800685 ASSERT_FALSE(ok);
686}
687
688TEST_F(ConfigurationParserTest, AndroidSdkGroupAction_NonNumeric) {
Ryan Mitchelleb9c9ac2018-08-09 09:18:26 -0700689 auto doc = test::BuildXmlDom(R"xml(
Shane Farmer67e8a302017-12-06 14:39:10 -0800690 <android-sdk
Ryan Mitchelleb9c9ac2018-08-09 09:18:26 -0700691 label="Q"
Shane Farmer67e8a302017-12-06 14:39:10 -0800692 minSdkVersion="25"
Ryan Mitchelleb9c9ac2018-08-09 09:18:26 -0700693 targetSdkVersion="Q"
694 maxSdkVersion="Q">
695 </android-sdk>)xml");
Shane Farmer67e8a302017-12-06 14:39:10 -0800696
697 PostProcessingConfiguration config;
Ryan Mitchelleb9c9ac2018-08-09 09:18:26 -0700698 ASSERT_TRUE(AndroidSdkTagHandler(&config, NodeCast<Element>(doc.get()->root.get()), &diag_));
Shane Farmer78c43d72017-12-04 09:08:38 -0800699 ASSERT_EQ(1ul, config.android_sdks.size());
Ryan Mitchelleb9c9ac2018-08-09 09:18:26 -0700700 ASSERT_EQ(1u, config.android_sdks.count("Q"));
Shane Farmer3edd4722017-09-01 14:34:22 -0700701
702 AndroidSdk sdk;
Shane Farmer67e8a302017-12-06 14:39:10 -0800703 sdk.min_sdk_version = 25;
Ryan Mitchelleb9c9ac2018-08-09 09:18:26 -0700704 sdk.target_sdk_version = 10000;
705 sdk.max_sdk_version = 10000;
706 ASSERT_EQ(sdk, config.android_sdks["Q"]);
Shane Farmer3edd4722017-09-01 14:34:22 -0700707}
708
Shane Farmer74cdea32017-05-12 16:22:36 -0700709TEST_F(ConfigurationParserTest, GlTextureGroupAction) {
710 static constexpr const char* xml = R"xml(
Shane Farmer11cdc1c2018-01-31 16:43:24 -0800711 <gl-texture-group label="dxt1" version-code-order="2">
Shane Farmer74cdea32017-05-12 16:22:36 -0700712 <gl-texture name="GL_EXT_texture_compression_dxt1">
713 <texture-path>assets/dxt1/main/*</texture-path>
714 <texture-path>
715 assets/dxt1/test/*
716 </texture-path>
717 </gl-texture>
718 </gl-texture-group>)xml";
719
720 auto doc = test::BuildXmlDom(xml);
721
Shane Farmer280be342017-06-21 15:20:15 -0700722 PostProcessingConfiguration config;
Shane Farmercb6c3f92017-11-27 13:19:36 -0800723 bool ok = GlTextureGroupTagHandler(&config, NodeCast<Element>(doc.get()->root.get()), &diag_);
Shane Farmer74cdea32017-05-12 16:22:36 -0700724 ASSERT_TRUE(ok);
725
Shane Farmercb6c3f92017-11-27 13:19:36 -0800726 EXPECT_THAT(config.gl_texture_groups, SizeIs(1ul));
Shane Farmer74cdea32017-05-12 16:22:36 -0700727 ASSERT_EQ(1u, config.gl_texture_groups.count("dxt1"));
728
Shane Farmer78c43d72017-12-04 09:08:38 -0800729 auto& out = config.gl_texture_groups["dxt1"].entry;
Shane Farmer74cdea32017-05-12 16:22:36 -0700730
731 GlTexture texture{
732 std::string("GL_EXT_texture_compression_dxt1"),
733 {"assets/dxt1/main/*", "assets/dxt1/test/*"}
734 };
735
736 ASSERT_EQ(1ul, out.size());
737 ASSERT_EQ(texture, out[0]);
738}
739
740TEST_F(ConfigurationParserTest, DeviceFeatureGroupAction) {
741 static constexpr const char* xml = R"xml(
Shane Farmer11cdc1c2018-01-31 16:43:24 -0800742 <device-feature-group label="low-latency" version-code-order="2">
Shane Farmer74cdea32017-05-12 16:22:36 -0700743 <supports-feature>android.hardware.audio.low_latency</supports-feature>
744 <supports-feature>
745 android.hardware.audio.pro
746 </supports-feature>
747 </device-feature-group>)xml";
748
749 auto doc = test::BuildXmlDom(xml);
750
Shane Farmer280be342017-06-21 15:20:15 -0700751 PostProcessingConfiguration config;
Shane Farmercb6c3f92017-11-27 13:19:36 -0800752 bool ok = DeviceFeatureGroupTagHandler(&config, NodeCast<Element>(doc.get()->root.get()), &diag_);
Shane Farmer74cdea32017-05-12 16:22:36 -0700753 ASSERT_TRUE(ok);
754
Shane Farmercb6c3f92017-11-27 13:19:36 -0800755 EXPECT_THAT(config.device_feature_groups, SizeIs(1ul));
Shane Farmer74cdea32017-05-12 16:22:36 -0700756 ASSERT_EQ(1u, config.device_feature_groups.count("low-latency"));
757
Shane Farmer78c43d72017-12-04 09:08:38 -0800758 auto& out = config.device_feature_groups["low-latency"].entry;
Shane Farmer74cdea32017-05-12 16:22:36 -0700759
760 DeviceFeature low_latency = "android.hardware.audio.low_latency";
761 DeviceFeature pro = "android.hardware.audio.pro";
762 ASSERT_THAT(out, ElementsAre(low_latency, pro));
763}
764
Shane Farmer11cdc1c2018-01-31 16:43:24 -0800765TEST_F(ConfigurationParserTest, Group_Valid) {
766 Group<int32_t> group;
767 group["item1"].order = 1;
768 group["item2"].order = 2;
769 group["item3"].order = 3;
770 group["item4"].order = 4;
771 group["item5"].order = 5;
772 group["item6"].order = 6;
773
774 EXPECT_TRUE(IsGroupValid(group, "test", &diag_));
775}
776
777TEST_F(ConfigurationParserTest, Group_OverlappingOrder) {
778 Group<int32_t> group;
779 group["item1"].order = 1;
780 group["item2"].order = 2;
781 group["item3"].order = 3;
782 group["item4"].order = 2;
783 group["item5"].order = 5;
784 group["item6"].order = 1;
785
786 EXPECT_FALSE(IsGroupValid(group, "test", &diag_));
787}
788
Shane Farmer1a21b8c2017-07-21 09:42:42 -0700789// Artifact name parser test cases.
790
Shane Farmer9f0e7f12017-06-22 12:26:44 -0700791TEST(ArtifactTest, Simple) {
792 StdErrDiagnostics diag;
Shane Farmercb6c3f92017-11-27 13:19:36 -0800793 ConfiguredArtifact x86;
Shane Farmer9f0e7f12017-06-22 12:26:44 -0700794 x86.abi_group = {"x86"};
795
Shane Farmer9ecc0752017-08-24 15:55:36 -0700796 auto x86_result = x86.ToArtifactName("something.${abi}.apk", "", &diag);
Shane Farmer9f0e7f12017-06-22 12:26:44 -0700797 ASSERT_TRUE(x86_result);
798 EXPECT_EQ(x86_result.value(), "something.x86.apk");
799
Shane Farmercb6c3f92017-11-27 13:19:36 -0800800 ConfiguredArtifact arm;
Shane Farmer9f0e7f12017-06-22 12:26:44 -0700801 arm.abi_group = {"armeabi-v7a"};
802
Shane Farmer9ecc0752017-08-24 15:55:36 -0700803 {
804 auto arm_result = arm.ToArtifactName("app.${abi}.apk", "", &diag);
805 ASSERT_TRUE(arm_result);
806 EXPECT_EQ(arm_result.value(), "app.armeabi-v7a.apk");
807 }
808
809 {
810 auto arm_result = arm.ToArtifactName("app.${abi}.apk", "different_name.apk", &diag);
811 ASSERT_TRUE(arm_result);
812 EXPECT_EQ(arm_result.value(), "app.armeabi-v7a.apk");
813 }
814
815 {
816 auto arm_result = arm.ToArtifactName("${basename}.${abi}.apk", "app.apk", &diag);
817 ASSERT_TRUE(arm_result);
818 EXPECT_EQ(arm_result.value(), "app.armeabi-v7a.apk");
819 }
820
821 {
822 auto arm_result = arm.ToArtifactName("app.${abi}.${ext}", "app.apk", &diag);
823 ASSERT_TRUE(arm_result);
824 EXPECT_EQ(arm_result.value(), "app.armeabi-v7a.apk");
825 }
Shane Farmer9f0e7f12017-06-22 12:26:44 -0700826}
827
828TEST(ArtifactTest, Complex) {
829 StdErrDiagnostics diag;
Shane Farmercb6c3f92017-11-27 13:19:36 -0800830 ConfiguredArtifact artifact;
Shane Farmer9f0e7f12017-06-22 12:26:44 -0700831 artifact.abi_group = {"mips64"};
832 artifact.screen_density_group = {"ldpi"};
833 artifact.device_feature_group = {"df1"};
834 artifact.gl_texture_group = {"glx1"};
835 artifact.locale_group = {"en-AU"};
Shane Farmer78c43d72017-12-04 09:08:38 -0800836 artifact.android_sdk = {"v26"};
Shane Farmer9f0e7f12017-06-22 12:26:44 -0700837
Shane Farmer9ecc0752017-08-24 15:55:36 -0700838 {
839 auto result = artifact.ToArtifactName(
Shane Farmerefe45392017-08-21 14:39:28 -0700840 "app.${density}_${locale}_${feature}_${gl}.${sdk}.${abi}.apk", "", &diag);
Shane Farmer9ecc0752017-08-24 15:55:36 -0700841 ASSERT_TRUE(result);
Shane Farmerefe45392017-08-21 14:39:28 -0700842 EXPECT_EQ(result.value(), "app.ldpi_en-AU_df1_glx1.v26.mips64.apk");
Shane Farmer9ecc0752017-08-24 15:55:36 -0700843 }
844
845 {
846 auto result = artifact.ToArtifactName(
Shane Farmerefe45392017-08-21 14:39:28 -0700847 "app.${density}_${locale}_${feature}_${gl}.${sdk}.${abi}.apk", "app.apk", &diag);
Shane Farmer9ecc0752017-08-24 15:55:36 -0700848 ASSERT_TRUE(result);
Shane Farmerefe45392017-08-21 14:39:28 -0700849 EXPECT_EQ(result.value(), "app.ldpi_en-AU_df1_glx1.v26.mips64.apk");
Shane Farmer9ecc0752017-08-24 15:55:36 -0700850 }
851
852 {
853 auto result = artifact.ToArtifactName(
Shane Farmerefe45392017-08-21 14:39:28 -0700854 "${basename}.${density}_${locale}_${feature}_${gl}.${sdk}.${abi}.apk", "app.apk", &diag);
Shane Farmer9ecc0752017-08-24 15:55:36 -0700855 ASSERT_TRUE(result);
Shane Farmerefe45392017-08-21 14:39:28 -0700856 EXPECT_EQ(result.value(), "app.ldpi_en-AU_df1_glx1.v26.mips64.apk");
Shane Farmer9ecc0752017-08-24 15:55:36 -0700857 }
858
859 {
860 auto result = artifact.ToArtifactName(
Shane Farmerefe45392017-08-21 14:39:28 -0700861 "app.${density}_${locale}_${feature}_${gl}.${sdk}.${abi}.${ext}", "app.apk", &diag);
Shane Farmer9ecc0752017-08-24 15:55:36 -0700862 ASSERT_TRUE(result);
Shane Farmerefe45392017-08-21 14:39:28 -0700863 EXPECT_EQ(result.value(), "app.ldpi_en-AU_df1_glx1.v26.mips64.apk");
Shane Farmer9ecc0752017-08-24 15:55:36 -0700864 }
865
866 {
867 auto result = artifact.ToArtifactName(
Shane Farmerefe45392017-08-21 14:39:28 -0700868 "${basename}.${density}_${locale}_${feature}_${gl}.${sdk}.${abi}", "app.apk", &diag);
Shane Farmer9ecc0752017-08-24 15:55:36 -0700869 ASSERT_TRUE(result);
Shane Farmerefe45392017-08-21 14:39:28 -0700870 EXPECT_EQ(result.value(), "app.ldpi_en-AU_df1_glx1.v26.mips64.apk");
Shane Farmer9ecc0752017-08-24 15:55:36 -0700871 }
Shane Farmer9f0e7f12017-06-22 12:26:44 -0700872}
873
874TEST(ArtifactTest, Missing) {
875 StdErrDiagnostics diag;
Shane Farmercb6c3f92017-11-27 13:19:36 -0800876 ConfiguredArtifact x86;
Shane Farmer9f0e7f12017-06-22 12:26:44 -0700877 x86.abi_group = {"x86"};
878
Shane Farmer9ecc0752017-08-24 15:55:36 -0700879 EXPECT_FALSE(x86.ToArtifactName("something.${density}.apk", "", &diag));
880 EXPECT_FALSE(x86.ToArtifactName("something.apk", "", &diag));
881 EXPECT_FALSE(x86.ToArtifactName("something.${density}.apk", "something.apk", &diag));
882 EXPECT_FALSE(x86.ToArtifactName("something.apk", "something.apk", &diag));
Shane Farmer9f0e7f12017-06-22 12:26:44 -0700883}
884
885TEST(ArtifactTest, Empty) {
886 StdErrDiagnostics diag;
Shane Farmercb6c3f92017-11-27 13:19:36 -0800887 ConfiguredArtifact artifact;
Shane Farmer9f0e7f12017-06-22 12:26:44 -0700888
Shane Farmer9ecc0752017-08-24 15:55:36 -0700889 EXPECT_FALSE(artifact.ToArtifactName("something.${density}.apk", "", &diag));
890 EXPECT_TRUE(artifact.ToArtifactName("something.apk", "", &diag));
891 EXPECT_FALSE(artifact.ToArtifactName("something.${density}.apk", "something.apk", &diag));
892 EXPECT_TRUE(artifact.ToArtifactName("something.apk", "something.apk", &diag));
Shane Farmer9f0e7f12017-06-22 12:26:44 -0700893}
894
Shane Farmer1a21b8c2017-07-21 09:42:42 -0700895TEST(ArtifactTest, Repeated) {
896 StdErrDiagnostics diag;
Shane Farmercb6c3f92017-11-27 13:19:36 -0800897 ConfiguredArtifact artifact;
Shane Farmer1a21b8c2017-07-21 09:42:42 -0700898 artifact.screen_density_group = {"mdpi"};
899
Shane Farmer9ecc0752017-08-24 15:55:36 -0700900 ASSERT_TRUE(artifact.ToArtifactName("something.${density}.apk", "", &diag));
901 EXPECT_FALSE(artifact.ToArtifactName("something.${density}.${density}.apk", "", &diag));
902 ASSERT_TRUE(artifact.ToArtifactName("something.${density}.apk", "something.apk", &diag));
Shane Farmer1a21b8c2017-07-21 09:42:42 -0700903}
904
905TEST(ArtifactTest, Nesting) {
906 StdErrDiagnostics diag;
Shane Farmercb6c3f92017-11-27 13:19:36 -0800907 ConfiguredArtifact x86;
Shane Farmer1a21b8c2017-07-21 09:42:42 -0700908 x86.abi_group = {"x86"};
909
Shane Farmer9ecc0752017-08-24 15:55:36 -0700910 EXPECT_FALSE(x86.ToArtifactName("something.${abi${density}}.apk", "", &diag));
Shane Farmer1a21b8c2017-07-21 09:42:42 -0700911
Ryan Mitchell4382e442021-07-14 12:53:01 -0700912 const std::optional<std::string>& name =
913 x86.ToArtifactName("something.${abi${abi}}.apk", "", &diag);
Shane Farmer0a5b2012017-06-22 12:24:12 -0700914 ASSERT_TRUE(name);
915 EXPECT_EQ(name.value(), "something.${abix86}.apk");
Shane Farmer1a21b8c2017-07-21 09:42:42 -0700916}
917
918TEST(ArtifactTest, Recursive) {
919 StdErrDiagnostics diag;
Shane Farmercb6c3f92017-11-27 13:19:36 -0800920 ConfiguredArtifact artifact;
Shane Farmer0a5b2012017-06-22 12:24:12 -0700921 artifact.device_feature_group = {"${gl}"};
Shane Farmer1a21b8c2017-07-21 09:42:42 -0700922 artifact.gl_texture_group = {"glx1"};
923
Shane Farmer9ecc0752017-08-24 15:55:36 -0700924 EXPECT_FALSE(artifact.ToArtifactName("app.${feature}.${gl}.apk", "", &diag));
Shane Farmer1a21b8c2017-07-21 09:42:42 -0700925
926 artifact.device_feature_group = {"df1"};
Shane Farmer0a5b2012017-06-22 12:24:12 -0700927 artifact.gl_texture_group = {"${feature}"};
Shane Farmer1a21b8c2017-07-21 09:42:42 -0700928 {
Shane Farmer9ecc0752017-08-24 15:55:36 -0700929 const auto& result = artifact.ToArtifactName("app.${feature}.${gl}.apk", "", &diag);
Shane Farmer0a5b2012017-06-22 12:24:12 -0700930 ASSERT_TRUE(result);
931 EXPECT_EQ(result.value(), "app.df1.${feature}.apk");
Shane Farmer1a21b8c2017-07-21 09:42:42 -0700932 }
933
934 // This is an invalid case, but should be the only possible case due to the ordering of
935 // replacement.
Shane Farmer0a5b2012017-06-22 12:24:12 -0700936 artifact.device_feature_group = {"${gl}"};
Shane Farmer1a21b8c2017-07-21 09:42:42 -0700937 artifact.gl_texture_group = {"glx1"};
938 {
Shane Farmer9ecc0752017-08-24 15:55:36 -0700939 const auto& result = artifact.ToArtifactName("app.${feature}.apk", "", &diag);
Shane Farmer0a5b2012017-06-22 12:24:12 -0700940 ASSERT_TRUE(result);
Shane Farmer1a21b8c2017-07-21 09:42:42 -0700941 EXPECT_EQ(result.value(), "app.glx1.apk");
942 }
943}
944
Shane Farmer74cdea32017-05-12 16:22:36 -0700945} // namespace
Shane Farmercb6c3f92017-11-27 13:19:36 -0800946} // namespace handler
947} // namespace configuration
Shane Farmer74cdea32017-05-12 16:22:36 -0700948} // namespace aapt