mirror of
https://gitee.com/openharmony/msdp_device_status
synced 2024-11-23 07:29:52 +00:00
add EnumeratorTest unittest
Signed-off-by: yang123 <yangyanling13@huawei.com>
This commit is contained in:
parent
b7d1455b1c
commit
950ba39eec
@ -20,6 +20,8 @@
|
||||
|
||||
#include "i_input_adapter.h"
|
||||
|
||||
#include "i_input_event_consumer.h"
|
||||
#include "i_input_event_filter.h"
|
||||
namespace OHOS {
|
||||
namespace Msdp {
|
||||
namespace DeviceStatus {
|
||||
@ -51,6 +53,52 @@ public:
|
||||
int32_t AddVirtualInputDevice(std::shared_ptr<MMI::InputDevice> device, int32_t &deviceId) override;
|
||||
int32_t RemoveVirtualInputDevice(int32_t deviceId) override;
|
||||
};
|
||||
|
||||
class PointerFilter : public MMI::IInputEventFilter {
|
||||
public:
|
||||
explicit PointerFilter(std::function<bool(std::shared_ptr<MMI::PointerEvent>)> filter)
|
||||
: filter_(filter) {}
|
||||
|
||||
bool OnInputEvent(std::shared_ptr<MMI::PointerEvent> pointerEvent) const override
|
||||
{
|
||||
return (filter_ != nullptr ? filter_(pointerEvent) : false);
|
||||
}
|
||||
|
||||
bool OnInputEvent(std::shared_ptr<MMI::KeyEvent> keyEvent) const override
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
private:
|
||||
std::function<bool(std::shared_ptr<MMI::PointerEvent>)> filter_;
|
||||
};
|
||||
|
||||
class InterceptorConsumer : public MMI::IInputEventConsumer {
|
||||
public:
|
||||
InterceptorConsumer(std::function<void(std::shared_ptr<MMI::PointerEvent>)> pointerCb,
|
||||
std::function<void(std::shared_ptr<MMI::KeyEvent>)> keyCb)
|
||||
: pointerCb_(pointerCb), keyCb_(keyCb) {}
|
||||
|
||||
void OnInputEvent(std::shared_ptr<MMI::KeyEvent> keyEvent) const override
|
||||
{
|
||||
if (keyCb_ != nullptr) {
|
||||
keyCb_(keyEvent);
|
||||
}
|
||||
}
|
||||
|
||||
void OnInputEvent(std::shared_ptr<MMI::PointerEvent> pointerEvent) const override
|
||||
{
|
||||
if (pointerCb_ != nullptr) {
|
||||
pointerCb_(pointerEvent);
|
||||
}
|
||||
}
|
||||
|
||||
void OnInputEvent(std::shared_ptr<MMI::AxisEvent> axisEvent) const override {}
|
||||
|
||||
private:
|
||||
std::function<void(std::shared_ptr<MMI::PointerEvent>)> pointerCb_;
|
||||
std::function<void(std::shared_ptr<MMI::KeyEvent>)> keyCb_;
|
||||
};
|
||||
} // namespace DeviceStatus
|
||||
} // namespace Msdp
|
||||
} // namespace OHOS
|
||||
|
@ -16,8 +16,6 @@
|
||||
#include "input_adapter.h"
|
||||
|
||||
#include "input_manager.h"
|
||||
#include "i_input_event_consumer.h"
|
||||
#include "i_input_event_filter.h"
|
||||
|
||||
#include "devicestatus_define.h"
|
||||
|
||||
@ -28,52 +26,6 @@ namespace OHOS {
|
||||
namespace Msdp {
|
||||
namespace DeviceStatus {
|
||||
|
||||
class PointerFilter : public MMI::IInputEventFilter {
|
||||
public:
|
||||
explicit PointerFilter(std::function<bool(std::shared_ptr<MMI::PointerEvent>)> filter)
|
||||
: filter_(filter) {}
|
||||
|
||||
bool OnInputEvent(std::shared_ptr<MMI::PointerEvent> pointerEvent) const override
|
||||
{
|
||||
return (filter_ != nullptr ? filter_(pointerEvent) : false);
|
||||
}
|
||||
|
||||
bool OnInputEvent(std::shared_ptr<MMI::KeyEvent> keyEvent) const override
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
private:
|
||||
std::function<bool(std::shared_ptr<MMI::PointerEvent>)> filter_;
|
||||
};
|
||||
|
||||
class InterceptorConsumer : public MMI::IInputEventConsumer {
|
||||
public:
|
||||
InterceptorConsumer(std::function<void(std::shared_ptr<MMI::PointerEvent>)> pointerCb,
|
||||
std::function<void(std::shared_ptr<MMI::KeyEvent>)> keyCb)
|
||||
: pointerCb_(pointerCb), keyCb_(keyCb) {}
|
||||
|
||||
void OnInputEvent(std::shared_ptr<MMI::KeyEvent> keyEvent) const override
|
||||
{
|
||||
if (keyCb_ != nullptr) {
|
||||
keyCb_(keyEvent);
|
||||
}
|
||||
}
|
||||
|
||||
void OnInputEvent(std::shared_ptr<MMI::PointerEvent> pointerEvent) const override
|
||||
{
|
||||
if (pointerCb_ != nullptr) {
|
||||
pointerCb_(pointerEvent);
|
||||
}
|
||||
}
|
||||
|
||||
void OnInputEvent(std::shared_ptr<MMI::AxisEvent> axisEvent) const override {}
|
||||
|
||||
private:
|
||||
std::function<void(std::shared_ptr<MMI::PointerEvent>)> pointerCb_;
|
||||
std::function<void(std::shared_ptr<MMI::KeyEvent>)> keyCb_;
|
||||
};
|
||||
|
||||
int32_t InputAdapter::AddMonitor(std::function<void(std::shared_ptr<MMI::PointerEvent>)> callback)
|
||||
{
|
||||
int32_t monitorId = MMI::InputManager::GetInstance()->AddMonitor(callback);
|
||||
|
@ -335,6 +335,23 @@ HWTEST_F(InputAdapterTest, TestKeyAddMonitor1, TestSize.Level1)
|
||||
RemovePermission();
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: TestAddKeyEventInterceptor1
|
||||
* @tc.desc: Test AddKeyEventInterceptor1
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(InputAdapterTest, AddKeyEventInterceptor1, TestSize.Level1)
|
||||
{
|
||||
CALL_TEST_DEBUG;
|
||||
SetPermission(SYSTEM_CORE, g_cores, sizeof(g_cores) / sizeof(g_cores[0]));
|
||||
std::shared_ptr<IInputAdapter> inputAdapter = std::make_shared<InputAdapter>();
|
||||
int32_t interceptorId = inputAdapter->AddInterceptor(nullptr, nullptr);
|
||||
ASSERT_EQ(interceptorId, RET_ERR);
|
||||
inputAdapter->RemoveInterceptor(interceptorId);
|
||||
RemovePermission();
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: TestAddKeyEventInterceptor1
|
||||
* @tc.desc: Test AddKeyEventInterceptor1
|
||||
|
@ -604,6 +604,25 @@ HWTEST_F(CooperateServerTest, ControlTest1, TestSize.Level0)
|
||||
ASSERT_NO_FATAL_FAILURE(cooperateServer_->Control(
|
||||
context, CooperateRequestID::UNKNOWN_COOPERATE_ACTION, data, reply));
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: RemovePermissionTest
|
||||
* @tc.desc: Test func named RemovePermission
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(CooperateServerTest, RemovePermissionTest, TestSize.Level0)
|
||||
{
|
||||
CALL_TEST_DEBUG;
|
||||
RemovePermission();
|
||||
CallingContext context {
|
||||
.intention = intention_,
|
||||
.tokenId = IPCSkeleton::GetCallingTokenID(),
|
||||
.uid = IPCSkeleton::GetCallingUid(),
|
||||
.pid = IPCSkeleton::GetCallingPid(),
|
||||
};
|
||||
cooperateServer_->Disable(context, datas, reply);
|
||||
}
|
||||
} // namespace DeviceStatus
|
||||
} // namespace Msdp
|
||||
} // namespace OHOS
|
@ -626,6 +626,19 @@ HWTEST_F(SocketSessionTest, SocketSessionTest31, TestSize.Level0)
|
||||
CALL_TEST_DEBUG;
|
||||
ASSERT_NO_FATAL_FAILURE(g_socketSessionManager->RegisterApplicationState());
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: SocketSessionTest32
|
||||
* @tc.desc: Drag Drawing
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(SocketSessionTest, SocketSessionTest32, TestSize.Level0)
|
||||
{
|
||||
CALL_TEST_DEBUG;
|
||||
int32_t pid = IPCSkeleton::GetCallingPid(),
|
||||
ASSERT_NO_FATAL_FAILURE(g_socketSessionManager->ReleaseSessionByPid(pid));
|
||||
}
|
||||
} // namespace DeviceStatus
|
||||
} // namespace Msdp
|
||||
} // namespace OHOS
|
||||
|
Loading…
Reference in New Issue
Block a user