blob: 7ffb3d515079ea1ebd076c0b73d2fe864f3d3267 [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 Farmer74cdea32017-05-12 16:22:36 -070021#include "androidfw/ResourceTypes.h"
22
23#include "test/Test.h"
24#include "xml/XmlDom.h"
25
26namespace aapt {
27namespace {
28
Adam Lesinski6b372992017-08-09 10:54:23 -070029using ::android::ResTable_config;
Shane Farmer74cdea32017-05-12 16:22:36 -070030using configuration::Abi;
31using configuration::AndroidSdk;
Shane Farmer9f0e7f12017-06-22 12:26:44 -070032using configuration::Artifact;
Shane Farmer280be342017-06-21 15:20:15 -070033using configuration::PostProcessingConfiguration;
Shane Farmer74cdea32017-05-12 16:22:36 -070034using configuration::DeviceFeature;
35using configuration::GlTexture;
36using configuration::Locale;
37using configuration::AndroidManifest;
Adam Lesinski6b372992017-08-09 10:54:23 -070038using ::testing::ElementsAre;
Shane Farmer74cdea32017-05-12 16:22:36 -070039using xml::Element;
40using xml::NodeCast;
41
42constexpr const char* kValidConfig = R"(<?xml version="1.0" encoding="utf-8" ?>
43<post-process xmlns="http://schemas.android.com/tools/aapt">
44 <groups>
45 <abi-group label="arm">
46 <abi>armeabi-v7a</abi>
47 <abi>arm64-v8a</abi>
48 </abi-group>
49 <abi-group label="other">
50 <abi>x86</abi>
51 <abi>mips</abi>
52 </abi-group>
53 <screen-density-group label="large">
54 <screen-density>xhdpi</screen-density>
55 <screen-density>xxhdpi</screen-density>
56 <screen-density>xxxhdpi</screen-density>
57 </screen-density-group>
58 <screen-density-group label="alldpi">
59 <screen-density>ldpi</screen-density>
60 <screen-density>mdpi</screen-density>
61 <screen-density>hdpi</screen-density>
62 <screen-density>xhdpi</screen-density>
63 <screen-density>xxhdpi</screen-density>
64 <screen-density>xxxhdpi</screen-density>
65 </screen-density-group>
66 <locale-group label="europe">
Shane Farmer0a5b2012017-06-22 12:24:12 -070067 <locale>en</locale>
68 <locale>es</locale>
69 <locale>fr</locale>
70 <locale>de</locale>
Shane Farmer74cdea32017-05-12 16:22:36 -070071 </locale-group>
72 <locale-group label="north-america">
Shane Farmer0a5b2012017-06-22 12:24:12 -070073 <locale>en</locale>
74 <locale>es-rMX</locale>
75 <locale>fr-rCA</locale>
Shane Farmer74cdea32017-05-12 16:22:36 -070076 </locale-group>
Shane Farmerefe45392017-08-21 14:39:28 -070077 <android-sdk-group label="v19">
Shane Farmer74cdea32017-05-12 16:22:36 -070078 <android-sdk
Shane Farmerefe45392017-08-21 14:39:28 -070079 minSdkVersion="v19"
80 targetSdkVersion="v24"
81 maxSdkVersion="v25">
Shane Farmer74cdea32017-05-12 16:22:36 -070082 <manifest>
83 <!--- manifest additions here XSLT? TODO -->
84 </manifest>
85 </android-sdk>
86 </android-sdk-group>
87 <gl-texture-group label="dxt1">
88 <gl-texture name="GL_EXT_texture_compression_dxt1">
89 <texture-path>assets/dxt1/*</texture-path>
90 </gl-texture>
91 </gl-texture-group>
92 <device-feature-group label="low-latency">
93 <supports-feature>android.hardware.audio.low_latency</supports-feature>
94 </device-feature-group>
95 </groups>
96 <artifacts>
97 <artifact-format>
98 ${base}.${abi}.${screen-density}.${locale}.${sdk}.${gl}.${feature}.release
99 </artifact-format>
100 <artifact
101 name="art1"
102 abi-group="arm"
103 screen-density-group="large"
104 locale-group="europe"
Shane Farmerefe45392017-08-21 14:39:28 -0700105 android-sdk-group="v19"
Shane Farmer74cdea32017-05-12 16:22:36 -0700106 gl-texture-group="dxt1"
107 device-feature-group="low-latency"/>
108 <artifact
109 name="art2"
110 abi-group="other"
111 screen-density-group="alldpi"
112 locale-group="north-america"
Shane Farmerefe45392017-08-21 14:39:28 -0700113 android-sdk-group="v19"
Shane Farmer74cdea32017-05-12 16:22:36 -0700114 gl-texture-group="dxt1"
115 device-feature-group="low-latency"/>
116 </artifacts>
117</post-process>
118)";
119
120class ConfigurationParserTest : public ConfigurationParser, public ::testing::Test {
121 public:
122 ConfigurationParserTest() : ConfigurationParser("") {}
123
124 protected:
125 StdErrDiagnostics diag_;
126};
127
Shane Farmerb1027272017-06-14 09:10:28 -0700128TEST_F(ConfigurationParserTest, ForPath_NoFile) {
129 auto result = ConfigurationParser::ForPath("./does_not_exist.xml");
130 EXPECT_FALSE(result);
131}
132
Shane Farmer74cdea32017-05-12 16:22:36 -0700133TEST_F(ConfigurationParserTest, ValidateFile) {
134 auto parser = ConfigurationParser::ForContents(kValidConfig).WithDiagnostics(&diag_);
135 auto result = parser.Parse();
136 ASSERT_TRUE(result);
Shane Farmer280be342017-06-21 15:20:15 -0700137 PostProcessingConfiguration& value = result.value();
Shane Farmer74cdea32017-05-12 16:22:36 -0700138 EXPECT_EQ(2ul, value.artifacts.size());
139 ASSERT_TRUE(value.artifact_format);
140 EXPECT_EQ(
141 "${base}.${abi}.${screen-density}.${locale}.${sdk}.${gl}.${feature}.release",
142 value.artifact_format.value()
143 );
144
145 EXPECT_EQ(2ul, value.abi_groups.size());
146 EXPECT_EQ(2ul, value.abi_groups["arm"].size());
147 EXPECT_EQ(2ul, value.abi_groups["other"].size());
148
149 EXPECT_EQ(2ul, value.screen_density_groups.size());
150 EXPECT_EQ(3ul, value.screen_density_groups["large"].size());
151 EXPECT_EQ(6ul, value.screen_density_groups["alldpi"].size());
152
Shane Farmer0a5b2012017-06-22 12:24:12 -0700153 EXPECT_EQ(2ul, value.locale_groups.size());
Shane Farmer74cdea32017-05-12 16:22:36 -0700154 EXPECT_EQ(4ul, value.locale_groups["europe"].size());
155 EXPECT_EQ(3ul, value.locale_groups["north-america"].size());
Shane Farmer74cdea32017-05-12 16:22:36 -0700156
157 EXPECT_EQ(1ul, value.android_sdk_groups.size());
Shane Farmerefe45392017-08-21 14:39:28 -0700158 EXPECT_TRUE(value.android_sdk_groups["v19"].min_sdk_version);
159 EXPECT_EQ("v19", value.android_sdk_groups["v19"].min_sdk_version.value());
Shane Farmer74cdea32017-05-12 16:22:36 -0700160
161 EXPECT_EQ(1ul, value.gl_texture_groups.size());
162 EXPECT_EQ(1ul, value.gl_texture_groups["dxt1"].size());
163
164 EXPECT_EQ(1ul, value.device_feature_groups.size());
165 EXPECT_EQ(1ul, value.device_feature_groups["low-latency"].size());
166}
167
168TEST_F(ConfigurationParserTest, InvalidNamespace) {
169 constexpr const char* invalid_ns = R"(<?xml version="1.0" encoding="utf-8" ?>
170 <post-process xmlns="http://schemas.android.com/tools/another-unknown-tool" />)";
171
172 auto result = ConfigurationParser::ForContents(invalid_ns).Parse();
173 ASSERT_FALSE(result);
174}
175
176TEST_F(ConfigurationParserTest, ArtifactAction) {
177 static constexpr const char* xml = R"xml(
178 <artifact
179 abi-group="arm"
180 screen-density-group="large"
181 locale-group="europe"
Shane Farmerefe45392017-08-21 14:39:28 -0700182 android-sdk-group="v19"
Shane Farmer74cdea32017-05-12 16:22:36 -0700183 gl-texture-group="dxt1"
184 device-feature-group="low-latency"/>)xml";
185
186 auto doc = test::BuildXmlDom(xml);
187
Shane Farmer280be342017-06-21 15:20:15 -0700188 PostProcessingConfiguration config;
Adam Lesinski6b372992017-08-09 10:54:23 -0700189 bool ok = artifact_handler_(&config, NodeCast<Element>(doc->root.get()), &diag_);
Shane Farmer74cdea32017-05-12 16:22:36 -0700190 ASSERT_TRUE(ok);
191
192 EXPECT_EQ(1ul, config.artifacts.size());
193
Shane Farmer57669432017-06-19 12:52:04 -0700194 auto& artifact = config.artifacts.front();
Shane Farmer0a5b2012017-06-22 12:24:12 -0700195 EXPECT_FALSE(artifact.name); // TODO: make this fail.
Shane Farmer74cdea32017-05-12 16:22:36 -0700196 EXPECT_EQ("arm", artifact.abi_group.value());
197 EXPECT_EQ("large", artifact.screen_density_group.value());
198 EXPECT_EQ("europe", artifact.locale_group.value());
Shane Farmerefe45392017-08-21 14:39:28 -0700199 EXPECT_EQ("v19", artifact.android_sdk_group.value());
Shane Farmer74cdea32017-05-12 16:22:36 -0700200 EXPECT_EQ("dxt1", artifact.gl_texture_group.value());
201 EXPECT_EQ("low-latency", artifact.device_feature_group.value());
Shane Farmer57669432017-06-19 12:52:04 -0700202
203 // Perform a second action to ensure we get 2 artifacts.
204 static constexpr const char* second = R"xml(
205 <artifact
206 abi-group="other"
207 screen-density-group="large"
208 locale-group="europe"
Shane Farmerefe45392017-08-21 14:39:28 -0700209 android-sdk-group="v19"
Shane Farmer57669432017-06-19 12:52:04 -0700210 gl-texture-group="dxt1"
211 device-feature-group="low-latency"/>)xml";
212 doc = test::BuildXmlDom(second);
213
214 ok = artifact_handler_(&config, NodeCast<Element>(doc.get()->root.get()), &diag_);
215 ASSERT_TRUE(ok);
216 EXPECT_EQ(2ul, config.artifacts.size());
Shane Farmer74cdea32017-05-12 16:22:36 -0700217}
218
219TEST_F(ConfigurationParserTest, ArtifactFormatAction) {
220 static constexpr const char* xml = R"xml(
221 <artifact-format>
222 ${base}.${abi}.${screen-density}.${locale}.${sdk}.${gl}.${feature}.release
223 </artifact-format>)xml";
224
225 auto doc = test::BuildXmlDom(xml);
226
Shane Farmer280be342017-06-21 15:20:15 -0700227 PostProcessingConfiguration config;
Shane Farmer74cdea32017-05-12 16:22:36 -0700228 bool ok = artifact_format_handler_(&config, NodeCast<Element>(doc.get()->root.get()), &diag_);
229 ASSERT_TRUE(ok);
230 ASSERT_TRUE(config.artifact_format);
231 EXPECT_EQ(
232 "${base}.${abi}.${screen-density}.${locale}.${sdk}.${gl}.${feature}.release",
233 static_cast<std::string>(config.artifact_format.value())
234 );
235}
236
237TEST_F(ConfigurationParserTest, AbiGroupAction) {
238 static constexpr const char* xml = R"xml(
239 <abi-group label="arm">
240 <!-- First comment. -->
241 <abi>
242 armeabi-v7a
243 </abi>
244 <!-- Another comment. -->
245 <abi>arm64-v8a</abi>
246 </abi-group>)xml";
247
248 auto doc = test::BuildXmlDom(xml);
249
Shane Farmer280be342017-06-21 15:20:15 -0700250 PostProcessingConfiguration config;
Shane Farmer74cdea32017-05-12 16:22:36 -0700251 bool ok = abi_group_handler_(&config, NodeCast<Element>(doc.get()->root.get()), &diag_);
252 ASSERT_TRUE(ok);
253
254 EXPECT_EQ(1ul, config.abi_groups.size());
255 ASSERT_EQ(1u, config.abi_groups.count("arm"));
256
257 auto& out = config.abi_groups["arm"];
258 ASSERT_THAT(out, ElementsAre(Abi::kArmV7a, Abi::kArm64V8a));
259}
260
261TEST_F(ConfigurationParserTest, ScreenDensityGroupAction) {
262 static constexpr const char* xml = R"xml(
263 <screen-density-group label="large">
264 <screen-density>xhdpi</screen-density>
265 <screen-density>
266 xxhdpi
267 </screen-density>
268 <screen-density>xxxhdpi</screen-density>
269 </screen-density-group>)xml";
270
271 auto doc = test::BuildXmlDom(xml);
272
Shane Farmer280be342017-06-21 15:20:15 -0700273 PostProcessingConfiguration config;
Shane Farmer74cdea32017-05-12 16:22:36 -0700274 bool ok =
275 screen_density_group_handler_(&config, NodeCast<Element>(doc.get()->root.get()), &diag_);
276 ASSERT_TRUE(ok);
277
278 EXPECT_EQ(1ul, config.screen_density_groups.size());
279 ASSERT_EQ(1u, config.screen_density_groups.count("large"));
280
281 ConfigDescription xhdpi;
282 xhdpi.density = ResTable_config::DENSITY_XHIGH;
283 ConfigDescription xxhdpi;
284 xxhdpi.density = ResTable_config::DENSITY_XXHIGH;
285 ConfigDescription xxxhdpi;
286 xxxhdpi.density = ResTable_config::DENSITY_XXXHIGH;
287
288 auto& out = config.screen_density_groups["large"];
289 ASSERT_THAT(out, ElementsAre(xhdpi, xxhdpi, xxxhdpi));
290}
291
292TEST_F(ConfigurationParserTest, LocaleGroupAction) {
293 static constexpr const char* xml = R"xml(
294 <locale-group label="europe">
Shane Farmer0a5b2012017-06-22 12:24:12 -0700295 <locale>en</locale>
296 <locale>es</locale>
297 <locale>fr</locale>
298 <locale>de</locale>
Shane Farmer74cdea32017-05-12 16:22:36 -0700299 </locale-group>)xml";
300
301 auto doc = test::BuildXmlDom(xml);
302
Shane Farmer280be342017-06-21 15:20:15 -0700303 PostProcessingConfiguration config;
Shane Farmer74cdea32017-05-12 16:22:36 -0700304 bool ok = locale_group_handler_(&config, NodeCast<Element>(doc.get()->root.get()), &diag_);
305 ASSERT_TRUE(ok);
306
307 ASSERT_EQ(1ul, config.locale_groups.size());
308 ASSERT_EQ(1u, config.locale_groups.count("europe"));
309
Shane Farmer0a5b2012017-06-22 12:24:12 -0700310 const auto& out = config.locale_groups["europe"];
Shane Farmer74cdea32017-05-12 16:22:36 -0700311
Shane Farmer0a5b2012017-06-22 12:24:12 -0700312 ConfigDescription en = test::ParseConfigOrDie("en");
313 ConfigDescription es = test::ParseConfigOrDie("es");
314 ConfigDescription fr = test::ParseConfigOrDie("fr");
315 ConfigDescription de = test::ParseConfigOrDie("de");
Shane Farmer74cdea32017-05-12 16:22:36 -0700316
317 ASSERT_THAT(out, ElementsAre(en, es, fr, de));
318}
319
320TEST_F(ConfigurationParserTest, AndroidSdkGroupAction) {
321 static constexpr const char* xml = R"xml(
Shane Farmerefe45392017-08-21 14:39:28 -0700322 <android-sdk-group label="v19">
Shane Farmer74cdea32017-05-12 16:22:36 -0700323 <android-sdk
Shane Farmerefe45392017-08-21 14:39:28 -0700324 minSdkVersion="v19"
325 targetSdkVersion="v24"
326 maxSdkVersion="v25">
Shane Farmer74cdea32017-05-12 16:22:36 -0700327 <manifest>
328 <!--- manifest additions here XSLT? TODO -->
329 </manifest>
330 </android-sdk>
331 </android-sdk-group>)xml";
332
333 auto doc = test::BuildXmlDom(xml);
334
Shane Farmer280be342017-06-21 15:20:15 -0700335 PostProcessingConfiguration config;
Shane Farmer74cdea32017-05-12 16:22:36 -0700336 bool ok = android_sdk_group_handler_(&config, NodeCast<Element>(doc.get()->root.get()), &diag_);
337 ASSERT_TRUE(ok);
338
339 ASSERT_EQ(1ul, config.android_sdk_groups.size());
Shane Farmerefe45392017-08-21 14:39:28 -0700340 ASSERT_EQ(1u, config.android_sdk_groups.count("v19"));
Shane Farmer74cdea32017-05-12 16:22:36 -0700341
Shane Farmerefe45392017-08-21 14:39:28 -0700342 auto& out = config.android_sdk_groups["v19"];
Shane Farmer74cdea32017-05-12 16:22:36 -0700343
344 AndroidSdk sdk;
Shane Farmerefe45392017-08-21 14:39:28 -0700345 sdk.min_sdk_version = std::string("v19");
346 sdk.target_sdk_version = std::string("v24");
347 sdk.max_sdk_version = std::string("v25");
Shane Farmer74cdea32017-05-12 16:22:36 -0700348 sdk.manifest = AndroidManifest();
349
Shane Farmerefe45392017-08-21 14:39:28 -0700350 ASSERT_EQ(sdk, out);
Shane Farmer74cdea32017-05-12 16:22:36 -0700351}
352
353TEST_F(ConfigurationParserTest, GlTextureGroupAction) {
354 static constexpr const char* xml = R"xml(
355 <gl-texture-group label="dxt1">
356 <gl-texture name="GL_EXT_texture_compression_dxt1">
357 <texture-path>assets/dxt1/main/*</texture-path>
358 <texture-path>
359 assets/dxt1/test/*
360 </texture-path>
361 </gl-texture>
362 </gl-texture-group>)xml";
363
364 auto doc = test::BuildXmlDom(xml);
365
Shane Farmer280be342017-06-21 15:20:15 -0700366 PostProcessingConfiguration config;
Shane Farmer74cdea32017-05-12 16:22:36 -0700367 bool ok = gl_texture_group_handler_(&config, NodeCast<Element>(doc.get()->root.get()), &diag_);
368 ASSERT_TRUE(ok);
369
370 EXPECT_EQ(1ul, config.gl_texture_groups.size());
371 ASSERT_EQ(1u, config.gl_texture_groups.count("dxt1"));
372
373 auto& out = config.gl_texture_groups["dxt1"];
374
375 GlTexture texture{
376 std::string("GL_EXT_texture_compression_dxt1"),
377 {"assets/dxt1/main/*", "assets/dxt1/test/*"}
378 };
379
380 ASSERT_EQ(1ul, out.size());
381 ASSERT_EQ(texture, out[0]);
382}
383
384TEST_F(ConfigurationParserTest, DeviceFeatureGroupAction) {
385 static constexpr const char* xml = R"xml(
386 <device-feature-group label="low-latency">
387 <supports-feature>android.hardware.audio.low_latency</supports-feature>
388 <supports-feature>
389 android.hardware.audio.pro
390 </supports-feature>
391 </device-feature-group>)xml";
392
393 auto doc = test::BuildXmlDom(xml);
394
Shane Farmer280be342017-06-21 15:20:15 -0700395 PostProcessingConfiguration config;
Shane Farmer74cdea32017-05-12 16:22:36 -0700396 bool ok
397 = device_feature_group_handler_(&config, NodeCast<Element>(doc.get()->root.get()), &diag_);
398 ASSERT_TRUE(ok);
399
400 EXPECT_EQ(1ul, config.device_feature_groups.size());
401 ASSERT_EQ(1u, config.device_feature_groups.count("low-latency"));
402
403 auto& out = config.device_feature_groups["low-latency"];
404
405 DeviceFeature low_latency = "android.hardware.audio.low_latency";
406 DeviceFeature pro = "android.hardware.audio.pro";
407 ASSERT_THAT(out, ElementsAre(low_latency, pro));
408}
409
Shane Farmer1a21b8c2017-07-21 09:42:42 -0700410// Artifact name parser test cases.
411
Shane Farmer9f0e7f12017-06-22 12:26:44 -0700412TEST(ArtifactTest, Simple) {
413 StdErrDiagnostics diag;
414 Artifact x86;
415 x86.abi_group = {"x86"};
416
Shane Farmer9ecc0752017-08-24 15:55:36 -0700417 auto x86_result = x86.ToArtifactName("something.${abi}.apk", "", &diag);
Shane Farmer9f0e7f12017-06-22 12:26:44 -0700418 ASSERT_TRUE(x86_result);
419 EXPECT_EQ(x86_result.value(), "something.x86.apk");
420
421 Artifact arm;
422 arm.abi_group = {"armeabi-v7a"};
423
Shane Farmer9ecc0752017-08-24 15:55:36 -0700424 {
425 auto arm_result = arm.ToArtifactName("app.${abi}.apk", "", &diag);
426 ASSERT_TRUE(arm_result);
427 EXPECT_EQ(arm_result.value(), "app.armeabi-v7a.apk");
428 }
429
430 {
431 auto arm_result = arm.ToArtifactName("app.${abi}.apk", "different_name.apk", &diag);
432 ASSERT_TRUE(arm_result);
433 EXPECT_EQ(arm_result.value(), "app.armeabi-v7a.apk");
434 }
435
436 {
437 auto arm_result = arm.ToArtifactName("${basename}.${abi}.apk", "app.apk", &diag);
438 ASSERT_TRUE(arm_result);
439 EXPECT_EQ(arm_result.value(), "app.armeabi-v7a.apk");
440 }
441
442 {
443 auto arm_result = arm.ToArtifactName("app.${abi}.${ext}", "app.apk", &diag);
444 ASSERT_TRUE(arm_result);
445 EXPECT_EQ(arm_result.value(), "app.armeabi-v7a.apk");
446 }
Shane Farmer9f0e7f12017-06-22 12:26:44 -0700447}
448
449TEST(ArtifactTest, Complex) {
450 StdErrDiagnostics diag;
451 Artifact artifact;
452 artifact.abi_group = {"mips64"};
453 artifact.screen_density_group = {"ldpi"};
454 artifact.device_feature_group = {"df1"};
455 artifact.gl_texture_group = {"glx1"};
456 artifact.locale_group = {"en-AU"};
Shane Farmerefe45392017-08-21 14:39:28 -0700457 artifact.android_sdk_group = {"v26"};
Shane Farmer9f0e7f12017-06-22 12:26:44 -0700458
Shane Farmer9ecc0752017-08-24 15:55:36 -0700459 {
460 auto result = artifact.ToArtifactName(
Shane Farmerefe45392017-08-21 14:39:28 -0700461 "app.${density}_${locale}_${feature}_${gl}.${sdk}.${abi}.apk", "", &diag);
Shane Farmer9ecc0752017-08-24 15:55:36 -0700462 ASSERT_TRUE(result);
Shane Farmerefe45392017-08-21 14:39:28 -0700463 EXPECT_EQ(result.value(), "app.ldpi_en-AU_df1_glx1.v26.mips64.apk");
Shane Farmer9ecc0752017-08-24 15:55:36 -0700464 }
465
466 {
467 auto result = artifact.ToArtifactName(
Shane Farmerefe45392017-08-21 14:39:28 -0700468 "app.${density}_${locale}_${feature}_${gl}.${sdk}.${abi}.apk", "app.apk", &diag);
Shane Farmer9ecc0752017-08-24 15:55:36 -0700469 ASSERT_TRUE(result);
Shane Farmerefe45392017-08-21 14:39:28 -0700470 EXPECT_EQ(result.value(), "app.ldpi_en-AU_df1_glx1.v26.mips64.apk");
Shane Farmer9ecc0752017-08-24 15:55:36 -0700471 }
472
473 {
474 auto result = artifact.ToArtifactName(
Shane Farmerefe45392017-08-21 14:39:28 -0700475 "${basename}.${density}_${locale}_${feature}_${gl}.${sdk}.${abi}.apk", "app.apk", &diag);
Shane Farmer9ecc0752017-08-24 15:55:36 -0700476 ASSERT_TRUE(result);
Shane Farmerefe45392017-08-21 14:39:28 -0700477 EXPECT_EQ(result.value(), "app.ldpi_en-AU_df1_glx1.v26.mips64.apk");
Shane Farmer9ecc0752017-08-24 15:55:36 -0700478 }
479
480 {
481 auto result = artifact.ToArtifactName(
Shane Farmerefe45392017-08-21 14:39:28 -0700482 "app.${density}_${locale}_${feature}_${gl}.${sdk}.${abi}.${ext}", "app.apk", &diag);
Shane Farmer9ecc0752017-08-24 15:55:36 -0700483 ASSERT_TRUE(result);
Shane Farmerefe45392017-08-21 14:39:28 -0700484 EXPECT_EQ(result.value(), "app.ldpi_en-AU_df1_glx1.v26.mips64.apk");
Shane Farmer9ecc0752017-08-24 15:55:36 -0700485 }
486
487 {
488 auto result = artifact.ToArtifactName(
Shane Farmerefe45392017-08-21 14:39:28 -0700489 "${basename}.${density}_${locale}_${feature}_${gl}.${sdk}.${abi}", "app.apk", &diag);
Shane Farmer9ecc0752017-08-24 15:55:36 -0700490 ASSERT_TRUE(result);
Shane Farmerefe45392017-08-21 14:39:28 -0700491 EXPECT_EQ(result.value(), "app.ldpi_en-AU_df1_glx1.v26.mips64.apk");
Shane Farmer9ecc0752017-08-24 15:55:36 -0700492 }
Shane Farmer9f0e7f12017-06-22 12:26:44 -0700493}
494
495TEST(ArtifactTest, Missing) {
496 StdErrDiagnostics diag;
497 Artifact x86;
498 x86.abi_group = {"x86"};
499
Shane Farmer9ecc0752017-08-24 15:55:36 -0700500 EXPECT_FALSE(x86.ToArtifactName("something.${density}.apk", "", &diag));
501 EXPECT_FALSE(x86.ToArtifactName("something.apk", "", &diag));
502 EXPECT_FALSE(x86.ToArtifactName("something.${density}.apk", "something.apk", &diag));
503 EXPECT_FALSE(x86.ToArtifactName("something.apk", "something.apk", &diag));
Shane Farmer9f0e7f12017-06-22 12:26:44 -0700504}
505
506TEST(ArtifactTest, Empty) {
507 StdErrDiagnostics diag;
508 Artifact artifact;
509
Shane Farmer9ecc0752017-08-24 15:55:36 -0700510 EXPECT_FALSE(artifact.ToArtifactName("something.${density}.apk", "", &diag));
511 EXPECT_TRUE(artifact.ToArtifactName("something.apk", "", &diag));
512 EXPECT_FALSE(artifact.ToArtifactName("something.${density}.apk", "something.apk", &diag));
513 EXPECT_TRUE(artifact.ToArtifactName("something.apk", "something.apk", &diag));
Shane Farmer9f0e7f12017-06-22 12:26:44 -0700514}
515
Shane Farmer1a21b8c2017-07-21 09:42:42 -0700516TEST(ArtifactTest, Repeated) {
517 StdErrDiagnostics diag;
518 Artifact artifact;
519 artifact.screen_density_group = {"mdpi"};
520
Shane Farmer9ecc0752017-08-24 15:55:36 -0700521 ASSERT_TRUE(artifact.ToArtifactName("something.${density}.apk", "", &diag));
522 EXPECT_FALSE(artifact.ToArtifactName("something.${density}.${density}.apk", "", &diag));
523 ASSERT_TRUE(artifact.ToArtifactName("something.${density}.apk", "something.apk", &diag));
Shane Farmer1a21b8c2017-07-21 09:42:42 -0700524}
525
526TEST(ArtifactTest, Nesting) {
527 StdErrDiagnostics diag;
528 Artifact x86;
529 x86.abi_group = {"x86"};
530
Shane Farmer9ecc0752017-08-24 15:55:36 -0700531 EXPECT_FALSE(x86.ToArtifactName("something.${abi${density}}.apk", "", &diag));
Shane Farmer1a21b8c2017-07-21 09:42:42 -0700532
Shane Farmer9ecc0752017-08-24 15:55:36 -0700533 const Maybe<std::string>& name = x86.ToArtifactName("something.${abi${abi}}.apk", "", &diag);
Shane Farmer0a5b2012017-06-22 12:24:12 -0700534 ASSERT_TRUE(name);
535 EXPECT_EQ(name.value(), "something.${abix86}.apk");
Shane Farmer1a21b8c2017-07-21 09:42:42 -0700536}
537
538TEST(ArtifactTest, Recursive) {
539 StdErrDiagnostics diag;
540 Artifact artifact;
Shane Farmer0a5b2012017-06-22 12:24:12 -0700541 artifact.device_feature_group = {"${gl}"};
Shane Farmer1a21b8c2017-07-21 09:42:42 -0700542 artifact.gl_texture_group = {"glx1"};
543
Shane Farmer9ecc0752017-08-24 15:55:36 -0700544 EXPECT_FALSE(artifact.ToArtifactName("app.${feature}.${gl}.apk", "", &diag));
Shane Farmer1a21b8c2017-07-21 09:42:42 -0700545
546 artifact.device_feature_group = {"df1"};
Shane Farmer0a5b2012017-06-22 12:24:12 -0700547 artifact.gl_texture_group = {"${feature}"};
Shane Farmer1a21b8c2017-07-21 09:42:42 -0700548 {
Shane Farmer9ecc0752017-08-24 15:55:36 -0700549 const auto& result = artifact.ToArtifactName("app.${feature}.${gl}.apk", "", &diag);
Shane Farmer0a5b2012017-06-22 12:24:12 -0700550 ASSERT_TRUE(result);
551 EXPECT_EQ(result.value(), "app.df1.${feature}.apk");
Shane Farmer1a21b8c2017-07-21 09:42:42 -0700552 }
553
554 // This is an invalid case, but should be the only possible case due to the ordering of
555 // replacement.
Shane Farmer0a5b2012017-06-22 12:24:12 -0700556 artifact.device_feature_group = {"${gl}"};
Shane Farmer1a21b8c2017-07-21 09:42:42 -0700557 artifact.gl_texture_group = {"glx1"};
558 {
Shane Farmer9ecc0752017-08-24 15:55:36 -0700559 const auto& result = artifact.ToArtifactName("app.${feature}.apk", "", &diag);
Shane Farmer0a5b2012017-06-22 12:24:12 -0700560 ASSERT_TRUE(result);
Shane Farmer1a21b8c2017-07-21 09:42:42 -0700561 EXPECT_EQ(result.value(), "app.glx1.apk");
562 }
563}
564
Shane Farmer74cdea32017-05-12 16:22:36 -0700565} // namespace
566} // namespace aapt