#include <glib.h>
#include <memory>
+#include <queue>
#include <utility>
#include "component_based/common/exception.h"
g_source_remove(idler_);
}
+ void PendingQueuePush(std::string inst_id);
+ std::string PendingQueuePop();
+ bool PendingQueueEmpty();
+
private:
friend class ApplicationBase;
explicit Impl(ApplicationBase* parent);
ApplicationBase* parent_;
std::string app_id_;
bool exiting_ = false;
- std::pair<std::string, ApplicationBase*> pending_context_;
- int idler_ = 0;
+ std::queue<std::string> pending_queue_;
+ guint idler_ = 0;
tizen_base::Bundle data_;
};
app_id_ = std::string(p.get());
}
+void ApplicationBase::Impl::PendingQueuePush(std::string inst_id) {
+ pending_queue_.push(std::move(inst_id));
+}
+
+std::string ApplicationBase::Impl::PendingQueuePop() {
+ auto inst_id = std::move(pending_queue_.front());
+ pending_queue_.pop();
+ return inst_id;
+}
+
+bool ApplicationBase::Impl::PendingQueueEmpty() {
+ return pending_queue_.empty();
+}
+
int ApplicationBase::OnCreate() {
LOGD("");
int ret = AppCoreMultiWindowBase::OnCreate();
}
int ApplicationBase::OnTerminate() {
+ if (impl_->idler_ != 0) {
+ g_source_remove(impl_->idler_);
+ impl_->idler_ = 0;
+ }
+
LOGD("");
return AppCoreMultiWindowBase::OnTerminate();
}
}
void ApplicationBase::ExitContextAtIdle(const std::string& inst_id) {
- impl_->pending_context_ = { inst_id, this };
+ impl_->PendingQueuePush(inst_id);
+
+ if (impl_->idler_ != 0)
+ return;
+
impl_->idler_ = g_idle_add([](gpointer data) -> gboolean {
ApplicationBase* app = static_cast<ApplicationBase*>(data);
- auto cxt = app->FindById(app->impl_->pending_context_.first);
- app->ExitContext(cxt);
- app->impl_->idler_ = 0;
- return G_SOURCE_REMOVE;
+ auto inst_id = std::move(app->impl_->PendingQueuePop());
+ auto ctx = app->FindById(inst_id);
+ if (ctx.get() != nullptr)
+ app->ExitContext(ctx);
+
+ if (app->GetContextCnt() == 0) {
+ LOGW("Exit");
+ app->impl_->idler_ = 0;
+ app->Exit();
+ return G_SOURCE_REMOVE;
+ }
+
+ if (app->impl_->PendingQueueEmpty()) {
+ app->impl_->idler_ = 0;
+ return G_SOURCE_REMOVE;
+ }
+
+ return G_SOURCE_CONTINUE;
}, this);
}
#include "mock/app_control_event_mock.h"
#include "mock/app_control_mock.h"
#include "mock/appcore_multiwindow_base_mock.h"
+#include "mock/aul_mock.h"
#include "mock/base_component_callback_mock.h"
#include "mock/base_frame_component_callback_mock.h"
#include "mock/base_service_component_callback_mock.h"
virtual public ::testing::NiceMock<BaseFrameComponentCallbackMock>,
virtual public ::testing::NiceMock<BaseServiceComponentCallbackMock>,
virtual public ::testing::NiceMock<BaseComponentCallbackMock>,
- virtual public ::testing::NiceMock<AppCoreMultiWindowBaseMock> {};
+ virtual public ::testing::NiceMock<AppCoreMultiWindowBaseMock>,
+ virtual public ::testing::NiceMock<AulMock>{};
ACTION(ReturnFakeWindow) {
frame_window_h frame_win = nullptr;
component_based_app_base_create_cb(_))
.Times(1)
.WillOnce(DoAll(
- DoExit(1000),
+ DoExit(10),
AddServiceBaseComponent(&GetMock<BaseServiceComponentCallbackMock>())
));
EXPECT_CALL(GetMock<ComponentBasedAppBaseCallbackMock>(),
component_based_app_base_create_cb(_))
.Times(1)
.WillOnce(DoAll(
- DoExit(1000),
+ DoExit(10),
AddFrameBaseComponent(&GetMock<BaseFrameComponentCallbackMock>())
));
EXPECT_CALL(GetMock<ComponentBasedAppBaseCallbackMock>(),
component_based_app_base_create_cb(_))
.Times(1)
.WillOnce(DoAll(
- DoExit(1000),
+ DoExit(10),
AddServiceBaseComponent(&GetMock<BaseServiceComponentCallbackMock>())
));
EXPECT_CALL(GetMock<ComponentBasedAppBaseCallbackMock>(),
component_based_app_base_create_cb(_))
.Times(1)
.WillOnce(DoAll(
- DoExit(1000),
+ DoExit(10),
AddServiceBaseComponent(&GetMock<BaseServiceComponentCallbackMock>())
));
EXPECT_CALL(GetMock<ComponentBasedAppBaseCallbackMock>(),
component_based_app_base_create_cb(_))
.Times(1)
.WillOnce(DoAll(
- DoExit(1000),
+ DoExit(10),
AddFrameBaseComponent(&GetMock<BaseFrameComponentCallbackMock>())
));
EXPECT_CALL(GetMock<ComponentBasedAppBaseCallbackMock>(),
component_based_app_base_create_cb(_))
.Times(1)
.WillOnce(DoAll(
- DoExit(1000),
+ DoExit(10),
AddBaseComponent(&GetMock<BaseComponentCallbackMock>())
));
EXPECT_CALL(GetMock<ComponentBasedAppBaseCallbackMock>(),
component_based_app_base_create_cb(_))
.Times(1)
.WillOnce(DoAll(
- DoExit(1000),
+ DoExit(10),
AddFrameBaseComponent(&GetMock<BaseFrameComponentCallbackMock>())
));
EXPECT_CALL(GetMock<ComponentBasedAppBaseCallbackMock>(),
component_based_app_base_create_cb(_))
.Times(1)
.WillOnce(DoAll(
- DoExit(2000),
+ DoExit(200),
AddServiceBaseComponent(&GetMock<BaseServiceComponentCallbackMock>())
));
EXPECT_CALL(GetMock<ComponentBasedAppBaseCallbackMock>(),
component_based_app_base_create_cb(_))
.Times(1)
.WillOnce(DoAll(
- DoExit(1000),
+ DoExit(10),
AddServiceBaseComponent(&GetMock<BaseServiceComponentCallbackMock>())
));
EXPECT_CALL(GetMock<ComponentBasedAppBaseCallbackMock>(),
component_based_app_base_create_cb(_))
.Times(1)
.WillOnce(DoAll(
- DoExit(1000),
+ DoExit(10),
AddServiceBaseComponent(&GetMock<BaseServiceComponentCallbackMock>())
));
EXPECT_CALL(GetMock<ComponentBasedAppBaseCallbackMock>(),
component_based_app_base_create_cb(_))
.Times(1)
.WillOnce(DoAll(
- DoExit(1000),
+ DoExit(10),
AddServiceBaseComponent(&GetMock<BaseServiceComponentCallbackMock>())
));
EXPECT_CALL(GetMock<ComponentBasedAppBaseCallbackMock>(),
component_based_app_base_create_cb(_))
.Times(1)
.WillOnce(DoAll(
- DoExit(1000),
+ DoExit(10),
AddServiceBaseComponent(&GetMock<BaseServiceComponentCallbackMock>())
));
EXPECT_CALL(GetMock<ComponentBasedAppBaseCallbackMock>(),
component_based_app_base_create_cb(_))
.Times(1)
.WillOnce(DoAll(
- DoExit(1000),
+ DoExit(10),
AddFrameBaseComponent(&GetMock<BaseFrameComponentCallbackMock>())
));
EXPECT_CALL(GetMock<ComponentBasedAppBaseCallbackMock>(),
component_based_app_base_create_cb(_))
.Times(1)
.WillOnce(DoAll(
- DoExit(1000),
+ DoExit(10),
AddServiceBaseComponent(&GetMock<BaseServiceComponentCallbackMock>())
));
EXPECT_CALL(GetMock<ComponentBasedAppBaseCallbackMock>(),
EXPECT_CALL(GetMock<ComponentBasedAppBaseCallbackMock>(),
component_based_app_base_create_cb(_))
.WillOnce(DoAll(
- DoExit(1000),
+ DoExit(10),
AddServiceBaseComponent(&GetMock<BaseServiceComponentCallbackMock>())
));
EXPECT_CALL(GetMock<AppCoreMultiWindowBaseMock>(), Run(_, _))
EXPECT_CALL(GetMock<ComponentBasedAppBaseCallbackMock>(),
component_based_app_base_create_cb(_))
.WillOnce(DoAll(
- DoExit(1000),
+ DoExit(10),
AddServiceBaseComponent(&GetMock<BaseServiceComponentCallbackMock>())
));
EXPECT_CALL(GetMock<AppCoreMultiWindowBaseMock>(), Run(_, _))
#include "component_based/efl_base/api/component_based_app.h"
#include "mock/app_common_mock.h"
+#include "mock/aul_mock.h"
#include "mock/appcore_multiwindow_base_mock.h"
#include "mock/component_based_app_callback_mock.h"
#include "mock/frame_component_callback_mock.h"
virtual public ::testing::NiceMock<ComponentBasedAppCallbackMock>,
virtual public ::testing::NiceMock<ServiceComponentCallbackMock>,
virtual public ::testing::NiceMock<FrameComponentCallbackMock>,
- virtual public ::testing::NiceMock<AppCoreMultiWindowBaseMock> {};
+ virtual public ::testing::NiceMock<AppCoreMultiWindowBaseMock>,
+ virtual public ::testing::NiceMock<AulMock>{};
ACTION_P(DoExit, timeout) {
g_timeout_add(timeout, [](gpointer data) -> gboolean {
component_based_app_create_cb(_))
.Times(1)
.WillOnce(DoAll(
- DoExit(1000),
+ DoExit(10),
AddServiceComponent(&GetMock<ServiceComponentCallbackMock>())
));
EXPECT_CALL(GetMock<ComponentBasedAppCallbackMock>(),
component_based_app_create_cb(_))
.Times(1)
.WillOnce(DoAll(
- DoExit(1000),
+ DoExit(10),
AddServiceComponent(&GetMock<ServiceComponentCallbackMock>())
));
EXPECT_CALL(GetMock<ComponentBasedAppCallbackMock>(),
component_based_app_create_cb(_))
.Times(1)
.WillOnce(DoAll(
- DoExit(1000),
+ DoExit(10),
AddFrameComponent(&GetMock<FrameComponentCallbackMock>())
));
EXPECT_CALL(GetMock<ComponentBasedAppCallbackMock>(),
component_based_app_create_cb(_))
.Times(1)
.WillOnce(DoAll(
- DoExit(1000),
+ DoExit(10),
AddServiceComponent(&GetMock<ServiceComponentCallbackMock>())
));
EXPECT_CALL(GetMock<ComponentBasedAppCallbackMock>(),
component_based_app_create_cb(_))
.Times(1)
.WillOnce(DoAll(
- DoExit(1000),
+ DoExit(10),
AddFrameComponent(&GetMock<FrameComponentCallbackMock>())
));
EXPECT_CALL(GetMock<ComponentBasedAppCallbackMock>(),
component_based_app_create_cb(_))
.Times(1)
.WillOnce(DoAll(
- DoExit(1000),
+ DoExit(10),
AddFrameComponent(&GetMock<FrameComponentCallbackMock>())
));
EXPECT_CALL(GetMock<ComponentBasedAppCallbackMock>(),
component_based_app_create_cb(_))
.Times(1)
.WillOnce(DoAll(
- DoExit(1000),
+ DoExit(10),
AddFrameComponent(&GetMock<FrameComponentCallbackMock>())
));
EXPECT_CALL(GetMock<ComponentBasedAppCallbackMock>(),
component_based_app_create_cb(_))
.Times(1)
.WillOnce(DoAll(
- DoExit(1000),
+ DoExit(10),
AddFrameComponent(&GetMock<FrameComponentCallbackMock>())
));
EXPECT_CALL(GetMock<ComponentBasedAppCallbackMock>(),
component_based_app_create_cb(_))
.Times(1)
.WillOnce(DoAll(
- DoExit(1000),
+ DoExit(10),
AddFrameComponent(&GetMock<FrameComponentCallbackMock>())
));
EXPECT_CALL(GetMock<ComponentBasedAppCallbackMock>(),
component_based_app_create_cb(_))
.Times(1)
.WillOnce(DoAll(
- DoExit(1000),
+ DoExit(10),
AddServiceComponent(&GetMock<ServiceComponentCallbackMock>())
));
EXPECT_CALL(GetMock<ComponentBasedAppCallbackMock>(),
component_based_app_create_cb(_))
.Times(1)
.WillOnce(DoAll(
- DoExit(1000),
+ DoExit(10),
AddFrameComponent(&GetMock<FrameComponentCallbackMock>())
));
EXPECT_CALL(GetMock<ComponentBasedAppCallbackMock>(),
component_based_app_create_cb(_))
.Times(1)
.WillOnce(DoAll(
- DoExit(1000),
+ DoExit(10),
AddFrameComponent(&GetMock<FrameComponentCallbackMock>())
));
EXPECT_CALL(GetMock<ComponentBasedAppCallbackMock>(),
EXPECT_CALL(GetMock<ComponentBasedAppCallbackMock>(),
component_based_app_create_cb(_))
.WillOnce(DoAll(
- DoExit(1000),
+ DoExit(10),
AddFrameComponent(&GetMock<FrameComponentCallbackMock>())
));
EXPECT_CALL(GetMock<AppCoreMultiWindowBaseMock>(), Run(_, _))
component_based_app_create_cb(_))
.Times(1)
.WillOnce(DoAll(
- DoExit(1000),
+ DoExit(10),
AddFrameComponent(&GetMock<FrameComponentCallbackMock>())
));
EXPECT_CALL(GetMock<ComponentBasedAppCallbackMock>(),
--- /dev/null
+/*
+ * Copyright (c) 2021 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 <glib.h>
+#include <bundle_internal.h>
+
+#include "mock/aul_mock.h"
+#include "mock/mock_hook.h"
+#include "mock/test_fixture.h"
+
+extern "C" int aul_app_get_appid_bypid(int pid, char *appid, int len) {
+ return MOCK_HOOK_P3(AulMock, aul_app_get_appid_bypid, pid, appid, len);
+}
+
+extern "C" const char* aul_get_app_resource_path(void) {
+ return MOCK_HOOK_P0(AulMock, aul_get_app_resource_path);
+}
+
+extern "C" int aul_watchdog_enable(void) {
+ return MOCK_HOOK_P0(AulMock, aul_watchdog_enable);
+}
+
+extern "C" int aul_watchdog_disable(void) {
+ return MOCK_HOOK_P0(AulMock, aul_watchdog_disable);
+}
+
+extern "C" int aul_watchdog_kick(void) {
+ return MOCK_HOOK_P0(AulMock, aul_watchdog_kick);
+}
+
+extern "C" int aul_app_lifecycle_update_state(aul_app_lifecycle_state_e state) {
+ return MOCK_HOOK_P1(AulMock, aul_app_lifecycle_update_state, state);
+}
+
+extern "C" int aul_status_update(int status) {
+ return MOCK_HOOK_P1(AulMock, aul_status_update, status);
+}
+
+extern "C" int aul_comp_notify_start(const char* instance_id) {
+ return MOCK_HOOK_P1(AulMock, aul_comp_notify_start, instance_id);
+}
+
+extern "C" int aul_comp_notify_exit(const char* instance_id) {
+ return MOCK_HOOK_P1(AulMock, aul_comp_notify_exit, instance_id);
+}
+
+extern "C" int aul_comp_status_update(const char* instance_id, int status) {
+ return MOCK_HOOK_P2(AulMock, aul_comp_status_update, instance_id, status);
+}
--- /dev/null
+/*
+ * Copyright (c) 2021 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.
+ */
+
+#ifndef UNIT_TESTS_MOCK_AUL_MOCK_H_
+#define UNIT_TESTS_MOCK_AUL_MOCK_H_
+
+#include <gmock/gmock.h>
+#include <bundle_internal.h>
+#include <bundle_cpp.h>
+#include <aul.h>
+#include <aul_app_lifecycle.h>
+
+#include "mock/module_mock.h"
+
+class AulMock : public virtual ModuleMock {
+ public:
+ AulMock() {
+ using ::testing::_;
+ using ::testing::Return;
+ using ::testing::Invoke;
+
+ ON_CALL(*this, aul_app_get_appid_bypid(_, _, _))
+ .WillByDefault(Invoke([&](int pid, char *appid, int len) -> int {
+ snprintf(appid, len, "test_appid");
+ return 0;
+ }));
+ ON_CALL(*this, aul_get_app_resource_path())
+ .WillByDefault(Invoke([&]() -> const char* {
+ static const char res_path[] = "/tmp/";
+ return res_path;
+ }));
+ ON_CALL(*this, aul_watchdog_enable())
+ .WillByDefault(Return(0));
+ ON_CALL(*this, aul_watchdog_disable())
+ .WillByDefault(Return(0));
+ ON_CALL(*this, aul_watchdog_kick())
+ .WillByDefault(Return(0));
+ ON_CALL(*this, aul_app_lifecycle_update_state(_))
+ .WillByDefault(Invoke([&](aul_app_lifecycle_state_e state) -> int {
+ return 0;
+ }));
+ ON_CALL(*this, aul_status_update(_))
+ .WillByDefault(Invoke([&](int status) -> int {
+ return 0;
+ }));
+ ON_CALL(*this, aul_comp_notify_start(_))
+ .WillByDefault(Invoke([&](const char* instance_id) -> int {
+ return 0;
+ }));
+ ON_CALL(*this, aul_comp_notify_exit(_))
+ .WillByDefault(Invoke([&](const char* instance_id) -> int {
+ return 0;
+ }));
+ ON_CALL(*this, aul_comp_status_update(_, _))
+ .WillByDefault(Invoke([&](const char* instance_id, int status) -> int {
+ return 0;
+ }));
+ }
+
+ virtual ~AulMock() {}
+
+ MOCK_METHOD3(aul_app_get_appid_bypid, int (int, char*, int));
+ MOCK_METHOD0(aul_get_app_resource_path, const char* ());
+ MOCK_METHOD0(aul_watchdog_enable, int ());
+ MOCK_METHOD0(aul_watchdog_disable, int ());
+ MOCK_METHOD0(aul_watchdog_kick, int ());
+ MOCK_METHOD1(aul_app_lifecycle_update_state, int (aul_app_lifecycle_state_e));
+ MOCK_METHOD1(aul_status_update, int (int));
+ MOCK_METHOD1(aul_comp_notify_start, int (const char*));
+ MOCK_METHOD1(aul_comp_notify_exit, int (const char*));
+ MOCK_METHOD2(aul_comp_status_update, int (const char*, int));
+};
+
+#endif // UNIT_TESTS_MOCK_AUL_MOCK_H_
+