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_extension.h"
27 #include "component_manager.h"
29 #include "test_fixture.h"
32 using ::testing::DoAll;
33 using ::testing::Return;
34 using ::testing::SetArgPointee;
35 using ::testing::StrEq;
36 using ::testing::Invoke;
38 struct aul_comp_context_s {
48 struct aul_comp_info_s {
52 class Mocks : public ::testing::NiceMock<AulMock> {};
54 static int __fake_aul_comp_context_create(const char* comp_id,
55 aul_comp_context_h* handle) {
56 aul_comp_context_h h = static_cast<aul_comp_context_h>(
57 calloc(1, sizeof(struct aul_comp_context_s)));
65 class ComponentManagerExtensionTest : public TestFixture {
67 ComponentManagerExtensionTest() : TestFixture(std::make_unique<Mocks>()) {}
68 virtual ~ComponentManagerExtensionTest() {}
69 virtual void SetUp() {
70 EXPECT_CALL(GetMock<AulMock>(),
71 aul_comp_context_create(_, _)).
72 WillOnce(Invoke(__fake_aul_comp_context_create));
73 component_manager_get_component_context("TestComponent", &handle_);
76 virtual void TearDown() {
77 if (handle_ != nullptr) {
78 component_context_destroy(handle_);
83 component_context_h GetHandle() const {
87 void SetHandle(component_context_h handle) {
92 component_context_h handle_ = nullptr;
95 TEST_F(ComponentManagerExtensionTest,
96 component_manager_pause_component_Positive) {
97 component_context_h handle = GetHandle();
98 EXPECT_CALL(GetMock<AulMock>(),
99 aul_comp_context_pause(_)).
100 WillOnce(Return(AUL_R_OK));
101 int ret = component_manager_pause_component(handle);
102 EXPECT_EQ(ret, COMPONENT_MANAGER_ERROR_NONE);
105 TEST_F(ComponentManagerExtensionTest,
106 component_manager_pause_component_Negative) {
107 int ret = component_manager_pause_component(nullptr);
108 EXPECT_EQ(ret, COMPONENT_MANAGER_ERROR_INVALID_PARAMETER);
111 TEST_F(ComponentManagerExtensionTest,
112 component_manager_terminate_component_Positive) {
113 component_context_h handle = GetHandle();
114 EXPECT_CALL(GetMock<AulMock>(),
115 aul_comp_context_terminate(_)).
116 WillOnce(Return(AUL_R_OK));
117 int ret = component_manager_terminate_component(handle);
118 EXPECT_EQ(ret, COMPONENT_MANAGER_ERROR_NONE);
121 TEST_F(ComponentManagerExtensionTest,
122 component_manager_terminate_component_Negative) {
123 int ret = component_manager_terminate_component(nullptr);
124 EXPECT_EQ(ret, COMPONENT_MANAGER_ERROR_INVALID_PARAMETER);