/* * 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 "Linker.h" #include "ResourceTable.h" #include "ResourceTableResolver.h" #include "ResourceValues.h" #include "Util.h" #include #include #include namespace aapt { struct LinkerTest : public ::testing::Test { virtual void SetUp() override { mTable = std::make_shared(); mTable->setPackage(u"android"); mTable->setPackageId(0x01); mLinker = std::make_shared(mTable, std::make_shared( mTable, std::vector>()), Linker::Options{}); // Create a few attributes for use in the tests. addResource(ResourceName{ {}, ResourceType::kAttr, u"integer" }, util::make_unique(false, android::ResTable_map::TYPE_INTEGER)); addResource(ResourceName{ {}, ResourceType::kAttr, u"string" }, util::make_unique(false, android::ResTable_map::TYPE_STRING)); addResource(ResourceName{ {}, ResourceType::kId, u"apple" }, util::make_unique()); addResource(ResourceName{ {}, ResourceType::kId, u"banana" }, util::make_unique()); std::unique_ptr flagAttr = util::make_unique( false, android::ResTable_map::TYPE_FLAGS); flagAttr->symbols.push_back(Attribute::Symbol{ ResourceNameRef{ u"android", ResourceType::kId, u"apple" }, 1 }); flagAttr->symbols.push_back(Attribute::Symbol{ ResourceNameRef{ u"android", ResourceType::kId, u"banana" }, 2 }); addResource(ResourceName{ {}, ResourceType::kAttr, u"flags" }, std::move(flagAttr)); } /* * Convenience method for adding resources with the default configuration and some * bogus source line. */ bool addResource(const ResourceNameRef& name, std::unique_ptr value) { return mTable->addResource(name, {}, SourceLine{ "test.xml", 21 }, std::move(value)); } std::shared_ptr mTable; std::shared_ptr mLinker; }; TEST_F(LinkerTest, DoNotInterpretEscapedStringAsReference) { ASSERT_TRUE(addResource(ResourceName{ u"android", ResourceType::kString, u"foo" }, util::make_unique(mTable->getValueStringPool().makeRef(u"?123")))); ASSERT_TRUE(mLinker->linkAndValidate()); EXPECT_TRUE(mLinker->getUnresolvedReferences().empty()); } TEST_F(LinkerTest, EscapeAndConvertRawString) { std::unique_ptr