!780 修复mmi队列执行ut问题,补充剩余ut

Merge pull request !780 from zhx/master
This commit is contained in:
openharmony_ci 2024-01-18 09:16:26 +00:00 committed by Gitee
commit 0fbff4beba
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
7 changed files with 213 additions and 6 deletions

View File

@ -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 <thread>
#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

View File

@ -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<std::mutex> lock(eventMutex_);
eventHandler_ = std::make_shared<OHOS::AppExecFwk::EventHandler>(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");

View File

@ -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

View File

@ -77,6 +77,7 @@ void DistributedSchedContinueManager::Init()
void DistributedSchedContinueManager::UnInit()
{
HILOGI("UnInit start");
MMIAdapter::GetInstance().UnInit();
if (eventHandler_ != nullptr) {
eventHandler_->GetEventRunner()->Stop();
eventThread_.join();

View File

@ -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",

View File

@ -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;
}
}
}

View File

@ -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