Theme_test.cpp revision 4c67a475a334e4f65238d439a3339195e03c03be
19d9cc6233c7035c32d3b8622aa5dc7d413193dc7Adam Lesinski/*
29d9cc6233c7035c32d3b8622aa5dc7d413193dc7Adam Lesinski * Copyright (C) 2014 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
174c67a475a334e4f65238d439a3339195e03c03beAdam Lesinski#include "androidfw/ResourceTypes.h"
184c67a475a334e4f65238d439a3339195e03c03beAdam Lesinski
194c67a475a334e4f65238d439a3339195e03c03beAdam Lesinski#include "utils/String16.h"
204c67a475a334e4f65238d439a3339195e03c03beAdam Lesinski#include "utils/String8.h"
219d9cc6233c7035c32d3b8622aa5dc7d413193dc7Adam Lesinski
229d9cc6233c7035c32d3b8622aa5dc7d413193dc7Adam Lesinski#include "TestHelpers.h"
239d9cc6233c7035c32d3b8622aa5dc7d413193dc7Adam Lesinski#include "data/app/R.h"
244c67a475a334e4f65238d439a3339195e03c03beAdam Lesinski#include "data/system/R.h"
259d9cc6233c7035c32d3b8622aa5dc7d413193dc7Adam Lesinski
264c67a475a334e4f65238d439a3339195e03c03beAdam Lesinskinamespace app = com::android::app;
279d9cc6233c7035c32d3b8622aa5dc7d413193dc7Adam Lesinski
284c67a475a334e4f65238d439a3339195e03c03beAdam Lesinskinamespace android {
299d9cc6233c7035c32d3b8622aa5dc7d413193dc7Adam Lesinski
309d9cc6233c7035c32d3b8622aa5dc7d413193dc7Adam Lesinski/**
319d9cc6233c7035c32d3b8622aa5dc7d413193dc7Adam Lesinski * TODO(adamlesinski): Enable when fixed.
329d9cc6233c7035c32d3b8622aa5dc7d413193dc7Adam Lesinski */
339d9cc6233c7035c32d3b8622aa5dc7d413193dc7Adam LesinskiTEST(ThemeTest, DISABLED_shouldCopyThemeFromDifferentResTable) {
344c67a475a334e4f65238d439a3339195e03c03beAdam Lesinski  ResTable table;
359d9cc6233c7035c32d3b8622aa5dc7d413193dc7Adam Lesinski
364c67a475a334e4f65238d439a3339195e03c03beAdam Lesinski  std::string system_contents;
374c67a475a334e4f65238d439a3339195e03c03beAdam Lesinski  ASSERT_TRUE(ReadFileFromZipToString("/system/system.apk", "resources.arsc",
384c67a475a334e4f65238d439a3339195e03c03beAdam Lesinski                                      &system_contents));
394c67a475a334e4f65238d439a3339195e03c03beAdam Lesinski  ASSERT_EQ(NO_ERROR,
404c67a475a334e4f65238d439a3339195e03c03beAdam Lesinski            table.add(system_contents.data(), system_contents.size()));
419d9cc6233c7035c32d3b8622aa5dc7d413193dc7Adam Lesinski
424c67a475a334e4f65238d439a3339195e03c03beAdam Lesinski  std::string app_contents;
434c67a475a334e4f65238d439a3339195e03c03beAdam Lesinski  ASSERT_TRUE(ReadFileFromZipToString("/basic/basic.apk", "resources.arsc",
444c67a475a334e4f65238d439a3339195e03c03beAdam Lesinski                                      &app_contents));
454c67a475a334e4f65238d439a3339195e03c03beAdam Lesinski  ASSERT_EQ(NO_ERROR, table.add(app_contents.data(), app_contents.size()));
469d9cc6233c7035c32d3b8622aa5dc7d413193dc7Adam Lesinski
474c67a475a334e4f65238d439a3339195e03c03beAdam Lesinski  ResTable::Theme theme1(table);
484c67a475a334e4f65238d439a3339195e03c03beAdam Lesinski  ASSERT_EQ(NO_ERROR, theme1.applyStyle(app::R::style::Theme_One));
494c67a475a334e4f65238d439a3339195e03c03beAdam Lesinski  Res_value val;
504c67a475a334e4f65238d439a3339195e03c03beAdam Lesinski  ASSERT_GE(theme1.getAttribute(android::R::attr::background, &val), 0);
514c67a475a334e4f65238d439a3339195e03c03beAdam Lesinski  ASSERT_EQ(Res_value::TYPE_INT_COLOR_RGB8, val.dataType);
524c67a475a334e4f65238d439a3339195e03c03beAdam Lesinski  ASSERT_EQ(uint32_t(0xffff0000), val.data);
534c67a475a334e4f65238d439a3339195e03c03beAdam Lesinski  ASSERT_GE(theme1.getAttribute(app::R::attr::number, &val), 0);
544c67a475a334e4f65238d439a3339195e03c03beAdam Lesinski  ASSERT_EQ(Res_value::TYPE_INT_DEC, val.dataType);
554c67a475a334e4f65238d439a3339195e03c03beAdam Lesinski  ASSERT_EQ(uint32_t(1), val.data);
569d9cc6233c7035c32d3b8622aa5dc7d413193dc7Adam Lesinski
574c67a475a334e4f65238d439a3339195e03c03beAdam Lesinski  ResTable table2;
584c67a475a334e4f65238d439a3339195e03c03beAdam Lesinski  ASSERT_EQ(NO_ERROR,
594c67a475a334e4f65238d439a3339195e03c03beAdam Lesinski            table2.add(system_contents.data(), system_contents.size()));
604c67a475a334e4f65238d439a3339195e03c03beAdam Lesinski  ASSERT_EQ(NO_ERROR, table2.add(app_contents.data(), app_contents.size()));
614c67a475a334e4f65238d439a3339195e03c03beAdam Lesinski
624c67a475a334e4f65238d439a3339195e03c03beAdam Lesinski  ResTable::Theme theme2(table2);
634c67a475a334e4f65238d439a3339195e03c03beAdam Lesinski  ASSERT_EQ(NO_ERROR, theme2.setTo(theme1));
644c67a475a334e4f65238d439a3339195e03c03beAdam Lesinski  ASSERT_GE(theme2.getAttribute(android::R::attr::background, &val), 0);
654c67a475a334e4f65238d439a3339195e03c03beAdam Lesinski  ASSERT_EQ(Res_value::TYPE_INT_COLOR_RGB8, val.dataType);
664c67a475a334e4f65238d439a3339195e03c03beAdam Lesinski  ASSERT_EQ(uint32_t(0xffff0000), val.data);
674c67a475a334e4f65238d439a3339195e03c03beAdam Lesinski  ASSERT_GE(theme2.getAttribute(app::R::attr::number, &val), 0);
684c67a475a334e4f65238d439a3339195e03c03beAdam Lesinski  ASSERT_EQ(Res_value::TYPE_INT_DEC, val.dataType);
694c67a475a334e4f65238d439a3339195e03c03beAdam Lesinski  ASSERT_EQ(uint32_t(1), val.data);
709d9cc6233c7035c32d3b8622aa5dc7d413193dc7Adam Lesinski}
714c67a475a334e4f65238d439a3339195e03c03beAdam Lesinski
724c67a475a334e4f65238d439a3339195e03c03beAdam Lesinski}  // namespace android
73