Shane Farmer | 74cdea3 | 2017-05-12 16:22:36 -0700 | [diff] [blame] | 1 | /* |
| 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 Farmer | 74cdea3 | 2017-05-12 16:22:36 -0700 | [diff] [blame] | 21 | #include "androidfw/ResourceTypes.h" |
| 22 | |
| 23 | #include "test/Test.h" |
| 24 | #include "xml/XmlDom.h" |
| 25 | |
| 26 | namespace aapt { |
| 27 | namespace { |
| 28 | |
Adam Lesinski | 6b37299 | 2017-08-09 10:54:23 -0700 | [diff] [blame] | 29 | using ::android::ResTable_config; |
Shane Farmer | 74cdea3 | 2017-05-12 16:22:36 -0700 | [diff] [blame] | 30 | using configuration::Abi; |
| 31 | using configuration::AndroidSdk; |
Shane Farmer | 9f0e7f1 | 2017-06-22 12:26:44 -0700 | [diff] [blame] | 32 | using configuration::Artifact; |
Shane Farmer | 280be34 | 2017-06-21 15:20:15 -0700 | [diff] [blame] | 33 | using configuration::PostProcessingConfiguration; |
Shane Farmer | 74cdea3 | 2017-05-12 16:22:36 -0700 | [diff] [blame] | 34 | using configuration::DeviceFeature; |
| 35 | using configuration::GlTexture; |
| 36 | using configuration::Locale; |
| 37 | using configuration::AndroidManifest; |
Adam Lesinski | 6b37299 | 2017-08-09 10:54:23 -0700 | [diff] [blame] | 38 | using ::testing::ElementsAre; |
Shane Farmer | 74cdea3 | 2017-05-12 16:22:36 -0700 | [diff] [blame] | 39 | using xml::Element; |
| 40 | using xml::NodeCast; |
| 41 | |
| 42 | constexpr 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 Farmer | 0a5b201 | 2017-06-22 12:24:12 -0700 | [diff] [blame] | 67 | <locale>en</locale> |
| 68 | <locale>es</locale> |
| 69 | <locale>fr</locale> |
| 70 | <locale>de</locale> |
Shane Farmer | 74cdea3 | 2017-05-12 16:22:36 -0700 | [diff] [blame] | 71 | </locale-group> |
| 72 | <locale-group label="north-america"> |
Shane Farmer | 0a5b201 | 2017-06-22 12:24:12 -0700 | [diff] [blame] | 73 | <locale>en</locale> |
| 74 | <locale>es-rMX</locale> |
| 75 | <locale>fr-rCA</locale> |
Shane Farmer | 74cdea3 | 2017-05-12 16:22:36 -0700 | [diff] [blame] | 76 | </locale-group> |
| 77 | <android-sdk-group label="19"> |
| 78 | <android-sdk |
| 79 | minSdkVersion="19" |
| 80 | targetSdkVersion="24" |
| 81 | maxSdkVersion="25"> |
| 82 | <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" |
| 105 | android-sdk-group="19" |
| 106 | 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" |
| 113 | android-sdk-group="19" |
| 114 | gl-texture-group="dxt1" |
| 115 | device-feature-group="low-latency"/> |
| 116 | </artifacts> |
| 117 | </post-process> |
| 118 | )"; |
| 119 | |
| 120 | class ConfigurationParserTest : public ConfigurationParser, public ::testing::Test { |
| 121 | public: |
| 122 | ConfigurationParserTest() : ConfigurationParser("") {} |
| 123 | |
| 124 | protected: |
| 125 | StdErrDiagnostics diag_; |
| 126 | }; |
| 127 | |
Shane Farmer | b102727 | 2017-06-14 09:10:28 -0700 | [diff] [blame] | 128 | TEST_F(ConfigurationParserTest, ForPath_NoFile) { |
| 129 | auto result = ConfigurationParser::ForPath("./does_not_exist.xml"); |
| 130 | EXPECT_FALSE(result); |
| 131 | } |
| 132 | |
Shane Farmer | 74cdea3 | 2017-05-12 16:22:36 -0700 | [diff] [blame] | 133 | TEST_F(ConfigurationParserTest, ValidateFile) { |
| 134 | auto parser = ConfigurationParser::ForContents(kValidConfig).WithDiagnostics(&diag_); |
| 135 | auto result = parser.Parse(); |
| 136 | ASSERT_TRUE(result); |
Shane Farmer | 280be34 | 2017-06-21 15:20:15 -0700 | [diff] [blame] | 137 | PostProcessingConfiguration& value = result.value(); |
Shane Farmer | 74cdea3 | 2017-05-12 16:22:36 -0700 | [diff] [blame] | 138 | 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 Farmer | 0a5b201 | 2017-06-22 12:24:12 -0700 | [diff] [blame] | 153 | EXPECT_EQ(2ul, value.locale_groups.size()); |
Shane Farmer | 74cdea3 | 2017-05-12 16:22:36 -0700 | [diff] [blame] | 154 | EXPECT_EQ(4ul, value.locale_groups["europe"].size()); |
| 155 | EXPECT_EQ(3ul, value.locale_groups["north-america"].size()); |
Shane Farmer | 74cdea3 | 2017-05-12 16:22:36 -0700 | [diff] [blame] | 156 | |
| 157 | EXPECT_EQ(1ul, value.android_sdk_groups.size()); |
| 158 | EXPECT_EQ(1ul, value.android_sdk_groups["19"].size()); |
| 159 | |
| 160 | EXPECT_EQ(1ul, value.gl_texture_groups.size()); |
| 161 | EXPECT_EQ(1ul, value.gl_texture_groups["dxt1"].size()); |
| 162 | |
| 163 | EXPECT_EQ(1ul, value.device_feature_groups.size()); |
| 164 | EXPECT_EQ(1ul, value.device_feature_groups["low-latency"].size()); |
| 165 | } |
| 166 | |
| 167 | TEST_F(ConfigurationParserTest, InvalidNamespace) { |
| 168 | constexpr const char* invalid_ns = R"(<?xml version="1.0" encoding="utf-8" ?> |
| 169 | <post-process xmlns="http://schemas.android.com/tools/another-unknown-tool" />)"; |
| 170 | |
| 171 | auto result = ConfigurationParser::ForContents(invalid_ns).Parse(); |
| 172 | ASSERT_FALSE(result); |
| 173 | } |
| 174 | |
| 175 | TEST_F(ConfigurationParserTest, ArtifactAction) { |
| 176 | static constexpr const char* xml = R"xml( |
| 177 | <artifact |
| 178 | abi-group="arm" |
| 179 | screen-density-group="large" |
| 180 | locale-group="europe" |
| 181 | android-sdk-group="19" |
| 182 | gl-texture-group="dxt1" |
| 183 | device-feature-group="low-latency"/>)xml"; |
| 184 | |
| 185 | auto doc = test::BuildXmlDom(xml); |
| 186 | |
Shane Farmer | 280be34 | 2017-06-21 15:20:15 -0700 | [diff] [blame] | 187 | PostProcessingConfiguration config; |
Adam Lesinski | 6b37299 | 2017-08-09 10:54:23 -0700 | [diff] [blame] | 188 | bool ok = artifact_handler_(&config, NodeCast<Element>(doc->root.get()), &diag_); |
Shane Farmer | 74cdea3 | 2017-05-12 16:22:36 -0700 | [diff] [blame] | 189 | ASSERT_TRUE(ok); |
| 190 | |
| 191 | EXPECT_EQ(1ul, config.artifacts.size()); |
| 192 | |
Shane Farmer | 5766943 | 2017-06-19 12:52:04 -0700 | [diff] [blame] | 193 | auto& artifact = config.artifacts.front(); |
Shane Farmer | 0a5b201 | 2017-06-22 12:24:12 -0700 | [diff] [blame] | 194 | EXPECT_FALSE(artifact.name); // TODO: make this fail. |
Shane Farmer | 74cdea3 | 2017-05-12 16:22:36 -0700 | [diff] [blame] | 195 | EXPECT_EQ("arm", artifact.abi_group.value()); |
| 196 | EXPECT_EQ("large", artifact.screen_density_group.value()); |
| 197 | EXPECT_EQ("europe", artifact.locale_group.value()); |
| 198 | EXPECT_EQ("19", artifact.android_sdk_group.value()); |
| 199 | EXPECT_EQ("dxt1", artifact.gl_texture_group.value()); |
| 200 | EXPECT_EQ("low-latency", artifact.device_feature_group.value()); |
Shane Farmer | 5766943 | 2017-06-19 12:52:04 -0700 | [diff] [blame] | 201 | |
| 202 | // Perform a second action to ensure we get 2 artifacts. |
| 203 | static constexpr const char* second = R"xml( |
| 204 | <artifact |
| 205 | abi-group="other" |
| 206 | screen-density-group="large" |
| 207 | locale-group="europe" |
| 208 | android-sdk-group="19" |
| 209 | gl-texture-group="dxt1" |
| 210 | device-feature-group="low-latency"/>)xml"; |
| 211 | doc = test::BuildXmlDom(second); |
| 212 | |
| 213 | ok = artifact_handler_(&config, NodeCast<Element>(doc.get()->root.get()), &diag_); |
| 214 | ASSERT_TRUE(ok); |
| 215 | EXPECT_EQ(2ul, config.artifacts.size()); |
Shane Farmer | 74cdea3 | 2017-05-12 16:22:36 -0700 | [diff] [blame] | 216 | } |
| 217 | |
| 218 | TEST_F(ConfigurationParserTest, ArtifactFormatAction) { |
| 219 | static constexpr const char* xml = R"xml( |
| 220 | <artifact-format> |
| 221 | ${base}.${abi}.${screen-density}.${locale}.${sdk}.${gl}.${feature}.release |
| 222 | </artifact-format>)xml"; |
| 223 | |
| 224 | auto doc = test::BuildXmlDom(xml); |
| 225 | |
Shane Farmer | 280be34 | 2017-06-21 15:20:15 -0700 | [diff] [blame] | 226 | PostProcessingConfiguration config; |
Shane Farmer | 74cdea3 | 2017-05-12 16:22:36 -0700 | [diff] [blame] | 227 | bool ok = artifact_format_handler_(&config, NodeCast<Element>(doc.get()->root.get()), &diag_); |
| 228 | ASSERT_TRUE(ok); |
| 229 | ASSERT_TRUE(config.artifact_format); |
| 230 | EXPECT_EQ( |
| 231 | "${base}.${abi}.${screen-density}.${locale}.${sdk}.${gl}.${feature}.release", |
| 232 | static_cast<std::string>(config.artifact_format.value()) |
| 233 | ); |
| 234 | } |
| 235 | |
| 236 | TEST_F(ConfigurationParserTest, AbiGroupAction) { |
| 237 | static constexpr const char* xml = R"xml( |
| 238 | <abi-group label="arm"> |
| 239 | <!-- First comment. --> |
| 240 | <abi> |
| 241 | armeabi-v7a |
| 242 | </abi> |
| 243 | <!-- Another comment. --> |
| 244 | <abi>arm64-v8a</abi> |
| 245 | </abi-group>)xml"; |
| 246 | |
| 247 | auto doc = test::BuildXmlDom(xml); |
| 248 | |
Shane Farmer | 280be34 | 2017-06-21 15:20:15 -0700 | [diff] [blame] | 249 | PostProcessingConfiguration config; |
Shane Farmer | 74cdea3 | 2017-05-12 16:22:36 -0700 | [diff] [blame] | 250 | bool ok = abi_group_handler_(&config, NodeCast<Element>(doc.get()->root.get()), &diag_); |
| 251 | ASSERT_TRUE(ok); |
| 252 | |
| 253 | EXPECT_EQ(1ul, config.abi_groups.size()); |
| 254 | ASSERT_EQ(1u, config.abi_groups.count("arm")); |
| 255 | |
| 256 | auto& out = config.abi_groups["arm"]; |
| 257 | ASSERT_THAT(out, ElementsAre(Abi::kArmV7a, Abi::kArm64V8a)); |
| 258 | } |
| 259 | |
| 260 | TEST_F(ConfigurationParserTest, ScreenDensityGroupAction) { |
| 261 | static constexpr const char* xml = R"xml( |
| 262 | <screen-density-group label="large"> |
| 263 | <screen-density>xhdpi</screen-density> |
| 264 | <screen-density> |
| 265 | xxhdpi |
| 266 | </screen-density> |
| 267 | <screen-density>xxxhdpi</screen-density> |
| 268 | </screen-density-group>)xml"; |
| 269 | |
| 270 | auto doc = test::BuildXmlDom(xml); |
| 271 | |
Shane Farmer | 280be34 | 2017-06-21 15:20:15 -0700 | [diff] [blame] | 272 | PostProcessingConfiguration config; |
Shane Farmer | 74cdea3 | 2017-05-12 16:22:36 -0700 | [diff] [blame] | 273 | bool ok = |
| 274 | screen_density_group_handler_(&config, NodeCast<Element>(doc.get()->root.get()), &diag_); |
| 275 | ASSERT_TRUE(ok); |
| 276 | |
| 277 | EXPECT_EQ(1ul, config.screen_density_groups.size()); |
| 278 | ASSERT_EQ(1u, config.screen_density_groups.count("large")); |
| 279 | |
| 280 | ConfigDescription xhdpi; |
| 281 | xhdpi.density = ResTable_config::DENSITY_XHIGH; |
| 282 | ConfigDescription xxhdpi; |
| 283 | xxhdpi.density = ResTable_config::DENSITY_XXHIGH; |
| 284 | ConfigDescription xxxhdpi; |
| 285 | xxxhdpi.density = ResTable_config::DENSITY_XXXHIGH; |
| 286 | |
| 287 | auto& out = config.screen_density_groups["large"]; |
| 288 | ASSERT_THAT(out, ElementsAre(xhdpi, xxhdpi, xxxhdpi)); |
| 289 | } |
| 290 | |
| 291 | TEST_F(ConfigurationParserTest, LocaleGroupAction) { |
| 292 | static constexpr const char* xml = R"xml( |
| 293 | <locale-group label="europe"> |
Shane Farmer | 0a5b201 | 2017-06-22 12:24:12 -0700 | [diff] [blame] | 294 | <locale>en</locale> |
| 295 | <locale>es</locale> |
| 296 | <locale>fr</locale> |
| 297 | <locale>de</locale> |
Shane Farmer | 74cdea3 | 2017-05-12 16:22:36 -0700 | [diff] [blame] | 298 | </locale-group>)xml"; |
| 299 | |
| 300 | auto doc = test::BuildXmlDom(xml); |
| 301 | |
Shane Farmer | 280be34 | 2017-06-21 15:20:15 -0700 | [diff] [blame] | 302 | PostProcessingConfiguration config; |
Shane Farmer | 74cdea3 | 2017-05-12 16:22:36 -0700 | [diff] [blame] | 303 | bool ok = locale_group_handler_(&config, NodeCast<Element>(doc.get()->root.get()), &diag_); |
| 304 | ASSERT_TRUE(ok); |
| 305 | |
| 306 | ASSERT_EQ(1ul, config.locale_groups.size()); |
| 307 | ASSERT_EQ(1u, config.locale_groups.count("europe")); |
| 308 | |
Shane Farmer | 0a5b201 | 2017-06-22 12:24:12 -0700 | [diff] [blame] | 309 | const auto& out = config.locale_groups["europe"]; |
Shane Farmer | 74cdea3 | 2017-05-12 16:22:36 -0700 | [diff] [blame] | 310 | |
Shane Farmer | 0a5b201 | 2017-06-22 12:24:12 -0700 | [diff] [blame] | 311 | ConfigDescription en = test::ParseConfigOrDie("en"); |
| 312 | ConfigDescription es = test::ParseConfigOrDie("es"); |
| 313 | ConfigDescription fr = test::ParseConfigOrDie("fr"); |
| 314 | ConfigDescription de = test::ParseConfigOrDie("de"); |
Shane Farmer | 74cdea3 | 2017-05-12 16:22:36 -0700 | [diff] [blame] | 315 | |
| 316 | ASSERT_THAT(out, ElementsAre(en, es, fr, de)); |
| 317 | } |
| 318 | |
| 319 | TEST_F(ConfigurationParserTest, AndroidSdkGroupAction) { |
| 320 | static constexpr const char* xml = R"xml( |
| 321 | <android-sdk-group label="19"> |
| 322 | <android-sdk |
| 323 | minSdkVersion="19" |
| 324 | targetSdkVersion="24" |
| 325 | maxSdkVersion="25"> |
| 326 | <manifest> |
| 327 | <!--- manifest additions here XSLT? TODO --> |
| 328 | </manifest> |
| 329 | </android-sdk> |
| 330 | </android-sdk-group>)xml"; |
| 331 | |
| 332 | auto doc = test::BuildXmlDom(xml); |
| 333 | |
Shane Farmer | 280be34 | 2017-06-21 15:20:15 -0700 | [diff] [blame] | 334 | PostProcessingConfiguration config; |
Shane Farmer | 74cdea3 | 2017-05-12 16:22:36 -0700 | [diff] [blame] | 335 | bool ok = android_sdk_group_handler_(&config, NodeCast<Element>(doc.get()->root.get()), &diag_); |
| 336 | ASSERT_TRUE(ok); |
| 337 | |
| 338 | ASSERT_EQ(1ul, config.android_sdk_groups.size()); |
| 339 | ASSERT_EQ(1u, config.android_sdk_groups.count("19")); |
| 340 | |
| 341 | auto& out = config.android_sdk_groups["19"]; |
| 342 | |
| 343 | AndroidSdk sdk; |
| 344 | sdk.min_sdk_version = std::string("19"); |
| 345 | sdk.target_sdk_version = std::string("24"); |
| 346 | sdk.max_sdk_version = std::string("25"); |
| 347 | sdk.manifest = AndroidManifest(); |
| 348 | |
| 349 | ASSERT_EQ(1ul, out.size()); |
| 350 | ASSERT_EQ(sdk, out[0]); |
| 351 | } |
| 352 | |
| 353 | TEST_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 Farmer | 280be34 | 2017-06-21 15:20:15 -0700 | [diff] [blame] | 366 | PostProcessingConfiguration config; |
Shane Farmer | 74cdea3 | 2017-05-12 16:22:36 -0700 | [diff] [blame] | 367 | 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 | |
| 384 | TEST_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 Farmer | 280be34 | 2017-06-21 15:20:15 -0700 | [diff] [blame] | 395 | PostProcessingConfiguration config; |
Shane Farmer | 74cdea3 | 2017-05-12 16:22:36 -0700 | [diff] [blame] | 396 | 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 Farmer | 1a21b8c | 2017-07-21 09:42:42 -0700 | [diff] [blame] | 410 | // Artifact name parser test cases. |
| 411 | |
Shane Farmer | 9f0e7f1 | 2017-06-22 12:26:44 -0700 | [diff] [blame] | 412 | TEST(ArtifactTest, Simple) { |
| 413 | StdErrDiagnostics diag; |
| 414 | Artifact x86; |
| 415 | x86.abi_group = {"x86"}; |
| 416 | |
Shane Farmer | 0a5b201 | 2017-06-22 12:24:12 -0700 | [diff] [blame] | 417 | auto x86_result = x86.ToArtifactName("something.${abi}.apk", &diag); |
Shane Farmer | 9f0e7f1 | 2017-06-22 12:26:44 -0700 | [diff] [blame] | 418 | 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 Farmer | 0a5b201 | 2017-06-22 12:24:12 -0700 | [diff] [blame] | 424 | auto arm_result = arm.ToArtifactName("app.${abi}.apk", &diag); |
Shane Farmer | 9f0e7f1 | 2017-06-22 12:26:44 -0700 | [diff] [blame] | 425 | ASSERT_TRUE(arm_result); |
| 426 | EXPECT_EQ(arm_result.value(), "app.armeabi-v7a.apk"); |
| 427 | } |
| 428 | |
| 429 | TEST(ArtifactTest, Complex) { |
| 430 | StdErrDiagnostics diag; |
| 431 | Artifact artifact; |
| 432 | artifact.abi_group = {"mips64"}; |
| 433 | artifact.screen_density_group = {"ldpi"}; |
| 434 | artifact.device_feature_group = {"df1"}; |
| 435 | artifact.gl_texture_group = {"glx1"}; |
| 436 | artifact.locale_group = {"en-AU"}; |
| 437 | artifact.android_sdk_group = {"26"}; |
| 438 | |
Shane Farmer | 0a5b201 | 2017-06-22 12:24:12 -0700 | [diff] [blame] | 439 | auto result = artifact.ToArtifactName( |
| 440 | "app.${density}_${locale}_${feature}_${gl}.sdk${sdk}.${abi}.apk", &diag); |
Shane Farmer | 9f0e7f1 | 2017-06-22 12:26:44 -0700 | [diff] [blame] | 441 | ASSERT_TRUE(result); |
| 442 | EXPECT_EQ(result.value(), "app.ldpi_en-AU_df1_glx1.sdk26.mips64.apk"); |
| 443 | } |
| 444 | |
| 445 | TEST(ArtifactTest, Missing) { |
| 446 | StdErrDiagnostics diag; |
| 447 | Artifact x86; |
| 448 | x86.abi_group = {"x86"}; |
| 449 | |
Shane Farmer | 0a5b201 | 2017-06-22 12:24:12 -0700 | [diff] [blame] | 450 | EXPECT_FALSE(x86.ToArtifactName("something.${density}.apk", &diag)); |
Shane Farmer | 9f0e7f1 | 2017-06-22 12:26:44 -0700 | [diff] [blame] | 451 | EXPECT_FALSE(x86.ToArtifactName("something.apk", &diag)); |
| 452 | } |
| 453 | |
| 454 | TEST(ArtifactTest, Empty) { |
| 455 | StdErrDiagnostics diag; |
| 456 | Artifact artifact; |
| 457 | |
Shane Farmer | 0a5b201 | 2017-06-22 12:24:12 -0700 | [diff] [blame] | 458 | EXPECT_FALSE(artifact.ToArtifactName("something.${density}.apk", &diag)); |
Shane Farmer | 9f0e7f1 | 2017-06-22 12:26:44 -0700 | [diff] [blame] | 459 | EXPECT_TRUE(artifact.ToArtifactName("something.apk", &diag)); |
| 460 | } |
| 461 | |
Shane Farmer | 1a21b8c | 2017-07-21 09:42:42 -0700 | [diff] [blame] | 462 | TEST(ArtifactTest, Repeated) { |
| 463 | StdErrDiagnostics diag; |
| 464 | Artifact artifact; |
| 465 | artifact.screen_density_group = {"mdpi"}; |
| 466 | |
Shane Farmer | 0a5b201 | 2017-06-22 12:24:12 -0700 | [diff] [blame] | 467 | ASSERT_TRUE(artifact.ToArtifactName("something.${density}.apk", &diag)); |
| 468 | EXPECT_FALSE(artifact.ToArtifactName("something.${density}.${density}.apk", &diag)); |
Shane Farmer | 1a21b8c | 2017-07-21 09:42:42 -0700 | [diff] [blame] | 469 | } |
| 470 | |
| 471 | TEST(ArtifactTest, Nesting) { |
| 472 | StdErrDiagnostics diag; |
| 473 | Artifact x86; |
| 474 | x86.abi_group = {"x86"}; |
| 475 | |
Shane Farmer | 0a5b201 | 2017-06-22 12:24:12 -0700 | [diff] [blame] | 476 | EXPECT_FALSE(x86.ToArtifactName("something.${abi${density}}.apk", &diag)); |
Shane Farmer | 1a21b8c | 2017-07-21 09:42:42 -0700 | [diff] [blame] | 477 | |
Shane Farmer | 0a5b201 | 2017-06-22 12:24:12 -0700 | [diff] [blame] | 478 | const Maybe<std::string>& name = x86.ToArtifactName("something.${abi${abi}}.apk", &diag); |
| 479 | ASSERT_TRUE(name); |
| 480 | EXPECT_EQ(name.value(), "something.${abix86}.apk"); |
Shane Farmer | 1a21b8c | 2017-07-21 09:42:42 -0700 | [diff] [blame] | 481 | } |
| 482 | |
| 483 | TEST(ArtifactTest, Recursive) { |
| 484 | StdErrDiagnostics diag; |
| 485 | Artifact artifact; |
Shane Farmer | 0a5b201 | 2017-06-22 12:24:12 -0700 | [diff] [blame] | 486 | artifact.device_feature_group = {"${gl}"}; |
Shane Farmer | 1a21b8c | 2017-07-21 09:42:42 -0700 | [diff] [blame] | 487 | artifact.gl_texture_group = {"glx1"}; |
| 488 | |
Shane Farmer | 0a5b201 | 2017-06-22 12:24:12 -0700 | [diff] [blame] | 489 | EXPECT_FALSE(artifact.ToArtifactName("app.${feature}.${gl}.apk", &diag)); |
Shane Farmer | 1a21b8c | 2017-07-21 09:42:42 -0700 | [diff] [blame] | 490 | |
| 491 | artifact.device_feature_group = {"df1"}; |
Shane Farmer | 0a5b201 | 2017-06-22 12:24:12 -0700 | [diff] [blame] | 492 | artifact.gl_texture_group = {"${feature}"}; |
Shane Farmer | 1a21b8c | 2017-07-21 09:42:42 -0700 | [diff] [blame] | 493 | { |
Shane Farmer | 0a5b201 | 2017-06-22 12:24:12 -0700 | [diff] [blame] | 494 | const auto& result = artifact.ToArtifactName("app.${feature}.${gl}.apk", &diag); |
| 495 | ASSERT_TRUE(result); |
| 496 | EXPECT_EQ(result.value(), "app.df1.${feature}.apk"); |
Shane Farmer | 1a21b8c | 2017-07-21 09:42:42 -0700 | [diff] [blame] | 497 | } |
| 498 | |
| 499 | // This is an invalid case, but should be the only possible case due to the ordering of |
| 500 | // replacement. |
Shane Farmer | 0a5b201 | 2017-06-22 12:24:12 -0700 | [diff] [blame] | 501 | artifact.device_feature_group = {"${gl}"}; |
Shane Farmer | 1a21b8c | 2017-07-21 09:42:42 -0700 | [diff] [blame] | 502 | artifact.gl_texture_group = {"glx1"}; |
| 503 | { |
Shane Farmer | 0a5b201 | 2017-06-22 12:24:12 -0700 | [diff] [blame] | 504 | const auto& result = artifact.ToArtifactName("app.${feature}.apk", &diag); |
| 505 | ASSERT_TRUE(result); |
Shane Farmer | 1a21b8c | 2017-07-21 09:42:42 -0700 | [diff] [blame] | 506 | EXPECT_EQ(result.value(), "app.glx1.apk"); |
| 507 | } |
| 508 | } |
| 509 | |
Shane Farmer | 74cdea3 | 2017-05-12 16:22:36 -0700 | [diff] [blame] | 510 | } // namespace |
| 511 | } // namespace aapt |