19d9cc6233c7035c32d3b8622aa5dc7d413193dc7Adam Lesinski/* 27ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski * Copyright (C) 2016 The Android Open Source Project 39d9cc6233c7035c32d3b8622aa5dc7d413193dc7Adam Lesinski * 49d9cc6233c7035c32d3b8622aa5dc7d413193dc7Adam Lesinski * Licensed under the Apache License, Version 2.0 (the "License"); 59d9cc6233c7035c32d3b8622aa5dc7d413193dc7Adam Lesinski * you may not use this file except in compliance with the License. 69d9cc6233c7035c32d3b8622aa5dc7d413193dc7Adam Lesinski * You may obtain a copy of the License at 79d9cc6233c7035c32d3b8622aa5dc7d413193dc7Adam Lesinski * 89d9cc6233c7035c32d3b8622aa5dc7d413193dc7Adam Lesinski * http://www.apache.org/licenses/LICENSE-2.0 99d9cc6233c7035c32d3b8622aa5dc7d413193dc7Adam Lesinski * 109d9cc6233c7035c32d3b8622aa5dc7d413193dc7Adam Lesinski * Unless required by applicable law or agreed to in writing, software 119d9cc6233c7035c32d3b8622aa5dc7d413193dc7Adam Lesinski * distributed under the License is distributed on an "AS IS" BASIS, 129d9cc6233c7035c32d3b8622aa5dc7d413193dc7Adam Lesinski * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 139d9cc6233c7035c32d3b8622aa5dc7d413193dc7Adam Lesinski * See the License for the specific language governing permissions and 149d9cc6233c7035c32d3b8622aa5dc7d413193dc7Adam Lesinski * limitations under the License. 159d9cc6233c7035c32d3b8622aa5dc7d413193dc7Adam Lesinski */ 169d9cc6233c7035c32d3b8622aa5dc7d413193dc7Adam Lesinski 177ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski#include "androidfw/AssetManager2.h" 184c67a475a334e4f65238d439a3339195e03c03beAdam Lesinski 197ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski#include "android-base/logging.h" 209d9cc6233c7035c32d3b8622aa5dc7d413193dc7Adam Lesinski 219d9cc6233c7035c32d3b8622aa5dc7d413193dc7Adam Lesinski#include "TestHelpers.h" 22929d6517dfd338f0d481dbe6587643d5aef27ec6Adam Lesinski#include "androidfw/ResourceUtils.h" 23da431a22da38f9c4085b5d71ed9a9c6122c6a5a6Adam Lesinski#include "data/lib_one/R.h" 24da431a22da38f9c4085b5d71ed9a9c6122c6a5a6Adam Lesinski#include "data/libclient/R.h" 257ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski#include "data/styles/R.h" 269d9cc6233c7035c32d3b8622aa5dc7d413193dc7Adam Lesinski 274c67a475a334e4f65238d439a3339195e03c03beAdam Lesinskinamespace app = com::android::app; 28da431a22da38f9c4085b5d71ed9a9c6122c6a5a6Adam Lesinskinamespace lib_one = com::android::lib_one; 29da431a22da38f9c4085b5d71ed9a9c6122c6a5a6Adam Lesinskinamespace libclient = com::android::libclient; 309d9cc6233c7035c32d3b8622aa5dc7d413193dc7Adam Lesinski 314c67a475a334e4f65238d439a3339195e03c03beAdam Lesinskinamespace android { 329d9cc6233c7035c32d3b8622aa5dc7d413193dc7Adam Lesinski 337ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinskiclass ThemeTest : public ::testing::Test { 347ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski public: 357ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski void SetUp() override { 367ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski style_assets_ = ApkAssets::Load(GetTestDataPath() + "/styles/styles.apk"); 377ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski ASSERT_NE(nullptr, style_assets_); 38da431a22da38f9c4085b5d71ed9a9c6122c6a5a6Adam Lesinski 39da431a22da38f9c4085b5d71ed9a9c6122c6a5a6Adam Lesinski libclient_assets_ = ApkAssets::Load(GetTestDataPath() + "/libclient/libclient.apk"); 40da431a22da38f9c4085b5d71ed9a9c6122c6a5a6Adam Lesinski ASSERT_NE(nullptr, libclient_assets_); 41da431a22da38f9c4085b5d71ed9a9c6122c6a5a6Adam Lesinski 42da431a22da38f9c4085b5d71ed9a9c6122c6a5a6Adam Lesinski lib_one_assets_ = ApkAssets::Load(GetTestDataPath() + "/lib_one/lib_one.apk"); 43da431a22da38f9c4085b5d71ed9a9c6122c6a5a6Adam Lesinski ASSERT_NE(nullptr, lib_one_assets_); 44da431a22da38f9c4085b5d71ed9a9c6122c6a5a6Adam Lesinski 45da431a22da38f9c4085b5d71ed9a9c6122c6a5a6Adam Lesinski lib_two_assets_ = ApkAssets::Load(GetTestDataPath() + "/lib_two/lib_two.apk"); 46da431a22da38f9c4085b5d71ed9a9c6122c6a5a6Adam Lesinski ASSERT_NE(nullptr, lib_two_assets_); 477ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski } 487ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski 497ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski protected: 500c40524953f3d36a880f91183302a2ea5c722930Adam Lesinski std::unique_ptr<const ApkAssets> style_assets_; 510c40524953f3d36a880f91183302a2ea5c722930Adam Lesinski std::unique_ptr<const ApkAssets> libclient_assets_; 520c40524953f3d36a880f91183302a2ea5c722930Adam Lesinski std::unique_ptr<const ApkAssets> lib_one_assets_; 530c40524953f3d36a880f91183302a2ea5c722930Adam Lesinski std::unique_ptr<const ApkAssets> lib_two_assets_; 547ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski}; 557ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski 567ad1110ecd6a840fcd2895c62668828a1ca029c6Adam LesinskiTEST_F(ThemeTest, EmptyTheme) { 577ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski AssetManager2 assetmanager; 587ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski assetmanager.SetApkAssets({style_assets_.get()}); 597ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski 607ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski std::unique_ptr<Theme> theme = assetmanager.NewTheme(); 617ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski EXPECT_EQ(0u, theme->GetChangingConfigurations()); 627ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski EXPECT_EQ(&assetmanager, theme->GetAssetManager()); 637ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski 647ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski Res_value value; 657ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski uint32_t flags; 667ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski EXPECT_EQ(kInvalidCookie, theme->GetAttribute(app::R::attr::attr_one, &value, &flags)); 677ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski} 687ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski 697ad1110ecd6a840fcd2895c62668828a1ca029c6Adam LesinskiTEST_F(ThemeTest, SingleThemeNoParent) { 707ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski AssetManager2 assetmanager; 717ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski assetmanager.SetApkAssets({style_assets_.get()}); 727ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski 737ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski std::unique_ptr<Theme> theme = assetmanager.NewTheme(); 747ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski ASSERT_TRUE(theme->ApplyStyle(app::R::style::StyleOne)); 757ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski 767ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski Res_value value; 777ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski uint32_t flags; 787ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski ApkAssetsCookie cookie; 797ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski 807ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski cookie = theme->GetAttribute(app::R::attr::attr_one, &value, &flags); 817ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski ASSERT_NE(kInvalidCookie, cookie); 827ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski EXPECT_EQ(Res_value::TYPE_INT_DEC, value.dataType); 837ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski EXPECT_EQ(1u, value.data); 847ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski EXPECT_EQ(static_cast<uint32_t>(ResTable_typeSpec::SPEC_PUBLIC), flags); 857ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski 867ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski cookie = theme->GetAttribute(app::R::attr::attr_two, &value, &flags); 877ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski ASSERT_NE(kInvalidCookie, cookie); 887ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski EXPECT_EQ(Res_value::TYPE_INT_DEC, value.dataType); 897ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski EXPECT_EQ(2u, value.data); 907ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski EXPECT_EQ(static_cast<uint32_t>(ResTable_typeSpec::SPEC_PUBLIC), flags); 917ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski} 927ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski 937ad1110ecd6a840fcd2895c62668828a1ca029c6Adam LesinskiTEST_F(ThemeTest, SingleThemeWithParent) { 947ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski AssetManager2 assetmanager; 957ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski assetmanager.SetApkAssets({style_assets_.get()}); 967ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski 977ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski std::unique_ptr<Theme> theme = assetmanager.NewTheme(); 987ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski ASSERT_TRUE(theme->ApplyStyle(app::R::style::StyleTwo)); 997ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski 1007ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski Res_value value; 1017ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski uint32_t flags; 1027ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski ApkAssetsCookie cookie; 1037ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski 1047ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski cookie = theme->GetAttribute(app::R::attr::attr_one, &value, &flags); 1057ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski ASSERT_NE(kInvalidCookie, cookie); 1067ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski EXPECT_EQ(Res_value::TYPE_INT_DEC, value.dataType); 1077ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski EXPECT_EQ(1u, value.data); 1087ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski EXPECT_EQ(static_cast<uint32_t>(ResTable_typeSpec::SPEC_PUBLIC), flags); 1097ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski 1107ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski cookie = theme->GetAttribute(app::R::attr::attr_two, &value, &flags); 1117ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski ASSERT_NE(kInvalidCookie, cookie); 1127ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski EXPECT_EQ(Res_value::TYPE_STRING, value.dataType); 1137ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski EXPECT_EQ(0, cookie); 1147ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski EXPECT_EQ(std::string("string"), 1157ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski GetStringFromPool(assetmanager.GetStringPoolForCookie(0), value.data)); 1167ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski EXPECT_EQ(static_cast<uint32_t>(ResTable_typeSpec::SPEC_PUBLIC), flags); 1177ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski 1187ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski // This attribute should point to an attr_indirect, so the result should be 3. 1197ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski cookie = theme->GetAttribute(app::R::attr::attr_three, &value, &flags); 1207ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski ASSERT_NE(kInvalidCookie, cookie); 1217ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski EXPECT_EQ(Res_value::TYPE_INT_DEC, value.dataType); 1227ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski EXPECT_EQ(3u, value.data); 1237ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski EXPECT_EQ(static_cast<uint32_t>(ResTable_typeSpec::SPEC_PUBLIC), flags); 1247ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski} 1257ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski 1267ad1110ecd6a840fcd2895c62668828a1ca029c6Adam LesinskiTEST_F(ThemeTest, MultipleThemesOverlaidNotForce) { 1277ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski AssetManager2 assetmanager; 1287ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski assetmanager.SetApkAssets({style_assets_.get()}); 1297ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski 1307ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski std::unique_ptr<Theme> theme = assetmanager.NewTheme(); 1317ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski ASSERT_TRUE(theme->ApplyStyle(app::R::style::StyleTwo)); 1327ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski ASSERT_TRUE(theme->ApplyStyle(app::R::style::StyleThree)); 1337ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski 1347ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski Res_value value; 1357ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski uint32_t flags; 1367ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski ApkAssetsCookie cookie; 1377ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski 1387ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski // attr_one is still here from the base. 1397ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski cookie = theme->GetAttribute(app::R::attr::attr_one, &value, &flags); 1407ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski ASSERT_NE(kInvalidCookie, cookie); 1417ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski EXPECT_EQ(Res_value::TYPE_INT_DEC, value.dataType); 1427ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski EXPECT_EQ(1u, value.data); 1437ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski EXPECT_EQ(static_cast<uint32_t>(ResTable_typeSpec::SPEC_PUBLIC), flags); 1447ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski 1457ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski // check for the new attr_six 1467ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski cookie = theme->GetAttribute(app::R::attr::attr_six, &value, &flags); 1477ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski ASSERT_NE(kInvalidCookie, cookie); 1487ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski EXPECT_EQ(Res_value::TYPE_INT_DEC, value.dataType); 1497ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski EXPECT_EQ(6u, value.data); 1507ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski EXPECT_EQ(static_cast<uint32_t>(ResTable_typeSpec::SPEC_PUBLIC), flags); 1517ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski 1527ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski // check for the old attr_five (force=true was not used). 1537ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski cookie = theme->GetAttribute(app::R::attr::attr_five, &value, &flags); 1547ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski ASSERT_NE(kInvalidCookie, cookie); 1557ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski EXPECT_EQ(Res_value::TYPE_REFERENCE, value.dataType); 1567ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski EXPECT_EQ(app::R::string::string_one, value.data); 1577ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski EXPECT_EQ(static_cast<uint32_t>(ResTable_typeSpec::SPEC_PUBLIC), flags); 1587ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski} 1597ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski 1607ad1110ecd6a840fcd2895c62668828a1ca029c6Adam LesinskiTEST_F(ThemeTest, MultipleThemesOverlaidForced) { 1617ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski AssetManager2 assetmanager; 1627ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski assetmanager.SetApkAssets({style_assets_.get()}); 1637ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski 1647ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski std::unique_ptr<Theme> theme = assetmanager.NewTheme(); 1657ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski ASSERT_TRUE(theme->ApplyStyle(app::R::style::StyleTwo)); 1667ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski ASSERT_TRUE(theme->ApplyStyle(app::R::style::StyleThree, true /* force */)); 1677ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski 1687ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski Res_value value; 1697ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski uint32_t flags; 1707ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski ApkAssetsCookie cookie; 1717ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski 1727ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski // attr_one is still here from the base. 1737ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski cookie = theme->GetAttribute(app::R::attr::attr_one, &value, &flags); 1747ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski ASSERT_NE(kInvalidCookie, cookie); 1757ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski EXPECT_EQ(Res_value::TYPE_INT_DEC, value.dataType); 1767ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski EXPECT_EQ(1u, value.data); 1777ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski EXPECT_EQ(static_cast<uint32_t>(ResTable_typeSpec::SPEC_PUBLIC), flags); 1787ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski 1797ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski // check for the new attr_six 1807ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski cookie = theme->GetAttribute(app::R::attr::attr_six, &value, &flags); 1817ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski ASSERT_NE(kInvalidCookie, cookie); 1827ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski EXPECT_EQ(Res_value::TYPE_INT_DEC, value.dataType); 1837ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski EXPECT_EQ(6u, value.data); 1847ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski EXPECT_EQ(static_cast<uint32_t>(ResTable_typeSpec::SPEC_PUBLIC), flags); 1857ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski 1867ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski // check for the new attr_five (force=true was used). 1877ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski cookie = theme->GetAttribute(app::R::attr::attr_five, &value, &flags); 1887ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski ASSERT_NE(kInvalidCookie, cookie); 1897ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski EXPECT_EQ(Res_value::TYPE_INT_DEC, value.dataType); 1907ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski EXPECT_EQ(5u, value.data); 1917ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski EXPECT_EQ(static_cast<uint32_t>(ResTable_typeSpec::SPEC_PUBLIC), flags); 192da431a22da38f9c4085b5d71ed9a9c6122c6a5a6Adam Lesinski} 193da431a22da38f9c4085b5d71ed9a9c6122c6a5a6Adam Lesinski 194da431a22da38f9c4085b5d71ed9a9c6122c6a5a6Adam LesinskiTEST_F(ThemeTest, ResolveDynamicAttributesAndReferencesToSharedLibrary) { 195da431a22da38f9c4085b5d71ed9a9c6122c6a5a6Adam Lesinski AssetManager2 assetmanager; 196da431a22da38f9c4085b5d71ed9a9c6122c6a5a6Adam Lesinski assetmanager.SetApkAssets( 197da431a22da38f9c4085b5d71ed9a9c6122c6a5a6Adam Lesinski {lib_two_assets_.get(), lib_one_assets_.get(), libclient_assets_.get()}); 198da431a22da38f9c4085b5d71ed9a9c6122c6a5a6Adam Lesinski 199da431a22da38f9c4085b5d71ed9a9c6122c6a5a6Adam Lesinski std::unique_ptr<Theme> theme = assetmanager.NewTheme(); 200da431a22da38f9c4085b5d71ed9a9c6122c6a5a6Adam Lesinski ASSERT_TRUE(theme->ApplyStyle(libclient::R::style::Theme, false /*force*/)); 201da431a22da38f9c4085b5d71ed9a9c6122c6a5a6Adam Lesinski 202da431a22da38f9c4085b5d71ed9a9c6122c6a5a6Adam Lesinski Res_value value; 203da431a22da38f9c4085b5d71ed9a9c6122c6a5a6Adam Lesinski uint32_t flags; 204da431a22da38f9c4085b5d71ed9a9c6122c6a5a6Adam Lesinski ApkAssetsCookie cookie; 205da431a22da38f9c4085b5d71ed9a9c6122c6a5a6Adam Lesinski 206da431a22da38f9c4085b5d71ed9a9c6122c6a5a6Adam Lesinski // The attribute should be resolved to the final value. 207da431a22da38f9c4085b5d71ed9a9c6122c6a5a6Adam Lesinski cookie = theme->GetAttribute(libclient::R::attr::foo, &value, &flags); 208da431a22da38f9c4085b5d71ed9a9c6122c6a5a6Adam Lesinski ASSERT_NE(kInvalidCookie, cookie); 209da431a22da38f9c4085b5d71ed9a9c6122c6a5a6Adam Lesinski EXPECT_EQ(Res_value::TYPE_INT_DEC, value.dataType); 210da431a22da38f9c4085b5d71ed9a9c6122c6a5a6Adam Lesinski EXPECT_EQ(700u, value.data); 211da431a22da38f9c4085b5d71ed9a9c6122c6a5a6Adam Lesinski EXPECT_EQ(static_cast<uint32_t>(ResTable_typeSpec::SPEC_PUBLIC), flags); 212da431a22da38f9c4085b5d71ed9a9c6122c6a5a6Adam Lesinski 213da431a22da38f9c4085b5d71ed9a9c6122c6a5a6Adam Lesinski // The reference should be resolved to a TYPE_REFERENCE. 214da431a22da38f9c4085b5d71ed9a9c6122c6a5a6Adam Lesinski cookie = theme->GetAttribute(libclient::R::attr::bar, &value, &flags); 215da431a22da38f9c4085b5d71ed9a9c6122c6a5a6Adam Lesinski ASSERT_NE(kInvalidCookie, cookie); 216da431a22da38f9c4085b5d71ed9a9c6122c6a5a6Adam Lesinski EXPECT_EQ(Res_value::TYPE_REFERENCE, value.dataType); 217da431a22da38f9c4085b5d71ed9a9c6122c6a5a6Adam Lesinski 218da431a22da38f9c4085b5d71ed9a9c6122c6a5a6Adam Lesinski // lib_one is assigned package ID 0x03. 219929d6517dfd338f0d481dbe6587643d5aef27ec6Adam Lesinski EXPECT_EQ(3u, get_package_id(value.data)); 220929d6517dfd338f0d481dbe6587643d5aef27ec6Adam Lesinski EXPECT_EQ(get_type_id(lib_one::R::string::foo), get_type_id(value.data)); 221929d6517dfd338f0d481dbe6587643d5aef27ec6Adam Lesinski EXPECT_EQ(get_entry_id(lib_one::R::string::foo), get_entry_id(value.data)); 2227ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski} 2237ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski 2247ad1110ecd6a840fcd2895c62668828a1ca029c6Adam LesinskiTEST_F(ThemeTest, CopyThemeSameAssetManager) { 2257ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski AssetManager2 assetmanager; 2267ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski assetmanager.SetApkAssets({style_assets_.get()}); 2277ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski 2287ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski std::unique_ptr<Theme> theme_one = assetmanager.NewTheme(); 2297ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski ASSERT_TRUE(theme_one->ApplyStyle(app::R::style::StyleOne)); 2307ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski 2317ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski Res_value value; 2327ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski uint32_t flags; 2337ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski ApkAssetsCookie cookie; 2347ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski 2357ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski // attr_one is still here from the base. 2367ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski cookie = theme_one->GetAttribute(app::R::attr::attr_one, &value, &flags); 2377ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski ASSERT_NE(kInvalidCookie, cookie); 2387ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski EXPECT_EQ(Res_value::TYPE_INT_DEC, value.dataType); 2397ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski EXPECT_EQ(1u, value.data); 2407ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski EXPECT_EQ(static_cast<uint32_t>(ResTable_typeSpec::SPEC_PUBLIC), flags); 2417ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski 2427ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski // attr_six is not here. 2437ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski EXPECT_EQ(kInvalidCookie, theme_one->GetAttribute(app::R::attr::attr_six, &value, &flags)); 2447ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski 2457ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski std::unique_ptr<Theme> theme_two = assetmanager.NewTheme(); 2467ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski ASSERT_TRUE(theme_two->ApplyStyle(app::R::style::StyleThree)); 2477ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski 2487ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski // Copy the theme to theme_one. 2497ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski ASSERT_TRUE(theme_one->SetTo(*theme_two)); 2507ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski 2517ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski // Clear theme_two to make sure we test that there WAS a copy. 2527ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski theme_two->Clear(); 2537ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski 2547ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski // attr_one is now not here. 2557ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski EXPECT_EQ(kInvalidCookie, theme_one->GetAttribute(app::R::attr::attr_one, &value, &flags)); 2567ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski 2577ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski // attr_six is now here because it was copied. 2587ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski cookie = theme_one->GetAttribute(app::R::attr::attr_six, &value, &flags); 2597ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski ASSERT_NE(kInvalidCookie, cookie); 2607ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski EXPECT_EQ(Res_value::TYPE_INT_DEC, value.dataType); 2617ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski EXPECT_EQ(6u, value.data); 2627ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski EXPECT_EQ(static_cast<uint32_t>(ResTable_typeSpec::SPEC_PUBLIC), flags); 2637ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski} 2647ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski 2657ad1110ecd6a840fcd2895c62668828a1ca029c6Adam LesinskiTEST_F(ThemeTest, FailToCopyThemeWithDifferentAssetManager) { 2667ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski AssetManager2 assetmanager_one; 2677ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski assetmanager_one.SetApkAssets({style_assets_.get()}); 2687ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski 2697ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski AssetManager2 assetmanager_two; 2707ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski assetmanager_two.SetApkAssets({style_assets_.get()}); 2717ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski 2727ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski auto theme_one = assetmanager_one.NewTheme(); 2737ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski ASSERT_TRUE(theme_one->ApplyStyle(app::R::style::StyleOne)); 2747ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski 2757ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski auto theme_two = assetmanager_two.NewTheme(); 2767ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski ASSERT_TRUE(theme_two->ApplyStyle(app::R::style::StyleTwo)); 2777ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski 2787ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski EXPECT_FALSE(theme_one->SetTo(*theme_two)); 2799d9cc6233c7035c32d3b8622aa5dc7d413193dc7Adam Lesinski} 2804c67a475a334e4f65238d439a3339195e03c03beAdam Lesinski 2814c67a475a334e4f65238d439a3339195e03c03beAdam Lesinski} // namespace android 282