diff options
Diffstat (limited to 'tools/aapt2/configuration/ConfigurationParser_test.cpp')
-rw-r--r-- | tools/aapt2/configuration/ConfigurationParser_test.cpp | 122 |
1 files changed, 92 insertions, 30 deletions
diff --git a/tools/aapt2/configuration/ConfigurationParser_test.cpp b/tools/aapt2/configuration/ConfigurationParser_test.cpp index 6bb168f15b1e..3654901e3e02 100644 --- a/tools/aapt2/configuration/ConfigurationParser_test.cpp +++ b/tools/aapt2/configuration/ConfigurationParser_test.cpp @@ -183,55 +183,117 @@ TEST_F(ConfigurationParserTest, InvalidNamespace) { } TEST_F(ConfigurationParserTest, ArtifactAction) { - static constexpr const char* xml = R"xml( + PostProcessingConfiguration config; + { + const auto doc = test::BuildXmlDom(R"xml( + <artifact + abi-group="arm" + screen-density-group="large" + locale-group="europe" + android-sdk-group="v19" + gl-texture-group="dxt1" + device-feature-group="low-latency"/>)xml"); + + ASSERT_TRUE(artifact_handler_(&config, NodeCast<Element>(doc->root.get()), &diag_)); + + EXPECT_EQ(1ul, config.artifacts.size()); + + auto& artifact = config.artifacts.back(); + EXPECT_FALSE(artifact.name); // TODO: make this fail. + EXPECT_EQ(1, artifact.version); + EXPECT_EQ("arm", artifact.abi_group.value()); + EXPECT_EQ("large", artifact.screen_density_group.value()); + EXPECT_EQ("europe", artifact.locale_group.value()); + EXPECT_EQ("v19", artifact.android_sdk_group.value()); + EXPECT_EQ("dxt1", artifact.gl_texture_group.value()); + EXPECT_EQ("low-latency", artifact.device_feature_group.value()); + } + + { + // Perform a second action to ensure we get 2 artifacts. + const auto doc = test::BuildXmlDom(R"xml( + <artifact + abi-group="other" + screen-density-group="large" + locale-group="europe" + android-sdk-group="v19" + gl-texture-group="dxt1" + device-feature-group="low-latency"/>)xml"); + + ASSERT_TRUE(artifact_handler_(&config, NodeCast<Element>(doc.get()->root.get()), &diag_)); + EXPECT_EQ(2ul, config.artifacts.size()); + EXPECT_EQ(2, config.artifacts.back().version); + } + + { + // Perform a third action with a set version code. + const auto doc = test::BuildXmlDom(R"xml( <artifact - abi-group="arm" + version="5" + abi-group="other" screen-density-group="large" locale-group="europe" android-sdk-group="v19" gl-texture-group="dxt1" - device-feature-group="low-latency"/>)xml"; + device-feature-group="low-latency"/>)xml"); - auto doc = test::BuildXmlDom(xml); - - PostProcessingConfiguration config; - bool ok = artifact_handler_(&config, NodeCast<Element>(doc->root.get()), &diag_); - ASSERT_TRUE(ok); - - EXPECT_EQ(1ul, config.artifacts.size()); - - auto& artifact = config.artifacts.front(); - EXPECT_FALSE(artifact.name); // TODO: make this fail. - EXPECT_EQ("arm", artifact.abi_group.value()); - EXPECT_EQ("large", artifact.screen_density_group.value()); - EXPECT_EQ("europe", artifact.locale_group.value()); - EXPECT_EQ("v19", artifact.android_sdk_group.value()); - EXPECT_EQ("dxt1", artifact.gl_texture_group.value()); - EXPECT_EQ("low-latency", artifact.device_feature_group.value()); + ASSERT_TRUE(artifact_handler_(&config, NodeCast<Element>(doc.get()->root.get()), &diag_)); + EXPECT_EQ(3ul, config.artifacts.size()); + EXPECT_EQ(5, config.artifacts.back().version); + } - // Perform a second action to ensure we get 2 artifacts. - static constexpr const char* second = R"xml( + { + // Perform a fourth action to ensure the version code still increments. + const auto doc = test::BuildXmlDom(R"xml( <artifact abi-group="other" screen-density-group="large" locale-group="europe" android-sdk-group="v19" gl-texture-group="dxt1" - device-feature-group="low-latency"/>)xml"; - doc = test::BuildXmlDom(second); + device-feature-group="low-latency"/>)xml"); - ok = artifact_handler_(&config, NodeCast<Element>(doc.get()->root.get()), &diag_); - ASSERT_TRUE(ok); - EXPECT_EQ(2ul, config.artifacts.size()); + ASSERT_TRUE(artifact_handler_(&config, NodeCast<Element>(doc.get()->root.get()), &diag_)); + EXPECT_EQ(4ul, config.artifacts.size()); + EXPECT_EQ(6, config.artifacts.back().version); + } +} + +TEST_F(ConfigurationParserTest, DuplicateArtifactVersion) { + static constexpr const char* configuration = R"xml(<?xml version="1.0" encoding="utf-8" ?> + <pst-process xmlns="http://schemas.android.com/tools/aapt">> + <artifacts> + <artifact-format> + ${base}.${abi}.${screen-density}.${locale}.${sdk}.${gl}.${feature}.release + </artifact-format> + <artifact + name="art1" + abi-group="arm" + screen-density-group="large" + locale-group="europe" + android-sdk-group="v19" + gl-texture-group="dxt1" + device-feature-group="low-latency"/> + <artifact + name="art2" + version = "1" + abi-group="other" + screen-density-group="alldpi" + locale-group="north-america" + android-sdk-group="v19" + gl-texture-group="dxt1" + device-feature-group="low-latency"/> + </artifacts> + </post-process>)xml"; + auto result = ConfigurationParser::ForContents(configuration).Parse(); + ASSERT_FALSE(result); } TEST_F(ConfigurationParserTest, ArtifactFormatAction) { - static constexpr const char* xml = R"xml( + const auto doc = test::BuildXmlDom(R"xml( <artifact-format> ${base}.${abi}.${screen-density}.${locale}.${sdk}.${gl}.${feature}.release - </artifact-format>)xml"; - - auto doc = test::BuildXmlDom(xml); + </artifact-format>)xml"); PostProcessingConfiguration config; bool ok = artifact_format_handler_(&config, NodeCast<Element>(doc.get()->root.get()), &diag_); |