--- /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_complication.h>
+#include <aul_sock.h>
+#include <gtest/gtest.h>
+#include <stdlib.h>
+
+#include <bundle_cpp.h>
+
+#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 kAppId[] = "org.tizen.complication";
+constexpr const char kProviderAppId[] = "org.tizen.complication-provider";
+
+class Mocks : virtual public ::testing::NiceMock<SocketMock> {};
+
+} // namespace
+
+class ComplicationTest : public TestFixture {
+ public:
+ ComplicationTest() : 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(ComplicationTest, aul_complication_update_request_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_complication_update_request(kAppId, kProviderAppId, getuid());
+ EXPECT_NE(kb, nullptr);
+ tizen_base::Bundle b(kb, false, true);
+
+ EXPECT_EQ(ret, AUL_R_OK);
+ EXPECT_EQ(cmd, COMPLICATION_UPDATE_REQUEST);
+ EXPECT_EQ(opt, (AUL_SOCK_BUNDLE | AUL_SOCK_QUEUE));
+ EXPECT_EQ(b.GetString(AUL_K_CALLER_APPID), kAppId);
+ EXPECT_EQ(b.GetString(AUL_K_APPID), kProviderAppId);
+ EXPECT_EQ(b.GetString(AUL_K_COMPLICATION_MODE), UPDATE_REQUEST);
+}
+
+TEST_F(ComplicationTest, aul_complication_update_request_N) {
+ int ret = aul_complication_update_request(kAppId, nullptr, getuid());
+ EXPECT_EQ(ret, AUL_R_EINVAL);
+
+ ret = aul_complication_update_request(nullptr, kProviderAppId, getuid());
+ EXPECT_EQ(ret, AUL_R_EINVAL);
+}
+
+TEST_F(ComplicationTest, aul_complication_launch_with_extra_data_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_complication_launch_with_extra_data(kAppId, kProviderAppId,
+ getuid(), "KEY", "VALUE");
+ EXPECT_NE(kb, nullptr);
+ tizen_base::Bundle b(kb, false, true);
+
+ EXPECT_EQ(ret, AUL_R_OK);
+ EXPECT_EQ(cmd, COMPLICATION_UPDATE_REQUEST);
+ EXPECT_EQ(opt, (AUL_SOCK_BUNDLE | AUL_SOCK_QUEUE));
+ EXPECT_EQ(b.GetString(AUL_K_CALLER_APPID), kAppId);
+ EXPECT_EQ(b.GetString(AUL_K_APPID), kProviderAppId);
+ EXPECT_EQ(b.GetString(AUL_K_COMPLICATION_MODE), LAUNCH_REQUEST);
+ EXPECT_EQ(b.GetString("KEY"), "VALUE");
+}
+
+TEST_F(ComplicationTest, aul_complication_launch_with_extra_data_N) {
+ int ret = aul_complication_launch_with_extra_data(kAppId, kProviderAppId,
+ getuid(), "KEY", nullptr);
+ EXPECT_EQ(ret, AUL_R_EINVAL);
+
+ ret = aul_complication_launch_with_extra_data(kAppId, kProviderAppId,
+ getuid(), nullptr, "VALUE");
+ EXPECT_EQ(ret, AUL_R_EINVAL);
+
+ ret = aul_complication_launch_with_extra_data(kAppId, nullptr,
+ getuid(), "KEY", "VALUE");
+ EXPECT_EQ(ret, AUL_R_EINVAL);
+
+ ret = aul_complication_launch_with_extra_data(nullptr, kProviderAppId,
+ getuid(), "KEY", "VALUE");
+ EXPECT_EQ(ret, AUL_R_EINVAL);
+}