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_context.h"
27 #include "mock/mock_aul_comp_info.h"
29 static int __fake_aul_comp_info_foreach_comp_info(aul_comp_info_cb callback,
31 aul_comp_info_h handle = nullptr;
32 callback(handle, user_data);
36 static int __fake_aul_comp_info_create(const char* comp_id,
37 aul_comp_info_h* handle) {
38 char* h = static_cast<char*>(malloc(sizeof(char)));
42 *handle = static_cast<aul_comp_info_h>(h);
46 static int __fake_aul_comp_info_destroy(aul_comp_info_h handle) {
50 std::free(static_cast<void*>(handle));
54 static int __fake_aul_comp_context_foreach_comp_context(
55 aul_comp_context_cb callback, void* user_data) {
56 aul_comp_context_h handle = nullptr;
57 callback(handle, user_data);
61 static int __fake_aul_comp_context_create(const char* comp_id,
62 aul_comp_context_h* handle) {
63 char* h = static_cast<char*>(malloc(sizeof(char)));
67 *handle = static_cast<aul_comp_context_h>(h);
71 static int __fake_aul_comp_context_destroy(aul_comp_context_h handle) {
75 std::free(static_cast<void*>(handle));
79 static int __fake_aul_comp_context_is_running(aul_comp_context_h handle,
85 static int __fake_aul_comp_context_resume(aul_comp_context_h handle) {
89 static int __fake_aul_comp_context_terminate_bg_comp(
90 aul_comp_context_h handle) {
94 class ComponentManagerTest : public testing::Test {
96 virtual void SetUp() {
97 aul_comp_info_foreach_comp_info_fake.custom_fake =
98 __fake_aul_comp_info_foreach_comp_info;
99 aul_comp_info_create_fake.custom_fake =
100 __fake_aul_comp_info_create;
101 aul_comp_info_destroy_fake.custom_fake =
102 __fake_aul_comp_info_destroy;
103 aul_comp_context_foreach_comp_context_fake.custom_fake =
104 __fake_aul_comp_context_foreach_comp_context;
105 aul_comp_context_create_fake.custom_fake =
106 __fake_aul_comp_context_create;
107 aul_comp_context_destroy_fake.custom_fake =
108 __fake_aul_comp_context_destroy;
109 aul_comp_context_is_running_fake.custom_fake =
110 __fake_aul_comp_context_is_running;
111 aul_comp_context_resume_fake.custom_fake =
112 __fake_aul_comp_context_resume;
113 aul_comp_context_terminate_bg_comp_fake.custom_fake =
114 __fake_aul_comp_context_terminate_bg_comp;
116 component_manager_get_component_context("TestComponent", &handle_);
117 component_context_cb_touched_ = false;
118 component_info_cb_touched_ = false;
121 virtual void TearDown() {
122 if (handle_ != nullptr) {
123 component_context_destroy(handle_);
128 component_context_h GetHandle() const {
132 void SetHandle(component_context_h handle) {
137 bool component_context_cb_touched_ = false;
138 bool component_info_cb_touched_ = false;
141 component_context_h handle_ = nullptr;
144 TEST_F(ComponentManagerTest,
145 component_manager_foreach_component_context_Positive) {
146 int ret = component_manager_foreach_component_context(
147 [](component_context_h handle, void* user_data) -> bool {
148 ComponentManagerTest* p = static_cast<ComponentManagerTest*>(user_data);
149 p->component_context_cb_touched_ = true;
152 EXPECT_EQ(ret, COMPONENT_MANAGER_ERROR_NONE);
153 EXPECT_EQ(component_context_cb_touched_, true);
156 TEST_F(ComponentManagerTest,
157 comopnent_manager_foreach_component_context_Negative) {
158 int ret = component_manager_foreach_component_context(nullptr, nullptr);
159 EXPECT_EQ(ret, COMPONENT_MANAGER_ERROR_INVALID_PARAMETER);
162 TEST_F(ComponentManagerTest,
163 component_manager_foreach_component_info_Positive) {
164 int ret = component_manager_foreach_component_info(
165 [](component_info_h handle, void* user_data) -> bool {
166 ComponentManagerTest* p = static_cast<ComponentManagerTest*>(user_data);
167 p->component_info_cb_touched_ = true;
170 EXPECT_EQ(ret, COMPONENT_MANAGER_ERROR_NONE);
171 EXPECT_EQ(component_info_cb_touched_, true);
174 TEST_F(ComponentManagerTest,
175 component_manager_foreach_component_info_Negative) {
176 int ret = component_manager_foreach_component_info(nullptr, nullptr);
177 EXPECT_EQ(ret, COMPONENT_MANAGER_ERROR_INVALID_PARAMETER);
180 TEST_F(ComponentManagerTest, component_manager_get_component_context_Positive) {
181 component_context_h handle = nullptr;
182 int ret = component_manager_get_component_context("TestComponent", &handle);
183 auto p = std::unique_ptr<std::remove_pointer<component_context_h>::type,
184 decltype(component_context_destroy)*>(handle, component_context_destroy);
185 EXPECT_EQ(ret, COMPONENT_MANAGER_ERROR_NONE);
186 EXPECT_NE(p, nullptr);
187 EXPECT_NE(p.get(), nullptr);
190 TEST_F(ComponentManagerTest, component_manager_get_component_context_Negative) {
191 int ret = component_manager_get_component_context(nullptr, nullptr);
192 EXPECT_EQ(ret, COMPONENT_MANAGER_ERROR_INVALID_PARAMETER);
195 TEST_F(ComponentManagerTest, component_manager_get_component_info_Positive) {
196 component_info_h handle = nullptr;
197 int ret = component_manager_get_component_info("TestComponent", &handle);
198 auto p = std::unique_ptr<std::remove_pointer<component_info_h>::type,
199 decltype(component_info_destroy)*>(handle, component_info_destroy);
200 EXPECT_EQ(ret, COMPONENT_MANAGER_ERROR_NONE);
201 EXPECT_NE(p, nullptr);
202 EXPECT_NE(p.get(), nullptr);
205 TEST_F(ComponentManagerTest, component_manager_get_component_info_Negative) {
206 int ret = component_manager_get_component_info(nullptr, nullptr);
207 EXPECT_EQ(ret, COMPONENT_MANAGER_ERROR_INVALID_PARAMETER);
210 TEST_F(ComponentManagerTest, component_manager_is_running_Positive) {
211 bool running = false;
212 int ret = component_manager_is_running("TestComponent", &running);
213 EXPECT_EQ(ret, COMPONENT_MANAGER_ERROR_NONE);
214 EXPECT_EQ(running, true);
217 TEST_F(ComponentManagerTest, component_manager_is_running_Negative) {
218 int ret = component_manager_is_running(nullptr, nullptr);
219 EXPECT_EQ(ret, COMPONENT_MANAGER_ERROR_INVALID_PARAMETER);
222 TEST_F(ComponentManagerTest, component_manager_resume_component_Positive) {
223 component_context_h handle = GetHandle();
225 int ret = component_manager_resume_component(handle);
226 EXPECT_EQ(ret, COMPONENT_MANAGER_ERROR_NONE);
229 TEST_F(ComponentManagerTest, component_manager_resume_component_Negative) {
230 int ret = component_manager_resume_component(nullptr);
231 EXPECT_EQ(ret, COMPONENT_MANAGER_ERROR_INVALID_PARAMETER);
234 TEST_F(ComponentManagerTest,
235 component_manager_terminate_bg_component_Positive) {
236 component_context_h handle = GetHandle();
238 int ret = component_manager_terminate_bg_component(handle);
239 EXPECT_EQ(ret, COMPONENT_MANAGER_ERROR_NONE);
242 TEST_F(ComponentManagerTest,
243 component_manager_terminate_bg_component_Negative) {
244 int ret = component_manager_terminate_bg_component(nullptr);
245 EXPECT_EQ(ret, COMPONENT_MANAGER_ERROR_INVALID_PARAMETER);