HELLO·Android
系统源代码
IT资讯
技术文章
我的收藏
注册
登录
-
我收藏的文章
创建代码块
我的代码块
我的账号
Android 10
|
10.0.0_r6
下载
查看原文件
收藏
根目录
frameworks
base
tools
aapt2
link
AutoVersioner_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/Linkers.h" #include "androidfw/ConfigDescription.h" #include "test/Test.h" using ::android::ConfigDescription; using ::testing::NotNull; namespace aapt { TEST(AutoVersionerTest, GenerateVersionedResources) { const ConfigDescription land_config = test::ParseConfigOrDie("land"); const ConfigDescription sw600dp_land_config = test::ParseConfigOrDie("sw600dp-land"); ResourceEntry entry("foo"); entry.values.push_back(util::make_unique
(ConfigDescription::DefaultConfig(), "")); entry.values.push_back(util::make_unique
(land_config, "")); entry.values.push_back(util::make_unique
(sw600dp_land_config, "")); EXPECT_TRUE(ShouldGenerateVersionedResource(&entry, ConfigDescription::DefaultConfig(), 17)); EXPECT_TRUE(ShouldGenerateVersionedResource(&entry, land_config, 17)); } TEST(AutoVersionerTest, GenerateVersionedResourceWhenHigherVersionExists) { const ConfigDescription sw600dp_v13_config = test::ParseConfigOrDie("sw600dp-v13"); const ConfigDescription v21_config = test::ParseConfigOrDie("v21"); ResourceEntry entry("foo"); entry.values.push_back(util::make_unique
(ConfigDescription::DefaultConfig(), "")); entry.values.push_back(util::make_unique
(sw600dp_v13_config, "")); entry.values.push_back(util::make_unique
(v21_config, "")); EXPECT_TRUE(ShouldGenerateVersionedResource(&entry, ConfigDescription::DefaultConfig(), 17)); EXPECT_FALSE(ShouldGenerateVersionedResource(&entry, ConfigDescription::DefaultConfig(), 22)); } TEST(AutoVersionerTest, VersionStylesForTable) { std::unique_ptr
table = test::ResourceTableBuilder() .SetPackageId("app", 0x7f) .AddValue( "app:style/Foo", test::ParseConfigOrDie("v4"), ResourceId(0x7f020000), test::StyleBuilder() .AddItem("android:attr/onClick", ResourceId(0x0101026f), util::make_unique
()) .AddItem("android:attr/paddingStart", ResourceId(0x010103b3), util::make_unique
()) .AddItem("android:attr/requiresSmallestWidthDp", ResourceId(0x01010364), util::make_unique
()) .AddItem("android:attr/colorAccent", ResourceId(0x01010435), util::make_unique
()) .Build()) .AddValue( "app:style/Foo", test::ParseConfigOrDie("v21"), ResourceId(0x7f020000), test::StyleBuilder() .AddItem("android:attr/paddingEnd", ResourceId(0x010103b4), util::make_unique
()) .Build()) .Build(); std::unique_ptr
context = test::ContextBuilder() .SetCompilationPackage("app") .SetPackageId(0x7f) .Build(); AutoVersioner versioner; ASSERT_TRUE(versioner.Consume(context.get(), table.get())); Style* style = test::GetValueForConfig