blob: ddf5b9a22c2f82afa324be3a028f8a35892e1e9c [file] [log] [blame]
Adam Lesinski1ab598f2015-08-14 14:26:04 -07001/*
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 "link/Linkers.h"
Adam Lesinskice5e56e2016-10-21 17:56:45 -070018
Adam Lesinski64587af2016-02-18 18:33:06 -080019#include "test/Test.h"
Adam Lesinski1ab598f2015-08-14 14:26:04 -070020
Adam Lesinskia45893a2017-05-30 15:19:02 -070021using ::testing::IsNull;
22using ::testing::NotNull;
23
Adam Lesinski1ab598f2015-08-14 14:26:04 -070024namespace aapt {
25
26class XmlReferenceLinkerTest : public ::testing::Test {
Adam Lesinskicacb28f2016-10-19 12:18:14 -070027 public:
28 void SetUp() override {
Adam Lesinski38665542016-12-28 12:25:46 -050029 context_ = test::ContextBuilder()
30 .SetCompilationPackage("com.app.test")
31 .SetNameManglerPolicy(NameManglerPolicy{"com.app.test", {"com.android.support"}})
32 .AddSymbolSource(
33 test::StaticSymbolSourceBuilder()
34 .AddPublicSymbol("android:attr/layout_width", ResourceId(0x01010000),
35 test::AttributeBuilder()
36 .SetTypeMask(android::ResTable_map::TYPE_ENUM |
37 android::ResTable_map::TYPE_DIMENSION)
38 .AddItem("match_parent", 0xffffffff)
39 .Build())
40 .AddPublicSymbol("android:attr/background", ResourceId(0x01010001),
41 test::AttributeBuilder()
42 .SetTypeMask(android::ResTable_map::TYPE_COLOR)
43 .Build())
44 .AddPublicSymbol("android:attr/attr", ResourceId(0x01010002),
45 test::AttributeBuilder().Build())
46 .AddPublicSymbol("android:attr/text", ResourceId(0x01010003),
47 test::AttributeBuilder()
48 .SetTypeMask(android::ResTable_map::TYPE_STRING)
49 .Build())
Ryan Mitchell4d5833e2019-09-04 02:46:03 -070050 .AddPublicSymbol("android:attr/angle", ResourceId(0x01010004),
51 test::AttributeBuilder().Build())
Adam Lesinski1ab598f2015-08-14 14:26:04 -070052
Adam Lesinski38665542016-12-28 12:25:46 -050053 // Add one real symbol that was introduces in v21
54 .AddPublicSymbol("android:attr/colorAccent", ResourceId(0x01010435),
55 test::AttributeBuilder().Build())
Adam Lesinski1ab598f2015-08-14 14:26:04 -070056
Adam Lesinski38665542016-12-28 12:25:46 -050057 // Private symbol.
58 .AddSymbol("android:color/hidden", ResourceId(0x01020001))
Adam Lesinski467f1712015-11-16 17:35:44 -080059
Adam Lesinski38665542016-12-28 12:25:46 -050060 .AddPublicSymbol("android:id/id", ResourceId(0x01030000))
61 .AddSymbol("com.app.test:id/id", ResourceId(0x7f030000))
62 .AddSymbol("com.app.test:color/green", ResourceId(0x7f020000))
63 .AddSymbol("com.app.test:color/red", ResourceId(0x7f020001))
64 .AddSymbol("com.app.test:attr/colorAccent", ResourceId(0x7f010000),
65 test::AttributeBuilder()
66 .SetTypeMask(android::ResTable_map::TYPE_COLOR)
67 .Build())
68 .AddPublicSymbol("com.app.test:attr/com.android.support$colorAccent",
69 ResourceId(0x7f010001),
70 test::AttributeBuilder()
71 .SetTypeMask(android::ResTable_map::TYPE_COLOR)
72 .Build())
73 .AddPublicSymbol("com.app.test:attr/attr", ResourceId(0x7f010002),
74 test::AttributeBuilder().Build())
75 .Build())
76 .Build();
Adam Lesinskicacb28f2016-10-19 12:18:14 -070077 }
Adam Lesinski1ab598f2015-08-14 14:26:04 -070078
Adam Lesinskicacb28f2016-10-19 12:18:14 -070079 protected:
Ryan Mitchell4d5833e2019-09-04 02:46:03 -070080 std::unique_ptr<test::Context> context_;
Adam Lesinski1ab598f2015-08-14 14:26:04 -070081};
82
Adam Lesinski1ab598f2015-08-14 14:26:04 -070083TEST_F(XmlReferenceLinkerTest, LinkBasicAttributes) {
Adam Lesinski6b372992017-08-09 10:54:23 -070084 std::unique_ptr<xml::XmlResource> doc = test::BuildXmlDomForPackageName(context_.get(), R"(
85 <View xmlns:android="http://schemas.android.com/apk/res/android"
86 android:layout_width="match_parent"
87 android:background="@color/green"
88 android:text="hello"
89 android:attr="\?hello"
90 nonAaptAttr="1"
91 nonAaptAttrRef="@id/id"
92 class="hello" />)");
Adam Lesinski1ab598f2015-08-14 14:26:04 -070093
Ryan Mitchell326e35ff2021-04-12 07:50:42 -070094 XmlReferenceLinker linker(nullptr);
Adam Lesinskice5e56e2016-10-21 17:56:45 -070095 ASSERT_TRUE(linker.Consume(context_.get(), doc.get()));
Adam Lesinski1ab598f2015-08-14 14:26:04 -070096
Adam Lesinski6b372992017-08-09 10:54:23 -070097 xml::Element* view_el = doc->root.get();
Adam Lesinskia45893a2017-05-30 15:19:02 -070098 ASSERT_THAT(view_el, NotNull());
Adam Lesinski1ab598f2015-08-14 14:26:04 -070099
Adam Lesinski38665542016-12-28 12:25:46 -0500100 xml::Attribute* xml_attr = view_el->FindAttribute(xml::kSchemaAndroid, "layout_width");
Adam Lesinskia45893a2017-05-30 15:19:02 -0700101 ASSERT_THAT(xml_attr, NotNull());
102 ASSERT_TRUE(xml_attr->compiled_attribute);
103 EXPECT_EQ(make_value(ResourceId(0x01010000)), xml_attr->compiled_attribute.value().id);
104 EXPECT_THAT(ValueCast<BinaryPrimitive>(xml_attr->compiled_value.get()), NotNull());
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700105
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700106 xml_attr = view_el->FindAttribute(xml::kSchemaAndroid, "background");
Adam Lesinskia45893a2017-05-30 15:19:02 -0700107 ASSERT_THAT(xml_attr, NotNull());
108 ASSERT_TRUE(xml_attr->compiled_attribute);
109 EXPECT_EQ(make_value(ResourceId(0x01010001)), xml_attr->compiled_attribute.value().id);
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700110 Reference* ref = ValueCast<Reference>(xml_attr->compiled_value.get());
Adam Lesinskia45893a2017-05-30 15:19:02 -0700111 ASSERT_THAT(ref, NotNull());
112 EXPECT_EQ(make_value(test::ParseNameOrDie("color/green")), ref->name); // Make sure the name
113 // didn't change.
114 EXPECT_EQ(make_value(ResourceId(0x7f020000)), ref->id);
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700115
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700116 xml_attr = view_el->FindAttribute(xml::kSchemaAndroid, "text");
Adam Lesinskia45893a2017-05-30 15:19:02 -0700117 ASSERT_THAT(xml_attr, NotNull());
118 EXPECT_TRUE(xml_attr->compiled_attribute);
119 EXPECT_THAT(xml_attr->compiled_value, IsNull()); // Strings don't get compiled for memory sake.
Adam Lesinski38665542016-12-28 12:25:46 -0500120
Adam Lesinski48448e82017-04-26 15:13:52 -0700121 xml_attr = view_el->FindAttribute(xml::kSchemaAndroid, "attr");
Adam Lesinskia45893a2017-05-30 15:19:02 -0700122 ASSERT_THAT(xml_attr, NotNull());
123 EXPECT_TRUE(xml_attr->compiled_attribute);
124 EXPECT_THAT(xml_attr->compiled_value, IsNull()); // Should be a plain string.
Adam Lesinski48448e82017-04-26 15:13:52 -0700125
Adam Lesinski38665542016-12-28 12:25:46 -0500126 xml_attr = view_el->FindAttribute("", "nonAaptAttr");
Adam Lesinskia45893a2017-05-30 15:19:02 -0700127 ASSERT_THAT(xml_attr, NotNull());
128 EXPECT_FALSE(xml_attr->compiled_attribute);
129 EXPECT_THAT(ValueCast<BinaryPrimitive>(xml_attr->compiled_value.get()), NotNull());
Adam Lesinski38665542016-12-28 12:25:46 -0500130
131 xml_attr = view_el->FindAttribute("", "nonAaptAttrRef");
Adam Lesinskia45893a2017-05-30 15:19:02 -0700132 ASSERT_THAT(xml_attr, NotNull());
133 EXPECT_FALSE(xml_attr->compiled_attribute);
134 EXPECT_THAT(ValueCast<Reference>(xml_attr->compiled_value.get()), NotNull());
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700135
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700136 xml_attr = view_el->FindAttribute("", "class");
Adam Lesinskia45893a2017-05-30 15:19:02 -0700137 ASSERT_THAT(xml_attr, NotNull());
138 EXPECT_FALSE(xml_attr->compiled_attribute);
139 EXPECT_THAT(xml_attr->compiled_value, IsNull());
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700140}
141
Adam Lesinski467f1712015-11-16 17:35:44 -0800142TEST_F(XmlReferenceLinkerTest, PrivateSymbolsAreNotLinked) {
Adam Lesinski6b372992017-08-09 10:54:23 -0700143 std::unique_ptr<xml::XmlResource> doc = test::BuildXmlDomForPackageName(context_.get(), R"(
144 <View xmlns:android="http://schemas.android.com/apk/res/android"
145 android:colorAccent="@android:color/hidden" />)");
Adam Lesinski467f1712015-11-16 17:35:44 -0800146
Ryan Mitchell326e35ff2021-04-12 07:50:42 -0700147 XmlReferenceLinker linker(nullptr);
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700148 ASSERT_FALSE(linker.Consume(context_.get(), doc.get()));
Adam Lesinski467f1712015-11-16 17:35:44 -0800149}
150
Adam Lesinski38665542016-12-28 12:25:46 -0500151TEST_F(XmlReferenceLinkerTest, PrivateSymbolsAreLinkedWhenReferenceHasStarPrefix) {
Adam Lesinski6b372992017-08-09 10:54:23 -0700152 std::unique_ptr<xml::XmlResource> doc = test::BuildXmlDomForPackageName(context_.get(), R"(
Adam Lesinski467f1712015-11-16 17:35:44 -0800153 <View xmlns:android="http://schemas.android.com/apk/res/android"
Adam Lesinski6b372992017-08-09 10:54:23 -0700154 android:colorAccent="@*android:color/hidden" />)");
Adam Lesinski467f1712015-11-16 17:35:44 -0800155
Ryan Mitchell326e35ff2021-04-12 07:50:42 -0700156 XmlReferenceLinker linker(nullptr);
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700157 ASSERT_TRUE(linker.Consume(context_.get(), doc.get()));
Adam Lesinski467f1712015-11-16 17:35:44 -0800158}
159
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700160TEST_F(XmlReferenceLinkerTest, LinkMangledAttributes) {
Adam Lesinski6b372992017-08-09 10:54:23 -0700161 std::unique_ptr<xml::XmlResource> doc = test::BuildXmlDomForPackageName(context_.get(), R"(
162 <View xmlns:support="http://schemas.android.com/apk/res/com.android.support"
163 support:colorAccent="#ff0000" />)");
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700164
Ryan Mitchell326e35ff2021-04-12 07:50:42 -0700165 XmlReferenceLinker linker(nullptr);
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700166 ASSERT_TRUE(linker.Consume(context_.get(), doc.get()));
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700167
Adam Lesinski6b372992017-08-09 10:54:23 -0700168 xml::Element* view_el = doc->root.get();
Adam Lesinskia45893a2017-05-30 15:19:02 -0700169 ASSERT_THAT(view_el, NotNull());
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700170
Adam Lesinski38665542016-12-28 12:25:46 -0500171 xml::Attribute* xml_attr =
172 view_el->FindAttribute(xml::BuildPackageNamespace("com.android.support"), "colorAccent");
Adam Lesinskia45893a2017-05-30 15:19:02 -0700173 ASSERT_THAT(xml_attr, NotNull());
174 ASSERT_TRUE(xml_attr->compiled_attribute);
175 EXPECT_EQ(make_value(ResourceId(0x7f010001)), xml_attr->compiled_attribute.value().id);
176 EXPECT_THAT(ValueCast<BinaryPrimitive>(xml_attr->compiled_value.get()), NotNull());
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700177}
178
179TEST_F(XmlReferenceLinkerTest, LinkAutoResReference) {
Adam Lesinski6b372992017-08-09 10:54:23 -0700180 std::unique_ptr<xml::XmlResource> doc = test::BuildXmlDomForPackageName(context_.get(), R"(
181 <View xmlns:app="http://schemas.android.com/apk/res-auto"
182 app:colorAccent="@app:color/red" />)");
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700183
Ryan Mitchell326e35ff2021-04-12 07:50:42 -0700184 XmlReferenceLinker linker(nullptr);
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700185 ASSERT_TRUE(linker.Consume(context_.get(), doc.get()));
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700186
Adam Lesinski6b372992017-08-09 10:54:23 -0700187 xml::Element* view_el = doc->root.get();
Adam Lesinskia45893a2017-05-30 15:19:02 -0700188 ASSERT_THAT(view_el, NotNull());
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700189
Adam Lesinski38665542016-12-28 12:25:46 -0500190 xml::Attribute* xml_attr = view_el->FindAttribute(xml::kSchemaAuto, "colorAccent");
Adam Lesinskia45893a2017-05-30 15:19:02 -0700191 ASSERT_THAT(xml_attr, NotNull());
192 ASSERT_TRUE(xml_attr->compiled_attribute);
193 EXPECT_EQ(make_value(ResourceId(0x7f010000)), xml_attr->compiled_attribute.value().id);
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700194 Reference* ref = ValueCast<Reference>(xml_attr->compiled_value.get());
Adam Lesinskia45893a2017-05-30 15:19:02 -0700195 ASSERT_THAT(ref, NotNull());
196 ASSERT_TRUE(ref->name);
197 EXPECT_EQ(make_value(ResourceId(0x7f020001)), ref->id);
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700198}
199
200TEST_F(XmlReferenceLinkerTest, LinkViewWithShadowedPackageAlias) {
Adam Lesinski6b372992017-08-09 10:54:23 -0700201 std::unique_ptr<xml::XmlResource> doc = test::BuildXmlDomForPackageName(context_.get(), R"(
202 <View xmlns:app="http://schemas.android.com/apk/res/android" app:attr="@app:id/id">
203 <View xmlns:app="http://schemas.android.com/apk/res/com.app.test" app:attr="@app:id/id"/>
204 </View>)");
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700205
Ryan Mitchell326e35ff2021-04-12 07:50:42 -0700206 XmlReferenceLinker linker(nullptr);
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700207 ASSERT_TRUE(linker.Consume(context_.get(), doc.get()));
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700208
Adam Lesinski6b372992017-08-09 10:54:23 -0700209 xml::Element* view_el = doc->root.get();
Adam Lesinskia45893a2017-05-30 15:19:02 -0700210 ASSERT_THAT(view_el, NotNull());
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700211
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700212 // All attributes and references in this element should be referring to
213 // "android" (0x01).
Adam Lesinski38665542016-12-28 12:25:46 -0500214 xml::Attribute* xml_attr = view_el->FindAttribute(xml::kSchemaAndroid, "attr");
Adam Lesinskia45893a2017-05-30 15:19:02 -0700215 ASSERT_THAT(xml_attr, NotNull());
216 ASSERT_TRUE(xml_attr->compiled_attribute);
217 EXPECT_EQ(make_value(ResourceId(0x01010002)), xml_attr->compiled_attribute.value().id);
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700218 Reference* ref = ValueCast<Reference>(xml_attr->compiled_value.get());
Adam Lesinskia45893a2017-05-30 15:19:02 -0700219 ASSERT_THAT(ref, NotNull());
220 EXPECT_EQ(make_value(ResourceId(0x01030000)), ref->id);
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700221
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700222 ASSERT_FALSE(view_el->GetChildElements().empty());
223 view_el = view_el->GetChildElements().front();
Adam Lesinskia45893a2017-05-30 15:19:02 -0700224 ASSERT_THAT(view_el, NotNull());
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700225
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700226 // All attributes and references in this element should be referring to
227 // "com.app.test" (0x7f).
Adam Lesinski38665542016-12-28 12:25:46 -0500228 xml_attr = view_el->FindAttribute(xml::BuildPackageNamespace("com.app.test"), "attr");
Adam Lesinskia45893a2017-05-30 15:19:02 -0700229 ASSERT_THAT(xml_attr, NotNull());
230 ASSERT_TRUE(xml_attr->compiled_attribute);
231 EXPECT_EQ(make_value(ResourceId(0x7f010002)), xml_attr->compiled_attribute.value().id);
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700232 ref = ValueCast<Reference>(xml_attr->compiled_value.get());
Adam Lesinskia45893a2017-05-30 15:19:02 -0700233 ASSERT_THAT(ref, NotNull());
234 EXPECT_EQ(make_value(ResourceId(0x7f030000)), ref->id);
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700235}
236
237TEST_F(XmlReferenceLinkerTest, LinkViewWithLocalPackageAndAliasOfTheSameName) {
Adam Lesinski6b372992017-08-09 10:54:23 -0700238 std::unique_ptr<xml::XmlResource> doc = test::BuildXmlDomForPackageName(context_.get(), R"(
239 <View xmlns:android="http://schemas.android.com/apk/res/com.app.test"
240 android:attr="@id/id"/>)");
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700241
Ryan Mitchell326e35ff2021-04-12 07:50:42 -0700242 XmlReferenceLinker linker(nullptr);
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700243 ASSERT_TRUE(linker.Consume(context_.get(), doc.get()));
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700244
Adam Lesinski6b372992017-08-09 10:54:23 -0700245 xml::Element* view_el = doc->root.get();
Adam Lesinskia45893a2017-05-30 15:19:02 -0700246 ASSERT_THAT(view_el, NotNull());
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700247
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700248 // All attributes and references in this element should be referring to
249 // "com.app.test" (0x7f).
Adam Lesinskia45893a2017-05-30 15:19:02 -0700250 xml::Attribute* xml_attr = view_el->FindAttribute(xml::BuildPackageNamespace("com.app.test"), "attr");
251 ASSERT_THAT(xml_attr, NotNull());
252 ASSERT_TRUE(xml_attr->compiled_attribute);
253 EXPECT_EQ(make_value(ResourceId(0x7f010002)), xml_attr->compiled_attribute.value().id);
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700254 Reference* ref = ValueCast<Reference>(xml_attr->compiled_value.get());
Adam Lesinskia45893a2017-05-30 15:19:02 -0700255 ASSERT_THAT(ref, NotNull());
256 EXPECT_EQ(make_value(ResourceId(0x7f030000)), ref->id);
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700257}
258
Ryan Mitchell4d5833e2019-09-04 02:46:03 -0700259
260TEST_F(XmlReferenceLinkerTest, AddAngleOnGradientForAndroidQ) {
261 std::unique_ptr<xml::XmlResource> doc = test::BuildXmlDomForPackageName(context_.get(), R"(
262 <gradient />)");
263
Ryan Mitchell326e35ff2021-04-12 07:50:42 -0700264 XmlReferenceLinker linker(nullptr);
Ryan Mitchell4d5833e2019-09-04 02:46:03 -0700265 ASSERT_TRUE(linker.Consume(context_.get(), doc.get()));
266
267 xml::Element* gradient_el = doc->root.get();
268 ASSERT_THAT(gradient_el, NotNull());
269
270 xml::Attribute* xml_attr = gradient_el->FindAttribute(xml::kSchemaAndroid, "angle");
271 ASSERT_THAT(xml_attr, NotNull());
272 ASSERT_TRUE(xml_attr->compiled_attribute);
273 EXPECT_EQ(make_value(ResourceId(0x01010004)), xml_attr->compiled_attribute.value().id);
274
275 BinaryPrimitive* value = ValueCast<BinaryPrimitive>(xml_attr->compiled_value.get());
276 ASSERT_THAT(value, NotNull());
277 EXPECT_EQ(value->value.dataType, android::Res_value::TYPE_INT_DEC);
278 EXPECT_EQ(value->value.data, 0U);
279}
280
281TEST_F(XmlReferenceLinkerTest, DoNotOverwriteAngleOnGradientForAndroidQ) {
282 std::unique_ptr<xml::XmlResource> doc = test::BuildXmlDomForPackageName(context_.get(), R"(
283 <gradient xmlns:android="http://schemas.android.com/apk/res/android"
284 android:angle="90"/>)");
285
Ryan Mitchell326e35ff2021-04-12 07:50:42 -0700286 XmlReferenceLinker linker(nullptr);
Ryan Mitchell4d5833e2019-09-04 02:46:03 -0700287 ASSERT_TRUE(linker.Consume(context_.get(), doc.get()));
288
289 xml::Element* gradient_el = doc->root.get();
290 ASSERT_THAT(gradient_el, NotNull());
291
292 xml::Attribute* xml_attr = gradient_el->FindAttribute(xml::kSchemaAndroid, "angle");
293 ASSERT_THAT(xml_attr, NotNull());
294 ASSERT_TRUE(xml_attr->compiled_attribute);
295 EXPECT_EQ(make_value(ResourceId(0x01010004)), xml_attr->compiled_attribute.value().id);
296
297 BinaryPrimitive* value = ValueCast<BinaryPrimitive>(xml_attr->compiled_value.get());
298 ASSERT_THAT(value, NotNull());
299 EXPECT_EQ(value->value.dataType, android::Res_value::TYPE_INT_DEC);
300 EXPECT_EQ(value->value.data, 90U);
301}
302
303TEST_F(XmlReferenceLinkerTest, DoNotOverwriteAngleOnGradientForPostAndroidQ) {
304 std::unique_ptr<xml::XmlResource> doc = test::BuildXmlDomForPackageName(context_.get(), R"(
305 <gradient xmlns:android="http://schemas.android.com/apk/res/android" />)");
306 context_->SetMinSdkVersion(30);
307
Ryan Mitchell326e35ff2021-04-12 07:50:42 -0700308 XmlReferenceLinker linker(nullptr);
Ryan Mitchell4d5833e2019-09-04 02:46:03 -0700309 ASSERT_TRUE(linker.Consume(context_.get(), doc.get()));
310
311 xml::Element* gradient_el = doc->root.get();
312 ASSERT_THAT(gradient_el, NotNull());
313
314 xml::Attribute* xml_attr = gradient_el->FindAttribute(xml::kSchemaAndroid, "angle");
315 ASSERT_THAT(xml_attr, IsNull());
316}
317
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700318} // namespace aapt