diff options
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) { |