| Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [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 "link/Linkers.h" |
| Adam Lesinski | 64587af | 2016-02-18 18:33:06 -0800 | [diff] [blame] | 18 | #include "test/Test.h" |
| Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 19 | |
| 20 | namespace aapt { |
| 21 | |
| 22 | class XmlReferenceLinkerTest : public ::testing::Test { |
| 23 | public: |
| 24 | void SetUp() override { |
| 25 | mContext = test::ContextBuilder() |
| Adam Lesinski | d0f116b | 2016-07-08 15:00:32 -0700 | [diff] [blame] | 26 | .setCompilationPackage("com.app.test") |
| Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 27 | .setNameManglerPolicy( |
| Adam Lesinski | d0f116b | 2016-07-08 15:00:32 -0700 | [diff] [blame] | 28 | NameManglerPolicy{ "com.app.test", { "com.android.support" } }) |
| Adam Lesinski | 64587af | 2016-02-18 18:33:06 -0800 | [diff] [blame] | 29 | .addSymbolSource(test::StaticSymbolSourceBuilder() |
| Adam Lesinski | 58a20a6 | 2016-07-25 17:56:58 -0700 | [diff] [blame] | 30 | .addPublicSymbol("android:attr/layout_width", ResourceId(0x01010000), |
| Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 31 | test::AttributeBuilder() |
| 32 | .setTypeMask(android::ResTable_map::TYPE_ENUM | |
| 33 | android::ResTable_map::TYPE_DIMENSION) |
| Adam Lesinski | d0f116b | 2016-07-08 15:00:32 -0700 | [diff] [blame] | 34 | .addItem("match_parent", 0xffffffff) |
| Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 35 | .build()) |
| Adam Lesinski | 58a20a6 | 2016-07-25 17:56:58 -0700 | [diff] [blame] | 36 | .addPublicSymbol("android:attr/background", ResourceId(0x01010001), |
| Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 37 | test::AttributeBuilder() |
| 38 | .setTypeMask(android::ResTable_map::TYPE_COLOR).build()) |
| Adam Lesinski | 58a20a6 | 2016-07-25 17:56:58 -0700 | [diff] [blame] | 39 | .addPublicSymbol("android:attr/attr", ResourceId(0x01010002), |
| Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 40 | test::AttributeBuilder().build()) |
| Adam Lesinski | 58a20a6 | 2016-07-25 17:56:58 -0700 | [diff] [blame] | 41 | .addPublicSymbol("android:attr/text", ResourceId(0x01010003), |
| Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 42 | test::AttributeBuilder() |
| 43 | .setTypeMask(android::ResTable_map::TYPE_STRING) |
| 44 | .build()) |
| 45 | |
| 46 | // Add one real symbol that was introduces in v21 |
| Adam Lesinski | 58a20a6 | 2016-07-25 17:56:58 -0700 | [diff] [blame] | 47 | .addPublicSymbol("android:attr/colorAccent", ResourceId(0x01010435), |
| Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 48 | test::AttributeBuilder().build()) |
| 49 | |
| Adam Lesinski | 467f171 | 2015-11-16 17:35:44 -0800 | [diff] [blame] | 50 | // Private symbol. |
| Adam Lesinski | 58a20a6 | 2016-07-25 17:56:58 -0700 | [diff] [blame] | 51 | .addSymbol("android:color/hidden", ResourceId(0x01020001)) |
| Adam Lesinski | 467f171 | 2015-11-16 17:35:44 -0800 | [diff] [blame] | 52 | |
| Adam Lesinski | 58a20a6 | 2016-07-25 17:56:58 -0700 | [diff] [blame] | 53 | .addPublicSymbol("android:id/id", ResourceId(0x01030000)) |
| 54 | .addSymbol("com.app.test:id/id", ResourceId(0x7f030000)) |
| 55 | .addSymbol("com.app.test:color/green", ResourceId(0x7f020000)) |
| 56 | .addSymbol("com.app.test:color/red", ResourceId(0x7f020001)) |
| 57 | .addSymbol("com.app.test:attr/colorAccent", ResourceId(0x7f010000), |
| Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 58 | test::AttributeBuilder() |
| 59 | .setTypeMask(android::ResTable_map::TYPE_COLOR).build()) |
| Adam Lesinski | 58a20a6 | 2016-07-25 17:56:58 -0700 | [diff] [blame] | 60 | .addPublicSymbol("com.app.test:attr/com.android.support$colorAccent", |
| Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 61 | ResourceId(0x7f010001), test::AttributeBuilder() |
| 62 | .setTypeMask(android::ResTable_map::TYPE_COLOR).build()) |
| Adam Lesinski | 58a20a6 | 2016-07-25 17:56:58 -0700 | [diff] [blame] | 63 | .addPublicSymbol("com.app.test:attr/attr", ResourceId(0x7f010002), |
| Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 64 | test::AttributeBuilder().build()) |
| 65 | .build()) |
| 66 | .build(); |
| 67 | } |
| 68 | |
| 69 | protected: |
| 70 | std::unique_ptr<IAaptContext> mContext; |
| 71 | }; |
| 72 | |
| Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 73 | TEST_F(XmlReferenceLinkerTest, LinkBasicAttributes) { |
| Adam Lesinski | 467f171 | 2015-11-16 17:35:44 -0800 | [diff] [blame] | 74 | std::unique_ptr<xml::XmlResource> doc = test::buildXmlDomForPackageName(mContext.get(), R"EOF( |
| Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 75 | <View xmlns:android="http://schemas.android.com/apk/res/android" |
| 76 | android:layout_width="match_parent" |
| 77 | android:background="@color/green" |
| 78 | android:text="hello" |
| 79 | class="hello" />)EOF"); |
| 80 | |
| 81 | XmlReferenceLinker linker; |
| 82 | ASSERT_TRUE(linker.consume(mContext.get(), doc.get())); |
| 83 | |
| Adam Lesinski | 467f171 | 2015-11-16 17:35:44 -0800 | [diff] [blame] | 84 | xml::Element* viewEl = xml::findRootElement(doc.get()); |
| Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 85 | ASSERT_NE(viewEl, nullptr); |
| 86 | |
| Adam Lesinski | d0f116b | 2016-07-08 15:00:32 -0700 | [diff] [blame] | 87 | xml::Attribute* xmlAttr = viewEl->findAttribute(xml::kSchemaAndroid, "layout_width"); |
| Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 88 | ASSERT_NE(xmlAttr, nullptr); |
| 89 | AAPT_ASSERT_TRUE(xmlAttr->compiledAttribute); |
| Adam Lesinski | 64587af | 2016-02-18 18:33:06 -0800 | [diff] [blame] | 90 | AAPT_ASSERT_TRUE(xmlAttr->compiledAttribute.value().id); |
| 91 | EXPECT_EQ(xmlAttr->compiledAttribute.value().id.value(), ResourceId(0x01010000)); |
| Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 92 | ASSERT_NE(xmlAttr->compiledValue, nullptr); |
| 93 | ASSERT_NE(valueCast<BinaryPrimitive>(xmlAttr->compiledValue.get()), nullptr); |
| 94 | |
| Adam Lesinski | d0f116b | 2016-07-08 15:00:32 -0700 | [diff] [blame] | 95 | xmlAttr = viewEl->findAttribute(xml::kSchemaAndroid, "background"); |
| Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 96 | ASSERT_NE(xmlAttr, nullptr); |
| 97 | AAPT_ASSERT_TRUE(xmlAttr->compiledAttribute); |
| Adam Lesinski | 64587af | 2016-02-18 18:33:06 -0800 | [diff] [blame] | 98 | AAPT_ASSERT_TRUE(xmlAttr->compiledAttribute.value().id); |
| 99 | EXPECT_EQ(xmlAttr->compiledAttribute.value().id.value(), ResourceId(0x01010001)); |
| Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 100 | ASSERT_NE(xmlAttr->compiledValue, nullptr); |
| 101 | Reference* ref = valueCast<Reference>(xmlAttr->compiledValue.get()); |
| 102 | ASSERT_NE(ref, nullptr); |
| 103 | AAPT_ASSERT_TRUE(ref->name); |
| Adam Lesinski | 58a20a6 | 2016-07-25 17:56:58 -0700 | [diff] [blame] | 104 | EXPECT_EQ(ref->name.value(), test::parseNameOrDie("color/green")); // Make sure the name |
| Adam Lesinski | d0f116b | 2016-07-08 15:00:32 -0700 | [diff] [blame] | 105 | // didn't change. |
| Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 106 | AAPT_ASSERT_TRUE(ref->id); |
| 107 | EXPECT_EQ(ref->id.value(), ResourceId(0x7f020000)); |
| 108 | |
| Adam Lesinski | d0f116b | 2016-07-08 15:00:32 -0700 | [diff] [blame] | 109 | xmlAttr = viewEl->findAttribute(xml::kSchemaAndroid, "text"); |
| Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 110 | ASSERT_NE(xmlAttr, nullptr); |
| 111 | AAPT_ASSERT_TRUE(xmlAttr->compiledAttribute); |
| 112 | ASSERT_FALSE(xmlAttr->compiledValue); // Strings don't get compiled for memory sake. |
| 113 | |
| Adam Lesinski | d0f116b | 2016-07-08 15:00:32 -0700 | [diff] [blame] | 114 | xmlAttr = viewEl->findAttribute("", "class"); |
| Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 115 | ASSERT_NE(xmlAttr, nullptr); |
| 116 | AAPT_ASSERT_FALSE(xmlAttr->compiledAttribute); |
| 117 | ASSERT_EQ(xmlAttr->compiledValue, nullptr); |
| 118 | } |
| 119 | |
| Adam Lesinski | 467f171 | 2015-11-16 17:35:44 -0800 | [diff] [blame] | 120 | TEST_F(XmlReferenceLinkerTest, PrivateSymbolsAreNotLinked) { |
| 121 | std::unique_ptr<xml::XmlResource> doc = test::buildXmlDomForPackageName(mContext.get(), R"EOF( |
| 122 | <View xmlns:android="http://schemas.android.com/apk/res/android" |
| 123 | android:colorAccent="@android:color/hidden" />)EOF"); |
| 124 | |
| 125 | XmlReferenceLinker linker; |
| 126 | ASSERT_FALSE(linker.consume(mContext.get(), doc.get())); |
| 127 | } |
| 128 | |
| 129 | TEST_F(XmlReferenceLinkerTest, PrivateSymbolsAreLinkedWhenReferenceHasStarPrefix) { |
| 130 | std::unique_ptr<xml::XmlResource> doc = test::buildXmlDomForPackageName(mContext.get(), R"EOF( |
| 131 | <View xmlns:android="http://schemas.android.com/apk/res/android" |
| 132 | android:colorAccent="@*android:color/hidden" />)EOF"); |
| 133 | |
| 134 | XmlReferenceLinker linker; |
| 135 | ASSERT_TRUE(linker.consume(mContext.get(), doc.get())); |
| 136 | } |
| 137 | |
| Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 138 | TEST_F(XmlReferenceLinkerTest, SdkLevelsAreRecorded) { |
| Adam Lesinski | 467f171 | 2015-11-16 17:35:44 -0800 | [diff] [blame] | 139 | std::unique_ptr<xml::XmlResource> doc = test::buildXmlDomForPackageName(mContext.get(), R"EOF( |
| Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 140 | <View xmlns:android="http://schemas.android.com/apk/res/android" |
| 141 | android:colorAccent="#ffffff" />)EOF"); |
| 142 | |
| 143 | XmlReferenceLinker linker; |
| 144 | ASSERT_TRUE(linker.consume(mContext.get(), doc.get())); |
| 145 | EXPECT_TRUE(linker.getSdkLevels().count(21) == 1); |
| 146 | } |
| 147 | |
| 148 | TEST_F(XmlReferenceLinkerTest, LinkMangledAttributes) { |
| Adam Lesinski | 467f171 | 2015-11-16 17:35:44 -0800 | [diff] [blame] | 149 | std::unique_ptr<xml::XmlResource> doc = test::buildXmlDomForPackageName(mContext.get(), R"EOF( |
| Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 150 | <View xmlns:support="http://schemas.android.com/apk/res/com.android.support" |
| 151 | support:colorAccent="#ff0000" />)EOF"); |
| 152 | |
| 153 | XmlReferenceLinker linker; |
| 154 | ASSERT_TRUE(linker.consume(mContext.get(), doc.get())); |
| 155 | |
| Adam Lesinski | 467f171 | 2015-11-16 17:35:44 -0800 | [diff] [blame] | 156 | xml::Element* viewEl = xml::findRootElement(doc.get()); |
| Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 157 | ASSERT_NE(viewEl, nullptr); |
| 158 | |
| 159 | xml::Attribute* xmlAttr = viewEl->findAttribute( |
| Adam Lesinski | d0f116b | 2016-07-08 15:00:32 -0700 | [diff] [blame] | 160 | xml::buildPackageNamespace("com.android.support"), "colorAccent"); |
| Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 161 | ASSERT_NE(xmlAttr, nullptr); |
| 162 | AAPT_ASSERT_TRUE(xmlAttr->compiledAttribute); |
| Adam Lesinski | 64587af | 2016-02-18 18:33:06 -0800 | [diff] [blame] | 163 | AAPT_ASSERT_TRUE(xmlAttr->compiledAttribute.value().id); |
| 164 | EXPECT_EQ(xmlAttr->compiledAttribute.value().id.value(), ResourceId(0x7f010001)); |
| Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 165 | ASSERT_NE(valueCast<BinaryPrimitive>(xmlAttr->compiledValue.get()), nullptr); |
| 166 | } |
| 167 | |
| 168 | TEST_F(XmlReferenceLinkerTest, LinkAutoResReference) { |
| Adam Lesinski | 467f171 | 2015-11-16 17:35:44 -0800 | [diff] [blame] | 169 | std::unique_ptr<xml::XmlResource> doc = test::buildXmlDomForPackageName(mContext.get(), R"EOF( |
| Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 170 | <View xmlns:app="http://schemas.android.com/apk/res-auto" |
| 171 | app:colorAccent="@app:color/red" />)EOF"); |
| 172 | |
| 173 | XmlReferenceLinker linker; |
| 174 | ASSERT_TRUE(linker.consume(mContext.get(), doc.get())); |
| 175 | |
| Adam Lesinski | 467f171 | 2015-11-16 17:35:44 -0800 | [diff] [blame] | 176 | xml::Element* viewEl = xml::findRootElement(doc.get()); |
| Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 177 | ASSERT_NE(viewEl, nullptr); |
| 178 | |
| Adam Lesinski | d0f116b | 2016-07-08 15:00:32 -0700 | [diff] [blame] | 179 | xml::Attribute* xmlAttr = viewEl->findAttribute(xml::kSchemaAuto, "colorAccent"); |
| Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 180 | ASSERT_NE(xmlAttr, nullptr); |
| 181 | AAPT_ASSERT_TRUE(xmlAttr->compiledAttribute); |
| Adam Lesinski | 64587af | 2016-02-18 18:33:06 -0800 | [diff] [blame] | 182 | AAPT_ASSERT_TRUE(xmlAttr->compiledAttribute.value().id); |
| 183 | EXPECT_EQ(xmlAttr->compiledAttribute.value().id.value(), ResourceId(0x7f010000)); |
| Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 184 | Reference* ref = valueCast<Reference>(xmlAttr->compiledValue.get()); |
| 185 | ASSERT_NE(ref, nullptr); |
| 186 | AAPT_ASSERT_TRUE(ref->name); |
| 187 | AAPT_ASSERT_TRUE(ref->id); |
| 188 | EXPECT_EQ(ref->id.value(), ResourceId(0x7f020001)); |
| 189 | } |
| 190 | |
| 191 | TEST_F(XmlReferenceLinkerTest, LinkViewWithShadowedPackageAlias) { |
| Adam Lesinski | 467f171 | 2015-11-16 17:35:44 -0800 | [diff] [blame] | 192 | std::unique_ptr<xml::XmlResource> doc = test::buildXmlDomForPackageName(mContext.get(), R"EOF( |
| Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 193 | <View xmlns:app="http://schemas.android.com/apk/res/android" |
| 194 | app:attr="@app:id/id"> |
| 195 | <View xmlns:app="http://schemas.android.com/apk/res/com.app.test" |
| 196 | app:attr="@app:id/id"/> |
| 197 | </View>)EOF"); |
| 198 | |
| 199 | XmlReferenceLinker linker; |
| 200 | ASSERT_TRUE(linker.consume(mContext.get(), doc.get())); |
| 201 | |
| Adam Lesinski | 467f171 | 2015-11-16 17:35:44 -0800 | [diff] [blame] | 202 | xml::Element* viewEl = xml::findRootElement(doc.get()); |
| Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 203 | ASSERT_NE(viewEl, nullptr); |
| 204 | |
| 205 | // All attributes and references in this element should be referring to "android" (0x01). |
| Adam Lesinski | d0f116b | 2016-07-08 15:00:32 -0700 | [diff] [blame] | 206 | xml::Attribute* xmlAttr = viewEl->findAttribute(xml::kSchemaAndroid, "attr"); |
| Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 207 | ASSERT_NE(xmlAttr, nullptr); |
| 208 | AAPT_ASSERT_TRUE(xmlAttr->compiledAttribute); |
| Adam Lesinski | 64587af | 2016-02-18 18:33:06 -0800 | [diff] [blame] | 209 | AAPT_ASSERT_TRUE(xmlAttr->compiledAttribute.value().id); |
| 210 | EXPECT_EQ(xmlAttr->compiledAttribute.value().id.value(), ResourceId(0x01010002)); |
| Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 211 | Reference* ref = valueCast<Reference>(xmlAttr->compiledValue.get()); |
| 212 | ASSERT_NE(ref, nullptr); |
| 213 | AAPT_ASSERT_TRUE(ref->id); |
| 214 | EXPECT_EQ(ref->id.value(), ResourceId(0x01030000)); |
| 215 | |
| 216 | ASSERT_FALSE(viewEl->getChildElements().empty()); |
| 217 | viewEl = viewEl->getChildElements().front(); |
| 218 | ASSERT_NE(viewEl, nullptr); |
| 219 | |
| 220 | // All attributes and references in this element should be referring to "com.app.test" (0x7f). |
| Adam Lesinski | d0f116b | 2016-07-08 15:00:32 -0700 | [diff] [blame] | 221 | xmlAttr = viewEl->findAttribute(xml::buildPackageNamespace("com.app.test"), "attr"); |
| Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 222 | ASSERT_NE(xmlAttr, nullptr); |
| 223 | AAPT_ASSERT_TRUE(xmlAttr->compiledAttribute); |
| Adam Lesinski | 64587af | 2016-02-18 18:33:06 -0800 | [diff] [blame] | 224 | AAPT_ASSERT_TRUE(xmlAttr->compiledAttribute.value().id); |
| 225 | EXPECT_EQ(xmlAttr->compiledAttribute.value().id.value(), ResourceId(0x7f010002)); |
| Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 226 | ref = valueCast<Reference>(xmlAttr->compiledValue.get()); |
| 227 | ASSERT_NE(ref, nullptr); |
| 228 | AAPT_ASSERT_TRUE(ref->id); |
| 229 | EXPECT_EQ(ref->id.value(), ResourceId(0x7f030000)); |
| 230 | } |
| 231 | |
| 232 | TEST_F(XmlReferenceLinkerTest, LinkViewWithLocalPackageAndAliasOfTheSameName) { |
| Adam Lesinski | 467f171 | 2015-11-16 17:35:44 -0800 | [diff] [blame] | 233 | std::unique_ptr<xml::XmlResource> doc = test::buildXmlDomForPackageName(mContext.get(), R"EOF( |
| Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 234 | <View xmlns:android="http://schemas.android.com/apk/res/com.app.test" |
| 235 | android:attr="@id/id"/>)EOF"); |
| 236 | |
| 237 | XmlReferenceLinker linker; |
| 238 | ASSERT_TRUE(linker.consume(mContext.get(), doc.get())); |
| 239 | |
| Adam Lesinski | 467f171 | 2015-11-16 17:35:44 -0800 | [diff] [blame] | 240 | xml::Element* viewEl = xml::findRootElement(doc.get()); |
| Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 241 | ASSERT_NE(viewEl, nullptr); |
| 242 | |
| 243 | // All attributes and references in this element should be referring to "com.app.test" (0x7f). |
| Adam Lesinski | d0f116b | 2016-07-08 15:00:32 -0700 | [diff] [blame] | 244 | xml::Attribute* xmlAttr = viewEl->findAttribute(xml::buildPackageNamespace("com.app.test"), |
| 245 | "attr"); |
| Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 246 | ASSERT_NE(xmlAttr, nullptr); |
| 247 | AAPT_ASSERT_TRUE(xmlAttr->compiledAttribute); |
| Adam Lesinski | 64587af | 2016-02-18 18:33:06 -0800 | [diff] [blame] | 248 | AAPT_ASSERT_TRUE(xmlAttr->compiledAttribute.value().id); |
| 249 | EXPECT_EQ(xmlAttr->compiledAttribute.value().id.value(), ResourceId(0x7f010002)); |
| Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 250 | Reference* ref = valueCast<Reference>(xmlAttr->compiledValue.get()); |
| 251 | ASSERT_NE(ref, nullptr); |
| 252 | AAPT_ASSERT_TRUE(ref->id); |
| 253 | EXPECT_EQ(ref->id.value(), ResourceId(0x7f030000)); |
| 254 | } |
| 255 | |
| 256 | } // namespace aapt |