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_extension.h"
26 #include "mock/mock_aul_comp_context.h"
28 static int __fake_aul_comp_context_create(const char* comp_id,
29 aul_comp_context_h* handle) {
30 char* h = static_cast<char*>(malloc(sizeof(char)));
34 *handle = static_cast<aul_comp_context_h>(h);
38 static int __fake_aul_comp_context_destroy(aul_comp_context_h handle) {
42 std::free(static_cast<void*>(handle));
46 static int __fake_aul_comp_context_pause(aul_comp_context_h handle) {
50 static int __fake_aul_comp_context_terminate(aul_comp_context_h handle) {
54 class ComponentManagerExtensionTest : public testing::Test {
56 virtual void SetUp() {
57 aul_comp_context_create_fake.custom_fake =
58 __fake_aul_comp_context_create;
59 aul_comp_context_destroy_fake.custom_fake =
60 __fake_aul_comp_context_destroy;
61 aul_comp_context_pause_fake.custom_fake =
62 __fake_aul_comp_context_pause;
63 aul_comp_context_terminate_fake.custom_fake =
64 __fake_aul_comp_context_terminate;
66 component_manager_get_component_context("TestComponent", &handle_);
69 virtual void TearDown() {
70 if (handle_ != nullptr) {
71 component_context_destroy(handle_);
76 component_context_h GetHandle() const {
80 void SetHandle(component_context_h handle) {
85 component_context_h handle_ = nullptr;
88 TEST_F(ComponentManagerExtensionTest,
89 component_manager_pause_component_Positive) {
90 component_context_h handle = GetHandle();
92 int ret = component_manager_pause_component(handle);
93 EXPECT_EQ(ret, COMPONENT_MANAGER_ERROR_NONE);
96 TEST_F(ComponentManagerExtensionTest,
97 component_manager_pause_component_Negative) {
98 int ret = component_manager_pause_component(nullptr);
99 EXPECT_EQ(ret, COMPONENT_MANAGER_ERROR_INVALID_PARAMETER);
102 TEST_F(ComponentManagerExtensionTest,
103 component_manager_terminate_component_Positive) {
104 component_context_h handle = GetHandle();
106 int ret = component_manager_terminate_component(handle);
107 EXPECT_EQ(ret, COMPONENT_MANAGER_ERROR_NONE);
110 TEST_F(ComponentManagerExtensionTest,
111 component_manager_terminate_component_Negative) {
112 int ret = component_manager_terminate_component(nullptr);
113 EXPECT_EQ(ret, COMPONENT_MANAGER_ERROR_INVALID_PARAMETER);