HELLO·Android
系统源代码
IT资讯
技术文章
我的收藏
注册
登录
-
我收藏的文章
创建代码块
我的代码块
我的账号
Nougat 7.1
|
7.1.1_r28
下载
查看原文件
收藏
根目录
frameworks
base
tools
aapt2
link
ReferenceLinker_test.cpp
/* * Copyright (C) 2015 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "link/ReferenceLinker.h" #include "test/Test.h" using android::ResTable_map; namespace aapt { TEST(ReferenceLinkerTest, LinkSimpleReferences) { std::unique_ptr
table = test::ResourceTableBuilder() .setPackageId(u"com.app.test", 0x7f) .addReference(u"@com.app.test:string/foo", ResourceId(0x7f020000), u"@com.app.test:string/bar") // Test use of local reference (w/o package name). .addReference(u"@com.app.test:string/bar", ResourceId(0x7f020001), u"@string/baz") .addReference(u"@com.app.test:string/baz", ResourceId(0x7f020002), u"@android:string/ok") .build(); std::unique_ptr
context = test::ContextBuilder() .setCompilationPackage(u"com.app.test") .setPackageId(0x7f) .setNameManglerPolicy(NameManglerPolicy{ u"com.app.test" }) .addSymbolSource(util::make_unique
(table.get())) .addSymbolSource(test::StaticSymbolSourceBuilder() .addPublicSymbol(u"@android:string/ok", ResourceId(0x01040034)) .build()) .build(); ReferenceLinker linker; ASSERT_TRUE(linker.consume(context.get(), table.get())); Reference* ref = test::getValue
(table.get(), u"@com.app.test:string/foo"); ASSERT_NE(ref, nullptr); AAPT_ASSERT_TRUE(ref->id); EXPECT_EQ(ref->id.value(), ResourceId(0x7f020001)); ref = test::getValue
(table.get(), u"@com.app.test:string/bar"); ASSERT_NE(ref, nullptr); AAPT_ASSERT_TRUE(ref->id); EXPECT_EQ(ref->id.value(), ResourceId(0x7f020002)); ref = test::getValue
(table.get(), u"@com.app.test:string/baz"); ASSERT_NE(ref, nullptr); AAPT_ASSERT_TRUE(ref->id); EXPECT_EQ(ref->id.value(), ResourceId(0x01040034)); } TEST(ReferenceLinkerTest, LinkStyleAttributes) { std::unique_ptr
table = test::ResourceTableBuilder() .setPackageId(u"com.app.test", 0x7f) .addValue(u"@com.app.test:style/Theme", test::StyleBuilder() .setParent(u"@android:style/Theme.Material") .addItem(u"@android:attr/foo", ResourceUtils::tryParseColor(u"#ff00ff")) .addItem(u"@android:attr/bar", {} /* placeholder */) .build()) .build(); { // We need to fill in the value for the attribute android:attr/bar after we build the // table, because we need access to the string pool. Style* style = test::getValue