2 * Copyright (c) 2020 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #include <gtest/gtest.h>
22 #include "theme/loader/theme_info.h"
23 #include "theme_plugin/theme_parser.h"
24 #include "unit_tests/mock/gio_mock.h"
25 #include "unit_tests/mock/pkgmgr_info_mock.h"
26 #include "unit_tests/mock/test_fixture.h"
29 using ::testing::Return;
30 using ::testing::SetArgPointee;
32 class Mocks : public ::testing::NiceMock<GioMock>,
33 public ::testing::NiceMock<PkgmgrInfoMock> {};
35 class ThemeParserTest : public TestFixture {
37 ThemeParserTest() : TestFixture(std::make_unique<Mocks>()) {}
39 virtual void SetUp() {
42 virtual void TearDown() {
46 TEST_F(ThemeParserTest, Inflate) {
47 char root_path[] = "test_samples";
48 EXPECT_CALL(GetMock<PkgmgrInfoMock>(),
49 pkgmgrinfo_pkginfo_get_root_path(_, _)).
51 SetArgPointee<1>(const_cast<char*>(root_path)),
52 Return(PMINFO_R_OK)));
54 ttm::plugin::ThemeParser parser("test_samples/test_theme.json", true);
55 auto info = parser.Inflate("testid", "testpkgid", 5001, true);
56 EXPECT_EQ(info.GetId(), "testid");
57 EXPECT_EQ(info.GetPkgid(), "testpkgid");
58 EXPECT_EQ(info.GetUid(), 5001);
59 EXPECT_EQ(info.GetVersion(), "1.0.0");
60 EXPECT_EQ(info.GetToolVersion(), "1.00.38.820793");
61 EXPECT_EQ(info.GetTitle(), "GOGO Theme");
62 EXPECT_EQ(info.GetDescription(), "Example for theme spec");
63 EXPECT_EQ(info.GetString("/header/profile"), "wearable");
64 EXPECT_EQ(info.GetString("/theme/home/app_tray"), "tray.png");
65 EXPECT_EQ(info.GetString("/theme/home/appicon/org.tizen.browser"),
67 EXPECT_EQ(info.GetString("/theme/home/appicon/org.tizen.calculator"),
69 EXPECT_EQ(info.GetString("/theme/home/appicon/org.tizen.calendar"),
71 EXPECT_EQ(info.GetString("/theme/home/appicon/org.tizen.clock"),
73 EXPECT_EQ(info.GetString("/theme/home/appicon/org.tizen.contact"),
75 EXPECT_EQ(info.GetString("/theme/home/size"), "30");
76 EXPECT_EQ(info.GetString("/theme/home/wallpaper"), "home_wallpaper.png");
77 EXPECT_EQ(info.GetString("/theme/keyboard/keypad_bg_color"), "#050a28");
78 EXPECT_EQ(info.GetString("/theme/watchface/id"), "org.tizen.gogowatch");
79 EXPECT_EQ(info.GetString("/theme/watchface/url"),
80 "https://www.download.gogowatch/get");
81 EXPECT_EQ(info.GetStringArray("/theme/preview"),
82 std::vector<std::string>({"GOGO_Preview.png"}));
83 EXPECT_EQ(info.GetString("/theme/files/theme_resources"),
84 "shared/res/theme_resources");
87 TEST_F(ThemeParserTest, MultidimensionalArray) {
88 ttm::plugin::ThemeParser parser(
89 "test_samples/test_multidimensional_array.json", false);
90 auto info = parser.Inflate("testid", "testpkgid", 5001, false);
91 std::vector<std::string> array_value({"1", "2", "3"});
92 EXPECT_EQ(info.GetStringArray("/1D_array"), array_value);
93 EXPECT_EQ(info.GetStringArray("/2D_array/0"), array_value);
94 EXPECT_EQ(info.GetStringArray("/2D_array/1"), array_value);
95 EXPECT_EQ(info.GetStringArray("/3D_array/0/0"), array_value);
96 EXPECT_EQ(info.GetStringArray("/3D_array/0/1"), array_value);
97 EXPECT_EQ(info.GetStringArray("/3D_array/1/0"), array_value);
98 EXPECT_EQ(info.GetStringArray("/3D_array/1/1"), array_value);
101 TEST_F(ThemeParserTest, InvalidJson) {
102 ttm::plugin::ThemeParser parser(
103 "test_samples/test_invalid_json.json", false);
104 auto info = parser.Inflate("testid", "testpkgid", 5001, false);
105 EXPECT_FALSE(info.IsValid());
108 TEST_F(ThemeParserTest, DifferentArrayElementType) {
109 ttm::plugin::ThemeParser parser(
110 "test_samples/test_different_array_element_type.json", false);
111 auto info = parser.Inflate("testid", "testpkgid", 5001, false);
112 EXPECT_FALSE(info.IsValid());
115 TEST_F(ThemeParserTest, EmptyArray) {
116 ttm::plugin::ThemeParser parser(
117 "test_samples/test_empty_array.json", false);
118 auto info = parser.Inflate("testid", "testpkgid", 5001, false);
119 EXPECT_FALSE(info.IsValid());