blob: 37746576f79c1453dc14b90d1027154bd8cf2324 [file] [log] [blame]
Adam Lesinski9d9cc622014-08-29 14:10:04 -07001/*
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 Lesinski4c67a472016-11-10 16:43:59 -080017#include "androidfw/ResourceTypes.h"
Adam Lesinski9d9cc622014-08-29 14:10:04 -070018
Adam Lesinski4c67a472016-11-10 16:43:59 -080019#include "utils/String16.h"
20#include "utils/String8.h"
21
Adam Lesinski9d9cc622014-08-29 14:10:04 -070022#include "TestHelpers.h"
Adam Lesinski9d9cc622014-08-29 14:10:04 -070023#include "data/app/R.h"
Adam Lesinski4c67a472016-11-10 16:43:59 -080024#include "data/system/R.h"
Adam Lesinski9d9cc622014-08-29 14:10:04 -070025
Adam Lesinski4c67a472016-11-10 16:43:59 -080026namespace app = com::android::app;
Adam Lesinski9d9cc622014-08-29 14:10:04 -070027
Adam Lesinski4c67a472016-11-10 16:43:59 -080028namespace android {
Adam Lesinski9d9cc622014-08-29 14:10:04 -070029
30/**
31 * TODO(adamlesinski): Enable when fixed.
32 */
33TEST(ThemeTest, DISABLED_shouldCopyThemeFromDifferentResTable) {
Adam Lesinski4c67a472016-11-10 16:43:59 -080034 ResTable table;
Adam Lesinski9d9cc622014-08-29 14:10:04 -070035
Adam Lesinski4c67a472016-11-10 16:43:59 -080036 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 Lesinski9d9cc622014-08-29 14:10:04 -070041
Adam Lesinski4c67a472016-11-10 16:43:59 -080042 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 Lesinski9d9cc622014-08-29 14:10:04 -070046
Adam Lesinski4c67a472016-11-10 16:43:59 -080047 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 Lesinski9d9cc622014-08-29 14:10:04 -070070}
71
Adam Lesinski4c67a472016-11-10 16:43:59 -080072} // namespace android