/* * 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("com.app.test", 0x7f) .addReference("com.app.test:string/foo", ResourceId(0x7f020000), "com.app.test:string/bar") // Test use of local reference (w/o package name). .addReference("com.app.test:string/bar", ResourceId(0x7f020001), "string/baz") .addReference("com.app.test:string/baz", ResourceId(0x7f020002), "android:string/ok") .build(); std::unique_ptr context = test::ContextBuilder() .setCompilationPackage("com.app.test") .setPackageId(0x7f) .setNameManglerPolicy(NameManglerPolicy{ "com.app.test" }) .addSymbolSource(util::make_unique(table.get())) .addSymbolSource(test::StaticSymbolSourceBuilder() .addPublicSymbol("android:string/ok", ResourceId(0x01040034)) .build()) .build(); ReferenceLinker linker; ASSERT_TRUE(linker.consume(context.get(), table.get())); Reference* ref = test::getValue(table.get(), "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(), "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(), "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("com.app.test", 0x7f) .addValue("com.app.test:style/Theme", test::StyleBuilder() .setParent("android:style/Theme.Material") .addItem("android:attr/foo", ResourceUtils::tryParseColor("#ff00ff")) .addItem("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