Adam Lesinski | 9d9cc62 | 2014-08-29 14:10:04 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Adam Lesinski | 4c67a47 | 2016-11-10 16:43:59 -0800 | [diff] [blame^] | 17 | #include "androidfw/ResourceTypes.h" |
Adam Lesinski | 9d9cc62 | 2014-08-29 14:10:04 -0700 | [diff] [blame] | 18 | |
Adam Lesinski | 4c67a47 | 2016-11-10 16:43:59 -0800 | [diff] [blame^] | 19 | #include "utils/String16.h" |
| 20 | #include "utils/String8.h" |
| 21 | |
Adam Lesinski | 9d9cc62 | 2014-08-29 14:10:04 -0700 | [diff] [blame] | 22 | #include "TestHelpers.h" |
Adam Lesinski | 9d9cc62 | 2014-08-29 14:10:04 -0700 | [diff] [blame] | 23 | #include "data/app/R.h" |
Adam Lesinski | 4c67a47 | 2016-11-10 16:43:59 -0800 | [diff] [blame^] | 24 | #include "data/system/R.h" |
Adam Lesinski | 9d9cc62 | 2014-08-29 14:10:04 -0700 | [diff] [blame] | 25 | |
Adam Lesinski | 4c67a47 | 2016-11-10 16:43:59 -0800 | [diff] [blame^] | 26 | namespace app = com::android::app; |
Adam Lesinski | 9d9cc62 | 2014-08-29 14:10:04 -0700 | [diff] [blame] | 27 | |
Adam Lesinski | 4c67a47 | 2016-11-10 16:43:59 -0800 | [diff] [blame^] | 28 | namespace android { |
Adam Lesinski | 9d9cc62 | 2014-08-29 14:10:04 -0700 | [diff] [blame] | 29 | |
| 30 | /** |
| 31 | * TODO(adamlesinski): Enable when fixed. |
| 32 | */ |
| 33 | TEST(ThemeTest, DISABLED_shouldCopyThemeFromDifferentResTable) { |
Adam Lesinski | 4c67a47 | 2016-11-10 16:43:59 -0800 | [diff] [blame^] | 34 | ResTable table; |
Adam Lesinski | 9d9cc62 | 2014-08-29 14:10:04 -0700 | [diff] [blame] | 35 | |
Adam Lesinski | 4c67a47 | 2016-11-10 16:43:59 -0800 | [diff] [blame^] | 36 | std::string system_contents; |
| 37 | ASSERT_TRUE(ReadFileFromZipToString("/system/system.apk", "resources.arsc", |
| 38 | &system_contents)); |
| 39 | ASSERT_EQ(NO_ERROR, |
| 40 | table.add(system_contents.data(), system_contents.size())); |
Adam Lesinski | 9d9cc62 | 2014-08-29 14:10:04 -0700 | [diff] [blame] | 41 | |
Adam Lesinski | 4c67a47 | 2016-11-10 16:43:59 -0800 | [diff] [blame^] | 42 | std::string app_contents; |
| 43 | ASSERT_TRUE(ReadFileFromZipToString("/basic/basic.apk", "resources.arsc", |
| 44 | &app_contents)); |
| 45 | ASSERT_EQ(NO_ERROR, table.add(app_contents.data(), app_contents.size())); |
Adam Lesinski | 9d9cc62 | 2014-08-29 14:10:04 -0700 | [diff] [blame] | 46 | |
Adam Lesinski | 4c67a47 | 2016-11-10 16:43:59 -0800 | [diff] [blame^] | 47 | ResTable::Theme theme1(table); |
| 48 | ASSERT_EQ(NO_ERROR, theme1.applyStyle(app::R::style::Theme_One)); |
| 49 | Res_value val; |
| 50 | ASSERT_GE(theme1.getAttribute(android::R::attr::background, &val), 0); |
| 51 | ASSERT_EQ(Res_value::TYPE_INT_COLOR_RGB8, val.dataType); |
| 52 | ASSERT_EQ(uint32_t(0xffff0000), val.data); |
| 53 | ASSERT_GE(theme1.getAttribute(app::R::attr::number, &val), 0); |
| 54 | ASSERT_EQ(Res_value::TYPE_INT_DEC, val.dataType); |
| 55 | ASSERT_EQ(uint32_t(1), val.data); |
| 56 | |
| 57 | ResTable table2; |
| 58 | ASSERT_EQ(NO_ERROR, |
| 59 | table2.add(system_contents.data(), system_contents.size())); |
| 60 | ASSERT_EQ(NO_ERROR, table2.add(app_contents.data(), app_contents.size())); |
| 61 | |
| 62 | ResTable::Theme theme2(table2); |
| 63 | ASSERT_EQ(NO_ERROR, theme2.setTo(theme1)); |
| 64 | ASSERT_GE(theme2.getAttribute(android::R::attr::background, &val), 0); |
| 65 | ASSERT_EQ(Res_value::TYPE_INT_COLOR_RGB8, val.dataType); |
| 66 | ASSERT_EQ(uint32_t(0xffff0000), val.data); |
| 67 | ASSERT_GE(theme2.getAttribute(app::R::attr::number, &val), 0); |
| 68 | ASSERT_EQ(Res_value::TYPE_INT_DEC, val.dataType); |
| 69 | ASSERT_EQ(uint32_t(1), val.data); |
Adam Lesinski | 9d9cc62 | 2014-08-29 14:10:04 -0700 | [diff] [blame] | 70 | } |
| 71 | |
Adam Lesinski | 4c67a47 | 2016-11-10 16:43:59 -0800 | [diff] [blame^] | 72 | } // namespace android |