diff options
| author | Shane Farmer <safarmer@google.com> | 2017-12-18 14:44:11 -0800 |
|---|---|---|
| committer | Shane Farmer <safarmer@google.com> | 2017-12-19 13:52:30 -0800 |
| commit | 39e474f4b4a975d8befa1e8f4cbedab5f47a43fa (patch) | |
| tree | 91cc16995c35d13b76fb471ea7631b49a800dc0c /tools/aapt2/configuration/ConfigurationParser_test.cpp | |
| parent | 2c12241fa8edaa4ae8bd01f50980ae647c41b45c (diff) | |
AAPT2: Allow empty group definitions
With ABI, screen density, and locale, it is possible to use a shorthand
notation when the group only has a single entry. The shorthand is to
leave the group empty and use a valid configuration for the group name.
Test: manually ran optimize command
Test: unit tests
Change-Id: If2d091e587474847c6c9e9be1a29196b261cc82d
Diffstat (limited to 'tools/aapt2/configuration/ConfigurationParser_test.cpp')
| -rw-r--r-- | tools/aapt2/configuration/ConfigurationParser_test.cpp | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/tools/aapt2/configuration/ConfigurationParser_test.cpp b/tools/aapt2/configuration/ConfigurationParser_test.cpp index 3f356d78bbfe..da00511fd192 100644 --- a/tools/aapt2/configuration/ConfigurationParser_test.cpp +++ b/tools/aapt2/configuration/ConfigurationParser_test.cpp @@ -338,6 +338,32 @@ TEST_F(ConfigurationParserTest, AbiGroupAction) { ASSERT_THAT(out, ElementsAre(Abi::kArmV7a, Abi::kArm64V8a)); } +TEST_F(ConfigurationParserTest, AbiGroupAction_EmptyGroup) { + static constexpr const char* xml = R"xml(<abi-group label="arm64-v8a"/>)xml"; + + auto doc = test::BuildXmlDom(xml); + + PostProcessingConfiguration config; + bool ok = AbiGroupTagHandler(&config, NodeCast<Element>(doc.get()->root.get()), &diag_); + ASSERT_TRUE(ok); + + EXPECT_THAT(config.abi_groups, SizeIs(1ul)); + ASSERT_EQ(1u, config.abi_groups.count("arm64-v8a")); + + auto& out = config.abi_groups["arm64-v8a"]; + ASSERT_THAT(out, ElementsAre(Abi::kArm64V8a)); +} + +TEST_F(ConfigurationParserTest, AbiGroupAction_InvalidEmptyGroup) { + static constexpr const char* xml = R"xml(<abi-group label="arm"/>)xml"; + + auto doc = test::BuildXmlDom(xml); + + PostProcessingConfiguration config; + bool ok = AbiGroupTagHandler(&config, NodeCast<Element>(doc.get()->root.get()), &diag_); + ASSERT_FALSE(ok); +} + TEST_F(ConfigurationParserTest, ScreenDensityGroupAction) { static constexpr const char* xml = R"xml( <screen-density-group label="large"> @@ -368,6 +394,35 @@ TEST_F(ConfigurationParserTest, ScreenDensityGroupAction) { ASSERT_THAT(out, ElementsAre(xhdpi, xxhdpi, xxxhdpi)); } +TEST_F(ConfigurationParserTest, ScreenDensityGroupAction_EmtpyGroup) { + static constexpr const char* xml = R"xml(<screen-density-group label="xhdpi"/>)xml"; + + auto doc = test::BuildXmlDom(xml); + + PostProcessingConfiguration config; + bool ok = ScreenDensityGroupTagHandler(&config, NodeCast<Element>(doc.get()->root.get()), &diag_); + ASSERT_TRUE(ok); + + EXPECT_THAT(config.screen_density_groups, SizeIs(1ul)); + ASSERT_EQ(1u, config.screen_density_groups.count("xhdpi")); + + ConfigDescription xhdpi; + xhdpi.density = ResTable_config::DENSITY_XHIGH; + + auto& out = config.screen_density_groups["xhdpi"]; + ASSERT_THAT(out, ElementsAre(xhdpi)); +} + +TEST_F(ConfigurationParserTest, ScreenDensityGroupAction_InvalidEmtpyGroup) { + static constexpr const char* xml = R"xml(<screen-density-group label="really-big-screen"/>)xml"; + + auto doc = test::BuildXmlDom(xml); + + PostProcessingConfiguration config; + bool ok = ScreenDensityGroupTagHandler(&config, NodeCast<Element>(doc.get()->root.get()), &diag_); + ASSERT_FALSE(ok); +} + TEST_F(ConfigurationParserTest, LocaleGroupAction) { static constexpr const char* xml = R"xml( <locale-group label="europe"> @@ -396,6 +451,35 @@ TEST_F(ConfigurationParserTest, LocaleGroupAction) { ASSERT_THAT(out, ElementsAre(en, es, fr, de)); } +TEST_F(ConfigurationParserTest, LocaleGroupAction_EmtpyGroup) { + static constexpr const char* xml = R"xml(<locale-group label="en"/>)xml"; + + auto doc = test::BuildXmlDom(xml); + + PostProcessingConfiguration config; + bool ok = LocaleGroupTagHandler(&config, NodeCast<Element>(doc.get()->root.get()), &diag_); + ASSERT_TRUE(ok); + + ASSERT_EQ(1ul, config.locale_groups.size()); + ASSERT_EQ(1u, config.locale_groups.count("en")); + + const auto& out = config.locale_groups["en"]; + + ConfigDescription en = test::ParseConfigOrDie("en"); + + ASSERT_THAT(out, ElementsAre(en)); +} + +TEST_F(ConfigurationParserTest, LocaleGroupAction_InvalidEmtpyGroup) { + static constexpr const char* xml = R"xml(<locale-group label="arm64"/>)xml"; + + auto doc = test::BuildXmlDom(xml); + + PostProcessingConfiguration config; + bool ok = LocaleGroupTagHandler(&config, NodeCast<Element>(doc.get()->root.get()), &diag_); + ASSERT_FALSE(ok); +} + TEST_F(ConfigurationParserTest, AndroidSdkGroupAction) { static constexpr const char* xml = R"xml( <android-sdk-group label="v19"> |
