diff options
author | Adam Lesinski <adamlesinski@google.com> | 2017-06-01 17:16:44 -0700 |
---|---|---|
committer | Adam Lesinski <adamlesinski@google.com> | 2017-06-01 17:16:44 -0700 |
commit | e597d68d33c76c2b830f5497ed4ba74c5193a056 (patch) | |
tree | 699e25d86f8ed610ef1b1b640efb5b86c89d4289 /tools/aapt2/ResourceParser_test.cpp | |
parent | ceb24e88cbb56aa63c990693a2d6ea35dce029f5 (diff) |
AAPT2: Allow any value type for <item> without format attr
TO bring AAPT2 behavior in-line with AAPT, <item> has a default
format of "any", and only becomes restricted with an explicit format
attribute.
Bug: 62260121
Test: make aapt2_tests
Change-Id: Ife416f520e6c2710bb30e3ba3f2d4463794bfa06
Diffstat (limited to 'tools/aapt2/ResourceParser_test.cpp')
-rw-r--r-- | tools/aapt2/ResourceParser_test.cpp | 26 |
1 files changed, 19 insertions, 7 deletions
diff --git a/tools/aapt2/ResourceParser_test.cpp b/tools/aapt2/ResourceParser_test.cpp index e3abde6bef29..e60ef66a21db 100644 --- a/tools/aapt2/ResourceParser_test.cpp +++ b/tools/aapt2/ResourceParser_test.cpp @@ -25,7 +25,9 @@ #include "test/Test.h" #include "xml/XmlPullParser.h" -using android::StringPiece; +using ::android::StringPiece; +using ::testing::Eq; +using ::testing::NotNull; namespace aapt { @@ -791,15 +793,25 @@ TEST_F(ResourceParserTest, AddResourcesElementShouldAddEntryWithUndefinedSymbol) } TEST_F(ResourceParserTest, ParseItemElementWithFormat) { - std::string input = - R"EOF(<item name="foo" type="integer" format="float">0.3</item>)EOF"; + std::string input = R"(<item name="foo" type="integer" format="float">0.3</item>)"; ASSERT_TRUE(TestParse(input)); - BinaryPrimitive* val = - test::GetValue<BinaryPrimitive>(&table_, "integer/foo"); - ASSERT_NE(nullptr, val); + BinaryPrimitive* val = test::GetValue<BinaryPrimitive>(&table_, "integer/foo"); + ASSERT_THAT(val, NotNull()); + EXPECT_THAT(val->value.dataType, Eq(android::Res_value::TYPE_FLOAT)); + + input = R"(<item name="bar" type="integer" format="fraction">100</item>)"; + ASSERT_FALSE(TestParse(input)); +} + +// An <item> without a format specifier accepts all types of values. +TEST_F(ResourceParserTest, ParseItemElementWithoutFormat) { + std::string input = R"(<item name="foo" type="integer">100%p</item>)"; + ASSERT_TRUE(TestParse(input)); - EXPECT_EQ(uint32_t(android::Res_value::TYPE_FLOAT), val->value.dataType); + BinaryPrimitive* val = test::GetValue<BinaryPrimitive>(&table_, "integer/foo"); + ASSERT_THAT(val, NotNull()); + EXPECT_THAT(val->value.dataType, Eq(android::Res_value::TYPE_FRACTION)); } TEST_F(ResourceParserTest, ParseConfigVaryingItem) { |