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 | 67e8a30 | 2017-12-06 14:39:10 -0800 | [diff] [blame] | 21 | #include "android-base/stringprintf.h" |
Shane Farmer | 74cdea3 | 2017-05-12 16:22:36 -0700 | [diff] [blame] | 22 | #include "androidfw/ResourceTypes.h" |
| 23 | |
Shane Farmer | 67e8a30 | 2017-12-06 14:39:10 -0800 | [diff] [blame] | 24 | #include "SdkConstants.h" |
Shane Farmer | 74cdea3 | 2017-05-12 16:22:36 -0700 | [diff] [blame] | 25 | #include "test/Test.h" |
| 26 | #include "xml/XmlDom.h" |
| 27 | |
| 28 | namespace aapt { |
Shane Farmer | 3edd472 | 2017-09-01 14:34:22 -0700 | [diff] [blame] | 29 | |
| 30 | namespace configuration { |
| 31 | void PrintTo(const AndroidSdk& sdk, std::ostream* os) { |
| 32 | *os << "SDK: min=" << sdk.min_sdk_version.value_or_default(-1) |
| 33 | << ", target=" << sdk.target_sdk_version.value_or_default(-1) |
| 34 | << ", max=" << sdk.max_sdk_version.value_or_default(-1); |
| 35 | } |
| 36 | } // namespace configuration |
| 37 | |
Shane Farmer | 74cdea3 | 2017-05-12 16:22:36 -0700 | [diff] [blame] | 38 | namespace { |
| 39 | |
Shane Farmer | 67e8a30 | 2017-12-06 14:39:10 -0800 | [diff] [blame] | 40 | using ::aapt::configuration::Abi; |
| 41 | using ::aapt::configuration::AndroidManifest; |
| 42 | using ::aapt::configuration::AndroidSdk; |
| 43 | using ::aapt::configuration::Artifact; |
| 44 | using ::aapt::configuration::DeviceFeature; |
| 45 | using ::aapt::configuration::GlTexture; |
| 46 | using ::aapt::configuration::Locale; |
| 47 | using ::aapt::configuration::PostProcessingConfiguration; |
| 48 | using ::aapt::xml::Element; |
| 49 | using ::aapt::xml::NodeCast; |
Adam Lesinski | 6b37299 | 2017-08-09 10:54:23 -0700 | [diff] [blame] | 50 | using ::android::ResTable_config; |
Shane Farmer | 67e8a30 | 2017-12-06 14:39:10 -0800 | [diff] [blame] | 51 | using ::android::base::StringPrintf; |
Adam Lesinski | 6b37299 | 2017-08-09 10:54:23 -0700 | [diff] [blame] | 52 | using ::testing::ElementsAre; |
Shane Farmer | 74cdea3 | 2017-05-12 16:22:36 -0700 | [diff] [blame] | 53 | |
| 54 | constexpr const char* kValidConfig = R"(<?xml version="1.0" encoding="utf-8" ?> |
| 55 | <post-process xmlns="http://schemas.android.com/tools/aapt"> |
| 56 | <groups> |
| 57 | <abi-group label="arm"> |
| 58 | <abi>armeabi-v7a</abi> |
| 59 | <abi>arm64-v8a</abi> |
| 60 | </abi-group> |
| 61 | <abi-group label="other"> |
| 62 | <abi>x86</abi> |
| 63 | <abi>mips</abi> |
| 64 | </abi-group> |
| 65 | <screen-density-group label="large"> |
| 66 | <screen-density>xhdpi</screen-density> |
| 67 | <screen-density>xxhdpi</screen-density> |
| 68 | <screen-density>xxxhdpi</screen-density> |
| 69 | </screen-density-group> |
| 70 | <screen-density-group label="alldpi"> |
| 71 | <screen-density>ldpi</screen-density> |
| 72 | <screen-density>mdpi</screen-density> |
| 73 | <screen-density>hdpi</screen-density> |
| 74 | <screen-density>xhdpi</screen-density> |
| 75 | <screen-density>xxhdpi</screen-density> |
| 76 | <screen-density>xxxhdpi</screen-density> |
| 77 | </screen-density-group> |
| 78 | <locale-group label="europe"> |
Shane Farmer | 0a5b201 | 2017-06-22 12:24:12 -0700 | [diff] [blame] | 79 | <locale>en</locale> |
| 80 | <locale>es</locale> |
| 81 | <locale>fr</locale> |
| 82 | <locale>de</locale> |
Shane Farmer | 74cdea3 | 2017-05-12 16:22:36 -0700 | [diff] [blame] | 83 | </locale-group> |
| 84 | <locale-group label="north-america"> |
Shane Farmer | 0a5b201 | 2017-06-22 12:24:12 -0700 | [diff] [blame] | 85 | <locale>en</locale> |
| 86 | <locale>es-rMX</locale> |
| 87 | <locale>fr-rCA</locale> |
Shane Farmer | 74cdea3 | 2017-05-12 16:22:36 -0700 | [diff] [blame] | 88 | </locale-group> |
Shane Farmer | efe4539 | 2017-08-21 14:39:28 -0700 | [diff] [blame] | 89 | <android-sdk-group label="v19"> |
Shane Farmer | 74cdea3 | 2017-05-12 16:22:36 -0700 | [diff] [blame] | 90 | <android-sdk |
Shane Farmer | 3edd472 | 2017-09-01 14:34:22 -0700 | [diff] [blame] | 91 | minSdkVersion="19" |
| 92 | targetSdkVersion="24" |
| 93 | maxSdkVersion="25"> |
Shane Farmer | 74cdea3 | 2017-05-12 16:22:36 -0700 | [diff] [blame] | 94 | <manifest> |
| 95 | <!--- manifest additions here XSLT? TODO --> |
| 96 | </manifest> |
| 97 | </android-sdk> |
| 98 | </android-sdk-group> |
| 99 | <gl-texture-group label="dxt1"> |
| 100 | <gl-texture name="GL_EXT_texture_compression_dxt1"> |
| 101 | <texture-path>assets/dxt1/*</texture-path> |
| 102 | </gl-texture> |
| 103 | </gl-texture-group> |
| 104 | <device-feature-group label="low-latency"> |
| 105 | <supports-feature>android.hardware.audio.low_latency</supports-feature> |
| 106 | </device-feature-group> |
| 107 | </groups> |
| 108 | <artifacts> |
| 109 | <artifact-format> |
| 110 | ${base}.${abi}.${screen-density}.${locale}.${sdk}.${gl}.${feature}.release |
| 111 | </artifact-format> |
| 112 | <artifact |
| 113 | name="art1" |
| 114 | abi-group="arm" |
| 115 | screen-density-group="large" |
| 116 | locale-group="europe" |
Shane Farmer | efe4539 | 2017-08-21 14:39:28 -0700 | [diff] [blame] | 117 | android-sdk-group="v19" |
Shane Farmer | 74cdea3 | 2017-05-12 16:22:36 -0700 | [diff] [blame] | 118 | gl-texture-group="dxt1" |
| 119 | device-feature-group="low-latency"/> |
| 120 | <artifact |
| 121 | name="art2" |
| 122 | abi-group="other" |
| 123 | screen-density-group="alldpi" |
| 124 | locale-group="north-america" |
Shane Farmer | efe4539 | 2017-08-21 14:39:28 -0700 | [diff] [blame] | 125 | android-sdk-group="v19" |
Shane Farmer | 74cdea3 | 2017-05-12 16:22:36 -0700 | [diff] [blame] | 126 | gl-texture-group="dxt1" |
| 127 | device-feature-group="low-latency"/> |
| 128 | </artifacts> |
| 129 | </post-process> |
| 130 | )"; |
| 131 | |
| 132 | class ConfigurationParserTest : public ConfigurationParser, public ::testing::Test { |
| 133 | public: |
| 134 | ConfigurationParserTest() : ConfigurationParser("") {} |
| 135 | |
| 136 | protected: |
| 137 | StdErrDiagnostics diag_; |
| 138 | }; |
| 139 | |
Shane Farmer | b102727 | 2017-06-14 09:10:28 -0700 | [diff] [blame] | 140 | TEST_F(ConfigurationParserTest, ForPath_NoFile) { |
| 141 | auto result = ConfigurationParser::ForPath("./does_not_exist.xml"); |
| 142 | EXPECT_FALSE(result); |
| 143 | } |
| 144 | |
Shane Farmer | 74cdea3 | 2017-05-12 16:22:36 -0700 | [diff] [blame] | 145 | TEST_F(ConfigurationParserTest, ValidateFile) { |
| 146 | auto parser = ConfigurationParser::ForContents(kValidConfig).WithDiagnostics(&diag_); |
| 147 | auto result = parser.Parse(); |
| 148 | ASSERT_TRUE(result); |
Shane Farmer | 280be34 | 2017-06-21 15:20:15 -0700 | [diff] [blame] | 149 | PostProcessingConfiguration& value = result.value(); |
Shane Farmer | 74cdea3 | 2017-05-12 16:22:36 -0700 | [diff] [blame] | 150 | EXPECT_EQ(2ul, value.artifacts.size()); |
| 151 | ASSERT_TRUE(value.artifact_format); |
| 152 | EXPECT_EQ( |
| 153 | "${base}.${abi}.${screen-density}.${locale}.${sdk}.${gl}.${feature}.release", |
| 154 | value.artifact_format.value() |
| 155 | ); |
| 156 | |
| 157 | EXPECT_EQ(2ul, value.abi_groups.size()); |
| 158 | EXPECT_EQ(2ul, value.abi_groups["arm"].size()); |
| 159 | EXPECT_EQ(2ul, value.abi_groups["other"].size()); |
| 160 | |
| 161 | EXPECT_EQ(2ul, value.screen_density_groups.size()); |
| 162 | EXPECT_EQ(3ul, value.screen_density_groups["large"].size()); |
| 163 | EXPECT_EQ(6ul, value.screen_density_groups["alldpi"].size()); |
| 164 | |
Shane Farmer | 0a5b201 | 2017-06-22 12:24:12 -0700 | [diff] [blame] | 165 | EXPECT_EQ(2ul, value.locale_groups.size()); |
Shane Farmer | 74cdea3 | 2017-05-12 16:22:36 -0700 | [diff] [blame] | 166 | EXPECT_EQ(4ul, value.locale_groups["europe"].size()); |
| 167 | EXPECT_EQ(3ul, value.locale_groups["north-america"].size()); |
Shane Farmer | 74cdea3 | 2017-05-12 16:22:36 -0700 | [diff] [blame] | 168 | |
| 169 | EXPECT_EQ(1ul, value.android_sdk_groups.size()); |
Shane Farmer | efe4539 | 2017-08-21 14:39:28 -0700 | [diff] [blame] | 170 | EXPECT_TRUE(value.android_sdk_groups["v19"].min_sdk_version); |
Shane Farmer | 3edd472 | 2017-09-01 14:34:22 -0700 | [diff] [blame] | 171 | EXPECT_EQ(19, value.android_sdk_groups["v19"].min_sdk_version.value()); |
Shane Farmer | 74cdea3 | 2017-05-12 16:22:36 -0700 | [diff] [blame] | 172 | |
| 173 | EXPECT_EQ(1ul, value.gl_texture_groups.size()); |
| 174 | EXPECT_EQ(1ul, value.gl_texture_groups["dxt1"].size()); |
| 175 | |
| 176 | EXPECT_EQ(1ul, value.device_feature_groups.size()); |
| 177 | EXPECT_EQ(1ul, value.device_feature_groups["low-latency"].size()); |
| 178 | } |
| 179 | |
| 180 | TEST_F(ConfigurationParserTest, InvalidNamespace) { |
| 181 | constexpr const char* invalid_ns = R"(<?xml version="1.0" encoding="utf-8" ?> |
| 182 | <post-process xmlns="http://schemas.android.com/tools/another-unknown-tool" />)"; |
| 183 | |
| 184 | auto result = ConfigurationParser::ForContents(invalid_ns).Parse(); |
| 185 | ASSERT_FALSE(result); |
| 186 | } |
| 187 | |
| 188 | TEST_F(ConfigurationParserTest, ArtifactAction) { |
Shane Farmer | 810fd18 | 2017-09-21 14:37:44 -0700 | [diff] [blame] | 189 | PostProcessingConfiguration config; |
| 190 | { |
| 191 | const auto doc = test::BuildXmlDom(R"xml( |
| 192 | <artifact |
| 193 | abi-group="arm" |
| 194 | screen-density-group="large" |
| 195 | locale-group="europe" |
| 196 | android-sdk-group="v19" |
| 197 | gl-texture-group="dxt1" |
| 198 | device-feature-group="low-latency"/>)xml"); |
| 199 | |
| 200 | ASSERT_TRUE(artifact_handler_(&config, NodeCast<Element>(doc->root.get()), &diag_)); |
| 201 | |
| 202 | EXPECT_EQ(1ul, config.artifacts.size()); |
| 203 | |
| 204 | auto& artifact = config.artifacts.back(); |
| 205 | EXPECT_FALSE(artifact.name); // TODO: make this fail. |
| 206 | EXPECT_EQ(1, artifact.version); |
| 207 | EXPECT_EQ("arm", artifact.abi_group.value()); |
| 208 | EXPECT_EQ("large", artifact.screen_density_group.value()); |
| 209 | EXPECT_EQ("europe", artifact.locale_group.value()); |
| 210 | EXPECT_EQ("v19", artifact.android_sdk_group.value()); |
| 211 | EXPECT_EQ("dxt1", artifact.gl_texture_group.value()); |
| 212 | EXPECT_EQ("low-latency", artifact.device_feature_group.value()); |
| 213 | } |
| 214 | |
| 215 | { |
| 216 | // Perform a second action to ensure we get 2 artifacts. |
| 217 | const auto doc = test::BuildXmlDom(R"xml( |
| 218 | <artifact |
| 219 | abi-group="other" |
| 220 | screen-density-group="large" |
| 221 | locale-group="europe" |
| 222 | android-sdk-group="v19" |
| 223 | gl-texture-group="dxt1" |
| 224 | device-feature-group="low-latency"/>)xml"); |
| 225 | |
| 226 | ASSERT_TRUE(artifact_handler_(&config, NodeCast<Element>(doc.get()->root.get()), &diag_)); |
| 227 | EXPECT_EQ(2ul, config.artifacts.size()); |
| 228 | EXPECT_EQ(2, config.artifacts.back().version); |
| 229 | } |
| 230 | |
| 231 | { |
| 232 | // Perform a third action with a set version code. |
| 233 | const auto doc = test::BuildXmlDom(R"xml( |
Shane Farmer | 74cdea3 | 2017-05-12 16:22:36 -0700 | [diff] [blame] | 234 | <artifact |
Shane Farmer | 810fd18 | 2017-09-21 14:37:44 -0700 | [diff] [blame] | 235 | version="5" |
| 236 | abi-group="other" |
Shane Farmer | 74cdea3 | 2017-05-12 16:22:36 -0700 | [diff] [blame] | 237 | screen-density-group="large" |
| 238 | locale-group="europe" |
Shane Farmer | efe4539 | 2017-08-21 14:39:28 -0700 | [diff] [blame] | 239 | android-sdk-group="v19" |
Shane Farmer | 74cdea3 | 2017-05-12 16:22:36 -0700 | [diff] [blame] | 240 | gl-texture-group="dxt1" |
Shane Farmer | 810fd18 | 2017-09-21 14:37:44 -0700 | [diff] [blame] | 241 | device-feature-group="low-latency"/>)xml"); |
Shane Farmer | 74cdea3 | 2017-05-12 16:22:36 -0700 | [diff] [blame] | 242 | |
Shane Farmer | 810fd18 | 2017-09-21 14:37:44 -0700 | [diff] [blame] | 243 | ASSERT_TRUE(artifact_handler_(&config, NodeCast<Element>(doc.get()->root.get()), &diag_)); |
| 244 | EXPECT_EQ(3ul, config.artifacts.size()); |
| 245 | EXPECT_EQ(5, config.artifacts.back().version); |
| 246 | } |
Shane Farmer | 74cdea3 | 2017-05-12 16:22:36 -0700 | [diff] [blame] | 247 | |
Shane Farmer | 810fd18 | 2017-09-21 14:37:44 -0700 | [diff] [blame] | 248 | { |
| 249 | // Perform a fourth action to ensure the version code still increments. |
| 250 | const auto doc = test::BuildXmlDom(R"xml( |
Shane Farmer | 5766943 | 2017-06-19 12:52:04 -0700 | [diff] [blame] | 251 | <artifact |
| 252 | abi-group="other" |
| 253 | screen-density-group="large" |
| 254 | locale-group="europe" |
Shane Farmer | efe4539 | 2017-08-21 14:39:28 -0700 | [diff] [blame] | 255 | android-sdk-group="v19" |
Shane Farmer | 5766943 | 2017-06-19 12:52:04 -0700 | [diff] [blame] | 256 | gl-texture-group="dxt1" |
Shane Farmer | 810fd18 | 2017-09-21 14:37:44 -0700 | [diff] [blame] | 257 | device-feature-group="low-latency"/>)xml"); |
Shane Farmer | 5766943 | 2017-06-19 12:52:04 -0700 | [diff] [blame] | 258 | |
Shane Farmer | 810fd18 | 2017-09-21 14:37:44 -0700 | [diff] [blame] | 259 | ASSERT_TRUE(artifact_handler_(&config, NodeCast<Element>(doc.get()->root.get()), &diag_)); |
| 260 | EXPECT_EQ(4ul, config.artifacts.size()); |
| 261 | EXPECT_EQ(6, config.artifacts.back().version); |
| 262 | } |
| 263 | } |
| 264 | |
| 265 | TEST_F(ConfigurationParserTest, DuplicateArtifactVersion) { |
| 266 | static constexpr const char* configuration = R"xml(<?xml version="1.0" encoding="utf-8" ?> |
| 267 | <pst-process xmlns="http://schemas.android.com/tools/aapt">> |
| 268 | <artifacts> |
| 269 | <artifact-format> |
| 270 | ${base}.${abi}.${screen-density}.${locale}.${sdk}.${gl}.${feature}.release |
| 271 | </artifact-format> |
| 272 | <artifact |
| 273 | name="art1" |
| 274 | abi-group="arm" |
| 275 | screen-density-group="large" |
| 276 | locale-group="europe" |
| 277 | android-sdk-group="v19" |
| 278 | gl-texture-group="dxt1" |
| 279 | device-feature-group="low-latency"/> |
| 280 | <artifact |
| 281 | name="art2" |
| 282 | version = "1" |
| 283 | abi-group="other" |
| 284 | screen-density-group="alldpi" |
| 285 | locale-group="north-america" |
| 286 | android-sdk-group="v19" |
| 287 | gl-texture-group="dxt1" |
| 288 | device-feature-group="low-latency"/> |
| 289 | </artifacts> |
| 290 | </post-process>)xml"; |
| 291 | auto result = ConfigurationParser::ForContents(configuration).Parse(); |
| 292 | ASSERT_FALSE(result); |
Shane Farmer | 74cdea3 | 2017-05-12 16:22:36 -0700 | [diff] [blame] | 293 | } |
| 294 | |
| 295 | TEST_F(ConfigurationParserTest, ArtifactFormatAction) { |
Shane Farmer | 810fd18 | 2017-09-21 14:37:44 -0700 | [diff] [blame] | 296 | const auto doc = test::BuildXmlDom(R"xml( |
Shane Farmer | 74cdea3 | 2017-05-12 16:22:36 -0700 | [diff] [blame] | 297 | <artifact-format> |
| 298 | ${base}.${abi}.${screen-density}.${locale}.${sdk}.${gl}.${feature}.release |
Shane Farmer | 810fd18 | 2017-09-21 14:37:44 -0700 | [diff] [blame] | 299 | </artifact-format>)xml"); |
Shane Farmer | 74cdea3 | 2017-05-12 16:22:36 -0700 | [diff] [blame] | 300 | |
Shane Farmer | 280be34 | 2017-06-21 15:20:15 -0700 | [diff] [blame] | 301 | PostProcessingConfiguration config; |
Shane Farmer | 74cdea3 | 2017-05-12 16:22:36 -0700 | [diff] [blame] | 302 | bool ok = artifact_format_handler_(&config, NodeCast<Element>(doc.get()->root.get()), &diag_); |
| 303 | ASSERT_TRUE(ok); |
| 304 | ASSERT_TRUE(config.artifact_format); |
| 305 | EXPECT_EQ( |
| 306 | "${base}.${abi}.${screen-density}.${locale}.${sdk}.${gl}.${feature}.release", |
| 307 | static_cast<std::string>(config.artifact_format.value()) |
| 308 | ); |
| 309 | } |
| 310 | |
| 311 | TEST_F(ConfigurationParserTest, AbiGroupAction) { |
| 312 | static constexpr const char* xml = R"xml( |
| 313 | <abi-group label="arm"> |
| 314 | <!-- First comment. --> |
| 315 | <abi> |
| 316 | armeabi-v7a |
| 317 | </abi> |
| 318 | <!-- Another comment. --> |
| 319 | <abi>arm64-v8a</abi> |
| 320 | </abi-group>)xml"; |
| 321 | |
| 322 | auto doc = test::BuildXmlDom(xml); |
| 323 | |
Shane Farmer | 280be34 | 2017-06-21 15:20:15 -0700 | [diff] [blame] | 324 | PostProcessingConfiguration config; |
Shane Farmer | 74cdea3 | 2017-05-12 16:22:36 -0700 | [diff] [blame] | 325 | bool ok = abi_group_handler_(&config, NodeCast<Element>(doc.get()->root.get()), &diag_); |
| 326 | ASSERT_TRUE(ok); |
| 327 | |
| 328 | EXPECT_EQ(1ul, config.abi_groups.size()); |
| 329 | ASSERT_EQ(1u, config.abi_groups.count("arm")); |
| 330 | |
| 331 | auto& out = config.abi_groups["arm"]; |
| 332 | ASSERT_THAT(out, ElementsAre(Abi::kArmV7a, Abi::kArm64V8a)); |
| 333 | } |
| 334 | |
| 335 | TEST_F(ConfigurationParserTest, ScreenDensityGroupAction) { |
| 336 | static constexpr const char* xml = R"xml( |
| 337 | <screen-density-group label="large"> |
| 338 | <screen-density>xhdpi</screen-density> |
| 339 | <screen-density> |
| 340 | xxhdpi |
| 341 | </screen-density> |
| 342 | <screen-density>xxxhdpi</screen-density> |
| 343 | </screen-density-group>)xml"; |
| 344 | |
| 345 | auto doc = test::BuildXmlDom(xml); |
| 346 | |
Shane Farmer | 280be34 | 2017-06-21 15:20:15 -0700 | [diff] [blame] | 347 | PostProcessingConfiguration config; |
Shane Farmer | 74cdea3 | 2017-05-12 16:22:36 -0700 | [diff] [blame] | 348 | bool ok = |
| 349 | screen_density_group_handler_(&config, NodeCast<Element>(doc.get()->root.get()), &diag_); |
| 350 | ASSERT_TRUE(ok); |
| 351 | |
| 352 | EXPECT_EQ(1ul, config.screen_density_groups.size()); |
| 353 | ASSERT_EQ(1u, config.screen_density_groups.count("large")); |
| 354 | |
| 355 | ConfigDescription xhdpi; |
| 356 | xhdpi.density = ResTable_config::DENSITY_XHIGH; |
| 357 | ConfigDescription xxhdpi; |
| 358 | xxhdpi.density = ResTable_config::DENSITY_XXHIGH; |
| 359 | ConfigDescription xxxhdpi; |
| 360 | xxxhdpi.density = ResTable_config::DENSITY_XXXHIGH; |
| 361 | |
| 362 | auto& out = config.screen_density_groups["large"]; |
| 363 | ASSERT_THAT(out, ElementsAre(xhdpi, xxhdpi, xxxhdpi)); |
| 364 | } |
| 365 | |
| 366 | TEST_F(ConfigurationParserTest, LocaleGroupAction) { |
| 367 | static constexpr const char* xml = R"xml( |
| 368 | <locale-group label="europe"> |
Shane Farmer | 0a5b201 | 2017-06-22 12:24:12 -0700 | [diff] [blame] | 369 | <locale>en</locale> |
| 370 | <locale>es</locale> |
| 371 | <locale>fr</locale> |
| 372 | <locale>de</locale> |
Shane Farmer | 74cdea3 | 2017-05-12 16:22:36 -0700 | [diff] [blame] | 373 | </locale-group>)xml"; |
| 374 | |
| 375 | auto doc = test::BuildXmlDom(xml); |
| 376 | |
Shane Farmer | 280be34 | 2017-06-21 15:20:15 -0700 | [diff] [blame] | 377 | PostProcessingConfiguration config; |
Shane Farmer | 74cdea3 | 2017-05-12 16:22:36 -0700 | [diff] [blame] | 378 | bool ok = locale_group_handler_(&config, NodeCast<Element>(doc.get()->root.get()), &diag_); |
| 379 | ASSERT_TRUE(ok); |
| 380 | |
| 381 | ASSERT_EQ(1ul, config.locale_groups.size()); |
| 382 | ASSERT_EQ(1u, config.locale_groups.count("europe")); |
| 383 | |
Shane Farmer | 0a5b201 | 2017-06-22 12:24:12 -0700 | [diff] [blame] | 384 | const auto& out = config.locale_groups["europe"]; |
Shane Farmer | 74cdea3 | 2017-05-12 16:22:36 -0700 | [diff] [blame] | 385 | |
Shane Farmer | 0a5b201 | 2017-06-22 12:24:12 -0700 | [diff] [blame] | 386 | ConfigDescription en = test::ParseConfigOrDie("en"); |
| 387 | ConfigDescription es = test::ParseConfigOrDie("es"); |
| 388 | ConfigDescription fr = test::ParseConfigOrDie("fr"); |
| 389 | ConfigDescription de = test::ParseConfigOrDie("de"); |
Shane Farmer | 74cdea3 | 2017-05-12 16:22:36 -0700 | [diff] [blame] | 390 | |
| 391 | ASSERT_THAT(out, ElementsAre(en, es, fr, de)); |
| 392 | } |
| 393 | |
| 394 | TEST_F(ConfigurationParserTest, AndroidSdkGroupAction) { |
| 395 | static constexpr const char* xml = R"xml( |
Shane Farmer | efe4539 | 2017-08-21 14:39:28 -0700 | [diff] [blame] | 396 | <android-sdk-group label="v19"> |
Shane Farmer | 74cdea3 | 2017-05-12 16:22:36 -0700 | [diff] [blame] | 397 | <android-sdk |
Shane Farmer | 3edd472 | 2017-09-01 14:34:22 -0700 | [diff] [blame] | 398 | minSdkVersion="19" |
| 399 | targetSdkVersion="24" |
| 400 | maxSdkVersion="25"> |
Shane Farmer | 74cdea3 | 2017-05-12 16:22:36 -0700 | [diff] [blame] | 401 | <manifest> |
| 402 | <!--- manifest additions here XSLT? TODO --> |
| 403 | </manifest> |
| 404 | </android-sdk> |
| 405 | </android-sdk-group>)xml"; |
| 406 | |
| 407 | auto doc = test::BuildXmlDom(xml); |
| 408 | |
Shane Farmer | 280be34 | 2017-06-21 15:20:15 -0700 | [diff] [blame] | 409 | PostProcessingConfiguration config; |
Shane Farmer | 74cdea3 | 2017-05-12 16:22:36 -0700 | [diff] [blame] | 410 | bool ok = android_sdk_group_handler_(&config, NodeCast<Element>(doc.get()->root.get()), &diag_); |
| 411 | ASSERT_TRUE(ok); |
| 412 | |
| 413 | ASSERT_EQ(1ul, config.android_sdk_groups.size()); |
Shane Farmer | efe4539 | 2017-08-21 14:39:28 -0700 | [diff] [blame] | 414 | ASSERT_EQ(1u, config.android_sdk_groups.count("v19")); |
Shane Farmer | 74cdea3 | 2017-05-12 16:22:36 -0700 | [diff] [blame] | 415 | |
Shane Farmer | efe4539 | 2017-08-21 14:39:28 -0700 | [diff] [blame] | 416 | auto& out = config.android_sdk_groups["v19"]; |
Shane Farmer | 74cdea3 | 2017-05-12 16:22:36 -0700 | [diff] [blame] | 417 | |
| 418 | AndroidSdk sdk; |
Shane Farmer | 3edd472 | 2017-09-01 14:34:22 -0700 | [diff] [blame] | 419 | sdk.min_sdk_version = 19; |
| 420 | sdk.target_sdk_version = 24; |
| 421 | sdk.max_sdk_version = 25; |
Shane Farmer | 74cdea3 | 2017-05-12 16:22:36 -0700 | [diff] [blame] | 422 | sdk.manifest = AndroidManifest(); |
| 423 | |
Shane Farmer | efe4539 | 2017-08-21 14:39:28 -0700 | [diff] [blame] | 424 | ASSERT_EQ(sdk, out); |
Shane Farmer | 74cdea3 | 2017-05-12 16:22:36 -0700 | [diff] [blame] | 425 | } |
| 426 | |
Shane Farmer | 67e8a30 | 2017-12-06 14:39:10 -0800 | [diff] [blame] | 427 | TEST_F(ConfigurationParserTest, AndroidSdkGroupAction_SingleVersion) { |
| 428 | { |
| 429 | static constexpr const char* xml = R"xml( |
| 430 | <android-sdk-group label="v19"> |
| 431 | <android-sdk minSdkVersion="19"></android-sdk> |
| 432 | </android-sdk-group>)xml"; |
| 433 | |
| 434 | auto doc = test::BuildXmlDom(xml); |
| 435 | |
| 436 | PostProcessingConfiguration config; |
| 437 | bool ok = android_sdk_group_handler_(&config, NodeCast<Element>(doc.get()->root.get()), &diag_); |
| 438 | ASSERT_TRUE(ok); |
| 439 | |
| 440 | ASSERT_EQ(1ul, config.android_sdk_groups.size()); |
| 441 | ASSERT_EQ(1u, config.android_sdk_groups.count("v19")); |
| 442 | |
| 443 | auto& out = config.android_sdk_groups["v19"]; |
| 444 | EXPECT_EQ(19, out.min_sdk_version.value()); |
| 445 | EXPECT_FALSE(out.max_sdk_version); |
| 446 | EXPECT_FALSE(out.target_sdk_version); |
| 447 | } |
| 448 | |
| 449 | { |
| 450 | static constexpr const char* xml = R"xml( |
| 451 | <android-sdk-group label="v19"> |
| 452 | <android-sdk maxSdkVersion="19"></android-sdk> |
| 453 | </android-sdk-group>)xml"; |
| 454 | |
| 455 | auto doc = test::BuildXmlDom(xml); |
| 456 | |
| 457 | PostProcessingConfiguration config; |
| 458 | bool ok = android_sdk_group_handler_(&config, NodeCast<Element>(doc.get()->root.get()), &diag_); |
| 459 | ASSERT_TRUE(ok); |
| 460 | |
| 461 | ASSERT_EQ(1ul, config.android_sdk_groups.size()); |
| 462 | ASSERT_EQ(1u, config.android_sdk_groups.count("v19")); |
| 463 | |
| 464 | auto& out = config.android_sdk_groups["v19"]; |
| 465 | EXPECT_EQ(19, out.max_sdk_version.value()); |
| 466 | EXPECT_FALSE(out.min_sdk_version); |
| 467 | EXPECT_FALSE(out.target_sdk_version); |
| 468 | } |
| 469 | |
| 470 | { |
| 471 | static constexpr const char* xml = R"xml( |
| 472 | <android-sdk-group label="v19"> |
| 473 | <android-sdk targetSdkVersion="19"></android-sdk> |
| 474 | </android-sdk-group>)xml"; |
| 475 | |
| 476 | auto doc = test::BuildXmlDom(xml); |
| 477 | |
| 478 | PostProcessingConfiguration config; |
| 479 | bool ok = android_sdk_group_handler_(&config, NodeCast<Element>(doc.get()->root.get()), &diag_); |
| 480 | ASSERT_TRUE(ok); |
| 481 | |
| 482 | ASSERT_EQ(1ul, config.android_sdk_groups.size()); |
| 483 | ASSERT_EQ(1u, config.android_sdk_groups.count("v19")); |
| 484 | |
| 485 | auto& out = config.android_sdk_groups["v19"]; |
| 486 | EXPECT_EQ(19, out.target_sdk_version.value()); |
| 487 | EXPECT_FALSE(out.min_sdk_version); |
| 488 | EXPECT_FALSE(out.max_sdk_version); |
| 489 | } |
| 490 | } |
| 491 | |
| 492 | TEST_F(ConfigurationParserTest, AndroidSdkGroupAction_InvalidVersion) { |
Shane Farmer | 3edd472 | 2017-09-01 14:34:22 -0700 | [diff] [blame] | 493 | static constexpr const char* xml = R"xml( |
Shane Farmer | 67e8a30 | 2017-12-06 14:39:10 -0800 | [diff] [blame] | 494 | <android-sdk-group label="v19"> |
Shane Farmer | 3edd472 | 2017-09-01 14:34:22 -0700 | [diff] [blame] | 495 | <android-sdk |
Shane Farmer | 67e8a30 | 2017-12-06 14:39:10 -0800 | [diff] [blame] | 496 | minSdkVersion="v19" |
| 497 | targetSdkVersion="v24" |
| 498 | maxSdkVersion="v25"> |
| 499 | <manifest> |
| 500 | <!--- manifest additions here XSLT? TODO --> |
| 501 | </manifest> |
Shane Farmer | 3edd472 | 2017-09-01 14:34:22 -0700 | [diff] [blame] | 502 | </android-sdk> |
| 503 | </android-sdk-group>)xml"; |
| 504 | |
| 505 | auto doc = test::BuildXmlDom(xml); |
| 506 | |
| 507 | PostProcessingConfiguration config; |
| 508 | bool ok = android_sdk_group_handler_(&config, NodeCast<Element>(doc.get()->root.get()), &diag_); |
Shane Farmer | 67e8a30 | 2017-12-06 14:39:10 -0800 | [diff] [blame] | 509 | ASSERT_FALSE(ok); |
| 510 | } |
| 511 | |
| 512 | TEST_F(ConfigurationParserTest, AndroidSdkGroupAction_NonNumeric) { |
| 513 | static constexpr const char* xml = R"xml( |
| 514 | <android-sdk-group label="P"> |
| 515 | <android-sdk |
| 516 | minSdkVersion="25" |
| 517 | targetSdkVersion="%s" |
| 518 | maxSdkVersion="%s"> |
| 519 | </android-sdk> |
| 520 | </android-sdk-group>)xml"; |
| 521 | |
| 522 | const auto& dev_sdk = GetDevelopmentSdkCodeNameAndVersion(); |
| 523 | const char* codename = dev_sdk.first.data(); |
| 524 | const ApiVersion& version = dev_sdk.second; |
| 525 | |
| 526 | auto doc = test::BuildXmlDom(StringPrintf(xml, codename, codename)); |
| 527 | |
| 528 | PostProcessingConfiguration config; |
| 529 | bool ok = android_sdk_group_handler_(&config, NodeCast<Element>(doc.get()->root.get()), &diag_); |
Shane Farmer | 3edd472 | 2017-09-01 14:34:22 -0700 | [diff] [blame] | 530 | ASSERT_TRUE(ok); |
| 531 | |
| 532 | ASSERT_EQ(1ul, config.android_sdk_groups.size()); |
Adam Lesinski | 178e678 | 2017-11-02 14:12:38 -0700 | [diff] [blame] | 533 | ASSERT_EQ(1u, config.android_sdk_groups.count("P")); |
Shane Farmer | 3edd472 | 2017-09-01 14:34:22 -0700 | [diff] [blame] | 534 | |
Adam Lesinski | 178e678 | 2017-11-02 14:12:38 -0700 | [diff] [blame] | 535 | auto& out = config.android_sdk_groups["P"]; |
Shane Farmer | 3edd472 | 2017-09-01 14:34:22 -0700 | [diff] [blame] | 536 | |
| 537 | AndroidSdk sdk; |
Shane Farmer | 67e8a30 | 2017-12-06 14:39:10 -0800 | [diff] [blame] | 538 | sdk.min_sdk_version = 25; |
| 539 | sdk.target_sdk_version = version; |
| 540 | sdk.max_sdk_version = version; |
Shane Farmer | 3edd472 | 2017-09-01 14:34:22 -0700 | [diff] [blame] | 541 | |
| 542 | ASSERT_EQ(sdk, out); |
| 543 | } |
| 544 | |
Shane Farmer | 74cdea3 | 2017-05-12 16:22:36 -0700 | [diff] [blame] | 545 | TEST_F(ConfigurationParserTest, GlTextureGroupAction) { |
| 546 | static constexpr const char* xml = R"xml( |
| 547 | <gl-texture-group label="dxt1"> |
| 548 | <gl-texture name="GL_EXT_texture_compression_dxt1"> |
| 549 | <texture-path>assets/dxt1/main/*</texture-path> |
| 550 | <texture-path> |
| 551 | assets/dxt1/test/* |
| 552 | </texture-path> |
| 553 | </gl-texture> |
| 554 | </gl-texture-group>)xml"; |
| 555 | |
| 556 | auto doc = test::BuildXmlDom(xml); |
| 557 | |
Shane Farmer | 280be34 | 2017-06-21 15:20:15 -0700 | [diff] [blame] | 558 | PostProcessingConfiguration config; |
Shane Farmer | 74cdea3 | 2017-05-12 16:22:36 -0700 | [diff] [blame] | 559 | bool ok = gl_texture_group_handler_(&config, NodeCast<Element>(doc.get()->root.get()), &diag_); |
| 560 | ASSERT_TRUE(ok); |
| 561 | |
| 562 | EXPECT_EQ(1ul, config.gl_texture_groups.size()); |
| 563 | ASSERT_EQ(1u, config.gl_texture_groups.count("dxt1")); |
| 564 | |
| 565 | auto& out = config.gl_texture_groups["dxt1"]; |
| 566 | |
| 567 | GlTexture texture{ |
| 568 | std::string("GL_EXT_texture_compression_dxt1"), |
| 569 | {"assets/dxt1/main/*", "assets/dxt1/test/*"} |
| 570 | }; |
| 571 | |
| 572 | ASSERT_EQ(1ul, out.size()); |
| 573 | ASSERT_EQ(texture, out[0]); |
| 574 | } |
| 575 | |
| 576 | TEST_F(ConfigurationParserTest, DeviceFeatureGroupAction) { |
| 577 | static constexpr const char* xml = R"xml( |
| 578 | <device-feature-group label="low-latency"> |
| 579 | <supports-feature>android.hardware.audio.low_latency</supports-feature> |
| 580 | <supports-feature> |
| 581 | android.hardware.audio.pro |
| 582 | </supports-feature> |
| 583 | </device-feature-group>)xml"; |
| 584 | |
| 585 | auto doc = test::BuildXmlDom(xml); |
| 586 | |
Shane Farmer | 280be34 | 2017-06-21 15:20:15 -0700 | [diff] [blame] | 587 | PostProcessingConfiguration config; |
Shane Farmer | 74cdea3 | 2017-05-12 16:22:36 -0700 | [diff] [blame] | 588 | bool ok |
| 589 | = device_feature_group_handler_(&config, NodeCast<Element>(doc.get()->root.get()), &diag_); |
| 590 | ASSERT_TRUE(ok); |
| 591 | |
| 592 | EXPECT_EQ(1ul, config.device_feature_groups.size()); |
| 593 | ASSERT_EQ(1u, config.device_feature_groups.count("low-latency")); |
| 594 | |
| 595 | auto& out = config.device_feature_groups["low-latency"]; |
| 596 | |
| 597 | DeviceFeature low_latency = "android.hardware.audio.low_latency"; |
| 598 | DeviceFeature pro = "android.hardware.audio.pro"; |
| 599 | ASSERT_THAT(out, ElementsAre(low_latency, pro)); |
| 600 | } |
| 601 | |
Shane Farmer | 1a21b8c | 2017-07-21 09:42:42 -0700 | [diff] [blame] | 602 | // Artifact name parser test cases. |
| 603 | |
Shane Farmer | 9f0e7f1 | 2017-06-22 12:26:44 -0700 | [diff] [blame] | 604 | TEST(ArtifactTest, Simple) { |
| 605 | StdErrDiagnostics diag; |
| 606 | Artifact x86; |
| 607 | x86.abi_group = {"x86"}; |
| 608 | |
Shane Farmer | 9ecc075 | 2017-08-24 15:55:36 -0700 | [diff] [blame] | 609 | auto x86_result = x86.ToArtifactName("something.${abi}.apk", "", &diag); |
Shane Farmer | 9f0e7f1 | 2017-06-22 12:26:44 -0700 | [diff] [blame] | 610 | ASSERT_TRUE(x86_result); |
| 611 | EXPECT_EQ(x86_result.value(), "something.x86.apk"); |
| 612 | |
| 613 | Artifact arm; |
| 614 | arm.abi_group = {"armeabi-v7a"}; |
| 615 | |
Shane Farmer | 9ecc075 | 2017-08-24 15:55:36 -0700 | [diff] [blame] | 616 | { |
| 617 | auto arm_result = arm.ToArtifactName("app.${abi}.apk", "", &diag); |
| 618 | ASSERT_TRUE(arm_result); |
| 619 | EXPECT_EQ(arm_result.value(), "app.armeabi-v7a.apk"); |
| 620 | } |
| 621 | |
| 622 | { |
| 623 | auto arm_result = arm.ToArtifactName("app.${abi}.apk", "different_name.apk", &diag); |
| 624 | ASSERT_TRUE(arm_result); |
| 625 | EXPECT_EQ(arm_result.value(), "app.armeabi-v7a.apk"); |
| 626 | } |
| 627 | |
| 628 | { |
| 629 | auto arm_result = arm.ToArtifactName("${basename}.${abi}.apk", "app.apk", &diag); |
| 630 | ASSERT_TRUE(arm_result); |
| 631 | EXPECT_EQ(arm_result.value(), "app.armeabi-v7a.apk"); |
| 632 | } |
| 633 | |
| 634 | { |
| 635 | auto arm_result = arm.ToArtifactName("app.${abi}.${ext}", "app.apk", &diag); |
| 636 | ASSERT_TRUE(arm_result); |
| 637 | EXPECT_EQ(arm_result.value(), "app.armeabi-v7a.apk"); |
| 638 | } |
Shane Farmer | 9f0e7f1 | 2017-06-22 12:26:44 -0700 | [diff] [blame] | 639 | } |
| 640 | |
| 641 | TEST(ArtifactTest, Complex) { |
| 642 | StdErrDiagnostics diag; |
| 643 | Artifact artifact; |
| 644 | artifact.abi_group = {"mips64"}; |
| 645 | artifact.screen_density_group = {"ldpi"}; |
| 646 | artifact.device_feature_group = {"df1"}; |
| 647 | artifact.gl_texture_group = {"glx1"}; |
| 648 | artifact.locale_group = {"en-AU"}; |
Shane Farmer | efe4539 | 2017-08-21 14:39:28 -0700 | [diff] [blame] | 649 | artifact.android_sdk_group = {"v26"}; |
Shane Farmer | 9f0e7f1 | 2017-06-22 12:26:44 -0700 | [diff] [blame] | 650 | |
Shane Farmer | 9ecc075 | 2017-08-24 15:55:36 -0700 | [diff] [blame] | 651 | { |
| 652 | auto result = artifact.ToArtifactName( |
Shane Farmer | efe4539 | 2017-08-21 14:39:28 -0700 | [diff] [blame] | 653 | "app.${density}_${locale}_${feature}_${gl}.${sdk}.${abi}.apk", "", &diag); |
Shane Farmer | 9ecc075 | 2017-08-24 15:55:36 -0700 | [diff] [blame] | 654 | ASSERT_TRUE(result); |
Shane Farmer | efe4539 | 2017-08-21 14:39:28 -0700 | [diff] [blame] | 655 | 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] | 656 | } |
| 657 | |
| 658 | { |
| 659 | auto result = artifact.ToArtifactName( |
Shane Farmer | efe4539 | 2017-08-21 14:39:28 -0700 | [diff] [blame] | 660 | "app.${density}_${locale}_${feature}_${gl}.${sdk}.${abi}.apk", "app.apk", &diag); |
Shane Farmer | 9ecc075 | 2017-08-24 15:55:36 -0700 | [diff] [blame] | 661 | ASSERT_TRUE(result); |
Shane Farmer | efe4539 | 2017-08-21 14:39:28 -0700 | [diff] [blame] | 662 | 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] | 663 | } |
| 664 | |
| 665 | { |
| 666 | auto result = artifact.ToArtifactName( |
Shane Farmer | efe4539 | 2017-08-21 14:39:28 -0700 | [diff] [blame] | 667 | "${basename}.${density}_${locale}_${feature}_${gl}.${sdk}.${abi}.apk", "app.apk", &diag); |
Shane Farmer | 9ecc075 | 2017-08-24 15:55:36 -0700 | [diff] [blame] | 668 | ASSERT_TRUE(result); |
Shane Farmer | efe4539 | 2017-08-21 14:39:28 -0700 | [diff] [blame] | 669 | 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] | 670 | } |
| 671 | |
| 672 | { |
| 673 | auto result = artifact.ToArtifactName( |
Shane Farmer | efe4539 | 2017-08-21 14:39:28 -0700 | [diff] [blame] | 674 | "app.${density}_${locale}_${feature}_${gl}.${sdk}.${abi}.${ext}", "app.apk", &diag); |
Shane Farmer | 9ecc075 | 2017-08-24 15:55:36 -0700 | [diff] [blame] | 675 | ASSERT_TRUE(result); |
Shane Farmer | efe4539 | 2017-08-21 14:39:28 -0700 | [diff] [blame] | 676 | 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] | 677 | } |
| 678 | |
| 679 | { |
| 680 | auto result = artifact.ToArtifactName( |
Shane Farmer | efe4539 | 2017-08-21 14:39:28 -0700 | [diff] [blame] | 681 | "${basename}.${density}_${locale}_${feature}_${gl}.${sdk}.${abi}", "app.apk", &diag); |
Shane Farmer | 9ecc075 | 2017-08-24 15:55:36 -0700 | [diff] [blame] | 682 | ASSERT_TRUE(result); |
Shane Farmer | efe4539 | 2017-08-21 14:39:28 -0700 | [diff] [blame] | 683 | 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] | 684 | } |
Shane Farmer | 9f0e7f1 | 2017-06-22 12:26:44 -0700 | [diff] [blame] | 685 | } |
| 686 | |
| 687 | TEST(ArtifactTest, Missing) { |
| 688 | StdErrDiagnostics diag; |
| 689 | Artifact x86; |
| 690 | x86.abi_group = {"x86"}; |
| 691 | |
Shane Farmer | 9ecc075 | 2017-08-24 15:55:36 -0700 | [diff] [blame] | 692 | EXPECT_FALSE(x86.ToArtifactName("something.${density}.apk", "", &diag)); |
| 693 | EXPECT_FALSE(x86.ToArtifactName("something.apk", "", &diag)); |
| 694 | EXPECT_FALSE(x86.ToArtifactName("something.${density}.apk", "something.apk", &diag)); |
| 695 | EXPECT_FALSE(x86.ToArtifactName("something.apk", "something.apk", &diag)); |
Shane Farmer | 9f0e7f1 | 2017-06-22 12:26:44 -0700 | [diff] [blame] | 696 | } |
| 697 | |
| 698 | TEST(ArtifactTest, Empty) { |
| 699 | StdErrDiagnostics diag; |
| 700 | Artifact artifact; |
| 701 | |
Shane Farmer | 9ecc075 | 2017-08-24 15:55:36 -0700 | [diff] [blame] | 702 | EXPECT_FALSE(artifact.ToArtifactName("something.${density}.apk", "", &diag)); |
| 703 | EXPECT_TRUE(artifact.ToArtifactName("something.apk", "", &diag)); |
| 704 | EXPECT_FALSE(artifact.ToArtifactName("something.${density}.apk", "something.apk", &diag)); |
| 705 | EXPECT_TRUE(artifact.ToArtifactName("something.apk", "something.apk", &diag)); |
Shane Farmer | 9f0e7f1 | 2017-06-22 12:26:44 -0700 | [diff] [blame] | 706 | } |
| 707 | |
Shane Farmer | 1a21b8c | 2017-07-21 09:42:42 -0700 | [diff] [blame] | 708 | TEST(ArtifactTest, Repeated) { |
| 709 | StdErrDiagnostics diag; |
| 710 | Artifact artifact; |
| 711 | artifact.screen_density_group = {"mdpi"}; |
| 712 | |
Shane Farmer | 9ecc075 | 2017-08-24 15:55:36 -0700 | [diff] [blame] | 713 | ASSERT_TRUE(artifact.ToArtifactName("something.${density}.apk", "", &diag)); |
| 714 | EXPECT_FALSE(artifact.ToArtifactName("something.${density}.${density}.apk", "", &diag)); |
| 715 | ASSERT_TRUE(artifact.ToArtifactName("something.${density}.apk", "something.apk", &diag)); |
Shane Farmer | 1a21b8c | 2017-07-21 09:42:42 -0700 | [diff] [blame] | 716 | } |
| 717 | |
| 718 | TEST(ArtifactTest, Nesting) { |
| 719 | StdErrDiagnostics diag; |
| 720 | Artifact x86; |
| 721 | x86.abi_group = {"x86"}; |
| 722 | |
Shane Farmer | 9ecc075 | 2017-08-24 15:55:36 -0700 | [diff] [blame] | 723 | EXPECT_FALSE(x86.ToArtifactName("something.${abi${density}}.apk", "", &diag)); |
Shane Farmer | 1a21b8c | 2017-07-21 09:42:42 -0700 | [diff] [blame] | 724 | |
Shane Farmer | 9ecc075 | 2017-08-24 15:55:36 -0700 | [diff] [blame] | 725 | const Maybe<std::string>& name = x86.ToArtifactName("something.${abi${abi}}.apk", "", &diag); |
Shane Farmer | 0a5b201 | 2017-06-22 12:24:12 -0700 | [diff] [blame] | 726 | ASSERT_TRUE(name); |
| 727 | EXPECT_EQ(name.value(), "something.${abix86}.apk"); |
Shane Farmer | 1a21b8c | 2017-07-21 09:42:42 -0700 | [diff] [blame] | 728 | } |
| 729 | |
| 730 | TEST(ArtifactTest, Recursive) { |
| 731 | StdErrDiagnostics diag; |
| 732 | Artifact artifact; |
Shane Farmer | 0a5b201 | 2017-06-22 12:24:12 -0700 | [diff] [blame] | 733 | artifact.device_feature_group = {"${gl}"}; |
Shane Farmer | 1a21b8c | 2017-07-21 09:42:42 -0700 | [diff] [blame] | 734 | artifact.gl_texture_group = {"glx1"}; |
| 735 | |
Shane Farmer | 9ecc075 | 2017-08-24 15:55:36 -0700 | [diff] [blame] | 736 | EXPECT_FALSE(artifact.ToArtifactName("app.${feature}.${gl}.apk", "", &diag)); |
Shane Farmer | 1a21b8c | 2017-07-21 09:42:42 -0700 | [diff] [blame] | 737 | |
| 738 | artifact.device_feature_group = {"df1"}; |
Shane Farmer | 0a5b201 | 2017-06-22 12:24:12 -0700 | [diff] [blame] | 739 | artifact.gl_texture_group = {"${feature}"}; |
Shane Farmer | 1a21b8c | 2017-07-21 09:42:42 -0700 | [diff] [blame] | 740 | { |
Shane Farmer | 9ecc075 | 2017-08-24 15:55:36 -0700 | [diff] [blame] | 741 | const auto& result = artifact.ToArtifactName("app.${feature}.${gl}.apk", "", &diag); |
Shane Farmer | 0a5b201 | 2017-06-22 12:24:12 -0700 | [diff] [blame] | 742 | ASSERT_TRUE(result); |
| 743 | EXPECT_EQ(result.value(), "app.df1.${feature}.apk"); |
Shane Farmer | 1a21b8c | 2017-07-21 09:42:42 -0700 | [diff] [blame] | 744 | } |
| 745 | |
| 746 | // This is an invalid case, but should be the only possible case due to the ordering of |
| 747 | // replacement. |
Shane Farmer | 0a5b201 | 2017-06-22 12:24:12 -0700 | [diff] [blame] | 748 | artifact.device_feature_group = {"${gl}"}; |
Shane Farmer | 1a21b8c | 2017-07-21 09:42:42 -0700 | [diff] [blame] | 749 | artifact.gl_texture_group = {"glx1"}; |
| 750 | { |
Shane Farmer | 9ecc075 | 2017-08-24 15:55:36 -0700 | [diff] [blame] | 751 | const auto& result = artifact.ToArtifactName("app.${feature}.apk", "", &diag); |
Shane Farmer | 0a5b201 | 2017-06-22 12:24:12 -0700 | [diff] [blame] | 752 | ASSERT_TRUE(result); |
Shane Farmer | 1a21b8c | 2017-07-21 09:42:42 -0700 | [diff] [blame] | 753 | EXPECT_EQ(result.value(), "app.glx1.apk"); |
| 754 | } |
| 755 | } |
| 756 | |
Shane Farmer | 74cdea3 | 2017-05-12 16:22:36 -0700 | [diff] [blame] | 757 | } // namespace |
| 758 | } // namespace aapt |