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.
18 #include <gtest/gtest.h>
19 #include <gmock/gmock.h>
20 #include <bundle_cpp.h>
21 #include <bundle_internal.h>
26 #include "component_manager.h"
28 #include "test_fixture.h"
31 using ::testing::DoAll;
32 using ::testing::Return;
33 using ::testing::SetArgPointee;
34 using ::testing::StrEq;
35 using ::testing::Invoke;
37 struct aul_comp_context_s {
47 struct aul_comp_info_s {
51 class Mocks : public ::testing::NiceMock<AulMock> {};
54 static const char ICON_PATH[] =
55 "/opt/usr/home/owner/apps_rw/org.tizen.helloworld/shared/res/helloworld.png";
57 static int __fake_aul_comp_info_create(const char* comp_id,
58 aul_comp_info_h* handle) {
59 aul_comp_info_h h = static_cast<aul_comp_info_h>(
60 calloc(1, sizeof(struct aul_comp_info_s)));
68 static int __fake_aul_comp_info_get_app_id(aul_comp_info_h handle,
70 *appid = "org.tizen.helloworld";
74 static int __fake_aul_comp_info_get_comp_id(aul_comp_info_h handle,
75 const char** compid) {
76 *compid = "TestComponent";
80 static int __fake_aul_comp_info_get_type(aul_comp_info_h handle,
86 static int __fake_aul_comp_info_is_icon_display(aul_comp_info_h handle,
92 static int __fake_aul_comp_info_is_taskmanage(
93 aul_comp_info_h handle, bool* taskmanage) {
98 static int __fake_aul_comp_info_get_icon(aul_comp_info_h handle,
104 static int __fake_aul_comp_info_get_label(aul_comp_info_h handle,
105 const char** label) {
106 *label = "TestComponent";
110 static int __fake_aul_comp_info_get_localed_label(aul_comp_info_h handle,
111 const char* locale, const char** label) {
112 *label = strdup("Kor_TestComponent");
116 static int __fake_aul_comp_info_clone(
117 aul_comp_info_h handle, aul_comp_info_h* clone) {
118 aul_comp_info_h h = static_cast<aul_comp_info_h>(
119 calloc(1, sizeof(struct aul_comp_info_s)));
128 class ComponentInfoTest : public TestFixture {
130 ComponentInfoTest() : TestFixture(std::make_unique<Mocks>()) {}
131 virtual ~ComponentInfoTest() {}
132 virtual void SetUp() {
133 EXPECT_CALL(GetMock<AulMock>(),
134 aul_comp_info_create(_, _)).
135 WillOnce(Invoke(__fake_aul_comp_info_create));
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;
161 EXPECT_CALL(GetMock<AulMock>(),
162 aul_comp_info_create(_, _)).
163 WillOnce(Invoke(__fake_aul_comp_info_create));
164 int ret = component_info_create("TestComponent", &handle);
165 EXPECT_EQ(ret, COMPONENT_MANAGER_ERROR_NONE);
167 // Post: Destroys the handle
168 component_info_destroy(handle);
171 TEST_F(ComponentInfoTest, component_info_create_Negative) {
172 int ret = component_info_create(nullptr, nullptr);
173 EXPECT_EQ(ret, COMPONENT_MANAGER_ERROR_INVALID_PARAMETER);
176 TEST_F(ComponentInfoTest, component_info_destroy_Positive) {
177 component_info_h handle = GetHandle();
179 int ret = component_info_destroy(handle);
180 EXPECT_EQ(ret, COMPONENT_MANAGER_ERROR_NONE);
184 TEST_F(ComponentInfoTest, component_info_destroy_Negative) {
185 int ret = component_info_destroy(nullptr);
186 EXPECT_EQ(ret, COMPONENT_MANAGER_ERROR_INVALID_PARAMETER);
189 TEST_F(ComponentInfoTest, component_info_get_app_id_Positive) {
190 component_info_h handle = GetHandle();
192 EXPECT_CALL(GetMock<AulMock>(),
193 aul_comp_info_get_app_id(_, _)).
194 WillOnce(Invoke(__fake_aul_comp_info_get_app_id));
195 char* value = nullptr;
196 int ret = component_info_get_app_id(handle, &value);
197 EXPECT_EQ(ret, COMPONENT_MANAGER_ERROR_NONE);
198 auto p = std::unique_ptr<char, decltype(std::free)*>(value, std::free);
199 EXPECT_EQ(std::string(p.get()), "org.tizen.helloworld");
202 TEST_F(ComponentInfoTest, component_info_get_app_id_Negative) {
203 int ret = component_info_get_app_id(nullptr, nullptr);
204 EXPECT_EQ(ret, COMPONENT_MANAGER_ERROR_INVALID_PARAMETER);
207 TEST_F(ComponentInfoTest, component_info_get_component_id_Positive) {
208 component_info_h handle = GetHandle();
210 EXPECT_CALL(GetMock<AulMock>(),
211 aul_comp_info_get_comp_id(_, _)).
212 WillOnce(Invoke(__fake_aul_comp_info_get_comp_id));
213 char* value = nullptr;
214 int ret = component_info_get_component_id(handle, &value);
215 EXPECT_EQ(ret, COMPONENT_MANAGER_ERROR_NONE);
216 auto p = std::unique_ptr<char, decltype(std::free)*>(value, std::free);
217 EXPECT_EQ(std::string(p.get()), "TestComponent");
220 TEST_F(ComponentInfoTest, component_info_get_component_id_Negative) {
221 int ret = component_info_get_component_id(nullptr, nullptr);
222 EXPECT_EQ(ret, COMPONENT_MANAGER_ERROR_INVALID_PARAMETER);
225 TEST_F(ComponentInfoTest, component_info_get_component_type_Positive) {
226 component_info_h handle = GetHandle();
228 EXPECT_CALL(GetMock<AulMock>(),
229 aul_comp_info_get_type(_, _)).
230 WillOnce(Invoke(__fake_aul_comp_info_get_type));
231 component_info_component_type_e type;
232 int ret = component_info_get_component_type(handle, &type);
233 EXPECT_EQ(ret, COMPONENT_MANAGER_ERROR_NONE);
234 EXPECT_EQ(type, COMPONENT_INFO_COMPONENT_TYPE_FRAME);
237 TEST_F(ComponentInfoTest, component_info_get_component_type_Negative) {
238 int ret = component_info_get_component_type(nullptr, nullptr);
239 EXPECT_EQ(ret, COMPONENT_MANAGER_ERROR_INVALID_PARAMETER);
242 TEST_F(ComponentInfoTest, component_info_is_icon_display_Positive) {
243 component_info_h handle = GetHandle();
245 EXPECT_CALL(GetMock<AulMock>(),
246 aul_comp_info_is_icon_display(_, _)).
247 WillOnce(Invoke(__fake_aul_comp_info_is_icon_display));
248 bool icon_display = false;
249 int ret = component_info_is_icon_display(handle, &icon_display);
250 EXPECT_EQ(ret, COMPONENT_MANAGER_ERROR_NONE);
251 EXPECT_EQ(icon_display, true);
254 TEST_F(ComponentInfoTest, component_info_is_icon_display_Negative) {
255 int ret = component_info_is_icon_display(nullptr, nullptr);
256 EXPECT_EQ(ret, COMPONENT_MANAGER_ERROR_INVALID_PARAMETER);
259 TEST_F(ComponentInfoTest, component_info_is_managed_by_task_manager_Positive) {
260 component_info_h handle = GetHandle();
262 EXPECT_CALL(GetMock<AulMock>(),
263 aul_comp_info_is_taskmanage(_, _)).
264 WillOnce(Invoke(__fake_aul_comp_info_is_taskmanage));
265 bool managed = false;
266 int ret = component_info_is_managed_by_task_manager(handle, &managed);
267 EXPECT_EQ(ret, COMPONENT_MANAGER_ERROR_NONE);
268 EXPECT_EQ(managed, true);
271 TEST_F(ComponentInfoTest, component_info_is_managed_by_task_manager_Negative) {
272 int ret = component_info_is_managed_by_task_manager(nullptr, nullptr);
273 EXPECT_EQ(ret, COMPONENT_MANAGER_ERROR_INVALID_PARAMETER);
276 TEST_F(ComponentInfoTest, component_info_get_icon_Positive) {
277 component_info_h handle = GetHandle();
279 EXPECT_CALL(GetMock<AulMock>(),
280 aul_comp_info_get_icon(_, _)).
281 WillOnce(Invoke(__fake_aul_comp_info_get_icon));
282 char* value = nullptr;
283 int ret = component_info_get_icon(handle, &value);
284 EXPECT_EQ(ret, COMPONENT_MANAGER_ERROR_NONE);
285 auto p = std::unique_ptr<char, decltype(std::free)*>(value, std::free);
286 EXPECT_EQ(std::string(p.get()), ICON_PATH);
289 TEST_F(ComponentInfoTest, component_info_get_icon_Negative) {
290 int ret = component_info_get_icon(nullptr, nullptr);
291 EXPECT_EQ(ret, COMPONENT_MANAGER_ERROR_INVALID_PARAMETER);
294 TEST_F(ComponentInfoTest, component_info_get_label_Positive) {
295 component_info_h handle = GetHandle();
297 EXPECT_CALL(GetMock<AulMock>(),
298 aul_comp_info_get_label(_, _)).
299 WillOnce(Invoke(__fake_aul_comp_info_get_label));
300 char* value = nullptr;
301 int ret = component_info_get_label(handle, &value);
302 EXPECT_EQ(ret, COMPONENT_MANAGER_ERROR_NONE);
303 auto p = std::unique_ptr<char, decltype(std::free)*>(value, std::free);
304 EXPECT_EQ(std::string(p.get()), "TestComponent");
307 TEST_F(ComponentInfoTest, component_info_get_label_Nagative) {
308 int ret = component_info_get_label(nullptr, nullptr);
309 EXPECT_EQ(ret, COMPONENT_MANAGER_ERROR_INVALID_PARAMETER);
312 TEST_F(ComponentInfoTest, component_info_get_localized_label_Positive) {
313 component_info_h handle = GetHandle();
315 EXPECT_CALL(GetMock<AulMock>(),
316 aul_comp_info_get_localed_label(_, _, _)).
317 WillOnce(Invoke(__fake_aul_comp_info_get_localed_label));
318 char* value = nullptr;
319 int ret = component_info_get_localized_label(handle, "ko-kr", &value);
320 EXPECT_EQ(ret, COMPONENT_MANAGER_ERROR_NONE);
321 auto p = std::unique_ptr<char, decltype(std::free)*>(value, std::free);
322 EXPECT_EQ(std::string(p.get()), "Kor_TestComponent");
325 TEST_F(ComponentInfoTest, component_info_get_localized_label_Negative) {
326 int ret = component_info_get_localized_label(nullptr, nullptr, nullptr);
327 EXPECT_EQ(ret, COMPONENT_MANAGER_ERROR_INVALID_PARAMETER);
330 TEST_F(ComponentInfoTest, component_info_clone_Positive) {
331 component_info_h handle = GetHandle();
333 EXPECT_CALL(GetMock<AulMock>(),
334 aul_comp_info_clone(_, _)).
335 WillOnce(Invoke(__fake_aul_comp_info_clone));
336 component_info_h clone = nullptr;
337 int ret = component_info_clone(&clone, handle);
338 EXPECT_EQ(ret, COMPONENT_MANAGER_ERROR_NONE);
339 component_info_destroy(clone);
342 TEST_F(ComponentInfoTest, component_info_clone_Negative) {
343 int ret = component_info_clone(nullptr, nullptr);
344 EXPECT_EQ(ret, COMPONENT_MANAGER_ERROR_INVALID_PARAMETER);