--- /dev/null
+/*
+ * Copyright (c) 2022 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <aul.h>
+#include <aul_cmd.h>
+#include <aul_comp_status.h>
+#include <aul_sock.h>
+#include <gtest/gtest.h>
+#include <stdlib.h>
+
+#include <bundle_cpp.h>
+
+#include <iostream>
+#include <memory>
+
+#include "mock/mock_hook.h"
+#include "mock/socket_mock.h"
+#include "mock/test_fixture.h"
+#include "src/launch.h"
+
+using ::testing::_;
+using ::testing::DoAll;
+using ::testing::Return;
+using ::testing::SetArgPointee;
+using ::testing::Invoke;
+using ::testing::SaveArg;
+
+namespace {
+
+constexpr const char kInstanceId[] = "frame@org.tizen.frame-component";
+
+class Mocks : virtual public ::testing::NiceMock<SocketMock> {};
+
+} // namespace
+
+class CompStatusTest : public TestFixture {
+ public:
+ CompStatusTest() : TestFixture(std::make_unique<::Mocks>()) {}
+
+ virtual void SetUp() {
+ if (aul_is_initialized())
+ return;
+
+ aul_launch_init(nullptr, nullptr);
+ }
+
+ virtual void TearDown() {
+ aul_launch_fini();
+ }
+};
+
+TEST_F(CompStatusTest, aul_comp_status_update_P) {
+ int cmd = -1;
+ int opt = -1;
+ bundle* kb = nullptr;
+
+ EXPECT_CALL(GetMock<SocketMock>(), send(_, _, _, _))
+ .Times(1)
+ .WillOnce(Invoke([&](int fd, const void* buf, size_t n, int flags)
+ -> ssize_t {
+ const app_pkt_t* pkt = reinterpret_cast<const app_pkt_t*>(buf);
+ cmd = pkt->cmd;
+ opt = pkt->opt;
+ kb = bundle_decode(pkt->data, pkt->len);
+ return n;
+ }));
+
+ int ret = aul_comp_status_update(kInstanceId, STATUS_CREATED);
+ EXPECT_NE(kb, nullptr);
+ tizen_base::Bundle b(kb, false, true);
+
+ EXPECT_EQ(ret, AUL_R_OK);
+ EXPECT_EQ(cmd, COMP_STATUS_UPDATE);
+ EXPECT_EQ(opt, (AUL_SOCK_NOREPLY | AUL_SOCK_BUNDLE));
+ EXPECT_EQ(b.GetString(AUL_K_INSTANCE_ID), kInstanceId);
+ EXPECT_EQ(b.GetString(AUL_K_STATUS), std::to_string(STATUS_CREATED));
+}
+
+TEST_F(CompStatusTest, aul_comp_status_update_N) {
+ int ret = aul_comp_status_update(kInstanceId, STATUS_TERMINATE + 1);
+ EXPECT_EQ(ret, AUL_R_EINVAL);
+
+ ret = aul_comp_status_update(nullptr, STATUS_TERMINATE);
+ EXPECT_EQ(ret, AUL_R_EINVAL);
+}
+
+TEST_F(CompStatusTest, aul_comp_notify_start_P) {
+ int cmd = -1;
+ int opt = -1;
+ bundle* kb = nullptr;
+
+ EXPECT_CALL(GetMock<SocketMock>(), send(_, _, _, _))
+ .Times(1)
+ .WillOnce(Invoke([&](int fd, const void* buf, size_t n, int flags)
+ -> ssize_t {
+ const app_pkt_t* pkt = reinterpret_cast<const app_pkt_t*>(buf);
+ cmd = pkt->cmd;
+ opt = pkt->opt;
+ kb = bundle_decode(pkt->data, pkt->len);
+ return n;
+ }));
+
+ int ret = aul_comp_notify_start(kInstanceId);
+ EXPECT_NE(kb, nullptr);
+ tizen_base::Bundle b(kb, false, true);
+
+ EXPECT_EQ(ret, AUL_R_OK);
+ EXPECT_EQ(cmd, COMP_NOTIFY_START);
+ EXPECT_EQ(opt, (AUL_SOCK_NOREPLY | AUL_SOCK_BUNDLE));
+ EXPECT_EQ(b.GetString(AUL_K_INSTANCE_ID), kInstanceId);
+}
+
+TEST_F(CompStatusTest, aul_comp_notify_start_N) {
+ int ret = aul_comp_notify_start(nullptr);
+ EXPECT_EQ(ret, AUL_R_EINVAL);
+}
+
+TEST_F(CompStatusTest, aul_comp_notify_exit_P) {
+ int cmd = -1;
+ int opt = -1;
+ bundle* kb = nullptr;
+
+ EXPECT_CALL(GetMock<SocketMock>(), send(_, _, _, _))
+ .Times(1)
+ .WillOnce(Invoke([&](int fd, const void* buf, size_t n, int flags)
+ -> ssize_t {
+ const app_pkt_t* pkt = reinterpret_cast<const app_pkt_t*>(buf);
+ cmd = pkt->cmd;
+ opt = pkt->opt;
+ kb = bundle_decode(pkt->data, pkt->len);
+ return n;
+ }));
+
+ int ret = aul_comp_notify_exit(kInstanceId);
+ EXPECT_NE(kb, nullptr);
+ tizen_base::Bundle b(kb, false, true);
+
+ EXPECT_EQ(ret, AUL_R_OK);
+ EXPECT_EQ(cmd, COMP_NOTIFY_EXIT);
+ EXPECT_EQ(opt, (AUL_SOCK_NOREPLY | AUL_SOCK_BUNDLE));
+ EXPECT_EQ(b.GetString(AUL_K_INSTANCE_ID), kInstanceId);
+}
+
+TEST_F(CompStatusTest, aul_comp_notify_exit_N) {
+ int ret = aul_comp_notify_exit(nullptr);
+ EXPECT_EQ(ret, AUL_R_EINVAL);
+}
+
+TEST_F(CompStatusTest, aul_comp_resume_P) {
+ int cmd = -1;
+ int opt = -1;
+ bundle* kb = nullptr;
+
+ EXPECT_CALL(GetMock<SocketMock>(), send(_, _, _, _))
+ .Times(1)
+ .WillOnce(Invoke([&](int fd, const void* buf, size_t n, int flags)
+ -> ssize_t {
+ const app_pkt_t* pkt = reinterpret_cast<const app_pkt_t*>(buf);
+ cmd = pkt->cmd;
+ opt = pkt->opt;
+ kb = bundle_decode(pkt->data, pkt->len);
+ return n;
+ }));
+ EXPECT_CALL(GetMock<SocketMock>(), recv(_, _, _, _))
+ .Times(1)
+ .WillOnce(Invoke([](int fd, void* buf, size_t n, int flags) -> ssize_t {
+ int ret = AUL_R_OK;
+ memcpy(buf, &ret, sizeof(int));
+ return sizeof(int);
+ }));
+
+ int ret = aul_comp_resume(kInstanceId);
+ EXPECT_NE(kb, nullptr);
+ tizen_base::Bundle b(kb, false, true);
+
+ EXPECT_EQ(ret, AUL_R_OK);
+ EXPECT_EQ(cmd, COMP_CONTEXT_RESUME);
+ EXPECT_EQ(opt, (AUL_SOCK_NONE | AUL_SOCK_BUNDLE));
+ EXPECT_EQ(b.GetString(AUL_K_INSTANCE_ID), kInstanceId);
+}
+
+TEST_F(CompStatusTest, aul_comp_resume_N) {
+ int ret = aul_comp_resume(nullptr);
+ EXPECT_EQ(ret, AUL_R_EINVAL);
+}
+
+TEST_F(CompStatusTest, aul_comp_terminate_P) {
+ int cmd = -1;
+ int opt = -1;
+ bundle* kb = nullptr;
+
+ EXPECT_CALL(GetMock<SocketMock>(), send(_, _, _, _))
+ .Times(1)
+ .WillOnce(Invoke([&](int fd, const void* buf, size_t n, int flags)
+ -> ssize_t {
+ const app_pkt_t* pkt = reinterpret_cast<const app_pkt_t*>(buf);
+ cmd = pkt->cmd;
+ opt = pkt->opt;
+ kb = bundle_decode(pkt->data, pkt->len);
+ return n;
+ }));
+ EXPECT_CALL(GetMock<SocketMock>(), recv(_, _, _, _))
+ .Times(1)
+ .WillOnce(Invoke([](int fd, void* buf, size_t n, int flags) -> ssize_t {
+ int ret = AUL_R_OK;
+ memcpy(buf, &ret, sizeof(int));
+ return sizeof(int);
+ }));
+
+ int ret = aul_comp_terminate(kInstanceId);
+ EXPECT_NE(kb, nullptr);
+ tizen_base::Bundle b(kb, false, true);
+
+ EXPECT_EQ(ret, AUL_R_OK);
+ EXPECT_EQ(cmd, COMP_CONTEXT_TERMINATE);
+ EXPECT_EQ(opt, (AUL_SOCK_NONE | AUL_SOCK_BUNDLE));
+ EXPECT_EQ(b.GetString(AUL_K_INSTANCE_ID), kInstanceId);
+}
+
+TEST_F(CompStatusTest, aul_comp_terminate_N) {
+ int ret = aul_comp_terminate(nullptr);
+ EXPECT_EQ(ret, AUL_R_EINVAL);
+}
+
+TEST_F(CompStatusTest, aul_comp_is_running_P) {
+ int cmd = -1;
+ int opt = -1;
+ bundle* kb = nullptr;
+
+ EXPECT_CALL(GetMock<SocketMock>(), send(_, _, _, _))
+ .Times(1)
+ .WillOnce(Invoke([&](int fd, const void* buf, size_t n, int flags)
+ -> ssize_t {
+ const app_pkt_t* pkt = reinterpret_cast<const app_pkt_t*>(buf);
+ cmd = pkt->cmd;
+ opt = pkt->opt;
+ kb = bundle_decode(pkt->data, pkt->len);
+ return n;
+ }));
+ EXPECT_CALL(GetMock<SocketMock>(), recv(_, _, _, _))
+ .Times(1)
+ .WillOnce(Invoke([](int fd, void* buf, size_t n, int flags) -> ssize_t {
+ int ret = 1;
+ memcpy(buf, &ret, sizeof(int));
+ return sizeof(int);
+ }));
+
+ bool running = false;
+ int ret = aul_comp_is_running(kInstanceId, &running);
+ EXPECT_NE(kb, nullptr);
+ tizen_base::Bundle b(kb, false, true);
+
+ EXPECT_EQ(ret, AUL_R_OK);
+ EXPECT_EQ(cmd, COMP_CONTEXT_IS_RUNNING);
+ EXPECT_EQ(opt, (AUL_SOCK_NONE | AUL_SOCK_BUNDLE));
+ EXPECT_EQ(running, true);
+ EXPECT_EQ(b.GetString(AUL_K_INSTANCE_ID), kInstanceId);
+}
+
+TEST_F(CompStatusTest, aul_comp_is_running_N) {
+ bool running = false;
+ int ret = aul_comp_is_running(nullptr, &running);
+ EXPECT_EQ(ret, AUL_R_EINVAL);
+
+ ret = aul_comp_is_running(kInstanceId, nullptr);
+ EXPECT_EQ(ret, AUL_R_EINVAL);
+}