diff --git a/services/dtbschedmgr/include/adapter/mmi_adapter.h b/services/dtbschedmgr/include/adapter/mmi_adapter.h index bbc4bdc8..3e81de40 100644 --- a/services/dtbschedmgr/include/adapter/mmi_adapter.h +++ b/services/dtbschedmgr/include/adapter/mmi_adapter.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) 2023-2024 Huawei Device 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 @@ -16,11 +16,11 @@ #ifndef OHOS_DTBSCHEDMGR_MMI_ADAPTER_H #define OHOS_DTBSCHEDMGR_MMI_ADAPTER_H -#ifdef SUPPORT_MULTIMODALINPUT_SERVICE #include #include "event_handler.h" +#ifdef SUPPORT_MULTIMODALINPUT_SERVICE #include "i_input_event_consumer.h" #include "input_manager.h" #endif @@ -36,6 +36,7 @@ public: virtual ~MMIAdapter() = default; void Init(); + void UnInit(); int32_t AddMMIListener(); void RemoveMMIListener(int32_t monitorId); #ifdef SUPPORT_MULTIMODALINPUT_SERVICE diff --git a/services/dtbschedmgr/src/adapter/mmi_adapter.cpp b/services/dtbschedmgr/src/adapter/mmi_adapter.cpp index efe61fa5..c170de3c 100644 --- a/services/dtbschedmgr/src/adapter/mmi_adapter.cpp +++ b/services/dtbschedmgr/src/adapter/mmi_adapter.cpp @@ -49,7 +49,7 @@ void MMIAdapter::StartEvent() { HILOGI("StartEvent start"); prctl(PR_SET_NAME, MMI_ADAPTER.c_str()); - auto runner = AppExecFwk::EventRunner::Create(); + auto runner = AppExecFwk::EventRunner::Create(false); { std::lock_guard lock(eventMutex_); eventHandler_ = std::make_shared(runner); @@ -59,6 +59,19 @@ void MMIAdapter::StartEvent() HILOGI("StartEvent end"); } +void MMIAdapter::UnInit() +{ + HILOGI("UnInit start"); + if (eventHandler_ != nullptr) { + eventHandler_->GetEventRunner()->Stop(); + eventThread_.join(); + eventHandler_ = nullptr; + } else { + HILOGE("eventHandler_ is nullptr"); + } + HILOGI("UnInit end"); +} + int32_t MMIAdapter::AddMMIListener() { HILOGD("AddMMIListener called"); diff --git a/services/dtbschedmgr/src/adapter/mmi_adapter_common.cpp b/services/dtbschedmgr/src/adapter/mmi_adapter_common.cpp index de79c0b5..137064e0 100644 --- a/services/dtbschedmgr/src/adapter/mmi_adapter_common.cpp +++ b/services/dtbschedmgr/src/adapter/mmi_adapter_common.cpp @@ -26,16 +26,23 @@ IMPLEMENT_SINGLE_INSTANCE(MMIAdapter); void MMIAdapter::Init() { - HILOGD("called"); + HILOGI("%{public}s common called. ", __func__); } + +void MMIAdapter::UnInit() +{ + HILOGI("%{public}s common called. ", __func__); +} + int32_t MMIAdapter::AddMMIListener() { - HILOGD("called"); + HILOGI("%{public}s common called. ", __func__); + return 0; } void MMIAdapter::RemoveMMIListener(int32_t monitorId) { - HILOGD("called"); + HILOGI("%{public}s common called. ", __func__); } } // namespace DistributedSchedule } // namespace OHOS \ No newline at end of file diff --git a/services/dtbschedmgr/src/mission/distributed_sched_continue_manager.cpp b/services/dtbschedmgr/src/mission/distributed_sched_continue_manager.cpp index 6e016497..da77987d 100644 --- a/services/dtbschedmgr/src/mission/distributed_sched_continue_manager.cpp +++ b/services/dtbschedmgr/src/mission/distributed_sched_continue_manager.cpp @@ -77,6 +77,7 @@ void DistributedSchedContinueManager::Init() void DistributedSchedContinueManager::UnInit() { HILOGI("UnInit start"); + MMIAdapter::GetInstance().UnInit(); if (eventHandler_ != nullptr) { eventHandler_->GetEventRunner()->Stop(); eventThread_.join(); diff --git a/services/dtbschedmgr/test/BUILD.gn b/services/dtbschedmgr/test/BUILD.gn index 414d390a..7128a078 100644 --- a/services/dtbschedmgr/test/BUILD.gn +++ b/services/dtbschedmgr/test/BUILD.gn @@ -171,6 +171,10 @@ if (dmsfwk_ces_listener) { if (dmsfwk_mmi_listener) { dtbschedmgr_sources += [ "${distributed_service}/dtbschedmgr/src/adapter/mmi_adapter.cpp" ] +} else { + dtbschedmgr_sources += [ + "${distributed_service}/dtbschedmgr/src/adapter/mmi_adapter_common.cpp", + ] } ohos_unittest("distributedschedsvrtest") { @@ -376,6 +380,9 @@ ohos_unittest("dschedmissionmanagertest") { "unittest/mission/snapshot_test.cpp", "unittest/mock_remote_stub.cpp", ] + if (dmsfwk_mmi_listener) { + sources += [ "unittest/adapter/mmi_adapter_test.cpp" ] + } sources += dtbschedmgr_sources configs = [ ":test_config", diff --git a/services/dtbschedmgr/test/unittest/adapter/mmi_adapter_test.cpp b/services/dtbschedmgr/test/unittest/adapter/mmi_adapter_test.cpp new file mode 100644 index 00000000..6e89f89b --- /dev/null +++ b/services/dtbschedmgr/test/unittest/adapter/mmi_adapter_test.cpp @@ -0,0 +1,142 @@ +/* + * Copyright (c) 2024 Huawei Device 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 "mmi_adapter_test.h" +#include "test_log.h" + +using namespace testing; +using namespace testing::ext; + +namespace OHOS { +namespace DistributedSchedule { + +void MMIAdapterTest::SetUpTestCase() +{ + DTEST_LOG << "MMIAdapterTest::SetUpTestCase" << std::endl; +} + +void MMIAdapterTest::TearDownTestCase() +{ + DTEST_LOG << "MMIAdapterTest::TearDownTestCase" << std::endl; +} + +void MMIAdapterTest::TearDown() +{ + DTEST_LOG << "MMIAdapterTest::TearDown" << std::endl; + MMIAdapter::GetInstance().UnInit(); +} + +void MMIAdapterTest::SetUp() +{ + DTEST_LOG << "MMIAdapterTest::SetUp" << std::endl; + MMIAdapter::GetInstance().Init(); +} + +/** + * @tc.name: AddMMIListener_001 + * @tc.desc: test AddMMIListener func + * @tc.type: FUNC + */ +HWTEST_F(MMIAdapterTest, AddMMIListener_001, TestSize.Level3) +{ + DTEST_LOG << "MMIAdapterTest AddMMIListener_001 begin" << std::endl; + int32_t ret = MMIAdapter::GetInstance().AddMMIListener(); + EXPECT_GT(ret, 0); + DTEST_LOG << "MMIAdapterTest AddMMIListener_001 end" << std::endl; +} + +/** + * @tc.name: RemoveMMIListener_001 + * @tc.desc: test RemoveMMIListener func + * @tc.type: FUNC + */ +HWTEST_F(MMIAdapterTest, RemoveMMIListener_001, TestSize.Level3) +{ + DTEST_LOG << "MMIAdapterTest RemoveMMIListener_001 begin" << std::endl; + int32_t mmiId = -1; + MMIAdapter::GetInstance().RemoveMMIListener(mmiId); + EXPECT_NE(MMIAdapter::GetInstance().eventHandler_, nullptr); + DTEST_LOG << "MMIAdapterTest RemoveMMIListener_001 end" << std::endl; +} + +/** + * @tc.name: PostRawMMIEvent_001 + * @tc.desc: test PostRawMMIEvent func + * @tc.type: FUNC + */ +HWTEST_F(MMIAdapterTest, PostRawMMIEvent_001, TestSize.Level3) +{ + DTEST_LOG << "MMIAdapterTest PostRawMMIEvent_001 begin" << std::endl; + MMIAdapter::GetInstance().PostRawMMIEvent(); + EXPECT_NE(MMIAdapter::GetInstance().eventHandler_, nullptr); + DTEST_LOG << "MMIAdapterTest PostRawMMIEvent_001 end" << std::endl; +} + +/** + * @tc.name: PostUnfreezeMMIEvent_001 + * @tc.desc: test PostUnfreezeMMIEvent func + * @tc.type: FUNC + */ +HWTEST_F(MMIAdapterTest, PostUnfreezeMMIEvent_001, TestSize.Level3) +{ + DTEST_LOG << "MMIAdapterTest PostUnfreezeMMIEvent_001 begin" << std::endl; + MMIAdapter::GetInstance().PostUnfreezeMMIEvent(); + EXPECT_NE(MMIAdapter::GetInstance().eventHandler_, nullptr); + DTEST_LOG << "MMIAdapterTest PostUnfreezeMMIEvent_001 end" << std::endl; +} + +/** + * @tc.name: HandleRawMMIEvent_001 + * @tc.desc: test HandleRawMMIEvent func + * @tc.type: FUNC + */ +HWTEST_F(MMIAdapterTest, HandleRawMMIEvent_001, TestSize.Level3) +{ + DTEST_LOG << "MMIAdapterTest HandleRawMMIEvent_001 begin" << std::endl; + MMIAdapter::GetInstance().isMMIFreezed_ = true; + MMIAdapter::GetInstance().HandleRawMMIEvent(); + EXPECT_EQ(MMIAdapter::GetInstance().isMMIFreezed_, true); + DTEST_LOG << "MMIAdapterTest HandleRawMMIEvent_001 end" << std::endl; +} + +/** + * @tc.name: HandleRawMMIEvent_002 + * @tc.desc: test HandleRawMMIEvent func + * @tc.type: FUNC + */ +HWTEST_F(MMIAdapterTest, HandleRawMMIEvent_002, TestSize.Level3) +{ + DTEST_LOG << "MMIAdapterTest HandleRawMMIEvent_002 begin" << std::endl; + MMIAdapter::GetInstance().isMMIFreezed_ = false; + MMIAdapter::GetInstance().HandleRawMMIEvent(); + EXPECT_EQ(MMIAdapter::GetInstance().isMMIFreezed_, true); + DTEST_LOG << "MMIAdapterTest HandleRawMMIEvent_002 end" << std::endl; +} + +/** + * @tc.name: HandleUnfreezeMMIEvent_001 + * @tc.desc: test HandleUnfreezeMMIEvent func + * @tc.type: FUNC + */ +HWTEST_F(MMIAdapterTest, HandleUnfreezeMMIEvent_001, TestSize.Level3) +{ + DTEST_LOG << "MMIAdapterTest HandleUnfreezeMMIEvent_001 begin" << std::endl; + MMIAdapter::GetInstance().isMMIFreezed_ = true; + MMIAdapter::GetInstance().HandleUnfreezeMMIEvent(); + EXPECT_EQ(MMIAdapter::GetInstance().isMMIFreezed_, false); + DTEST_LOG << "MMIAdapterTest HandleUnfreezeMMIEvent_001 end" << std::endl; +} +} +} diff --git a/services/dtbschedmgr/test/unittest/adapter/mmi_adapter_test.h b/services/dtbschedmgr/test/unittest/adapter/mmi_adapter_test.h new file mode 100644 index 00000000..d54c8180 --- /dev/null +++ b/services/dtbschedmgr/test/unittest/adapter/mmi_adapter_test.h @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2024 Huawei Device 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 MMI_ADAPTER_TEST_H +#define MMI_ADAPTER_TEST_H + +#include "gtest/gtest.h" + +#define private public +#include "adapter/mmi_adapter.h" +#undef private + +namespace OHOS { +namespace DistributedSchedule { +class MMIAdapterTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + void SetUp(); + void TearDown(); +}; +} // namespace DistributedSchedule +} // namespace OHOS +#endif // MMI_ADAPTER_TEST_H