diff options
author | Adam Lesinski <adamlesinski@google.com> | 2016-01-11 13:10:24 -0800 |
---|---|---|
committer | Adam Lesinski <adamlesinski@google.com> | 2016-01-13 18:48:24 -0800 |
commit | 52364f7ae31716d7827ea8f8566f4a28bd30a921 (patch) | |
tree | ce146fb6dc5e9f9b1166964b77273b6481f8258b /tools/aapt2/ResourceParser_test.cpp | |
parent | d901155166983adde84d9da2a6b265371191068a (diff) |
AAPT2: Variety of small fixes to get the build working
- Add option to rename package in AndroidManifest.xml
- Support default versionName and versionCode
- Accept True and False as valid booleans
Change-Id: I400e350b9dcd0fd1c197d1929144299c7823617d
Diffstat (limited to 'tools/aapt2/ResourceParser_test.cpp')
-rw-r--r-- | tools/aapt2/ResourceParser_test.cpp | 37 |
1 files changed, 35 insertions, 2 deletions
diff --git a/tools/aapt2/ResourceParser_test.cpp b/tools/aapt2/ResourceParser_test.cpp index 8d10ba14924b..cf0fcd11b903 100644 --- a/tools/aapt2/ResourceParser_test.cpp +++ b/tools/aapt2/ResourceParser_test.cpp @@ -47,13 +47,26 @@ struct ResourceParserTest : public ::testing::Test { mContext = test::ContextBuilder().build(); } + ::testing::AssertionResult testParse(const StringPiece& str) { + return testParse(str, ConfigDescription{}, {}); + } + + ::testing::AssertionResult testParse(const StringPiece& str, const ConfigDescription& config) { + return testParse(str, config, {}); + } + ::testing::AssertionResult testParse(const StringPiece& str, - std::initializer_list<std::u16string> products = {}) { + std::initializer_list<std::u16string> products) { + return testParse(str, {}, std::move(products)); + } + + ::testing::AssertionResult testParse(const StringPiece& str, const ConfigDescription& config, + std::initializer_list<std::u16string> products) { std::stringstream input(kXmlPreamble); input << "<resources>\n" << str << "\n</resources>" << std::endl; ResourceParserOptions parserOptions; parserOptions.products = products; - ResourceParser parser(mContext->getDiagnostics(), &mTable, Source{ "test" }, {}, + ResourceParser parser(mContext->getDiagnostics(), &mTable, Source{ "test" }, config, parserOptions); xml::XmlPullParser xmlParser(input); if (parser.parse(&xmlParser)) { @@ -138,6 +151,26 @@ TEST_F(ResourceParserTest, ParseAttr) { EXPECT_EQ(uint32_t(android::ResTable_map::TYPE_ANY), attr->typeMask); } +// Old AAPT allowed attributes to be defined under different configurations, but ultimately +// stored them with the default configuration. Check that we have the same behavior. +TEST_F(ResourceParserTest, ParseAttrAndDeclareStyleableUnderConfigButRecordAsNoConfig) { + const ConfigDescription watchConfig = test::parseConfigOrDie("watch"); + std::string input = R"EOF( + <attr name="foo" /> + <declare-styleable name="bar"> + <attr name="baz" /> + </declare-styleable>)EOF"; + ASSERT_TRUE(testParse(input, watchConfig)); + + EXPECT_EQ(nullptr, test::getValueForConfig<Attribute>(&mTable, u"@attr/foo", watchConfig)); + EXPECT_EQ(nullptr, test::getValueForConfig<Attribute>(&mTable, u"@attr/baz", watchConfig)); + EXPECT_EQ(nullptr, test::getValueForConfig<Styleable>(&mTable, u"@styleable/bar", watchConfig)); + + EXPECT_NE(nullptr, test::getValue<Attribute>(&mTable, u"@attr/foo")); + EXPECT_NE(nullptr, test::getValue<Attribute>(&mTable, u"@attr/baz")); + EXPECT_NE(nullptr, test::getValue<Styleable>(&mTable, u"@styleable/bar")); +} + TEST_F(ResourceParserTest, ParseAttrWithMinMax) { std::string input = "<attr name=\"foo\" min=\"10\" max=\"23\" format=\"integer\"/>"; ASSERT_TRUE(testParse(input)); |