Merge "AAPT2: Allow any value type for <item> without format attr" into oc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
1ac325e4d5
@@ -415,6 +415,10 @@ bool ResourceParser::ParseResource(xml::XmlPullParser* parser,
|
||||
if (resource_type == "item") {
|
||||
can_be_bag = false;
|
||||
|
||||
// The default format for <item> is any. If a format attribute is present, that one will
|
||||
// override the default.
|
||||
resource_format = android::ResTable_map::TYPE_ANY;
|
||||
|
||||
// Items have their type encoded in the type attribute.
|
||||
if (Maybe<StringPiece> maybe_type = xml::FindNonEmptyAttribute(parser, "type")) {
|
||||
resource_type = maybe_type.value().to_string();
|
||||
@@ -481,8 +485,8 @@ bool ResourceParser::ParseResource(xml::XmlPullParser* parser,
|
||||
out_resource->name.type = item_iter->second.type;
|
||||
out_resource->name.entry = maybe_name.value().to_string();
|
||||
|
||||
// Only use the implicit format for this type if it wasn't overridden.
|
||||
if (!resource_format) {
|
||||
// Only use the implied format of the type when there is no explicit format.
|
||||
if (resource_format == 0u) {
|
||||
resource_format = item_iter->second.format;
|
||||
}
|
||||
|
||||
|
||||
@@ -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));
|
||||
|
||||
EXPECT_EQ(uint32_t(android::Res_value::TYPE_FLOAT), val->value.dataType);
|
||||
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));
|
||||
|
||||
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) {
|
||||
|
||||
@@ -30,6 +30,8 @@
|
||||
<flag name="weak" value="4" />
|
||||
</attr>
|
||||
|
||||
<item name="value_that_allows_any_format" type="integer">-100%p</item>
|
||||
|
||||
<!-- Override the Widget styleable declared in StaticLibOne.
|
||||
This should merge the two when built in overlay mode. -->
|
||||
<declare-styleable name="Widget">
|
||||
|
||||
Reference in New Issue
Block a user