2 * Copyright (c) 2019 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.
19 #include <gtest/gtest.h>
24 #include "mock_aul_comp_info.h"
25 #include "component_manager.h"
27 static const char ICON_PATH[] =
28 "/opt/usr/home/owner/apps_rw/org.tizen.helloworld/shared/res/helloworld.png";
30 static int __fake_aul_comp_info_create(const char* compid,
31 aul_comp_info_h* handle) {
32 char* h = static_cast<char*>(malloc(sizeof(char)));
36 *handle = static_cast<aul_comp_info_h>(h);
41 static int __fake_aul_comp_info_destroy(
42 aul_comp_info_h handle) {
46 free(static_cast<void*>(handle));
51 static int __fake_aul_comp_info_get_app_id(aul_comp_info_h handle,
53 *appid = "org.tizen.helloworld";
57 static int __fake_aul_comp_info_get_comp_id(aul_comp_info_h handle,
58 const char** compid) {
59 *compid = "TestComponent";
63 static int __fake_aul_comp_info_get_type(aul_comp_info_h handle,
69 static int __fake_aul_comp_info_is_icon_display(aul_comp_info_h handle,
75 static int __fake_aul_comp_info_is_taskmanage(
76 aul_comp_info_h handle, bool* taskmanage) {
81 static int __fake_aul_comp_info_get_icon(aul_comp_info_h handle,
87 static int __fake_aul_comp_info_get_label(aul_comp_info_h handle,
89 *label = "TestComponent";
93 static int __fake_aul_comp_info_get_localed_label(const char* compid,
94 const char* locale, char** label) {
95 *label = strdup("Kor_TestComponent");
99 static int __fake_aul_comp_info_clone(
100 aul_comp_info_h handle, aul_comp_info_h* clone) {
101 char* h = static_cast<char *>(malloc(sizeof(char)));
105 *clone = static_cast<aul_comp_info_h>(h);
110 class ComponentInfoTest : public testing::Test {
112 virtual void SetUp() {
113 aul_comp_info_create_fake.custom_fake =
114 __fake_aul_comp_info_create;
115 aul_comp_info_destroy_fake.custom_fake =
116 __fake_aul_comp_info_destroy;
117 aul_comp_info_get_app_id_fake.custom_fake =
118 __fake_aul_comp_info_get_app_id;
119 aul_comp_info_get_comp_id_fake.custom_fake =
120 __fake_aul_comp_info_get_comp_id;
121 aul_comp_info_get_type_fake.custom_fake =
122 __fake_aul_comp_info_get_type;
123 aul_comp_info_is_icon_display_fake.custom_fake =
124 __fake_aul_comp_info_is_icon_display;
125 aul_comp_info_is_taskmanage_fake.custom_fake =
126 __fake_aul_comp_info_is_taskmanage;
127 aul_comp_info_get_icon_fake.custom_fake =
128 __fake_aul_comp_info_get_icon;
129 aul_comp_info_get_label_fake.custom_fake =
130 __fake_aul_comp_info_get_label;
131 aul_comp_info_get_localed_label_fake.custom_fake =
132 __fake_aul_comp_info_get_localed_label;
133 aul_comp_info_clone_fake.custom_fake =
134 __fake_aul_comp_info_clone;
136 component_info_create("TestComponent", &handle_);
139 virtual void TearDown() {
140 if (handle_ != nullptr) {
141 component_info_destroy(handle_);
146 component_info_h GetHandle() const {
150 void SetHandle(component_info_h handle) {
155 component_info_h handle_ = nullptr;
158 TEST_F(ComponentInfoTest, component_info_create_Positive) {
159 component_info_h handle = nullptr;
160 int ret = component_info_create("TestComponent", &handle);
161 EXPECT_EQ(ret, COMPONENT_MANAGER_ERROR_NONE);
163 // Post: Destroys the handle
164 component_info_destroy(handle);
167 TEST_F(ComponentInfoTest, component_info_create_Negative) {
168 int ret = component_info_create(nullptr, nullptr);
169 EXPECT_EQ(ret, COMPONENT_MANAGER_ERROR_INVALID_PARAMETER);
172 TEST_F(ComponentInfoTest, component_info_destroy_Positive) {
173 component_info_h handle = GetHandle();
175 int ret = component_info_destroy(handle);
176 EXPECT_EQ(ret, COMPONENT_MANAGER_ERROR_NONE);
180 TEST_F(ComponentInfoTest, component_info_destroy_Negative) {
181 int ret = component_info_destroy(nullptr);
182 EXPECT_EQ(ret, COMPONENT_MANAGER_ERROR_INVALID_PARAMETER);
185 TEST_F(ComponentInfoTest, component_info_get_app_id_Positive) {
186 component_info_h handle = GetHandle();
188 char* value = nullptr;
189 int ret = component_info_get_app_id(handle, &value);
190 EXPECT_EQ(ret, COMPONENT_MANAGER_ERROR_NONE);
191 auto p = std::unique_ptr<char, decltype(std::free)*>(value, std::free);
192 EXPECT_EQ(std::string(p.get()), "org.tizen.helloworld");
195 TEST_F(ComponentInfoTest, component_info_get_app_id_Negative) {
196 int ret = component_info_get_app_id(nullptr, nullptr);
197 EXPECT_EQ(ret, COMPONENT_MANAGER_ERROR_INVALID_PARAMETER);
200 TEST_F(ComponentInfoTest, component_info_get_comp_id_Positive) {
201 component_info_h handle = GetHandle();
203 char* value = nullptr;
204 int ret = component_info_get_comp_id(handle, &value);
205 EXPECT_EQ(ret, COMPONENT_MANAGER_ERROR_NONE);
206 auto p = std::unique_ptr<char, decltype(std::free)*>(value, std::free);
207 EXPECT_EQ(std::string(p.get()), "TestComponent");
210 TEST_F(ComponentInfoTest, component_info_get_comp_id_Negative) {
211 int ret = component_info_get_comp_id(nullptr, nullptr);
212 EXPECT_EQ(ret, COMPONENT_MANAGER_ERROR_INVALID_PARAMETER);
215 TEST_F(ComponentInfoTest, component_info_get_component_type_Positive) {
216 component_info_h handle = GetHandle();
218 component_info_component_type_e type;
219 int ret = component_info_get_component_type(handle, &type);
220 EXPECT_EQ(ret, COMPONENT_MANAGER_ERROR_NONE);
221 EXPECT_EQ(type, COMPONENT_INFO_COMPONENT_TYPE_FRAME);
224 TEST_F(ComponentInfoTest, component_info_get_component_type_Negative) {
225 int ret = component_info_get_component_type(nullptr, nullptr);
226 EXPECT_EQ(ret, COMPONENT_MANAGER_ERROR_INVALID_PARAMETER);
229 TEST_F(ComponentInfoTest, component_info_is_icon_display_Positive) {
230 component_info_h handle = GetHandle();
232 bool icon_display = false;
233 int ret = component_info_is_icon_display(handle, &icon_display);
234 EXPECT_EQ(ret, COMPONENT_MANAGER_ERROR_NONE);
235 EXPECT_EQ(icon_display, true);
238 TEST_F(ComponentInfoTest, component_info_is_icon_display_Negative) {
239 int ret = component_info_is_icon_display(nullptr, nullptr);
240 EXPECT_EQ(ret, COMPONENT_MANAGER_ERROR_INVALID_PARAMETER);
243 TEST_F(ComponentInfoTest, component_info_is_taskmanage_Positive) {
244 component_info_h handle = GetHandle();
246 bool taskmanage = false;
247 int ret = component_info_is_taskmanage(handle, &taskmanage);
248 EXPECT_EQ(ret, COMPONENT_MANAGER_ERROR_NONE);
249 EXPECT_EQ(taskmanage, true);
252 TEST_F(ComponentInfoTest, component_info_is_taskmanage_Negative) {
253 int ret = component_info_is_taskmanage(nullptr, nullptr);
254 EXPECT_EQ(ret, COMPONENT_MANAGER_ERROR_INVALID_PARAMETER);
257 TEST_F(ComponentInfoTest, component_info_get_icon_Positive) {
258 component_info_h handle = GetHandle();
260 char* value = nullptr;
261 int ret = component_info_get_icon(handle, &value);
262 EXPECT_EQ(ret, COMPONENT_MANAGER_ERROR_NONE);
263 auto p = std::unique_ptr<char, decltype(std::free)*>(value, std::free);
264 EXPECT_EQ(std::string(p.get()), ICON_PATH);
267 TEST_F(ComponentInfoTest, component_info_get_icon_Negative) {
268 int ret = component_info_get_icon(nullptr, nullptr);
269 EXPECT_EQ(ret, COMPONENT_MANAGER_ERROR_INVALID_PARAMETER);
272 TEST_F(ComponentInfoTest, component_info_get_label_Positive) {
273 component_info_h handle = GetHandle();
275 char* value = nullptr;
276 int ret = component_info_get_label(handle, &value);
277 EXPECT_EQ(ret, COMPONENT_MANAGER_ERROR_NONE);
278 auto p = std::unique_ptr<char, decltype(std::free)*>(value, std::free);
279 EXPECT_EQ(std::string(p.get()), "TestComponent");
282 TEST_F(ComponentInfoTest, component_info_get_label_Nagative) {
283 int ret = component_info_get_label(nullptr, nullptr);
284 EXPECT_EQ(ret, COMPONENT_MANAGER_ERROR_INVALID_PARAMETER);
287 TEST_F(ComponentInfoTest, component_info_get_localed_label_Positive) {
288 component_info_h handle = GetHandle();
290 char* value = nullptr;
291 int ret = component_info_get_localed_label(handle, "ko-kr", &value);
292 EXPECT_EQ(ret, COMPONENT_MANAGER_ERROR_NONE);
293 auto p = std::unique_ptr<char, decltype(std::free)*>(value, std::free);
294 EXPECT_EQ(std::string(p.get()), "Kor_TestComponent");
297 TEST_F(ComponentInfoTest, component_info_get_localed_label_Negative) {
298 int ret = component_info_get_localed_label(nullptr, nullptr, nullptr);
299 EXPECT_EQ(ret, COMPONENT_MANAGER_ERROR_INVALID_PARAMETER);
302 TEST_F(ComponentInfoTest, component_info_clone_Positive) {
303 component_info_h handle = GetHandle();
305 component_info_h clone = nullptr;
306 int ret = component_info_clone(&clone, handle);
307 EXPECT_EQ(ret, COMPONENT_MANAGER_ERROR_NONE);
308 component_info_destroy(clone);
311 TEST_F(ComponentInfoTest, component_info_clone_Negative) {
312 int ret = component_info_clone(nullptr, nullptr);
313 EXPECT_EQ(ret, COMPONENT_MANAGER_ERROR_INVALID_PARAMETER);