Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include "ResourceParser.h" |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 18 | |
| 19 | #include <sstream> |
| 20 | #include <string> |
| 21 | |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 22 | #include "ResourceTable.h" |
Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 23 | #include "ResourceUtils.h" |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 24 | #include "ResourceValues.h" |
Adam Lesinski | 0045116 | 2017-10-03 07:44:08 -0700 | [diff] [blame] | 25 | #include "io/StringStream.h" |
Adam Lesinski | d0f116b | 2016-07-08 15:00:32 -0700 | [diff] [blame] | 26 | #include "test/Test.h" |
Adam Lesinski | 467f171 | 2015-11-16 17:35:44 -0800 | [diff] [blame] | 27 | #include "xml/XmlPullParser.h" |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 28 | |
Adam Lesinski | efeb7af | 2017-08-02 14:57:43 -0700 | [diff] [blame] | 29 | using ::aapt::io::StringInputStream; |
Adam Lesinski | a45893a | 2017-05-30 15:19:02 -0700 | [diff] [blame] | 30 | using ::aapt::test::StrValueEq; |
Adam Lesinski | bab4ef5 | 2017-06-01 15:22:57 -0700 | [diff] [blame] | 31 | using ::aapt::test::ValueEq; |
Adam Lesinski | a45893a | 2017-05-30 15:19:02 -0700 | [diff] [blame] | 32 | using ::android::Res_value; |
Adam Lesinski | 71be705 | 2017-12-12 16:48:07 -0800 | [diff] [blame] | 33 | using ::android::ResTable_map; |
Adam Lesinski | e597d68 | 2017-06-01 17:16:44 -0700 | [diff] [blame] | 34 | using ::android::StringPiece; |
| 35 | using ::testing::Eq; |
Adam Lesinski | a45893a | 2017-05-30 15:19:02 -0700 | [diff] [blame] | 36 | using ::testing::IsEmpty; |
| 37 | using ::testing::IsNull; |
Adam Lesinski | e597d68 | 2017-06-01 17:16:44 -0700 | [diff] [blame] | 38 | using ::testing::NotNull; |
Adam Lesinski | bab4ef5 | 2017-06-01 15:22:57 -0700 | [diff] [blame] | 39 | using ::testing::Pointee; |
Adam Lesinski | a45893a | 2017-05-30 15:19:02 -0700 | [diff] [blame] | 40 | using ::testing::SizeIs; |
Adam Lesinski | 71be705 | 2017-12-12 16:48:07 -0800 | [diff] [blame] | 41 | using ::testing::StrEq; |
Adam Lesinski | d5083f6 | 2017-01-16 15:07:21 -0800 | [diff] [blame] | 42 | |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 43 | namespace aapt { |
| 44 | |
Adam Lesinski | bab4ef5 | 2017-06-01 15:22:57 -0700 | [diff] [blame] | 45 | constexpr const char* kXmlPreamble = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"; |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 46 | |
Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 47 | TEST(ResourceParserSingleTest, FailToParseWithNoRootResourcesElement) { |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 48 | std::unique_ptr<IAaptContext> context = test::ContextBuilder().Build(); |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 49 | ResourceTable table; |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 50 | ResourceParser parser(context->GetDiagnostics(), &table, Source{"test"}, {}); |
Adam Lesinski | efeb7af | 2017-08-02 14:57:43 -0700 | [diff] [blame] | 51 | |
| 52 | std::string input = kXmlPreamble; |
| 53 | input += R"(<attr name="foo"/>)"; |
| 54 | StringInputStream in(input); |
| 55 | xml::XmlPullParser xml_parser(&in); |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 56 | ASSERT_FALSE(parser.Parse(&xml_parser)); |
Adam Lesinski | 769de98 | 2015-04-10 19:43:55 -0700 | [diff] [blame] | 57 | } |
| 58 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 59 | class ResourceParserTest : public ::testing::Test { |
| 60 | public: |
Adam Lesinski | bab4ef5 | 2017-06-01 15:22:57 -0700 | [diff] [blame] | 61 | void SetUp() override { |
| 62 | context_ = test::ContextBuilder().Build(); |
| 63 | } |
Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 64 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 65 | ::testing::AssertionResult TestParse(const StringPiece& str) { |
| 66 | return TestParse(str, ConfigDescription{}); |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 67 | } |
Adam Lesinski | 52364f7 | 2016-01-11 13:10:24 -0800 | [diff] [blame] | 68 | |
Adam Lesinski | bab4ef5 | 2017-06-01 15:22:57 -0700 | [diff] [blame] | 69 | ::testing::AssertionResult TestParse(const StringPiece& str, const ConfigDescription& config) { |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 70 | ResourceParserOptions parserOptions; |
Adam Lesinski | bab4ef5 | 2017-06-01 15:22:57 -0700 | [diff] [blame] | 71 | ResourceParser parser(context_->GetDiagnostics(), &table_, Source{"test"}, config, |
| 72 | parserOptions); |
Adam Lesinski | efeb7af | 2017-08-02 14:57:43 -0700 | [diff] [blame] | 73 | |
| 74 | std::string input = kXmlPreamble; |
| 75 | input += "<resources>\n"; |
| 76 | input.append(str.data(), str.size()); |
| 77 | input += "\n</resources>"; |
| 78 | StringInputStream in(input); |
| 79 | xml::XmlPullParser xmlParser(&in); |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 80 | if (parser.Parse(&xmlParser)) { |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 81 | return ::testing::AssertionSuccess(); |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 82 | } |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 83 | return ::testing::AssertionFailure(); |
| 84 | } |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 85 | |
| 86 | protected: |
| 87 | ResourceTable table_; |
| 88 | std::unique_ptr<IAaptContext> context_; |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 89 | }; |
| 90 | |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 91 | TEST_F(ResourceParserTest, ParseQuotedString) { |
Adam Lesinski | a45893a | 2017-05-30 15:19:02 -0700 | [diff] [blame] | 92 | ASSERT_TRUE(TestParse(R"(<string name="foo"> " hey there " </string>)")); |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 93 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 94 | String* str = test::GetValue<String>(&table_, "string/foo"); |
Adam Lesinski | a45893a | 2017-05-30 15:19:02 -0700 | [diff] [blame] | 95 | ASSERT_THAT(str, NotNull()); |
| 96 | EXPECT_THAT(*str, StrValueEq(" hey there ")); |
| 97 | EXPECT_THAT(str->untranslatable_sections, IsEmpty()); |
Adam Lesinski | 2eed52e | 2018-02-21 15:55:58 -0800 | [diff] [blame] | 98 | |
| 99 | ASSERT_TRUE(TestParse(R"(<string name="bar">Isn\'t it cool?</string>)")); |
| 100 | str = test::GetValue<String>(&table_, "string/bar"); |
| 101 | ASSERT_THAT(str, NotNull()); |
| 102 | EXPECT_THAT(*str, StrValueEq("Isn't it cool?")); |
| 103 | |
| 104 | ASSERT_TRUE(TestParse(R"(<string name="baz">"Isn't it cool?"</string>)")); |
| 105 | str = test::GetValue<String>(&table_, "string/baz"); |
| 106 | ASSERT_THAT(str, NotNull()); |
| 107 | EXPECT_THAT(*str, StrValueEq("Isn't it cool?")); |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 108 | } |
| 109 | |
| 110 | TEST_F(ResourceParserTest, ParseEscapedString) { |
Adam Lesinski | a45893a | 2017-05-30 15:19:02 -0700 | [diff] [blame] | 111 | ASSERT_TRUE(TestParse(R"(<string name="foo">\?123</string>)")); |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 112 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 113 | String* str = test::GetValue<String>(&table_, "string/foo"); |
Adam Lesinski | a45893a | 2017-05-30 15:19:02 -0700 | [diff] [blame] | 114 | ASSERT_THAT(str, NotNull()); |
| 115 | EXPECT_THAT(*str, StrValueEq("?123")); |
| 116 | EXPECT_THAT(str->untranslatable_sections, IsEmpty()); |
Adam Lesinski | 549e437 | 2017-06-27 18:39:07 -0700 | [diff] [blame] | 117 | |
| 118 | ASSERT_TRUE(TestParse(R"(<string name="bar">This isn\’t a bad string</string>)")); |
| 119 | str = test::GetValue<String>(&table_, "string/bar"); |
| 120 | ASSERT_THAT(str, NotNull()); |
| 121 | EXPECT_THAT(*str, StrValueEq("This isn’t a bad string")); |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 122 | } |
| 123 | |
Adam Lesinski | 9f22204 | 2015-11-04 13:51:45 -0800 | [diff] [blame] | 124 | TEST_F(ResourceParserTest, ParseFormattedString) { |
Adam Lesinski | a45893a | 2017-05-30 15:19:02 -0700 | [diff] [blame] | 125 | ASSERT_FALSE(TestParse(R"(<string name="foo">%d %s</string>)")); |
| 126 | ASSERT_TRUE(TestParse(R"(<string name="foo">%1$d %2$s</string>)")); |
Adam Lesinski | 9f22204 | 2015-11-04 13:51:45 -0800 | [diff] [blame] | 127 | } |
| 128 | |
Adam Lesinski | 8c3f31f | 2016-09-07 13:45:13 -0700 | [diff] [blame] | 129 | TEST_F(ResourceParserTest, ParseStyledString) { |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 130 | // Use a surrogate pair unicode point so that we can verify that the span |
Adam Lesinski | 7542162 | 2017-01-06 15:20:04 -0800 | [diff] [blame] | 131 | // indices use UTF-16 length and not UTF-8 length. |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 132 | std::string input = |
Adam Lesinski | 8049f3d | 2017-03-31 18:28:14 -0700 | [diff] [blame] | 133 | "<string name=\"foo\">This is my aunt\u2019s <b>fickle <small>string</small></b></string>"; |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 134 | ASSERT_TRUE(TestParse(input)); |
Adam Lesinski | 8c3f31f | 2016-09-07 13:45:13 -0700 | [diff] [blame] | 135 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 136 | StyledString* str = test::GetValue<StyledString>(&table_, "string/foo"); |
Adam Lesinski | a45893a | 2017-05-30 15:19:02 -0700 | [diff] [blame] | 137 | ASSERT_THAT(str, NotNull()); |
Adam Lesinski | 8c3f31f | 2016-09-07 13:45:13 -0700 | [diff] [blame] | 138 | |
Adam Lesinski | 2eed52e | 2018-02-21 15:55:58 -0800 | [diff] [blame] | 139 | EXPECT_THAT(str->value->value, StrEq("This is my aunt\u2019s fickle string")); |
Adam Lesinski | a45893a | 2017-05-30 15:19:02 -0700 | [diff] [blame] | 140 | EXPECT_THAT(str->value->spans, SizeIs(2)); |
| 141 | EXPECT_THAT(str->untranslatable_sections, IsEmpty()); |
Adam Lesinski | 8c3f31f | 2016-09-07 13:45:13 -0700 | [diff] [blame] | 142 | |
Adam Lesinski | 2eed52e | 2018-02-21 15:55:58 -0800 | [diff] [blame] | 143 | EXPECT_THAT(*str->value->spans[0].name, StrEq("b")); |
| 144 | EXPECT_THAT(str->value->spans[0].first_char, Eq(18u)); |
Adam Lesinski | a45893a | 2017-05-30 15:19:02 -0700 | [diff] [blame] | 145 | EXPECT_THAT(str->value->spans[0].last_char, Eq(30u)); |
Adam Lesinski | 8049f3d | 2017-03-31 18:28:14 -0700 | [diff] [blame] | 146 | |
Adam Lesinski | 2eed52e | 2018-02-21 15:55:58 -0800 | [diff] [blame] | 147 | EXPECT_THAT(*str->value->spans[1].name, StrEq("small")); |
| 148 | EXPECT_THAT(str->value->spans[1].first_char, Eq(25u)); |
Adam Lesinski | a45893a | 2017-05-30 15:19:02 -0700 | [diff] [blame] | 149 | EXPECT_THAT(str->value->spans[1].last_char, Eq(30u)); |
Adam Lesinski | 8c3f31f | 2016-09-07 13:45:13 -0700 | [diff] [blame] | 150 | } |
| 151 | |
| 152 | TEST_F(ResourceParserTest, ParseStringWithWhitespace) { |
Adam Lesinski | a45893a | 2017-05-30 15:19:02 -0700 | [diff] [blame] | 153 | ASSERT_TRUE(TestParse(R"(<string name="foo"> This is what I think </string>)")); |
Adam Lesinski | 8c3f31f | 2016-09-07 13:45:13 -0700 | [diff] [blame] | 154 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 155 | String* str = test::GetValue<String>(&table_, "string/foo"); |
Adam Lesinski | a45893a | 2017-05-30 15:19:02 -0700 | [diff] [blame] | 156 | ASSERT_THAT(str, NotNull()); |
Adam Lesinski | 2eed52e | 2018-02-21 15:55:58 -0800 | [diff] [blame] | 157 | EXPECT_THAT(*str->value, StrEq("This is what I think")); |
Adam Lesinski | a45893a | 2017-05-30 15:19:02 -0700 | [diff] [blame] | 158 | EXPECT_THAT(str->untranslatable_sections, IsEmpty()); |
Adam Lesinski | 8c3f31f | 2016-09-07 13:45:13 -0700 | [diff] [blame] | 159 | |
Adam Lesinski | a45893a | 2017-05-30 15:19:02 -0700 | [diff] [blame] | 160 | ASSERT_TRUE(TestParse(R"(<string name="foo2">" This is what I think "</string>)")); |
Adam Lesinski | 8c3f31f | 2016-09-07 13:45:13 -0700 | [diff] [blame] | 161 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 162 | str = test::GetValue<String>(&table_, "string/foo2"); |
Adam Lesinski | a45893a | 2017-05-30 15:19:02 -0700 | [diff] [blame] | 163 | ASSERT_THAT(str, NotNull()); |
| 164 | EXPECT_THAT(*str, StrValueEq(" This is what I think ")); |
Adam Lesinski | 8c3f31f | 2016-09-07 13:45:13 -0700 | [diff] [blame] | 165 | } |
| 166 | |
Adam Lesinski | 2eed52e | 2018-02-21 15:55:58 -0800 | [diff] [blame] | 167 | TEST_F(ResourceParserTest, ParseStyledStringWithWhitespace) { |
| 168 | std::string input = R"(<string name="foo"> <b> My <i> favorite</i> string </b> </string>)"; |
| 169 | ASSERT_TRUE(TestParse(input)); |
| 170 | |
| 171 | StyledString* str = test::GetValue<StyledString>(&table_, "string/foo"); |
| 172 | ASSERT_THAT(str, NotNull()); |
| 173 | EXPECT_THAT(str->value->value, StrEq(" My favorite string ")); |
| 174 | EXPECT_THAT(str->untranslatable_sections, IsEmpty()); |
| 175 | |
| 176 | ASSERT_THAT(str->value->spans, SizeIs(2u)); |
| 177 | EXPECT_THAT(*str->value->spans[0].name, StrEq("b")); |
| 178 | EXPECT_THAT(str->value->spans[0].first_char, Eq(1u)); |
| 179 | EXPECT_THAT(str->value->spans[0].last_char, Eq(21u)); |
| 180 | |
| 181 | EXPECT_THAT(*str->value->spans[1].name, StrEq("i")); |
| 182 | EXPECT_THAT(str->value->spans[1].first_char, Eq(5u)); |
| 183 | EXPECT_THAT(str->value->spans[1].last_char, Eq(13u)); |
| 184 | } |
| 185 | |
Adam Lesinski | 7542162 | 2017-01-06 15:20:04 -0800 | [diff] [blame] | 186 | TEST_F(ResourceParserTest, IgnoreXliffTagsOtherThanG) { |
Adam Lesinski | a45893a | 2017-05-30 15:19:02 -0700 | [diff] [blame] | 187 | std::string input = R"( |
Adam Lesinski | 7542162 | 2017-01-06 15:20:04 -0800 | [diff] [blame] | 188 | <string name="foo" xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2"> |
Adam Lesinski | a45893a | 2017-05-30 15:19:02 -0700 | [diff] [blame] | 189 | There are <xliff:source>no</xliff:source> apples</string>)"; |
Adam Lesinski | 7542162 | 2017-01-06 15:20:04 -0800 | [diff] [blame] | 190 | ASSERT_TRUE(TestParse(input)); |
| 191 | |
| 192 | String* str = test::GetValue<String>(&table_, "string/foo"); |
Adam Lesinski | a45893a | 2017-05-30 15:19:02 -0700 | [diff] [blame] | 193 | ASSERT_THAT(str, NotNull()); |
| 194 | EXPECT_THAT(*str, StrValueEq("There are no apples")); |
| 195 | EXPECT_THAT(str->untranslatable_sections, IsEmpty()); |
Adam Lesinski | 7542162 | 2017-01-06 15:20:04 -0800 | [diff] [blame] | 196 | } |
| 197 | |
| 198 | TEST_F(ResourceParserTest, NestedXliffGTagsAreIllegal) { |
Adam Lesinski | a45893a | 2017-05-30 15:19:02 -0700 | [diff] [blame] | 199 | std::string input = R"( |
Adam Lesinski | 7542162 | 2017-01-06 15:20:04 -0800 | [diff] [blame] | 200 | <string name="foo" xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2"> |
Adam Lesinski | a45893a | 2017-05-30 15:19:02 -0700 | [diff] [blame] | 201 | Do not <xliff:g>translate <xliff:g>this</xliff:g></xliff:g></string>)"; |
Adam Lesinski | 7542162 | 2017-01-06 15:20:04 -0800 | [diff] [blame] | 202 | EXPECT_FALSE(TestParse(input)); |
| 203 | } |
| 204 | |
| 205 | TEST_F(ResourceParserTest, RecordUntranslateableXliffSectionsInString) { |
Adam Lesinski | a45893a | 2017-05-30 15:19:02 -0700 | [diff] [blame] | 206 | std::string input = R"( |
Adam Lesinski | 7542162 | 2017-01-06 15:20:04 -0800 | [diff] [blame] | 207 | <string name="foo" xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2"> |
Adam Lesinski | a45893a | 2017-05-30 15:19:02 -0700 | [diff] [blame] | 208 | There are <xliff:g id="count">%1$d</xliff:g> apples</string>)"; |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 209 | ASSERT_TRUE(TestParse(input)); |
Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 210 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 211 | String* str = test::GetValue<String>(&table_, "string/foo"); |
Adam Lesinski | a45893a | 2017-05-30 15:19:02 -0700 | [diff] [blame] | 212 | ASSERT_THAT(str, NotNull()); |
| 213 | EXPECT_THAT(*str, StrValueEq("There are %1$d apples")); |
Adam Lesinski | 7542162 | 2017-01-06 15:20:04 -0800 | [diff] [blame] | 214 | |
Adam Lesinski | 2eed52e | 2018-02-21 15:55:58 -0800 | [diff] [blame] | 215 | ASSERT_THAT(str->untranslatable_sections, SizeIs(1)); |
| 216 | EXPECT_THAT(str->untranslatable_sections[0].start, Eq(10u)); |
Adam Lesinski | a45893a | 2017-05-30 15:19:02 -0700 | [diff] [blame] | 217 | EXPECT_THAT(str->untranslatable_sections[0].end, Eq(14u)); |
Adam Lesinski | 7542162 | 2017-01-06 15:20:04 -0800 | [diff] [blame] | 218 | } |
| 219 | |
| 220 | TEST_F(ResourceParserTest, RecordUntranslateableXliffSectionsInStyledString) { |
Adam Lesinski | a45893a | 2017-05-30 15:19:02 -0700 | [diff] [blame] | 221 | std::string input = R"( |
Adam Lesinski | 7542162 | 2017-01-06 15:20:04 -0800 | [diff] [blame] | 222 | <string name="foo" xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2"> |
Adam Lesinski | a45893a | 2017-05-30 15:19:02 -0700 | [diff] [blame] | 223 | There are <b><xliff:g id="count">%1$d</xliff:g></b> apples</string>)"; |
Adam Lesinski | 7542162 | 2017-01-06 15:20:04 -0800 | [diff] [blame] | 224 | ASSERT_TRUE(TestParse(input)); |
| 225 | |
| 226 | StyledString* str = test::GetValue<StyledString>(&table_, "string/foo"); |
Adam Lesinski | a45893a | 2017-05-30 15:19:02 -0700 | [diff] [blame] | 227 | ASSERT_THAT(str, NotNull()); |
Adam Lesinski | 2eed52e | 2018-02-21 15:55:58 -0800 | [diff] [blame] | 228 | EXPECT_THAT(str->value->value, Eq(" There are %1$d apples")); |
Adam Lesinski | 7542162 | 2017-01-06 15:20:04 -0800 | [diff] [blame] | 229 | |
Adam Lesinski | 2eed52e | 2018-02-21 15:55:58 -0800 | [diff] [blame] | 230 | ASSERT_THAT(str->untranslatable_sections, SizeIs(1)); |
| 231 | EXPECT_THAT(str->untranslatable_sections[0].start, Eq(11u)); |
| 232 | EXPECT_THAT(str->untranslatable_sections[0].end, Eq(15u)); |
| 233 | |
| 234 | ASSERT_THAT(str->value->spans, SizeIs(1u)); |
| 235 | EXPECT_THAT(*str->value->spans[0].name, StrEq("b")); |
| 236 | EXPECT_THAT(str->value->spans[0].first_char, Eq(11u)); |
| 237 | EXPECT_THAT(str->value->spans[0].last_char, Eq(14u)); |
Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 238 | } |
| 239 | |
Adam Lesinski | dfa5e07 | 2015-05-12 21:42:59 -0700 | [diff] [blame] | 240 | TEST_F(ResourceParserTest, ParseNull) { |
Adam Lesinski | a45893a | 2017-05-30 15:19:02 -0700 | [diff] [blame] | 241 | std::string input = R"(<integer name="foo">@null</integer>)"; |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 242 | ASSERT_TRUE(TestParse(input)); |
Adam Lesinski | dfa5e07 | 2015-05-12 21:42:59 -0700 | [diff] [blame] | 243 | |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 244 | // The Android runtime treats a value of android::Res_value::TYPE_NULL as |
| 245 | // a non-existing value, and this causes problems in styles when trying to |
Adam Lesinski | 7542162 | 2017-01-06 15:20:04 -0800 | [diff] [blame] | 246 | // resolve an attribute. Null values must be encoded as android::Res_value::TYPE_REFERENCE |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 247 | // with a data value of 0. |
Adam Lesinski | bab4ef5 | 2017-06-01 15:22:57 -0700 | [diff] [blame] | 248 | Reference* null_ref = test::GetValue<Reference>(&table_, "integer/foo"); |
| 249 | ASSERT_THAT(null_ref, NotNull()); |
| 250 | EXPECT_FALSE(null_ref->name); |
| 251 | EXPECT_FALSE(null_ref->id); |
Adam Lesinski | a45893a | 2017-05-30 15:19:02 -0700 | [diff] [blame] | 252 | EXPECT_THAT(null_ref->reference_type, Eq(Reference::Type::kResource)); |
Adam Lesinski | dfa5e07 | 2015-05-12 21:42:59 -0700 | [diff] [blame] | 253 | } |
| 254 | |
| 255 | TEST_F(ResourceParserTest, ParseEmpty) { |
Adam Lesinski | a45893a | 2017-05-30 15:19:02 -0700 | [diff] [blame] | 256 | std::string input = R"(<integer name="foo">@empty</integer>)"; |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 257 | ASSERT_TRUE(TestParse(input)); |
Adam Lesinski | dfa5e07 | 2015-05-12 21:42:59 -0700 | [diff] [blame] | 258 | |
Adam Lesinski | bab4ef5 | 2017-06-01 15:22:57 -0700 | [diff] [blame] | 259 | BinaryPrimitive* integer = test::GetValue<BinaryPrimitive>(&table_, "integer/foo"); |
Adam Lesinski | a45893a | 2017-05-30 15:19:02 -0700 | [diff] [blame] | 260 | ASSERT_THAT(integer, NotNull()); |
| 261 | EXPECT_THAT(integer->value.dataType, Eq(Res_value::TYPE_NULL)); |
| 262 | EXPECT_THAT(integer->value.data, Eq(Res_value::DATA_NULL_EMPTY)); |
Adam Lesinski | dfa5e07 | 2015-05-12 21:42:59 -0700 | [diff] [blame] | 263 | } |
| 264 | |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 265 | TEST_F(ResourceParserTest, ParseAttr) { |
Adam Lesinski | a45893a | 2017-05-30 15:19:02 -0700 | [diff] [blame] | 266 | std::string input = R"( |
| 267 | <attr name="foo" format="string"/> |
| 268 | <attr name="bar"/>)"; |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 269 | ASSERT_TRUE(TestParse(input)); |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 270 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 271 | Attribute* attr = test::GetValue<Attribute>(&table_, "attr/foo"); |
Adam Lesinski | a45893a | 2017-05-30 15:19:02 -0700 | [diff] [blame] | 272 | ASSERT_THAT(attr, NotNull()); |
| 273 | EXPECT_THAT(attr->type_mask, Eq(ResTable_map::TYPE_STRING)); |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 274 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 275 | attr = test::GetValue<Attribute>(&table_, "attr/bar"); |
Adam Lesinski | a45893a | 2017-05-30 15:19:02 -0700 | [diff] [blame] | 276 | ASSERT_THAT(attr, NotNull()); |
| 277 | EXPECT_THAT(attr->type_mask, Eq(ResTable_map::TYPE_ANY)); |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 278 | } |
| 279 | |
Adam Lesinski | a45893a | 2017-05-30 15:19:02 -0700 | [diff] [blame] | 280 | // Old AAPT allowed attributes to be defined under different configurations, but ultimately |
| 281 | // stored them with the default configuration. Check that we have the same behavior. |
Adam Lesinski | bab4ef5 | 2017-06-01 15:22:57 -0700 | [diff] [blame] | 282 | TEST_F(ResourceParserTest, ParseAttrAndDeclareStyleableUnderConfigButRecordAsNoConfig) { |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 283 | const ConfigDescription watch_config = test::ParseConfigOrDie("watch"); |
Adam Lesinski | bab4ef5 | 2017-06-01 15:22:57 -0700 | [diff] [blame] | 284 | std::string input = R"( |
| 285 | <attr name="foo" /> |
| 286 | <declare-styleable name="bar"> |
| 287 | <attr name="baz" /> |
| 288 | </declare-styleable>)"; |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 289 | ASSERT_TRUE(TestParse(input, watch_config)); |
Adam Lesinski | 52364f7 | 2016-01-11 13:10:24 -0800 | [diff] [blame] | 290 | |
Adam Lesinski | a45893a | 2017-05-30 15:19:02 -0700 | [diff] [blame] | 291 | EXPECT_THAT(test::GetValueForConfig<Attribute>(&table_, "attr/foo", watch_config), IsNull()); |
| 292 | EXPECT_THAT(test::GetValueForConfig<Attribute>(&table_, "attr/baz", watch_config), IsNull()); |
| 293 | EXPECT_THAT(test::GetValueForConfig<Styleable>(&table_, "styleable/bar", watch_config), IsNull()); |
Adam Lesinski | 52364f7 | 2016-01-11 13:10:24 -0800 | [diff] [blame] | 294 | |
Adam Lesinski | a45893a | 2017-05-30 15:19:02 -0700 | [diff] [blame] | 295 | EXPECT_THAT(test::GetValue<Attribute>(&table_, "attr/foo"), NotNull()); |
| 296 | EXPECT_THAT(test::GetValue<Attribute>(&table_, "attr/baz"), NotNull()); |
| 297 | EXPECT_THAT(test::GetValue<Styleable>(&table_, "styleable/bar"), NotNull()); |
Adam Lesinski | 52364f7 | 2016-01-11 13:10:24 -0800 | [diff] [blame] | 298 | } |
| 299 | |
Adam Lesinski | a587065 | 2015-11-20 15:32:30 -0800 | [diff] [blame] | 300 | TEST_F(ResourceParserTest, ParseAttrWithMinMax) { |
Adam Lesinski | a45893a | 2017-05-30 15:19:02 -0700 | [diff] [blame] | 301 | std::string input = R"(<attr name="foo" min="10" max="23" format="integer"/>)"; |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 302 | ASSERT_TRUE(TestParse(input)); |
Adam Lesinski | a587065 | 2015-11-20 15:32:30 -0800 | [diff] [blame] | 303 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 304 | Attribute* attr = test::GetValue<Attribute>(&table_, "attr/foo"); |
Adam Lesinski | a45893a | 2017-05-30 15:19:02 -0700 | [diff] [blame] | 305 | ASSERT_THAT(attr, NotNull()); |
| 306 | EXPECT_THAT(attr->type_mask, Eq(ResTable_map::TYPE_INTEGER)); |
| 307 | EXPECT_THAT(attr->min_int, Eq(10)); |
| 308 | EXPECT_THAT(attr->max_int, Eq(23)); |
Adam Lesinski | a587065 | 2015-11-20 15:32:30 -0800 | [diff] [blame] | 309 | } |
| 310 | |
| 311 | TEST_F(ResourceParserTest, FailParseAttrWithMinMaxButNotInteger) { |
Adam Lesinski | a45893a | 2017-05-30 15:19:02 -0700 | [diff] [blame] | 312 | ASSERT_FALSE(TestParse(R"(<attr name="foo" min="10" max="23" format="string"/>)")); |
Adam Lesinski | a587065 | 2015-11-20 15:32:30 -0800 | [diff] [blame] | 313 | } |
| 314 | |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 315 | TEST_F(ResourceParserTest, ParseUseAndDeclOfAttr) { |
Adam Lesinski | a45893a | 2017-05-30 15:19:02 -0700 | [diff] [blame] | 316 | std::string input = R"( |
| 317 | <declare-styleable name="Styleable"> |
| 318 | <attr name="foo" /> |
| 319 | </declare-styleable> |
| 320 | <attr name="foo" format="string"/>)"; |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 321 | ASSERT_TRUE(TestParse(input)); |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 322 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 323 | Attribute* attr = test::GetValue<Attribute>(&table_, "attr/foo"); |
Adam Lesinski | a45893a | 2017-05-30 15:19:02 -0700 | [diff] [blame] | 324 | ASSERT_THAT(attr, NotNull()); |
| 325 | EXPECT_THAT(attr->type_mask, Eq(ResTable_map::TYPE_STRING)); |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 326 | } |
| 327 | |
| 328 | TEST_F(ResourceParserTest, ParseDoubleUseOfAttr) { |
Adam Lesinski | a45893a | 2017-05-30 15:19:02 -0700 | [diff] [blame] | 329 | std::string input = R"( |
| 330 | <declare-styleable name="Theme"> |
| 331 | <attr name="foo" /> |
| 332 | </declare-styleable> |
| 333 | <declare-styleable name="Window"> |
| 334 | <attr name="foo" format="boolean"/> |
| 335 | </declare-styleable>)"; |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 336 | ASSERT_TRUE(TestParse(input)); |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 337 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 338 | Attribute* attr = test::GetValue<Attribute>(&table_, "attr/foo"); |
Adam Lesinski | a45893a | 2017-05-30 15:19:02 -0700 | [diff] [blame] | 339 | ASSERT_THAT(attr, NotNull()); |
| 340 | EXPECT_THAT(attr->type_mask, Eq(ResTable_map::TYPE_BOOLEAN)); |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 341 | } |
| 342 | |
| 343 | TEST_F(ResourceParserTest, ParseEnumAttr) { |
Adam Lesinski | a45893a | 2017-05-30 15:19:02 -0700 | [diff] [blame] | 344 | std::string input = R"( |
| 345 | <attr name="foo"> |
| 346 | <enum name="bar" value="0"/> |
| 347 | <enum name="bat" value="1"/> |
| 348 | <enum name="baz" value="2"/> |
| 349 | </attr>)"; |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 350 | ASSERT_TRUE(TestParse(input)); |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 351 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 352 | Attribute* enum_attr = test::GetValue<Attribute>(&table_, "attr/foo"); |
Adam Lesinski | a45893a | 2017-05-30 15:19:02 -0700 | [diff] [blame] | 353 | ASSERT_THAT(enum_attr, NotNull()); |
| 354 | EXPECT_THAT(enum_attr->type_mask, Eq(ResTable_map::TYPE_ENUM)); |
| 355 | ASSERT_THAT(enum_attr->symbols, SizeIs(3)); |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 356 | |
Adam Lesinski | a45893a | 2017-05-30 15:19:02 -0700 | [diff] [blame] | 357 | ASSERT_TRUE(enum_attr->symbols[0].symbol.name); |
| 358 | EXPECT_THAT(enum_attr->symbols[0].symbol.name.value().entry, Eq("bar")); |
| 359 | EXPECT_THAT(enum_attr->symbols[0].value, Eq(0u)); |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 360 | |
Adam Lesinski | a45893a | 2017-05-30 15:19:02 -0700 | [diff] [blame] | 361 | ASSERT_TRUE(enum_attr->symbols[1].symbol.name); |
| 362 | EXPECT_THAT(enum_attr->symbols[1].symbol.name.value().entry, Eq("bat")); |
| 363 | EXPECT_THAT(enum_attr->symbols[1].value, Eq(1u)); |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 364 | |
Adam Lesinski | a45893a | 2017-05-30 15:19:02 -0700 | [diff] [blame] | 365 | ASSERT_TRUE(enum_attr->symbols[2].symbol.name); |
| 366 | EXPECT_THAT(enum_attr->symbols[2].symbol.name.value().entry, Eq("baz")); |
| 367 | EXPECT_THAT(enum_attr->symbols[2].value, Eq(2u)); |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 368 | } |
| 369 | |
| 370 | TEST_F(ResourceParserTest, ParseFlagAttr) { |
Adam Lesinski | a45893a | 2017-05-30 15:19:02 -0700 | [diff] [blame] | 371 | std::string input = R"( |
| 372 | <attr name="foo"> |
| 373 | <flag name="bar" value="0"/> |
| 374 | <flag name="bat" value="1"/> |
| 375 | <flag name="baz" value="2"/> |
| 376 | </attr>)"; |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 377 | ASSERT_TRUE(TestParse(input)); |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 378 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 379 | Attribute* flag_attr = test::GetValue<Attribute>(&table_, "attr/foo"); |
Adam Lesinski | a45893a | 2017-05-30 15:19:02 -0700 | [diff] [blame] | 380 | ASSERT_THAT(flag_attr, NotNull()); |
| 381 | EXPECT_THAT(flag_attr->type_mask, Eq(ResTable_map::TYPE_FLAGS)); |
| 382 | ASSERT_THAT(flag_attr->symbols, SizeIs(3)); |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 383 | |
Adam Lesinski | a45893a | 2017-05-30 15:19:02 -0700 | [diff] [blame] | 384 | ASSERT_TRUE(flag_attr->symbols[0].symbol.name); |
| 385 | EXPECT_THAT(flag_attr->symbols[0].symbol.name.value().entry, Eq("bar")); |
| 386 | EXPECT_THAT(flag_attr->symbols[0].value, Eq(0u)); |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 387 | |
Adam Lesinski | a45893a | 2017-05-30 15:19:02 -0700 | [diff] [blame] | 388 | ASSERT_TRUE(flag_attr->symbols[1].symbol.name); |
| 389 | EXPECT_THAT(flag_attr->symbols[1].symbol.name.value().entry, Eq("bat")); |
| 390 | EXPECT_THAT(flag_attr->symbols[1].value, Eq(1u)); |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 391 | |
Adam Lesinski | a45893a | 2017-05-30 15:19:02 -0700 | [diff] [blame] | 392 | ASSERT_TRUE(flag_attr->symbols[2].symbol.name); |
| 393 | EXPECT_THAT(flag_attr->symbols[2].symbol.name.value().entry, Eq("baz")); |
| 394 | EXPECT_THAT(flag_attr->symbols[2].value, Eq(2u)); |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 395 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 396 | std::unique_ptr<BinaryPrimitive> flag_value = |
| 397 | ResourceUtils::TryParseFlagSymbol(flag_attr, "baz|bat"); |
Adam Lesinski | a45893a | 2017-05-30 15:19:02 -0700 | [diff] [blame] | 398 | ASSERT_THAT(flag_value, NotNull()); |
| 399 | EXPECT_THAT(flag_value->value.data, Eq(1u | 2u)); |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 400 | } |
| 401 | |
| 402 | TEST_F(ResourceParserTest, FailToParseEnumAttrWithNonUniqueKeys) { |
Adam Lesinski | a45893a | 2017-05-30 15:19:02 -0700 | [diff] [blame] | 403 | std::string input = R"( |
| 404 | <attr name="foo"> |
| 405 | <enum name="bar" value="0"/> |
| 406 | <enum name="bat" value="1"/> |
| 407 | <enum name="bat" value="2"/> |
| 408 | </attr>)"; |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 409 | ASSERT_FALSE(TestParse(input)); |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 410 | } |
| 411 | |
| 412 | TEST_F(ResourceParserTest, ParseStyle) { |
Adam Lesinski | a45893a | 2017-05-30 15:19:02 -0700 | [diff] [blame] | 413 | std::string input = R"( |
| 414 | <style name="foo" parent="@style/fu"> |
| 415 | <item name="bar">#ffffffff</item> |
| 416 | <item name="bat">@string/hey</item> |
| 417 | <item name="baz"><b>hey</b></item> |
| 418 | </style>)"; |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 419 | ASSERT_TRUE(TestParse(input)); |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 420 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 421 | Style* style = test::GetValue<Style>(&table_, "style/foo"); |
Adam Lesinski | a45893a | 2017-05-30 15:19:02 -0700 | [diff] [blame] | 422 | ASSERT_THAT(style, NotNull()); |
| 423 | ASSERT_TRUE(style->parent); |
| 424 | EXPECT_THAT(style->parent.value().name, Eq(make_value(test::ParseNameOrDie("style/fu")))); |
| 425 | ASSERT_THAT(style->entries, SizeIs(3)); |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 426 | |
Adam Lesinski | a45893a | 2017-05-30 15:19:02 -0700 | [diff] [blame] | 427 | EXPECT_THAT(style->entries[0].key.name, Eq(make_value(test::ParseNameOrDie("attr/bar")))); |
| 428 | EXPECT_THAT(style->entries[1].key.name, Eq(make_value(test::ParseNameOrDie("attr/bat")))); |
| 429 | EXPECT_THAT(style->entries[2].key.name, Eq(make_value(test::ParseNameOrDie("attr/baz")))); |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 430 | } |
| 431 | |
Adam Lesinski | 769de98 | 2015-04-10 19:43:55 -0700 | [diff] [blame] | 432 | TEST_F(ResourceParserTest, ParseStyleWithShorthandParent) { |
Adam Lesinski | a45893a | 2017-05-30 15:19:02 -0700 | [diff] [blame] | 433 | ASSERT_TRUE(TestParse(R"(<style name="foo" parent="com.app:Theme"/>)")); |
Adam Lesinski | 769de98 | 2015-04-10 19:43:55 -0700 | [diff] [blame] | 434 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 435 | Style* style = test::GetValue<Style>(&table_, "style/foo"); |
Adam Lesinski | a45893a | 2017-05-30 15:19:02 -0700 | [diff] [blame] | 436 | ASSERT_THAT(style, NotNull()); |
| 437 | ASSERT_TRUE(style->parent); |
| 438 | EXPECT_THAT(style->parent.value().name, Eq(make_value(test::ParseNameOrDie("com.app:style/Theme")))); |
Adam Lesinski | 769de98 | 2015-04-10 19:43:55 -0700 | [diff] [blame] | 439 | } |
| 440 | |
Adam Lesinski | 24aad16 | 2015-04-24 19:19:30 -0700 | [diff] [blame] | 441 | TEST_F(ResourceParserTest, ParseStyleWithPackageAliasedParent) { |
Adam Lesinski | a45893a | 2017-05-30 15:19:02 -0700 | [diff] [blame] | 442 | std::string input = R"( |
| 443 | <style xmlns:app="http://schemas.android.com/apk/res/android" |
| 444 | name="foo" parent="app:Theme"/>)"; |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 445 | ASSERT_TRUE(TestParse(input)); |
Adam Lesinski | 24aad16 | 2015-04-24 19:19:30 -0700 | [diff] [blame] | 446 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 447 | Style* style = test::GetValue<Style>(&table_, "style/foo"); |
Adam Lesinski | a45893a | 2017-05-30 15:19:02 -0700 | [diff] [blame] | 448 | ASSERT_THAT(style, NotNull()); |
| 449 | ASSERT_TRUE(style->parent); |
| 450 | ASSERT_TRUE(style->parent.value().name); |
| 451 | EXPECT_THAT(style->parent.value().name, Eq(make_value(test::ParseNameOrDie("android:style/Theme")))); |
Adam Lesinski | 24aad16 | 2015-04-24 19:19:30 -0700 | [diff] [blame] | 452 | } |
| 453 | |
| 454 | TEST_F(ResourceParserTest, ParseStyleWithPackageAliasedItems) { |
Adam Lesinski | a45893a | 2017-05-30 15:19:02 -0700 | [diff] [blame] | 455 | std::string input = R"( |
| 456 | <style xmlns:app="http://schemas.android.com/apk/res/android" name="foo"> |
| 457 | <item name="app:bar">0</item> |
| 458 | </style>)"; |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 459 | ASSERT_TRUE(TestParse(input)); |
Adam Lesinski | 24aad16 | 2015-04-24 19:19:30 -0700 | [diff] [blame] | 460 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 461 | Style* style = test::GetValue<Style>(&table_, "style/foo"); |
Adam Lesinski | a45893a | 2017-05-30 15:19:02 -0700 | [diff] [blame] | 462 | ASSERT_THAT(style, NotNull()); |
| 463 | ASSERT_THAT(style->entries, SizeIs(1)); |
| 464 | EXPECT_THAT(style->entries[0].key.name, Eq(make_value(test::ParseNameOrDie("android:attr/bar")))); |
Adam Lesinski | 24aad16 | 2015-04-24 19:19:30 -0700 | [diff] [blame] | 465 | } |
| 466 | |
Adam Lesinski | bdaa092 | 2015-05-08 20:16:23 -0700 | [diff] [blame] | 467 | TEST_F(ResourceParserTest, ParseStyleWithInferredParent) { |
Adam Lesinski | a45893a | 2017-05-30 15:19:02 -0700 | [diff] [blame] | 468 | ASSERT_TRUE(TestParse(R"(<style name="foo.bar"/>)")); |
Adam Lesinski | bdaa092 | 2015-05-08 20:16:23 -0700 | [diff] [blame] | 469 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 470 | Style* style = test::GetValue<Style>(&table_, "style/foo.bar"); |
Adam Lesinski | a45893a | 2017-05-30 15:19:02 -0700 | [diff] [blame] | 471 | ASSERT_THAT(style, NotNull()); |
| 472 | ASSERT_TRUE(style->parent); |
| 473 | EXPECT_THAT(style->parent.value().name, Eq(make_value(test::ParseNameOrDie("style/foo")))); |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 474 | EXPECT_TRUE(style->parent_inferred); |
Adam Lesinski | bdaa092 | 2015-05-08 20:16:23 -0700 | [diff] [blame] | 475 | } |
| 476 | |
Adam Lesinski | a45893a | 2017-05-30 15:19:02 -0700 | [diff] [blame] | 477 | TEST_F(ResourceParserTest, ParseStyleWithInferredParentOverridenByEmptyParentAttribute) { |
| 478 | ASSERT_TRUE(TestParse(R"(<style name="foo.bar" parent=""/>)")); |
Adam Lesinski | bdaa092 | 2015-05-08 20:16:23 -0700 | [diff] [blame] | 479 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 480 | Style* style = test::GetValue<Style>(&table_, "style/foo.bar"); |
Adam Lesinski | a45893a | 2017-05-30 15:19:02 -0700 | [diff] [blame] | 481 | ASSERT_THAT(style, NotNull()); |
| 482 | EXPECT_FALSE(style->parent); |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 483 | EXPECT_FALSE(style->parent_inferred); |
Adam Lesinski | bdaa092 | 2015-05-08 20:16:23 -0700 | [diff] [blame] | 484 | } |
| 485 | |
Adam Lesinski | 24b8ff0 | 2015-12-16 14:01:57 -0800 | [diff] [blame] | 486 | TEST_F(ResourceParserTest, ParseStyleWithPrivateParentReference) { |
Adam Lesinski | a45893a | 2017-05-30 15:19:02 -0700 | [diff] [blame] | 487 | ASSERT_TRUE(TestParse(R"(<style name="foo" parent="*android:style/bar" />)")); |
Adam Lesinski | 24b8ff0 | 2015-12-16 14:01:57 -0800 | [diff] [blame] | 488 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 489 | Style* style = test::GetValue<Style>(&table_, "style/foo"); |
Adam Lesinski | a45893a | 2017-05-30 15:19:02 -0700 | [diff] [blame] | 490 | ASSERT_THAT(style, NotNull()); |
| 491 | ASSERT_TRUE(style->parent); |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 492 | EXPECT_TRUE(style->parent.value().private_reference); |
Adam Lesinski | 24b8ff0 | 2015-12-16 14:01:57 -0800 | [diff] [blame] | 493 | } |
| 494 | |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 495 | TEST_F(ResourceParserTest, ParseAutoGeneratedIdReference) { |
Adam Lesinski | a45893a | 2017-05-30 15:19:02 -0700 | [diff] [blame] | 496 | ASSERT_TRUE(TestParse(R"(<string name="foo">@+id/bar</string>)")); |
| 497 | ASSERT_THAT(test::GetValue<Id>(&table_, "id/bar"), NotNull()); |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 498 | } |
| 499 | |
| 500 | TEST_F(ResourceParserTest, ParseAttributesDeclareStyleable) { |
Adam Lesinski | a45893a | 2017-05-30 15:19:02 -0700 | [diff] [blame] | 501 | std::string input = R"( |
| 502 | <declare-styleable name="foo"> |
| 503 | <attr name="bar" /> |
| 504 | <attr name="bat" format="string|reference"/> |
| 505 | <attr name="baz"> |
| 506 | <enum name="foo" value="1"/> |
| 507 | </attr> |
| 508 | </declare-styleable>)"; |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 509 | ASSERT_TRUE(TestParse(input)); |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 510 | |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 511 | Maybe<ResourceTable::SearchResult> result = |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 512 | table_.FindResource(test::ParseNameOrDie("styleable/foo")); |
Adam Lesinski | a45893a | 2017-05-30 15:19:02 -0700 | [diff] [blame] | 513 | ASSERT_TRUE(result); |
Adam Lesinski | 71be705 | 2017-12-12 16:48:07 -0800 | [diff] [blame] | 514 | EXPECT_THAT(result.value().entry->visibility.level, Eq(Visibility::Level::kPublic)); |
Adam Lesinski | 9f22204 | 2015-11-04 13:51:45 -0800 | [diff] [blame] | 515 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 516 | Attribute* attr = test::GetValue<Attribute>(&table_, "attr/bar"); |
Adam Lesinski | a45893a | 2017-05-30 15:19:02 -0700 | [diff] [blame] | 517 | ASSERT_THAT(attr, NotNull()); |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 518 | EXPECT_TRUE(attr->IsWeak()); |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 519 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 520 | attr = test::GetValue<Attribute>(&table_, "attr/bat"); |
Adam Lesinski | a45893a | 2017-05-30 15:19:02 -0700 | [diff] [blame] | 521 | ASSERT_THAT(attr, NotNull()); |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 522 | EXPECT_TRUE(attr->IsWeak()); |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 523 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 524 | attr = test::GetValue<Attribute>(&table_, "attr/baz"); |
Adam Lesinski | a45893a | 2017-05-30 15:19:02 -0700 | [diff] [blame] | 525 | ASSERT_THAT(attr, NotNull()); |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 526 | EXPECT_TRUE(attr->IsWeak()); |
Adam Lesinski | a45893a | 2017-05-30 15:19:02 -0700 | [diff] [blame] | 527 | EXPECT_THAT(attr->symbols, SizeIs(1)); |
Adam Lesinski | 9ba47d8 | 2015-10-13 11:37:10 -0700 | [diff] [blame] | 528 | |
Adam Lesinski | a45893a | 2017-05-30 15:19:02 -0700 | [diff] [blame] | 529 | EXPECT_THAT(test::GetValue<Id>(&table_, "id/foo"), NotNull()); |
Adam Lesinski | 9ba47d8 | 2015-10-13 11:37:10 -0700 | [diff] [blame] | 530 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 531 | Styleable* styleable = test::GetValue<Styleable>(&table_, "styleable/foo"); |
Adam Lesinski | a45893a | 2017-05-30 15:19:02 -0700 | [diff] [blame] | 532 | ASSERT_THAT(styleable, NotNull()); |
| 533 | ASSERT_THAT(styleable->entries, SizeIs(3)); |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 534 | |
Adam Lesinski | a45893a | 2017-05-30 15:19:02 -0700 | [diff] [blame] | 535 | EXPECT_THAT(styleable->entries[0].name, Eq(make_value(test::ParseNameOrDie("attr/bar")))); |
| 536 | EXPECT_THAT(styleable->entries[1].name, Eq(make_value(test::ParseNameOrDie("attr/bat")))); |
| 537 | EXPECT_THAT(styleable->entries[2].name, Eq(make_value(test::ParseNameOrDie("attr/baz")))); |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 538 | } |
| 539 | |
Adam Lesinski | 467f171 | 2015-11-16 17:35:44 -0800 | [diff] [blame] | 540 | TEST_F(ResourceParserTest, ParsePrivateAttributesDeclareStyleable) { |
Adam Lesinski | a45893a | 2017-05-30 15:19:02 -0700 | [diff] [blame] | 541 | std::string input = R"( |
| 542 | <declare-styleable xmlns:privAndroid="http://schemas.android.com/apk/prv/res/android" |
| 543 | name="foo"> |
| 544 | <attr name="*android:bar" /> |
| 545 | <attr name="privAndroid:bat" /> |
| 546 | </declare-styleable>)"; |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 547 | ASSERT_TRUE(TestParse(input)); |
| 548 | Styleable* styleable = test::GetValue<Styleable>(&table_, "styleable/foo"); |
Adam Lesinski | a45893a | 2017-05-30 15:19:02 -0700 | [diff] [blame] | 549 | ASSERT_THAT(styleable, NotNull()); |
| 550 | ASSERT_THAT(styleable->entries, SizeIs(2)); |
Adam Lesinski | 467f171 | 2015-11-16 17:35:44 -0800 | [diff] [blame] | 551 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 552 | EXPECT_TRUE(styleable->entries[0].private_reference); |
Adam Lesinski | a45893a | 2017-05-30 15:19:02 -0700 | [diff] [blame] | 553 | ASSERT_TRUE(styleable->entries[0].name); |
| 554 | EXPECT_THAT(styleable->entries[0].name.value().package, Eq("android")); |
Adam Lesinski | 467f171 | 2015-11-16 17:35:44 -0800 | [diff] [blame] | 555 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 556 | EXPECT_TRUE(styleable->entries[1].private_reference); |
Adam Lesinski | a45893a | 2017-05-30 15:19:02 -0700 | [diff] [blame] | 557 | ASSERT_TRUE(styleable->entries[1].name); |
| 558 | EXPECT_THAT(styleable->entries[1].name.value().package, Eq("android")); |
Adam Lesinski | 467f171 | 2015-11-16 17:35:44 -0800 | [diff] [blame] | 559 | } |
| 560 | |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 561 | TEST_F(ResourceParserTest, ParseArray) { |
Adam Lesinski | a45893a | 2017-05-30 15:19:02 -0700 | [diff] [blame] | 562 | std::string input = R"( |
| 563 | <array name="foo"> |
| 564 | <item>@string/ref</item> |
| 565 | <item>hey</item> |
| 566 | <item>23</item> |
| 567 | </array>)"; |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 568 | ASSERT_TRUE(TestParse(input)); |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 569 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 570 | Array* array = test::GetValue<Array>(&table_, "array/foo"); |
Adam Lesinski | a45893a | 2017-05-30 15:19:02 -0700 | [diff] [blame] | 571 | ASSERT_THAT(array, NotNull()); |
Adam Lesinski | 4ffea04 | 2017-08-10 15:37:28 -0700 | [diff] [blame] | 572 | ASSERT_THAT(array->elements, SizeIs(3)); |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 573 | |
Adam Lesinski | 4ffea04 | 2017-08-10 15:37:28 -0700 | [diff] [blame] | 574 | EXPECT_THAT(ValueCast<Reference>(array->elements[0].get()), NotNull()); |
| 575 | EXPECT_THAT(ValueCast<String>(array->elements[1].get()), NotNull()); |
| 576 | EXPECT_THAT(ValueCast<BinaryPrimitive>(array->elements[2].get()), NotNull()); |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 577 | } |
| 578 | |
Adam Lesinski | 9ba47d8 | 2015-10-13 11:37:10 -0700 | [diff] [blame] | 579 | TEST_F(ResourceParserTest, ParseStringArray) { |
Adam Lesinski | a45893a | 2017-05-30 15:19:02 -0700 | [diff] [blame] | 580 | std::string input = R"( |
Adam Lesinski | d5fd76a | 2017-05-16 12:18:08 -0700 | [diff] [blame] | 581 | <string-array name="foo"> |
| 582 | <item>"Werk"</item>" |
Adam Lesinski | a45893a | 2017-05-30 15:19:02 -0700 | [diff] [blame] | 583 | </string-array>)"; |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 584 | ASSERT_TRUE(TestParse(input)); |
Adam Lesinski | a45893a | 2017-05-30 15:19:02 -0700 | [diff] [blame] | 585 | EXPECT_THAT(test::GetValue<Array>(&table_, "array/foo"), NotNull()); |
Adam Lesinski | 9ba47d8 | 2015-10-13 11:37:10 -0700 | [diff] [blame] | 586 | } |
| 587 | |
Adam Lesinski | d5fd76a | 2017-05-16 12:18:08 -0700 | [diff] [blame] | 588 | TEST_F(ResourceParserTest, ParseArrayWithFormat) { |
Adam Lesinski | a45893a | 2017-05-30 15:19:02 -0700 | [diff] [blame] | 589 | std::string input = R"( |
Adam Lesinski | d5fd76a | 2017-05-16 12:18:08 -0700 | [diff] [blame] | 590 | <array name="foo" format="string"> |
| 591 | <item>100</item> |
Adam Lesinski | a45893a | 2017-05-30 15:19:02 -0700 | [diff] [blame] | 592 | </array>)"; |
Adam Lesinski | d5fd76a | 2017-05-16 12:18:08 -0700 | [diff] [blame] | 593 | ASSERT_TRUE(TestParse(input)); |
| 594 | |
| 595 | Array* array = test::GetValue<Array>(&table_, "array/foo"); |
Adam Lesinski | a45893a | 2017-05-30 15:19:02 -0700 | [diff] [blame] | 596 | ASSERT_THAT(array, NotNull()); |
Adam Lesinski | 4ffea04 | 2017-08-10 15:37:28 -0700 | [diff] [blame] | 597 | ASSERT_THAT(array->elements, SizeIs(1)); |
Adam Lesinski | d5fd76a | 2017-05-16 12:18:08 -0700 | [diff] [blame] | 598 | |
Adam Lesinski | 4ffea04 | 2017-08-10 15:37:28 -0700 | [diff] [blame] | 599 | String* str = ValueCast<String>(array->elements[0].get()); |
Adam Lesinski | a45893a | 2017-05-30 15:19:02 -0700 | [diff] [blame] | 600 | ASSERT_THAT(str, NotNull()); |
| 601 | EXPECT_THAT(*str, StrValueEq("100")); |
Adam Lesinski | d5fd76a | 2017-05-16 12:18:08 -0700 | [diff] [blame] | 602 | } |
| 603 | |
| 604 | TEST_F(ResourceParserTest, ParseArrayWithBadFormat) { |
Adam Lesinski | a45893a | 2017-05-30 15:19:02 -0700 | [diff] [blame] | 605 | std::string input = R"( |
Adam Lesinski | d5fd76a | 2017-05-16 12:18:08 -0700 | [diff] [blame] | 606 | <array name="foo" format="integer"> |
| 607 | <item>Hi</item> |
Adam Lesinski | a45893a | 2017-05-30 15:19:02 -0700 | [diff] [blame] | 608 | </array>)"; |
Adam Lesinski | d5fd76a | 2017-05-16 12:18:08 -0700 | [diff] [blame] | 609 | ASSERT_FALSE(TestParse(input)); |
| 610 | } |
| 611 | |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 612 | TEST_F(ResourceParserTest, ParsePlural) { |
Adam Lesinski | a45893a | 2017-05-30 15:19:02 -0700 | [diff] [blame] | 613 | std::string input = R"( |
| 614 | <plurals name="foo"> |
| 615 | <item quantity="other">apples</item> |
| 616 | <item quantity="one">apple</item> |
| 617 | </plurals>)"; |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 618 | ASSERT_TRUE(TestParse(input)); |
Adam Lesinski | 8f7c550 | 2017-03-02 17:45:01 -0800 | [diff] [blame] | 619 | |
| 620 | Plural* plural = test::GetValue<Plural>(&table_, "plurals/foo"); |
Adam Lesinski | a45893a | 2017-05-30 15:19:02 -0700 | [diff] [blame] | 621 | ASSERT_THAT(plural, NotNull()); |
| 622 | EXPECT_THAT(plural->values[Plural::Zero], IsNull()); |
| 623 | EXPECT_THAT(plural->values[Plural::Two], IsNull()); |
| 624 | EXPECT_THAT(plural->values[Plural::Few], IsNull()); |
| 625 | EXPECT_THAT(plural->values[Plural::Many], IsNull()); |
Adam Lesinski | 8f7c550 | 2017-03-02 17:45:01 -0800 | [diff] [blame] | 626 | |
Adam Lesinski | a45893a | 2017-05-30 15:19:02 -0700 | [diff] [blame] | 627 | EXPECT_THAT(plural->values[Plural::One], NotNull()); |
| 628 | EXPECT_THAT(plural->values[Plural::Other], NotNull()); |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 629 | } |
| 630 | |
| 631 | TEST_F(ResourceParserTest, ParseCommentsWithResource) { |
Adam Lesinski | a45893a | 2017-05-30 15:19:02 -0700 | [diff] [blame] | 632 | std::string input = R"( |
| 633 | <!--This is a comment--> |
| 634 | <string name="foo">Hi</string>)"; |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 635 | ASSERT_TRUE(TestParse(input)); |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 636 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 637 | String* value = test::GetValue<String>(&table_, "string/foo"); |
Adam Lesinski | a45893a | 2017-05-30 15:19:02 -0700 | [diff] [blame] | 638 | ASSERT_THAT(value, NotNull()); |
| 639 | EXPECT_THAT(value->GetComment(), Eq("This is a comment")); |
Adam Lesinski | e78fd61 | 2015-10-22 12:48:43 -0700 | [diff] [blame] | 640 | } |
Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 641 | |
Adam Lesinski | e78fd61 | 2015-10-22 12:48:43 -0700 | [diff] [blame] | 642 | TEST_F(ResourceParserTest, DoNotCombineMultipleComments) { |
Adam Lesinski | a45893a | 2017-05-30 15:19:02 -0700 | [diff] [blame] | 643 | std::string input = R"( |
| 644 | <!--One--> |
| 645 | <!--Two--> |
| 646 | <string name="foo">Hi</string>)"; |
Adam Lesinski | e78fd61 | 2015-10-22 12:48:43 -0700 | [diff] [blame] | 647 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 648 | ASSERT_TRUE(TestParse(input)); |
Adam Lesinski | e78fd61 | 2015-10-22 12:48:43 -0700 | [diff] [blame] | 649 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 650 | String* value = test::GetValue<String>(&table_, "string/foo"); |
Adam Lesinski | a45893a | 2017-05-30 15:19:02 -0700 | [diff] [blame] | 651 | ASSERT_THAT(value, NotNull()); |
| 652 | EXPECT_THAT(value->GetComment(), Eq("Two")); |
Adam Lesinski | e78fd61 | 2015-10-22 12:48:43 -0700 | [diff] [blame] | 653 | } |
| 654 | |
| 655 | TEST_F(ResourceParserTest, IgnoreCommentBeforeEndTag) { |
Adam Lesinski | a45893a | 2017-05-30 15:19:02 -0700 | [diff] [blame] | 656 | std::string input = R"( |
| 657 | <!--One--> |
| 658 | <string name="foo"> |
| 659 | Hi |
| 660 | <!--Two--> |
| 661 | </string>)"; |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 662 | ASSERT_TRUE(TestParse(input)); |
Adam Lesinski | e78fd61 | 2015-10-22 12:48:43 -0700 | [diff] [blame] | 663 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 664 | String* value = test::GetValue<String>(&table_, "string/foo"); |
Adam Lesinski | a45893a | 2017-05-30 15:19:02 -0700 | [diff] [blame] | 665 | ASSERT_THAT(value, NotNull()); |
| 666 | EXPECT_THAT(value->GetComment(), Eq("One")); |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 667 | } |
| 668 | |
Adam Lesinski | ca5638f | 2015-10-21 14:42:43 -0700 | [diff] [blame] | 669 | TEST_F(ResourceParserTest, ParseNestedComments) { |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 670 | // We only care about declare-styleable and enum/flag attributes because |
Adam Lesinski | a45893a | 2017-05-30 15:19:02 -0700 | [diff] [blame] | 671 | // comments from those end up in R.java |
| 672 | std::string input = R"( |
| 673 | <declare-styleable name="foo"> |
| 674 | <!-- The name of the bar --> |
| 675 | <attr name="barName" format="string|reference" /> |
| 676 | </declare-styleable> |
Adam Lesinski | ca5638f | 2015-10-21 14:42:43 -0700 | [diff] [blame] | 677 | |
Adam Lesinski | a45893a | 2017-05-30 15:19:02 -0700 | [diff] [blame] | 678 | <attr name="foo"> |
| 679 | <!-- The very first --> |
| 680 | <enum name="one" value="1" /> |
| 681 | </attr>)"; |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 682 | ASSERT_TRUE(TestParse(input)); |
Adam Lesinski | ca5638f | 2015-10-21 14:42:43 -0700 | [diff] [blame] | 683 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 684 | Styleable* styleable = test::GetValue<Styleable>(&table_, "styleable/foo"); |
Adam Lesinski | a45893a | 2017-05-30 15:19:02 -0700 | [diff] [blame] | 685 | ASSERT_THAT(styleable, NotNull()); |
| 686 | ASSERT_THAT(styleable->entries, SizeIs(1)); |
| 687 | EXPECT_THAT(styleable->entries[0].GetComment(), Eq("The name of the bar")); |
Adam Lesinski | ca5638f | 2015-10-21 14:42:43 -0700 | [diff] [blame] | 688 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 689 | Attribute* attr = test::GetValue<Attribute>(&table_, "attr/foo"); |
Adam Lesinski | a45893a | 2017-05-30 15:19:02 -0700 | [diff] [blame] | 690 | ASSERT_THAT(attr, NotNull()); |
| 691 | ASSERT_THAT(attr->symbols, SizeIs(1)); |
| 692 | EXPECT_THAT(attr->symbols[0].symbol.GetComment(), Eq("The very first")); |
Adam Lesinski | ca5638f | 2015-10-21 14:42:43 -0700 | [diff] [blame] | 693 | } |
| 694 | |
Adam Lesinski | a45893a | 2017-05-30 15:19:02 -0700 | [diff] [blame] | 695 | // Declaring an ID as public should not require a separate definition (as an ID has no value). |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 696 | TEST_F(ResourceParserTest, ParsePublicIdAsDefinition) { |
Adam Lesinski | a45893a | 2017-05-30 15:19:02 -0700 | [diff] [blame] | 697 | ASSERT_TRUE(TestParse(R"(<public type="id" name="foo"/>)")); |
| 698 | ASSERT_THAT(test::GetValue<Id>(&table_, "id/foo"), NotNull()); |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 699 | } |
| 700 | |
Adam Lesinski | e4bb9eb | 2016-02-12 22:18:51 -0800 | [diff] [blame] | 701 | TEST_F(ResourceParserTest, KeepAllProducts) { |
Adam Lesinski | a45893a | 2017-05-30 15:19:02 -0700 | [diff] [blame] | 702 | std::string input = R"( |
| 703 | <string name="foo" product="phone">hi</string> |
| 704 | <string name="foo" product="no-sdcard">ho</string> |
| 705 | <string name="bar" product="">wee</string> |
| 706 | <string name="baz">woo</string> |
| 707 | <string name="bit" product="phablet">hoot</string> |
| 708 | <string name="bot" product="default">yes</string>)"; |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 709 | ASSERT_TRUE(TestParse(input)); |
Adam Lesinski | 9ba47d8 | 2015-10-13 11:37:10 -0700 | [diff] [blame] | 710 | |
Adam Lesinski | a45893a | 2017-05-30 15:19:02 -0700 | [diff] [blame] | 711 | ASSERT_THAT(test::GetValueForConfigAndProduct<String>(&table_, "string/foo", ConfigDescription::DefaultConfig(), "phone"), NotNull()); |
| 712 | ASSERT_THAT(test::GetValueForConfigAndProduct<String>(&table_, "string/foo",ConfigDescription::DefaultConfig(), "no-sdcard"), NotNull()); |
| 713 | ASSERT_THAT(test::GetValueForConfigAndProduct<String>(&table_, "string/bar", ConfigDescription::DefaultConfig(), ""), NotNull()); |
| 714 | ASSERT_THAT(test::GetValueForConfigAndProduct<String>(&table_, "string/baz", ConfigDescription::DefaultConfig(), ""), NotNull()); |
| 715 | ASSERT_THAT(test::GetValueForConfigAndProduct<String>(&table_, "string/bit", ConfigDescription::DefaultConfig(), "phablet"), NotNull()); |
| 716 | ASSERT_THAT(test::GetValueForConfigAndProduct<String>(&table_, "string/bot", ConfigDescription::DefaultConfig(), "default"), NotNull()); |
Adam Lesinski | 9ba47d8 | 2015-10-13 11:37:10 -0700 | [diff] [blame] | 717 | } |
| 718 | |
Adam Lesinski | 27afb9e | 2015-11-06 18:25:04 -0800 | [diff] [blame] | 719 | TEST_F(ResourceParserTest, AutoIncrementIdsInPublicGroup) { |
Adam Lesinski | a45893a | 2017-05-30 15:19:02 -0700 | [diff] [blame] | 720 | std::string input = R"( |
| 721 | <public-group type="attr" first-id="0x01010040"> |
| 722 | <public name="foo" /> |
| 723 | <public name="bar" /> |
| 724 | </public-group>)"; |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 725 | ASSERT_TRUE(TestParse(input)); |
Adam Lesinski | 27afb9e | 2015-11-06 18:25:04 -0800 | [diff] [blame] | 726 | |
Adam Lesinski | a45893a | 2017-05-30 15:19:02 -0700 | [diff] [blame] | 727 | Maybe<ResourceTable::SearchResult> result = table_.FindResource(test::ParseNameOrDie("attr/foo")); |
| 728 | ASSERT_TRUE(result); |
Adam Lesinski | 27afb9e | 2015-11-06 18:25:04 -0800 | [diff] [blame] | 729 | |
Adam Lesinski | a45893a | 2017-05-30 15:19:02 -0700 | [diff] [blame] | 730 | ASSERT_TRUE(result.value().package->id); |
| 731 | ASSERT_TRUE(result.value().type->id); |
| 732 | ASSERT_TRUE(result.value().entry->id); |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 733 | ResourceId actual_id(result.value().package->id.value(), |
| 734 | result.value().type->id.value(), |
| 735 | result.value().entry->id.value()); |
Adam Lesinski | a45893a | 2017-05-30 15:19:02 -0700 | [diff] [blame] | 736 | EXPECT_THAT(actual_id, Eq(ResourceId(0x01010040))); |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 737 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 738 | result = table_.FindResource(test::ParseNameOrDie("attr/bar")); |
Adam Lesinski | a45893a | 2017-05-30 15:19:02 -0700 | [diff] [blame] | 739 | ASSERT_TRUE(result); |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 740 | |
Adam Lesinski | a45893a | 2017-05-30 15:19:02 -0700 | [diff] [blame] | 741 | ASSERT_TRUE(result.value().package->id); |
| 742 | ASSERT_TRUE(result.value().type->id); |
| 743 | ASSERT_TRUE(result.value().entry->id); |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 744 | actual_id = ResourceId(result.value().package->id.value(), |
| 745 | result.value().type->id.value(), |
| 746 | result.value().entry->id.value()); |
Adam Lesinski | a45893a | 2017-05-30 15:19:02 -0700 | [diff] [blame] | 747 | EXPECT_THAT(actual_id, Eq(ResourceId(0x01010041))); |
Adam Lesinski | 27afb9e | 2015-11-06 18:25:04 -0800 | [diff] [blame] | 748 | } |
| 749 | |
Adam Lesinski | 71be705 | 2017-12-12 16:48:07 -0800 | [diff] [blame] | 750 | TEST_F(ResourceParserTest, StrongestSymbolVisibilityWins) { |
| 751 | std::string input = R"( |
| 752 | <!-- private --> |
| 753 | <java-symbol type="string" name="foo" /> |
| 754 | <!-- public --> |
| 755 | <public type="string" name="foo" id="0x01020000" /> |
| 756 | <!-- private2 --> |
| 757 | <java-symbol type="string" name="foo" />)"; |
| 758 | ASSERT_TRUE(TestParse(input)); |
| 759 | |
| 760 | Maybe<ResourceTable::SearchResult> result = |
| 761 | table_.FindResource(test::ParseNameOrDie("string/foo")); |
| 762 | ASSERT_TRUE(result); |
| 763 | |
| 764 | ResourceEntry* entry = result.value().entry; |
| 765 | ASSERT_THAT(entry, NotNull()); |
| 766 | EXPECT_THAT(entry->visibility.level, Eq(Visibility::Level::kPublic)); |
| 767 | EXPECT_THAT(entry->visibility.comment, StrEq("public")); |
| 768 | } |
| 769 | |
Adam Lesinski | fa10505 | 2015-11-07 13:34:39 -0800 | [diff] [blame] | 770 | TEST_F(ResourceParserTest, ExternalTypesShouldOnlyBeReferences) { |
Adam Lesinski | a45893a | 2017-05-30 15:19:02 -0700 | [diff] [blame] | 771 | ASSERT_TRUE(TestParse(R"(<item type="layout" name="foo">@layout/bar</item>)")); |
| 772 | ASSERT_FALSE(TestParse(R"(<item type="layout" name="bar">"this is a string"</item>)")); |
Adam Lesinski | fa10505 | 2015-11-07 13:34:39 -0800 | [diff] [blame] | 773 | } |
| 774 | |
Adam Lesinski | 4488f1c | 2017-05-26 17:33:38 -0700 | [diff] [blame] | 775 | TEST_F(ResourceParserTest, AddResourcesElementShouldAddEntryWithUndefinedSymbol) { |
Adam Lesinski | a45893a | 2017-05-30 15:19:02 -0700 | [diff] [blame] | 776 | ASSERT_TRUE(TestParse(R"(<add-resource name="bar" type="string" />)")); |
Adam Lesinski | a6fe345 | 2015-12-09 15:20:52 -0800 | [diff] [blame] | 777 | |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 778 | Maybe<ResourceTable::SearchResult> result = |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 779 | table_.FindResource(test::ParseNameOrDie("string/bar")); |
Adam Lesinski | a45893a | 2017-05-30 15:19:02 -0700 | [diff] [blame] | 780 | ASSERT_TRUE(result); |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 781 | const ResourceEntry* entry = result.value().entry; |
Adam Lesinski | a45893a | 2017-05-30 15:19:02 -0700 | [diff] [blame] | 782 | ASSERT_THAT(entry, NotNull()); |
Adam Lesinski | 71be705 | 2017-12-12 16:48:07 -0800 | [diff] [blame] | 783 | EXPECT_THAT(entry->visibility.level, Eq(Visibility::Level::kUndefined)); |
| 784 | EXPECT_TRUE(entry->allow_new); |
Adam Lesinski | a6fe345 | 2015-12-09 15:20:52 -0800 | [diff] [blame] | 785 | } |
| 786 | |
Adam Lesinski | 7ff3ee1 | 2015-12-14 16:08:50 -0800 | [diff] [blame] | 787 | TEST_F(ResourceParserTest, ParseItemElementWithFormat) { |
Adam Lesinski | a45893a | 2017-05-30 15:19:02 -0700 | [diff] [blame] | 788 | ASSERT_TRUE(TestParse(R"(<item name="foo" type="integer" format="float">0.3</item>)")); |
Adam Lesinski | 7ff3ee1 | 2015-12-14 16:08:50 -0800 | [diff] [blame] | 789 | |
Adam Lesinski | e597d68 | 2017-06-01 17:16:44 -0700 | [diff] [blame] | 790 | BinaryPrimitive* val = test::GetValue<BinaryPrimitive>(&table_, "integer/foo"); |
| 791 | ASSERT_THAT(val, NotNull()); |
Adam Lesinski | a45893a | 2017-05-30 15:19:02 -0700 | [diff] [blame] | 792 | EXPECT_THAT(val->value.dataType, Eq(Res_value::TYPE_FLOAT)); |
Adam Lesinski | 7ff3ee1 | 2015-12-14 16:08:50 -0800 | [diff] [blame] | 793 | |
Adam Lesinski | a45893a | 2017-05-30 15:19:02 -0700 | [diff] [blame] | 794 | ASSERT_FALSE(TestParse(R"(<item name="bar" type="integer" format="fraction">100</item>)")); |
Adam Lesinski | e597d68 | 2017-06-01 17:16:44 -0700 | [diff] [blame] | 795 | } |
| 796 | |
| 797 | // An <item> without a format specifier accepts all types of values. |
| 798 | TEST_F(ResourceParserTest, ParseItemElementWithoutFormat) { |
Adam Lesinski | a45893a | 2017-05-30 15:19:02 -0700 | [diff] [blame] | 799 | ASSERT_TRUE(TestParse(R"(<item name="foo" type="integer">100%p</item>)")); |
Adam Lesinski | e597d68 | 2017-06-01 17:16:44 -0700 | [diff] [blame] | 800 | |
| 801 | BinaryPrimitive* val = test::GetValue<BinaryPrimitive>(&table_, "integer/foo"); |
| 802 | ASSERT_THAT(val, NotNull()); |
Adam Lesinski | a45893a | 2017-05-30 15:19:02 -0700 | [diff] [blame] | 803 | EXPECT_THAT(val->value.dataType, Eq(Res_value::TYPE_FRACTION)); |
Adam Lesinski | 7ff3ee1 | 2015-12-14 16:08:50 -0800 | [diff] [blame] | 804 | } |
| 805 | |
Adam Lesinski | 86d67df | 2017-01-31 13:47:27 -0800 | [diff] [blame] | 806 | TEST_F(ResourceParserTest, ParseConfigVaryingItem) { |
Adam Lesinski | a45893a | 2017-05-30 15:19:02 -0700 | [diff] [blame] | 807 | ASSERT_TRUE(TestParse(R"(<item name="foo" type="configVarying">Hey</item>)")); |
| 808 | ASSERT_THAT(test::GetValue<String>(&table_, "configVarying/foo"), NotNull()); |
Adam Lesinski | 86d67df | 2017-01-31 13:47:27 -0800 | [diff] [blame] | 809 | } |
| 810 | |
| 811 | TEST_F(ResourceParserTest, ParseBagElement) { |
Adam Lesinski | a45893a | 2017-05-30 15:19:02 -0700 | [diff] [blame] | 812 | std::string input = R"( |
| 813 | <bag name="bag" type="configVarying"> |
| 814 | <item name="test">Hello!</item> |
| 815 | </bag>)"; |
Adam Lesinski | 86d67df | 2017-01-31 13:47:27 -0800 | [diff] [blame] | 816 | ASSERT_TRUE(TestParse(input)); |
| 817 | |
| 818 | Style* val = test::GetValue<Style>(&table_, "configVarying/bag"); |
Adam Lesinski | a45893a | 2017-05-30 15:19:02 -0700 | [diff] [blame] | 819 | ASSERT_THAT(val, NotNull()); |
| 820 | ASSERT_THAT(val->entries, SizeIs(1)); |
Adam Lesinski | 86d67df | 2017-01-31 13:47:27 -0800 | [diff] [blame] | 821 | |
Adam Lesinski | a45893a | 2017-05-30 15:19:02 -0700 | [diff] [blame] | 822 | EXPECT_THAT(val->entries[0].key, Eq(Reference(test::ParseNameOrDie("attr/test")))); |
| 823 | EXPECT_THAT(ValueCast<RawString>(val->entries[0].value.get()), NotNull()); |
Adam Lesinski | 86d67df | 2017-01-31 13:47:27 -0800 | [diff] [blame] | 824 | } |
| 825 | |
Adam Lesinski | bab4ef5 | 2017-06-01 15:22:57 -0700 | [diff] [blame] | 826 | TEST_F(ResourceParserTest, ParseElementWithNoValue) { |
| 827 | std::string input = R"( |
| 828 | <item type="drawable" format="reference" name="foo" /> |
| 829 | <string name="foo" />)"; |
| 830 | ASSERT_TRUE(TestParse(input)); |
| 831 | ASSERT_THAT(test::GetValue(&table_, "drawable/foo"), Pointee(ValueEq(Reference()))); |
| 832 | |
| 833 | String* str = test::GetValue<String>(&table_, "string/foo"); |
| 834 | ASSERT_THAT(str, NotNull()); |
Adam Lesinski | a45893a | 2017-05-30 15:19:02 -0700 | [diff] [blame] | 835 | EXPECT_THAT(*str, StrValueEq("")); |
Adam Lesinski | bab4ef5 | 2017-06-01 15:22:57 -0700 | [diff] [blame] | 836 | } |
| 837 | |
Adam Lesinski | b9f0548 | 2017-06-02 16:32:37 -0700 | [diff] [blame] | 838 | TEST_F(ResourceParserTest, ParsePlatformIndependentNewline) { |
Adam Lesinski | a45893a | 2017-05-30 15:19:02 -0700 | [diff] [blame] | 839 | ASSERT_TRUE(TestParse(R"(<string name="foo">%1$s %n %2$s</string>)")); |
Adam Lesinski | b9f0548 | 2017-06-02 16:32:37 -0700 | [diff] [blame] | 840 | } |
| 841 | |
Adam Lesinski | 46c4d72 | 2017-08-23 13:03:56 -0700 | [diff] [blame] | 842 | TEST_F(ResourceParserTest, ParseOverlayableTagWithSystemPolicy) { |
| 843 | std::string input = R"( |
| 844 | <overlayable policy="illegal_policy"> |
| 845 | <item type="string" name="foo" /> |
| 846 | </overlayable>)"; |
| 847 | EXPECT_FALSE(TestParse(input)); |
| 848 | |
| 849 | input = R"( |
| 850 | <overlayable policy="system"> |
| 851 | <item name="foo" /> |
| 852 | </overlayable>)"; |
| 853 | EXPECT_FALSE(TestParse(input)); |
| 854 | |
| 855 | input = R"( |
| 856 | <overlayable policy="system"> |
| 857 | <item type="attr" /> |
| 858 | </overlayable>)"; |
| 859 | EXPECT_FALSE(TestParse(input)); |
| 860 | |
| 861 | input = R"( |
| 862 | <overlayable policy="system"> |
| 863 | <item type="bad_type" name="foo" /> |
| 864 | </overlayable>)"; |
| 865 | EXPECT_FALSE(TestParse(input)); |
| 866 | |
| 867 | input = R"(<overlayable policy="system" />)"; |
| 868 | EXPECT_TRUE(TestParse(input)); |
| 869 | |
| 870 | input = R"(<overlayable />)"; |
| 871 | EXPECT_TRUE(TestParse(input)); |
| 872 | |
| 873 | input = R"( |
| 874 | <overlayable policy="system"> |
| 875 | <item type="string" name="foo" /> |
| 876 | <item type="dimen" name="foo" /> |
| 877 | </overlayable>)"; |
| 878 | ASSERT_TRUE(TestParse(input)); |
| 879 | |
| 880 | input = R"( |
| 881 | <overlayable> |
| 882 | <item type="string" name="bar" /> |
| 883 | </overlayable>)"; |
| 884 | ASSERT_TRUE(TestParse(input)); |
Adam Lesinski | 71be705 | 2017-12-12 16:48:07 -0800 | [diff] [blame] | 885 | |
| 886 | Maybe<ResourceTable::SearchResult> search_result = |
| 887 | table_.FindResource(test::ParseNameOrDie("string/bar")); |
| 888 | ASSERT_TRUE(search_result); |
| 889 | ASSERT_THAT(search_result.value().entry, NotNull()); |
| 890 | EXPECT_THAT(search_result.value().entry->visibility.level, Eq(Visibility::Level::kUndefined)); |
| 891 | EXPECT_TRUE(search_result.value().entry->overlayable); |
| 892 | } |
| 893 | |
| 894 | TEST_F(ResourceParserTest, DuplicateOverlayableIsError) { |
| 895 | std::string input = R"( |
| 896 | <overlayable> |
| 897 | <item type="string" name="foo" /> |
| 898 | <item type="string" name="foo" /> |
| 899 | </overlayable>)"; |
| 900 | EXPECT_FALSE(TestParse(input)); |
Adam Lesinski | 46c4d72 | 2017-08-23 13:03:56 -0700 | [diff] [blame] | 901 | } |
| 902 | |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 903 | } // namespace aapt |