Theme_test.cpp revision 4c67a475a334e4f65238d439a3339195e03c03be
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
17#include "androidfw/ResourceTypes.h"
18
19#include "utils/String16.h"
20#include "utils/String8.h"
21
22#include "TestHelpers.h"
23#include "data/app/R.h"
24#include "data/system/R.h"
25
26namespace app = com::android::app;
27
28namespace android {
29
30/**
31 * TODO(adamlesinski): Enable when fixed.
32 */
33TEST(ThemeTest, DISABLED_shouldCopyThemeFromDifferentResTable) {
34  ResTable table;
35
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()));
41
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()));
46
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);
70}
71
72}  // namespace android
73