817fdb989dd75e786a3422f11d41942c7bf184a5
[platform/core/appfw/tizen-theme-manager.git] / test / unit_tests / test_theme.cc
1 /*
2  * Copyright (c) 2020 Samsung Electronics Co., Ltd.
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 <stdlib.h>
18 #include <gtest/gtest.h>
19
20 #include <iostream>
21 #include <memory>
22
23 #include "api/theme.h"
24 #include "api/theme_error.h"
25 #include "theme/loader/theme_info.h"
26
27 using ttm::loader::ThemeInfo;
28
29 class ThemeTest : public testing::Test {
30  public:
31   virtual ~ThemeTest() {}
32
33   virtual void SetUp() {
34     b_.Add("id", "testid");
35     b_.Add("version", "1.0");
36     b_.Add("tool_version", "1.1");
37     b_.Add("title", "Test");
38     b_.Add("resolution", "360X360");
39     b_.Add("preview", "shared/res/preview.png");
40     b_.Add("description", "test");
41   }
42
43   virtual void TearDown() {
44   }
45
46   tizen_base::Bundle b_;
47 };
48
49 TEST_F(ThemeTest, Theme_GetId) {
50   std::shared_ptr<ThemeInfo> info(
51       new ThemeInfo(b_));
52   theme_h handle = static_cast<void*>(&info);
53   char *id;
54   int ret = theme_get_id(handle, &id);
55
56   EXPECT_EQ(ret, THEME_MANAGER_ERROR_NONE);
57   EXPECT_EQ(std::string(id), "testid");
58
59   free(id);
60 }
61
62 TEST_F(ThemeTest, Theme_GetId_N) {
63   char *id;
64   int ret = theme_get_id(nullptr, &id);
65
66   EXPECT_EQ(ret, THEME_MANAGER_ERROR_INVALID_PARAMETER);
67 }
68
69 TEST_F(ThemeTest, Theme_GetVersion) {
70   std::shared_ptr<ThemeInfo> info(
71       new ThemeInfo(b_));
72   theme_h handle = static_cast<void*>(&info);
73   char *version;
74   int ret = theme_get_version(handle, &version);
75
76   EXPECT_EQ(ret, THEME_MANAGER_ERROR_NONE);
77   EXPECT_EQ(std::string(version), "1.0");
78
79   free(version);
80 }
81
82 TEST_F(ThemeTest, Theme_GetVersion_N) {
83   char *version;
84   int ret = theme_get_version(nullptr, &version);
85
86   EXPECT_EQ(ret, THEME_MANAGER_ERROR_INVALID_PARAMETER);
87 }
88
89 TEST_F(ThemeTest, Theme_GetToolVersion) {
90   std::shared_ptr<ThemeInfo> info(
91       new ThemeInfo(b_));
92
93   theme_h handle = static_cast<void*>(&info);
94   char *version;
95   int ret = theme_get_tool_version(handle, &version);
96
97   EXPECT_EQ(ret, THEME_MANAGER_ERROR_NONE);
98   EXPECT_EQ(std::string(version), "1.1");
99
100   free(version);
101 }
102
103 TEST_F(ThemeTest, Theme_GetToolVersion_N) {
104   char *version;
105   int ret = theme_get_tool_version(nullptr, &version);
106
107   EXPECT_EQ(ret, THEME_MANAGER_ERROR_INVALID_PARAMETER);
108 }
109
110 TEST_F(ThemeTest, Theme_GetTitle) {
111   std::shared_ptr<ThemeInfo> info(
112       new ThemeInfo(b_));
113
114   theme_h handle = static_cast<void*>(&info);
115   char *title;
116   int ret = theme_get_title(handle, &title);
117
118   EXPECT_EQ(ret, THEME_MANAGER_ERROR_NONE);
119   EXPECT_EQ(std::string(title), "Test");
120
121   free(title);
122 }
123
124
125 TEST_F(ThemeTest, Theme_GetTitle_N) {
126   char *title;
127   int ret = theme_get_title(nullptr, &title);
128
129   EXPECT_EQ(ret, THEME_MANAGER_ERROR_INVALID_PARAMETER);
130 }
131
132 TEST_F(ThemeTest, Theme_GetResolution) {
133   std::shared_ptr<ThemeInfo> info(
134       new ThemeInfo(b_));
135
136   theme_h handle = static_cast<void*>(&info);
137   char *resolution;
138   int ret = theme_get_resolution(handle, &resolution);
139
140   EXPECT_EQ(ret, THEME_MANAGER_ERROR_NONE);
141   EXPECT_EQ(std::string(resolution), "360X360");
142 }
143
144 TEST_F(ThemeTest, Theme_GetResolution_N) {
145   char *resolution;
146   int ret = theme_get_title(nullptr, &resolution);
147
148   EXPECT_EQ(ret, THEME_MANAGER_ERROR_INVALID_PARAMETER);
149 }
150
151 TEST_F(ThemeTest, Theme_GetPreview) {
152   std::shared_ptr<ThemeInfo> info(
153       new ThemeInfo(b_));
154
155   theme_h handle = static_cast<void*>(&info);
156   char *preview;
157   int ret = theme_get_preview(handle, &preview);
158
159   EXPECT_EQ(ret, THEME_MANAGER_ERROR_NONE);
160   EXPECT_EQ(std::string(preview), "shared/res/preview.png");
161
162   free(preview);
163 }
164
165 TEST_F(ThemeTest, Theme_GetPreview_N) {
166   char *preview;
167   int ret = theme_get_preview(nullptr, &preview);
168
169   EXPECT_EQ(ret, THEME_MANAGER_ERROR_INVALID_PARAMETER);
170 }
171
172 TEST_F(ThemeTest, Theme_GetDescription) {
173   std::shared_ptr<ThemeInfo> info(
174       new ThemeInfo(b_));
175
176   theme_h handle = static_cast<void*>(&info);
177   char *description;
178   int ret = theme_get_description(handle, &description);
179
180   EXPECT_EQ(ret, THEME_MANAGER_ERROR_NONE);
181   EXPECT_EQ(std::string(description), "test");
182
183   free(description);
184 }
185
186 TEST_F(ThemeTest, Theme_GetDescription_N) {
187   char *description;
188   int ret = theme_get_description(nullptr, &description);
189
190   EXPECT_EQ(ret, THEME_MANAGER_ERROR_INVALID_PARAMETER);
191 }