diff options
author | Adam Lesinski <adamlesinski@google.com> | 2016-01-06 15:45:28 -0800 |
---|---|---|
committer | Adam Lesinski <adamlesinski@google.com> | 2016-01-06 16:18:40 -0800 |
commit | 7751afc796842bbb24bfbb19bd0fee4a7b7c8a4e (patch) | |
tree | fad12506e9f244038a186dd8dbe31e87f6bafafe /tools/aapt2/ResourceParser_test.cpp | |
parent | 198ce1a5e6fbe2cb84263e427032e9715e27379f (diff) |
AAPT2: Fix product support
Previously the default product wasn't tried if 'default' wasn't specified on the command line.
Also adds support for multiple products.
Change-Id: I1e4872b34bb8d609b6444841a4e7e4dbb3bbb76b
Diffstat (limited to 'tools/aapt2/ResourceParser_test.cpp')
-rw-r--r-- | tools/aapt2/ResourceParser_test.cpp | 34 |
1 files changed, 26 insertions, 8 deletions
diff --git a/tools/aapt2/ResourceParser_test.cpp b/tools/aapt2/ResourceParser_test.cpp index ab44a064a953..8d10ba14924b 100644 --- a/tools/aapt2/ResourceParser_test.cpp +++ b/tools/aapt2/ResourceParser_test.cpp @@ -48,11 +48,11 @@ struct ResourceParserTest : public ::testing::Test { } ::testing::AssertionResult testParse(const StringPiece& str, - Maybe<std::u16string> product = {}) { + std::initializer_list<std::u16string> products = {}) { std::stringstream input(kXmlPreamble); input << "<resources>\n" << str << "\n</resources>" << std::endl; ResourceParserOptions parserOptions; - parserOptions.product = product; + parserOptions.products = products; ResourceParser parser(mContext->getDiagnostics(), &mTable, Source{ "test" }, {}, parserOptions); xml::XmlPullParser xmlParser(input); @@ -514,11 +514,15 @@ TEST_F(ResourceParserTest, ParsePublicIdAsDefinition) { } TEST_F(ResourceParserTest, FilterProductsThatDontMatch) { - std::string input = "<string name=\"foo\" product=\"phone\">hi</string>\n" - "<string name=\"foo\" product=\"no-sdcard\">ho</string>\n" - "<string name=\"bar\" product=\"\">wee</string>\n" - "<string name=\"baz\">woo</string>\n"; - ASSERT_TRUE(testParse(input, std::u16string(u"no-sdcard"))); + std::string input = R"EOF( + <string name="foo" product="phone">hi</string> + <string name="foo" product="no-sdcard">ho</string> + <string name="bar" product="">wee</string> + <string name="baz">woo</string> + <string name="bit" product="phablet">hoot</string> + <string name="bot" product="default">yes</string> + )EOF"; + ASSERT_TRUE(testParse(input, { std::u16string(u"no-sdcard"), std::u16string(u"phablet") })); String* fooStr = test::getValue<String>(&mTable, u"@string/foo"); ASSERT_NE(nullptr, fooStr); @@ -526,11 +530,25 @@ TEST_F(ResourceParserTest, FilterProductsThatDontMatch) { EXPECT_NE(nullptr, test::getValue<String>(&mTable, u"@string/bar")); EXPECT_NE(nullptr, test::getValue<String>(&mTable, u"@string/baz")); + EXPECT_NE(nullptr, test::getValue<String>(&mTable, u"@string/bit")); + EXPECT_NE(nullptr, test::getValue<String>(&mTable, u"@string/bot")); +} + +TEST_F(ResourceParserTest, FilterProductsThatBothMatchInOrder) { + std::string input = R"EOF( + <string name="foo" product="phone">phone</string> + <string name="foo" product="default">default</string> + )EOF"; + ASSERT_TRUE(testParse(input, { std::u16string(u"phone") })); + + String* foo = test::getValue<String>(&mTable, u"@string/foo"); + ASSERT_NE(nullptr, foo); + EXPECT_EQ(std::u16string(u"phone"), *foo->value); } TEST_F(ResourceParserTest, FailWhenProductFilterStripsOutAllVersionsOfResource) { std::string input = "<string name=\"foo\" product=\"tablet\">hello</string>\n"; - ASSERT_FALSE(testParse(input, std::u16string(u"phone"))); + ASSERT_FALSE(testParse(input, { std::u16string(u"phone") })); } TEST_F(ResourceParserTest, AutoIncrementIdsInPublicGroup) { |