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 "include/component_manager.h"
26 #include "mock/mock_aul_comp_info.h"
28 static const char ICON_PATH[] =
29 "/opt/usr/home/owner/apps_rw/org.tizen.helloworld/shared/res/helloworld.png";
31 static int __fake_aul_comp_info_create(const char* compid,
32 aul_comp_info_h* handle) {
33 char* h = static_cast<char*>(malloc(sizeof(char)));
37 *handle = static_cast<aul_comp_info_h>(h);
42 static int __fake_aul_comp_info_destroy(
43 aul_comp_info_h handle) {
47 free(static_cast<void*>(handle));
52 static int __fake_aul_comp_info_get_app_id(aul_comp_info_h handle,
54 *appid = "org.tizen.helloworld";
58 static int __fake_aul_comp_info_get_comp_id(aul_comp_info_h handle,
59 const char** compid) {
60 *compid = "TestComponent";
64 static int __fake_aul_comp_info_get_type(aul_comp_info_h handle,
70 static int __fake_aul_comp_info_is_icon_display(aul_comp_info_h handle,
76 static int __fake_aul_comp_info_is_taskmanage(
77 aul_comp_info_h handle, bool* taskmanage) {
82 static int __fake_aul_comp_info_get_icon(aul_comp_info_h handle,
88 static int __fake_aul_comp_info_get_label(aul_comp_info_h handle,
90 *label = "TestComponent";
94 static int __fake_aul_comp_info_get_localed_label(aul_comp_info_h handle,
95 const char* locale, char** label) {
96 *label = strdup("Kor_TestComponent");
100 static int __fake_aul_comp_info_clone(
101 aul_comp_info_h handle, aul_comp_info_h* clone) {
102 char* h = static_cast<char *>(malloc(sizeof(char)));
106 *clone = static_cast<aul_comp_info_h>(h);
111 class ComponentInfoTest : public testing::Test {
113 virtual void SetUp() {
114 aul_comp_info_create_fake.custom_fake =
115 __fake_aul_comp_info_create;
116 aul_comp_info_destroy_fake.custom_fake =
117 __fake_aul_comp_info_destroy;
118 aul_comp_info_get_app_id_fake.custom_fake =
119 __fake_aul_comp_info_get_app_id;
120 aul_comp_info_get_comp_id_fake.custom_fake =
121 __fake_aul_comp_info_get_comp_id;
122 aul_comp_info_get_type_fake.custom_fake =
123 __fake_aul_comp_info_get_type;
124 aul_comp_info_is_icon_display_fake.custom_fake =
125 __fake_aul_comp_info_is_icon_display;
126 aul_comp_info_is_taskmanage_fake.custom_fake =
127 __fake_aul_comp_info_is_taskmanage;
128 aul_comp_info_get_icon_fake.custom_fake =
129 __fake_aul_comp_info_get_icon;
130 aul_comp_info_get_label_fake.custom_fake =
131 __fake_aul_comp_info_get_label;
132 aul_comp_info_get_localed_label_fake.custom_fake =
133 __fake_aul_comp_info_get_localed_label;
134 aul_comp_info_clone_fake.custom_fake =
135 __fake_aul_comp_info_clone;
137 component_info_create("TestComponent", &handle_);
140 virtual void TearDown() {
141 if (handle_ != nullptr) {
142 component_info_destroy(handle_);
147 component_info_h GetHandle() const {
151 void SetHandle(component_info_h handle) {
156 component_info_h handle_ = nullptr;
159 TEST_F(ComponentInfoTest, component_info_create_Positive) {
160 component_info_h handle = nullptr;
161 int ret = component_info_create("TestComponent", &handle);
162 EXPECT_EQ(ret, COMPONENT_MANAGER_ERROR_NONE);
164 // Post: Destroys the handle
165 component_info_destroy(handle);
168 TEST_F(ComponentInfoTest, component_info_create_Negative) {
169 int ret = component_info_create(nullptr, nullptr);
170 EXPECT_EQ(ret, COMPONENT_MANAGER_ERROR_INVALID_PARAMETER);
173 TEST_F(ComponentInfoTest, component_info_destroy_Positive) {
174 component_info_h handle = GetHandle();
176 int ret = component_info_destroy(handle);
177 EXPECT_EQ(ret, COMPONENT_MANAGER_ERROR_NONE);
181 TEST_F(ComponentInfoTest, component_info_destroy_Negative) {
182 int ret = component_info_destroy(nullptr);
183 EXPECT_EQ(ret, COMPONENT_MANAGER_ERROR_INVALID_PARAMETER);
186 TEST_F(ComponentInfoTest, component_info_get_app_id_Positive) {
187 component_info_h handle = GetHandle();
189 char* value = nullptr;
190 int ret = component_info_get_app_id(handle, &value);
191 EXPECT_EQ(ret, COMPONENT_MANAGER_ERROR_NONE);
192 auto p = std::unique_ptr<char, decltype(std::free)*>(value, std::free);
193 EXPECT_EQ(std::string(p.get()), "org.tizen.helloworld");
196 TEST_F(ComponentInfoTest, component_info_get_app_id_Negative) {
197 int ret = component_info_get_app_id(nullptr, nullptr);
198 EXPECT_EQ(ret, COMPONENT_MANAGER_ERROR_INVALID_PARAMETER);
201 TEST_F(ComponentInfoTest, component_info_get_component_id_Positive) {
202 component_info_h handle = GetHandle();
204 char* value = nullptr;
205 int ret = component_info_get_component_id(handle, &value);
206 EXPECT_EQ(ret, COMPONENT_MANAGER_ERROR_NONE);
207 auto p = std::unique_ptr<char, decltype(std::free)*>(value, std::free);
208 EXPECT_EQ(std::string(p.get()), "TestComponent");
211 TEST_F(ComponentInfoTest, component_info_get_component_id_Negative) {
212 int ret = component_info_get_component_id(nullptr, nullptr);
213 EXPECT_EQ(ret, COMPONENT_MANAGER_ERROR_INVALID_PARAMETER);
216 TEST_F(ComponentInfoTest, component_info_get_component_type_Positive) {
217 component_info_h handle = GetHandle();
219 component_info_component_type_e type;
220 int ret = component_info_get_component_type(handle, &type);
221 EXPECT_EQ(ret, COMPONENT_MANAGER_ERROR_NONE);
222 EXPECT_EQ(type, COMPONENT_INFO_COMPONENT_TYPE_FRAME);
225 TEST_F(ComponentInfoTest, component_info_get_component_type_Negative) {
226 int ret = component_info_get_component_type(nullptr, nullptr);
227 EXPECT_EQ(ret, COMPONENT_MANAGER_ERROR_INVALID_PARAMETER);
230 TEST_F(ComponentInfoTest, component_info_is_icon_display_Positive) {
231 component_info_h handle = GetHandle();
233 bool icon_display = false;
234 int ret = component_info_is_icon_display(handle, &icon_display);
235 EXPECT_EQ(ret, COMPONENT_MANAGER_ERROR_NONE);
236 EXPECT_EQ(icon_display, true);
239 TEST_F(ComponentInfoTest, component_info_is_icon_display_Negative) {
240 int ret = component_info_is_icon_display(nullptr, nullptr);
241 EXPECT_EQ(ret, COMPONENT_MANAGER_ERROR_INVALID_PARAMETER);
244 TEST_F(ComponentInfoTest, component_info_is_managed_by_task_manager_Positive) {
245 component_info_h handle = GetHandle();
247 bool managed = false;
248 int ret = component_info_is_managed_by_task_manager(handle, &managed);
249 EXPECT_EQ(ret, COMPONENT_MANAGER_ERROR_NONE);
250 EXPECT_EQ(managed, true);
253 TEST_F(ComponentInfoTest, component_info_is_managed_by_task_manager_Negative) {
254 int ret = component_info_is_managed_by_task_manager(nullptr, nullptr);
255 EXPECT_EQ(ret, COMPONENT_MANAGER_ERROR_INVALID_PARAMETER);
258 TEST_F(ComponentInfoTest, component_info_get_icon_Positive) {
259 component_info_h handle = GetHandle();
261 char* value = nullptr;
262 int ret = component_info_get_icon(handle, &value);
263 EXPECT_EQ(ret, COMPONENT_MANAGER_ERROR_NONE);
264 auto p = std::unique_ptr<char, decltype(std::free)*>(value, std::free);
265 EXPECT_EQ(std::string(p.get()), ICON_PATH);
268 TEST_F(ComponentInfoTest, component_info_get_icon_Negative) {
269 int ret = component_info_get_icon(nullptr, nullptr);
270 EXPECT_EQ(ret, COMPONENT_MANAGER_ERROR_INVALID_PARAMETER);
273 TEST_F(ComponentInfoTest, component_info_get_label_Positive) {
274 component_info_h handle = GetHandle();
276 char* value = nullptr;
277 int ret = component_info_get_label(handle, &value);
278 EXPECT_EQ(ret, COMPONENT_MANAGER_ERROR_NONE);
279 auto p = std::unique_ptr<char, decltype(std::free)*>(value, std::free);
280 EXPECT_EQ(std::string(p.get()), "TestComponent");
283 TEST_F(ComponentInfoTest, component_info_get_label_Nagative) {
284 int ret = component_info_get_label(nullptr, nullptr);
285 EXPECT_EQ(ret, COMPONENT_MANAGER_ERROR_INVALID_PARAMETER);
288 TEST_F(ComponentInfoTest, component_info_get_localized_label_Positive) {
289 component_info_h handle = GetHandle();
291 char* value = nullptr;
292 int ret = component_info_get_localized_label(handle, "ko-kr", &value);
293 EXPECT_EQ(ret, COMPONENT_MANAGER_ERROR_NONE);
294 auto p = std::unique_ptr<char, decltype(std::free)*>(value, std::free);
295 EXPECT_EQ(std::string(p.get()), "Kor_TestComponent");
298 TEST_F(ComponentInfoTest, component_info_get_localized_label_Negative) {
299 int ret = component_info_get_localized_label(nullptr, nullptr, nullptr);
300 EXPECT_EQ(ret, COMPONENT_MANAGER_ERROR_INVALID_PARAMETER);
303 TEST_F(ComponentInfoTest, component_info_clone_Positive) {
304 component_info_h handle = GetHandle();
306 component_info_h clone = nullptr;
307 int ret = component_info_clone(&clone, handle);
308 EXPECT_EQ(ret, COMPONENT_MANAGER_ERROR_NONE);
309 component_info_destroy(clone);
312 TEST_F(ComponentInfoTest, component_info_clone_Negative) {
313 int ret = component_info_clone(nullptr, nullptr);
314 EXPECT_EQ(ret, COMPONENT_MANAGER_ERROR_INVALID_PARAMETER);