/* * 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; using ::testing::Eq; using ::testing::IsNull; using ::testing::NotNull; namespace aapt { TEST(ReferenceLinkerTest, LinkSimpleReferences) { std::unique_ptr table = test::ResourceTableBuilder() .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_THAT(ref, NotNull()); ASSERT_TRUE(ref->id); EXPECT_EQ(ResourceId(0x7f020001), ref->id.value()); ref = test::GetValue(table.get(), "com.app.test:string/bar"); ASSERT_THAT(ref, NotNull()); ASSERT_TRUE(ref->id); EXPECT_EQ(ResourceId(0x7f020002), ref->id.value()); ref = test::GetValue(table.get(), "com.app.test:string/baz"); ASSERT_THAT(ref, NotNull()); ASSERT_TRUE(ref->id); EXPECT_EQ(ResourceId(0x01040034), ref->id.value()); } TEST(ReferenceLinkerTest, LinkStyleAttributes) { std::unique_ptr table = test::ResourceTableBuilder() .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