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> |
Shane Farmer | efe4539 | 2017-08-21 14:39:28 -0700 | [diff] [blame^] | 77 | <android-sdk-group label="v19"> |
Shane Farmer | 74cdea3 | 2017-05-12 16:22:36 -0700 | [diff] [blame] | 78 | <android-sdk |
Shane Farmer | efe4539 | 2017-08-21 14:39:28 -0700 | [diff] [blame^] | 79 | minSdkVersion="v19" |
| 80 | targetSdkVersion="v24" |
| 81 | maxSdkVersion="v25"> |
Shane Farmer | 74cdea3 | 2017-05-12 16:22:36 -0700 | [diff] [blame] | 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" |
Shane Farmer | efe4539 | 2017-08-21 14:39:28 -0700 | [diff] [blame^] | 105 | android-sdk-group="v19" |
Shane Farmer | 74cdea3 | 2017-05-12 16:22:36 -0700 | [diff] [blame] | 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" |
Shane Farmer | efe4539 | 2017-08-21 14:39:28 -0700 | [diff] [blame^] | 113 | android-sdk-group="v19" |
Shane Farmer | 74cdea3 | 2017-05-12 16:22:36 -0700 | [diff] [blame] | 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()); |
Shane Farmer | efe4539 | 2017-08-21 14:39:28 -0700 | [diff] [blame^] | 158 | EXPECT_TRUE(value.android_sdk_groups["v19"].min_sdk_version); |
| 159 | EXPECT_EQ("v19", value.android_sdk_groups["v19"].min_sdk_version.value()); |
Shane Farmer | 74cdea3 | 2017-05-12 16:22:36 -0700 | [diff] [blame] | 160 | |
| 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 | |
| 168 | TEST_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 | |
| 176 | TEST_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 Farmer | efe4539 | 2017-08-21 14:39:28 -0700 | [diff] [blame^] | 182 | android-sdk-group="v19" |
Shane Farmer | 74cdea3 | 2017-05-12 16:22:36 -0700 | [diff] [blame] | 183 | gl-texture-group="dxt1" |
| 184 | device-feature-group="low-latency"/>)xml"; |
| 185 | |
| 186 | auto doc = test::BuildXmlDom(xml); |
| 187 | |
Shane Farmer | 280be34 | 2017-06-21 15:20:15 -0700 | [diff] [blame] | 188 | PostProcessingConfiguration config; |
Adam Lesinski | 6b37299 | 2017-08-09 10:54:23 -0700 | [diff] [blame] | 189 | bool ok = artifact_handler_(&config, NodeCast<Element>(doc->root.get()), &diag_); |
Shane Farmer | 74cdea3 | 2017-05-12 16:22:36 -0700 | [diff] [blame] | 190 | ASSERT_TRUE(ok); |
| 191 | |
| 192 | EXPECT_EQ(1ul, config.artifacts.size()); |
| 193 | |
Shane Farmer | 5766943 | 2017-06-19 12:52:04 -0700 | [diff] [blame] | 194 | auto& artifact = config.artifacts.front(); |
Shane Farmer | 0a5b201 | 2017-06-22 12:24:12 -0700 | [diff] [blame] | 195 | EXPECT_FALSE(artifact.name); // TODO: make this fail. |
Shane Farmer | 74cdea3 | 2017-05-12 16:22:36 -0700 | [diff] [blame] | 196 | 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 Farmer | efe4539 | 2017-08-21 14:39:28 -0700 | [diff] [blame^] | 199 | EXPECT_EQ("v19", artifact.android_sdk_group.value()); |
Shane Farmer | 74cdea3 | 2017-05-12 16:22:36 -0700 | [diff] [blame] | 200 | EXPECT_EQ("dxt1", artifact.gl_texture_group.value()); |
| 201 | EXPECT_EQ("low-latency", artifact.device_feature_group.value()); |
Shane Farmer | 5766943 | 2017-06-19 12:52:04 -0700 | [diff] [blame] | 202 | |
| 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 Farmer | efe4539 | 2017-08-21 14:39:28 -0700 | [diff] [blame^] | 209 | android-sdk-group="v19" |
Shane Farmer | 5766943 | 2017-06-19 12:52:04 -0700 | [diff] [blame] | 210 | 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 Farmer | 74cdea3 | 2017-05-12 16:22:36 -0700 | [diff] [blame] | 217 | } |
| 218 | |
| 219 | TEST_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 Farmer | 280be34 | 2017-06-21 15:20:15 -0700 | [diff] [blame] | 227 | PostProcessingConfiguration config; |
Shane Farmer | 74cdea3 | 2017-05-12 16:22:36 -0700 | [diff] [blame] | 228 | 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 | |
| 237 | TEST_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 Farmer | 280be34 | 2017-06-21 15:20:15 -0700 | [diff] [blame] | 250 | PostProcessingConfiguration config; |
Shane Farmer | 74cdea3 | 2017-05-12 16:22:36 -0700 | [diff] [blame] | 251 | 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 | |
| 261 | TEST_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 Farmer | 280be34 | 2017-06-21 15:20:15 -0700 | [diff] [blame] | 273 | PostProcessingConfiguration config; |
Shane Farmer | 74cdea3 | 2017-05-12 16:22:36 -0700 | [diff] [blame] | 274 | 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 | |
| 292 | TEST_F(ConfigurationParserTest, LocaleGroupAction) { |
| 293 | static constexpr const char* xml = R"xml( |
| 294 | <locale-group label="europe"> |
Shane Farmer | 0a5b201 | 2017-06-22 12:24:12 -0700 | [diff] [blame] | 295 | <locale>en</locale> |
| 296 | <locale>es</locale> |
| 297 | <locale>fr</locale> |
| 298 | <locale>de</locale> |
Shane Farmer | 74cdea3 | 2017-05-12 16:22:36 -0700 | [diff] [blame] | 299 | </locale-group>)xml"; |
| 300 | |
| 301 | auto doc = test::BuildXmlDom(xml); |
| 302 | |
Shane Farmer | 280be34 | 2017-06-21 15:20:15 -0700 | [diff] [blame] | 303 | PostProcessingConfiguration config; |
Shane Farmer | 74cdea3 | 2017-05-12 16:22:36 -0700 | [diff] [blame] | 304 | 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 Farmer | 0a5b201 | 2017-06-22 12:24:12 -0700 | [diff] [blame] | 310 | const auto& out = config.locale_groups["europe"]; |
Shane Farmer | 74cdea3 | 2017-05-12 16:22:36 -0700 | [diff] [blame] | 311 | |
Shane Farmer | 0a5b201 | 2017-06-22 12:24:12 -0700 | [diff] [blame] | 312 | ConfigDescription en = test::ParseConfigOrDie("en"); |
| 313 | ConfigDescription es = test::ParseConfigOrDie("es"); |
| 314 | ConfigDescription fr = test::ParseConfigOrDie("fr"); |
| 315 | ConfigDescription de = test::ParseConfigOrDie("de"); |
Shane Farmer | 74cdea3 | 2017-05-12 16:22:36 -0700 | [diff] [blame] | 316 | |
| 317 | ASSERT_THAT(out, ElementsAre(en, es, fr, de)); |
| 318 | } |
| 319 | |
| 320 | TEST_F(ConfigurationParserTest, AndroidSdkGroupAction) { |
| 321 | static constexpr const char* xml = R"xml( |
Shane Farmer | efe4539 | 2017-08-21 14:39:28 -0700 | [diff] [blame^] | 322 | <android-sdk-group label="v19"> |
Shane Farmer | 74cdea3 | 2017-05-12 16:22:36 -0700 | [diff] [blame] | 323 | <android-sdk |
Shane Farmer | efe4539 | 2017-08-21 14:39:28 -0700 | [diff] [blame^] | 324 | minSdkVersion="v19" |
| 325 | targetSdkVersion="v24" |
| 326 | maxSdkVersion="v25"> |
Shane Farmer | 74cdea3 | 2017-05-12 16:22:36 -0700 | [diff] [blame] | 327 | <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 Farmer | 280be34 | 2017-06-21 15:20:15 -0700 | [diff] [blame] | 335 | PostProcessingConfiguration config; |
Shane Farmer | 74cdea3 | 2017-05-12 16:22:36 -0700 | [diff] [blame] | 336 | 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 Farmer | efe4539 | 2017-08-21 14:39:28 -0700 | [diff] [blame^] | 340 | ASSERT_EQ(1u, config.android_sdk_groups.count("v19")); |
Shane Farmer | 74cdea3 | 2017-05-12 16:22:36 -0700 | [diff] [blame] | 341 | |
Shane Farmer | efe4539 | 2017-08-21 14:39:28 -0700 | [diff] [blame^] | 342 | auto& out = config.android_sdk_groups["v19"]; |
Shane Farmer | 74cdea3 | 2017-05-12 16:22:36 -0700 | [diff] [blame] | 343 | |
| 344 | AndroidSdk sdk; |
Shane Farmer | efe4539 | 2017-08-21 14:39:28 -0700 | [diff] [blame^] | 345 | sdk.min_sdk_version = std::string("v19"); |
| 346 | sdk.target_sdk_version = std::string("v24"); |
| 347 | sdk.max_sdk_version = std::string("v25"); |
Shane Farmer | 74cdea3 | 2017-05-12 16:22:36 -0700 | [diff] [blame] | 348 | sdk.manifest = AndroidManifest(); |
| 349 | |
Shane Farmer | efe4539 | 2017-08-21 14:39:28 -0700 | [diff] [blame^] | 350 | ASSERT_EQ(sdk, out); |
Shane Farmer | 74cdea3 | 2017-05-12 16:22:36 -0700 | [diff] [blame] | 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 | 9ecc075 | 2017-08-24 15:55:36 -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 | 9ecc075 | 2017-08-24 15:55:36 -0700 | [diff] [blame] | 424 | { |
| 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 Farmer | 9f0e7f1 | 2017-06-22 12:26:44 -0700 | [diff] [blame] | 447 | } |
| 448 | |
| 449 | TEST(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 Farmer | efe4539 | 2017-08-21 14:39:28 -0700 | [diff] [blame^] | 457 | artifact.android_sdk_group = {"v26"}; |
Shane Farmer | 9f0e7f1 | 2017-06-22 12:26:44 -0700 | [diff] [blame] | 458 | |
Shane Farmer | 9ecc075 | 2017-08-24 15:55:36 -0700 | [diff] [blame] | 459 | { |
| 460 | auto result = artifact.ToArtifactName( |
Shane Farmer | efe4539 | 2017-08-21 14:39:28 -0700 | [diff] [blame^] | 461 | "app.${density}_${locale}_${feature}_${gl}.${sdk}.${abi}.apk", "", &diag); |
Shane Farmer | 9ecc075 | 2017-08-24 15:55:36 -0700 | [diff] [blame] | 462 | ASSERT_TRUE(result); |
Shane Farmer | efe4539 | 2017-08-21 14:39:28 -0700 | [diff] [blame^] | 463 | EXPECT_EQ(result.value(), "app.ldpi_en-AU_df1_glx1.v26.mips64.apk"); |
Shane Farmer | 9ecc075 | 2017-08-24 15:55:36 -0700 | [diff] [blame] | 464 | } |
| 465 | |
| 466 | { |
| 467 | auto result = artifact.ToArtifactName( |
Shane Farmer | efe4539 | 2017-08-21 14:39:28 -0700 | [diff] [blame^] | 468 | "app.${density}_${locale}_${feature}_${gl}.${sdk}.${abi}.apk", "app.apk", &diag); |
Shane Farmer | 9ecc075 | 2017-08-24 15:55:36 -0700 | [diff] [blame] | 469 | ASSERT_TRUE(result); |
Shane Farmer | efe4539 | 2017-08-21 14:39:28 -0700 | [diff] [blame^] | 470 | EXPECT_EQ(result.value(), "app.ldpi_en-AU_df1_glx1.v26.mips64.apk"); |
Shane Farmer | 9ecc075 | 2017-08-24 15:55:36 -0700 | [diff] [blame] | 471 | } |
| 472 | |
| 473 | { |
| 474 | auto result = artifact.ToArtifactName( |
Shane Farmer | efe4539 | 2017-08-21 14:39:28 -0700 | [diff] [blame^] | 475 | "${basename}.${density}_${locale}_${feature}_${gl}.${sdk}.${abi}.apk", "app.apk", &diag); |
Shane Farmer | 9ecc075 | 2017-08-24 15:55:36 -0700 | [diff] [blame] | 476 | ASSERT_TRUE(result); |
Shane Farmer | efe4539 | 2017-08-21 14:39:28 -0700 | [diff] [blame^] | 477 | EXPECT_EQ(result.value(), "app.ldpi_en-AU_df1_glx1.v26.mips64.apk"); |
Shane Farmer | 9ecc075 | 2017-08-24 15:55:36 -0700 | [diff] [blame] | 478 | } |
| 479 | |
| 480 | { |
| 481 | auto result = artifact.ToArtifactName( |
Shane Farmer | efe4539 | 2017-08-21 14:39:28 -0700 | [diff] [blame^] | 482 | "app.${density}_${locale}_${feature}_${gl}.${sdk}.${abi}.${ext}", "app.apk", &diag); |
Shane Farmer | 9ecc075 | 2017-08-24 15:55:36 -0700 | [diff] [blame] | 483 | ASSERT_TRUE(result); |
Shane Farmer | efe4539 | 2017-08-21 14:39:28 -0700 | [diff] [blame^] | 484 | EXPECT_EQ(result.value(), "app.ldpi_en-AU_df1_glx1.v26.mips64.apk"); |
Shane Farmer | 9ecc075 | 2017-08-24 15:55:36 -0700 | [diff] [blame] | 485 | } |
| 486 | |
| 487 | { |
| 488 | auto result = artifact.ToArtifactName( |
Shane Farmer | efe4539 | 2017-08-21 14:39:28 -0700 | [diff] [blame^] | 489 | "${basename}.${density}_${locale}_${feature}_${gl}.${sdk}.${abi}", "app.apk", &diag); |
Shane Farmer | 9ecc075 | 2017-08-24 15:55:36 -0700 | [diff] [blame] | 490 | ASSERT_TRUE(result); |
Shane Farmer | efe4539 | 2017-08-21 14:39:28 -0700 | [diff] [blame^] | 491 | EXPECT_EQ(result.value(), "app.ldpi_en-AU_df1_glx1.v26.mips64.apk"); |
Shane Farmer | 9ecc075 | 2017-08-24 15:55:36 -0700 | [diff] [blame] | 492 | } |
Shane Farmer | 9f0e7f1 | 2017-06-22 12:26:44 -0700 | [diff] [blame] | 493 | } |
| 494 | |
| 495 | TEST(ArtifactTest, Missing) { |
| 496 | StdErrDiagnostics diag; |
| 497 | Artifact x86; |
| 498 | x86.abi_group = {"x86"}; |
| 499 | |
Shane Farmer | 9ecc075 | 2017-08-24 15:55:36 -0700 | [diff] [blame] | 500 | 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 Farmer | 9f0e7f1 | 2017-06-22 12:26:44 -0700 | [diff] [blame] | 504 | } |
| 505 | |
| 506 | TEST(ArtifactTest, Empty) { |
| 507 | StdErrDiagnostics diag; |
| 508 | Artifact artifact; |
| 509 | |
Shane Farmer | 9ecc075 | 2017-08-24 15:55:36 -0700 | [diff] [blame] | 510 | 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 Farmer | 9f0e7f1 | 2017-06-22 12:26:44 -0700 | [diff] [blame] | 514 | } |
| 515 | |
Shane Farmer | 1a21b8c | 2017-07-21 09:42:42 -0700 | [diff] [blame] | 516 | TEST(ArtifactTest, Repeated) { |
| 517 | StdErrDiagnostics diag; |
| 518 | Artifact artifact; |
| 519 | artifact.screen_density_group = {"mdpi"}; |
| 520 | |
Shane Farmer | 9ecc075 | 2017-08-24 15:55:36 -0700 | [diff] [blame] | 521 | 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 Farmer | 1a21b8c | 2017-07-21 09:42:42 -0700 | [diff] [blame] | 524 | } |
| 525 | |
| 526 | TEST(ArtifactTest, Nesting) { |
| 527 | StdErrDiagnostics diag; |
| 528 | Artifact x86; |
| 529 | x86.abi_group = {"x86"}; |
| 530 | |
Shane Farmer | 9ecc075 | 2017-08-24 15:55:36 -0700 | [diff] [blame] | 531 | EXPECT_FALSE(x86.ToArtifactName("something.${abi${density}}.apk", "", &diag)); |
Shane Farmer | 1a21b8c | 2017-07-21 09:42:42 -0700 | [diff] [blame] | 532 | |
Shane Farmer | 9ecc075 | 2017-08-24 15:55:36 -0700 | [diff] [blame] | 533 | const Maybe<std::string>& name = x86.ToArtifactName("something.${abi${abi}}.apk", "", &diag); |
Shane Farmer | 0a5b201 | 2017-06-22 12:24:12 -0700 | [diff] [blame] | 534 | ASSERT_TRUE(name); |
| 535 | EXPECT_EQ(name.value(), "something.${abix86}.apk"); |
Shane Farmer | 1a21b8c | 2017-07-21 09:42:42 -0700 | [diff] [blame] | 536 | } |
| 537 | |
| 538 | TEST(ArtifactTest, Recursive) { |
| 539 | StdErrDiagnostics diag; |
| 540 | Artifact artifact; |
Shane Farmer | 0a5b201 | 2017-06-22 12:24:12 -0700 | [diff] [blame] | 541 | artifact.device_feature_group = {"${gl}"}; |
Shane Farmer | 1a21b8c | 2017-07-21 09:42:42 -0700 | [diff] [blame] | 542 | artifact.gl_texture_group = {"glx1"}; |
| 543 | |
Shane Farmer | 9ecc075 | 2017-08-24 15:55:36 -0700 | [diff] [blame] | 544 | EXPECT_FALSE(artifact.ToArtifactName("app.${feature}.${gl}.apk", "", &diag)); |
Shane Farmer | 1a21b8c | 2017-07-21 09:42:42 -0700 | [diff] [blame] | 545 | |
| 546 | artifact.device_feature_group = {"df1"}; |
Shane Farmer | 0a5b201 | 2017-06-22 12:24:12 -0700 | [diff] [blame] | 547 | artifact.gl_texture_group = {"${feature}"}; |
Shane Farmer | 1a21b8c | 2017-07-21 09:42:42 -0700 | [diff] [blame] | 548 | { |
Shane Farmer | 9ecc075 | 2017-08-24 15:55:36 -0700 | [diff] [blame] | 549 | const auto& result = artifact.ToArtifactName("app.${feature}.${gl}.apk", "", &diag); |
Shane Farmer | 0a5b201 | 2017-06-22 12:24:12 -0700 | [diff] [blame] | 550 | ASSERT_TRUE(result); |
| 551 | EXPECT_EQ(result.value(), "app.df1.${feature}.apk"); |
Shane Farmer | 1a21b8c | 2017-07-21 09:42:42 -0700 | [diff] [blame] | 552 | } |
| 553 | |
| 554 | // This is an invalid case, but should be the only possible case due to the ordering of |
| 555 | // replacement. |
Shane Farmer | 0a5b201 | 2017-06-22 12:24:12 -0700 | [diff] [blame] | 556 | artifact.device_feature_group = {"${gl}"}; |
Shane Farmer | 1a21b8c | 2017-07-21 09:42:42 -0700 | [diff] [blame] | 557 | artifact.gl_texture_group = {"glx1"}; |
| 558 | { |
Shane Farmer | 9ecc075 | 2017-08-24 15:55:36 -0700 | [diff] [blame] | 559 | const auto& result = artifact.ToArtifactName("app.${feature}.apk", "", &diag); |
Shane Farmer | 0a5b201 | 2017-06-22 12:24:12 -0700 | [diff] [blame] | 560 | ASSERT_TRUE(result); |
Shane Farmer | 1a21b8c | 2017-07-21 09:42:42 -0700 | [diff] [blame] | 561 | EXPECT_EQ(result.value(), "app.glx1.apk"); |
| 562 | } |
| 563 | } |
| 564 | |
Shane Farmer | 74cdea3 | 2017-05-12 16:22:36 -0700 | [diff] [blame] | 565 | } // namespace |
| 566 | } // namespace aapt |